mirror of
https://github.com/sdwolf4103/opencode-working-memory.git
synced 2026-07-17 12:56:42 +02:00
1bba0511bb
## Task 1: Fix exitCode undefined false positive - Add `typeof exitCode !== "number"` check in plugin.ts - Only extract errors when exitCode is explicitly non-zero - Prevent git-log/cat with "errors" text from creating false positives ## Task 2: Fix workspace memory XML truncation - Budget-aware line-by-line rendering - Always include closing </workspace_memory> tag - Return empty string when budget too small - Bonus: canonical exact deduplication with source priority ## Task 3: Remove "always" as trigger - Replace "always" with "going forward" in patterns - Add word boundary via `g` flag and matchAll loop - "from now on" still works as expected ## Task 4: Verification - 22 tests passing - typecheck passing Tests cover: - git log/cat with loose "errors" ignored - TS2345/TypeError strong signals captured - undefined exitCode: no create, no clear - exitCode 0: clears errors - exitCode non-zero: creates error - XML never truncated mid-tag - "always" not a trigger
27 lines
1021 B
TypeScript
27 lines
1021 B
TypeScript
import { createHash } from "crypto";
|
|
import { homedir } from "os";
|
|
import { join } from "path";
|
|
import { realpath } from "fs/promises";
|
|
|
|
export function dataHome(): string {
|
|
return process.env.XDG_DATA_HOME ?? join(homedir(), ".local", "share");
|
|
}
|
|
|
|
export async function workspaceKey(root: string): Promise<string> {
|
|
const resolved = await realpath(root).catch(() => root);
|
|
return createHash("sha256").update(resolved).digest("hex").slice(0, 16);
|
|
}
|
|
|
|
export async function memoryRoot(root: string): Promise<string> {
|
|
return join(dataHome(), "opencode-working-memory", "workspaces", await workspaceKey(root));
|
|
}
|
|
|
|
export async function workspaceMemoryPath(root: string): Promise<string> {
|
|
return join(await memoryRoot(root), "workspace-memory.json");
|
|
}
|
|
|
|
export async function sessionStatePath(root: string, sessionID: string): Promise<string> {
|
|
const safeSessionID = createHash("sha256").update(sessionID).digest("hex").slice(0, 32);
|
|
return join(await memoryRoot(root), "sessions", `${safeSessionID}.json`);
|
|
}
|