@intentius/chant 0.124.58 → 0.124.59

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.
Files changed (70) hide show
  1. package/dist/ci-product.d.ts.map +1 -1
  2. package/dist/ci-product.js +1 -2
  3. package/dist/cli/handlers/lifecycle-drift.d.ts +2 -1
  4. package/dist/cli/handlers/lifecycle-drift.d.ts.map +1 -1
  5. package/dist/cli/handlers/lifecycle-drift.js +4 -2
  6. package/dist/cli/handlers/lock.d.ts.map +1 -1
  7. package/dist/cli/handlers/lock.js +45 -2
  8. package/dist/cli/main.d.ts.map +1 -1
  9. package/dist/cli/main.js +5 -1
  10. package/dist/cli/mcp/product-tools.d.ts.map +1 -1
  11. package/dist/cli/mcp/product-tools.js +1 -2
  12. package/dist/cli/parse-args.d.ts.map +1 -1
  13. package/dist/cli/parse-args.js +18 -0
  14. package/dist/cli/registry.d.ts +6 -0
  15. package/dist/cli/registry.d.ts.map +1 -1
  16. package/dist/drift-record.d.ts +5 -0
  17. package/dist/drift-record.d.ts.map +1 -1
  18. package/dist/e2e-harness/index.d.ts.map +1 -1
  19. package/dist/e2e-harness/index.js +1 -2
  20. package/dist/lifecycle/lock-beat.d.ts +27 -0
  21. package/dist/lifecycle/lock-beat.d.ts.map +1 -0
  22. package/dist/lifecycle/lock-beat.js +84 -0
  23. package/dist/lifecycle/resource-lock.d.ts +54 -1
  24. package/dist/lifecycle/resource-lock.d.ts.map +1 -1
  25. package/dist/lifecycle/resource-lock.js +128 -7
  26. package/dist/op/activities/activity-contracts.d.ts +4 -4
  27. package/dist/op/index.d.ts +1 -1
  28. package/dist/op/index.d.ts.map +1 -1
  29. package/dist/op/index.js +1 -1
  30. package/dist/op/op-waves-notify.d.ts.map +1 -1
  31. package/dist/op/op-waves-notify.js +11 -0
  32. package/dist/op/op-waves-run.d.ts +28 -1
  33. package/dist/op/op-waves-run.d.ts.map +1 -1
  34. package/dist/op/op-waves-run.js +92 -7
  35. package/dist/op/op-waves.d.ts +12 -1
  36. package/dist/op/op-waves.d.ts.map +1 -1
  37. package/dist/op/op-waves.js +9 -2
  38. package/dist/release-floors.d.ts +1 -1
  39. package/dist/release-floors.js +1 -1
  40. package/dist/template-request/template-request.d.ts.map +1 -1
  41. package/dist/template-request/template-request.js +1 -2
  42. package/dist/wave-runtime.mjs +298 -298
  43. package/dist/workspace/drift-cli.d.ts +13 -1
  44. package/dist/workspace/drift-cli.d.ts.map +1 -1
  45. package/dist/workspace/drift-cli.js +19 -3
  46. package/package.json +1 -1
  47. package/src/ci-product.ts +1 -2
  48. package/src/cli/handlers/lifecycle-drift.test.ts +52 -0
  49. package/src/cli/handlers/lifecycle-drift.ts +4 -2
  50. package/src/cli/handlers/lock.ts +41 -2
  51. package/src/cli/main.ts +5 -1
  52. package/src/cli/mcp/product-tools.test.ts +1 -2
  53. package/src/cli/mcp/product-tools.ts +1 -2
  54. package/src/cli/parse-args.ts +12 -0
  55. package/src/cli/registry.ts +6 -0
  56. package/src/drift-record.ts +5 -0
  57. package/src/e2e-harness/index.ts +1 -2
  58. package/src/lifecycle/lock-beat.ts +99 -0
  59. package/src/lifecycle/resource-lock-liveness.test.ts +289 -0
  60. package/src/lifecycle/resource-lock.ts +143 -8
  61. package/src/op/index.ts +1 -0
  62. package/src/op/op-waves-notify.ts +11 -0
  63. package/src/op/op-waves-preview.test.ts +167 -0
  64. package/src/op/op-waves-run.ts +116 -8
  65. package/src/op/op-waves.ts +20 -3
  66. package/src/release-floors.ts +1 -1
  67. package/src/template-request/template-request.test.ts +1 -2
  68. package/src/template-request/template-request.ts +1 -2
  69. package/src/workspace/drift-cli.test.ts +35 -1
  70. package/src/workspace/drift-cli.ts +21 -3
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * `chant workspace drift [dir] --member <name> [--read <read>] [--resource
3
- * <addr>] [--env <env>] [--stream] [-o <file>]` (behold#995): one member's
3
+ * <addr>] [--stack <name>] [--env <env>] [--stream] [-o <file>]` (behold#995): one member's
4
4
  * drift, read by the engine that owns it, as chant's drift record
5
5
  * (`../drift-record.ts`, #4451).
6
6
  *
@@ -13,6 +13,14 @@
13
13
  * | `choudoufu` | `ownership` | the same, through `choudoufu live-plan -json` (and `live-ls`), or `--read plan` for live-plan with a plan beside it; `--resource <addr>` passes `choudoufu live-plan -resource=<addr>`'s stream through |
14
14
  * | `pulumi` | `refresh` | `chant lifecycle drift` in the member's reader project: the pulumi lexicon's `readDrift`, `pulumi refresh --preview-only --json --target <urn>` per resource in the checked-in export, or `plunge drift --resource <urn> --stream` for a member on plunge; `--resource <urn>` reads that URN alone (#4455) |
15
15
  *
16
+ * `--stack <name>` reads that stack's export for a `pulumi` member, from the
17
+ * index store (`refs/chant/snapshots`), where a member of several stacks
18
+ * holds one export each. Without it the member reads the export its store
19
+ * holds, which is the right one only for a member of one stack. A store with
20
+ * no export for the stack answers `no-drift-read`, naming the stack; it never
21
+ * falls back to another stack's export or the checked-in file. Any other kind
22
+ * answers `read-unsupported`.
23
+ *
16
24
  * Any other kind has no drift read and answers `no-drift-read`. A member of
17
25
  * a package's kind runs in the reader project `workspace graph` writes for it
18
26
  * (`./kind-readers.ts`), under the member's own toolchain, so chant core
@@ -43,6 +51,8 @@ export type DriftErrorCode = (typeof DRIFT_ERROR_CODES)[number];
43
51
  export declare const DRIFT_READS_BY_KIND: Record<string, readonly DriftRead[]>;
44
52
  /** The kinds whose engine reads one resource on its own, for `--resource`. */
45
53
  export declare const DRIFT_RESOURCE_KINDS: readonly string[];
54
+ /** The kinds whose engine keeps one export per stack, for `--stack`. */
55
+ export declare const DRIFT_STACK_KINDS: readonly string[];
46
56
  /** The document `workspace drift` prints: a drift document with the read contract's head. */
47
57
  export type WorkspaceDriftDocument = DriftDocument & {
48
58
  contract: number;
@@ -59,6 +69,8 @@ export interface DriftQuery {
59
69
  member: string;
60
70
  read?: string;
61
71
  resource?: string;
72
+ /** The stack whose stored export is read (`--stack`), for a pulumi member. */
73
+ stack?: string;
62
74
  env?: string;
63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nD,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,uBAAuB;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,cAAc,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACnD,CAAC;AAEF,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,MAAM,eAAe,GAAG;IAAE,KAAK,EAAE,SAAS,EAAE,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE;QAAE,IAAI,EAAE,cAAc,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAqG5G;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,eAAe,CAAC,CAoFpF;AAED,sFAAsF;AACtF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,sBAAsB,CAQjG;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAuC5E"}
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * `chant workspace drift [dir] --member <name> [--read <read>] [--resource
3
- * <addr>] [--env <env>] [--stream] [-o <file>]` (behold#995): one member's
3
+ * <addr>] [--stack <name>] [--env <env>] [--stream] [-o <file>]` (behold#995): one member's
4
4
  * drift, read by the engine that owns it, as chant's drift record
5
5
  * (`../drift-record.ts`, #4451).
6
6
  *
@@ -13,6 +13,14 @@
13
13
  * | `choudoufu` | `ownership` | the same, through `choudoufu live-plan -json` (and `live-ls`), or `--read plan` for live-plan with a plan beside it; `--resource <addr>` passes `choudoufu live-plan -resource=<addr>`'s stream through |
14
14
  * | `pulumi` | `refresh` | `chant lifecycle drift` in the member's reader project: the pulumi lexicon's `readDrift`, `pulumi refresh --preview-only --json --target <urn>` per resource in the checked-in export, or `plunge drift --resource <urn> --stream` for a member on plunge; `--resource <urn>` reads that URN alone (#4455) |
15
15
  *
16
+ * `--stack <name>` reads that stack's export for a `pulumi` member, from the
17
+ * index store (`refs/chant/snapshots`), where a member of several stacks
18
+ * holds one export each. Without it the member reads the export its store
19
+ * holds, which is the right one only for a member of one stack. A store with
20
+ * no export for the stack answers `no-drift-read`, naming the stack; it never
21
+ * falls back to another stack's export or the checked-in file. Any other kind
22
+ * answers `read-unsupported`.
23
+ *
16
24
  * Any other kind has no drift read and answers `no-drift-read`. A member of
17
25
  * a package's kind runs in the reader project `workspace graph` writes for it
18
26
  * (`./kind-readers.ts`), under the member's own toolchain, so chant core
@@ -76,7 +84,9 @@ export const DRIFT_RESOURCE_KINDS = ["choudoufu", "pulumi"];
76
84
  * the read was refused.
77
85
  */
78
86
  const MEMBER_REFUSED_EXITS = [1, 3];
79
- const USAGE = "chant workspace drift [dir] --member <name> [--read <state|plan|refresh|live-read|ownership>] [--resource <addr>] [--env <env>] [--components] [--stream] [-o <file>]";
87
+ const USAGE = "chant workspace drift [dir] --member <name> [--read <state|plan|refresh|live-read|ownership>] [--resource <addr>] [--stack <name>] [--env <env>] [--components] [--stream] [-o <file>]";
88
+ /** The kinds whose engine keeps one export per stack, for `--stack`. */
89
+ export const DRIFT_STACK_KINDS = ["pulumi"];
80
90
  class DriftReadFailure extends Error {
81
91
  constructor(code, message) {
82
92
  super(message);
@@ -171,7 +181,7 @@ function chantRecords(member, diffOut, componentsOut, observedAt, version) {
171
181
  function memberArgv(kind, query, read) {
172
182
  if (kind === "chant")
173
183
  return ["lifecycle", "diff", query.env, "--live", "--json"];
174
- return ["lifecycle", "drift", ".", "--member", query.member, "--read", read, ...(query.resource !== undefined ? ["--resource", query.resource] : [])];
184
+ return ["lifecycle", "drift", ".", "--member", query.member, "--read", read, ...(query.resource !== undefined ? ["--resource", query.resource] : []), ...(query.stack !== undefined ? ["--stack", query.stack] : [])];
175
185
  }
176
186
  /**
177
187
  * Read one member's drift and return the stream lines, placed on its graph.
@@ -198,6 +208,11 @@ export async function readWorkspaceDrift(query) {
198
208
  if (query.resource !== undefined && !DRIFT_RESOURCE_KINDS.includes(entry.kind)) {
199
209
  throw new DriftReadFailure("resource-unsupported", `--resource reads one resource through choudoufu live-plan -resource, pulumi refresh --target or plunge drift --resource; ${query.member} is kind ${entry.kind}`);
200
210
  }
211
+ if (query.stack !== undefined && !DRIFT_STACK_KINDS.includes(entry.kind)) {
212
+ throw new DriftReadFailure("read-unsupported", `--stack reads a stack's export from the index store, which a ${DRIFT_STACK_KINDS.join(" or ")} member has; ${query.member} is kind ${entry.kind}`);
213
+ }
214
+ if (query.stack !== undefined && query.stack.trim() === "")
215
+ throw new DriftReadFailure("read-unsupported", "--stack needs a stack name");
201
216
  if (entry.kind === "chant" && !query.env)
202
217
  throw new DriftReadFailure("env-required", `${query.member} is a chant member, read live through chant lifecycle diff <env> --live: add --env <env>`);
203
218
  const { registry: kinds, problems } = loadKindRegistry(declaration.pins, located.rootOnDisk);
@@ -298,6 +313,7 @@ export async function runWorkspaceDrift(ctx) {
298
313
  member: members[0],
299
314
  ...(args.driftRead !== undefined ? { read: args.driftRead } : {}),
300
315
  ...(args.resource !== undefined ? { resource: args.resource } : {}),
316
+ ...(args.carveStack !== undefined ? { stack: args.carveStack } : {}),
301
317
  ...(args.env !== undefined ? { env: args.env } : {}),
302
318
  ...(args.components ? { components: true } : {}),
303
319
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant",
3
- "version": "0.124.58",
3
+ "version": "0.124.59",
4
4
  "description": "Declarative infrastructure-as-code toolkit — TypeScript on Node.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
package/src/ci-product.ts CHANGED
@@ -13,7 +13,6 @@ import type { CiProductWords, CiProductWordsInput } from "./ci-product-words";
13
13
  import type { ProductMcpHook } from "./cli/mcp/product-tools";
14
14
  import type { ProductWaveHook } from "./op/op-waves-after-plan";
15
15
  import { OTLP_EXPORTER_FLOOR } from "./otlp";
16
- import { NEXT_RELEASE } from "./release-floors";
17
16
 
18
17
  /**
19
18
  * The first chant with the product pipeline (#4550): the words, the
@@ -127,7 +126,7 @@ export { prActionJob, PR_ACTION_JOB, prApplyComment, prCommentLockJobs, prCommen
127
126
  * reads what was asked with `productActionFromEnv`. A product
128
127
  * feature-detects on this floor.
129
128
  */
130
- export const PRODUCT_ACTIONS_FLOOR = NEXT_RELEASE;
129
+ export const PRODUCT_ACTIONS_FLOOR = "0.124.58";
131
130
  export { CI_SERVICES_FLOOR, engineServices, githubServices, gitlabServices, serviceWaitLine, servicesJobEnv, type CiService } from "./components/ci-services";
132
131
  export { renderPrNote, prStatusContext, prApproveCommand, prApproveCommands, prApproveTargets, prMergeSentence, type PrMemberDetail } from "./pr-loop";
133
132
  export { upsertPlanNote } from "./pr-post";
@@ -0,0 +1,52 @@
1
+ /**
2
+ * `chant lifecycle drift --stack <name>` hands the stack to each lexicon's
3
+ * `readDrift`, which is how `chant workspace drift --stack` reaches a pulumi
4
+ * member's reader project.
5
+ */
6
+ import { mkdtempSync, rmSync } from "node:fs";
7
+ import { tmpdir } from "node:os";
8
+ import { join } from "node:path";
9
+ import { afterEach, describe, expect, test, vi } from "vitest";
10
+ import type { ReadDriftOptions } from "../../drift-record";
11
+ import { parseArgs } from "../parse-args";
12
+ import type { CommandContext } from "../registry";
13
+ import { runLifecycleDrift } from "./lifecycle-drift";
14
+
15
+ const dirs: string[] = [];
16
+ afterEach(() => {
17
+ vi.restoreAllMocks();
18
+ for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
19
+ });
20
+
21
+ async function run(argv: string[], answer: (o: ReadDriftOptions) => unknown): Promise<{ seen: ReadDriftOptions[]; code: number; out: string[] }> {
22
+ const dir = mkdtempSync(join(tmpdir(), "lifecycle-drift-"));
23
+ dirs.push(dir);
24
+ vi.spyOn(process, "cwd").mockReturnValue(dir);
25
+ const out: string[] = [];
26
+ vi.spyOn(console, "log").mockImplementation((line: string) => void out.push(line));
27
+ vi.spyOn(process.stdout, "write").mockImplementation((chunk: string | Uint8Array) => (out.push(String(chunk)), true));
28
+ const seen: ReadDriftOptions[] = [];
29
+ const plugin = { name: "fake", readDrift: async (o: ReadDriftOptions) => (seen.push(o), answer(o)) };
30
+ const code = await runLifecycleDrift({ args: parseArgs(argv), plugins: [plugin] } as unknown as CommandContext);
31
+ return { seen, code, out };
32
+ }
33
+
34
+ describe("chant lifecycle drift --stack", () => {
35
+ test("the lexicon's readDrift gets the stack", async () => {
36
+ const { seen, code } = await run(["lifecycle", "drift", ".", "--member", "shop", "--stack", "prod-eu"], () => ({ lines: [] }));
37
+ expect(code).toBe(0);
38
+ expect(seen).toHaveLength(1);
39
+ expect(seen[0]).toMatchObject({ member: "shop", stack: "prod-eu" });
40
+ });
41
+
42
+ test("without it the option is absent", async () => {
43
+ const { seen } = await run(["lifecycle", "drift", ".", "--member", "shop"], () => ({ lines: [] }));
44
+ expect(seen[0]).not.toHaveProperty("stack");
45
+ });
46
+
47
+ test("a refusal is the one stdout line, exit 1", async () => {
48
+ const { code, out } = await run(["lifecycle", "drift", ".", "--member", "shop", "--stack", "x"], () => ({ refused: { code: "no-drift-read", message: "no export for stack x" } }));
49
+ expect(code).toBe(1);
50
+ expect(JSON.parse(out.join("")).refused).toEqual({ code: "no-drift-read", message: "fake: no export for stack x" });
51
+ });
52
+ });
@@ -12,7 +12,8 @@
12
12
  * never imports a lexicon to read drift.
13
13
  *
14
14
  * `--member` names the workspace member the records are for; it defaults to
15
- * the project directory's name. A lexicon that refuses the read (a read its
15
+ * the project directory's name. `--stack` names the stack to read, for a
16
+ * lexicon whose store holds one export per stack (pulumi). A lexicon that refuses the read (a read its
16
17
  * engine has not got, or one resource on an engine that cannot read one on
17
18
  * its own) makes the command print `{"refused": {code, message}}` as its
18
19
  * only stdout line and exit 3, so the workspace command can name the
@@ -33,7 +34,7 @@ import type { CommandContext } from "../registry";
33
34
  */
34
35
  export const DRIFT_REFUSED_EXIT = CHANT_EXIT.failed;
35
36
 
36
- const USAGE = "chant lifecycle drift [--member <name>] [--read <state|plan|refresh|live-read|ownership>] [--resource <addr>]";
37
+ const USAGE = "chant lifecycle drift [--member <name>] [--read <state|plan|refresh|live-read|ownership>] [--resource <addr>] [--stack <name>]";
37
38
 
38
39
  function refuse(code: ReadDriftRefusalCode, message: string): number {
39
40
  console.log(JSON.stringify({ refused: { code, message } }));
@@ -63,6 +64,7 @@ export async function runLifecycleDrift(ctx: CommandContext): Promise<number> {
63
64
  config: config as Record<string, unknown>,
64
65
  ...(read !== undefined ? { read: read as DriftRead } : {}),
65
66
  ...(args.resource !== undefined ? { resource: args.resource } : {}),
67
+ ...(args.carveStack !== undefined ? { stack: args.carveStack } : {}),
66
68
  observedAt,
67
69
  });
68
70
  if ("refused" in answer) return refuse(answer.refused.code, `${plugin.name}: ${answer.refused.message}`);
@@ -9,6 +9,7 @@
9
9
  * chant lock --list [--gate <name>] [--json]
10
10
  * chant lock --alive <run>
11
11
  * chant unlock --pr <n> [<target>...] [--gate <name>] [--json]
12
+ * chant unlock --run <id> [--gate <name>] [--json]
12
13
  * ```
13
14
  *
14
15
  * The targets are names: the components `chant components pr-plan` selects,
@@ -35,6 +36,11 @@
35
36
  * finished, `alive` while it runs or when nobody can say. The lock tag's
36
37
  * shell asks it before taking a lease over.
37
38
  *
39
+ * `chant unlock --run <id>` (#4660) frees every row run `<id>` holds on the
40
+ * gate and drops its place in the queue, for a hold whose run is gone and
41
+ * that no beat or forge answer has freed. `--beat <run> --parent <pid>` is
42
+ * the heartbeat side process of a hold (../../lifecycle/lock-beat.ts).
43
+ *
38
44
  * `--forge` reads which holders are still open, so a lock whose pull
39
45
  * request merged or closed is taken over, and, with `--head`, posts the
40
46
  * `chant/lock` status on that commit. Without it every lock counts as held.
@@ -138,6 +144,22 @@ export async function runLock(ctx: CommandContext): Promise<number> {
138
144
  return 0;
139
145
  }
140
146
 
147
+ if (args.beatRun !== undefined) {
148
+ if (args.parentPid === undefined) return fail("--beat needs the process it beats for: --beat <run> --parent <pid>");
149
+ const { beatLockRows, lockBeatSeconds } = await import("../../lifecycle/resource-lock");
150
+ const { runBeatLoop } = await import("../../lifecycle/lock-beat");
151
+ const run = args.beatRun;
152
+ await runBeatLoop({
153
+ gate,
154
+ run,
155
+ parent: args.parentPid,
156
+ intervalMs: lockBeatSeconds(process.env) * 1000,
157
+ beat: (at) => beatLockRows(gate, run, at),
158
+ log: (line) => console.error(line),
159
+ });
160
+ return 0;
161
+ }
162
+
141
163
  if (args.list) {
142
164
  if (targetsOf(ctx).length > 0 || args.pr !== undefined) return fail("--list prints every lock; drop the targets and --pr");
143
165
  let file;
@@ -168,7 +190,7 @@ export async function runLock(ctx: CommandContext): Promise<number> {
168
190
  if (rows.length === 0) console.error(formatInfo(`no target locks on ${gate}`));
169
191
  for (const [target, l] of rows) console.log(`${target}\tpull request ${l.pr}\t${l.stage}\t${l.by}\t${l.at}`);
170
192
  if (leased.length === 0) console.error(formatInfo(`no apply rows held on ${gate}`));
171
- for (const { key, holder } of leased) console.log(`${key}\trun ${holder.run}\t${holder.at}${holder.url ? `\t${holder.url}` : ""}`);
193
+ for (const { key, holder } of leased) console.log(`${key}\trun ${holder.run}\t${holder.at}${holder.url ? `\t${holder.url}` : ""}${holder.beat ? `\tbeat ${holder.beat}` : ""}`);
172
194
  return 0;
173
195
  }
174
196
 
@@ -244,7 +266,24 @@ export async function runUnlock(ctx: CommandContext): Promise<number> {
244
266
  const { args } = ctx;
245
267
  const gate = gateOf(ctx);
246
268
  if (typeof gate !== "string") return fail(gate.error);
247
- if (args.pr === undefined) return fail("chant unlock needs the pull or merge request whose locks it releases: --pr <n>");
269
+ if (args.unlockRun !== undefined) {
270
+ if (args.pr !== undefined || targetsOf(ctx).length > 0) return fail("--run frees the rows of one run; drop --pr and the targets");
271
+ const { clearRunLockRows } = await import("../../lifecycle/resource-lock");
272
+ let cleared;
273
+ try {
274
+ cleared = await clearRunLockRows(gate, args.unlockRun);
275
+ } catch (err) {
276
+ return fail(`could not clear run ${args.unlockRun} from ${gate}: ${err instanceof Error ? err.message : String(err)}`);
277
+ }
278
+ if (args.json) {
279
+ console.log(JSON.stringify({ gate, run: args.unlockRun, released: cleared.released, waited: cleared.waited, pushed: cleared.pushed }, null, 2));
280
+ return 0;
281
+ }
282
+ if (cleared.released.length === 0 && !cleared.waited) console.error(formatInfo(`run ${args.unlockRun} holds no row and waits for none on ${gate}`));
283
+ else console.error(formatSuccess(`freed ${cleared.released.length > 0 ? cleared.released.join(", ") : "no row"}${cleared.waited ? " and took run " + args.unlockRun + " out of the queue" : ""} on ${gate}`));
284
+ return 0;
285
+ }
286
+ if (args.pr === undefined) return fail("chant unlock needs the pull or merge request whose locks it releases: --pr <n>, or the run whose rows it frees: --run <id>");
248
287
  const targets = targetsOf(ctx);
249
288
  let result;
250
289
  try {
package/src/cli/main.ts CHANGED
@@ -19,6 +19,7 @@ import { dispatchCommandGroup, collectCommandGroups, formatCommandGroupsHelp, ty
19
19
  import type { LexiconPlugin } from "../lexicon";
20
20
  import { parseArgs } from "./parse-args";
21
21
  import { flushAndExit, waitForStreamDrain } from "./flush";
22
+ import { setOwnChantCommand } from "../lifecycle/lock-beat";
22
23
 
23
24
  export { parseArgs, waitForStreamDrain };
24
25
 
@@ -675,7 +676,8 @@ Ops:
675
676
  posts chant/lock on --head. Exits 3 when another open
676
677
  pull request holds a target. --list prints the locks
677
678
  unlock [<target>...] Release the locks a pull request holds (--pr <n>,
678
- --gate <name>, --json)
679
+ --gate <name>, --json). --run <id> frees the rows a
680
+ run holds or waits for on the gate instead
679
681
  graph Show Op dependency graph (--stacks for cross-stack order,
680
682
  --format ir|mermaid|dot|layout for the lint-gated graph IR,
681
683
  a Mermaid flowchart, Graphviz DOT, or node positions;
@@ -2202,6 +2204,8 @@ async function main(): Promise<void> {
2202
2204
  // whole CLI through the npm .bin shim / a symlinked checkout).
2203
2205
  const isMain = isEntryPoint(process.argv[1], import.meta.url);
2204
2206
  if (isMain) {
2207
+ // #4660: a row hold starts its heartbeat as this chant, run again.
2208
+ setOwnChantCommand([process.execPath, ...process.execArgv, process.argv[1]!]);
2205
2209
  main().catch(async (err) => {
2206
2210
  const verbose = process.argv.includes("--verbose") || process.argv.includes("-v");
2207
2211
  // #4116: a failure to import a package the project has not installed is named as such first.
@@ -13,7 +13,6 @@ import { McpServer } from "./server";
13
13
  import { PRODUCT_MCP_PROPOSE_FLOOR, productToolWriteWord, ProductToolRefusedError, type ProductMcpHook } from "./product-tools";
14
14
  import { PROPOSE_INSTRUCTIONS } from "./server";
15
15
  import { READ_ONLY_CORE_TOOLS } from "./read-only";
16
- import { NEXT_RELEASE } from "../../release-floors";
17
16
  import * as ciProduct from "../../ci-product";
18
17
  import { reportReader, reportToolKey, safeReportKey } from "./report-tools";
19
18
  import type { ToolDefinition } from "./types";
@@ -155,7 +154,7 @@ describe("the --propose tier (#4655)", () => {
155
154
  });
156
155
 
157
156
  test("the tier's floor is on @intentius/chant/ci-product for a product to feature-detect", () => {
158
- expect(PRODUCT_MCP_PROPOSE_FLOOR).toBe(NEXT_RELEASE);
157
+ expect(PRODUCT_MCP_PROPOSE_FLOOR).toBe("0.124.58");
159
158
  expect(ciProduct.PRODUCT_MCP_PROPOSE_FLOOR).toBe(PRODUCT_MCP_PROPOSE_FLOOR);
160
159
  expect(ciProduct.PRODUCT_TOOL_PROPOSE_WORDS).toEqual(["request", "propose"]);
161
160
  });
@@ -33,7 +33,6 @@
33
33
  */
34
34
 
35
35
  import type { McpToolContribution } from "../../mcp/types";
36
- import { NEXT_RELEASE } from "../../release-floors";
37
36
  import { reportReader, reportUrlFor, type ReportReader } from "./report-tools";
38
37
 
39
38
  /** What a product's tools are handed. */
@@ -77,7 +76,7 @@ export interface ProductMcpHook {
77
76
  * it passes `--propose` or `propose: true`, and refuses naming this release
78
77
  * when its chant is older.
79
78
  */
80
- export const PRODUCT_MCP_PROPOSE_FLOOR = NEXT_RELEASE;
79
+ export const PRODUCT_MCP_PROPOSE_FLOOR = "0.124.58";
81
80
 
82
81
  /** The words a `forgeWrite` tool's name may hold on the `--propose` tier, which the write-word check passes over (chant#4655). */
83
82
  export const PRODUCT_TOOL_PROPOSE_WORDS = ["request", "propose"] as const;
@@ -531,6 +531,18 @@ export function parseArgs(args: string[]): ParsedArgs {
531
531
  // `chant lock --alive <run>` (#4552): print whether a run holding rows or the repo lock tag still runs.
532
532
  result.aliveRun = args[++i];
533
533
  if (!result.aliveRun || result.aliveRun.startsWith("-")) throw new Error("--alive needs a run id: --alive <run>");
534
+ } else if (arg === "--beat") {
535
+ // `chant lock --beat <run> --parent <pid>` (#4660): the heartbeat side process of a row hold.
536
+ result.beatRun = args[++i];
537
+ if (!result.beatRun || result.beatRun.startsWith("-")) throw new Error("--beat needs a run id: --beat <run> --parent <pid>");
538
+ } else if (arg === "--parent") {
539
+ const pid = Number(args[++i]);
540
+ if (!Number.isInteger(pid) || pid < 1) throw new Error("--parent needs a process id: --parent <pid>");
541
+ result.parentPid = pid;
542
+ } else if (arg === "--run") {
543
+ // `chant unlock --run <id>` (#4660): free the rows a run holds or waits for.
544
+ result.unlockRun = args[++i];
545
+ if (!result.unlockRun || result.unlockRun.startsWith("-")) throw new Error("--run needs a run id: --run <id>");
534
546
  } else if (arg === "--from-report") {
535
547
  // `chant lock --from-report <pr-plan.json>` (#4293): lock the components a pull-request report lists.
536
548
  result.fromReport = args[++i];
@@ -367,6 +367,12 @@ export interface ParsedArgs {
367
367
  fromReport?: string;
368
368
  /** `chant lock --alive <run>` (#4552): print `alive` or `dead` for a run that holds rows or the repo lock tag. */
369
369
  aliveRun?: string;
370
+ /** `chant lock --beat <run>` (#4660): the heartbeat side process of the rows a run holds. Not for people. */
371
+ beatRun?: string;
372
+ /** `chant lock --beat <run> --parent <pid>`: the process whose end ends the beat. */
373
+ parentPid?: number;
374
+ /** `chant unlock --run <id>` (#4660): free the rows a run holds or waits for, whatever the forge says of it. */
375
+ unlockRun?: string;
370
376
  /** Every `--pr <n>`, in order: `chant release compose` (#4168 4.3) takes several. */
371
377
  prs?: number[];
372
378
  /** `chant release cut --channel <tag>` (#4168 4.3): the tag a publish of the release moves in place of `latest`. */
@@ -1190,6 +1190,11 @@ export interface ReadDriftOptions {
1190
1190
  read?: DriftRead;
1191
1191
  /** One address to read, on an engine that can read one resource on its own. */
1192
1192
  resource?: string;
1193
+ /**
1194
+ * The stack to read (`chant workspace drift --stack`), for an engine whose store holds one export per stack.
1195
+ * A lexicon with no such store refuses it with `read-unsupported`; one whose store lacks that stack's export refuses with `no-drift-read`.
1196
+ */
1197
+ stack?: string;
1193
1198
  /** RFC 3339, the `observedAt` of every record the lexicon builds itself. */
1194
1199
  observedAt: string;
1195
1200
  }
@@ -19,7 +19,6 @@
19
19
  */
20
20
  import { existsSync } from "node:fs";
21
21
  import { join } from "node:path";
22
- import { NEXT_RELEASE } from "../release-floors";
23
22
 
24
23
  /** The first chant with the e2e harness. */
25
24
  export const E2E_HARNESS_FLOOR = "0.124.56";
@@ -30,7 +29,7 @@ export const E2E_HARNESS_FLOOR = "0.124.56";
30
29
  * outcomes, and the forge reads under them. A scenario that uses one needs
31
30
  * this chant or newer.
32
31
  */
33
- export const E2E_HARNESS_PULL_STEPS_FLOOR = NEXT_RELEASE;
32
+ export const E2E_HARNESS_PULL_STEPS_FLOOR = "0.124.58";
34
33
 
35
34
  /**
36
35
  * The harness's chant docker-lexicon project, to `chant build <dir>/src
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The heartbeat of a row hold (#4660). A job that is cancelled or killed
3
+ * never runs its cleanup, so the hold it took stays on `chant/lifecycle`
4
+ * and later waves on the stack wait on it. The hold carries a liveness
5
+ * token, `beat`, that a side process of the apply refreshes every
6
+ * `CHANT_LOCK_BEAT` seconds. The next waiter reads a hold whose beat is
7
+ * older than `CHANT_LOCK_BEAT_STALE` seconds as gone and takes it over
8
+ * (./resource-lock.ts `forgeLockLiveness`).
9
+ *
10
+ * The beat runs in its own process because an apply waits on its tool with
11
+ * `spawnSync`, which stops every timer of the job's process. The side
12
+ * process is `chant lock --beat <run> --parent <pid>`: it touches the hold,
13
+ * and ends when the hold is gone or when the job's process is. A job that is
14
+ * killed takes it along, and one that is not leaves a beat that goes stale.
15
+ *
16
+ * Only the chant CLI starts one ({@link setOwnChantCommand}); library
17
+ * callers and tests start none, and a hold without a beat keeps the forge
18
+ * and lease rules.
19
+ */
20
+ import { spawn } from "node:child_process";
21
+ import type { LockBeatStarter } from "./resource-lock";
22
+
23
+ let own: string[] | undefined;
24
+
25
+ /** Record how to run this chant again; called by the CLI entry point. */
26
+ export function setOwnChantCommand(command: readonly string[] | undefined): void {
27
+ own = command && command.length > 0 && command.every((c) => typeof c === "string" && c !== "") ? [...command] : undefined;
28
+ }
29
+
30
+ /** The starter of the heartbeat side process, or undefined outside the chant CLI or when `CHANT_LOCK_BEAT=off`. */
31
+ export function ownBeatStarter(env: Record<string, string | undefined> = process.env): LockBeatStarter | undefined {
32
+ if (!own || env.CHANT_LOCK_BEAT === "off") return undefined;
33
+ const command = own;
34
+ return ({ gate, holder, cwd }) => {
35
+ const [bin, ...lead] = command;
36
+ const child = spawn(bin!, [...lead, "lock", "--beat", holder.run, "--gate", gate, "--parent", String(process.pid)], {
37
+ ...(cwd ? { cwd } : {}),
38
+ detached: true,
39
+ stdio: "ignore",
40
+ env,
41
+ });
42
+ child.on("error", () => {
43
+ // No side process: the hold keeps the forge and lease rules.
44
+ });
45
+ child.unref();
46
+ return () => {
47
+ try {
48
+ child.kill("SIGTERM");
49
+ } catch {
50
+ // Already gone.
51
+ }
52
+ };
53
+ };
54
+ }
55
+
56
+ export interface BeatLoop {
57
+ gate: string;
58
+ run: string;
59
+ /** The process whose end ends the loop. */
60
+ parent: number;
61
+ intervalMs: number;
62
+ /** Touch the hold: `gone` ends the loop. */
63
+ beat(at: string): Promise<"held" | "gone">;
64
+ parentAlive?(pid: number): boolean;
65
+ sleep?(ms: number): Promise<void>;
66
+ now?(): number;
67
+ /** Where a failed touch is said. */
68
+ log?(line: string): void;
69
+ }
70
+
71
+ function processAlive(pid: number): boolean {
72
+ try {
73
+ process.kill(pid, 0);
74
+ return true;
75
+ } catch (e) {
76
+ return (e as NodeJS.ErrnoException).code === "EPERM";
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Touch the hold now and every interval until it is released or taken over
82
+ * (`released`) or the parent process ends (`parent-gone`). A touch that fails
83
+ * is tried again at the next interval; the hold goes stale only after
84
+ * `CHANT_LOCK_BEAT_STALE` seconds of failures.
85
+ */
86
+ export async function runBeatLoop(loop: BeatLoop): Promise<"released" | "parent-gone"> {
87
+ const alive = loop.parentAlive ?? processAlive;
88
+ const sleep = loop.sleep ?? ((ms: number) => new Promise<void>((r) => setTimeout(r, ms)));
89
+ const now = loop.now ?? Date.now;
90
+ for (;;) {
91
+ if (!alive(loop.parent)) return "parent-gone";
92
+ try {
93
+ if ((await loop.beat(new Date(now()).toISOString())) === "gone") return "released";
94
+ } catch (err) {
95
+ loop.log?.(`could not touch the hold of run ${loop.run} on ${loop.gate}: ${err instanceof Error ? err.message : String(err)}`);
96
+ }
97
+ await sleep(loop.intervalMs);
98
+ }
99
+ }