@kitman-sh/software-engineering 0.14.8 → 0.15.0
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/CHANGELOG.md +118 -0
- package/agents/releaser.md +3 -3
- package/dist/bundle.js +12562 -5360
- package/dist/declarations.json +139340 -4561
- package/kitman.config.ts +163 -2
- package/package.json +4 -3
- package/src/agents.ts +10 -0
- package/src/approved.ts +219 -0
- package/src/backport-schemas.ts +46 -0
- package/src/backport.ts +110 -0
- package/src/build-schemas.ts +135 -0
- package/src/build.ts +202 -739
- package/src/change-request-body.ts +22 -3
- package/src/delivery.ts +26 -6
- package/src/deploy.ts +661 -0
- package/src/errand.ts +124 -76
- package/src/file-tasks.ts +17 -10
- package/src/firewatch.ts +191 -82
- package/src/hillclimb.ts +563 -273
- package/src/hindsight.ts +154 -100
- package/src/implemented.ts +143 -0
- package/src/index.ts +511 -12
- package/src/land-epic.ts +30 -19
- package/src/land.ts +293 -0
- package/src/landed.ts +30 -0
- package/src/opened.ts +79 -0
- package/src/plan-review.ts +7 -8
- package/src/plan.ts +717 -432
- package/src/project-update.ts +50 -11
- package/src/rallied.ts +535 -0
- package/src/release-set.ts +370 -0
- package/src/release.ts +1402 -573
- package/src/reproduced.ts +82 -0
- package/src/research.ts +53 -37
- package/src/revert.ts +331 -0
- package/src/review.ts +466 -250
- package/src/shepherd-output.ts +81 -35
- package/src/shepherd.ts +2109 -1304
- package/src/standing.ts +165 -0
- package/src/suggested-check.ts +8 -0
- package/src/sweep.ts +432 -253
- package/src/tidy.ts +239 -156
package/src/project-update.ts
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
agent,
|
|
3
|
+
defineLoop,
|
|
4
|
+
draftUpdate,
|
|
5
|
+
DraftUpdateRequest,
|
|
6
|
+
projectActivity,
|
|
7
|
+
ProjectActivityResult,
|
|
8
|
+
step
|
|
9
|
+
} from '@kitman-sh/sdk/loop'
|
|
2
10
|
import * as Effect from 'effect/Effect'
|
|
3
11
|
import * as Schema from 'effect/Schema'
|
|
4
12
|
|
|
13
|
+
const writer = agent('writer')
|
|
14
|
+
|
|
5
15
|
const Health = Schema.Literals(['on_track', 'at_risk', 'off_track'])
|
|
6
16
|
|
|
7
|
-
const Input = Schema.Struct({
|
|
17
|
+
const Input = Schema.Struct({
|
|
18
|
+
projectId: Schema.String.annotate({ description: 'The Project to draft an Update for.' })
|
|
19
|
+
})
|
|
8
20
|
|
|
9
21
|
const Output = Schema.Struct({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
22
|
+
draftId: Schema.optional(Schema.String).annotate({
|
|
23
|
+
description: 'Left out when nothing happened since the last Update, so there was nothing to draft.'
|
|
24
|
+
}),
|
|
25
|
+
health: Schema.optional(Health).annotate({
|
|
26
|
+
description: 'The health the draft gives the Project: on track, at risk or off track.'
|
|
27
|
+
})
|
|
13
28
|
})
|
|
14
29
|
|
|
15
30
|
const Written = Schema.Struct({
|
|
@@ -50,6 +65,30 @@ const noteOf = (read: ProjectActivityResult, written: typeof Written.Type) => {
|
|
|
50
65
|
return `${written.healthReason === undefined ? `${moved}.` : `${moved}: ${written.healthReason}`}\n\n${written.note}`
|
|
51
66
|
}
|
|
52
67
|
|
|
68
|
+
const Update = Schema.Struct({
|
|
69
|
+
health: Health,
|
|
70
|
+
/** The note as it is drafted, opening with why the health moved when it did. */
|
|
71
|
+
note: Schema.String
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
/** The writer's Update from what the Project's Runs and Task changes show. The Loop that uses it names a `writer`. */
|
|
75
|
+
export const written = step('written', {
|
|
76
|
+
payload: { read: ProjectActivityResult },
|
|
77
|
+
success: Update,
|
|
78
|
+
run: ({ read }) =>
|
|
79
|
+
Effect.map(writer('write', { prompt: prompt(read), output: Written }), written => ({
|
|
80
|
+
health: written.health,
|
|
81
|
+
note: noteOf(read, written)
|
|
82
|
+
}))
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
/** Drafts the Update into the Inbox of the person who asked, replacing their unposted draft. */
|
|
86
|
+
export const posted = step('posted', {
|
|
87
|
+
payload: DraftUpdateRequest,
|
|
88
|
+
success: Schema.Struct({ draftId: Schema.String }),
|
|
89
|
+
run: request => Effect.map(draftUpdate('draft', request), draft => ({ draftId: draft.id }))
|
|
90
|
+
})
|
|
91
|
+
|
|
53
92
|
/**
|
|
54
93
|
* Reads a Project's Runs and Task changes since its latest Update, as the person who asked, and drafts the next Update
|
|
55
94
|
* into that person's Inbox, replacing their unposted draft. It never posts one: only a person can. With nothing new it
|
|
@@ -57,8 +96,9 @@ const noteOf = (read: ProjectActivityResult, written: typeof Written.Type) => {
|
|
|
57
96
|
*/
|
|
58
97
|
export default defineLoop({
|
|
59
98
|
id: 'project-update',
|
|
60
|
-
version: '
|
|
99
|
+
version: '3.0.0',
|
|
61
100
|
title: 'Project update',
|
|
101
|
+
description: "Drafts a Project's next Update from its recent Runs and Task changes, for a person to post.",
|
|
62
102
|
input: Input,
|
|
63
103
|
output: Output,
|
|
64
104
|
agents: { writer: 'writer' },
|
|
@@ -70,12 +110,11 @@ export default defineLoop({
|
|
|
70
110
|
|
|
71
111
|
if (read.runs.length === 0 && read.taskChanges.length === 0) return {}
|
|
72
112
|
|
|
73
|
-
const
|
|
113
|
+
const update = yield* written({ read })
|
|
74
114
|
|
|
75
|
-
const
|
|
115
|
+
const { draftId } = yield* posted({
|
|
76
116
|
projectId,
|
|
77
|
-
|
|
78
|
-
note: noteOf(read, written),
|
|
117
|
+
...update,
|
|
79
118
|
writtenFrom: {
|
|
80
119
|
runs: read.runs.length,
|
|
81
120
|
taskChanges: read.taskChanges.length,
|
|
@@ -83,6 +122,6 @@ export default defineLoop({
|
|
|
83
122
|
}
|
|
84
123
|
})
|
|
85
124
|
|
|
86
|
-
return { draftId
|
|
125
|
+
return { draftId, health: update.health }
|
|
87
126
|
})
|
|
88
127
|
})
|
package/src/rallied.ts
ADDED
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import {
|
|
2
|
+
agent,
|
|
3
|
+
call,
|
|
4
|
+
type Disputed,
|
|
5
|
+
isBlocking,
|
|
6
|
+
LoopOutcome,
|
|
7
|
+
type LoopServices,
|
|
8
|
+
Measurement,
|
|
9
|
+
MergedFinding,
|
|
10
|
+
rallyStop,
|
|
11
|
+
Rebuttal,
|
|
12
|
+
RebuttalVerdict,
|
|
13
|
+
settleRound,
|
|
14
|
+
type SettledRound,
|
|
15
|
+
step,
|
|
16
|
+
type StepError,
|
|
17
|
+
stepName,
|
|
18
|
+
syncBase,
|
|
19
|
+
testsNotRunReasons,
|
|
20
|
+
verify,
|
|
21
|
+
VerifyResult
|
|
22
|
+
} from '@kitman-sh/sdk/loop'
|
|
23
|
+
import * as Effect from 'effect/Effect'
|
|
24
|
+
import * as Schema from 'effect/Schema'
|
|
25
|
+
import * as SchemaTransformation from 'effect/SchemaTransformation'
|
|
26
|
+
import {
|
|
27
|
+
brokenChecks,
|
|
28
|
+
checkFindings,
|
|
29
|
+
codeFindings,
|
|
30
|
+
isCheckFinding,
|
|
31
|
+
scopeFindings,
|
|
32
|
+
unsettledIds,
|
|
33
|
+
withoutOutput
|
|
34
|
+
} from './change-request-body'
|
|
35
|
+
import { blockingCount } from './convergence'
|
|
36
|
+
import { OutOfScopeFinding } from './out-of-scope'
|
|
37
|
+
import review from './review'
|
|
38
|
+
import { ReviewedScope } from './reviewed-scope'
|
|
39
|
+
import { SuggestedCheck } from './suggested-check'
|
|
40
|
+
import { ChangeRequestSummary, OneSentence, Reason, ShortStatement } from './text-limits'
|
|
41
|
+
|
|
42
|
+
const FixRebuttal = Schema.Struct({ ...Rebuttal.fields, reason: Reason })
|
|
43
|
+
|
|
44
|
+
const FixOrRebuttal = Schema.Struct({
|
|
45
|
+
summary: ChangeRequestSummary,
|
|
46
|
+
claims: Schema.Array(ShortStatement),
|
|
47
|
+
rebuttals: Schema.Array(FixRebuttal)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const FixOnly = Schema.Struct({ summary: OneSentence })
|
|
51
|
+
|
|
52
|
+
const findingLine = (finding: MergedFinding) => `- **${finding.severity}** \`${finding.id}\` ${finding.detail}`
|
|
53
|
+
|
|
54
|
+
const disputeLine = ({ finding, rebuttal }: Disputed) => `${findingLine(finding)}\n You rebutted: ${rebuttal.reason}`
|
|
55
|
+
|
|
56
|
+
const fixPrompt = (settled: SettledRound, guidance: string | undefined) => {
|
|
57
|
+
const checks = settled.open.filter(finding => isCheckFinding(finding.id))
|
|
58
|
+
|
|
59
|
+
const findings = settled.open.filter(finding => !isCheckFinding(finding.id))
|
|
60
|
+
|
|
61
|
+
return [
|
|
62
|
+
...(guidance === undefined ? [] : [`${guidance}\n`]),
|
|
63
|
+
...(checks.length === 0
|
|
64
|
+
? []
|
|
65
|
+
: [
|
|
66
|
+
'These checks fail on your head and pass on the base. Only the check passing closes one. If you are sure the change did not cause it, such as a flaky test, rebut it with your reason: the ChangeRequest reports that as your claim and the check stays open. If you change nothing, a check runs again only when it reads the target branch; when only these are open and they fail as you were shown, the rally ends.',
|
|
67
|
+
...checks.map(findingLine),
|
|
68
|
+
'Read the full output of a failed check with the Kitman tool check_output, by its name.'
|
|
69
|
+
]),
|
|
70
|
+
...(findings.length === 0
|
|
71
|
+
? []
|
|
72
|
+
: [
|
|
73
|
+
'The review found these. Fix each, or rebut it with your reason if it is wrong; reviewers judge the rebuttals next round.',
|
|
74
|
+
...findings.map(findingLine)
|
|
75
|
+
]),
|
|
76
|
+
...(settled.standing.length === 0
|
|
77
|
+
? []
|
|
78
|
+
: [
|
|
79
|
+
'The reviewers rejected your rebuttal of these. Fix each, or rebut it again with a better reason; one you leave stays a dispute for a person to settle.',
|
|
80
|
+
...settled.standing.map(disputeLine)
|
|
81
|
+
])
|
|
82
|
+
].join('\n')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const blockingPrompt = (settled: SettledRound, intro = 'The review found these. Fix each.') =>
|
|
86
|
+
[intro, ...settled.open.filter(isBlocking).map(finding => `- ${finding.id}: ${finding.detail}`)].join('\n\n')
|
|
87
|
+
|
|
88
|
+
const onlyChecksBlock = (settled: SettledRound) => unsettledIds(settled).every(isCheckFinding)
|
|
89
|
+
|
|
90
|
+
const Dispute = Schema.Struct({ finding: MergedFinding, rebuttal: Rebuttal })
|
|
91
|
+
|
|
92
|
+
const rally = {
|
|
93
|
+
/** Less what its checks printed, which its verify Step's entry holds: a journal entry is at most 256 KiB. */
|
|
94
|
+
head: VerifyResult,
|
|
95
|
+
/** The last round that reviewed. */
|
|
96
|
+
round: Schema.Int,
|
|
97
|
+
/** That round's findings: open, withdrawn by the reviewers, and disputes that stand. */
|
|
98
|
+
settled: Schema.Struct({
|
|
99
|
+
open: Schema.Array(MergedFinding),
|
|
100
|
+
withdrawn: Schema.Array(Dispute),
|
|
101
|
+
standing: Schema.Array(Dispute)
|
|
102
|
+
}),
|
|
103
|
+
/** The last Review's judgement of the scope, when it made one. */
|
|
104
|
+
scope: Schema.optionalKey(ReviewedScope),
|
|
105
|
+
/** The Reviews' findings kept apart as out of scope, as the last one left them. */
|
|
106
|
+
outOfScope: Schema.Array(OutOfScopeFinding),
|
|
107
|
+
/** Each Review round's blocking count, first to last, which decides whether a Rebuild may follow. */
|
|
108
|
+
blockingCounts: Schema.Array(Schema.Int),
|
|
109
|
+
/** The Step of the last Review, which an approval of `head` names as its `review`. */
|
|
110
|
+
review: Schema.String,
|
|
111
|
+
/** The claims given and those of each fix. */
|
|
112
|
+
claims: Schema.Array(Schema.String),
|
|
113
|
+
/** The rounds that could not merge the target in, since the last one that could. */
|
|
114
|
+
conflicts: Schema.Array(Schema.String)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Nothing blocks. */
|
|
118
|
+
export class Settled extends Schema.TaggedClass<Settled>()('Settled', rally) {}
|
|
119
|
+
|
|
120
|
+
/** The reviewers rejected a rebuttal of a blocking finding. */
|
|
121
|
+
export class DisputeStands extends Schema.TaggedClass<DisputeStands>()('DisputeStands', rally) {}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A round found the same blocking findings as the one before it, or a fix left the tree as it was, with only checks open
|
|
125
|
+
* and nothing rebutted.
|
|
126
|
+
*/
|
|
127
|
+
export class FindingsReturned extends Schema.TaggedClass<FindingsReturned>()('FindingsReturned', rally) {}
|
|
128
|
+
|
|
129
|
+
/** The last round left findings that block. */
|
|
130
|
+
export class RoundCap extends Schema.TaggedClass<RoundCap>()('RoundCap', rally) {}
|
|
131
|
+
|
|
132
|
+
/** No base was given and no base sync said which target commit it merged, so a review would have nothing fixed to diff against. */
|
|
133
|
+
export class BaseUnpinned extends Schema.TaggedError<BaseUnpinned>()('BaseUnpinned', {
|
|
134
|
+
message: Schema.String
|
|
135
|
+
}) {}
|
|
136
|
+
|
|
137
|
+
/** An `afterFix` ends the rally with this, before another review; `reason` is the caller's own. */
|
|
138
|
+
export class Halted extends Schema.TaggedError<Halted>()('Halted', {
|
|
139
|
+
reason: Schema.String,
|
|
140
|
+
message: Schema.String,
|
|
141
|
+
/** What it measured, when that is why. */
|
|
142
|
+
measurement: Schema.optionalKey(Measurement)
|
|
143
|
+
}) {}
|
|
144
|
+
|
|
145
|
+
type AfterFix = Effect.Effect<VerifyResult | void, Halted | StepError, LoopServices>
|
|
146
|
+
|
|
147
|
+
/** An Effect has no JSON, so the journal and the manifest hold null for it. */
|
|
148
|
+
const AfterFix = Schema.declare((value): value is AfterFix => Effect.isEffect(value), {
|
|
149
|
+
toCodecJson: () =>
|
|
150
|
+
Schema.link<AfterFix>()(
|
|
151
|
+
Schema.Null,
|
|
152
|
+
SchemaTransformation.transform({ decode: (): AfterFix => Effect.void, encode: () => null })
|
|
153
|
+
)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
const given = {
|
|
157
|
+
base: Schema.optional(Schema.String).annotate({
|
|
158
|
+
description: "What each Review diffs against; the target's commit the round merged in when left out."
|
|
159
|
+
}),
|
|
160
|
+
target: Schema.optional(Schema.String).annotate({
|
|
161
|
+
description: 'The branch to merge in before each review; the default branch when left out.'
|
|
162
|
+
}),
|
|
163
|
+
outcome: Schema.optional(LoopOutcome).annotate({ description: 'The Outcome the change must prove.' }),
|
|
164
|
+
claims: Schema.Array(Schema.String).annotate({
|
|
165
|
+
description: 'What the change is claimed to do so far, for Review to check.'
|
|
166
|
+
}),
|
|
167
|
+
suggested: Schema.Array(SuggestedCheck).annotate({
|
|
168
|
+
description: 'Checks to run when the repository has none approved.'
|
|
169
|
+
}),
|
|
170
|
+
extra: Schema.optional(Schema.Array(SuggestedCheck)).annotate({
|
|
171
|
+
description: "Checks to run on every head besides the approved ones, such as a bug's reproducing check."
|
|
172
|
+
}),
|
|
173
|
+
fixer: Schema.String.annotate({
|
|
174
|
+
description: "The Loop's name for the agent that fixes or rebuts, and settles a conflict merging the target in."
|
|
175
|
+
}),
|
|
176
|
+
reviewed: Schema.optional(Schema.String).annotate({
|
|
177
|
+
description: 'The head an earlier review read, whose fix the first round reviews.'
|
|
178
|
+
}),
|
|
179
|
+
earlier: Schema.optional(Schema.Array(MergedFinding)).annotate({
|
|
180
|
+
description: "That earlier review's open findings, which the first round checks."
|
|
181
|
+
}),
|
|
182
|
+
verified: Schema.optional(VerifyResult).annotate({
|
|
183
|
+
description:
|
|
184
|
+
'A head the caller verified, which the first round reviews as it is: it merges no target in and verifies nothing, so `base` is required.'
|
|
185
|
+
}),
|
|
186
|
+
deliveredBy: Schema.optional(Schema.String).annotate({
|
|
187
|
+
description: "The ChangeRequest the change delivers, for Review to read its Task's Out of scope list."
|
|
188
|
+
}),
|
|
189
|
+
outOfScopeFindings: Schema.optional(Schema.Array(OutOfScopeFinding)).annotate({
|
|
190
|
+
description: "Earlier reviews' findings kept apart as out of scope."
|
|
191
|
+
}),
|
|
192
|
+
unmetCriteria: Schema.optional(Schema.Array(Schema.String)).annotate({
|
|
193
|
+
description: 'The acceptance criteria the implementer answered not met, for the scope seat to judge.'
|
|
194
|
+
}),
|
|
195
|
+
metCriteria: Schema.optional(Schema.Array(Schema.String)).annotate({
|
|
196
|
+
description: 'The acceptance criteria the implementer answered met.'
|
|
197
|
+
}),
|
|
198
|
+
afterMergeCriteria: Schema.optional(Schema.Array(Schema.String)).annotate({
|
|
199
|
+
description: 'The acceptance criteria the implementer answered can only be seen once merged.'
|
|
200
|
+
}),
|
|
201
|
+
scope: Schema.optional(ReviewedScope).annotate({
|
|
202
|
+
description: "That earlier review's scope judgement, which the first round judges again."
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const Conflict = Schema.Struct({ files: Schema.Array(Schema.String), reason: Schema.String })
|
|
207
|
+
|
|
208
|
+
const headRead = {
|
|
209
|
+
head: VerifyResult,
|
|
210
|
+
/** Why the round could not merge the target in. */
|
|
211
|
+
conflict: Schema.optionalKey(Conflict)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export class Reviewed extends Schema.TaggedClass<Reviewed>()('Reviewed', {
|
|
215
|
+
...headRead,
|
|
216
|
+
findings: Schema.Array(MergedFinding),
|
|
217
|
+
verdicts: Schema.Array(RebuttalVerdict),
|
|
218
|
+
scope: Schema.optionalKey(ReviewedScope),
|
|
219
|
+
outOfScopeFindings: Schema.optionalKey(Schema.Array(OutOfScopeFinding)),
|
|
220
|
+
/** The Review's Step. */
|
|
221
|
+
review: Schema.String
|
|
222
|
+
}) {}
|
|
223
|
+
|
|
224
|
+
/** The head's tree and evidence are those of the head `known`, so a review would judge the same change. */
|
|
225
|
+
export class SameEvidence extends Schema.TaggedClass<SameEvidence>()('SameEvidence', headRead) {}
|
|
226
|
+
|
|
227
|
+
/** Two checks can print the same, so a failure is its check's and what it printed. */
|
|
228
|
+
const ShownFailure = Schema.Struct({ id: Schema.String, detail: Schema.String })
|
|
229
|
+
|
|
230
|
+
type ShownFailure = typeof ShownFailure.Type
|
|
231
|
+
|
|
232
|
+
const Known = Schema.Struct({
|
|
233
|
+
head: VerifyResult,
|
|
234
|
+
/** What the fixer was told of each check that failed. */
|
|
235
|
+
shown: Schema.Array(ShownFailure)
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
const unshownFailure = (head: VerifyResult, shown: readonly ShownFailure[]) =>
|
|
239
|
+
checkFindings(head).some(({ id, detail }) => !shown.some(failure => failure.id === id && failure.detail === detail))
|
|
240
|
+
|
|
241
|
+
const isSameEvidence = ({ head: before, shown }: typeof Known.Type, now: VerifyResult) => {
|
|
242
|
+
const read = (head: VerifyResult) =>
|
|
243
|
+
JSON.stringify([head.tree, brokenChecks(head).map(check => check.name), testsNotRunReasons(head)])
|
|
244
|
+
|
|
245
|
+
return read(before) === read(now) && !unshownFailure(now, shown)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** One round of a rally before its fix: merges the target in, verifies the head and has it reviewed. */
|
|
249
|
+
export const reviewed = step('reviewed', {
|
|
250
|
+
payload: {
|
|
251
|
+
...given,
|
|
252
|
+
round: Schema.Int,
|
|
253
|
+
rebuttals: Schema.Array(Rebuttal).annotate({ description: 'For the reviewers to judge.' }),
|
|
254
|
+
known: Schema.optional(Known).annotate({
|
|
255
|
+
description:
|
|
256
|
+
'A head already reviewed, and what the fixer was told of its failing checks; a head with its tree and evidence, and no failure the fixer was not told of, is not reviewed again.'
|
|
257
|
+
})
|
|
258
|
+
},
|
|
259
|
+
success: Schema.Union([Reviewed, SameEvidence]),
|
|
260
|
+
error: BaseUnpinned,
|
|
261
|
+
run: payload =>
|
|
262
|
+
Effect.gen(function* () {
|
|
263
|
+
const {
|
|
264
|
+
base,
|
|
265
|
+
target,
|
|
266
|
+
outcome,
|
|
267
|
+
claims,
|
|
268
|
+
suggested,
|
|
269
|
+
extra,
|
|
270
|
+
fixer,
|
|
271
|
+
earlier = [],
|
|
272
|
+
verified,
|
|
273
|
+
rebuttals,
|
|
274
|
+
deliveredBy,
|
|
275
|
+
outOfScopeFindings = [],
|
|
276
|
+
unmetCriteria = [],
|
|
277
|
+
metCriteria = [],
|
|
278
|
+
afterMergeCriteria = [],
|
|
279
|
+
scope: judged
|
|
280
|
+
} = payload
|
|
281
|
+
|
|
282
|
+
// Reviewers see what will merge; a conflict the fixer cannot settle is left unsettled, not hidden.
|
|
283
|
+
const synced =
|
|
284
|
+
verified === undefined
|
|
285
|
+
? yield* syncBase('sync', { agent: fixer, ...(target === undefined ? undefined : { target }) })
|
|
286
|
+
: undefined
|
|
287
|
+
|
|
288
|
+
// The synced commit is pinned, so a target that moves during the round does not move what is reviewed.
|
|
289
|
+
const reviewBase = base ?? synced?.base
|
|
290
|
+
|
|
291
|
+
if (reviewBase === undefined)
|
|
292
|
+
return yield* new BaseUnpinned({
|
|
293
|
+
message:
|
|
294
|
+
verified === undefined
|
|
295
|
+
? `The Runner did not report which commit of ${target ?? 'the default branch'} it merged in round ${payload.round}, so there is no base to review against; update the Runner`
|
|
296
|
+
: 'A head the caller verified is reviewed with no target merged in, so it needs a base to review against'
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
const head =
|
|
300
|
+
verified ?? (yield* verify('verify', { suggested, ...(extra === undefined ? undefined : { extra }) }))
|
|
301
|
+
|
|
302
|
+
const found = {
|
|
303
|
+
head,
|
|
304
|
+
...(synced?.status === 'conflict' ? { conflict: { files: synced.files, reason: synced.reason } } : undefined)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (payload.known !== undefined && isSameEvidence(payload.known, head)) return new SameEvidence(found)
|
|
308
|
+
|
|
309
|
+
const failing = brokenChecks(head).map(check => check.name)
|
|
310
|
+
const notRun = testsNotRunReasons(head)
|
|
311
|
+
|
|
312
|
+
const { findings, verdicts, scope, ...apart } = yield* call('review', review, {
|
|
313
|
+
base: reviewBase,
|
|
314
|
+
head: head.revision,
|
|
315
|
+
...(deliveredBy === undefined ? undefined : { deliveredBy }),
|
|
316
|
+
...(rebuttals.length === 0 ? undefined : { rebuttals }),
|
|
317
|
+
...(earlier.length === 0 ? undefined : { earlier }),
|
|
318
|
+
...(payload.reviewed === undefined ? undefined : { reviewed: payload.reviewed }),
|
|
319
|
+
...(outOfScopeFindings.length === 0 ? undefined : { outOfScopeFindings }),
|
|
320
|
+
...(unmetCriteria.length === 0 ? undefined : { unmetCriteria }),
|
|
321
|
+
...(metCriteria.length === 0 ? undefined : { metCriteria }),
|
|
322
|
+
...(afterMergeCriteria.length === 0 ? undefined : { afterMergeCriteria }),
|
|
323
|
+
...(judged === undefined ? undefined : { scope: judged }),
|
|
324
|
+
...(outcome === undefined ? undefined : { outcome }),
|
|
325
|
+
...(failing.length === 0 ? undefined : { failing }),
|
|
326
|
+
...(notRun.length === 0 ? undefined : { notRun }),
|
|
327
|
+
claims
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
return new Reviewed({
|
|
331
|
+
...found,
|
|
332
|
+
findings,
|
|
333
|
+
verdicts,
|
|
334
|
+
...(scope === undefined ? undefined : { scope }),
|
|
335
|
+
...(apart.outOfScopeFindings === undefined ? undefined : { outOfScopeFindings: apart.outOfScopeFindings }),
|
|
336
|
+
review: yield* stepName('review')
|
|
337
|
+
})
|
|
338
|
+
})
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
export class Fixed extends Schema.TaggedClass<Fixed>()('Fixed', {
|
|
342
|
+
claims: Schema.Array(Schema.String),
|
|
343
|
+
rebuttals: Schema.Array(Rebuttal)
|
|
344
|
+
}) {}
|
|
345
|
+
|
|
346
|
+
export const fixed = step('fixed', {
|
|
347
|
+
payload: {
|
|
348
|
+
fixer: given.fixer,
|
|
349
|
+
prompt: Schema.String,
|
|
350
|
+
rebuts: Schema.Boolean.annotate({ description: 'Whether the fixer may rebut a finding instead of fixing it.' })
|
|
351
|
+
},
|
|
352
|
+
success: Fixed,
|
|
353
|
+
run: ({ fixer, prompt, rebuts }) =>
|
|
354
|
+
Effect.gen(function* () {
|
|
355
|
+
const fix = agent(fixer)
|
|
356
|
+
|
|
357
|
+
const { claims, rebuttals } = rebuts
|
|
358
|
+
? yield* fix('fix', { prompt, output: FixOrRebuttal })
|
|
359
|
+
: yield* Effect.as(fix('fix', { prompt, output: FixOnly }), { claims: [], rebuttals: [] })
|
|
360
|
+
|
|
361
|
+
return new Fixed({ claims, rebuttals })
|
|
362
|
+
})
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
class FixChecked extends Schema.TaggedClass<FixChecked>()('FixChecked', {
|
|
366
|
+
/** The fixed head, when the caller verified it. */
|
|
367
|
+
head: Schema.optionalKey(VerifyResult)
|
|
368
|
+
}) {}
|
|
369
|
+
|
|
370
|
+
/** Not exported, so no Layer that replaces `fixed` or this skips it. */
|
|
371
|
+
const afterFixed = step('afterFix', {
|
|
372
|
+
payload: { afterFix: AfterFix },
|
|
373
|
+
success: FixChecked,
|
|
374
|
+
error: Halted,
|
|
375
|
+
run: ({ afterFix }) => Effect.map(afterFix, head => new FixChecked(head === undefined ? {} : { head }))
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Merges the target in, verifies the head and has it reviewed, then has the fixer fix or rebut the findings, until the
|
|
380
|
+
* rally stops. The last Step that changes code comes before the last review, so the reviewed revision is the one that
|
|
381
|
+
* ships. The calling Loop lists Review in `calls`.
|
|
382
|
+
*/
|
|
383
|
+
export const rallied = step('rallied', {
|
|
384
|
+
payload: {
|
|
385
|
+
...given,
|
|
386
|
+
maxRounds: Schema.Int.annotate({ description: 'Review rounds before the rally stops.' }),
|
|
387
|
+
guidance: Schema.optional(Schema.String).annotate({
|
|
388
|
+
description: 'What the fixer is told before the findings, such as what each fix has to keep.'
|
|
389
|
+
}),
|
|
390
|
+
fixes: Schema.optional(Schema.Literals(['open', 'blocking'])).annotate({
|
|
391
|
+
description:
|
|
392
|
+
'What each round fixes; `open` when left out. `open`: every open finding and what Review finds not done of the Task, each fixed or rebutted, until the rally stops. `blocking`: what blocks alone, none of it rebutted, until nothing blocks or the last round; what Review finds not done is only reported, in `scope`.'
|
|
393
|
+
}),
|
|
394
|
+
afterFix: Schema.optional(AfterFix).annotate({
|
|
395
|
+
description:
|
|
396
|
+
'An Effect to run after each fix, before the round that reviews it. A head it gives, having verified it, is reviewed as `verified` is. Failing with `Halted` ends the rally. The journal holds null for it.'
|
|
397
|
+
})
|
|
398
|
+
},
|
|
399
|
+
success: Schema.Union([Settled, DisputeStands, FindingsReturned, RoundCap]),
|
|
400
|
+
error: Schema.Union([BaseUnpinned, Halted]),
|
|
401
|
+
run: ({ maxRounds, guidance, fixes = 'open', afterFix, ...payload }) =>
|
|
402
|
+
Effect.gen(function* () {
|
|
403
|
+
const fixesOpen = fixes === 'open'
|
|
404
|
+
const claims = [...payload.claims]
|
|
405
|
+
const conflicts: string[] = []
|
|
406
|
+
const blockingCounts: number[] = []
|
|
407
|
+
let outOfScope = payload.outOfScopeFindings ?? []
|
|
408
|
+
let rebuttals: readonly Rebuttal[] = []
|
|
409
|
+
let earlier = payload.earlier ?? []
|
|
410
|
+
let { verified } = payload
|
|
411
|
+
let previous: readonly string[] | undefined
|
|
412
|
+
let last: Pick<Settled, 'head' | 'settled' | 'scope' | 'review'> | undefined
|
|
413
|
+
const shown: ShownFailure[] = []
|
|
414
|
+
|
|
415
|
+
for (let round = 1; ; round++) {
|
|
416
|
+
const found = yield* reviewed({
|
|
417
|
+
...payload,
|
|
418
|
+
round,
|
|
419
|
+
claims: [...claims],
|
|
420
|
+
rebuttals,
|
|
421
|
+
earlier,
|
|
422
|
+
verified,
|
|
423
|
+
reviewed: last?.head.revision ?? payload.reviewed,
|
|
424
|
+
outOfScopeFindings: outOfScope.length === 0 ? undefined : outOfScope,
|
|
425
|
+
scope: last === undefined ? payload.scope : last.scope,
|
|
426
|
+
known:
|
|
427
|
+
fixesOpen && last !== undefined && rebuttals.length === 0 && onlyChecksBlock(last.settled)
|
|
428
|
+
? { head: last.head, shown: [...shown] }
|
|
429
|
+
: undefined
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
const { head, conflict } = found
|
|
433
|
+
|
|
434
|
+
// A round that merges or finds the branch up to date settles every round before it that could not merge.
|
|
435
|
+
if (conflict !== undefined)
|
|
436
|
+
conflicts.push(
|
|
437
|
+
`Could not merge the target branch in round ${round}: ${conflict.files.join(', ')} (${conflict.reason})`
|
|
438
|
+
)
|
|
439
|
+
else if (verified === undefined) conflicts.length = 0
|
|
440
|
+
|
|
441
|
+
if (found._tag === 'SameEvidence') {
|
|
442
|
+
if (last === undefined) return yield* Effect.die(new Error('Evidence is the same as no round before it'))
|
|
443
|
+
|
|
444
|
+
return new FindingsReturned({
|
|
445
|
+
...last,
|
|
446
|
+
round: round - 1,
|
|
447
|
+
head: withoutOutput(head),
|
|
448
|
+
claims,
|
|
449
|
+
conflicts,
|
|
450
|
+
outOfScope,
|
|
451
|
+
blockingCounts
|
|
452
|
+
})
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
outOfScope = found.outOfScopeFindings ?? []
|
|
456
|
+
const checks = checkFindings(head)
|
|
457
|
+
|
|
458
|
+
const settledWith = (checked: readonly MergedFinding[]) =>
|
|
459
|
+
settleRound({
|
|
460
|
+
findings: [...found.findings, ...(fixesOpen ? scopeFindings(found.scope) : []), ...checked],
|
|
461
|
+
rebuttals,
|
|
462
|
+
verdicts: found.verdicts
|
|
463
|
+
})
|
|
464
|
+
|
|
465
|
+
const settled = settledWith(checks)
|
|
466
|
+
|
|
467
|
+
blockingCounts.push(blockingCount(settled))
|
|
468
|
+
|
|
469
|
+
// A dispute that stands stays in front of the reviewers when a broken check carries the rally on past it.
|
|
470
|
+
earlier = codeFindings(settled)
|
|
471
|
+
|
|
472
|
+
// A failure the fixer has not been shown has not returned, and a dispute does not keep it from them.
|
|
473
|
+
const unseen = unshownFailure(head, shown)
|
|
474
|
+
|
|
475
|
+
const decision = rallyStop({
|
|
476
|
+
round,
|
|
477
|
+
maxRounds,
|
|
478
|
+
settled,
|
|
479
|
+
...(previous === undefined || unseen || !fixesOpen ? undefined : { previous })
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
const quiet = withoutOutput(head)
|
|
483
|
+
|
|
484
|
+
last = {
|
|
485
|
+
head: quiet,
|
|
486
|
+
settled: settledWith(checkFindings(quiet)),
|
|
487
|
+
...(found.scope === undefined ? undefined : { scope: found.scope }),
|
|
488
|
+
review: found.review
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (decision.stop && (!unseen || round >= maxRounds)) {
|
|
492
|
+
const ended = { ...last, round, claims, conflicts, outOfScope, blockingCounts }
|
|
493
|
+
|
|
494
|
+
switch (decision.reason) {
|
|
495
|
+
case 'settled':
|
|
496
|
+
return new Settled(ended)
|
|
497
|
+
case 'dispute_stands':
|
|
498
|
+
return new DisputeStands(ended)
|
|
499
|
+
case 'findings_returned':
|
|
500
|
+
return new FindingsReturned(ended)
|
|
501
|
+
case 'round_cap':
|
|
502
|
+
return new RoundCap(ended)
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
for (const { id, detail } of checks) shown.push({ id, detail })
|
|
507
|
+
|
|
508
|
+
const fix = yield* fixed({
|
|
509
|
+
fixer: payload.fixer,
|
|
510
|
+
prompt: fixesOpen ? fixPrompt(settled, guidance) : blockingPrompt(settled, guidance),
|
|
511
|
+
rebuts: fixesOpen
|
|
512
|
+
})
|
|
513
|
+
|
|
514
|
+
verified = afterFix === undefined ? undefined : (yield* afterFixed({ afterFix })).head
|
|
515
|
+
claims.push(
|
|
516
|
+
...fix.claims,
|
|
517
|
+
...fix.rebuttals.flatMap(rebuttal =>
|
|
518
|
+
isCheckFinding(rebuttal.findingId) ? [`Rebutted ${rebuttal.findingId}: ${rebuttal.reason}`] : []
|
|
519
|
+
)
|
|
520
|
+
)
|
|
521
|
+
// Evidence is not the reviewers' to withdraw.
|
|
522
|
+
const rebutted = fix.rebuttals.filter(rebuttal => !isCheckFinding(rebuttal.findingId))
|
|
523
|
+
|
|
524
|
+
// A blocking dispute the fixer does not repeat is still one, unless the fix ends the finding.
|
|
525
|
+
rebuttals = [
|
|
526
|
+
...rebutted,
|
|
527
|
+
...settled.standing
|
|
528
|
+
.filter(entry => isBlocking(entry.finding))
|
|
529
|
+
.map(entry => entry.rebuttal)
|
|
530
|
+
.filter(rebuttal => !rebutted.some(entry => entry.findingId === rebuttal.findingId))
|
|
531
|
+
]
|
|
532
|
+
previous = settled.open.filter(isBlocking).map(finding => finding.id)
|
|
533
|
+
}
|
|
534
|
+
})
|
|
535
|
+
})
|