From fbd7fe8c8e7cc0dc0a7d2181f5e54b01ebab5270 Mon Sep 17 00:00:00 2001 From: Joshua Lelon Mitchell Date: Tue, 20 Jan 2026 08:28:34 -0600 Subject: [PATCH] Fix docid lookup in qmd get command (#36) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `qmd get` command was documented to support docid lookups (e.g., `qmd get "#abc123"` or `qmd get abc123`), but the implementation in getDocument() never actually handled docids. The findDocumentByDocid() function existed in store.ts and worked correctly, but getDocument() in qmd.ts reimplemented document lookup without calling it. This adds docid detection at the start of getDocument() to resolve docids to virtual paths before other path handling. Co-authored-by: Joshua Mitchell Co-authored-by: Claude Opus 4.5 --- src/qmd.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/qmd.ts b/src/qmd.ts index 35f9502..9845c1a 100755 --- a/src/qmd.ts +++ b/src/qmd.ts @@ -18,6 +18,7 @@ import { removeCollection, renameCollection, findSimilarFiles, + findDocumentByDocid, matchFilesByGlob, getHashesNeedingEmbedding, getHashesForEmbedding, @@ -697,6 +698,18 @@ function getDocument(filename: string, fromLine?: number, maxLines?: number, lin } } + // Handle docid lookup (#hash or 6-char hex) + if (inputPath.startsWith('#') || /^[a-f0-9]{6}$/i.test(inputPath)) { + const docidMatch = findDocumentByDocid(db, inputPath); + if (docidMatch) { + inputPath = docidMatch.filepath; + } else { + console.error(`Document not found: ${filename}`); + closeDb(); + process.exit(1); + } + } + let doc: { collectionName: string; path: string; body: string } | null = null; let virtualPath: string;