opencode-codex-memory 0.7.6 → 0.8.0
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 +51 -8
- package/dist/opencode.json +2 -2
- package/dist/src/capture.d.ts +5 -0
- package/dist/src/capture.js +8 -0
- package/dist/src/codex-interop.js +5 -0
- package/dist/src/db.d.ts +7 -1
- package/dist/src/db.js +38 -11
- package/dist/src/diagnostics.js +5 -1
- package/dist/src/host-client.d.ts +5 -0
- package/dist/src/index.d.ts +12 -4
- package/dist/src/index.js +71 -66
- package/dist/src/lifecycle.js +14 -9
- package/dist/src/llm.d.ts +3 -2
- package/dist/src/llm.js +47 -11
- package/dist/src/local-session-times.d.ts +6 -0
- package/dist/src/local-session-times.js +59 -0
- package/dist/src/memory-version.d.ts +5 -0
- package/dist/src/memory-version.js +16 -0
- package/dist/src/migration.d.ts +24 -0
- package/dist/src/migration.js +37 -0
- package/dist/src/options.d.ts +10 -0
- package/dist/src/options.js +3 -0
- package/dist/src/paths.d.ts +9 -3
- package/dist/src/paths.js +22 -8
- package/dist/src/phase1.js +16 -2
- package/dist/src/phase2.js +15 -9
- package/dist/src/pipeline.d.ts +3 -0
- package/dist/src/pipeline.js +74 -0
- package/dist/src/ratelimit.js +9 -4
- package/dist/src/rollout-input.d.ts +3 -2
- package/dist/src/rollout-input.js +26 -17
- package/dist/src/session-version.d.ts +9 -0
- package/dist/src/session-version.js +27 -0
- package/dist/src/source.js +21 -6
- package/dist/src/store.d.ts +19 -3
- package/dist/src/store.js +121 -38
- package/dist/src/templates/consolidation_v2.md +54 -0
- package/dist/src/templates/read_path_v2.md +58 -0
- package/dist/src/templates/stage_one_input_v2.md +21 -0
- package/dist/src/templates/stage_one_system_v2.md +53 -0
- package/dist/src/token.d.ts +2 -0
- package/dist/src/token.js +16 -0
- package/dist/src/v2/agents.d.ts +4 -2
- package/dist/src/v2/agents.js +15 -7
- package/dist/src/v2/citation-overlay.d.ts +1 -1
- package/dist/src/v2/citation-overlay.js +27 -4
- package/dist/src/v2/plugin.js +27 -74
- package/dist/src/v2/shim.js +20 -9
- package/dist/src/v2/status-rpc.d.ts +70 -1
- package/dist/src/v2/status-rpc.js +41 -2
- package/dist/src/v2/status.d.ts +1 -1
- package/dist/src/v2/status.js +35 -9
- package/dist/src/v2/tui.js +57 -2
- package/dist/src/workspace.d.ts +8 -6
- package/dist/src/workspace.js +31 -11
- package/dist/tools/control.d.ts +6 -2
- package/dist/tools/control.js +209 -155
- package/dist/tools/memory.js +11 -1
- package/opencode.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { MemoryStore } from "./store.js";
|
|
2
|
+
import { runPhase1 } from "./phase1.js";
|
|
3
|
+
import { runPhase2 } from "./phase2.js";
|
|
4
|
+
import { pluginOptions } from "./options.js";
|
|
5
|
+
import { memoryDbPath } from "./paths.js";
|
|
6
|
+
import { withMemoryVersion, writeMemoryVersions } from "./memory-version.js";
|
|
7
|
+
import { isPluginShuttingDown } from "./lifecycle.js";
|
|
8
|
+
import { recordDiagnostic } from "./diagnostics.js";
|
|
9
|
+
const extracting = new Set();
|
|
10
|
+
async function consolidate(store, bypassCooldown) {
|
|
11
|
+
try {
|
|
12
|
+
const result = await runPhase2(store, {
|
|
13
|
+
maxRaw: pluginOptions.max_raw_memories_for_consolidation,
|
|
14
|
+
maxUnusedDays: pluginOptions.max_unused_days,
|
|
15
|
+
extensionRetentionDays: 7,
|
|
16
|
+
consolidationModel: pluginOptions.consolidation_model,
|
|
17
|
+
codexInterop: pluginOptions.codex_interop,
|
|
18
|
+
claudeImport: pluginOptions.claude_import,
|
|
19
|
+
bypassCooldown,
|
|
20
|
+
});
|
|
21
|
+
if (!["already_running", "skipped_cooldown", "skipped_running"].includes(result.status)) {
|
|
22
|
+
recordDiagnostic(["succeeded", "no_workspace_changes"].includes(result.status) ? "info" : "warn", "phase2", `${store.version}: ${result.status}`);
|
|
23
|
+
}
|
|
24
|
+
return result.status;
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
recordDiagnostic("error", "phase2", `${store.version}: ${String(err)}`);
|
|
28
|
+
return "failed";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Codex start.rs: independently run phase 1 then phase 2 for each write version. */
|
|
32
|
+
export async function runMemoryPipeline(currentSessionId, bypassCooldown = false) {
|
|
33
|
+
if (!pluginOptions.generate_memories)
|
|
34
|
+
return ["generation_disabled"];
|
|
35
|
+
if (isPluginShuttingDown())
|
|
36
|
+
return ["shutting_down"];
|
|
37
|
+
return Promise.all(writeMemoryVersions().map((version) => withMemoryVersion(version, async () => {
|
|
38
|
+
const key = memoryDbPath();
|
|
39
|
+
if (extracting.has(key))
|
|
40
|
+
return "already_running";
|
|
41
|
+
const store = new MemoryStore();
|
|
42
|
+
extracting.add(key);
|
|
43
|
+
try {
|
|
44
|
+
await runPhase1(store, {
|
|
45
|
+
maxAgeDays: pluginOptions.max_rollout_age_days,
|
|
46
|
+
minIdleHours: pluginOptions.min_rollout_idle_hours,
|
|
47
|
+
maxClaimed: pluginOptions.max_rollouts_per_startup,
|
|
48
|
+
maxUnusedDays: pluginOptions.max_unused_days,
|
|
49
|
+
excludeSession: currentSessionId,
|
|
50
|
+
extractModel: pluginOptions.extract_model,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
recordDiagnostic("error", "phase1", `${version}: ${String(err)}`);
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
extracting.delete(key);
|
|
58
|
+
}
|
|
59
|
+
return consolidate(store, bypassCooldown);
|
|
60
|
+
}).catch((err) => {
|
|
61
|
+
recordDiagnostic("error", "pipeline", `${version}: ${String(err)}`);
|
|
62
|
+
return "failed";
|
|
63
|
+
})));
|
|
64
|
+
}
|
|
65
|
+
export async function runMemoryConsolidation() {
|
|
66
|
+
if (!pluginOptions.generate_memories)
|
|
67
|
+
return ["generation_disabled"];
|
|
68
|
+
if (isPluginShuttingDown())
|
|
69
|
+
return ["shutting_down"];
|
|
70
|
+
return Promise.all(writeMemoryVersions().map((version) => withMemoryVersion(version, async () => consolidate(new MemoryStore(), false)).catch((err) => {
|
|
71
|
+
recordDiagnostic("error", "pipeline", `${version}: ${String(err)}`);
|
|
72
|
+
return "failed";
|
|
73
|
+
})));
|
|
74
|
+
}
|
package/dist/src/ratelimit.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { pluginOptions } from "./options.js";
|
|
2
|
+
import { memoryDbPath } from "./paths.js";
|
|
1
3
|
export class ProviderCapacityError extends Error {
|
|
2
4
|
statusCode;
|
|
3
5
|
constructor(message, statusCode) {
|
|
@@ -26,7 +28,7 @@ export class ProviderCapacityError extends Error {
|
|
|
26
28
|
* - phase 2 has no 30s timer; the DB claim + 6h cooldown serialize it.
|
|
27
29
|
* The observed-quota stamp still skips phase 2 (Codex start.rs skips both).
|
|
28
30
|
*/
|
|
29
|
-
|
|
31
|
+
const lastPhase1Work = new Map();
|
|
30
32
|
const providerCapacityUntil = new Map();
|
|
31
33
|
const MIN_PHASE1_INTERVAL_MS = 30_000;
|
|
32
34
|
export const PROVIDER_CAPACITY_BACKOFF_MS = 3_600_000;
|
|
@@ -100,8 +102,11 @@ export async function checkRateLimit(kind = "phase1", model) {
|
|
|
100
102
|
// Phase 2: no 30s gate (codex relies on DB claim/cooldown only).
|
|
101
103
|
if (kind === "phase2")
|
|
102
104
|
return { ok: true };
|
|
105
|
+
// Live harness sets options.test; skip the process stampede timer there.
|
|
106
|
+
if (pluginOptions.test)
|
|
107
|
+
return { ok: true };
|
|
103
108
|
const now = Date.now();
|
|
104
|
-
if (now - lastPhase1Work < MIN_PHASE1_INTERVAL_MS) {
|
|
109
|
+
if (now - (lastPhase1Work.get(memoryDbPath()) ?? 0) < MIN_PHASE1_INTERVAL_MS) {
|
|
105
110
|
return { ok: false, reason: "phase1 rate limit (30s since last claimed work)" };
|
|
106
111
|
}
|
|
107
112
|
return { ok: true };
|
|
@@ -109,10 +114,10 @@ export async function checkRateLimit(kind = "phase1", model) {
|
|
|
109
114
|
/** Call after a phase-1 pass claimed at least one job (token-using work started). */
|
|
110
115
|
export function markRateLimitUsed(kind = "phase1") {
|
|
111
116
|
if (kind === "phase1")
|
|
112
|
-
lastPhase1Work
|
|
117
|
+
lastPhase1Work.set(memoryDbPath(), Date.now());
|
|
113
118
|
}
|
|
114
119
|
/** Test seam: reset the process-local stamps. */
|
|
115
120
|
export function resetRateLimitForTest() {
|
|
116
|
-
lastPhase1Work
|
|
121
|
+
lastPhase1Work.clear();
|
|
117
122
|
providerCapacityUntil.clear();
|
|
118
123
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TranscriptMessage } from "./capture.js";
|
|
2
2
|
/**
|
|
3
3
|
* Human-first extract input. OpenCode parts, not Codex RolloutItem:
|
|
4
|
-
*
|
|
4
|
+
* question-tool replies retain their question; host transcripts expose no
|
|
5
|
+
* Codex MessagePhase::Commentary or internal content-item provenance.
|
|
5
6
|
*/
|
|
6
|
-
export declare function serializeTieredInput(items: TranscriptMessage[],
|
|
7
|
+
export declare function serializeTieredInput(items: TranscriptMessage[], byteLimit?: number): string;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { isMemoryExcludedFragment } from "./redact.js";
|
|
1
|
+
import { isMemoryExcludedFragment, redact } from "./redact.js";
|
|
2
|
+
import { stripCitations } from "./citation.js";
|
|
3
|
+
import { truncateToBytes } from "./token.js";
|
|
2
4
|
const OMITTED = "[... response items omitted ...]\n";
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
5
|
+
const TRUNCATION_RESERVE_BYTES = 96;
|
|
6
|
+
const TOOL_ROW_BYTES = 8_000;
|
|
7
|
+
const MAX_ROW_BYTES = 10_000;
|
|
8
|
+
const DEFAULT_BYTE_LIMIT = 600_000;
|
|
6
9
|
const TIER_ORDER = ["human", "final", "other_agent", "commentary", "context", "tool"];
|
|
7
10
|
const LABELS = {
|
|
8
11
|
human: "human user",
|
|
@@ -28,6 +31,8 @@ function classify(msg) {
|
|
|
28
31
|
return null;
|
|
29
32
|
if (msg.role === "developer" || msg.role === "system")
|
|
30
33
|
return null;
|
|
34
|
+
if (msg.userReply)
|
|
35
|
+
return "human";
|
|
31
36
|
if (msg.type === "tool")
|
|
32
37
|
return "tool";
|
|
33
38
|
if (msg.type === "file" || msg.type === "image")
|
|
@@ -37,6 +42,8 @@ function classify(msg) {
|
|
|
37
42
|
return null;
|
|
38
43
|
if (msg.type === "agent" || msg.type === "task")
|
|
39
44
|
return "other_agent";
|
|
45
|
+
if (isOtherAgent(text))
|
|
46
|
+
return "other_agent";
|
|
40
47
|
if (msg.role === "user") {
|
|
41
48
|
if (isMemoryExcludedFragment(text))
|
|
42
49
|
return null;
|
|
@@ -56,18 +63,20 @@ function rowText(msg, tier) {
|
|
|
56
63
|
return "[image omitted]";
|
|
57
64
|
if (msg.type === "file" && !msg.text?.trim())
|
|
58
65
|
return "[file omitted]";
|
|
59
|
-
let text = msg.
|
|
60
|
-
|
|
61
|
-
text
|
|
62
|
-
if (
|
|
63
|
-
text = text
|
|
66
|
+
let text = redact(stripCitations(msg.userReply
|
|
67
|
+
? `Assistant question: ${msg.userReply.question}\nHuman reply: ${msg.userReply.answer}`
|
|
68
|
+
: msg.text ?? ""));
|
|
69
|
+
if (tier === "tool")
|
|
70
|
+
text = truncateToBytes(text, TOOL_ROW_BYTES - TRUNCATION_RESERVE_BYTES);
|
|
71
|
+
text = truncateToBytes(text, MAX_ROW_BYTES - TRUNCATION_RESERVE_BYTES);
|
|
64
72
|
return text;
|
|
65
73
|
}
|
|
66
74
|
/**
|
|
67
75
|
* Human-first extract input. OpenCode parts, not Codex RolloutItem:
|
|
68
|
-
*
|
|
76
|
+
* question-tool replies retain their question; host transcripts expose no
|
|
77
|
+
* Codex MessagePhase::Commentary or internal content-item provenance.
|
|
69
78
|
*/
|
|
70
|
-
export function serializeTieredInput(items,
|
|
79
|
+
export function serializeTieredInput(items, byteLimit = DEFAULT_BYTE_LIMIT) {
|
|
71
80
|
const rows = [];
|
|
72
81
|
for (const msg of items) {
|
|
73
82
|
const tier = classify(msg);
|
|
@@ -78,18 +87,18 @@ export function serializeTieredInput(items, charLimit = DEFAULT_CHAR_LIMIT) {
|
|
|
78
87
|
continue;
|
|
79
88
|
rows.push({ tier, text: `[${LABELS[tier]}]\n${body}\n` });
|
|
80
89
|
}
|
|
81
|
-
let remaining = Math.max(0,
|
|
90
|
+
let remaining = Math.max(0, byteLimit - OMITTED.length);
|
|
82
91
|
const selected = rows.map(() => null);
|
|
83
92
|
for (const tier of TIER_ORDER) {
|
|
84
93
|
for (let i = rows.length - 1; i >= 0; i--) {
|
|
85
|
-
if (rows[i].tier !== tier || remaining <= OMITTED.length)
|
|
94
|
+
if (rows[i].tier !== tier || remaining <= OMITTED.length + TRUNCATION_RESERVE_BYTES)
|
|
86
95
|
continue;
|
|
87
96
|
let text = rows[i].text;
|
|
88
|
-
if (text
|
|
89
|
-
text = text
|
|
97
|
+
if (Buffer.byteLength(text) > remaining - OMITTED.length)
|
|
98
|
+
text = truncateToBytes(text, Math.max(0, remaining - OMITTED.length - TRUNCATION_RESERVE_BYTES));
|
|
90
99
|
if (!text)
|
|
91
100
|
continue;
|
|
92
|
-
remaining -= text
|
|
101
|
+
remaining -= Buffer.byteLength(text) + OMITTED.length;
|
|
93
102
|
selected[i] = text;
|
|
94
103
|
}
|
|
95
104
|
}
|
|
@@ -105,7 +114,7 @@ export function serializeTieredInput(items, charLimit = DEFAULT_CHAR_LIMIT) {
|
|
|
105
114
|
gap = true;
|
|
106
115
|
}
|
|
107
116
|
}
|
|
108
|
-
if (rendered
|
|
117
|
+
if (Buffer.byteLength(rendered) > byteLimit)
|
|
109
118
|
return "";
|
|
110
119
|
return rendered;
|
|
111
120
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type MemoryVersion } from "./options.js";
|
|
2
|
+
/** Freeze injection, retrieval, notes and citation accounting to one namespace.
|
|
3
|
+
* Codex keeps this in thread extension state. Persist our stamp because plugin
|
|
4
|
+
* reloads and host reconnects do not end an OpenCode conversation.
|
|
5
|
+
*/
|
|
6
|
+
export declare function sessionMemoryVersion(sessionId?: string): MemoryVersion;
|
|
7
|
+
export declare function withSessionMemoryVersion<T>(sessionId: string | undefined, run: () => T): T;
|
|
8
|
+
/** Status reporting must not freeze a session before its first real use. */
|
|
9
|
+
export declare function peekSessionMemoryVersion(sessionId?: string | null): MemoryVersion;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { openSessionMetaDb } from "./db.js";
|
|
2
|
+
import { pluginOptions } from "./options.js";
|
|
3
|
+
import { withMemoryVersion } from "./memory-version.js";
|
|
4
|
+
/** Freeze injection, retrieval, notes and citation accounting to one namespace.
|
|
5
|
+
* Codex keeps this in thread extension state. Persist our stamp because plugin
|
|
6
|
+
* reloads and host reconnects do not end an OpenCode conversation.
|
|
7
|
+
*/
|
|
8
|
+
export function sessionMemoryVersion(sessionId) {
|
|
9
|
+
if (!sessionId)
|
|
10
|
+
return pluginOptions.version;
|
|
11
|
+
const db = openSessionMetaDb();
|
|
12
|
+
db.prepare("INSERT OR IGNORE INTO memory_session_versions (session_id, version) VALUES (?, ?)")
|
|
13
|
+
.run(sessionId, pluginOptions.version);
|
|
14
|
+
return db.prepare("SELECT version FROM memory_session_versions WHERE session_id = ?")
|
|
15
|
+
.get(sessionId).version;
|
|
16
|
+
}
|
|
17
|
+
export function withSessionMemoryVersion(sessionId, run) {
|
|
18
|
+
return withMemoryVersion(sessionMemoryVersion(sessionId), run);
|
|
19
|
+
}
|
|
20
|
+
/** Status reporting must not freeze a session before its first real use. */
|
|
21
|
+
export function peekSessionMemoryVersion(sessionId) {
|
|
22
|
+
if (!sessionId)
|
|
23
|
+
return pluginOptions.version;
|
|
24
|
+
const row = openSessionMetaDb().prepare("SELECT version FROM memory_session_versions WHERE session_id = ?")
|
|
25
|
+
.get(sessionId);
|
|
26
|
+
return row?.version ?? pluginOptions.version;
|
|
27
|
+
}
|
package/dist/src/source.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { currentMemoryVersion } from "./memory-version.js";
|
|
3
4
|
import { memoryRoot } from "./paths.js";
|
|
4
5
|
import { assertMemoryRootSafe, safeResolveMemoryPath, withRegularFileNoFollow } from "./path-guard.js";
|
|
5
6
|
import { truncateToTokens } from "./token.js";
|
|
6
7
|
import { fillTemplate } from "./llm.js";
|
|
7
8
|
const MEMORY_SUMMARY_TOKEN_LIMIT = 2500;
|
|
8
9
|
const READ_PATH_TEMPLATE = "read_path.md";
|
|
10
|
+
const READ_PATH_TEMPLATE_V2 = "read_path_v2.md";
|
|
9
11
|
// Tool-dependent guidance for read_path.md. With dedicated_tools on, the
|
|
10
12
|
// prompt points at the memory_* tools (our platform adaptation — the memory
|
|
11
13
|
// dir lives outside the workspace). With them off, it falls back to codex's
|
|
@@ -16,6 +18,13 @@ const SEARCH_STEP_TOOLS = `2. Search {{ base_path }}/MEMORY.md for those keyword
|
|
|
16
18
|
pass \`since\`/\`until\` to \`memory_search\` — with a query it searches only that
|
|
17
19
|
period's sessions/notes; without a query it lists them chronologically.`;
|
|
18
20
|
const SEARCH_STEP_FILES = `2. Search {{ base_path }}/MEMORY.md using those keywords.`;
|
|
21
|
+
const SEARCH_STEP_TOOLS_V2 = `Search {{ base_path }}/rollout_summaries/ with the \`memory_search\`
|
|
22
|
+
tool, or read a recap with \`memory_read\`, when extra evidence, wording,
|
|
23
|
+
chronology, or uncertainty could change your answer.
|
|
24
|
+
- For time-scoped recall ("what was I working on last week / around date X"),
|
|
25
|
+
pass \`since\`/\`until\` to \`memory_search\` — with a query it searches only that
|
|
26
|
+
period's sessions/notes; without a query it lists them chronologically.`;
|
|
27
|
+
const SEARCH_STEP_FILES_V2 = `Search {{ base_path }}/rollout_summaries/ using those keywords when a needed route is missing.`;
|
|
19
28
|
const UPDATE_INSTRUCTIONS_TOOLS = `Use the \`memory_add_note\` tool, which writes
|
|
20
29
|
one small note file under \`extensions/ad_hoc/notes/\` describing what to
|
|
21
30
|
add/delete/update. Do not edit the memory files yourself; the consolidation
|
|
@@ -25,9 +34,10 @@ const UPDATE_INSTRUCTIONS_FILES = `- Write your update in {{ base_path }}/extens
|
|
|
25
34
|
- The name of this file must be \`<timestamp>-<short slug>.md\`
|
|
26
35
|
- Do not edit the other memory files yourself; the consolidation pass will
|
|
27
36
|
integrate the note.`;
|
|
28
|
-
|
|
37
|
+
const cache = new Map();
|
|
29
38
|
function readTemplate() {
|
|
30
|
-
const
|
|
39
|
+
const name = currentMemoryVersion() === "v2" ? READ_PATH_TEMPLATE_V2 : READ_PATH_TEMPLATE;
|
|
40
|
+
const templatePath = path.join(import.meta.dirname, "templates", name);
|
|
31
41
|
return fs.readFileSync(templatePath, "utf8");
|
|
32
42
|
}
|
|
33
43
|
function readMemorySummary() {
|
|
@@ -36,6 +46,7 @@ function readMemorySummary() {
|
|
|
36
46
|
// neither the root nor memory_summary.md may redirect outside the workspace.
|
|
37
47
|
const summaryPath = safeResolveMemoryPath("memory_summary.md");
|
|
38
48
|
return withRegularFileNoFollow(summaryPath, fs.constants.O_RDONLY, (fd, stat) => {
|
|
49
|
+
const cached = cache.get(summaryPath);
|
|
39
50
|
if (cached && cached.mtime === stat.mtimeMs) {
|
|
40
51
|
return cached.content;
|
|
41
52
|
}
|
|
@@ -43,10 +54,10 @@ function readMemorySummary() {
|
|
|
43
54
|
if (!raw)
|
|
44
55
|
return null;
|
|
45
56
|
const truncated = truncateToTokens(raw, MEMORY_SUMMARY_TOKEN_LIMIT);
|
|
46
|
-
|
|
57
|
+
cache.set(summaryPath, {
|
|
47
58
|
content: truncated,
|
|
48
59
|
mtime: stat.mtimeMs,
|
|
49
|
-
};
|
|
60
|
+
});
|
|
50
61
|
return truncated;
|
|
51
62
|
});
|
|
52
63
|
}
|
|
@@ -55,15 +66,19 @@ function readMemorySummary() {
|
|
|
55
66
|
}
|
|
56
67
|
}
|
|
57
68
|
export function invalidateCache() {
|
|
58
|
-
|
|
69
|
+
cache.clear();
|
|
59
70
|
}
|
|
60
71
|
export function buildMemorySystemPrompt(dedicatedTools) {
|
|
61
72
|
const summary = readMemorySummary();
|
|
62
73
|
if (!summary)
|
|
63
74
|
return null;
|
|
64
75
|
const template = readTemplate();
|
|
76
|
+
const v2 = currentMemoryVersion() === "v2";
|
|
77
|
+
const searchStep = dedicatedTools
|
|
78
|
+
? (v2 ? SEARCH_STEP_TOOLS_V2 : SEARCH_STEP_TOOLS)
|
|
79
|
+
: (v2 ? SEARCH_STEP_FILES_V2 : SEARCH_STEP_FILES);
|
|
65
80
|
return fillTemplate(template, {
|
|
66
|
-
search_step:
|
|
81
|
+
search_step: searchStep,
|
|
67
82
|
update_instructions: dedicatedTools ? UPDATE_INSTRUCTIONS_TOOLS : UPDATE_INSTRUCTIONS_FILES,
|
|
68
83
|
// Filled last so {{ base_path }} nested inside the snippets above resolves.
|
|
69
84
|
base_path: memoryRoot(),
|
package/dist/src/store.d.ts
CHANGED
|
@@ -40,10 +40,17 @@ export type Phase2ClaimResult = {
|
|
|
40
40
|
} | {
|
|
41
41
|
type: "skipped_retry_unavailable";
|
|
42
42
|
};
|
|
43
|
+
/** Wipe jobs/outputs in every versioned DB. Leaves memory_session_meta on memory.db. */
|
|
44
|
+
export declare function clearAllVersionMemoryData(): void;
|
|
45
|
+
/** Include inactive existing stores for deletion, reset guards and diagnostics. */
|
|
46
|
+
export declare function existingMemoryStores(): MemoryStore[];
|
|
43
47
|
export declare class MemoryStore {
|
|
44
48
|
private db;
|
|
45
|
-
|
|
49
|
+
private meta;
|
|
50
|
+
readonly version: import("./options.js").MemoryVersion;
|
|
51
|
+
constructor(db?: Database, meta?: Database, version?: import("./options.js").MemoryVersion);
|
|
46
52
|
stage1Outputs(): Stage1Output[];
|
|
53
|
+
stage1OutputCount(): number;
|
|
47
54
|
hasStage1Output(sessionId: string): boolean;
|
|
48
55
|
/**
|
|
49
56
|
* Deletes stale rows; snapshots consumed by the last successful Phase 2 are
|
|
@@ -91,6 +98,8 @@ export declare class MemoryStore {
|
|
|
91
98
|
* still back the consolidated artifacts.
|
|
92
99
|
*/
|
|
93
100
|
markPhase2Succeeded(ownershipToken: string, selected?: Pick<Stage1Output, "session_id" | "source_updated_at">[]): void;
|
|
101
|
+
/** High-water mark of distinct sessions consumed by one successful run. */
|
|
102
|
+
maxConsolidatedThreadCount(): number;
|
|
94
103
|
/**
|
|
95
104
|
* Phase-2 job snapshot for memory_inspect. Always returns the global job row
|
|
96
105
|
* when it exists (including failed/running), so diagnostics are not limited
|
|
@@ -167,18 +176,25 @@ export declare class MemoryStore {
|
|
|
167
176
|
/**
|
|
168
177
|
* Stage-1 job counts + recent failures for memory_inspect. Helps diagnose
|
|
169
178
|
* "nothing is learning" without reading the raw jobs table.
|
|
179
|
+
*
|
|
180
|
+
* `staleBeforeSec`: exhausted jobs finished before this unix-seconds cutoff
|
|
181
|
+
* (typically now − max_rollout_age_days) are counted in `stale_exhausted`
|
|
182
|
+
* and omitted from `recent_errors` so leftover rows from old plugin
|
|
183
|
+
* versions do not bury live due/backoff failures.
|
|
170
184
|
*/
|
|
171
|
-
stage1JobSnapshot(): {
|
|
185
|
+
stage1JobSnapshot(staleBeforeSec?: number): {
|
|
172
186
|
by_status: Record<string, number>;
|
|
173
187
|
by_failure_class: {
|
|
174
188
|
backoff: number;
|
|
175
189
|
provider_capacity: number;
|
|
176
190
|
other_exhausted: number;
|
|
191
|
+
due: number;
|
|
177
192
|
};
|
|
193
|
+
stale_exhausted: number;
|
|
178
194
|
recent_errors: Stage1RecentError[];
|
|
179
195
|
};
|
|
180
196
|
}
|
|
181
|
-
export type Stage1FailureClass = "backoff" | "provider_capacity" | "other_exhausted";
|
|
197
|
+
export type Stage1FailureClass = "backoff" | "provider_capacity" | "other_exhausted" | "due";
|
|
182
198
|
export interface Stage1RecentError {
|
|
183
199
|
session_id: string;
|
|
184
200
|
last_error: string;
|