@codemem/opencode-plugin 0.50.0-beta.2 → 0.50.0-beta.4
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.
|
@@ -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.
|
|
@@ -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.4";
|
|
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;
|
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.4",
|
|
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.4",
|
|
46
46
|
"vitest": "^4.1.11"
|
|
47
47
|
},
|
|
48
48
|
"repository": {
|