@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
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Continuing, LoopOutcome, step, verify, VerifyResult } from '@kitman-sh/sdk/loop'
|
|
2
|
+
import * as Effect from 'effect/Effect'
|
|
3
|
+
import * as Schema from 'effect/Schema'
|
|
4
|
+
import { implementer } from './agents'
|
|
5
|
+
import { taskOf } from './build-schemas'
|
|
6
|
+
import { withoutOutput } from './change-request-body'
|
|
7
|
+
import { SuggestedCheck } from './suggested-check'
|
|
8
|
+
import { ChangeRequestSummary } from './text-limits'
|
|
9
|
+
|
|
10
|
+
const ReproducingTest = Schema.Struct({
|
|
11
|
+
/** The check that runs only the test reproducing the bug; verify runs it on the base and on each head. */
|
|
12
|
+
check: SuggestedCheck,
|
|
13
|
+
summary: ChangeRequestSummary,
|
|
14
|
+
/** The branch's commit where the reproducing test is in place and the fix is not yet; the head when none is. */
|
|
15
|
+
revision: Schema.optional(Schema.String)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const reproducingCheckGuidance =
|
|
19
|
+
'Give in `check` the command that runs only that test, with a `name` of letters, digits, `.`, `_`, `:` and `-` that no approved verification of the repository has, unless it is exactly that approved check. Kitman runs it before the fix, where it must fail, and on every head after, where it must pass.'
|
|
20
|
+
|
|
21
|
+
const reproducePrompt = (task: string) =>
|
|
22
|
+
[
|
|
23
|
+
`Reproduce the bug in ${task} before anyone fixes it.`,
|
|
24
|
+
'Add a test that fails because of the bug, and change nothing else.',
|
|
25
|
+
reproducingCheckGuidance
|
|
26
|
+
].join('\n\n')
|
|
27
|
+
|
|
28
|
+
const reproducedOnBranchPrompt = (task: string) =>
|
|
29
|
+
[
|
|
30
|
+
`An earlier Run already worked on fixing the bug in ${task}, on this branch.`,
|
|
31
|
+
'Find the commit on this branch where the test reproducing the bug was in place and the fix was not yet, and give it as `revision`. Change nothing.',
|
|
32
|
+
'If no commit on the branch has the reproducing test without the fix, add a test that fails on the branch head now, change nothing else, and give no `revision`.',
|
|
33
|
+
reproducingCheckGuidance
|
|
34
|
+
].join('\n\n')
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The bug has a check written to reproduce it, and `base` is what verify found without the fix, less what its checks
|
|
38
|
+
* printed. Whether the check failed there is the evidence gate's to say.
|
|
39
|
+
*/
|
|
40
|
+
export class Reproduced extends Schema.TaggedClass<Reproduced>()('Reproduced', {
|
|
41
|
+
check: SuggestedCheck,
|
|
42
|
+
base: VerifyResult
|
|
43
|
+
}) {}
|
|
44
|
+
|
|
45
|
+
/** What verify found before the change, less what its checks printed. */
|
|
46
|
+
export class BaseVerified extends Schema.TaggedClass<BaseVerified>()('BaseVerified', { base: VerifyResult }) {}
|
|
47
|
+
|
|
48
|
+
/** The Outcome needs no proof from before the change. */
|
|
49
|
+
export class NotNeeded extends Schema.TaggedClass<NotNeeded>()('NotNeeded', {}) {}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Collects the proof an Outcome needs from before the change: a bug's reproducing check, which the Loop's `implementer`
|
|
53
|
+
* writes, or a refactor's base. Continuing an earlier Run's branch, a bug's proof comes from the commit on it that has the
|
|
54
|
+
* test and not the fix.
|
|
55
|
+
*/
|
|
56
|
+
export const reproduced = step('reproduced', {
|
|
57
|
+
payload: {
|
|
58
|
+
words: Schema.optional(Schema.String).annotate({ description: 'What to build; the Task when left out.' }),
|
|
59
|
+
outcome: Schema.optional(LoopOutcome).annotate({ description: 'The Outcome the change must prove.' }),
|
|
60
|
+
continuing: Schema.optional(Continuing).annotate({
|
|
61
|
+
description: 'The earlier Run whose branch this one continues.'
|
|
62
|
+
})
|
|
63
|
+
},
|
|
64
|
+
success: Schema.Union([Reproduced, BaseVerified, NotNeeded]),
|
|
65
|
+
run: ({ words, outcome, continuing }) =>
|
|
66
|
+
Effect.gen(function* () {
|
|
67
|
+
if (outcome === 'refactor') return new BaseVerified({ base: withoutOutput(yield* verify('verify', {})) })
|
|
68
|
+
|
|
69
|
+
if (outcome !== 'bug') return new NotNeeded()
|
|
70
|
+
|
|
71
|
+
const task = taskOf(words)
|
|
72
|
+
|
|
73
|
+
const { check, revision } = yield* implementer('reproduce', {
|
|
74
|
+
prompt: continuing === undefined ? reproducePrompt(task) : reproducedOnBranchPrompt(task),
|
|
75
|
+
output: ReproducingTest
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const base = yield* verify('verify', { ...(revision === undefined ? undefined : { revision }), extra: [check] })
|
|
79
|
+
|
|
80
|
+
return new Reproduced({ check, base: withoutOutput(base) })
|
|
81
|
+
})
|
|
82
|
+
})
|
package/src/research.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { agent, artifact, defineLoop, LoopOutcome, note, step } from '@kitman-sh/sdk/loop'
|
|
2
2
|
import * as Effect from 'effect/Effect'
|
|
3
3
|
import * as Schema from 'effect/Schema'
|
|
4
|
+
import { reviewer } from './agents'
|
|
4
5
|
import { ScopedTickets } from './plan-review'
|
|
5
6
|
import { OneSentence } from './text-limits'
|
|
6
7
|
|
|
8
|
+
const researcher = agent('researcher')
|
|
9
|
+
|
|
7
10
|
export class ResearchQuestionMissing extends Schema.TaggedError<ResearchQuestionMissing>()('ResearchQuestionMissing', {
|
|
8
11
|
message: Schema.String
|
|
9
12
|
}) {}
|
|
10
13
|
|
|
11
14
|
const Input = Schema.Struct({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
repoBindingId: Schema.optional(Schema.String)
|
|
15
|
+
taskId: Schema.optional(Schema.String).annotate({ description: 'The Task whose question to research.' }),
|
|
16
|
+
words: Schema.optional(Schema.String).annotate({ description: 'The question, when there is no Task.' }),
|
|
17
|
+
repoBindingId: Schema.optional(Schema.String).annotate({
|
|
18
|
+
description: "The repository to read; the Team's default repository when left out."
|
|
19
|
+
})
|
|
18
20
|
})
|
|
19
21
|
|
|
20
22
|
const Sources = Schema.NonEmptyArray(Schema.String)
|
|
@@ -61,13 +63,17 @@ const Verdict = Schema.Struct({
|
|
|
61
63
|
})
|
|
62
64
|
|
|
63
65
|
const Output = Schema.Struct({
|
|
64
|
-
reportArtifactId: Schema.String,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
fix: Schema.optionalKey(Fix)
|
|
70
|
-
|
|
66
|
+
reportArtifactId: Schema.String.annotate({ description: 'The Artifact holding the research report.' }),
|
|
67
|
+
gaps: Schema.Array(Schema.String).annotate({ description: 'Gaps the reviewer still found after one more pass.' }),
|
|
68
|
+
unreached: Schema.Array(Schema.String).annotate({
|
|
69
|
+
description: 'The sources the report needed and could not reach.'
|
|
70
|
+
}),
|
|
71
|
+
fix: Schema.optionalKey(Fix).annotate({
|
|
72
|
+
description: 'The change the report proposes, with its Outcome, for a Build to start from.'
|
|
73
|
+
}),
|
|
74
|
+
nextStepTasks: Schema.optionalKey(NextSteps).annotate({
|
|
75
|
+
description: 'Next steps worth doing, as tickets File as Tasks can file.'
|
|
76
|
+
})
|
|
71
77
|
})
|
|
72
78
|
|
|
73
79
|
const researchPrompt = (words: string | undefined) =>
|
|
@@ -98,6 +104,29 @@ const againPrompt = (words: string | undefined, gaps: readonly string[]) =>
|
|
|
98
104
|
...gaps.map(gap => `- ${gap}`)
|
|
99
105
|
].join('\n\n')
|
|
100
106
|
|
|
107
|
+
/** The researcher's report; with `gaps`, a second pass that answers what a reviewer found unsupported. */
|
|
108
|
+
export const researched = step('researched', {
|
|
109
|
+
payload: {
|
|
110
|
+
words: Schema.optional(Schema.String),
|
|
111
|
+
gaps: Schema.Array(Schema.String).annotate({
|
|
112
|
+
description: 'What the review found unsupported; none on a first pass.'
|
|
113
|
+
})
|
|
114
|
+
},
|
|
115
|
+
success: Report,
|
|
116
|
+
run: ({ words, gaps }) =>
|
|
117
|
+
researcher('research', {
|
|
118
|
+
prompt: gaps.length === 0 ? researchPrompt(words) : againPrompt(words, gaps),
|
|
119
|
+
output: Report
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
/** Whether a report's conclusions follow from the evidence it cites. The Loop that uses it names a `reviewer` agent. */
|
|
124
|
+
export const researchReviewed = step('researchReviewed', {
|
|
125
|
+
payload: { report: Report },
|
|
126
|
+
success: Verdict,
|
|
127
|
+
run: ({ report }) => reviewer('review', { prompt: reviewPrompt(report), output: Verdict })
|
|
128
|
+
})
|
|
129
|
+
|
|
101
130
|
const list = (items: readonly string[]) => (items.length === 0 ? ['None.'] : items.map(item => `- ${item}`))
|
|
102
131
|
|
|
103
132
|
const reportMarkdown = (report: Report, gaps: readonly string[]) =>
|
|
@@ -154,8 +183,9 @@ const sample = {
|
|
|
154
183
|
*/
|
|
155
184
|
export default defineLoop({
|
|
156
185
|
id: 'research',
|
|
157
|
-
version: '
|
|
186
|
+
version: '3.0.0',
|
|
158
187
|
title: 'Research',
|
|
188
|
+
description: 'Answers a question from primary sources, with a reviewed report and suggested next steps.',
|
|
159
189
|
input: Input,
|
|
160
190
|
output: Output,
|
|
161
191
|
outcome: 'investigation',
|
|
@@ -169,7 +199,10 @@ export default defineLoop({
|
|
|
169
199
|
checks: [
|
|
170
200
|
{
|
|
171
201
|
name: 'reports',
|
|
172
|
-
script: {
|
|
202
|
+
script: {
|
|
203
|
+
input: { taskId: 'task-1' },
|
|
204
|
+
outputs: { 'researched/research': sample, 'researchReviewed/review': { supported: true, gaps: [] } }
|
|
205
|
+
}
|
|
173
206
|
}
|
|
174
207
|
],
|
|
175
208
|
run: input =>
|
|
@@ -177,31 +210,14 @@ export default defineLoop({
|
|
|
177
210
|
if (input.taskId === undefined && input.words === undefined)
|
|
178
211
|
return yield* new ResearchQuestionMissing({ message: 'Give the question to research, or a Task' })
|
|
179
212
|
|
|
180
|
-
const first = yield*
|
|
181
|
-
|
|
182
|
-
prompt: researchPrompt(input.words),
|
|
183
|
-
output: Report
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
const firstVerdict = yield* agentWork('review', {
|
|
187
|
-
agent: 'reviewer',
|
|
188
|
-
prompt: reviewPrompt(first),
|
|
189
|
-
output: Verdict
|
|
190
|
-
})
|
|
213
|
+
const first = yield* researched({ words: input.words, gaps: [] })
|
|
214
|
+
const firstVerdict = yield* researchReviewed({ report: first })
|
|
191
215
|
|
|
192
|
-
const report = firstVerdict.supported
|
|
193
|
-
? first
|
|
194
|
-
: yield* agentWork('research:again', {
|
|
195
|
-
agent: 'researcher',
|
|
196
|
-
prompt: againPrompt(input.words, firstVerdict.gaps),
|
|
197
|
-
output: Report
|
|
198
|
-
})
|
|
216
|
+
const report = firstVerdict.supported ? first : yield* researched({ words: input.words, gaps: firstVerdict.gaps })
|
|
199
217
|
|
|
200
218
|
const gaps = firstVerdict.supported
|
|
201
219
|
? []
|
|
202
|
-
: yield*
|
|
203
|
-
Effect.map(verdict => (verdict.supported ? [] : verdict.gaps))
|
|
204
|
-
)
|
|
220
|
+
: yield* researchReviewed({ report }).pipe(Effect.map(verdict => (verdict.supported ? [] : verdict.gaps)))
|
|
205
221
|
|
|
206
222
|
// The tickets are in the Output, where the offer to file them reads them.
|
|
207
223
|
const { nextStepTasks: _, ...data } = report
|
package/src/revert.ts
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyChange,
|
|
3
|
+
ask,
|
|
4
|
+
call,
|
|
5
|
+
type CalledLoop,
|
|
6
|
+
changeRequest,
|
|
7
|
+
ChangeRequestResult,
|
|
8
|
+
defineLoop,
|
|
9
|
+
mergedChangeRequest,
|
|
10
|
+
recordRevert,
|
|
11
|
+
type MergedChangeRequest
|
|
12
|
+
} from '@kitman-sh/sdk/loop'
|
|
13
|
+
import * as Effect from 'effect/Effect'
|
|
14
|
+
import * as Schema from 'effect/Schema'
|
|
15
|
+
import { implementer } from './agents'
|
|
16
|
+
import { verifyHead } from './change-request-body'
|
|
17
|
+
import shepherd from './shepherd'
|
|
18
|
+
import { ShepherdOutput } from './shepherd-output'
|
|
19
|
+
import { OneSentence } from './text-limits'
|
|
20
|
+
|
|
21
|
+
const Input = Schema.Struct({
|
|
22
|
+
changeRequestId: Schema.String.annotate({
|
|
23
|
+
description:
|
|
24
|
+
'The merged ChangeRequest whose change to take back out; the Run starts from the branch it merged into.'
|
|
25
|
+
}),
|
|
26
|
+
reason: Schema.optional(Schema.String).annotate({
|
|
27
|
+
description: 'Why it comes out, for the revert ChangeRequest and the note on each Task moved back.'
|
|
28
|
+
}),
|
|
29
|
+
reverts: Schema.optional(Schema.Boolean).annotate({
|
|
30
|
+
description:
|
|
31
|
+
'Marks the Loop that takes a merged change back out: Kitman starts the Run from the branch the ChangeRequest merged into, for no Task.'
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const Dependent = Schema.Struct({
|
|
36
|
+
reference: Schema.String,
|
|
37
|
+
url: Schema.String,
|
|
38
|
+
files: Schema.Array(Schema.String)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const Output = Schema.Struct({
|
|
42
|
+
status: Schema.Literals(['reverted', 'opened', 'already', 'not_merged', 'conflict', 'stopped']).annotate({
|
|
43
|
+
description:
|
|
44
|
+
'reverted: the revert landed and the Tasks moved back; opened: Shepherd did not land it; already: the branch has no change to take out; not_merged; conflict: later changes conflict where the agent could not settle them; stopped: a person stopped it.'
|
|
45
|
+
}),
|
|
46
|
+
reason: Schema.String.annotate({ description: 'Why it ended as it did, in a line.' }),
|
|
47
|
+
shippedIn: Schema.optional(Schema.String).annotate({
|
|
48
|
+
description: 'The first full version that shipped the change, when one did.'
|
|
49
|
+
}),
|
|
50
|
+
dependents: Schema.optional(Schema.Array(Dependent)).annotate({
|
|
51
|
+
description: 'The later ChangeRequests into the branch that changed what the revert conflicted on.'
|
|
52
|
+
}),
|
|
53
|
+
changeRequest: Schema.optional(ChangeRequestResult).annotate({ description: 'The revert ChangeRequest.' }),
|
|
54
|
+
landed: Schema.optional(ShepherdOutput).annotate({ description: 'What Shepherd did with the revert.' }),
|
|
55
|
+
reopened: Schema.optional(
|
|
56
|
+
Schema.Array(Schema.Struct({ key: Schema.String, state: Schema.optional(Schema.String) }))
|
|
57
|
+
).annotate({ description: "The original's Tasks, with the state each moved back to." })
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
type Output = typeof Output.Type
|
|
61
|
+
|
|
62
|
+
type Dependent = typeof Dependent.Type
|
|
63
|
+
|
|
64
|
+
/** A Task key as the forge's signals find one in a title: upper-cased, with no word boundary. */
|
|
65
|
+
const signalledKey = /[A-Z][A-Z0-9]*-[0-9]+/u
|
|
66
|
+
|
|
67
|
+
/** The revert's title names the original but no Task key, so merging it completes none of the Tasks it reopens. */
|
|
68
|
+
export const revertTitle = (original: Pick<MergedChangeRequest, 'reference' | 'title'>) => {
|
|
69
|
+
const title = original.title
|
|
70
|
+
.replace(/[a-z][a-z0-9]*-[0-9]+/giu, ' ')
|
|
71
|
+
.replace(/\s+/gu, ' ')
|
|
72
|
+
.trim()
|
|
73
|
+
|
|
74
|
+
const kept = signalledKey.test(title.toUpperCase()) ? '' : title
|
|
75
|
+
|
|
76
|
+
return `Revert ${original.reference} ${kept}`.trim().slice(0, 200)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const DependentsAnswer = Schema.Struct({
|
|
80
|
+
dependents: Schema.Array(
|
|
81
|
+
Schema.Struct({
|
|
82
|
+
/** The id of a ChangeRequest from the list. */
|
|
83
|
+
changeRequestId: Schema.String,
|
|
84
|
+
/** The conflicting files it changed. */
|
|
85
|
+
files: Schema.Array(Schema.String),
|
|
86
|
+
why: OneSentence
|
|
87
|
+
})
|
|
88
|
+
)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
const dependentsPrompt = (original: MergedChangeRequest, files: readonly string[], settled: boolean) =>
|
|
92
|
+
[
|
|
93
|
+
`Kitman reverted ${original.reference} "${original.title}" on this branch, and the revert conflicted with what ${original.targetBranch} did since in: ${files.join(', ')}. ${settled ? 'Those conflicts are settled in the last commit.' : 'Kitman put the branch back as it was.'}`,
|
|
94
|
+
`Find which of these ChangeRequests, merged into ${original.targetBranch} after it, changed those files: run \`git log --format='%H %s' ${original.mergeRevision ?? original.targetBranch}..HEAD -- <files>\` and match each commit to a ChangeRequest below by its merge revision, or by a subject that names it.`,
|
|
95
|
+
original.later
|
|
96
|
+
.map(
|
|
97
|
+
later =>
|
|
98
|
+
`- ${later.id}: ${later.reference} ${later.title}${later.mergeRevision === undefined ? '' : ` (merged as ${later.mergeRevision})`}`
|
|
99
|
+
)
|
|
100
|
+
.join('\n'),
|
|
101
|
+
'Change no file and commit nothing. Answer with each ChangeRequest that changed those files, by its id, with the files and why it depends on the reverted change in a line.'
|
|
102
|
+
].join('\n\n')
|
|
103
|
+
|
|
104
|
+
/** The later ChangeRequests into the branch that changed the files the revert conflicted on, as an agent finds them. */
|
|
105
|
+
const dependentsOf = (original: MergedChangeRequest, files: readonly string[], settled: boolean) =>
|
|
106
|
+
original.later.length === 0
|
|
107
|
+
? Effect.succeed([])
|
|
108
|
+
: Effect.map(
|
|
109
|
+
implementer('find-dependents', {
|
|
110
|
+
prompt: dependentsPrompt(original, files, settled),
|
|
111
|
+
output: DependentsAnswer,
|
|
112
|
+
timeout: '20 minutes'
|
|
113
|
+
}),
|
|
114
|
+
({ dependents }): readonly Dependent[] =>
|
|
115
|
+
original.later.flatMap(later => {
|
|
116
|
+
const named = dependents.find(dependent => dependent.changeRequestId === later.id)
|
|
117
|
+
|
|
118
|
+
return named === undefined ? [] : [{ reference: later.reference, url: later.url, files: named.files }]
|
|
119
|
+
})
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
const dependentWords = (dependents: readonly Dependent[]) =>
|
|
123
|
+
dependents.length === 0
|
|
124
|
+
? 'No later ChangeRequest Kitman knows of changed them.'
|
|
125
|
+
: `Later changes depend on it: ${dependents.map(dependent => `${dependent.reference} (${dependent.files.join(', ')})`).join('; ')}.`
|
|
126
|
+
|
|
127
|
+
/** Its first full version, and the prereleases that had it, in words. */
|
|
128
|
+
const shippedWords = (original: MergedChangeRequest) => {
|
|
129
|
+
const full = original.releases.find(release => !release.prerelease)
|
|
130
|
+
const prereleases = original.releases.filter(release => release.prerelease).map(release => release.version)
|
|
131
|
+
|
|
132
|
+
if (full !== undefined) return `${original.reference} shipped in ${full.version}.`
|
|
133
|
+
|
|
134
|
+
return prereleases.length === 0
|
|
135
|
+
? `${original.reference} is in no Release Kitman recorded.`
|
|
136
|
+
: `${original.reference} is in prereleases ${prereleases.join(', ')}, and in no full version yet.`
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const revertBody = (input: {
|
|
140
|
+
readonly original: MergedChangeRequest
|
|
141
|
+
readonly reason: string | undefined
|
|
142
|
+
readonly settled: readonly string[]
|
|
143
|
+
readonly dependents: readonly Dependent[]
|
|
144
|
+
readonly failing: readonly string[]
|
|
145
|
+
readonly notRun: readonly string[]
|
|
146
|
+
}) =>
|
|
147
|
+
[
|
|
148
|
+
`Reverts ${input.original.reference} [${input.original.title}](${input.original.url}) on \`${input.original.targetBranch}\`.`,
|
|
149
|
+
input.reason === undefined || input.reason.trim() === '' ? undefined : `Why: ${input.reason.trim()}`,
|
|
150
|
+
shippedWords(input.original),
|
|
151
|
+
input.original.tasks.length === 0
|
|
152
|
+
? undefined
|
|
153
|
+
: `Once it merges, ${input.original.tasks.map(task => task.key).join(', ')} move back to their Team's first started state.`,
|
|
154
|
+
input.settled.length === 0
|
|
155
|
+
? undefined
|
|
156
|
+
: `The revert conflicted with later changes in ${input.settled.join(', ')}; the agent settled them so that work stays. ${dependentWords(input.dependents)}`,
|
|
157
|
+
input.failing.length === 0 ? undefined : `Checks that fail with the change out: ${input.failing.join(', ')}.`,
|
|
158
|
+
input.notRun.length === 0 ? undefined : `Not verified:\n${input.notRun.map(item => `- ${item}`).join('\n')}`
|
|
159
|
+
]
|
|
160
|
+
.filter(part => part !== undefined)
|
|
161
|
+
.join('\n\n')
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Takes a merged ChangeRequest's change back out of the branch it merged into: the Runner reverts it as one commit,
|
|
165
|
+
* the agent settles what later changes conflict with, and a person decides before a revert that later changes depend on
|
|
166
|
+
* goes on. Verified, the revert opens as a ChangeRequest that names the original and Shepherd lands it. Once it lands,
|
|
167
|
+
* Kitman records the original reverted, so the Releases that contain it say so, and moves its Tasks back to their
|
|
168
|
+
* Team's first started state with a note on why and for whom.
|
|
169
|
+
*/
|
|
170
|
+
const revert = defineLoop({
|
|
171
|
+
id: 'revert',
|
|
172
|
+
version: '1.0.0',
|
|
173
|
+
title: 'Revert',
|
|
174
|
+
description: "Takes a merged ChangeRequest's change back out of its branch and lands the revert.",
|
|
175
|
+
input: Input,
|
|
176
|
+
output: Output,
|
|
177
|
+
agents: { implementer: 'implementer' },
|
|
178
|
+
checkout: 'write',
|
|
179
|
+
capabilities: ['agent_work', 'read_change_request', 'verify', 'change_request', 'write_back', 'ask', 'call'],
|
|
180
|
+
calls: (): readonly CalledLoop[] => [shepherd],
|
|
181
|
+
run: input =>
|
|
182
|
+
Effect.gen(function* () {
|
|
183
|
+
const original = yield* mergedChangeRequest('original', { changeRequestId: input.changeRequestId })
|
|
184
|
+
const ref = original.reference
|
|
185
|
+
const shipped = original.releases.find(release => !release.prerelease)?.version
|
|
186
|
+
const shippedIn = shipped === undefined ? undefined : { shippedIn: shipped }
|
|
187
|
+
|
|
188
|
+
if (original.status !== 'merged')
|
|
189
|
+
return {
|
|
190
|
+
status: 'not_merged',
|
|
191
|
+
reason: `${ref} is ${original.status}, so it has no change to take out`
|
|
192
|
+
} satisfies Output
|
|
193
|
+
|
|
194
|
+
if (original.reverted !== undefined)
|
|
195
|
+
return {
|
|
196
|
+
status: 'already',
|
|
197
|
+
reason: `${ref} was reverted already, at ${original.reverted.at}`,
|
|
198
|
+
...shippedIn
|
|
199
|
+
} satisfies Output
|
|
200
|
+
|
|
201
|
+
const applied = yield* applyChange('revert', {
|
|
202
|
+
agent: 'implementer',
|
|
203
|
+
changeRequestId: original.id,
|
|
204
|
+
revert: true
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
if (applied.status === 'already')
|
|
208
|
+
return {
|
|
209
|
+
status: 'already',
|
|
210
|
+
reason: `${original.targetBranch} does not have ${ref}'s change, so there is nothing to take out`,
|
|
211
|
+
...shippedIn
|
|
212
|
+
} satisfies Output
|
|
213
|
+
|
|
214
|
+
if (applied.status === 'conflict') {
|
|
215
|
+
const dependents = yield* dependentsOf(original, applied.files, false)
|
|
216
|
+
|
|
217
|
+
yield* ask('conflict', {
|
|
218
|
+
prompt: `Reverting ${ref} conflicts with what ${original.targetBranch} did since, in ${applied.files.join(', ')}, and the agent could not settle them: ${applied.reason}. ${dependentWords(dependents)} ${original.targetBranch} is as it was. ${shippedWords(original)}`,
|
|
219
|
+
options: [
|
|
220
|
+
{ value: 'Revert by hand', description: 'A person reverts it and settles those files from here.' },
|
|
221
|
+
{ value: 'Leave it in', description: `${ref}'s change stays on ${original.targetBranch}.` }
|
|
222
|
+
],
|
|
223
|
+
recommended: 'Revert by hand',
|
|
224
|
+
recommendationReason: 'Only a person can say how the later changes should work without it.',
|
|
225
|
+
default: null
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
status: 'conflict',
|
|
230
|
+
reason: `Reverting ${ref} conflicts in ${applied.files.join(', ')}: ${applied.reason}`,
|
|
231
|
+
dependents,
|
|
232
|
+
...shippedIn
|
|
233
|
+
} satisfies Output
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const dependents = applied.settled.length === 0 ? [] : yield* dependentsOf(original, applied.settled, true)
|
|
237
|
+
|
|
238
|
+
if (applied.settled.length > 0) {
|
|
239
|
+
const going = yield* ask('dependents', {
|
|
240
|
+
prompt: `Reverting ${ref} conflicted with later changes to ${original.targetBranch} in ${applied.settled.join(', ')}, and the agent settled them so that work stays. ${dependentWords(dependents)} ${shippedWords(original)} Open the revert?`,
|
|
241
|
+
options: [
|
|
242
|
+
{ value: 'Open the revert', description: 'Verifies it, opens its ChangeRequest and lands it.' },
|
|
243
|
+
{ value: 'Stop', description: `Nothing is opened, and ${ref}'s change stays on ${original.targetBranch}.` }
|
|
244
|
+
],
|
|
245
|
+
recommended: 'Open the revert',
|
|
246
|
+
recommendationReason: 'The agent kept the later work, and its checks and review still run before it merges.',
|
|
247
|
+
default: null
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
if (going === 'Stop')
|
|
251
|
+
return { status: 'stopped', reason: 'A person stopped the revert', dependents, ...shippedIn } satisfies Output
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const head = yield* verifyHead('verify', applied.revision)
|
|
255
|
+
|
|
256
|
+
if (head.failing.length > 0) {
|
|
257
|
+
const going = yield* ask('checks-failed', {
|
|
258
|
+
prompt: `With ${ref}'s change out, ${head.failing.join(', ')} fail on ${original.targetBranch}. Open the revert anyway?`,
|
|
259
|
+
options: [
|
|
260
|
+
{
|
|
261
|
+
value: 'Open it anyway',
|
|
262
|
+
description: 'Opens its ChangeRequest; Shepherd fixes what its pipeline fails.'
|
|
263
|
+
},
|
|
264
|
+
{ value: 'Stop', description: `Nothing is opened, and ${ref}'s change stays on ${original.targetBranch}.` }
|
|
265
|
+
],
|
|
266
|
+
recommended: 'Stop',
|
|
267
|
+
recommendationReason: 'Failing checks may mean later changes need the change, which a person should look at.',
|
|
268
|
+
default: null
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
if (going === 'Stop')
|
|
272
|
+
return {
|
|
273
|
+
status: 'stopped',
|
|
274
|
+
reason: `A person stopped the revert: ${head.failing.join(', ')} fail without ${ref}'s change`,
|
|
275
|
+
dependents,
|
|
276
|
+
...shippedIn
|
|
277
|
+
} satisfies Output
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const opened = yield* changeRequest('change-request', {
|
|
281
|
+
title: revertTitle(original),
|
|
282
|
+
body: revertBody({
|
|
283
|
+
original,
|
|
284
|
+
reason: input.reason,
|
|
285
|
+
settled: applied.settled,
|
|
286
|
+
dependents,
|
|
287
|
+
failing: head.failing,
|
|
288
|
+
notRun: head.notRun
|
|
289
|
+
})
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
const landed = yield* call('shepherd', shepherd, {
|
|
293
|
+
changeRequestId: opened.id,
|
|
294
|
+
branch: original.targetBranch,
|
|
295
|
+
...(head.notRun.length === 0 ? undefined : { notRun: head.notRun })
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
const found = dependents.length === 0 ? undefined : { dependents }
|
|
299
|
+
|
|
300
|
+
if (landed.status !== 'merged')
|
|
301
|
+
return {
|
|
302
|
+
status: 'opened',
|
|
303
|
+
reason: `${opened.url} reverts ${ref}; Shepherd ended ${landed.status}: ${landed.reason}`,
|
|
304
|
+
changeRequest: opened,
|
|
305
|
+
landed,
|
|
306
|
+
...found,
|
|
307
|
+
...shippedIn
|
|
308
|
+
} satisfies Output
|
|
309
|
+
|
|
310
|
+
const recorded = yield* recordRevert('record-revert', {
|
|
311
|
+
changeRequestId: original.id,
|
|
312
|
+
revertedBy: opened.id,
|
|
313
|
+
...(input.reason === undefined ? undefined : { reason: input.reason })
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
return {
|
|
317
|
+
status: 'reverted',
|
|
318
|
+
reason: `${opened.url} took ${ref} out of ${original.targetBranch}. ${shippedWords(original)}`,
|
|
319
|
+
changeRequest: opened,
|
|
320
|
+
landed,
|
|
321
|
+
reopened: recorded.tasks.map(task => ({
|
|
322
|
+
key: task.key,
|
|
323
|
+
...(task.state === undefined ? undefined : { state: task.state })
|
|
324
|
+
})),
|
|
325
|
+
...found,
|
|
326
|
+
...shippedIn
|
|
327
|
+
} satisfies Output
|
|
328
|
+
})
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
export default revert
|