opencode-codex-memory 0.10.3 → 0.12.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 +7 -4
- package/dist/gui-experimental.cjs +1 -0
- package/dist/src/capture.d.ts +2 -2
- package/dist/src/capture.js +4 -4
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +7 -2
- package/dist/src/phase1.d.ts +11 -1
- package/dist/src/phase1.js +37 -21
- package/dist/src/phase2.d.ts +2 -0
- package/dist/src/phase2.js +1 -1
- package/dist/src/pipeline.d.ts +4 -1
- package/dist/src/pipeline.js +42 -25
- package/dist/src/recovery-info.d.ts +30 -0
- package/dist/src/recovery-info.js +33 -0
- package/dist/src/recovery-status.d.ts +10 -0
- package/dist/src/recovery-status.js +54 -0
- package/dist/src/retry.d.ts +14 -0
- package/dist/src/retry.js +147 -0
- package/dist/src/store.d.ts +11 -3
- package/dist/src/store.js +72 -17
- package/dist/src/v2/gui.d.ts +4 -0
- package/dist/src/v2/panel-messages.d.ts +52 -0
- package/dist/src/v2/panel-messages.js +198 -0
- package/dist/src/v2/panel-status.d.ts +24 -0
- package/dist/src/v2/panel-status.js +212 -0
- package/dist/src/v2/plugin.js +21 -2
- package/dist/src/v2/status-rpc.d.ts +95 -1
- package/dist/src/v2/status-rpc.js +71 -3
- package/dist/src/v2/status.js +50 -28
- package/dist/src/v2/tools.js +3 -2
- package/dist/src/v2/tui.js +707 -266
- package/dist/tools/control.d.ts +1 -0
- package/dist/tools/control.js +81 -4
- package/package.json +12 -9
package/dist/tools/control.d.ts
CHANGED
package/dist/tools/control.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "fs";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { tool } from "@opencode-ai/plugin";
|
|
4
4
|
import { allMemoryRoots, memoryDbPath, memoryRoot, memorySummaryPath, sessionMetaDbPath, dataRoot, memoryHomeSource, } from "../src/paths.js";
|
|
5
|
-
import { clearAllVersionMemoryData, MemoryStore, PHASE2_COOLDOWN_MS } from "../src/store.js";
|
|
5
|
+
import { clearAllVersionMemoryData, existingMemoryStores, MemoryStore, PHASE2_COOLDOWN_MS } from "../src/store.js";
|
|
6
6
|
import { invalidateCache } from "../src/source.js";
|
|
7
7
|
import { estimateTokens } from "../src/token.js";
|
|
8
8
|
import { assertMemoryRootSafe, readRegularFileNoFollow } from "../src/path-guard.js";
|
|
@@ -17,6 +17,9 @@ import { activeProviderCapacityBackoffs } from "../src/ratelimit.js";
|
|
|
17
17
|
import { readMigrationStatus, memoryPipelineSnapshots } from "../src/migration.js";
|
|
18
18
|
import { peekSessionMemoryVersion } from "../src/session-version.js";
|
|
19
19
|
import { withMemoryVersion, writeMemoryVersions } from "../src/memory-version.js";
|
|
20
|
+
import { MEMORY_RETRY_PHASES, modelRecoveryGuidance } from "../src/recovery-info.js";
|
|
21
|
+
import { recoveryNotices } from "../src/recovery-status.js";
|
|
22
|
+
import { clearMemoryRetryResult, memoryRetryBlockedReason, memoryRetryStatus, requestMemoryRetry, } from "../src/retry.js";
|
|
20
23
|
function isSymlinkedRoot() {
|
|
21
24
|
for (const root of allMemoryRoots()) {
|
|
22
25
|
try {
|
|
@@ -185,6 +188,8 @@ function renderAgentHealth() {
|
|
|
185
188
|
function resetBlockedReason() {
|
|
186
189
|
if (isSymlinkedRoot())
|
|
187
190
|
return "Reset refused: memory root is a symlink. Remove it manually to be safe.";
|
|
191
|
+
if (memoryRetryStatus()?.state === "running")
|
|
192
|
+
return "Wait for the current memory retry to finish.";
|
|
188
193
|
// Cheap preflight. The DB barrier checks both writers again after approval.
|
|
189
194
|
if (isPhase2InFlight())
|
|
190
195
|
return "Reset refused: memory consolidation is currently running. Try again in a few minutes.";
|
|
@@ -203,6 +208,7 @@ export function performMemoryReset() {
|
|
|
203
208
|
// codex keeps its state DB pool open across resets (clear_memory_roots_contents
|
|
204
209
|
// only wipes directories); closing here would strand cached handles elsewhere.
|
|
205
210
|
invalidateCache();
|
|
211
|
+
clearMemoryRetryResult();
|
|
206
212
|
return {
|
|
207
213
|
ok: true,
|
|
208
214
|
message: "Memory reset complete. Extracted memories and jobs cleared, memories directory (incl. git history) wiped, cache invalidated. Per-session memory modes were preserved.",
|
|
@@ -264,14 +270,53 @@ function phase2NoteLines(phase2) {
|
|
|
264
270
|
return ["phase2_note: idle, cooldown elapsed"];
|
|
265
271
|
return [];
|
|
266
272
|
}
|
|
273
|
+
function inspectRecovery(writers, now) {
|
|
274
|
+
const notices = recoveryNotices(writers, now);
|
|
275
|
+
const latest = memoryRetryStatus();
|
|
276
|
+
const blocked = memoryRetryBlockedReason() ?? null;
|
|
277
|
+
const phases = blocked
|
|
278
|
+
? []
|
|
279
|
+
: MEMORY_RETRY_PHASES.filter((phase) => notices.some((notice) => notice.retryPhase === phase));
|
|
280
|
+
const lines = [
|
|
281
|
+
"Recovery:",
|
|
282
|
+
...(latest ? [` Latest ${latest.phase} retry (${latest.state}): ${latest.message}`] : []),
|
|
283
|
+
...notices.map(({ phase, kind, version, detail, sessionID, retryAt }) => {
|
|
284
|
+
const label = `${phase ?? "memory"}${version ? ` (${version})` : ""}${sessionID ? ` for ${sessionID}` : ""}`;
|
|
285
|
+
const error = kind === "provider_capacity"
|
|
286
|
+
? `Provider rate limit or quota${detail ? `: ${detail}` : ""}`
|
|
287
|
+
: (detail ?? "A background memory job failed.");
|
|
288
|
+
const advice = kind === "provider_capacity"
|
|
289
|
+
? "Wait for the provider limit to clear. Backup models can help on future runs."
|
|
290
|
+
: phase
|
|
291
|
+
? modelRecoveryGuidance([detail ?? ""], phase)?.description
|
|
292
|
+
: undefined;
|
|
293
|
+
return [
|
|
294
|
+
` ${label}${kind === "extraction_exhausted" ? " ran out of retries" : ""}: ${error}`,
|
|
295
|
+
...(retryAt !== undefined
|
|
296
|
+
? [` Automatic retry after ${new Date(retryAt).toISOString()} on OpenCode activity.`]
|
|
297
|
+
: []),
|
|
298
|
+
...(advice ? [` ${advice}`] : []),
|
|
299
|
+
].join("\n");
|
|
300
|
+
}),
|
|
301
|
+
...(blocked
|
|
302
|
+
? [` Manual retry unavailable: ${blocked}`]
|
|
303
|
+
: phases.length
|
|
304
|
+
? phases.map((phase) => ` After fixing the issue, call memory_retry({"phase":"${phase}"}).`)
|
|
305
|
+
: [" No failed work is ready for a manual retry."]),
|
|
306
|
+
];
|
|
307
|
+
return {
|
|
308
|
+
lines,
|
|
309
|
+
metadata: { notices, retryable_phases: phases, blocked_reason: blocked, latest_retry: latest },
|
|
310
|
+
};
|
|
311
|
+
}
|
|
267
312
|
export const memory_inspect = tool({
|
|
268
313
|
description: "Inspect the current memory state. Returns: stage1_outputs count, stage-1 job status " +
|
|
269
|
-
"breakdown, failure classes (backoff / provider_capacity / other_exhausted), recent errors, " +
|
|
314
|
+
"breakdown, failure classes (backoff / provider_capacity / other_exhausted), recent errors, recovery steps, " +
|
|
270
315
|
"Phase 2 job status (including per-writer last error / retry time), V2 readiness failure reason and UTF-8 summary bytes, " +
|
|
271
316
|
"last discovery outcome, pipeline diagnostics, memory_summary token estimate " +
|
|
272
317
|
"(on-disk; injection caps at ~2500), a listing of the memories directory, the " +
|
|
273
318
|
"effective plugin options, and any configuration warnings. Use it to verify " +
|
|
274
|
-
"configuration and
|
|
319
|
+
"configuration, diagnose failed jobs, and see the latest memory_retry outcome. Read-only.",
|
|
275
320
|
args: {
|
|
276
321
|
min_consolidated_threads: tool.schema
|
|
277
322
|
.number()
|
|
@@ -291,7 +336,8 @@ function inspect(args, ctx) {
|
|
|
291
336
|
assertMemoryRootSafe();
|
|
292
337
|
const store = new MemoryStore();
|
|
293
338
|
const outputs = store.stage1Outputs();
|
|
294
|
-
const
|
|
339
|
+
const now = Date.now();
|
|
340
|
+
const staleBeforeSec = Math.floor(now / 1000) - pluginOptions.max_rollout_age_days * 86_400;
|
|
295
341
|
const stage1Jobs = store.stage1JobSnapshot(staleBeforeSec);
|
|
296
342
|
const summaryPath = memorySummaryPath();
|
|
297
343
|
let summaryChars = 0;
|
|
@@ -303,6 +349,16 @@ function inspect(args, ctx) {
|
|
|
303
349
|
}
|
|
304
350
|
const listing = listMemoriesDir();
|
|
305
351
|
const phase2 = store.phase2JobSnapshot();
|
|
352
|
+
const writeVersions = writeMemoryVersions();
|
|
353
|
+
const recovery = inspectRecovery(existingMemoryStores()
|
|
354
|
+
.filter((writer) => writeVersions.includes(writer.version))
|
|
355
|
+
.map((writer) => writer.version === store.version
|
|
356
|
+
? { version: writer.version, phase1: stage1Jobs, phase2 }
|
|
357
|
+
: {
|
|
358
|
+
version: writer.version,
|
|
359
|
+
phase1: writer.stage1JobSnapshot(staleBeforeSec),
|
|
360
|
+
phase2: writer.phase2JobSnapshot(),
|
|
361
|
+
}), now);
|
|
306
362
|
const phase2Lines = phase2
|
|
307
363
|
? [
|
|
308
364
|
`phase2_status: ${phase2.status}`,
|
|
@@ -370,6 +426,8 @@ function inspect(args, ctx) {
|
|
|
370
426
|
? ["recent_events:", ...diagnostics.map((e) => ` ${formatDiagnosticLine(e)}`)]
|
|
371
427
|
: ["recent_events: none"];
|
|
372
428
|
const out = [
|
|
429
|
+
...recovery.lines,
|
|
430
|
+
"",
|
|
373
431
|
`stage1_outputs: ${outputs.length}`,
|
|
374
432
|
`read_version: ${peekSessionMemoryVersion(ctx?.sessionID)}`,
|
|
375
433
|
`dual_write: ${pluginOptions.dual_write}`,
|
|
@@ -405,6 +463,7 @@ function inspect(args, ctx) {
|
|
|
405
463
|
return {
|
|
406
464
|
output: out,
|
|
407
465
|
metadata: {
|
|
466
|
+
recovery: recovery.metadata,
|
|
408
467
|
stage1_count: outputs.length,
|
|
409
468
|
migration,
|
|
410
469
|
pipelines,
|
|
@@ -486,3 +545,21 @@ export const memory_mode = tool({
|
|
|
486
545
|
}
|
|
487
546
|
},
|
|
488
547
|
});
|
|
548
|
+
export const memory_retry = tool({
|
|
549
|
+
description: "On the user's explicit request, retry failed memory extraction or consolidation once with current background models. " +
|
|
550
|
+
"This runs only the selected phase and returns its outcome. It skips ordinary failure delays but respects provider " +
|
|
551
|
+
"rate limits, active work, learning settings, and session eligibility. Use memory_inspect to diagnose failures or " +
|
|
552
|
+
"check the latest outcome. Do not keep retrying after a failure or blocked result.",
|
|
553
|
+
args: {
|
|
554
|
+
phase: tool.schema.enum(MEMORY_RETRY_PHASES).describe("Retry failed session extraction or a failed memory update."),
|
|
555
|
+
},
|
|
556
|
+
async execute({ phase }, ctx) {
|
|
557
|
+
ctx.abort?.throwIfAborted();
|
|
558
|
+
const request = requestMemoryRetry(phase, ctx.sessionID);
|
|
559
|
+
const retry = request.ok ? await request.completion : { phase, state: "blocked", message: request.message };
|
|
560
|
+
return {
|
|
561
|
+
output: `Memory ${retry.phase} retry (${retry.state}): ${retry.message}`,
|
|
562
|
+
metadata: { retry },
|
|
563
|
+
};
|
|
564
|
+
},
|
|
565
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-codex-memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
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",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"types": "./dist/src/tui.d.ts",
|
|
22
22
|
"import": "./dist/src/tui.js"
|
|
23
23
|
},
|
|
24
|
+
"./gui-experimental": "./dist/gui-experimental.cjs",
|
|
24
25
|
"./tools/*": {
|
|
25
26
|
"import": "./dist/tools/*.js",
|
|
26
27
|
"types": "./dist/tools/*.d.ts"
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
},
|
|
44
45
|
"scripts": {
|
|
45
46
|
"dev": "bun --watch src/index.ts",
|
|
46
|
-
"build": "rm -rf dist && tsc && bun scripts/build-tui.ts && cp -R src/templates dist/src/templates && cp opencode.json dist/opencode.json",
|
|
47
|
+
"build": "rm -rf dist && tsc && bun scripts/build-tui.ts && bun scripts/build-gui.ts && cp -R src/templates dist/src/templates && cp opencode.json dist/opencode.json",
|
|
47
48
|
"smoke": "bun scripts/smoke.ts",
|
|
48
49
|
"contract": "bun scripts/check-opencode-contract.ts",
|
|
49
50
|
"contract:v2": "bun scripts/check-opencode2-contract.ts",
|
|
@@ -66,20 +67,22 @@
|
|
|
66
67
|
"license": "Apache-2.0",
|
|
67
68
|
"dependencies": {
|
|
68
69
|
"@opencode-ai/plugin": "1.19.6",
|
|
69
|
-
"@opencode/client": "2.4.
|
|
70
|
+
"@opencode/client": "2.4.4",
|
|
70
71
|
"diff": "9.0.0",
|
|
71
|
-
"isomorphic-git": "1.
|
|
72
|
+
"isomorphic-git": "1.45.0",
|
|
72
73
|
"xdg-basedir": "5.1.0"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
|
-
"@opencode/plugin": "2.4.
|
|
76
|
-
"@opencode/theme": "2.4.
|
|
77
|
-
"@opentui/core": "0.9.
|
|
78
|
-
"@opentui/solid": "0.9.
|
|
76
|
+
"@opencode/plugin": "2.4.4",
|
|
77
|
+
"@opencode/theme": "2.4.4",
|
|
78
|
+
"@opentui/core": "0.9.12",
|
|
79
|
+
"@opentui/solid": "0.9.12",
|
|
79
80
|
"@types/bun": "1.4.5",
|
|
80
81
|
"prettier": "3.10.1",
|
|
81
82
|
"solid-js": "1.9.20",
|
|
82
|
-
"typescript": "
|
|
83
|
+
"typescript": "7.0.2",
|
|
84
|
+
"vite": "8.4.1",
|
|
85
|
+
"vite-plugin-solid": "2.11.17"
|
|
83
86
|
},
|
|
84
87
|
"peerDependencies": {
|
|
85
88
|
"@opencode/client": ">=2.0.3",
|