fix(memory-core): narrow qmd and artifact dir typing

This commit is contained in:
Vincent Koc
2026-04-06 23:09:35 +01:00
parent d88eb0e031
commit 32eff914c6
2 changed files with 23 additions and 20 deletions

View File

@@ -1760,41 +1760,41 @@ export class QmdMemoryManager implements MemorySearchManager {
}
const parsedUnknown: unknown = JSON.parse(result.stdout);
const parsedRecord = asRecord(parsedUnknown);
const structuredContent = parsedRecord ? asRecord(parsedRecord.structuredContent) : null;
const structured: unknown = structuredContent ?? parsedUnknown;
const structured =
asRecord(parsedUnknown) && asRecord(parsedUnknown.structuredContent)
? parsedUnknown.structuredContent
: parsedUnknown;
const structuredRecord = asRecord(structured);
const results: unknown[] =
asRecord(structured) && Array.isArray(structured.results)
? (structured.results as unknown[])
structuredRecord && Array.isArray(structuredRecord.results)
? (structuredRecord.results as unknown[])
: Array.isArray(structured)
? structured
: [];
const out: QmdQueryResult[] = [];
for (const item of results) {
if (!asRecord(item)) {
const itemRecord = asRecord(item);
if (!itemRecord) {
continue;
}
const docidRaw = item.docid;
const docidRaw = itemRecord.docid;
const docid = typeof docidRaw === "string" ? docidRaw.replace(/^#/, "").trim() : "";
if (!docid) {
continue;
}
const scoreRaw = item.score;
const scoreRaw = itemRecord.score;
const score = typeof scoreRaw === "number" ? scoreRaw : Number(scoreRaw);
const snippet = typeof item.snippet === "string" ? item.snippet : "";
const snippet = typeof itemRecord.snippet === "string" ? itemRecord.snippet : "";
out.push({
docid,
score: Number.isFinite(score) ? score : 0,
snippet,
collection: typeof item.collection === "string" ? item.collection : undefined,
file: typeof item.file === "string" ? item.file : undefined,
body: typeof item.body === "string" ? item.body : undefined,
startLine: this.normalizeSnippetLine(item.start_line ?? item.startLine),
endLine: this.normalizeSnippetLine(item.end_line ?? item.endLine),
collection: typeof itemRecord.collection === "string" ? itemRecord.collection : undefined,
file: typeof itemRecord.file === "string" ? itemRecord.file : undefined,
body: typeof itemRecord.body === "string" ? itemRecord.body : undefined,
startLine: this.normalizeSnippetLine(itemRecord.start_line ?? itemRecord.startLine),
endLine: this.normalizeSnippetLine(itemRecord.end_line ?? itemRecord.endLine),
});
}
return out;

View File

@@ -532,10 +532,13 @@ async function ensureShortTermArtifactsDir(workspaceDir: string): Promise<void>
await existing;
return;
}
const ensuring = fs.mkdir(artifactsDir, { recursive: true }).catch((err) => {
ensuredShortTermDirs.delete(artifactsDir);
throw err;
});
const ensuring = fs
.mkdir(artifactsDir, { recursive: true })
.then(() => undefined)
.catch((err) => {
ensuredShortTermDirs.delete(artifactsDir);
throw err;
});
ensuredShortTermDirs.set(artifactsDir, ensuring);
await ensuring;
}