opencode-codex-memory 0.9.7 → 0.9.8
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 +2 -2
- package/dist/src/agent-health.js +8 -4
- package/dist/src/migration.d.ts +2 -0
- package/dist/src/migration.js +17 -3
- package/dist/src/v2/status-rpc.d.ts +10 -0
- package/dist/src/v2/status-rpc.js +7 -0
- package/dist/src/v2/tui.js +21 -3
- package/dist/src/workspace.d.ts +6 -0
- package/dist/src/workspace.js +21 -8
- package/dist/tools/control.js +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ to your existing global `~/.config/opencode/opencode.jsonc` or `opencode.json`
|
|
|
35
35
|
{
|
|
36
36
|
"$schema": "https://opencode.ai/config.json",
|
|
37
37
|
"plugins": [
|
|
38
|
-
{ "package": "opencode-codex-memory@0.9.
|
|
38
|
+
{ "package": "opencode-codex-memory@0.9.8" }
|
|
39
39
|
]
|
|
40
40
|
}
|
|
41
41
|
```
|
|
@@ -45,7 +45,7 @@ to your existing global `~/.config/opencode/opencode.jsonc` or `opencode.json`
|
|
|
45
45
|
```json
|
|
46
46
|
{
|
|
47
47
|
"$schema": "https://opencode.ai/config.json",
|
|
48
|
-
"plugin": ["opencode-codex-memory@0.9.
|
|
48
|
+
"plugin": ["opencode-codex-memory@0.9.8"]
|
|
49
49
|
}
|
|
50
50
|
```
|
|
51
51
|
|
package/dist/src/agent-health.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { memoryRoot } from "./paths.js";
|
|
4
|
+
import { writeMemoryVersions } from "./memory-version.js";
|
|
4
5
|
const AGENT_NAMES = ["memorize", "memorize-extract"];
|
|
5
6
|
const REQUIRED_ALLOWS = {
|
|
6
7
|
memorize: ["read", "edit", "write", "glob", "grep"],
|
|
@@ -69,13 +70,16 @@ function permissionIssues(name, definition) {
|
|
|
69
70
|
}
|
|
70
71
|
if (name === "memorize") {
|
|
71
72
|
const external = asRecord(permission.external_directory);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
// Agent grants cover all writers; helper-session rules narrow each job to one root.
|
|
74
|
+
const expectedPaths = new Set(writeMemoryVersions().map((version) => path.join(memoryRoot(version), "*")));
|
|
75
|
+
for (const expectedPath of expectedPaths) {
|
|
76
|
+
if (external?.[expectedPath] !== "allow") {
|
|
77
|
+
issues.push(`consolidator must allow external_directory '${expectedPath}'`);
|
|
78
|
+
}
|
|
75
79
|
}
|
|
76
80
|
if (external) {
|
|
77
81
|
for (const [grantedPath, action] of Object.entries(external)) {
|
|
78
|
-
if (grantedPath
|
|
82
|
+
if (expectedPaths.has(grantedPath))
|
|
79
83
|
continue;
|
|
80
84
|
if (hasNonDenyAction(action)) {
|
|
81
85
|
issues.push(`consolidator must deny extra external_directory '${grantedPath}'`);
|
package/dist/src/migration.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export declare const DEFAULT_MIN_CONSOLIDATED_THREADS = 20;
|
|
|
3
3
|
export declare function readMigrationStatus(minConsolidatedThreads?: number): {
|
|
4
4
|
v2ConsolidatedThreads: number;
|
|
5
5
|
v2Ready: boolean;
|
|
6
|
+
v2NotReadyReason: string | null;
|
|
7
|
+
v2SummaryBytes: number | null;
|
|
6
8
|
minConsolidatedThreads: number;
|
|
7
9
|
};
|
|
8
10
|
export declare function memoryPipelineSnapshots(): {
|
package/dist/src/migration.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import { memoryDbPath, memoryRoot } from "./paths.js";
|
|
3
3
|
import { MemoryStore, existingMemoryStores } from "./store.js";
|
|
4
4
|
import { withMemoryVersion } from "./memory-version.js";
|
|
5
|
-
import {
|
|
5
|
+
import { validateV2Summary } from "./workspace.js";
|
|
6
6
|
import { safeResolveUnderRoot, readRegularFileNoFollow } from "./path-guard.js";
|
|
7
7
|
export const DEFAULT_MIN_CONSOLIDATED_THREADS = 20;
|
|
8
8
|
/** Codex memory/status: high-water progress AND a currently valid V2 summary. */
|
|
@@ -14,14 +14,28 @@ export function readMigrationStatus(minConsolidatedThreads = DEFAULT_MIN_CONSOLI
|
|
|
14
14
|
? withMemoryVersion("v2", () => new MemoryStore().maxConsolidatedThreadCount())
|
|
15
15
|
: 0;
|
|
16
16
|
let valid = false;
|
|
17
|
+
let v2SummaryBytes = null;
|
|
18
|
+
let v2NotReadyReason = null;
|
|
17
19
|
try {
|
|
18
20
|
const file = safeResolveUnderRoot(memoryRoot("v2"), "memory_summary.md");
|
|
19
|
-
|
|
21
|
+
const validation = validateV2Summary(readRegularFileNoFollow(file).content.toString("utf8"));
|
|
22
|
+
valid = validation.ok;
|
|
23
|
+
v2SummaryBytes = validation.bytes;
|
|
24
|
+
v2NotReadyReason = validation.reason;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
const code = error?.code;
|
|
28
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
29
|
+
v2NotReadyReason = `cannot read V2 memory summary${typeof code === "string" ? ` (${code})` : ""}: ${message}`;
|
|
30
|
+
}
|
|
31
|
+
if (valid && v2ConsolidatedThreads < minConsolidatedThreads) {
|
|
32
|
+
v2NotReadyReason = `insufficient consolidated threads: ${v2ConsolidatedThreads} < ${minConsolidatedThreads}`;
|
|
20
33
|
}
|
|
21
|
-
catch { /* Missing or unsafe summary is not ready. */ }
|
|
22
34
|
return {
|
|
23
35
|
v2ConsolidatedThreads,
|
|
24
36
|
v2Ready: valid && v2ConsolidatedThreads >= minConsolidatedThreads,
|
|
37
|
+
v2NotReadyReason,
|
|
38
|
+
v2SummaryBytes,
|
|
25
39
|
minConsolidatedThreads,
|
|
26
40
|
};
|
|
27
41
|
}
|
|
@@ -15,6 +15,9 @@ export interface MemoryStatus {
|
|
|
15
15
|
dualWrite: boolean;
|
|
16
16
|
v2ConsolidatedThreads: number;
|
|
17
17
|
v2Ready: boolean;
|
|
18
|
+
/** Readiness diagnostics; optional for older servers. Null reason means ready. */
|
|
19
|
+
v2NotReadyReason?: string | null;
|
|
20
|
+
v2SummaryBytes?: number | null;
|
|
18
21
|
minConsolidatedThreads: number;
|
|
19
22
|
pipelines: {
|
|
20
23
|
version: "v1" | "v2";
|
|
@@ -90,6 +93,13 @@ export declare const MemoryStatusRpc: {
|
|
|
90
93
|
readonly v2Ready: {
|
|
91
94
|
readonly type: "boolean";
|
|
92
95
|
};
|
|
96
|
+
readonly v2NotReadyReason: {
|
|
97
|
+
readonly type: readonly ["string", "null"];
|
|
98
|
+
};
|
|
99
|
+
readonly v2SummaryBytes: {
|
|
100
|
+
readonly type: readonly ["integer", "null"];
|
|
101
|
+
readonly minimum: 0;
|
|
102
|
+
};
|
|
93
103
|
readonly minConsolidatedThreads: {
|
|
94
104
|
readonly type: "integer";
|
|
95
105
|
readonly minimum: 1;
|
|
@@ -48,6 +48,8 @@ export const MemoryStatusRpc = {
|
|
|
48
48
|
dualWrite: { type: "boolean" },
|
|
49
49
|
v2ConsolidatedThreads: { type: "integer", minimum: 0 },
|
|
50
50
|
v2Ready: { type: "boolean" },
|
|
51
|
+
v2NotReadyReason: { type: ["string", "null"] },
|
|
52
|
+
v2SummaryBytes: { type: ["integer", "null"], minimum: 0 },
|
|
51
53
|
minConsolidatedThreads: { type: "integer", minimum: 1, maximum: 4096 },
|
|
52
54
|
useMemories: { type: "boolean" },
|
|
53
55
|
pipelines: {
|
|
@@ -174,6 +176,11 @@ export function isMemoryStatus(value) {
|
|
|
174
176
|
}
|
|
175
177
|
if (!Number.isInteger(value.v2ConsolidatedThreads) || value.v2ConsolidatedThreads < 0)
|
|
176
178
|
return false;
|
|
179
|
+
if (value.v2NotReadyReason !== undefined && value.v2NotReadyReason !== null && typeof value.v2NotReadyReason !== "string")
|
|
180
|
+
return false;
|
|
181
|
+
if (value.v2SummaryBytes !== undefined && value.v2SummaryBytes !== null &&
|
|
182
|
+
(!Number.isInteger(value.v2SummaryBytes) || value.v2SummaryBytes < 0))
|
|
183
|
+
return false;
|
|
177
184
|
if (!Number.isInteger(value.minConsolidatedThreads) || value.minConsolidatedThreads < 1 || value.minConsolidatedThreads > 4096)
|
|
178
185
|
return false;
|
|
179
186
|
if (!Array.isArray(value.pipelines) || !value.pipelines.every((pipeline) => isRecord(pipeline) && (pipeline.version === "v1" || pipeline.version === "v2")
|
package/dist/src/v2/tui.js
CHANGED
|
@@ -56,6 +56,8 @@ var MemoryStatusRpc = {
|
|
|
56
56
|
dualWrite: { type: "boolean" },
|
|
57
57
|
v2ConsolidatedThreads: { type: "integer", minimum: 0 },
|
|
58
58
|
v2Ready: { type: "boolean" },
|
|
59
|
+
v2NotReadyReason: { type: ["string", "null"] },
|
|
60
|
+
v2SummaryBytes: { type: ["integer", "null"], minimum: 0 },
|
|
59
61
|
minConsolidatedThreads: { type: "integer", minimum: 1, maximum: 4096 },
|
|
60
62
|
useMemories: { type: "boolean" },
|
|
61
63
|
pipelines: {
|
|
@@ -182,6 +184,10 @@ function isMemoryStatus(value) {
|
|
|
182
184
|
}
|
|
183
185
|
if (!Number.isInteger(value.v2ConsolidatedThreads) || value.v2ConsolidatedThreads < 0)
|
|
184
186
|
return false;
|
|
187
|
+
if (value.v2NotReadyReason !== undefined && value.v2NotReadyReason !== null && typeof value.v2NotReadyReason !== "string")
|
|
188
|
+
return false;
|
|
189
|
+
if (value.v2SummaryBytes !== undefined && value.v2SummaryBytes !== null && (!Number.isInteger(value.v2SummaryBytes) || value.v2SummaryBytes < 0))
|
|
190
|
+
return false;
|
|
185
191
|
if (!Number.isInteger(value.minConsolidatedThreads) || value.minConsolidatedThreads < 1 || value.minConsolidatedThreads > 4096)
|
|
186
192
|
return false;
|
|
187
193
|
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") && ["phase2CooldownUntil", "phase1RetryAt", "phase2RetryAt"].every((key) => pipeline[key] === undefined || pipeline[key] === null || typeof pipeline[key] === "number" && Number.isFinite(pipeline[key]))))
|
|
@@ -378,7 +384,11 @@ function pipelineRows(s, now) {
|
|
|
378
384
|
label: `${version} consolidation`,
|
|
379
385
|
value: pipeline.phase2Status === "running" ? "Running" : paused ? "Paused" : consolidationRetry ? `Retry ${remaining(pipeline.phase2RetryAt, now)}` : cooldown ? `${consolidation} \xB7 cooldown ends ${remaining(pipeline.phase2CooldownUntil, now)}` : pipeline.phase2Status === "pending" ? "Queued \xB7 next activity" : consolidation,
|
|
380
386
|
tone: pipeline.lastError ? "warn" : "muted"
|
|
381
|
-
}
|
|
387
|
+
}, ...pipeline.lastError ? [{
|
|
388
|
+
label: `${version} last error`,
|
|
389
|
+
value: pipeline.lastError,
|
|
390
|
+
tone: "warn"
|
|
391
|
+
}] : []];
|
|
382
392
|
});
|
|
383
393
|
}
|
|
384
394
|
function statusRows(s, now) {
|
|
@@ -393,9 +403,17 @@ function statusRows(s, now) {
|
|
|
393
403
|
value: s.dualWrite ? "v1 + v2" : s.version
|
|
394
404
|
}, {
|
|
395
405
|
label: "V2 readiness",
|
|
396
|
-
value: `${s.v2Ready ? "Ready" : "
|
|
406
|
+
value: `${s.v2Ready ? "Ready" : "Not ready"} \xB7 ${s.v2ConsolidatedThreads}/${s.minConsolidatedThreads} sessions`,
|
|
397
407
|
tone: s.v2Ready ? "ok" : "muted"
|
|
398
|
-
}, ...
|
|
408
|
+
}, ...s.v2NotReadyReason ? [{
|
|
409
|
+
label: "V2 not ready",
|
|
410
|
+
value: s.v2NotReadyReason,
|
|
411
|
+
tone: "muted"
|
|
412
|
+
}] : [], ...s.v2SummaryBytes !== undefined ? [{
|
|
413
|
+
label: "V2 summary",
|
|
414
|
+
value: s.v2SummaryBytes === null ? "Unreadable" : `${s.v2SummaryBytes} UTF-8 bytes \xB7 limit <10000`,
|
|
415
|
+
tone: s.v2SummaryBytes !== null && s.v2SummaryBytes >= 1e4 ? "warn" : "muted"
|
|
416
|
+
}] : [], ...pipelineRows(s, now), {
|
|
399
417
|
label: "Use memories",
|
|
400
418
|
value: s.useMemories ? "On" : "Off",
|
|
401
419
|
tone: s.useMemories ? "ok" : "muted"
|
package/dist/src/workspace.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ import { type WorkspaceDiff } from "./git-baseline.js";
|
|
|
4
4
|
/** Mirrors codex `remove_memory_symlinks` (workspace.rs): unlink every symlink in the tree, never follow. */
|
|
5
5
|
export declare function removeMemorySymlinks(root?: string): number;
|
|
6
6
|
export declare function ensureLayout(): void;
|
|
7
|
+
/** Same Codex predicate, with content-free diagnostics for inspect and failed jobs. */
|
|
8
|
+
export declare function validateV2Summary(summary: string): {
|
|
9
|
+
ok: boolean;
|
|
10
|
+
bytes: number;
|
|
11
|
+
reason: string | null;
|
|
12
|
+
};
|
|
7
13
|
export declare function isValidV2Summary(summary: string): boolean;
|
|
8
14
|
export declare function validateConsolidationArtifacts(root?: string): {
|
|
9
15
|
ok: true;
|
package/dist/src/workspace.js
CHANGED
|
@@ -93,13 +93,24 @@ export function ensureLayout() {
|
|
|
93
93
|
* Invalid artifacts force a consolidator re-run and block baseline reset.
|
|
94
94
|
*/
|
|
95
95
|
const V2_SUMMARY_HEADINGS = ["## User Profile", "## User preferences", "## General Tips", "## What's in Memory"];
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
96
|
+
/** Same Codex predicate, with content-free diagnostics for inspect and failed jobs. */
|
|
97
|
+
export function validateV2Summary(summary) {
|
|
98
|
+
const bytes = Buffer.byteLength(summary, "utf8");
|
|
99
|
+
if (summary.split(/\r?\n/, 1)[0] !== "v1") {
|
|
100
|
+
const hint = summary.startsWith("\uFEFF") ? " (UTF-8 BOM detected)" : "";
|
|
101
|
+
return { ok: false, bytes, reason: `summary must start with the exact line 'v1'${hint}` };
|
|
102
|
+
}
|
|
103
|
+
if (bytes >= 10_000) {
|
|
104
|
+
return { ok: false, bytes, reason: `summary must be under 10000 UTF-8 bytes (got ${bytes})` };
|
|
105
|
+
}
|
|
101
106
|
const lines = summary.split(/\r?\n/).map((line) => line.trim());
|
|
102
|
-
|
|
107
|
+
const missing = V2_SUMMARY_HEADINGS.filter((heading) => !lines.includes(heading));
|
|
108
|
+
return missing.length
|
|
109
|
+
? { ok: false, bytes, reason: `missing required headings: ${missing.join(", ")}` }
|
|
110
|
+
: { ok: true, bytes, reason: null };
|
|
111
|
+
}
|
|
112
|
+
export function isValidV2Summary(summary) {
|
|
113
|
+
return validateV2Summary(summary).ok;
|
|
103
114
|
}
|
|
104
115
|
export function validateConsolidationArtifacts(root = memoryRoot()) {
|
|
105
116
|
return validateConsolidationArtifactsForVersion(root, "v1");
|
|
@@ -141,8 +152,10 @@ export function validateConsolidationArtifactsForVersion(root = memoryRoot(), ve
|
|
|
141
152
|
if (first !== "v1") {
|
|
142
153
|
return { ok: false, reason: `memory summary artifact does not start with v1: ${summaryPath}` };
|
|
143
154
|
}
|
|
144
|
-
if (version === "v2"
|
|
145
|
-
|
|
155
|
+
if (version === "v2") {
|
|
156
|
+
const validation = validateV2Summary(summary);
|
|
157
|
+
if (!validation.ok)
|
|
158
|
+
return { ok: false, reason: `invalid v2 memory summary: ${validation.reason}` };
|
|
146
159
|
}
|
|
147
160
|
return { ok: true };
|
|
148
161
|
}
|
package/dist/tools/control.js
CHANGED
|
@@ -272,7 +272,7 @@ function phase2NoteLines(phase2) {
|
|
|
272
272
|
export const memory_inspect = tool({
|
|
273
273
|
description: "Inspect the current memory state. Returns: stage1_outputs count, stage-1 job status " +
|
|
274
274
|
"breakdown, failure classes (backoff / provider_capacity / other_exhausted), recent errors, " +
|
|
275
|
-
"Phase 2 job status (including last error / retry time), " +
|
|
275
|
+
"Phase 2 job status (including per-writer last error / retry time), V2 readiness failure reason and UTF-8 summary bytes, " +
|
|
276
276
|
"last discovery outcome, pipeline diagnostics, memory_summary token estimate " +
|
|
277
277
|
"(on-disk; injection caps at ~2500), a listing of the memories directory, the " +
|
|
278
278
|
"effective plugin options, and any configuration warnings. Use it to verify " +
|
|
@@ -379,8 +379,14 @@ function inspect(args, ctx) {
|
|
|
379
379
|
`read_version: ${peekSessionMemoryVersion(ctx?.sessionID)}`,
|
|
380
380
|
`dual_write: ${pluginOptions.dual_write}`,
|
|
381
381
|
`v2_ready: ${migration.v2Ready}`,
|
|
382
|
+
`v2_not_ready_reason: ${migration.v2NotReadyReason ?? "none"}`,
|
|
383
|
+
`v2_summary_bytes: ${migration.v2SummaryBytes ?? "unknown"} (UTF-8; must be under 10000)`,
|
|
382
384
|
`v2_consolidated_threads: ${migration.v2ConsolidatedThreads} (minimum ${migration.minConsolidatedThreads})`,
|
|
383
|
-
...pipelines.
|
|
385
|
+
...pipelines.flatMap((p) => [
|
|
386
|
+
`pipeline_${p.version}: outputs=${p.stage1Count}, phase2=${p.phase2?.status ?? "none"}, root=${p.root}`,
|
|
387
|
+
` pipeline_${p.version}_phase2_last_error: ${p.phase2?.last_error ?? "none"}`,
|
|
388
|
+
` pipeline_${p.version}_phase2_retry_at: ${fmtUnixSec(p.phase2?.retry_at ?? null)}`,
|
|
389
|
+
]),
|
|
384
390
|
...stage1Lines,
|
|
385
391
|
...phase2Lines,
|
|
386
392
|
discoveryLine,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-codex-memory",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.8",
|
|
4
4
|
"description": "Persistent memory plugin for opencode — ports codex's two-phase memory system (extraction → consolidation → injection → citation feedback)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|