opencode-codex-memory 0.11.0 → 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.
@@ -0,0 +1,198 @@
1
+ import { hasConsolidationLease, remaining } from "./panel-status.js";
2
+ import { modelRecoveryGuidance } from "../recovery-info.js";
3
+ import { MEMORY_NOTICE_KINDS } from "./status-rpc.js";
4
+ export const memoryHelp = {
5
+ models: { label: "Background model setup", path: "configuration.md#choose-background-models" },
6
+ providers: { label: "Open provider settings", path: null },
7
+ backup: { label: "Set up backup models", path: "configuration.md#backup-models" },
8
+ configuration: { label: "Memory configuration", path: "configuration.md#where-to-put-options" },
9
+ service: { label: "Check the OpenCode service", path: "troubleshooting.md#check-opencodes-server" },
10
+ troubleshooting: { label: "Troubleshooting", path: "troubleshooting.md#common-symptoms" },
11
+ codex: { label: "Codex import setup", path: "integrations.md#sharing-memory-with-the-codex-cli" },
12
+ };
13
+ export function memoryHelpURL(help) {
14
+ const page = memoryHelp[help].path;
15
+ return page === null ? null : `https://github.com/moritzfl/opencode-codex-memory/blob/main/docs/${page}`;
16
+ }
17
+ export const retryLabels = {
18
+ extraction: { action: "Retry extraction", result: "Extraction retry" },
19
+ consolidation: { action: "Retry consolidation", result: "Consolidation retry" },
20
+ };
21
+ function retryDescription(times, now) {
22
+ return times.every((time) => time > now)
23
+ ? `Automatic retry can run ${remaining(Math.min(...times), now)}, when there’s OpenCode activity.`
24
+ : "Automatic retry can run on the next OpenCode activity.";
25
+ }
26
+ function noticeMessage(kind, details, now, retryPhases, supportsRetry, sessionID) {
27
+ switch (kind) {
28
+ case "extraction_exhausted": {
29
+ const current = sessionID ? details.find((notice) => notice.sessionID === sessionID) : undefined;
30
+ const affected = current ?? details[0];
31
+ const recovery = modelRecoveryGuidance(details.filter((notice) => notice.sessionID === affected?.sessionID).map((notice) => notice.detail ?? ""), "extraction");
32
+ const conversation = current ? "this conversation" : "an affected conversation";
33
+ const nextStep = retryPhases.length
34
+ ? "Retry a batch with the current background models. No new message is needed."
35
+ : supportsRetry
36
+ ? "Wait for the provider limit to clear before retrying."
37
+ : `After fixing the issue, send a new message in ${conversation} and let it go idle.`;
38
+ return {
39
+ title: "Learning stopped for some sessions",
40
+ description: `${recovery?.description ?? "Some conversations ran out of retries."} ${nextStep}`,
41
+ help: recovery?.help ?? "troubleshooting",
42
+ warning: true,
43
+ affectedSessionID: current ? undefined : affected?.sessionID,
44
+ details,
45
+ };
46
+ }
47
+ case "extraction_retry":
48
+ case "consolidation_failed": {
49
+ const extraction = kind === "extraction_retry";
50
+ const phase = extraction ? "Extraction" : "Consolidation";
51
+ const recovery = modelRecoveryGuidance(details.map((notice) => notice.detail ?? ""), extraction ? "extraction" : "consolidation");
52
+ const times = details.map((notice) => notice.retryAt ?? 0);
53
+ const waiting = times.every((time) => time > now);
54
+ const retry = retryDescription(times, now);
55
+ return {
56
+ title: recovery ? `${phase} failed` : waiting ? `${phase} waiting to retry` : `${phase} can retry`,
57
+ description: [
58
+ recovery?.description ??
59
+ (extraction ? "Learning from some sessions failed." : "The last memory update failed."),
60
+ retry,
61
+ retryPhases.length ? "You can retry now with the current models." : "",
62
+ ]
63
+ .filter(Boolean)
64
+ .join(" "),
65
+ help: recovery?.help ?? (extraction ? undefined : "troubleshooting"),
66
+ warning: !!recovery,
67
+ details,
68
+ };
69
+ }
70
+ case "provider_capacity":
71
+ return {
72
+ title: "Provider rate limit or quota",
73
+ description: details.every((notice) => (notice.retryAt ?? 0) > now)
74
+ ? retryDescription(details.map((notice) => notice.retryAt ?? 0), now)
75
+ : retryPhases.length
76
+ ? "If the provider allows requests again, retry with the current background models."
77
+ : "Learning can resume when the provider allows requests again.",
78
+ help: "backup",
79
+ details,
80
+ };
81
+ case "configuration":
82
+ return {
83
+ title: "Check memory configuration",
84
+ description: "OpenCode ignored or adjusted some memory options. Correct the options listed below.",
85
+ help: "configuration",
86
+ warning: true,
87
+ details,
88
+ };
89
+ case "consolidator_setup":
90
+ return {
91
+ title: "Memory agent needs attention",
92
+ description: "Check for overrides of the memorize agent. Restore the plugin's default agent permissions.",
93
+ help: "troubleshooting",
94
+ warning: true,
95
+ details,
96
+ };
97
+ case "discovery":
98
+ return {
99
+ title: "Learning is limited to recent activity",
100
+ description: "Memory can only see conversations this server has observed. Check the OpenCode service to restore access to past sessions.",
101
+ help: "service",
102
+ warning: true,
103
+ details,
104
+ };
105
+ case "codex_import":
106
+ return {
107
+ title: "Codex import is blocked",
108
+ description: "Check the Codex home and memory paths. OpenCode can still learn from its own conversations.",
109
+ help: "codex",
110
+ warning: true,
111
+ details,
112
+ };
113
+ }
114
+ }
115
+ export function memoryMessages(status, now, sessionID) {
116
+ if (status.activity === "stopping")
117
+ return [{ title: "Memory is stopping", description: "Wait for OpenCode to reconnect." }];
118
+ const shownRetries = new Set();
119
+ const messages = MEMORY_NOTICE_KINDS.flatMap((kind) => {
120
+ const notices = status.notices?.filter((notice) => notice.kind === kind) ?? [];
121
+ if (!notices.length)
122
+ return [];
123
+ const retryPhases = [];
124
+ if (status.manualRetry !== undefined) {
125
+ for (const { retryPhase } of notices) {
126
+ if (!retryPhase || shownRetries.has(retryPhase))
127
+ continue;
128
+ retryPhases.push(retryPhase);
129
+ shownRetries.add(retryPhase);
130
+ }
131
+ }
132
+ return [
133
+ { ...noticeMessage(kind, notices, now, retryPhases, status.manualRetry !== undefined, sessionID), retryPhases },
134
+ ];
135
+ });
136
+ if (status.manualRetry?.state === "running")
137
+ return [{ title: `Retrying ${status.manualRetry.phase}…`, description: status.manualRetry.message }, ...messages];
138
+ if (status.generateMemories) {
139
+ const active = status.pipelines.filter((pipeline) => status.dualWrite || pipeline.version === status.version);
140
+ if (status.activity === "consolidating") {
141
+ messages.unshift({ title: "Consolidating memories", description: "Updating the memory files used for recall." });
142
+ }
143
+ else if (status.activity === "extracting") {
144
+ messages.unshift({
145
+ title: "Learning from sessions",
146
+ description: "Saving useful context from eligible conversations.",
147
+ });
148
+ }
149
+ else if (active.some((pipeline) => hasConsolidationLease(pipeline, now))) {
150
+ messages.unshift({
151
+ title: "Waiting for consolidation",
152
+ description: "A consolidation lock is active. Wait for the run to finish or for the lock to expire.",
153
+ });
154
+ }
155
+ if (messages.length)
156
+ return messages.sort((a, b) => Number(!!b.warning) - Number(!!a.warning));
157
+ if (status.notices === undefined && status.activity === "error")
158
+ return [
159
+ {
160
+ title: "Check memory status",
161
+ description: "See the reported warnings, or ask the agent to run memory_inspect for recent errors.",
162
+ warning: true,
163
+ help: "troubleshooting",
164
+ },
165
+ ];
166
+ if (status.notices === undefined && status.activity === "retrying")
167
+ return [
168
+ {
169
+ title: "Waiting to retry",
170
+ description: retryDescription([status.retryAt ?? 0], now),
171
+ },
172
+ ];
173
+ const queued = active.filter((pipeline) => pipeline.phase2Status === "pending");
174
+ if (queued.length) {
175
+ const cooldowns = queued.map((pipeline) => pipeline.phase2CooldownUntil ?? 0);
176
+ return [
177
+ {
178
+ title: "Consolidation queued",
179
+ description: cooldowns.every((time) => time > now)
180
+ ? `Cooldown ends ${remaining(Math.min(...cooldowns), now)}. OpenCode can update memory on activity after that.`
181
+ : "OpenCode can update memory on the next conversation activity or when a session goes idle.",
182
+ },
183
+ ];
184
+ }
185
+ return [
186
+ {
187
+ title: "Idle",
188
+ description: "OpenCode checks for eligible idle conversations on new activity.",
189
+ },
190
+ ];
191
+ }
192
+ return [
193
+ status.useMemories
194
+ ? { title: "Learning paused", description: "OpenCode can still use existing memories in conversations." }
195
+ : { title: "Memory is off", description: "Turn on recall or learning below." },
196
+ ...messages,
197
+ ];
198
+ }
@@ -9,14 +9,16 @@ export declare function watchMemoryStatus(read: (signal: AbortSignal) => Promise
9
9
  refresh: () => Promise<void>;
10
10
  signal: AbortSignal;
11
11
  };
12
- export declare function isMemoryRunning(status: MemoryStatus): boolean;
12
+ export declare function hasConsolidationLease(pipeline: MemoryStatus["pipelines"][number], now: number): boolean;
13
+ export declare function isMemoryRunning(status: MemoryStatus, now?: number): boolean;
14
+ export declare function elapsed(time: number, now: number): string;
15
+ export declare function remaining(time: number | null | undefined, now: number): string;
13
16
  export type StatusRow = {
14
17
  label: string;
15
18
  value: string;
16
19
  tone?: "ok" | "warn" | "muted";
17
20
  };
18
- export declare function statusRows(s: MemoryStatus, now: number, { includeReadinessDiagnostic }?: {
19
- includeReadinessDiagnostic?: boolean | undefined;
20
- }): StatusRow[];
21
+ export declare function diagnosticRows(s: MemoryStatus, now: number): StatusRow[];
22
+ export declare function statusRows(s: MemoryStatus, now: number): StatusRow[];
21
23
  export declare function usageRows(s: MemoryStatus, sessionID?: string): StatusRow[];
22
24
  export declare function configRows(s: MemoryStatus): StatusRow[];
@@ -50,12 +50,16 @@ export function watchMemoryStatus(read, subscribe) {
50
50
  void refresh();
51
51
  return { status, unavailable, refreshing, updatedAt, refresh, signal: lifetime.signal };
52
52
  }
53
- export function isMemoryRunning(status) {
54
- return (status.activity === "consolidating" ||
53
+ export function hasConsolidationLease(pipeline, now) {
54
+ return pipeline.phase2Status === "running" && (pipeline.phase2LeaseUntil == null || pipeline.phase2LeaseUntil > now);
55
+ }
56
+ export function isMemoryRunning(status, now = Date.now()) {
57
+ return (status.manualRetry?.state === "running" ||
58
+ status.activity === "consolidating" ||
55
59
  status.activity === "extracting" ||
56
- status.pipelines.some((pipeline) => pipeline.extracting > 0 || pipeline.phase2Status === "running"));
60
+ status.pipelines.some((pipeline) => pipeline.extracting > 0 || hasConsolidationLease(pipeline, now)));
57
61
  }
58
- function elapsed(time, now) {
62
+ export function elapsed(time, now) {
59
63
  const minutes = Math.max(0, Math.floor((now - time) / 60_000));
60
64
  if (minutes === 0)
61
65
  return "just now";
@@ -65,7 +69,7 @@ function elapsed(time, now) {
65
69
  return `${Math.floor(minutes / 60)}h ago`;
66
70
  return `${Math.floor(minutes / 1440)}d ago`;
67
71
  }
68
- function remaining(time, now) {
72
+ export function remaining(time, now) {
69
73
  if (time == null)
70
74
  return "—";
71
75
  const minutes = Math.max(0, Math.ceil((time - now) / 60_000));
@@ -107,7 +111,7 @@ function pipelineRows(s, now) {
107
111
  },
108
112
  {
109
113
  label: `${version} consolidation`,
110
- value: pipeline.phase2Status === "running"
114
+ value: hasConsolidationLease(pipeline, now)
111
115
  ? "Running"
112
116
  : paused
113
117
  ? "Paused"
@@ -117,7 +121,9 @@ function pipelineRows(s, now) {
117
121
  ? `${consolidation} · cooldown ends ${remaining(pipeline.phase2CooldownUntil, now)}`
118
122
  : pipeline.phase2Status === "pending"
119
123
  ? "Queued · next activity"
120
- : consolidation,
124
+ : pipeline.phase2Status === "running"
125
+ ? "Interrupted · next activity"
126
+ : consolidation,
121
127
  tone: pipeline.lastError ? "warn" : "muted",
122
128
  },
123
129
  ...(pipeline.lastError
@@ -126,9 +132,8 @@ function pipelineRows(s, now) {
126
132
  ];
127
133
  });
128
134
  }
129
- export function statusRows(s, now, { includeReadinessDiagnostic = true } = {}) {
135
+ export function diagnosticRows(s, now) {
130
136
  return [
131
- { label: "Activity", value: activityLabels[s.activity] },
132
137
  { label: "Memory version", value: `${s.sessionVersion} (default ${s.version})` },
133
138
  { label: "Learning pipelines", value: s.dualWrite ? "v1 + v2" : s.version },
134
139
  {
@@ -136,9 +141,7 @@ export function statusRows(s, now, { includeReadinessDiagnostic = true } = {}) {
136
141
  value: `${s.v2Ready ? "Ready" : "Not ready"} · ${s.v2ConsolidatedThreads}/${s.minConsolidatedThreads} sessions`,
137
142
  tone: s.v2Ready ? "ok" : "muted",
138
143
  },
139
- ...(includeReadinessDiagnostic && s.v2NotReadyReason
140
- ? [{ label: "V2 not ready", value: s.v2NotReadyReason, tone: "muted" }]
141
- : []),
144
+ ...(s.v2NotReadyReason ? [{ label: "V2 not ready", value: s.v2NotReadyReason, tone: "muted" }] : []),
142
145
  ...(s.v2SummaryBytes !== undefined
143
146
  ? [
144
147
  {
@@ -153,6 +156,12 @@ export function statusRows(s, now, { includeReadinessDiagnostic = true } = {}) {
153
156
  ]
154
157
  : []),
155
158
  ...pipelineRows(s, now),
159
+ ];
160
+ }
161
+ export function statusRows(s, now) {
162
+ return [
163
+ { label: "Activity", value: activityLabels[s.activity] },
164
+ ...diagnosticRows(s, now),
156
165
  { label: "Use memories", value: s.useMemories ? "On" : "Off", tone: s.useMemories ? "ok" : "muted" },
157
166
  {
158
167
  label: "Learn from sessions",
@@ -34,13 +34,15 @@ import { ensureV2Agents } from "./agents.js";
34
34
  import { buildV2Tools } from "./tools.js";
35
35
  import { performMemoryReset } from "../../tools/control.js";
36
36
  import { guardMemorySearchTools } from "./search-sandbox.js";
37
- import { MemoryStatusRpc } from "./status-rpc.js";
37
+ import { isMemoryRetryPhase, MemoryStatusRpc } from "./status-rpc.js";
38
38
  import { readMemoryStatus } from "./status.js";
39
+ import { clearMemoryRetryResult, memoryRetryStatus, onMemoryRetryChanged, requestMemoryRetry, waitForMemoryRetry, } from "../retry.js";
39
40
  import { recordInjection, resetInjectionStats } from "./injection.js";
40
41
  import { overlayV2CitationInstructions } from "./citation-overlay.js";
41
42
  import { estimateTokens } from "../token.js";
42
43
  const backgroundTasks = new Set();
43
44
  const statusListeners = new Set();
45
+ const RETRY_RESULT_LIFETIME_MS = 2 * 60_000;
44
46
  /**
45
47
  * The V2 host runs one plugin instance per location in the same process and
46
48
  * evicts idle locations independently. Process-wide state (lifecycle, shim
@@ -86,6 +88,7 @@ function trackBackgroundTask(task) {
86
88
  }
87
89
  /** Test seam: wait for hook-launched work to settle. */
88
90
  export async function waitForV2BackgroundTasks() {
91
+ await waitForMemoryRetry();
89
92
  while (backgroundTasks.size > 0) {
90
93
  await Promise.all([...backgroundTasks]);
91
94
  }
@@ -97,6 +100,7 @@ export function resetV2ModuleStateForTest() {
97
100
  clearTimeout(statusNotifyTimer);
98
101
  statusNotifyTimer = null;
99
102
  backgroundTasks.clear();
103
+ clearMemoryRetryResult();
100
104
  seenTurnSessions.clear();
101
105
  liveInstances.length = 0;
102
106
  activeConfig = undefined;
@@ -248,7 +252,10 @@ async function attach(ctx) {
248
252
  status: async (input) => {
249
253
  const sessionID = input?.sessionID;
250
254
  const minimum = input?.minConsolidatedThreads;
251
- return readMemoryStatus(typeof sessionID === "string" ? sessionID : null, minimum);
255
+ return {
256
+ ...readMemoryStatus(typeof sessionID === "string" ? sessionID : null, minimum),
257
+ manualRetry: memoryRetryStatus(RETRY_RESULT_LIFETIME_MS),
258
+ };
252
259
  },
253
260
  setOption: async (input) => {
254
261
  const { key, value } = (input ?? {});
@@ -301,11 +308,20 @@ async function attach(ctx) {
301
308
  return { ok: true };
302
309
  },
303
310
  consolidateNow: async () => {
311
+ if (memoryRetryStatus()?.state === "running")
312
+ return { status: "already_running", message: "A memory retry is in progress." };
304
313
  // Runs detached so the dialog does not block on a multi-minute turn.
305
314
  const run = consolidateNow();
306
315
  trackBackgroundTask(run.then(() => { }));
307
316
  return { status: "started" };
308
317
  },
318
+ retryFailed: async (input) => {
319
+ const phase = input?.phase;
320
+ if (!isMemoryRetryPhase(phase))
321
+ return { ok: false, message: "Choose extraction or consolidation to retry." };
322
+ const request = requestMemoryRetry(phase);
323
+ return request.ok ? { ok: true } : request;
324
+ },
309
325
  resetMemory: async (input) => {
310
326
  if (input?.confirm !== true)
311
327
  return { ok: false, message: "Reset not confirmed." };
@@ -440,6 +456,7 @@ async function attach(ctx) {
440
456
  console.warn("[opencode-codex-memory] orphaned phase2 sweep failed:", err);
441
457
  }
442
458
  statusListeners.add(publishStatus);
459
+ const unsubscribeRetry = onMemoryRetryChanged(publishStatus);
443
460
  // Event loop: execution.succeeded pumps phase 1 the way V1's idle events did.
444
461
  const eventAbort = new AbortController();
445
462
  void (async () => {
@@ -509,6 +526,7 @@ async function attach(ctx) {
509
526
  .finally(() => eventLoops.delete(eventAbort));
510
527
  eventLoops.add(eventAbort);
511
528
  return () => {
529
+ unsubscribeRetry();
512
530
  statusListeners.delete(publishStatus);
513
531
  eventAbort.abort();
514
532
  };
@@ -530,6 +548,7 @@ function releaseLocation(ctx) {
530
548
  draining = Promise.allSettled([abortActiveSubSessions(), waitForV2BackgroundTasks()]).then(() => {
531
549
  setSubSessionDirectory();
532
550
  setV2Context(null);
551
+ clearMemoryRetryResult();
533
552
  activeConfig = undefined;
534
553
  draining = undefined;
535
554
  invalidateCache();
@@ -6,6 +6,8 @@
6
6
  * `Rpc.define` is a runtime passthrough (validation only), so a plain object
7
7
  * with JSON Schema nodes is an equivalent portable definition.
8
8
  */
9
+ import { type MemoryNotice, type MemoryRetry, type MemoryRetryPhase } from "../recovery-info.js";
10
+ export { MEMORY_NOTICE_KINDS, type MemoryNotice, type MemoryRetry, type MemoryRetryPhase } from "../recovery-info.js";
9
11
  export declare const MEMORY_STATUS_ACTIVITIES: readonly ["idle", "extracting", "consolidating", "retrying", "error", "read_only", "disabled", "stopping"];
10
12
  export type MemoryStatusActivity = (typeof MEMORY_STATUS_ACTIVITIES)[number];
11
13
  export interface MemoryStatus {
@@ -31,6 +33,7 @@ export interface MemoryStatus {
31
33
  phase2CooldownUntil?: number | null;
32
34
  phase1RetryAt?: number | null;
33
35
  phase2RetryAt?: number | null;
36
+ phase2LeaseUntil?: number | null;
34
37
  }[];
35
38
  useMemories: boolean;
36
39
  generateMemories: boolean;
@@ -40,6 +43,10 @@ export interface MemoryStatus {
40
43
  lastSuccessAt: number | null;
41
44
  retryAt: number | null;
42
45
  warnings: string[];
46
+ /** Typed guidance inputs. Older servers only send warning strings. */
47
+ notices?: MemoryNotice[];
48
+ /** Null when no recent request; absent on servers without manual retry support. */
49
+ manualRetry?: MemoryRetry | null;
43
50
  /** Per-session read/write mode when a sessionID was supplied. */
44
51
  sessionMode: "enabled" | "disabled" | "polluted" | null;
45
52
  /** Root directory of the memory workspace. */
@@ -147,6 +154,9 @@ export declare const MemoryStatusRpc: {
147
154
  readonly phase2RetryAt: {
148
155
  readonly type: readonly ["number", "null"];
149
156
  };
157
+ readonly phase2LeaseUntil: {
158
+ readonly type: readonly ["number", "null"];
159
+ };
150
160
  };
151
161
  readonly required: readonly ["version", "stage1Count", "extracting", "phase2Status", "lastError"];
152
162
  readonly additionalProperties: false;
@@ -176,6 +186,59 @@ export declare const MemoryStatusRpc: {
176
186
  readonly type: "string";
177
187
  };
178
188
  };
189
+ readonly notices: {
190
+ readonly type: "array";
191
+ readonly items: {
192
+ readonly type: "object";
193
+ readonly properties: {
194
+ readonly kind: {
195
+ readonly type: "string";
196
+ readonly enum: readonly ["extraction_exhausted", "consolidator_setup", "configuration", "discovery", "codex_import", "consolidation_failed", "extraction_retry", "provider_capacity"];
197
+ };
198
+ readonly detail: {
199
+ readonly type: "string";
200
+ };
201
+ readonly version: {
202
+ readonly type: "string";
203
+ readonly enum: readonly ["v1", "v2"];
204
+ };
205
+ readonly phase: {
206
+ readonly type: "string";
207
+ readonly enum: readonly ["extraction", "consolidation"];
208
+ };
209
+ readonly sessionID: {
210
+ readonly type: "string";
211
+ };
212
+ readonly retryAt: {
213
+ readonly type: "number";
214
+ };
215
+ readonly retryPhase: {
216
+ readonly type: "string";
217
+ readonly enum: readonly ["extraction", "consolidation"];
218
+ };
219
+ };
220
+ readonly required: readonly ["kind"];
221
+ readonly additionalProperties: false;
222
+ };
223
+ };
224
+ readonly manualRetry: {
225
+ readonly type: readonly ["object", "null"];
226
+ readonly properties: {
227
+ readonly phase: {
228
+ readonly type: "string";
229
+ readonly enum: readonly ["extraction", "consolidation"];
230
+ };
231
+ readonly state: {
232
+ readonly type: "string";
233
+ readonly enum: readonly ["running", "completed", "blocked", "failed"];
234
+ };
235
+ readonly message: {
236
+ readonly type: "string";
237
+ };
238
+ };
239
+ readonly required: readonly ["phase", "state", "message"];
240
+ readonly additionalProperties: false;
241
+ };
179
242
  readonly sessionMode: {
180
243
  readonly type: readonly ["string", "null"];
181
244
  readonly enum: readonly ["enabled", "disabled", "polluted", null];
@@ -274,11 +337,41 @@ export declare const MemoryStatusRpc: {
274
337
  readonly status: {
275
338
  readonly type: "string";
276
339
  };
340
+ readonly message: {
341
+ readonly type: "string";
342
+ };
277
343
  };
278
344
  readonly required: readonly ["status"];
279
345
  readonly additionalProperties: false;
280
346
  };
281
347
  };
348
+ /** Try failed work with current options. Progress and outcome appear in status. */
349
+ readonly retryFailed: {
350
+ readonly input: {
351
+ readonly type: "object";
352
+ readonly properties: {
353
+ readonly phase: {
354
+ readonly type: "string";
355
+ readonly enum: readonly ["extraction", "consolidation"];
356
+ };
357
+ };
358
+ readonly required: readonly ["phase"];
359
+ readonly additionalProperties: false;
360
+ };
361
+ readonly output: {
362
+ readonly type: "object";
363
+ readonly properties: {
364
+ readonly ok: {
365
+ readonly type: "boolean";
366
+ };
367
+ readonly message: {
368
+ readonly type: "string";
369
+ };
370
+ };
371
+ readonly required: readonly ["ok"];
372
+ readonly additionalProperties: false;
373
+ };
374
+ };
282
375
  /** Same wipe as the V1 memory_reset tool; the panel's confirm step is the approval. */
283
376
  readonly resetMemory: {
284
377
  readonly input: {
@@ -316,6 +409,7 @@ export declare const MemoryStatusRpc: {
316
409
  };
317
410
  };
318
411
  };
412
+ export declare function isMemoryRetryPhase(value: unknown): value is MemoryRetryPhase;
319
413
  /** Runtime guard for the untyped RPC client result (no zod in the TUI bundle). */
320
414
  export declare function isMemoryStatus(value: unknown): value is MemoryStatus;
321
415
  /** Throwing parser for tests and call sites that want a typed value. */
@@ -6,6 +6,8 @@
6
6
  * `Rpc.define` is a runtime passthrough (validation only), so a plain object
7
7
  * with JSON Schema nodes is an equivalent portable definition.
8
8
  */
9
+ import { MEMORY_NOTICE_KINDS, MEMORY_RETRY_PHASES, MEMORY_RETRY_STATES, } from "../recovery-info.js";
10
+ export { MEMORY_NOTICE_KINDS } from "../recovery-info.js";
9
11
  export const MEMORY_STATUS_ACTIVITIES = [
10
12
  "idle",
11
13
  "extracting",
@@ -27,6 +29,7 @@ const INJECTED_SCHEMA = {
27
29
  required: ["sessionTokens", "sessionRequests", "totalTokens", "totalRequests"],
28
30
  additionalProperties: false,
29
31
  };
32
+ const RETRY_PHASE_SCHEMA = { type: "string", enum: [...MEMORY_RETRY_PHASES] };
30
33
  export const MemoryStatusRpc = {
31
34
  id: "opencode-codex-memory",
32
35
  methods: {
@@ -66,6 +69,7 @@ export const MemoryStatusRpc = {
66
69
  phase2CooldownUntil: { type: ["number", "null"] },
67
70
  phase1RetryAt: { type: ["number", "null"] },
68
71
  phase2RetryAt: { type: ["number", "null"] },
72
+ phase2LeaseUntil: { type: ["number", "null"] },
69
73
  },
70
74
  required: ["version", "stage1Count", "extracting", "phase2Status", "lastError"],
71
75
  additionalProperties: false,
@@ -78,6 +82,33 @@ export const MemoryStatusRpc = {
78
82
  lastSuccessAt: { type: ["number", "null"] },
79
83
  retryAt: { type: ["number", "null"] },
80
84
  warnings: { type: "array", items: { type: "string" } },
85
+ notices: {
86
+ type: "array",
87
+ items: {
88
+ type: "object",
89
+ properties: {
90
+ kind: { type: "string", enum: [...MEMORY_NOTICE_KINDS] },
91
+ detail: { type: "string" },
92
+ version: { type: "string", enum: ["v1", "v2"] },
93
+ phase: RETRY_PHASE_SCHEMA,
94
+ sessionID: { type: "string" },
95
+ retryAt: { type: "number" },
96
+ retryPhase: RETRY_PHASE_SCHEMA,
97
+ },
98
+ required: ["kind"],
99
+ additionalProperties: false,
100
+ },
101
+ },
102
+ manualRetry: {
103
+ type: ["object", "null"],
104
+ properties: {
105
+ phase: RETRY_PHASE_SCHEMA,
106
+ state: { type: "string", enum: [...MEMORY_RETRY_STATES] },
107
+ message: { type: "string" },
108
+ },
109
+ required: ["phase", "state", "message"],
110
+ additionalProperties: false,
111
+ },
81
112
  sessionMode: { type: ["string", "null"], enum: ["enabled", "disabled", "polluted", null] },
82
113
  memoryRoot: { type: "string" },
83
114
  injected: INJECTED_SCHEMA,
@@ -147,11 +178,26 @@ export const MemoryStatusRpc = {
147
178
  input: { type: "object", properties: {}, additionalProperties: false },
148
179
  output: {
149
180
  type: "object",
150
- properties: { status: { type: "string" } },
181
+ properties: { status: { type: "string" }, message: { type: "string" } },
151
182
  required: ["status"],
152
183
  additionalProperties: false,
153
184
  },
154
185
  },
186
+ /** Try failed work with current options. Progress and outcome appear in status. */
187
+ retryFailed: {
188
+ input: {
189
+ type: "object",
190
+ properties: { phase: RETRY_PHASE_SCHEMA },
191
+ required: ["phase"],
192
+ additionalProperties: false,
193
+ },
194
+ output: {
195
+ type: "object",
196
+ properties: { ok: { type: "boolean" }, message: { type: "string" } },
197
+ required: ["ok"],
198
+ additionalProperties: false,
199
+ },
200
+ },
155
201
  /** Same wipe as the V1 memory_reset tool; the panel's confirm step is the approval. */
156
202
  resetMemory: {
157
203
  input: {
@@ -175,6 +221,9 @@ export const MemoryStatusRpc = {
175
221
  function isRecord(value) {
176
222
  return typeof value === "object" && value !== null && !Array.isArray(value);
177
223
  }
224
+ export function isMemoryRetryPhase(value) {
225
+ return value === "extraction" || value === "consolidation";
226
+ }
178
227
  /** Runtime guard for the untyped RPC client result (no zod in the TUI bundle). */
179
228
  export function isMemoryStatus(value) {
180
229
  if (!isRecord(value))
@@ -217,7 +266,7 @@ export function isMemoryStatus(value) {
217
266
  pipeline.extracting >= 0 &&
218
267
  (pipeline.phase2Status === null || typeof pipeline.phase2Status === "string") &&
219
268
  (pipeline.lastError === null || typeof pipeline.lastError === "string") &&
220
- ["phase2CooldownUntil", "phase1RetryAt", "phase2RetryAt"].every((key) => pipeline[key] === undefined ||
269
+ ["phase2CooldownUntil", "phase1RetryAt", "phase2RetryAt", "phase2LeaseUntil"].every((key) => pipeline[key] === undefined ||
221
270
  pipeline[key] === null ||
222
271
  (typeof pipeline[key] === "number" && Number.isFinite(pipeline[key])))))
223
272
  return false;
@@ -230,6 +279,25 @@ export function isMemoryStatus(value) {
230
279
  if (!Array.isArray(value.warnings) || !value.warnings.every((w) => typeof w === "string")) {
231
280
  return false;
232
281
  }
282
+ if (value.notices !== undefined &&
283
+ (!Array.isArray(value.notices) ||
284
+ !value.notices.every((notice) => isRecord(notice) &&
285
+ typeof notice.kind === "string" &&
286
+ MEMORY_NOTICE_KINDS.includes(notice.kind) &&
287
+ (notice.version === undefined || notice.version === "v1" || notice.version === "v2") &&
288
+ (notice.phase === undefined || isMemoryRetryPhase(notice.phase)) &&
289
+ (notice.detail === undefined || typeof notice.detail === "string") &&
290
+ (notice.sessionID === undefined || typeof notice.sessionID === "string") &&
291
+ (notice.retryPhase === undefined || isMemoryRetryPhase(notice.retryPhase)) &&
292
+ (notice.retryAt === undefined || (typeof notice.retryAt === "number" && Number.isFinite(notice.retryAt))))))
293
+ return false;
294
+ const retry = value.manualRetry;
295
+ if (retry != null &&
296
+ (!isRecord(retry) ||
297
+ !isMemoryRetryPhase(retry.phase) ||
298
+ typeof retry.message !== "string" ||
299
+ !MEMORY_RETRY_STATES.includes(retry.state)))
300
+ return false;
233
301
  if (value.sessionMode !== null &&
234
302
  value.sessionMode !== "enabled" &&
235
303
  value.sessionMode !== "disabled" &&