Summary
Two improvements to --no-interactive output (markdown and JSON):
1. Show matched token in each result line
Current (markdown):
- **org/repo** (1 match)
- [ ] [src/foo.ts:3:5](https://github.com/org/repo/blob/main/src/foo.ts#L3)
Proposed:
- **org/repo** (1 match)
- [ ] [src/foo.ts:3:5](https://github.com/org/repo/blob/main/src/foo.ts#L3): `useFlag`
Current (JSON matches[] entry):
{ "path": "src/foo.ts", "url": "...", "line": 3, "col": 5 }
Proposed:
{ "path": "src/foo.ts", "url": "...", "line": 3, "col": 5, "matchedText": "useFlag" }
The exact matched token is already available in TextMatchSegment.text — no API change required.
Falls back gracefully (no extra field) when location data is unavailable.
2. Add a query title heading
Current:
1 repo · 2 files · 3 matches selected
Proposed (plain query):
# Results for "useFlag"
1 repo · 2 files · 3 matches selected
With qualifiers:
# Results for "useFlag" · including archived · excluding templates
1 repo · 2 files · 3 matches selected
Regex mode (query = /useFlag/i):
# Results for `/useFlag/i`
1 repo · 2 files · 3 matches selected
The heading also appears in --output-type repo-only mode (before the repo list).
Motivation
- Makes piped/saved markdown documents self-describing without consulting the replay command
- The
matchedText field makes JSON output directly usable in downstream scripts without needing to re-fetch content
- Regex users can immediately see the pattern that was applied at a glance
Implementation notes
- New exported function
buildQueryTitle(query, options) in src/output.ts
- Uses
isRegexQuery() from src/regex.ts to detect regex syntax
matchedText uses TextMatchSegment.text (already in existing types — no type changes needed)
- Both changes are purely in
src/output.ts (pure function layer)
Acceptance criteria
Summary
Two improvements to
--no-interactiveoutput (markdown and JSON):1. Show matched token in each result line
Current (markdown):
Proposed:
Current (JSON
matches[]entry):{ "path": "src/foo.ts", "url": "...", "line": 3, "col": 5 }Proposed:
{ "path": "src/foo.ts", "url": "...", "line": 3, "col": 5, "matchedText": "useFlag" }The exact matched token is already available in
TextMatchSegment.text— no API change required.Falls back gracefully (no extra field) when location data is unavailable.
2. Add a query title heading
Current:
Proposed (plain query):
With qualifiers:
Regex mode (query =
/useFlag/i):The heading also appears in
--output-type repo-onlymode (before the repo list).Motivation
matchedTextfield makes JSON output directly usable in downstream scripts without needing to re-fetch contentImplementation notes
buildQueryTitle(query, options)insrc/output.tsisRegexQuery()fromsrc/regex.tsto detect regex syntaxmatchedTextusesTextMatchSegment.text(already in existing types — no type changes needed)src/output.ts(pure function layer)Acceptance criteria
buildMarkdownOutputprepends# Results for ...with correct qualifiers: `{matchedText}`when location is availablematches[]includes"matchedText"when location is availablerepo-onlymode also gets the H1 headingbun testpasses with new and updated testsbun run lint,bun run format:check,bun run knippass