@feigi/fleet-ctl 0.0.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 (245) hide show
  1. package/.claude-plugin/plugin.json +9 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +18 -0
  4. package/agents/fleet-finisher.agent.md +7 -0
  5. package/agents/fleet-implementer-alt.agent.md +210 -0
  6. package/agents/fleet-implementer.agent.md +210 -0
  7. package/agents/fleet-merge-bot.agent.md +7 -0
  8. package/agents/fleet-review-comments.agent.md +40 -0
  9. package/agents/fleet-review-correctness.agent.md +43 -0
  10. package/agents/fleet-review-runner.agent.md +73 -0
  11. package/agents/fleet-review-silent-failure.agent.md +49 -0
  12. package/agents/fleet-review-simplify.agent.md +46 -0
  13. package/agents/fleet-review-snapshot.agent.md +24 -0
  14. package/agents/fleet-review-tests.agent.md +46 -0
  15. package/agents/fleet-review-types.agent.md +41 -0
  16. package/agents/fleet-review-verifier.agent.md +29 -0
  17. package/commands/review-and-fix.md +98 -0
  18. package/commands/run-merge-bot.md +357 -0
  19. package/commands/run-team-help.md +17 -0
  20. package/package.json +23 -0
  21. package/scripts/agent-test-dir-prose.test.mjs +59 -0
  22. package/scripts/agent-test.test.mjs +1636 -0
  23. package/scripts/ambient-git-vars-mjs-prose.test.mjs +354 -0
  24. package/scripts/ambient-git-vars-prose.test.mjs +192 -0
  25. package/scripts/ancestry-check-position-prose.test.mjs +175 -0
  26. package/scripts/apply-ruleset.test.mjs +420 -0
  27. package/scripts/arg-header-probes-prose.test.mjs +393 -0
  28. package/scripts/arg.mjs +600 -0
  29. package/scripts/arg.test.mjs +1354 -0
  30. package/scripts/board-cli.test.mjs +694 -0
  31. package/scripts/board-identity.test.mjs +429 -0
  32. package/scripts/board-liveness-banner.test.mjs +119 -0
  33. package/scripts/board-prev-shape.test.mjs +229 -0
  34. package/scripts/board-tryparse-null.test.mjs +119 -0
  35. package/scripts/board.html +471 -0
  36. package/scripts/board.mjs +2037 -0
  37. package/scripts/board.test.mjs +3086 -0
  38. package/scripts/brief-after-cut-prose.test.mjs +53 -0
  39. package/scripts/candidates-exit3-prose.test.mjs +302 -0
  40. package/scripts/candidates.mjs +674 -0
  41. package/scripts/candidates.test.mjs +2101 -0
  42. package/scripts/caveat-unification-prose.test.mjs +98 -0
  43. package/scripts/ci-comment-rot-prose.test.mjs +2025 -0
  44. package/scripts/ci-completes-premise-prose.test.mjs +257 -0
  45. package/scripts/ci-state-prose.test.mjs +113 -0
  46. package/scripts/ci-state.mjs +761 -0
  47. package/scripts/ci-state.test.mjs +1640 -0
  48. package/scripts/ci-vacuous-green.test.mjs +368 -0
  49. package/scripts/citation-sweep-prose.test.mjs +1572 -0
  50. package/scripts/claim-lifecycle.test.mjs +185 -0
  51. package/scripts/claim-ticket.sh +417 -0
  52. package/scripts/claim-ticket.test.mjs +1121 -0
  53. package/scripts/closing-keyword-prose.test.mjs +193 -0
  54. package/scripts/cockpit-launch-idempotent-prose.test.mjs +165 -0
  55. package/scripts/cockpit-tick-nonblocking.test.mjs +210 -0
  56. package/scripts/compute-board.mjs +579 -0
  57. package/scripts/compute-board.test.mjs +1060 -0
  58. package/scripts/compute-spend.mjs +329 -0
  59. package/scripts/compute-spend.test.mjs +451 -0
  60. package/scripts/cross-repo-citation-prose.test.mjs +156 -0
  61. package/scripts/cwd-isolation-pins.mjs +83 -0
  62. package/scripts/dedupe-guard-prose.test.mjs +243 -0
  63. package/scripts/derive-testcmd.sh +239 -0
  64. package/scripts/derive-testcmd.test.mjs +380 -0
  65. package/scripts/diff-stats.mjs +231 -0
  66. package/scripts/diff-stats.test.mjs +408 -0
  67. package/scripts/dispatch-block-golden-prose.test.mjs +1024 -0
  68. package/scripts/dispatch-block-pins-prose.test.mjs +615 -0
  69. package/scripts/drop-merged-label.sh +173 -0
  70. package/scripts/drop-merged-label.test.mjs +480 -0
  71. package/scripts/expected-jobs-prose.test.mjs +80 -0
  72. package/scripts/filing-bar-seat-prose.test.mjs +242 -0
  73. package/scripts/filing-claim-bar-prose.test.mjs +166 -0
  74. package/scripts/finisher-dispatch-premise-prose.test.mjs +312 -0
  75. package/scripts/finisher-halt-prose.test.mjs +106 -0
  76. package/scripts/finisher-name-prose.test.mjs +134 -0
  77. package/scripts/finisher-own-tree-prose.test.mjs +285 -0
  78. package/scripts/finisher-pin-race-prose.test.mjs +339 -0
  79. package/scripts/fix-applier-correction-rules-prose.test.mjs +201 -0
  80. package/scripts/fix-applier-result-file-prose.test.mjs +100 -0
  81. package/scripts/fleet-bootstrap +155 -0
  82. package/scripts/fleet-heartbeat.mjs +272 -0
  83. package/scripts/fleet-heartbeat.test.mjs +450 -0
  84. package/scripts/fleet-provenance +207 -0
  85. package/scripts/fleet-provenance.test.mjs +64 -0
  86. package/scripts/fleet-run +148 -0
  87. package/scripts/fleet-run.test.mjs +90 -0
  88. package/scripts/fleet-state.mjs +400 -0
  89. package/scripts/fleet-state.test.mjs +373 -0
  90. package/scripts/fleet-tick-prose.test.mjs +299 -0
  91. package/scripts/fleet-tick.mjs +832 -0
  92. package/scripts/fleet-tick.test.mjs +1332 -0
  93. package/scripts/force-with-lease-reason-prose.test.mjs +184 -0
  94. package/scripts/frontmatter-allowlist.json +64 -0
  95. package/scripts/frontmatter-check.mjs +256 -0
  96. package/scripts/frontmatter-check.test.mjs +436 -0
  97. package/scripts/git-env.mjs +124 -0
  98. package/scripts/git-env.test.mjs +149 -0
  99. package/scripts/git-status-untracked-mode-sweep.test.mjs +216 -0
  100. package/scripts/gone-walk.test.mjs +213 -0
  101. package/scripts/gp-sep-invariant-prose.test.mjs +188 -0
  102. package/scripts/head-moved-after-label-prose.test.mjs +233 -0
  103. package/scripts/immutable-body-claim-prose.test.mjs +413 -0
  104. package/scripts/implementer-model-tier.test.mjs +643 -0
  105. package/scripts/inflight-citation-prose.test.mjs +144 -0
  106. package/scripts/inflight-exit2-prose.test.mjs +81 -0
  107. package/scripts/inflight-probe-guard-prose.test.mjs +109 -0
  108. package/scripts/inflight-scan-scope-prose.test.mjs +57 -0
  109. package/scripts/inflight.sh +1106 -0
  110. package/scripts/inflight.test.mjs +2984 -0
  111. package/scripts/injection-control-prose.test.mjs +404 -0
  112. package/scripts/install-root-audit.test.mjs +464 -0
  113. package/scripts/instrument-check-prose.test.mjs +235 -0
  114. package/scripts/instruments.sh +394 -0
  115. package/scripts/instruments.test.mjs +787 -0
  116. package/scripts/issue-tracker-prose.test.mjs +71 -0
  117. package/scripts/json.sh +248 -0
  118. package/scripts/json.test.mjs +364 -0
  119. package/scripts/ledger-dispatch.test.mjs +516 -0
  120. package/scripts/ledger-grammar.mjs +85 -0
  121. package/scripts/ledger-grammar.test.mjs +142 -0
  122. package/scripts/ledger-read-require-file.test.mjs +197 -0
  123. package/scripts/ledger.mjs +1753 -0
  124. package/scripts/ledger.test.mjs +3554 -0
  125. package/scripts/line-distance-prose.test.mjs +245 -0
  126. package/scripts/liveness-rationale-prose.test.mjs +83 -0
  127. package/scripts/locale-pin-prose.test.mjs +189 -0
  128. package/scripts/member-outcome-prose.test.mjs +167 -0
  129. package/scripts/member-outcomes-header.test.mjs +148 -0
  130. package/scripts/member-outcomes-prose.test.mjs +63 -0
  131. package/scripts/member-outcomes.mjs +231 -0
  132. package/scripts/member-outcomes.test.mjs +507 -0
  133. package/scripts/member-prompt-prose.test.mjs +161 -0
  134. package/scripts/member-record.mjs +605 -0
  135. package/scripts/member-record.test.mjs +516 -0
  136. package/scripts/member-write-guard.mjs +279 -0
  137. package/scripts/member-write-guard.test.mjs +211 -0
  138. package/scripts/merge-commit-probe-prose.test.mjs +122 -0
  139. package/scripts/merge-gate.mjs +262 -0
  140. package/scripts/merge-gate.test.mjs +613 -0
  141. package/scripts/muted-git-guard-sweep.test.mjs +493 -0
  142. package/scripts/net-ssh-precedence-prose.test.mjs +91 -0
  143. package/scripts/net-watchdog-prose.test.mjs +79 -0
  144. package/scripts/net.sh +409 -0
  145. package/scripts/net.test.mjs +211 -0
  146. package/scripts/no-ci-gate-prose.test.mjs +108 -0
  147. package/scripts/no-undo-audit.sh +1134 -0
  148. package/scripts/no-undo-audit.test.mjs +3965 -0
  149. package/scripts/no-wave.test.mjs +138 -0
  150. package/scripts/node-floor-sweep.test.mjs +611 -0
  151. package/scripts/pointer-target-prose.test.mjs +186 -0
  152. package/scripts/pr-overlap.mjs +417 -0
  153. package/scripts/pr-overlap.test.mjs +695 -0
  154. package/scripts/printf-die-sweep.test.mjs +384 -0
  155. package/scripts/prompt-renderer.mjs +39 -0
  156. package/scripts/prompt-renderer.test.mjs +68 -0
  157. package/scripts/prose-pin.mjs +808 -0
  158. package/scripts/prose-pin.test.mjs +1034 -0
  159. package/scripts/prove-merge.sh +228 -0
  160. package/scripts/prove-merge.test.mjs +995 -0
  161. package/scripts/pull-table-relabel-prose.test.mjs +60 -0
  162. package/scripts/quiet-payload-prose.test.mjs +222 -0
  163. package/scripts/reap.sh +1768 -0
  164. package/scripts/reap.test.mjs +4395 -0
  165. package/scripts/reaping-prose.test.mjs +159 -0
  166. package/scripts/refuter-scratch-prose.test.mjs +135 -0
  167. package/scripts/release-label-required-prose.test.mjs +71 -0
  168. package/scripts/release-label-split-prose.test.mjs +169 -0
  169. package/scripts/release-ticket.sh +1716 -0
  170. package/scripts/release-ticket.test.mjs +5106 -0
  171. package/scripts/renovate-release-contract.test.mjs +379 -0
  172. package/scripts/repo-root.mjs +544 -0
  173. package/scripts/repo-root.test.mjs +873 -0
  174. package/scripts/reporter-output-rule-prose.test.mjs +208 -0
  175. package/scripts/review-agent-report-only.test.mjs +49 -0
  176. package/scripts/review-core-cwd-isolation.test.mjs +374 -0
  177. package/scripts/review-core-reads.test.mjs +478 -0
  178. package/scripts/review-core-refuter-scratch.test.mjs +148 -0
  179. package/scripts/review-core-snapshot-path.test.mjs +777 -0
  180. package/scripts/review-core-specialist-scratch.test.mjs +189 -0
  181. package/scripts/review-core-testcmd.test.mjs +288 -0
  182. package/scripts/review-core-unrun.test.mjs +530 -0
  183. package/scripts/review-core-unverified-discriminant.test.mjs +208 -0
  184. package/scripts/review-core.mjs +1028 -0
  185. package/scripts/review-eval-resolver-path.test.mjs +55 -0
  186. package/scripts/review-eval.mjs +197 -0
  187. package/scripts/review-host-fixture.mjs +73 -0
  188. package/scripts/review-in-run-retry.test.mjs +187 -0
  189. package/scripts/review-no-vendor-dispatch.test.mjs +45 -0
  190. package/scripts/review-path-default.test.mjs +796 -0
  191. package/scripts/review-runner-spawns.test.mjs +93 -0
  192. package/scripts/review-runner.test.mjs +155 -0
  193. package/scripts/review-tier-audit.test.mjs +140 -0
  194. package/scripts/run-artifact-pr-prose.test.mjs +341 -0
  195. package/scripts/run-merge-bot-prose.test.mjs +1391 -0
  196. package/scripts/scratch-partition-invariant-prose.test.mjs +74 -0
  197. package/scripts/scripts-path-citation-sweep.test.mjs +73 -0
  198. package/scripts/section-between-guard-prose.test.mjs +378 -0
  199. package/scripts/select-dimensions.test.mjs +674 -0
  200. package/scripts/shared-refusal.test.mjs +388 -0
  201. package/scripts/shell-traps-prose.test.mjs +507 -0
  202. package/scripts/shortlist.mjs +355 -0
  203. package/scripts/shortlist.test.mjs +366 -0
  204. package/scripts/slow-transport.mjs +72 -0
  205. package/scripts/snapshot-repo.test.mjs +772 -0
  206. package/scripts/snapshot-runner-audience-prose.test.mjs +129 -0
  207. package/scripts/spend-view.test.mjs +312 -0
  208. package/scripts/staleness-qualifier-prose.test.mjs +251 -0
  209. package/scripts/staleness-verdict-prose.test.mjs +142 -0
  210. package/scripts/staleness.mjs +414 -0
  211. package/scripts/staleness.test.mjs +893 -0
  212. package/scripts/stalled-member-liveness-prose.test.mjs +219 -0
  213. package/scripts/stash-prohibition-prose.test.mjs +313 -0
  214. package/scripts/strip-comments.mjs +44 -0
  215. package/scripts/tier-check.mjs +468 -0
  216. package/scripts/tier-check.test.mjs +726 -0
  217. package/scripts/tier-guard-gate-prose.test.mjs +216 -0
  218. package/scripts/tier-outcomes-header.test.mjs +586 -0
  219. package/scripts/tier-outcomes.mjs +441 -0
  220. package/scripts/tier-outcomes.test.mjs +342 -0
  221. package/scripts/tier-roles.mjs +250 -0
  222. package/scripts/tier-roles.test.mjs +316 -0
  223. package/scripts/tracker-block-copy-prose.test.mjs +288 -0
  224. package/scripts/triage-labels-gloss-prose.test.mjs +97 -0
  225. package/scripts/unattended-git-sweep.test.mjs +142 -0
  226. package/scripts/verify-sha-exit2-prose.test.mjs +269 -0
  227. package/scripts/verify-sha.sh +117 -0
  228. package/scripts/verify-sha.test.mjs +693 -0
  229. package/scripts/watcher-degraded-block.test.mjs +372 -0
  230. package/scripts/watcher-key-prose.test.mjs +106 -0
  231. package/scripts/within-run-pair-prose.test.mjs +208 -0
  232. package/scripts/worktree-audit.sh +482 -0
  233. package/scripts/worktree-audit.test.mjs +1407 -0
  234. package/scripts/worktree-head-prose.test.mjs +276 -0
  235. package/scripts/worktree-listing-sweep.test.mjs +217 -0
  236. package/scripts/worktree-model-prose.test.mjs +216 -0
  237. package/scripts/worktree.sh +470 -0
  238. package/skills/next-ticket/SKILL.md +138 -0
  239. package/skills/run-team/SKILL.md +3603 -0
  240. package/skills/run-team/references/ci-and-staleness.md +75 -0
  241. package/skills/run-team/references/correction-tickets.md +37 -0
  242. package/skills/run-team/references/isolation.md +23 -0
  243. package/skills/run-team/references/member-lifecycle.md +73 -0
  244. package/skills/run-team/references/reaping.md +73 -0
  245. package/skills/sizing-a-ticket/SKILL.md +39 -0
@@ -0,0 +1,471 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>fleet cockpit</title>
7
+ <style>
8
+ :root { color-scheme: dark; --bg:#0d1117; --panel:#161b22; --line:#30363d;
9
+ --fg:#e6edf3; --dim:#8b949e; --red:#f85149; --amber:#d29922; --green:#3fb950; --blue:#58a6ff; }
10
+ * { box-sizing: border-box; }
11
+ /* The page is the window's height (#1759): header, banner, attention strip,
12
+ spend panel and footer keep their natural height and never shrink; #board
13
+ takes the rest, and each column scrolls on its own past that. The board's
14
+ min-height is the floor for a window too short for the fixed parts — they
15
+ then overflow body and the PAGE scrolls, rather than squeezing the
16
+ columns to nothing or clipping anything off. */
17
+ body { margin:0; background:var(--bg); color:var(--fg);
18
+ font:14px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;
19
+ height:100vh; display:flex; flex-direction:column; }
20
+ /* Belt-and-braces: a flex item's own min-height:auto already stops it
21
+ shrinking below its content, so nothing here strictly needs flex:none to
22
+ hold its height — #board's own min-height:200px is what actually floors
23
+ the layout. Costs nothing to keep, and guards against a future rule on
24
+ any of these six children that would otherwise let it shrink. */
25
+ body > * { flex:none; }
26
+ header { display:flex; align-items:center; gap:12px; padding:10px 16px; border-bottom:1px solid var(--line); }
27
+ header h1 { font-size:15px; margin:0; font-weight:600; }
28
+ #age { color:var(--dim); font-size:12px; margin-left:auto; }
29
+ #stale-banner { display:none; background:var(--amber); color:#000; padding:6px 16px; font-weight:600; }
30
+ /* A stopped RUN, not stale data: red, because the fleet is not working and
31
+ its claimed tickets are stranded behind a label the next run's scan skips. */
32
+ #stale-banner.dead { background:var(--red); color:#fff; }
33
+ #attention { padding:8px 16px; border-bottom:1px solid var(--line); background:#2d1618; }
34
+ #attention:empty { display:none; }
35
+ .att { display:inline-block; margin:2px 10px 2px 0; }
36
+ .att .n { color:var(--blue); font-weight:600; }
37
+ .flag { color:var(--red); font-weight:600; }
38
+ #board { display:grid; grid-template-columns:repeat(5,1fr); grid-template-rows:minmax(0,1fr); gap:10px; padding:14px; align-items:start;
39
+ flex:1 1 0; min-height:200px; }
40
+ /* As tall as its content, capped at the board's height, then it scrolls. */
41
+ .col { background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:8px; min-height:80px;
42
+ max-height:100%; overflow-y:auto; }
43
+ /* Pinned while the cards scroll beneath. The negative margins stretch its
44
+ opaque background to the column's padding edge so no card shows around
45
+ it; the padding puts the text back exactly where the old margin had it.
46
+ top is -8px, not 0, because Chromium measures a sticky offset from the
47
+ scroller's padding edge — 0 would park it 8px down, cards showing above. */
48
+ .col h2 { font-size:11px; letter-spacing:.06em; color:var(--dim); margin:-8px -8px 0; padding:10px 12px 8px; text-transform:uppercase;
49
+ position:sticky; top:-8px; z-index:1; background:var(--panel); }
50
+ .col h2 span { color:var(--fg); }
51
+ .card { background:#0d1117; border:1px solid var(--line); border-radius:6px; padding:7px 8px; margin-bottom:7px; }
52
+ .card .top { display:flex; gap:6px; align-items:baseline; }
53
+ .card .n { color:var(--blue); font-weight:600; }
54
+ .card .title { color:var(--fg); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
55
+ .card .meta { color:var(--dim); font-size:12px; margin-top:3px; display:flex; gap:8px; flex-wrap:wrap; }
56
+ .card a { color:var(--blue); text-decoration:none; }
57
+ .dot { width:8px; height:8px; border-radius:50%; display:inline-block; vertical-align:middle; }
58
+ .dot.green{background:var(--green)} .dot.red{background:var(--red)} .dot.unknown{background:var(--dim)}
59
+ .badge { border:1px solid var(--line); border-radius:10px; padding:0 6px; }
60
+ .badge.flag { border-color:var(--red); color:var(--red); }
61
+ footer { color:var(--dim); padding:10px 16px; border-top:1px solid var(--line); font-size:12px; }
62
+ footer .filed { margin-top:4px; }
63
+ #spend { padding:0 14px 14px; }
64
+ #spend:empty { display:none; }
65
+ .spend-wrap { background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:10px 12px; }
66
+ .spend-hd { display:flex; align-items:baseline; gap:10px; margin-bottom:8px; }
67
+ .spend-hd h2 { font-size:11px; letter-spacing:.06em; color:var(--dim); margin:0; text-transform:uppercase; }
68
+ .spend-hd .lede { color:var(--fg); }
69
+ .spend-hd .note { color:var(--dim); font-size:11px; margin-left:auto; }
70
+ .spend-cols { display:grid; grid-template-columns:1fr 1fr; gap:18px; }
71
+ @media (max-width:900px) { .spend-cols { grid-template-columns:1fr; } }
72
+ .spend-cols h3 { font-size:11px; color:var(--dim); margin:0 0 6px; font-weight:600; letter-spacing:.04em; }
73
+ .srow { display:grid; grid-template-columns:8.5em 3.4em 1fr 3em; gap:8px; align-items:center; margin-bottom:3px; font-size:12px; }
74
+ .srow .lbl { color:var(--fg); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
75
+ .srow .num { color:var(--dim); text-align:right; }
76
+ .srow .pct { color:var(--dim); text-align:right; }
77
+ .bar { background:#0d1117; border-radius:3px; height:9px; overflow:hidden; }
78
+ .bar i { display:block; height:100%; background:var(--blue); }
79
+ .bar i.rev { background:var(--amber); }
80
+ </style>
81
+ </head>
82
+ <body>
83
+ <header><h1 id="heading">🛰 fleet cockpit</h1><span id="age"></span></header>
84
+ <div id="stale-banner"></div>
85
+ <div id="attention"></div>
86
+ <div id="board"></div>
87
+ <div id="spend"></div>
88
+ <footer id="footer"></footer>
89
+ <script>
90
+ const COLUMNS = ["POOL", "IMPLEMENTING", "REVIEW", "READY", "MERGED"];
91
+ let interval = 15;
92
+ let repoUrl = null; // full repo URL from the model (carries the host) — PR links, GHE-safe
93
+
94
+ // The instance's name, for the tab strip and the header (#1584). Two cockpits
95
+ // are two WORKSPACES, and until this the pair rendered one constant twice —
96
+ // the operator's only way to tell two open windows apart was to read the
97
+ // tickets on them. `repo` has ridden the payload since the board existed and
98
+ // nothing on the page ever read it.
99
+ //
100
+ // Truthiness, not a null check: `gh repo view` failing leaves gather()'s
101
+ // `repo` null, a malformed answer can leave it "", and the identity stub
102
+ // served before the first tick (#1660) carries no `repo` key at all. All
103
+ // three mean "this board cannot name its repo", and all three must render
104
+ // today's constant rather than `fleet cockpit — undefined`.
105
+ //
106
+ // Returned rather than assigned: this page is served as one self-contained
107
+ // file with no build and no DOM harness, so a decision is testable only as a
108
+ // pure function something can lift out of the source — the seam spendView and
109
+ // ledgerBanner already use.
110
+ const TITLE = "fleet cockpit";
111
+ function boardTitle(repo) { return repo ? `${TITLE} — ${repo}` : TITLE; }
112
+
113
+ const el = (t, cls, txt) => { const e = document.createElement(t); if (cls) e.className = cls; if (txt != null) e.textContent = txt; return e; };
114
+ const mins = (ms) => Math.floor((Date.now() - ms) / 60000);
115
+
116
+ // A run's headline is routinely tens of millions, where "48785k" is unreadable.
117
+ const k = (n) => (n >= 1e6 ? (n / 1e6).toFixed(1) + "M" : n >= 1000 ? (n / 1000).toFixed(0) + "k" : String(Math.round(n)));
118
+
119
+ function spendRows(host, items, { label, value, pct, highlight }) {
120
+ for (const it of items) {
121
+ const row = el("div", "srow");
122
+ const lbl = el("span", "lbl", label(it));
123
+ lbl.title = label(it); // the column ellipsises; long tool names are unreadable without this
124
+ row.append(lbl, el("span", "num", value(it)));
125
+ const bar = el("div", "bar");
126
+ const fill = el("i", highlight?.(it) ? "rev" : null);
127
+ fill.style.width = Math.max(1, Math.round(pct(it))) + "%";
128
+ bar.append(fill);
129
+ row.append(bar, el("span", "pct", pct(it).toFixed(0) + "%"));
130
+ host.append(row);
131
+ }
132
+ }
133
+
134
+ // Which of the spend panel's outcomes the tri-state `spend` contract lands on,
135
+ // and the strings that outcome needs — as a value, with no DOM touched. The
136
+ // branching lives here rather than in renderSpend below because this page has no
137
+ // other test seam: it is served as one self-contained file, so a test reaches
138
+ // this decision only by lifting it out of the source and calling it directly,
139
+ // which spend-view.test.mjs does. That gap is not academic — the falsy-cacheWrite
140
+ // case below shipped broken and its fix shipped untested, because until this
141
+ // split there was nothing a test could call (#371).
142
+ //
143
+ // `kind` is the tag the renderer switches on; "hidden" appends nothing at all.
144
+ // Both text-only outcomes carry the same `text` field because both render as one
145
+ // `spend-wrap` div, differing only in wording.
146
+ function spendView(sp) {
147
+ // #916's phrase, shared by both the early note-only branch and the funded
148
+ // panel's note below, so a rewording can't update one copy and silently
149
+ // miss the other. It names the LINES, not the files: one transcript can
150
+ // hold several damaged lines, and "1 transcript damaged" would read as a
151
+ // whole agent lost — which is what `skipped` means and this does not.
152
+ const damagedPhrase = (n, suffix = "") => `${n} damaged transcript line${n === 1 ? "" : "s"}${suffix}`;
153
+ if (!sp) return { kind: "hidden" }; // genuinely nothing yet — normal at run start
154
+ // A read failure is a bug the operator has to act on, and it used to look
155
+ // exactly like an idle run. stderr is not a channel here: the board is
156
+ // launched backgrounded and the operator is watching this page, not a log.
157
+ //
158
+ // Switch on `ok`, gatherSpend's explicit tag, and never on `error`. Reading
159
+ // the error case off `error`'s truthiness was #959: `{ error: "" }` and
160
+ // `{ error: undefined }` — both of which the producer's outer catch can emit,
161
+ // from a message-less throw and a thrown non-Error — matched neither this
162
+ // branch nor a success shape, so they fell through, found no totals, and HID
163
+ // the panel. That is the fault-as-idle-run conflation this branch exists to
164
+ // remove, reappearing one field over.
165
+ //
166
+ // `!sp.ok`, not `sp.ok === false`, so an UNTAGGED payload is an error too.
167
+ // That direction is deliberate: an old `board.json` still on disk after an
168
+ // upgrade renders a loud "spend unavailable" and self-heals on the next tick
169
+ // (~15s), where the other bias would route a legacy `{ error: "…" }` to
170
+ // hidden — trading a visible, temporary wrong answer for an invisible one.
171
+ //
172
+ // An empty or absent message loses only the wording, never the panel: the tag
173
+ // has already decided. `|| "no reason given"` is `ledger.mjs`'s idiom for the
174
+ // same shape ("gh failed without saying why").
175
+ if (!sp.ok) return { kind: "error", text: "spend unavailable: " + (sp.error || "no reason given") };
176
+ // Zeroes would read as "this run was free", a worse lie than absence — but a
177
+ // skipped count is not a zero, and hiding it here re-created the exact
178
+ // conflation this panel exists to remove: "3 of 4 transcripts unreadable"
179
+ // rendered identically to "nothing yet". stderr does not cover it (see
180
+ // above), so the note goes out on its own, without the zeroed two-column body.
181
+ if (!sp.totals || !sp.totals.cacheWrite) {
182
+ // #916's worst case: when a damaged line WAS the run's only cache-creation
183
+ // turn there is nothing left to sum, so cache-write is 0 with `skipped`
184
+ // also 0 — a freshly-dispatched agent with no cache-creation turn flushed
185
+ // yet can land here too, which is why `damaged` alone, without `skipped`,
186
+ // must still be checked rather than assumed impossible. Measured before
187
+ // `damaged` existed, that run rendered `hidden` — a destroyed run shown
188
+ // as a run that had not started.
189
+ const bits = [];
190
+ if (sp.skipped) bits.push(`${sp.skipped} transcript${sp.skipped === 1 ? "" : "s"} skipped`);
191
+ if (sp.damaged) bits.push(damagedPhrase(sp.damaged));
192
+ return bits.length
193
+ ? { kind: "note", text: `${bits.join("; ")}; no spend recorded yet` }
194
+ : { kind: "hidden" };
195
+ }
196
+ return {
197
+ kind: "panel",
198
+ lede: `${k(sp.totals.cacheWrite)} cache-write · ${k(sp.totals.cacheRead)} cache-read · ${k(sp.totals.output)} output · ${sp.totals.agents} agents · review ${sp.reviewPct.toFixed(0)}%`,
199
+ // `skipped` means "contributed nothing"; `damaged` means "contributed, but
200
+ // may be missing the torn line's tool_use blocks and output_tokens
201
+ // snapshot" (#916) — cache_creation/cache_read repeat on every line
202
+ // of a turn and survive a mid-turn tear, so the panel's totals are not
203
+ // necessarily short. Two different
204
+ // lies, so two different phrases, both routed through the one channel that
205
+ // already reaches the browser every tick. Listed in that order: most spend
206
+ // lost first, so the one that most changes how to read the lede is read
207
+ // first.
208
+ note: [
209
+ sp.skipped ? `${sp.skipped} transcript${sp.skipped === 1 ? "" : "s"} skipped` : null,
210
+ sp.damaged ? damagedPhrase(sp.damaged, " — spend may be incomplete") : null,
211
+ "ranked on cache-creation; tool split is attributed, not billed",
212
+ ].filter(Boolean).join("; "),
213
+ // These bars are percentages of the ATTRIBUTED subtotal, not of the headline
214
+ // number: only a turn FOLLOWING a tool result can be charged to a tool, and an
215
+ // agent's first turn — usually its single largest write — follows nothing. Say
216
+ // what fraction is covered, so the two columns are not read as one base.
217
+ // `!= null` rather than truthiness, so a genuine 0% still says so.
218
+ toolHeading: sp.attributedPct != null
219
+ ? `by tool — ${sp.attributedPct.toFixed(0)}% of cache-write attributed`
220
+ : "by tool",
221
+ roles: sp.roles || [],
222
+ tools: (sp.tools || []).slice(0, 8),
223
+ };
224
+ }
225
+
226
+ // Two views of one run: WHO spent it (role) and WHAT it went on (tool). The two
227
+ // percentage columns do NOT share a base — role pct is over total cache-write,
228
+ // tool pct is over the attributable subset only (turns following a tool result).
229
+ // Read each column against itself, never across.
230
+ function renderSpend(sp) {
231
+ const host = document.getElementById("spend");
232
+ host.innerHTML = "";
233
+ const v = spendView(sp);
234
+ if (v.kind === "hidden") return;
235
+ if (v.kind !== "panel") { host.append(el("div", "spend-wrap", v.text)); return; }
236
+
237
+ const wrap = el("div", "spend-wrap");
238
+ const hd = el("div", "spend-hd");
239
+ hd.append(el("h2", null, "spend"));
240
+ hd.append(el("span", "lede", v.lede));
241
+ hd.append(el("span", "note", v.note));
242
+ wrap.append(hd);
243
+
244
+ const cols = el("div", "spend-cols");
245
+ const byRole = el("div");
246
+ byRole.append(el("h3", null, "by role"));
247
+ spendRows(byRole, v.roles, {
248
+ label: (r) => `${r.role} ×${r.agents}`,
249
+ value: (r) => k(r.cacheWrite),
250
+ pct: (r) => r.pct,
251
+ highlight: (r) => r.role === "reviewer" || r.role === "specialist",
252
+ });
253
+ const byTool = el("div");
254
+ byTool.append(el("h3", null, v.toolHeading));
255
+ spendRows(byTool, v.tools, {
256
+ label: (t) => `${t.tool} ×${t.calls}`,
257
+ value: (t) => k(t.cacheWrite),
258
+ pct: (t) => t.pct,
259
+ });
260
+ cols.append(byRole, byTool);
261
+ wrap.append(cols);
262
+ host.append(wrap);
263
+ }
264
+
265
+ function render(m) {
266
+ interval = m.interval || 15;
267
+ repoUrl = m.repoUrl || null;
268
+ // Every render, never once at startup: a board whose repo read fails on a
269
+ // later tick goes BACK to the constant, and one whose repo arrives late
270
+ // (the pre-first-tick stub carries none) picks it up on the tick after.
271
+ // The emoji stays out of the tab title — a tab strip has no room for it,
272
+ // and the document's own <title> is the constant this falls back to.
273
+ const name = boardTitle(m.repo);
274
+ document.title = name;
275
+ document.getElementById("heading").textContent = "🛰 " + name;
276
+ // attention strip
277
+ const att = document.getElementById("attention");
278
+ att.innerHTML = "";
279
+ for (const t of m.attention || []) {
280
+ const span = el("span", "att");
281
+ span.append(el("span", "n", "#" + t.issue), document.createTextNode(" "));
282
+ span.append(el("span", "flag", (t.flags || []).join(" ")));
283
+ att.append(span);
284
+ }
285
+ // columns — each built once and kept, its contents rewritten every tick
286
+ // (#1848). A column scrolls on its own (#1759) and a scroll offset lives on
287
+ // the element, so a tick that threw the columns away and built new ones
288
+ // jumped every column back to the top within one poll. Keeping the node
289
+ // keeps its scroll — and a scroll still in flight — with nothing to save
290
+ // or restore. #board's own children ARE the column cache: nothing else
291
+ // ever appends to or clears #board, so board.children[i] is always
292
+ // COLUMNS[i]'s node and no separate Map is needed to remember it (#1857
293
+ // review — a Map here could only ever agree with board.children or go
294
+ // silently stale against it, never disagree usefully). Every column's
295
+ // contents are built before any of them reach the DOM, so a ticket that
296
+ // makes card() throw partway through leaves EVERY column on the previous
297
+ // tick together — never some columns on the new tick and others frozen on
298
+ // the old one, a mixed-tick board that could look like a normal render
299
+ // (#1857 review; poll()'s own catch below still banners the failure).
300
+ const board = document.getElementById("board");
301
+ const q = m.queue || {};
302
+ const next = COLUMNS.map((name) => {
303
+ const inCol = (m.tickets || []).filter((t) => t.column === name);
304
+ const h = el("h2", null, name + " ");
305
+ // #2108: POOL's own count is `q.pool` — the same number, except that a
306
+ // capped pool read makes it `"100+"`, and a header reading a bare 100
307
+ // beside a footer reading 100+ would be the exact claim the `+` retracts.
308
+ h.append(el("span", null, String(name === "POOL" ? q.pool ?? inCol.length : inCol.length)));
309
+ return [h, ...inCol.map(card)];
310
+ });
311
+ COLUMNS.forEach((name, i) => {
312
+ let col = board.children[i];
313
+ if (!col) board.append(col = el("div", "col"));
314
+ col.replaceChildren(...next[i]);
315
+ });
316
+ renderSpend(m.spend);
317
+ // #2108: computed here, ahead of the footer, not only inside the banner
318
+ // arm below. The banner is a single slot behind a stale/stall/ledger
319
+ // priority chain (next section): whenever any of those also fires on the
320
+ // same tick, that chain's capMsg arm never runs, and an open-PR cap has no
321
+ // other surface — unlike the pool cap, which always keeps its `n+` in the
322
+ // header and footer above regardless of the banner. Appending it to the
323
+ // footer, which does not compete for that slot, is what stops a
324
+ // co-occurring higher-priority message from silently swallowing this one
325
+ // (found by review: capNotice was reachable but unrenderable whenever
326
+ // ledgerMsg/stallMsg/stale also held).
327
+ const capMsg = m.capNotice ? "⚠ " + m.capNotice : null;
328
+ // footer
329
+ const foot = document.getElementById("footer");
330
+ foot.innerHTML = "";
331
+ foot.append(el("div", null, `pool ${q.pool ?? 0} · supply ${q.supply ?? 0} · review-backlog ${q.reviewBacklog ?? 0}`));
332
+ if (capMsg) foot.append(el("div", null, capMsg));
333
+ const filed = el("div", "filed", `filed follow-ups (${(m.filed || []).length}): ` +
334
+ (m.filed || []).map((f) => "#" + f.issue).join(" "));
335
+ foot.append(filed);
336
+ // freshness
337
+ // #1713: exactly one payload reaches this page without a `generatedAt` —
338
+ // #1660's identity stub, written at bind time so a racing launch's probe has
339
+ // something to read. The page can now SEE it, because the cockpit answers
340
+ // HTTP while its first tick is still computing where it used to answer
341
+ // nothing at all until the tick was done. Only computeBoard() sets the
342
+ // field, so its absence means "no board built yet", not "a board of unknown
343
+ // age" — and `mins(undefined)` is NaN, which rendered as "updated NaNm ago".
344
+ const built = typeof m.generatedAt === "number";
345
+ document.getElementById("age").textContent = built ? "updated " + mins(m.generatedAt) + "m ago" : "building…";
346
+ const banner = document.getElementById("stale-banner");
347
+ const ledgerMsg = ledgerBanner(m.ledgerState);
348
+ const stallMsg = livenessBanner(m.liveness);
349
+ // #2108: best-effort placement in the single banner slot when nothing
350
+ // higher-priority holds it — ranked last, since stale/a stall/an unread
351
+ // ledger each say the board is wrong wholesale, versus this notice, which
352
+ // only says it may be short at one edge. The footer append above is what
353
+ // actually guarantees this notice reaches the operator on a tick where a
354
+ // higher-priority arm wins the slot instead.
355
+ // className reset on EVERY arm, never only on the arm that sets it: this
356
+ // element is reused across ticks, so a `dead` class left behind by an
357
+ // earlier render paints the next tick's ledger or stale message red. One
358
+ // assignment per arm is what makes that unreachable rather than unlikely.
359
+ if (built && Date.now() - m.generatedAt > interval * 1000 * 2) {
360
+ banner.style.display = "block";
361
+ banner.className = "";
362
+ banner.textContent = "⚠ data stale — server/controller stopped?";
363
+ } else if (stallMsg) {
364
+ banner.style.display = "block";
365
+ banner.className = "dead";
366
+ banner.textContent = stallMsg;
367
+ } else if (ledgerMsg) {
368
+ banner.style.display = "block";
369
+ banner.className = "";
370
+ banner.textContent = ledgerMsg;
371
+ } else if (capMsg) {
372
+ banner.style.display = "block";
373
+ banner.className = "";
374
+ banner.textContent = capMsg;
375
+ } else { banner.style.display = "none"; banner.className = ""; }
376
+ }
377
+
378
+ // The heartbeat's mark, rendered — #1597. A dead run's tickets keep the label
379
+ // that marks them in flight, and the candidate scan EXCLUDES that label, so a
380
+ // run that stopped silently costs the night AND strands its tickets out of
381
+ // sight of the next run's scans. This is the surface that says so while the
382
+ // cockpit is still up; fleet-tick's start says it when nothing survived.
383
+ //
384
+ // The words are NOT composed here. `text` is computed by compute-board.mjs
385
+ // through fleet-state.mjs's stallReport(), the same function fleet-tick
386
+ // prints, so the two surfaces cannot describe one dead run differently. This
387
+ // function owns exactly one decision — whether there is a banner at all —
388
+ // and a payload with no `text` yields no banner rather than an empty one.
389
+ // The `l` check alone already covers a board.json written before this field
390
+ // existed (`liveness` is simply absent there, `undefined`, caught by `l &&`)
391
+ // — what the SECOND guard defends against is a hand-edited or partially
392
+ // written board.json carrying a truthy `liveness` object with no `text` of
393
+ // its own: `⚠ undefined` is worse than no banner at all.
394
+ //
395
+ // Ranked BELOW "data stale" at the call site above, deliberately. A board
396
+ // that stopped updating cannot be trusted to say anything current about the
397
+ // beat — its liveness field is as old as the rest of it — and announcing a
398
+ // death off a frozen page is the cry-wolf direction. Above the ledger
399
+ // messages, which report a degraded read of one input; this reports that
400
+ // nobody is working the board at all.
401
+ function livenessBanner(l) {
402
+ return l && l.text ? "⚠ " + l.text : null;
403
+ }
404
+
405
+ // Three ledger states, three renderings (#816). `read` refuses an absent ledger
406
+ // under --require-file now, so gather() can tell "there was no ledger to read"
407
+ // from "read it, nothing filed yet" from "read it, the answer would not parse".
408
+ // All three used to arrive here as the same empty lists and drew the same empty
409
+ // board, which reads as a quiet run rather than a broken one.
410
+ //
411
+ // A ledger read empty gets no banner at all: it is the ordinary state of a run
412
+ // that has just started, and a warning there would fire on every first tick and
413
+ // train the operator to ignore this strip. Stale outranks both messages at the
414
+ // call site above — it says the whole board is old, not that one read failed.
415
+ function ledgerBanner(state) {
416
+ if (state === "unread") return "⚠ ledger not read — no ledger file, or it could not be read (see --ledger / stderr)";
417
+ if (state === "unparsed") return "⚠ ledger read did not parse — this board is incomplete";
418
+ return null;
419
+ }
420
+
421
+ function card(t) {
422
+ const c = el("div", "card");
423
+ const top = el("div", "top");
424
+ top.append(el("span", "n", "#" + t.issue));
425
+ top.append(el("span", "title", t.title || ""));
426
+ c.append(top);
427
+ const meta = el("div", "meta");
428
+ if (t.agent) meta.append(el("span", null, t.agent));
429
+ if (t.pr != null) {
430
+ const a = el("a", null, "PR#" + t.pr);
431
+ a.href = repoUrl ? repoUrl + "/pull/" + t.pr : "#";
432
+ a.target = "_blank"; a.rel = "noopener";
433
+ meta.append(a);
434
+ }
435
+ if (t.ci) { const d = el("span", "dot " + t.ci); meta.append(d); }
436
+ if (t.sinceEnteredStage) meta.append(el("span", null, mins(t.sinceEnteredStage) + "m"));
437
+ for (const f of t.flags || []) meta.append(el("span", "badge flag", f));
438
+ if (t.ruling) meta.append(el("span", "badge", "ruled:" + t.ruling));
439
+ c.append(meta);
440
+ return c;
441
+ }
442
+
443
+ function warn(msg) {
444
+ const banner = document.getElementById("stale-banner");
445
+ banner.style.display = "block";
446
+ banner.textContent = msg;
447
+ }
448
+
449
+ async function poll() {
450
+ let r;
451
+ try {
452
+ r = await fetch("/board.json", { cache: "no-store" });
453
+ } catch (e) {
454
+ warn("⚠ cockpit server not running"); // transport failure only — server unreachable
455
+ setTimeout(poll, interval * 1000);
456
+ return;
457
+ }
458
+ if (!r.ok) {
459
+ warn("⚠ board.json HTTP " + r.status); // server up, but no readable board yet (e.g. first tick failed)
460
+ } else {
461
+ // Parse + render sit OUTSIDE the transport try: a corrupt payload or a
462
+ // render bug is NOT a dead server, and must not be mislabelled as one.
463
+ try { render(await r.json()); }
464
+ catch (e) { warn("⚠ board render failed: " + e.message); }
465
+ }
466
+ setTimeout(poll, interval * 1000);
467
+ }
468
+ poll();
469
+ </script>
470
+ </body>
471
+ </html>