@kitman-sh/software-engineering 0.11.0-rc.3 → 0.11.0-rc.5

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
@@ -19856,7 +19856,8 @@ var claim = (name, request) => gen2(function* () {
19856
19856
  return first;
19857
19857
  const { holder } = first;
19858
19858
  const fallback = holder.sameLoop ? takeOver : "Leave it";
19859
- const answer = (yield* LoopRun).granted.has("ask") ? yield* ask(`${name}-offer`, {
19859
+ const askFirst = !(holder.sameLoop && request.takeOverOwnLoop === true);
19860
+ const answer = askFirst && (yield* LoopRun).granted.has("ask") ? yield* ask(`${name}-offer`, {
19860
19861
  prompt: `${request.resource} is still held by ${holderName(holder)}${holder.status === undefined ? "" : `, which ${holder.status}`}${holder.reason === undefined ? "" : `: ${holder.reason}`}. Take it over?`,
19861
19862
  options: [takeOver, "Leave it"],
19862
19863
  recommended: fallback,
@@ -21230,6 +21231,10 @@ var Drafted = Struct({
21230
21231
  notes: String5,
21231
21232
  changeRequests: ArraySchema(String5)
21232
21233
  });
21234
+ var Picked = Struct({
21235
+ ...Drafted.fields,
21236
+ releasedIn: optional2(String5)
21237
+ });
21233
21238
  var Deployed = Struct({
21234
21239
  status: Literals(["deployed", "failed", "rolled_back", "rollback_failed", "none"]),
21235
21240
  detail: FindingDetail
@@ -21254,7 +21259,8 @@ var Output2 = Struct({
21254
21259
  "rollback_failed",
21255
21260
  "timed_out",
21256
21261
  "not_due",
21257
- "no_version"
21262
+ "no_version",
21263
+ "nothing_to_release"
21258
21264
  ]),
21259
21265
  reason: String5,
21260
21266
  tag: optional2(String5),
@@ -21299,6 +21305,19 @@ var redraftPrompt = (drafted, edit) => [
21299
21305
  ].join(`
21300
21306
 
21301
21307
  `);
21308
+ var pickPrompt = (drafted, revision, givenTag) => {
21309
+ const ownTag = givenTag ?? drafted.tag;
21310
+ return [
21311
+ "This Release now holds the deploy target, so no other Release tags until it settles. Another Release may have tagged since these notes were drafted: pick their version again.",
21312
+ `Fetch the tags (\`git fetch origin --tags\`) and list the release tags that contain ${revision} (\`git tag --contains ${revision}\`). ${ownTag} at ${revision} itself, as \`git rev-list -n 1 ${ownTag}\` tells, is this Release tagged on an earlier attempt: ignore it. Any other, ${ownTag} at another commit included, means ${revision} is released already: give that tag as releasedIn and the draft unchanged.`,
21313
+ givenTag === undefined ? `Otherwise, when ${drafted.tag} is still free and the latest release tag is still ${drafted.previousTag ?? "none"}, give the draft unchanged. When not, give the next version tag after the latest release tag, that latest tag as previousTag, and drop from the notes and changeRequests what it already released.` : `Otherwise give the draft unchanged. The release is tagged ${givenTag}.`,
21314
+ "```json",
21315
+ JSON.stringify(drafted, null, 2),
21316
+ "```"
21317
+ ].join(`
21318
+
21319
+ `);
21320
+ };
21302
21321
  var readyToMerge = (changeRequestId, round = 1) => gen2(function* () {
21303
21322
  for (let pass = 1;; pass++) {
21304
21323
  const at = (name) => {
@@ -21358,7 +21377,7 @@ var readyToMerge = (changeRequestId, round = 1) => gen2(function* () {
21358
21377
  var recovery = (previous) => previous === undefined ? ["Retry the deploy", "Leave it"] : ["Retry the deploy", `Roll back to ${previous}`, "Leave it"];
21359
21378
  var release_default = defineLoop({
21360
21379
  id: "release",
21361
- version: "2.1.0",
21380
+ version: "2.2.0",
21362
21381
  title: "Release",
21363
21382
  input: Input2,
21364
21383
  output: Output2,
@@ -21448,7 +21467,7 @@ var release_default = defineLoop({
21448
21467
  prompt: draftPrompt(input.tag, changeRequestId, input.releaseScope),
21449
21468
  output: Drafted
21450
21469
  });
21451
- const tag = input.tag ?? drafted.tag;
21470
+ let tag = input.tag ?? drafted.tag;
21452
21471
  for (let round = 1;; round++) {
21453
21472
  const answer = yield* ask(round === 1 ? "approve" : `approve:${round}`, {
21454
21473
  prompt: `Release ${tag} with these notes?
@@ -21503,7 +21522,7 @@ ${drafted.notes}`,
21503
21522
  output: Drafted
21504
21523
  });
21505
21524
  }
21506
- const notes = yield* artifact("notes", {
21525
+ let notes = yield* artifact("notes", {
21507
21526
  kind: "release_notes",
21508
21527
  title: drafted.title,
21509
21528
  text: drafted.notes,
@@ -21545,7 +21564,35 @@ ${drafted.notes}`,
21545
21564
  }
21546
21565
  }
21547
21566
  const deployEvent = input.deployEvent ?? "deploy";
21548
- yield* claim("deploy-target", { resource: `deploy:${input.deployTarget ?? deployEvent}` });
21567
+ yield* claim("deploy-target", { resource: `deploy:${input.deployTarget ?? deployEvent}`, takeOverOwnLoop: true });
21568
+ const { releasedIn, ...picked } = yield* agentWork("pick-version", {
21569
+ agent: "releaser",
21570
+ prompt: pickPrompt({ ...drafted, tag }, revision, input.tag),
21571
+ output: Picked
21572
+ });
21573
+ if (releasedIn !== undefined)
21574
+ return {
21575
+ status: "nothing_to_release",
21576
+ reason: `${revision} is already released in ${releasedIn}`,
21577
+ tag: releasedIn,
21578
+ notesArtifactId: notes.artifactId,
21579
+ revision
21580
+ };
21581
+ const pickedTag = input.tag ?? picked.tag;
21582
+ if (pickedTag !== tag || picked.notes !== drafted.notes || picked.title !== drafted.title) {
21583
+ notes = yield* artifact("notes:picked", {
21584
+ kind: "release_notes",
21585
+ title: picked.title,
21586
+ text: picked.notes,
21587
+ data: {
21588
+ tag: pickedTag,
21589
+ changeRequests: picked.changeRequests,
21590
+ ...input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) }
21591
+ }
21592
+ });
21593
+ }
21594
+ drafted = picked;
21595
+ tag = pickedTag;
21549
21596
  const released = yield* release2("tag", {
21550
21597
  tag,
21551
21598
  revision,
@@ -22416,7 +22463,7 @@ Merge now?`,
22416
22463
  ...done("merged", `Merged at ${merged.revision}; its Release gate failed, so the next Release ships it`),
22417
22464
  release: { runStatus: released.status, reason: released.reason }
22418
22465
  };
22419
- if (released.status !== "deployed" && released.status !== "rejected" && released.status !== "gate_failed" && released.status !== "not_due")
22466
+ if (released.status !== "deployed" && released.status !== "rejected" && released.status !== "gate_failed" && released.status !== "not_due" && released.status !== "nothing_to_release")
22420
22467
  yield* ask("release-failed", {
22421
22468
  prompt: `Merged at ${merged.revision}, but its Release ended ${released.status}: ${released.reason}`,
22422
22469
  options: [{ value: "Taken over", description: "A person looks at the release and production from here." }],
@@ -30558,4 +30605,4 @@ var runKit = (config, identity, packages) => {
30558
30605
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
30559
30606
  };
30560
30607
  // .kitman-build-entry.ts
30561
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.11.0-rc.3" }, []);
30608
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.11.0-rc.5" }, []);
@@ -1629,7 +1629,7 @@
1629
1629
  {
1630
1630
  "id": "release",
1631
1631
  "title": "Release",
1632
- "version": "2.1.0",
1632
+ "version": "2.2.0",
1633
1633
  "input": {
1634
1634
  "type": "object",
1635
1635
  "properties": {
@@ -1833,7 +1833,8 @@
1833
1833
  "rollback_failed",
1834
1834
  "timed_out",
1835
1835
  "not_due",
1836
- "no_version"
1836
+ "no_version",
1837
+ "nothing_to_release"
1837
1838
  ]
1838
1839
  },
1839
1840
  "reason": {
@@ -3847,7 +3848,7 @@
3847
3848
  "carried": [
3848
3849
  {
3849
3850
  "name": "@kitman-sh/software-engineering",
3850
- "version": "0.11.0-rc.3",
3851
+ "version": "0.11.0-rc.5",
3851
3852
  "setup": "2a237548a69b0cd53ec3be7f687cfa8c2128335b3a655d34e185f2abce6a3c37",
3852
3853
  "loops": [
3853
3854
  "build",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitman-sh/software-engineering",
3
- "version": "0.11.0-rc.3",
3
+ "version": "0.11.0-rc.5",
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.11.0-rc.3",
20
+ "@kitman-sh/sdk": "0.11.0-rc.5",
21
21
  "effect": "^4.1.2"
22
22
  },
23
23
  "kitman": {
24
24
  "bundle": "dist/bundle.js",
25
- "digest": "a6b98a1b3ddd4933798238c32adeb66b6a8f09babf8945724220b5efa76fd4e6",
25
+ "digest": "e7d8cf7cb3e1f0c89d840c9b52ca421f05050cf3a2e45a1ed5a5a1374b1df829",
26
26
  "protocolVersion": 5,
27
27
  "declarations": "dist/declarations.json",
28
28
  "setup": {
package/src/release.ts CHANGED
@@ -57,6 +57,13 @@ const Drafted = Schema.Struct({
57
57
 
58
58
  type Drafted = typeof Drafted.Type
59
59
 
60
+ /** The draft, its version picked again once the Release holds the deploy target. */
61
+ const Picked = Schema.Struct({
62
+ ...Drafted.fields,
63
+ /** A release tag that already contains the revision and is not this Release's own tag at it, which leaves nothing to release. */
64
+ releasedIn: Schema.optional(Schema.String)
65
+ })
66
+
60
67
  /** What the repository's own deploy script did, as the releaser read it from its last line and exit code. */
61
68
  const Deployed = Schema.Struct({
62
69
  /** none: the repository has no `.kitman/deploy`, so the deploy is left to whatever sends the deploy Event. */
@@ -87,7 +94,9 @@ const Output = Schema.Struct({
87
94
  /** Its trigger is a Milestone or Project being done, and this Run was not started by one nor told to release now. */
88
95
  'not_due',
89
96
  /** A Milestone or Project started it without the version to cut, which a Release never picks for itself. */
90
- 'no_version'
97
+ 'no_version',
98
+ /** An existing tag already contains the revision, as when another Release tagged it first. */
99
+ 'nothing_to_release'
91
100
  ]),
92
101
  /** Why it stopped, or what happened, in a line. */
93
102
  reason: Schema.String,
@@ -151,6 +160,21 @@ const redraftPrompt = (drafted: Drafted, edit: string) =>
151
160
  '```'
152
161
  ].join('\n\n')
153
162
 
163
+ const pickPrompt = (drafted: Drafted, revision: string, givenTag: string | undefined) => {
164
+ const ownTag = givenTag ?? drafted.tag
165
+
166
+ return [
167
+ 'This Release now holds the deploy target, so no other Release tags until it settles. Another Release may have tagged since these notes were drafted: pick their version again.',
168
+ `Fetch the tags (\`git fetch origin --tags\`) and list the release tags that contain ${revision} (\`git tag --contains ${revision}\`). ${ownTag} at ${revision} itself, as \`git rev-list -n 1 ${ownTag}\` tells, is this Release tagged on an earlier attempt: ignore it. Any other, ${ownTag} at another commit included, means ${revision} is released already: give that tag as releasedIn and the draft unchanged.`,
169
+ givenTag === undefined
170
+ ? `Otherwise, when ${drafted.tag} is still free and the latest release tag is still ${drafted.previousTag ?? 'none'}, give the draft unchanged. When not, give the next version tag after the latest release tag, that latest tag as previousTag, and drop from the notes and changeRequests what it already released.`
171
+ : `Otherwise give the draft unchanged. The release is tagged ${givenTag}.`,
172
+ '```json',
173
+ JSON.stringify(drafted, null, 2),
174
+ '```'
175
+ ].join('\n\n')
176
+ }
177
+
154
178
  const approval = ['Approve', 'Edit notes', 'Reject'] as const
155
179
 
156
180
  /**
@@ -246,9 +270,11 @@ const recovery = (previous: string | undefined) =>
246
270
  * Proves the release before anyone is asked: the approved checks pass on the revision to tag, or a release
247
271
  * ChangeRequest is green, approved and mergeable. A failed check runs once more in a fresh checkout; one that passes
248
272
  * there is recorded as an environment failure. It then asks once, with no default, whether to release the drafted
249
- * notes, which can be edited in place. On approval it merges the ChangeRequest when there is one, tags and publishes
250
- * once (a tag already released at the same revision counts as done; one at another is never moved), holds the deploy
251
- * target so two Releases never deploy over each other, and waits for the deploy. A failed or late deploy asks whether
273
+ * notes, which can be edited in place. On approval it merges the ChangeRequest when there is one, holds the deploy
274
+ * target so two Releases never tag or deploy over each other, taking it over from a Release that failed holding it,
275
+ * and picks the version again under it: a revision an existing tag already contains ends as nothing to release. It
276
+ * then tags and publishes once (a tag already released at the same revision counts as done; one at another is never
277
+ * moved) and waits for the deploy. A failed or late deploy asks whether
252
278
  * to retry (it runs the tag's failed pipeline again and waits), roll back to the previous tag (it runs that
253
279
  * tag's pipeline again in full and waits for its deploy), or leave it, which it does by default.
254
280
  *
@@ -258,7 +284,7 @@ const recovery = (previous: string | undefined) =>
258
284
  */
259
285
  export default defineLoop({
260
286
  id: 'release',
261
- version: '2.1.0',
287
+ version: '2.2.0',
262
288
  title: 'Release',
263
289
  input: Input,
264
290
  output: Output,
@@ -372,7 +398,7 @@ export default defineLoop({
372
398
  output: Drafted
373
399
  })
374
400
 
375
- const tag = input.tag ?? drafted.tag
401
+ let tag = input.tag ?? drafted.tag
376
402
 
377
403
  // The question has no default: a release goes out only when someone says so.
378
404
  for (let round = 1; ; round++) {
@@ -435,7 +461,7 @@ export default defineLoop({
435
461
  })
436
462
  }
437
463
 
438
- const notes = yield* artifact('notes', {
464
+ let notes = yield* artifact('notes', {
439
465
  kind: 'release_notes',
440
466
  title: drafted.title,
441
467
  text: drafted.notes,
@@ -486,8 +512,42 @@ export default defineLoop({
486
512
 
487
513
  const deployEvent = input.deployEvent ?? 'deploy'
488
514
 
489
- // Held until the Run completes, so the next Release deploys after this one is settled.
490
- yield* claim('deploy-target', { resource: `deploy:${input.deployTarget ?? deployEvent}` })
515
+ // Held until the Run completes, so the next Release deploys after this one is settled. One a failed Release kept
516
+ // is taken over, since a Release always deploys what is newest.
517
+ yield* claim('deploy-target', { resource: `deploy:${input.deployTarget ?? deployEvent}`, takeOverOwnLoop: true })
518
+
519
+ const { releasedIn, ...picked } = yield* agentWork('pick-version', {
520
+ agent: 'releaser',
521
+ prompt: pickPrompt({ ...drafted, tag }, revision, input.tag),
522
+ output: Picked
523
+ })
524
+
525
+ if (releasedIn !== undefined)
526
+ return {
527
+ status: 'nothing_to_release',
528
+ reason: `${revision} is already released in ${releasedIn}`,
529
+ tag: releasedIn,
530
+ notesArtifactId: notes.artifactId,
531
+ revision
532
+ } satisfies Output
533
+
534
+ const pickedTag = input.tag ?? picked.tag
535
+
536
+ if (pickedTag !== tag || picked.notes !== drafted.notes || picked.title !== drafted.title) {
537
+ notes = yield* artifact('notes:picked', {
538
+ kind: 'release_notes',
539
+ title: picked.title,
540
+ text: picked.notes,
541
+ data: {
542
+ tag: pickedTag,
543
+ changeRequests: picked.changeRequests,
544
+ ...(input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) })
545
+ }
546
+ })
547
+ }
548
+
549
+ drafted = picked
550
+ tag = pickedTag
491
551
 
492
552
  const released = yield* release('tag', {
493
553
  tag,
package/src/shepherd.ts CHANGED
@@ -1316,12 +1316,13 @@ export default defineLoop({
1316
1316
  release: { runStatus: released.status, reason: released.reason }
1317
1317
  }
1318
1318
 
1319
- // It merged either way; a Release that did not deploy, other than one a person rejected, needs a person.
1319
+ // It merged either way; a Release that did not deploy, other than one a person rejected or one that found it released, needs a person.
1320
1320
  if (
1321
1321
  released.status !== 'deployed' &&
1322
1322
  released.status !== 'rejected' &&
1323
1323
  released.status !== 'gate_failed' &&
1324
- released.status !== 'not_due'
1324
+ released.status !== 'not_due' &&
1325
+ released.status !== 'nothing_to_release'
1325
1326
  )
1326
1327
  yield* ask('release-failed', {
1327
1328
  prompt: `Merged at ${merged.revision}, but its Release ended ${released.status}: ${released.reason}`,