@kitman-sh/software-engineering 0.13.7 → 0.13.9

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/bundle.js CHANGED
@@ -19385,7 +19385,8 @@ var ticketsProblem = (tickets) => {
19385
19385
  const { blocked } = wavesOf(tickets);
19386
19386
  return blocked.length === 0 ? undefined : cycleMessage(blocked);
19387
19387
  };
19388
- var PlanTickets = ArraySchema(PlanTicket).check(makeFilter2((tickets) => ticketsProblem(tickets) ?? true));
19388
+ var planTicketsOf = (ticket) => ArraySchema(ticket).check(makeFilter2((tickets) => ticketsProblem(tickets) ?? true));
19389
+ var PlanTickets = planTicketsOf(PlanTicket);
19389
19390
 
19390
19391
  class BlockingCycle extends TaggedError3()("BlockingCycle", {
19391
19392
  tickets: ArraySchema(String5)
@@ -21174,6 +21175,12 @@ var deliveryLayerWords = {
21174
21175
  workspace: "the Workspace"
21175
21176
  };
21176
21177
 
21178
+ // src/reviewed-scope.ts
21179
+ var ReviewedScope = Struct({
21180
+ ...ScopeJudgement.fields,
21181
+ reported: optional2(ArraySchema(String5))
21182
+ });
21183
+
21177
21184
  // src/text-limits.ts
21178
21185
  var bounded2 = (maxLength, description) => String5.check(isMaxLength(maxLength)).annotate({ description });
21179
21186
  var OneSentence = bounded2(300, "One sentence, at most 300 characters.");
@@ -21209,6 +21216,7 @@ var Input = Struct({
21209
21216
  claims: optional2(ArraySchema(String5)),
21210
21217
  earlier: optional2(ArraySchema(MergedFinding)),
21211
21218
  reviewed: optional2(String5),
21219
+ scope: optional2(ReviewedScope),
21212
21220
  failing: optional2(ArraySchema(String5)),
21213
21221
  notRun: optional2(ArraySchema(String5)),
21214
21222
  next: optional2(Literals(choices)),
@@ -21224,11 +21232,14 @@ var SeatFinding = Struct({
21224
21232
  checked: optional2(ArraySchema(ShortStatement)),
21225
21233
  outsideFix: optional2(Boolean3)
21226
21234
  });
21227
- var ReviewedScope = Struct({
21228
- ...ScopeJudgement.fields,
21229
- reported: optional2(ArraySchema(String5))
21230
- });
21231
21235
  var agreedScope = (scope) => scope.unmet.length === 0 && (scope.reported ?? []).length > 0 ? { ...scope, met: true } : scope;
21236
+ var carriedScope = (judged, earlier) => {
21237
+ if (judged === undefined)
21238
+ return earlier;
21239
+ const scope = agreedScope(judged);
21240
+ const reported = [...new Set([...earlier?.reported ?? [], ...scope.reported ?? []])].filter((item) => !scope.unmet.includes(item));
21241
+ return earlier === undefined || reported.length === 0 ? scope : { ...scope, reported };
21242
+ };
21232
21243
  var SeatOutput = Struct({
21233
21244
  summary: OneSentence,
21234
21245
  findings: ArraySchema(SeatFinding),
@@ -21265,13 +21276,14 @@ class ReviewBaseUnpinned extends TaggedError3()("ReviewBaseUnpinned", {
21265
21276
  message: String5
21266
21277
  }) {
21267
21278
  }
21279
+ var unfetchable = (head) => `If the Runner cannot fetch revision ${head} (a fork, say), report exactly that as your only finding, a blocker, and stop.`;
21268
21280
  var targetOf = (input, { base, head, branches, epic }) => {
21269
21281
  if (epic !== undefined)
21270
21282
  return `the epic's whole change \`git diff ${base}...${head}\` in your checkout: epic branch \`${epic.branch}\` against default branch \`${epic.defaultBranch}\`, as they stood when this review started. Fetch both from \`origin\` and diff exactly those commits, even if either branch has moved since.`;
21271
21283
  if (input.changeRequestId !== undefined && branches !== undefined) {
21272
21284
  const { source, target } = branches;
21273
21285
  const from = source === undefined ? "" : ` from source branch \`${source}\``;
21274
- return `ChangeRequest ${input.changeRequestId} at revision ${head}: \`git diff ${base}...${head}\`, its change${from} into target branch \`${target}\` as that stood when this review started. This names all you need of the ChangeRequest, so look nothing up: fetch \`${source ?? head}\` and \`${target}\` from \`origin\`, and diff exactly those commits even if either branch has moved since. If the Runner cannot fetch revision ${head} (a fork, say), report exactly that as your only finding, a blocker, and stop.`;
21286
+ return `ChangeRequest ${input.changeRequestId} at revision ${head}: \`git diff ${base}...${head}\`, its change${from} into target branch \`${target}\` as that stood when this review started. This names all you need of the ChangeRequest, so look nothing up: fetch \`${source ?? head}\` and \`${target}\` from \`origin\`, and diff exactly those commits even if either branch has moved since. ${unfetchable(head)}`;
21275
21287
  }
21276
21288
  if (input.files === undefined && input.approved !== undefined)
21277
21289
  return [
@@ -21312,39 +21324,78 @@ var pinnedRange = (input) => gen2(function* () {
21312
21324
  return { base, head };
21313
21325
  });
21314
21326
  var wholeChange = (input) => input.files === undefined && input.approved === undefined;
21315
- var scopePrompt = (input) => [
21316
- "If your brief has a Task, judge its scope and give it as `scope`: does the change do what the Task's description and each of its Acceptance Criteria ask? Judge it against what is still agreed: a criterion or part an answer under your brief's Answers so far put out of scope is reported, not unmet; list each in `reported`, one line each, and leave it out of `unmet`. Set `met` to true only if the change does all the rest, and list in `unmet` one line for each other criterion or part of the description that is not done. If your brief has no Task, leave `scope` out.",
21317
- ...input.outcome === undefined ? [] : [`The Outcome to prove is ${input.outcome}.`],
21318
- ...input.claims === undefined || input.claims.length === 0 ? [] : [
21319
- "The implementer claims it built these. Check them against the code rather than taking them on trust:",
21320
- ...input.claims.map((claim) => `- ${claim}`)
21321
- ]
21327
+ var wholeScopePrompt = "If your brief has a Task, judge its scope and give it as `scope`: does the change do what the Task's description and each of its Acceptance Criteria ask? Judge it against what is still agreed: a criterion or part an answer under your brief's Answers so far put out of scope is reported, not unmet; list each in `reported`, one line each, and leave it out of `unmet`. Set `met` to true only if the change does all the rest, and list in `unmet` one line for each other criterion or part of the description that is not done. If your brief has no Task, leave `scope` out.";
21328
+ var rejudgedScopePrompt = (unmet) => [
21329
+ [
21330
+ "If your brief has a Task, judge its scope again and give it as `scope`. An earlier round judged what the Task's description and Acceptance Criteria ask, and that stands, so do not judge all of it again.",
21331
+ ...unmet.length === 0 ? ["It found nothing unmet."] : [
21332
+ "It found these unmet. Judge each of these again, against the code at the head, and list each that is still not done in `unmet`, in the same words:",
21333
+ ...unmet.map((item) => `- ${item}`)
21334
+ ]
21335
+ ].join(`
21336
+ `),
21337
+ "Also list in `unmet`, one line each, any criterion or part the fix undoes. What an answer under your brief's Answers so far put out of scope is reported, not unmet: list each of these in `reported` instead. Set `met` to true only if `unmet` is empty. If your brief has no Task, leave `scope` out."
21322
21338
  ].join(`
21323
21339
 
21324
21340
  `);
21325
- var exhaustivePrompt = [
21326
- "Review exhaustively, in this one pass. For each rule or check the change adds or alters, such as who may read or change what, a validation, a limit or a state transition, trace it through every caller and every input it can get before you report: each kind of actor, each visibility, Team and Project scope, and ids the caller gives.",
21341
+ var fixRound = (input) => (input.earlier?.length ?? 0) > 0 || input.reviewed !== undefined;
21342
+ var scopeToRejudge = (input) => fixRound(input) && (input.scope?.met === true || (input.scope?.unmet.length ?? 0) > 0) ? input.scope : undefined;
21343
+ var scopePrompt = (input) => {
21344
+ const earlier = scopeToRejudge(input);
21345
+ return [
21346
+ earlier === undefined ? wholeScopePrompt : rejudgedScopePrompt(earlier.unmet),
21347
+ ...input.outcome === undefined ? [] : [`The Outcome to prove is ${input.outcome}.`],
21348
+ ...input.claims === undefined || input.claims.length === 0 ? [] : [
21349
+ earlier === undefined ? "The implementer claims it built these. Check them against the code rather than taking them on trust:" : "The implementer claims these. Check those about the fix or an unmet item against the code rather than taking them on trust:",
21350
+ ...input.claims.map((claim) => `- ${claim}`)
21351
+ ]
21352
+ ].join(`
21353
+
21354
+ `);
21355
+ };
21356
+ var exhaustivePrompt = (subject) => [
21357
+ `Review exhaustively, in this one pass. For each rule or check ${subject} adds or alters, such as who may read or change what, a validation, a limit or a state transition, trace it through every caller and every input it can get before you report: each kind of actor, each visibility, Team and Project scope, and ids the caller gives.`,
21327
21358
  "Report every finding of every severity in this one pass, grouped by the rule it breaks: do not stop at the first serious one in an area, and hold none back for a later round. Give each its `rule`, worded alike for every finding that breaks the same rule, and its `checked`: the sibling cases of that rule you checked and found fine, so the next round need not explore them again."
21328
21359
  ].join(" ");
21329
21360
  var earlierPrompt = (earlier) => [
21330
- "An earlier review found these. Give each as a `followUps` entry with its id: fixed, changed (the code moved but the problem stands) or still_there. Do not report them again as findings.",
21361
+ "Earlier rounds, by both reviewers, left these findings open. Give each as a `followUps` entry with its id: fixed, changed (the code moved but the problem stands) or still_there. Do not report them again as findings.",
21331
21362
  ...earlier.map((finding) => `- ${finding.id} (${finding.severity}): ${finding.detail}`)
21332
21363
  ].join(`
21333
21364
  `);
21334
- var fixRound = (input) => (input.earlier?.length ?? 0) > 0 || input.reviewed !== undefined;
21335
- var fixPrompt = (fix) => `This round reviews ${fix} and the code it touches, exhaustively as above. Raise a new problem outside the fix and the code it touches only if it is a blocker; report one that is not as a minor with \`outsideFix\` set to true, which does not block landing.`;
21336
- var fixOf = (input, head) => input.reviewed === undefined ? "the fix since the earlier review" : `the fix, \`git diff ${input.reviewed}..${head}\` (the target branch merged into it is not the fix),`;
21337
- var promptFor = (seat, target, head, input, failing, notRun) => [
21338
- `You are one of two reviewers. Follow your \`${seats[seat].skill}\` skill; if you do not have it: ${seats[seat].focus}`,
21365
+ var outsideFixPrompt = "Raise a new problem outside the fix and the code it touches only if it is a blocker; report one that is not as a minor with `outsideFix` set to true, which does not block landing.";
21366
+ var fixTargetOf = (input, { head, branches, epic }) => {
21367
+ const from = input.reviewed ?? (input.files === undefined ? undefined : input.since);
21368
+ const branch = branches === undefined ? epic?.branch : branches.source ?? head;
21369
+ return [
21370
+ `${from === undefined ? `the fix made since the earlier review, up to revision ${head}, which you find from the open findings and \`git log\`,` : `the fix, \`git diff ${from}..${head}\`,`} and the code it touches. An empty fix means nothing was changed, so judge only what is asked below. An earlier round reviewed the rest of the change, so do not review that again. You may read any other code you need.`,
21371
+ "The commits merging the target branch brought in are not the fix; what such a merge changed in this change, such as a settled conflict, is.",
21372
+ ...input.files === undefined ? input.approved === undefined ? [] : [
21373
+ `The change was approved at ${input.approved}. Report a problem in code it already had there only if it matters, with \`approvedCode\` set to true: such findings are kept apart and do not block.`
21374
+ ] : [
21375
+ [
21376
+ "Whatever changed in these files since then, even by merging the target branch, counts as the fix:",
21377
+ ...input.files.map((file) => `- ${file}`)
21378
+ ].join(`
21379
+ `)
21380
+ ],
21381
+ ...branch === undefined ? [] : [
21382
+ `Look nothing up: fetch \`${branch}\` from \`origin\`, and read exactly revision ${head} even if it has moved since. ${unfetchable(head)}`
21383
+ ]
21384
+ ].join(`
21385
+
21386
+ `);
21387
+ };
21388
+ var promptFor = (seat, target, input, failing, notRun) => [
21389
+ `You are ${fixRound(input) ? "the only reviewer of this round" : "one of two reviewers"}. Follow your \`${seats[seat].skill}\` skill; if you do not have it: ${seats[seat].focus}`,
21339
21390
  `Review ${target}`,
21340
21391
  "Give `summary`: one sentence on whether it can merge and what matters most.",
21341
21392
  "Report each problem as a finding: severity blocker (must not ship), major (fix before merge) or minor (optional); the file path from the repository root; the line; and the detail. When it is one instance of a class of bug, name every other instance in the diff in its detail. Report nothing you have not checked in the code.",
21342
- exhaustivePrompt,
21393
+ exhaustivePrompt(fixRound(input) ? "the fix" : "the change"),
21343
21394
  "What an answer under your brief's Answers so far put out of scope is reported, not missing: do not report it as a finding.",
21344
21395
  "If the diff is too big to review in one go, review it directory by directory and say so in a finding on the first file you skipped.",
21345
21396
  ...seat === scopeSeat && wholeChange(input) ? [scopePrompt(input)] : [],
21346
21397
  ...input.earlier === undefined || input.earlier.length === 0 ? [] : [earlierPrompt(input.earlier)],
21347
- ...fixRound(input) ? [fixPrompt(fixOf(input, head))] : [],
21398
+ ...fixRound(input) ? [outsideFixPrompt] : [],
21348
21399
  ...failing.length === 0 ? [] : [
21349
21400
  `These checks fail on this head and pass on the base: ${failing.join(", ")}. The implementer has their output, so do not report them as findings, and do not say it can merge while they fail.`
21350
21401
  ],
@@ -21369,6 +21420,19 @@ var detailOf = (detail, rule, checked) => [
21369
21420
  detail,
21370
21421
  ...checked.length === 0 ? [] : [`Checked and fine: ${checked.join("; ")}.`]
21371
21422
  ].join(" ");
21423
+ var severityRank = { blocker: 0, major: 1, minor: 2 };
21424
+ var blockingSeatsOf = (finding) => isBlocking(finding) ? finding.blockingSeats ?? finding.seats : [];
21425
+ var withEarlier = (worse, earlier) => {
21426
+ const { blockingSeats: _, ...finding } = worse;
21427
+ const seats = [...new Set([...earlier.seats, ...worse.seats])];
21428
+ const blockingSeats = [...new Set([...blockingSeatsOf(earlier), ...blockingSeatsOf(worse)])];
21429
+ return {
21430
+ ...finding,
21431
+ detail: `${finding.detail} Still open on this line: ${earlier.detail}`,
21432
+ seats,
21433
+ ...blockingSeats.length === seats.length ? undefined : { blockingSeats }
21434
+ };
21435
+ };
21372
21436
  var idOf = (finding) => `${finding.file}:${finding.line}`;
21373
21437
  var groupedByRule = (bySeat) => {
21374
21438
  const rules = new Map;
@@ -21420,14 +21484,15 @@ ${followUps.map((entry) => `- \`${entry.id}\` ${entry.status.replace("_", " ")}`
21420
21484
  ].join(`
21421
21485
 
21422
21486
  `);
21423
- var fixBrief = (changeRequestId, findings) => [
21487
+ var fixBrief = (changeRequestId, findings, unmet) => [
21424
21488
  `Fix what a review of ChangeRequest ${changeRequestId} found, on its branch:`,
21425
- ...findings.map((finding) => `- ${finding.id} (${finding.severity}): ${finding.detail}`)
21489
+ ...findings.map((finding) => `- ${finding.id} (${finding.severity}): ${finding.detail}`),
21490
+ ...unmet.length === 0 ? [] : ["Do what it found unmet:", ...unmet.map((item) => `- ${item}`)]
21426
21491
  ].join(`
21427
21492
  `);
21428
21493
  var review_default = defineLoop({
21429
21494
  id: "review",
21430
- version: "3.9.0",
21495
+ version: "3.10.0",
21431
21496
  title: "Review",
21432
21497
  input: Input,
21433
21498
  output: Output,
@@ -21457,37 +21522,45 @@ var review_default = defineLoop({
21457
21522
  return yield* new ReviewDiffEmpty({
21458
21523
  message: `Base and head are both commit ${range.head}, so the diff is empty: give the base the change is to merge into`
21459
21524
  });
21460
- const target = targetOf(input, range);
21525
+ const target = fixRound(input) ? fixTargetOf(input, range) : targetOf(input, range);
21461
21526
  const verified = head === undefined ? { failing: [], notRun: [] } : yield* verifyHead("verify", head);
21462
21527
  const failing = [...new Set([...input.failing ?? [], ...verified.failing])];
21463
21528
  const notRun = [...new Set([...input.notRun ?? [], ...verified.notRun])];
21464
- const outputs = yield* forEach2(seatNames, (seat) => agentWork(`review:${seat}`, {
21529
+ const outputs = yield* forEach2(fixRound(input) ? [scopeSeat] : seatNames, (seat) => agentWork(`review:${seat}`, {
21465
21530
  agent: seat,
21466
- prompt: promptFor(seat, target, range.head, input, failing, notRun),
21531
+ prompt: promptFor(seat, target, input, failing, notRun),
21467
21532
  output: SeatOutput
21468
21533
  }).pipe(map8((output) => [seat, output])), { concurrency: "unbounded" });
21469
21534
  const earlier = input.earlier ?? [];
21470
- const earlierIds = new Set(earlier.map((finding) => finding.id));
21535
+ const earlierById = new Map(earlier.map((finding) => [finding.id, finding]));
21471
21536
  const answered = followUpsOf(earlier, outputs.flatMap(([, output]) => output.followUps ?? []));
21472
21537
  const standing = new Set(answered.flatMap((entry) => entry.status === "fixed" ? [] : [entry.id]));
21473
- const verdicts = outputs.flatMap(([, output]) => output.verdicts ?? []);
21474
- const settled = settleRound({ findings: earlier, rebuttals: input.rebuttals ?? [], verdicts });
21538
+ const given = outputs.flatMap(([, output]) => output.verdicts ?? []);
21539
+ const settled = settleRound({ findings: earlier, rebuttals: input.rebuttals ?? [], verdicts: given });
21475
21540
  const withdrawn = new Set(settled.withdrawn.map((entry) => entry.finding.id));
21476
- const carried = earlier.filter((finding) => standing.has(finding.id) && !withdrawn.has(finding.id));
21541
+ const open = new Map([...earlierById].filter(([id]) => standing.has(id) && !withdrawn.has(id)));
21477
21542
  const followUps = answered.filter((entry) => !withdrawn.has(entry.id));
21478
21543
  const sinceApproval = input.approved !== undefined && input.files === undefined;
21544
+ const isNew = (finding) => {
21545
+ const before = earlierById.get(idOf(finding));
21546
+ return before === undefined || severityRank[finding.severity] < severityRank[before.severity] || !standing.has(before.id) && !withdrawn.has(before.id);
21547
+ };
21479
21548
  const merged = (approvedCode) => groupedByRule(Object.fromEntries(outputs.map(([seat, output]) => [
21480
21549
  seat,
21481
- output.findings.filter((finding) => !earlierIds.has(`${finding.file}:${finding.line}`) && (sinceApproval && finding.approvedCode === true) === approvedCode).map((finding) => fixRound(input) ? outsideFixAsMinor(finding) : finding)
21550
+ output.findings.map((finding) => fixRound(input) ? outsideFixAsMinor(finding) : finding).filter((finding) => isNew(finding) && (sinceApproval && finding.approvedCode === true) === approvedCode)
21482
21551
  ])));
21483
- const fresh = merged(false);
21552
+ const fresh = merged(false).map((finding) => {
21553
+ const before = open.get(finding.id);
21554
+ return before === undefined ? finding : withEarlier(finding, before);
21555
+ });
21556
+ const freshIds = new Set(fresh.map((finding) => finding.id));
21484
21557
  const approvedFindings = sinceApproval ? merged(true) : [];
21485
- const findings = [...carried, ...fresh];
21558
+ const findings = [...[...open.values()].filter((finding) => !freshIds.has(finding.id)), ...fresh];
21559
+ const verdicts = given.map((verdict) => freshIds.has(verdict.findingId) ? { ...verdict, accepted: false } : verdict);
21486
21560
  const blockers = findings.filter(isBlocking);
21487
- const judged = wholeChange(input) ? outputs.find(([seat]) => seat === scopeSeat)?.[1].scope : undefined;
21488
- const scope = judged === undefined ? undefined : agreedScope(judged);
21561
+ const judged = outputs.find(([seat]) => seat === scopeSeat)?.[1].scope;
21562
+ const scope = wholeChange(input) ? carriedScope(judged, fixRound(input) ? input.scope : undefined) : undefined;
21489
21563
  const summary = blockers.length > 0 ? `Blocking: fix ${blockers.map((finding) => finding.id).join(", ")} before merging.` : scope?.met === false ? "Not ready: the change does not yet do what was asked." : failing.length > 0 ? `Not ready: ${failing.join(", ")} fails on this head.` : notRun.length > 0 ? "Not ready: verify never ran some of its tests, so they are unverified." : findings.length === 0 ? sinceApproval ? `No findings in what changed since ${input.approved}: nothing stands in the way of merging.` : "No findings: nothing stands in the way of merging." : ["Can merge: nothing blocks it.", ...outputs.map(([, output]) => output.summary)].join(" ");
21490
- const freshIds = new Set(fresh.map((finding) => finding.id));
21491
21564
  const text = reviewText(summary, findings, followUps, approvedFindings, notRun, scope?.reported ?? []);
21492
21565
  const stored = yield* artifact("findings", {
21493
21566
  kind: "review-findings",
@@ -21537,18 +21610,19 @@ What next?`,
21537
21610
  }
21538
21611
  if (choice === "Fix here") {
21539
21612
  const fixed = yield* call("fix", buildLoop(), {
21540
- words: fixBrief(changeRequestId, findings),
21613
+ words: fixBrief(changeRequestId, findings, scope?.unmet ?? []),
21541
21614
  changeRequestId,
21542
21615
  maxRounds: 2,
21543
21616
  reviewed: range.head,
21544
21617
  ...findings.length === 0 ? undefined : { earlier: findings },
21618
+ ...scope === undefined ? undefined : { scope },
21545
21619
  ...ownDeliveryTarget(input)
21546
21620
  });
21547
21621
  return { choice, detail: fixed.settled ? "Fixed and pushed" : `Pushed; left: ${fixed.unsettled.join("; ")}` };
21548
21622
  }
21549
21623
  if (choice === "Build from it") {
21550
21624
  const built = yield* call("build", buildLoop(), {
21551
- words: fixBrief(changeRequestId, findings),
21625
+ words: fixBrief(changeRequestId, findings, scope?.unmet ?? []),
21552
21626
  ...ownDeliveryTarget(input)
21553
21627
  });
21554
21628
  return { choice, detail: built.changeRequest.url };
@@ -22104,7 +22178,8 @@ var ShepherdOutput = Struct({
22104
22178
  taskId: optional2(String5),
22105
22179
  branch: optional2(String5),
22106
22180
  reviewed: optional2(String5),
22107
- earlier: optional2(ArraySchema(MergedFinding))
22181
+ earlier: optional2(ArraySchema(MergedFinding)),
22182
+ scope: optional2(ReviewedScope)
22108
22183
  }))
22109
22184
  });
22110
22185
 
@@ -22294,7 +22369,7 @@ var repliesPrompt = (threads) => [
22294
22369
  var threadKey = (thread) => `${thread.id}:${thread.comments.length}`;
22295
22370
  var shepherd_default = defineLoop({
22296
22371
  id: "shepherd",
22297
- version: "1.9.0",
22372
+ version: "1.10.0",
22298
22373
  title: "Shepherd",
22299
22374
  input: Input3,
22300
22375
  output: Output3,
@@ -22331,6 +22406,7 @@ var shepherd_default = defineLoop({
22331
22406
  const leftToPerson = new Set;
22332
22407
  let headFindings = [];
22333
22408
  let headFindingsAt;
22409
+ let headScope;
22334
22410
  const unranAt = new Map;
22335
22411
  const rounds = { "ci-fix": 0, "head-fix": 0 };
22336
22412
  const allowed = { "ci-fix": 0, "head-fix": 0 };
@@ -22544,7 +22620,13 @@ ${open}`,
22544
22620
  unreviewed = caught.from === unreviewed.synced ? { ...unreviewed, files, synced: caught.head } : { ...unreviewed, files };
22545
22621
  } else if (caught !== undefined && verdict.kind === "review") {
22546
22622
  notCarried = undefined;
22547
- unreviewed = { files: verdict.files, synced: caught.head, sync: `sync:${cycle}`, earlier: [] };
22623
+ unreviewed = {
22624
+ files: verdict.files,
22625
+ synced: caught.head,
22626
+ sync: `sync:${cycle}`,
22627
+ from: caught.from,
22628
+ earlier: []
22629
+ };
22548
22630
  } else if (caught !== undefined) {
22549
22631
  notCarried = undefined;
22550
22632
  const carried = yield* approveChangeRequest(`carry:${cycle}`, {
@@ -22627,7 +22709,8 @@ ${open}`,
22627
22709
  }
22628
22710
  return stop(ready);
22629
22711
  });
22630
- const reviewMergedFiles = (cycle, head, files) => gen2(function* () {
22712
+ const reviewMergedFiles = (cycle, pipeline, files) => gen2(function* () {
22713
+ const { head } = pipeline;
22631
22714
  yield* passTurn();
22632
22715
  const reviewed = yield* call(`review:${cycle}`, reviewLoop(), {
22633
22716
  base: `origin/${target}`,
@@ -22640,7 +22723,7 @@ ${open}`,
22640
22723
  if (reviewed.blocking) {
22641
22724
  const blocking = reviewed.findings.filter(isBlocking);
22642
22725
  if (!(yield* mayFix("head-fix", cycle, blocking.map((finding) => finding.id).join(", "))))
22643
- return stop(handBack(`The review of the catch-up merge's files still finds ${blocking.map((finding) => finding.id).join(", ")} after ${rounds["head-fix"]} head-fix rounds`, findingLines2(blocking), { reviewed: head, earlier: reviewed.findings }));
22726
+ return stop(handBack(`The review of the catch-up merge's files still finds ${blocking.map((finding) => finding.id).join(", ")} after ${rounds["head-fix"]} head-fix rounds`, findingLines2(blocking), pipeline.approved === files.from ? { reviewed: head, earlier: reviewed.findings } : undefined));
22644
22727
  rounds["head-fix"]++;
22645
22728
  const fix = yield* agentWork(`review-fix:${cycle}`, {
22646
22729
  agent: "implementer",
@@ -22700,12 +22783,18 @@ ${open}`,
22700
22783
  ...notRun.length === 0 ? undefined : { notRun },
22701
22784
  ...since === undefined ? undefined : { approved: since },
22702
22785
  ...headFindings.length === 0 ? undefined : { earlier: headFindings },
22703
- ...headFindingsAt === undefined ? undefined : { reviewed: headFindingsAt }
22786
+ ...headFindingsAt === undefined ? undefined : { reviewed: headFindingsAt },
22787
+ ...headScope === undefined ? undefined : { scope: headScope }
22704
22788
  });
22705
22789
  if (reviewed.blocking) {
22706
22790
  const blocking = reviewed.findings.filter(isBlocking);
22707
22791
  if (!(yield* mayFix("head-fix", cycle, blocking.map((finding) => finding.id).join(", "))))
22708
- return stop(handBack(`The review of ${head} still finds ${blocking.map((finding) => finding.id).join(", ")} after ${rounds["head-fix"]} head-fix rounds`, findingLines2(blocking), { reviewed: head, earlier: reviewed.findings }));
22792
+ return stop(handBack(`The review of ${head} still finds ${blocking.map((finding) => finding.id).join(", ")} after ${rounds["head-fix"]} head-fix rounds`, [findingLines2(blocking), ...(reviewed.scope?.unmet ?? []).map((item) => `- Not done: ${item}`)].join(`
22793
+ `), {
22794
+ reviewed: head,
22795
+ earlier: reviewed.findings,
22796
+ ...reviewed.scope === undefined ? undefined : { scope: reviewed.scope }
22797
+ }));
22709
22798
  rounds["head-fix"]++;
22710
22799
  const fix = yield* agentWork(`head-fix:${cycle}`, {
22711
22800
  agent: "implementer",
@@ -22715,11 +22804,13 @@ ${open}`,
22715
22804
  });
22716
22805
  headFindings = reviewed.findings;
22717
22806
  headFindingsAt = head;
22807
+ headScope = reviewed.scope;
22718
22808
  fixedFrom = { head, changed: fix.changed, looks: 0 };
22719
22809
  return { kind: "fixing" };
22720
22810
  }
22721
22811
  headFindings = [];
22722
22812
  headFindingsAt = undefined;
22813
+ headScope = undefined;
22723
22814
  if (notRun.length > 0)
22724
22815
  unranAt.set(head, { notRun, review: `head-review:${cycle}` });
22725
22816
  else {
@@ -22765,7 +22856,7 @@ ${open}`,
22765
22856
  if (head !== pipeline.head)
22766
22857
  return;
22767
22858
  if (unreviewed !== undefined)
22768
- return yield* reviewMergedFiles(cycle, head, unreviewed);
22859
+ return yield* reviewMergedFiles(cycle, pipeline, unreviewed);
22769
22860
  if (notCarried !== undefined && pipeline.approved !== head)
22770
22861
  return yield* reviewHead(cycle, pipeline, "the head its catch-up merge pushed");
22771
22862
  return;
@@ -22990,7 +23081,7 @@ ${open}`,
22990
23081
  }
22991
23082
  let reviewedHere = reviewedHeads.has(pipeline.head) && (pipeline.approved === pipeline.head || unranAt.has(pipeline.head));
22992
23083
  if (unreviewed !== undefined) {
22993
- const reviewing = yield* reviewMergedFiles(cycle, pipeline.head, unreviewed);
23084
+ const reviewing = yield* reviewMergedFiles(cycle, pipeline, unreviewed);
22994
23085
  if (reviewing.kind === "stop")
22995
23086
  return reviewing.output;
22996
23087
  if (reviewing.kind === "fixing")
@@ -23177,6 +23268,7 @@ var BuildInput = Struct({
23177
23268
  maxRebuilds: optional2(Int.check(isGreaterThanOrEqualTo2(0))),
23178
23269
  reviewed: optional2(String5),
23179
23270
  earlier: optional2(ArraySchema(MergedFinding)),
23271
+ scope: optional2(ReviewedScope),
23180
23272
  ...DeliveryFields
23181
23273
  });
23182
23274
  var CriterionAnswer = Struct({
@@ -23224,6 +23316,7 @@ var BuildOutput = Struct({
23224
23316
  criteria: ArraySchema(CriterionAnswer),
23225
23317
  notRun: optional2(ArraySchema(String5)),
23226
23318
  findings: optional2(ArraySchema(MergedFinding)),
23319
+ scope: optional2(ReviewedScope),
23227
23320
  blockingCounts: optional2(ArraySchema(Int)),
23228
23321
  approval: optional2(ApproveChangeRequestResult),
23229
23322
  landed: optional2(ShepherdOutput),
@@ -23300,7 +23393,7 @@ var reproducedOnBranchPrompt = (task) => [
23300
23393
  var findingLine = (finding) => `- **${finding.severity}** \`${finding.id}\` ${finding.detail}`;
23301
23394
  var disputeLine = ({ finding, rebuttal }) => `${findingLine(finding)}
23302
23395
  You rebutted: ${rebuttal.reason}`;
23303
- var fixPrompt2 = (settled) => {
23396
+ var fixPrompt = (settled) => {
23304
23397
  const checks = settled.open.filter((finding) => isCheckFinding(finding.id));
23305
23398
  const findings = settled.open.filter((finding) => !isCheckFinding(finding.id));
23306
23399
  return [
@@ -23365,12 +23458,14 @@ var rally = (input) => gen2(function* () {
23365
23458
  };
23366
23459
  const failing = brokenChecks(head).map((check) => check.name);
23367
23460
  const notRun = testsNotRunReasons(head);
23461
+ const scope = last === undefined ? input.scope : last.scope;
23368
23462
  const reviewed = yield* call(`review:${round}`, review_default, {
23369
23463
  base,
23370
23464
  head: head.revision,
23371
23465
  ...rebuttals.length === 0 ? undefined : { rebuttals },
23372
23466
  ...earlier.length === 0 ? undefined : { earlier },
23373
23467
  ...last === undefined ? input.reviewed === undefined ? undefined : { reviewed: input.reviewed } : { reviewed: last.head.revision },
23468
+ ...scope === undefined ? undefined : { scope },
23374
23469
  ...input.outcome === undefined ? undefined : { outcome: input.outcome },
23375
23470
  ...failing.length === 0 ? undefined : { failing },
23376
23471
  ...notRun.length === 0 ? undefined : { notRun },
@@ -23407,7 +23502,7 @@ var rally = (input) => gen2(function* () {
23407
23502
  shown.add(finding.detail);
23408
23503
  const fixed = yield* agentWork(`fix:${round}`, {
23409
23504
  agent: "implementer",
23410
- prompt: fixPrompt2(settled),
23505
+ prompt: fixPrompt(settled),
23411
23506
  output: Fixed
23412
23507
  });
23413
23508
  claims.push(...fixed.claims, ...fixed.rebuttals.flatMap((rebuttal) => isCheckFinding(rebuttal.findingId) ? [`Rebutted ${rebuttal.findingId}: ${rebuttal.reason}`] : []));
@@ -23422,7 +23517,7 @@ var rally = (input) => gen2(function* () {
23422
23517
  });
23423
23518
  var build2 = defineLoop({
23424
23519
  id: "build",
23425
- version: "2.10.0",
23520
+ version: "2.11.0",
23426
23521
  title: "Build",
23427
23522
  input: BuildInput,
23428
23523
  output: BuildOutput,
@@ -23484,7 +23579,8 @@ var build2 = defineLoop({
23484
23579
  suggested: implemented.checks ?? [],
23485
23580
  reproducing: reproduced?.check,
23486
23581
  reviewed: input.reviewed,
23487
- earlier: input.earlier ?? []
23582
+ earlier: input.earlier ?? [],
23583
+ scope: input.scope
23488
23584
  });
23489
23585
  const verdict = evidenceGate({
23490
23586
  ...outcome === undefined ? undefined : { outcome },
@@ -23535,6 +23631,7 @@ var build2 = defineLoop({
23535
23631
  criteria,
23536
23632
  ...lastNotRun.length === 0 ? undefined : { notRun: lastNotRun },
23537
23633
  ...last.earlier.length === 0 ? undefined : { findings: last.earlier },
23634
+ ...last.scope === undefined ? undefined : { scope: last.scope },
23538
23635
  blockingCounts: last.blockingCounts,
23539
23636
  ...approval === undefined ? undefined : { approval }
23540
23637
  };
@@ -23599,6 +23696,7 @@ var build2 = defineLoop({
23599
23696
  land: false,
23600
23697
  reviewed: settledAs.revision,
23601
23698
  ...settledAs.findings === undefined ? undefined : { earlier: settledAs.findings },
23699
+ ...settledAs.scope === undefined ? undefined : { scope: settledAs.scope },
23602
23700
  ...ownDeliveryTarget(input)
23603
23701
  }, { constraints: standing.map(standingConstraint) });
23604
23702
  settledAs = rebuilt;
@@ -23813,7 +23911,7 @@ var changePrompt = (discovery, plan, tried, cycle) => [
23813
23911
 
23814
23912
  `);
23815
23913
  var revertPrompt = (start, cycle) => `Cycle ${cycle}'s change did not prove faster. Revert its commits, and only those: run \`git revert --no-edit ${start}..HEAD\`. Touch no commit at or before ${start}, never reset or force-push, and change nothing else.`;
23816
- var fixPrompt3 = (findings) => [
23914
+ var fixPrompt2 = (findings) => [
23817
23915
  "The review of the climb found these. Fix each, keep behaviour exactly as it is and keep the gain, and commit. Kitman verifies and measures again; a fix that costs the gain ends the climb.",
23818
23916
  ...findings.map((finding) => `- ${finding.id}: ${finding.detail}`)
23819
23917
  ].join(`
@@ -23876,7 +23974,7 @@ var steadier = (plan) => {
23876
23974
  };
23877
23975
  var hillclimb_default = defineLoop({
23878
23976
  id: "hillclimb",
23879
- version: "1.4.0",
23977
+ version: "1.5.0",
23880
23978
  title: "Hillclimb",
23881
23979
  outcome: "performance",
23882
23980
  input: Input5,
@@ -24010,7 +24108,7 @@ var hillclimb_default = defineLoop({
24010
24108
  const blocking = reviewed.findings.filter(isBlocking);
24011
24109
  yield* agentWork(`fix:${round}`, {
24012
24110
  agent: "implementer",
24013
- prompt: fixPrompt3(blocking),
24111
+ prompt: fixPrompt2(blocking),
24014
24112
  output: Struct({ summary: OneSentence })
24015
24113
  });
24016
24114
  const fixed = yield* verify(`verify:fix:${round}`, {});
@@ -24029,8 +24127,9 @@ var hillclimb_default = defineLoop({
24029
24127
  outcome: "performance",
24030
24128
  ...notRunOf(fixed),
24031
24129
  claims,
24032
- earlier: blocking,
24033
- reviewed: fixedFrom
24130
+ earlier: reviewed.findings,
24131
+ reviewed: fixedFrom,
24132
+ ...reviewed.scope === undefined ? undefined : { scope: reviewed.scope }
24034
24133
  });
24035
24134
  }
24036
24135
  const notRun = testsNotRunReasons(head);
@@ -24228,6 +24327,112 @@ Start a Build that fixes it as a bug: ${conclusion.fix}?`,
24228
24327
  })
24229
24328
  });
24230
24329
 
24330
+ // src/plan-review.ts
24331
+ var Concern = Struct({
24332
+ ticket: optional2(String5),
24333
+ concern: Reason
24334
+ });
24335
+ var Check = Struct({ concerns: ArraySchema(Concern) });
24336
+ var Recheck = Struct({
24337
+ concerns: ArraySchema(Struct({
24338
+ ...Concern.fields,
24339
+ earlier: optional2(String5)
24340
+ }))
24341
+ });
24342
+ var DeclinedConcern = Struct({ concern: String5, why: Reason });
24343
+ var outOfScopeText = ({ outOfScope = [] }) => outOfScope.length === 0 ? [] : ["Out of scope:", ...outOfScope.map((item) => `- ${item}`)];
24344
+ var ticketText = (ticket) => [
24345
+ `### ${ticket.key}: ${ticket.title}`,
24346
+ ticket.body,
24347
+ ...ticket.promise === undefined ? [] : [`Promise: ${ticket.promise}`],
24348
+ ...ticket.acceptanceCriteria.map((criterion) => `- [ ] ${criterion}`),
24349
+ ...outOfScopeText(ticket),
24350
+ ...ticket.repoBindingId === undefined ? [] : [`Repository (repoBindingId): ${ticket.repoBindingId}`],
24351
+ ...ticket.outcome === undefined ? [] : [`Outcome: ${ticket.outcome}`],
24352
+ ...ticket.blockedBy.length === 0 ? [] : [`Blocked by: ${ticket.blockedBy.join(", ")}`]
24353
+ ].join(`
24354
+
24355
+ `);
24356
+ var checks = [
24357
+ "Load skills({ name: 'scope-tasks' }) from the Kitman MCP, read the code the plan is about, and check every ticket for each of these:",
24358
+ [
24359
+ "- One Promise: the ticket promises one thing, and its Out of scope list names the cases it does not handle. An open-ended Promise is a concern.",
24360
+ "- Size: estimate the context one agent session needs from reading the code to a verified change. 200k tokens or more is a concern; give your estimate.",
24361
+ "- Decisions: no design decision is left to the implementer.",
24362
+ "- Blockers: it is blocked by each ticket whose code it needs, and by no other."
24363
+ ].join(`
24364
+ `),
24365
+ "Give each concern its ticket's key, and say what would answer it. What the person asked for is not a concern. Submit no concerns when every ticket holds. Change nothing."
24366
+ ].join(`
24367
+
24368
+ `);
24369
+ var askedText = (asked) => `What the person asked for, in turn; where two differ, the later one holds:
24370
+
24371
+ ${asked}`;
24372
+ var answeredConcern = (concern, declined = []) => {
24373
+ const why = declined.find((entry) => entry.concern === concern.id)?.why;
24374
+ return [
24375
+ `${concern.id}${concern.ticket === undefined ? "" : `, on ${concern.ticket}`}: ${concern.concern}`,
24376
+ ...why === undefined ? [] : [`The planner did not act on it: ${why}`]
24377
+ ].join(`
24378
+ `);
24379
+ };
24380
+ var checkPrompt = (asked, text) => ["Review this plan before a person is asked to approve it.", checks, askedText(asked), text].join(`
24381
+
24382
+ `);
24383
+ var revisePrompt = (asked, text, concerns) => [
24384
+ "A reviewer checked the plan before a person is asked to approve it. Revise it to answer each concern, and keep what the person asked for and what no concern is about. Change no files; a decision a concern asks for goes in the plan. List in declined the id of each concern you did not act on and why; keep that out of the plan itself.",
24385
+ concerns.map((concern) => answeredConcern(concern)).join(`
24386
+
24387
+ `),
24388
+ askedText(asked),
24389
+ text
24390
+ ].join(`
24391
+
24392
+ `);
24393
+ var recheckPrompt = (asked, text, concerns, declined) => [
24394
+ "The planner revised this plan after your review. Check it once more. Raise again only a concern the revision does not answer, with its id in earlier; when the planner gave a reason not to act on it, raise it only if you can answer the reason. What you raise is shown to the person with the plan as still disputed.",
24395
+ checks,
24396
+ "Your concerns on the plan before its revision:",
24397
+ concerns.map((concern) => answeredConcern(concern, declined)).join(`
24398
+
24399
+ `),
24400
+ askedText(asked),
24401
+ text
24402
+ ].join(`
24403
+
24404
+ `);
24405
+ var reviewPlan = (step, { plan, asked, text, revise }) => gen2(function* () {
24406
+ const first = yield* agentWork(step, {
24407
+ agent: "plan-reviewer",
24408
+ prompt: checkPrompt(asked, text(plan)),
24409
+ output: Check
24410
+ });
24411
+ if (first.concerns.length === 0)
24412
+ return { plan, disputed: [] };
24413
+ const concerns = first.concerns.map((concern, index) => ({ ...concern, id: `c${index + 1}` }));
24414
+ const revised = yield* revise(`${step}:revise`, revisePrompt(asked, text(plan), concerns));
24415
+ const again = yield* agentWork(`${step}:recheck`, {
24416
+ agent: "plan-reviewer",
24417
+ prompt: recheckPrompt(asked, text(revised.plan), concerns, revised.declined),
24418
+ output: Recheck
24419
+ });
24420
+ const disputed = again.concerns.map(({ earlier, ...concern }) => {
24421
+ const declined = revised.declined.find((entry) => entry.concern === earlier)?.why;
24422
+ return declined === undefined ? concern : { ...concern, declined };
24423
+ });
24424
+ return { plan: revised.plan, disputed };
24425
+ });
24426
+ var oneLine = (text) => text.replace(/\s+/gu, " ").trim();
24427
+ var disputedText = (disputed) => disputed.length === 0 ? [] : [
24428
+ "## Still disputed",
24429
+ disputed.flatMap(({ ticket, concern, declined }) => [
24430
+ `- ${ticket === undefined ? "" : `${ticket}: `}${oneLine(concern)}`,
24431
+ ...declined === undefined ? [] : [` - The planner did not act on it: ${oneLine(declined)}`]
24432
+ ]).join(`
24433
+ `)
24434
+ ];
24435
+
24231
24436
  // src/plan.ts
24232
24437
  var Input7 = Struct({
24233
24438
  words: String5,
@@ -24236,10 +24441,15 @@ var Input7 = Struct({
24236
24441
  projectId: optional2(String5),
24237
24442
  implement: optional2(Boolean3)
24238
24443
  });
24444
+ var ScopedTickets = planTicketsOf(Struct({
24445
+ ...PlanTicket.fields,
24446
+ promise: String5.check(isPattern2(/\S/)),
24447
+ outOfScope: ArraySchema(String5)
24448
+ }));
24239
24449
  var Plan = Struct({
24240
24450
  title: String5,
24241
24451
  spec: String5,
24242
- tickets: PlanTickets,
24452
+ tickets: ScopedTickets,
24243
24453
  outOfScope: ArraySchema(String5),
24244
24454
  afterMerge: ArraySchema(String5),
24245
24455
  docs: optional2(Struct({ title: String5, summary: String5 }))
@@ -24249,11 +24459,16 @@ var Revised = Struct({
24249
24459
  addressed: ArraySchema(PlanAddressed),
24250
24460
  declined: ArraySchema(PlanDeclined)
24251
24461
  });
24462
+ var { docs: _docs, ...reworkedPlan } = Plan.fields;
24463
+ var Reworked = Struct({ ...reworkedPlan, declined: ArraySchema(DeclinedConcern) });
24464
+ var ReworkedAnswer = Struct({
24465
+ ...Reworked.fields,
24466
+ comments: Struct({ addressed: ArraySchema(PlanAddressed), declined: ArraySchema(PlanDeclined) })
24467
+ });
24252
24468
  var CriteriaCheck = Struct({
24253
24469
  alreadyMet: ArraySchema(Struct({ key: String5, criterion: String5 }))
24254
24470
  });
24255
24471
  var Rejected = Struct({ key: String5, reason: String5 });
24256
- var Opinion = Struct({ summary: String5, concerns: ArraySchema(String5) });
24257
24472
  var TicketResult = Struct({
24258
24473
  key: String5,
24259
24474
  title: String5,
@@ -24274,13 +24489,11 @@ var Output8 = Struct({
24274
24489
  tasks: optional2(CreateTasksResult.fields.tasks),
24275
24490
  docs: optional2(ChangeRequestResult)
24276
24491
  });
24277
- var menu = ["Implement now", "File as Tasks", "Second opinion", "Refine", "Finish"];
24492
+ var menu = ["Implement now", "File as Tasks", "Refine", "Finish"];
24278
24493
  var maxRounds = 6;
24279
- var maxOpinionsPerPlan = 2;
24280
24494
  var menuDescriptions = {
24281
24495
  "Implement now": "Builds the tickets in dependency order and delivers them.",
24282
24496
  "File as Tasks": "Makes a Task of each ticket, to build later.",
24283
- "Second opinion": "Another Agent reviews the plan.",
24284
24497
  Refine: "You say what to change and the planner rewrites it.",
24285
24498
  Finish: "Ends the Run with the plan as it is."
24286
24499
  };
@@ -24289,6 +24502,7 @@ var onHeld = ["Merge again", ...onConflict];
24289
24502
  var onFailure = ["Retry with a steer", "Skip it and its dependents", "Stop here"];
24290
24503
  var ticketRules = [
24291
24504
  "Each ticket is one Build: a vertical slice an agent can implement, review and deliver as one ChangeRequest. Give it a short unique key, and list in blockedBy the keys of the tickets whose code it needs; tickets never block each other in a cycle. Set repoBindingId only when it changes another repository than the plan, keep one repository per ticket, and no cycle across repositories. Set outcome to the kind of change: feature, bug, refactor, docs, migration, investigation or performance.",
24505
+ "Give each ticket its promise: one sentence that says what is true once it is done. List in its outOfScope the cases it does not handle. Two promises are two tickets.",
24292
24506
  "Each acceptance criterion is something a Build can show before its ChangeRequest: a behaviour a test or a check proves. A text search is never a criterion, nor is something the code already does. Outcomes only visible after merge go under afterMerge, not under a ticket's criteria."
24293
24507
  ].join(`
24294
24508
 
@@ -24315,24 +24529,10 @@ var planText = (plan) => [
24315
24529
  ].join(`
24316
24530
 
24317
24531
  `);
24318
- var outOfScopeText = ({ outOfScope = [] }) => outOfScope.length === 0 ? [] : ["Out of scope:", ...outOfScope.map((item) => `- ${item}`)];
24319
- var ticketText = (ticket) => [
24320
- `### ${ticket.key}: ${ticket.title}`,
24321
- ticket.body,
24322
- ...ticket.promise === undefined ? [] : [`Promise: ${ticket.promise}`],
24323
- ...ticket.acceptanceCriteria.map((criterion) => `- [ ] ${criterion}`),
24324
- ...outOfScopeText(ticket),
24325
- ...ticket.blockedBy.length === 0 ? [] : [`Blocked by: ${ticket.blockedBy.join(", ")}`]
24326
- ].join(`
24532
+ var documentText = (plan, disputed) => [planText(plan), ...disputedText(disputed)].join(`
24327
24533
 
24328
24534
  `);
24329
- var opinionPrompt = (plan) => [
24330
- "Review this plan as a second opinion. Look for missing scope, tickets too big to review, wrong blockers and risks. Change nothing.",
24331
- planText(plan)
24332
- ].join(`
24333
-
24334
- `);
24335
- var refinePrompt = (plan, words) => [`Change the plan as the user asks: ${words}`, ticketRules, planText(plan)].join(`
24535
+ var refinePrompt = (document, words) => [`Change the plan as the user asks: ${words}`, ticketRules, document].join(`
24336
24536
 
24337
24537
  `);
24338
24538
  var commentText = (comment) => {
@@ -24340,13 +24540,14 @@ var commentText = (comment) => {
24340
24540
  return `${comment.id}, ${on}
24341
24541
  ${comment.body}`;
24342
24542
  };
24343
- var revisePrompt = (plan, review) => [
24344
- `A person reviewed revision ${review.revision} of the plan and requested changes. Each comment names its id, then the text it quotes and the line of the plan's Markdown below it is on, then what the person said. Revise the plan to answer each comment; list in addressed the id of each comment the new revision answers and how, in one sentence. List in declined the id of each comment you did not act on and why, in one sentence; keep that out of the plan itself.`,
24345
- review.comments.map(commentText).join(`
24543
+ var commentsText = (review) => review.comments.map(commentText).join(`
24346
24544
 
24347
- `),
24545
+ `);
24546
+ var revisePrompt2 = (document, review) => [
24547
+ `A person reviewed revision ${review.revision} of the plan and requested changes. Each comment names its id, then the text it quotes and the line of the plan's Markdown below it is on, then what the person said. Revise the plan to answer each comment; list in addressed the id of each comment the new revision answers and how, in one sentence. List in declined the id of each comment you did not act on and why, in one sentence; keep that out of the plan itself.`,
24548
+ commentsText(review),
24348
24549
  ticketRules,
24349
- planText(plan)
24550
+ document
24350
24551
  ].join(`
24351
24552
 
24352
24553
  `);
@@ -24370,8 +24571,51 @@ var guarded = (plan, check) => {
24370
24571
  ]);
24371
24572
  return { plan: { ...plan, tickets }, rejected };
24372
24573
  };
24373
- var checked = (plan, revision) => map8(agentWork(`criteria-check:${revision}`, { agent: "reviewer", prompt: criteriaPrompt2(plan), output: CriteriaCheck }), (check) => guarded(plan, check));
24374
- var storePlan = (plan, suffix, revision, answered) => gen2(function* () {
24574
+ var answeredText = ({ addressed, declined }) => [
24575
+ "The plan answers a person's review, whose comments are in what the person asked for. This is what the plan above did about each. Give comments the same for your revision: list in its addressed the id of each comment your revision answers and how, and in its declined the id of each it does not act on and why, each in one sentence.",
24576
+ [
24577
+ ...addressed.map(({ comment, how }) => `Comment ${comment}, addressed: ${how}`),
24578
+ ...declined.map(({ comment, why }) => `Comment ${comment}, declined: ${why}`)
24579
+ ].join(`
24580
+ `)
24581
+ ].join(`
24582
+
24583
+ `);
24584
+ var rework = (step, prompt, answered) => answered === undefined ? agentWorkOnce(step, { agent: "planner", prompt: [prompt, ticketRules].join(`
24585
+
24586
+ `), output: Reworked }).pipe(map8(({ declined, ...plan }) => ({ plan: { plan }, declined }))) : agentWorkOnce(step, {
24587
+ agent: "planner",
24588
+ prompt: [prompt, ticketRules, answeredText(answered)].join(`
24589
+
24590
+ `),
24591
+ output: ReworkedAnswer
24592
+ }).pipe(map8(({ declined, comments, ...plan }) => ({
24593
+ plan: { plan, answered: { review: answered.review, ...comments } },
24594
+ declined
24595
+ })));
24596
+ var checked = (draft, revision, asked) => gen2(function* () {
24597
+ const reviewed = yield* reviewPlan(`plan-review:${revision}`, {
24598
+ plan: draft,
24599
+ asked: asked.join(`
24600
+
24601
+ `),
24602
+ text: ({ plan }) => planText(plan),
24603
+ revise: (step, prompt) => rework(step, prompt, draft.answered)
24604
+ });
24605
+ const check = yield* agentWork(`criteria-check:${revision}`, {
24606
+ agent: "reviewer",
24607
+ prompt: criteriaPrompt2(reviewed.plan.plan),
24608
+ output: CriteriaCheck
24609
+ });
24610
+ const { plan, rejected } = guarded(reviewed.plan.plan, check);
24611
+ return {
24612
+ plan,
24613
+ rejected,
24614
+ answered: reviewed.plan.answered,
24615
+ disputed: reviewed.disputed.filter((entry) => !rejected.some(({ key }) => key === entry.ticket))
24616
+ };
24617
+ });
24618
+ var storePlan = ({ plan, disputed, answered }, suffix, revision) => gen2(function* () {
24375
24619
  yield* artifact(`spec${suffix}`, {
24376
24620
  kind: "plan_spec",
24377
24621
  title: plan.title,
@@ -24384,12 +24628,11 @@ var storePlan = (plan, suffix, revision, answered) => gen2(function* () {
24384
24628
  text: plan.tickets.map(ticketText).join(`
24385
24629
 
24386
24630
  `),
24387
- data: plan.tickets.map(({ repoBindingId, outcome, promise, outOfScope, ...ticket }) => ({
24631
+ data: plan.tickets.map(({ repoBindingId, outcome, ...ticket }) => ({
24388
24632
  ...ticket,
24389
24633
  acceptanceCriteria: [...ticket.acceptanceCriteria],
24390
24634
  blockedBy: [...ticket.blockedBy],
24391
- ...promise === undefined ? undefined : { promise },
24392
- ...outOfScope === undefined ? undefined : { outOfScope: [...outOfScope] },
24635
+ outOfScope: [...ticket.outOfScope],
24393
24636
  ...repoBindingId === undefined ? undefined : { repoBindingId },
24394
24637
  ...outcome === undefined ? undefined : { outcome }
24395
24638
  }))
@@ -24397,7 +24640,7 @@ var storePlan = (plan, suffix, revision, answered) => gen2(function* () {
24397
24640
  yield* artifact(`document${suffix}`, {
24398
24641
  kind: "plan_document",
24399
24642
  title: plan.title,
24400
- text: planText(plan),
24643
+ text: documentText(plan, disputed),
24401
24644
  data: {
24402
24645
  revision,
24403
24646
  ...answered === undefined ? undefined : {
@@ -24624,11 +24867,11 @@ var implement = (input, plan, revision, filed) => gen2(function* () {
24624
24867
  });
24625
24868
  var plan_default = defineLoop({
24626
24869
  id: "plan",
24627
- version: "2.2.0",
24870
+ version: "3.0.0",
24628
24871
  title: "Plan",
24629
24872
  input: Input7,
24630
24873
  output: Output8,
24631
- agents: { planner: "planner", reviewer: "reviewer" },
24874
+ agents: { planner: "planner", reviewer: "reviewer", "plan-reviewer": "plan-reviewer" },
24632
24875
  checkout: "write",
24633
24876
  capabilities: [
24634
24877
  "agent_work",
@@ -24652,10 +24895,10 @@ var plan_default = defineLoop({
24652
24895
  });
24653
24896
  const docs = drafted.docs === undefined ? undefined : yield* changeRequest("docs", { title: drafted.docs.title, body: drafted.docs.summary });
24654
24897
  let revision = 1;
24655
- let { plan, rejected } = yield* checked(drafted, revision);
24898
+ const asked = [input.words];
24899
+ let { plan, rejected, disputed } = yield* checked({ plan: drafted }, revision, asked);
24656
24900
  let filed;
24657
- let opinions = 0;
24658
- yield* storePlan(plan, "", revision);
24901
+ yield* storePlan({ plan, disputed }, "", revision);
24659
24902
  const project = input.projectId === undefined ? undefined : { projectId: input.projectId };
24660
24903
  const held = new Map;
24661
24904
  let implementing = false;
@@ -24684,7 +24927,12 @@ var plan_default = defineLoop({
24684
24927
  const approve = () => gen2(function* () {
24685
24928
  for (;; ) {
24686
24929
  const answer = yield* ask(`review:${revision}`, {
24687
- prompt: `Review revision ${revision} of the plan "${plan.title}": approve it, or request changes by commenting on what should change.`,
24930
+ prompt: [
24931
+ `Review revision ${revision} of the plan "${plan.title}": approve it, or request changes by commenting on what should change.`,
24932
+ ...disputed.length === 0 ? [] : [
24933
+ `The plan reviewer still disputes ${disputed.length} point${disputed.length === 1 ? "" : "s"}, listed at the end of the plan.`
24934
+ ]
24935
+ ].join(" "),
24688
24936
  freeText: true,
24689
24937
  recommended: PlanApproval,
24690
24938
  recommendationReason: "Approve it once the plan reads right; until then the Run waits for you.",
@@ -24693,18 +24941,20 @@ var plan_default = defineLoop({
24693
24941
  });
24694
24942
  if (isPlanApproval(answer))
24695
24943
  return;
24696
- const review = readPlanReview(answer, revision, planText(plan));
24944
+ const review = readPlanReview(answer, revision, documentText(plan, disputed));
24697
24945
  const revised = yield* agentWorkOnce(`revise-plan:${revision}`, {
24698
24946
  agent: "planner",
24699
- prompt: revisePrompt(plan, review),
24947
+ prompt: revisePrompt2(documentText(plan, disputed), review),
24700
24948
  output: Revised
24701
24949
  });
24702
24950
  const { addressed, declined, ...next } = revised;
24703
24951
  const before = plan;
24704
24952
  const count = review.comments.length;
24705
24953
  revision++;
24706
- ({ plan, rejected } = yield* checked(next, revision));
24707
- yield* storePlan(plan, `:review-${revision}`, revision, { review, addressed, declined });
24954
+ asked.push(commentsText(review));
24955
+ const ready = yield* checked({ plan: next, answered: { review, addressed, declined } }, revision, asked);
24956
+ ({ plan, rejected, disputed } = ready);
24957
+ yield* storePlan(ready, `:review-${revision}`, revision);
24708
24958
  yield* artifact(`changes:review-${revision}`, {
24709
24959
  kind: "plan_changes",
24710
24960
  title: `Revision ${revision} of ${plan.title}`,
@@ -24715,7 +24965,7 @@ var plan_default = defineLoop({
24715
24965
  const decide = gen2(function* () {
24716
24966
  for (let round = 1;round <= maxRounds; round++) {
24717
24967
  const isFiled = filed?.revision === revision;
24718
- const options = menu.filter((option) => !(option === "File as Tasks" && isFiled) && !(option === "Second opinion" && opinions >= maxOpinionsPerPlan));
24968
+ const options = menu.filter((option) => !(option === "File as Tasks" && isFiled));
24719
24969
  const fallback = input.implement === true ? "Implement now" : isFiled ? "Finish" : "File as Tasks";
24720
24970
  const answer = yield* ask(`next:${round}`, {
24721
24971
  prompt: `What next for the plan "${plan.title}"?`,
@@ -24739,22 +24989,6 @@ var plan_default = defineLoop({
24739
24989
  case "File as Tasks":
24740
24990
  yield* file(`file-tasks:${round}`);
24741
24991
  break;
24742
- case "Second opinion": {
24743
- opinions++;
24744
- const opinion = yield* agentWork(`second-opinion:${round}`, {
24745
- agent: "reviewer",
24746
- prompt: opinionPrompt(plan),
24747
- output: Opinion
24748
- });
24749
- yield* artifact(`opinion:${round}`, {
24750
- kind: "plan_review",
24751
- title: `Second opinion on ${plan.title}`,
24752
- text: [opinion.summary, ...opinion.concerns.map((concern) => `- ${concern}`)].join(`
24753
-
24754
- `)
24755
- });
24756
- break;
24757
- }
24758
24992
  case "Refine": {
24759
24993
  const words = yield* ask(`refine:${round}`, {
24760
24994
  prompt: "What should change in the plan?",
@@ -24764,13 +24998,14 @@ var plan_default = defineLoop({
24764
24998
  });
24765
24999
  const refined = yield* agentWorkOnce(`refine-plan:${round}`, {
24766
25000
  agent: "planner",
24767
- prompt: refinePrompt(plan, words),
25001
+ prompt: refinePrompt(documentText(plan, disputed), words),
24768
25002
  output: Plan
24769
25003
  });
24770
25004
  const before = plan;
24771
25005
  revision++;
24772
- ({ plan, rejected } = yield* checked(refined, revision));
24773
- yield* storePlan(plan, `:${round}`, revision);
25006
+ asked.push(words);
25007
+ ({ plan, rejected, disputed } = yield* checked({ plan: refined }, revision, asked));
25008
+ yield* storePlan({ plan, disputed }, `:${round}`, revision);
24774
25009
  yield* artifact(`changes:${round}`, {
24775
25010
  kind: "plan_changes",
24776
25011
  title: `Revision ${revision} of ${plan.title}`,
@@ -25070,7 +25305,7 @@ var Output11 = Struct({
25070
25305
  improvements: ArraySchema(Struct({ key: String5, loop: Literals(["errand", "build"]), outcome: String5 })),
25071
25306
  notStarted: ArraySchema(Struct({ key: String5, reason: Reason }))
25072
25307
  });
25073
- var oneLine = (text) => text.replace(/\s*\n\s*/g, " \u23CE ");
25308
+ var oneLine2 = (text) => text.replace(/\s*\n\s*/g, " \u23CE ");
25074
25309
  var rootOf = (run) => run.rootRunId ?? run.runId;
25075
25310
  var digest = (runs) => runs.flatMap((run) => [
25076
25311
  [
@@ -25080,18 +25315,18 @@ var digest = (runs) => runs.flatMap((run) => [
25080
25315
  ...rootOf(run) === run.runId ? [] : [`part of ${rootOf(run)}`],
25081
25316
  ...run.teamId === undefined ? [] : [`team ${run.teamId}`],
25082
25317
  ...run.retried === true ? ["retried"] : [],
25083
- ...run.failure === undefined ? [] : [`failure: ${oneLine(run.failure)}`],
25318
+ ...run.failure === undefined ? [] : [`failure: ${oneLine2(run.failure)}`],
25084
25319
  ...run.omitted === undefined ? [] : [`${run.omitted} entries left out`]
25085
25320
  ].join(" \xB7 "),
25086
25321
  ...run.entries.flatMap((entry, index) => [
25087
25322
  ...run.entries[index - 1]?.stepAttemptId === entry.stepAttemptId ? [] : [` attempt ${entry.stepAttemptId}`],
25088
- ` ${entry.sequence} ${entry.kind}: ${oneLine(entry.text)}`
25323
+ ` ${entry.sequence} ${entry.kind}: ${oneLine2(entry.text)}`
25089
25324
  ])
25090
25325
  ]).join(`
25091
25326
  `);
25092
25327
  var earlier = (findings) => findings.length === 0 ? "No earlier finding is open." : [
25093
25328
  "Earlier findings still open, by key. When a problem is one of these, give it that key exactly; a new key only for a new problem:",
25094
- ...findings.map((found) => `- ${found.key}: ${oneLine(found.title)} (${found.taskKey === undefined ? "proposal waiting for a decision" : `open Task ${found.taskKey}`})`)
25329
+ ...findings.map((found) => `- ${found.key}: ${oneLine2(found.title)} (${found.taskKey === undefined ? "proposal waiting for a decision" : `open Task ${found.taskKey}`})`)
25095
25330
  ].join(`
25096
25331
  `);
25097
25332
  var prompt4 = (read, days) => [
@@ -25277,7 +25512,7 @@ var batchPrompt = (requests, target) => [
25277
25512
  ].join(`
25278
25513
 
25279
25514
  `);
25280
- var fixPrompt4 = (failed, applied) => [
25515
+ var fixPrompt3 = (failed, applied) => [
25281
25516
  `The batch of ${applied.map((number) => `!${number}`).join(", ")} fails these checks:`,
25282
25517
  ...failed.checks.filter((check) => check.status === "failed").map((check) => `- ${check.name}: \`${check.command}\``),
25283
25518
  "Fix what an update broke, the way its changelog says to. If an update cannot be fixed in a small change, take it back out and drop it with the reason. Commit nothing yourself."
@@ -25410,7 +25645,7 @@ var sweep_default = defineLoop({
25410
25645
  for (let round = 1;!checked.passed && round <= maxFixRounds && batched.applied.length > 0; round++) {
25411
25646
  batched = yield* agentWork(`fix:${round}`, {
25412
25647
  agent: "implementer",
25413
- prompt: fixPrompt4(checked, batched.applied),
25648
+ prompt: fixPrompt3(checked, batched.applied),
25414
25649
  output: Batched
25415
25650
  });
25416
25651
  for (const drop of batched.dropped)
@@ -25719,6 +25954,11 @@ var kitman_config_default = defineKit({
25719
25954
  extends: "reviewer",
25720
25955
  skills: ["code-review-and-quality", "security-and-hardening"]
25721
25956
  },
25957
+ "plan-reviewer": {
25958
+ extends: "reviewer",
25959
+ fallbacks: [{ harness: "claude", model: "opus", effort: "high" }],
25960
+ instructions: { file: "agents/plan-reviewer.md" }
25961
+ },
25722
25962
  planner: {
25723
25963
  harness: "claude",
25724
25964
  model: "claude-fable-5-2",
@@ -31520,4 +31760,4 @@ var runKit = (config, identity, packages) => {
31520
31760
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
31521
31761
  };
31522
31762
  // .kitman-build-entry.ts
31523
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.13.7" }, []);
31763
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.13.9" }, []);