@yagni-app/code-staging 1.2.14-staging.2282.1 → 1.2.14-staging.2283.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,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
|
}
|
|
@@ -98,6 +98,20 @@ export interface TurnFacts {
|
|
|
98
98
|
export declare const NEXT_STEP_NOTE_FILE_NAME = "next-step-note.md";
|
|
99
99
|
/** The file the host writes a yak's new messages to (`attempts/inputs.ts`, `yaks/turns.ts`). */
|
|
100
100
|
export declare const NEW_SINCE_LAST_TURN_FILE_NAME = "new-since-last-turn.md";
|
|
101
|
+
/** The file the host names a yak's System's other repositories in (`attempts/inputs.ts`, YAG-1211). */
|
|
102
|
+
export declare const SYSTEM_REPOSITORIES_FILE_NAME = "system-repositories.json";
|
|
103
|
+
/**
|
|
104
|
+
* The System's other repositories the host named, by `owner/name` and
|
|
105
|
+
* folder (an absolute path, never the session's own), each with the head
|
|
106
|
+
* the attempt last pushed there and the attempt's branch; none when the
|
|
107
|
+
* file is absent or does not parse.
|
|
108
|
+
*/
|
|
109
|
+
export declare function systemRepositoriesOf(text: string | null, cwd: string): Array<{
|
|
110
|
+
repository: string;
|
|
111
|
+
dir: string;
|
|
112
|
+
pushedHead: string | null;
|
|
113
|
+
branch: string | null;
|
|
114
|
+
}>;
|
|
101
115
|
/** The one message a turn sends the session. Pure. */
|
|
102
116
|
export declare function turnMessage(facts: TurnFacts): string;
|
|
103
117
|
/** The model's own account of a turn that builds (`session-report.json`). */
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
*/
|
|
41
41
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
42
42
|
import { homedir } from "node:os";
|
|
43
|
-
import { join, relative } from "node:path";
|
|
43
|
+
import { isAbsolute, join, relative } from "node:path";
|
|
44
44
|
import { openPlacedValues } from "../placedValues.js";
|
|
45
45
|
import { scanChange } from "./changeScan.js";
|
|
46
46
|
import { completeCloudSession, RESULT_FILE_NAME, } from "./cloud.js";
|
|
@@ -48,7 +48,7 @@ import { finishExec } from "./finish.js";
|
|
|
48
48
|
import { MISSION_CHECKS_FILE_NAME, readMissionChecksFile } from "./missionChecks.js";
|
|
49
49
|
import { creditExhaustionReason } from "./orchestrator.js";
|
|
50
50
|
import { WORK_A_TICKET_SKILL } from "./personas.js";
|
|
51
|
-
import { healPlacedSecrets } from "./placedValueHeal.js";
|
|
51
|
+
import { healPlacedSecrets, publicationBase } from "./placedValueHeal.js";
|
|
52
52
|
import { extractPlanJson } from "./planOutput.js";
|
|
53
53
|
import { PLAN_CHANGES_RULE, parsePlanChanges, planChangeNote, } from "./planChanges.js";
|
|
54
54
|
import { runStage as defaultRunStage } from "./runner.js";
|
|
@@ -118,6 +118,37 @@ function feedStage(stage) {
|
|
|
118
118
|
export const NEXT_STEP_NOTE_FILE_NAME = "next-step-note.md";
|
|
119
119
|
/** The file the host writes a yak's new messages to (`attempts/inputs.ts`, `yaks/turns.ts`). */
|
|
120
120
|
export const NEW_SINCE_LAST_TURN_FILE_NAME = "new-since-last-turn.md";
|
|
121
|
+
/** The file the host names a yak's System's other repositories in (`attempts/inputs.ts`, YAG-1211). */
|
|
122
|
+
export const SYSTEM_REPOSITORIES_FILE_NAME = "system-repositories.json";
|
|
123
|
+
/**
|
|
124
|
+
* The System's other repositories the host named, by `owner/name` and
|
|
125
|
+
* folder (an absolute path, never the session's own), each with the head
|
|
126
|
+
* the attempt last pushed there and the attempt's branch; none when the
|
|
127
|
+
* file is absent or does not parse.
|
|
128
|
+
*/
|
|
129
|
+
export function systemRepositoriesOf(text, cwd) {
|
|
130
|
+
if (!text)
|
|
131
|
+
return [];
|
|
132
|
+
try {
|
|
133
|
+
const parsed = JSON.parse(text);
|
|
134
|
+
const branch = typeof parsed.branch === "string" && parsed.branch ? parsed.branch : null;
|
|
135
|
+
if (!Array.isArray(parsed.repositories))
|
|
136
|
+
return [];
|
|
137
|
+
return parsed.repositories.flatMap((entry) => {
|
|
138
|
+
const { fullName, dir, pushedHead } = (entry ?? {});
|
|
139
|
+
if (typeof fullName !== "string" || typeof dir !== "string")
|
|
140
|
+
return [];
|
|
141
|
+
if (!isAbsolute(dir) || dir.includes("..") || dir === cwd)
|
|
142
|
+
return [];
|
|
143
|
+
const pushed = typeof pushedHead === "string" && SHA.test(pushedHead) ? pushedHead : null;
|
|
144
|
+
return [{ repository: fullName, dir, pushedHead: pushed, branch }];
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const SHA = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
|
|
121
152
|
const REPORT_CONTRACT = (outDir) => `Last, write ${join(outDir, SESSION_REPORT_FILE_NAME)} as JSON, honestly: ` +
|
|
122
153
|
'{"summary": "<what you changed, in two or three sentences>", ' +
|
|
123
154
|
'"checks": [{"name": "lint", "command": "pnpm lint", "cwd": ".", "exitCode": 0, "durationMs": 41000, ' +
|
|
@@ -483,6 +514,25 @@ async function runTurn(input, deps, pulse) {
|
|
|
483
514
|
const baseSha = start.head;
|
|
484
515
|
const preRunDirt = parseChangedPaths(start.status);
|
|
485
516
|
const writes = input.stage !== "plan";
|
|
517
|
+
// A yak's System's other repositories, each as the turn found it, for the
|
|
518
|
+
// read of a writing turn's change for a placed secret (YAG-1211).
|
|
519
|
+
const others = [];
|
|
520
|
+
if (writes) {
|
|
521
|
+
const listed = systemRepositoriesOf(readOrNull(join(input.inputDir, SYSTEM_REPOSITORIES_FILE_NAME)), input.cwd);
|
|
522
|
+
for (const { repository, dir, pushedHead, branch } of listed) {
|
|
523
|
+
const found = await snapshot(dir, input.signal);
|
|
524
|
+
others.push({
|
|
525
|
+
repository,
|
|
526
|
+
cwd: dir,
|
|
527
|
+
// Where the host's push there starts, so an earlier turn's commits it
|
|
528
|
+
// will publish are read too, never only this turn's.
|
|
529
|
+
base: found.tracked
|
|
530
|
+
? await publicationBase(exec, dir, { head: found.head, pushedHead, branch }, input.signal)
|
|
531
|
+
: null,
|
|
532
|
+
skip: parseChangedPaths(found.status),
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
}
|
|
486
536
|
const stageId = feedStage(input.stage);
|
|
487
537
|
const timeBudgetMs = input.deadlineMs === undefined
|
|
488
538
|
? undefined
|
|
@@ -564,6 +614,7 @@ async function runTurn(input, deps, pulse) {
|
|
|
564
614
|
store: deps.placedValues === undefined ? openPlacedValues() : deps.placedValues,
|
|
565
615
|
exec,
|
|
566
616
|
skip: preRunDirt,
|
|
617
|
+
others,
|
|
567
618
|
...(input.signal ? { signal: input.signal } : {}),
|
|
568
619
|
});
|
|
569
620
|
stages.push(...healed.asked);
|
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.2283.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": "070b30a13ecb2f930f932a574a84bc43a19f903b"
|
|
62
62
|
}
|