Skip to content

Commit 4ebcb5a

Browse files
committed
fix(memory): fall back to qmd get when filesystem path is slugified
1 parent 3700279 commit 4ebcb5a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/memory/qmd-manager.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,13 @@ export class QmdMemoryManager implements MemorySearchManager {
893893
}
894894
const statResult = await statRegularFile(absPath);
895895
if (statResult.missing) {
896+
// Fall back to `qmd get` which can resolve slugified paths.
897+
if (relPath.startsWith("qmd/")) {
898+
const qmdText = await this.getQmdDoc(relPath);
899+
if (qmdText !== null) {
900+
return { text: qmdText, path: relPath };
901+
}
902+
}
896903
return { text: "", path: relPath };
897904
}
898905
if (params.from !== undefined || params.lines !== undefined) {
@@ -1794,6 +1801,23 @@ export class QmdMemoryManager implements MemorySearchManager {
17941801
return !path.isAbsolute(relativePath);
17951802
}
17961803

1804+
private async getQmdDoc(relPath: string): Promise<string | null> {
1805+
const [, collection, ...rest] = relPath.split("/");
1806+
if (!collection || rest.length === 0) {
1807+
return null;
1808+
}
1809+
const uri = `qmd://${collection}/${rest.join("/")}`;
1810+
try {
1811+
const result = await this.runQmd(["get", uri], {
1812+
timeoutMs: this.qmd.limits.timeoutMs,
1813+
});
1814+
const text = result.stdout?.trim();
1815+
return text || null;
1816+
} catch {
1817+
return null;
1818+
}
1819+
}
1820+
17971821
private resolveReadPath(relPath: string): string {
17981822
if (relPath.startsWith("qmd/")) {
17991823
const [, collection, ...rest] = relPath.split("/");

0 commit comments

Comments
 (0)