opencode-codex-memory 0.7.7 → 0.8.1

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.
Files changed (63) hide show
  1. package/README.md +64 -482
  2. package/dist/opencode.json +2 -2
  3. package/dist/src/capture.d.ts +5 -0
  4. package/dist/src/capture.js +8 -0
  5. package/dist/src/claude-import.js +25 -27
  6. package/dist/src/codex-interop.js +5 -0
  7. package/dist/src/db.d.ts +7 -1
  8. package/dist/src/db.js +38 -11
  9. package/dist/src/host-client.d.ts +5 -0
  10. package/dist/src/index.d.ts +12 -4
  11. package/dist/src/index.js +39 -61
  12. package/dist/src/lifecycle.js +14 -9
  13. package/dist/src/llm.d.ts +3 -2
  14. package/dist/src/llm.js +47 -11
  15. package/dist/src/memory-version.d.ts +5 -0
  16. package/dist/src/memory-version.js +16 -0
  17. package/dist/src/migration.d.ts +24 -0
  18. package/dist/src/migration.js +37 -0
  19. package/dist/src/options.d.ts +4 -0
  20. package/dist/src/options.js +2 -0
  21. package/dist/src/paths.d.ts +9 -3
  22. package/dist/src/paths.js +22 -8
  23. package/dist/src/phase1.js +16 -2
  24. package/dist/src/phase2.js +15 -9
  25. package/dist/src/pipeline.d.ts +3 -0
  26. package/dist/src/pipeline.js +74 -0
  27. package/dist/src/ratelimit.js +5 -4
  28. package/dist/src/rollout-input.d.ts +3 -2
  29. package/dist/src/rollout-input.js +26 -17
  30. package/dist/src/session-version.d.ts +9 -0
  31. package/dist/src/session-version.js +27 -0
  32. package/dist/src/source.js +21 -6
  33. package/dist/src/store.d.ts +10 -1
  34. package/dist/src/store.js +76 -24
  35. package/dist/src/templates/consolidation_v2.md +54 -0
  36. package/dist/src/templates/read_path_v2.md +58 -0
  37. package/dist/src/templates/stage_one_input_v2.md +21 -0
  38. package/dist/src/templates/stage_one_system_v2.md +53 -0
  39. package/dist/src/token.d.ts +2 -0
  40. package/dist/src/token.js +16 -0
  41. package/dist/src/v2/agents.d.ts +4 -2
  42. package/dist/src/v2/agents.js +28 -9
  43. package/dist/src/v2/citation-overlay.d.ts +1 -1
  44. package/dist/src/v2/citation-overlay.js +27 -4
  45. package/dist/src/v2/plugin.js +47 -76
  46. package/dist/src/v2/search-sandbox.d.ts +4 -0
  47. package/dist/src/v2/search-sandbox.js +33 -0
  48. package/dist/src/v2/service.d.ts +2 -0
  49. package/dist/src/v2/service.js +43 -4
  50. package/dist/src/v2/shim.d.ts +2 -2
  51. package/dist/src/v2/shim.js +82 -39
  52. package/dist/src/v2/status-rpc.d.ts +70 -1
  53. package/dist/src/v2/status-rpc.js +41 -2
  54. package/dist/src/v2/status.d.ts +1 -1
  55. package/dist/src/v2/status.js +28 -6
  56. package/dist/src/v2/tui.js +57 -2
  57. package/dist/src/workspace.d.ts +8 -6
  58. package/dist/src/workspace.js +31 -11
  59. package/dist/tools/control.d.ts +6 -2
  60. package/dist/tools/control.js +196 -164
  61. package/dist/tools/memory.js +11 -1
  62. package/opencode.json +2 -2
  63. package/package.json +2 -2
@@ -1,5 +1,6 @@
1
1
  import { memoryRoot } from "../paths.js";
2
- import { invalidateOwnService, lastServiceFailure, ownServiceClient } from "./service.js";
2
+ import { consolidationPermissions } from "./agents.js";
3
+ import { invalidateOwnService, lastServiceFailure, ownServiceClient, serviceRequest } from "./service.js";
3
4
  let v2ctx = null;
4
5
  export function setV2Context(ctx) {
5
6
  v2ctx = ctx;
@@ -32,7 +33,7 @@ async function sessionGoneOnService(client, sessionID) {
32
33
  if (typeof client.session.get !== "function")
33
34
  return false;
34
35
  try {
35
- const info = await client.session.get({ sessionID });
36
+ const info = await serviceRequest(client, () => client.session.get({ sessionID }));
36
37
  if (info?.error && isNotFoundError(info.error)) {
37
38
  return true;
38
39
  }
@@ -204,7 +205,7 @@ export function adaptV2Messages(msgs) {
204
205
  }
205
206
  return rows;
206
207
  }
207
- /** V2 catalog.model.list → V1 provider-list shape for catalogVariantKeys. */
208
+ /** V2 model.list (legacy catalog.model.list) → V1 provider-list shape. */
208
209
  export function adaptProviderCatalog(v2) {
209
210
  const items = und(v2);
210
211
  const list = Array.isArray(items) ? items : items?.data ?? [];
@@ -213,7 +214,9 @@ export function adaptProviderCatalog(v2) {
213
214
  if (!m || typeof m !== "object")
214
215
  continue;
215
216
  const providerID = m.providerID;
216
- const modelID = m.modelID ?? m.id;
217
+ // id is the selectable OpenCode alias; modelID can be a different provider
218
+ // wire name. Legacy catalogs exposed only modelID.
219
+ const modelID = m.id ?? m.modelID;
217
220
  if (typeof providerID !== "string" || typeof modelID !== "string")
218
221
  continue;
219
222
  if (!providers.has(providerID))
@@ -225,7 +228,7 @@ export function adaptProviderCatalog(v2) {
225
228
  }
226
229
  }
227
230
  ;
228
- providers.get(providerID)[modelID] = { variants };
231
+ providers.get(providerID)[modelID] = { ...(m.variants !== undefined ? { variants } : {}) };
229
232
  }
230
233
  return { all: [...providers.entries()].map(([id, models]) => ({ id, models })) };
231
234
  }
@@ -263,6 +266,60 @@ function responseNextCursor(response) {
263
266
  const next = direct ?? payload?.cursor?.next;
264
267
  return typeof next === "string" && next.length > 0 ? next : undefined;
265
268
  }
269
+ /** Read durable messages in source order, including terminal errors/idle rows. */
270
+ async function loadV2Messages(sessionID, context, signal) {
271
+ const client = await ownServiceClient();
272
+ if (typeof client?.message?.list === "function") {
273
+ const messages = [];
274
+ const seenCursors = new Set();
275
+ let cursor;
276
+ while (true) {
277
+ const response = await serviceRequest(client, () => client.message.list(cursor ? { sessionID, cursor } : { sessionID, order: "asc" }, signal ? { signal } : undefined));
278
+ const rows = responseRows(response);
279
+ if (!rows)
280
+ throw new Error("registered service returned an invalid message list");
281
+ messages.push(...rows);
282
+ const next = responseNextCursor(response);
283
+ if (!next)
284
+ return messages;
285
+ if (seenCursors.has(next))
286
+ throw new Error("registered service repeated a message cursor");
287
+ seenCursors.add(next);
288
+ cursor = next;
289
+ }
290
+ }
291
+ const raw = await (context ?? ctx()).session.context({ sessionID });
292
+ const rows = responseRows(raw);
293
+ if (!rows)
294
+ throw new Error("session context returned an invalid message list");
295
+ return rows;
296
+ }
297
+ function completedPromptResponse(rows, promptID) {
298
+ const boundary = typeof promptID === "string" ? rows.findIndex((m) => m?.id === promptID && m.type === "user") : -1;
299
+ if (boundary < 0)
300
+ throw new Error("submitted prompt missing from consolidation transcript");
301
+ const turn = rows.slice(boundary + 1);
302
+ const nextUser = turn.findIndex((m) => m?.type === "user");
303
+ const messages = nextUser < 0 ? turn : turn.slice(0, nextUser);
304
+ const assistant = messages.findLast((m) => m?.type === "assistant");
305
+ if (!assistant)
306
+ throw new Error("no assistant reply after consolidation wait");
307
+ if (assistant.error) {
308
+ // V1 runPrompt recognizes info.error, including its quota status code.
309
+ const error = assistant.error;
310
+ return { data: { info: { error: {
311
+ name: error.type ?? error.name,
312
+ data: { message: error.message ?? error.data?.message, statusCode: error.status ?? error.statusCode ?? error.data?.statusCode },
313
+ } }, parts: [] } };
314
+ }
315
+ const idle = messages.findLast((m) => m?.type === "idle");
316
+ if (idle && idle.outcome !== "succeeded")
317
+ throw new Error(`consolidation ${idle.outcome} after session.wait`);
318
+ if (!assistant.time?.completed || !["stop", "length", "content-filter"].includes(assistant.finish)) {
319
+ throw new Error(`consolidation turn incomplete after session.wait (${assistant.finish ?? "no finish"})`);
320
+ }
321
+ return { data: { info: {}, parts: [{ type: "text", text: joinTextParts(assistant.content) }] } };
322
+ }
266
323
  function adaptV2SessionRow(row) {
267
324
  if (!row || typeof row !== "object")
268
325
  return row;
@@ -302,7 +359,7 @@ async function v2promptWithWait(sessionID, body, signal) {
302
359
  throw new Error("sub-agent prompt cancelled");
303
360
  const publicClient = await ownServiceClient();
304
361
  if (typeof publicClient?.generate?.text === "function") {
305
- const gen = await publicClient.generate.text(payload, signal ? { signal } : undefined);
362
+ const gen = await serviceRequest(publicClient, () => publicClient.generate.text(payload, signal ? { signal } : undefined));
306
363
  const outText = typeof gen?.text === "string" ? gen.text : JSON.stringify(gen);
307
364
  return { data: { parts: [{ type: "text", text: outText }] } };
308
365
  }
@@ -357,7 +414,9 @@ async function v2promptWithWait(sessionID, body, signal) {
357
414
  else {
358
415
  await waitP;
359
416
  }
360
- return { data: { posted } };
417
+ // wait means idle, not successful. Codex requires Completed before phase 2
418
+ // may validate artifacts and reset the last-successful workspace baseline.
419
+ return completedPromptResponse(await loadV2Messages(sessionID, c, signal), und(posted)?.id);
361
420
  }
362
421
  /** Build the V1-shaped client. Passed to setPluginInput() by V2 setup(). */
363
422
  export function buildV1ClientShim() {
@@ -417,7 +476,7 @@ export function buildV1ClientShim() {
417
476
  }
418
477
  const client = await ownServiceClient();
419
478
  if (client && typeof client.session.list === "function") {
420
- return paginateSessionList((input) => client.session.list(input), limit, cursor, search);
479
+ return paginateSessionList((input) => serviceRequest(client, () => client.session.list(input)), limit, cursor, search);
421
480
  }
422
481
  if (client)
423
482
  throw new Error("registered service does not support session.list");
@@ -439,6 +498,9 @@ export function buildV1ClientShim() {
439
498
  const res = await ctx().session.create({
440
499
  ...(opts?.body?.title ? { title: opts.body.title } : {}),
441
500
  ...(opts?.body?.metadata ? { metadata: opts.body.metadata } : {}),
501
+ ...(opts?.body?.title === "codex-memory-consolidate"
502
+ ? { permissions: consolidationPermissions(memoryRoot()) }
503
+ : {}),
442
504
  location: { directory: opts?.query?.directory ?? memoryRoot() },
443
505
  });
444
506
  return { data: { id: und(res)?.id } };
@@ -452,37 +514,14 @@ export function buildV1ClientShim() {
452
514
  return await v2promptWithWait(opts.path.id, opts.body, opts.signal);
453
515
  }
454
516
  catch (e) {
455
- return { error: e };
517
+ return { error: e instanceof Error ? { message: e.message } : e };
456
518
  }
457
519
  },
458
520
  messages: async (opts) => {
459
521
  try {
460
522
  if (isReleasedSubSession(opts.path.id))
461
523
  throw Object.assign(new Error("SessionNotFound"), { _tag: "SessionNotFoundError" });
462
- const client = await ownServiceClient();
463
- if (typeof client?.message?.list === "function") {
464
- const messages = [];
465
- const seenCursors = new Set();
466
- let cursor;
467
- while (true) {
468
- const response = await client.message.list(cursor ? { sessionID: opts.path.id, cursor } : { sessionID: opts.path.id, order: "asc" });
469
- const rows = responseRows(response);
470
- if (!rows)
471
- throw new Error("registered service returned an invalid message list");
472
- messages.push(...rows);
473
- const next = responseNextCursor(response);
474
- if (!next || seenCursors.has(next))
475
- break;
476
- seenCursors.add(next);
477
- cursor = next;
478
- }
479
- return { data: adaptV2Messages(messages) };
480
- }
481
- const raw = await ctx().session.context({
482
- sessionID: opts.path.id,
483
- });
484
- const rows = Array.isArray(raw) ? raw : responseRows(raw) ?? [];
485
- return { data: adaptV2Messages(rows) };
524
+ return { data: adaptV2Messages(await loadV2Messages(opts.path.id)) };
486
525
  }
487
526
  catch (e) {
488
527
  return { error: e };
@@ -500,7 +539,7 @@ export function buildV1ClientShim() {
500
539
  const client = await serviceOrThrow();
501
540
  if (typeof client.session.remove !== "function")
502
541
  throw new Error("registered service does not support session.remove");
503
- const result = await client.session.remove({ sessionID: opts.path.id }, opts.signal ? { signal: opts.signal } : undefined);
542
+ const result = await serviceRequest(client, () => client.session.remove({ sessionID: opts.path.id }, opts.signal ? { signal: opts.signal } : undefined));
504
543
  if (result?.error)
505
544
  throw result.error;
506
545
  if (await sessionGoneOnService(client, opts.path.id)) {
@@ -526,7 +565,7 @@ export function buildV1ClientShim() {
526
565
  try {
527
566
  const client = await ownServiceClient();
528
567
  if (client?.session?.get) {
529
- const info = await client.session.get({ sessionID: opts.path.id });
568
+ const info = await serviceRequest(client, () => client.session.get({ sessionID: opts.path.id }));
530
569
  if (info?.error && isNotFoundError(info.error)) {
531
570
  markReleased(opts.path.id);
532
571
  return {};
@@ -559,7 +598,7 @@ export function buildV1ClientShim() {
559
598
  const client = await ownServiceClient();
560
599
  if (client?.session?.get) {
561
600
  try {
562
- const info = und(await client.session.get({ sessionID: opts.path.id }));
601
+ const info = und(await serviceRequest(client, () => client.session.get({ sessionID: opts.path.id })));
563
602
  return { data: info };
564
603
  }
565
604
  catch (e) {
@@ -584,7 +623,7 @@ export function buildV1ClientShim() {
584
623
  const client = await serviceOrThrow();
585
624
  if (typeof client.session.interrupt !== "function")
586
625
  throw new Error("registered service does not support session.interrupt");
587
- const result = await client.session.interrupt({ sessionID: opts.path.id });
626
+ const result = await serviceRequest(client, () => client.session.interrupt({ sessionID: opts.path.id }));
588
627
  if (!result?.error)
589
628
  return {};
590
629
  }
@@ -604,7 +643,7 @@ export function buildV1ClientShim() {
604
643
  get: async () => {
605
644
  try {
606
645
  const client = await serviceOrThrow();
607
- const response = await client.config?.get({ location: { directory: ctx().location.directory } });
646
+ const response = await serviceRequest(client, async () => client.config?.get({ location: { directory: ctx().location.directory } }));
608
647
  const documents = und(response);
609
648
  const candidates = Array.isArray(documents) ? documents : documents?.type === "document" ? [documents] : [];
610
649
  let info = {};
@@ -635,7 +674,11 @@ export function buildV1ClientShim() {
635
674
  const provider = {
636
675
  list: async () => {
637
676
  try {
638
- const res = await ctx().catalog.model.list();
677
+ const c = ctx();
678
+ const models = c.model ?? c.catalog?.model;
679
+ if (typeof models?.list !== "function")
680
+ throw new Error("host does not support model.list");
681
+ const res = await models.list();
639
682
  return { data: adaptProviderCatalog(res) };
640
683
  }
641
684
  catch (e) {
@@ -10,6 +10,19 @@ export declare const MEMORY_STATUS_ACTIVITIES: readonly ["idle", "extracting", "
10
10
  export type MemoryStatusActivity = (typeof MEMORY_STATUS_ACTIVITIES)[number];
11
11
  export interface MemoryStatus {
12
12
  activity: MemoryStatusActivity;
13
+ version: "v1" | "v2";
14
+ sessionVersion: "v1" | "v2";
15
+ dualWrite: boolean;
16
+ v2ConsolidatedThreads: number;
17
+ v2Ready: boolean;
18
+ minConsolidatedThreads: number;
19
+ pipelines: {
20
+ version: "v1" | "v2";
21
+ stage1Count: number;
22
+ extracting: number;
23
+ phase2Status: string | null;
24
+ lastError: string | null;
25
+ }[];
13
26
  useMemories: boolean;
14
27
  generateMemories: boolean;
15
28
  extractModel: string | null;
@@ -40,6 +53,11 @@ export declare const MemoryStatusRpc: {
40
53
  readonly sessionID: {
41
54
  readonly type: "string";
42
55
  };
56
+ readonly minConsolidatedThreads: {
57
+ readonly type: "integer";
58
+ readonly minimum: 1;
59
+ readonly maximum: 4096;
60
+ };
43
61
  };
44
62
  readonly additionalProperties: false;
45
63
  };
@@ -50,9 +68,60 @@ export declare const MemoryStatusRpc: {
50
68
  readonly type: "string";
51
69
  readonly enum: readonly ["idle", "extracting", "consolidating", "retrying", "error", "read_only", "disabled", "stopping"];
52
70
  };
71
+ readonly version: {
72
+ readonly type: "string";
73
+ readonly enum: readonly ["v1", "v2"];
74
+ };
75
+ readonly sessionVersion: {
76
+ readonly type: "string";
77
+ readonly enum: readonly ["v1", "v2"];
78
+ };
79
+ readonly dualWrite: {
80
+ readonly type: "boolean";
81
+ };
82
+ readonly v2ConsolidatedThreads: {
83
+ readonly type: "integer";
84
+ readonly minimum: 0;
85
+ };
86
+ readonly v2Ready: {
87
+ readonly type: "boolean";
88
+ };
89
+ readonly minConsolidatedThreads: {
90
+ readonly type: "integer";
91
+ readonly minimum: 1;
92
+ readonly maximum: 4096;
93
+ };
53
94
  readonly useMemories: {
54
95
  readonly type: "boolean";
55
96
  };
97
+ readonly pipelines: {
98
+ readonly type: "array";
99
+ readonly items: {
100
+ readonly type: "object";
101
+ readonly properties: {
102
+ readonly version: {
103
+ readonly type: "string";
104
+ readonly enum: readonly ["v1", "v2"];
105
+ };
106
+ readonly stage1Count: {
107
+ readonly type: "integer";
108
+ readonly minimum: 0;
109
+ };
110
+ readonly extracting: {
111
+ readonly type: "integer";
112
+ readonly minimum: 0;
113
+ };
114
+ readonly phase2Status: {
115
+ readonly type: readonly ["string", "null"];
116
+ };
117
+ readonly lastError: {
118
+ readonly type: readonly ["string", "null"];
119
+ };
120
+ };
121
+ readonly required: readonly ["version", "stage1Count", "extracting", "phase2Status", "lastError"];
122
+ readonly additionalProperties: false;
123
+ };
124
+ };
56
125
  readonly generateMemories: {
57
126
  readonly type: "boolean";
58
127
  };
@@ -104,7 +173,7 @@ export declare const MemoryStatusRpc: {
104
173
  readonly additionalProperties: false;
105
174
  };
106
175
  };
107
- readonly required: readonly ["activity", "useMemories", "generateMemories", "extractModel", "consolidationModel", "codexImport", "lastSuccessAt", "retryAt", "warnings", "sessionMode", "memoryRoot", "injected"];
176
+ readonly required: readonly ["activity", "version", "sessionVersion", "dualWrite", "v2ConsolidatedThreads", "v2Ready", "minConsolidatedThreads", "pipelines", "useMemories", "generateMemories", "extractModel", "consolidationModel", "codexImport", "lastSuccessAt", "retryAt", "warnings", "sessionMode", "memoryRoot", "injected"];
108
177
  readonly additionalProperties: false;
109
178
  };
110
179
  };
@@ -33,14 +33,38 @@ export const MemoryStatusRpc = {
33
33
  status: {
34
34
  input: {
35
35
  type: "object",
36
- properties: { sessionID: { type: "string" } },
36
+ properties: {
37
+ sessionID: { type: "string" },
38
+ minConsolidatedThreads: { type: "integer", minimum: 1, maximum: 4096 },
39
+ },
37
40
  additionalProperties: false,
38
41
  },
39
42
  output: {
40
43
  type: "object",
41
44
  properties: {
42
45
  activity: { type: "string", enum: [...MEMORY_STATUS_ACTIVITIES] },
46
+ version: { type: "string", enum: ["v1", "v2"] },
47
+ sessionVersion: { type: "string", enum: ["v1", "v2"] },
48
+ dualWrite: { type: "boolean" },
49
+ v2ConsolidatedThreads: { type: "integer", minimum: 0 },
50
+ v2Ready: { type: "boolean" },
51
+ minConsolidatedThreads: { type: "integer", minimum: 1, maximum: 4096 },
43
52
  useMemories: { type: "boolean" },
53
+ pipelines: {
54
+ type: "array",
55
+ items: {
56
+ type: "object",
57
+ properties: {
58
+ version: { type: "string", enum: ["v1", "v2"] },
59
+ stage1Count: { type: "integer", minimum: 0 },
60
+ extracting: { type: "integer", minimum: 0 },
61
+ phase2Status: { type: ["string", "null"] },
62
+ lastError: { type: ["string", "null"] },
63
+ },
64
+ required: ["version", "stage1Count", "extracting", "phase2Status", "lastError"],
65
+ additionalProperties: false,
66
+ },
67
+ },
44
68
  generateMemories: { type: "boolean" },
45
69
  extractModel: { type: ["string", "null"] },
46
70
  consolidationModel: { type: ["string", "null"] },
@@ -54,6 +78,7 @@ export const MemoryStatusRpc = {
54
78
  },
55
79
  required: [
56
80
  "activity",
81
+ "version", "sessionVersion", "dualWrite", "v2ConsolidatedThreads", "v2Ready", "minConsolidatedThreads", "pipelines",
57
82
  "useMemories",
58
83
  "generateMemories",
59
84
  "extractModel",
@@ -121,10 +146,24 @@ export function isMemoryStatus(value) {
121
146
  !MEMORY_STATUS_ACTIVITIES.includes(value.activity)) {
122
147
  return false;
123
148
  }
124
- for (const key of ["useMemories", "generateMemories", "codexImport"]) {
149
+ for (const key of ["useMemories", "generateMemories", "codexImport", "dualWrite", "v2Ready"]) {
125
150
  if (typeof value[key] !== "boolean")
126
151
  return false;
127
152
  }
153
+ for (const key of ["version", "sessionVersion"]) {
154
+ if (value[key] !== "v1" && value[key] !== "v2")
155
+ return false;
156
+ }
157
+ if (!Number.isInteger(value.v2ConsolidatedThreads) || value.v2ConsolidatedThreads < 0)
158
+ return false;
159
+ if (!Number.isInteger(value.minConsolidatedThreads) || value.minConsolidatedThreads < 1 || value.minConsolidatedThreads > 4096)
160
+ return false;
161
+ if (!Array.isArray(value.pipelines) || !value.pipelines.every((pipeline) => isRecord(pipeline) && (pipeline.version === "v1" || pipeline.version === "v2")
162
+ && Number.isInteger(pipeline.stage1Count) && pipeline.stage1Count >= 0
163
+ && Number.isInteger(pipeline.extracting) && pipeline.extracting >= 0
164
+ && (pipeline.phase2Status === null || typeof pipeline.phase2Status === "string")
165
+ && (pipeline.lastError === null || typeof pipeline.lastError === "string")))
166
+ return false;
128
167
  for (const key of ["extractModel", "consolidationModel", "lastSuccessAt", "retryAt"]) {
129
168
  const v = value[key];
130
169
  if (v !== null && typeof v !== (key === "extractModel" || key === "consolidationModel" ? "string" : "number")) {
@@ -1,3 +1,3 @@
1
1
  import type { MemoryStatus } from "./status-rpc.js";
2
2
  /** Read the same snapshots as memory_inspect; never claim or advance a job. */
3
- export declare function readMemoryStatus(sessionID?: string | null): MemoryStatus;
3
+ export declare function readMemoryStatus(sessionID?: string | null, minConsolidatedThreads?: number): MemoryStatus;
@@ -7,9 +7,21 @@ 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";
11
+ import { peekSessionMemoryVersion } from "../session-version.js";
12
+ import { withMemoryVersion, writeMemoryVersions } from "../memory-version.js";
10
13
  /** Read the same snapshots as memory_inspect; never claim or advance a job. */
11
- export function readMemoryStatus(sessionID) {
12
- const store = new MemoryStore();
14
+ export function readMemoryStatus(sessionID, minConsolidatedThreads) {
15
+ const sessionVersion = peekSessionMemoryVersion(sessionID);
16
+ const store = withMemoryVersion(sessionVersion, () => new MemoryStore());
17
+ const pipelines = memoryPipelineSnapshots().map((pipeline) => ({
18
+ version: pipeline.version,
19
+ stage1Count: pipeline.stage1Count,
20
+ extracting: pipeline.stage1Jobs.running ?? 0,
21
+ phase2Status: pipeline.phase2?.status ?? null,
22
+ lastError: pipeline.phase2?.last_error ?? null,
23
+ }));
24
+ const active = pipelines.filter((pipeline) => writeMemoryVersions().includes(pipeline.version));
13
25
  const options = pluginOptions;
14
26
  const now = Date.now();
15
27
  const staleBeforeSec = Math.floor(now / 1000) - options.max_rollout_age_days * 86_400;
@@ -31,6 +43,10 @@ export function readMemoryStatus(sessionID) {
31
43
  }
32
44
  if (phase2?.last_error)
33
45
  warnings.push("Consolidation failed; see memory_inspect for details.");
46
+ for (const pipeline of active) {
47
+ if (pipeline.version !== sessionVersion && pipeline.lastError)
48
+ warnings.push(`${pipeline.version}: consolidation failed; see memory_inspect.`);
49
+ }
34
50
  if (phase1.by_failure_class.due > 0)
35
51
  warnings.push("Some extraction jobs are due to retry.");
36
52
  if (phase1.by_failure_class.other_exhausted > phase1.stale_exhausted) {
@@ -38,8 +54,9 @@ export function readMemoryStatus(sessionID) {
38
54
  }
39
55
  if (phase1.by_failure_class.provider_capacity > 0)
40
56
  warnings.push("Some extraction jobs hit provider capacity limits.");
41
- const codexImport = options.codex_interop.import && resolveCodexInterop(options.codex_interop) !== null;
42
- if (options.codex_interop.import && !codexImport)
57
+ const importsV1 = options.codex_interop.import && writeMemoryVersions().includes("v1");
58
+ const codexImport = importsV1 && withMemoryVersion("v1", () => resolveCodexInterop(options.codex_interop)) !== null;
59
+ if (importsV1 && !codexImport)
43
60
  warnings.push("Codex import is misconfigured.");
44
61
  // A `running` row this process does not own is either another opencode
45
62
  // instance's live job or an orphaned lease (e.g. a server restart killed the
@@ -56,7 +73,7 @@ export function readMemoryStatus(sessionID) {
56
73
  activity = "stopping";
57
74
  else if (isPhase2InFlight())
58
75
  activity = "consolidating";
59
- else if ((phase1.by_status.running ?? 0) > 0)
76
+ else if (active.some((pipeline) => pipeline.extracting > 0))
60
77
  activity = "extracting";
61
78
  else if (!options.generate_memories)
62
79
  activity = options.use_memories ? "read_only" : "disabled";
@@ -66,6 +83,11 @@ export function readMemoryStatus(sessionID) {
66
83
  activity = "error";
67
84
  return {
68
85
  activity,
86
+ version: options.version,
87
+ sessionVersion,
88
+ pipelines,
89
+ dualWrite: options.dual_write,
90
+ ...readMigrationStatus(minConsolidatedThreads),
69
91
  useMemories: options.use_memories,
70
92
  generateMemories: options.generate_memories,
71
93
  extractModel: options.extract_model ?? null,
@@ -76,7 +98,7 @@ export function readMemoryStatus(sessionID) {
76
98
  retryAt,
77
99
  warnings,
78
100
  sessionMode: sessionID ? store.getMemoryMode(sessionID) : null,
79
- memoryRoot: memoryRoot(),
101
+ memoryRoot: memoryRoot(sessionVersion),
80
102
  injected: {
81
103
  sessionTokens: session.tokens,
82
104
  sessionRequests: session.requests,
@@ -39,14 +39,38 @@ var MemoryStatusRpc = {
39
39
  status: {
40
40
  input: {
41
41
  type: "object",
42
- properties: { sessionID: { type: "string" } },
42
+ properties: {
43
+ sessionID: { type: "string" },
44
+ minConsolidatedThreads: { type: "integer", minimum: 1, maximum: 4096 }
45
+ },
43
46
  additionalProperties: false
44
47
  },
45
48
  output: {
46
49
  type: "object",
47
50
  properties: {
48
51
  activity: { type: "string", enum: [...MEMORY_STATUS_ACTIVITIES] },
52
+ version: { type: "string", enum: ["v1", "v2"] },
53
+ sessionVersion: { type: "string", enum: ["v1", "v2"] },
54
+ dualWrite: { type: "boolean" },
55
+ v2ConsolidatedThreads: { type: "integer", minimum: 0 },
56
+ v2Ready: { type: "boolean" },
57
+ minConsolidatedThreads: { type: "integer", minimum: 1, maximum: 4096 },
49
58
  useMemories: { type: "boolean" },
59
+ pipelines: {
60
+ type: "array",
61
+ items: {
62
+ type: "object",
63
+ properties: {
64
+ version: { type: "string", enum: ["v1", "v2"] },
65
+ stage1Count: { type: "integer", minimum: 0 },
66
+ extracting: { type: "integer", minimum: 0 },
67
+ phase2Status: { type: ["string", "null"] },
68
+ lastError: { type: ["string", "null"] }
69
+ },
70
+ required: ["version", "stage1Count", "extracting", "phase2Status", "lastError"],
71
+ additionalProperties: false
72
+ }
73
+ },
50
74
  generateMemories: { type: "boolean" },
51
75
  extractModel: { type: ["string", "null"] },
52
76
  consolidationModel: { type: ["string", "null"] },
@@ -60,6 +84,13 @@ var MemoryStatusRpc = {
60
84
  },
61
85
  required: [
62
86
  "activity",
87
+ "version",
88
+ "sessionVersion",
89
+ "dualWrite",
90
+ "v2ConsolidatedThreads",
91
+ "v2Ready",
92
+ "minConsolidatedThreads",
93
+ "pipelines",
63
94
  "useMemories",
64
95
  "generateMemories",
65
96
  "extractModel",
@@ -122,10 +153,20 @@ function isMemoryStatus(value) {
122
153
  if (typeof value.activity !== "string" || !MEMORY_STATUS_ACTIVITIES.includes(value.activity)) {
123
154
  return false;
124
155
  }
125
- for (const key of ["useMemories", "generateMemories", "codexImport"]) {
156
+ for (const key of ["useMemories", "generateMemories", "codexImport", "dualWrite", "v2Ready"]) {
126
157
  if (typeof value[key] !== "boolean")
127
158
  return false;
128
159
  }
160
+ for (const key of ["version", "sessionVersion"]) {
161
+ if (value[key] !== "v1" && value[key] !== "v2")
162
+ return false;
163
+ }
164
+ if (!Number.isInteger(value.v2ConsolidatedThreads) || value.v2ConsolidatedThreads < 0)
165
+ return false;
166
+ if (!Number.isInteger(value.minConsolidatedThreads) || value.minConsolidatedThreads < 1 || value.minConsolidatedThreads > 4096)
167
+ return false;
168
+ 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")))
169
+ return false;
129
170
  for (const key of ["extractModel", "consolidationModel", "lastSuccessAt", "retryAt"]) {
130
171
  const v = value[key];
131
172
  if (v !== null && typeof v !== (key === "extractModel" || key === "consolidationModel" ? "string" : "number")) {
@@ -235,6 +276,20 @@ function statusRows(s, now) {
235
276
  label: "Activity",
236
277
  value: labels[s.activity]
237
278
  }, {
279
+ label: "Memory version",
280
+ value: `${s.sessionVersion} (default ${s.version})`
281
+ }, {
282
+ label: "Learning pipelines",
283
+ value: s.dualWrite ? "v1 + v2" : s.version
284
+ }, {
285
+ label: "V2 readiness",
286
+ value: `${s.v2Ready ? "Ready" : "Warming"} \xB7 ${s.v2ConsolidatedThreads}/${s.minConsolidatedThreads} sessions`,
287
+ tone: s.v2Ready ? "ok" : "muted"
288
+ }, ...s.pipelines.map((pipeline) => ({
289
+ label: `${pipeline.version.toUpperCase()} pipeline`,
290
+ value: `${pipeline.stage1Count} recaps \xB7 ${pipeline.extracting ? "extracting" : pipeline.phase2Status ?? "idle"}`,
291
+ tone: pipeline.lastError ? "warn" : "muted"
292
+ })), {
238
293
  label: "Read memories",
239
294
  value: s.useMemories ? "On" : "Off",
240
295
  tone: s.useMemories ? "ok" : "muted"
@@ -1,20 +1,22 @@
1
+ import type { MemoryVersion } from "./options.js";
1
2
  import type { Stage1Output } from "./store.js";
2
3
  import { type WorkspaceDiff } from "./git-baseline.js";
3
4
  /** Mirrors codex `remove_memory_symlinks` (workspace.rs): unlink every symlink in the tree, never follow. */
4
5
  export declare function removeMemorySymlinks(root?: string): number;
5
6
  export declare function ensureLayout(): void;
6
- /**
7
- * Mirrors codex `validate_consolidation_artifacts` (workspace.rs): after
8
- * consolidation (or when deciding an early no-diff succeed), MEMORY.md must be
9
- * a regular file and memory_summary.md must start with the exact line `v1`.
10
- * Invalid artifacts force a consolidator re-run and block baseline reset.
11
- */
7
+ export declare function isValidV2Summary(summary: string): boolean;
12
8
  export declare function validateConsolidationArtifacts(root?: string): {
13
9
  ok: true;
14
10
  } | {
15
11
  ok: false;
16
12
  reason: string;
17
13
  };
14
+ export declare function validateConsolidationArtifactsForVersion(root?: string, version?: MemoryVersion): {
15
+ ok: true;
16
+ } | {
17
+ ok: false;
18
+ reason: string;
19
+ };
18
20
  export declare function rolloutSummaryFileStem(o: Pick<Stage1Output, "session_id" | "source_updated_at" | "rollout_slug">): string;
19
21
  export declare function rebuildRawMemories(outputs: Stage1Output[]): string;
20
22
  export declare function writeRolloutSummaries(outputs: Stage1Output[]): void;