forgedock 1.61.2 → 1.62.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.
Files changed (131) hide show
  1. package/bin/config-schema.mjs +10 -1
  2. package/bin/engine/outcome-codes.mjs +4 -0
  3. package/bin/engine-cli.mjs +159 -17
  4. package/bin/env/env.mjs +6 -4
  5. package/bin/forge-home-check.mjs +91 -0
  6. package/bin/forgedock.mjs +50 -7
  7. package/bin/gc.mjs +2 -0
  8. package/bin/hooks/pre-tool-use.mjs +4 -0
  9. package/bin/journey.mjs +55 -5
  10. package/bin/lean/admission.mjs +16 -5
  11. package/bin/lean/batch-health.mjs +55 -16
  12. package/bin/lean/batch-health.test.mjs +67 -1
  13. package/bin/lean/batch.mjs +8 -0
  14. package/bin/lean/batch.test.mjs +5 -0
  15. package/bin/lean/ceiling.mjs +20 -0
  16. package/bin/lean/ceiling.test.mjs +33 -2
  17. package/bin/lean/ci-gate.mjs +240 -0
  18. package/bin/lean/ci-gate.test.mjs +227 -0
  19. package/bin/lean/ci-precheck.mjs +178 -0
  20. package/bin/lean/ci-precheck.test.mjs +149 -0
  21. package/bin/lean/conformance.mjs +85 -9
  22. package/bin/lean/conformance.test.mjs +155 -3
  23. package/bin/lean/context.test.mjs +7 -6
  24. package/bin/lean/dag.mjs +128 -0
  25. package/bin/lean/dag.test.mjs +131 -0
  26. package/bin/lean/decisions.mjs +5 -4
  27. package/bin/lean/decisions.test.mjs +11 -0
  28. package/bin/lean/delguard.mjs +84 -0
  29. package/bin/lean/delguard.test.mjs +104 -0
  30. package/bin/lean/depcache.mjs +125 -17
  31. package/bin/lean/depcache.test.mjs +111 -0
  32. package/bin/lean/design-gate.mjs +5 -5
  33. package/bin/lean/design-gate.test.mjs +14 -0
  34. package/bin/lean/effects.mjs +72 -4
  35. package/bin/lean/execution.mjs +41 -7
  36. package/bin/lean/execution.test.mjs +99 -3
  37. package/bin/lean/forgedock-lane-workflow.test.mjs +35 -0
  38. package/bin/lean/guardgate.mjs +30 -7
  39. package/bin/lean/guardgate.test.mjs +44 -1
  40. package/bin/lean/guards.test.mjs +1 -1
  41. package/bin/lean/heavy.test.mjs +87 -0
  42. package/bin/lean/hotarea.mjs +73 -0
  43. package/bin/lean/hotarea.test.mjs +73 -0
  44. package/bin/lean/issuewatch-reconcile.mjs +20 -1
  45. package/bin/lean/issuewatch-reconcile.test.mjs +30 -0
  46. package/bin/lean/lanecheck.mjs +27 -3
  47. package/bin/lean/lanecheck.test.mjs +47 -5
  48. package/bin/lean/laneconfine.mjs +83 -0
  49. package/bin/lean/laneconfine.test.mjs +113 -0
  50. package/bin/lean/lean.mjs +376 -79
  51. package/bin/lean/lean.test.mjs +710 -22
  52. package/bin/lean/live-reconcile.mjs +169 -0
  53. package/bin/lean/live-reconcile.test.mjs +176 -0
  54. package/bin/lean/orchestrate-envhold.test.mjs +245 -0
  55. package/bin/lean/orchestrate-hostfallback.test.mjs +39 -0
  56. package/bin/lean/orchestrate.mjs +207 -17
  57. package/bin/lean/outcomeevidence.mjs +104 -0
  58. package/bin/lean/outcomeevidence.test.mjs +78 -0
  59. package/bin/lean/page-capture.mjs +68 -0
  60. package/bin/lean/page-capture.test.mjs +44 -0
  61. package/bin/lean/pagegate.mjs +46 -7
  62. package/bin/lean/pagegate.test.mjs +66 -1
  63. package/bin/lean/postdeploy-check.mjs +18 -4
  64. package/bin/lean/postdeploy-check.test.mjs +32 -1
  65. package/bin/lean/prefilter.mjs +36 -4
  66. package/bin/lean/prefilter.test.mjs +31 -1
  67. package/bin/lean/preflight.mjs +22 -0
  68. package/bin/lean/preflight.test.mjs +19 -1
  69. package/bin/lean/probe.mjs +18 -0
  70. package/bin/lean/probe.test.mjs +40 -0
  71. package/bin/lean/prompts.mjs +40 -3
  72. package/bin/lean/recovery.test.mjs +20 -0
  73. package/bin/lean/recurrence.mjs +133 -0
  74. package/bin/lean/recurrence.test.mjs +99 -0
  75. package/bin/lean/release-config.mjs +2 -1
  76. package/bin/lean/release-config.test.mjs +18 -0
  77. package/bin/lean/release-control.mjs +4 -2
  78. package/bin/lean/release-control.test.mjs +15 -0
  79. package/bin/lean/release-merge-hold.mjs +65 -0
  80. package/bin/lean/release-merge-hold.test.mjs +69 -0
  81. package/bin/lean/release-review.mjs +26 -9
  82. package/bin/lean/release-review.test.mjs +53 -0
  83. package/bin/lean/release-status.mjs +3 -1
  84. package/bin/lean/release-status.test.mjs +11 -0
  85. package/bin/lean/release.test.mjs +26 -1
  86. package/bin/lean/render.mjs +8 -7
  87. package/bin/lean/routing.mjs +49 -0
  88. package/bin/lean/routing.test.mjs +54 -1
  89. package/bin/lean/run-issue-placement.test.mjs +30 -1
  90. package/bin/lean/sandbox-actions.mjs +121 -0
  91. package/bin/lean/sandbox-actions.test.mjs +94 -0
  92. package/bin/lean/sandbox-provider.contract.test.mjs +22 -1
  93. package/bin/lean/sandbox-remote.mjs +3 -1
  94. package/bin/lean/schedd-health.mjs +14 -2
  95. package/bin/lean/schedd-health.test.mjs +13 -0
  96. package/bin/lean/schedd.mjs +43 -17
  97. package/bin/lean/schedd.test.mjs +61 -1
  98. package/bin/lean/toolchain.mjs +16 -6
  99. package/bin/lean/toolplace.mjs +12 -0
  100. package/bin/lean/weakguard.mjs +105 -0
  101. package/bin/lean/weakguard.test.mjs +59 -0
  102. package/bin/lean/winspawn.mjs +61 -0
  103. package/bin/lean/winspawn.test.mjs +45 -0
  104. package/bin/lean/worktree.mjs +3 -1
  105. package/bin/lean/worktree.test.mjs +11 -0
  106. package/bin/pool/agent.mjs +210 -14
  107. package/bin/pool/cache-sweep.mjs +74 -0
  108. package/bin/pool/cli.mjs +11 -3
  109. package/bin/pool/docker.mjs +33 -2
  110. package/bin/pool/health.mjs +38 -0
  111. package/bin/pool/lane-tools.mjs +23 -4
  112. package/bin/pool/lane-tools.test.mjs +12 -1
  113. package/bin/pool/router.mjs +21 -3
  114. package/bin/runner.mjs +37 -0
  115. package/bin/splash-scene.mjs +356 -0
  116. package/bin/win-hide-children.mjs +114 -0
  117. package/commands/orchestrate.md +18 -27
  118. package/commands/review-pr-agents/infra.md +1 -0
  119. package/commands/review-pr-staging.md +2 -2
  120. package/docs/CONFIG.md +60 -3
  121. package/docs/OUTCOME-CODES.md +3 -0
  122. package/package.json +1 -1
  123. package/plugins/forgedock-splash/.claude-plugin/plugin.json +1 -1
  124. package/plugins/forgedock-splash/README.md +1 -1
  125. package/plugins/forgedock-splash/hooks/scene.ts +142 -8
  126. package/pool/README.md +6 -0
  127. package/pool/image/entrypoint.sh +1 -0
  128. package/scripts/check-spec-size.sh +3 -1
  129. package/scripts/gen-splash-scene.mjs +24 -0
  130. package/scripts/review-staging-pre.sh +8 -3
  131. package/scripts/review-staging-pre.test.sh +2 -0
@@ -16,6 +16,7 @@ export const RECIPES = {
16
16
  "postgresql-client": { versioned: true, steps: (v) => [apt(v ? `postgresql-client-${v}` : "postgresql-client")] },
17
17
  python: { versioned: true, steps: (v) => [apt(v ? `python${v} python${v}-venv` : "python3 python3-venv")] },
18
18
  xvfb: { versioned: false, steps: () => [apt("xvfb xauth")] }, // headless X for browser/GUI tests that call xvfb-run
19
+ shellcheck: { versioned: false, steps: () => [apt("shellcheck")] }, // shell-script linter for validate commands
19
20
  playwright: { versioned: true, steps: (v) => [`RUN npx --yes playwright${v ? `@${v}` : ""} install --with-deps chromium`] },
20
21
  // Example of a release-tarball tool; the version is required.
21
22
  promtool: { versioned: true, steps: (v) => [`RUN curl -fsSL https://github.com/prometheus/prometheus/releases/download/v${v ?? "2.54.1"}/prometheus-${v ?? "2.54.1"}.linux-amd64.tar.gz | tar -xz --strip-components=1 -C /usr/local/bin --wildcards '*/promtool'`] },
@@ -42,8 +43,19 @@ export function validateLaneTools(raw) {
42
43
  return { tools: [...tools].sort(), errors };
43
44
  }
44
45
 
45
- /** True when `name` has a lane_tools recipe (#5652). */
46
- export function hasRecipe(name) { return Object.hasOwn(RECIPES, String(name)); }
46
+ /** Binaries a recipe provides under another name (#5764): the probe misses `python3`, not the `python` recipe. */
47
+ const BINARY_RECIPES = { pip3: "python", psql: "postgresql-client", pg_dump: "postgresql-client", "xvfb-run": "xvfb" };
48
+
49
+ /** The recipe that provides `tool` (a recipe name or a binary it installs), else null (#5764). */
50
+ export function recipeFor(tool) {
51
+ const t = String(tool);
52
+ if (Object.hasOwn(RECIPES, t)) return t;
53
+ if (/^python3(\.\d+)?$/.test(t)) return "python";
54
+ return Object.hasOwn(BINARY_RECIPES, t) ? BINARY_RECIPES[t] : null;
55
+ }
56
+
57
+ /** True when `name` has a lane_tools recipe, directly or as a binary one provides (#5652, #5764). */
58
+ export function hasRecipe(name) { return recipeFor(name) !== null; }
47
59
 
48
60
  /**
49
61
  * In-sandbox install commands (#5652) for one tool: the recipe's Dockerfile `RUN` steps as shell commands, `sudo` prefixed
@@ -51,9 +63,11 @@ export function hasRecipe(name) { return Object.hasOwn(RECIPES, String(name)); }
51
63
  */
52
64
  export function installCommands(entry, { root = true } = {}) {
53
65
  const { name, version } = parseLaneTool(entry);
54
- if (!hasRecipe(name)) return [];
66
+ const recipe = recipeFor(name);
67
+ if (!recipe) return [];
55
68
  const sh = (s) => s.replace(/^RUN\s+/, "");
56
- return RECIPES[name].steps(version).map((s) => (root ? sh(s) : `sudo sh -c ${JSON.stringify(sh(s))}`));
69
+ // a binary alias installs the unversioned recipe: python@3.12 provides python3.12, not python3 (#5764)
70
+ return RECIPES[recipe].steps(recipe === name ? version : null).map((s) => (root ? sh(s) : `sudo sh -c ${JSON.stringify(sh(s))}`));
57
71
  }
58
72
 
59
73
  /**
@@ -87,6 +101,11 @@ export function laneToolsTag(baseImage, tools) {
87
101
  return `${baseImage}-t${h}`;
88
102
  }
89
103
 
104
+ /** True when `tag` is the base image itself or a per-repo tools variant (`<base>-t<12 hex>`) of it. */
105
+ export function isLaneToolsTagOf(tag, base) {
106
+ return typeof tag === "string" && (tag === base || (tag.startsWith(`${base}-t`) && /^[0-9a-f]{12}$/.test(tag.slice(base.length + 2))));
107
+ }
108
+
90
109
  /** The generated Dockerfile: FROM the base lane image, then each recipe's steps in sorted order. */
91
110
  export function laneToolsDockerfile(baseImage, tools) {
92
111
  const steps = [...tools].sort().flatMap((e) => { const { name, version } = parseLaneTool(e); return RECIPES[name].steps(version); });
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: AGPL-3.0-or-later
3
3
  import { describe, it } from "node:test";
4
4
  import assert from "node:assert/strict";
5
- import { hasRecipe, installCommands, installLaneTools, laneToolsDockerfile } from "./lane-tools.mjs";
5
+ import { hasRecipe, recipeFor, installCommands, installLaneTools, laneToolsDockerfile } from "./lane-tools.mjs";
6
6
 
7
7
  describe("#5652 in-sandbox lane tool install", () => {
8
8
  it("installCommands strips RUN, prefixes sudo when not root, and is empty without a recipe", () => {
@@ -23,4 +23,15 @@ describe("#5652 in-sandbox lane tool install", () => {
23
23
  it("the image Dockerfile still uses the RUN steps", () => {
24
24
  assert.match(laneToolsDockerfile("base:1", ["postgresql-client"]), /\nRUN apt-get update/);
25
25
  });
26
+ it("#5763 shellcheck is an unversioned apt recipe in the derived image", () => {
27
+ assert.ok(hasRecipe("shellcheck"));
28
+ assert.match(installCommands("shellcheck")[0], /^apt-get update && apt-get install -y --no-install-recommends shellcheck /);
29
+ assert.match(laneToolsDockerfile("base:1", ["shellcheck"]), /\nRUN apt-get update && apt-get install -y --no-install-recommends shellcheck /);
30
+ });
31
+ it("#5764 a binary a recipe provides resolves to it; python3 installs the unversioned python recipe", () => {
32
+ for (const [b, r] of [["python3", "python"], ["python3.12", "python"], ["pip3", "python"], ["psql", "postgresql-client"], ["xvfb-run", "xvfb"], ["python", "python"]]) assert.equal(recipeFor(b), r, b);
33
+ assert.ok(hasRecipe("python3") && !hasRecipe("zzcheck") && recipeFor("zzcheck") === null);
34
+ assert.match(installCommands("python3")[0], /install -y --no-install-recommends python3 python3-venv /);
35
+ assert.match(installCommands("python@3.12")[0], /python3\.12 python3\.12-venv/);
36
+ });
26
37
  });
@@ -197,17 +197,34 @@ export function createRouter(cfg, { fetchFn = globalThis.fetch, now = () => Date
197
197
 
198
198
  /** #5053: an agent's 401 reaches the dispatcher through this router; tag it so it is not mistaken for a router auth failure. */
199
199
  const agentBody = (r, name) => (r.status === 401 ? { ...(r.data && typeof r.data === "object" ? r.data : {}), error: "unauthorized", hop: "agent", agent: name, reason: typeof r.data?.reason === "string" ? r.data.reason : "agent auth: router token rejected by agent" } : r.data ?? {});
200
+ // #5856: placement by priority. Agents that report no reservations/borrowable fields are flat (cpus_free), as before.
201
+ // reserved: a host holding that reservation with room left (the agent reclaims from borrowed lanes itself);
202
+ // normal: unreserved headroom; borrow: any physical headroom, preferring hosts with free non-reserved capacity.
203
+ const fitsPriority = (c, spec, size) => {
204
+ const prio = spec?.priority;
205
+ if (prio === "reserved" && Array.isArray(c.reservations)) {
206
+ const r = c.reservations.find((x) => x.name === spec.reservation) ?? (spec.reservation ? null : c.reservations.length === 1 ? c.reservations[0] : null);
207
+ return Boolean(r) && r.cpus_free >= size.cpus && r.mem_free_gb >= size.mem_gb;
208
+ }
209
+ const cpusFree = prio === "normal" && Number.isFinite(c.cpus_free_unreserved) ? c.cpus_free_unreserved : c.cpus_free;
210
+ const memFree = prio === "normal" && Number.isFinite(c.mem_free_unreserved_gb) ? c.mem_free_unreserved_gb : c.mem_free_gb;
211
+ return cpusFree >= size.cpus && memFree >= size.mem_gb;
212
+ };
213
+ const headroom = (c, spec) => (spec?.priority === "borrow" && Number.isFinite(c.cpus_free_unreserved) ? c.cpus_free_unreserved : 0);
200
214
  async function launch(spec) {
201
215
  if (typeof spec?.id !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(spec.id)) return { status: 400, body: { error: "spec.id required ([A-Za-z0-9._-], max 128)" } };
202
216
  const known = own(sbx(), spec.id);
203
217
  if (known && own(agents(), known.agent)) {
204
218
  known.touched = now(); store.save();
205
219
  const r = await agentCall(own(agents(), known.agent), "POST", "/sandboxes", { spec: withForgeYaml(spec), ...sizeFor(spec) });
206
- return { status: r.status, body: agentBody(r, known.agent), retryAfter: r.retryAfter };
220
+ // #5856: a drained borrow lane whose host is now full (reserved work took it) is placed on another host, not refused.
221
+ if (!(r.status === 503 && spec.priority === "borrow")) return { status: r.status, body: agentBody(r, known.agent), retryAfter: r.retryAfter };
222
+ delete sbx()[spec.id]; store.save();
207
223
  }
208
224
  const size = sizeFor(spec);
209
- const fits = (await capacities()).filter((c) => c.ok && !c.paused && c.cpus_free >= size.cpus && c.mem_free_gb >= size.mem_gb)
210
- .sort((a, b) => b.cpus_free - a.cpus_free || b.mem_free_gb - a.mem_free_gb);
225
+ const sized = (await capacities()).filter((c) => c.ok && !c.paused && fitsPriority(c, spec, size));
226
+ const diskLow = sized.filter((c) => c.host_disk_low === true).map((c) => c.name); // #5733: never POST to a host whose drive is short
227
+ const fits = sized.filter((c) => c.host_disk_low !== true).sort((a, b) => headroom(b, spec) - headroom(a, spec) || b.cpus_free - a.cpus_free || b.mem_free_gb - a.mem_free_gb);
211
228
  let busy = null; // the last agent 503 (e.g. lane_tools image building): its body and Retry-After are passed back
212
229
  for (const c of fits) {
213
230
  const r = await agentCall(own(agents(), c.name), "POST", "/sandboxes", { spec: withForgeYaml(spec), ...size }, 120000);
@@ -216,6 +233,7 @@ export function createRouter(cfg, { fetchFn = globalThis.fetch, now = () => Date
216
233
  return { status: r.status, body: { ...agentBody(r, c.name), agent: c.name } };
217
234
  }
218
235
  if (busy) return { status: 503, body: { ...agentBody(busy.r, busy.name), agent: busy.name }, retryAfter: busy.r.retryAfter ?? cfg.retry_after_s ?? 60 };
236
+ if (diskLow.length) return { status: 503, body: { error: "no host has free disk", code: "pool.disk_low", agents: diskLow }, retryAfter: cfg.disk_low_retry_after_s ?? 300 }; // a capacity deferral, not a failure
219
237
  return { status: 503, body: { error: "no host has a free reservation", lane: size }, retryAfter: cfg.retry_after_s ?? 60 };
220
238
  }
221
239
 
package/bin/runner.mjs CHANGED
@@ -1370,9 +1370,39 @@ const AUTH_FAILURE_RE = /Failed to authenticate|authentication_error|OAuth token
1370
1370
  export function detectAuthFailure(stdout, output = "") {
1371
1371
  const env = parseCliEnvelope(stdout);
1372
1372
  if (env) return env.is_error === true && typeof env.result === "string" && AUTH_FAILURE_RE.test(env.result);
1373
+ // forge#5762: a JSON envelope cut off before `result` is not evidence of a login failure.
1374
+ if (typeof stdout === "string" && stdout.trimStart().startsWith("{")) return false;
1373
1375
  return typeof output === "string" && AUTH_FAILURE_RE.test(output);
1374
1376
  }
1375
1377
 
1378
+ const MAX_CLI_RESULT_LEN = 500;
1379
+ /** forge#5762: masks credential-looking tokens before CLI text is stored in a lane or run log. */
1380
+ export function redactCliText(text) {
1381
+ return String(text)
1382
+ .replace(/\b(?:sk|pk)-[A-Za-z0-9_-]{8,}/g, "[redacted]")
1383
+ .replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._~+\/=-]{8,}/gi, "$1 [redacted]")
1384
+ .replace(/\b((?:access|refresh|oauth|api)[_-]?(?:token|key)|authorization)(["']?\s*[:=]\s*["']?)[^\s"',}]{6,}/gi, "$1$2[redacted]");
1385
+ }
1386
+
1387
+ /**
1388
+ * forge#5762: the facts a failed CLI run reports: `result` and `is_error` (redacted, capped) and whether the CLI never
1389
+ * reached the API (`duration_api_ms` 0, read from the raw text when the envelope is cut off). Never throws.
1390
+ * @returns {{cliResult?:string, cliIsError?:boolean, cliApiMs?:number}}
1391
+ */
1392
+ export function cliFailureFacts(stdout) {
1393
+ const env = parseCliEnvelope(stdout);
1394
+ const facts = {};
1395
+ if (env) {
1396
+ if (typeof env.result === "string") facts.cliResult = sanitizeAndCap(redactCliText(env.result), MAX_CLI_RESULT_LEN);
1397
+ if (typeof env.is_error === "boolean") facts.cliIsError = env.is_error;
1398
+ if (typeof env.duration_api_ms === "number") facts.cliApiMs = env.duration_api_ms;
1399
+ } else if (typeof stdout === "string") {
1400
+ const m = /"duration_api_ms"\s*:\s*(\d+)/.exec(stdout.slice(0, 4096));
1401
+ if (m) facts.cliApiMs = Number(m[1]);
1402
+ }
1403
+ return facts;
1404
+ }
1405
+
1376
1406
  /**
1377
1407
  * Best-effort extraction of a Claude CLI session-limit reset time from
1378
1408
  * captured stdout/stderr (forge#2241). The CLI's own session-limit message
@@ -1873,6 +1903,9 @@ export function runCliBackend({
1873
1903
  // forge#5168: a failed login (never when the usage limit already matched,
1874
1904
  // which keeps precedence) lets the lane defer as `backend.auth`.
1875
1905
  else if (detectAuthFailure(stdout, output)) err.authFailure = true;
1906
+ // forge#5762: keep the CLI's own result text; an exit that never reached the API and is no login or limit is transient.
1907
+ Object.assign(err, cliFailureFacts(stdout));
1908
+ if (!err.usageLimit && !err.authFailure && err.cliApiMs === 0 && result.status === 1) err.cliFailed = true;
1876
1909
  if (resetAt) {
1877
1910
  err.resetAt = resetAt;
1878
1911
  // forge#2524: also attach a machine-usable epoch-ms timestamp so
@@ -2082,6 +2115,7 @@ const CONTEXT_HARD_CAP = 1.25;
2082
2115
  * heavy step, test or lint child) the kill waits until idleMs + `busyMs` of silence, `onIdleExtend(info)` is told once per
2083
2116
  * idle stretch, and a later kill carries `extended: true` and `heavyQueue` (info.heavyQueue).
2084
2117
  * #4395: a stream result carries `baselineTokens`, the first assistant turn's context; absent when no message was seen.
2118
+ * #5812: and `endTokens`, the last assistant turn's context (what a `--resume` of the session starts from).
2085
2119
  * #4410: a stream result (and a CLI_TURNS / CLI_CONTEXT error) carries `toolUses`, [{msg, name, path, cmd}] per tool_use
2086
2120
  * (deduped by tool_use id, capped at TOOL_USES_MAX), for bin/lean/toolstats.mjs; absent on the non-stream path.
2087
2121
  * #5334: every stream kill (CLI_IDLE, CLI_TIMEOUT, a host kill's CLI_BACKEND_FAILED) carries the usage, `turns` and `toolUses`
@@ -2259,6 +2293,9 @@ export async function runCliBackendAsync(opts) {
2259
2293
  const first = msgUsage.values().next().value;
2260
2294
  if (stream && toolUses.size && r && typeof r === "object") r.toolUses = [...toolUses.values()];
2261
2295
  if (first && r && typeof r === "object") r.baselineTokens = toFiniteUsageNumber(first.input_tokens) + toFiniteUsageNumber(first.cache_read_input_tokens) + toFiniteUsageNumber(first.cache_creation_input_tokens);
2296
+ // #5812: the last assistant turn's context: what a resume of this session starts from
2297
+ const last = [...msgUsage.values()].pop();
2298
+ if (last && r && typeof r === "object") r.endTokens = toFiniteUsageNumber(last.input_tokens) + toFiniteUsageNumber(last.cache_read_input_tokens) + toFiniteUsageNumber(last.cache_creation_input_tokens);
2262
2299
  return r;
2263
2300
  }
2264
2301
 
@@ -0,0 +1,356 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ // GENERATED from plugins/forgedock-splash/hooks/scene.ts (types stripped) so `npx forgedock` can play the
4
+ // startup-splash scene on any supported Node, including from node_modules where Node refuses to strip types.
5
+ // Do not edit by hand: change scene.ts, then run: node scripts/gen-splash-scene.mjs
6
+ // bin/tests/splash-scene-parity.test.mjs fails if the two drift.
7
+ // Pure scene: frame number -> rows of coloured runs. No engine imports, so the
8
+ // same code drives the mod and the offline frame preview.
9
+
10
+ export const TICK = 60
11
+
12
+ // The ForgeDock "F" mark, exactly as the CLI draws it (bin/cinema.mjs HERO_MARK).
13
+ const MARK = [
14
+ ' ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄',
15
+ ' ▄▄██████████████████',
16
+ ' ▄█████████████▀▀▀▀▀▀▀▀▀',
17
+ ' ▄██████████▀▀',
18
+ ' ▀▀▀▀▀ ▄▄███████▀',
19
+ ' ▄████████▀',
20
+ ' ▄██████▀',
21
+ ' ▀▀▀▀',
22
+ ]
23
+ const MW = 28 // mark width
24
+ const TOP = 1 // canvas row of the mark's first row (row 0 is headroom for sparks)
25
+ const H = MARK.length + TOP
26
+ const CW = 56 // canvas width
27
+ const TEXT_X = 33 // column of the wordmark block
28
+
29
+ // Brand stops (bin/cinema.mjs) and Claude's orange for the mascot.
30
+ const DARK = { chrome: ['#f7f3ea', '#d9cfba', '#a99a82', '#6e6252'], ember: ['#ff4d00', '#ff8c1a', '#ffd166'], hot: '#ffffff', bg: '#1a1714' }
31
+ // Light terminals: a darker steel and deeper embers so the mark reads on white; the "white-hot" flash becomes bright orange.
32
+ const LIGHT = { chrome: ['#6e6252', '#5c5144', '#4a4136', '#2f2922'], ember: ['#c43c00', '#e06600', '#f29d00'], hot: '#ff7a00', bg: '#f4f1ec' }
33
+ let CHROME = DARK.chrome
34
+ let EMBER = DARK.ember
35
+ let WHITE = DARK.hot
36
+ let BG = DARK.bg
37
+ const CLAUDE = '#d97757'
38
+ const HEART = '#ff6f91'
39
+ const STEAM = '#d8d3cb'
40
+ const FLAME_RED = '#c8200a'
41
+
42
+ /** Pick the palette for the terminal's theme (Claude Code's `theme` setting). */
43
+ export function setTheme(light ) {
44
+ const t = light ? LIGHT : DARK
45
+ CHROME = t.chrome
46
+ EMBER = t.ember
47
+ WHITE = t.hot
48
+ BG = t.bg
49
+ }
50
+
51
+ /** Smallest band the scene fits in. */
52
+ export const MIN_COLUMNS = 56
53
+ export const MIN_ROWS = 9
54
+ const WORD = 'F O R G E D O C K'
55
+
56
+ // Clawd poses (3 rows, 9 wide).
57
+ const P = {
58
+ stand: [' ▐▛███▜▌ ', '▝▜█████▛▘', ' ▘▘ ▝▝ '],
59
+ stepA: [' ▐▛███▜▌ ', '▝▜█████▛▘', ' ▘▘ ▝▝ '],
60
+ stepB: [' ▐▛███▜▌ ', '▝▜█████▛▘', ' ▘▘ ▝▝ '],
61
+ look: [' ▐▀███▀▌ ', '▝▜█████▛▘', ' ▘▘ ▝▝ '],
62
+ blink: [' ▐█████▌ ', '▝▜█████▛▘', ' ▘▘ ▝▝ '],
63
+ side: [' ▐█▜██▛▌ ', '▝▜█████▛▘', ' ▘▘ ▝▝ '],
64
+ crouch: [' ', ' ▐▛███▜▌ ', '▀▀█████▀▀'],
65
+ jump: ['▗▐▀███▀▌▖', ' ▜█████▛ ', ' ▝▘ ▝▘ '],
66
+ cheer: ['▗▐▛███▜▌▖', ' ▜█████▛ ', ' ▘▘ ▝▝ '],
67
+ // one claw up, swinging: a wave hello / goodbye
68
+ waveA: [' ▐▛███▜▌▗', '▝▜█████▛ ', ' ▘▘ ▝▝ '],
69
+ waveB: [' ▐▛███▜▌▝', '▝▜█████▛▖', ' ▘▘ ▝▝ '],
70
+ // dizzy wobble after the bonk
71
+ dizzyL: ['▐▀███▀▌ ', '▜█████▛▘ ', ' ▘▘ ▝▝ '],
72
+ dizzyR: [' ▐▀███▀▌', ' ▝▜█████▛', ' ▘▘ ▝▝ '],
73
+ }
74
+
75
+ // Beats (frame numbers).
76
+ const FORGE = 12 // the F is forged in, glowing then cooling
77
+ const WALK_END = FORGE + 18 // Clawd walks in under the overhang
78
+ const LOOK_END = WALK_END + 5 // looks up at the bar
79
+ const CROUCH_END = LOOK_END + 2
80
+ const BONK = CROUCH_END + 3 // head meets the bar
81
+ const LAND = BONK + 3
82
+ const DIZZY_END = LAND + 8 // stars circle Clawd's head, then it shakes it off
83
+ const SHINE_END = BONK + 18 // shine ring expands from the impact
84
+ const TYPE_START = BONK + 6
85
+ const TYPE_END = TYPE_START + WORD.length
86
+ const HOLD_START = TYPE_END + 4
87
+ const FADE_START = HOLD_START + 32
88
+ export const LAST = FADE_START + 10
89
+
90
+ const CLAWD_X = 21 // under the right end of the top bar, clear of the F's lower strokes
91
+ const START_X = CW // walks in from the right edge
92
+ const IMPACT = { r: TOP + 2, c: 25 } // underside of the top bar, above Clawd's head
93
+
94
+ const hex = (s ) => [1, 3, 5].map(i => parseInt(s.slice(i, i + 2), 16))
95
+ export const mix = (a , b , t ) => {
96
+ const x = hex(a), y = hex(b), k = Math.max(0, Math.min(1, t))
97
+ return '#' + x.map((v, i) => Math.round(v + ((y[i] ?? v) - v) * k).toString(16).padStart(2, '0')).join('')
98
+ }
99
+ const ramp = (stops , t ) => {
100
+ const u = Math.max(0, Math.min(1, t)) * (stops.length - 1)
101
+ const i = Math.min(stops.length - 2, Math.floor(u))
102
+ return mix(stops[i] ?? WHITE, stops[i + 1] ?? WHITE, u - i)
103
+ }
104
+ const easeOut = (t ) => 1 - (1 - t) * (1 - t)
105
+ // Deterministic flicker noise in [0, 1).
106
+ const noise = (a , b ) => {
107
+ const x = Math.sin(a * 127.1 + b * 311.7) * 43758.5453
108
+ return x - Math.floor(x)
109
+ }
110
+
111
+ // Light comes from the upper left: faces open to the sky catch it, faces open to the floor fall into shade.
112
+ const blank = (r , c ) => (MARK[r]?.[c] ?? ' ') === ' '
113
+ function lit(r , c , base ) {
114
+ const grain = (noise(c * 0.7, r * 3.1) - 0.5) * 0.08 // brushed steel: faint horizontal streaks
115
+ base = mix(base, CHROME[0] ?? WHITE, 0.3) // polished: lift the whole face toward the brightest stop
116
+ let col = grain > 0 ? mix(base, CHROME[0] ?? WHITE, grain) : mix(base, CHROME[3] ?? WHITE, -grain)
117
+ if (blank(r - 1, c)) col = mix(col, CHROME[0] ?? WHITE, 0.55) // top bevel highlight
118
+ else if (blank(r, c - 1)) col = mix(col, CHROME[0] ?? WHITE, 0.3) // left bevel
119
+ if (blank(r + 1, c)) col = mix(col, CHROME[3] ?? WHITE, 0.18) // underside in shade
120
+ return col
121
+ }
122
+
123
+ function markColor(r , c , f ) {
124
+ const chrome = lit(r, c, ramp(CHROME, c / MW + r * 0.06))
125
+ if (f < FORGE + 6) {
126
+ const age = (f / FORGE) * (MW + 6) - r * 0.6 - c
127
+ if (age < 0) return null
128
+ if (age < 1.5) return EMBER[2] ?? WHITE
129
+ if (age < 3) return EMBER[1] ?? WHITE
130
+ if (age < 5) return EMBER[0] ?? WHITE
131
+ return mix(EMBER[0] ?? WHITE, chrome, (age - 5) / 5)
132
+ }
133
+ if (f >= BONK && f < SHINE_END) {
134
+ const t = f - BONK
135
+ const dr = (r + TOP - IMPACT.r) * 2 // rows are ~2x taller than columns are wide
136
+ const dist = Math.sqrt(dr * dr + (c - IMPACT.c) ** 2)
137
+ if (t < 2 && dist < 2.6) return WHITE // a small flash right at the point of impact
138
+ if (t < 7 && dist < 4) {
139
+ // the struck spot glows hot, then fades straight back to chrome (no muddy brown)
140
+ const heat = t < 4 ? (EMBER[2] ?? WHITE) : (EMBER[1] ?? WHITE)
141
+ return mix(heat, chrome, Math.min(1, (t - 2) / 4 + dist / 6))
142
+ }
143
+ const radius = (t - 1) * 2.4
144
+ const d = Math.abs(dist - radius)
145
+ if (d < 1.2) return WHITE
146
+ if (d < 3) return mix(WHITE, chrome, (d - 1.2) / 1.8)
147
+ }
148
+ // Still warm: the underside keeps a faint, slowly breathing ember glow.
149
+ const warm = Math.max(0, (r - 3) / 5) * (0.24 + 0.1 * Math.sin(f / 4 + c / 3))
150
+ const settle = Math.min(1, (f - FORGE - 6) / 8)
151
+ return warm > 0 && settle > 0 ? mix(chrome, EMBER[0] ?? WHITE, warm * settle) : chrome
152
+ }
153
+
154
+ // Upward-facing edges of the F: the blank cell just above each top surface is where flames lick.
155
+ const EDGES = []
156
+ MARK.forEach((line, r) => [...line].forEach((ch, c) => {
157
+ if (ch !== ' ' && (r === 0 || (MARK[r - 1]?.[c] ?? ' ') === ' ')) EDGES.push({ r: r - 1, c, age0: r * 0.6 + c })
158
+ }))
159
+
160
+ // How hot the fire is along an edge cell at frame f (0 = none, 1 = roaring).
161
+ function heat(e , f ) {
162
+ let h = 0
163
+ if (f < FORGE + 10) {
164
+ const age = (f / FORGE) * (MW + 6) - e.age0 // same front that forges the mark
165
+ if (age > 0) h = age < 6 ? 1 : Math.max(0, 1 - (age - 6) / 10)
166
+ }
167
+ const t = f - BONK
168
+ if (t >= 0 && t < 6) h = Math.max(h, (1 - t / 6) * Math.max(0, 1 - Math.abs(e.c - IMPACT.c) / 7))
169
+ if (f >= FORGE + 10) h = Math.max(h, 0.26) // a low, living flame once settled
170
+ return h
171
+ }
172
+
173
+ function fire(f , put ) {
174
+ const LV = ['░', '░', '▒', '▒', '▓', '▄']
175
+ for (const e of EDGES) {
176
+ const h = heat(e, f) * (0.55 + 0.45 * noise(e.c, Math.floor(f / 2)))
177
+ if (h < 0.12) continue
178
+ const i = Math.min(LV.length - 1, Math.floor(h * LV.length))
179
+ // deep red at the base of the range, orange through the body, yellow only in the hottest core
180
+ const color = h > 0.95 ? (EMBER[2] ?? WHITE) : ramp([FLAME_RED, EMBER[0] ?? WHITE, EMBER[1] ?? WHITE, EMBER[2] ?? WHITE], h * 0.8)
181
+ put(e.r + TOP, e.c, { ch: LV[i] ?? '▁', color })
182
+ }
183
+ }
184
+
185
+ // Fresh off the anvil: a puff of quench steam as the metal cools.
186
+ function steam(f , put ) {
187
+ const t = f - (FORGE + 3)
188
+ if (t < 0 || t > 12) return
189
+ for (let i = 0; i < 6; i++) {
190
+ const start = i * 1.5
191
+ const a = t - start
192
+ if (a < 0 || a > 7) continue
193
+ const c = 13 + i * 3 + Math.round(Math.sin(a / 1.3 + i) * 1.2)
194
+ const r = TOP - 1 + (a < 3 ? 1 : 0) // hugs the bar, then lifts into the headroom
195
+ put(r, c, { ch: a < 5 ? '~' : '·', color: mix(STEAM, BG, a / 8) })
196
+ }
197
+ }
198
+
199
+ // Embers drifting up off the mark.
200
+ function embers(f , put ) {
201
+ if (f < FORGE + 4) return
202
+ for (let i = 0; i < 9; i++) {
203
+ const period = 16 + (i % 4) * 3
204
+ const a = (f + i * 7) % period
205
+ if (a > 9) continue
206
+ const e = EDGES[Math.floor(noise(i, Math.floor((f + i * 7) / period)) * EDGES.length)]
207
+ if (!e) continue
208
+ const r = e.r + TOP - Math.floor(a / 2)
209
+ const c = e.c + Math.round(Math.sin(a / 2 + i) * 1.4)
210
+ const color = mix(EMBER[1] ?? WHITE, FLAME_RED, a / 9)
211
+ put(r, c, { ch: a < 5 ? '•' : '·', color, bold: a < 5 })
212
+ }
213
+ }
214
+
215
+ function clawd(f ) {
216
+ if (f < FORGE) return null
217
+ if (f < WALK_END) {
218
+ const t = (f - FORGE) / (WALK_END - FORGE)
219
+ const x = Math.round(START_X + (CLAWD_X - START_X) * easeOut(t))
220
+ const step = Math.floor(f / 2) % 2
221
+ return { x, lift: step, pose: step ? P.stepA : P.stepB } // a bouncy trot
222
+ }
223
+ if (f < LOOK_END) return { x: CLAWD_X, lift: 0, pose: P.look }
224
+ if (f < CROUCH_END) return { x: CLAWD_X, lift: 0, pose: P.crouch }
225
+ if (f < BONK) return { x: CLAWD_X, lift: Math.min(2, f - CROUCH_END + 1), pose: P.jump }
226
+ if (f === BONK) return { x: CLAWD_X, lift: 2, pose: P.jump }
227
+ if (f < LAND) return { x: CLAWD_X, lift: LAND - f, pose: P.jump }
228
+ if (f === LAND) return { x: CLAWD_X, lift: 0, pose: P.crouch }
229
+ if (f < DIZZY_END) return { x: CLAWD_X, lift: 0, pose: Math.floor((f - LAND) / 2) % 2 ? P.dizzyL : P.dizzyR }
230
+ if (f < HOLD_START) {
231
+ const k = (f - DIZZY_END) % 6
232
+ return { x: CLAWD_X, lift: k === 2 || k === 3 ? 1 : 0, pose: P.cheer }
233
+ }
234
+ if (f >= FADE_START) return { x: CLAWD_X, lift: 0, pose: Math.floor(f / 2) % 2 ? P.waveA : P.waveB } // bye!
235
+ // Idle: glance at the wordmark, wave hello, a happy hop, then a blink.
236
+ const k = f - HOLD_START
237
+ if (k >= 2 && k < 9) return { x: CLAWD_X, lift: 0, pose: P.side }
238
+ if (k >= 10 && k < 20) return { x: CLAWD_X, lift: 0, pose: Math.floor(k / 2) % 2 ? P.waveA : P.waveB }
239
+ if (k >= 21 && k < 25) return { x: CLAWD_X, lift: k === 22 || k === 23 ? 1 : 0, pose: P.cheer }
240
+ return { x: CLAWD_X, lift: 0, pose: k === 27 || k === 28 ? P.blink : P.stand }
241
+ }
242
+
243
+ // Sparks thrown from the impact: analytic paths with a little gravity.
244
+ const SPARKS = [
245
+ [1.2, -1.1], [2.2, -0.8], [3.2, -0.35], [3.8, 0.15], [2.8, 0.55], [1.6, 0.9], [4.4, -0.6], [0.6, -1.4],
246
+ ]
247
+ function sparks(f , put ) {
248
+ const t = f - BONK
249
+ if (t < 1 || t > 11) return
250
+ // Plain glyphs every terminal font has.
251
+ const glyph = ['*', '*', '*', '+', '+', '+', '•', '•', '·', '·', '.', '.'][t] ?? '.'
252
+ const color = t < 3 ? WHITE : t < 5 ? (EMBER[2] ?? WHITE) : t < 8 ? (EMBER[1] ?? WHITE) : (EMBER[0] ?? WHITE)
253
+ for (const [vx, vy] of SPARKS) {
254
+ const c = Math.round(IMPACT.c + 2 + (vx ?? 0) * t * 1.3)
255
+ const r = Math.round(IMPACT.r + (vy ?? 0) * t * 0.6 + 0.05 * t * t)
256
+ put(r, c, { ch: glyph, color, bold: t < 4 })
257
+ }
258
+ }
259
+
260
+ // Little extras that make Clawd feel alive: a "!" when it spots the bar, dizzy stars, floating hearts.
261
+ function cute(f , put ) {
262
+ const head = H - 4 // the row just above Clawd's head when standing
263
+ if (f >= WALK_END && f < LOOK_END) put(head, CLAWD_X + 4, { ch: '!', color: EMBER[2] ?? WHITE, bold: true }, true)
264
+ if (f > LAND && f < DIZZY_END) {
265
+ const a = (f - LAND) * 1.1
266
+ for (const off of [0, Math.PI]) {
267
+ const c = Math.round(CLAWD_X + 4 + Math.cos(a + off) * 3.5)
268
+ put(head - (Math.sin(a + off) > 0.3 ? 1 : 0), c, { ch: '*', color: EMBER[2] ?? WHITE, bold: true }, true)
269
+ }
270
+ }
271
+ // hearts float up and wobble out from Clawd while it cheers and waves
272
+ for (let i = 0; i < 6; i++) {
273
+ const born = DIZZY_END + 1 + i * 5
274
+ const age = f - born
275
+ if (age < 0 || age > 7 || born >= FADE_START) continue
276
+ const r = head - Math.floor(age * 0.7)
277
+ const c = CLAWD_X + 7 + (i % 2) + Math.round(Math.sin(age / 1.4 + i))
278
+ const color = mix(HEART, BG, Math.max(0, (age - 4) / 4))
279
+ put(r, c, { ch: age < 6 ? '♥' : '·', color, bold: age < 3 })
280
+ }
281
+ }
282
+
283
+ export function scene(f ) {
284
+ const grid = Array.from({ length: H }, () => Array.from({ length: CW }, () => ({ ch: ' ' })))
285
+ const put = (r , c , cell , over = false) => {
286
+ const row = grid[r]
287
+ if (!row || c < 0 || c >= CW) return
288
+ if (!over && row[c]?.ch !== ' ') return
289
+ row[c] = cell
290
+ }
291
+
292
+ MARK.forEach((line, r) =>
293
+ [...line].forEach((ch, c) => {
294
+ if (ch === ' ') return
295
+ const color = markColor(r, c, f)
296
+ if (color) put(r + TOP, c, { ch, color })
297
+ }),
298
+ )
299
+
300
+ // 2.5D depth: each forged cell casts a solid face to its right and below (light from the upper left).
301
+ const depth = mix(CHROME[3] ?? WHITE, BG, 0.3)
302
+ MARK.forEach((line, r) =>
303
+ [...line].forEach((ch, c) => {
304
+ if (ch === ' ' || !markColor(r, c, f)) return
305
+ const face = f < FORGE + 6 ? mix(EMBER[0] ?? WHITE, BG, 0.5) : depth
306
+ if (blank(r, c + 1)) put(r + TOP, c + 1, { ch: '▌', color: face })
307
+ if (blank(r + 1, c) && (ch === '█' || ch === '▄')) put(r + TOP + 1, c + 1, { ch: '▀', color: face })
308
+ }),
309
+ )
310
+
311
+ // Wordmark block: letters land white-hot and cool to ember.
312
+ if (f >= TYPE_START) {
313
+ const n = Math.min(WORD.length, f - TYPE_START + 1)
314
+ ;[...WORD.slice(0, n)].forEach((ch, i) => {
315
+ const age = f - TYPE_START - i
316
+ const settled = ramp(EMBER, i / WORD.length)
317
+ put(TOP + 2, TEXT_X + i, { ch, color: age < 1 ? WHITE : age < 3 ? mix(WHITE, settled, age / 3) : settled, bold: true })
318
+ })
319
+ }
320
+ if (f >= TYPE_END) [...'for Claude Code'].forEach((ch, i) => put(TOP + 3, TEXT_X + i, { ch, color: CLAUDE, bold: true }))
321
+ if (f >= HOLD_START) {
322
+ const pulse = ramp(EMBER, 0.5 + 0.5 * Math.sin((f - HOLD_START) / 3))
323
+ ;[...'» supercharged'].forEach((ch, i) => put(TOP + 5, TEXT_X + i, { ch, color: pulse, bold: true }))
324
+ }
325
+
326
+ const cd = clawd(f)
327
+ if (cd) {
328
+ const top = H - 3 - cd.lift
329
+ cd.pose.forEach((line, i) =>
330
+ [...line].forEach((ch, j) => {
331
+ if (ch !== ' ') put(top + i, cd.x + j, { ch, color: CLAUDE }, true)
332
+ }),
333
+ )
334
+ }
335
+ fire(f, put)
336
+ steam(f, put)
337
+ sparks(f, put)
338
+ embers(f, put)
339
+ cute(f, put)
340
+
341
+ // Fade everything to the background over the last beat.
342
+ const fade = f >= FADE_START ? (f - FADE_START + 1) / (LAST - FADE_START + 1) : 0
343
+
344
+ return grid.map(row => {
345
+ const runs = []
346
+ for (const cell of row) {
347
+ const color = cell.color && fade > 0 ? mix(cell.color, BG, fade) : cell.color
348
+ const last = runs[runs.length - 1]
349
+ if (last && last.color === color && last.bold === cell.bold) last.text += cell.ch
350
+ else runs.push({ text: cell.ch, color, bold: cell.bold })
351
+ }
352
+ // Drop trailing blanks so the band is no wider than it needs to be.
353
+ while (runs.length && !runs[runs.length - 1]?.color && !runs[runs.length - 1]?.text.trim()) runs.pop()
354
+ return runs
355
+ })
356
+ }