浏览代码

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>
Joshua Lelon Mitchell 4 月之前
父节点
当前提交
fbd7fe8c8e
共有 1 个文件被更改,包括 13 次插入0 次删除
  1. 13 0
      src/qmd.ts

+ 13 - 0
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;