Skip to content

feat: search improvements and tool_use indexing#2

Merged
andyhtran merged 5 commits intomainfrom
feat/search-improvements
Mar 6, 2026
Merged

feat: search improvements and tool_use indexing#2
andyhtran merged 5 commits intomainfrom
feat/search-improvements

Conversation

@andyhtran
Copy link
Copy Markdown
Owner

Summary

  • Multi-term AND search: cct search "Read search.go" matches sessions containing all terms
  • Role labels: search results show [u]/[a] prefixes to distinguish user vs assistant matches
  • --session flag: scope search to a single session with -s <id>
  • Sub-agent filtering: --no-agents excludes agent sessions from search; --agents includes them in list/stats; ShortID preserves full agent IDs to avoid collisions
  • Search tool_use blocks: file paths, bash commands, grep patterns, and URLs from tool invocations are now searchable. Matches show source labels like [a:Read], [a:Bash]
  • -C context flag: cct search "query" -C 200 adds extra characters to snippet width for more surrounding context
  • Internal simplifications: generic parallelMap deduplicates worker pool boilerplate; printResumeHints deduplicates hint loops; FindByPrefixFull simplified; exportJSON encoder setup cleaned up

Test plan

  • go test ./... — all pass
  • go vet ./... — clean
  • Manual smoke test of all commands: list, search, info, export, stats, plans, resume --dry-run, version, schema, log
  • Verified -C flag with default, 0, 100, 500 values
  • Verified tool_use search with file paths, bash commands, multi-term queries
  • Verified [a:Read], [a:Bash], [a:ToolSearch] source labels in output
  • Verified --no-agents, --session, --json flags

🤖 Generated with Claude Code

andyhtran and others added 5 commits March 6, 2026 13:03
Split multi-word queries into individual terms and require all terms
to appear somewhere across the session's messages. Single-term queries
retain exact substring matching.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Show [u]/[a] prefix in table output and structured role field in JSON
to distinguish user vs assistant messages in search matches.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add -s/--session flag to `cct search` to scope search to a single
session, eliminating the need for `cct export <id> | grep`.

Fix a bug where sub-agent files (agent-*.jsonl) had their file-derived
ID overwritten by the parent session's `sessionId` field from the JSONL
content. This caused FindByPrefix to see multiple "different" sessions
with the same ID (e.g. the parent file + 2 sub-agent files all claiming
to be c8035fd7), returning ErrMultipleMatches and blocking --session,
info, export, and resume for any session that had sub-agents.

Root cause: extractUserMetadata (parse.go) unconditionally replaced
s.ID with the `sessionId` value from the first user message. For
regular sessions this was redundant (sessionId == filename). For
sub-agent files, `sessionId` pointed to the parent session, causing
identity collision. Verified across 501 non-agent files that sessionId
always matches the filename, confirming the override was never needed.

Fix: remove the sessionId override entirely. The file-derived ID
(from the .jsonl filename) is always the correct, unique identifier.

This resolved 313 duplicate ID collisions across 2847 sessions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Exclude agent-*.jsonl files from list and stats by default (--agents
to include). Keep agents in search by default (--no-agents to exclude)
and tag them with "(agent)" in the PROJECT column.

Fix ShortID for agent files: return the full 14-char ID instead of
truncating to 8 chars, which caused collisions (only 256 possible
values for 2157 agent files). Skip agent sessions in resume hints.

Add IsAgentSession helper and IsAgent field to Session struct.
Widen SESSION column from 10 to 16 chars to fit agent IDs.

Also clean up 7 redundant comments across 4 files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Search tool_use blocks: extract tool name and string input values
  (file paths, commands, patterns, URLs) so they are searchable.
  Matches show source labels like [a:Read] and [a:Bash].
- Add -C/--context flag to search for wider snippet context.
- Add Match.Source field to attribute matches to specific tools.
- Extract parallelMap generic helper, deduplicating ScanFiles and
  SearchFiles worker pool boilerplate.
- Extract printResumeHints helper, deduplicating list.go and search.go.
- Simplify FindByPrefixFull to return full parse directly.
- Simplify exportJSON encoder setup to create writer first.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@andyhtran andyhtran merged commit 877b8db into main Mar 6, 2026
3 checks passed
@andyhtran andyhtran deleted the feat/search-improvements branch March 15, 2026 09:41
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