opencode-codex-memory 0.7.5 → 0.7.7
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 +8 -8
- package/dist/src/diagnostics.js +5 -1
- package/dist/src/index.js +32 -5
- package/dist/src/local-session-times.d.ts +6 -0
- package/dist/src/local-session-times.js +59 -0
- package/dist/src/options.d.ts +6 -0
- package/dist/src/options.js +1 -0
- package/dist/src/ratelimit.js +4 -0
- package/dist/src/store.d.ts +9 -2
- package/dist/src/store.js +45 -14
- package/dist/src/v2/citation-overlay.d.ts +1 -1
- package/dist/src/v2/citation-overlay.js +8 -3
- package/dist/src/v2/plugin.js +3 -2
- package/dist/src/v2/shim.js +15 -8
- package/dist/src/v2/status.js +7 -3
- package/dist/tools/control.js +25 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ If you want the mental model — learning, remembering, forgetting — see
|
|
|
53
53
|
|
|
54
54
|
```json
|
|
55
55
|
{
|
|
56
|
-
"plugin": ["opencode-codex-memory@0.7.
|
|
56
|
+
"plugin": ["opencode-codex-memory@0.7.7"]
|
|
57
57
|
}
|
|
58
58
|
```
|
|
59
59
|
|
|
@@ -73,7 +73,7 @@ V2 plugin syntax:
|
|
|
73
73
|
|
|
74
74
|
```jsonc
|
|
75
75
|
{
|
|
76
|
-
"plugins": [{ "package": "opencode-codex-memory@0.7.
|
|
76
|
+
"plugins": [{ "package": "opencode-codex-memory@0.7.7" }],
|
|
77
77
|
}
|
|
78
78
|
```
|
|
79
79
|
|
|
@@ -208,7 +208,7 @@ To set options, turn the plugin entry into a `[name, options]` pair:
|
|
|
208
208
|
```json
|
|
209
209
|
{
|
|
210
210
|
"plugin": [
|
|
211
|
-
["opencode-codex-memory@0.7.
|
|
211
|
+
["opencode-codex-memory@0.7.7", { "disable_on_external_context": true, "min_rollout_idle_hours": 2 }]
|
|
212
212
|
]
|
|
213
213
|
}
|
|
214
214
|
```
|
|
@@ -280,7 +280,7 @@ dedicated directory:
|
|
|
280
280
|
```json
|
|
281
281
|
{
|
|
282
282
|
"plugin": [
|
|
283
|
-
["opencode-codex-memory@0.7.
|
|
283
|
+
["opencode-codex-memory@0.7.7", { "home": "/path/to/opencode-memory" }]
|
|
284
284
|
]
|
|
285
285
|
}
|
|
286
286
|
```
|
|
@@ -290,7 +290,7 @@ OpenCode 2:
|
|
|
290
290
|
```jsonc
|
|
291
291
|
{
|
|
292
292
|
"plugins": [
|
|
293
|
-
{ "package": "opencode-codex-memory@0.7.
|
|
293
|
+
{ "package": "opencode-codex-memory@0.7.7", "options": { "home": "/path/to/opencode-memory" } }
|
|
294
294
|
]
|
|
295
295
|
}
|
|
296
296
|
```
|
|
@@ -325,7 +325,7 @@ Off by default; no changes to Codex's own config are required.
|
|
|
325
325
|
{
|
|
326
326
|
"plugin": [
|
|
327
327
|
[
|
|
328
|
-
"opencode-codex-memory@0.7.
|
|
328
|
+
"opencode-codex-memory@0.7.7",
|
|
329
329
|
{ "codex_interop": { "import": true, "export": true } }
|
|
330
330
|
]
|
|
331
331
|
]
|
|
@@ -382,7 +382,7 @@ from the project memories Claude already keeps on your machine. **One-way only**
|
|
|
382
382
|
```json
|
|
383
383
|
{
|
|
384
384
|
"plugin": [
|
|
385
|
-
["opencode-codex-memory@0.7.
|
|
385
|
+
["opencode-codex-memory@0.7.7", { "claude_import": { "enabled": true } }]
|
|
386
386
|
]
|
|
387
387
|
}
|
|
388
388
|
```
|
|
@@ -409,7 +409,7 @@ Claude names each project with an opaque id (a folder under
|
|
|
409
409
|
{
|
|
410
410
|
"plugin": [
|
|
411
411
|
[
|
|
412
|
-
"opencode-codex-memory@0.7.
|
|
412
|
+
"opencode-codex-memory@0.7.7",
|
|
413
413
|
{
|
|
414
414
|
"claude_import": {
|
|
415
415
|
"enabled": true,
|
package/dist/src/diagnostics.js
CHANGED
|
@@ -13,11 +13,15 @@ export function recordDiagnostic(level, kind, message) {
|
|
|
13
13
|
events.shift();
|
|
14
14
|
}
|
|
15
15
|
export function recordDiscoveryStatus(status) {
|
|
16
|
+
const prev = discovery;
|
|
16
17
|
discovery = { ...status, at: Date.now() };
|
|
17
18
|
if (!status.ok) {
|
|
18
19
|
recordDiagnostic("warn", "discovery", status.error ?? "session discovery failed");
|
|
20
|
+
return;
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
// Same count every 30s cache hit is not a pipeline event — only log
|
|
23
|
+
// changes (or the first success) so inspect is not 12× "listed 1".
|
|
24
|
+
if (!prev || !prev.ok || prev.count !== status.count) {
|
|
21
25
|
recordDiagnostic("info", "discovery", `listed ${status.count} session(s)`);
|
|
22
26
|
}
|
|
23
27
|
}
|
package/dist/src/index.js
CHANGED
|
@@ -170,6 +170,7 @@ const KNOWN_OPTION_KEYS = new Set([
|
|
|
170
170
|
"max_rollout_age_days",
|
|
171
171
|
"max_rollouts_per_startup",
|
|
172
172
|
"min_rollout_idle_hours",
|
|
173
|
+
"test",
|
|
173
174
|
"home",
|
|
174
175
|
"codex_interop",
|
|
175
176
|
"claude_import",
|
|
@@ -186,6 +187,14 @@ function clampInt(key, value, min, max, fallback) {
|
|
|
186
187
|
}
|
|
187
188
|
return Math.min(max, Math.max(min, Math.floor(value)));
|
|
188
189
|
}
|
|
190
|
+
/** Finite number, no Codex range clamp. Used only when options.test is true. */
|
|
191
|
+
function finiteNumber(key, value, fallback) {
|
|
192
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
193
|
+
recordConfigWarning(`${key} must be a finite number; using default ${fallback}`);
|
|
194
|
+
return fallback;
|
|
195
|
+
}
|
|
196
|
+
return value;
|
|
197
|
+
}
|
|
189
198
|
export function applyPluginOptions(opts) {
|
|
190
199
|
// Fresh pass per apply so memory_inspect never shows warnings for keys the
|
|
191
200
|
// caller has since fixed. server() clears too, for boots without options.
|
|
@@ -209,6 +218,13 @@ export function applyPluginOptions(opts) {
|
|
|
209
218
|
else
|
|
210
219
|
recordConfigWarning(`${key} must be a boolean; using default ${pluginOptions[key]}`);
|
|
211
220
|
}
|
|
221
|
+
// options.test: live-harness only. Skips MemoriesToml numeric clamps.
|
|
222
|
+
if ("test" in raw) {
|
|
223
|
+
if (typeof raw.test === "boolean")
|
|
224
|
+
pluginOptions.test = raw.test;
|
|
225
|
+
else
|
|
226
|
+
recordConfigWarning("test must be a boolean; using default false");
|
|
227
|
+
}
|
|
212
228
|
for (const key of ["extract_model", "consolidation_model"]) {
|
|
213
229
|
if (!(key in raw))
|
|
214
230
|
continue;
|
|
@@ -217,16 +233,27 @@ export function applyPluginOptions(opts) {
|
|
|
217
233
|
else
|
|
218
234
|
recordConfigWarning(`${key} must be a string; using the opencode model default`);
|
|
219
235
|
}
|
|
236
|
+
const testing = pluginOptions.test;
|
|
220
237
|
if ("max_raw_memories_for_consolidation" in opts)
|
|
221
|
-
pluginOptions.max_raw_memories_for_consolidation =
|
|
238
|
+
pluginOptions.max_raw_memories_for_consolidation = testing
|
|
239
|
+
? finiteNumber("max_raw_memories_for_consolidation", opts.max_raw_memories_for_consolidation, 256)
|
|
240
|
+
: clampInt("max_raw_memories_for_consolidation", opts.max_raw_memories_for_consolidation, 1, 4096, 256);
|
|
222
241
|
if ("max_unused_days" in opts)
|
|
223
|
-
pluginOptions.max_unused_days =
|
|
242
|
+
pluginOptions.max_unused_days = testing
|
|
243
|
+
? finiteNumber("max_unused_days", opts.max_unused_days, 30)
|
|
244
|
+
: clampInt("max_unused_days", opts.max_unused_days, 0, 365, 30);
|
|
224
245
|
if ("max_rollout_age_days" in opts)
|
|
225
|
-
pluginOptions.max_rollout_age_days =
|
|
246
|
+
pluginOptions.max_rollout_age_days = testing
|
|
247
|
+
? finiteNumber("max_rollout_age_days", opts.max_rollout_age_days, 10)
|
|
248
|
+
: clampInt("max_rollout_age_days", opts.max_rollout_age_days, 0, 90, 10);
|
|
226
249
|
if ("max_rollouts_per_startup" in opts)
|
|
227
|
-
pluginOptions.max_rollouts_per_startup =
|
|
250
|
+
pluginOptions.max_rollouts_per_startup = testing
|
|
251
|
+
? finiteNumber("max_rollouts_per_startup", opts.max_rollouts_per_startup, 2)
|
|
252
|
+
: clampInt("max_rollouts_per_startup", opts.max_rollouts_per_startup, 1, 128, 2);
|
|
228
253
|
if ("min_rollout_idle_hours" in opts)
|
|
229
|
-
pluginOptions.min_rollout_idle_hours =
|
|
254
|
+
pluginOptions.min_rollout_idle_hours = testing
|
|
255
|
+
? finiteNumber("min_rollout_idle_hours", opts.min_rollout_idle_hours, 6)
|
|
256
|
+
: clampInt("min_rollout_idle_hours", opts.min_rollout_idle_hours, 1, 48, 6);
|
|
230
257
|
if ("home" in raw) {
|
|
231
258
|
if (typeof raw.home !== "string") {
|
|
232
259
|
recordConfigWarning("home must be a string; using the OpenCode data dir");
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox/live-test helper: read session watermarks from the isolated
|
|
3
|
+
* OpenCode db. Only looks at OPENCODE_CODEX_MEMORY_TEST_ROOT (never the
|
|
4
|
+
* host ~/.local/share/opencode db).
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync } from "fs";
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
import { Database } from "bun:sqlite";
|
|
9
|
+
export function localSessionUpdatedAt() {
|
|
10
|
+
const out = new Map();
|
|
11
|
+
const testRoot = process.env.OPENCODE_CODEX_MEMORY_TEST_ROOT?.trim();
|
|
12
|
+
if (!testRoot)
|
|
13
|
+
return out;
|
|
14
|
+
const dbPath = join(testRoot, "opencode.db");
|
|
15
|
+
if (!existsSync(dbPath))
|
|
16
|
+
return out;
|
|
17
|
+
try {
|
|
18
|
+
const db = new Database(dbPath, { readonly: true, strict: false });
|
|
19
|
+
try {
|
|
20
|
+
const names = new Set(db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all().map((r) => r.name));
|
|
21
|
+
const table = names.has("session_v2") ? "session_v2" : names.has("session") ? "session" : null;
|
|
22
|
+
if (!table)
|
|
23
|
+
return out;
|
|
24
|
+
const rows = db.prepare(`SELECT id, time_updated FROM "${table}"`).all();
|
|
25
|
+
for (const row of rows) {
|
|
26
|
+
if (!row.id || typeof row.time_updated !== "number")
|
|
27
|
+
continue;
|
|
28
|
+
out.set(row.id, row.time_updated);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
db.close();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Isolated serve without a readable db: keep host list as-is.
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
export function overlaySqliteSessionTimes(rows) {
|
|
41
|
+
const times = localSessionUpdatedAt();
|
|
42
|
+
if (times.size === 0)
|
|
43
|
+
return rows;
|
|
44
|
+
return rows.map((row) => {
|
|
45
|
+
if (!row || typeof row !== "object")
|
|
46
|
+
return row;
|
|
47
|
+
const rec = row;
|
|
48
|
+
if (typeof rec.id !== "string" || !times.has(rec.id))
|
|
49
|
+
return row;
|
|
50
|
+
const updated = times.get(rec.id);
|
|
51
|
+
return { ...rec, time: { ...(typeof rec.time === "object" && rec.time ? rec.time : {}), updated } };
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export function overlaySqliteUpdatedAt(rows) {
|
|
55
|
+
const times = localSessionUpdatedAt();
|
|
56
|
+
if (times.size === 0)
|
|
57
|
+
return rows;
|
|
58
|
+
return rows.map((row) => (times.has(row.id) ? { ...row, updated_at: times.get(row.id) } : row));
|
|
59
|
+
}
|
package/dist/src/options.d.ts
CHANGED
|
@@ -25,6 +25,12 @@ export interface PluginOptionsState {
|
|
|
25
25
|
max_rollout_age_days: number;
|
|
26
26
|
max_rollouts_per_startup: number;
|
|
27
27
|
min_rollout_idle_hours: number;
|
|
28
|
+
/**
|
|
29
|
+
* Live-harness only. Not a Codex knob. When true, numeric ranges are not
|
|
30
|
+
* clamped to MemoriesToml so tests can use e.g. min_rollout_idle_hours: 0.01.
|
|
31
|
+
* Production configs must leave this unset.
|
|
32
|
+
*/
|
|
33
|
+
test: boolean;
|
|
28
34
|
codex_interop: CodexInteropOptions;
|
|
29
35
|
claude_import: ClaudeImportOptions;
|
|
30
36
|
}
|
package/dist/src/options.js
CHANGED
package/dist/src/ratelimit.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pluginOptions } from "./options.js";
|
|
1
2
|
export class ProviderCapacityError extends Error {
|
|
2
3
|
statusCode;
|
|
3
4
|
constructor(message, statusCode) {
|
|
@@ -100,6 +101,9 @@ export async function checkRateLimit(kind = "phase1", model) {
|
|
|
100
101
|
// Phase 2: no 30s gate (codex relies on DB claim/cooldown only).
|
|
101
102
|
if (kind === "phase2")
|
|
102
103
|
return { ok: true };
|
|
104
|
+
// Live harness sets options.test; skip the process stampede timer there.
|
|
105
|
+
if (pluginOptions.test)
|
|
106
|
+
return { ok: true };
|
|
103
107
|
const now = Date.now();
|
|
104
108
|
if (now - lastPhase1Work < MIN_PHASE1_INTERVAL_MS) {
|
|
105
109
|
return { ok: false, reason: "phase1 rate limit (30s since last claimed work)" };
|
package/dist/src/store.d.ts
CHANGED
|
@@ -167,18 +167,25 @@ export declare class MemoryStore {
|
|
|
167
167
|
/**
|
|
168
168
|
* Stage-1 job counts + recent failures for memory_inspect. Helps diagnose
|
|
169
169
|
* "nothing is learning" without reading the raw jobs table.
|
|
170
|
+
*
|
|
171
|
+
* `staleBeforeSec`: exhausted jobs finished before this unix-seconds cutoff
|
|
172
|
+
* (typically now − max_rollout_age_days) are counted in `stale_exhausted`
|
|
173
|
+
* and omitted from `recent_errors` so leftover rows from old plugin
|
|
174
|
+
* versions do not bury live due/backoff failures.
|
|
170
175
|
*/
|
|
171
|
-
stage1JobSnapshot(): {
|
|
176
|
+
stage1JobSnapshot(staleBeforeSec?: number): {
|
|
172
177
|
by_status: Record<string, number>;
|
|
173
178
|
by_failure_class: {
|
|
174
179
|
backoff: number;
|
|
175
180
|
provider_capacity: number;
|
|
176
181
|
other_exhausted: number;
|
|
182
|
+
due: number;
|
|
177
183
|
};
|
|
184
|
+
stale_exhausted: number;
|
|
178
185
|
recent_errors: Stage1RecentError[];
|
|
179
186
|
};
|
|
180
187
|
}
|
|
181
|
-
export type Stage1FailureClass = "backoff" | "provider_capacity" | "other_exhausted";
|
|
188
|
+
export type Stage1FailureClass = "backoff" | "provider_capacity" | "other_exhausted" | "due";
|
|
182
189
|
export interface Stage1RecentError {
|
|
183
190
|
session_id: string;
|
|
184
191
|
last_error: string;
|
package/dist/src/store.js
CHANGED
|
@@ -650,8 +650,13 @@ export class MemoryStore {
|
|
|
650
650
|
/**
|
|
651
651
|
* Stage-1 job counts + recent failures for memory_inspect. Helps diagnose
|
|
652
652
|
* "nothing is learning" without reading the raw jobs table.
|
|
653
|
+
*
|
|
654
|
+
* `staleBeforeSec`: exhausted jobs finished before this unix-seconds cutoff
|
|
655
|
+
* (typically now − max_rollout_age_days) are counted in `stale_exhausted`
|
|
656
|
+
* and omitted from `recent_errors` so leftover rows from old plugin
|
|
657
|
+
* versions do not bury live due/backoff failures.
|
|
653
658
|
*/
|
|
654
|
-
stage1JobSnapshot() {
|
|
659
|
+
stage1JobSnapshot(staleBeforeSec) {
|
|
655
660
|
const rows = this.db
|
|
656
661
|
.prepare("SELECT status, COUNT(*) AS c FROM memory_jobs WHERE kind='memory_stage1' GROUP BY status")
|
|
657
662
|
.all();
|
|
@@ -660,36 +665,62 @@ export class MemoryStore {
|
|
|
660
665
|
by_status[r.status] = r.c;
|
|
661
666
|
const tNow = nowSec();
|
|
662
667
|
const errorRows = this.db
|
|
663
|
-
.prepare(`SELECT job_key AS session_id, last_error, retry_at, status, retry_remaining FROM memory_jobs
|
|
668
|
+
.prepare(`SELECT job_key AS session_id, last_error, retry_at, status, retry_remaining, finished_at FROM memory_jobs
|
|
664
669
|
WHERE kind='memory_stage1' AND last_error IS NOT NULL
|
|
665
670
|
ORDER BY COALESCE(finished_at, started_at, 0) DESC`)
|
|
666
671
|
.all();
|
|
667
|
-
const by_failure_class = { backoff: 0, provider_capacity: 0, other_exhausted: 0 };
|
|
668
|
-
const
|
|
672
|
+
const by_failure_class = { backoff: 0, provider_capacity: 0, other_exhausted: 0, due: 0 };
|
|
673
|
+
const live = [];
|
|
674
|
+
let stale_exhausted = 0;
|
|
669
675
|
for (const row of errorRows) {
|
|
670
676
|
const failure_class = classifyStage1Failure(row, tNow);
|
|
671
677
|
if (failure_class)
|
|
672
678
|
by_failure_class[failure_class]++;
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
679
|
+
const entry = {
|
|
680
|
+
session_id: row.session_id,
|
|
681
|
+
last_error: row.last_error,
|
|
682
|
+
retry_at: row.retry_at,
|
|
683
|
+
status: row.status,
|
|
684
|
+
retry_remaining: row.retry_remaining,
|
|
685
|
+
failure_class,
|
|
686
|
+
};
|
|
687
|
+
if (isStaleExhausted(row, staleBeforeSec)) {
|
|
688
|
+
stale_exhausted++;
|
|
689
|
+
continue;
|
|
682
690
|
}
|
|
691
|
+
live.push(entry);
|
|
683
692
|
}
|
|
684
|
-
|
|
693
|
+
live.sort((a, b) => liveErrorRank(a.failure_class) - liveErrorRank(b.failure_class));
|
|
694
|
+
return { by_status, by_failure_class, stale_exhausted, recent_errors: live.slice(0, 5) };
|
|
685
695
|
}
|
|
686
696
|
}
|
|
697
|
+
function liveErrorRank(klass) {
|
|
698
|
+
if (klass === "due")
|
|
699
|
+
return 0;
|
|
700
|
+
if (klass === "backoff")
|
|
701
|
+
return 1;
|
|
702
|
+
if (klass === "provider_capacity")
|
|
703
|
+
return 2;
|
|
704
|
+
if (klass === "other_exhausted")
|
|
705
|
+
return 3;
|
|
706
|
+
return 4;
|
|
707
|
+
}
|
|
708
|
+
function isStaleExhausted(row, staleBeforeSec) {
|
|
709
|
+
if (staleBeforeSec == null)
|
|
710
|
+
return false;
|
|
711
|
+
if (row.status !== "failed" && row.retry_remaining > 0)
|
|
712
|
+
return false;
|
|
713
|
+
const ts = row.finished_at ?? row.retry_at ?? 0;
|
|
714
|
+
return ts > 0 && ts < staleBeforeSec;
|
|
715
|
+
}
|
|
687
716
|
function classifyStage1Failure(row, nowSec) {
|
|
688
717
|
if (row.status === "failed" || row.retry_remaining <= 0) {
|
|
689
718
|
return isProviderCapacityError(row.last_error) ? "provider_capacity" : "other_exhausted";
|
|
690
719
|
}
|
|
691
720
|
if (row.retry_at != null && row.retry_at > nowSec)
|
|
692
721
|
return "backoff";
|
|
722
|
+
if (row.retry_at != null && row.retry_at <= nowSec)
|
|
723
|
+
return "due";
|
|
693
724
|
if (isProviderCapacityError(row.last_error))
|
|
694
725
|
return "provider_capacity";
|
|
695
726
|
return null;
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* the TUI renders fenced `memory-citation` blocks, so the V2 context hook
|
|
4
4
|
* overlays this section onto the shared inject prompt.
|
|
5
5
|
*/
|
|
6
|
-
export declare const V2_CITATION_INSTRUCTIONS = "Memory citation requirements:\n\n- If ANY relevant memory files were used: append exactly one fenced code\n block with the language tag `memory-citation` as the VERY LAST content of\n the final reply.
|
|
6
|
+
export declare const V2_CITATION_INSTRUCTIONS = "Memory citation requirements:\n\n- If ANY relevant memory files were used: append exactly one fenced code\n block with the language tag `memory-citation` as the VERY LAST content of\n the final reply. Answer first, then a blank line, then the block. The\n opening fence must be on its own line at column 0 \u2014 never glue it to the\n last sentence, or markdown clients treat the block as paragraph text and\n collapse its newlines. The host renders this block natively.\n- Use this exact structure for programmatic parsing (blank line before the\n fence is required):\n````\nanswer text ends here.\n\n```memory-citation\nMEMORY.md:234-236|note=build command for the api service\nrollout_summaries/2026-02-17T21-23-02-ln3m-example.md:10-12|note=weekly report format\nsessions: ses_abc123 ses_def456\n```\n````\n- Do not wrap it in `<memory-citation>` XML tags; the fenced form replaces\n that older format.\n- Citation entry lines are for rendering:\n - one citation entry per line\n - format: `<file>:<line_start>-<line_end>|note=<how memory was used>`\n - use file paths relative to the memory base path (for example, `MEMORY.md`,\n `rollout_summaries/...`, `skills/...`)\n - only cite files actually used under the memory base path (do not cite\n workspace files as memory citations)\n - if you used `MEMORY.md` and then a rollout summary/skill file, cite both\n - list entries in order of importance (most important first)\n - `note` should be short, single-line, and use simple characters only (avoid\n unusual symbols, no newlines)\n- The final `sessions:` line is for us to track which past sessions you find\n useful:\n - one line, space-separated session ids after `sessions:`\n - session ids look like `ses_...` and appear in rollout summary files and\n MEMORY.md as `session_id:`\n - include unique ids only; do not repeat ids\n - omit the `sessions:` line if no session ids are available\n - do not include file paths or notes on this line\n - for every citation entry, try to find and cite the corresponding session id\n- Never include memory citations inside pull-request messages.\n- Never cite blank lines; double-check ranges.\n\n";
|
|
7
7
|
export declare function overlayV2CitationInstructions(prompt: string): string;
|
|
@@ -7,10 +7,15 @@ export const V2_CITATION_INSTRUCTIONS = `Memory citation requirements:
|
|
|
7
7
|
|
|
8
8
|
- If ANY relevant memory files were used: append exactly one fenced code
|
|
9
9
|
block with the language tag \`memory-citation\` as the VERY LAST content of
|
|
10
|
-
the final reply.
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
the final reply. Answer first, then a blank line, then the block. The
|
|
11
|
+
opening fence must be on its own line at column 0 — never glue it to the
|
|
12
|
+
last sentence, or markdown clients treat the block as paragraph text and
|
|
13
|
+
collapse its newlines. The host renders this block natively.
|
|
14
|
+
- Use this exact structure for programmatic parsing (blank line before the
|
|
15
|
+
fence is required):
|
|
13
16
|
\`\`\`\`
|
|
17
|
+
answer text ends here.
|
|
18
|
+
|
|
14
19
|
\`\`\`memory-citation
|
|
15
20
|
MEMORY.md:234-236|note=build command for the api service
|
|
16
21
|
rollout_summaries/2026-02-17T21-23-02-ln3m-example.md:10-12|note=weekly report format
|
package/dist/src/v2/plugin.js
CHANGED
|
@@ -278,8 +278,9 @@ export async function setup(ctx) {
|
|
|
278
278
|
resetAgentHealth();
|
|
279
279
|
mcpStatusInFlight = null;
|
|
280
280
|
clearConfigWarnings();
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
const rawOptions = ctx.options;
|
|
282
|
+
if (rawOptions && Object.keys(rawOptions).length > 0)
|
|
283
|
+
applyPluginOptions(rawOptions);
|
|
283
284
|
else {
|
|
284
285
|
const previousDb = memoryDbPath();
|
|
285
286
|
resetPluginOptions();
|
package/dist/src/v2/shim.js
CHANGED
|
@@ -288,16 +288,15 @@ async function v2promptWithWait(sessionID, body, signal) {
|
|
|
288
288
|
if (body.format) {
|
|
289
289
|
const prompt = body.system ? `${body.system}\n\n---\n\n${text}` : text;
|
|
290
290
|
const parsed = body.model ? parseModelRef(`${body.model.providerID}/${body.model.modelID}`) : null;
|
|
291
|
+
// Model.Ref requires providerID + id. A variant is valid only alongside
|
|
292
|
+
// that complete reference; never emit a variant-only model object.
|
|
291
293
|
const payload = {
|
|
292
294
|
prompt,
|
|
293
|
-
...(parsed
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
},
|
|
299
|
-
}
|
|
300
|
-
: {}),
|
|
295
|
+
...(parsed ? { model: {
|
|
296
|
+
providerID: parsed.providerID,
|
|
297
|
+
id: parsed.modelID,
|
|
298
|
+
...(body.variant ? { variant: body.variant } : {}),
|
|
299
|
+
} } : {}),
|
|
301
300
|
};
|
|
302
301
|
if (signal?.aborted)
|
|
303
302
|
throw new Error("sub-agent prompt cancelled");
|
|
@@ -490,6 +489,12 @@ export function buildV1ClientShim() {
|
|
|
490
489
|
}
|
|
491
490
|
},
|
|
492
491
|
delete: async (opts) => {
|
|
492
|
+
// generate.text never creates a host session. Its synthetic handle is
|
|
493
|
+
// released locally; passing it to session APIs fails the ^ses schema.
|
|
494
|
+
if (opts.path.id === EXTRACT_STUB_SESSION_ID) {
|
|
495
|
+
markReleased(opts.path.id);
|
|
496
|
+
return {};
|
|
497
|
+
}
|
|
493
498
|
let shutdownError;
|
|
494
499
|
try {
|
|
495
500
|
const client = await serviceOrThrow();
|
|
@@ -573,6 +578,8 @@ export function buildV1ClientShim() {
|
|
|
573
578
|
}
|
|
574
579
|
},
|
|
575
580
|
abort: async (opts) => {
|
|
581
|
+
if (opts.path.id === EXTRACT_STUB_SESSION_ID)
|
|
582
|
+
return {};
|
|
576
583
|
try {
|
|
577
584
|
const client = await serviceOrThrow();
|
|
578
585
|
if (typeof client.session.interrupt !== "function")
|
package/dist/src/v2/status.js
CHANGED
|
@@ -10,10 +10,11 @@ import { memoryRoot } from "../paths.js";
|
|
|
10
10
|
/** Read the same snapshots as memory_inspect; never claim or advance a job. */
|
|
11
11
|
export function readMemoryStatus(sessionID) {
|
|
12
12
|
const store = new MemoryStore();
|
|
13
|
-
const phase1 = store.stage1JobSnapshot();
|
|
14
|
-
const phase2 = store.phase2JobSnapshot();
|
|
15
13
|
const options = pluginOptions;
|
|
16
14
|
const now = Date.now();
|
|
15
|
+
const staleBeforeSec = Math.floor(now / 1000) - options.max_rollout_age_days * 86_400;
|
|
16
|
+
const phase1 = store.stage1JobSnapshot(staleBeforeSec);
|
|
17
|
+
const phase2 = store.phase2JobSnapshot();
|
|
17
18
|
const session = sessionInjection(sessionID);
|
|
18
19
|
const total = injectionTotals();
|
|
19
20
|
const retryTimes = [
|
|
@@ -30,8 +31,11 @@ export function readMemoryStatus(sessionID) {
|
|
|
30
31
|
}
|
|
31
32
|
if (phase2?.last_error)
|
|
32
33
|
warnings.push("Consolidation failed; see memory_inspect for details.");
|
|
33
|
-
if (phase1.by_failure_class.
|
|
34
|
+
if (phase1.by_failure_class.due > 0)
|
|
35
|
+
warnings.push("Some extraction jobs are due to retry.");
|
|
36
|
+
if (phase1.by_failure_class.other_exhausted > phase1.stale_exhausted) {
|
|
34
37
|
warnings.push("Some extraction jobs exhausted their retries.");
|
|
38
|
+
}
|
|
35
39
|
if (phase1.by_failure_class.provider_capacity > 0)
|
|
36
40
|
warnings.push("Some extraction jobs hit provider capacity limits.");
|
|
37
41
|
const codexImport = options.codex_interop.import && resolveCodexInterop(options.codex_interop) !== null;
|
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 { memoryRoot, memorySummaryPath, dataRoot, memoryHomeSource } from "../src/paths.js";
|
|
5
|
-
import { MemoryStore } from "../src/store.js";
|
|
5
|
+
import { 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";
|
|
@@ -222,6 +222,19 @@ function fmtWatermarkMs(ms) {
|
|
|
222
222
|
return "none";
|
|
223
223
|
return new Date(ms).toISOString();
|
|
224
224
|
}
|
|
225
|
+
function phase2NoteLines(phase2) {
|
|
226
|
+
if (phase2.last_error || phase2.status === "running" || phase2.finished_at == null)
|
|
227
|
+
return [];
|
|
228
|
+
const until = phase2.finished_at + PHASE2_COOLDOWN_MS / 1000;
|
|
229
|
+
const now = Math.floor(Date.now() / 1000);
|
|
230
|
+
if (now < until)
|
|
231
|
+
return [`phase2_note: idle, 6h cooldown until ${fmtUnixSec(until)}`];
|
|
232
|
+
if (phase2.status === "pending")
|
|
233
|
+
return ["phase2_note: pending, cooldown elapsed"];
|
|
234
|
+
if (phase2.status === "done")
|
|
235
|
+
return ["phase2_note: idle, cooldown elapsed"];
|
|
236
|
+
return [];
|
|
237
|
+
}
|
|
225
238
|
export const memory_inspect = tool({
|
|
226
239
|
description: "Inspect the current memory state. Returns: stage1_outputs count, stage-1 job status " +
|
|
227
240
|
"breakdown, failure classes (backoff / provider_capacity / other_exhausted), recent errors, " +
|
|
@@ -237,7 +250,8 @@ export const memory_inspect = tool({
|
|
|
237
250
|
assertMemoryRootSafe();
|
|
238
251
|
const store = new MemoryStore();
|
|
239
252
|
const outputs = store.stage1Outputs();
|
|
240
|
-
const
|
|
253
|
+
const staleBeforeSec = Math.floor(Date.now() / 1000) - pluginOptions.max_rollout_age_days * 86_400;
|
|
254
|
+
const stage1Jobs = store.stage1JobSnapshot(staleBeforeSec);
|
|
241
255
|
const summaryPath = memorySummaryPath();
|
|
242
256
|
let summaryChars = 0;
|
|
243
257
|
let summaryTokens = 0;
|
|
@@ -260,6 +274,7 @@ export const memory_inspect = tool({
|
|
|
260
274
|
`phase2_last_success_watermark: ${fmtWatermarkMs(phase2.last_success_watermark)}`,
|
|
261
275
|
// Clean-success finish only — never a failure timestamp.
|
|
262
276
|
`phase2_last_success_finished_at: ${fmtUnixSec(phase2.success_finished_at)}`,
|
|
277
|
+
...phase2NoteLines(phase2),
|
|
263
278
|
]
|
|
264
279
|
: [
|
|
265
280
|
"phase2_status: none",
|
|
@@ -277,6 +292,7 @@ export const memory_inspect = tool({
|
|
|
277
292
|
.map(([s, c]) => `${s}=${c}`);
|
|
278
293
|
const fc = stage1Jobs.by_failure_class;
|
|
279
294
|
const failureParts = [
|
|
295
|
+
fc.due > 0 ? `due=${fc.due}` : "",
|
|
280
296
|
fc.backoff > 0 ? `backoff=${fc.backoff}` : "",
|
|
281
297
|
fc.provider_capacity > 0 ? `provider_capacity=${fc.provider_capacity}` : "",
|
|
282
298
|
fc.other_exhausted > 0 ? `other_exhausted=${fc.other_exhausted}` : "",
|
|
@@ -284,6 +300,11 @@ export const memory_inspect = tool({
|
|
|
284
300
|
const stage1Lines = [
|
|
285
301
|
`stage1_jobs: ${stage1StatusParts.length > 0 ? stage1StatusParts.join(" ") : "none"}`,
|
|
286
302
|
`stage1_failures: ${failureParts.length > 0 ? failureParts.join(" ") : "none"}`,
|
|
303
|
+
...(stage1Jobs.stale_exhausted > 0
|
|
304
|
+
? [
|
|
305
|
+
`stage1_stale_exhausted: ${stage1Jobs.stale_exhausted} (older than max_rollout_age_days, will not retry)`,
|
|
306
|
+
]
|
|
307
|
+
: []),
|
|
287
308
|
...stage1Jobs.recent_errors.map((e) => {
|
|
288
309
|
const klass = e.failure_class ? `, ${e.failure_class}` : "";
|
|
289
310
|
const retry = e.retry_at ? ` retry_at=${fmtUnixSec(e.retry_at)}` : "";
|
|
@@ -292,7 +313,7 @@ export const memory_inspect = tool({
|
|
|
292
313
|
];
|
|
293
314
|
const discovery = getDiscoveryStatus();
|
|
294
315
|
const discoveryLine = discovery
|
|
295
|
-
? `discovery: ${discovery.ok ? "ok" : "failed"} count=${discovery.count} at=${new Date(discovery.at).toISOString()}${discovery.error ? ` error=${discovery.error}` : ""}`
|
|
316
|
+
? `discovery: ${discovery.ok ? "ok" : "failed"} count=${discovery.count} at=${new Date(discovery.at).toISOString()}${discovery.error ? ` error=${discovery.error}` : ""} (this process's session list, not total chats)`
|
|
296
317
|
: "discovery: never ran (no phase-1 pass yet this process)";
|
|
297
318
|
const idleHours = pluginOptions.min_rollout_idle_hours;
|
|
298
319
|
const eligibilityHint = `eligibility: sessions must be idle ≥ ${idleHours}h and younger than ${pluginOptions.max_rollout_age_days}d ` +
|
|
@@ -337,6 +358,7 @@ export const memory_inspect = tool({
|
|
|
337
358
|
stage1_count: outputs.length,
|
|
338
359
|
stage1_jobs: stage1Jobs.by_status,
|
|
339
360
|
stage1_failures: stage1Jobs.by_failure_class,
|
|
361
|
+
stage1_stale_exhausted: stage1Jobs.stale_exhausted,
|
|
340
362
|
stage1_recent_errors: stage1Jobs.recent_errors,
|
|
341
363
|
phase2_status: phase2?.status ?? null,
|
|
342
364
|
phase2_last_error: phase2?.last_error ?? null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-codex-memory",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
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",
|