Skip to content

Add query title heading and matched token to output#127

Merged
shouze merged 3 commits intomainfrom
feat/output-query-title-matched-token
Apr 1, 2026
Merged

Add query title heading and matched token to output#127
shouze merged 3 commits intomainfrom
feat/output-query-title-matched-token

Conversation

@shouze
Copy link
Copy Markdown
Contributor

@shouze shouze commented Apr 1, 2026

Closes #126

What

Two improvements to the --no-interactive output (markdown and JSON).

1. Query title heading

Every output now starts with a # Results for H1 heading. Qualifiers are appended when active:

# Results for "useFeatureFlag"
# Results for "useFeatureFlag" · including archived · excluding templates
# Results for `/useFeatureFlag/i`

Appears in both repo-and-matches and repo-only modes.

2. Matched token inline in each result line

Markdown — before:

- **org/repo** (1 match)
  - [ ] [src/foo.ts:3:5](https://github.com/org/repo/blob/main/src/foo.ts#L3)

Markdown — after:

- **org/repo** (1 match)
  - [ ] [src/foo.ts:3:5](https://github.com/org/repo/blob/main/src/foo.ts#L3): `useFeatureFlag`

JSON — before:

{ "path": "src/foo.ts", "url": "...", "line": 3, "col": 5 }

JSON — after:

{ "path": "src/foo.ts", "url": "...", "line": 3, "col": 5, "matchedText": "useFeatureFlag" }

Both fields fall back gracefully when location/segment data is unavailable (no API change required — TextMatchSegment.text already existed).

Changes

File Change
src/output.ts New buildQueryTitle() + updated buildMarkdownOutput / buildJsonOutput
src/output.test.ts New describe("buildQueryTitle") (6 cases) + updated snapshots
docs/usage/output-formats.md Updated all examples + new "Query title" section
docs/usage/non-interactive-mode.md Updated example output
README.md Updated Structured output bullet + added Regex search to features list and comparison table

Verification

bun test               ✓  742 pass, 0 fail
bun run lint           ✓  0 warnings, 0 errors
bun run format:check   ✓  all files correctly formatted
bun run knip           ✓  no unused exports
bun run build.ts       ✓  binary compiles
aikido_full_scan       ✓  0 issues

- buildMarkdownOutput now prepends '# Results for "query"' (H1) with
  optional qualifiers (· including archived · excluding templates).
  In regex mode the query is displayed in backticks.
- Each match line appended with the exact matched token in backticks
  when TextMatchSegment.text is available (e.g. \`: \`useFlag\`\`).
- buildJsonOutput adds matchedText field to each match entry alongside
  the existing line/col fields (omitted when location is unavailable).
- repo-only mode also gets the H1 heading before the repo list.
- New exported buildQueryTitle(query, options) in src/output.ts.
- 78 tests pass (new describe + updated snapshots in output.test.ts).
- README.md and docs updated to reflect new output format.

Closes #126
Copilot AI review requested due to automatic review settings April 1, 2026 04:56
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Coverage after merging feat/output-query-title-matched-token into main will be

95.85%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.57%100%100%93.89%319–323, 384, 401, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.25%100%95.24%99.59%80
   regex.ts99.26%100%100%99.21%251
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

🔦 Lighthouse Report

Page ⚡ Perf ♿ A11y 🛡️ BP 🔍 SEO Report
/github-code-search/getting-started/ 🟢 99 (≥97) 🟢 100 (≥99) 🟢 100 (≥99) 🟢 100 (≥99) 🔗 view
/github-code-search/ 🟢 98 (≥97) 🟢 100 (≥99) 🟢 100 (≥99) 🟢 100 (≥99) 🔗 view

Thresholds: Perf ≥ 97 · A11y ≥ 99 · BP ≥ 99 · SEO ≥ 99
commit e650509 · full workflow run

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds more self-describing non-interactive outputs by introducing a query title heading and surfacing the matched token per result line (Markdown) / per match entry (JSON), aligning with issue #126.

Changes:

  • Add buildQueryTitle() and prepend # Results for ... to Markdown output (both repo-and-matches and repo-only).
  • Append matched token to each Markdown match line and include matchedText in JSON match objects when segment data exists.
  • Update tests and documentation examples to reflect the new output.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/output.ts Adds buildQueryTitle(); updates Markdown/JSON builders to include query title + matched token.
src/output.test.ts Adds unit tests for buildQueryTitle() and updates/extends output expectations.
docs/usage/output-formats.md Updates output examples and adds a “Query title” section.
docs/usage/non-interactive-mode.md Updates example output to include the new heading and matched token.
README.md Updates feature description for structured output and adds “Regex search” to the feature list/table.

…ge-case tests

- Add mdInlineCode() helper using variable-length backtick fence (CommonMark
  §6.1) so regex patterns containing backticks produce valid inline code spans.
  Reuse for seg.text in match lines.
- buildQueryTitle: use mdInlineCode() for regex queries (fixes embedded
  backticks) and JSON.stringify() for plain queries (escapes embedded " and
  converts \n so the heading always stays on a single line).
- Fix JSDoc example: '# Results for \`useFlag/i\`' → '# Results for \`/useFlag/i\`'.
- buildJsonOutput: guard matchedText behind seg.text non-empty check, matching
  markdown behaviour and preventing '"matchedText": ""' in JSON output.
- Add edge-case tests: plain query with embedded quotes, plain query with
  newline, regex with embedded backtick, empty seg.text omitted from JSON.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Coverage after merging feat/output-query-title-matched-token into main will be

95.87%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.57%100%100%93.89%319–323, 384, 401, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.26%100%100%99.21%251
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Comment on lines 248 to 252
// Use VS Code-ready path:line:col as link text and anchor the URL to the
// line when location info is available (GitHub #Lline deeplink).
// Position is fragment-relative (GitHub Code Search API does not return
// absolute line numbers).
const seg = m.textMatches[0]?.matches[0];
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline comment says the segment position is fragment-relative, but api.ts now attempts to resolve absolute file line numbers by fetching raw content (falling back to fragment-relative when that fails). Updating this comment to reflect the current behavior would prevent confusion when interpreting seg.line/seg.col.

Copilot uses AI. Check for mistakes.
- output.ts: update inline comment — seg.line/seg.col are now absolute
  file line numbers resolved by api.ts (not fragment-relative)
- output-formats.md: replace nested-backtick prose with fenced code block
  example to avoid malformed Markdown rendering
- output-formats.md: reword Query title section to distinguish format
  (Markdown/JSON) from output-type (repo-only/repo-and-matches)
- output-formats.md: remove #L2 anchor from JSON example url field —
  buildJsonOutput() emits m.htmlUrl without anchoring to line
- README.md: qualify matchedText/line/col as 'when segment data is
  available' to avoid overstating the JSON schema guarantee
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Coverage after merging feat/output-query-title-matched-token into main will be

95.87%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.57%100%100%93.89%319–323, 384, 401, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.26%100%100%99.21%251
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

@shouze shouze merged commit 300cd5e into main Apr 1, 2026
9 checks passed
@shouze shouze deleted the feat/output-query-title-matched-token branch April 1, 2026 05:34
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.

Show matched token and query title in output

2 participants