@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/kitman.config.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { defineKit } from '@kitman-sh/sdk/loop'
|
|
2
2
|
import {
|
|
3
|
+
backport,
|
|
3
4
|
build,
|
|
5
|
+
deploy,
|
|
4
6
|
errand,
|
|
5
7
|
fileTasks,
|
|
6
8
|
hillclimb,
|
|
@@ -8,17 +10,171 @@ import {
|
|
|
8
10
|
plan,
|
|
9
11
|
projectUpdate,
|
|
10
12
|
release,
|
|
13
|
+
releaseSet,
|
|
11
14
|
research,
|
|
12
15
|
hindsight,
|
|
16
|
+
land,
|
|
13
17
|
landEpic,
|
|
14
18
|
review,
|
|
19
|
+
revert,
|
|
15
20
|
shepherd,
|
|
16
21
|
sweep,
|
|
17
22
|
tidy
|
|
18
23
|
} from './src/index'
|
|
19
24
|
|
|
20
|
-
/** Its Loops by id, for a fork to spread the one it replaces. */
|
|
21
|
-
export {
|
|
25
|
+
/** Its Loops by id, for a fork to spread the one it replaces, and the Steps it defines with their outcomes. */
|
|
26
|
+
export {
|
|
27
|
+
loops,
|
|
28
|
+
steps,
|
|
29
|
+
approved,
|
|
30
|
+
Approved,
|
|
31
|
+
ApprovalRefused,
|
|
32
|
+
ChangesWanted,
|
|
33
|
+
LeftToPerson,
|
|
34
|
+
ReviewBuilt,
|
|
35
|
+
Checked,
|
|
36
|
+
checked,
|
|
37
|
+
ReviewDone,
|
|
38
|
+
ReviewFixed,
|
|
39
|
+
followedUp,
|
|
40
|
+
judged,
|
|
41
|
+
Posted,
|
|
42
|
+
Ranged,
|
|
43
|
+
ranged,
|
|
44
|
+
ReviewBaseUnpinned,
|
|
45
|
+
ReviewDiffEmpty,
|
|
46
|
+
ReviewReviewed,
|
|
47
|
+
ReviewSeat,
|
|
48
|
+
ReviewSeats,
|
|
49
|
+
reviewSeats,
|
|
50
|
+
ReviewTargetMissing,
|
|
51
|
+
seated,
|
|
52
|
+
SeatOutput,
|
|
53
|
+
done,
|
|
54
|
+
Done,
|
|
55
|
+
Blocked,
|
|
56
|
+
TooBig,
|
|
57
|
+
buildTried,
|
|
58
|
+
Built,
|
|
59
|
+
chosen,
|
|
60
|
+
delivered,
|
|
61
|
+
Delivered,
|
|
62
|
+
drafted,
|
|
63
|
+
Drafted,
|
|
64
|
+
Failed,
|
|
65
|
+
failureAnswered,
|
|
66
|
+
FileAsTasks,
|
|
67
|
+
filed,
|
|
68
|
+
Filed,
|
|
69
|
+
Finish,
|
|
70
|
+
ImplementNow,
|
|
71
|
+
MergeAgain,
|
|
72
|
+
Merged,
|
|
73
|
+
mergeTried,
|
|
74
|
+
PlanApproved,
|
|
75
|
+
planReviewed,
|
|
76
|
+
Rebuild,
|
|
77
|
+
Refine,
|
|
78
|
+
refined,
|
|
79
|
+
retried,
|
|
80
|
+
SkipIt,
|
|
81
|
+
Skipped,
|
|
82
|
+
Steer,
|
|
83
|
+
StopHere,
|
|
84
|
+
Stopped,
|
|
85
|
+
ticketBuilt,
|
|
86
|
+
opened,
|
|
87
|
+
Opened,
|
|
88
|
+
rallied,
|
|
89
|
+
BaseUnpinned,
|
|
90
|
+
DisputeStands,
|
|
91
|
+
FindingsReturned,
|
|
92
|
+
Fixed,
|
|
93
|
+
Halted,
|
|
94
|
+
Reviewed,
|
|
95
|
+
RoundCap,
|
|
96
|
+
SameEvidence,
|
|
97
|
+
Settled,
|
|
98
|
+
surveyed,
|
|
99
|
+
Surveyed,
|
|
100
|
+
tidied,
|
|
101
|
+
Tidied,
|
|
102
|
+
NothingWorthIt,
|
|
103
|
+
folded,
|
|
104
|
+
Folded,
|
|
105
|
+
AlertResolved,
|
|
106
|
+
Placed,
|
|
107
|
+
investigated,
|
|
108
|
+
concluded,
|
|
109
|
+
Concluded,
|
|
110
|
+
fixOffered,
|
|
111
|
+
FixDeclined,
|
|
112
|
+
FixStarted,
|
|
113
|
+
FixFailed,
|
|
114
|
+
researched,
|
|
115
|
+
researchReviewed,
|
|
116
|
+
found,
|
|
117
|
+
proposed,
|
|
118
|
+
improved,
|
|
119
|
+
written,
|
|
120
|
+
posted,
|
|
121
|
+
reproduced,
|
|
122
|
+
Reproduced,
|
|
123
|
+
BaseVerified,
|
|
124
|
+
NotNeeded,
|
|
125
|
+
implemented,
|
|
126
|
+
Implemented,
|
|
127
|
+
standing,
|
|
128
|
+
TakenOver,
|
|
129
|
+
Rebuilt,
|
|
130
|
+
BuildBlocked,
|
|
131
|
+
landed,
|
|
132
|
+
Assessed,
|
|
133
|
+
Closed,
|
|
134
|
+
LeftOpen,
|
|
135
|
+
Listed,
|
|
136
|
+
Mended,
|
|
137
|
+
Moved,
|
|
138
|
+
NothingLeft,
|
|
139
|
+
NothingToSweep,
|
|
140
|
+
Superseded,
|
|
141
|
+
Verified,
|
|
142
|
+
Calibrated,
|
|
143
|
+
ChecksFailed,
|
|
144
|
+
Discovered,
|
|
145
|
+
Exhausted,
|
|
146
|
+
ExternalFiled,
|
|
147
|
+
GainGone,
|
|
148
|
+
Improved,
|
|
149
|
+
Kept,
|
|
150
|
+
NoGain,
|
|
151
|
+
Reverted,
|
|
152
|
+
RevertUnconfirmed,
|
|
153
|
+
TooNoisy,
|
|
154
|
+
Unfiled,
|
|
155
|
+
Unsafe
|
|
156
|
+
} from './src/index'
|
|
157
|
+
|
|
158
|
+
/** What Release's Steps end in, for a Layer that replaces one or a Loop of your own that calls them. */
|
|
159
|
+
export {
|
|
160
|
+
Cut,
|
|
161
|
+
Deployed,
|
|
162
|
+
DeployFailed,
|
|
163
|
+
Edit,
|
|
164
|
+
Gated,
|
|
165
|
+
GateFailed,
|
|
166
|
+
NothingToLand,
|
|
167
|
+
NothingToRelease,
|
|
168
|
+
NotDeployed,
|
|
169
|
+
NotLanded,
|
|
170
|
+
Published,
|
|
171
|
+
Rejected,
|
|
172
|
+
ReleaseApproved,
|
|
173
|
+
ReleaseDrafted,
|
|
174
|
+
ReleaseLanded,
|
|
175
|
+
TagTaken,
|
|
176
|
+
VersionTaken
|
|
177
|
+
} from './src/index'
|
|
22
178
|
|
|
23
179
|
/** Where an Agent's Step goes when the Runner's default Harness cannot run, such as Claude Code out of quota. */
|
|
24
180
|
const fallbacks = [{ harness: 'pi' }]
|
|
@@ -40,7 +196,9 @@ const reviewer = {
|
|
|
40
196
|
/** Kitman's Kit for building software: its Loops, the Agents they run, and the skills those use. */
|
|
41
197
|
export default defineKit({
|
|
42
198
|
loops: [
|
|
199
|
+
backport,
|
|
43
200
|
build,
|
|
201
|
+
deploy,
|
|
44
202
|
errand,
|
|
45
203
|
fileTasks,
|
|
46
204
|
hillclimb,
|
|
@@ -48,10 +206,13 @@ export default defineKit({
|
|
|
48
206
|
plan,
|
|
49
207
|
projectUpdate,
|
|
50
208
|
release,
|
|
209
|
+
releaseSet,
|
|
51
210
|
research,
|
|
52
211
|
hindsight,
|
|
212
|
+
land,
|
|
53
213
|
landEpic,
|
|
54
214
|
review,
|
|
215
|
+
revert,
|
|
55
216
|
shepherd,
|
|
56
217
|
sweep,
|
|
57
218
|
tidy
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitman-sh/software-engineering",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
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": "SEE LICENSE IN LICENSE.md",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"dist",
|
|
13
|
+
"CHANGELOG.md",
|
|
13
14
|
"INSTRUCTIONS.md",
|
|
14
15
|
"agents",
|
|
15
16
|
"kitman.config.ts",
|
|
@@ -18,12 +19,12 @@
|
|
|
18
19
|
"LICENSE.md"
|
|
19
20
|
],
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"@kitman-sh/sdk": "0.
|
|
22
|
+
"@kitman-sh/sdk": "0.15.0",
|
|
22
23
|
"effect": "^4.1.2"
|
|
23
24
|
},
|
|
24
25
|
"kitman": {
|
|
25
26
|
"bundle": "dist/bundle.js",
|
|
26
|
-
"digest": "
|
|
27
|
+
"digest": "fdbfbd9642d48aa08ae59a4b4f8abfb318e944e3fb87e7872b5e41ff6d20cef5",
|
|
27
28
|
"protocolVersion": 5,
|
|
28
29
|
"declarations": "dist/declarations.json",
|
|
29
30
|
"setup": {
|
package/src/agents.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { agent } from '@kitman-sh/sdk/loop'
|
|
2
|
+
|
|
3
|
+
export const implementer = agent('implementer')
|
|
4
|
+
|
|
5
|
+
/** The implementer of a plan-reviewed Task's first implementation, at lower effort. */
|
|
6
|
+
export const plannedImplementer = agent('planned-implementer')
|
|
7
|
+
|
|
8
|
+
export const investigator = agent('investigator')
|
|
9
|
+
|
|
10
|
+
export const reviewer = agent('reviewer')
|
package/src/approved.ts
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { approveChangeRequest, ask, call, MergedFinding, step, stepName } from '@kitman-sh/sdk/loop'
|
|
2
|
+
import * as Effect from 'effect/Effect'
|
|
3
|
+
import * as Schema from 'effect/Schema'
|
|
4
|
+
import { verifyHead } from './change-request-body'
|
|
5
|
+
import { OutOfScopeFinding } from './out-of-scope'
|
|
6
|
+
import { ReviewInput, ReviewOutput } from './review'
|
|
7
|
+
import { ReviewedScope } from './reviewed-scope'
|
|
8
|
+
|
|
9
|
+
/** The findings the Review kept apart as out of scope, for the next review and a Build handed the ChangeRequest. */
|
|
10
|
+
const keptApart = { outOfScopeFindings: Schema.optionalKey(Schema.Array(OutOfScopeFinding)) }
|
|
11
|
+
|
|
12
|
+
const kept = (findings: readonly OutOfScopeFinding[] | undefined) =>
|
|
13
|
+
findings === undefined || findings.length === 0 ? undefined : { outOfScopeFindings: findings }
|
|
14
|
+
|
|
15
|
+
/** Review, by its schemas: Review calls Build, which calls Shepherd, which uses this Step. */
|
|
16
|
+
const reviewLoop = () => ({ id: 'review', input: ReviewInput, output: ReviewOutput })
|
|
17
|
+
|
|
18
|
+
/** Kitman approved the head. */
|
|
19
|
+
export class Approved extends Schema.TaggedClass<Approved>()('Approved', {
|
|
20
|
+
head: Schema.String,
|
|
21
|
+
/** The id of the approval this Step recorded; left out when the head was approved already. */
|
|
22
|
+
approval: Schema.optionalKey(Schema.String),
|
|
23
|
+
...keptApart
|
|
24
|
+
}) {}
|
|
25
|
+
|
|
26
|
+
/** The head's approval is a person's: they chose to approve it themselves, or verify never ran some of its tests. */
|
|
27
|
+
export class LeftToPerson extends Schema.TaggedError<LeftToPerson>()('LeftToPerson', {
|
|
28
|
+
head: Schema.String,
|
|
29
|
+
why: Schema.String,
|
|
30
|
+
/** The tests verify never ran, when a Review passed the head but left it unapproved for them. */
|
|
31
|
+
notRun: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
32
|
+
/** The Step of that passing Review, which an approval names as its `review` once a person says to merge. */
|
|
33
|
+
review: Schema.optionalKey(Schema.String),
|
|
34
|
+
...keptApart
|
|
35
|
+
}) {}
|
|
36
|
+
|
|
37
|
+
/** The Review blocks: its findings, blocking or not. */
|
|
38
|
+
export class ChangesWanted extends Schema.TaggedError<ChangesWanted>()('ChangesWanted', {
|
|
39
|
+
findings: Schema.Array(MergedFinding),
|
|
40
|
+
/** The Review's scope judgement, when it judged one. */
|
|
41
|
+
scope: Schema.optionalKey(ReviewedScope),
|
|
42
|
+
...keptApart
|
|
43
|
+
}) {}
|
|
44
|
+
|
|
45
|
+
/** The Review passed, but Kitman refused the approval, as for a Run that pushed to the branch. */
|
|
46
|
+
export class ApprovalRefused extends Schema.TaggedError<ApprovalRefused>()('ApprovalRefused', {
|
|
47
|
+
head: Schema.String,
|
|
48
|
+
reason: Schema.String,
|
|
49
|
+
...keptApart
|
|
50
|
+
}) {}
|
|
51
|
+
|
|
52
|
+
const Unreviewed = Schema.Struct({
|
|
53
|
+
files: Schema.Array(Schema.String),
|
|
54
|
+
/** The head the catch-up that left them pushed; a later head's review reads what changed since it too. */
|
|
55
|
+
caughtUp: Schema.String,
|
|
56
|
+
/** The catch-up's base sync Step, as `level`'s `CaughtUp` names it: its carried approval covers the rest. */
|
|
57
|
+
sync: Schema.String
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Gets a ChangeRequest's head approved: at once when it is approved already; by a Review of only the files a catch-up
|
|
62
|
+
* left unreviewed; or, when a person or a full-auto Team says to, by a Review of what changed since the last approved
|
|
63
|
+
* head, or of the whole change. The calling Loop lists Review in `calls`.
|
|
64
|
+
*/
|
|
65
|
+
export const approved = step('approved', {
|
|
66
|
+
payload: {
|
|
67
|
+
changeRequestId: Schema.String,
|
|
68
|
+
head: Schema.String.annotate({ description: 'The head to approve.' }),
|
|
69
|
+
target: Schema.optional(Schema.String).annotate({
|
|
70
|
+
description:
|
|
71
|
+
'The branch the ChangeRequest merges into, which the Review diffs against; the default branch when left out.'
|
|
72
|
+
}),
|
|
73
|
+
approved: Schema.optional(Schema.String).annotate({
|
|
74
|
+
description: 'The last approved head, other than `head`: the Review reads only what changed since it.'
|
|
75
|
+
}),
|
|
76
|
+
unreviewed: Schema.optional(Unreviewed).annotate({
|
|
77
|
+
description: "The files a catch-up merge settled or rewrote, as `level`'s `CaughtUp` names them."
|
|
78
|
+
}),
|
|
79
|
+
which: Schema.optional(Schema.String).annotate({
|
|
80
|
+
description: 'What the head is, as the Question to review it names it, such as "the head whose pipeline passed".'
|
|
81
|
+
}),
|
|
82
|
+
notRun: Schema.optional(Schema.Array(Schema.String)).annotate({
|
|
83
|
+
description: 'Why each test verify never ran is unverified, besides those verify at the head finds.'
|
|
84
|
+
}),
|
|
85
|
+
earlier: Schema.optional(Schema.Array(MergedFinding)).annotate({
|
|
86
|
+
description: "An earlier review's findings, for a Review of the fix for them."
|
|
87
|
+
}),
|
|
88
|
+
reviewed: Schema.optional(Schema.String).annotate({ description: 'The head that earlier review read.' }),
|
|
89
|
+
scope: Schema.optional(ReviewedScope).annotate({
|
|
90
|
+
description: "That earlier review's scope judgement, for a Review of the whole change or what changed since."
|
|
91
|
+
}),
|
|
92
|
+
outOfScopeFindings: Schema.optional(Schema.Array(OutOfScopeFinding)).annotate({
|
|
93
|
+
description: "Earlier reviews' findings kept apart as out of scope."
|
|
94
|
+
})
|
|
95
|
+
},
|
|
96
|
+
success: Approved,
|
|
97
|
+
error: Schema.Union([LeftToPerson, ChangesWanted, ApprovalRefused]),
|
|
98
|
+
run: ({
|
|
99
|
+
changeRequestId,
|
|
100
|
+
head,
|
|
101
|
+
target = 'HEAD',
|
|
102
|
+
approved: since,
|
|
103
|
+
unreviewed,
|
|
104
|
+
which,
|
|
105
|
+
notRun: known = [],
|
|
106
|
+
earlier = [],
|
|
107
|
+
reviewed,
|
|
108
|
+
scope,
|
|
109
|
+
outOfScopeFindings
|
|
110
|
+
}) =>
|
|
111
|
+
Effect.gen(function* () {
|
|
112
|
+
const fixOf = {
|
|
113
|
+
deliveredBy: changeRequestId,
|
|
114
|
+
...(earlier.length === 0 ? undefined : { earlier }),
|
|
115
|
+
...(reviewed === undefined ? undefined : { reviewed }),
|
|
116
|
+
...kept(outOfScopeFindings)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (unreviewed !== undefined) {
|
|
120
|
+
const files = yield* call('review', reviewLoop(), {
|
|
121
|
+
base: `origin/${target}`,
|
|
122
|
+
head,
|
|
123
|
+
files: unreviewed.files,
|
|
124
|
+
...(head === unreviewed.caughtUp ? undefined : { since: unreviewed.caughtUp }),
|
|
125
|
+
...fixOf
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
const filesKept = kept(files.outOfScopeFindings)
|
|
129
|
+
|
|
130
|
+
if (files.blocking) return yield* new ChangesWanted({ findings: files.findings, ...filesKept })
|
|
131
|
+
|
|
132
|
+
const approval = yield* approveChangeRequest('approve', {
|
|
133
|
+
changeRequestId,
|
|
134
|
+
head,
|
|
135
|
+
summary: `A review of the files merging ${target} in changed (${unreviewed.files.join(', ')}) passed with nothing blocking.`,
|
|
136
|
+
review: 'review',
|
|
137
|
+
carries: unreviewed.sync
|
|
138
|
+
}).pipe(
|
|
139
|
+
Effect.catchTag('StepFailed', error => Effect.succeed({ approved: false as const, reason: error.reason }))
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
if (!approval.approved) return yield* new ApprovalRefused({ head, reason: approval.reason, ...filesKept })
|
|
143
|
+
|
|
144
|
+
return new Approved({ head, approval: approval.reviewId, ...filesKept })
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (since === head) return new Approved({ head, ...kept(outOfScopeFindings) })
|
|
148
|
+
|
|
149
|
+
const reviewIt = yield* ask('unapproved', {
|
|
150
|
+
prompt: `Nobody has approved ${head}${which === undefined ? '' : `, ${which}`}. Have Kitman review it?`,
|
|
151
|
+
options: [
|
|
152
|
+
{
|
|
153
|
+
value: 'Review',
|
|
154
|
+
description:
|
|
155
|
+
since === undefined
|
|
156
|
+
? "Kitman's Review reads the whole change at this head and approves it if nothing blocks."
|
|
157
|
+
: `Kitman's Review reads what changed since ${since}, the last approved head, and approves it if nothing there blocks.`
|
|
158
|
+
},
|
|
159
|
+
{ value: 'Wait', description: 'Waits for a person to approve this head.' }
|
|
160
|
+
],
|
|
161
|
+
recommended: 'Review',
|
|
162
|
+
recommendationReason: 'A passing Review of the change is what approved the head Build shipped.',
|
|
163
|
+
default: 'Wait',
|
|
164
|
+
// A full-auto Team merges what its Review approved, including heads a Loop pushed itself.
|
|
165
|
+
auto: 'Review',
|
|
166
|
+
evidence: { head },
|
|
167
|
+
timeout: '1 hour'
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
if (reviewIt === 'Wait')
|
|
171
|
+
return yield* new LeftToPerson({ head, why: `A person approves ${head}`, ...kept(outOfScopeFindings) })
|
|
172
|
+
|
|
173
|
+
const { notRun: headNotRun } = yield* verifyHead('verify', head)
|
|
174
|
+
const notRun = [...new Set([...known, ...headNotRun])]
|
|
175
|
+
|
|
176
|
+
const change = yield* call('review', reviewLoop(), {
|
|
177
|
+
base: `origin/${target}`,
|
|
178
|
+
head,
|
|
179
|
+
...(notRun.length === 0 ? undefined : { notRun }),
|
|
180
|
+
...(since === undefined ? undefined : { approved: since }),
|
|
181
|
+
...fixOf,
|
|
182
|
+
...(scope === undefined ? undefined : { scope })
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
const changeKept = kept(change.outOfScopeFindings)
|
|
186
|
+
|
|
187
|
+
if (change.blocking)
|
|
188
|
+
return yield* new ChangesWanted({
|
|
189
|
+
findings: change.findings,
|
|
190
|
+
...(change.scope === undefined ? undefined : { scope: change.scope }),
|
|
191
|
+
...changeKept
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
if (notRun.length > 0)
|
|
195
|
+
return yield* new LeftToPerson({
|
|
196
|
+
head,
|
|
197
|
+
why: `A review of ${head} passed, but verify never ran some of its tests`,
|
|
198
|
+
notRun,
|
|
199
|
+
review: yield* stepName('review'),
|
|
200
|
+
...changeKept
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
const recorded = yield* approveChangeRequest('approve', {
|
|
204
|
+
changeRequestId,
|
|
205
|
+
head,
|
|
206
|
+
summary:
|
|
207
|
+
since === undefined
|
|
208
|
+
? `A review of the whole change at ${head} passed with nothing blocking.`
|
|
209
|
+
: `A review of what changed between ${since}, the last approved head, and ${head} passed with nothing blocking.`,
|
|
210
|
+
review: 'review'
|
|
211
|
+
}).pipe(
|
|
212
|
+
Effect.catchTag('StepFailed', error => Effect.succeed({ approved: false as const, reason: error.reason }))
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
if (!recorded.approved) return yield* new ApprovalRefused({ head, reason: recorded.reason, ...changeKept })
|
|
216
|
+
|
|
217
|
+
return new Approved({ head, approval: recorded.reviewId, ...changeKept })
|
|
218
|
+
})
|
|
219
|
+
})
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ChangeRequestResult } from '@kitman-sh/sdk/loop'
|
|
2
|
+
import * as Schema from 'effect/Schema'
|
|
3
|
+
import { ShepherdOutput } from './shepherd-output'
|
|
4
|
+
|
|
5
|
+
export const BackportInput = Schema.Struct({
|
|
6
|
+
mergedChangeRequestId: Schema.String.annotate({
|
|
7
|
+
description: 'The merged ChangeRequest whose change to apply; `kitman run start backport !123` names it.'
|
|
8
|
+
}),
|
|
9
|
+
branch: Schema.String.annotate({
|
|
10
|
+
description: 'The branch to apply it to: the Run starts from it, and its ChangeRequest merges into it.'
|
|
11
|
+
}),
|
|
12
|
+
merge: Schema.optional(Schema.Boolean).annotate({
|
|
13
|
+
description: 'Merges the backport once it is approved, green and mergeable, without asking.'
|
|
14
|
+
}),
|
|
15
|
+
hold: Schema.optional(Schema.Boolean).annotate({
|
|
16
|
+
description:
|
|
17
|
+
'Stops once the backport is level, green and approved, and leaves it for a person to merge, as an automatic Backport does in a Team that asks before merging.'
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export type BackportInput = typeof BackportInput.Type
|
|
22
|
+
|
|
23
|
+
export const BackportOutput = Schema.Struct({
|
|
24
|
+
status: Schema.Literals([
|
|
25
|
+
/** The ChangeRequest is not merged, so it has no change to apply. */
|
|
26
|
+
'not_merged',
|
|
27
|
+
/** A Revert took the change back out of its branch, so it is not applied elsewhere. */
|
|
28
|
+
'reverted',
|
|
29
|
+
/** The branch already has the change: nothing to do. */
|
|
30
|
+
'nothing_to_do',
|
|
31
|
+
/** The change conflicts with the branch in files the agent could not settle; nothing was opened. */
|
|
32
|
+
'conflict',
|
|
33
|
+
/** The backport's ChangeRequest is open, and Shepherd saw it as far as `landed` says. */
|
|
34
|
+
'opened'
|
|
35
|
+
]).annotate({ description: 'not_merged, reverted, nothing_to_do, conflict, or opened the backport ChangeRequest.' }),
|
|
36
|
+
reason: Schema.String.annotate({ description: 'Why it ended as it did, in a line.' }),
|
|
37
|
+
original: Schema.optional(
|
|
38
|
+
Schema.Struct({ reference: Schema.String, url: Schema.String, title: Schema.String })
|
|
39
|
+
).annotate({ description: 'The merged ChangeRequest it backports.' }),
|
|
40
|
+
changeRequest: Schema.optional(ChangeRequestResult).annotate({ description: "The backport's ChangeRequest." }),
|
|
41
|
+
landed: Schema.optional(ShepherdOutput).annotate({
|
|
42
|
+
description: "What Shepherd did with the backport's ChangeRequest."
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
export type BackportOutput = typeof BackportOutput.Type
|
package/src/backport.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyChange,
|
|
3
|
+
call,
|
|
4
|
+
type CalledLoop,
|
|
5
|
+
changeRequest,
|
|
6
|
+
defineLoop,
|
|
7
|
+
mergedChangeRequest,
|
|
8
|
+
runContext,
|
|
9
|
+
testsNotRunReasons,
|
|
10
|
+
verify
|
|
11
|
+
} from '@kitman-sh/sdk/loop'
|
|
12
|
+
import * as Effect from 'effect/Effect'
|
|
13
|
+
import { BackportInput, BackportOutput } from './backport-schemas'
|
|
14
|
+
import { evidenceTable } from './change-request-body'
|
|
15
|
+
import shepherd from './shepherd'
|
|
16
|
+
|
|
17
|
+
type Output = BackportOutput
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Applies a merged ChangeRequest's change to another branch and lands it there. The Run starts from `branch`;
|
|
21
|
+
* `applyChange` cherry-picks the change with no agent unless it conflicts, a branch that has it already ends as nothing
|
|
22
|
+
* to do, and the change is verified, opened as a ChangeRequest into `branch` that names the original, and handed to
|
|
23
|
+
* Shepherd, which reviews and lands it like any other. Kitman links the ChangeRequest to the original's Tasks. Shepherd
|
|
24
|
+
* offers a Backport after each merge for every other live branch of the repository.
|
|
25
|
+
*/
|
|
26
|
+
const backport = defineLoop({
|
|
27
|
+
id: 'backport',
|
|
28
|
+
version: '1.0.0',
|
|
29
|
+
title: 'Backport',
|
|
30
|
+
description: "Applies a merged ChangeRequest's change to another branch and lands it there.",
|
|
31
|
+
input: BackportInput,
|
|
32
|
+
output: BackportOutput,
|
|
33
|
+
agents: { implementer: 'implementer' },
|
|
34
|
+
checkout: 'write',
|
|
35
|
+
capabilities: ['agent_work', 'read_change_request', 'verify', 'change_request', 'call'],
|
|
36
|
+
calls: (): readonly CalledLoop[] => [shepherd],
|
|
37
|
+
run: input =>
|
|
38
|
+
Effect.gen(function* () {
|
|
39
|
+
const original = yield* mergedChangeRequest('original', { changeRequestId: input.mergedChangeRequestId })
|
|
40
|
+
const named = { reference: original.reference, url: original.url, title: original.title }
|
|
41
|
+
|
|
42
|
+
if (original.status !== 'merged')
|
|
43
|
+
return {
|
|
44
|
+
status: 'not_merged',
|
|
45
|
+
reason: `${original.reference} is ${original.status}, so it has no change to backport`,
|
|
46
|
+
original: named
|
|
47
|
+
} satisfies Output
|
|
48
|
+
|
|
49
|
+
if (original.reverted !== undefined)
|
|
50
|
+
return {
|
|
51
|
+
status: 'reverted',
|
|
52
|
+
reason: `${original.reference} was reverted out of ${original.targetBranch} at ${original.reverted.at}, so it is not backported`,
|
|
53
|
+
original: named
|
|
54
|
+
} satisfies Output
|
|
55
|
+
|
|
56
|
+
const applied = yield* applyChange('apply', { agent: 'implementer', changeRequestId: original.id })
|
|
57
|
+
|
|
58
|
+
// A Run continuing its open ChangeRequest checks out that branch, which has the change from an earlier attempt.
|
|
59
|
+
if (applied.status === 'already' && (yield* runContext).continuing === undefined)
|
|
60
|
+
return {
|
|
61
|
+
status: 'nothing_to_do',
|
|
62
|
+
reason: `${input.branch} already has the change of ${original.url}`,
|
|
63
|
+
original: named
|
|
64
|
+
} satisfies Output
|
|
65
|
+
|
|
66
|
+
if (applied.status === 'conflict')
|
|
67
|
+
return {
|
|
68
|
+
status: 'conflict',
|
|
69
|
+
reason: `The change of ${original.url} conflicts with ${input.branch} in ${applied.files.join(', ')}: ${applied.reason}`,
|
|
70
|
+
original: named
|
|
71
|
+
} satisfies Output
|
|
72
|
+
|
|
73
|
+
const head = yield* verify('verify', {})
|
|
74
|
+
|
|
75
|
+
const opened = yield* changeRequest('change-request', {
|
|
76
|
+
title: `${original.title} (backport to ${input.branch})`.slice(0, 240),
|
|
77
|
+
body: [
|
|
78
|
+
`Backports ${original.url}, ${original.title}, merged into \`${original.targetBranch}\`, to \`${input.branch}\`.`,
|
|
79
|
+
applied.status === 'already'
|
|
80
|
+
? 'An earlier attempt on this branch applied it.'
|
|
81
|
+
: applied.settled.length === 0
|
|
82
|
+
? 'It applied cleanly.'
|
|
83
|
+
: `An agent settled its conflicts in ${applied.settled.map(file => `\`${file}\``).join(', ')}.`,
|
|
84
|
+
'## Evidence',
|
|
85
|
+
evidenceTable(head)
|
|
86
|
+
].join('\n\n')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const notRun = testsNotRunReasons(head)
|
|
90
|
+
|
|
91
|
+
const landed = yield* call('shepherd', shepherd, {
|
|
92
|
+
changeRequestId: opened.id,
|
|
93
|
+
branch: input.branch,
|
|
94
|
+
offersBackports: false,
|
|
95
|
+
...(notRun.length === 0 ? undefined : { notRun }),
|
|
96
|
+
...(input.merge === undefined ? undefined : { merge: input.merge }),
|
|
97
|
+
...(input.hold === undefined ? undefined : { hold: input.hold })
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
status: 'opened',
|
|
102
|
+
reason: `${opened.url} backports ${original.url} to ${input.branch}; Shepherd ended ${landed.status}: ${landed.reason}`,
|
|
103
|
+
original: named,
|
|
104
|
+
changeRequest: opened,
|
|
105
|
+
landed
|
|
106
|
+
} satisfies Output
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
export default backport
|