opencode-codex-memory 0.8.3 → 0.8.4

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 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.8.3" }
38
+ { "package": "opencode-codex-memory@0.8.4" }
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.8.3"]
48
+ "plugin": ["opencode-codex-memory@0.8.4"]
49
49
  }
50
50
  ```
51
51
 
@@ -22,6 +22,10 @@ export interface MemoryStatus {
22
22
  extracting: number;
23
23
  phase2Status: string | null;
24
24
  lastError: string | null;
25
+ /** Unix milliseconds; optional for older servers. Cooldown is not a retry. */
26
+ phase2CooldownUntil?: number | null;
27
+ phase1RetryAt?: number | null;
28
+ phase2RetryAt?: number | null;
25
29
  }[];
26
30
  useMemories: boolean;
27
31
  generateMemories: boolean;
@@ -117,6 +121,15 @@ export declare const MemoryStatusRpc: {
117
121
  readonly lastError: {
118
122
  readonly type: readonly ["string", "null"];
119
123
  };
124
+ readonly phase2CooldownUntil: {
125
+ readonly type: readonly ["number", "null"];
126
+ };
127
+ readonly phase1RetryAt: {
128
+ readonly type: readonly ["number", "null"];
129
+ };
130
+ readonly phase2RetryAt: {
131
+ readonly type: readonly ["number", "null"];
132
+ };
120
133
  };
121
134
  readonly required: readonly ["version", "stage1Count", "extracting", "phase2Status", "lastError"];
122
135
  readonly additionalProperties: false;
@@ -60,6 +60,9 @@ export const MemoryStatusRpc = {
60
60
  extracting: { type: "integer", minimum: 0 },
61
61
  phase2Status: { type: ["string", "null"] },
62
62
  lastError: { type: ["string", "null"] },
63
+ phase2CooldownUntil: { type: ["number", "null"] },
64
+ phase1RetryAt: { type: ["number", "null"] },
65
+ phase2RetryAt: { type: ["number", "null"] },
63
66
  },
64
67
  required: ["version", "stage1Count", "extracting", "phase2Status", "lastError"],
65
68
  additionalProperties: false,
@@ -162,7 +165,8 @@ export function isMemoryStatus(value) {
162
165
  && Number.isInteger(pipeline.stage1Count) && pipeline.stage1Count >= 0
163
166
  && Number.isInteger(pipeline.extracting) && pipeline.extracting >= 0
164
167
  && (pipeline.phase2Status === null || typeof pipeline.phase2Status === "string")
165
- && (pipeline.lastError === null || typeof pipeline.lastError === "string")))
168
+ && (pipeline.lastError === null || typeof pipeline.lastError === "string")
169
+ && ["phase2CooldownUntil", "phase1RetryAt", "phase2RetryAt"].every((key) => pipeline[key] === undefined || pipeline[key] === null || (typeof pipeline[key] === "number" && Number.isFinite(pipeline[key])))))
166
170
  return false;
167
171
  for (const key of ["extractModel", "consolidationModel", "lastSuccessAt", "retryAt"]) {
168
172
  const v = value[key];
@@ -1,4 +1,4 @@
1
- import { MemoryStore } from "../store.js";
1
+ import { MemoryStore, existingMemoryStores, PHASE2_COOLDOWN_MS } from "../store.js";
2
2
  import { pluginOptions, getConfigWarnings } from "../options.js";
3
3
  import { getAgentHealth } from "../agent-health.js";
4
4
  import { isPhase2InFlight } from "../phase2.js";
@@ -7,7 +7,7 @@ import { activeProviderCapacityBackoffs } from "../ratelimit.js";
7
7
  import { resolveCodexInterop } from "../codex-interop.js";
8
8
  import { injectionTotals, sessionInjection } from "./injection.js";
9
9
  import { memoryRoot } from "../paths.js";
10
- import { readMigrationStatus, memoryPipelineSnapshots } from "../migration.js";
10
+ import { readMigrationStatus } from "../migration.js";
11
11
  import { peekSessionMemoryVersion } from "../session-version.js";
12
12
  import { withMemoryVersion, writeMemoryVersions } from "../memory-version.js";
13
13
  import { getV2DiscoveryStatus } from "./shim.js";
@@ -15,27 +15,44 @@ import { getV2DiscoveryStatus } from "./shim.js";
15
15
  export function readMemoryStatus(sessionID, minConsolidatedThreads) {
16
16
  const sessionVersion = peekSessionMemoryVersion(sessionID);
17
17
  const store = withMemoryVersion(sessionVersion, () => new MemoryStore());
18
- const pipelines = memoryPipelineSnapshots().map((pipeline) => ({
19
- version: pipeline.version,
20
- stage1Count: pipeline.stage1Count,
21
- extracting: pipeline.stage1Jobs.running ?? 0,
22
- phase2Status: pipeline.phase2?.status ?? null,
23
- lastError: pipeline.phase2?.last_error ?? null,
24
- }));
25
- const active = pipelines.filter((pipeline) => writeMemoryVersions().includes(pipeline.version));
26
18
  const options = pluginOptions;
27
19
  const now = Date.now();
28
20
  const staleBeforeSec = Math.floor(now / 1000) - options.max_rollout_age_days * 86_400;
29
- const phase1 = store.stage1JobSnapshot(staleBeforeSec);
21
+ const snapshots = existingMemoryStores().map((pipelineStore) => ({
22
+ version: pipelineStore.version,
23
+ stage1Count: pipelineStore.stage1OutputCount(),
24
+ phase1: pipelineStore.stage1JobSnapshot(staleBeforeSec),
25
+ phase2: pipelineStore.phase2JobSnapshot(),
26
+ }));
27
+ const nextRetry = (times) => {
28
+ const future = times.filter((time) => time != null && time * 1000 > now);
29
+ return future.length ? Math.min(...future) * 1000 : null;
30
+ };
31
+ const pipelines = snapshots.map((pipeline) => {
32
+ const cooldown = pipeline.phase2?.success_finished_at == null
33
+ ? null : pipeline.phase2.success_finished_at * 1000 + PHASE2_COOLDOWN_MS;
34
+ return {
35
+ version: pipeline.version,
36
+ stage1Count: pipeline.stage1Count,
37
+ extracting: pipeline.phase1.by_status.running ?? 0,
38
+ phase2Status: pipeline.phase2?.status ?? null,
39
+ lastError: pipeline.phase2?.last_error ?? null,
40
+ phase2CooldownUntil: cooldown !== null && cooldown > now ? cooldown : null,
41
+ phase1RetryAt: nextRetry(pipeline.phase1.recent_errors
42
+ .filter((error) => error.failure_class === "backoff" || error.failure_class === "provider_capacity")
43
+ .map((error) => error.retry_at)),
44
+ phase2RetryAt: nextRetry([pipeline.phase2?.retry_at]),
45
+ };
46
+ });
47
+ const active = pipelines.filter((pipeline) => writeMemoryVersions().includes(pipeline.version));
30
48
  const phase2 = store.phase2JobSnapshot();
31
49
  const session = sessionInjection(sessionID);
32
50
  const total = injectionTotals();
33
- const retryTimes = [
51
+ const retryAt = nextRetry([
34
52
  ...activeProviderCapacityBackoffs().map((backoff) => backoff.retry_at),
35
- ...phase1.recent_errors.map((error) => error.retry_at),
36
- phase2?.retry_at,
37
- ].filter((time) => time != null && time * 1000 > now);
38
- const retryAt = retryTimes.length ? Math.min(...retryTimes) * 1000 : null;
53
+ ...active.flatMap((pipeline) => [pipeline.phase1RetryAt, pipeline.phase2RetryAt]
54
+ .map((time) => time === null ? null : time / 1000)),
55
+ ]);
39
56
  const warnings = [...getConfigWarnings()];
40
57
  const discoveryWarning = getV2DiscoveryStatus()?.warning;
41
58
  if (options.generate_memories && discoveryWarning)
@@ -51,13 +68,22 @@ export function readMemoryStatus(sessionID, minConsolidatedThreads) {
51
68
  if (pipeline.version !== sessionVersion && pipeline.lastError)
52
69
  warnings.push(`${pipeline.version}: consolidation failed; see memory_inspect.`);
53
70
  }
54
- if (phase1.by_failure_class.due > 0)
55
- warnings.push("Some extraction jobs are due to retry.");
56
- if (phase1.by_failure_class.other_exhausted > phase1.stale_exhausted) {
57
- warnings.push("Some extraction jobs exhausted their retries.");
71
+ for (const pipeline of snapshots.filter((pipeline) => writeMemoryVersions().includes(pipeline.version))) {
72
+ const phase1 = pipeline.phase1;
73
+ const prefix = `${pipeline.version}: `;
74
+ if (phase1.by_failure_class.backoff > 0) {
75
+ const error = phase1.recent_errors.find((error) => error.failure_class === "backoff");
76
+ const count = phase1.by_failure_class.backoff;
77
+ warnings.push(`${prefix}Extraction retry (${count} ${count === 1 ? "job" : "jobs"})${error ? `: ${error.last_error.slice(0, 200)}` : "."}`);
78
+ }
79
+ if (phase1.by_failure_class.due > 0)
80
+ warnings.push(`${prefix}Some extraction jobs are due to retry.`);
81
+ if (phase1.by_failure_class.other_exhausted > phase1.stale_exhausted) {
82
+ warnings.push(`${prefix}Some extraction jobs exhausted their retries.`);
83
+ }
84
+ if (phase1.by_failure_class.provider_capacity > 0)
85
+ warnings.push(`${prefix}Some extraction jobs hit provider capacity limits.`);
58
86
  }
59
- if (phase1.by_failure_class.provider_capacity > 0)
60
- warnings.push("Some extraction jobs hit provider capacity limits.");
61
87
  const importsV1 = options.codex_interop.import && writeMemoryVersions().includes("v1");
62
88
  const codexImport = importsV1 && withMemoryVersion("v1", () => resolveCodexInterop(options.codex_interop)) !== null;
63
89
  if (importsV1 && !codexImport)
@@ -67,7 +67,10 @@ var MemoryStatusRpc = {
67
67
  stage1Count: { type: "integer", minimum: 0 },
68
68
  extracting: { type: "integer", minimum: 0 },
69
69
  phase2Status: { type: ["string", "null"] },
70
- lastError: { type: ["string", "null"] }
70
+ lastError: { type: ["string", "null"] },
71
+ phase2CooldownUntil: { type: ["number", "null"] },
72
+ phase1RetryAt: { type: ["number", "null"] },
73
+ phase2RetryAt: { type: ["number", "null"] }
71
74
  },
72
75
  required: ["version", "stage1Count", "extracting", "phase2Status", "lastError"],
73
76
  additionalProperties: false
@@ -167,7 +170,7 @@ function isMemoryStatus(value) {
167
170
  return false;
168
171
  if (!Number.isInteger(value.minConsolidatedThreads) || value.minConsolidatedThreads < 1 || value.minConsolidatedThreads > 4096)
169
172
  return false;
170
- 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")))
173
+ 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]))))
171
174
  return false;
172
175
  for (const key of ["extractModel", "consolidationModel", "lastSuccessAt", "retryAt"]) {
173
176
  const v = value[key];
@@ -341,6 +344,29 @@ function watchStatus(rpc, context, sessionID) {
341
344
  signal: lifetime.signal
342
345
  };
343
346
  }
347
+ function pipelineRows(s, now) {
348
+ return s.pipelines.flatMap((pipeline) => {
349
+ const version = pipeline.version.toUpperCase();
350
+ const paused = !s.generateMemories || !s.dualWrite && pipeline.version !== s.version;
351
+ const extractionRetry = pipeline.phase1RetryAt != null && pipeline.phase1RetryAt > now;
352
+ const consolidationRetry = pipeline.phase2RetryAt != null && pipeline.phase2RetryAt > now;
353
+ const cooldown = pipeline.phase2CooldownUntil != null && pipeline.phase2CooldownUntil > now;
354
+ const consolidation = pipeline.phase2Status === "pending" ? "Queued" : pipeline.phase2Status === "failed" ? "Retry due" : "Idle";
355
+ return [{
356
+ label: `${version} recaps`,
357
+ value: `${pipeline.stage1Count} stored`,
358
+ tone: "muted"
359
+ }, {
360
+ label: `${version} extraction`,
361
+ value: pipeline.extracting ? `Running (${pipeline.extracting})` : paused ? "Paused" : extractionRetry ? `Retry ${remaining(pipeline.phase1RetryAt, now)}` : "Idle",
362
+ tone: extractionRetry && !paused ? "warn" : "muted"
363
+ }, {
364
+ label: `${version} consolidation`,
365
+ 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,
366
+ tone: pipeline.lastError ? "warn" : "muted"
367
+ }];
368
+ });
369
+ }
344
370
  function statusRows(s, now) {
345
371
  return [{
346
372
  label: "Activity",
@@ -355,11 +381,7 @@ function statusRows(s, now) {
355
381
  label: "V2 readiness",
356
382
  value: `${s.v2Ready ? "Ready" : "Warming"} \xB7 ${s.v2ConsolidatedThreads}/${s.minConsolidatedThreads} sessions`,
357
383
  tone: s.v2Ready ? "ok" : "muted"
358
- }, ...s.pipelines.map((pipeline) => ({
359
- label: `${pipeline.version.toUpperCase()} pipeline`,
360
- value: `${pipeline.stage1Count} recaps \xB7 ${pipeline.extracting ? "extracting" : pipeline.phase2Status ?? "idle"}`,
361
- tone: pipeline.lastError ? "warn" : "muted"
362
- })), {
384
+ }, ...pipelineRows(s, now), {
363
385
  label: "Use memories",
364
386
  value: s.useMemories ? "On" : "Off",
365
387
  tone: s.useMemories ? "ok" : "muted"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-codex-memory",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
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",