@yagni-app/code-staging 1.2.14-staging.2282.1 → 1.2.14-staging.2286.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/pipeline/cloud.d.ts +30 -0
- package/dist/extension/pipeline/cloud.js +79 -3
- package/dist/extension/pipeline/finish.d.ts +6 -0
- package/dist/extension/pipeline/finish.js +46 -2
- package/dist/extension/pipeline/placedValueHeal.d.ts +37 -0
- package/dist/extension/pipeline/placedValueHeal.js +72 -4
- package/dist/extension/pipeline/sessionLane.d.ts +16 -1
- package/dist/extension/pipeline/sessionLane.js +70 -3
- package/package.json +2 -2
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* lives (`packages/shared/src/attempts.ts`): the two meet only at this JSON.
|
|
17
17
|
*/
|
|
18
18
|
import type { ContinuationStage } from "./continuation.js";
|
|
19
|
+
import { type RunFinishOpts } from "./finish.js";
|
|
19
20
|
import { type PlanChange } from "./planChanges.js";
|
|
20
21
|
import { type VerifyCheckRun, type VerifyOutcome } from "./verify.js";
|
|
21
22
|
import type { WorktreeExec } from "./worktree.js";
|
|
@@ -210,7 +211,36 @@ export interface CloudCompletion {
|
|
|
210
211
|
planPaths: (planText: string) => string[];
|
|
211
212
|
exec: WorktreeExec;
|
|
212
213
|
writeFile: (path: string, text: string) => void;
|
|
214
|
+
/**
|
|
215
|
+
* The System's other repositories a yak's session may change in place
|
|
216
|
+
* (YAG-1211), each with its dirt from before the turn: each gets this
|
|
217
|
+
* repository's final commit over its own leftovers (YAG-1217). Absent on
|
|
218
|
+
* every other session.
|
|
219
|
+
*/
|
|
220
|
+
others?: ReadonlyArray<OtherRepositoryFinish>;
|
|
221
|
+
/** The attempt's branch, for a detached checkout among `others` to take before its commit. */
|
|
222
|
+
othersBranch?: string | null;
|
|
223
|
+
}
|
|
224
|
+
/** Another repository of a yak's System, as the turn's final commit meets it (YAG-1217). */
|
|
225
|
+
export interface OtherRepositoryFinish {
|
|
226
|
+
/** `owner/name`. */
|
|
227
|
+
repository: string;
|
|
228
|
+
/** Its working copy. */
|
|
229
|
+
cwd: string;
|
|
230
|
+
/** Its dirt from before the turn, never committed. */
|
|
231
|
+
preRunDirt: readonly string[];
|
|
213
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* The final commit in each of the System's other repositories a yak's
|
|
235
|
+
* session changed (YAG-1217): the ticket's own repository's commit, with its
|
|
236
|
+
* message and trailers, over that repository's own leftovers only (never its
|
|
237
|
+
* dirt from before the turn). One holding nothing of the turn's own is left
|
|
238
|
+
* alone, so no note is written for it. A detached checkout takes the
|
|
239
|
+
* attempt's branch first when that branch is not there yet, so the next
|
|
240
|
+
* wake knows the work as this attempt's. What could not be committed is a
|
|
241
|
+
* note naming the repository; the host names the repository in the thread.
|
|
242
|
+
*/
|
|
243
|
+
export declare function finishOtherRepositories(others: ReadonlyArray<OtherRepositoryFinish>, finish: Omit<RunFinishOpts, "cwd" | "baselinePaths" | "baseSha" | "exec">, exec: WorktreeExec, branch: string | null): Promise<string[]>;
|
|
214
244
|
/**
|
|
215
245
|
* The changes to the plan the session's implement stage reported: the last
|
|
216
246
|
* implement summary that carries a plan-changes block. None when no implement
|
|
@@ -23,7 +23,7 @@ import { extractPlanChanges, planChangeNote } from "./planChanges.js";
|
|
|
23
23
|
import { buildPlanFile, planMarkdown } from "./planOutput.js";
|
|
24
24
|
import { cloudLane } from "./stages.js";
|
|
25
25
|
import { applyStageTiers, parseStageTiers, STAGE_TIERS_ENV } from "./tierCap.js";
|
|
26
|
-
import { CHECK_NOT_RUN_NOTE } from "./verify.js";
|
|
26
|
+
import { CHECK_NOT_RUN_NOTE, parseChangedPaths, } from "./verify.js";
|
|
27
27
|
/** Set on every stage child of a cloud session, so its prompt describes the cloud sandbox. */
|
|
28
28
|
export const CLOUD_SESSION_ENV = "YAGNI_GO_CLOUD";
|
|
29
29
|
/** Where the session writes `plan.md`, `plan.json` and `result.json`. */
|
|
@@ -291,6 +291,75 @@ export function cannotRunNote(checks) {
|
|
|
291
291
|
function findingKey(finding) {
|
|
292
292
|
return `${finding.file ?? ""}:${finding.line ?? ""}:${finding.message}`;
|
|
293
293
|
}
|
|
294
|
+
const ATTEMPT_BRANCH = /^yagni\/[a-z0-9][a-z0-9._-]{0,120}$/;
|
|
295
|
+
/**
|
|
296
|
+
* Whether a checkout is on the attempt's branch, after a detached one takes
|
|
297
|
+
* it when that branch is not there yet: true, or why not, in words.
|
|
298
|
+
*/
|
|
299
|
+
async function onAttemptBranch(run, branch) {
|
|
300
|
+
if (!branch || !ATTEMPT_BRANCH.test(branch))
|
|
301
|
+
return "the host named no branch for this ticket";
|
|
302
|
+
const on = await run(["git", "branch", "--show-current"]);
|
|
303
|
+
if (on.code !== 0)
|
|
304
|
+
return "its branch could not be read";
|
|
305
|
+
const current = on.output.trim();
|
|
306
|
+
if (current === branch)
|
|
307
|
+
return true;
|
|
308
|
+
if (current)
|
|
309
|
+
return `it is on ${current}, not this ticket's branch`;
|
|
310
|
+
const there = await run(["git", "rev-parse", "--verify", "--quiet", `refs/heads/${branch}`]);
|
|
311
|
+
if (there.code === 0)
|
|
312
|
+
return "it is detached away from this ticket's branch";
|
|
313
|
+
const made = await run(["git", "checkout", "--quiet", "-b", branch]);
|
|
314
|
+
return made.code === 0 ? true : "this ticket's branch could not be made there";
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* The final commit in each of the System's other repositories a yak's
|
|
318
|
+
* session changed (YAG-1217): the ticket's own repository's commit, with its
|
|
319
|
+
* message and trailers, over that repository's own leftovers only (never its
|
|
320
|
+
* dirt from before the turn). One holding nothing of the turn's own is left
|
|
321
|
+
* alone, so no note is written for it. A detached checkout takes the
|
|
322
|
+
* attempt's branch first when that branch is not there yet, so the next
|
|
323
|
+
* wake knows the work as this attempt's. What could not be committed is a
|
|
324
|
+
* note naming the repository; the host names the repository in the thread.
|
|
325
|
+
*/
|
|
326
|
+
export async function finishOtherRepositories(others, finish, exec, branch) {
|
|
327
|
+
const notes = [];
|
|
328
|
+
for (const other of others) {
|
|
329
|
+
const run = (argv) => exec(argv, other.cwd).catch((err) => ({
|
|
330
|
+
code: -1,
|
|
331
|
+
output: err instanceof Error ? err.message : String(err),
|
|
332
|
+
}));
|
|
333
|
+
const status = await run(["git", "status", "--porcelain"]);
|
|
334
|
+
if (status.code !== 0) {
|
|
335
|
+
notes.push(`In ${other.repository}: what the turn left could not be read, so nothing there was committed.`);
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
const before = new Set(other.preRunDirt);
|
|
339
|
+
if (parseChangedPaths(status.output).every((path) => before.has(path)))
|
|
340
|
+
continue;
|
|
341
|
+
// The commit goes on the attempt's branch only, never on another
|
|
342
|
+
// ticket's: a detached checkout takes the branch when it is not there
|
|
343
|
+
// yet; any other is said and left (Codex round 2).
|
|
344
|
+
const owned = await onAttemptBranch(run, branch);
|
|
345
|
+
if (owned !== true) {
|
|
346
|
+
notes.push(`In ${other.repository}: ${owned}, so what the turn left there was not committed.`);
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
const done = await runFinish({
|
|
350
|
+
...finish,
|
|
351
|
+
cwd: other.cwd,
|
|
352
|
+
// Dirt from before the turn stays out, staged or not (Codex round 1).
|
|
353
|
+
...(other.preRunDirt.length > 0
|
|
354
|
+
? { baselinePaths: [...other.preRunDirt], onlyRunOwned: true }
|
|
355
|
+
: {}),
|
|
356
|
+
exec,
|
|
357
|
+
});
|
|
358
|
+
if (!done.committed)
|
|
359
|
+
notes.push(...done.notes.map((note) => `In ${other.repository}: ${note}`));
|
|
360
|
+
}
|
|
361
|
+
return notes;
|
|
362
|
+
}
|
|
294
363
|
/**
|
|
295
364
|
* The changes to the plan the session's implement stage reported: the last
|
|
296
365
|
* implement summary that carries a plan-changes block. None when no implement
|
|
@@ -395,8 +464,7 @@ export async function completeCloudSession(c, ran) {
|
|
|
395
464
|
notes.push("The review loop stopped clean, but the final scan or checks found a blocker in what is committed.");
|
|
396
465
|
}
|
|
397
466
|
const title = c.plan ? planTitle(c.plan) : undefined;
|
|
398
|
-
const
|
|
399
|
-
cwd: c.cwd,
|
|
467
|
+
const commit = {
|
|
400
468
|
worktreeMode: true,
|
|
401
469
|
hereBaseline: "unknown",
|
|
402
470
|
ticket: ticketOfBranch(branch) ?? c.identity.attemptId,
|
|
@@ -411,12 +479,20 @@ export async function completeCloudSession(c, ran) {
|
|
|
411
479
|
decisionsRecorded: result?.decisionsRecorded ?? 0,
|
|
412
480
|
rounds: result?.rounds.length ?? 0,
|
|
413
481
|
openPr: false,
|
|
482
|
+
};
|
|
483
|
+
const finish = await runFinish({
|
|
484
|
+
...commit,
|
|
485
|
+
cwd: c.cwd,
|
|
414
486
|
...(c.preRunDirt.length > 0 ? { baselinePaths: c.preRunDirt } : {}),
|
|
415
487
|
...(c.baseSha ? { baseSha: c.baseSha } : {}),
|
|
416
488
|
exec: c.exec,
|
|
417
489
|
});
|
|
418
490
|
committed = finish.committed;
|
|
419
491
|
notes.push(...finish.notes);
|
|
492
|
+
// The System's other repositories get the same final commit (YAG-1217).
|
|
493
|
+
if (c.others?.length) {
|
|
494
|
+
notes.push(...(await finishOtherRepositories(c.others, commit, c.exec, c.othersBranch ?? null)));
|
|
495
|
+
}
|
|
420
496
|
}
|
|
421
497
|
const facts = await gitFacts(c.cwd, c.exec, c.baseSha);
|
|
422
498
|
notes.push(...facts.notes);
|
|
@@ -80,6 +80,12 @@ export interface RunFinishOpts extends TrailerInputs {
|
|
|
80
80
|
* commit on top, so the branch still carries the run's `YAGNI-Run` line.
|
|
81
81
|
*/
|
|
82
82
|
baseSha?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Commit only the run's own paths (`git commit -- <paths>`), never what was
|
|
85
|
+
* already staged among `baselinePaths` (a yak's System's other
|
|
86
|
+
* repositories, YAG-1217). Absent: the index is committed as staged.
|
|
87
|
+
*/
|
|
88
|
+
onlyRunOwned?: boolean;
|
|
83
89
|
signal?: AbortSignal;
|
|
84
90
|
exec?: WorktreeExec;
|
|
85
91
|
}
|
|
@@ -260,6 +260,36 @@ async function committedSince(run, baseSha) {
|
|
|
260
260
|
.map((line) => line.trim())
|
|
261
261
|
.filter(Boolean);
|
|
262
262
|
}
|
|
263
|
+
/** Each rename in `git status --porcelain` (`R old -> new`), as its source and destination. */
|
|
264
|
+
function renamesIn(status) {
|
|
265
|
+
const renames = [];
|
|
266
|
+
for (const raw of status.split("\n")) {
|
|
267
|
+
if (raw.length < 4 || !raw.slice(0, 2).includes("R"))
|
|
268
|
+
continue;
|
|
269
|
+
const entry = raw[2] === " " ? raw.slice(3) : raw.slice(2);
|
|
270
|
+
const arrow = entry.indexOf(" -> ");
|
|
271
|
+
if (arrow < 0)
|
|
272
|
+
continue;
|
|
273
|
+
const from = entry.slice(0, arrow).trim();
|
|
274
|
+
const to = entry.slice(arrow + 4).trim();
|
|
275
|
+
if (from && to)
|
|
276
|
+
renames.push({ from, to });
|
|
277
|
+
}
|
|
278
|
+
return renames;
|
|
279
|
+
}
|
|
280
|
+
/** The source of each rename whose destination is one of `paths`: a commit limited to paths names both. */
|
|
281
|
+
function renameSources(status, paths) {
|
|
282
|
+
const wanted = new Set(paths);
|
|
283
|
+
return renamesIn(status)
|
|
284
|
+
.filter((rename) => wanted.has(rename.to) && !wanted.has(rename.from))
|
|
285
|
+
.map((rename) => rename.from);
|
|
286
|
+
}
|
|
287
|
+
/** The destination of each rename whose source is among `baseline`. */
|
|
288
|
+
function renamedFrom(status, baseline) {
|
|
289
|
+
return renamesIn(status)
|
|
290
|
+
.filter((rename) => baseline.has(rename.from))
|
|
291
|
+
.map((rename) => rename.to);
|
|
292
|
+
}
|
|
263
293
|
/**
|
|
264
294
|
* Run the FINISH stage. NEVER throws; every failure path returns an honest
|
|
265
295
|
* {@link FinishResult} with notes. See the module docblock for the contract.
|
|
@@ -300,7 +330,12 @@ export async function runFinish(opts) {
|
|
|
300
330
|
// commit only these, so the provenance commit never folds in non-run work.
|
|
301
331
|
const changed = parseChangedPaths(status.output);
|
|
302
332
|
const baseline = new Set(opts.baselinePaths ?? []);
|
|
303
|
-
|
|
333
|
+
// A path-limited commit leaves out a rename whose source was dirt from
|
|
334
|
+
// before the run too: its destination carries that dirt (Codex round 3).
|
|
335
|
+
const dirtyRenames = opts.onlyRunOwned === true ? renamedFrom(status.output, baseline) : [];
|
|
336
|
+
const runOwned = baseline.size === 0
|
|
337
|
+
? changed
|
|
338
|
+
: changed.filter((p) => !baseline.has(p) && !dirtyRenames.includes(p));
|
|
304
339
|
// Nothing of the run's own left in the tree, but its work may already be
|
|
305
340
|
// committed past its base: the trailer then goes on an empty commit.
|
|
306
341
|
const committed = runOwned.length === 0 ? await committedSince(run, opts.baseSha) : [];
|
|
@@ -329,7 +364,16 @@ export async function runFinish(opts) {
|
|
|
329
364
|
return skipped(`FINISH could not stage the changes (git add failed: ${tail(add.output)}); nothing was committed.`);
|
|
330
365
|
}
|
|
331
366
|
}
|
|
332
|
-
|
|
367
|
+
// Only the run's own paths, so dirt from before the run that was already
|
|
368
|
+
// staged is never committed with them.
|
|
369
|
+
const only = opts.onlyRunOwned === true && !trailerOnly && baseline.size > 0;
|
|
370
|
+
const commitArgs = [
|
|
371
|
+
...(trailerOnly ? ["--allow-empty"] : []),
|
|
372
|
+
"-m",
|
|
373
|
+
message,
|
|
374
|
+
// A rename's source too, so its deletion goes with it (Codex round 2).
|
|
375
|
+
...(only ? ["--", ...runOwned, ...renameSources(status.output, runOwned)] : []),
|
|
376
|
+
];
|
|
333
377
|
let commit = await run(["git", "commit", ...commitArgs]);
|
|
334
378
|
if (commit.code !== 0) {
|
|
335
379
|
// Most likely a missing git identity in a fresh environment (mirrors
|
|
@@ -29,7 +29,42 @@ export interface PlacedSecretHit {
|
|
|
29
29
|
committed: boolean;
|
|
30
30
|
/** A commit message holds it. */
|
|
31
31
|
message: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Another repository of a yak's System the session changed in place
|
|
34
|
+
* (YAG-1211), where the hit is: its `owner/name`, its folder and the
|
|
35
|
+
* turn's start there. Absent: the session's own repository.
|
|
36
|
+
*/
|
|
37
|
+
elsewhere?: {
|
|
38
|
+
repository: string;
|
|
39
|
+
dir: string;
|
|
40
|
+
base: string;
|
|
41
|
+
};
|
|
32
42
|
}
|
|
43
|
+
/** Another repository of a yak's System, checked out beside the session's own (YAG-1211). */
|
|
44
|
+
export interface OtherRepositoryScan {
|
|
45
|
+
/** `owner/name`. */
|
|
46
|
+
repository: string;
|
|
47
|
+
/** Its working copy. */
|
|
48
|
+
cwd: string;
|
|
49
|
+
/** Its head when the turn started; null when it could not be read (not scanned). */
|
|
50
|
+
base: string | null;
|
|
51
|
+
/** Its dirt from before the turn. */
|
|
52
|
+
skip?: readonly string[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Where the host's push of another repository of a yak's System starts, as
|
|
56
|
+
* its collection reads it (`attempts/repositoryWork.ts`, `workStartOf` and
|
|
57
|
+
* `remoteBaseOf`), so the session reads every commit that push publishes:
|
|
58
|
+
* the head the attempt last pushed there, when the checkout descends from
|
|
59
|
+
* it; else, on the attempt's own branch, the newest commit of it GitHub has
|
|
60
|
+
* (an earlier turn's work, never pushed, is published too); else where the
|
|
61
|
+
* turn found it. Read when the turn starts, before the session moves it.
|
|
62
|
+
*/
|
|
63
|
+
export declare function publicationBase(exec: WorktreeExec, cwd: string, input: {
|
|
64
|
+
head: string;
|
|
65
|
+
pushedHead: string | null;
|
|
66
|
+
branch: string | null;
|
|
67
|
+
}, signal?: AbortSignal): Promise<string>;
|
|
33
68
|
export interface PlacedSecretScanOpts {
|
|
34
69
|
exec: WorktreeExec;
|
|
35
70
|
/** The tree's dirt from before the turn (`git status` paths, a folder ending in `/`): not the turn's. */
|
|
@@ -63,5 +98,7 @@ export declare function healPlacedSecrets(run: StageResult, turn: (message: stri
|
|
|
63
98
|
cwd: string;
|
|
64
99
|
base: string | null;
|
|
65
100
|
store: PlacedValues | null;
|
|
101
|
+
/** A yak's System's other repositories the session may change in place (YAG-1211), each read as its own. */
|
|
102
|
+
others?: readonly OtherRepositoryScan[];
|
|
66
103
|
}): Promise<PlacedSecretHeal>;
|
|
67
104
|
//# sourceMappingURL=placedValueHeal.d.ts.map
|
|
@@ -22,6 +22,47 @@ import { join } from "node:path";
|
|
|
22
22
|
import { logEvent } from "../errorSink.js";
|
|
23
23
|
import { PLACED_VALUE_MARK } from "../placedValues.js";
|
|
24
24
|
import { addedTextOfDiff } from "./changeScan.js";
|
|
25
|
+
const SHA = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
|
|
26
|
+
/** At most this many commits of its own a checkout is read for, as the host reads it. */
|
|
27
|
+
const MAX_OWN_COMMITS = 500;
|
|
28
|
+
/**
|
|
29
|
+
* Where the host's push of another repository of a yak's System starts, as
|
|
30
|
+
* its collection reads it (`attempts/repositoryWork.ts`, `workStartOf` and
|
|
31
|
+
* `remoteBaseOf`), so the session reads every commit that push publishes:
|
|
32
|
+
* the head the attempt last pushed there, when the checkout descends from
|
|
33
|
+
* it; else, on the attempt's own branch, the newest commit of it GitHub has
|
|
34
|
+
* (an earlier turn's work, never pushed, is published too); else where the
|
|
35
|
+
* turn found it. Read when the turn starts, before the session moves it.
|
|
36
|
+
*/
|
|
37
|
+
export async function publicationBase(exec, cwd, input, signal) {
|
|
38
|
+
const git = (args) => exec(["git", ...args], cwd, signal);
|
|
39
|
+
if (input.pushedHead && SHA.test(input.pushedHead)) {
|
|
40
|
+
const descends = await git(["merge-base", "--is-ancestor", input.pushedHead, input.head]);
|
|
41
|
+
if (descends.code === 0)
|
|
42
|
+
return input.pushedHead;
|
|
43
|
+
}
|
|
44
|
+
if (!input.branch)
|
|
45
|
+
return input.head;
|
|
46
|
+
const on = await git(["symbolic-ref", "-q", "--short", "HEAD"]);
|
|
47
|
+
if (on.code !== 0 || on.output.trim() !== input.branch)
|
|
48
|
+
return input.head;
|
|
49
|
+
const own = await git(["rev-list", "--count", input.head, "--not", "--remotes"]);
|
|
50
|
+
const count = Number(own.output.trim());
|
|
51
|
+
if (own.code !== 0 || !Number.isInteger(count) || count === 0 || count > MAX_OWN_COMMITS) {
|
|
52
|
+
return input.head;
|
|
53
|
+
}
|
|
54
|
+
const boundary = await git(["rev-list", "--boundary", input.head, "--not", "--remotes"]);
|
|
55
|
+
if (boundary.code !== 0)
|
|
56
|
+
return input.head;
|
|
57
|
+
const bases = [
|
|
58
|
+
...new Set(boundary.output
|
|
59
|
+
.split("\n")
|
|
60
|
+
.filter((line) => line.startsWith("-"))
|
|
61
|
+
.map((line) => line.slice(1).trim())),
|
|
62
|
+
];
|
|
63
|
+
// One commit below them all, as the host takes it; else only this turn's.
|
|
64
|
+
return bases.length === 1 && SHA.test(bases[0]) ? bases[0] : input.head;
|
|
65
|
+
}
|
|
25
66
|
/** How much of one new file is read: a value sits in source, not past the first megabyte. */
|
|
26
67
|
const MAX_READ_BYTES = 1024 * 1024;
|
|
27
68
|
/** Each named git read's output, or the first that failed, by name and exit code. */
|
|
@@ -134,6 +175,14 @@ function listed(items) {
|
|
|
134
175
|
/** The ask: each secret by name and place, what to do instead, and to finish as before. */
|
|
135
176
|
export function placedSecretAsk(hits, base) {
|
|
136
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
|
+
];
|
|
137
186
|
return [
|
|
138
187
|
"Your change holds the value of a System credential, and YAGNI never pushes a change that holds one:",
|
|
139
188
|
...hits.map((hit) => {
|
|
@@ -144,7 +193,7 @@ export function placedSecretAsk(hits, base) {
|
|
|
144
193
|
: []),
|
|
145
194
|
...(hit.message ? ["a commit message"] : []),
|
|
146
195
|
];
|
|
147
|
-
return `- ${hit.name}, in ${listed(places)}`;
|
|
196
|
+
return `- ${hit.name}, in ${listed(places)}${hit.elsewhere ? ` in ${hit.elsewhere.repository} (\`${hit.elsewhere.dir}\`)` : ""}`;
|
|
148
197
|
}),
|
|
149
198
|
"",
|
|
150
199
|
"Take each one out. Where the code needs it, read it from the environment instead " +
|
|
@@ -152,7 +201,7 @@ export function placedSecretAsk(hits, base) {
|
|
|
152
201
|
`You cannot see the value: what you read shows it as ${PLACED_VALUE_MARK}, so find the line by what is ` +
|
|
153
202
|
"around it, or write the file again whole. Never read /run/yagni/env, or print a value, to find it.",
|
|
154
203
|
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
|
|
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).`
|
|
156
205
|
: "Then commit.",
|
|
157
206
|
"Then end your turn as before, with your report.",
|
|
158
207
|
].join("\n");
|
|
@@ -169,7 +218,25 @@ export async function healPlacedSecrets(run, turn, opts) {
|
|
|
169
218
|
if (!store || !base || opts.signal?.aborted || run.timedOut || run.exitCode !== 0) {
|
|
170
219
|
return unchanged;
|
|
171
220
|
}
|
|
172
|
-
const
|
|
221
|
+
const scanOne = (cwd, from, skip) => placedSecretsInChange(cwd, from, store.secrets(), { ...opts, skip }).catch(() => null);
|
|
222
|
+
// The session's own repository, then each other one it may have changed:
|
|
223
|
+
// null when any of them could not be read.
|
|
224
|
+
const scan = async () => {
|
|
225
|
+
const own = await scanOne(opts.cwd, base, opts.skip);
|
|
226
|
+
if (own === null)
|
|
227
|
+
return null;
|
|
228
|
+
const hits = [...own];
|
|
229
|
+
for (const other of opts.others ?? []) {
|
|
230
|
+
if (!other.base)
|
|
231
|
+
continue;
|
|
232
|
+
const found = await scanOne(other.cwd, other.base, other.skip);
|
|
233
|
+
if (found === null)
|
|
234
|
+
return null;
|
|
235
|
+
const elsewhere = { repository: other.repository, dir: other.cwd, base: other.base };
|
|
236
|
+
hits.push(...found.map((hit) => ({ ...hit, elsewhere })));
|
|
237
|
+
}
|
|
238
|
+
return hits;
|
|
239
|
+
};
|
|
173
240
|
const unread = "The change could not be read for the System's credentials before the turn ended; the host still checks its push.";
|
|
174
241
|
const hits = await scan();
|
|
175
242
|
if (hits === null)
|
|
@@ -188,7 +255,8 @@ export async function healPlacedSecrets(run, turn, opts) {
|
|
|
188
255
|
function stillThereNote(left) {
|
|
189
256
|
if (left.length === 0)
|
|
190
257
|
return null;
|
|
191
|
-
|
|
258
|
+
// One name once, though more than one repository holds it.
|
|
259
|
+
const names = [...new Set(left.map((hit) => hit.name))];
|
|
192
260
|
const them = names.length > 1 ? "them" : "it";
|
|
193
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.`;
|
|
194
262
|
}
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
* verifies with a fresh `verification` subagent, commits and never
|
|
28
28
|
* pushes, and writes its own account to `session-report.json`. This
|
|
29
29
|
* process then runs what the cloud lane's finish runs (the secret and
|
|
30
|
-
* binary scan, a commit of anything left, the
|
|
30
|
+
* binary scan, a commit of anything left, in the ticket's repository
|
|
31
|
+
* and in each of a yak's System's other repositories, the git facts) and writes
|
|
31
32
|
* `result.json` with the model's checks, what it could not verify and
|
|
32
33
|
* where it departed from the plan folded in, each departure in
|
|
33
34
|
* `planChanges` for the host to write into the plan (`planChanges.ts`).
|
|
@@ -98,6 +99,20 @@ export interface TurnFacts {
|
|
|
98
99
|
export declare const NEXT_STEP_NOTE_FILE_NAME = "next-step-note.md";
|
|
99
100
|
/** The file the host writes a yak's new messages to (`attempts/inputs.ts`, `yaks/turns.ts`). */
|
|
100
101
|
export declare const NEW_SINCE_LAST_TURN_FILE_NAME = "new-since-last-turn.md";
|
|
102
|
+
/** The file the host names a yak's System's other repositories in (`attempts/inputs.ts`, YAG-1211). */
|
|
103
|
+
export declare const SYSTEM_REPOSITORIES_FILE_NAME = "system-repositories.json";
|
|
104
|
+
/**
|
|
105
|
+
* The System's other repositories the host named, by `owner/name` and
|
|
106
|
+
* folder (an absolute path, never the session's own), each with the head
|
|
107
|
+
* the attempt last pushed there and the attempt's branch; none when the
|
|
108
|
+
* file is absent or does not parse.
|
|
109
|
+
*/
|
|
110
|
+
export declare function systemRepositoriesOf(text: string | null, cwd: string): Array<{
|
|
111
|
+
repository: string;
|
|
112
|
+
dir: string;
|
|
113
|
+
pushedHead: string | null;
|
|
114
|
+
branch: string | null;
|
|
115
|
+
}>;
|
|
101
116
|
/** The one message a turn sends the session. Pure. */
|
|
102
117
|
export declare function turnMessage(facts: TurnFacts): string;
|
|
103
118
|
/** The model's own account of a turn that builds (`session-report.json`). */
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
* verifies with a fresh `verification` subagent, commits and never
|
|
28
28
|
* pushes, and writes its own account to `session-report.json`. This
|
|
29
29
|
* process then runs what the cloud lane's finish runs (the secret and
|
|
30
|
-
* binary scan, a commit of anything left, the
|
|
30
|
+
* binary scan, a commit of anything left, in the ticket's repository
|
|
31
|
+
* and in each of a yak's System's other repositories, the git facts) and writes
|
|
31
32
|
* `result.json` with the model's checks, what it could not verify and
|
|
32
33
|
* where it departed from the plan folded in, each departure in
|
|
33
34
|
* `planChanges` for the host to write into the plan (`planChanges.ts`).
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
*/
|
|
41
42
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
42
43
|
import { homedir } from "node:os";
|
|
43
|
-
import { join, relative } from "node:path";
|
|
44
|
+
import { isAbsolute, join, relative } from "node:path";
|
|
44
45
|
import { openPlacedValues } from "../placedValues.js";
|
|
45
46
|
import { scanChange } from "./changeScan.js";
|
|
46
47
|
import { completeCloudSession, RESULT_FILE_NAME, } from "./cloud.js";
|
|
@@ -48,7 +49,7 @@ import { finishExec } from "./finish.js";
|
|
|
48
49
|
import { MISSION_CHECKS_FILE_NAME, readMissionChecksFile } from "./missionChecks.js";
|
|
49
50
|
import { creditExhaustionReason } from "./orchestrator.js";
|
|
50
51
|
import { WORK_A_TICKET_SKILL } from "./personas.js";
|
|
51
|
-
import { healPlacedSecrets } from "./placedValueHeal.js";
|
|
52
|
+
import { healPlacedSecrets, publicationBase } from "./placedValueHeal.js";
|
|
52
53
|
import { extractPlanJson } from "./planOutput.js";
|
|
53
54
|
import { PLAN_CHANGES_RULE, parsePlanChanges, planChangeNote, } from "./planChanges.js";
|
|
54
55
|
import { runStage as defaultRunStage } from "./runner.js";
|
|
@@ -118,6 +119,37 @@ function feedStage(stage) {
|
|
|
118
119
|
export const NEXT_STEP_NOTE_FILE_NAME = "next-step-note.md";
|
|
119
120
|
/** The file the host writes a yak's new messages to (`attempts/inputs.ts`, `yaks/turns.ts`). */
|
|
120
121
|
export const NEW_SINCE_LAST_TURN_FILE_NAME = "new-since-last-turn.md";
|
|
122
|
+
/** The file the host names a yak's System's other repositories in (`attempts/inputs.ts`, YAG-1211). */
|
|
123
|
+
export const SYSTEM_REPOSITORIES_FILE_NAME = "system-repositories.json";
|
|
124
|
+
/**
|
|
125
|
+
* The System's other repositories the host named, by `owner/name` and
|
|
126
|
+
* folder (an absolute path, never the session's own), each with the head
|
|
127
|
+
* the attempt last pushed there and the attempt's branch; none when the
|
|
128
|
+
* file is absent or does not parse.
|
|
129
|
+
*/
|
|
130
|
+
export function systemRepositoriesOf(text, cwd) {
|
|
131
|
+
if (!text)
|
|
132
|
+
return [];
|
|
133
|
+
try {
|
|
134
|
+
const parsed = JSON.parse(text);
|
|
135
|
+
const branch = typeof parsed.branch === "string" && parsed.branch ? parsed.branch : null;
|
|
136
|
+
if (!Array.isArray(parsed.repositories))
|
|
137
|
+
return [];
|
|
138
|
+
return parsed.repositories.flatMap((entry) => {
|
|
139
|
+
const { fullName, dir, pushedHead } = (entry ?? {});
|
|
140
|
+
if (typeof fullName !== "string" || typeof dir !== "string")
|
|
141
|
+
return [];
|
|
142
|
+
if (!isAbsolute(dir) || dir.includes("..") || dir === cwd)
|
|
143
|
+
return [];
|
|
144
|
+
const pushed = typeof pushedHead === "string" && SHA.test(pushedHead) ? pushedHead : null;
|
|
145
|
+
return [{ repository: fullName, dir, pushedHead: pushed, branch }];
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const SHA = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
|
|
121
153
|
const REPORT_CONTRACT = (outDir) => `Last, write ${join(outDir, SESSION_REPORT_FILE_NAME)} as JSON, honestly: ` +
|
|
122
154
|
'{"summary": "<what you changed, in two or three sentences>", ' +
|
|
123
155
|
'"checks": [{"name": "lint", "command": "pnpm lint", "cwd": ".", "exitCode": 0, "durationMs": 41000, ' +
|
|
@@ -483,6 +515,28 @@ async function runTurn(input, deps, pulse) {
|
|
|
483
515
|
const baseSha = start.head;
|
|
484
516
|
const preRunDirt = parseChangedPaths(start.status);
|
|
485
517
|
const writes = input.stage !== "plan";
|
|
518
|
+
// A yak's System's other repositories, each as the turn found it, for the
|
|
519
|
+
// read of a writing turn's change for a placed secret (YAG-1211).
|
|
520
|
+
const others = [];
|
|
521
|
+
/** The attempt's branch the host named with them: a detached one takes it before its commit. */
|
|
522
|
+
let othersBranch = null;
|
|
523
|
+
if (writes) {
|
|
524
|
+
const listed = systemRepositoriesOf(readOrNull(join(input.inputDir, SYSTEM_REPOSITORIES_FILE_NAME)), input.cwd);
|
|
525
|
+
for (const { repository, dir, pushedHead, branch } of listed) {
|
|
526
|
+
othersBranch ??= branch;
|
|
527
|
+
const found = await snapshot(dir, input.signal);
|
|
528
|
+
others.push({
|
|
529
|
+
repository,
|
|
530
|
+
cwd: dir,
|
|
531
|
+
// Where the host's push there starts, so an earlier turn's commits it
|
|
532
|
+
// will publish are read too, never only this turn's.
|
|
533
|
+
base: found.tracked
|
|
534
|
+
? await publicationBase(exec, dir, { head: found.head, pushedHead, branch }, input.signal)
|
|
535
|
+
: null,
|
|
536
|
+
skip: parseChangedPaths(found.status),
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
}
|
|
486
540
|
const stageId = feedStage(input.stage);
|
|
487
541
|
const timeBudgetMs = input.deadlineMs === undefined
|
|
488
542
|
? undefined
|
|
@@ -564,6 +618,7 @@ async function runTurn(input, deps, pulse) {
|
|
|
564
618
|
store: deps.placedValues === undefined ? openPlacedValues() : deps.placedValues,
|
|
565
619
|
exec,
|
|
566
620
|
skip: preRunDirt,
|
|
621
|
+
others,
|
|
567
622
|
...(input.signal ? { signal: input.signal } : {}),
|
|
568
623
|
});
|
|
569
624
|
stages.push(...healed.asked);
|
|
@@ -620,6 +675,18 @@ async function runTurn(input, deps, pulse) {
|
|
|
620
675
|
planPaths: (text) => baselineDirs(input.cwd, planPaths(text), readFile).map((dir) => relative(input.cwd, dir) || "."),
|
|
621
676
|
exec,
|
|
622
677
|
writeFile,
|
|
678
|
+
// Each other repository of the System gets the same final commit,
|
|
679
|
+
// over what the turn left there (YAG-1217).
|
|
680
|
+
...(others.length > 0
|
|
681
|
+
? {
|
|
682
|
+
others: others.map((other) => ({
|
|
683
|
+
repository: other.repository,
|
|
684
|
+
cwd: other.cwd,
|
|
685
|
+
preRunDirt: other.skip ?? [],
|
|
686
|
+
})),
|
|
687
|
+
othersBranch,
|
|
688
|
+
}
|
|
689
|
+
: {}),
|
|
623
690
|
}, ran);
|
|
624
691
|
const noted = { ...done.attempt, notes: [...notes, ...done.attempt.notes] };
|
|
625
692
|
const attempt = writes
|
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.2286.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": "b3afbfd2d6403169485a62c523d0f37c0b07cf00"
|
|
62
62
|
}
|