@kitman-sh/software-engineering 0.50.0 → 0.51.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/dist/bundle.js +234 -42
- package/dist/declarations.json +2983 -1365
- package/kitman.config.ts +6 -0
- package/package.json +3 -3
- package/src/build-schemas.ts +34 -2
- package/src/build.ts +33 -10
- package/src/errand.ts +9 -1
- package/src/firewatch.ts +25 -6
- package/src/hillclimb.ts +3 -0
- package/src/hindsight.ts +8 -1
- package/src/implemented.ts +112 -16
- package/src/index.ts +11 -4
- package/src/plan.ts +10 -3
- package/src/rallied.ts +13 -2
- package/src/reproduced.ts +28 -3
- package/src/review.ts +19 -7
- package/src/standing.ts +9 -2
- package/src/suggested-check.ts +104 -4
package/src/rallied.ts
CHANGED
|
@@ -221,6 +221,12 @@ export class Reviewed extends Schema.TaggedClass<Reviewed>()('Reviewed', {
|
|
|
221
221
|
review: Schema.String
|
|
222
222
|
}) {}
|
|
223
223
|
|
|
224
|
+
/** The head is the base, so there is no change to review; `reverted` when a fix in a later round returned it there. */
|
|
225
|
+
export class Unchanged extends Schema.TaggedClass<Unchanged>()('Unchanged', {
|
|
226
|
+
head: VerifyResult,
|
|
227
|
+
reverted: Schema.Boolean
|
|
228
|
+
}) {}
|
|
229
|
+
|
|
224
230
|
/** The head's tree and evidence are those of the head `known`, so a review would judge the same change. */
|
|
225
231
|
export class SameEvidence extends Schema.TaggedClass<SameEvidence>()('SameEvidence', headRead) {}
|
|
226
232
|
|
|
@@ -256,7 +262,7 @@ export const reviewed = step('reviewed', {
|
|
|
256
262
|
'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
263
|
})
|
|
258
264
|
},
|
|
259
|
-
success: Schema.Union([Reviewed, SameEvidence]),
|
|
265
|
+
success: Schema.Union([Reviewed, SameEvidence, Unchanged]),
|
|
260
266
|
error: BaseUnpinned,
|
|
261
267
|
run: payload =>
|
|
262
268
|
Effect.gen(function* () {
|
|
@@ -299,6 +305,8 @@ export const reviewed = step('reviewed', {
|
|
|
299
305
|
const head =
|
|
300
306
|
verified ?? (yield* verify('verify', { suggested, ...(extra === undefined ? undefined : { extra }) }))
|
|
301
307
|
|
|
308
|
+
if (head.revision === reviewBase) return new Unchanged({ head, reverted: payload.round > 1 })
|
|
309
|
+
|
|
302
310
|
const found = {
|
|
303
311
|
head,
|
|
304
312
|
...(synced?.status === 'conflict' ? { conflict: { files: synced.files, reason: synced.reason } } : undefined)
|
|
@@ -396,7 +404,7 @@ export const rallied = step('rallied', {
|
|
|
396
404
|
'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
405
|
})
|
|
398
406
|
},
|
|
399
|
-
success: Schema.Union([Settled, DisputeStands, FindingsReturned, RoundCap]),
|
|
407
|
+
success: Schema.Union([Settled, DisputeStands, FindingsReturned, RoundCap, Unchanged]),
|
|
400
408
|
error: Schema.Union([BaseUnpinned, Halted]),
|
|
401
409
|
run: ({ maxRounds, guidance, fixes = 'open', afterFix, ...payload }) =>
|
|
402
410
|
Effect.gen(function* () {
|
|
@@ -429,6 +437,9 @@ export const rallied = step('rallied', {
|
|
|
429
437
|
: undefined
|
|
430
438
|
})
|
|
431
439
|
|
|
440
|
+
if (found._tag === 'Unchanged')
|
|
441
|
+
return new Unchanged({ head: withoutOutput(found.head), reverted: found.reverted })
|
|
442
|
+
|
|
432
443
|
const { head, conflict } = found
|
|
433
444
|
|
|
434
445
|
// A round that merges or finds the branch up to date settles every round before it that could not merge.
|
package/src/reproduced.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as Schema from 'effect/Schema'
|
|
|
4
4
|
import { implementer } from './agents'
|
|
5
5
|
import { taskOf } from './build-schemas'
|
|
6
6
|
import { withoutOutput } from './change-request-body'
|
|
7
|
-
import { SuggestedCheck } from './suggested-check'
|
|
7
|
+
import { refusedCheck, Renamed, renamedChecks, renamePrompt, SuggestedCheck, unstartedRefusal } from './suggested-check'
|
|
8
8
|
import { ChangeRequestSummary } from './text-limits'
|
|
9
9
|
|
|
10
10
|
const ReproducingTest = Schema.Struct({
|
|
@@ -75,8 +75,33 @@ export const reproduced = step('reproduced', {
|
|
|
75
75
|
output: ReproducingTest
|
|
76
76
|
})
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
// A reproducing check that did not start has not shown the bug, so it is refused rather than counted as failing.
|
|
79
|
+
const verifyAt = (name: string, reproducing: typeof SuggestedCheck.Type) =>
|
|
80
|
+
verify(name, { ...(revision === undefined ? undefined : { revision }), extra: [reproducing] }).pipe(
|
|
81
|
+
Effect.flatMap(base => {
|
|
82
|
+
const refusal = unstartedRefusal(name, base, [reproducing])
|
|
79
83
|
|
|
80
|
-
|
|
84
|
+
return refusal === undefined
|
|
85
|
+
? Effect.succeed(new Reproduced({ check: reproducing, base: withoutOutput(base) }))
|
|
86
|
+
: Effect.fail(refusal)
|
|
87
|
+
})
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
return yield* verifyAt('verify', check).pipe(
|
|
91
|
+
Effect.catchTag('StepFailed', error =>
|
|
92
|
+
refusedCheck(error)
|
|
93
|
+
? Effect.gen(function* () {
|
|
94
|
+
const renamed = yield* implementer('rename', {
|
|
95
|
+
prompt: renamePrompt(error.reason, [check]),
|
|
96
|
+
output: Renamed
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const [reproducing = check] = renamedChecks([check], renamed)
|
|
100
|
+
|
|
101
|
+
return yield* verifyAt('verify-renamed', reproducing)
|
|
102
|
+
})
|
|
103
|
+
: Effect.fail(error)
|
|
104
|
+
)
|
|
105
|
+
)
|
|
81
106
|
})
|
|
82
107
|
})
|
package/src/review.ts
CHANGED
|
@@ -30,6 +30,7 @@ import * as Effect from 'effect/Effect'
|
|
|
30
30
|
import * as Schema from 'effect/Schema'
|
|
31
31
|
import * as Struct from 'effect/Struct'
|
|
32
32
|
import build, { BuildInput, BuildOutput } from './build'
|
|
33
|
+
import { isNothingToDo, type NothingToDo } from './build-schemas'
|
|
33
34
|
import { verifyHead } from './change-request-body'
|
|
34
35
|
import { DeliveryFields, ownDeliveryTarget } from './delivery'
|
|
35
36
|
import { caseOf, inCase, listedCases, numberedCases, OutOfScopeFinding, outOfScopeCase } from './out-of-scope'
|
|
@@ -1160,6 +1161,12 @@ const reviewText = (
|
|
|
1160
1161
|
].join('\n\n')
|
|
1161
1162
|
}
|
|
1162
1163
|
|
|
1164
|
+
/** What a person is told of a Build that found nothing to do, naming a ChangeRequest it left open for them to close. */
|
|
1165
|
+
const nothingNeeded = (built: typeof NothingToDo.Type) =>
|
|
1166
|
+
built.changeRequest === undefined
|
|
1167
|
+
? `Nothing needed changing: ${built.summary}`
|
|
1168
|
+
: `Nothing needed changing, so close ${built.changeRequest.url}: ${built.summary}`
|
|
1169
|
+
|
|
1163
1170
|
const fixBrief = (changeRequestId: string, findings: readonly MergedFinding[], unmet: readonly string[]) =>
|
|
1164
1171
|
[
|
|
1165
1172
|
`Fix what a review of ChangeRequest ${changeRequestId} found, on its branch:`,
|
|
@@ -1563,12 +1570,13 @@ export const followedUp = step('followedUp', {
|
|
|
1563
1570
|
...(scope === undefined ? undefined : { scope }),
|
|
1564
1571
|
...ownDeliveryTarget(input)
|
|
1565
1572
|
}).pipe(
|
|
1566
|
-
Effect.map(
|
|
1567
|
-
fixed
|
|
1568
|
-
new
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1573
|
+
Effect.map(fixed =>
|
|
1574
|
+
isNothingToDo(fixed)
|
|
1575
|
+
? new Done({ choice, detail: nothingNeeded(fixed) })
|
|
1576
|
+
: new Fixed({
|
|
1577
|
+
choice,
|
|
1578
|
+
detail: fixed.settled ? 'Fixed and pushed' : `Pushed; left: ${fixed.unsettled.join('; ')}`
|
|
1579
|
+
})
|
|
1572
1580
|
),
|
|
1573
1581
|
Effect.catchTag('ChildFailed', failed => Effect.succeed(new Done({ choice, detail: failed.reason })))
|
|
1574
1582
|
)
|
|
@@ -1578,7 +1586,11 @@ export const followedUp = step('followedUp', {
|
|
|
1578
1586
|
words: fixBrief(changeRequestId, findings, scope?.unmet ?? []),
|
|
1579
1587
|
...ownDeliveryTarget(input)
|
|
1580
1588
|
}).pipe(
|
|
1581
|
-
Effect.map(built =>
|
|
1589
|
+
Effect.map(built =>
|
|
1590
|
+
isNothingToDo(built)
|
|
1591
|
+
? new Done({ choice, detail: nothingNeeded(built) })
|
|
1592
|
+
: new Built({ choice, detail: built.changeRequest.url })
|
|
1593
|
+
),
|
|
1582
1594
|
Effect.catchTag('ChildFailed', failed => Effect.succeed(new Done({ choice, detail: failed.reason })))
|
|
1583
1595
|
)
|
|
1584
1596
|
|
package/src/standing.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as Effect from 'effect/Effect'
|
|
|
3
3
|
import * as Schema from 'effect/Schema'
|
|
4
4
|
import * as SchemaTransformation from 'effect/SchemaTransformation'
|
|
5
5
|
import * as Struct from 'effect/Struct'
|
|
6
|
-
import { BuildInput, BuildOutput, Built } from './build-schemas'
|
|
6
|
+
import { BuildInput, BuildOutput, Built, isNothingToDo, NothingToDo } from './build-schemas'
|
|
7
7
|
import { rebuildRefusal } from './convergence'
|
|
8
8
|
import { ownDeliveryTarget } from './delivery'
|
|
9
9
|
import { OutOfScopeFinding } from './out-of-scope'
|
|
@@ -42,6 +42,11 @@ export class TakenOver extends Schema.TaggedClass<TakenOver>()('TakenOver', {})
|
|
|
42
42
|
/** Another Build ran on the ChangeRequest; `built` is what it made. */
|
|
43
43
|
export class Rebuilt extends Schema.TaggedClass<Rebuilt>()('Rebuilt', { built: Built }) {}
|
|
44
44
|
|
|
45
|
+
/** A rebuild left the branch at its target, so the ChangeRequest has no change left to land; `built` is what it found. */
|
|
46
|
+
export class RebuildUnchanged extends Schema.TaggedClass<RebuildUnchanged>()('RebuildUnchanged', {
|
|
47
|
+
built: NothingToDo
|
|
48
|
+
}) {}
|
|
49
|
+
|
|
45
50
|
/** Build was marked blocked on findings that still stand, so the Task waits on its owner. */
|
|
46
51
|
export class BuildBlocked extends Schema.TaggedError<BuildBlocked>()('BuildBlocked', {
|
|
47
52
|
message: Schema.String
|
|
@@ -78,7 +83,7 @@ export const standing = step('standing', {
|
|
|
78
83
|
Struct.pick(BuildInput.fields, ['words', 'taskId', 'repoBindingId', 'outcome', 'maxRounds', 'deliversTo'])
|
|
79
84
|
).annotate({ description: "The Build's own Input, which a rebuild is given too." })
|
|
80
85
|
},
|
|
81
|
-
success: Schema.Union([TakenOver, Rebuilt]),
|
|
86
|
+
success: Schema.Union([TakenOver, Rebuilt, RebuildUnchanged]),
|
|
82
87
|
error: BuildBlocked,
|
|
83
88
|
run: ({
|
|
84
89
|
changeRequest,
|
|
@@ -160,6 +165,8 @@ export const standing = step('standing', {
|
|
|
160
165
|
{ constraints: unsettled.map(standingConstraint) }
|
|
161
166
|
)
|
|
162
167
|
|
|
168
|
+
if (isNothingToDo(rebuilt)) return new RebuildUnchanged({ built: { ...rebuilt, changeRequest } })
|
|
169
|
+
|
|
163
170
|
return new Rebuilt({ built: Struct.omit(rebuilt, ['changeRequest', 'landed', 'next']) })
|
|
164
171
|
})
|
|
165
172
|
})
|
package/src/suggested-check.ts
CHANGED
|
@@ -1,8 +1,108 @@
|
|
|
1
|
-
import { CheckName } from '@kitman-sh/sdk/loop'
|
|
1
|
+
import { ApprovedCheck, CheckName, StepFailed, type VerifyResult } from '@kitman-sh/sdk/loop'
|
|
2
2
|
import * as Schema from 'effect/Schema'
|
|
3
3
|
|
|
4
|
+
/** A check an agent names, held to what Kitman accepts of a check it runs. */
|
|
4
5
|
export const SuggestedCheck = Schema.Struct({
|
|
5
|
-
name:
|
|
6
|
-
command:
|
|
7
|
-
workingDirectory:
|
|
6
|
+
name: ApprovedCheck.fields.name,
|
|
7
|
+
command: ApprovedCheck.fields.command,
|
|
8
|
+
workingDirectory: ApprovedCheck.fields.workingDirectory
|
|
8
9
|
})
|
|
10
|
+
|
|
11
|
+
type SuggestedCheck = typeof SuggestedCheck.Type
|
|
12
|
+
|
|
13
|
+
// Kitman's refusals of a check an agent named; a refusal for anything else, such as a Run without a repository, renames nothing.
|
|
14
|
+
const checkRefusals = ['Already a check of this repository with another command', 'Two checks named', 'Could not start']
|
|
15
|
+
|
|
16
|
+
/** Kitman refused a check an agent named: for its name, such as an approved check's with another command, or a command that did not start. */
|
|
17
|
+
export const refusedCheck = (error: StepFailed) =>
|
|
18
|
+
error.code === 'step_refused' && checkRefusals.some(refusal => error.reason.startsWith(refusal))
|
|
19
|
+
|
|
20
|
+
const sameCommand = (one: SuggestedCheck, other: SuggestedCheck) =>
|
|
21
|
+
one.command === other.command && one.workingDirectory === other.workingDirectory
|
|
22
|
+
|
|
23
|
+
/** Refuses, as Kitman would, checks an agent named that share a name with different commands. */
|
|
24
|
+
export const clashingChecks = (step: string, checks: readonly SuggestedCheck[]) => {
|
|
25
|
+
const twice = [
|
|
26
|
+
...new Set(
|
|
27
|
+
checks.flatMap((check, index) =>
|
|
28
|
+
checks.slice(0, index).some(other => other.name === check.name && !sameCommand(other, check))
|
|
29
|
+
? [check.name]
|
|
30
|
+
: []
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
return twice.length === 0
|
|
36
|
+
? undefined
|
|
37
|
+
: new StepFailed({
|
|
38
|
+
step,
|
|
39
|
+
code: 'step_refused',
|
|
40
|
+
reason: `Two checks named with different commands: ${twice.join(', ')}; give each check its own name`
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The checks an agent named that could not start on the tree `result` verified. */
|
|
45
|
+
export const unstartedChecks = (result: VerifyResult, named: readonly SuggestedCheck[]) =>
|
|
46
|
+
result.checks.filter(
|
|
47
|
+
check => check.notStarted === true && named.some(one => one.name === check.name && one.command === check.command)
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
/** Kitman refuses checks an agent named that could not start, with what it can run instead. */
|
|
51
|
+
export const unstartedRefusal = (step: string, result: VerifyResult, named: readonly SuggestedCheck[]) => {
|
|
52
|
+
const unstarted = unstartedChecks(result, named)
|
|
53
|
+
|
|
54
|
+
return unstarted.length === 0
|
|
55
|
+
? undefined
|
|
56
|
+
: new StepFailed({
|
|
57
|
+
step,
|
|
58
|
+
code: 'step_refused',
|
|
59
|
+
reason: [
|
|
60
|
+
`Could not start: ${unstarted.map(check => `${check.name}: \`${check.command}\` printed ${JSON.stringify(check.outputTail ?? '')}`).join('; ')}`,
|
|
61
|
+
(result.runnable ?? []).length === 0
|
|
62
|
+
? 'The repository approves no checks'
|
|
63
|
+
: `Its checks are ${(result.runnable ?? []).map(shownCheck).join('; ')}`
|
|
64
|
+
].join('. ')
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const Renamed = Schema.Struct({
|
|
69
|
+
renamed: Schema.Record(Schema.String, CheckName),
|
|
70
|
+
/** A command that starts, for a check that did not, keyed by its number. */
|
|
71
|
+
commands: Schema.optional(
|
|
72
|
+
Schema.Record(
|
|
73
|
+
Schema.String,
|
|
74
|
+
Schema.Struct({
|
|
75
|
+
command: SuggestedCheck.fields.command,
|
|
76
|
+
workingDirectory: SuggestedCheck.fields.workingDirectory
|
|
77
|
+
})
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
const shownCheck = (check: SuggestedCheck) =>
|
|
83
|
+
`${check.name}: \`${check.command}\`${check.workingDirectory === undefined ? '' : ` in ${check.workingDirectory}`}`
|
|
84
|
+
|
|
85
|
+
const numbered = (check: SuggestedCheck, index: number) => `${index + 1}. ${shownCheck(check)}`
|
|
86
|
+
|
|
87
|
+
export const renamePrompt = (reason: string, named: readonly SuggestedCheck[], kept: readonly SuggestedCheck[] = []) =>
|
|
88
|
+
[
|
|
89
|
+
`Kitman will not run the checks you named: ${reason}`,
|
|
90
|
+
['You named:', ...named.map(numbered)].join('\n'),
|
|
91
|
+
...(kept.length === 0
|
|
92
|
+
? []
|
|
93
|
+
: [['These keep their names:', ...kept.map(check => `- ${shownCheck(check)}`)].join('\n')]),
|
|
94
|
+
"Give in `renamed`, keyed by each one's number, a new name of letters, digits, `.`, `_`, `:` and `-` that no other check has, for each you rename. Kitman keeps each command and runs it under its new name, except one that could not start: give it, in `commands` under its number, a command that runs in this repository, or one of its checks exactly with that check's name. Change nothing in the workspace."
|
|
95
|
+
].join('\n\n')
|
|
96
|
+
|
|
97
|
+
/** The checks under the names `renamed` gives them by number, with the commands it gives those that did not start. */
|
|
98
|
+
export const renamedChecks = (named: readonly SuggestedCheck[], renamed: typeof Renamed.Type) =>
|
|
99
|
+
named.map((check, index) => {
|
|
100
|
+
const key = String(index + 1)
|
|
101
|
+
const run = renamed.commands?.[key] ?? check
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
name: renamed.renamed[key] ?? check.name,
|
|
105
|
+
command: run.command,
|
|
106
|
+
...(run.workingDirectory === undefined ? undefined : { workingDirectory: run.workingDirectory })
|
|
107
|
+
}
|
|
108
|
+
})
|