opencode-codex-memory 0.7.7 → 0.8.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.
Files changed (57) hide show
  1. package/README.md +51 -8
  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/codex-interop.js +5 -0
  6. package/dist/src/db.d.ts +7 -1
  7. package/dist/src/db.js +38 -11
  8. package/dist/src/host-client.d.ts +5 -0
  9. package/dist/src/index.d.ts +12 -4
  10. package/dist/src/index.js +39 -61
  11. package/dist/src/lifecycle.js +14 -9
  12. package/dist/src/llm.d.ts +3 -2
  13. package/dist/src/llm.js +47 -11
  14. package/dist/src/memory-version.d.ts +5 -0
  15. package/dist/src/memory-version.js +16 -0
  16. package/dist/src/migration.d.ts +24 -0
  17. package/dist/src/migration.js +37 -0
  18. package/dist/src/options.d.ts +4 -0
  19. package/dist/src/options.js +2 -0
  20. package/dist/src/paths.d.ts +9 -3
  21. package/dist/src/paths.js +22 -8
  22. package/dist/src/phase1.js +16 -2
  23. package/dist/src/phase2.js +15 -9
  24. package/dist/src/pipeline.d.ts +3 -0
  25. package/dist/src/pipeline.js +74 -0
  26. package/dist/src/ratelimit.js +5 -4
  27. package/dist/src/rollout-input.d.ts +3 -2
  28. package/dist/src/rollout-input.js +26 -17
  29. package/dist/src/session-version.d.ts +9 -0
  30. package/dist/src/session-version.js +27 -0
  31. package/dist/src/source.js +21 -6
  32. package/dist/src/store.d.ts +10 -1
  33. package/dist/src/store.js +76 -24
  34. package/dist/src/templates/consolidation_v2.md +54 -0
  35. package/dist/src/templates/read_path_v2.md +58 -0
  36. package/dist/src/templates/stage_one_input_v2.md +21 -0
  37. package/dist/src/templates/stage_one_system_v2.md +53 -0
  38. package/dist/src/token.d.ts +2 -0
  39. package/dist/src/token.js +16 -0
  40. package/dist/src/v2/agents.d.ts +4 -2
  41. package/dist/src/v2/agents.js +15 -7
  42. package/dist/src/v2/citation-overlay.d.ts +1 -1
  43. package/dist/src/v2/citation-overlay.js +27 -4
  44. package/dist/src/v2/plugin.js +24 -72
  45. package/dist/src/v2/shim.js +5 -1
  46. package/dist/src/v2/status-rpc.d.ts +70 -1
  47. package/dist/src/v2/status-rpc.js +41 -2
  48. package/dist/src/v2/status.d.ts +1 -1
  49. package/dist/src/v2/status.js +28 -6
  50. package/dist/src/v2/tui.js +57 -2
  51. package/dist/src/workspace.d.ts +8 -6
  52. package/dist/src/workspace.js +31 -11
  53. package/dist/tools/control.d.ts +6 -2
  54. package/dist/tools/control.js +196 -164
  55. package/dist/tools/memory.js +11 -1
  56. package/opencode.json +2 -2
  57. package/package.json +1 -1
@@ -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;
@@ -1,6 +1,7 @@
1
1
  import { createHash } from "crypto";
2
2
  import fs from "fs";
3
3
  import path from "path";
4
+ import { currentMemoryVersion } from "./memory-version.js";
4
5
  import { memoryRoot } from "./paths.js";
5
6
  import { assertMemoryRootSafe, readRegularFileNoFollow, safeResolveMemoryPath, writeRegularFileNoFollow, } from "./path-guard.js";
6
7
  import { DIFF_ARTIFACT } from "./git-baseline.js";
@@ -73,9 +74,11 @@ export function ensureLayout() {
73
74
  for (const dir of [ROLLOUT_DIR, SKILLS_DIR, EXTENSIONS_DIR, ADHOC_NOTES_DIR]) {
74
75
  fs.mkdirSync(safeResolveMemoryPath(dir), { recursive: true });
75
76
  }
76
- const memoryMd = safeResolveMemoryPath("MEMORY.md");
77
- if (!fs.existsSync(memoryMd))
78
- writeRegularFileNoFollow(memoryMd, "# MEMORY.md\n\n_Searchable index of memories._\n");
77
+ if (currentMemoryVersion() === "v1") {
78
+ const memoryMd = safeResolveMemoryPath("MEMORY.md");
79
+ if (!fs.existsSync(memoryMd))
80
+ writeRegularFileNoFollow(memoryMd, "# MEMORY.md\n\n_Searchable index of memories._\n");
81
+ }
79
82
  const summary = safeResolveMemoryPath("memory_summary.md");
80
83
  if (!fs.existsSync(summary))
81
84
  writeRegularFileNoFollow(summary, "");
@@ -89,7 +92,19 @@ export function ensureLayout() {
89
92
  * a regular file and memory_summary.md must start with the exact line `v1`.
90
93
  * Invalid artifacts force a consolidator re-run and block baseline reset.
91
94
  */
95
+ const V2_SUMMARY_HEADINGS = ["## User Profile", "## User preferences", "## General Tips", "## What's in Memory"];
96
+ export function isValidV2Summary(summary) {
97
+ if (summary.split(/\r?\n/, 1)[0] !== "v1")
98
+ return false;
99
+ if (Buffer.byteLength(summary, "utf8") >= 10_000)
100
+ return false;
101
+ const lines = summary.split(/\r?\n/).map((line) => line.trim());
102
+ return V2_SUMMARY_HEADINGS.every((heading) => lines.includes(heading));
103
+ }
92
104
  export function validateConsolidationArtifacts(root = memoryRoot()) {
105
+ return validateConsolidationArtifactsForVersion(root, "v1");
106
+ }
107
+ export function validateConsolidationArtifactsForVersion(root = memoryRoot(), version = currentMemoryVersion()) {
93
108
  let removedSymlinks;
94
109
  try {
95
110
  removedSymlinks = removeMemorySymlinks(root);
@@ -100,14 +115,16 @@ export function validateConsolidationArtifacts(root = memoryRoot()) {
100
115
  if (removedSymlinks !== 0) {
101
116
  return { ok: false, reason: `removed ${removedSymlinks} symbolic links from consolidated memory workspace` };
102
117
  }
103
- const memoryPath = path.join(root, "MEMORY.md");
104
- try {
105
- const st = fs.lstatSync(memoryPath);
106
- if (!st.isFile())
107
- return { ok: false, reason: `consolidated memory artifact is not a file: ${memoryPath}` };
108
- }
109
- catch {
110
- return { ok: false, reason: `missing consolidated memory artifact: ${memoryPath}` };
118
+ if (version === "v1") {
119
+ const memoryPath = path.join(root, "MEMORY.md");
120
+ try {
121
+ const st = fs.lstatSync(memoryPath);
122
+ if (!st.isFile())
123
+ return { ok: false, reason: `consolidated memory artifact is not a file: ${memoryPath}` };
124
+ }
125
+ catch {
126
+ return { ok: false, reason: `missing consolidated memory artifact: ${memoryPath}` };
127
+ }
111
128
  }
112
129
  const summaryPath = path.join(root, "memory_summary.md");
113
130
  let summary;
@@ -124,6 +141,9 @@ export function validateConsolidationArtifacts(root = memoryRoot()) {
124
141
  if (first !== "v1") {
125
142
  return { ok: false, reason: `memory summary artifact does not start with v1: ${summaryPath}` };
126
143
  }
144
+ if (version === "v2" && !isValidV2Summary(summary)) {
145
+ return { ok: false, reason: "invalid v2 memory summary" };
146
+ }
127
147
  return { ok: true };
128
148
  }
129
149
  const RAW_MEMORY_MAX_CHARS = 10_000;
@@ -9,8 +9,12 @@ export declare const memory_reset: {
9
9
  };
10
10
  export declare const memory_inspect: {
11
11
  description: string;
12
- args: {};
13
- execute(args: Record<string, never>, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
12
+ args: {
13
+ min_consolidated_threads: import("zod").ZodOptional<import("zod").ZodNumber>;
14
+ };
15
+ execute(args: {
16
+ min_consolidated_threads?: number | undefined;
17
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
14
18
  };
15
19
  export declare const memory_mode: {
16
20
  description: string;