Skip to content

Show matched token and query title in output #126

Description

@shouze

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

  • buildMarkdownOutput prepends # Results for ... with correct qualifiers
  • Each match line in markdown ends with : `{matchedText}` when location is available
  • JSON matches[] includes "matchedText" when location is available
  • repo-only mode also gets the H1 heading
  • bun test passes with new and updated tests
  • bun run lint, bun run format:check, bun run knip pass

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions