Skip to content

feat(log): add search command and date shortcuts#9

Merged
ntwrknrd merged 2 commits intomainfrom
fix/session-duration-v3-format
Jan 11, 2026
Merged

feat(log): add search command and date shortcuts#9
ntwrknrd merged 2 commits intomainfrom
fix/session-duration-v3-format

Conversation

@ntwrknrd
Copy link
Copy Markdown
Owner

Summary

Adds new features to the nssh log commands:

New nssh log search command

Search through session recordings for keywords or patterns:

nssh log search "show interfaces"
nssh log search -s router1 "bgp neighbor"
nssh log search --last 10 "error"
nssh log search -i "WARNING"  # case-sensitive
nssh log search -C 2 "error"  # show context lines
  • Searches .txt exports if available (faster), otherwise parses .cast files directly with ANSI stripping
  • Highlights matches in yellow

Date shortcuts for --select flag

Adds convenient shortcuts to --select/-s on list, delete, and search commands:

  • today, yesterday
  • this-week, last-week
  • this-month, last-month

Examples:

nssh log list -s today
nssh log list -s yesterday
nssh log search -s this-week "error"
nssh log delete -s last-month --dry-run

Improved date filtering

Date filtering now matches on either StartedAt OR mtime (last updated), so sessions that started yesterday but were active today will match both yesterday and today.

ntwrknrd and others added 2 commits January 11, 2026 00:53
Sessions showed 0:00 duration because:
1. WriteIndex was defined but never called - no index files were created
2. Fallback to reading v3 cast files failed (v3 uses relative timestamps
   that must be summed, not absolute timestamps)

Changes:
- Call WriteIndex in recording_wrapper.go when sessions end, capturing
  wall-clock startedAt/finishedAt times
- Simplify readFromCastFile to use mtime as fallback finish time
  (accurate for completed sessions, avoids parsing entire file)
- Remove broken readFinalTimestamp that didn't work for v3 format
- Add one-time migration script (scripts/migrate-indexes.sh) to
  backfill indexes for existing cast files

For new sessions: Index file written with accurate wall-clock duration
For old sessions: Migration script parses cast files and generates indexes

Amp-Thread-ID: https://ampcode.com/threads/T-019bab65-8279-746f-9c0d-5480177d9aae
Co-authored-by: Amp <amp@ampcode.com>
- Add 'nssh log search <pattern>' to grep through session recordings
  - Searches .txt exports if available, otherwise parses .cast files
  - Supports --select, --last, --case-sensitive, --context flags
  - Highlights matches in output

- Add date shortcuts to --select flag on list, delete, search commands:
  - today, yesterday, this-week, last-week, this-month, last-month

- Date filtering now matches on either StartedAt OR mtime, so sessions
  that started yesterday but were active today match both dates
@ntwrknrd ntwrknrd force-pushed the fix/session-duration-v3-format branch from 5066cb9 to baf275c Compare January 11, 2026 06:44
@ntwrknrd ntwrknrd merged commit fa0513b into main Jan 11, 2026
13 checks passed
@ntwrknrd ntwrknrd deleted the fix/session-duration-v3-format branch January 11, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant