@yagni-app/code-staging 1.2.15-staging.2661.1 → 1.2.15-staging.2666.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.
@@ -29,12 +29,23 @@ export interface AddedText {
29
29
  text: string;
30
30
  }>;
31
31
  }
32
+ /** A scan hit's kind in words: `github_token` is "a GitHub token". */
33
+ export declare function describeKind(kind: string): string;
34
+ /** One scan hit: where it is and what kind, never the value. */
35
+ export interface ChangeScanHit {
36
+ file: string;
37
+ /** Absent for a binary file. */
38
+ line?: number;
39
+ kind: string;
40
+ }
32
41
  /**
33
42
  * The stop-class secret findings in what this run added, one per kind and
34
43
  * line. `sessionSecrets` are this session's own credentials (the run token),
35
44
  * matched by value and never echoed.
36
45
  */
37
46
  export declare function scanAddedText(files: readonly AddedText[], sessionSecrets?: readonly string[]): Finding[];
47
+ /** {@link scanAddedText}'s hits, by place and kind. */
48
+ export declare function addedTextHits(files: readonly AddedText[], sessionSecrets?: readonly string[]): ChangeScanHit[];
38
49
  /** A binary file this run added or changed, other than an image: the host never stores one. */
39
50
  export declare function binaryFindings(paths: readonly string[]): Finding[];
40
51
  export declare function addedTextOfDiff(diff: string): AddedText[];
@@ -62,4 +73,6 @@ export interface ChangeScanOpts {
62
73
  * notes the scan did not run.
63
74
  */
64
75
  export declare function scanChange(cwd: string, opts: ChangeScanOpts, skip?: readonly string[], signal?: AbortSignal): Promise<Finding[] | null>;
76
+ /** {@link scanChange}'s hits, by place and kind: a binary file is kind `binary_file`. */
77
+ export declare function scanChangeHits(cwd: string, opts: ChangeScanOpts, skip?: readonly string[], signal?: AbortSignal): Promise<ChangeScanHit[] | null>;
65
78
  //# sourceMappingURL=changeScan.d.ts.map
@@ -129,15 +129,20 @@ const WORDS = {
129
129
  authorization_token: "a live authorization header",
130
130
  high_entropy_secret: "a random value assigned to a credential's name",
131
131
  session_credential: "a credential from this session",
132
+ binary_file: "a binary file",
132
133
  };
134
+ /** A scan hit's kind in words: `github_token` is "a GitHub token". */
135
+ export function describeKind(kind) {
136
+ return WORDS[kind] ?? kind.replace(/_/g, " ");
137
+ }
133
138
  function finding(path, line, kind) {
134
139
  return {
135
140
  severity: "critical",
136
141
  lens: "does_it_hold",
137
142
  file: path,
138
143
  line,
139
- message: `secret scan: this adds ${WORDS[kind] ?? kind.replace(/_/g, " ")}, and YAGNI will not publish a change that holds one. ` +
140
- "Take it out (read it from the environment or a secret store instead). A test value must not look like a real credential: use an obvious fake such as `test-token`.",
144
+ message: `secret scan: this adds ${describeKind(kind)}, and YAGNI will not publish a change that holds one. ` +
145
+ "Take it out (read it from the environment or a secret store instead). A test value must not look like a real credential: build it when the test runs, or use an obvious fake such as `test-token`.",
141
146
  };
142
147
  }
143
148
  /**
@@ -146,6 +151,10 @@ function finding(path, line, kind) {
146
151
  * matched by value and never echoed.
147
152
  */
148
153
  export function scanAddedText(files, sessionSecrets = []) {
154
+ return addedTextHits(files, sessionSecrets).map((hit) => finding(hit.file, hit.line, hit.kind));
155
+ }
156
+ /** {@link scanAddedText}'s hits, by place and kind. */
157
+ export function addedTextHits(files, sessionSecrets = []) {
149
158
  const out = [];
150
159
  const seen = new Set();
151
160
  const secrets = sessionSecrets.filter((secret) => secret.length >= 16);
@@ -169,7 +178,7 @@ export function scanAddedText(files, sessionSecrets = []) {
169
178
  if (seen.has(key))
170
179
  return;
171
180
  seen.add(key);
172
- out.push(finding(file.path, line, kind));
181
+ out.push({ file: file.path, line, kind });
173
182
  };
174
183
  for (const [kind, pattern] of PROVIDER_SECRET_PATTERNS) {
175
184
  const index = text.search(pattern);
@@ -306,6 +315,19 @@ const MAX_SCANNED_FILE_BYTES = 1024 * 1024;
306
315
  * notes the scan did not run.
307
316
  */
308
317
  export async function scanChange(cwd, opts, skip = [], signal) {
318
+ const hits = await scanChangeHits(cwd, opts, skip, signal);
319
+ if (hits === null)
320
+ return null;
321
+ const binary = hits.filter((hit) => hit.kind === "binary_file").map((hit) => hit.file);
322
+ return [
323
+ ...binaryFindings(binary),
324
+ ...hits
325
+ .filter((hit) => hit.kind !== "binary_file")
326
+ .map((hit) => finding(hit.file, hit.line, hit.kind)),
327
+ ];
328
+ }
329
+ /** {@link scanChange}'s hits, by place and kind: a binary file is kind `binary_file`. */
330
+ export async function scanChangeHits(cwd, opts, skip = [], signal) {
309
331
  // `git status --porcelain` lists an untracked folder as `dir/`, so a skip
310
332
  // entry ending in `/` covers every file under it (FINISH leaves it out of
311
333
  // the commit the same way).
@@ -351,6 +373,9 @@ export async function scanChange(cwd, opts, skip = [], signal) {
351
373
  .map((text, index) => ({ line: index + 1, text }));
352
374
  added.push({ path, lines });
353
375
  }
354
- return [...binaryFindings(binary), ...scanAddedText(added, opts.sessionSecrets ?? [])];
376
+ return [
377
+ ...binary.filter((path) => !isImagePath(path)).map((file) => ({ file, kind: "binary_file" })),
378
+ ...addedTextHits(added, opts.sessionSecrets ?? []),
379
+ ];
355
380
  }
356
381
  //# sourceMappingURL=changeScan.js.map
@@ -16,8 +16,15 @@
16
16
  *
17
17
  * Only exact text is found, as on the host: a value the session encoded
18
18
  * first gets past both.
19
+ *
20
+ * The same heal reads the change with the finish's own secret and binary
21
+ * scan (`changeScan.ts`), which otherwise runs only after the session ended
22
+ * and fails the run: a credential-shaped value (a test's fake token, a line
23
+ * a formatter reflowed) is named by place and kind, and asked about in the
24
+ * same one message as a System secret.
19
25
  */
20
26
  import { type PlacedSecret, type PlacedValues } from "../placedValues.js";
27
+ import { type ChangeScanHit } from "./changeScan.js";
21
28
  import type { StageResult } from "./types.js";
22
29
  import type { WorktreeExec } from "./worktree.js";
23
30
  /** One secret the change holds, and where; never its value. */
@@ -78,7 +85,24 @@ export interface PlacedSecretScanOpts {
78
85
  * function.
79
86
  */
80
87
  export declare function placedSecretsInChange(cwd: string, base: string, secrets: readonly PlacedSecret[], opts: PlacedSecretScanOpts): Promise<PlacedSecretHit[] | null>;
81
- /** The ask: each secret by name and place, what to do instead, and to finish as before. */
88
+ /** A secret-scan hit in the change, and where its repository is. */
89
+ export interface ScanHit extends ChangeScanHit {
90
+ /** A commit past the start adds a hit in that repository: the branch needs rewriting. */
91
+ committed: boolean;
92
+ /** Another repository of a yak's System; absent: the session's own. */
93
+ elsewhere?: {
94
+ repository: string;
95
+ dir: string;
96
+ base: string;
97
+ };
98
+ }
99
+ /**
100
+ * The one message for a turn's hits, both kinds: each by place (a System
101
+ * secret by name, a scan hit by kind), what to do instead, the commits to
102
+ * rewrite when one holds it, and to finish as before.
103
+ */
104
+ export declare function healAsk(placed: readonly PlacedSecretHit[], scanned: readonly ScanHit[], base: string): string;
105
+ /** The ask for System secrets alone. */
82
106
  export declare function placedSecretAsk(hits: readonly PlacedSecretHit[], base: string): string;
83
107
  export interface PlacedSecretHeal {
84
108
  /** The turn's last run: the ask's, when it ran to its end. */
@@ -89,10 +113,12 @@ export interface PlacedSecretHeal {
89
113
  note: string | null;
90
114
  }
91
115
  /**
92
- * Reads a writing turn's change for the System's secrets and, when it holds
93
- * one, asks the model once to take it out and finish. Not asked of a turn
94
- * that was stopped, ran out of time or ended in an error, nor on a machine
95
- * with no secret placed.
116
+ * Reads a writing turn's change for the System's secrets and with the
117
+ * secret scan and, when it holds one, asks the model once to take it out and
118
+ * finish. Not asked of a turn that was stopped, ran out of time or ended in
119
+ * an error, nor with under {@link MIN_REVIEW_ROUND_MS} of the run left (a
120
+ * note says so). The System's secrets are read only on a machine with one
121
+ * placed.
96
122
  */
97
123
  export declare function healPlacedSecrets(run: StageResult, turn: (message: string) => Promise<StageResult>, opts: PlacedSecretScanOpts & {
98
124
  cwd: string;
@@ -100,5 +126,9 @@ export declare function healPlacedSecrets(run: StageResult, turn: (message: stri
100
126
  store: PlacedValues | null;
101
127
  /** A yak's System's other repositories the session may change in place (YAG-1211), each read as its own. */
102
128
  others?: readonly OtherRepositoryScan[];
129
+ /** This session's own credentials, which the secret scan matches by value. */
130
+ sessionSecrets?: readonly string[];
131
+ /** The run's time left; under {@link MIN_REVIEW_ROUND_MS} no ask is sent. */
132
+ timeLeftMs?: () => number | undefined;
103
133
  }): Promise<PlacedSecretHeal>;
104
134
  //# sourceMappingURL=placedValueHeal.d.ts.map
@@ -16,12 +16,19 @@
16
16
  *
17
17
  * Only exact text is found, as on the host: a value the session encoded
18
18
  * first gets past both.
19
+ *
20
+ * The same heal reads the change with the finish's own secret and binary
21
+ * scan (`changeScan.ts`), which otherwise runs only after the session ended
22
+ * and fails the run: a credential-shaped value (a test's fake token, a line
23
+ * a formatter reflowed) is named by place and kind, and asked about in the
24
+ * same one message as a System secret.
19
25
  */
20
26
  import { readFileSync } from "node:fs";
21
27
  import { join } from "node:path";
22
28
  import { logEvent } from "../errorSink.js";
23
29
  import { PLACED_VALUE_MARK } from "../placedValues.js";
24
- import { addedTextOfDiff } from "./changeScan.js";
30
+ import { addedTextHits, addedTextOfDiff, describeKind, scanChangeHits, } from "./changeScan.js";
31
+ import { MIN_REVIEW_ROUND_MS } from "./planReview.js";
25
32
  const SHA = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
26
33
  /** At most this many commits of its own a checkout is read for, as the host reads it. */
27
34
  const MAX_OWN_COMMITS = 500;
@@ -172,17 +179,13 @@ function listed(items) {
172
179
  ? (items[0] ?? "")
173
180
  : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
174
181
  }
175
- /** The ask: each secret by name and place, what to do instead, and to finish as before. */
176
- export function placedSecretAsk(hits, base) {
177
- const rewrite = hits.some((hit) => hit.committed || hit.message);
178
- // Each repository whose commits hold one, by the command that rewrites them there.
179
- const resets = [
180
- ...new Set(hits
181
- .filter((hit) => hit.committed || hit.message)
182
- .map((hit) => hit.elsewhere
183
- ? `\`git -C ${hit.elsewhere.dir} reset --soft ${hit.elsewhere.base}\` in ${hit.elsewhere.repository}`
184
- : `\`git reset --soft ${base}\``)),
185
- ];
182
+ /** Where a hit's repository is, for the ask: nothing for the session's own. */
183
+ const whereElse = (elsewhere) => elsewhere ? ` in ${elsewhere.repository} (\`${elsewhere.dir}\`)` : "";
184
+ /** The command that rewrites a repository's commits since the turn's start. */
185
+ const resetOf = (elsewhere, base) => elsewhere
186
+ ? `\`git -C ${elsewhere.dir} reset --soft ${elsewhere.base}\` in ${elsewhere.repository}`
187
+ : `\`git reset --soft ${base}\``;
188
+ function placedLines(hits) {
186
189
  return [
187
190
  "Your change holds the value of a System credential, and YAGNI never pushes a change that holds one:",
188
191
  ...hits.map((hit) => {
@@ -193,71 +196,217 @@ export function placedSecretAsk(hits, base) {
193
196
  : []),
194
197
  ...(hit.message ? ["a commit message"] : []),
195
198
  ];
196
- return `- ${hit.name}, in ${listed(places)}${hit.elsewhere ? ` in ${hit.elsewhere.repository} (\`${hit.elsewhere.dir}\`)` : ""}`;
199
+ return `- ${hit.name}, in ${listed(places)}${whereElse(hit.elsewhere)}`;
197
200
  }),
198
201
  "",
199
202
  "Take each one out. Where the code needs it, read it from the environment instead " +
200
203
  `(\`process.env.${hits[0].name}\`, \`os.environ["${hits[0].name}"]\`), and in a test use an obvious fake. ` +
201
204
  `You cannot see the value: what you read shows it as ${PLACED_VALUE_MARK}, so find the line by what is ` +
202
205
  "around it, or write the file again whole. Never read /run/yagni/env, or print a value, to find it.",
203
- rewrite
204
- ? `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 ${listed(resets)} once the files are fixed, then commit again).`
206
+ ];
207
+ }
208
+ function scanLines(hits) {
209
+ const binary = hits.some((hit) => hit.kind === "binary_file");
210
+ const credential = hits.some((hit) => hit.kind !== "binary_file");
211
+ return [
212
+ "The secret scan found what looks like a credential or a binary file in your change, and the change does not ship with one. Each is named by place and kind, never by value:",
213
+ ...hits.map((hit) => `- \`${hit.file}${hit.line === undefined ? "" : `:${hit.line}`}\`, ${describeKind(hit.kind)}${whereElse(hit.elsewhere)}`),
214
+ "",
215
+ "Take each one out:",
216
+ ...(credential
217
+ ? [
218
+ '- A test or fixture value: build it when the test runs (`"ghs_" + "a".repeat(36)`), or use an obvious fake with no credential prefix. A literal with the prefix and 20 or more letters or digits still matches.',
219
+ "- A literal already in the repository that this turn moved or reformatted: put the line back as it was.",
220
+ "- A real value in code: read it from the environment instead.",
221
+ ]
222
+ : []),
223
+ ...(binary ? ["- A binary file: leave it out, or produce it in the build."] : []),
224
+ "A `gitleaks:allow` comment does not count for YAGNI: the value itself has to go.",
225
+ ];
226
+ }
227
+ /**
228
+ * The one message for a turn's hits, both kinds: each by place (a System
229
+ * secret by name, a scan hit by kind), what to do instead, the commits to
230
+ * rewrite when one holds it, and to finish as before.
231
+ */
232
+ export function healAsk(placed, scanned, base) {
233
+ // Each repository whose commits hold one, by the command that rewrites them there.
234
+ const resets = [
235
+ ...new Set([
236
+ ...placed
237
+ .filter((hit) => hit.committed || hit.message)
238
+ .map((hit) => resetOf(hit.elsewhere, base)),
239
+ ...scanned.filter((hit) => hit.committed).map((hit) => resetOf(hit.elsewhere, base)),
240
+ ]),
241
+ ];
242
+ return [
243
+ ...(placed.length > 0 ? placedLines(placed) : []),
244
+ ...(placed.length > 0 && scanned.length > 0 ? [""] : []),
245
+ ...(scanned.length > 0 ? scanLines(scanned) : []),
246
+ resets.length > 0
247
+ ? `A commit on this branch adds one too, maybe one already taken out of the files, and every commit is pushed and scanned: rewrite this branch's commits so that none of them, and no message, holds one (for example ${listed(resets)} once the files are fixed, then commit again).`
205
248
  : "Then commit.",
206
249
  "Then end your turn as before, with your report.",
207
250
  ].join("\n");
208
251
  }
252
+ /** The ask for System secrets alone. */
253
+ export function placedSecretAsk(hits, base) {
254
+ return healAsk(hits, [], base);
255
+ }
209
256
  /**
210
- * Reads a writing turn's change for the System's secrets and, when it holds
211
- * one, asks the model once to take it out and finish. Not asked of a turn
212
- * that was stopped, ran out of time or ended in an error, nor on a machine
213
- * with no secret placed.
257
+ * Reads a writing turn's change for the System's secrets and with the
258
+ * secret scan and, when it holds one, asks the model once to take it out and
259
+ * finish. Not asked of a turn that was stopped, ran out of time or ended in
260
+ * an error, nor with under {@link MIN_REVIEW_ROUND_MS} of the run left (a
261
+ * note says so). The System's secrets are read only on a machine with one
262
+ * placed.
214
263
  */
215
264
  export async function healPlacedSecrets(run, turn, opts) {
216
265
  const unchanged = { run, asked: [], note: null };
217
266
  const { store, base } = opts;
218
- if (!store || !base || opts.signal?.aborted || run.timedOut || run.exitCode !== 0) {
267
+ if (!base || opts.signal?.aborted || run.timedOut || run.exitCode !== 0) {
219
268
  return unchanged;
220
269
  }
221
- const scanOne = (cwd, from, skip) => placedSecretsInChange(cwd, from, store.secrets(), { ...opts, skip }).catch(() => null);
270
+ const secrets = store?.secrets() ?? [];
271
+ const placedOne = (cwd, from, skip) => secrets.length === 0
272
+ ? Promise.resolve([])
273
+ : placedSecretsInChange(cwd, from, secrets, { ...opts, skip }).catch(() => null);
274
+ const scanOne = async (cwd, from, skip) => {
275
+ const scanOpts = {
276
+ exec: opts.exec,
277
+ base: from,
278
+ ...(opts.sessionSecrets ? { sessionSecrets: opts.sessionSecrets } : {}),
279
+ ...(opts.readFile ? { readFile: opts.readFile } : {}),
280
+ };
281
+ const hits = await scanChangeHits(cwd, scanOpts, skip, opts.signal).catch(() => null);
282
+ if (hits === null)
283
+ return null;
284
+ if (hits.length === 0)
285
+ return [];
286
+ // A log that could not be read counts as a commit that adds it: the ask
287
+ // then says to rewrite, which is safe for commits not yet pushed.
288
+ const committed = (await commitsAddAHit(cwd, from, opts)) ?? true;
289
+ return hits.map((hit) => ({ ...hit, committed }));
290
+ };
222
291
  // The session's own repository, then each other one it may have changed:
223
292
  // null when any of them could not be read.
224
293
  const scan = async () => {
225
- const own = await scanOne(opts.cwd, base, opts.skip);
226
- if (own === null)
294
+ const [ownPlaced, ownScanned] = await Promise.all([
295
+ placedOne(opts.cwd, base, opts.skip),
296
+ scanOne(opts.cwd, base, opts.skip),
297
+ ]);
298
+ if (ownPlaced === null || ownScanned === null)
227
299
  return null;
228
- const hits = [...own];
300
+ const placed = [...ownPlaced];
301
+ const scanned = [...ownScanned];
229
302
  for (const other of opts.others ?? []) {
230
303
  if (!other.base)
231
304
  continue;
232
- const found = await scanOne(other.cwd, other.base, other.skip);
233
- if (found === null)
305
+ const [found, flagged] = await Promise.all([
306
+ placedOne(other.cwd, other.base, other.skip),
307
+ scanOne(other.cwd, other.base, other.skip),
308
+ ]);
309
+ if (found === null || flagged === null)
234
310
  return null;
235
311
  const elsewhere = { repository: other.repository, dir: other.cwd, base: other.base };
236
- hits.push(...found.map((hit) => ({ ...hit, elsewhere })));
312
+ placed.push(...found.map((hit) => ({ ...hit, elsewhere })));
313
+ scanned.push(...flagged.map((hit) => ({ ...hit, elsewhere })));
237
314
  }
238
- return hits;
315
+ return { placed, scanned };
239
316
  };
240
- const unread = "The change could not be read for the System's credentials before the turn ended; the host still checks its push.";
317
+ const unread = "The change could not be read for credentials before the turn ended; the host still checks its push.";
241
318
  const hits = await scan();
242
319
  if (hits === null)
243
320
  return { ...unchanged, note: unread };
244
- if (hits.length === 0)
321
+ if (hits.placed.length === 0 && hits.scanned.length === 0)
245
322
  return unchanged;
246
- const again = await turn(placedSecretAsk(hits, base));
247
- const left = await scan();
323
+ const left = opts.timeLeftMs?.();
324
+ if (left !== undefined && left < MIN_REVIEW_ROUND_MS) {
325
+ return { ...unchanged, note: lowTimeNote(hits.placed, hits.scanned) };
326
+ }
327
+ const again = await turn(healAsk(hits.placed, hits.scanned, base));
328
+ const after = await scan();
329
+ // The change is clean but a commit may still add the value: the host
330
+ // pushes it, and the repository's own secret scan, which reads every
331
+ // commit, can flag the pull request. Read only where a hit was.
332
+ const inCommits = [];
333
+ if (after !== null && after.scanned.length === 0) {
334
+ const flaggedRepos = new Map(hits.scanned.map((hit) => [
335
+ hit.elsewhere?.dir ?? opts.cwd,
336
+ { name: hit.elsewhere?.repository ?? null, from: hit.elsewhere?.base ?? base },
337
+ ]));
338
+ for (const [cwd, { name, from }] of flaggedRepos) {
339
+ if (await commitsAddAHit(cwd, from, opts))
340
+ inCommits.push(name ?? "this repository");
341
+ }
342
+ }
343
+ const notes = [
344
+ after === null ? unread : stillThereNote(after.placed, after.scanned),
345
+ inCommits.length > 0
346
+ ? `A commit on the branch in ${listed(inCommits)} still adds what the secret scan flagged, though the change no longer holds it: the repository's own secret scan, which reads every commit, can flag the pull request.`
347
+ : null,
348
+ ].filter((note) => note !== null);
248
349
  return {
249
350
  run: again.exitCode === 0 ? again : run,
250
351
  asked: [again],
251
- note: left === null ? unread : stillThereNote(left),
352
+ note: notes.length > 0 ? notes.join(" ") : null,
252
353
  };
253
354
  }
254
- /** The result's note for secrets still in the change after the ask, by name; null when none is. */
255
- function stillThereNote(left) {
256
- if (left.length === 0)
355
+ /**
356
+ * Whether a commit past `from` adds a scan hit in its own patch: the
357
+ * repository's own secret scan reads every commit of the pull request, so
358
+ * such a commit is rewritten, not only fixed on top. Any hit counts, not only
359
+ * one the change still holds: a value a later commit took out is still in
360
+ * the commit that added it. A merge's patch is not
361
+ * read (`git log -p` shows none), so merging the default branch in never
362
+ * asks for a rewrite. Null when the log could not be read.
363
+ */
364
+ async function commitsAddAHit(cwd, from, opts) {
365
+ const log = await opts
366
+ .exec([
367
+ "git",
368
+ "-c",
369
+ "core.quotepath=off",
370
+ "log",
371
+ "-p",
372
+ "--format=",
373
+ "-U0",
374
+ "--no-color",
375
+ "--no-ext-diff",
376
+ "--text",
377
+ `${from}..HEAD`,
378
+ ], cwd, opts.signal)
379
+ .catch(() => ({ code: 1, output: "" }));
380
+ if (log.code !== 0)
257
381
  return null;
258
- // One name once, though more than one repository holds it.
259
- const names = [...new Set(left.map((hit) => hit.name))];
260
- const them = names.length > 1 ? "them" : "it";
261
- 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.`;
382
+ return addedTextHits(addedTextOfDiff(log.output), opts.sessionSecrets ?? []).length > 0;
383
+ }
384
+ /** Each scan hit by place and kind, for a note: `a.ts:3` (a GitHub token). */
385
+ function scanPlaces(hits) {
386
+ return listed(hits.map((hit) => `${hit.elsewhere ? `${hit.elsewhere.repository}: ` : ""}${hit.file}${hit.line === undefined ? "" : `:${hit.line}`} (${describeKind(hit.kind)})`));
387
+ }
388
+ /** The result's note for hits that had no ask, the run's time being short. */
389
+ function lowTimeNote(placed, scanned) {
390
+ const what = [
391
+ ...(placed.length > 0
392
+ ? [`the System's ${listed([...new Set(placed.map((hit) => hit.name))])}`]
393
+ : []),
394
+ ...(scanned.length > 0 ? [`what the secret scan flags (${scanPlaces(scanned)})`] : []),
395
+ ];
396
+ return `The change holds ${listed(what)}, and under ${MIN_REVIEW_ROUND_MS / 60_000} minutes of the run were left, so the session was not asked to take it out.`;
397
+ }
398
+ /** The result's note for hits still in the change after the ask; null when none is. */
399
+ function stillThereNote(placed, scanned) {
400
+ const notes = [];
401
+ if (placed.length > 0) {
402
+ // One name once, though more than one repository holds it.
403
+ const names = [...new Set(placed.map((hit) => hit.name))];
404
+ const them = names.length > 1 ? "them" : "it";
405
+ notes.push(`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.`);
406
+ }
407
+ if (scanned.length > 0) {
408
+ notes.push(`The change still holds what the secret scan flags after one ask to take it out: ${scanPlaces(scanned)}.`);
409
+ }
410
+ return notes.length > 0 ? notes.join(" ") : null;
262
411
  }
263
412
  //# sourceMappingURL=placedValueHeal.js.map
@@ -354,6 +354,7 @@ const BUILD_RULES = (outDir, who, yak = null, template = null) => [
354
354
  "- Each behavior change gets a test. Run it once without the change and see it fail, then with it; in the report, that test's check says in its note what failed without the change.",
355
355
  "- A check checks.json marks measureOnBase, or one you would call fails_on_base, is measured on the unchanged code during this attempt: before your first edit, or in a git worktree at the commit this branch started from. A red in the repository's record is not a measurement, however recent; a baseMeasured entry in checks.json is.",
356
356
  "- Commit on the branch you are on. Never push and never open or edit a pull request: YAGNI pushes your commits and opens it.",
357
+ '- Never write a value shaped like a real credential in any file, tests included (a `ghp_` or `ghs_` token, an `sk-` key, an `AKIA` key, a private-key block). In a test, build the value when the test runs (`"ghs_" + "a".repeat(36)`) or use an obvious fake without the prefix. A `gitleaks:allow` comment does not count. Do not copy the token-shaped literals already in the repository.',
357
358
  `- ${yak ? workingStyleAskRule(yak.style, outDir, yak.review) : NEEDS_PERSON_RULE(outDir)}`,
358
359
  `- ${PULL_REQUEST_CONTRACT(outDir, yak !== null)}${template ? templateRule(template) : ""}`,
359
360
  `- ${REPORT_CONTRACT(outDir)}`,
@@ -1241,6 +1242,8 @@ async function runTurn(input, deps, pulse, tally) {
1241
1242
  ...(workingStyle ? { workingStyle } : {}),
1242
1243
  ...(pullRequestTemplate ? { pullRequestTemplate } : {}),
1243
1244
  });
1245
+ // This session's own credentials: the heal and the finish's scan match them by value.
1246
+ const sessionSecrets = [input.childEnv.YAGNI_TOKEN, input.childEnv.GH_ENTERPRISE_TOKEN].filter((value) => Boolean(value));
1244
1247
  const notes = [];
1245
1248
  const stages = [];
1246
1249
  let planText = "";
@@ -1251,8 +1254,9 @@ async function runTurn(input, deps, pulse, tally) {
1251
1254
  let run = await turn(message);
1252
1255
  stages.push(run);
1253
1256
  if (writes) {
1254
- // A System secret in the change is taken out in this session, before
1255
- // the host's push would stop on it for a person (YAG-1209).
1257
+ // A System secret, or what the finish's secret scan flags, in the
1258
+ // change is taken out in this session, before the finish fails the run
1259
+ // or the host's push stops on it for a person.
1256
1260
  const healed = await healPlacedSecrets(run, turn, {
1257
1261
  cwd: input.cwd,
1258
1262
  base: baseSha,
@@ -1260,6 +1264,8 @@ async function runTurn(input, deps, pulse, tally) {
1260
1264
  exec,
1261
1265
  skip: preRunDirt,
1262
1266
  others,
1267
+ sessionSecrets,
1268
+ timeLeftMs,
1263
1269
  ...(input.signal ? { signal: input.signal } : {}),
1264
1270
  });
1265
1271
  stages.push(...healed.asked);
@@ -1369,7 +1375,6 @@ async function runTurn(input, deps, pulse, tally) {
1369
1375
  input.writeErr(error);
1370
1376
  ran = { error, partial: stages };
1371
1377
  }
1372
- const sessionSecrets = [input.childEnv.YAGNI_TOKEN, input.childEnv.GH_ENTERPRISE_TOKEN].filter((value) => Boolean(value));
1373
1378
  const done = await completeCloudSession({
1374
1379
  identity: input.identity,
1375
1380
  outDir: input.outDir,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yagni-app/code-staging",
3
- "version": "1.2.15-staging.2661.1",
3
+ "version": "1.2.15-staging.2666.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": "891908951ce7f3ebe498ef06c319cf1d50b9a852"
61
+ "yagniSourceSha": "70d0ae45371f758e20640b133b17ba814e062bf0"
62
62
  }