@yagni-app/code-staging 1.2.14-staging.2276.1 → 1.2.14-staging.2282.1
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/dist/extension/branding.d.ts +18 -0
- package/dist/extension/branding.js +30 -0
- package/dist/extension/index.d.ts +2 -0
- package/dist/extension/index.js +15 -0
- package/dist/extension/pipeline/changeScan.d.ts +0 -4
- package/dist/extension/pipeline/changeScan.js +50 -3
- package/dist/extension/pipeline/placedValueHeal.d.ts +67 -0
- package/dist/extension/pipeline/placedValueHeal.js +195 -0
- package/dist/extension/pipeline/sessionInbox.d.ts +67 -0
- package/dist/extension/pipeline/sessionInbox.js +255 -0
- package/dist/extension/pipeline/sessionLane.d.ts +15 -0
- package/dist/extension/pipeline/sessionLane.js +42 -2
- package/dist/extension/placedValues.d.ts +102 -0
- package/dist/extension/placedValues.js +462 -0
- package/package.json +2 -2
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A yak's System places its provided values on the machine the session works
|
|
3
|
+
* on (YAG-1209): a tmpfs file, `/run/yagni/secret/env`, linked at
|
|
4
|
+
* `/run/yagni/env`, owned by the run user the session runs as, so the session
|
|
5
|
+
* can read it, and a running service's environment too. This module is the
|
|
6
|
+
* first of three precautions: it replaces each placed secret in what the
|
|
7
|
+
* model reads. Only the secrets count ({@link PLACED_SECRET_NAMES_FILE}: a
|
|
8
|
+
* credential the host's one change classifier calls a secret); test data
|
|
9
|
+
* and a public value the model reads as they are. The session is told never
|
|
10
|
+
* to read the file (`branding.ts`, `PLACED_VALUES_SECTION`), its finish asks
|
|
11
|
+
* the model to take a secret out of its change (`pipeline/placedValueHeal.ts`),
|
|
12
|
+
* and the host refuses a push that still holds one (the backend's
|
|
13
|
+
* `attempts/placedValues.ts`).
|
|
14
|
+
*
|
|
15
|
+
* It acts only where the file is: on any other machine {@link openPlacedValues}
|
|
16
|
+
* opens nothing and no handler registers, so every other session is unchanged.
|
|
17
|
+
* Where it is, three handlers run after every other one the extension adds:
|
|
18
|
+
* `tool_result` rewrites what a tool returns before the model reads it (and
|
|
19
|
+
* before the session file keeps it), `message_end` rewrites any other message
|
|
20
|
+
* before the session file keeps it (a background job's notification quotes
|
|
21
|
+
* the job's output tail, and pi's compaction and branch summaries read the
|
|
22
|
+
* saved session, never a model call's context), and `context` rewrites every
|
|
23
|
+
* message a model call carries, as the backstop. An assistant's own message
|
|
24
|
+
* is never rewritten: its thinking is signed.
|
|
25
|
+
*
|
|
26
|
+
* Honest scope: an exact match of each value in the forms it is printed in
|
|
27
|
+
* (raw, inside the file, as bash and JSON quote it). A value the session
|
|
28
|
+
* encodes first (base64, split, reversed), part of a value cut by a tool's
|
|
29
|
+
* truncation, and a value inside an image all get past.
|
|
30
|
+
*/
|
|
31
|
+
import { readFileSync, statSync } from "node:fs";
|
|
32
|
+
import { logEvent } from "./errorSink.js";
|
|
33
|
+
/** Where the backend places the values (`repos/system/needs/placement.ts`, `SYSTEM_SECRET_FILE`). */
|
|
34
|
+
export const PLACED_VALUES_FILE = "/run/yagni/secret/env";
|
|
35
|
+
/** The link scripts source (`SYSTEM_ENV_PATH`). */
|
|
36
|
+
export const PLACED_VALUES_LINK = "/run/yagni/env";
|
|
37
|
+
/**
|
|
38
|
+
* The names of the placed values that are secrets, one per line, names only
|
|
39
|
+
* (`SYSTEM_SECRET_NAMES_FILE`): the host's one classifier picked them
|
|
40
|
+
* (`placedSecretsOf`, a credential its change scan calls a secret). Every
|
|
41
|
+
* other value (test data, a public URL) the model reads as it is. A machine
|
|
42
|
+
* whose values were placed without this file keeps every value from the model.
|
|
43
|
+
*/
|
|
44
|
+
export const PLACED_SECRET_NAMES_FILE = "/run/yagni/secret/secret-names";
|
|
45
|
+
/**
|
|
46
|
+
* The shortest value replaced: the shortest a person can enter for a need
|
|
47
|
+
* (`SYSTEM_NEED_VALUE_MIN_LENGTH`), and the floor the host's redactors keep.
|
|
48
|
+
* Anything shorter (`postgres`, a port) would mangle ordinary output.
|
|
49
|
+
*/
|
|
50
|
+
export const PLACED_VALUE_MIN_LENGTH = 8;
|
|
51
|
+
/** The host's own mark (`redactValues`), so the transcript reads the same on both sides. */
|
|
52
|
+
export const PLACED_VALUE_MARK = "[REDACTED]";
|
|
53
|
+
/** The tmpfs is mounted at 1 MiB; a larger file is not the host's. */
|
|
54
|
+
const MAX_FILE_BYTES = 1024 * 1024;
|
|
55
|
+
const NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
56
|
+
const WITHHELD = "[The tool's output was withheld: it could not be checked for the System's placed values.]";
|
|
57
|
+
const WITHHELD_MESSAGE = "[This message was withheld: it could not be checked for the System's placed values.]";
|
|
58
|
+
/**
|
|
59
|
+
* The values in the host's file: one `NAME='value'` line per value, a `'`
|
|
60
|
+
* inside written `'"'"'`, a value free to span lines. A line it cannot read
|
|
61
|
+
* is skipped.
|
|
62
|
+
*/
|
|
63
|
+
export function parsePlacedEnvFile(text) {
|
|
64
|
+
const values = new Map();
|
|
65
|
+
let at = 0;
|
|
66
|
+
while (at < text.length) {
|
|
67
|
+
const eq = text.indexOf("=", at);
|
|
68
|
+
const lineEnd = text.indexOf("\n", at);
|
|
69
|
+
const name = eq === -1 ? "" : text.slice(at, eq);
|
|
70
|
+
const read = NAME.test(name) && (lineEnd === -1 || eq < lineEnd) ? quotedValueAt(text, eq + 1) : null;
|
|
71
|
+
if (read)
|
|
72
|
+
values.set(name, read.value);
|
|
73
|
+
at = read ? read.next : lineEnd === -1 ? text.length : lineEnd + 1;
|
|
74
|
+
}
|
|
75
|
+
return values;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The quoted value that starts at `start` (`'a'"'"'b'`, free to span lines),
|
|
79
|
+
* and where the next line starts; null when the line is not one the host writes.
|
|
80
|
+
*/
|
|
81
|
+
function quotedValueAt(text, start) {
|
|
82
|
+
if (start >= text.length || text[start] === "\n")
|
|
83
|
+
return null;
|
|
84
|
+
let cursor = start;
|
|
85
|
+
let value = "";
|
|
86
|
+
while (cursor < text.length && text[cursor] !== "\n") {
|
|
87
|
+
if (text.startsWith(`"'"`, cursor)) {
|
|
88
|
+
value += "'";
|
|
89
|
+
cursor += 3;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const close = text[cursor] === "'" ? text.indexOf("'", cursor + 1) : -1;
|
|
93
|
+
if (close === -1)
|
|
94
|
+
return null;
|
|
95
|
+
value += text.slice(cursor + 1, close);
|
|
96
|
+
cursor = close + 1;
|
|
97
|
+
}
|
|
98
|
+
return { value, next: cursor + 1 };
|
|
99
|
+
}
|
|
100
|
+
/** Bash's own names for the characters its ANSI-C quoting escapes (`ansic_quote`). */
|
|
101
|
+
const ANSI_C_NAMED = {
|
|
102
|
+
"\u001b": "\\E",
|
|
103
|
+
"\u0007": "\\a",
|
|
104
|
+
"\v": "\\v",
|
|
105
|
+
"\b": "\\b",
|
|
106
|
+
"\f": "\\f",
|
|
107
|
+
"\n": "\\n",
|
|
108
|
+
"\r": "\\r",
|
|
109
|
+
"\t": "\\t",
|
|
110
|
+
"\\": "\\\\",
|
|
111
|
+
"'": "\\'",
|
|
112
|
+
};
|
|
113
|
+
/** A value inside bash's `$'...'` (`declare -p` of a value with a newline or a control character). */
|
|
114
|
+
function ansiCQuoted(value) {
|
|
115
|
+
let out = "";
|
|
116
|
+
for (const char of value) {
|
|
117
|
+
const code = char.codePointAt(0);
|
|
118
|
+
const named = ANSI_C_NAMED[char];
|
|
119
|
+
if (named)
|
|
120
|
+
out += named;
|
|
121
|
+
else if (code < 0x20 || code === 0x7f)
|
|
122
|
+
out += `\\${code.toString(8).padStart(3, "0")}`;
|
|
123
|
+
else
|
|
124
|
+
out += char;
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Every form a value is printed in, longest first: as it is, inside the
|
|
130
|
+
* host's file, as bash quotes it (`declare -p`, `set`, in single, double or
|
|
131
|
+
* ANSI-C quotes), and as JSON escapes it (`docker inspect`, `jq`, a
|
|
132
|
+
* multi-line key). Values under the floor are left out.
|
|
133
|
+
*/
|
|
134
|
+
export function placedValueForms(values) {
|
|
135
|
+
const forms = new Set();
|
|
136
|
+
for (const value of values) {
|
|
137
|
+
if (value.length < PLACED_VALUE_MIN_LENGTH)
|
|
138
|
+
continue;
|
|
139
|
+
forms.add(value);
|
|
140
|
+
forms.add(value.replaceAll("'", `'"'"'`));
|
|
141
|
+
forms.add(value.replaceAll("'", `'\\''`));
|
|
142
|
+
forms.add(value.replace(/[\\"$`]/g, (char) => `\\${char}`));
|
|
143
|
+
forms.add(ansiCQuoted(value));
|
|
144
|
+
forms.add(JSON.stringify(value).slice(1, -1));
|
|
145
|
+
}
|
|
146
|
+
return [...forms].sort((a, b) => b.length - a.length);
|
|
147
|
+
}
|
|
148
|
+
/** `text` with every form replaced by the mark. */
|
|
149
|
+
export function redactPlacedText(text, forms) {
|
|
150
|
+
let out = text;
|
|
151
|
+
for (const form of forms) {
|
|
152
|
+
if (out.includes(form))
|
|
153
|
+
out = out.split(form).join(PLACED_VALUE_MARK);
|
|
154
|
+
}
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
/** The file's text, or null when it is not a regular file of the host's size. */
|
|
158
|
+
function readPlacedFile(path) {
|
|
159
|
+
try {
|
|
160
|
+
const stat = statSync(path);
|
|
161
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES)
|
|
162
|
+
return null;
|
|
163
|
+
return readFileSync(path, "utf8");
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** The names the host listed as secrets, or null when it listed none (a placement before the list). */
|
|
170
|
+
function readSecretNames(path) {
|
|
171
|
+
const text = path ? readPlacedFile(path) : null;
|
|
172
|
+
if (text === null)
|
|
173
|
+
return null;
|
|
174
|
+
return new Set(text
|
|
175
|
+
.split("\n")
|
|
176
|
+
.map((line) => line.trim())
|
|
177
|
+
.filter((line) => NAME.test(line)));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Opens the placed values when one of `paths` is there, else null (no file:
|
|
181
|
+
* not a yak's machine, and nothing should change). Only the secrets among
|
|
182
|
+
* them are kept from the model: those `namesPath` lists. A secret is kept
|
|
183
|
+
* for the life of the process, so a session that deletes the file and prints
|
|
184
|
+
* a copy is still covered, and one placed later is added. While there is no
|
|
185
|
+
* list (a placement from before it, or the list gone), every value read is
|
|
186
|
+
* kept from the model too, but only until a list is read: it is read again
|
|
187
|
+
* at every check, and test data and a public value then show as they are.
|
|
188
|
+
*/
|
|
189
|
+
export function openPlacedValues(paths = [PLACED_VALUES_FILE, PLACED_VALUES_LINK], namesPath = PLACED_SECRET_NAMES_FILE) {
|
|
190
|
+
/** Each secret the list named, by value: never forgotten. */
|
|
191
|
+
const kept = new Map();
|
|
192
|
+
/** Every value read while there is no list: kept until a list is read. */
|
|
193
|
+
const unlisted = new Map();
|
|
194
|
+
let forms = [];
|
|
195
|
+
const all = () => new Map([...unlisted, ...kept]);
|
|
196
|
+
const read = () => {
|
|
197
|
+
let found = false;
|
|
198
|
+
const names = readSecretNames(namesPath);
|
|
199
|
+
// The list says what is a secret: whatever it does not name shows again.
|
|
200
|
+
if (names !== null)
|
|
201
|
+
unlisted.clear();
|
|
202
|
+
for (const path of paths) {
|
|
203
|
+
const text = readPlacedFile(path);
|
|
204
|
+
if (text === null)
|
|
205
|
+
continue;
|
|
206
|
+
found = true;
|
|
207
|
+
for (const [name, value] of parsePlacedEnvFile(text)) {
|
|
208
|
+
if (names === null)
|
|
209
|
+
unlisted.set(value, name);
|
|
210
|
+
else if (names.has(name) && !kept.has(value))
|
|
211
|
+
kept.set(value, name);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// A handful of values: their forms are made again at each check.
|
|
215
|
+
forms = placedValueForms(all().keys());
|
|
216
|
+
return found;
|
|
217
|
+
};
|
|
218
|
+
if (!read())
|
|
219
|
+
return null;
|
|
220
|
+
return {
|
|
221
|
+
forms: () => {
|
|
222
|
+
read();
|
|
223
|
+
return forms;
|
|
224
|
+
},
|
|
225
|
+
secrets: () => {
|
|
226
|
+
read();
|
|
227
|
+
return [...kept].map(([value, name]) => ({ name, value }));
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/** The parts with each text part's values replaced; the same array when nothing changed. */
|
|
232
|
+
function redactParts(parts, forms) {
|
|
233
|
+
let changed = false;
|
|
234
|
+
const next = parts.map((part) => {
|
|
235
|
+
if (part?.type !== "text" || typeof part.text !== "string")
|
|
236
|
+
return part;
|
|
237
|
+
const text = redactPlacedText(part.text, forms);
|
|
238
|
+
if (text === part.text)
|
|
239
|
+
return part;
|
|
240
|
+
changed = true;
|
|
241
|
+
return { ...part, text };
|
|
242
|
+
});
|
|
243
|
+
return changed ? next : parts;
|
|
244
|
+
}
|
|
245
|
+
/** String or parts, as a user or custom message carries its content. */
|
|
246
|
+
function redactContent(content, forms) {
|
|
247
|
+
if (typeof content === "string")
|
|
248
|
+
return redactPlacedText(content, forms);
|
|
249
|
+
return (Array.isArray(content) ? redactParts(content, forms) : content);
|
|
250
|
+
}
|
|
251
|
+
/** How deep {@link redactDetails} walks: a tool's details are a few levels of plain data. */
|
|
252
|
+
const MAX_DETAILS_DEPTH = 8;
|
|
253
|
+
/**
|
|
254
|
+
* A tool result's `details` with each string's secrets replaced: plain
|
|
255
|
+
* objects and arrays walked, anything else left as it is. The model never
|
|
256
|
+
* reads them, but the session saves them (the edit tool's `diff` and
|
|
257
|
+
* `patch` quote the lines around an edit). The same value when nothing changed.
|
|
258
|
+
*/
|
|
259
|
+
function redactDetails(value, forms, depth = 0) {
|
|
260
|
+
if (typeof value === "string")
|
|
261
|
+
return redactPlacedText(value, forms);
|
|
262
|
+
if (depth >= MAX_DETAILS_DEPTH || value === null || typeof value !== "object")
|
|
263
|
+
return value;
|
|
264
|
+
if (Array.isArray(value)) {
|
|
265
|
+
const next = value.map((item) => redactDetails(item, forms, depth + 1));
|
|
266
|
+
return next.some((item, at) => item !== value[at]) ? next : value;
|
|
267
|
+
}
|
|
268
|
+
const proto = Object.getPrototypeOf(value);
|
|
269
|
+
if (proto !== Object.prototype && proto !== null)
|
|
270
|
+
return value;
|
|
271
|
+
let changed = false;
|
|
272
|
+
const next = {};
|
|
273
|
+
for (const [key, item] of Object.entries(value)) {
|
|
274
|
+
next[key] = redactDetails(item, forms, depth + 1);
|
|
275
|
+
if (next[key] !== item)
|
|
276
|
+
changed = true;
|
|
277
|
+
}
|
|
278
|
+
return changed ? next : value;
|
|
279
|
+
}
|
|
280
|
+
/** One message with its values replaced; the same object when nothing changed. Never an assistant's. */
|
|
281
|
+
function redactMessage(message, forms) {
|
|
282
|
+
const m = message;
|
|
283
|
+
switch (m.role) {
|
|
284
|
+
case "user":
|
|
285
|
+
case "custom":
|
|
286
|
+
case "toolResult": {
|
|
287
|
+
const content = m.content === undefined ? undefined : redactContent(m.content, forms);
|
|
288
|
+
const details = redactDetails(m.details, forms);
|
|
289
|
+
return content === m.content && details === m.details
|
|
290
|
+
? message
|
|
291
|
+
: {
|
|
292
|
+
...m,
|
|
293
|
+
...(content !== undefined ? { content } : {}),
|
|
294
|
+
...(details !== undefined ? { details } : {}),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
case "bashExecution": {
|
|
298
|
+
if (typeof m.output !== "string")
|
|
299
|
+
return message;
|
|
300
|
+
const output = redactPlacedText(m.output, forms);
|
|
301
|
+
return output === m.output ? message : { ...m, output };
|
|
302
|
+
}
|
|
303
|
+
case "compactionSummary":
|
|
304
|
+
case "branchSummary": {
|
|
305
|
+
if (typeof m.summary !== "string")
|
|
306
|
+
return message;
|
|
307
|
+
const summary = redactPlacedText(m.summary, forms);
|
|
308
|
+
return summary === m.summary ? message : { ...m, summary };
|
|
309
|
+
}
|
|
310
|
+
default:
|
|
311
|
+
return message;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* One message with its text withheld, for one that could not be checked: the
|
|
316
|
+
* same text-bearing fields {@link redactMessage} rewrites, `details` dropped.
|
|
317
|
+
* Never an assistant's.
|
|
318
|
+
*/
|
|
319
|
+
function withheldMessage(message) {
|
|
320
|
+
switch (message.role) {
|
|
321
|
+
case "user":
|
|
322
|
+
case "custom":
|
|
323
|
+
case "toolResult": {
|
|
324
|
+
const { details: _unchecked, ...rest } = message;
|
|
325
|
+
return { ...rest, content: [{ type: "text", text: WITHHELD_MESSAGE }] };
|
|
326
|
+
}
|
|
327
|
+
case "bashExecution":
|
|
328
|
+
return { ...message, output: WITHHELD_MESSAGE };
|
|
329
|
+
case "compactionSummary":
|
|
330
|
+
case "branchSummary":
|
|
331
|
+
return { ...message, summary: WITHHELD_MESSAGE };
|
|
332
|
+
default:
|
|
333
|
+
return message;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/** The message redacted, or withheld when it could not be checked; never passed through unchecked. */
|
|
337
|
+
function checkedMessage(message, forms, event) {
|
|
338
|
+
try {
|
|
339
|
+
if (forms === null)
|
|
340
|
+
throw new Error("the placed values could not be read");
|
|
341
|
+
return redactMessage(message, forms);
|
|
342
|
+
}
|
|
343
|
+
catch (err) {
|
|
344
|
+
logEvent({
|
|
345
|
+
source: "placed-values",
|
|
346
|
+
level: "warn",
|
|
347
|
+
event,
|
|
348
|
+
fields: { role: message.role, errorClass: err instanceof Error ? err.name : typeof err },
|
|
349
|
+
});
|
|
350
|
+
return withheldMessage(message);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Every form, or null when they could not be read (a message is then
|
|
355
|
+
* withheld, not passed), the failure logged by its error's class.
|
|
356
|
+
*/
|
|
357
|
+
function formsOf(store, handler) {
|
|
358
|
+
try {
|
|
359
|
+
return store.forms();
|
|
360
|
+
}
|
|
361
|
+
catch (err) {
|
|
362
|
+
logEvent({
|
|
363
|
+
source: "placed-values",
|
|
364
|
+
level: "warn",
|
|
365
|
+
event: "values_unread",
|
|
366
|
+
fields: { handler, errorClass: err instanceof Error ? err.name : typeof err },
|
|
367
|
+
});
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Registers the handlers. Call it after every other `tool_result`,
|
|
373
|
+
* `message_end`, `context` and `before_agent_start` handler the extension
|
|
374
|
+
* adds, so it sees what they append. Each message handler withholds what it
|
|
375
|
+
* could not check rather than pass it.
|
|
376
|
+
*/
|
|
377
|
+
export function registerPlacedValueRedaction(pi, store) {
|
|
378
|
+
pi.on("tool_result", (event) => {
|
|
379
|
+
try {
|
|
380
|
+
const forms = store.forms();
|
|
381
|
+
if (forms.length === 0)
|
|
382
|
+
return undefined;
|
|
383
|
+
const raw = event.content;
|
|
384
|
+
// The model never reads `details`, but the session saves them.
|
|
385
|
+
const details = redactDetails(event.details, forms);
|
|
386
|
+
const withDetails = details === event.details ? {} : { details };
|
|
387
|
+
if (typeof raw === "string") {
|
|
388
|
+
// Off pi's contract, but a tool that answers one string is still checked.
|
|
389
|
+
const text = redactPlacedText(raw, forms);
|
|
390
|
+
return text === raw && details === event.details
|
|
391
|
+
? undefined
|
|
392
|
+
: { content: [{ type: "text", text }], ...withDetails };
|
|
393
|
+
}
|
|
394
|
+
if (!Array.isArray(event.content)) {
|
|
395
|
+
return details === event.details ? undefined : withDetails;
|
|
396
|
+
}
|
|
397
|
+
const content = redactParts(event.content, forms);
|
|
398
|
+
return content === event.content && details === event.details
|
|
399
|
+
? undefined
|
|
400
|
+
: { content, ...withDetails };
|
|
401
|
+
}
|
|
402
|
+
catch (err) {
|
|
403
|
+
// Never pass through what could not be checked.
|
|
404
|
+
logEvent({
|
|
405
|
+
source: "placed-values",
|
|
406
|
+
level: "warn",
|
|
407
|
+
event: "tool_result_withheld",
|
|
408
|
+
fields: { errorClass: err instanceof Error ? err.name : typeof err },
|
|
409
|
+
});
|
|
410
|
+
// pi keeps a result's `details` unless a handler names new ones.
|
|
411
|
+
return { content: [{ type: "text", text: WITHHELD }], details: {} };
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
// A message is saved as `message_end` leaves it, and pi's compaction and
|
|
415
|
+
// branch summaries read the saved session, never the `context` pass below:
|
|
416
|
+
// a user or extension message that quotes a value (a background job's
|
|
417
|
+
// notice quotes its output) is saved replaced.
|
|
418
|
+
pi.on("message_end", (event) => {
|
|
419
|
+
const forms = formsOf(store, "message_end");
|
|
420
|
+
if (forms?.length === 0)
|
|
421
|
+
return undefined;
|
|
422
|
+
const message = checkedMessage(event.message, forms, "message_withheld");
|
|
423
|
+
return message === event.message ? undefined : { message };
|
|
424
|
+
});
|
|
425
|
+
pi.on("context", (event) => {
|
|
426
|
+
const forms = formsOf(store, "context");
|
|
427
|
+
if (forms?.length === 0 || !Array.isArray(event.messages))
|
|
428
|
+
return undefined;
|
|
429
|
+
let changed = false;
|
|
430
|
+
const messages = event.messages.map((message) => {
|
|
431
|
+
const next = checkedMessage(message, forms, "context_message_withheld");
|
|
432
|
+
if (next !== message)
|
|
433
|
+
changed = true;
|
|
434
|
+
return next;
|
|
435
|
+
});
|
|
436
|
+
return changed ? { messages } : undefined;
|
|
437
|
+
});
|
|
438
|
+
// The system prompt is not a message: pi builds it from the repository's
|
|
439
|
+
// own instruction files (AGENTS.md and the like), which could quote a
|
|
440
|
+
// secret, and this extension's branding. Registered after the branding, so
|
|
441
|
+
// it reads the prompt as sent.
|
|
442
|
+
pi.on("before_agent_start", (event) => {
|
|
443
|
+
if (typeof event.systemPrompt !== "string")
|
|
444
|
+
return undefined;
|
|
445
|
+
const forms = formsOf(store, "before_agent_start");
|
|
446
|
+
if (forms === null) {
|
|
447
|
+
// The one handler that does not fail closed: the prompt is the
|
|
448
|
+
// session's whole instructions, and withholding it would end the
|
|
449
|
+
// session. It goes as it is; `values_unread` above logs why.
|
|
450
|
+
logEvent({
|
|
451
|
+
source: "placed-values",
|
|
452
|
+
level: "warn",
|
|
453
|
+
event: "system_prompt_unchecked",
|
|
454
|
+
fields: {},
|
|
455
|
+
});
|
|
456
|
+
return undefined;
|
|
457
|
+
}
|
|
458
|
+
const systemPrompt = redactPlacedText(event.systemPrompt, forms);
|
|
459
|
+
return systemPrompt === event.systemPrompt ? undefined : { systemPrompt };
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
//# sourceMappingURL=placedValues.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yagni-app/code-staging",
|
|
3
|
-
"version": "1.2.14-staging.
|
|
3
|
+
"version": "1.2.14-staging.2282.1",
|
|
4
4
|
"description": "YAGNI Code: a terminal coding agent that already knows your company. One YAGNI login routes the model and grounds the agent in your team's context.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"author": "YAGNI, Inc. <jack@yagni.app> (https://yagni.app)",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"turndown": "^7.2.4",
|
|
59
59
|
"typebox": "^1.3.15"
|
|
60
60
|
},
|
|
61
|
-
"yagniSourceSha": "
|
|
61
|
+
"yagniSourceSha": "ab5e7376b562f4a0af054b2bd7377214afdc1394"
|
|
62
62
|
}
|