opencode-workflow-guard 1.8.1 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/lib/audit.ts +64 -20
- package/src/lib/guard-dispatcher.ts +2 -1
- package/src/lib/project-memory.ts +22 -4
- package/src/lib/sqlite.ts +20 -0
- package/src/lib/tool-outcomes.ts +22 -0
- package/src/lib/types.ts +1 -1
- package/src/policies/changelog.ts +15 -0
- package/src/policies/continuation.ts +1 -0
- package/src/workflow-guard.ts +18 -12
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ For the optional TUI badge, configure `"opencode-workflow-guard"` in `tui.json`.
|
|
|
33
33
|
npm run typecheck # Strict TypeScript check (0 errors)
|
|
34
34
|
npm test # Run 415+ unit and adversarial tests
|
|
35
35
|
npm run test:all # Typecheck + unit + install/load checks
|
|
36
|
-
WORKFLOW_GUARD_LIVE_E2E=1 npm run test:install # Also run
|
|
36
|
+
WORKFLOW_GUARD_LIVE_E2E=1 npm run test:install # Also run policy probes with OpenCode's most recently selected model
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
---
|
package/package.json
CHANGED
package/src/lib/audit.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { appendFileSync, chmodSync, existsSync, mkdirSync, openSync, readSync, closeSync, renameSync, statSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
+
import { Database, type SqliteDatabase } from "./sqlite.ts";
|
|
5
6
|
import type { AuditEntry, VerifyResult } from "./types.ts";
|
|
6
7
|
import { asRecord } from "./utils.ts";
|
|
7
8
|
|
|
@@ -17,6 +18,37 @@ const MAX_AUDIT_BYTES = 4 * 1024 * 1024;
|
|
|
17
18
|
const RETAIN_AUDIT_BYTES = 2 * 1024 * 1024;
|
|
18
19
|
const MAX_VERIFY_HISTORY_BYTES = 1024 * 1024;
|
|
19
20
|
const RETAIN_VERIFY_HISTORY_BYTES = 512 * 1024;
|
|
21
|
+
let verifiedHistoryState: { size: number; mtimeMs: number; ctimeMs: number; ino: number | bigint } | undefined;
|
|
22
|
+
const lockDatabases = new Map<string, SqliteDatabase>();
|
|
23
|
+
|
|
24
|
+
function getVerifyHistoryState(): typeof verifiedHistoryState {
|
|
25
|
+
const stat = statSync(VERIFY_HISTORY_FILE);
|
|
26
|
+
return { size: stat.size, mtimeMs: stat.mtimeMs, ctimeMs: stat.ctimeMs, ino: stat.ino };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function sameVerifyHistoryState(a: typeof verifiedHistoryState, b: typeof verifiedHistoryState): boolean {
|
|
30
|
+
return a?.size === b?.size && a?.mtimeMs === b?.mtimeMs && a?.ctimeMs === b?.ctimeMs && a?.ino === b?.ino;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function withFileLock<T>(path: string, action: () => T): T {
|
|
34
|
+
let db = lockDatabases.get(path);
|
|
35
|
+
if (!db) {
|
|
36
|
+
const lockPath = `${path}.lock.sqlite`;
|
|
37
|
+
db = new Database(lockPath);
|
|
38
|
+
db.exec("PRAGMA busy_timeout = 5000");
|
|
39
|
+
chmodSync(lockPath, 0o600);
|
|
40
|
+
lockDatabases.set(path, db);
|
|
41
|
+
}
|
|
42
|
+
db.exec("BEGIN IMMEDIATE");
|
|
43
|
+
try {
|
|
44
|
+
const result = action();
|
|
45
|
+
db.exec("COMMIT");
|
|
46
|
+
return result;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
try { db.exec("ROLLBACK"); } catch {}
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
20
52
|
|
|
21
53
|
export function getAuditFilePath(): string {
|
|
22
54
|
return AUDIT_FILE;
|
|
@@ -30,7 +62,7 @@ export function getVerifyHistoryFilePath(): string {
|
|
|
30
62
|
return VERIFY_HISTORY_FILE;
|
|
31
63
|
}
|
|
32
64
|
|
|
33
|
-
function
|
|
65
|
+
function appendBoundedJsonlUnlocked(path: string, value: unknown, maxBytes: number, retainBytes: number): void {
|
|
34
66
|
appendFileSync(path, JSON.stringify(value) + "\n", { encoding: "utf8", mode: 0o600 });
|
|
35
67
|
chmodSync(path, 0o600);
|
|
36
68
|
const stat = statSync(path);
|
|
@@ -46,31 +78,43 @@ function appendBoundedJsonl(path: string, value: unknown, maxBytes: number, reta
|
|
|
46
78
|
const text = buffer.toString("utf8");
|
|
47
79
|
const firstNewline = text.indexOf("\n");
|
|
48
80
|
const retained = firstNewline >= 0 ? text.slice(firstNewline + 1) : "";
|
|
49
|
-
const temp = `${path}.${process.pid}.tmp`;
|
|
81
|
+
const temp = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
50
82
|
writeFileSync(temp, retained, { encoding: "utf8", mode: 0o600 });
|
|
51
83
|
renameSync(temp, path);
|
|
52
84
|
}
|
|
53
85
|
|
|
86
|
+
function appendBoundedJsonl(path: string, value: unknown, maxBytes: number, retainBytes: number): void {
|
|
87
|
+
withFileLock(path, () => appendBoundedJsonlUnlocked(path, value, maxBytes, retainBytes));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function verifyHistoryNeedsSanitation(): boolean {
|
|
91
|
+
if (!existsSync(VERIFY_HISTORY_FILE)) return false;
|
|
92
|
+
const state = getVerifyHistoryState();
|
|
93
|
+
if (sameVerifyHistoryState(verifiedHistoryState, state)) return false;
|
|
94
|
+
return readFileSync(VERIFY_HISTORY_FILE, "utf8").split("\n").some((line) => {
|
|
95
|
+
if (!line.trim()) return false;
|
|
96
|
+
try {
|
|
97
|
+
const value = JSON.parse(line) as { command?: unknown; output?: unknown };
|
|
98
|
+
return typeof value.command !== "string" || !/^sha256:[0-9a-f]{64}$/.test(value.command) || typeof value.output !== "string" || !/^sha256:[0-9a-f]{64}$/.test(value.output);
|
|
99
|
+
} catch {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
54
105
|
export function persistVerifyHistory(verifyData: NonNullable<VerifyResult>): void {
|
|
55
106
|
try {
|
|
56
107
|
mkdirSync(AUDIT_DIR, { recursive: true });
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (legacy) writeFileSync(VERIFY_HISTORY_FILE, "", { encoding: "utf8", mode: 0o600 });
|
|
68
|
-
}
|
|
69
|
-
appendBoundedJsonl(VERIFY_HISTORY_FILE, {
|
|
70
|
-
...verifyData,
|
|
71
|
-
command: `sha256:${createHash("sha256").update(verifyData.command).digest("hex")}`,
|
|
72
|
-
output: `sha256:${createHash("sha256").update(verifyData.output).digest("hex")}`,
|
|
73
|
-
}, MAX_VERIFY_HISTORY_BYTES, RETAIN_VERIFY_HISTORY_BYTES);
|
|
108
|
+
withFileLock(VERIFY_HISTORY_FILE, () => {
|
|
109
|
+
if (verifyHistoryNeedsSanitation()) writeFileSync(VERIFY_HISTORY_FILE, "", { encoding: "utf8", mode: 0o600 });
|
|
110
|
+
appendBoundedJsonlUnlocked(VERIFY_HISTORY_FILE, {
|
|
111
|
+
...verifyData,
|
|
112
|
+
command: `sha256:${createHash("sha256").update(verifyData.command).digest("hex")}`,
|
|
113
|
+
output: `sha256:${createHash("sha256").update(verifyData.output).digest("hex")}`,
|
|
114
|
+
}, MAX_VERIFY_HISTORY_BYTES, RETAIN_VERIFY_HISTORY_BYTES);
|
|
115
|
+
const state = getVerifyHistoryState();
|
|
116
|
+
verifiedHistoryState = verifyHistoryNeedsSanitation() ? undefined : state;
|
|
117
|
+
});
|
|
74
118
|
} catch {}
|
|
75
119
|
}
|
|
76
120
|
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
snipVerifyOutput,
|
|
35
35
|
} from "./verify.ts";
|
|
36
36
|
import { detectShellMutation, extractPatchPaths, guardShellMutation, isPathOutsideWorkspace } from "../policies/boundary.ts";
|
|
37
|
-
import { branchHasChangelogChange, checkLockfileSync, hasPrCreateInvocation, prBodyIncludesChangelog } from "../policies/changelog.ts";
|
|
37
|
+
import { branchHasChangelogChange, checkLockfileSync, hasPrCreateInvocation, prBodyHasLiteralLineBreakEscapes, prBodyIncludesChangelog } from "../policies/changelog.ts";
|
|
38
38
|
import { extractEditContent, liveMutationIn } from "../policies/destructive.ts";
|
|
39
39
|
import { branchHasDocumentationChange } from "../policies/docs.ts";
|
|
40
40
|
import { claimFiles } from "../policies/file-claims.ts";
|
|
@@ -413,6 +413,7 @@ export async function guardToolCallImpl(
|
|
|
413
413
|
const prTool = isAz ? "az repos pr create" : "gh pr create";
|
|
414
414
|
const descFlag = isAz ? "--description" : "--body";
|
|
415
415
|
const preflightFailures: string[] = [];
|
|
416
|
+
if (prBodyHasLiteralLineBreakEscapes(raw)) preflightFailures.push(`PR description contains literal \\n/\\r escapes that will render as text; use real newlines, ANSI-C quoting ($'...\\n...'), or a body/description file instead.`);
|
|
416
417
|
const conflictCheck = checkMergeConflicts(prRoot);
|
|
417
418
|
if (conflictCheck.hasConflicts) preflightFailures.push(conflictCheck.reason ?? "Branch has merge conflicts with its base branch.");
|
|
418
419
|
const branch = currentGitBranch(prRoot);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { appendFileSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
4
|
-
import { spawnSync } from "node:child_process";
|
|
5
|
-
import {
|
|
4
|
+
import { execFile, spawnSync } from "node:child_process";
|
|
5
|
+
import { Database, type SqliteDatabase } from "./sqlite.ts";
|
|
6
6
|
import type { ProjectMemoryInput, ProjectMemoryKind, ProjectMemoryRecord, ProjectMemorySource, ReviewFollowup, ReviewFollowupInput } from "./types.ts";
|
|
7
7
|
|
|
8
8
|
const KINDS = new Set<ProjectMemoryKind>(["fact", "decision", "constraint", "lesson"]);
|
|
9
9
|
const SOURCES = new Set<ProjectMemorySource>(["user", "file", "git", "tool", "agent", "portable"]);
|
|
10
10
|
|
|
11
11
|
export interface ProjectMemoryStore {
|
|
12
|
-
db:
|
|
12
|
+
db: SqliteDatabase;
|
|
13
13
|
projectId: string;
|
|
14
14
|
close(): void;
|
|
15
15
|
}
|
|
@@ -45,10 +45,28 @@ export function isProjectMemoryFresh(memory: ProjectMemoryRecord, root: string):
|
|
|
45
45
|
return untracked.status === 0 && !untracked.stdout.trim();
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
function execGit(root: string, args: string[]): Promise<{ status: number; stdout: string }> {
|
|
49
|
+
return new Promise((resolve) => {
|
|
50
|
+
execFile("git", ["-C", root, ...args], { encoding: "utf8", timeout: 2_000 }, (error, stdout) => {
|
|
51
|
+
resolve({ status: error ? (typeof error.code === "number" ? error.code : -1) : 0, stdout });
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function isProjectMemoryFreshAsync(memory: ProjectMemoryRecord, root: string): Promise<boolean> {
|
|
57
|
+
if (!memory.commit || memory.paths.length === 0) return true;
|
|
58
|
+
if (!/^[0-9a-f]{7,64}$/i.test(memory.commit)) return false;
|
|
59
|
+
const [diff, untracked] = await Promise.all([
|
|
60
|
+
execGit(root, ["diff", "--quiet", memory.commit, "--", ...memory.paths]),
|
|
61
|
+
execGit(root, ["ls-files", "--others", "--exclude-standard", "--", ...memory.paths]),
|
|
62
|
+
]);
|
|
63
|
+
return diff.status === 0 && untracked.status === 0 && !untracked.stdout.trim();
|
|
64
|
+
}
|
|
65
|
+
|
|
48
66
|
export function openProjectMemory(projectId: string, directory = getProjectMemoryDir()): ProjectMemoryStore {
|
|
49
67
|
if (!projectId || projectId.length > 200) throw new Error("Invalid project memory identity.");
|
|
50
68
|
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
51
|
-
const db = new
|
|
69
|
+
const db = new Database(join(directory, `${projectId.replace(/[^a-zA-Z0-9._-]/g, "_")}.sqlite`));
|
|
52
70
|
db.exec(`
|
|
53
71
|
PRAGMA journal_mode = WAL;
|
|
54
72
|
PRAGMA busy_timeout = 2000;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type RunResult = { changes: number | bigint };
|
|
2
|
+
type Statement = {
|
|
3
|
+
run(...params: unknown[]): RunResult;
|
|
4
|
+
all(...params: unknown[]): unknown[];
|
|
5
|
+
get(...params: unknown[]): unknown;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export interface SqliteDatabase {
|
|
9
|
+
exec(sql: string): unknown;
|
|
10
|
+
prepare(sql: string): Statement;
|
|
11
|
+
close(): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type DatabaseConstructor = new (path: string) => SqliteDatabase;
|
|
15
|
+
const sqliteModuleName = "Bun" in globalThis ? "bun:sqlite" : "node:sqlite";
|
|
16
|
+
const sqliteModule = await import(sqliteModuleName) as { Database?: DatabaseConstructor; DatabaseSync?: DatabaseConstructor };
|
|
17
|
+
|
|
18
|
+
const DatabaseImpl = sqliteModule.Database ?? sqliteModule.DatabaseSync;
|
|
19
|
+
if (!DatabaseImpl) throw new Error(`SQLite database implementation unavailable from ${sqliteModuleName}`);
|
|
20
|
+
export const Database: DatabaseConstructor = DatabaseImpl;
|
package/src/lib/tool-outcomes.ts
CHANGED
|
@@ -21,8 +21,11 @@ export interface ToolOutcome {
|
|
|
21
21
|
repeatedFailureCount?: number;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
const MAX_TRACKED_CALLS = 4096;
|
|
25
|
+
|
|
24
26
|
export class ToolOutcomeTracker {
|
|
25
27
|
private readonly terminalCalls = new Map<string, Set<string>>();
|
|
28
|
+
private readonly fallbackCalls = new Map<string, Set<string>>();
|
|
26
29
|
private readonly failures = new Map<string, { signature: string; count: number }>();
|
|
27
30
|
|
|
28
31
|
record(part: ToolOutcomePart): ToolOutcome | undefined {
|
|
@@ -35,7 +38,13 @@ export class ToolOutcomeTracker {
|
|
|
35
38
|
this.terminalCalls.set(part.sessionID, terminalCalls);
|
|
36
39
|
}
|
|
37
40
|
if (terminalCalls.has(part.callID)) return undefined;
|
|
41
|
+
const fallbackCalls = this.fallbackCalls.get(part.sessionID);
|
|
42
|
+
if (fallbackCalls?.delete(part.callID) && status === "completed") {
|
|
43
|
+
terminalCalls.add(part.callID);
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
38
46
|
terminalCalls.add(part.callID);
|
|
47
|
+
if (terminalCalls.size > MAX_TRACKED_CALLS) terminalCalls.delete(terminalCalls.values().next().value!);
|
|
39
48
|
|
|
40
49
|
const start = part.state?.time?.start;
|
|
41
50
|
const end = part.state?.time?.end;
|
|
@@ -53,8 +62,21 @@ export class ToolOutcomeTracker {
|
|
|
53
62
|
return { sessionID: part.sessionID, callID: part.callID, tool: part.tool, status, durationMs, repeatedFailureCount: count };
|
|
54
63
|
}
|
|
55
64
|
|
|
65
|
+
recordFallbackCompleted(sessionID: string, callID: string, tool: string, durationMs?: number): ToolOutcome | undefined {
|
|
66
|
+
if (this.terminalCalls.get(sessionID)?.has(callID) || this.fallbackCalls.get(sessionID)?.has(callID)) return undefined;
|
|
67
|
+
let fallbackCalls = this.fallbackCalls.get(sessionID);
|
|
68
|
+
if (!fallbackCalls) {
|
|
69
|
+
fallbackCalls = new Set();
|
|
70
|
+
this.fallbackCalls.set(sessionID, fallbackCalls);
|
|
71
|
+
}
|
|
72
|
+
fallbackCalls.add(callID);
|
|
73
|
+
if (fallbackCalls.size > MAX_TRACKED_CALLS) fallbackCalls.delete(fallbackCalls.values().next().value!);
|
|
74
|
+
return { sessionID, callID, tool, status: "completed", durationMs };
|
|
75
|
+
}
|
|
76
|
+
|
|
56
77
|
clearSession(sessionID: string): void {
|
|
57
78
|
this.failures.delete(sessionID);
|
|
58
79
|
this.terminalCalls.delete(sessionID);
|
|
80
|
+
this.fallbackCalls.delete(sessionID);
|
|
59
81
|
}
|
|
60
82
|
}
|
package/src/lib/types.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface TodoSdkClient {
|
|
|
12
12
|
get?: (opts: { path: { id: string } }) => Promise<{ data?: { parentID?: unknown } }>;
|
|
13
13
|
promptAsync?: (opts: {
|
|
14
14
|
path: { id: string };
|
|
15
|
-
body: { messageID?: string; parts: Array<{ type: "text"; text: string }> };
|
|
15
|
+
body: { messageID?: string; parts: Array<{ type: "text"; text: string; synthetic?: boolean }> };
|
|
16
16
|
}) => Promise<unknown>;
|
|
17
17
|
};
|
|
18
18
|
tui?: {
|
|
@@ -178,6 +178,21 @@ export function prBodyIncludesChangelog(command: string, invocationRoot: string
|
|
|
178
178
|
return false;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
export function prBodyHasLiteralLineBreakEscapes(command: string): boolean {
|
|
182
|
+
const words = prShellWords(command);
|
|
183
|
+
const cliIndex = words.findIndex((word) => word === "gh" || word === "az");
|
|
184
|
+
if (cliIndex < 0) return false;
|
|
185
|
+
|
|
186
|
+
for (let i = cliIndex; i < words.length; i += 1) {
|
|
187
|
+
const word = words[i]!;
|
|
188
|
+
let body: string | undefined;
|
|
189
|
+
if (["--body", "-b", "--description", "-d"].includes(word)) body = words[i + 1];
|
|
190
|
+
else if (/^(?:--body|--description)=/.test(word)) body = word.slice(word.indexOf("=") + 1);
|
|
191
|
+
if (body && /\\[nr](?:\\[nr]|(?=\s*[-*#]))/.test(body)) return true;
|
|
192
|
+
}
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
|
|
181
196
|
export function checkLockfileSync(root: string): { isOutOfSync: boolean; manifest?: string; lockfile?: string; reason?: string } {
|
|
182
197
|
try {
|
|
183
198
|
let modifiedFiles: string[] = [];
|
|
@@ -48,6 +48,7 @@ export async function continueUnfinishedSession(sessionID: string): Promise<bool
|
|
|
48
48
|
parts: [{
|
|
49
49
|
type: "text",
|
|
50
50
|
text: "Workflow Guard: unfinished todos remain. Continue working through them. If you need user input, use the question tool instead of ending the run.",
|
|
51
|
+
synthetic: true,
|
|
51
52
|
}],
|
|
52
53
|
},
|
|
53
54
|
});
|
package/src/workflow-guard.ts
CHANGED
|
@@ -131,7 +131,7 @@ export {
|
|
|
131
131
|
exportProjectKnowledge,
|
|
132
132
|
importProjectKnowledge,
|
|
133
133
|
} from "./lib/project-memory.ts";
|
|
134
|
-
import { ensureProjectMemoryExcluded, getProjectMemoryIdentity, getRecentProjectMemory, importProjectKnowledge,
|
|
134
|
+
import { ensureProjectMemoryExcluded, getProjectMemoryIdentity, getRecentProjectMemory, importProjectKnowledge, isProjectMemoryFreshAsync, listReviewFollowups, openProjectMemory } from "./lib/project-memory.ts";
|
|
135
135
|
|
|
136
136
|
// ── Audit & durable verification cache ───────────────────────────────────────
|
|
137
137
|
import {
|
|
@@ -416,15 +416,19 @@ export const WorkflowGuard: Plugin = async (ctx) => {
|
|
|
416
416
|
|
|
417
417
|
"tool.execute.after": async (input, output) => {
|
|
418
418
|
const startedAt = toolLifecycle.finish(input.sessionID, input.callID);
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
419
|
+
const outcome = toolOutcomes.recordFallbackCompleted(input.sessionID, input.callID, input.tool, startedAt === undefined ? undefined : Date.now() - startedAt);
|
|
420
|
+
if (outcome) {
|
|
421
|
+
audit({
|
|
422
|
+
ts: new Date().toISOString(),
|
|
423
|
+
sessionID: outcome.sessionID,
|
|
424
|
+
callID: outcome.callID,
|
|
425
|
+
tool: outcome.tool,
|
|
426
|
+
decision: "allow",
|
|
427
|
+
phase: "outcome",
|
|
428
|
+
durationMs: outcome.durationMs,
|
|
429
|
+
reason: outcome.status,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
428
432
|
releaseFileClaims(input.sessionID, input.callID);
|
|
429
433
|
if (input.tool === "read") {
|
|
430
434
|
const observation = toolLifecycle.takeReadObservation(input.sessionID, input.callID);
|
|
@@ -503,8 +507,10 @@ export const WorkflowGuard: Plugin = async (ctx) => {
|
|
|
503
507
|
contextBlocks.push(stateLines.join("\n"));
|
|
504
508
|
let projectKnowledge: ReturnType<typeof getRecentProjectMemory> = [];
|
|
505
509
|
try {
|
|
506
|
-
|
|
507
|
-
.filter((memory) => memory.source !== "portable"
|
|
510
|
+
const candidates = (projectMemory ? getRecentProjectMemory(projectMemory, 8) : [])
|
|
511
|
+
.filter((memory) => memory.source !== "portable");
|
|
512
|
+
const freshness = await Promise.all(candidates.map((memory) => isProjectMemoryFreshAsync(memory, effectiveRoot)));
|
|
513
|
+
projectKnowledge = candidates.filter((_, index) => freshness[index]);
|
|
508
514
|
} catch {}
|
|
509
515
|
if (projectKnowledge.length > 0) {
|
|
510
516
|
const lines = projectKnowledge.map((memory) => `- [${memory.kind}:${memory.id.slice(0, 8)}] ${memory.content.slice(0, 300)}`);
|