opencode-codex-memory 0.10.1 → 0.10.2
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 +10 -12
- package/dist/src/agent-health.js +10 -7
- package/dist/src/capture.js +7 -7
- package/dist/src/citation.js +12 -3
- package/dist/src/claude-import.js +1 -3
- package/dist/src/codex-interop.js +20 -5
- package/dist/src/db.d.ts +0 -2
- package/dist/src/db.js +0 -4
- package/dist/src/git-baseline.d.ts +4 -6
- package/dist/src/git-baseline.js +45 -68
- package/dist/src/host-client.d.ts +5 -0
- package/dist/src/host-client.js +24 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +56 -99
- package/dist/src/llm.d.ts +4 -1
- package/dist/src/llm.js +41 -13
- package/dist/src/options.d.ts +7 -0
- package/dist/src/options.js +20 -2
- package/dist/src/paths.d.ts +1 -0
- package/dist/src/paths.js +5 -2
- package/dist/src/phase1.js +12 -21
- package/dist/src/phase2.js +3 -3
- package/dist/src/reasoning-variant.d.ts +7 -0
- package/dist/src/reasoning-variant.js +11 -2
- package/dist/src/rollout-input.js +3 -5
- package/dist/src/session-version.js +4 -5
- package/dist/src/source.js +6 -2
- package/dist/src/store.d.ts +3 -2
- package/dist/src/store.js +72 -47
- package/dist/src/v2/agents.js +11 -14
- package/dist/src/v2/model-readiness.js +3 -1
- package/dist/src/v2/plugin.js +81 -109
- package/dist/src/v2/search-sandbox.js +1 -1
- package/dist/src/v2/service.js +5 -0
- package/dist/src/v2/shim.d.ts +3 -0
- package/dist/src/v2/shim.js +144 -90
- package/dist/src/v2/status-rpc.js +40 -14
- package/dist/src/v2/status.js +4 -7
- package/dist/src/v2/tools.d.ts +15 -9
- package/dist/src/v2/tools.js +9 -9
- package/dist/src/v2/tui.js +14 -4
- package/dist/src/workspace.js +13 -4
- package/dist/tools/control.js +29 -28
- package/dist/tools/memory.js +163 -89
- package/package.json +22 -9
package/dist/src/v2/tools.d.ts
CHANGED
|
@@ -10,6 +10,18 @@
|
|
|
10
10
|
* Inspect additionally reports the V2 host discovery scope and fallback reason.
|
|
11
11
|
*/
|
|
12
12
|
import { z } from "zod";
|
|
13
|
+
type CallContext = {
|
|
14
|
+
sessionID: string;
|
|
15
|
+
messageID: string;
|
|
16
|
+
agent: string;
|
|
17
|
+
id?: string;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
abort?: AbortSignal;
|
|
20
|
+
};
|
|
21
|
+
type Ask = (ctx: CallContext, request: {
|
|
22
|
+
patterns: string[];
|
|
23
|
+
metadata: unknown;
|
|
24
|
+
}) => Promise<void>;
|
|
13
25
|
interface V2ToolDefinition {
|
|
14
26
|
name: string;
|
|
15
27
|
description: string;
|
|
@@ -23,12 +35,7 @@ interface V2ToolDefinition {
|
|
|
23
35
|
options: {
|
|
24
36
|
codemode: false;
|
|
25
37
|
};
|
|
26
|
-
execute: (input: any, ctx: {
|
|
27
|
-
sessionID: string;
|
|
28
|
-
messageID: string;
|
|
29
|
-
agent: string;
|
|
30
|
-
abort?: AbortSignal;
|
|
31
|
-
}) => Promise<{
|
|
38
|
+
execute: (input: any, ctx: CallContext) => Promise<{
|
|
32
39
|
content: string | unknown[];
|
|
33
40
|
metadata?: unknown;
|
|
34
41
|
}>;
|
|
@@ -36,8 +43,7 @@ interface V2ToolDefinition {
|
|
|
36
43
|
/**
|
|
37
44
|
* Same gating as the V1 entry: the read/search/list/add-note tools require
|
|
38
45
|
* BOTH use_memories and dedicated_tools (codex MemoriesExtension); the
|
|
39
|
-
* control tools are always available.
|
|
40
|
-
* which V2 plugin tools cannot request: reset lives in the memory panel.
|
|
46
|
+
* control tools are always available. Destructive reset lives in the panel.
|
|
41
47
|
*/
|
|
42
|
-
export declare function buildV2Tools(): V2ToolDefinition[];
|
|
48
|
+
export declare function buildV2Tools(ask?: Ask): V2ToolDefinition[];
|
|
43
49
|
export {};
|
package/dist/src/v2/tools.js
CHANGED
|
@@ -14,7 +14,7 @@ import { memory_read, memory_search, memory_list, memory_add_note } from "../../
|
|
|
14
14
|
import { memory_inspect, memory_mode } from "../../tools/control.js";
|
|
15
15
|
import { pluginOptions } from "../options.js";
|
|
16
16
|
import { getV2DiscoveryStatus } from "./shim.js";
|
|
17
|
-
function adaptTool(name, v1) {
|
|
17
|
+
function adaptTool(name, v1, ask) {
|
|
18
18
|
return {
|
|
19
19
|
name,
|
|
20
20
|
description: v1.description,
|
|
@@ -27,11 +27,12 @@ function adaptTool(name, v1) {
|
|
|
27
27
|
agent: tctx.agent,
|
|
28
28
|
directory: "",
|
|
29
29
|
worktree: "",
|
|
30
|
-
abort: tctx.
|
|
30
|
+
abort: tctx.signal ?? tctx.abort ?? new AbortController().signal,
|
|
31
31
|
metadata: () => { },
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
ask: async (request) => {
|
|
33
|
+
if (ask)
|
|
34
|
+
return ask(tctx, request);
|
|
35
|
+
throw new Error("User approval is unavailable to plugin tools on this host. Use /memory-inspect → Controls instead.");
|
|
35
36
|
},
|
|
36
37
|
};
|
|
37
38
|
const res = await v1.execute(input, v1ctx);
|
|
@@ -71,10 +72,9 @@ const CONTROL_ONLY = new Set(["memory_inspect", "memory_mode"]);
|
|
|
71
72
|
/**
|
|
72
73
|
* Same gating as the V1 entry: the read/search/list/add-note tools require
|
|
73
74
|
* BOTH use_memories and dedicated_tools (codex MemoriesExtension); the
|
|
74
|
-
* control tools are always available.
|
|
75
|
-
* which V2 plugin tools cannot request: reset lives in the memory panel.
|
|
75
|
+
* control tools are always available. Destructive reset lives in the panel.
|
|
76
76
|
*/
|
|
77
|
-
export function buildV2Tools() {
|
|
77
|
+
export function buildV2Tools(ask) {
|
|
78
78
|
const full = pluginOptions.use_memories && pluginOptions.dedicated_tools;
|
|
79
|
-
return ALL_MEMORY_TOOLS.filter(([name]) => full || CONTROL_ONLY.has(name)).map(([name, v1]) => adaptTool(name, v1));
|
|
79
|
+
return ALL_MEMORY_TOOLS.filter(([name]) => full || CONTROL_ONLY.has(name)).map(([name, v1]) => adaptTool(name, v1, ask));
|
|
80
80
|
}
|
package/dist/src/v2/tui.js
CHANGED
|
@@ -124,7 +124,12 @@ var MemoryStatusRpc = {
|
|
|
124
124
|
required: ["key", "value"],
|
|
125
125
|
additionalProperties: false
|
|
126
126
|
},
|
|
127
|
-
output: {
|
|
127
|
+
output: {
|
|
128
|
+
type: "object",
|
|
129
|
+
properties: { ok: { type: "boolean" } },
|
|
130
|
+
required: ["ok"],
|
|
131
|
+
additionalProperties: false
|
|
132
|
+
}
|
|
128
133
|
},
|
|
129
134
|
setSessionMode: {
|
|
130
135
|
input: {
|
|
@@ -136,7 +141,12 @@ var MemoryStatusRpc = {
|
|
|
136
141
|
required: ["sessionID", "mode"],
|
|
137
142
|
additionalProperties: false
|
|
138
143
|
},
|
|
139
|
-
output: {
|
|
144
|
+
output: {
|
|
145
|
+
type: "object",
|
|
146
|
+
properties: { ok: { type: "boolean" } },
|
|
147
|
+
required: ["ok"],
|
|
148
|
+
additionalProperties: false
|
|
149
|
+
}
|
|
140
150
|
},
|
|
141
151
|
consolidateNow: {
|
|
142
152
|
input: { type: "object", properties: {}, additionalProperties: false },
|
|
@@ -1021,9 +1031,9 @@ function MemoryDialog(context, sessionID) {
|
|
|
1021
1031
|
_$insert(_el$19, () => tab() === "Controls" ? "select" : "scroll", null);
|
|
1022
1032
|
_$insert(_el$21, () => tab() === "Controls" ? "Enter/Space change" : "PgUp/PgDn page \xB7 Home/End ends");
|
|
1023
1033
|
_$effect((_p$) => {
|
|
1024
|
-
var _v$5 = Math.min(tab() === "Overview" ? 34 : sessionID ? 25 : 22, Math.max(8, dimensions().height - 2)), _v$6
|
|
1034
|
+
var _v$5 = Math.min(tab() === "Overview" ? 34 : sessionID ? 25 : 22, Math.max(8, dimensions().height - 2)), { text: _v$6, muted: _v$7 } = color, _v$8 = click(() => {
|
|
1025
1035
|
refresh();
|
|
1026
|
-
}), _v$9 = color.muted, _v$0 = click(() => context.ui.dialog.clear()), _v$1
|
|
1036
|
+
}), _v$9 = color.muted, _v$0 = click(() => context.ui.dialog.clear()), { muted: _v$1, muted: _v$10 } = color;
|
|
1027
1037
|
_v$5 !== _p$.e && (_p$.e = _$setProp(_el$9, "height", _v$5, _p$.e));
|
|
1028
1038
|
_v$6 !== _p$.t && (_p$.t = _$setProp(_el$1, "fg", _v$6, _p$.t));
|
|
1029
1039
|
_v$7 !== _p$.a && (_p$.a = _$setProp(_el$13, "fg", _v$7, _p$.a));
|
package/dist/src/workspace.js
CHANGED
|
@@ -75,7 +75,9 @@ export function ensureLayout() {
|
|
|
75
75
|
removeMemorySymlinks(root);
|
|
76
76
|
const v1 = currentMemoryVersion() === "v1";
|
|
77
77
|
// Codex V2 consolidates into memory_summary.md only; it has no skills/.
|
|
78
|
-
for (const dir of v1
|
|
78
|
+
for (const dir of v1
|
|
79
|
+
? [ROLLOUT_DIR, SKILLS_DIR, EXTENSIONS_DIR, ADHOC_NOTES_DIR]
|
|
80
|
+
: [ROLLOUT_DIR, EXTENSIONS_DIR, ADHOC_NOTES_DIR]) {
|
|
79
81
|
fs.mkdirSync(safeResolveMemoryPath(dir), { recursive: true });
|
|
80
82
|
}
|
|
81
83
|
if (!v1) {
|
|
@@ -103,7 +105,12 @@ export function ensureLayout() {
|
|
|
103
105
|
* a regular file and memory_summary.md must start with the exact line `v1`.
|
|
104
106
|
* Invalid artifacts force a consolidator re-run and block baseline reset.
|
|
105
107
|
*/
|
|
106
|
-
const V2_SUMMARY_HEADINGS = [
|
|
108
|
+
const V2_SUMMARY_HEADINGS = [
|
|
109
|
+
"## User Profile",
|
|
110
|
+
"## User preferences",
|
|
111
|
+
"## General Tips",
|
|
112
|
+
"## What's in Memory",
|
|
113
|
+
];
|
|
107
114
|
/** Codex format checks with content-free diagnostics; V2 size is bounded at injection. */
|
|
108
115
|
export function validateV2Summary(summary) {
|
|
109
116
|
const bytes = Buffer.byteLength(summary, "utf8");
|
|
@@ -312,8 +319,10 @@ export function writeWorkspaceDiff(diff) {
|
|
|
312
319
|
// multibyte content. Cut on the byte buffer and drop a split trailing char.
|
|
313
320
|
if (Buffer.byteLength(body, "utf8") > WORKSPACE_DIFF_MAX_BYTES) {
|
|
314
321
|
body =
|
|
315
|
-
Buffer.from(body, "utf8")
|
|
316
|
-
|
|
322
|
+
Buffer.from(body, "utf8")
|
|
323
|
+
.subarray(0, WORKSPACE_DIFF_MAX_BYTES)
|
|
324
|
+
.toString("utf8")
|
|
325
|
+
.replace(/\uFFFD+$/, "") + `\n[workspace diff truncated at ${WORKSPACE_DIFF_MAX_BYTES} bytes]\n`;
|
|
317
326
|
}
|
|
318
327
|
rendered += "\n## Diff\n\n```diff\n" + body + (body.endsWith("\n") ? "" : "\n") + "```\n";
|
|
319
328
|
}
|
package/dist/tools/control.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { tool } from "@opencode-ai/plugin";
|
|
4
|
-
import { allMemoryRoots, memoryDbPath, memoryRoot, memorySummaryPath, sessionMetaDbPath, dataRoot, memoryHomeSource } from "../src/paths.js";
|
|
4
|
+
import { allMemoryRoots, memoryDbPath, memoryRoot, memorySummaryPath, sessionMetaDbPath, dataRoot, memoryHomeSource, } from "../src/paths.js";
|
|
5
5
|
import { clearAllVersionMemoryData, MemoryStore, PHASE2_COOLDOWN_MS } from "../src/store.js";
|
|
6
6
|
import { invalidateCache } from "../src/source.js";
|
|
7
7
|
import { estimateTokens } from "../src/token.js";
|
|
@@ -10,7 +10,7 @@ import { isPhase2InFlight } from "../src/phase2.js";
|
|
|
10
10
|
import { pluginOptions, getConfigWarnings } from "../src/options.js";
|
|
11
11
|
import { codexInteropBlockReason, codexInteropMtimes, resolveCodexInterop } from "../src/codex-interop.js";
|
|
12
12
|
import { claudeImportStatus, resolveClaudeHome } from "../src/claude-import.js";
|
|
13
|
-
import { formatDiagnosticLine, getDiscoveryStatus, getRecentDiagnostics
|
|
13
|
+
import { formatDiagnosticLine, getDiscoveryStatus, getRecentDiagnostics } from "../src/diagnostics.js";
|
|
14
14
|
import { isPluginShuttingDown } from "../src/lifecycle.js";
|
|
15
15
|
import { getAgentHealth } from "../src/agent-health.js";
|
|
16
16
|
import { activeProviderCapacityBackoffs } from "../src/ratelimit.js";
|
|
@@ -185,14 +185,7 @@ function renderAgentHealth() {
|
|
|
185
185
|
function resetBlockedReason() {
|
|
186
186
|
if (isSymlinkedRoot())
|
|
187
187
|
return "Reset refused: memory root is a symlink. Remove it manually to be safe.";
|
|
188
|
-
//
|
|
189
|
-
// after the wipe (the sub-agent edits live artifacts and resets the git
|
|
190
|
-
// baseline). Refuse instead of racing it. clearMemoryData also leaves a
|
|
191
|
-
// phase-2 cooldown marker so the next idle/chat hook cannot first-run-claim
|
|
192
|
-
// phase 2 and re-seed the root via ensureLayout. Cross-process consolidators
|
|
193
|
-
// already in flight remain ownership-guarded (their final mark becomes a
|
|
194
|
-
// no-op once the row is replaced) but may leave stray files — same window
|
|
195
|
-
// codex has between CLI clear and a running daemon.
|
|
188
|
+
// Cheap preflight. The DB barrier checks both writers again after approval.
|
|
196
189
|
if (isPhase2InFlight())
|
|
197
190
|
return "Reset refused: memory consolidation is currently running. Try again in a few minutes.";
|
|
198
191
|
return null;
|
|
@@ -206,12 +199,14 @@ export function performMemoryReset() {
|
|
|
206
199
|
if (blocked)
|
|
207
200
|
return { ok: false, message: blocked };
|
|
208
201
|
try {
|
|
209
|
-
clearAllVersionMemoryData();
|
|
210
|
-
wipeMemoriesDir();
|
|
202
|
+
clearAllVersionMemoryData(wipeMemoriesDir);
|
|
211
203
|
// codex keeps its state DB pool open across resets (clear_memory_roots_contents
|
|
212
204
|
// only wipes directories); closing here would strand cached handles elsewhere.
|
|
213
205
|
invalidateCache();
|
|
214
|
-
return {
|
|
206
|
+
return {
|
|
207
|
+
ok: true,
|
|
208
|
+
message: "Memory reset complete. Extracted memories and jobs cleared, memories directory (incl. git history) wiped, cache invalidated. Per-session memory modes were preserved.",
|
|
209
|
+
};
|
|
215
210
|
}
|
|
216
211
|
catch (err) {
|
|
217
212
|
return { ok: false, message: `memory_reset error: ${err.message}` };
|
|
@@ -278,7 +273,12 @@ export const memory_inspect = tool({
|
|
|
278
273
|
"effective plugin options, and any configuration warnings. Use it to verify " +
|
|
279
274
|
"configuration and debug why memory is not building. Read-only.",
|
|
280
275
|
args: {
|
|
281
|
-
min_consolidated_threads: tool.schema
|
|
276
|
+
min_consolidated_threads: tool.schema
|
|
277
|
+
.number()
|
|
278
|
+
.int()
|
|
279
|
+
.min(1)
|
|
280
|
+
.max(4096)
|
|
281
|
+
.optional()
|
|
282
282
|
.describe("V2 readiness threshold: distinct sessions in a successful consolidation (default 20)."),
|
|
283
283
|
},
|
|
284
284
|
async execute(args, ctx) {
|
|
@@ -342,9 +342,7 @@ function inspect(args, ctx) {
|
|
|
342
342
|
`stage1_jobs: ${stage1StatusParts.length > 0 ? stage1StatusParts.join(" ") : "none"}`,
|
|
343
343
|
`stage1_failures: ${failureParts.length > 0 ? failureParts.join(" ") : "none"}`,
|
|
344
344
|
...(stage1Jobs.stale_exhausted > 0
|
|
345
|
-
? [
|
|
346
|
-
`stage1_stale_exhausted: ${stage1Jobs.stale_exhausted} (older than max_rollout_age_days, will not retry)`,
|
|
347
|
-
]
|
|
345
|
+
? [`stage1_stale_exhausted: ${stage1Jobs.stale_exhausted} (older than max_rollout_age_days, will not retry)`]
|
|
348
346
|
: []),
|
|
349
347
|
...stage1Jobs.recent_errors.map((e) => {
|
|
350
348
|
const klass = e.failure_class ? `, ${e.failure_class}` : "";
|
|
@@ -360,10 +358,7 @@ function inspect(args, ctx) {
|
|
|
360
358
|
const eligibilityHint = `eligibility: sessions must be idle ≥ ${idleHours}h and younger than ${pluginOptions.max_rollout_age_days}d ` +
|
|
361
359
|
`(generate_memories=${pluginOptions.generate_memories}). ` +
|
|
362
360
|
`For faster local testing, set min_rollout_idle_hours to 1 (clamp floor).`;
|
|
363
|
-
const processLines = [
|
|
364
|
-
`phase2_in_flight: ${isPhase2InFlight()}`,
|
|
365
|
-
`plugin_shutting_down: ${isPluginShuttingDown()}`,
|
|
366
|
-
];
|
|
361
|
+
const processLines = [`phase2_in_flight: ${isPhase2InFlight()}`, `plugin_shutting_down: ${isPluginShuttingDown()}`];
|
|
367
362
|
const capacityBackoffs = activeProviderCapacityBackoffs();
|
|
368
363
|
const capacityLines = capacityBackoffs.length > 0
|
|
369
364
|
? capacityBackoffs.map((b) => `provider_capacity_backoff ${b.scope}: retry_at=${fmtUnixSec(b.retry_at)}`)
|
|
@@ -436,9 +431,7 @@ function inspect(args, ctx) {
|
|
|
436
431
|
codex_interop: { ...pluginOptions.codex_interop },
|
|
437
432
|
claude_import: {
|
|
438
433
|
...pluginOptions.claude_import,
|
|
439
|
-
...(pluginOptions.claude_import.projects
|
|
440
|
-
? { projects: [...pluginOptions.claude_import.projects] }
|
|
441
|
-
: {}),
|
|
434
|
+
...(pluginOptions.claude_import.projects ? { projects: [...pluginOptions.claude_import.projects] } : {}),
|
|
442
435
|
},
|
|
443
436
|
},
|
|
444
437
|
config_warnings: [...getConfigWarnings()],
|
|
@@ -465,7 +458,7 @@ export const memory_mode = tool({
|
|
|
465
458
|
let polluted;
|
|
466
459
|
try {
|
|
467
460
|
store = new MemoryStore();
|
|
468
|
-
polluted = store.
|
|
461
|
+
polluted = store.isPolluted(sid);
|
|
469
462
|
}
|
|
470
463
|
catch (err) {
|
|
471
464
|
return { output: `memory_mode error: ${err.message}` };
|
|
@@ -474,11 +467,19 @@ export const memory_mode = tool({
|
|
|
474
467
|
// that read that content must not lift it on its own. A rejection
|
|
475
468
|
// propagates to the host as usual.
|
|
476
469
|
if (args.mode === "enabled" && polluted) {
|
|
477
|
-
await ctx.ask({
|
|
470
|
+
await ctx.ask({
|
|
471
|
+
permission: "memory_mode",
|
|
472
|
+
patterns: [sid],
|
|
473
|
+
always: [],
|
|
474
|
+
metadata: { sessionId: sid, from: "polluted", to: "enabled" },
|
|
475
|
+
});
|
|
478
476
|
}
|
|
479
477
|
try {
|
|
480
|
-
store.setMemoryMode(sid, args.mode);
|
|
481
|
-
return {
|
|
478
|
+
store.setMemoryMode(sid, args.mode, args.mode === "enabled" && polluted);
|
|
479
|
+
return {
|
|
480
|
+
output: `Memory mode for session ${sid} set to '${args.mode}'.`,
|
|
481
|
+
metadata: { sessionId: sid, mode: args.mode },
|
|
482
|
+
};
|
|
482
483
|
}
|
|
483
484
|
catch (err) {
|
|
484
485
|
return { output: `memory_mode error: ${err.message}` };
|