@kitman-sh/software-engineering 0.10.68 → 0.10.69

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 CHANGED
@@ -19067,6 +19067,7 @@ var verify = (name, request) => takeStep(name, "verify", "verify", gen2(function
19067
19067
  ...request.revision === undefined ? undefined : { revision: request.revision },
19068
19068
  ...request.checks === undefined ? undefined : { checks: request.checks },
19069
19069
  ...request.suggested === undefined || request.suggested.length === 0 ? undefined : { suggested: request.suggested },
19070
+ ...request.rerunFailed === true ? { rerunFailed: true } : undefined,
19070
19071
  token: token2
19071
19072
  }));
19072
19073
  return yield* await_2(deferred);
@@ -20249,7 +20250,7 @@ var journaled = (engine, journal, ran) => ({
20249
20250
  })
20250
20251
  });
20251
20252
  var scriptedExit = (scripted, failure) => scripted === undefined ? fail5(failure("nothing was scripted for this Step")) : scripted instanceof ScriptedFailure ? fail5(failure(scripted.reason)) : succeed4(scripted);
20252
- var scriptedHost = (script, engine, agentLaunches, childLaunches, waits) => {
20253
+ var scriptedHost = (script, engine, agentLaunches, childLaunches, waits, verifyLaunches) => {
20253
20254
  const resolve = (deferred, token, exit) => done4(deferred, { token, exit }).pipe(provideService2(WorkflowEngine, engine));
20254
20255
  return {
20255
20256
  startAgentWork: (launch) => andThen2(sync2(() => agentLaunches.push({
@@ -20279,6 +20280,13 @@ var scriptedHost = (script, engine, agentLaunches, childLaunches, waits) => {
20279
20280
  claimResource: (launch) => launch.action === "let_go" ? resolve(letGoDeferred(launch.step), launch.token, succeed4(null)) : resolve(claimDeferred(launch.step), launch.token, succeed4(script.claims?.[launch.step] ?? { status: "granted", resource: launch.resource })),
20280
20281
  startVerification: (launch) => {
20281
20282
  const scripted = script.verifications?.[launch.step];
20283
+ if (launch.measure === undefined)
20284
+ verifyLaunches.push({
20285
+ step: launch.step,
20286
+ ...launch.revision === undefined ? undefined : { revision: launch.revision },
20287
+ ...launch.checks === undefined ? undefined : { checks: launch.checks },
20288
+ ...launch.rerunFailed === undefined ? undefined : { rerunFailed: launch.rerunFailed }
20289
+ });
20282
20290
  if (launch.measure !== undefined) {
20283
20291
  const measured = script.measurements?.[launch.step];
20284
20292
  const flat = Array.from({ length: launch.measure.samples }, () => Object.fromEntries(launch.measure?.plan.metrics.map((metric) => [metric.name, 100]) ?? []));
@@ -20329,6 +20337,7 @@ var testLoop = (loop, script) => {
20329
20337
  const agentLaunches = [];
20330
20338
  const childLaunches = [];
20331
20339
  const waits = [];
20340
+ const verifyLaunches = [];
20332
20341
  let latestSteps = [];
20333
20342
  const declared = capabilitiesOf(loop);
20334
20343
  const granted = new Set((script.grant ?? declared).filter((capability) => declared.includes(capability)));
@@ -20341,7 +20350,7 @@ var testLoop = (loop, script) => {
20341
20350
  const execute = (payload) => gen2(function* () {
20342
20351
  const engine = yield* WorkflowEngine;
20343
20352
  return yield* executeLoop(loop, {
20344
- host: scriptedHost(script, engine, agentLaunches, childLaunches, waits),
20353
+ host: scriptedHost(script, engine, agentLaunches, childLaunches, waits, verifyLaunches),
20345
20354
  activities,
20346
20355
  granted,
20347
20356
  onRun: (run) => {
@@ -20351,7 +20360,7 @@ var testLoop = (loop, script) => {
20351
20360
  });
20352
20361
  return gen2(function* () {
20353
20362
  const result = yield* exit2(workflow.execute({ input: script.input }).pipe(provideService2(ConfigProvider, fromUnknown(script.secrets ?? {}))));
20354
- return { result, steps: latestSteps, journal, activities: ran, agentLaunches, childLaunches, waits };
20363
+ return { result, steps: latestSteps, journal, activities: ran, agentLaunches, childLaunches, waits, verifyLaunches };
20355
20364
  }).pipe(provide4(workflow.toLayer(execute).pipe(provideMerge(layerMemory))));
20356
20365
  };
20357
20366
  // ../../packages/sdk/src/loop/review.ts
@@ -20991,14 +21000,41 @@ var release_default = defineLoop({
20991
21000
  const changeRequestId = input.changeRequestId;
20992
21001
  let gated;
20993
21002
  if (changeRequestId === undefined) {
20994
- const gate = yield* verify("gate", input.revision === undefined ? {} : { revision: input.revision });
21003
+ const gate = yield* verify("gate", {
21004
+ ...input.revision === undefined ? undefined : { revision: input.revision },
21005
+ rerunFailed: true
21006
+ });
20995
21007
  if (!gate.passed) {
20996
- const failing = gate.checks.filter((check) => check.status !== "passed").map((check) => check.name);
20997
- return {
20998
- status: "gate_failed",
20999
- reason: `The checks fail at ${gate.revision}: ${failing.join(", ")}`,
21000
- revision: gate.revision
21001
- };
21008
+ const failed = gate.checks.filter((check) => check.status !== "passed" && !check.preExisting);
21009
+ const retry = yield* verify("gate:retry", {
21010
+ revision: gate.revision,
21011
+ ...failed.length === 0 ? undefined : { checks: failed.map((check) => check.name) },
21012
+ rerunFailed: true
21013
+ });
21014
+ const environmental = failed.filter((check) => retry.checks.some((again) => again.name === check.name && again.status === "passed"));
21015
+ const names = environmental.map((check) => check.name).join(", ");
21016
+ if (environmental.length > 0)
21017
+ yield* artifact("environment-failure", {
21018
+ kind: "gate_environment_failure",
21019
+ title: `${names} failed on the gate's checkout at ${gate.revision}`,
21020
+ text: `These checks failed at ${gate.revision} and passed in a fresh checkout of it, so the first checkout's environment failed them, not the code: ${names}.`,
21021
+ data: {
21022
+ revision: gate.revision,
21023
+ checks: environmental.map((check) => ({
21024
+ name: check.name,
21025
+ failedEvidenceId: check.evidenceId,
21026
+ ...check.outputTail === undefined ? undefined : { outputTail: check.outputTail }
21027
+ }))
21028
+ }
21029
+ });
21030
+ const failing = retry.checks.filter((check) => check.status !== "passed").map((check) => check.name);
21031
+ if (!retry.passed || retry.checks.length === 0 || failing.length > 0) {
21032
+ return {
21033
+ status: "gate_failed",
21034
+ reason: `The checks fail at ${retry.revision}, and again in a fresh checkout: ${(failing.length > 0 ? failing : failed.map((check) => check.name)).join(", ")}`,
21035
+ revision: retry.revision
21036
+ };
21037
+ }
21002
21038
  }
21003
21039
  gated = gate.revision;
21004
21040
  } else {
@@ -21595,7 +21631,26 @@ var shepherd_default = defineLoop({
21595
21631
  if (ship === "Not now")
21596
21632
  return done("merged", `Merged at ${merged.revision}`);
21597
21633
  const released = yield* call("release", release_default, { revision: merged.revision });
21598
- if (released.status !== "deployed" && released.status !== "rejected")
21634
+ const handedOn = released.status === "gate_failed" && (yield* ask("release-gate-failed", {
21635
+ prompt: `Merged at ${merged.revision}, but its Release gate failed: ${released.reason}`,
21636
+ options: [
21637
+ {
21638
+ value: "Next Release",
21639
+ description: "Leaves the revision to the next Release, which gates it with the next merge."
21640
+ },
21641
+ { value: "Taken over", description: "A person looks at the failing checks from here." }
21642
+ ],
21643
+ recommended: "Next Release",
21644
+ recommendationReason: "Nothing was tagged or deployed, and the gate already ran the failure again in a fresh checkout.",
21645
+ default: null,
21646
+ auto: "Next Release"
21647
+ })) === "Next Release";
21648
+ if (handedOn)
21649
+ return {
21650
+ ...done("merged", `Merged at ${merged.revision}; its Release gate failed, so the next Release ships it`),
21651
+ release: { runStatus: released.status, reason: released.reason }
21652
+ };
21653
+ if (released.status !== "deployed" && released.status !== "rejected" && released.status !== "gate_failed")
21599
21654
  yield* ask("release-failed", {
21600
21655
  prompt: `Merged at ${merged.revision}, but its Release ended ${released.status}: ${released.reason}`,
21601
21656
  options: [{ value: "Taken over", description: "A person looks at the release and production from here." }],
@@ -26474,6 +26529,7 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
26474
26529
  revision: optionalKey2(String5),
26475
26530
  checks: optional2(ArraySchema(String5)),
26476
26531
  suggested: optionalKey2(ArraySchema(ApprovedCheck)),
26532
+ rerunFailed: optionalKey2(Boolean3),
26477
26533
  measure: optionalKey2(Struct({
26478
26534
  base: optionalKey2(String5),
26479
26535
  plan: MeasurePlan,
@@ -26965,6 +27021,7 @@ var runnerHost = (capabilities) => ({
26965
27021
  ...launch.revision === undefined ? undefined : { revision: launch.revision },
26966
27022
  ...launch.checks === undefined ? undefined : { checks: launch.checks },
26967
27023
  ...launch.suggested === undefined ? undefined : { suggested: launch.suggested },
27024
+ ...launch.rerunFailed === undefined ? undefined : { rerunFailed: launch.rerunFailed },
26968
27025
  ...launch.measure === undefined ? undefined : { measure: launch.measure }
26969
27026
  })).pipe(asVoid2),
26970
27027
  startAgentWork: (launch) => requested(launch.step, capabilities.startAgentStep({
@@ -27188,6 +27245,7 @@ var rpcProgramPorts = (rpc, work) => {
27188
27245
  ...verification.revision === undefined ? undefined : { revision: verification.revision },
27189
27246
  ...verification.checks === undefined ? undefined : { checks: [...verification.checks] },
27190
27247
  ...verification.suggested === undefined ? undefined : { suggested: [...verification.suggested] },
27248
+ ...verification.rerunFailed === undefined ? undefined : { rerunFailed: verification.rerunFailed },
27191
27249
  ...verification.measure === undefined ? undefined : { measure: verification.measure }
27192
27250
  }),
27193
27251
  startAgentStep: ({ secrets, ...step }) => rpc.startAgentStep({ lease, ...step, ...secrets === undefined ? undefined : { secrets: [...secrets] } }),
@@ -29480,4 +29538,4 @@ var runKit = (config, identity, packages) => {
29480
29538
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
29481
29539
  };
29482
29540
  // .kitman-build-entry.ts
29483
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.68" }, []);
29541
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.69" }, []);
@@ -3187,7 +3187,7 @@
3187
3187
  "carried": [
3188
3188
  {
3189
3189
  "name": "@kitman-sh/software-engineering",
3190
- "version": "0.10.68",
3190
+ "version": "0.10.69",
3191
3191
  "setup": "2a237548a69b0cd53ec3be7f687cfa8c2128335b3a655d34e185f2abce6a3c37",
3192
3192
  "loops": [
3193
3193
  "build",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitman-sh/software-engineering",
3
- "version": "0.10.68",
3
+ "version": "0.10.69",
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": "UNLICENSED",
@@ -17,12 +17,12 @@
17
17
  "tsconfig.json"
18
18
  ],
19
19
  "dependencies": {
20
- "@kitman-sh/sdk": "0.10.68",
20
+ "@kitman-sh/sdk": "0.10.69",
21
21
  "effect": "4.1.2"
22
22
  },
23
23
  "kitman": {
24
24
  "bundle": "dist/bundle.js",
25
- "digest": "083a5bb10db9a060c498a798c31bedd029f001bd27e587a42720f16ca6d4a4fa",
25
+ "digest": "27f761c2d200d215f836134dccfed9a3fa59b9cdd77877079250bd354d2a6f08",
26
26
  "protocolVersion": 5,
27
27
  "declarations": "dist/declarations.json",
28
28
  "setup": {
package/src/release.ts CHANGED
@@ -194,7 +194,8 @@ const recovery = (previous: string | undefined) =>
194
194
 
195
195
  /**
196
196
  * Proves the release before anyone is asked: the approved checks pass on the revision to tag, or a release
197
- * ChangeRequest is green, approved and mergeable. It then asks once, with no default, whether to release the drafted
197
+ * ChangeRequest is green, approved and mergeable. A failed check runs once more in a fresh checkout; one that passes
198
+ * there is recorded as an environment failure. It then asks once, with no default, whether to release the drafted
198
199
  * notes, which can be edited in place. On approval it merges the ChangeRequest when there is one, tags and publishes
199
200
  * once (a tag already released at the same revision counts as done; one at another is never moved), holds the deploy
200
201
  * target so two Releases never deploy over each other, and waits for the deploy. A failed or late deploy asks whether
@@ -225,16 +226,53 @@ export default defineLoop({
225
226
  let gated: string
226
227
 
227
228
  if (changeRequestId === undefined) {
228
- const gate = yield* verify('gate', input.revision === undefined ? {} : { revision: input.revision })
229
+ // A failure an earlier Release recorded at this tree may be its checkout's, so it is run again.
230
+ const gate = yield* verify('gate', {
231
+ ...(input.revision === undefined ? undefined : { revision: input.revision }),
232
+ rerunFailed: true
233
+ })
229
234
 
230
235
  if (!gate.passed) {
231
- const failing = gate.checks.filter(check => check.status !== 'passed').map(check => check.name)
236
+ const failed = gate.checks.filter(check => check.status !== 'passed' && !check.preExisting)
232
237
 
233
- return {
234
- status: 'gate_failed',
235
- reason: `The checks fail at ${gate.revision}: ${failing.join(', ')}`,
236
- revision: gate.revision
237
- } satisfies Output
238
+ // Once more in a fresh checkout of the same commit: a check that passes there failed on its environment.
239
+ const retry = yield* verify('gate:retry', {
240
+ revision: gate.revision,
241
+ ...(failed.length === 0 ? undefined : { checks: failed.map(check => check.name) }),
242
+ rerunFailed: true
243
+ })
244
+
245
+ const environmental = failed.filter(check =>
246
+ retry.checks.some(again => again.name === check.name && again.status === 'passed')
247
+ )
248
+
249
+ const names = environmental.map(check => check.name).join(', ')
250
+
251
+ if (environmental.length > 0)
252
+ yield* artifact('environment-failure', {
253
+ kind: 'gate_environment_failure',
254
+ title: `${names} failed on the gate's checkout at ${gate.revision}`,
255
+ text: `These checks failed at ${gate.revision} and passed in a fresh checkout of it, so the first checkout's environment failed them, not the code: ${names}.`,
256
+ data: {
257
+ revision: gate.revision,
258
+ checks: environmental.map(check => ({
259
+ name: check.name,
260
+ failedEvidenceId: check.evidenceId,
261
+ ...(check.outputTail === undefined ? undefined : { outputTail: check.outputTail })
262
+ }))
263
+ }
264
+ })
265
+
266
+ // A retry passes only when its checks passed: one failing again may read as pre-existing against a moved target.
267
+ const failing = retry.checks.filter(check => check.status !== 'passed').map(check => check.name)
268
+
269
+ if (!retry.passed || retry.checks.length === 0 || failing.length > 0) {
270
+ return {
271
+ status: 'gate_failed',
272
+ reason: `The checks fail at ${retry.revision}, and again in a fresh checkout: ${(failing.length > 0 ? failing : failed.map(check => check.name)).join(', ')}`,
273
+ revision: retry.revision
274
+ } satisfies Output
275
+ }
238
276
  }
239
277
 
240
278
  gated = gate.revision
package/src/shepherd.ts CHANGED
@@ -651,8 +651,34 @@ export default defineLoop({
651
651
 
652
652
  const released = yield* call('release', release, { revision: merged.revision })
653
653
 
654
+ // A failed gate changed nothing in production, and the next merge's Release gates this revision with its own.
655
+ const handedOn =
656
+ released.status === 'gate_failed' &&
657
+ (yield* ask('release-gate-failed', {
658
+ prompt: `Merged at ${merged.revision}, but its Release gate failed: ${released.reason}`,
659
+ options: [
660
+ {
661
+ value: 'Next Release',
662
+ description: 'Leaves the revision to the next Release, which gates it with the next merge.'
663
+ },
664
+ { value: 'Taken over', description: 'A person looks at the failing checks from here.' }
665
+ ],
666
+ recommended: 'Next Release',
667
+ recommendationReason:
668
+ 'Nothing was tagged or deployed, and the gate already ran the failure again in a fresh checkout.',
669
+ // No default: outside full auto a person decides.
670
+ default: null,
671
+ auto: 'Next Release'
672
+ })) === 'Next Release'
673
+
674
+ if (handedOn)
675
+ return {
676
+ ...done('merged', `Merged at ${merged.revision}; its Release gate failed, so the next Release ships it`),
677
+ release: { runStatus: released.status, reason: released.reason }
678
+ }
679
+
654
680
  // It merged either way; a Release that did not deploy, other than one a person rejected, needs a person.
655
- if (released.status !== 'deployed' && released.status !== 'rejected')
681
+ if (released.status !== 'deployed' && released.status !== 'rejected' && released.status !== 'gate_failed')
656
682
  yield* ask('release-failed', {
657
683
  prompt: `Merged at ${merged.revision}, but its Release ended ${released.status}: ${released.reason}`,
658
684
  options: [{ value: 'Taken over', description: 'A person looks at the release and production from here.' }],