opencode-codex-memory 0.7.7 → 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/host-client.d.ts +5 -0
- package/dist/src/index.d.ts +12 -4
- package/dist/src/index.js +39 -61
- 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/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 +4 -0
- package/dist/src/options.js +2 -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 +5 -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 +10 -1
- package/dist/src/store.js +76 -24
- 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 +24 -72
- package/dist/src/v2/shim.js +5 -1
- 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 +28 -6
- 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 +196 -164
- package/dist/tools/memory.js +11 -1
- package/opencode.json +2 -2
- package/package.json +1 -1
package/dist/src/v2/tui.js
CHANGED
|
@@ -39,14 +39,38 @@ var MemoryStatusRpc = {
|
|
|
39
39
|
status: {
|
|
40
40
|
input: {
|
|
41
41
|
type: "object",
|
|
42
|
-
properties: {
|
|
42
|
+
properties: {
|
|
43
|
+
sessionID: { type: "string" },
|
|
44
|
+
minConsolidatedThreads: { type: "integer", minimum: 1, maximum: 4096 }
|
|
45
|
+
},
|
|
43
46
|
additionalProperties: false
|
|
44
47
|
},
|
|
45
48
|
output: {
|
|
46
49
|
type: "object",
|
|
47
50
|
properties: {
|
|
48
51
|
activity: { type: "string", enum: [...MEMORY_STATUS_ACTIVITIES] },
|
|
52
|
+
version: { type: "string", enum: ["v1", "v2"] },
|
|
53
|
+
sessionVersion: { type: "string", enum: ["v1", "v2"] },
|
|
54
|
+
dualWrite: { type: "boolean" },
|
|
55
|
+
v2ConsolidatedThreads: { type: "integer", minimum: 0 },
|
|
56
|
+
v2Ready: { type: "boolean" },
|
|
57
|
+
minConsolidatedThreads: { type: "integer", minimum: 1, maximum: 4096 },
|
|
49
58
|
useMemories: { type: "boolean" },
|
|
59
|
+
pipelines: {
|
|
60
|
+
type: "array",
|
|
61
|
+
items: {
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: {
|
|
64
|
+
version: { type: "string", enum: ["v1", "v2"] },
|
|
65
|
+
stage1Count: { type: "integer", minimum: 0 },
|
|
66
|
+
extracting: { type: "integer", minimum: 0 },
|
|
67
|
+
phase2Status: { type: ["string", "null"] },
|
|
68
|
+
lastError: { type: ["string", "null"] }
|
|
69
|
+
},
|
|
70
|
+
required: ["version", "stage1Count", "extracting", "phase2Status", "lastError"],
|
|
71
|
+
additionalProperties: false
|
|
72
|
+
}
|
|
73
|
+
},
|
|
50
74
|
generateMemories: { type: "boolean" },
|
|
51
75
|
extractModel: { type: ["string", "null"] },
|
|
52
76
|
consolidationModel: { type: ["string", "null"] },
|
|
@@ -60,6 +84,13 @@ var MemoryStatusRpc = {
|
|
|
60
84
|
},
|
|
61
85
|
required: [
|
|
62
86
|
"activity",
|
|
87
|
+
"version",
|
|
88
|
+
"sessionVersion",
|
|
89
|
+
"dualWrite",
|
|
90
|
+
"v2ConsolidatedThreads",
|
|
91
|
+
"v2Ready",
|
|
92
|
+
"minConsolidatedThreads",
|
|
93
|
+
"pipelines",
|
|
63
94
|
"useMemories",
|
|
64
95
|
"generateMemories",
|
|
65
96
|
"extractModel",
|
|
@@ -122,10 +153,20 @@ function isMemoryStatus(value) {
|
|
|
122
153
|
if (typeof value.activity !== "string" || !MEMORY_STATUS_ACTIVITIES.includes(value.activity)) {
|
|
123
154
|
return false;
|
|
124
155
|
}
|
|
125
|
-
for (const key of ["useMemories", "generateMemories", "codexImport"]) {
|
|
156
|
+
for (const key of ["useMemories", "generateMemories", "codexImport", "dualWrite", "v2Ready"]) {
|
|
126
157
|
if (typeof value[key] !== "boolean")
|
|
127
158
|
return false;
|
|
128
159
|
}
|
|
160
|
+
for (const key of ["version", "sessionVersion"]) {
|
|
161
|
+
if (value[key] !== "v1" && value[key] !== "v2")
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
if (!Number.isInteger(value.v2ConsolidatedThreads) || value.v2ConsolidatedThreads < 0)
|
|
165
|
+
return false;
|
|
166
|
+
if (!Number.isInteger(value.minConsolidatedThreads) || value.minConsolidatedThreads < 1 || value.minConsolidatedThreads > 4096)
|
|
167
|
+
return false;
|
|
168
|
+
if (!Array.isArray(value.pipelines) || !value.pipelines.every((pipeline) => isRecord(pipeline) && (pipeline.version === "v1" || pipeline.version === "v2") && Number.isInteger(pipeline.stage1Count) && pipeline.stage1Count >= 0 && Number.isInteger(pipeline.extracting) && pipeline.extracting >= 0 && (pipeline.phase2Status === null || typeof pipeline.phase2Status === "string") && (pipeline.lastError === null || typeof pipeline.lastError === "string")))
|
|
169
|
+
return false;
|
|
129
170
|
for (const key of ["extractModel", "consolidationModel", "lastSuccessAt", "retryAt"]) {
|
|
130
171
|
const v = value[key];
|
|
131
172
|
if (v !== null && typeof v !== (key === "extractModel" || key === "consolidationModel" ? "string" : "number")) {
|
|
@@ -235,6 +276,20 @@ function statusRows(s, now) {
|
|
|
235
276
|
label: "Activity",
|
|
236
277
|
value: labels[s.activity]
|
|
237
278
|
}, {
|
|
279
|
+
label: "Memory version",
|
|
280
|
+
value: `${s.sessionVersion} (default ${s.version})`
|
|
281
|
+
}, {
|
|
282
|
+
label: "Learning pipelines",
|
|
283
|
+
value: s.dualWrite ? "v1 + v2" : s.version
|
|
284
|
+
}, {
|
|
285
|
+
label: "V2 readiness",
|
|
286
|
+
value: `${s.v2Ready ? "Ready" : "Warming"} \xB7 ${s.v2ConsolidatedThreads}/${s.minConsolidatedThreads} sessions`,
|
|
287
|
+
tone: s.v2Ready ? "ok" : "muted"
|
|
288
|
+
}, ...s.pipelines.map((pipeline) => ({
|
|
289
|
+
label: `${pipeline.version.toUpperCase()} pipeline`,
|
|
290
|
+
value: `${pipeline.stage1Count} recaps \xB7 ${pipeline.extracting ? "extracting" : pipeline.phase2Status ?? "idle"}`,
|
|
291
|
+
tone: pipeline.lastError ? "warn" : "muted"
|
|
292
|
+
})), {
|
|
238
293
|
label: "Read memories",
|
|
239
294
|
value: s.useMemories ? "On" : "Off",
|
|
240
295
|
tone: s.useMemories ? "ok" : "muted"
|
package/dist/src/workspace.d.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
import type { MemoryVersion } from "./options.js";
|
|
1
2
|
import type { Stage1Output } from "./store.js";
|
|
2
3
|
import { type WorkspaceDiff } from "./git-baseline.js";
|
|
3
4
|
/** Mirrors codex `remove_memory_symlinks` (workspace.rs): unlink every symlink in the tree, never follow. */
|
|
4
5
|
export declare function removeMemorySymlinks(root?: string): number;
|
|
5
6
|
export declare function ensureLayout(): void;
|
|
6
|
-
|
|
7
|
-
* Mirrors codex `validate_consolidation_artifacts` (workspace.rs): after
|
|
8
|
-
* consolidation (or when deciding an early no-diff succeed), MEMORY.md must be
|
|
9
|
-
* a regular file and memory_summary.md must start with the exact line `v1`.
|
|
10
|
-
* Invalid artifacts force a consolidator re-run and block baseline reset.
|
|
11
|
-
*/
|
|
7
|
+
export declare function isValidV2Summary(summary: string): boolean;
|
|
12
8
|
export declare function validateConsolidationArtifacts(root?: string): {
|
|
13
9
|
ok: true;
|
|
14
10
|
} | {
|
|
15
11
|
ok: false;
|
|
16
12
|
reason: string;
|
|
17
13
|
};
|
|
14
|
+
export declare function validateConsolidationArtifactsForVersion(root?: string, version?: MemoryVersion): {
|
|
15
|
+
ok: true;
|
|
16
|
+
} | {
|
|
17
|
+
ok: false;
|
|
18
|
+
reason: string;
|
|
19
|
+
};
|
|
18
20
|
export declare function rolloutSummaryFileStem(o: Pick<Stage1Output, "session_id" | "source_updated_at" | "rollout_slug">): string;
|
|
19
21
|
export declare function rebuildRawMemories(outputs: Stage1Output[]): string;
|
|
20
22
|
export declare function writeRolloutSummaries(outputs: Stage1Output[]): void;
|
package/dist/src/workspace.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from "crypto";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
|
+
import { currentMemoryVersion } from "./memory-version.js";
|
|
4
5
|
import { memoryRoot } from "./paths.js";
|
|
5
6
|
import { assertMemoryRootSafe, readRegularFileNoFollow, safeResolveMemoryPath, writeRegularFileNoFollow, } from "./path-guard.js";
|
|
6
7
|
import { DIFF_ARTIFACT } from "./git-baseline.js";
|
|
@@ -73,9 +74,11 @@ export function ensureLayout() {
|
|
|
73
74
|
for (const dir of [ROLLOUT_DIR, SKILLS_DIR, EXTENSIONS_DIR, ADHOC_NOTES_DIR]) {
|
|
74
75
|
fs.mkdirSync(safeResolveMemoryPath(dir), { recursive: true });
|
|
75
76
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
if (currentMemoryVersion() === "v1") {
|
|
78
|
+
const memoryMd = safeResolveMemoryPath("MEMORY.md");
|
|
79
|
+
if (!fs.existsSync(memoryMd))
|
|
80
|
+
writeRegularFileNoFollow(memoryMd, "# MEMORY.md\n\n_Searchable index of memories._\n");
|
|
81
|
+
}
|
|
79
82
|
const summary = safeResolveMemoryPath("memory_summary.md");
|
|
80
83
|
if (!fs.existsSync(summary))
|
|
81
84
|
writeRegularFileNoFollow(summary, "");
|
|
@@ -89,7 +92,19 @@ export function ensureLayout() {
|
|
|
89
92
|
* a regular file and memory_summary.md must start with the exact line `v1`.
|
|
90
93
|
* Invalid artifacts force a consolidator re-run and block baseline reset.
|
|
91
94
|
*/
|
|
95
|
+
const V2_SUMMARY_HEADINGS = ["## User Profile", "## User preferences", "## General Tips", "## What's in Memory"];
|
|
96
|
+
export function isValidV2Summary(summary) {
|
|
97
|
+
if (summary.split(/\r?\n/, 1)[0] !== "v1")
|
|
98
|
+
return false;
|
|
99
|
+
if (Buffer.byteLength(summary, "utf8") >= 10_000)
|
|
100
|
+
return false;
|
|
101
|
+
const lines = summary.split(/\r?\n/).map((line) => line.trim());
|
|
102
|
+
return V2_SUMMARY_HEADINGS.every((heading) => lines.includes(heading));
|
|
103
|
+
}
|
|
92
104
|
export function validateConsolidationArtifacts(root = memoryRoot()) {
|
|
105
|
+
return validateConsolidationArtifactsForVersion(root, "v1");
|
|
106
|
+
}
|
|
107
|
+
export function validateConsolidationArtifactsForVersion(root = memoryRoot(), version = currentMemoryVersion()) {
|
|
93
108
|
let removedSymlinks;
|
|
94
109
|
try {
|
|
95
110
|
removedSymlinks = removeMemorySymlinks(root);
|
|
@@ -100,14 +115,16 @@ export function validateConsolidationArtifacts(root = memoryRoot()) {
|
|
|
100
115
|
if (removedSymlinks !== 0) {
|
|
101
116
|
return { ok: false, reason: `removed ${removedSymlinks} symbolic links from consolidated memory workspace` };
|
|
102
117
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
118
|
+
if (version === "v1") {
|
|
119
|
+
const memoryPath = path.join(root, "MEMORY.md");
|
|
120
|
+
try {
|
|
121
|
+
const st = fs.lstatSync(memoryPath);
|
|
122
|
+
if (!st.isFile())
|
|
123
|
+
return { ok: false, reason: `consolidated memory artifact is not a file: ${memoryPath}` };
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return { ok: false, reason: `missing consolidated memory artifact: ${memoryPath}` };
|
|
127
|
+
}
|
|
111
128
|
}
|
|
112
129
|
const summaryPath = path.join(root, "memory_summary.md");
|
|
113
130
|
let summary;
|
|
@@ -124,6 +141,9 @@ export function validateConsolidationArtifacts(root = memoryRoot()) {
|
|
|
124
141
|
if (first !== "v1") {
|
|
125
142
|
return { ok: false, reason: `memory summary artifact does not start with v1: ${summaryPath}` };
|
|
126
143
|
}
|
|
144
|
+
if (version === "v2" && !isValidV2Summary(summary)) {
|
|
145
|
+
return { ok: false, reason: "invalid v2 memory summary" };
|
|
146
|
+
}
|
|
127
147
|
return { ok: true };
|
|
128
148
|
}
|
|
129
149
|
const RAW_MEMORY_MAX_CHARS = 10_000;
|
package/dist/tools/control.d.ts
CHANGED
|
@@ -9,8 +9,12 @@ export declare const memory_reset: {
|
|
|
9
9
|
};
|
|
10
10
|
export declare const memory_inspect: {
|
|
11
11
|
description: string;
|
|
12
|
-
args: {
|
|
13
|
-
|
|
12
|
+
args: {
|
|
13
|
+
min_consolidated_threads: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
14
|
+
};
|
|
15
|
+
execute(args: {
|
|
16
|
+
min_consolidated_threads?: number | undefined;
|
|
17
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
14
18
|
};
|
|
15
19
|
export declare const memory_mode: {
|
|
16
20
|
description: string;
|