@codemem/opencode-plugin 0.50.0-beta.1 → 0.50.0-beta.3
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/.opencode/lib/delegation-context.js +4 -1
- package/.opencode/lib/memory-tool-contracts.json +6 -2
- package/.opencode/lib/opencode-v2-adapter.js +34 -0
- package/.opencode/lib/private-text.mjs +228 -0
- package/.opencode/lib/raw-event-delivery.js +4 -2
- package/.opencode/lib/runtime.js +32 -14
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import { stripPrivate } from "./private-text.mjs";
|
|
2
3
|
|
|
3
4
|
const MAX_BINDINGS = 128;
|
|
4
5
|
const MAX_BRIEF_CHARS = 64_000;
|
|
@@ -114,7 +115,9 @@ export const createDelegationContext = ({
|
|
|
114
115
|
parent_session_id: binding.parent, child_session_id: sessionID,
|
|
115
116
|
task_call_id: binding.call, message_id: messageID,
|
|
116
117
|
requested_agent: binding.agent, current_agent: info.agent,
|
|
117
|
-
|
|
118
|
+
// Ingestion checks this digest against the brief it stores, which has lost its
|
|
119
|
+
// private blocks, so both sides hash the same cleaned text.
|
|
120
|
+
brief_sha256: digest(stripPrivate(text)),
|
|
118
121
|
});
|
|
119
122
|
};
|
|
120
123
|
// V1 invokes this with all resolved parts before saving them individually.
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
},
|
|
147
147
|
{
|
|
148
148
|
"name": "memory_search_index",
|
|
149
|
-
"description": "Keyword-search memories when you know exact terms or identifiers. Returns compact entries
|
|
149
|
+
"description": "Keyword-search memories when you know exact terms or identifiers. Returns compact entries without bodies: IDs, clipped titles, and widening labels when present. Expand selected IDs with memory_get or memory_get_observations.",
|
|
150
150
|
"input": {
|
|
151
151
|
"type": "object",
|
|
152
152
|
"properties": {
|
|
@@ -1204,7 +1204,7 @@
|
|
|
1204
1204
|
},
|
|
1205
1205
|
{
|
|
1206
1206
|
"name": "memory_get_observations",
|
|
1207
|
-
"description": "Fetch multiple memories by exact IDs. Does not inherit the default project. Missing or filtered-out IDs are omitted
|
|
1207
|
+
"description": "Fetch multiple memories by exact IDs. Returns full rows by default. Use compact for full body text without metadata. Does not inherit the default project. Missing or filtered-out IDs are omitted.",
|
|
1208
1208
|
"input": {
|
|
1209
1209
|
"type": "object",
|
|
1210
1210
|
"properties": {
|
|
@@ -1216,6 +1216,10 @@
|
|
|
1216
1216
|
"maxItems": 200,
|
|
1217
1217
|
"description": "Memory IDs to fetch"
|
|
1218
1218
|
},
|
|
1219
|
+
"compact": {
|
|
1220
|
+
"type": "boolean",
|
|
1221
|
+
"description": "Return only id, kind, title, body_text, and project"
|
|
1222
|
+
},
|
|
1219
1223
|
"kind": {
|
|
1220
1224
|
"type": "string",
|
|
1221
1225
|
"description": "Filter by memory kind"
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
isMemoryToolId,
|
|
9
9
|
MEMORY_TOOL_NAMESPACE,
|
|
10
10
|
MEMORY_TOOL_NAMESPACE_DESCRIPTION,
|
|
11
|
+
memoryToolId,
|
|
11
12
|
} from "./memory-tools.js";
|
|
12
13
|
import { addCallerToPooledMcpTools, createCallSequence } from "./pooled-mcp-caller.js";
|
|
13
14
|
import { createCodememRuntime } from "./runtime.js";
|
|
@@ -22,6 +23,10 @@ const FAILED_TOOL_ERROR = Object.freeze({
|
|
|
22
23
|
const CODEMEM_CONTEXT_PART_ID_PREFIX = "codemem-context-";
|
|
23
24
|
const CODEMEM_RECALL_METADATA_VERSION = 1;
|
|
24
25
|
const CODEMEM_V2_PART_METADATA_KEY = "codememPart";
|
|
26
|
+
const PINNED_RETRIEVAL_IDS = new Set([
|
|
27
|
+
memoryToolId("memory_search_index"),
|
|
28
|
+
memoryToolId("memory_get_observations"),
|
|
29
|
+
]);
|
|
25
30
|
|
|
26
31
|
const asRecord = (value) =>
|
|
27
32
|
value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
@@ -345,6 +350,10 @@ export const translateV2Event = (event) => createV2EventTranslator().translate(e
|
|
|
345
350
|
export const translateV2ToolResult = (input) => {
|
|
346
351
|
const failed = input?.status === "error";
|
|
347
352
|
const result = asRecord(input?.result);
|
|
353
|
+
const nestedCalls = asRecord(result.metadata).toolCalls;
|
|
354
|
+
const executionWrapper = input?.tool === "execute" && Array.isArray(nestedCalls);
|
|
355
|
+
const containsMemoryCalls = executionWrapper
|
|
356
|
+
&& nestedCalls.some((call) => isMemoryToolId(call?.tool));
|
|
348
357
|
let output = null;
|
|
349
358
|
if (!failed) output = result.output ?? result.content ?? input?.result ?? null;
|
|
350
359
|
return {
|
|
@@ -353,6 +362,10 @@ export const translateV2ToolResult = (input) => {
|
|
|
353
362
|
sessionID: typeof input?.sessionID === "string" ? input.sessionID : null,
|
|
354
363
|
tool: typeof input?.tool === "string" ? input.tool : "unknown",
|
|
355
364
|
args: asRecord(input?.input),
|
|
365
|
+
...(typeof input?.codemode === "boolean" ? { codemode: input.codemode } : {}),
|
|
366
|
+
...(typeof input?.messageID === "string" ? { messageID: input.messageID } : {}),
|
|
367
|
+
...(executionWrapper ? { executionWrapper } : {}),
|
|
368
|
+
...(containsMemoryCalls ? { containsMemoryCalls } : {}),
|
|
356
369
|
},
|
|
357
370
|
output: {
|
|
358
371
|
output,
|
|
@@ -432,6 +445,26 @@ const addV2MemoryTools = (editor, memoryTools, options) => {
|
|
|
432
445
|
}
|
|
433
446
|
};
|
|
434
447
|
|
|
448
|
+
const supportsRetrievalPins = (version) => {
|
|
449
|
+
const match = /^v?2\.(\d+)\.(\d+)(?:\+.+)?$/.exec(version ?? "");
|
|
450
|
+
if (!match) return false;
|
|
451
|
+
const [, minor, patch] = match;
|
|
452
|
+
return Number(minor) > 4 || (Number(minor) === 4 && Number(patch) >= 1);
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
export const pinV2RetrievalCatalog = (editor, version) => {
|
|
456
|
+
if (!supportsRetrievalPins(version)) return;
|
|
457
|
+
if (typeof editor.list !== "function" || typeof editor.update !== "function") return;
|
|
458
|
+
for (const tool of editor.list()) {
|
|
459
|
+
if (!PINNED_RETRIEVAL_IDS.has(tool.id) || tool.options?.namespace !== MEMORY_TOOL_NAMESPACE) continue;
|
|
460
|
+
if (tool.options.codemode === false) continue;
|
|
461
|
+
editor.update(tool.id, (target) => {
|
|
462
|
+
const options = target.options;
|
|
463
|
+
target.options = { ...options, codemode: { ...asRecord(options.codemode), pinned: true } };
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
|
|
435
468
|
const isV2CodememMcpConfigured = async (context) => {
|
|
436
469
|
const response = await context.mcp.list();
|
|
437
470
|
if (!Array.isArray(response?.data)) throw new TypeError("MCP server list unavailable");
|
|
@@ -493,6 +526,7 @@ const registerV2Tools = async (context, runtime, isActive) => {
|
|
|
493
526
|
directory: context.location.directory,
|
|
494
527
|
isActive,
|
|
495
528
|
});
|
|
529
|
+
pinV2RetrievalCatalog(editor, context.app?.version);
|
|
496
530
|
});
|
|
497
531
|
return mcpObserver ? [tools, mcpObserver] : [tools];
|
|
498
532
|
};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
//#region packages/core/src/private-text.ts
|
|
2
|
+
var TAG_NAME_CHAR = /[A-Za-z0-9_.:-]/;
|
|
3
|
+
var WHITESPACE = /\s/;
|
|
4
|
+
var CUT = (text) => ({
|
|
5
|
+
kind: "cut",
|
|
6
|
+
end: text.length
|
|
7
|
+
});
|
|
8
|
+
function skipWhitespace(text, index) {
|
|
9
|
+
let next = index;
|
|
10
|
+
while (next < text.length && WHITESPACE.test(text.charAt(next))) next += 1;
|
|
11
|
+
return next;
|
|
12
|
+
}
|
|
13
|
+
/** The private tag starting at `text[start]` (a `<`), or null when it is not one. */
|
|
14
|
+
function readPrivateTag(text, start) {
|
|
15
|
+
let index = skipWhitespace(text, start + 1);
|
|
16
|
+
const closer = text.charAt(index) === "/";
|
|
17
|
+
index = skipWhitespace(text, closer ? index + 1 : index);
|
|
18
|
+
const nameStart = index;
|
|
19
|
+
while (index < text.length && TAG_NAME_CHAR.test(text.charAt(index))) index += 1;
|
|
20
|
+
if (text.slice(nameStart, index).toLowerCase() !== "private") return null;
|
|
21
|
+
return readTagEnd(text, index, closer);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Where a tag ends: the first `>` outside a quoted attribute value. A tag that
|
|
25
|
+
* reaches the end of the text, ends inside an unclosed quote, or meets an unquoted
|
|
26
|
+
* `<` before its `>` is malformed and cut off, so it can never hide another tag.
|
|
27
|
+
*/
|
|
28
|
+
function readTagEnd(text, start, closer) {
|
|
29
|
+
let lastSignificant = "";
|
|
30
|
+
for (let index = start; index < text.length; index += 1) {
|
|
31
|
+
const char = text.charAt(index);
|
|
32
|
+
if (char === "\"" || char === "'") {
|
|
33
|
+
const closingQuote = text.indexOf(char, index + 1);
|
|
34
|
+
if (closingQuote === -1) break;
|
|
35
|
+
index = closingQuote;
|
|
36
|
+
lastSignificant = char;
|
|
37
|
+
} else if (char === ">") return tagEnding(index + 1, closer, lastSignificant);
|
|
38
|
+
else if (char === "<") break;
|
|
39
|
+
else if (!WHITESPACE.test(char)) lastSignificant = char;
|
|
40
|
+
}
|
|
41
|
+
return CUT(text);
|
|
42
|
+
}
|
|
43
|
+
/** A tag ending at `end`; an opener whose last character before `>` is `/` is self-closing. */
|
|
44
|
+
function tagEnding(end, closer, lastSignificant) {
|
|
45
|
+
if (closer) return {
|
|
46
|
+
kind: "close",
|
|
47
|
+
end
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
kind: lastSignificant === "/" ? "self" : "open",
|
|
51
|
+
end
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Block content running to `terminator`, or a cut when the terminator never comes. */
|
|
55
|
+
function readUntil(text, start, terminator) {
|
|
56
|
+
const at = text.indexOf(terminator, start);
|
|
57
|
+
return at === -1 ? CUT(text) : {
|
|
58
|
+
kind: "other",
|
|
59
|
+
end: at + terminator.length
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The tag at a `<` inside a block. Every `<` there starts a tag, including one
|
|
64
|
+
* followed by a space or digit, because reading it as a tag removes more. A private
|
|
65
|
+
* tag changes depth; any other tag, comment or CDATA section is skipped whole as
|
|
66
|
+
* block content, so a closer in its quoted attributes or body cannot end the block.
|
|
67
|
+
*/
|
|
68
|
+
function readBlockTag(text, start) {
|
|
69
|
+
const privateTag = readPrivateTag(text, start);
|
|
70
|
+
if (privateTag) return privateTag;
|
|
71
|
+
if (text.startsWith("<!--", start)) return readUntil(text, start + 4, "-->");
|
|
72
|
+
if (text.startsWith("<![CDATA[", start)) return readUntil(text, start + 9, "]]>");
|
|
73
|
+
const tag = readTagEnd(text, start + 1, false);
|
|
74
|
+
return tag.kind === "cut" ? tag : {
|
|
75
|
+
kind: "other",
|
|
76
|
+
end: tag.end
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** Remove private blocks from one text value, scanned on its own. Non-strings become "". */
|
|
80
|
+
function stripPrivate(text) {
|
|
81
|
+
if (typeof text !== "string" || !text) return "";
|
|
82
|
+
if (!text.toLowerCase().includes("private")) return text;
|
|
83
|
+
return removePrivateBlocks(text);
|
|
84
|
+
}
|
|
85
|
+
/** The output once scanning stops at `end`; text after an open block is removed. */
|
|
86
|
+
function finish(state, text, end) {
|
|
87
|
+
return state.depth === 0 ? state.output + text.slice(state.kept, end) : state.output;
|
|
88
|
+
}
|
|
89
|
+
/** A private opener or closer: keep the text before it when outside a block, then move depth. */
|
|
90
|
+
function applyMarker(state, text, start, tag) {
|
|
91
|
+
if (state.depth === 0) state.output += text.slice(state.kept, start);
|
|
92
|
+
if (tag.kind === "open") state.depth += 1;
|
|
93
|
+
else if (state.depth > 0) state.depth -= 1;
|
|
94
|
+
state.kept = tag.end;
|
|
95
|
+
}
|
|
96
|
+
function removePrivateBlocks(text) {
|
|
97
|
+
const state = {
|
|
98
|
+
output: "",
|
|
99
|
+
depth: 0,
|
|
100
|
+
kept: 0
|
|
101
|
+
};
|
|
102
|
+
let index = text.indexOf("<");
|
|
103
|
+
while (index !== -1) {
|
|
104
|
+
const tag = state.depth > 0 ? readBlockTag(text, index) : readPrivateTag(text, index);
|
|
105
|
+
if (!tag) {
|
|
106
|
+
index = text.indexOf("<", index + 1);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (tag.kind === "cut") return finish(state, text, index);
|
|
110
|
+
if (tag.kind === "open" || tag.kind === "close") applyMarker(state, text, index, tag);
|
|
111
|
+
index = text.indexOf("<", tag.end);
|
|
112
|
+
}
|
|
113
|
+
return finish(state, text, text.length);
|
|
114
|
+
}
|
|
115
|
+
/** True when the text contains a private marker that stripping would remove. */
|
|
116
|
+
function hasPrivateMarker(text) {
|
|
117
|
+
return stripPrivate(text) !== text;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Remove private blocks from every string value, each scanned on its own. An entry
|
|
121
|
+
* whose key carries a private marker is dropped with its value. Numbers, booleans
|
|
122
|
+
* and null are not text and are kept.
|
|
123
|
+
*/
|
|
124
|
+
function stripPrivateValues(value) {
|
|
125
|
+
if (typeof value === "string") return stripPrivate(value);
|
|
126
|
+
if (Array.isArray(value)) return value.map(stripPrivateValues);
|
|
127
|
+
if (value != null && typeof value === "object") {
|
|
128
|
+
const result = {};
|
|
129
|
+
for (const [key, item] of Object.entries(value)) if (!hasPrivateMarker(key)) result[key] = stripPrivateValues(item);
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
/** True when any string or key inside the value carries a private marker. */
|
|
135
|
+
function containsPrivateMarker(value) {
|
|
136
|
+
if (typeof value === "string") return hasPrivateMarker(value);
|
|
137
|
+
if (Array.isArray(value)) return value.some(containsPrivateMarker);
|
|
138
|
+
if (value != null && typeof value === "object") return Object.entries(value).some(([key, item]) => hasPrivateMarker(key) || containsPrivateMarker(item));
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
/** Fields that route or identify a raw event. They are kept exactly as sent. */
|
|
142
|
+
var RAW_EVENT_ROUTING_KEYS = /* @__PURE__ */ new Set([
|
|
143
|
+
"source",
|
|
144
|
+
"session_stream_id",
|
|
145
|
+
"session_id",
|
|
146
|
+
"stream_id",
|
|
147
|
+
"opencode_session_id",
|
|
148
|
+
"event_id",
|
|
149
|
+
"event_type",
|
|
150
|
+
"event_seq",
|
|
151
|
+
"ts_wall_ms",
|
|
152
|
+
"ts_mono_ms",
|
|
153
|
+
"host_generation"
|
|
154
|
+
]);
|
|
155
|
+
/** Captured content of a raw event. Each is cleaned before it is kept. */
|
|
156
|
+
var RAW_EVENT_CONTENT_KEYS = /* @__PURE__ */ new Set([
|
|
157
|
+
"payload",
|
|
158
|
+
"cwd",
|
|
159
|
+
"project",
|
|
160
|
+
"started_at"
|
|
161
|
+
]);
|
|
162
|
+
var isRecord = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
163
|
+
/** The kept form of one field of a raw event, or undefined when the field is dropped. */
|
|
164
|
+
function cleanRawEventField(key, value, clean) {
|
|
165
|
+
if (RAW_EVENT_ROUTING_KEYS.has(key)) return value;
|
|
166
|
+
if (RAW_EVENT_CONTENT_KEYS.has(key)) return clean(value);
|
|
167
|
+
if (key === "capture_context" && value != null && !containsPrivateMarker(value)) return clean(value);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* One raw event reduced to the fields ingestion reads, in their original order.
|
|
171
|
+
* Routing fields are kept as sent, content is cleaned, and every other field is
|
|
172
|
+
* dropped. A request's `events` list is reduced the same way, event by event.
|
|
173
|
+
*/
|
|
174
|
+
function cleanRawEvent(item, clean, { withEvents }) {
|
|
175
|
+
const cleaned = {};
|
|
176
|
+
for (const [key, value] of Object.entries(item)) {
|
|
177
|
+
if (withEvents && key === "events") {
|
|
178
|
+
cleaned.events = Array.isArray(value) ? value.map((event) => isRecord(event) ? cleanRawEvent(event, clean, { withEvents: false }) : clean(event)) : clean(value);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const kept = cleanRawEventField(key, value, clean);
|
|
182
|
+
if (kept !== void 0) cleaned[key] = kept;
|
|
183
|
+
}
|
|
184
|
+
return cleaned;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The form of a raw-event envelope, or of a request carrying `events`, that may be
|
|
188
|
+
* stored: each event reduced to the fields ingestion reads and cleaned on its own.
|
|
189
|
+
* `clean` cleans content values; core also redacts secret-named fields with it.
|
|
190
|
+
*/
|
|
191
|
+
function sanitizeRawEventEnvelope(envelope, clean = stripPrivateValues) {
|
|
192
|
+
if (!isRecord(envelope)) return envelope;
|
|
193
|
+
return cleanRawEvent(envelope, clean, { withEvents: true });
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Top-level fields of a native hook payload that route or identify the event, such
|
|
197
|
+
* as the session, event name, turn, tool call and transcript location. They are
|
|
198
|
+
* kept as sent; every other field is captured content.
|
|
199
|
+
*/
|
|
200
|
+
var HOOK_ROUTING_KEYS = /* @__PURE__ */ new Set([
|
|
201
|
+
"session_id",
|
|
202
|
+
"sessionId",
|
|
203
|
+
"hook_event_name",
|
|
204
|
+
"turn_id",
|
|
205
|
+
"tool_use_id",
|
|
206
|
+
"transcript_path",
|
|
207
|
+
"codemem_generated_event_nonce",
|
|
208
|
+
"piEvent",
|
|
209
|
+
"pi_event",
|
|
210
|
+
"event",
|
|
211
|
+
"type",
|
|
212
|
+
"entryId",
|
|
213
|
+
"entry_id",
|
|
214
|
+
"toolCallId",
|
|
215
|
+
"tool_call_id"
|
|
216
|
+
]);
|
|
217
|
+
/**
|
|
218
|
+
* A native hook payload (Claude, Codex or Pi) with private blocks removed from its
|
|
219
|
+
* content, each string value on its own, before it is spooled or saved.
|
|
220
|
+
*/
|
|
221
|
+
function sanitizeHookPayload(payload) {
|
|
222
|
+
const sanitized = {};
|
|
223
|
+
for (const [key, value] of Object.entries(payload)) if (HOOK_ROUTING_KEYS.has(key)) sanitized[key] = value;
|
|
224
|
+
else if (!hasPrivateMarker(key)) sanitized[key] = stripPrivateValues(value);
|
|
225
|
+
return sanitized;
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
export { containsPrivateMarker, hasPrivateMarker, sanitizeHookPayload, sanitizeRawEventEnvelope, stripPrivate, stripPrivateValues };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { appendFile, mkdir } from "node:fs/promises";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
+
import { sanitizeRawEventEnvelope } from "./private-text.mjs";
|
|
4
5
|
import {
|
|
5
6
|
DEFAULT_DRAIN_LIMIT,
|
|
6
7
|
DEFAULT_MAX_ENTRIES,
|
|
@@ -475,7 +476,8 @@ const cachedEnvelope = (state, sessionID, type, payload, now) => {
|
|
|
475
476
|
const cached = payload && typeof payload === "object" ? state.envelopes.get(payload) : null;
|
|
476
477
|
if (cached) return cached;
|
|
477
478
|
const options = state.options;
|
|
478
|
-
|
|
479
|
+
// Remove private blocks before the envelope is sent or written to the retry spool.
|
|
480
|
+
const envelope = sanitizeRawEventEnvelope(options.buildEnvelope({
|
|
479
481
|
sessionID,
|
|
480
482
|
type,
|
|
481
483
|
payload,
|
|
@@ -486,7 +488,7 @@ const cachedEnvelope = (state, sessionID, type, payload, now) => {
|
|
|
486
488
|
nowMono: typeof performance !== "undefined" && performance.now ? performance.now() : null,
|
|
487
489
|
nextEventId: options.nextEventId,
|
|
488
490
|
captureContext: state.captureContexts.get(payload),
|
|
489
|
-
});
|
|
491
|
+
}));
|
|
490
492
|
const serialized = JSON.stringify(envelope);
|
|
491
493
|
const value = { body: JSON.parse(serialized), serialized };
|
|
492
494
|
if (payload && typeof payload === "object") state.envelopes.set(payload, value);
|
package/.opencode/lib/runtime.js
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
|
|
39
39
|
const TRUTHY_VALUES = ["1", "true", "yes"];
|
|
40
40
|
const DISABLED_VALUES = ["0", "false", "off"];
|
|
41
|
-
const PINNED_BACKEND_VERSION = "0.50.0-beta.
|
|
41
|
+
const PINNED_BACKEND_VERSION = "0.50.0-beta.3";
|
|
42
42
|
const COMPAT_CHECK_DELAY_MS = 1500;
|
|
43
43
|
const COMPAT_CHECK_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
44
44
|
const MAX_UPDATE_STATUS_BYTES = 16 * 1024;
|
|
@@ -1854,6 +1854,29 @@ const mapOpencodeEventTypeToAdapterType = (eventType) => {
|
|
|
1854
1854
|
return null;
|
|
1855
1855
|
};
|
|
1856
1856
|
|
|
1857
|
+
const toolCaptureMetadata = (event) => ({
|
|
1858
|
+
...(typeof event.codemode === "boolean" ? { codemode: event.codemode } : {}),
|
|
1859
|
+
...(event.message_id ? { message_id: event.message_id } : {}),
|
|
1860
|
+
...(event.execution_wrapper ? { execution_wrapper: true } : {}),
|
|
1861
|
+
...(event.contains_memory_calls ? { contains_memory_calls: true } : {}),
|
|
1862
|
+
});
|
|
1863
|
+
|
|
1864
|
+
const buildToolCaptureEvent = (input, output, serialize) => ({
|
|
1865
|
+
type: "tool.execute.after",
|
|
1866
|
+
tool: input.tool,
|
|
1867
|
+
args: input.args ?? {},
|
|
1868
|
+
result: output.error ? null : serialize(output.output),
|
|
1869
|
+
error: output.error ? serialize(output.error) : null,
|
|
1870
|
+
...(input.id ? { tool_call_id: String(input.id) } : {}),
|
|
1871
|
+
...toolCaptureMetadata({
|
|
1872
|
+
codemode: input.codemode,
|
|
1873
|
+
message_id: input.messageID,
|
|
1874
|
+
execution_wrapper: input.executionWrapper,
|
|
1875
|
+
contains_memory_calls: input.containsMemoryCalls,
|
|
1876
|
+
}),
|
|
1877
|
+
timestamp: new Date().toISOString(),
|
|
1878
|
+
});
|
|
1879
|
+
|
|
1857
1880
|
const buildOpencodeAdapterPayload = (event) => {
|
|
1858
1881
|
const eventType = event?.type;
|
|
1859
1882
|
if (eventType === "user_prompt") {
|
|
@@ -1889,6 +1912,7 @@ const buildOpencodeAdapterPayload = (event) => {
|
|
|
1889
1912
|
tool_output: event?.result ?? null,
|
|
1890
1913
|
error: event?.error ?? null,
|
|
1891
1914
|
...(toolCallID ? { tool_call_id: toolCallID } : {}),
|
|
1915
|
+
...toolCaptureMetadata(event),
|
|
1892
1916
|
};
|
|
1893
1917
|
}
|
|
1894
1918
|
|
|
@@ -1921,6 +1945,10 @@ const sanitizeIdPart = (value, fallback, maxChars) => {
|
|
|
1921
1945
|
const buildAdapterEventId = ({ sessionID, eventType, event, payload, ts }) => {
|
|
1922
1946
|
const safeSessionID = sanitizeIdPart(sessionID, "unknown", 48);
|
|
1923
1947
|
const safeType = sanitizeIdPart(eventType, "event", 24);
|
|
1948
|
+
if (typeof event.codemode === "boolean" && event.tool_call_id && eventType === "tool_result") {
|
|
1949
|
+
const digest = stableDigest([sessionID, event.message_id ?? null, event.tool_call_id]);
|
|
1950
|
+
return `oc:${safeSessionID}:${safeType}:${digest}`;
|
|
1951
|
+
}
|
|
1924
1952
|
const rawTimestamp =
|
|
1925
1953
|
typeof event?.timestamp === "string" && event.timestamp.trim()
|
|
1926
1954
|
? event.timestamp.trim()
|
|
@@ -3937,6 +3965,7 @@ export const createCodememRuntime = async ({ location, host, hostGeneration = nu
|
|
|
3937
3965
|
return String(value);
|
|
3938
3966
|
}
|
|
3939
3967
|
};
|
|
3968
|
+
const serializeToolCapture = (value) => truncate(safeStringify(value));
|
|
3940
3969
|
|
|
3941
3970
|
const trimRetainedEvents = (retainedEvents) => {
|
|
3942
3971
|
trimEventQueue({
|
|
@@ -4755,14 +4784,11 @@ export const createCodememRuntime = async ({ location, host, hostGeneration = nu
|
|
|
4755
4784
|
if (sessionID) await capturePendingPrompts({ sessionID });
|
|
4756
4785
|
if (!runtimeActive) return;
|
|
4757
4786
|
const args = input.args ?? {};
|
|
4758
|
-
const result = output.output;
|
|
4759
|
-
const error = output.error ?? null;
|
|
4760
4787
|
const toolName = input.tool;
|
|
4761
|
-
const toolCallID = input.id ?? null;
|
|
4762
4788
|
|
|
4763
4789
|
// Update activity and session context
|
|
4764
4790
|
updateActivity();
|
|
4765
|
-
sessionContext.toolCount++;
|
|
4791
|
+
if (!input.executionWrapper) sessionContext.toolCount++;
|
|
4766
4792
|
|
|
4767
4793
|
// Track files from tool events
|
|
4768
4794
|
const filePath = args.filePath || args.path;
|
|
@@ -4781,15 +4807,7 @@ export const createCodememRuntime = async ({ location, host, hostGeneration = nu
|
|
|
4781
4807
|
}
|
|
4782
4808
|
}
|
|
4783
4809
|
|
|
4784
|
-
captureCodememEvent(input.sessionID,
|
|
4785
|
-
type: "tool.execute.after",
|
|
4786
|
-
tool: toolName,
|
|
4787
|
-
args,
|
|
4788
|
-
result: error ? null : truncate(safeStringify(result)),
|
|
4789
|
-
error: error ? truncate(safeStringify(error)) : null,
|
|
4790
|
-
...(toolCallID ? { tool_call_id: String(toolCallID) } : {}),
|
|
4791
|
-
timestamp: new Date().toISOString(),
|
|
4792
|
-
});
|
|
4810
|
+
captureCodememEvent(input.sessionID, buildToolCaptureEvent(input, output, serializeToolCapture));
|
|
4793
4811
|
await logLine(`tool.execute.after ${toolName} queued=${events.length} tools=${sessionContext.toolCount}`);
|
|
4794
4812
|
|
|
4795
4813
|
// Check if we should force flush due to threshold
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemem/opencode-plugin",
|
|
3
|
-
"version": "0.50.0-beta.
|
|
3
|
+
"version": "0.50.0-beta.3",
|
|
4
4
|
"description": "Codemem plugin for OpenCode",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@babel/parser": "8.1.0",
|
|
43
43
|
"@opencode/cli": "2.0.24",
|
|
44
44
|
"@types/node": "^24.12.4",
|
|
45
|
-
"codemem": "^0.50.0-beta.
|
|
45
|
+
"codemem": "^0.50.0-beta.3",
|
|
46
46
|
"vitest": "^4.1.11"
|
|
47
47
|
},
|
|
48
48
|
"repository": {
|