fix(search): gitea_code_search returns only filenames, repeated, without line numbers or snippets #27

Closed
opened 2026-10-24 00:59:01 +00:00 by dsh · 1 comment
Owner

Symptom

gitea_code_search returns only file paths, repeated once per match, with no line numbers and no match text. The handler already produces {path, line, text} rows, but the formatter drops line/text, so the tool cannot be used to find code.

Repro

gitea_code_search {q:"formatToolResult", limit:5}
→ CHANGELOG.md
  CHANGELOG.md
  CHANGELOG.md
  CHANGELOG.md
  CHANGELOG.md
  lib/handlers.js
  lib/handlers.js
  lib/handlers/formatters.js
  ... (20 path lines)

A no-match search renders No results. correctly.

Observed vs expected

  • Observed: filename-only lines; duplicates; no way to see the matched code; limit behaves per file (git grep --max-count) rather than globally.
  • Expected: one line per match, e.g. lib/handlers/formatters.js:71: export function formatToolResult(...), capped globally by limit with a visible footer.

Root cause

lib/handlers/repos.js maps matches to { path, line, text }. lib/handlers/formatters.js generic array branch:

if (item?.path != null) return `${item.branch || ''} ${item.path}`.trim()

drops line and text. The handler passes --max-count=${limit} to git grep, which limits matches per file, not in total.

Proposed fix

Add a gitea_code_search formatter emitting path:line: text (single-line clipped text), apply a global row cap + footer, and make the handler stop after limit total matches (or document limit as per-file). Add formatter tests for the three row shapes (path/line/text, raw, empty).

Acceptance: matches show file, line and snippet; total rows never exceed the requested limit; duplicates only for genuinely repeated matches at different lines.

Duplicate check

Searched search (state all) — no code-search issue; the brief notes gitea_code_search runs local git grep by design, which is not the problem.

Layer

dsh-gitea plugin/tool (handler + formatter).

## Symptom `gitea_code_search` returns only file paths, repeated once per match, with no line numbers and no match text. The handler already produces `{path, line, text}` rows, but the formatter drops `line`/`text`, so the tool cannot be used to find code. ## Repro ``` gitea_code_search {q:"formatToolResult", limit:5} → CHANGELOG.md CHANGELOG.md CHANGELOG.md CHANGELOG.md CHANGELOG.md lib/handlers.js lib/handlers.js lib/handlers/formatters.js ... (20 path lines) ``` A no-match search renders `No results.` correctly. ## Observed vs expected - Observed: filename-only lines; duplicates; no way to see the matched code; `limit` behaves per file (`git grep --max-count`) rather than globally. - Expected: one line per match, e.g. `lib/handlers/formatters.js:71: export function formatToolResult(...)`, capped globally by `limit` with a visible footer. ## Root cause `lib/handlers/repos.js` maps matches to `{ path, line, text }`. `lib/handlers/formatters.js` generic array branch: ```js if (item?.path != null) return `${item.branch || ''} ${item.path}`.trim() ``` drops `line` and `text`. The handler passes `--max-count=${limit}` to git grep, which limits matches per file, not in total. ## Proposed fix Add a `gitea_code_search` formatter emitting `path:line: text` (single-line clipped text), apply a global row cap + footer, and make the handler stop after `limit` total matches (or document `limit` as per-file). Add formatter tests for the three row shapes (`path/line/text`, `raw`, empty). Acceptance: matches show file, line and snippet; total rows never exceed the requested limit; duplicates only for genuinely repeated matches at different lines. ## Duplicate check Searched `search` (state all) — no code-search issue; the brief notes `gitea_code_search` runs local `git grep` by design, which is not the problem. ## Layer dsh-gitea plugin/tool (handler + formatter).
Author
Owner

Fixed in 56f41de (PR #41).

gitea_code_search now emits path:line: snippet per match. The handler caps matches globally (it previously passed --max-count to git grep, which is per file) and returns {items,total_count,truncated,limit}; the formatter adds … showing N of M matches.

Live: q:"formatToolResult", limit:5 → five path:line: rows + … showing 5 of 26 matches.

Tests: test/qa-formatters.test.mjs.

Fixed in `56f41de` (PR #41). `gitea_code_search` now emits `path:line: snippet` per match. The handler caps matches **globally** (it previously passed `--max-count` to `git grep`, which is per file) and returns `{items,total_count,truncated,limit}`; the formatter adds `… showing N of M matches`. Live: `q:"formatToolResult", limit:5` → five `path:line:` rows + `… showing 5 of 26 matches`. Tests: `test/qa-formatters.test.mjs`.
dsh closed this issue 2026-10-24 01:25:25 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
dsh-plugins/dsh-gitea#27
No description provided.