@kitman-sh/software-engineering 0.10.82 → 0.10.83

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
@@ -19378,6 +19378,7 @@ var PipelineStatus = Struct({
19378
19378
  runnerChecks: optionalKey2(ArraySchema(String5)),
19379
19379
  approved: optionalKey2(String5),
19380
19380
  repository: optionalKey2(String5),
19381
+ targetBranch: optionalKey2(String5),
19381
19382
  conflicts: optionalKey2(Boolean3),
19382
19383
  needsRebase: optionalKey2(Boolean3),
19383
19384
  target: optionalKey2(Struct({ branch: String5, head: String5, jobs: ArraySchema(PipelineJob) }))
@@ -20068,6 +20069,12 @@ var MeasureEvidence = Struct({
20068
20069
  head: MeasureSamples,
20069
20070
  baseAgain: optionalKey2(MeasureSamples)
20070
20071
  });
20072
+ var ResolveSpec = Struct({
20073
+ revisions: ArraySchema(String5.check(isMinLength(1), isMaxLength(240))).check(isMinLength(1), isMaxLength(10))
20074
+ });
20075
+ var ResolvedRevisions = Struct({
20076
+ commits: ArraySchema(String5.check(isPattern2(new RegExp("^[0-9a-f]{40}([0-9a-f]{24})?$", "u"))))
20077
+ });
20071
20078
  var VerificationWorkUnit = Struct({
20072
20079
  kind: Literal2("verification"),
20073
20080
  id: Id,
@@ -20080,6 +20087,7 @@ var VerificationWorkUnit = Struct({
20080
20087
  baseline: optionalKey2(String5.check(isMinLength(1), isMaxLength(300))),
20081
20088
  checks: ArraySchema(RepositoryCheck).check(isMaxLength(50)),
20082
20089
  measure: optionalKey2(MeasureSpec),
20090
+ resolve: optionalKey2(ResolveSpec),
20083
20091
  hosts: optionalKey2(ArraySchema(NetworkHost)),
20084
20092
  storageOrigin: StorageOrigin
20085
20093
  });
@@ -20128,7 +20136,8 @@ var TreeEvidence = Struct({
20128
20136
  var VerificationEvidence = Struct({
20129
20137
  head: TreeEvidence,
20130
20138
  baseline: optionalKey2(TreeEvidence),
20131
- measurement: optionalKey2(MeasureEvidence)
20139
+ measurement: optionalKey2(MeasureEvidence),
20140
+ resolved: optionalKey2(ResolvedRevisions)
20132
20141
  });
20133
20142
  var BoundaryChange = Struct({
20134
20143
  kind: Literal2("change"),
@@ -20171,6 +20180,7 @@ var WorkUnitOutcome = Struct({
20171
20180
  evidence: optionalKey2(VerificationEvidence),
20172
20181
  boundary: optionalKey2(BoundaryChange),
20173
20182
  catchUp: optionalKey2(CatchUp),
20183
+ syncedTarget: optionalKey2(Revision),
20174
20184
  harnessHold: optionalKey2(HarnessHold),
20175
20185
  restart: optionalKey2(StepRestart),
20176
20186
  failureSummary: optionalKey2(String5.check(isMinLength(1), isMaxLength(4000)))
@@ -20301,6 +20311,14 @@ var measure = (name, request) => takeStep(name, "measure", "measure", gen2(funct
20301
20311
  });
20302
20312
  }));
20303
20313
 
20314
+ // ../../packages/sdk/src/loop/resolve.ts
20315
+ var resolveDeferred = (step) => make14(`resolve/${step}`, { success: ResolvedRevisions, error: StepFailed });
20316
+ var resolveRevisions = (name, revisions) => takeStep(name, "verify", "verify", gen2(function* () {
20317
+ const deferred = resolveDeferred(name);
20318
+ yield* launch(deferred, (host, token) => host.startVerification({ step: name, resolve: { revisions }, token }));
20319
+ return (yield* await_2(deferred)).commits;
20320
+ }));
20321
+
20304
20322
  // ../../packages/sdk/src/loop/test-loop.ts
20305
20323
  var LoopJournal = Struct({
20306
20324
  activities: Record(String5, Json2),
@@ -20345,7 +20363,7 @@ var defaultActivities = {
20345
20363
  },
20346
20364
  transcripts: { run: () => succeed7({ runs: [] }) },
20347
20365
  changeRequestRead: {
20348
- pipeline: () => succeed7({ head: "head", status: "success", source: "forge", jobs: [] }),
20366
+ pipeline: () => succeed7({ head: "head", status: "success", source: "forge", jobs: [], targetBranch: "main" }),
20349
20367
  reviewThreads: () => succeed7({ threads: [] }),
20350
20368
  opened: () => succeed7({ changeRequests: [] }),
20351
20369
  own: () => succeed7({ changeRequests: [] })
@@ -20423,6 +20441,14 @@ var scriptedHost = (script, engine, agentLaunches, childLaunches, waits, verifyL
20423
20441
  claimResource: (launch) => flatMap3(script.claimed?.({ step: launch.step, resource: launch.resource, action: launch.action }) ?? undefined_2, (settled) => launch.action === "let_go" ? resolve(letGoDeferred(launch.step), launch.token, succeed4(null)) : resolve(claimDeferred(launch.step), launch.token, succeed4(settled ?? script.claims?.[launch.step] ?? { status: "granted", resource: launch.resource }))),
20424
20442
  startVerification: (launch) => {
20425
20443
  const scripted = script.verifications?.[launch.step];
20444
+ if (launch.resolve !== undefined) {
20445
+ const commits = launch.resolve.revisions.map((revision) => {
20446
+ const scriptedCommit = script.commits?.[revision];
20447
+ return scriptedCommit === undefined ? madeUpCommit(revision) : scriptedCommit;
20448
+ });
20449
+ const unnamed = launch.resolve.revisions.filter((_, index) => commits[index] === null);
20450
+ return resolve(resolveDeferred(launch.step), launch.token, unnamed.length > 0 ? fail5(new StepFailed({ step: launch.step, reason: `No commit named ${unnamed.join(", ")}` })) : succeed4({ commits: commits.filter((commit) => commit !== null) }));
20451
+ }
20426
20452
  if (launch.measure === undefined)
20427
20453
  verifyLaunches.push({
20428
20454
  step: launch.step,
@@ -20452,6 +20478,18 @@ var scriptedHost = (script, engine, agentLaunches, childLaunches, waits, verifyL
20452
20478
  }
20453
20479
  };
20454
20480
  };
20481
+ var fullSha = /^[0-9a-f]{40}$/u;
20482
+ var madeUpCommit = (revision) => {
20483
+ if (fullSha.test(revision))
20484
+ return revision;
20485
+ const word = (seed) => {
20486
+ let hash = seed;
20487
+ for (const char of revision)
20488
+ hash = Math.imul(hash ^ char.charCodeAt(0), 16777619) >>> 0;
20489
+ return hash.toString(16).padStart(8, "0");
20490
+ };
20491
+ return [2166136261, 16777619, 1540483477, 668265263, 374761393].map(word).join("");
20492
+ };
20455
20493
  var loopWorkflow = (loop) => make13(`kitman-loop/${loop.id}`, {
20456
20494
  payload: { input: Json2 },
20457
20495
  idempotencyKey: () => loop.id,
@@ -20654,10 +20692,11 @@ var merged = {
20654
20692
  settled: ArraySchema(String5)
20655
20693
  };
20656
20694
  var SyncAnswer = Union2([UpToDate, Struct(merged), Conflict]);
20695
+ var reported = { base: optionalKey2(String5) };
20657
20696
  var BaseSync = Union2([
20658
- UpToDate,
20659
- Struct({ ...merged, catchUp: optionalKey2(CatchUp) }),
20660
- Conflict
20697
+ Struct({ ...UpToDate.fields, ...reported }),
20698
+ Struct({ ...merged, catchUp: optionalKey2(CatchUp), ...reported }),
20699
+ Struct({ ...Conflict.fields, ...reported })
20661
20700
  ]);
20662
20701
  var afterMerge = "One thing comes before any answer of merged, a clean merge included, and stopping above means stopping after it: before you answer merged, do what the repository's agent instructions say to do once the target branch is merged in, such as regenerating this branch's database migrations on top of the target's. Leave what that changes in the workspace: Kitman commits it.";
20663
20702
  var prompt = (target) => [
@@ -20856,25 +20895,48 @@ class ReviewTargetMissing extends TaggedError3()("ReviewTargetMissing", {
20856
20895
  message: String5
20857
20896
  }) {
20858
20897
  }
20859
- var targetOf = (input, head) => {
20898
+
20899
+ class ReviewDiffEmpty extends TaggedError3()("ReviewDiffEmpty", {
20900
+ message: String5
20901
+ }) {
20902
+ }
20903
+
20904
+ class ReviewBaseUnpinned extends TaggedError3()("ReviewBaseUnpinned", {
20905
+ message: String5
20906
+ }) {
20907
+ }
20908
+ var targetOf = (input, { base, head }) => {
20860
20909
  if (input.changeRequestId !== undefined)
20861
- return `ChangeRequest ${input.changeRequestId} at revision ${head}. Read it with \`kitman.changeRequests.get("${input.changeRequestId}")\` through Kitman's MCP, fetch its source branch, and review the diff of revision ${head} against its target branch, even if the branch has moved since. If the Runner cannot fetch that revision (a fork, say), report exactly that as your only finding, a blocker, and stop.`;
20862
- if (input.base !== undefined && input.head !== undefined && input.files === undefined && input.approved !== undefined)
20910
+ return `ChangeRequest ${input.changeRequestId} at revision ${head}: \`git diff ${base}...${head}\`, its change against its target branch as that stood when this review started. Read it with \`kitman.changeRequests.get("${input.changeRequestId}")\` through Kitman's MCP and fetch its source branch; diff exactly those commits even if either branch has moved since. If the Runner cannot fetch that revision (a fork, say), report exactly that as your only finding, a blocker, and stop.`;
20911
+ if (input.files === undefined && input.approved !== undefined)
20863
20912
  return [
20864
- `only what the change gained or lost since it was approved at ${input.approved}: compare \`git diff ${input.base}...${input.approved}\`, the change as approved, with \`git diff ${input.base}...${input.head}\`, the change now, in your checkout. The rest was reviewed and approved before.`,
20913
+ `only what the change gained or lost since it was approved at ${input.approved}: compare \`git diff ${base}...${input.approved}\`, the change as approved, with \`git diff ${base}...${head}\`, the change now, in your checkout. The rest was reviewed and approved before.`,
20865
20914
  "Report a problem in code the change already had at the approved head only if it matters, with `approvedCode` set to true: such findings are kept apart and do not block."
20866
20915
  ].join(`
20867
20916
 
20868
20917
  `);
20869
- if (input.base !== undefined && input.head !== undefined)
20870
- return input.files === undefined ? `the change \`git diff ${input.base}...${input.head}\` in your checkout.` : [
20871
- `only these files of the change \`git diff ${input.base}...${input.head}\` in your checkout; the rest of it was reviewed and approved before:`,
20872
- ...input.files.map((file) => `- ${file}`),
20873
- ...input.since === undefined ? [] : [`Also review all of \`git diff ${input.since}..${input.head}\`, whichever files it touches.`]
20874
- ].join(`
20918
+ return input.files === undefined ? `the change \`git diff ${base}...${head}\` in your checkout.` : [
20919
+ `only these files of the change \`git diff ${base}...${head}\` in your checkout; the rest of it was reviewed and approved before:`,
20920
+ ...input.files.map((file) => `- ${file}`),
20921
+ ...input.since === undefined ? [] : [`Also review all of \`git diff ${input.since}..${head}\`, whichever files it touches.`]
20922
+ ].join(`
20875
20923
  `);
20876
- return;
20877
20924
  };
20925
+ var pinnedRange = (input) => gen2(function* () {
20926
+ if (input.changeRequestId !== undefined) {
20927
+ const status = yield* pipelineStatus("head", { changeRequestId: input.changeRequestId });
20928
+ if (status.targetBranch === undefined)
20929
+ return yield* new ReviewBaseUnpinned({
20930
+ message: `Kitman did not say which branch ChangeRequest ${input.changeRequestId} merges into, so there is no base to review against; update Kitman`
20931
+ });
20932
+ const [base = ""] = yield* resolveRevisions("pin", [`origin/${status.targetBranch}`]);
20933
+ return { base, head: status.head.toLowerCase() };
20934
+ }
20935
+ if (input.base === undefined || input.head === undefined)
20936
+ return yield* new ReviewTargetMissing({ message: "Name a ChangeRequest, or both base and head revisions" });
20937
+ const [base = "", head = ""] = yield* resolveRevisions("pin", [input.base, input.head]);
20938
+ return { base, head };
20939
+ });
20878
20940
  var wholeChange = (input) => input.files === undefined && input.approved === undefined;
20879
20941
  var scopePrompt = (input) => [
20880
20942
  "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? Set `met` to true only if it does all of it, and list in `unmet` one line for each criterion or part of the description that is not done. If your brief has no Task, leave `scope` out.",
@@ -20949,7 +21011,7 @@ var fixBrief = (changeRequestId, findings) => [
20949
21011
  `);
20950
21012
  var review_default = defineLoop({
20951
21013
  id: "review",
20952
- version: "3.5.0",
21014
+ version: "3.6.0",
20953
21015
  title: "Review",
20954
21016
  input: Input,
20955
21017
  output: Output,
@@ -20973,10 +21035,13 @@ var review_default = defineLoop({
20973
21035
  { id: "review", title: "Review again", loop: "review" }
20974
21036
  ],
20975
21037
  run: (input) => gen2(function* () {
20976
- const head = input.changeRequestId === undefined ? undefined : (yield* pipelineStatus("head", { changeRequestId: input.changeRequestId })).head;
20977
- const target = targetOf(input, head);
20978
- if (target === undefined)
20979
- return yield* new ReviewTargetMissing({ message: "Name a ChangeRequest, or both base and head revisions" });
21038
+ const range = yield* pinnedRange(input);
21039
+ const head = input.changeRequestId === undefined ? undefined : range.head;
21040
+ if (range.base === range.head)
21041
+ return yield* new ReviewDiffEmpty({
21042
+ message: `Base and head are both commit ${range.head}, so the diff is empty: give the base the change is to merge into`
21043
+ });
21044
+ const target = targetOf(input, range);
20980
21045
  const verified = head === undefined ? { failing: [], notRun: [] } : yield* verifyHead("verify", head);
20981
21046
  const failing = [...new Set([...input.failing ?? [], ...verified.failing])];
20982
21047
  const notRun = [...new Set([...input.notRun ?? [], ...verified.notRun])];
@@ -22243,6 +22308,11 @@ class BuildBlocked extends TaggedError3()("BuildBlocked", {
22243
22308
  }) {
22244
22309
  }
22245
22310
 
22311
+ class BuildBaseUnpinned extends TaggedError3()("BuildBaseUnpinned", {
22312
+ message: String5
22313
+ }) {
22314
+ }
22315
+
22246
22316
  class BuildTargetMissing extends TaggedError3()("BuildTargetMissing", {
22247
22317
  message: String5
22248
22318
  }) {
@@ -22339,6 +22409,11 @@ var rally = (input) => gen2(function* () {
22339
22409
  });
22340
22410
  if (synced.status === "conflict")
22341
22411
  conflicts.push(`Could not merge the target branch in round ${round}: ${synced.files.join(", ")} (${synced.reason})`);
22412
+ const base = synced.base;
22413
+ if (base === undefined)
22414
+ return yield* new BuildBaseUnpinned({
22415
+ message: `The Runner did not report which commit of ${input.target ?? "the default branch"} it merged in round ${round}, so there is no base to review against; update the Runner`
22416
+ });
22342
22417
  const head = yield* verify(`verify:${round}`, { suggested: input.suggested });
22343
22418
  if (last !== undefined && last.head.tree === head.tree && rebuttals.length === 0 && onlyChecksBlock(last.settled))
22344
22419
  return {
@@ -22352,7 +22427,7 @@ var rally = (input) => gen2(function* () {
22352
22427
  const failing = brokenChecks(head).map((check) => check.name);
22353
22428
  const notRun = testsNotRunReasons(head);
22354
22429
  const reviewed = yield* call(`review:${round}`, review_default, {
22355
- base: input.base,
22430
+ base,
22356
22431
  head: head.revision,
22357
22432
  ...rebuttals.length === 0 ? undefined : { rebuttals },
22358
22433
  ...earlier.length === 0 ? undefined : { earlier },
@@ -22396,7 +22471,7 @@ var rally = (input) => gen2(function* () {
22396
22471
  });
22397
22472
  var build2 = defineLoop({
22398
22473
  id: "build",
22399
- version: "2.4.0",
22474
+ version: "2.5.0",
22400
22475
  title: "Build",
22401
22476
  input: BuildInput,
22402
22477
  output: BuildOutput,
@@ -22420,7 +22495,7 @@ var build2 = defineLoop({
22420
22495
  yield* writeBack("write-back:started", { milestone: "started" });
22421
22496
  const task = input.words === undefined ? "the Task your brief describes." : `this: ${input.words}`;
22422
22497
  const outcome = input.outcome;
22423
- const target = input.branch ?? input.continuing?.targetBranch;
22498
+ const target = input.continuing?.targetBranch ?? input.branch;
22424
22499
  if (input.changeRequestId !== undefined && input.continuing?.changeRequestId !== input.changeRequestId)
22425
22500
  return yield* new BuildTargetMissing({
22426
22501
  message: `Kitman did not put this Run on ChangeRequest ${input.changeRequestId}'s branch`
@@ -22446,7 +22521,6 @@ var build2 = defineLoop({
22446
22521
  })).criteria : implemented.criteria ?? [];
22447
22522
  const last = yield* rally({
22448
22523
  maxRounds: input.maxRounds ?? 3,
22449
- base: `origin/${target ?? "HEAD"}`,
22450
22524
  target,
22451
22525
  outcome,
22452
22526
  claims: [...implemented.claims, ...criteria.map((answer) => `Criterion ${answerLine(answer)}`)],
@@ -27158,7 +27232,8 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
27158
27232
  plan: MeasurePlan,
27159
27233
  samples: Int,
27160
27234
  calibrate: Boolean3
27161
- }))
27235
+ })),
27236
+ resolve: optionalKey2(ResolveSpec)
27162
27237
  },
27163
27238
  success: Struct({ verificationId: String5 }),
27164
27239
  error: RunnerRpcError
@@ -27299,6 +27374,7 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
27299
27374
  runnerChecks: optionalKey2(ArraySchema(String5)),
27300
27375
  approved: optionalKey2(String5),
27301
27376
  repository: optionalKey2(String5),
27377
+ targetBranch: optionalKey2(String5),
27302
27378
  conflicts: optionalKey2(Boolean3),
27303
27379
  needsRebase: optionalKey2(Boolean3),
27304
27380
  target: optionalKey2(Struct({
@@ -27657,12 +27733,13 @@ var runnerHost = (capabilities) => ({
27657
27733
  })).pipe(asVoid2),
27658
27734
  startVerification: (launch) => requested(launch.step, capabilities.startVerification({
27659
27735
  step: launch.step,
27660
- deferredName: (launch.measure === undefined ? verifyDeferred : measureDeferred)(launch.step).name,
27736
+ deferredName: (launch.resolve !== undefined ? resolveDeferred : launch.measure === undefined ? verifyDeferred : measureDeferred)(launch.step).name,
27661
27737
  ...launch.revision === undefined ? undefined : { revision: launch.revision },
27662
27738
  ...launch.checks === undefined ? undefined : { checks: launch.checks },
27663
27739
  ...launch.suggested === undefined ? undefined : { suggested: launch.suggested },
27664
27740
  ...launch.rerunFailed === undefined ? undefined : { rerunFailed: launch.rerunFailed },
27665
- ...launch.measure === undefined ? undefined : { measure: launch.measure }
27741
+ ...launch.measure === undefined ? undefined : { measure: launch.measure },
27742
+ ...launch.resolve === undefined ? undefined : { resolve: launch.resolve }
27666
27743
  })).pipe(asVoid2),
27667
27744
  startAgentWork: (launch) => requested(launch.step, capabilities.startAgentStep({
27668
27745
  step: launch.step,
@@ -27888,7 +27965,8 @@ var rpcProgramPorts = (rpc, work) => {
27888
27965
  ...verification.checks === undefined ? undefined : { checks: [...verification.checks] },
27889
27966
  ...verification.suggested === undefined ? undefined : { suggested: [...verification.suggested] },
27890
27967
  ...verification.rerunFailed === undefined ? undefined : { rerunFailed: verification.rerunFailed },
27891
- ...verification.measure === undefined ? undefined : { measure: verification.measure }
27968
+ ...verification.measure === undefined ? undefined : { measure: verification.measure },
27969
+ ...verification.resolve === undefined ? undefined : { resolve: { revisions: [...verification.resolve.revisions] } }
27892
27970
  }),
27893
27971
  startAgentStep: ({ secrets, ...step }) => rpc.startAgentStep({ lease, ...step, ...secrets === undefined ? undefined : { secrets: [...secrets] } }),
27894
27972
  awaitEvent: (wait) => rpc.awaitEvent({ lease, ...wait }),
@@ -30184,4 +30262,4 @@ var runKit = (config, identity, packages) => {
30184
30262
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
30185
30263
  };
30186
30264
  // .kitman-build-entry.ts
30187
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.82" }, []);
30265
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.83" }, []);
@@ -3,7 +3,7 @@
3
3
  {
4
4
  "id": "build",
5
5
  "title": "Build",
6
- "version": "2.4.0",
6
+ "version": "2.5.0",
7
7
  "input": {
8
8
  "type": "object",
9
9
  "properties": {
@@ -2102,7 +2102,7 @@
2102
2102
  {
2103
2103
  "id": "review",
2104
2104
  "title": "Review",
2105
- "version": "3.5.0",
2105
+ "version": "3.6.0",
2106
2106
  "input": {
2107
2107
  "type": "object",
2108
2108
  "properties": {
@@ -3417,7 +3417,7 @@
3417
3417
  "carried": [
3418
3418
  {
3419
3419
  "name": "@kitman-sh/software-engineering",
3420
- "version": "0.10.82",
3420
+ "version": "0.10.83",
3421
3421
  "setup": "2a237548a69b0cd53ec3be7f687cfa8c2128335b3a655d34e185f2abce6a3c37",
3422
3422
  "loops": [
3423
3423
  "build",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitman-sh/software-engineering",
3
- "version": "0.10.82",
3
+ "version": "0.10.83",
4
4
  "description": "Everything for building software: Loops, their Agents, the skills they use and the Ponytail plugin.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -17,12 +17,12 @@
17
17
  "tsconfig.json"
18
18
  ],
19
19
  "dependencies": {
20
- "@kitman-sh/sdk": "0.10.82",
20
+ "@kitman-sh/sdk": "0.10.83",
21
21
  "effect": "^4.1.2"
22
22
  },
23
23
  "kitman": {
24
24
  "bundle": "dist/bundle.js",
25
- "digest": "828c128c0e8d48d9b8612e9fc73aca0cedaa37a4a28d319ffec70eabd5d1fe84",
25
+ "digest": "2ebc1034e681c6f84e977ff6d45fa9612edfcbe582157648d7c7247bb441bfae",
26
26
  "protocolVersion": 5,
27
27
  "declarations": "dist/declarations.json",
28
28
  "setup": {
package/src/build.ts CHANGED
@@ -153,6 +153,11 @@ export class BuildBlocked extends Schema.TaggedError<BuildBlocked>()('BuildBlock
153
153
  message: Schema.String
154
154
  }) {}
155
155
 
156
+ /** The base sync did not say which target commit it merged, so a review would have no fixed base to diff against. */
157
+ export class BuildBaseUnpinned extends Schema.TaggedError<BuildBaseUnpinned>()('BuildBaseUnpinned', {
158
+ message: Schema.String
159
+ }) {}
160
+
156
161
  export class BuildTargetMissing extends Schema.TaggedError<BuildTargetMissing>()('BuildTargetMissing', {
157
162
  message: Schema.String
158
163
  }) {}
@@ -278,7 +283,6 @@ type Round = {
278
283
  */
279
284
  const rally = (input: {
280
285
  readonly maxRounds: number
281
- readonly base: string
282
286
  readonly target: string | undefined
283
287
  readonly outcome: LoopOutcome | undefined
284
288
  readonly claims: readonly string[]
@@ -305,6 +309,14 @@ const rally = (input: {
305
309
  `Could not merge the target branch in round ${round}: ${synced.files.join(', ')} (${synced.reason})`
306
310
  )
307
311
 
312
+ // Pinned, so a target that moves during the round does not move what is reviewed.
313
+ const base = synced.base
314
+
315
+ if (base === undefined)
316
+ return yield* new BuildBaseUnpinned({
317
+ message: `The Runner did not report which commit of ${input.target ?? 'the default branch'} it merged in round ${round}, so there is no base to review against; update the Runner`
318
+ })
319
+
308
320
  const head = yield* verify(`verify:${round}`, { suggested: input.suggested })
309
321
 
310
322
  // Evidence is held per tree, so the same checks would fail again and a review would judge the same change.
@@ -322,7 +334,7 @@ const rally = (input: {
322
334
  const notRun = testsNotRunReasons(head)
323
335
 
324
336
  const reviewed = yield* call(`review:${round}`, review, {
325
- base: input.base,
337
+ base,
326
338
  head: head.revision,
327
339
  ...(rebuttals.length === 0 ? undefined : { rebuttals }),
328
340
  ...(earlier.length === 0 ? undefined : { earlier }),
@@ -396,7 +408,7 @@ const rally = (input: {
396
408
  */
397
409
  const build = defineLoop({
398
410
  id: 'build',
399
- version: '2.4.0',
411
+ version: '2.5.0',
400
412
  title: 'Build',
401
413
  input: BuildInput,
402
414
  output: BuildOutput,
@@ -425,7 +437,8 @@ const build = defineLoop({
425
437
 
426
438
  const task = input.words === undefined ? 'the Task your brief describes.' : `this: ${input.words}`
427
439
  const outcome = input.outcome
428
- const target = input.branch ?? input.continuing?.targetBranch
440
+ // A retry carries the Run's own branch as `branch`; the ChangeRequest it continues says what it merges into.
441
+ const target = input.continuing?.targetBranch ?? input.branch
429
442
 
430
443
  if (input.changeRequestId !== undefined && input.continuing?.changeRequestId !== input.changeRequestId)
431
444
  return yield* new BuildTargetMissing({
@@ -475,8 +488,6 @@ const build = defineLoop({
475
488
 
476
489
  const last = yield* rally({
477
490
  maxRounds: input.maxRounds ?? 3,
478
- // Against the target, not `revision`: a Build handed a revision, such as an Errand's head, reviews that change too.
479
- base: `origin/${target ?? 'HEAD'}`,
480
491
  target,
481
492
  outcome,
482
493
  claims: [...implemented.claims, ...criteria.map(answer => `Criterion ${answerLine(answer)}`)],
package/src/review.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  Rebuttal,
16
16
  RebuttalVerdict,
17
17
  pipelineStatus,
18
+ resolveRevisions,
18
19
  ScopeJudgement
19
20
  } from '@kitman-sh/sdk/loop'
20
21
  import * as Effect from 'effect/Effect'
@@ -125,30 +126,67 @@ export class ReviewTargetMissing extends Schema.TaggedError<ReviewTargetMissing>
125
126
  message: Schema.String
126
127
  }) {}
127
128
 
128
- const targetOf = (input: typeof Input.Type, head?: string) => {
129
+ /** The base and head are one commit, so there is no change to review. */
130
+ export class ReviewDiffEmpty extends Schema.TaggedError<ReviewDiffEmpty>()('ReviewDiffEmpty', {
131
+ message: Schema.String
132
+ }) {}
133
+
134
+ /** A ChangeRequest's target branch is not known, so the review has no base to pin. */
135
+ export class ReviewBaseUnpinned extends Schema.TaggedError<ReviewBaseUnpinned>()('ReviewBaseUnpinned', {
136
+ message: Schema.String
137
+ }) {}
138
+
139
+ /** The commits a review diffs, `git diff base...head`, resolved once so every seat reads the same diff. */
140
+ type Range = { readonly base: string; readonly head: string }
141
+
142
+ const targetOf = (input: typeof Input.Type, { base, head }: Range) => {
129
143
  if (input.changeRequestId !== undefined)
130
- return `ChangeRequest ${input.changeRequestId} at revision ${head}. Read it with \`kitman.changeRequests.get("${input.changeRequestId}")\` through Kitman's MCP, fetch its source branch, and review the diff of revision ${head} against its target branch, even if the branch has moved since. If the Runner cannot fetch that revision (a fork, say), report exactly that as your only finding, a blocker, and stop.`
144
+ return `ChangeRequest ${input.changeRequestId} at revision ${head}: \`git diff ${base}...${head}\`, its change against its target branch as that stood when this review started. Read it with \`kitman.changeRequests.get("${input.changeRequestId}")\` through Kitman's MCP and fetch its source branch; diff exactly those commits even if either branch has moved since. If the Runner cannot fetch that revision (a fork, say), report exactly that as your only finding, a blocker, and stop.`
131
145
 
132
- if (input.base !== undefined && input.head !== undefined && input.files === undefined && input.approved !== undefined)
146
+ if (input.files === undefined && input.approved !== undefined)
133
147
  return [
134
- `only what the change gained or lost since it was approved at ${input.approved}: compare \`git diff ${input.base}...${input.approved}\`, the change as approved, with \`git diff ${input.base}...${input.head}\`, the change now, in your checkout. The rest was reviewed and approved before.`,
148
+ `only what the change gained or lost since it was approved at ${input.approved}: compare \`git diff ${base}...${input.approved}\`, the change as approved, with \`git diff ${base}...${head}\`, the change now, in your checkout. The rest was reviewed and approved before.`,
135
149
  'Report a problem in code the change already had at the approved head only if it matters, with `approvedCode` set to true: such findings are kept apart and do not block.'
136
150
  ].join('\n\n')
137
151
 
138
- if (input.base !== undefined && input.head !== undefined)
139
- return input.files === undefined
140
- ? `the change \`git diff ${input.base}...${input.head}\` in your checkout.`
141
- : [
142
- `only these files of the change \`git diff ${input.base}...${input.head}\` in your checkout; the rest of it was reviewed and approved before:`,
143
- ...input.files.map(file => `- ${file}`),
144
- ...(input.since === undefined
145
- ? []
146
- : [`Also review all of \`git diff ${input.since}..${input.head}\`, whichever files it touches.`])
147
- ].join('\n')
148
-
149
- return undefined
152
+ return input.files === undefined
153
+ ? `the change \`git diff ${base}...${head}\` in your checkout.`
154
+ : [
155
+ `only these files of the change \`git diff ${base}...${head}\` in your checkout; the rest of it was reviewed and approved before:`,
156
+ ...input.files.map(file => `- ${file}`),
157
+ ...(input.since === undefined
158
+ ? []
159
+ : [`Also review all of \`git diff ${input.since}..${head}\`, whichever files it touches.`])
160
+ ].join('\n')
150
161
  }
151
162
 
163
+ /**
164
+ * The commits the review diffs, read on a Runner when it starts: a ChangeRequest's head against its target branch,
165
+ * else `base` against `head`. A branch that moves later does not move the diff.
166
+ */
167
+ const pinnedRange = (input: typeof Input.Type) =>
168
+ Effect.gen(function* () {
169
+ if (input.changeRequestId !== undefined) {
170
+ const status = yield* pipelineStatus('head', { changeRequestId: input.changeRequestId })
171
+
172
+ if (status.targetBranch === undefined)
173
+ return yield* new ReviewBaseUnpinned({
174
+ message: `Kitman did not say which branch ChangeRequest ${input.changeRequestId} merges into, so there is no base to review against; update Kitman`
175
+ })
176
+
177
+ const [base = ''] = yield* resolveRevisions('pin', [`origin/${status.targetBranch}`])
178
+
179
+ return { base, head: status.head.toLowerCase() }
180
+ }
181
+
182
+ if (input.base === undefined || input.head === undefined)
183
+ return yield* new ReviewTargetMissing({ message: 'Name a ChangeRequest, or both base and head revisions' })
184
+
185
+ const [base = '', head = ''] = yield* resolveRevisions('pin', [input.base, input.head])
186
+
187
+ return { base, head }
188
+ })
189
+
152
190
  /** A review of the whole change judges its scope; one of some files or of a change since an approval does not. */
153
191
  const wholeChange = (input: typeof Input.Type) => input.files === undefined && input.approved === undefined
154
192
 
@@ -258,15 +296,16 @@ const fixBrief = (changeRequestId: string, findings: readonly MergedFinding[]) =
258
296
 
259
297
  /**
260
298
  * Reviews a ChangeRequest or a revision range with two reviewer Agents, one following the `code-review` skill and one
261
- * `code-review-and-quality`, and writes one review from their findings, each said once. Given an earlier review's
262
- * findings it follows them up, keeping their ids. On a ChangeRequest it verifies the head it reviews against the
299
+ * `code-review-and-quality`, and writes one review from their findings, each said once. It first resolves the base and
300
+ * head to commits on a Runner, so every reviewer reads one diff, and fails when they are one commit. Given an earlier
301
+ * review's findings it follows them up, keeping their ids. On a ChangeRequest it verifies the head it reviews against the
263
302
  * ChangeRequest's target and approves it when nothing blocks it, none of its checks broke and verify ran all of its
264
303
  * tests, unless it wrote the change, then asks what next and posts only when told to, as one summary comment it edits
265
304
  * on later reviews.
266
305
  */
267
306
  export default defineLoop({
268
307
  id: 'review',
269
- version: '3.5.0',
308
+ version: '3.6.0',
270
309
  title: 'Review',
271
310
  input: Input,
272
311
  output: Output,
@@ -293,15 +332,15 @@ export default defineLoop({
293
332
  run: input =>
294
333
  Effect.gen(function* () {
295
334
  // The head is read first, so an approval approves the commit the reviewers read.
296
- const head =
297
- input.changeRequestId === undefined
298
- ? undefined
299
- : (yield* pipelineStatus('head', { changeRequestId: input.changeRequestId })).head
335
+ const range = yield* pinnedRange(input)
336
+ const head = input.changeRequestId === undefined ? undefined : range.head
300
337
 
301
- const target = targetOf(input, head)
338
+ if (range.base === range.head)
339
+ return yield* new ReviewDiffEmpty({
340
+ message: `Base and head are both commit ${range.head}, so the diff is empty: give the base the change is to merge into`
341
+ })
302
342
 
303
- if (target === undefined)
304
- return yield* new ReviewTargetMissing({ message: 'Name a ChangeRequest, or both base and head revisions' })
343
+ const target = targetOf(input, range)
305
344
 
306
345
  // Evidence Kitman holds for the head's tree is reused.
307
346
  const verified = head === undefined ? { failing: [], notRun: [] } : yield* verifyHead('verify', head)