Fix docid lookup in qmd get command (#36)

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 <jlelonmitchell@gmail.com >
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Joshua Lelon Mitchell 2026-01-20 08:28:34 -06:00 committed by GitHub
parent 5b1671d2f6
commit fbd7fe8c8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;