opencode-codex-memory 0.9.8 → 0.9.9

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.9.8" }
38
+ { "package": "opencode-codex-memory@0.9.9" }
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.9.8"]
48
+ "plugin": ["opencode-codex-memory@0.9.9"]
49
49
  }
50
50
  ```
51
51
 
@@ -5,6 +5,7 @@ export declare function readMigrationStatus(minConsolidatedThreads?: number): {
5
5
  v2Ready: boolean;
6
6
  v2NotReadyReason: string | null;
7
7
  v2SummaryBytes: number | null;
8
+ v2InjectedSummaryBytes: number | null;
8
9
  minConsolidatedThreads: number;
9
10
  };
10
11
  export declare function memoryPipelineSnapshots(): {
@@ -4,6 +4,7 @@ import { MemoryStore, existingMemoryStores } from "./store.js";
4
4
  import { withMemoryVersion } from "./memory-version.js";
5
5
  import { validateV2Summary } from "./workspace.js";
6
6
  import { safeResolveUnderRoot, readRegularFileNoFollow } from "./path-guard.js";
7
+ import { MEMORY_V2_SUMMARY_MAX_BYTES, truncateToBytes } from "./token.js";
7
8
  export const DEFAULT_MIN_CONSOLIDATED_THREADS = 20;
8
9
  /** Codex memory/status: high-water progress AND a currently valid V2 summary. */
9
10
  export function readMigrationStatus(minConsolidatedThreads = DEFAULT_MIN_CONSOLIDATED_THREADS) {
@@ -15,12 +16,15 @@ export function readMigrationStatus(minConsolidatedThreads = DEFAULT_MIN_CONSOLI
15
16
  : 0;
16
17
  let valid = false;
17
18
  let v2SummaryBytes = null;
19
+ let v2InjectedSummaryBytes = null;
18
20
  let v2NotReadyReason = null;
19
21
  try {
20
22
  const file = safeResolveUnderRoot(memoryRoot("v2"), "memory_summary.md");
21
- const validation = validateV2Summary(readRegularFileNoFollow(file).content.toString("utf8"));
23
+ const summary = readRegularFileNoFollow(file).content.toString("utf8");
24
+ const validation = validateV2Summary(summary);
22
25
  valid = validation.ok;
23
26
  v2SummaryBytes = validation.bytes;
27
+ v2InjectedSummaryBytes = Buffer.byteLength(truncateToBytes(summary.trim(), MEMORY_V2_SUMMARY_MAX_BYTES), "utf8");
24
28
  v2NotReadyReason = validation.reason;
25
29
  }
26
30
  catch (error) {
@@ -36,6 +40,7 @@ export function readMigrationStatus(minConsolidatedThreads = DEFAULT_MIN_CONSOLI
36
40
  v2Ready: valid && v2ConsolidatedThreads >= minConsolidatedThreads,
37
41
  v2NotReadyReason,
38
42
  v2SummaryBytes,
43
+ v2InjectedSummaryBytes,
39
44
  minConsolidatedThreads,
40
45
  };
41
46
  }
@@ -3,7 +3,7 @@ import path from "path";
3
3
  import { currentMemoryVersion } from "./memory-version.js";
4
4
  import { memoryRoot } from "./paths.js";
5
5
  import { assertMemoryRootSafe, safeResolveMemoryPath, withRegularFileNoFollow } from "./path-guard.js";
6
- import { truncateToTokens } from "./token.js";
6
+ import { MEMORY_V2_SUMMARY_MAX_BYTES, truncateToBytes, truncateToTokens } from "./token.js";
7
7
  import { fillTemplate } from "./llm.js";
8
8
  const MEMORY_SUMMARY_TOKEN_LIMIT = 2500;
9
9
  const READ_PATH_TEMPLATE = "read_path.md";
@@ -61,7 +61,9 @@ function readMemorySummary() {
61
61
  const raw = fs.readFileSync(fd, "utf8").trim();
62
62
  if (!raw)
63
63
  return null;
64
- const truncated = truncateToTokens(raw, MEMORY_SUMMARY_TOKEN_LIMIT);
64
+ const truncated = currentMemoryVersion() === "v2"
65
+ ? truncateToBytes(raw, MEMORY_V2_SUMMARY_MAX_BYTES)
66
+ : truncateToTokens(raw, MEMORY_SUMMARY_TOKEN_LIMIT);
65
67
  cache.set(summaryPath, { content: truncated, identity });
66
68
  return truncated;
67
69
  });
@@ -23,7 +23,8 @@ decisions, or provenance; redact secrets and access-bearing URL values as
23
23
 
24
24
  Begin with `v1`, followed by `## User Profile`, `## User preferences`,
25
25
  `## General Tips`, and `## What's in Memory`; keep the complete result
26
- comfortably under 10,000 UTF-8 bytes. Use judgment to preserve substantive older
26
+ comfortably under 10,000 UTF-8 bytes, aiming for at most 9,000 bytes to leave
27
+ headroom. Use judgment to preserve substantive older
27
28
  context and give recent, consequential work richer direct routes without
28
29
  obscuring actionable preferences or status.
29
30
 
@@ -1,4 +1,5 @@
1
1
  export declare const TOKEN_ESTIMATE_CHARS_PER_TOKEN = 4;
2
+ export declare const MEMORY_V2_SUMMARY_MAX_BYTES = 9999;
2
3
  export declare function estimateTokens(input: string): number;
3
4
  /**
4
5
  * Middle truncation, like codex truncate_with_head_and_tail: keep the head
package/dist/src/token.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export const TOKEN_ESTIMATE_CHARS_PER_TOKEN = 4;
2
+ // V2's injected summary stays strictly below Codex's 10,000-byte artifact target.
3
+ export const MEMORY_V2_SUMMARY_MAX_BYTES = 9_999;
2
4
  export function estimateTokens(input) {
3
5
  return Math.max(0, Math.round(input.length / TOKEN_ESTIMATE_CHARS_PER_TOKEN));
4
6
  }
@@ -18,6 +18,8 @@ export interface MemoryStatus {
18
18
  /** Readiness diagnostics; optional for older servers. Null reason means ready. */
19
19
  v2NotReadyReason?: string | null;
20
20
  v2SummaryBytes?: number | null;
21
+ /** Bounded summary payload, excluding read-path instructions; optional for older servers. */
22
+ v2InjectedSummaryBytes?: number | null;
21
23
  minConsolidatedThreads: number;
22
24
  pipelines: {
23
25
  version: "v1" | "v2";
@@ -100,6 +102,11 @@ export declare const MemoryStatusRpc: {
100
102
  readonly type: readonly ["integer", "null"];
101
103
  readonly minimum: 0;
102
104
  };
105
+ readonly v2InjectedSummaryBytes: {
106
+ readonly type: readonly ["integer", "null"];
107
+ readonly minimum: 0;
108
+ readonly maximum: 9999;
109
+ };
103
110
  readonly minConsolidatedThreads: {
104
111
  readonly type: "integer";
105
112
  readonly minimum: 1;
@@ -50,6 +50,7 @@ export const MemoryStatusRpc = {
50
50
  v2Ready: { type: "boolean" },
51
51
  v2NotReadyReason: { type: ["string", "null"] },
52
52
  v2SummaryBytes: { type: ["integer", "null"], minimum: 0 },
53
+ v2InjectedSummaryBytes: { type: ["integer", "null"], minimum: 0, maximum: 9999 },
53
54
  minConsolidatedThreads: { type: "integer", minimum: 1, maximum: 4096 },
54
55
  useMemories: { type: "boolean" },
55
56
  pipelines: {
@@ -178,8 +179,12 @@ export function isMemoryStatus(value) {
178
179
  return false;
179
180
  if (value.v2NotReadyReason !== undefined && value.v2NotReadyReason !== null && typeof value.v2NotReadyReason !== "string")
180
181
  return false;
181
- if (value.v2SummaryBytes !== undefined && value.v2SummaryBytes !== null &&
182
- (!Number.isInteger(value.v2SummaryBytes) || value.v2SummaryBytes < 0))
182
+ for (const key of ["v2SummaryBytes", "v2InjectedSummaryBytes"]) {
183
+ if (value[key] !== undefined && value[key] !== null &&
184
+ (!Number.isInteger(value[key]) || value[key] < 0))
185
+ return false;
186
+ }
187
+ if (typeof value.v2InjectedSummaryBytes === "number" && value.v2InjectedSummaryBytes > 9999)
183
188
  return false;
184
189
  if (!Number.isInteger(value.minConsolidatedThreads) || value.minConsolidatedThreads < 1 || value.minConsolidatedThreads > 4096)
185
190
  return false;
@@ -58,6 +58,7 @@ var MemoryStatusRpc = {
58
58
  v2Ready: { type: "boolean" },
59
59
  v2NotReadyReason: { type: ["string", "null"] },
60
60
  v2SummaryBytes: { type: ["integer", "null"], minimum: 0 },
61
+ v2InjectedSummaryBytes: { type: ["integer", "null"], minimum: 0, maximum: 9999 },
61
62
  minConsolidatedThreads: { type: "integer", minimum: 1, maximum: 4096 },
62
63
  useMemories: { type: "boolean" },
63
64
  pipelines: {
@@ -186,7 +187,11 @@ function isMemoryStatus(value) {
186
187
  return false;
187
188
  if (value.v2NotReadyReason !== undefined && value.v2NotReadyReason !== null && typeof value.v2NotReadyReason !== "string")
188
189
  return false;
189
- if (value.v2SummaryBytes !== undefined && value.v2SummaryBytes !== null && (!Number.isInteger(value.v2SummaryBytes) || value.v2SummaryBytes < 0))
190
+ for (const key of ["v2SummaryBytes", "v2InjectedSummaryBytes"]) {
191
+ if (value[key] !== undefined && value[key] !== null && (!Number.isInteger(value[key]) || value[key] < 0))
192
+ return false;
193
+ }
194
+ if (typeof value.v2InjectedSummaryBytes === "number" && value.v2InjectedSummaryBytes > 9999)
190
195
  return false;
191
196
  if (!Number.isInteger(value.minConsolidatedThreads) || value.minConsolidatedThreads < 1 || value.minConsolidatedThreads > 4096)
192
197
  return false;
@@ -411,8 +416,8 @@ function statusRows(s, now) {
411
416
  tone: "muted"
412
417
  }] : [], ...s.v2SummaryBytes !== undefined ? [{
413
418
  label: "V2 summary",
414
- value: s.v2SummaryBytes === null ? "Unreadable" : `${s.v2SummaryBytes} UTF-8 bytes \xB7 limit <10000`,
415
- tone: s.v2SummaryBytes !== null && s.v2SummaryBytes >= 1e4 ? "warn" : "muted"
419
+ value: s.v2SummaryBytes === null ? "Unreadable" : s.v2InjectedSummaryBytes != null ? `${s.v2SummaryBytes} bytes on disk \xB7 ${s.v2InjectedSummaryBytes} injected${s.v2SummaryBytes >= 1e4 ? " (capped)" : ""}` : `${s.v2SummaryBytes} UTF-8 bytes`,
420
+ tone: "muted"
416
421
  }] : [], ...pipelineRows(s, now), {
417
422
  label: "Use memories",
418
423
  value: s.useMemories ? "On" : "Off",
@@ -4,7 +4,7 @@ import { type WorkspaceDiff } from "./git-baseline.js";
4
4
  /** Mirrors codex `remove_memory_symlinks` (workspace.rs): unlink every symlink in the tree, never follow. */
5
5
  export declare function removeMemorySymlinks(root?: string): number;
6
6
  export declare function ensureLayout(): void;
7
- /** Same Codex predicate, with content-free diagnostics for inspect and failed jobs. */
7
+ /** Codex format checks with content-free diagnostics; V2 size is bounded at injection. */
8
8
  export declare function validateV2Summary(summary: string): {
9
9
  ok: boolean;
10
10
  bytes: number;
@@ -93,16 +93,13 @@ export function ensureLayout() {
93
93
  * Invalid artifacts force a consolidator re-run and block baseline reset.
94
94
  */
95
95
  const V2_SUMMARY_HEADINGS = ["## User Profile", "## User preferences", "## General Tips", "## What's in Memory"];
96
- /** Same Codex predicate, with content-free diagnostics for inspect and failed jobs. */
96
+ /** Codex format checks with content-free diagnostics; V2 size is bounded at injection. */
97
97
  export function validateV2Summary(summary) {
98
98
  const bytes = Buffer.byteLength(summary, "utf8");
99
99
  if (summary.split(/\r?\n/, 1)[0] !== "v1") {
100
100
  const hint = summary.startsWith("\uFEFF") ? " (UTF-8 BOM detected)" : "";
101
101
  return { ok: false, bytes, reason: `summary must start with the exact line 'v1'${hint}` };
102
102
  }
103
- if (bytes >= 10_000) {
104
- return { ok: false, bytes, reason: `summary must be under 10000 UTF-8 bytes (got ${bytes})` };
105
- }
106
103
  const lines = summary.split(/\r?\n/).map((line) => line.trim());
107
104
  const missing = V2_SUMMARY_HEADINGS.filter((heading) => !lines.includes(heading));
108
105
  return missing.length
@@ -380,7 +380,8 @@ function inspect(args, ctx) {
380
380
  `dual_write: ${pluginOptions.dual_write}`,
381
381
  `v2_ready: ${migration.v2Ready}`,
382
382
  `v2_not_ready_reason: ${migration.v2NotReadyReason ?? "none"}`,
383
- `v2_summary_bytes: ${migration.v2SummaryBytes ?? "unknown"} (UTF-8; must be under 10000)`,
383
+ `v2_summary_bytes: ${migration.v2SummaryBytes ?? "unknown"} (UTF-8 on disk)`,
384
+ `v2_injected_summary_bytes: ${migration.v2InjectedSummaryBytes ?? "unknown"} (UTF-8; capped under 10000, including truncation marker)`,
384
385
  `v2_consolidated_threads: ${migration.v2ConsolidatedThreads} (minimum ${migration.minConsolidatedThreads})`,
385
386
  ...pipelines.flatMap((p) => [
386
387
  `pipeline_${p.version}: outputs=${p.stage1Count}, phase2=${p.phase2?.status ?? "none"}, root=${p.root}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-codex-memory",
3
- "version": "0.9.8",
3
+ "version": "0.9.9",
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",