@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
|
@@ -112,6 +112,19 @@ export declare const SANDBOX_SECTION: string;
|
|
|
112
112
|
* contain the standalone word "pi", no `- ` bullet lines, no emojis.
|
|
113
113
|
*/
|
|
114
114
|
export declare const SANDBOX_CLOUD_SECTION: string;
|
|
115
|
+
export declare const PLACED_VALUES_SECTION_HEADER = "## The System's values";
|
|
116
|
+
/**
|
|
117
|
+
* What a session on a machine that holds a yak's System values is told
|
|
118
|
+
* (YAG-1209): never read them. Appended only where the extension found the
|
|
119
|
+
* file at activation (`placedValues.ts`), so no other session's prompt
|
|
120
|
+
* changes. The paths are the backend's (`repos/system/needs/placement.ts`),
|
|
121
|
+
* created at run time, never on the image, so the image smoke does not read
|
|
122
|
+
* this section.
|
|
123
|
+
*
|
|
124
|
+
* Content constraints (parity with {@link SANDBOX_SECTION}): must not contain
|
|
125
|
+
* the standalone word "pi", no `- ` bullet lines, no emojis.
|
|
126
|
+
*/
|
|
127
|
+
export declare const PLACED_VALUES_SECTION: string;
|
|
115
128
|
/**
|
|
116
129
|
* File-tool steering: prefer the first-class write/edit tools over bash file
|
|
117
130
|
* writes, one write call per file instead of a heredoc batch, and never create
|
|
@@ -221,6 +234,11 @@ export interface BrandSystemPromptOptions {
|
|
|
221
234
|
* {@link SANDBOX_CLOUD_SECTION} instead of {@link SANDBOX_SECTION}.
|
|
222
235
|
*/
|
|
223
236
|
cloud?: boolean;
|
|
237
|
+
/**
|
|
238
|
+
* The machine holds a yak's System values (`placedValues.ts` found the
|
|
239
|
+
* file): {@link PLACED_VALUES_SECTION} is appended. Absent, nothing changes.
|
|
240
|
+
*/
|
|
241
|
+
placedValues?: boolean;
|
|
224
242
|
}
|
|
225
243
|
/**
|
|
226
244
|
* Rebrand pi's assembled system prompt as YAGNI Code's, and optionally inject a
|
|
@@ -253,6 +253,31 @@ export const SANDBOX_CLOUD_SECTION = `${SANDBOX_SECTION_HEADER}\n` +
|
|
|
253
253
|
"and read one with " +
|
|
254
254
|
"`gh api -H 'Accept: application/vnd.github.raw' 'repos/<owner>/<repo>/contents/<path>'`. " +
|
|
255
255
|
"Nothing there is part of your change.";
|
|
256
|
+
export const PLACED_VALUES_SECTION_HEADER = "## The System's values";
|
|
257
|
+
/**
|
|
258
|
+
* What a session on a machine that holds a yak's System values is told
|
|
259
|
+
* (YAG-1209): never read them. Appended only where the extension found the
|
|
260
|
+
* file at activation (`placedValues.ts`), so no other session's prompt
|
|
261
|
+
* changes. The paths are the backend's (`repos/system/needs/placement.ts`),
|
|
262
|
+
* created at run time, never on the image, so the image smoke does not read
|
|
263
|
+
* this section.
|
|
264
|
+
*
|
|
265
|
+
* Content constraints (parity with {@link SANDBOX_SECTION}): must not contain
|
|
266
|
+
* the standalone word "pi", no `- ` bullet lines, no emojis.
|
|
267
|
+
*/
|
|
268
|
+
export const PLACED_VALUES_SECTION = `${PLACED_VALUES_SECTION_HEADER}\n` +
|
|
269
|
+
"\n" +
|
|
270
|
+
"This machine holds the System's provided values, the credentials and test data its " +
|
|
271
|
+
"services run with, in `/run/yagni/secret/env` (linked at `/run/yagni/env`). Never read, " +
|
|
272
|
+
"print, copy or search that file, and never read a running service's environment " +
|
|
273
|
+
"(`/proc/<pid>/environ`, `docker inspect`, `env` or `printenv` run inside a container). " +
|
|
274
|
+
"A command that needs the values sources the file itself " +
|
|
275
|
+
"(`set -a; . /run/yagni/env; set +a; <command>`) and never prints one. Code you write " +
|
|
276
|
+
"reads a credential by its variable name, never as a literal, and no credential goes " +
|
|
277
|
+
"into a file, a commit message or your report. A credential that reaches you in any " +
|
|
278
|
+
"output shows as [REDACTED], and YAGNI does not push a change, commit message or pull " +
|
|
279
|
+
"request that holds one. Test data (a test user, seed records, the app's URL) and a " +
|
|
280
|
+
"public value show as they are, and a test may hold them.";
|
|
256
281
|
/**
|
|
257
282
|
* File-tool steering: prefer the first-class write/edit tools over bash file
|
|
258
283
|
* writes, one write call per file instead of a heredoc batch, and never create
|
|
@@ -475,6 +500,11 @@ export function brandSystemPrompt(original, opts = {}) {
|
|
|
475
500
|
else if (!s.includes(TICKET_IMAGE_RULE_HEADER)) {
|
|
476
501
|
s = `${s}\n\n${TICKET_IMAGE_RULE_HEADER}\n${TICKET_IMAGE_RULE}`;
|
|
477
502
|
}
|
|
503
|
+
// 5b1. YAG-1209: a machine that holds a yak's System values says never to
|
|
504
|
+
// read them, beside what the sandbox has. Same idempotency shape.
|
|
505
|
+
if (opts.placedValues && !s.includes(PLACED_VALUES_SECTION_HEADER)) {
|
|
506
|
+
s = `${s}\n\n${PLACED_VALUES_SECTION}`;
|
|
507
|
+
}
|
|
478
508
|
// 5b2. GitHub operations — a standing directive added alongside
|
|
479
509
|
// the ticket-image rule (same placement, same idempotency shape). It is
|
|
480
510
|
// universal knowledge, not user policy, so it rides the branded prompt
|
|
@@ -27,6 +27,8 @@ import { maybeOfferMiningBeat as defaultMaybeOfferMiningBeat, type MineBeatMarke
|
|
|
27
27
|
export interface RegisterYagniDeps {
|
|
28
28
|
baseUrl?: string;
|
|
29
29
|
getToken?: () => string | undefined;
|
|
30
|
+
/** Where a yak's System places its values (`placedValues.ts`); the backend's paths by default. */
|
|
31
|
+
placedValuePaths?: readonly string[];
|
|
30
32
|
/** The token's ISO expiry, forwarded by the launcher (for the expiry notice). */
|
|
31
33
|
getTokenExpiresAt?: () => string | undefined;
|
|
32
34
|
/** Clock seam for the expiry notice (defaults to Date.now). */
|
package/dist/extension/index.js
CHANGED
|
@@ -48,6 +48,7 @@ import { createGrantCensus } from "./permission/grantCensus.js";
|
|
|
48
48
|
import { runsInSandboxHarness, toolchainBashToolDefinition, toolchainSpawnHookFromEnv, toolchainUserBashOperations, } from "./toolchain/spawnHook.js";
|
|
49
49
|
import { CLOUD_SESSION_ENV } from "./pipeline/cloud.js";
|
|
50
50
|
import { registerCompactionPins } from "./pipeline/compactionPins.js";
|
|
51
|
+
import { registerSessionInbox } from "./pipeline/sessionInbox.js";
|
|
51
52
|
import { registerStageClock } from "./pipeline/stageClock.js";
|
|
52
53
|
import { registerBashDefaultTimeout } from "./toolchain/bashDefaultTimeout.js";
|
|
53
54
|
import { scrubSecrets } from "./pipeline/scrubSecrets.js";
|
|
@@ -62,6 +63,7 @@ import { registerDecisionCommands } from "./decisions.js";
|
|
|
62
63
|
import { makeDecisionCapture } from "./decisionCapture.js";
|
|
63
64
|
import { loadGroundingEnabled } from "./grounding.js";
|
|
64
65
|
import { attributionPromptSection, loadAttributionSettings, } from "./attribution.js";
|
|
66
|
+
import { openPlacedValues, registerPlacedValueRedaction } from "./placedValues.js";
|
|
65
67
|
import { registerAmbientRecall } from "./recall.js";
|
|
66
68
|
import { resilientFetch } from "./resilientFetch.js";
|
|
67
69
|
import { installNonZeroExitReporter, installUncaughtExceptionMonitor, makeCrashReporter, runningUnderTest, } from "./crashReport.js";
|
|
@@ -174,6 +176,10 @@ export async function registerYagni(pi, deps = {}) {
|
|
|
174
176
|
// mode under the harness, where team_read is registered). A local eval
|
|
175
177
|
// compare sets eval mode without the harness, so it keeps the laptop's.
|
|
176
178
|
const sandboxSession = cloudSession || (evalMode && runsInSandboxHarness(env));
|
|
179
|
+
// YAG-1209: a yak's machine holds its System's values in a file this
|
|
180
|
+
// session could read. Opened only where the file is (null everywhere else,
|
|
181
|
+
// where nothing below changes); its handlers register last, at the end.
|
|
182
|
+
const placedValues = openPlacedValues(deps.placedValuePaths);
|
|
177
183
|
// A timed /go stage child refuses every tool once its time is up. Order does
|
|
178
184
|
// not matter: pi runs every tool_call handler until one blocks, and an allow
|
|
179
185
|
// (a result without `block`) never ends the loop, so this block always lands.
|
|
@@ -185,6 +191,10 @@ export async function registerYagni(pi, deps = {}) {
|
|
|
185
191
|
// Not doing list and the Decisions above the fold (YAG-1163). Anywhere else
|
|
186
192
|
// it registers nothing.
|
|
187
193
|
registerCompactionPins(pi, env);
|
|
194
|
+
// A session-lane turn takes what a person sends a yak while it runs, from
|
|
195
|
+
// its execution's inbox, after each tool call (YAG-1210). Anywhere else it
|
|
196
|
+
// registers nothing.
|
|
197
|
+
registerSessionInbox(pi, env);
|
|
188
198
|
// The grounding settings switch (the judgment-loop kill switch): resolved
|
|
189
199
|
// ONCE at boot from the USER-tier config (default on; a malformed config
|
|
190
200
|
// fails soft to on with a sink warn). Eval mode is its own carve-out and
|
|
@@ -1752,6 +1762,7 @@ export async function registerYagni(pi, deps = {}) {
|
|
|
1752
1762
|
fileToolSteering: condensedToolsRegistered,
|
|
1753
1763
|
...(sandboxSession ? { sandbox: true } : {}),
|
|
1754
1764
|
...(cloudSession ? { cloud: true } : {}),
|
|
1765
|
+
...(placedValues ? { placedValues: true } : {}),
|
|
1755
1766
|
}),
|
|
1756
1767
|
});
|
|
1757
1768
|
// Turn-lifecycle WAL: a `turn_start` with no matching `turn_end` is the
|
|
@@ -2209,6 +2220,10 @@ export async function registerYagni(pi, deps = {}) {
|
|
|
2209
2220
|
fields: { toolName: event.toolName, errorClass },
|
|
2210
2221
|
});
|
|
2211
2222
|
});
|
|
2223
|
+
// YAG-1209: last, so the placed values are replaced in whatever every
|
|
2224
|
+
// other tool_result and context handler above added.
|
|
2225
|
+
if (placedValues)
|
|
2226
|
+
registerPlacedValueRedaction(pi, placedValues);
|
|
2212
2227
|
}
|
|
2213
2228
|
export default async function (pi) {
|
|
2214
2229
|
await registerYagni(pi);
|
|
@@ -37,10 +37,6 @@ export interface AddedText {
|
|
|
37
37
|
export declare function scanAddedText(files: readonly AddedText[], sessionSecrets?: readonly string[]): Finding[];
|
|
38
38
|
/** A binary file this run added or changed, other than an image: the host never stores one. */
|
|
39
39
|
export declare function binaryFindings(paths: readonly string[]): Finding[];
|
|
40
|
-
/**
|
|
41
|
-
* A unified diff (`-U0`) as the text each file gained: its `+` lines with
|
|
42
|
-
* their new line numbers. Deleted files and binary sections gain nothing.
|
|
43
|
-
*/
|
|
44
40
|
export declare function addedTextOfDiff(diff: string): AddedText[];
|
|
45
41
|
/** The git seam: argv run in `cwd`, resolving its exit code and output. */
|
|
46
42
|
export type ScanExec = (argv: string[], cwd: string, signal?: AbortSignal) => Promise<{
|
|
@@ -218,17 +218,63 @@ export function binaryFindings(paths) {
|
|
|
218
218
|
* A unified diff (`-U0`) as the text each file gained: its `+` lines with
|
|
219
219
|
* their new line numbers. Deleted files and binary sections gain nothing.
|
|
220
220
|
*/
|
|
221
|
+
const C_ESCAPES = {
|
|
222
|
+
a: 7,
|
|
223
|
+
b: 8,
|
|
224
|
+
t: 9,
|
|
225
|
+
n: 10,
|
|
226
|
+
v: 11,
|
|
227
|
+
f: 12,
|
|
228
|
+
r: 13,
|
|
229
|
+
'"': 34,
|
|
230
|
+
"\\": 92,
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* A patch header's path as the file is named: git C-quotes a name holding a
|
|
234
|
+
* quote, a backslash, a tab or a newline (`"b/a\"b.txt"`) even with
|
|
235
|
+
* `core.quotepath=off`, and may append a tab after an unquoted one.
|
|
236
|
+
*/
|
|
237
|
+
function gitHeaderPath(raw) {
|
|
238
|
+
if (!raw.startsWith('"'))
|
|
239
|
+
return raw.replace(/\t.*$/, "");
|
|
240
|
+
const end = raw.lastIndexOf('"');
|
|
241
|
+
// By code point, so a character outside the BMP (an emoji) stays whole.
|
|
242
|
+
const inner = Array.from(raw.slice(1, end > 0 ? end : undefined));
|
|
243
|
+
const bytes = [];
|
|
244
|
+
for (let at = 0; at < inner.length; at++) {
|
|
245
|
+
const char = inner[at];
|
|
246
|
+
if (char !== "\\") {
|
|
247
|
+
bytes.push(...Buffer.from(char, "utf8"));
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const octal = /^[0-7]{3}$/.exec(inner.slice(at + 1, at + 4).join(""));
|
|
251
|
+
if (octal) {
|
|
252
|
+
bytes.push(Number.parseInt(octal[0], 8));
|
|
253
|
+
at += 3;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
const next = inner[at + 1] ?? "";
|
|
257
|
+
bytes.push(C_ESCAPES[next] ?? next.charCodeAt(0));
|
|
258
|
+
at += 1;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return Buffer.from(bytes).toString("utf8");
|
|
262
|
+
}
|
|
221
263
|
export function addedTextOfDiff(diff) {
|
|
222
264
|
const files = [];
|
|
223
265
|
let current;
|
|
224
266
|
let next = 0;
|
|
267
|
+
// A file's header comes before its first hunk: inside one, a line that
|
|
268
|
+
// reads `+++ ` is an added line that starts `++ `, never a header.
|
|
269
|
+
let inHunk = false;
|
|
225
270
|
for (const raw of diff.split("\n")) {
|
|
226
271
|
if (raw.startsWith("diff --git ")) {
|
|
227
272
|
current = undefined;
|
|
273
|
+
inHunk = false;
|
|
228
274
|
continue;
|
|
229
275
|
}
|
|
230
|
-
if (raw.startsWith("+++ ")) {
|
|
231
|
-
const path = raw.slice(4)
|
|
276
|
+
if (!inHunk && raw.startsWith("+++ ")) {
|
|
277
|
+
const path = gitHeaderPath(raw.slice(4));
|
|
232
278
|
current = path === "/dev/null" ? undefined : { path: path.replace(/^b\//, ""), lines: [] };
|
|
233
279
|
if (current)
|
|
234
280
|
files.push(current);
|
|
@@ -237,9 +283,10 @@ export function addedTextOfDiff(diff) {
|
|
|
237
283
|
const hunk = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(raw);
|
|
238
284
|
if (hunk) {
|
|
239
285
|
next = Number(hunk[1]);
|
|
286
|
+
inHunk = true;
|
|
240
287
|
continue;
|
|
241
288
|
}
|
|
242
|
-
if (current && raw.startsWith("+")) {
|
|
289
|
+
if (current && inHunk && raw.startsWith("+")) {
|
|
243
290
|
current.lines.push({ line: next, text: raw.slice(1) });
|
|
244
291
|
next += 1;
|
|
245
292
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A System secret in the session's own change, taken out by the session
|
|
3
|
+
* before it ends (YAG-1209). A yak's machine holds its System's values
|
|
4
|
+
* (`../placedValues.ts`), and the host never pushes a change that holds one
|
|
5
|
+
* of the secrets among them: that refusal hands the push to a person. So
|
|
6
|
+
* before a writing turn ends, its change is read for each secret's value. One
|
|
7
|
+
* there is named to the model by variable and place, never by value, and the
|
|
8
|
+
* model is asked once, in the same session, to read it from the environment
|
|
9
|
+
* instead and finish. A secret still there after that is left for the host's
|
|
10
|
+
* refusal, the backstop, and the turn's result says so by name.
|
|
11
|
+
*
|
|
12
|
+
* What is read: the change's added lines and new files (the tree's dirt from
|
|
13
|
+
* before the turn left out, as `changeScan.ts` leaves it), every path it
|
|
14
|
+
* touched, each commit's own patch past the turn's start (a value one commit
|
|
15
|
+
* added and a later one took out is still pushed), and their messages.
|
|
16
|
+
*
|
|
17
|
+
* Only exact text is found, as on the host: a value the session encoded
|
|
18
|
+
* first gets past both.
|
|
19
|
+
*/
|
|
20
|
+
import { type PlacedSecret, type PlacedValues } from "../placedValues.js";
|
|
21
|
+
import type { StageResult } from "./types.js";
|
|
22
|
+
import type { WorktreeExec } from "./worktree.js";
|
|
23
|
+
/** One secret the change holds, and where; never its value. */
|
|
24
|
+
export interface PlacedSecretHit {
|
|
25
|
+
name: string;
|
|
26
|
+
/** The change's files that hold it in their text or their path, each path with any value marked. */
|
|
27
|
+
files: string[];
|
|
28
|
+
/** A commit past the start holds it, whether or not the change still does: the branch needs rewriting. */
|
|
29
|
+
committed: boolean;
|
|
30
|
+
/** A commit message holds it. */
|
|
31
|
+
message: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface PlacedSecretScanOpts {
|
|
34
|
+
exec: WorktreeExec;
|
|
35
|
+
/** The tree's dirt from before the turn (`git status` paths, a folder ending in `/`): not the turn's. */
|
|
36
|
+
skip?: readonly string[];
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
readFile?: (path: string) => Buffer;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Each secret the change past `base` holds, or null when git could not say
|
|
42
|
+
* what changed (the read that failed is logged). The value never leaves this
|
|
43
|
+
* function.
|
|
44
|
+
*/
|
|
45
|
+
export declare function placedSecretsInChange(cwd: string, base: string, secrets: readonly PlacedSecret[], opts: PlacedSecretScanOpts): Promise<PlacedSecretHit[] | null>;
|
|
46
|
+
/** The ask: each secret by name and place, what to do instead, and to finish as before. */
|
|
47
|
+
export declare function placedSecretAsk(hits: readonly PlacedSecretHit[], base: string): string;
|
|
48
|
+
export interface PlacedSecretHeal {
|
|
49
|
+
/** The turn's last run: the ask's, when it ran to its end. */
|
|
50
|
+
run: StageResult;
|
|
51
|
+
/** The ask's run, when there was one. */
|
|
52
|
+
asked: StageResult[];
|
|
53
|
+
/** For the turn's result: a secret the change still holds, by name, or a scan that could not read it. */
|
|
54
|
+
note: string | null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Reads a writing turn's change for the System's secrets and, when it holds
|
|
58
|
+
* one, asks the model once to take it out and finish. Not asked of a turn
|
|
59
|
+
* that was stopped, ran out of time or ended in an error, nor on a machine
|
|
60
|
+
* with no secret placed.
|
|
61
|
+
*/
|
|
62
|
+
export declare function healPlacedSecrets(run: StageResult, turn: (message: string) => Promise<StageResult>, opts: PlacedSecretScanOpts & {
|
|
63
|
+
cwd: string;
|
|
64
|
+
base: string | null;
|
|
65
|
+
store: PlacedValues | null;
|
|
66
|
+
}): Promise<PlacedSecretHeal>;
|
|
67
|
+
//# sourceMappingURL=placedValueHeal.d.ts.map
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A System secret in the session's own change, taken out by the session
|
|
3
|
+
* before it ends (YAG-1209). A yak's machine holds its System's values
|
|
4
|
+
* (`../placedValues.ts`), and the host never pushes a change that holds one
|
|
5
|
+
* of the secrets among them: that refusal hands the push to a person. So
|
|
6
|
+
* before a writing turn ends, its change is read for each secret's value. One
|
|
7
|
+
* there is named to the model by variable and place, never by value, and the
|
|
8
|
+
* model is asked once, in the same session, to read it from the environment
|
|
9
|
+
* instead and finish. A secret still there after that is left for the host's
|
|
10
|
+
* refusal, the backstop, and the turn's result says so by name.
|
|
11
|
+
*
|
|
12
|
+
* What is read: the change's added lines and new files (the tree's dirt from
|
|
13
|
+
* before the turn left out, as `changeScan.ts` leaves it), every path it
|
|
14
|
+
* touched, each commit's own patch past the turn's start (a value one commit
|
|
15
|
+
* added and a later one took out is still pushed), and their messages.
|
|
16
|
+
*
|
|
17
|
+
* Only exact text is found, as on the host: a value the session encoded
|
|
18
|
+
* first gets past both.
|
|
19
|
+
*/
|
|
20
|
+
import { readFileSync } from "node:fs";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import { logEvent } from "../errorSink.js";
|
|
23
|
+
import { PLACED_VALUE_MARK } from "../placedValues.js";
|
|
24
|
+
import { addedTextOfDiff } from "./changeScan.js";
|
|
25
|
+
/** How much of one new file is read: a value sits in source, not past the first megabyte. */
|
|
26
|
+
const MAX_READ_BYTES = 1024 * 1024;
|
|
27
|
+
/** Each named git read's output, or the first that failed, by name and exit code. */
|
|
28
|
+
async function readAll(reads) {
|
|
29
|
+
const names = Object.keys(reads);
|
|
30
|
+
const results = await Promise.all(names.map((name) => reads[name]));
|
|
31
|
+
const out = {};
|
|
32
|
+
for (const [at, name] of names.entries()) {
|
|
33
|
+
const result = results[at];
|
|
34
|
+
if (result.code !== 0)
|
|
35
|
+
return { failed: name, code: result.code };
|
|
36
|
+
out[name] = result.output;
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Each secret the change past `base` holds, or null when git could not say
|
|
42
|
+
* what changed (the read that failed is logged). The value never leaves this
|
|
43
|
+
* function.
|
|
44
|
+
*/
|
|
45
|
+
export async function placedSecretsInChange(cwd, base, secrets, opts) {
|
|
46
|
+
if (secrets.length === 0)
|
|
47
|
+
return [];
|
|
48
|
+
const skipFiles = new Set((opts.skip ?? []).filter((path) => !path.endsWith("/")));
|
|
49
|
+
const skipDirs = (opts.skip ?? []).filter((path) => path.endsWith("/"));
|
|
50
|
+
const skipped = (path) => skipFiles.has(path) || skipDirs.some((dir) => path.startsWith(dir));
|
|
51
|
+
const git = (args) => opts.exec(["git", "-c", "core.quotepath=off", ...args], cwd, opts.signal);
|
|
52
|
+
const range = `${base}..HEAD`;
|
|
53
|
+
// Each commit's own patch, as the host's push reads it: a merge's by what
|
|
54
|
+
// it changed beyond merging (`remerge`), and one of three parents or more,
|
|
55
|
+
// which `remerge` shows nothing for, against its first parent.
|
|
56
|
+
const patch = ["--format=", "-p", "-U0", "--text", "--no-color", "--no-ext-diff"];
|
|
57
|
+
const remerge = "--diff-merges=remerge";
|
|
58
|
+
const octopus = ["--min-parents=3", "--diff-merges=first-parent"];
|
|
59
|
+
const read = await readAll({
|
|
60
|
+
diff: git(["diff", base, "-U0", "--no-color", "--no-renames", "--no-ext-diff", "--text"]),
|
|
61
|
+
changedPaths: git(["diff", base, "--name-only", "-z", "--no-renames"]),
|
|
62
|
+
others: git(["ls-files", "--others", "--exclude-standard", "-z"]),
|
|
63
|
+
merged: git(["log", remerge, ...patch, range]),
|
|
64
|
+
octopusMerged: git(["log", ...octopus, ...patch, range]),
|
|
65
|
+
mergedPaths: git(["log", remerge, "--format=", "--name-only", "-z", range]),
|
|
66
|
+
octopusPaths: git(["log", ...octopus, "--format=", "--name-only", "-z", range]),
|
|
67
|
+
messages: git(["log", "--format=%B%x00", range]),
|
|
68
|
+
});
|
|
69
|
+
if ("failed" in read) {
|
|
70
|
+
logEvent({
|
|
71
|
+
source: "placed-values",
|
|
72
|
+
level: "warn",
|
|
73
|
+
event: "heal_scan_unread",
|
|
74
|
+
fields: { read: read.failed, exitCode: read.code },
|
|
75
|
+
});
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const { diff, changedPaths, others, messages } = read;
|
|
79
|
+
const history = `${read.merged}\n${read.octopusMerged}`;
|
|
80
|
+
const historyPaths = `${read.mergedPaths}\0${read.octopusPaths}`;
|
|
81
|
+
const split = (text) => text.split("\0").filter(Boolean);
|
|
82
|
+
const texts = addedTextOfDiff(diff)
|
|
83
|
+
.filter((file) => !skipped(file.path))
|
|
84
|
+
.map((file) => ({ path: file.path, text: file.lines.map((line) => line.text).join("\n") }));
|
|
85
|
+
const readFile = opts.readFile ?? ((path) => readFileSync(path));
|
|
86
|
+
for (const path of split(others)) {
|
|
87
|
+
if (skipped(path))
|
|
88
|
+
continue;
|
|
89
|
+
try {
|
|
90
|
+
texts.push({
|
|
91
|
+
path,
|
|
92
|
+
text: readFile(join(cwd, path)).subarray(0, MAX_READ_BYTES).toString("utf8"),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// A file gone since git listed it holds nothing to push.
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const paths = [...split(changedPaths), ...split(others)].filter((path) => !skipped(path));
|
|
100
|
+
const historyText = addedTextOfDiff(history)
|
|
101
|
+
.map((file) => file.lines.map((line) => line.text).join("\n"))
|
|
102
|
+
.join("\n");
|
|
103
|
+
// A path is shown with every secret out of it, the longest first, never
|
|
104
|
+
// only the one it is named for.
|
|
105
|
+
const longestFirst = [...secrets].sort((a, b) => b.value.length - a.value.length);
|
|
106
|
+
const shown = (path) => longestFirst.reduce((out, { value }) => out.split(value).join(PLACED_VALUE_MARK), path);
|
|
107
|
+
const hits = [];
|
|
108
|
+
const named = new Set();
|
|
109
|
+
for (const { name, value } of secrets) {
|
|
110
|
+
if (named.has(name))
|
|
111
|
+
continue;
|
|
112
|
+
const files = [
|
|
113
|
+
...new Set([
|
|
114
|
+
...texts.filter((file) => file.text.includes(value)).map((file) => file.path),
|
|
115
|
+
...paths.filter((path) => path.includes(value)),
|
|
116
|
+
]),
|
|
117
|
+
].map(shown);
|
|
118
|
+
// A commit that holds it is pushed even once the tree no longer does.
|
|
119
|
+
const committed = historyText.includes(value) || split(historyPaths).some((path) => path.includes(value));
|
|
120
|
+
const message = messages.includes(value);
|
|
121
|
+
if (files.length === 0 && !committed && !message)
|
|
122
|
+
continue;
|
|
123
|
+
named.add(name);
|
|
124
|
+
hits.push({ name, files, committed, message });
|
|
125
|
+
}
|
|
126
|
+
return hits;
|
|
127
|
+
}
|
|
128
|
+
/** `a`, `a and b`, `a, b and c`. */
|
|
129
|
+
function listed(items) {
|
|
130
|
+
return items.length < 2
|
|
131
|
+
? (items[0] ?? "")
|
|
132
|
+
: `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
|
|
133
|
+
}
|
|
134
|
+
/** The ask: each secret by name and place, what to do instead, and to finish as before. */
|
|
135
|
+
export function placedSecretAsk(hits, base) {
|
|
136
|
+
const rewrite = hits.some((hit) => hit.committed || hit.message);
|
|
137
|
+
return [
|
|
138
|
+
"Your change holds the value of a System credential, and YAGNI never pushes a change that holds one:",
|
|
139
|
+
...hits.map((hit) => {
|
|
140
|
+
const places = [
|
|
141
|
+
...hit.files.map((file) => `\`${file}\``),
|
|
142
|
+
...(hit.committed
|
|
143
|
+
? [`${hit.files.length ? "a" : "an earlier"} commit on this branch`]
|
|
144
|
+
: []),
|
|
145
|
+
...(hit.message ? ["a commit message"] : []),
|
|
146
|
+
];
|
|
147
|
+
return `- ${hit.name}, in ${listed(places)}`;
|
|
148
|
+
}),
|
|
149
|
+
"",
|
|
150
|
+
"Take each one out. Where the code needs it, read it from the environment instead " +
|
|
151
|
+
`(\`process.env.${hits[0].name}\`, \`os.environ["${hits[0].name}"]\`), and in a test use an obvious fake. ` +
|
|
152
|
+
`You cannot see the value: what you read shows it as ${PLACED_VALUE_MARK}, so find the line by what is ` +
|
|
153
|
+
"around it, or write the file again whole. Never read /run/yagni/env, or print a value, to find it.",
|
|
154
|
+
rewrite
|
|
155
|
+
? `A commit on this branch holds it too, and every commit is pushed: rewrite this branch's commits so that none of them, and no message, holds it (for example \`git reset --soft ${base}\` once the files are fixed, then commit again).`
|
|
156
|
+
: "Then commit.",
|
|
157
|
+
"Then end your turn as before, with your report.",
|
|
158
|
+
].join("\n");
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Reads a writing turn's change for the System's secrets and, when it holds
|
|
162
|
+
* one, asks the model once to take it out and finish. Not asked of a turn
|
|
163
|
+
* that was stopped, ran out of time or ended in an error, nor on a machine
|
|
164
|
+
* with no secret placed.
|
|
165
|
+
*/
|
|
166
|
+
export async function healPlacedSecrets(run, turn, opts) {
|
|
167
|
+
const unchanged = { run, asked: [], note: null };
|
|
168
|
+
const { store, base } = opts;
|
|
169
|
+
if (!store || !base || opts.signal?.aborted || run.timedOut || run.exitCode !== 0) {
|
|
170
|
+
return unchanged;
|
|
171
|
+
}
|
|
172
|
+
const scan = () => placedSecretsInChange(opts.cwd, base, store.secrets(), opts).catch(() => null);
|
|
173
|
+
const unread = "The change could not be read for the System's credentials before the turn ended; the host still checks its push.";
|
|
174
|
+
const hits = await scan();
|
|
175
|
+
if (hits === null)
|
|
176
|
+
return { ...unchanged, note: unread };
|
|
177
|
+
if (hits.length === 0)
|
|
178
|
+
return unchanged;
|
|
179
|
+
const again = await turn(placedSecretAsk(hits, base));
|
|
180
|
+
const left = await scan();
|
|
181
|
+
return {
|
|
182
|
+
run: again.exitCode === 0 ? again : run,
|
|
183
|
+
asked: [again],
|
|
184
|
+
note: left === null ? unread : stillThereNote(left),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** The result's note for secrets still in the change after the ask, by name; null when none is. */
|
|
188
|
+
function stillThereNote(left) {
|
|
189
|
+
if (left.length === 0)
|
|
190
|
+
return null;
|
|
191
|
+
const names = left.map((hit) => hit.name);
|
|
192
|
+
const them = names.length > 1 ? "them" : "it";
|
|
193
|
+
return `The change still holds the System's ${listed(names)} after one ask to take ${them} out: YAGNI will not push it, and a person is asked.`;
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=placedValueHeal.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
export { SESSION_INBOX_DIR_ENV, sessionInboxDir } from "./sessionLane.js";
|
|
3
|
+
/** A message the host wrote: `<id>.json`. */
|
|
4
|
+
export declare const INBOX_MESSAGE_SUFFIX = ".json";
|
|
5
|
+
/** The receipt this turn writes once pi put the message in the conversation: `<id>.received`. */
|
|
6
|
+
export declare const INBOX_RECEIPT_SUFFIX = ".received";
|
|
7
|
+
/** The most one message file may weigh; a larger one is never read, and goes the host's other way. */
|
|
8
|
+
export declare const MAX_INBOX_FILE_BYTES: number;
|
|
9
|
+
/** The most of a message's text one steer carries. */
|
|
10
|
+
export declare const MAX_STEER_CHARS = 16000;
|
|
11
|
+
/** The most messages one check hands to pi: the oldest first. */
|
|
12
|
+
export declare const MAX_INBOX_FILES_PER_CHECK = 20;
|
|
13
|
+
/**
|
|
14
|
+
* The most message files one check reads to find the oldest: more than the
|
|
15
|
+
* host ever gives one execution's inbox (50, `MAX_INBOX_MESSAGES_PER_EXECUTION`
|
|
16
|
+
* in the backend's `yaks/inbox.ts`), so messages reach pi in the order they
|
|
17
|
+
* were written whatever their file names.
|
|
18
|
+
*/
|
|
19
|
+
export declare const MAX_INBOX_FILES_READ = 64;
|
|
20
|
+
/** Whether a string is a message id the inbox names files by. */
|
|
21
|
+
export declare function isInboxMessageId(value: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The first line of a message's steer, naming it: what the receipt matches
|
|
24
|
+
* the message pi puts in the conversation by, so a person's words that quote
|
|
25
|
+
* another message cannot answer for it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function steerHeader(id: string): string;
|
|
28
|
+
/** One message as the host wrote it. */
|
|
29
|
+
export interface InboxMessage {
|
|
30
|
+
id: string;
|
|
31
|
+
/** The words as the host wrapped them for the session, untrusted content marked. */
|
|
32
|
+
text: string;
|
|
33
|
+
/** When the person wrote it (epoch ms): the order messages are handed over in. */
|
|
34
|
+
at: number;
|
|
35
|
+
}
|
|
36
|
+
/** A message file's text read as a message named `id`, or null when it is not one. Pure. */
|
|
37
|
+
export declare function parseInboxMessage(id: string, raw: string): InboxMessage | null;
|
|
38
|
+
/** The steer a message is handed over as: its header, then its words, capped. Pure. */
|
|
39
|
+
export declare function steerText(message: InboxMessage): string;
|
|
40
|
+
/** The file system the inbox reads and writes; a test's own. */
|
|
41
|
+
export interface InboxFs {
|
|
42
|
+
list(dir: string): string[];
|
|
43
|
+
size(path: string): number;
|
|
44
|
+
read(path: string): string;
|
|
45
|
+
exists(path: string): boolean;
|
|
46
|
+
/** Write `text` to `path` whole: written beside it, then renamed over it. */
|
|
47
|
+
writeWhole(path: string, text: string): void;
|
|
48
|
+
}
|
|
49
|
+
export declare const nodeInboxFs: InboxFs;
|
|
50
|
+
/** What a registered inbox does, for the test that drives it without pi. */
|
|
51
|
+
export interface SessionInbox {
|
|
52
|
+
/** Read the folder and hand each new message to pi; returns the ids handed over. */
|
|
53
|
+
check(idle: boolean): string[];
|
|
54
|
+
/** A user message pi put in the conversation: the receipt, when it is one of ours. */
|
|
55
|
+
delivered(message: {
|
|
56
|
+
role?: unknown;
|
|
57
|
+
content?: unknown;
|
|
58
|
+
} | undefined): string | null;
|
|
59
|
+
}
|
|
60
|
+
/** The inbox's logic over its folder, its file system and pi's send. */
|
|
61
|
+
export declare function createSessionInbox(dir: string, send: (text: string) => void, fs?: InboxFs, now?: () => number): SessionInbox;
|
|
62
|
+
/**
|
|
63
|
+
* On a session-lane turn whose inbox the session lane named, messages in it
|
|
64
|
+
* reach the session after each tool call. Registered nowhere else.
|
|
65
|
+
*/
|
|
66
|
+
export declare function registerSessionInbox(pi: Pick<ExtensionAPI, "on" | "sendUserMessage">, env?: NodeJS.ProcessEnv, fs?: InboxFs): boolean;
|
|
67
|
+
//# sourceMappingURL=sessionInbox.d.ts.map
|