@kitman-sh/software-engineering 0.50.0 → 0.50.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitman-sh/software-engineering",
3
- "version": "0.50.0",
3
+ "version": "0.50.1",
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",
@@ -19,12 +19,12 @@
19
19
  "LICENSE.md"
20
20
  ],
21
21
  "dependencies": {
22
- "@kitman-sh/sdk": "0.50.0",
22
+ "@kitman-sh/sdk": "0.50.1",
23
23
  "effect": "^4.1.2"
24
24
  },
25
25
  "kitman": {
26
26
  "bundle": "dist/bundle.js",
27
- "digest": "6139e1a2da3f82c161d4dc09b9eee20c813edba1939cb05be0ce49602bf26ac9",
27
+ "digest": "5361725f74b96461420e27f93c8765e29fac0e113dd0adb77ae31b93edef7135",
28
28
  "protocolVersion": 5,
29
29
  "declarations": "dist/declarations.json",
30
30
  "setup": {
package/src/build.ts CHANGED
@@ -15,7 +15,7 @@ import * as Schema from 'effect/Schema'
15
15
  import { BuildInput, BuildOutput, type Built, type CriterionAnswer } from './build-schemas'
16
16
  import { brokenChecks, changeRequestBody, codeFindings, unsettledItems } from './change-request-body'
17
17
  import { epicOf, ownDeliveryTarget } from './delivery'
18
- import { implemented, type Implemented } from './implemented'
18
+ import { implemented, proofsOf, type Implemented } from './implemented'
19
19
  import { landed } from './landed'
20
20
  import { opened } from './opened'
21
21
  import { caseOf, inCase, listedCases, outOfScopeLines } from './out-of-scope'
@@ -138,8 +138,8 @@ const gated = ({
138
138
  ...(before._tag === 'NotNeeded' ? undefined : { base: before.base }),
139
139
  ...(last.scope === undefined ? undefined : { review: last.scope }),
140
140
  ...(before._tag === 'Reproduced' ? { reproducing: before.check.name } : undefined),
141
- ...(change.documented === undefined ? undefined : { documented: change.documented }),
142
- ...(change.rollback === undefined ? undefined : { rollback: change.rollback })
141
+ ...(change.documented === undefined ? undefined : { documented: change.documented.map(check => check.name) }),
142
+ ...(change.rollback === undefined ? undefined : { rollback: change.rollback.name })
143
143
  })
144
144
 
145
145
  const stopped = stoppedAs[last._tag]
@@ -260,9 +260,12 @@ const build = defineLoop({
260
260
  outcome,
261
261
  continuing,
262
262
  ...(cases.length === 0 ? undefined : { cases }),
263
+ ...(before._tag === 'Reproduced' ? { reproducing: before.check } : undefined),
263
264
  ...(input.planReviewed === true ? { planReviewed: true } : undefined)
264
265
  })
265
266
 
267
+ const proven = [...(before._tag === 'Reproduced' ? [before.check] : []), ...proofsOf(outcome, change)]
268
+
266
269
  const last = yield* rallied({
267
270
  fixer: 'implementer',
268
271
  maxRounds: input.maxRounds ?? 3,
@@ -270,7 +273,7 @@ const build = defineLoop({
270
273
  outcome,
271
274
  claims: [...change.claims, ...change.criteria.map(answer => `Criterion ${answerLine(answer, cases)}`)],
272
275
  suggested: change.checks ?? [],
273
- extra: before._tag === 'Reproduced' ? [before.check] : undefined,
276
+ extra: proven.length === 0 ? undefined : proven,
274
277
  reviewed: input.reviewed,
275
278
  earlier: input.earlier,
276
279
  deliveredBy: input.changeRequestId,
@@ -1,10 +1,18 @@
1
- import { Continuing, continuingBrief, LoopOutcome, step } from '@kitman-sh/sdk/loop'
1
+ import { Continuing, continuingBrief, LoopOutcome, step, verify, type VerifyResult } from '@kitman-sh/sdk/loop'
2
2
  import * as Effect from 'effect/Effect'
3
3
  import * as Schema from 'effect/Schema'
4
4
  import { implementer, plannedImplementer } from './agents'
5
5
  import { CriterionAnswer, taskOf } from './build-schemas'
6
6
  import { caseOf, numberedCases } from './out-of-scope'
7
- import { SuggestedCheck } from './suggested-check'
7
+ import {
8
+ clashingChecks,
9
+ refusedCheck,
10
+ Renamed,
11
+ renamedChecks,
12
+ renamePrompt,
13
+ SuggestedCheck,
14
+ unstartedRefusal
15
+ } from './suggested-check'
8
16
  import { ChangeRequestSummary, ShortStatement } from './text-limits'
9
17
 
10
18
  const Change = Schema.Struct({
@@ -12,25 +20,30 @@ const Change = Schema.Struct({
12
20
  title: Schema.String,
13
21
  summary: ChangeRequestSummary,
14
22
  claims: Schema.Array(ShortStatement),
15
- /** The approved checks that run the documented commands, for a docs Outcome. */
16
- documented: Schema.optional(Schema.Array(Schema.String)),
17
- /** The approved check that rolls a migration back. */
18
- rollback: Schema.optional(Schema.String),
23
+ /** The checks that run the documented commands, for a docs Outcome; Kitman runs them on every head. */
24
+ documented: Schema.optional(Schema.Array(SuggestedCheck)),
25
+ /** The check that rolls a migration back; Kitman runs it on every head. */
26
+ rollback: Schema.optional(SuggestedCheck),
19
27
  /** Each acceptance criterion of the Task, answered; empty when it has none, left out when building from words. */
20
28
  criteria: Schema.optional(Schema.Array(CriterionAnswer)),
21
29
  /** Checks to run when the repository has none approved, from its package scripts or CI config. */
22
30
  checks: Schema.optional(Schema.Array(SuggestedCheck))
23
31
  })
24
32
 
33
+ type SuggestedCheckType = typeof SuggestedCheck.Type
34
+
25
35
  const Criteria = Schema.Struct({ criteria: Schema.Array(CriterionAnswer) })
26
36
 
37
+ const proofGuidance =
38
+ "Give each the command itself, with a `name` of letters, digits, `.`, `_`, `:` and `-` that no check of the repository has, unless it is exactly an approved check's name, command and directory. Kitman runs them on every head; a narrower command than an approved check is its own check."
39
+
27
40
  const outcomeGuidance = {
28
41
  feature: 'Deliver the whole scope; review checks it was met.',
29
42
  bug: 'Your failing test is already in place: make it pass.',
30
43
  refactor: 'Keep behaviour exactly as it is; the approved verifications must pass before and after.',
31
44
  investigation: 'Investigate and report what you found, with its sources.',
32
- docs: 'Name, in `documented`, the approved checks that run the commands you documented.',
33
- migration: 'Name, in `rollback`, the approved check that rolls the migration back.',
45
+ docs: `Name, in \`documented\`, a check for each command you documented that runs exactly it. ${proofGuidance}`,
46
+ migration: `Name, in \`rollback\`, the check that rolls the migration back. ${proofGuidance}`,
34
47
  performance: 'Make it faster without changing behaviour.'
35
48
  } as const satisfies { readonly [outcome in LoopOutcome]: string }
36
49
 
@@ -82,6 +95,88 @@ const criteriaPrompt = (unanswered: boolean, unmet: readonly CriterionAnswer[],
82
95
  criteriaGuidance
83
96
  ].join('\n\n')
84
97
 
98
+ type ProofLaunch = {
99
+ readonly checks: readonly string[]
100
+ readonly suggested?: readonly SuggestedCheckType[]
101
+ readonly extra: readonly SuggestedCheckType[]
102
+ }
103
+
104
+ type Proofs = Pick<typeof Change.Type, 'documented' | 'rollback'>
105
+
106
+ /** The checks a docs or migration change names to prove it, which Kitman runs on every head. */
107
+ export const proofsOf = (outcome: LoopOutcome | undefined, change: Proofs) => {
108
+ if (outcome === 'docs') return change.documented ?? []
109
+
110
+ return outcome === 'migration' && change.rollback !== undefined ? [change.rollback] : []
111
+ }
112
+
113
+ /**
114
+ * Kitman refuses a check it will not run as soon as the implementer names one, so it can correct it before the review:
115
+ * it runs the proofs at once, and refuses every name it will not take and every command that does not start together.
116
+ */
117
+ const runnableProofs = (
118
+ outcome: LoopOutcome | undefined,
119
+ change: Proofs & Pick<typeof Change.Type, 'checks'>,
120
+ reproducing: SuggestedCheckType | undefined
121
+ ) =>
122
+ Effect.gen(function* () {
123
+ const kept = reproducing === undefined ? [] : [reproducing]
124
+
125
+ const checked = <E, R>(
126
+ {
127
+ checks,
128
+ proofs
129
+ }: { readonly checks: readonly SuggestedCheckType[]; readonly proofs: readonly SuggestedCheckType[] },
130
+ verified: (launch: ProofLaunch) => Effect.Effect<VerifyResult, E, R>
131
+ ) =>
132
+ proofs.length === 0
133
+ ? Effect.suspend(() => {
134
+ const clash = clashingChecks('implemented', [...kept, ...checks])
135
+
136
+ return clash === undefined ? Effect.void : Effect.fail(clash)
137
+ })
138
+ : verified({ checks: [], ...(checks.length === 0 ? undefined : { suggested: checks }), extra: proofs }).pipe(
139
+ Effect.flatMap(result => {
140
+ const refusal = unstartedRefusal('implemented', result, proofs)
141
+
142
+ return refusal === undefined ? Effect.void : Effect.fail(refusal)
143
+ })
144
+ )
145
+
146
+ const named = { checks: change.checks ?? [], proofs: proofsOf(outcome, change) }
147
+
148
+ const { checks, proofs } = yield* checked(named, launch => verify('proofs', launch)).pipe(
149
+ Effect.as(named),
150
+ Effect.catchTag('StepFailed', error =>
151
+ refusedCheck(error)
152
+ ? Effect.gen(function* () {
153
+ const all = [...named.checks, ...named.proofs]
154
+
155
+ const renamed = renamedChecks(
156
+ all,
157
+ yield* implementer('rename', { prompt: renamePrompt(error.reason, all, kept), output: Renamed })
158
+ )
159
+
160
+ const again = {
161
+ checks: renamed.slice(0, named.checks.length),
162
+ proofs: renamed.slice(named.checks.length)
163
+ }
164
+
165
+ yield* checked(again, launch => verify('proofs-renamed', launch))
166
+
167
+ return again
168
+ })
169
+ : Effect.fail(error)
170
+ )
171
+ )
172
+
173
+ return {
174
+ ...(change.checks === undefined ? undefined : { checks }),
175
+ ...(outcome === 'docs' && change.documented !== undefined ? { documented: proofs } : undefined),
176
+ ...(outcome === 'migration' && change.rollback !== undefined ? { rollback: proofs[0] } : undefined)
177
+ }
178
+ })
179
+
85
180
  /** The change is in the workspace, with the Task's acceptance criteria answered; none when it has none. */
86
181
  export class Implemented extends Schema.TaggedClass<Implemented>()('Implemented', {
87
182
  ...Change.fields,
@@ -105,13 +200,16 @@ export const implemented = step('implemented', {
105
200
  cases: Schema.optional(Schema.Array(Schema.String)).annotate({
106
201
  description: "The Task's Out of scope list, which the implementer does not build."
107
202
  }),
203
+ reproducing: Schema.optional(SuggestedCheck).annotate({
204
+ description: "The bug's reproducing check, whose name the implementer's checks may not take for another command."
205
+ }),
108
206
  planReviewed: Schema.optional(Schema.Boolean).annotate({
109
207
  description:
110
208
  'Plan review passed the Task and this is its first implementation: the `planned-implementer` makes it.'
111
209
  })
112
210
  },
113
211
  success: Implemented,
114
- run: ({ words, taskId, outcome, continuing, cases = [], planReviewed }) =>
212
+ run: ({ words, taskId, outcome, continuing, cases = [], reproducing, planReviewed }) =>
115
213
  Effect.gen(function* () {
116
214
  const work = {
117
215
  skill: 'implement',
@@ -131,13 +229,11 @@ export const implemented = step('implemented', {
131
229
  answer => answer.status === 'not_met' && caseOf(cases, answer) === undefined
132
230
  )
133
231
 
134
- if (!unanswered && unmet.length === 0) return new Implemented({ ...change, criteria: change.criteria ?? [] })
135
-
136
- const { criteria } = yield* implementer('criteria', {
137
- prompt: criteriaPrompt(unanswered, unmet, cases),
138
- output: Criteria
139
- })
232
+ const { criteria } =
233
+ !unanswered && unmet.length === 0
234
+ ? { criteria: change.criteria ?? [] }
235
+ : yield* implementer('criteria', { prompt: criteriaPrompt(unanswered, unmet, cases), output: Criteria })
140
236
 
141
- return new Implemented({ ...change, criteria })
237
+ return new Implemented({ ...change, ...(yield* runnableProofs(outcome, change, reproducing)), criteria })
142
238
  })
143
239
  })
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
- const base = yield* verify('verify', { ...(revision === undefined ? undefined : { revision }), extra: [check] })
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
- return new Reproduced({ check, base: withoutOutput(base) })
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
  })
@@ -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: CheckName,
6
- command: Schema.String,
7
- workingDirectory: Schema.optionalKey(Schema.String)
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
+ })