@kitman-sh/software-engineering 0.10.69 → 0.10.71

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/src/plan.ts CHANGED
@@ -106,6 +106,8 @@ const menuDescriptions: Record<Choice, string> = {
106
106
 
107
107
  const onConflict = ['Rebuild on the integration branch', 'Skip'] as const
108
108
 
109
+ const onUnverified = ['Skip', 'Merge'] as const
110
+
109
111
  const onFailure = ['Retry with a steer', 'Skip it and its dependents', 'Stop here'] as const
110
112
 
111
113
  const ticketRules = [
@@ -256,9 +258,10 @@ const settled = (ticket: PlanTicket, result: Omit<TicketResult, 'key' | 'title'>
256
258
  })
257
259
 
258
260
  /**
259
- * Builds a ticket from the integration head, then merges its ChangeRequest into the integration branch. On a
260
- * conflict the user chooses to rebuild from the head as it is now, or to give the ticket up. `steer` is a person's
261
- * words for a retry; `label` names its Steps apart from the first try's.
261
+ * Builds a ticket from the integration head, then merges its ChangeRequest into the integration branch. When verify
262
+ * never ran some of its tests, the user chooses to merge it or skip it. On a conflict the user chooses to rebuild from
263
+ * the head as it is now, or to give the ticket up. `steer` is a person's words for a retry; `label` names its Steps
264
+ * apart from the first try's.
262
265
  */
263
266
  const buildTicket = (
264
267
  ticket: PlanTicket,
@@ -293,14 +296,31 @@ const buildTicket = (
293
296
  if (built instanceof ChildFailed)
294
297
  return settled(ticket, { status: 'failed', repoBindingId: head.repoBindingId, reason: built.reason })
295
298
 
299
+ const delivered = { repoBindingId: head.repoBindingId, changeRequest: built.changeRequest }
300
+
301
+ if (built.notRun !== undefined && built.notRun.length > 0) {
302
+ const unverified = yield* ask(`unverified:${name}${suffix}`, {
303
+ prompt: `Verify never ran some tests of the ChangeRequest for ${ticket.key} (${built.changeRequest.url}):\n${built.notRun.map(item => `- ${item}`).join('\n')}\n\nMerge it once they pass by hand, or skip it and the tickets it blocks?`,
304
+ options: [
305
+ { value: 'Skip', description: 'Leaves it and the tickets it blocks unmerged.' },
306
+ { value: 'Merge', description: 'Merges it into the integration branch, for when the tests pass by hand.' }
307
+ ] satisfies { readonly value: (typeof onUnverified)[number]; readonly description: string }[],
308
+ recommended: 'Skip',
309
+ recommendationReason: 'Nobody has seen these tests pass, so merging would land them as if they had.',
310
+ default: 'Skip',
311
+ timeout: '1 day'
312
+ })
313
+
314
+ if (unverified === 'Skip')
315
+ return settled(ticket, { status: 'skipped', ...delivered, reason: 'Verify never ran some of its tests' })
316
+ }
317
+
296
318
  // Only what the Build verified merges; a commit pushed to its branch since is rebuilt or skipped like a conflict.
297
319
  const merged = yield* mergeChangeRequest(`merge:${name}${suffix}`, {
298
320
  changeRequestId: built.changeRequest.id,
299
321
  head: built.revision
300
322
  })
301
323
 
302
- const delivered = { repoBindingId: head.repoBindingId, changeRequest: built.changeRequest }
303
-
304
324
  if (merged.status === 'merged') return settled(ticket, { status: 'merged', ...delivered })
305
325
 
306
326
  const choice = yield* ask(`conflict:${name}${suffix}`, {
@@ -478,7 +498,7 @@ const implement = (input: typeof Input.Type, plan: Plan, revision: number, filed
478
498
  */
479
499
  export default defineLoop({
480
500
  id: 'plan',
481
- version: '2.0.0',
501
+ version: '2.1.0',
482
502
  title: 'Plan',
483
503
  input: Input,
484
504
  output: Output,
package/src/review.ts CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  import * as Effect from 'effect/Effect'
21
21
  import * as Schema from 'effect/Schema'
22
22
  import build, { BuildInput, BuildOutput } from './build'
23
+ import { verifyHead } from './change-request-body'
23
24
 
24
25
  /** Build, by its schemas: the module imports this one, so its definition is not ready when this one loads. */
25
26
  const buildLoop = () => ({ id: 'build', input: BuildInput, output: BuildOutput })
@@ -57,6 +58,11 @@ const Input = Schema.Struct({
57
58
  files: Schema.optional(Schema.Array(Schema.String)),
58
59
  /** With `files`, also reviews everything in `git diff since..head`, such as a fix made after the files' review. */
59
60
  since: Schema.optional(Schema.String),
61
+ /**
62
+ * With `base` and `head`, the last approved head: reviews only what the change gained or lost since then, judges no
63
+ * scope, and keeps findings about code that head already had apart, where they do not block.
64
+ */
65
+ approved: Schema.optional(Schema.String),
60
66
  /** The implementer's rebuttals of the last round's findings, for the panel to judge. */
61
67
  rebuttals: Schema.optional(Schema.Array(Rebuttal)),
62
68
  /** The Outcome the change must prove. */
@@ -67,6 +73,8 @@ const Input = Schema.Struct({
67
73
  earlier: Schema.optional(Schema.Array(MergedFinding)),
68
74
  /** The checks that fail on the head and pass on the base, which the implementer is already told. */
69
75
  failing: Schema.optional(Schema.Array(Schema.String)),
76
+ /** Why each head test verify never ran is unverified; a ChangeRequest's head is verified here too. */
77
+ notRun: Schema.optional(Schema.Array(Schema.String)),
70
78
  /** What to do after a ChangeRequest's review without asking; Done when nobody answers. */
71
79
  next: Schema.optional(Schema.Literals(choices))
72
80
  })
@@ -75,10 +83,16 @@ const FollowUpStatus = Schema.Literals(['fixed', 'changed', 'still_there'])
75
83
 
76
84
  const FollowUp = Schema.Struct({ id: Schema.String, status: FollowUpStatus })
77
85
 
86
+ const SeatFinding = Schema.Struct({
87
+ ...Finding.fields,
88
+ /** In a review since an approved head: the problem is in code the change already had there. */
89
+ approvedCode: Schema.optional(Schema.Boolean)
90
+ })
91
+
78
92
  const SeatOutput = Schema.Struct({
79
93
  /** One sentence: can it merge, and what matters most. */
80
94
  summary: Schema.String,
81
- findings: Schema.Array(Finding),
95
+ findings: Schema.Array(SeatFinding),
82
96
  verdicts: Schema.optional(Schema.Array(RebuttalVerdict)),
83
97
  scope: Schema.optional(ScopeJudgement),
84
98
  followUps: Schema.optional(Schema.Array(FollowUp))
@@ -88,6 +102,8 @@ const Output = Schema.Struct({
88
102
  /** What the review leads with: each reviewer's one sentence. */
89
103
  summary: Schema.String,
90
104
  findings: Schema.Array(MergedFinding),
105
+ /** In a review since an approved head, the findings about code that head already had; they never block. */
106
+ approvedFindings: Schema.optional(Schema.Array(MergedFinding)),
91
107
  /** Each earlier finding, as fixed, changed but not fixed, or still there. */
92
108
  followUps: Schema.Array(FollowUp),
93
109
  verdicts: Schema.Array(RebuttalVerdict),
@@ -111,6 +127,12 @@ const targetOf = (input: typeof Input.Type, head?: string) => {
111
127
  if (input.changeRequestId !== undefined)
112
128
  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.`
113
129
 
130
+ if (input.base !== undefined && input.head !== undefined && input.files === undefined && input.approved !== undefined)
131
+ return [
132
+ `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.`,
133
+ '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.'
134
+ ].join('\n\n')
135
+
114
136
  if (input.base !== undefined && input.head !== undefined)
115
137
  return input.files === undefined
116
138
  ? `the change \`git diff ${input.base}...${input.head}\` in your checkout.`
@@ -125,6 +147,9 @@ const targetOf = (input: typeof Input.Type, head?: string) => {
125
147
  return undefined
126
148
  }
127
149
 
150
+ /** A review of the whole change judges its scope; one of some files or of a change since an approval does not. */
151
+ const wholeChange = (input: typeof Input.Type) => input.files === undefined && input.approved === undefined
152
+
128
153
  const scopePrompt = (input: typeof Input.Type) =>
129
154
  [
130
155
  "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.",
@@ -143,19 +168,33 @@ const earlierPrompt = (earlier: readonly MergedFinding[]) =>
143
168
  ...earlier.map(finding => `- ${finding.id} (${finding.severity}): ${finding.detail}`)
144
169
  ].join('\n')
145
170
 
146
- const promptFor = (seat: keyof typeof seats, target: string, input: typeof Input.Type) =>
171
+ const promptFor = (
172
+ seat: keyof typeof seats,
173
+ target: string,
174
+ input: typeof Input.Type,
175
+ failing: readonly string[],
176
+ notRun: readonly string[]
177
+ ) =>
147
178
  [
148
179
  `You are one of two reviewers. Follow your \`${seats[seat].skill}\` skill; if you do not have it: ${seats[seat].focus}`,
149
180
  `Review ${target}`,
150
181
  'Give `summary`: one sentence on whether it can merge and what matters most.',
151
182
  '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.',
152
183
  '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.',
153
- ...(seat === scopeSeat && input.files === undefined ? [scopePrompt(input)] : []),
184
+ ...(seat === scopeSeat && wholeChange(input) ? [scopePrompt(input)] : []),
154
185
  ...(input.earlier === undefined || input.earlier.length === 0 ? [] : [earlierPrompt(input.earlier)]),
155
- ...(input.failing === undefined || input.failing.length === 0
186
+ ...(failing.length === 0
156
187
  ? []
157
188
  : [
158
- `These checks fail on this head and pass on the base: ${input.failing.join(', ')}. The implementer has their output, so do not report them as findings, and do not say it can merge while they fail.`
189
+ `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.`
190
+ ]),
191
+ ...(notRun.length === 0
192
+ ? []
193
+ : [
194
+ [
195
+ 'Verify never ran these tests: its checks passed with them skipped. Treat what they test as unverified, not as passing; read each in the code, report one that looks wrong as a finding, and do not say it can merge on their strength.',
196
+ ...notRun.map(item => `- ${item}`)
197
+ ].join('\n')
159
198
  ]),
160
199
  ...(input.rebuttals === undefined || input.rebuttals.length === 0
161
200
  ? []
@@ -181,22 +220,27 @@ const followUpsOf = (earlier: readonly MergedFinding[], answers: readonly (typeo
181
220
  }
182
221
  })
183
222
 
223
+ const findingLines = (findings: readonly MergedFinding[]) =>
224
+ findings
225
+ .map(finding => `- **${finding.severity}** \`${finding.id}\` ${finding.detail} _(${finding.seats.join(', ')})_`)
226
+ .join('\n')
227
+
184
228
  const reviewText = (
185
229
  summary: string,
186
230
  findings: readonly MergedFinding[],
187
- followUps: readonly (typeof FollowUp.Type)[]
231
+ followUps: readonly (typeof FollowUp.Type)[],
232
+ approvedFindings: readonly MergedFinding[],
233
+ notRun: readonly string[]
188
234
  ) =>
189
235
  [
190
236
  `**Kitman review.** ${summary}`,
191
- ...(findings.length === 0
237
+ ...(notRun.length === 0
192
238
  ? []
193
- : [
194
- findings
195
- .map(
196
- finding => `- **${finding.severity}** \`${finding.id}\` ${finding.detail} _(${finding.seats.join(', ')})_`
197
- )
198
- .join('\n')
199
- ]),
239
+ : [`Verify never ran these tests, so they are unverified:\n${notRun.map(item => `- ${item}`).join('\n')}`]),
240
+ ...(findings.length === 0 ? [] : [findingLines(findings)]),
241
+ ...(approvedFindings.length === 0
242
+ ? []
243
+ : [`In code approved before, not blocking:\n${findingLines(approvedFindings)}`]),
200
244
  ...(followUps.length === 0
201
245
  ? []
202
246
  : [
@@ -213,13 +257,14 @@ const fixBrief = (changeRequestId: string, findings: readonly MergedFinding[]) =
213
257
  /**
214
258
  * Reviews a ChangeRequest or a revision range with two reviewer Agents, one following the `code-review` skill and one
215
259
  * `code-review-and-quality`, and writes one review from their findings, each said once. Given an earlier review's
216
- * findings it follows them up, keeping their ids. On a ChangeRequest it approves the head it reviewed when nothing
217
- * blocks it, unless it wrote the change, then asks what next and posts only when told to, as one summary
218
- * comment it edits on later reviews.
260
+ * findings it follows them up, keeping their ids. On a ChangeRequest it verifies the head it reviews against the
261
+ * ChangeRequest's target and approves it when nothing blocks it, none of its checks broke and verify ran all of its
262
+ * tests, unless it wrote the change, then asks what next and posts only when told to, as one summary comment it edits
263
+ * on later reviews.
219
264
  */
220
265
  export default defineLoop({
221
266
  id: 'review',
222
- version: '3.3.0',
267
+ version: '3.5.0',
223
268
  title: 'Review',
224
269
  input: Input,
225
270
  output: Output,
@@ -256,12 +301,18 @@ export default defineLoop({
256
301
  if (target === undefined)
257
302
  return yield* new ReviewTargetMissing({ message: 'Name a ChangeRequest, or both base and head revisions' })
258
303
 
304
+ // Evidence Kitman holds for the head's tree is reused.
305
+ const verified = head === undefined ? { failing: [], notRun: [] } : yield* verifyHead('verify', head)
306
+
307
+ const failing = [...new Set([...(input.failing ?? []), ...verified.failing])]
308
+ const notRun = [...new Set([...(input.notRun ?? []), ...verified.notRun])]
309
+
259
310
  const outputs = yield* Effect.forEach(
260
311
  seatNames,
261
312
  seat =>
262
313
  agentWork(`review:${seat}`, {
263
314
  agent: seat,
264
- prompt: promptFor(seat, target, input),
315
+ prompt: promptFor(seat, target, input, failing, notRun),
265
316
  output: SeatOutput
266
317
  }).pipe(Effect.map(output => [seat, output] as const)),
267
318
  { concurrency: 'unbounded' }
@@ -290,20 +341,29 @@ export default defineLoop({
290
341
  const carried = earlier.filter(finding => standing.has(finding.id) && !withdrawn(finding.id))
291
342
  const followUps = answered.filter(entry => !withdrawn(entry.id))
292
343
 
293
- const fresh = mergeFindings(
294
- Object.fromEntries(
295
- outputs.map(([seat, output]) => [
296
- seat,
297
- output.findings.filter(finding => !earlierIds.has(`${finding.file}:${finding.line}`))
298
- ])
344
+ const sinceApproval = input.approved !== undefined && input.files === undefined
345
+
346
+ const merged = (approvedCode: boolean) =>
347
+ mergeFindings(
348
+ Object.fromEntries(
349
+ outputs.map(([seat, output]) => [
350
+ seat,
351
+ output.findings.filter(
352
+ finding =>
353
+ !earlierIds.has(`${finding.file}:${finding.line}`) &&
354
+ (sinceApproval && finding.approvedCode === true) === approvedCode
355
+ )
356
+ ])
357
+ )
299
358
  )
300
- )
359
+
360
+ const fresh = merged(false)
361
+ const approvedFindings = sinceApproval ? merged(true) : []
301
362
 
302
363
  const findings = [...carried, ...fresh]
303
364
 
304
365
  const blockers = findings.filter(isBlocking)
305
- const scope = input.files === undefined ? outputs.find(([seat]) => seat === scopeSeat)?.[1].scope : undefined
306
- const failing = input.failing ?? []
366
+ const scope = wholeChange(input) ? outputs.find(([seat]) => seat === scopeSeat)?.[1].scope : undefined
307
367
 
308
368
  // A seat's own summary is kept only when nothing blocks, so it cannot contradict the verdict.
309
369
  const summary =
@@ -313,18 +373,22 @@ export default defineLoop({
313
373
  ? 'Not ready: the change does not yet do what was asked.'
314
374
  : failing.length > 0
315
375
  ? `Not ready: ${failing.join(', ')} fails on this head.`
316
- : findings.length === 0
317
- ? 'No findings: nothing stands in the way of merging.'
318
- : ['Can merge: nothing blocks it.', ...outputs.map(([, output]) => output.summary)].join(' ')
376
+ : notRun.length > 0
377
+ ? 'Not ready: verify never ran some of its tests, so they are unverified.'
378
+ : findings.length === 0
379
+ ? sinceApproval
380
+ ? `No findings in what changed since ${input.approved}: nothing stands in the way of merging.`
381
+ : 'No findings: nothing stands in the way of merging.'
382
+ : ['Can merge: nothing blocks it.', ...outputs.map(([, output]) => output.summary)].join(' ')
319
383
 
320
384
  const freshIds = new Set(fresh.map(finding => finding.id))
321
- const text = reviewText(summary, findings, followUps)
385
+ const text = reviewText(summary, findings, followUps, approvedFindings, notRun)
322
386
 
323
387
  const stored = yield* artifact('findings', {
324
388
  kind: 'review-findings',
325
389
  title: 'Review findings',
326
390
  text,
327
- data: { findings, followUps }
391
+ data: { findings, followUps, ...(approvedFindings.length === 0 ? undefined : { approvedFindings }) }
328
392
  })
329
393
 
330
394
  const reviewed = {
@@ -334,6 +398,7 @@ export default defineLoop({
334
398
  verdicts,
335
399
  blocking: findings.some(isBlocking),
336
400
  artifactId: stored.artifactId,
401
+ ...(approvedFindings.length === 0 ? undefined : { approvedFindings }),
337
402
  ...(scope === undefined ? undefined : { scope })
338
403
  }
339
404
 
@@ -342,7 +407,7 @@ export default defineLoop({
342
407
  if (changeRequestId === undefined || head === undefined) return reviewed
343
408
 
344
409
  const approval =
345
- reviewed.blocking || scope?.met === false || failing.length > 0
410
+ reviewed.blocking || scope?.met === false || failing.length > 0 || notRun.length > 0
346
411
  ? undefined
347
412
  : yield* approveChangeRequest('approve', { changeRequestId, head, summary }).pipe(
348
413
  Effect.map(result =>
@@ -360,10 +425,12 @@ export default defineLoop({
360
425
  { value: 'Build from it', description: 'A Build fixes them in a new ChangeRequest.' },
361
426
  { value: 'Done', description: 'Keeps the review as an artifact and stops.' }
362
427
  ] satisfies { readonly value: (typeof choices)[number]; readonly description: string }[],
363
- recommended: reviewed.blocking ? 'Fix here' : 'Done',
428
+ recommended: reviewed.blocking ? 'Fix here' : notRun.length > 0 ? 'Post to the ChangeRequest' : 'Done',
364
429
  recommendationReason: reviewed.blocking
365
430
  ? 'A blocking finding stops the merge, and fixing it here is the shortest way through.'
366
- : 'Nothing blocks the merge, so the findings can wait in the Run.',
431
+ : notRun.length > 0
432
+ ? 'Verify never ran some of its tests, so whoever merges it needs to know to run them first.'
433
+ : 'Nothing blocks the merge, so the findings can wait in the Run.',
367
434
  default: 'Done',
368
435
  timeout: '1 hour'
369
436
  }))
@@ -2,7 +2,8 @@ import * as Schema from 'effect/Schema'
2
2
 
3
3
  /** Shepherd's Output, outside shepherd.ts so Build can import it without the review → build → shepherd cycle. */
4
4
  export const ShepherdOutput = Schema.Struct({
5
- status: Schema.Literals(['merged', 'ready', 'needs_you']),
5
+ /** handed_back: its fix rounds ran out, and the ChangeRequest goes back to Build with what is still open. */
6
+ status: Schema.Literals(['merged', 'ready', 'needs_you', 'handed_back']),
6
7
  /** Why it stopped, in a line a person can act on. */
7
8
  reason: Schema.String,
8
9
  fixRounds: Schema.Int,
@@ -10,5 +11,15 @@ export const ShepherdOutput = Schema.Struct({
10
11
  /** The Release it started after merging, when it was told to release. */
11
12
  release: Schema.optional(
12
13
  Schema.Struct({ runStatus: Schema.String, reason: Schema.String, tag: Schema.optional(Schema.String) })
14
+ ),
15
+ /** The Build its offer starts when it hands the ChangeRequest back: that ChangeRequest, and what is still open. */
16
+ handBack: Schema.optional(
17
+ Schema.Struct({
18
+ changeRequestId: Schema.String,
19
+ words: Schema.String,
20
+ taskId: Schema.optional(Schema.String),
21
+ /** The ChangeRequest's target, which Build merges into. */
22
+ branch: Schema.optional(Schema.String)
23
+ })
13
24
  )
14
25
  })