Skip to content

fix: include line in CLI --json search output#533

Merged
tobi merged 1 commit into
tobi:mainfrom
rymalia:fix/json-line-field
Apr 9, 2026
Merged

fix: include line in CLI --json search output#533
tobi merged 1 commit into
tobi:mainfrom
rymalia:fix/json-line-field

Conversation

@rymalia

@rymalia rymalia commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • --json search output now includes a line field (1-indexed) pointing to the best-matching line in the document, enabling editor integrations like code --goto file:line

Problem

#505 requested a line field in --json output for editor integrations. #506 was merged to fix it, but the fix landed in searchResultsToJson() in formatter.ts — a function with no callers. The CLI's actual JSON output is generated by outputResults() in qmd.ts, which has its own inline formatting. That inline path destructured only .snippet from extractSnippet(), discarding the .line property.

Fix

Extract the full SnippetResult from extractSnippet() and spread line into the JSON output object — matching what the CLI display path already does for terminal output.

Before:

{"file": "qmd://blog/post.md", "snippet": "@@ -42,4 @@ ..."}

After:

{"file": "qmd://blog/post.md", "line": 42, "snippet": "@@ -42,4 @@ ..."}

Test plan

  • qmd search "term" --json includes line field in each result
  • qmd query "term" --json includes line field in each result
  • qmd search "term" --json --full omits line (no snippet extraction when showing full body)
  • Existing CLI tests pass (npx vitest run test/cli.test.ts — 91/91)

Closes #505

🤖 Generated with Claude Code

but that function has no callers — the CLI's outputResults() uses its
own inline JSON formatting that destructured only .snippet from
extractSnippet(), discarding .line. Extract the full SnippetResult
and spread the line field into the JSON output object.

Closes tobi#505
@rymalia

rymalia commented Apr 7, 2026

Copy link
Copy Markdown
Contributor Author

CI note: The Bun (ubuntu-latest) failure in createStore throws without explicit path in test mode is a pre-existing test isolation issue — the test doesn't call _resetProductionModeForTesting() before asserting, so leaked module state from prior Bun test files can suppress the throw. Unrelated to this PR's 3-line change in outputResults() JSON formatting.

Re-running the job will likely pass — the failure depends on Bun's test file execution order.

@tobi tobi merged commit 414fee5 into tobi:main Apr 9, 2026
7 of 8 checks passed
tanarchytan referenced this pull request in tanarchytan/lotl Apr 14, 2026
Audited tobi/qmd's 458 commits since our fork divergence, filtered to
post-cleanup-compatible fixes (skipped node-llama-cpp / Qwen3 / GGUF
specific ones since we removed those layers in the 2026-04-13 cleanup).

Already had (verified during audit, no action):
- 09a4d19 fix(store): error on embedding dimension mismatch (#501)
- ef062e1 fix(multi-get): brace expansion glob (#424)
- 0212363 fix(mcp): read version from package.json (#431)

Cherry-picked tonight:
- 77e71d0 fix: USERPROFILE fallback for Windows HOME (max0n232)
  src/store/path.ts: HOME = HOME || USERPROFILE || /tmp. Critical for
  MCP subprocess case on Windows where Claude Code passes USERPROFILE
  but not HOME, causing QMD to open an empty /tmp DB.

- 9dd8a73 fix(mcp): enableProductionMode before getDefaultDbPath (jungholee)
  src/mcp/server.ts: imports + calls enableProductionMode at module
  init. CLI users already get this via cli/qmd.ts:110, but SDK
  consumers importing the MCP server directly hit the production-mode
  guard on getDefaultDbPath. This is the same race upstream fixed.

- 0adbdeb fix(store): surface actionable sqlite-vec guidance (Tobi)
  src/store/db-init.ts: track _sqliteVecUnavailableReason at init
  time so ensureVecTableInternal can throw with the original cause
  instead of a generic "extension not available" message. Reuses our
  existing createSqliteVecUnavailableError helper.

- 17074ea fix: include line in CLI --json output (rymalia, #533)
  src/cli/qmd.ts: outputResults JSON branch now emits snippetInfo.line
  alongside the snippet so JSON consumers can navigate to the right
  source line.

Skipped (post-cleanup incompatible):
- f53ee26 fix: detect non-GGUF model files - we removed node-llama-cpp
- 6db34d7 fix(llm): catch GPU init failures - llama.cpp specific
- 8644fa9 fix(store): thread embed model URI to format functions -
  uses Qwen3 detection (formatQueryForEmbedding Qwen3 branch) which
  we ripped out tonight. The format function exists, but the Qwen3
  conditional doesn't.
- 54550a3 fix(llm): explicit embed context size - llama.cpp specific
- 1ecb5c9 Fix QMD_LLAMA_GPU backend override - QMD_LLAMA_* env vars
  removed in cleanup
- 26e3d0c fix(status): avoid build attempts during device probe -
  device probe was LlamaCpp-specific, removed in cleanup
- handelize chain (9fb9de4 -> 9c9de94 -> 828823d -> fee576b) - upstream
  briefly removed .toLowerCase(), broke things, reverted, added a
  migration for users hit by the broken window. We never participated
  in that experiment so the chain is a no-op for us.

Deferred (real feature, too invasive for tonight):
- 8404cc3 fix(uri): include index in custom qmd links - adds index
  segment to qmd:// URI parsing so CLI commands can switch indexes
  inline. Requires schema change to VirtualPath type (currently
  {collectionName, path}, would need optional indexName field) plus
  call sites in get/multi-get. Worth porting in a separate session.

Also need to verify (separate work):
- 3023ab3 fix: bump transitive deps for security alerts - need to
  cross-reference against our package-lock.json since our dep set
  diverged after the node-llama-cpp removal.

Tests: pick-vector-matches + memory-eviction + mcp suite all green
(66 pass / 3 skipped). Full suite deferred until phase 5 completes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
rymalia added a commit to rymalia/qmd that referenced this pull request May 27, 2026
CLAUDE.local.md version bump v2.0.1 → v2.1.0. Two session summaries:
upstream rebase sync (45 commits integrated via rebase) and v2.1.0
testing session (PR tobi#533 submitted, bugs found in JSON line field
and multi-collection search, comments on tobi#383, tobi#463, tobi#217, tobi#241).
rymalia added a commit to rymalia/qmd that referenced this pull request May 27, 2026
CLAUDE.local.md version bump v2.0.1 → v2.1.0. Two session summaries:
upstream rebase sync (45 commits integrated via rebase) and v2.1.0
testing session (PR tobi#533 submitted, bugs found in JSON line field
and multi-collection search, comments on tobi#383, tobi#463, tobi#217, tobi#241).
@rymalia rymalia deleted the fix/json-line-field branch May 27, 2026 04:07
lucndm pushed a commit to lucndm/qmd that referenced this pull request Jun 7, 2026
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.

Include line in --json search output

2 participants