@yagni-app/code-staging 1.2.15-staging.2581.1 → 1.2.15-staging.2594.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 +7 -0
- package/dist/extension/pipeline/sessionLane.d.ts +50 -0
- package/dist/extension/pipeline/sessionLane.js +273 -12
- package/dist/extension/pipeline/trackerWorkflow.d.ts +122 -0
- package/dist/extension/pipeline/trackerWorkflow.js +355 -0
- package/package.json +2 -2
|
@@ -137,6 +137,13 @@ export interface AttemptResult extends CloudIdentity {
|
|
|
137
137
|
* adds its own parts.
|
|
138
138
|
*/
|
|
139
139
|
pullRequestText?: string;
|
|
140
|
+
/** The repository template the description was written in (`trackerWorkflow.ts`, YAG-1477). */
|
|
141
|
+
pullRequestTemplate?: string;
|
|
142
|
+
/** The QA steps written after a clean build, and the skill that wrote them (YAG-1479). */
|
|
143
|
+
qaSteps?: {
|
|
144
|
+
text: string;
|
|
145
|
+
skill: string | null;
|
|
146
|
+
};
|
|
140
147
|
/**
|
|
141
148
|
* How a plan turn asked for the plan's UI preview left it (`sessionLane.ts`):
|
|
142
149
|
* a whole page, its word that nothing on a screen changes, or neither.
|
|
@@ -56,6 +56,7 @@ import { type PlanChange } from "./planChanges.js";
|
|
|
56
56
|
import { type ResilienceAttemptRecord } from "./resilience.js";
|
|
57
57
|
import { type RunStageDeps } from "./runner.js";
|
|
58
58
|
import { type SessionTicketPath } from "./ticketPath.js";
|
|
59
|
+
import { type QaStepsSource } from "./trackerWorkflow.js";
|
|
59
60
|
import type { JsonEvent, ModelTier, PipelineStage, StageId, StageResult, StopReason } from "./types.js";
|
|
60
61
|
import { type VerifyCheckRun } from "./verify.js";
|
|
61
62
|
import { snapshotWorkspace } from "./workspace.js";
|
|
@@ -111,6 +112,25 @@ export declare const PLAN_PREVIEW_TURN_TOOLS: string[];
|
|
|
111
112
|
* (`parseDesignDocument`): empty when it is a whole page within size. Pure.
|
|
112
113
|
*/
|
|
113
114
|
export declare function previewPageProblems(text: string | null): string[];
|
|
115
|
+
/**
|
|
116
|
+
* What the QA steps message may use (YAG-1479): reading, searching and
|
|
117
|
+
* listing files, and nothing else. No shell, no edit or write, no subagent:
|
|
118
|
+
* it cannot change a checkout, so nothing has to be put back after it. pi's
|
|
119
|
+
* `--tools` allowlist on that one launch enforces it, for built-in and
|
|
120
|
+
* extension tools alike.
|
|
121
|
+
*/
|
|
122
|
+
export declare const QA_STEPS_TURN_TOOLS: string[];
|
|
123
|
+
/**
|
|
124
|
+
* The only environment the QA steps launch gets (YAG-1479): what a pi child
|
|
125
|
+
* needs to start, reach the model and read files, by name. Everything else
|
|
126
|
+
* of the building turn's environment stays out, the GitHub token
|
|
127
|
+
* (`GH_ENTERPRISE_TOKEN`), the crash reporter's token, the inbox, the
|
|
128
|
+
* helper sessions and the telemetry headers included. `YAGNI_TOKEN` is kept
|
|
129
|
+
* because the model call itself needs it: the extension's provider sends it
|
|
130
|
+
* to YAGNI's model proxy (`config.ts` `getToken`), the only way this turn
|
|
131
|
+
* reaches a model.
|
|
132
|
+
*/
|
|
133
|
+
export declare const QA_STEPS_TURN_ENV: readonly ["PATH", "HOME", "USER", "LOGNAME", "SHELL", "LANG", "LC_ALL", "LC_CTYPE", "TZ", "TMPDIR", "TERM", "XDG_CONFIG_HOME", "NODE_ENV", "NODE_EXTRA_CA_CERTS", "NODE_USE_SYSTEM_CA", "NODE_USE_ENV_PROXY", "SSL_CERT_FILE", "SSL_CERT_DIR", "HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY", "http_proxy", "https_proxy", "no_proxy", "PI_CODING_AGENT_DIR", "PI_CODING_AGENT_SESSION_DIR", "PI_CONFIG_DIR", "PI_OTEL_DISABLED", "YAGNI_BASE_URL", "YAGNI_TOKEN", "YAGNI_TOKEN_EXPIRES_AT", "YAGNI_SESSION_ID", "YAGNI_WORKSPACE_ID", "YAGNI_CODING_AGENT_DIR", "YAGNI_CODE_HOME", "YAGNI_CODE_TMPDIR", "YAGNI_CODE_VERSION", "YAGNI_SURFACE", "YAGNI_SYSTEM_CA", "YAGNI_GO_CLOUD", "YAGNI_GO_TIER_CAP", "YAGNI_GO_STAGE_TIERS", "YAGNI_OTEL_DISABLED", "YAGNI_DISABLE_CRASH_REPORTS", "YAGNI_DISABLE_BRANDING"];
|
|
114
134
|
/** What a turn that builds may use: the plan turn's tools and the writes. */
|
|
115
135
|
export declare const BUILD_TURN_TOOLS: string[];
|
|
116
136
|
/** The run's files under the run user's home: its one session, and the playbook it runs on. */
|
|
@@ -174,6 +194,13 @@ export interface TurnFacts {
|
|
|
174
194
|
* Absent on a Team that is not a yak, whose turns read as they always did.
|
|
175
195
|
*/
|
|
176
196
|
workingStyle?: SessionWorkingStyle | null;
|
|
197
|
+
/**
|
|
198
|
+
* The repository's pull request template, by its path, where the host's
|
|
199
|
+
* `tracker-workflow.json` asks for it and the checkout has one (YAG-1477):
|
|
200
|
+
* the description is written in its sections. Absent, the contract is as
|
|
201
|
+
* it always was.
|
|
202
|
+
*/
|
|
203
|
+
pullRequestTemplate?: string | null;
|
|
177
204
|
}
|
|
178
205
|
/** The file the host writes when a yak approves its own plans (`attempts/inputs.ts`, `yaks/ownPlans.ts`). */
|
|
179
206
|
export declare const OWN_PLANS_FILE_NAME = "own-plans.md";
|
|
@@ -421,6 +448,29 @@ export declare function heartbeatLine(pulse: TurnPulse, stage: StageId, at: numb
|
|
|
421
448
|
* Never throws for the model's sake.
|
|
422
449
|
*/
|
|
423
450
|
export declare function runSessionTurn(input: SessionTurnInput, deps?: SessionTurnDeps): Promise<SessionTurnOutcome>;
|
|
451
|
+
export declare function writeQaSteps(source: QaStepsSource, turn: (message: string, stage?: PipelineStage) => Promise<StageResult>, buildStage: PipelineStage, io: {
|
|
452
|
+
cwd: string;
|
|
453
|
+
inputDir: string;
|
|
454
|
+
outDir: string;
|
|
455
|
+
readOrNull: (path: string) => string | null;
|
|
456
|
+
writeFile: (path: string, text: string) => void;
|
|
457
|
+
/** The build's change, given up front (`changeForQaSteps`). */
|
|
458
|
+
change?: string;
|
|
459
|
+
/** The System's other repositories this session works in: named, their changes not shown. */
|
|
460
|
+
otherRepositories?: readonly string[];
|
|
461
|
+
}): Promise<{
|
|
462
|
+
steps: {
|
|
463
|
+
text: string;
|
|
464
|
+
skill: string | null;
|
|
465
|
+
} | null;
|
|
466
|
+
asked: StageResult | null;
|
|
467
|
+
note: string | null;
|
|
468
|
+
/**
|
|
469
|
+
* For the session's log only, never the attempt: the failure's name and
|
|
470
|
+
* its message through `scrubSecrets`, capped at `QA_STEPS_ERROR_LOG_CHARS`.
|
|
471
|
+
*/
|
|
472
|
+
logged?: string;
|
|
473
|
+
}>;
|
|
424
474
|
/** `result.json` written again; one that cannot be written says so in its own notes, which the stream carries. */
|
|
425
475
|
/** The env var the turn's execution id reaches the model calls by. */
|
|
426
476
|
export declare const EXECUTION_ID_ENV = "YAGNI_EXECUTION_ID";
|
|
@@ -55,7 +55,7 @@ import { logEvent } from "../errorSink.js";
|
|
|
55
55
|
import { openPlacedValues } from "../placedValues.js";
|
|
56
56
|
import { scanChange } from "./changeScan.js";
|
|
57
57
|
import { CODE_WRITER_ENV, ignoredCodeWriter, resolveCodeWriter, } from "./codeWriter.js";
|
|
58
|
-
import { completeCloudSession, RESULT_FILE_NAME, } from "./cloud.js";
|
|
58
|
+
import { completeCloudSession, RESULT_FILE_NAME, resultUsage, } from "./cloud.js";
|
|
59
59
|
import { finishExec } from "./finish.js";
|
|
60
60
|
import { HELPER_SESSIONS_DIR_ENV } from "./helperSessions.js";
|
|
61
61
|
import { MISSION_CHECKS_FILE_NAME, readMissionChecksFile } from "./missionChecks.js";
|
|
@@ -72,6 +72,7 @@ import { scrubSecrets } from "./scrubSecrets.js";
|
|
|
72
72
|
import { DECISIONS_READ_TOOL, PIECES_RULE, YAK_FOLLOW_UPS_RULE, PLAN_JSON_CONTRACT, YAK_PLAN_JSON_CONTRACT, } from "./stages.js";
|
|
73
73
|
import { planReviewRoundsFor, planSizeOf, sessionTicketPathOf, TICKET_PATH_FILE_NAME, } from "./ticketPath.js";
|
|
74
74
|
import { SESSION_PLAN_MINUTES, STAGE_WRAP_UP_GRACE_MS } from "./stageClock.js";
|
|
75
|
+
import { findPullRequestTemplate, changeForQaSteps, FETCHED_BASE_REF, pullRequestBaseOf, findRepositorySkill, listRepositorySkills, QA_STEPS_FILE_NAME, qaStepsMessage, qaStepsOf, repositorySkillsTrusted, TRACKER_WORKFLOW_FILE_NAME, templateRule, trackerWorkflowOf, } from "./trackerWorkflow.js";
|
|
75
76
|
import { editsMostlyFailed } from "./events.js";
|
|
76
77
|
import { DEFAULT_RESILIENCE_POLICY } from "./types.js";
|
|
77
78
|
import { baselineDirs, parseChangedPaths, planPaths } from "./verify.js";
|
|
@@ -158,6 +159,71 @@ export function previewPageProblems(text) {
|
|
|
158
159
|
}
|
|
159
160
|
return problems;
|
|
160
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* What the QA steps message may use (YAG-1479): reading, searching and
|
|
164
|
+
* listing files, and nothing else. No shell, no edit or write, no subagent:
|
|
165
|
+
* it cannot change a checkout, so nothing has to be put back after it. pi's
|
|
166
|
+
* `--tools` allowlist on that one launch enforces it, for built-in and
|
|
167
|
+
* extension tools alike.
|
|
168
|
+
*/
|
|
169
|
+
export const QA_STEPS_TURN_TOOLS = ["read", "grep", "find", "ls"];
|
|
170
|
+
/**
|
|
171
|
+
* The only environment the QA steps launch gets (YAG-1479): what a pi child
|
|
172
|
+
* needs to start, reach the model and read files, by name. Everything else
|
|
173
|
+
* of the building turn's environment stays out, the GitHub token
|
|
174
|
+
* (`GH_ENTERPRISE_TOKEN`), the crash reporter's token, the inbox, the
|
|
175
|
+
* helper sessions and the telemetry headers included. `YAGNI_TOKEN` is kept
|
|
176
|
+
* because the model call itself needs it: the extension's provider sends it
|
|
177
|
+
* to YAGNI's model proxy (`config.ts` `getToken`), the only way this turn
|
|
178
|
+
* reaches a model.
|
|
179
|
+
*/
|
|
180
|
+
export const QA_STEPS_TURN_ENV = [
|
|
181
|
+
"PATH",
|
|
182
|
+
"HOME",
|
|
183
|
+
"USER",
|
|
184
|
+
"LOGNAME",
|
|
185
|
+
"SHELL",
|
|
186
|
+
"LANG",
|
|
187
|
+
"LC_ALL",
|
|
188
|
+
"LC_CTYPE",
|
|
189
|
+
"TZ",
|
|
190
|
+
"TMPDIR",
|
|
191
|
+
"TERM",
|
|
192
|
+
"XDG_CONFIG_HOME",
|
|
193
|
+
"NODE_ENV",
|
|
194
|
+
"NODE_EXTRA_CA_CERTS",
|
|
195
|
+
"NODE_USE_SYSTEM_CA",
|
|
196
|
+
"NODE_USE_ENV_PROXY",
|
|
197
|
+
"SSL_CERT_FILE",
|
|
198
|
+
"SSL_CERT_DIR",
|
|
199
|
+
"HTTP_PROXY",
|
|
200
|
+
"HTTPS_PROXY",
|
|
201
|
+
"NO_PROXY",
|
|
202
|
+
"http_proxy",
|
|
203
|
+
"https_proxy",
|
|
204
|
+
"no_proxy",
|
|
205
|
+
"PI_CODING_AGENT_DIR",
|
|
206
|
+
"PI_CODING_AGENT_SESSION_DIR",
|
|
207
|
+
"PI_CONFIG_DIR",
|
|
208
|
+
"PI_OTEL_DISABLED",
|
|
209
|
+
"YAGNI_BASE_URL",
|
|
210
|
+
"YAGNI_TOKEN",
|
|
211
|
+
"YAGNI_TOKEN_EXPIRES_AT",
|
|
212
|
+
"YAGNI_SESSION_ID",
|
|
213
|
+
"YAGNI_WORKSPACE_ID",
|
|
214
|
+
"YAGNI_CODING_AGENT_DIR",
|
|
215
|
+
"YAGNI_CODE_HOME",
|
|
216
|
+
"YAGNI_CODE_TMPDIR",
|
|
217
|
+
"YAGNI_CODE_VERSION",
|
|
218
|
+
"YAGNI_SURFACE",
|
|
219
|
+
"YAGNI_SYSTEM_CA",
|
|
220
|
+
"YAGNI_GO_CLOUD",
|
|
221
|
+
"YAGNI_GO_TIER_CAP",
|
|
222
|
+
"YAGNI_GO_STAGE_TIERS",
|
|
223
|
+
"YAGNI_OTEL_DISABLED",
|
|
224
|
+
"YAGNI_DISABLE_CRASH_REPORTS",
|
|
225
|
+
"YAGNI_DISABLE_BRANDING",
|
|
226
|
+
];
|
|
161
227
|
/** What a turn that builds may use: the plan turn's tools and the writes. */
|
|
162
228
|
export const BUILD_TURN_TOOLS = [
|
|
163
229
|
...PLAN_TURN_TOOLS,
|
|
@@ -223,7 +289,14 @@ export function systemRepositoriesOf(text, cwd) {
|
|
|
223
289
|
if (!isAbsolute(dir) || dir.includes("..") || dir === cwd)
|
|
224
290
|
return [];
|
|
225
291
|
const pushed = typeof pushedHead === "string" && SHA.test(pushedHead) ? pushedHead : null;
|
|
226
|
-
return [
|
|
292
|
+
return [
|
|
293
|
+
{
|
|
294
|
+
repository: fullName,
|
|
295
|
+
dir,
|
|
296
|
+
pushedHead: pushed,
|
|
297
|
+
branch,
|
|
298
|
+
},
|
|
299
|
+
];
|
|
227
300
|
});
|
|
228
301
|
}
|
|
229
302
|
catch {
|
|
@@ -270,7 +343,7 @@ const NARRATION_RULE = "Narrate as you go, in one short line each: when you star
|
|
|
270
343
|
* `working-style.json`) say when it may stop by its working style; every
|
|
271
344
|
* other Team's read as they always did.
|
|
272
345
|
*/
|
|
273
|
-
const BUILD_RULES = (outDir, who, yak = null) => [
|
|
346
|
+
const BUILD_RULES = (outDir, who, yak = null, template = null) => [
|
|
274
347
|
"Write tools are on now. Work as your playbook says:",
|
|
275
348
|
`- ${NARRATION_RULE}`,
|
|
276
349
|
"- Prefer the smallest change that meets the ticket, and keep the diff to what the ticket needs.",
|
|
@@ -280,7 +353,7 @@ const BUILD_RULES = (outDir, who, yak = null) => [
|
|
|
280
353
|
"- 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.",
|
|
281
354
|
"- Commit on the branch you are on. Never push and never open or edit a pull request: YAGNI pushes your commits and opens it.",
|
|
282
355
|
`- ${yak ? workingStyleAskRule(yak.style, outDir, yak.review) : NEEDS_PERSON_RULE(outDir)}`,
|
|
283
|
-
`- ${PULL_REQUEST_CONTRACT(outDir, yak !== null)}`,
|
|
356
|
+
`- ${PULL_REQUEST_CONTRACT(outDir, yak !== null)}${template ? templateRule(template) : ""}`,
|
|
284
357
|
`- ${REPORT_CONTRACT(outDir)}`,
|
|
285
358
|
].join("\n");
|
|
286
359
|
const INPUTS = (inputDir) => [
|
|
@@ -490,7 +563,7 @@ export function turnMessage(facts) {
|
|
|
490
563
|
parts.push(note);
|
|
491
564
|
if (newSince)
|
|
492
565
|
parts.push(newSince);
|
|
493
|
-
parts.push(BUILD_RULES(facts.outDir, facts.codeWriter ?? { writer: "session" }, facts.workingStyle ? { style: facts.workingStyle, review: facts.review === true } : null));
|
|
566
|
+
parts.push(BUILD_RULES(facts.outDir, facts.codeWriter ?? { writer: "session" }, facts.workingStyle ? { style: facts.workingStyle, review: facts.review === true } : null, facts.pullRequestTemplate ?? null));
|
|
494
567
|
return parts.join("\n\n");
|
|
495
568
|
}
|
|
496
569
|
const MAX_REPORTED_CHECKS = 40;
|
|
@@ -1050,11 +1123,48 @@ async function runTurn(input, deps, pulse, tally) {
|
|
|
1050
1123
|
},
|
|
1051
1124
|
now,
|
|
1052
1125
|
};
|
|
1126
|
+
// The QA steps message's launch (YAG-1479), from an explicit read-only set,
|
|
1127
|
+
// never a copy of the building turn's: its environment by name
|
|
1128
|
+
// (`QA_STEPS_TURN_ENV`: no inbox, so a person's message waits unreceipted
|
|
1129
|
+
// for a turn that can act on it; no helper sessions; no GitHub token), and
|
|
1130
|
+
// not write-capable for the retry paths. Its tools are `QA_STEPS_TURN_TOOLS`.
|
|
1131
|
+
const qaRunDeps = {
|
|
1132
|
+
cwd: input.cwd,
|
|
1133
|
+
env: {
|
|
1134
|
+
...Object.fromEntries(QA_STEPS_TURN_ENV.flatMap((name) => {
|
|
1135
|
+
const value = input.childEnv[name];
|
|
1136
|
+
return value === undefined ? [] : [[name, value]];
|
|
1137
|
+
})),
|
|
1138
|
+
[SESSION_INPUT_DIR_ENV]: input.inputDir,
|
|
1139
|
+
...(EXECUTION_ID.test(input.identity.executionId)
|
|
1140
|
+
? { [EXECUTION_ID_ENV]: input.identity.executionId }
|
|
1141
|
+
: {}),
|
|
1142
|
+
},
|
|
1143
|
+
sessionFile: paths.sessionFile,
|
|
1144
|
+
callerLabel: SESSION_CALLER_LABEL,
|
|
1145
|
+
...(input.runId ? { attribution: { runId: input.runId } } : {}),
|
|
1146
|
+
...(input.signal ? { signal: input.signal } : {}),
|
|
1147
|
+
...(input.extraArgs?.length ? { extraArgs: input.extraArgs } : {}),
|
|
1148
|
+
stageWriteCapable: false,
|
|
1149
|
+
personaBody: () => WORK_A_TICKET_SKILL,
|
|
1150
|
+
writePrompt: async () => ({ filePath: paths.skillFile, cleanup: () => undefined }),
|
|
1151
|
+
onEvent: (event) => {
|
|
1152
|
+
notePulse(pulse, event, now());
|
|
1153
|
+
input.emit({ ...event, yagni: { stage: stageId } });
|
|
1154
|
+
},
|
|
1155
|
+
now,
|
|
1156
|
+
};
|
|
1053
1157
|
// What the host said about how this ticket runs (YAG-1306); null on every
|
|
1054
1158
|
// ticket that is not a one-session yak's.
|
|
1055
1159
|
const ticketPath = sessionTicketPathOf(readOrNull(join(input.inputDir, TICKET_PATH_FILE_NAME)));
|
|
1056
1160
|
// A yak ticket's working style: when a writing turn may stop for a person.
|
|
1057
1161
|
const workingStyle = sessionWorkingStyleOf(readOrNull(join(input.inputDir, WORKING_STYLE_FILE_NAME)));
|
|
1162
|
+
// `tracker.workflow` (YAG-1477, YAG-1479): only a writing turn, only where
|
|
1163
|
+
// the host wrote the file; every other turn reads as it did.
|
|
1164
|
+
const workflow = writes
|
|
1165
|
+
? trackerWorkflowOf(readOrNull(join(input.inputDir, TRACKER_WORKFLOW_FILE_NAME)))
|
|
1166
|
+
: null;
|
|
1167
|
+
const pullRequestTemplate = workflow?.template ? findPullRequestTemplate(input.cwd) : null;
|
|
1058
1168
|
// A stage's rows say when a turn takes the same stage up again (YAG-1306):
|
|
1059
1169
|
// the host resumed a stage an earlier turn stopped in, or this is one more
|
|
1060
1170
|
// message of this turn (a re-ask, a review round). A count of stages then
|
|
@@ -1062,7 +1172,7 @@ async function runTurn(input, deps, pulse, tally) {
|
|
|
1062
1172
|
let stageOpened = Boolean(input.continuation?.priorStop);
|
|
1063
1173
|
/** The plan review round whose turn is running, for its stage rows; null outside one. */
|
|
1064
1174
|
let reviewRound = null;
|
|
1065
|
-
const turn = async (message) => {
|
|
1175
|
+
const turn = async (message, stage = turnStage, deps = runDeps) => {
|
|
1066
1176
|
// Only on a one-session ticket: every other ticket's stream is as it was.
|
|
1067
1177
|
const marks = ticketPath
|
|
1068
1178
|
? {
|
|
@@ -1074,7 +1184,7 @@ async function runTurn(input, deps, pulse, tally) {
|
|
|
1074
1184
|
const began = now();
|
|
1075
1185
|
input.emit({ type: "pipeline_stage", stage: stageId, phase: "start", ...marks, at: began });
|
|
1076
1186
|
try {
|
|
1077
|
-
const result = await runStage(withClock(
|
|
1187
|
+
const result = await runStage(withClock(stage), { ticket: message }, deps);
|
|
1078
1188
|
// Counted as each message ends, so a turn that throws later still counts it.
|
|
1079
1189
|
tally.messages.push(result);
|
|
1080
1190
|
return result;
|
|
@@ -1112,11 +1222,13 @@ async function runTurn(input, deps, pulse, tally) {
|
|
|
1112
1222
|
codeWriter: resolveCodeWriter(input.childEnv),
|
|
1113
1223
|
...(ticketPath ? { ticketPath } : {}),
|
|
1114
1224
|
...(workingStyle ? { workingStyle } : {}),
|
|
1225
|
+
...(pullRequestTemplate ? { pullRequestTemplate } : {}),
|
|
1115
1226
|
});
|
|
1116
1227
|
const notes = [];
|
|
1117
1228
|
const stages = [];
|
|
1118
1229
|
let planText = "";
|
|
1119
1230
|
let uiPreview = null;
|
|
1231
|
+
let qaSteps = null;
|
|
1120
1232
|
let ran;
|
|
1121
1233
|
try {
|
|
1122
1234
|
let run = await turn(message);
|
|
@@ -1271,16 +1383,90 @@ async function runTurn(input, deps, pulse, tally) {
|
|
|
1271
1383
|
}
|
|
1272
1384
|
: {}),
|
|
1273
1385
|
}, ran);
|
|
1386
|
+
// The turn's result as it ends: the model's account and its ask for a
|
|
1387
|
+
// person folded in. Read once before the QA steps (they run only for a
|
|
1388
|
+
// build whose final result is clean) and once after, with their notes.
|
|
1389
|
+
const accountOf = (base) => writes
|
|
1390
|
+
? withNeedsPerson(withSessionAccount(base, parseSessionReport(readOrNull(join(input.outDir, SESSION_REPORT_FILE_NAME)), knownBaselines(input.inputDir, readFile)), pullRequestTextOf(readOrNull(join(input.outDir, PULL_REQUEST_FILE_NAME)))), readNeedsPerson(readOrNull(needsPersonFile)))
|
|
1391
|
+
: uiPreview
|
|
1392
|
+
? { ...base, uiPreview }
|
|
1393
|
+
: base;
|
|
1394
|
+
const finalStop = accountOf({
|
|
1395
|
+
...done.attempt,
|
|
1396
|
+
notes: [...notes, ...done.attempt.notes],
|
|
1397
|
+
}).stopReason;
|
|
1398
|
+
// The QA steps for the change (YAG-1479), only for a build whose final
|
|
1399
|
+
// result is clean and complete (never one that stops to ask a person, or
|
|
1400
|
+
// changed nothing): one more message that can only read
|
|
1401
|
+
// (`QA_STEPS_TURN_TOOLS`), given the change up front. A message that
|
|
1402
|
+
// fails or writes nothing never fails the build.
|
|
1403
|
+
if (writes &&
|
|
1404
|
+
workflow?.qaSteps &&
|
|
1405
|
+
done.ok &&
|
|
1406
|
+
finalStop === "clean" &&
|
|
1407
|
+
input.signal?.aborted !== true) {
|
|
1408
|
+
// The steps describe the ticket's own repository's pull request, from
|
|
1409
|
+
// the commit the host names as where it starts. The System's other
|
|
1410
|
+
// repositories are named and not diffed: their checkouts hold no fetched
|
|
1411
|
+
// base to read a pull request's start from, and the host's comment says
|
|
1412
|
+
// their changes are not covered. A start not named, or not in the
|
|
1413
|
+
// history, is unreadable, and no steps are written; the note says why.
|
|
1414
|
+
const baseOf = async (cwd, sha, fetchedBaseRef) => {
|
|
1415
|
+
const found = await pullRequestBaseOf(exec, cwd, sha, input.signal, fetchedBaseRef);
|
|
1416
|
+
return "sha" in found ? { base: found.sha } : { base: null, noBase: found.reason };
|
|
1417
|
+
};
|
|
1418
|
+
const change = await changeForQaSteps([
|
|
1419
|
+
{
|
|
1420
|
+
repository: "This repository",
|
|
1421
|
+
cwd: input.cwd,
|
|
1422
|
+
// The base as the host last fetched it, where it did (every turn
|
|
1423
|
+
// that can follow a base merge); else the commit it names.
|
|
1424
|
+
...(await baseOf(input.cwd, workflow.baseSha, FETCHED_BASE_REF)),
|
|
1425
|
+
},
|
|
1426
|
+
], exec, input.signal);
|
|
1427
|
+
if (change.unread.length > 0) {
|
|
1428
|
+
// Steps written without seeing the change are worse than none.
|
|
1429
|
+
const note = `No QA steps for this build: ${change.unread
|
|
1430
|
+
.map((u) => `the change in ${u.repository} could not be read (${u.reason})`)
|
|
1431
|
+
.join("; ")}.`;
|
|
1432
|
+
notes.push(note);
|
|
1433
|
+
input.writeErr(note);
|
|
1434
|
+
}
|
|
1435
|
+
else {
|
|
1436
|
+
const steps = await writeQaSteps(workflow.qaSteps, (message, stage) => turn(message, stage, qaRunDeps), turnStage, {
|
|
1437
|
+
cwd: input.cwd,
|
|
1438
|
+
inputDir: input.inputDir,
|
|
1439
|
+
outDir: input.outDir,
|
|
1440
|
+
readOrNull,
|
|
1441
|
+
writeFile,
|
|
1442
|
+
change: change.text,
|
|
1443
|
+
otherRepositories: others.map((other) => other.repository),
|
|
1444
|
+
});
|
|
1445
|
+
if (steps.asked)
|
|
1446
|
+
stages.push(steps.asked);
|
|
1447
|
+
if (steps.note) {
|
|
1448
|
+
notes.push(steps.note);
|
|
1449
|
+
input.writeErr(steps.logged ?? steps.note);
|
|
1450
|
+
}
|
|
1451
|
+
qaSteps = steps.steps;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1274
1454
|
const noted = {
|
|
1275
1455
|
...done.attempt,
|
|
1456
|
+
// The spend, once, from every message this turn ran, the QA steps message
|
|
1457
|
+
// included: the finish's total was read before that message ran.
|
|
1458
|
+
usage: resultUsage({ stages: "result" in ran ? ran.result.stages : ran.partial, rounds: [] }),
|
|
1276
1459
|
notes: [...notes, ...done.attempt.notes],
|
|
1277
1460
|
...turnPromptFacts(input.childEnv),
|
|
1278
1461
|
};
|
|
1279
|
-
const
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1462
|
+
const accounted = accountOf(noted);
|
|
1463
|
+
// The template the description was written in, and the QA steps
|
|
1464
|
+
// (`tracker.workflow`): only on the turn that wrote them.
|
|
1465
|
+
const attempt = {
|
|
1466
|
+
...accounted,
|
|
1467
|
+
...(pullRequestTemplate && accounted.pullRequestText ? { pullRequestTemplate } : {}),
|
|
1468
|
+
...(qaSteps ? { qaSteps } : {}),
|
|
1469
|
+
};
|
|
1284
1470
|
// The cloud lane's finish wrote `result.json`; it is written again with
|
|
1285
1471
|
// what this turn adds to it (the model's account, the plan turn's put-back,
|
|
1286
1472
|
// how it left its UI preview, the system prompt it ran on).
|
|
@@ -1289,6 +1475,81 @@ async function runTurn(input, deps, pulse, tally) {
|
|
|
1289
1475
|
const ok = writes ? done.ok && attempt.stopReason === "clean" : done.ok;
|
|
1290
1476
|
return { ok, attempt };
|
|
1291
1477
|
}
|
|
1478
|
+
/**
|
|
1479
|
+
* The QA steps after a clean build (YAG-1479): one more message in the same
|
|
1480
|
+
* session, on read-only tools only (`QA_STEPS_TURN_TOOLS`), given the change up front, whose last message is the
|
|
1481
|
+
* steps. The repository's skills are offered only where they are trusted.
|
|
1482
|
+
* The steps go to `qa-steps.md` and the result. A message that fails, or
|
|
1483
|
+
* leaves nothing, is a note: the build stands as it was. Never throws.
|
|
1484
|
+
*/
|
|
1485
|
+
/** How a QA steps turn that did not complete is named on the attempt, by `turnStop`'s reason. */
|
|
1486
|
+
const QA_STEPS_EARLY_STOP = {
|
|
1487
|
+
failed: "error",
|
|
1488
|
+
aborted: "aborted",
|
|
1489
|
+
budget_exceeded: "out of time",
|
|
1490
|
+
};
|
|
1491
|
+
/** How much of a failed QA steps write's (scrubbed) message the session log keeps. */
|
|
1492
|
+
const QA_STEPS_ERROR_LOG_CHARS = 200;
|
|
1493
|
+
export async function writeQaSteps(source, turn, buildStage, io) {
|
|
1494
|
+
// The message, once it answered: a stage that ran stays in the stage list
|
|
1495
|
+
// (and its spend in the usage), whatever happens to its output after.
|
|
1496
|
+
let asked = null;
|
|
1497
|
+
try {
|
|
1498
|
+
const trusted = repositorySkillsTrusted(io.readOrNull(join(io.inputDir, "sources.json")));
|
|
1499
|
+
// A named skill is looked up by its name, whatever the listing's cap;
|
|
1500
|
+
// only automatic selection reads the (capped) list.
|
|
1501
|
+
let skills = [];
|
|
1502
|
+
if (source.source === "skill") {
|
|
1503
|
+
const named = findRepositorySkill(io.cwd, trusted, source.skill);
|
|
1504
|
+
if (named)
|
|
1505
|
+
skills = [named];
|
|
1506
|
+
}
|
|
1507
|
+
else {
|
|
1508
|
+
skills = listRepositorySkills(io.cwd, trusted);
|
|
1509
|
+
}
|
|
1510
|
+
asked = await turn(qaStepsMessage(source, skills, io.change ?? "", io.otherRepositories ?? []), {
|
|
1511
|
+
...buildStage,
|
|
1512
|
+
tools: QA_STEPS_TURN_TOOLS,
|
|
1513
|
+
});
|
|
1514
|
+
// Only a turn that completed normally, by the same rule as every other
|
|
1515
|
+
// turn (`turnStop`): a child can exit 0 on an error or aborted stop, its
|
|
1516
|
+
// earlier partial text still kept, and that text is no steps.
|
|
1517
|
+
const { stop } = turnStop(asked, false, false);
|
|
1518
|
+
if (stop !== "clean") {
|
|
1519
|
+
// A fixed phrase per reason: no words of the model's or the error's.
|
|
1520
|
+
return {
|
|
1521
|
+
steps: null,
|
|
1522
|
+
asked,
|
|
1523
|
+
note: `The QA steps turn stopped early (${QA_STEPS_EARLY_STOP[stop] ?? "error"}); no steps were written.`,
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
const steps = qaStepsOf(asked.finalOutput, skills);
|
|
1527
|
+
if (!steps) {
|
|
1528
|
+
return {
|
|
1529
|
+
steps: null,
|
|
1530
|
+
asked,
|
|
1531
|
+
note: "The QA steps message left no steps; the ticket's tracker issue gets none for this push.",
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
io.writeFile(join(io.outDir, QA_STEPS_FILE_NAME), `${steps.text}\n`);
|
|
1535
|
+
return { steps, asked, note: null };
|
|
1536
|
+
}
|
|
1537
|
+
catch (err) {
|
|
1538
|
+
// A fixed sentence on the attempt: the error's own words never travel
|
|
1539
|
+
// there. The session's log line gets its shape, scrubbed and capped.
|
|
1540
|
+
const name = err instanceof Error ? err.name : typeof err;
|
|
1541
|
+
const said = scrubSecrets(err instanceof Error ? err.message : String(err))
|
|
1542
|
+
.replace(/\s+/g, " ")
|
|
1543
|
+
.trim()
|
|
1544
|
+
.slice(0, QA_STEPS_ERROR_LOG_CHARS);
|
|
1545
|
+
return {
|
|
1546
|
+
steps: null,
|
|
1547
|
+
asked,
|
|
1548
|
+
note: "The QA steps could not be written; the build stands.",
|
|
1549
|
+
logged: `QA steps write failed: ${name}${said ? `: ${said}` : ""}`,
|
|
1550
|
+
};
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1292
1553
|
/** The re-ask that recovers a plan whose plan-json block did not read. */
|
|
1293
1554
|
const PLAN_BLOCK_REASK = "Your last message did not end with a plan-json block that reads. Send the whole plan again as " +
|
|
1294
1555
|
"your last message, ending with the plan-json block exactly as the contract says.";
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** The file the host writes the switch's parts in (`TRACKER_WORKFLOW_INPUT_FILE`). */
|
|
2
|
+
export declare const TRACKER_WORKFLOW_FILE_NAME = "tracker-workflow.json";
|
|
3
|
+
/** The QA steps as this process writes them, beside the report. */
|
|
4
|
+
export declare const QA_STEPS_FILE_NAME = "qa-steps.md";
|
|
5
|
+
/** The most of the steps a result carries (the host's `MAX_QA_STEPS_CHARS`). */
|
|
6
|
+
export declare const MAX_QA_STEPS_CHARS = 8000;
|
|
7
|
+
export type QaStepsSource = {
|
|
8
|
+
source: "auto";
|
|
9
|
+
} | {
|
|
10
|
+
source: "skill";
|
|
11
|
+
skill: string;
|
|
12
|
+
};
|
|
13
|
+
export interface TrackerWorkflow {
|
|
14
|
+
template: boolean;
|
|
15
|
+
qaSteps: QaStepsSource | null;
|
|
16
|
+
/** The commit the ticket's pull request starts from, as the host names it; null when not told. */
|
|
17
|
+
baseSha: string | null;
|
|
18
|
+
}
|
|
19
|
+
/** A full commit id, or null. */
|
|
20
|
+
export declare function commitShaOf(value: unknown): string | null;
|
|
21
|
+
/** `tracker-workflow.json` as the host wrote it, or null when absent or unreadable. */
|
|
22
|
+
export declare function trackerWorkflowOf(text: string | null): TrackerWorkflow | null;
|
|
23
|
+
/**
|
|
24
|
+
* The repository's pull request template, by its path in the checkout:
|
|
25
|
+
* `pull_request_template.md` in `.github/`, the root, then `docs/` (any
|
|
26
|
+
* case), else the one file of a `PULL_REQUEST_TEMPLATE/` folder there. A
|
|
27
|
+
* folder of several templates names none: which one a pull request takes is
|
|
28
|
+
* the opener's choice, and a guess is not made. Null when there is none.
|
|
29
|
+
*/
|
|
30
|
+
export declare function findPullRequestTemplate(cwd: string): string | null;
|
|
31
|
+
/** The contract's words for a repository template: its sections, its order, honestly. */
|
|
32
|
+
export declare function templateRule(path: string): string;
|
|
33
|
+
/** One skill the repository has, as its `SKILL.md` front matter names it. */
|
|
34
|
+
export interface RepositorySkill {
|
|
35
|
+
name: string;
|
|
36
|
+
description: string;
|
|
37
|
+
path: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The skills the repository has (`.claude/skills/<name>/SKILL.md`,
|
|
41
|
+
* `.agents/skills/<name>/SKILL.md`), by name, description and path; none
|
|
42
|
+
* where the repository's skills are not trusted. Read here, never by a
|
|
43
|
+
* registry: the repository is the only source.
|
|
44
|
+
*/
|
|
45
|
+
export declare function listRepositorySkills(cwd: string, trusted: boolean): RepositorySkill[];
|
|
46
|
+
/**
|
|
47
|
+
* The skill a setting names, looked up by that name directly, whatever the
|
|
48
|
+
* listing's cap: null where the repository has none by that name (or its
|
|
49
|
+
* skills are not trusted).
|
|
50
|
+
*/
|
|
51
|
+
export declare function findRepositorySkill(cwd: string, trusted: boolean, name: string): RepositorySkill | null;
|
|
52
|
+
/** Whether `sources.json` says the repository's own skills are trusted. */
|
|
53
|
+
export declare function repositorySkillsTrusted(sourcesText: string | null): boolean;
|
|
54
|
+
type Exec = (argv: string[], cwd: string, signal?: AbortSignal) => Promise<{
|
|
55
|
+
code: number;
|
|
56
|
+
output: string;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Where a checkout's pull request starts: the commit the host names for it
|
|
60
|
+
* (the attempt's base for the ticket's repository, the first wake's head for
|
|
61
|
+
* each other one), which the checkout holds as an ancestor of HEAD. The
|
|
62
|
+
* host names a commit, not a branch: the session's checkouts keep no
|
|
63
|
+
* remote-tracking refs. No guess: a commit not named, or not in this
|
|
64
|
+
* checkout's history, gives a reason a person can act on, and that
|
|
65
|
+
* repository's change counts as unreadable.
|
|
66
|
+
*/
|
|
67
|
+
/**
|
|
68
|
+
* The base branch as the host last fetched it into the ticket's checkout
|
|
69
|
+
* (`SESSION_MERGED_BASE_REF` in the backend's `attempts/session.ts`): on
|
|
70
|
+
* every reused or resumed turn (`fetchTurnRefs`) and on every turn that
|
|
71
|
+
* merges the base (`mergeBaseIntoCheckout`), so on every turn that can
|
|
72
|
+
* follow a base merge. A first build has none, and no merge either.
|
|
73
|
+
*/
|
|
74
|
+
export declare const FETCHED_BASE_REF = "refs/yagni/base";
|
|
75
|
+
export declare function pullRequestBaseOf(exec: Exec, cwd: string, baseSha: string | null, signal?: AbortSignal,
|
|
76
|
+
/** The ticket's checkout only: where the host fetched the base, when it did. */
|
|
77
|
+
fetchedBaseRef?: string): Promise<{
|
|
78
|
+
sha: string;
|
|
79
|
+
} | {
|
|
80
|
+
reason: string;
|
|
81
|
+
}>;
|
|
82
|
+
/** The most of the change the QA steps message is given, across every repository. */
|
|
83
|
+
export declare const MAX_QA_CHANGE_CHARS = 60000;
|
|
84
|
+
/**
|
|
85
|
+
* The build's change, as the QA steps message is given it up front (YAG-1479):
|
|
86
|
+
* per repository, the files it changed and its diff since where its pull
|
|
87
|
+
* request starts (the whole pull request, on every turn, never one turn's
|
|
88
|
+
* change), bounded. The message has read-only tools and no shell, so it is
|
|
89
|
+
* handed what git would have told it. `unread` names each repository whose
|
|
90
|
+
* change could not be read; the caller then writes no steps at all, since
|
|
91
|
+
* steps written without the change are worse than none. Never throws.
|
|
92
|
+
*/
|
|
93
|
+
export declare function changeForQaSteps(repositories: ReadonlyArray<{
|
|
94
|
+
repository: string;
|
|
95
|
+
cwd: string;
|
|
96
|
+
base: string | null;
|
|
97
|
+
/** Why there is no base, in words a person can act on. */
|
|
98
|
+
noBase?: string;
|
|
99
|
+
}>, exec: Exec, signal?: AbortSignal): Promise<{
|
|
100
|
+
text: string;
|
|
101
|
+
unread: Array<{
|
|
102
|
+
repository: string;
|
|
103
|
+
reason: string;
|
|
104
|
+
}>;
|
|
105
|
+
}>;
|
|
106
|
+
/**
|
|
107
|
+
* The message that asks for the QA steps, after a clean build: which skill
|
|
108
|
+
* to use (the named one, the best fit among the repository's, or none), and
|
|
109
|
+
* the answer's shape. Nothing in the repository is to change.
|
|
110
|
+
*/
|
|
111
|
+
export declare function qaStepsMessage(source: QaStepsSource, skills: readonly RepositorySkill[], change?: string, otherRepositories?: readonly string[]): string;
|
|
112
|
+
/**
|
|
113
|
+
* The turn's answer as the result carries it: the steps without the first
|
|
114
|
+
* line, and the skill that line names when it is one of the repository's;
|
|
115
|
+
* the yak's own words otherwise. Null when nothing is left.
|
|
116
|
+
*/
|
|
117
|
+
export declare function qaStepsOf(answer: string, skills: readonly RepositorySkill[]): {
|
|
118
|
+
text: string;
|
|
119
|
+
skill: string | null;
|
|
120
|
+
} | null;
|
|
121
|
+
export {};
|
|
122
|
+
//# sourceMappingURL=trackerWorkflow.d.ts.map
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a building turn does where the workspace's `tracker.workflow` switch
|
|
3
|
+
* is on (the host writes `tracker-workflow.json` beside the ticket only
|
|
4
|
+
* there, `attempts/inputs.ts`):
|
|
5
|
+
*
|
|
6
|
+
* - The pull request's description follows the repository's own template
|
|
7
|
+
* (YAG-1477): this process finds the template in the checkout
|
|
8
|
+
* ({@link findPullRequestTemplate}) and the turn's contract tells the
|
|
9
|
+
* model to write `pull-request.md` in its sections; the result names the
|
|
10
|
+
* template (`pullRequestTemplate`) so the host folds its own parts after
|
|
11
|
+
* them.
|
|
12
|
+
* - The QA steps for the change (YAG-1479): after a clean build, one more
|
|
13
|
+
* message in the same session, read-only, whose last message is the
|
|
14
|
+
* steps. A repository skill is offered only where the repository's skills
|
|
15
|
+
* are trusted (`sources.json`'s `repo.trusted`); with none that fits, or
|
|
16
|
+
* none trusted, the yak writes them in its own words. This process writes
|
|
17
|
+
* them to `qa-steps.md` and the result carries them (`qaSteps`).
|
|
18
|
+
*
|
|
19
|
+
* Without the file, every turn reads exactly as it did.
|
|
20
|
+
*/
|
|
21
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
22
|
+
import { join, relative } from "node:path";
|
|
23
|
+
import { scrubSecrets } from "./scrubSecrets.js";
|
|
24
|
+
/** The file the host writes the switch's parts in (`TRACKER_WORKFLOW_INPUT_FILE`). */
|
|
25
|
+
export const TRACKER_WORKFLOW_FILE_NAME = "tracker-workflow.json";
|
|
26
|
+
/** The QA steps as this process writes them, beside the report. */
|
|
27
|
+
export const QA_STEPS_FILE_NAME = "qa-steps.md";
|
|
28
|
+
/** The most of the steps a result carries (the host's `MAX_QA_STEPS_CHARS`). */
|
|
29
|
+
export const MAX_QA_STEPS_CHARS = 8_000;
|
|
30
|
+
const COMMIT = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
|
|
31
|
+
/** A full commit id, or null. */
|
|
32
|
+
export function commitShaOf(value) {
|
|
33
|
+
return typeof value === "string" && COMMIT.test(value) ? value : null;
|
|
34
|
+
}
|
|
35
|
+
const SKILL_NAME = /^[A-Za-z0-9][A-Za-z0-9._ -]{0,99}$/;
|
|
36
|
+
/** `tracker-workflow.json` as the host wrote it, or null when absent or unreadable. */
|
|
37
|
+
export function trackerWorkflowOf(text) {
|
|
38
|
+
if (!text)
|
|
39
|
+
return null;
|
|
40
|
+
try {
|
|
41
|
+
const parsed = JSON.parse(text);
|
|
42
|
+
if (parsed.version !== 1)
|
|
43
|
+
return null;
|
|
44
|
+
const qa = (parsed.qaSteps ?? null);
|
|
45
|
+
const qaSteps = qa?.source === "auto"
|
|
46
|
+
? { source: "auto" }
|
|
47
|
+
: qa?.source === "skill" && typeof qa.skill === "string" && SKILL_NAME.test(qa.skill)
|
|
48
|
+
? { source: "skill", skill: qa.skill }
|
|
49
|
+
: null;
|
|
50
|
+
return {
|
|
51
|
+
template: parsed.template === true,
|
|
52
|
+
qaSteps,
|
|
53
|
+
baseSha: commitShaOf(parsed.baseSha),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Where GitHub looks for a pull request template, in its own order. */
|
|
61
|
+
const TEMPLATE_DIRS = [".github", "", "docs"];
|
|
62
|
+
const TEMPLATE_FILE = /^pull_request_template\.(md|markdown|txt)$/i;
|
|
63
|
+
const TEMPLATE_DIR = /^pull_request_template$/i;
|
|
64
|
+
/** One directory's entries, or none when it cannot be read. */
|
|
65
|
+
function entriesOf(dir) {
|
|
66
|
+
try {
|
|
67
|
+
return readdirSync(dir).sort();
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function isFile(path) {
|
|
74
|
+
try {
|
|
75
|
+
return statSync(path).isFile();
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The repository's pull request template, by its path in the checkout:
|
|
83
|
+
* `pull_request_template.md` in `.github/`, the root, then `docs/` (any
|
|
84
|
+
* case), else the one file of a `PULL_REQUEST_TEMPLATE/` folder there. A
|
|
85
|
+
* folder of several templates names none: which one a pull request takes is
|
|
86
|
+
* the opener's choice, and a guess is not made. Null when there is none.
|
|
87
|
+
*/
|
|
88
|
+
export function findPullRequestTemplate(cwd) {
|
|
89
|
+
for (const sub of TEMPLATE_DIRS) {
|
|
90
|
+
const dir = sub ? join(cwd, sub) : cwd;
|
|
91
|
+
const entries = entriesOf(dir);
|
|
92
|
+
const file = entries.find((name) => TEMPLATE_FILE.test(name) && isFile(join(dir, name)));
|
|
93
|
+
if (file)
|
|
94
|
+
return relative(cwd, join(dir, file));
|
|
95
|
+
const folder = entries.find((name) => TEMPLATE_DIR.test(name));
|
|
96
|
+
if (!folder)
|
|
97
|
+
continue;
|
|
98
|
+
const files = entriesOf(join(dir, folder)).filter((name) => /\.(md|markdown|txt)$/i.test(name) && isFile(join(dir, folder, name)));
|
|
99
|
+
if (files.length === 1 && files[0])
|
|
100
|
+
return relative(cwd, join(dir, folder, files[0]));
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
/** The contract's words for a repository template: its sections, its order, honestly. */
|
|
105
|
+
export function templateRule(path) {
|
|
106
|
+
return (` The repository has a pull request template at ${path}: read it, and write the description in its sections, ` +
|
|
107
|
+
"in its order, with its headings. Fill each section honestly: a checklist item you did not do stays unticked, " +
|
|
108
|
+
"and a section you have nothing for says so in a few words. Treat its HTML comments as instructions to follow, " +
|
|
109
|
+
"never as text to keep, and leave no HTML comment in the file. Everything above still holds inside its sections.");
|
|
110
|
+
}
|
|
111
|
+
const SKILL_ROOTS = [".claude/skills", ".agents/skills"];
|
|
112
|
+
const MAX_SKILLS = 40;
|
|
113
|
+
function frontMatter(text) {
|
|
114
|
+
const match = text.match(/^---\r?\n([\s\S]{0,4000}?)\r?\n---/);
|
|
115
|
+
if (!match?.[1])
|
|
116
|
+
return {};
|
|
117
|
+
const fields = {};
|
|
118
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
119
|
+
const field = line.match(/^([A-Za-z_-]+):\s*(.*)$/);
|
|
120
|
+
if (field?.[1] && field[2] !== undefined) {
|
|
121
|
+
fields[field[1].toLowerCase()] = field[2].replace(/^["']|["']$/g, "").trim();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return fields;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The skills the repository has (`.claude/skills/<name>/SKILL.md`,
|
|
128
|
+
* `.agents/skills/<name>/SKILL.md`), by name, description and path; none
|
|
129
|
+
* where the repository's skills are not trusted. Read here, never by a
|
|
130
|
+
* registry: the repository is the only source.
|
|
131
|
+
*/
|
|
132
|
+
export function listRepositorySkills(cwd, trusted) {
|
|
133
|
+
if (!trusted)
|
|
134
|
+
return [];
|
|
135
|
+
const seen = new Map();
|
|
136
|
+
for (const root of SKILL_ROOTS) {
|
|
137
|
+
for (const entry of entriesOf(join(cwd, root))) {
|
|
138
|
+
const skill = skillAt(cwd, root, entry);
|
|
139
|
+
if (!skill || seen.has(skill.name.toLowerCase()))
|
|
140
|
+
continue;
|
|
141
|
+
seen.set(skill.name.toLowerCase(), skill);
|
|
142
|
+
// The cap is for automatic selection's list only.
|
|
143
|
+
if (seen.size >= MAX_SKILLS)
|
|
144
|
+
return [...seen.values()];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return [...seen.values()];
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The skill a setting names, looked up by that name directly, whatever the
|
|
151
|
+
* listing's cap: null where the repository has none by that name (or its
|
|
152
|
+
* skills are not trusted).
|
|
153
|
+
*/
|
|
154
|
+
export function findRepositorySkill(cwd, trusted, name) {
|
|
155
|
+
if (!trusted)
|
|
156
|
+
return null;
|
|
157
|
+
const wanted = name.toLowerCase();
|
|
158
|
+
for (const root of SKILL_ROOTS) {
|
|
159
|
+
for (const entry of entriesOf(join(cwd, root))) {
|
|
160
|
+
const skill = skillAt(cwd, root, entry);
|
|
161
|
+
if (skill && skill.name.toLowerCase() === wanted)
|
|
162
|
+
return skill;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
/** One skill folder's `SKILL.md`, by name, description and path; null when it is not one. */
|
|
168
|
+
function skillAt(cwd, root, entry) {
|
|
169
|
+
const file = join(cwd, root, entry, "SKILL.md");
|
|
170
|
+
if (!existsSync(file) || !isFile(file))
|
|
171
|
+
return null;
|
|
172
|
+
let text = "";
|
|
173
|
+
try {
|
|
174
|
+
text = readFileSync(file, "utf8").slice(0, 8_000);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
const fields = frontMatter(text);
|
|
180
|
+
const name = (fields.name || entry).slice(0, 100);
|
|
181
|
+
if (!SKILL_NAME.test(name))
|
|
182
|
+
return null;
|
|
183
|
+
return {
|
|
184
|
+
name,
|
|
185
|
+
description: (fields.description ?? "").replace(/\s+/g, " ").slice(0, 300),
|
|
186
|
+
path: relative(cwd, file),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/** Whether `sources.json` says the repository's own skills are trusted. */
|
|
190
|
+
export function repositorySkillsTrusted(sourcesText) {
|
|
191
|
+
if (!sourcesText)
|
|
192
|
+
return false;
|
|
193
|
+
try {
|
|
194
|
+
const parsed = JSON.parse(sourcesText);
|
|
195
|
+
return parsed.repo?.trusted === true;
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Where a checkout's pull request starts: the commit the host names for it
|
|
203
|
+
* (the attempt's base for the ticket's repository, the first wake's head for
|
|
204
|
+
* each other one), which the checkout holds as an ancestor of HEAD. The
|
|
205
|
+
* host names a commit, not a branch: the session's checkouts keep no
|
|
206
|
+
* remote-tracking refs. No guess: a commit not named, or not in this
|
|
207
|
+
* checkout's history, gives a reason a person can act on, and that
|
|
208
|
+
* repository's change counts as unreadable.
|
|
209
|
+
*/
|
|
210
|
+
/**
|
|
211
|
+
* The base branch as the host last fetched it into the ticket's checkout
|
|
212
|
+
* (`SESSION_MERGED_BASE_REF` in the backend's `attempts/session.ts`): on
|
|
213
|
+
* every reused or resumed turn (`fetchTurnRefs`) and on every turn that
|
|
214
|
+
* merges the base (`mergeBaseIntoCheckout`), so on every turn that can
|
|
215
|
+
* follow a base merge. A first build has none, and no merge either.
|
|
216
|
+
*/
|
|
217
|
+
export const FETCHED_BASE_REF = "refs/yagni/base";
|
|
218
|
+
export async function pullRequestBaseOf(exec, cwd, baseSha, signal,
|
|
219
|
+
/** The ticket's checkout only: where the host fetched the base, when it did. */
|
|
220
|
+
fetchedBaseRef) {
|
|
221
|
+
// After a merge of a newer base the pull request starts at the merge-base
|
|
222
|
+
// with that base, never the attempt's first base: the merged-in upstream
|
|
223
|
+
// work is not the pull request's.
|
|
224
|
+
if (fetchedBaseRef) {
|
|
225
|
+
const at = await exec(["git", "-c", "core.hooksPath=/dev/null", "merge-base", "HEAD", fetchedBaseRef], cwd, signal).catch(() => ({ code: -1, output: "" }));
|
|
226
|
+
const sha = at.output.trim();
|
|
227
|
+
if (at.code === 0 && COMMIT.test(sha))
|
|
228
|
+
return { sha };
|
|
229
|
+
}
|
|
230
|
+
if (!baseSha) {
|
|
231
|
+
return {
|
|
232
|
+
reason: "YAGNI did not say which commit its pull request starts from, so what the pull request changes cannot be told; the next build YAGNI prepares there writes the steps",
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
const found = await exec(["git", "-c", "core.hooksPath=/dev/null", "merge-base", "--is-ancestor", baseSha, "HEAD"], cwd, signal).catch(() => ({ code: -1, output: "" }));
|
|
236
|
+
if (found.code === 0)
|
|
237
|
+
return { sha: baseSha };
|
|
238
|
+
return {
|
|
239
|
+
reason: `the commit its pull request starts from (${baseSha.slice(0, 7)}) is not in this checkout's history, which happens when the branch was rewritten; a build from the pull request's current branch writes the steps`,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/** The most of the change the QA steps message is given, across every repository. */
|
|
243
|
+
export const MAX_QA_CHANGE_CHARS = 60_000;
|
|
244
|
+
/**
|
|
245
|
+
* The build's change, as the QA steps message is given it up front (YAG-1479):
|
|
246
|
+
* per repository, the files it changed and its diff since where its pull
|
|
247
|
+
* request starts (the whole pull request, on every turn, never one turn's
|
|
248
|
+
* change), bounded. The message has read-only tools and no shell, so it is
|
|
249
|
+
* handed what git would have told it. `unread` names each repository whose
|
|
250
|
+
* change could not be read; the caller then writes no steps at all, since
|
|
251
|
+
* steps written without the change are worse than none. Never throws.
|
|
252
|
+
*/
|
|
253
|
+
export async function changeForQaSteps(repositories, exec, signal) {
|
|
254
|
+
const unread = [];
|
|
255
|
+
const parts = [];
|
|
256
|
+
let left = MAX_QA_CHANGE_CHARS;
|
|
257
|
+
for (const repo of repositories) {
|
|
258
|
+
const git = (...args) => exec(["git", "-c", "core.hooksPath=/dev/null", ...args], repo.cwd, signal).catch(() => ({
|
|
259
|
+
code: -1,
|
|
260
|
+
output: "",
|
|
261
|
+
}));
|
|
262
|
+
if (!repo.base) {
|
|
263
|
+
unread.push({
|
|
264
|
+
repository: repo.repository,
|
|
265
|
+
reason: repo.noBase ?? "YAGNI did not say which commit its pull request starts from",
|
|
266
|
+
});
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const files = await git("diff", "--name-status", `${repo.base}..HEAD`);
|
|
270
|
+
const diff = await git("diff", "--no-color", "--no-ext-diff", `${repo.base}..HEAD`);
|
|
271
|
+
if (files.code !== 0 || diff.code !== 0) {
|
|
272
|
+
const failed = files.code !== 0 ? files : diff;
|
|
273
|
+
// The tail of what git said, through the lane's redaction, bounded.
|
|
274
|
+
const tail = scrubSecrets(failed.output).trim().split("\n").slice(-3).join(" ").slice(-300);
|
|
275
|
+
unread.push({
|
|
276
|
+
repository: repo.repository,
|
|
277
|
+
reason: `git failed, exit ${failed.code}${tail ? `: ${tail}` : ""}`,
|
|
278
|
+
});
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (!files.output.trim())
|
|
282
|
+
continue;
|
|
283
|
+
const text = diff.output.length > left
|
|
284
|
+
? `${diff.output.slice(0, Math.max(0, left))}\n(The diff is cut here; read the files for the rest.)`
|
|
285
|
+
: diff.output;
|
|
286
|
+
left -= Math.min(diff.output.length, left);
|
|
287
|
+
parts.push(`## ${repo.repository}\n\nFiles changed:\n${files.output.trim()}\n\n\`\`\`diff\n${text.trimEnd()}\n\`\`\``);
|
|
288
|
+
}
|
|
289
|
+
return { text: parts.join("\n\n"), unread };
|
|
290
|
+
}
|
|
291
|
+
/** The first line of the turn's answer when the yak wrote the steps itself. */
|
|
292
|
+
const OWN_WORDS = "written-by: yak";
|
|
293
|
+
/**
|
|
294
|
+
* The message that asks for the QA steps, after a clean build: which skill
|
|
295
|
+
* to use (the named one, the best fit among the repository's, or none), and
|
|
296
|
+
* the answer's shape. Nothing in the repository is to change.
|
|
297
|
+
*/
|
|
298
|
+
export function qaStepsMessage(source, skills, change = "", otherRepositories = []) {
|
|
299
|
+
const named = source.source === "skill"
|
|
300
|
+
? skills.find((skill) => skill.name.toLowerCase() === source.skill.toLowerCase())
|
|
301
|
+
: undefined;
|
|
302
|
+
const lines = [
|
|
303
|
+
"The build is done. Now write the QA steps for this change: what a tester does, step by step, to check it works, " +
|
|
304
|
+
"on the screens and flows it touches, with what they should see at each step. " +
|
|
305
|
+
"Write for a person who has not read the code. Plain steps, no command output, no secret or environment value, " +
|
|
306
|
+
"no mention of anyone. You can read files, and search and list them; you cannot run commands or change anything. " +
|
|
307
|
+
"The change is below; read the files it touches as you need.",
|
|
308
|
+
"How to write them (where a skill you follow gives a format, its format governs; these rules apply where it is silent, and always to your own words):",
|
|
309
|
+
"- Fit the length to the change: the fewest steps that test it. A small change gets a few steps. For an ordinary change, about 10 steps and about 1,500 characters at most; shorter is better.",
|
|
310
|
+
"- Each step is what the tester does in the application and what they should see: the screen, the action, the expected result. No section of prerequisites unless the tester truly needs one thing set up first, and then one line; no list of what they need.",
|
|
311
|
+
"- If the change has nothing to test in the running application (documentation, comments, an internal refactor with no change in behaviour), say so in one sentence and give at most three checks, or none.",
|
|
312
|
+
"- Edge cases: only ones specific to this change where a tester could plausibly see a different result; at most three, and none is fine. No generic ones.",
|
|
313
|
+
"- Never judge the change: do not say whether the code or the wording is correct, and do not reassure. Only say what to do and what should be seen.",
|
|
314
|
+
"- No pass-criteria section that restates the steps.",
|
|
315
|
+
];
|
|
316
|
+
if (named) {
|
|
317
|
+
lines.push(`Use the repository's ${named.name} skill to write them: read ${named.path} and follow it.`, `Start your last message with the line "written-by: skill ${named.name}".`);
|
|
318
|
+
}
|
|
319
|
+
else if (source.source === "auto" && skills.length > 0) {
|
|
320
|
+
lines.push("The repository has these skills (name: what it is for):", ...skills.map((skill) => `- ${skill.name}: ${skill.description || "(no description)"} (${skill.path})`), "If one of them is for writing QA or test steps for a change, read its SKILL.md and follow it, and start your " +
|
|
321
|
+
'last message with the line "written-by: skill <its name>". If none fits, write the steps in your own words ' +
|
|
322
|
+
`and start your last message with the line "${OWN_WORDS}".`);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
lines.push(`Write the steps in your own words, and start your last message with the line "${OWN_WORDS}".`);
|
|
326
|
+
}
|
|
327
|
+
lines.push("Where a skill says to run a command, you cannot: write the steps from what you can read.", "Your last message is the steps, in Markdown, and nothing else.");
|
|
328
|
+
if (otherRepositories.length > 0) {
|
|
329
|
+
lines.push(`This build also works in ${otherRepositories.join(", ")}. Their changes are not shown here and the steps do not cover them: write the steps for this repository's change.`);
|
|
330
|
+
}
|
|
331
|
+
if (change.trim())
|
|
332
|
+
lines.push("", "The change, as the build committed it:", "", change);
|
|
333
|
+
return lines.join("\n");
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* The turn's answer as the result carries it: the steps without the first
|
|
337
|
+
* line, and the skill that line names when it is one of the repository's;
|
|
338
|
+
* the yak's own words otherwise. Null when nothing is left.
|
|
339
|
+
*/
|
|
340
|
+
export function qaStepsOf(answer, skills) {
|
|
341
|
+
const trimmed = answer.trim();
|
|
342
|
+
if (!trimmed)
|
|
343
|
+
return null;
|
|
344
|
+
const [first = "", ...rest] = trimmed.split(/\r?\n/);
|
|
345
|
+
const said = first.trim().match(/^written-by:\s*(?:skill\s+(.+)|yak)\s*$/i);
|
|
346
|
+
const body = (said ? rest.join("\n") : trimmed).trim().slice(0, MAX_QA_STEPS_CHARS);
|
|
347
|
+
if (!body)
|
|
348
|
+
return null;
|
|
349
|
+
const claimed = said?.[1]?.trim().toLowerCase();
|
|
350
|
+
const skill = claimed
|
|
351
|
+
? (skills.find((s) => s.name.toLowerCase() === claimed)?.name ?? null)
|
|
352
|
+
: null;
|
|
353
|
+
return { text: body, skill };
|
|
354
|
+
}
|
|
355
|
+
//# sourceMappingURL=trackerWorkflow.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yagni-app/code-staging",
|
|
3
|
-
"version": "1.2.15-staging.
|
|
3
|
+
"version": "1.2.15-staging.2594.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": "25126ec6429f90ed337088607a80c80d827a653b"
|
|
62
62
|
}
|