@aragon-agent/cli 0.6.43 → 0.6.45

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 (251) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +69 -2
  3. package/dist/agent/controller.d.ts +69 -0
  4. package/dist/agent/controller.js +224 -11
  5. package/dist/agent/governance-view.d.ts +40 -0
  6. package/dist/agent/governance-view.js +40 -0
  7. package/dist/agent/governance-wiring.d.ts +162 -0
  8. package/dist/agent/governance-wiring.js +470 -0
  9. package/dist/agent/plan-prompt.d.ts +7 -0
  10. package/dist/agent/plan-prompt.js +2 -1
  11. package/dist/agent/reducer.d.ts +33 -1
  12. package/dist/agent/reducer.js +45 -9
  13. package/dist/agent/system-prompt.d.ts +19 -0
  14. package/dist/agent/system-prompt.js +9 -1
  15. package/dist/cli.js +45 -1
  16. package/dist/commands/builtins.js +10 -4
  17. package/dist/commands/governance-command.d.ts +35 -0
  18. package/dist/commands/governance-command.js +292 -0
  19. package/dist/commands/governance-runs-table.d.ts +40 -0
  20. package/dist/commands/governance-runs-table.js +130 -0
  21. package/dist/commands/registry.d.ts +12 -0
  22. package/dist/config/app-paths.d.ts +10 -0
  23. package/dist/config/app-paths.js +12 -0
  24. package/dist/config/cli-commands.d.ts +18 -0
  25. package/dist/config/cli-commands.js +47 -1
  26. package/dist/config/env.d.ts +2 -1
  27. package/dist/config/env.js +10 -1
  28. package/dist/config/governance-config.d.ts +125 -0
  29. package/dist/config/governance-config.js +164 -0
  30. package/dist/config/governance-launch.d.ts +71 -0
  31. package/dist/config/governance-launch.js +58 -0
  32. package/dist/config/load.d.ts +15 -0
  33. package/dist/config/load.js +26 -1
  34. package/dist/config/model-profile-store.d.ts +4 -2
  35. package/dist/config/schema.d.ts +22 -0
  36. package/dist/config/schema.js +6 -0
  37. package/dist/config/store.js +14 -1
  38. package/dist/config/ui-state.d.ts +11 -0
  39. package/dist/config/ui-state.js +11 -0
  40. package/dist/diagnostics/doctor.js +20 -0
  41. package/dist/governance/card-normalize.d.ts +24 -0
  42. package/dist/governance/card-normalize.js +76 -0
  43. package/dist/governance/copy.d.ts +109 -0
  44. package/dist/governance/copy.js +223 -0
  45. package/dist/governance/engine/aftermath.d.ts +49 -0
  46. package/dist/governance/engine/aftermath.js +134 -0
  47. package/dist/governance/engine/artifact-persist.d.ts +35 -0
  48. package/dist/governance/engine/artifact-persist.js +86 -0
  49. package/dist/governance/engine/budget.d.ts +52 -0
  50. package/dist/governance/engine/budget.js +112 -0
  51. package/dist/governance/engine/cards.d.ts +18 -0
  52. package/dist/governance/engine/cards.js +186 -0
  53. package/dist/governance/engine/digest.d.ts +32 -0
  54. package/dist/governance/engine/digest.js +63 -0
  55. package/dist/governance/engine/engine-core.d.ts +219 -0
  56. package/dist/governance/engine/engine-core.js +562 -0
  57. package/dist/governance/engine/engine.d.ts +68 -0
  58. package/dist/governance/engine/engine.js +314 -0
  59. package/dist/governance/engine/estimate.d.ts +38 -0
  60. package/dist/governance/engine/estimate.js +46 -0
  61. package/dist/governance/engine/inspector.d.ts +16 -0
  62. package/dist/governance/engine/inspector.js +396 -0
  63. package/dist/governance/engine/integration.d.ts +35 -0
  64. package/dist/governance/engine/integration.js +220 -0
  65. package/dist/governance/engine/lifecycle.d.ts +29 -0
  66. package/dist/governance/engine/lifecycle.js +656 -0
  67. package/dist/governance/engine/pause.d.ts +56 -0
  68. package/dist/governance/engine/pause.js +107 -0
  69. package/dist/governance/engine/phase-members.d.ts +15 -0
  70. package/dist/governance/engine/phase-members.js +34 -0
  71. package/dist/governance/engine/phase-planner.d.ts +53 -0
  72. package/dist/governance/engine/phase-planner.js +282 -0
  73. package/dist/governance/engine/rebuild.d.ts +27 -0
  74. package/dist/governance/engine/rebuild.js +57 -0
  75. package/dist/governance/engine/report.d.ts +66 -0
  76. package/dist/governance/engine/report.js +220 -0
  77. package/dist/governance/engine/run-digest.d.ts +20 -0
  78. package/dist/governance/engine/run-digest.js +42 -0
  79. package/dist/governance/engine/spec-builder.d.ts +117 -0
  80. package/dist/governance/engine/spec-builder.js +321 -0
  81. package/dist/governance/engine/stage-runner.d.ts +22 -0
  82. package/dist/governance/engine/stage-runner.js +664 -0
  83. package/dist/governance/engine/start-input.d.ts +19 -0
  84. package/dist/governance/engine/start-input.js +111 -0
  85. package/dist/governance/engine/state-machine.d.ts +101 -0
  86. package/dist/governance/engine/state-machine.js +586 -0
  87. package/dist/governance/engine/submission-queries.d.ts +42 -0
  88. package/dist/governance/engine/submission-queries.js +97 -0
  89. package/dist/governance/engine/submission-render.d.ts +12 -0
  90. package/dist/governance/engine/submission-render.js +92 -0
  91. package/dist/governance/engine/submissions.d.ts +27 -0
  92. package/dist/governance/engine/submissions.js +455 -0
  93. package/dist/governance/engine/visibility.d.ts +104 -0
  94. package/dist/governance/engine/visibility.js +223 -0
  95. package/dist/governance/governed-dispatch.d.ts +19 -0
  96. package/dist/governance/governed-dispatch.js +17 -0
  97. package/dist/governance/limits.d.ts +107 -0
  98. package/dist/governance/limits.js +131 -0
  99. package/dist/governance/posture-transition.d.ts +38 -0
  100. package/dist/governance/posture-transition.js +44 -0
  101. package/dist/governance/posture.d.ts +35 -0
  102. package/dist/governance/posture.js +59 -0
  103. package/dist/governance/profiles.d.ts +48 -0
  104. package/dist/governance/profiles.js +140 -0
  105. package/dist/governance/prompts/orchestrator-block.d.ts +40 -0
  106. package/dist/governance/prompts/orchestrator-block.js +128 -0
  107. package/dist/governance/prompts/plan-addendum.d.ts +22 -0
  108. package/dist/governance/prompts/plan-addendum.js +60 -0
  109. package/dist/governance/prompts/refusals.d.ts +48 -0
  110. package/dist/governance/prompts/refusals.js +82 -0
  111. package/dist/governance/prompts/role-blocks.d.ts +40 -0
  112. package/dist/governance/prompts/role-blocks.js +255 -0
  113. package/dist/governance/report-reader.d.ts +31 -0
  114. package/dist/governance/report-reader.js +57 -0
  115. package/dist/governance/roles.d.ts +83 -0
  116. package/dist/governance/roles.js +142 -0
  117. package/dist/governance/rules/claims.d.ts +83 -0
  118. package/dist/governance/rules/claims.js +250 -0
  119. package/dist/governance/rules/elimination.d.ts +66 -0
  120. package/dist/governance/rules/elimination.js +105 -0
  121. package/dist/governance/rules/events-table.d.ts +46 -0
  122. package/dist/governance/rules/events-table.js +94 -0
  123. package/dist/governance/rules/failure-analysis.d.ts +28 -0
  124. package/dist/governance/rules/failure-analysis.js +93 -0
  125. package/dist/governance/rules/ledger-replay.d.ts +53 -0
  126. package/dist/governance/rules/ledger-replay.js +53 -0
  127. package/dist/governance/rules/ledger-state.d.ts +85 -0
  128. package/dist/governance/rules/ledger-state.js +175 -0
  129. package/dist/governance/rules/ledger.d.ts +228 -0
  130. package/dist/governance/rules/ledger.js +560 -0
  131. package/dist/governance/rules/rca.d.ts +68 -0
  132. package/dist/governance/rules/rca.js +220 -0
  133. package/dist/governance/rules/settlement.d.ts +129 -0
  134. package/dist/governance/rules/settlement.js +363 -0
  135. package/dist/governance/rules/suspicion.d.ts +66 -0
  136. package/dist/governance/rules/suspicion.js +169 -0
  137. package/dist/governance/store/artifacts.d.ts +81 -0
  138. package/dist/governance/store/artifacts.js +173 -0
  139. package/dist/governance/store/atomic.d.ts +79 -0
  140. package/dist/governance/store/atomic.js +119 -0
  141. package/dist/governance/store/events-log.d.ts +35 -0
  142. package/dist/governance/store/events-log.js +86 -0
  143. package/dist/governance/store/run-lock.d.ts +51 -0
  144. package/dist/governance/store/run-lock.js +122 -0
  145. package/dist/governance/store/run-store.d.ts +229 -0
  146. package/dist/governance/store/run-store.js +644 -0
  147. package/dist/governance/store/scoreboard-export.d.ts +53 -0
  148. package/dist/governance/store/scoreboard-export.js +65 -0
  149. package/dist/governance/tools/child-tools.d.ts +31 -0
  150. package/dist/governance/tools/child-tools.js +65 -0
  151. package/dist/governance/tools/guard.d.ts +71 -0
  152. package/dist/governance/tools/guard.js +194 -0
  153. package/dist/governance/tools/inspector-tools.d.ts +63 -0
  154. package/dist/governance/tools/inspector-tools.js +424 -0
  155. package/dist/governance/tools/lead-tools.d.ts +42 -0
  156. package/dist/governance/tools/lead-tools.js +226 -0
  157. package/dist/governance/tools/normalize-util.d.ts +101 -0
  158. package/dist/governance/tools/normalize-util.js +230 -0
  159. package/dist/governance/tools/scan-incomplete.d.ts +79 -0
  160. package/dist/governance/tools/scan-incomplete.js +486 -0
  161. package/dist/governance/tools/shared-tools.d.ts +44 -0
  162. package/dist/governance/tools/shared-tools.js +125 -0
  163. package/dist/governance/tools/submit-normalizers.d.ts +28 -0
  164. package/dist/governance/tools/submit-normalizers.js +474 -0
  165. package/dist/governance/tools/submit-tools.d.ts +26 -0
  166. package/dist/governance/tools/submit-tools.js +171 -0
  167. package/dist/governance/types.d.ts +661 -0
  168. package/dist/governance/types.js +27 -0
  169. package/dist/proc/kill-tree.d.ts +19 -1
  170. package/dist/proc/kill-tree.js +32 -5
  171. package/dist/proc/limits.d.ts +19 -0
  172. package/dist/proc/limits.js +19 -0
  173. package/dist/proc/supervisor.js +8 -1
  174. package/dist/session/validate-session.js +32 -1
  175. package/dist/team/runtime.d.ts +8 -0
  176. package/dist/team/runtime.js +9 -0
  177. package/dist/team/subagent.d.ts +23 -0
  178. package/dist/team/subagent.js +14 -3
  179. package/dist/team/types.d.ts +6 -0
  180. package/dist/tools/bounded-spawn.d.ts +56 -0
  181. package/dist/tools/bounded-spawn.js +76 -0
  182. package/dist/tools/index.d.ts +30 -7
  183. package/dist/tools/index.js +14 -0
  184. package/dist/tools/plan-tools.d.ts +14 -2
  185. package/dist/tools/plan-tools.js +5 -2
  186. package/dist/tools/search-tools.js +52 -44
  187. package/dist/ui/App.js +145 -25
  188. package/dist/ui/BottomStatusRow.js +1 -1
  189. package/dist/ui/Composer.d.ts +7 -1
  190. package/dist/ui/Composer.js +9 -6
  191. package/dist/ui/GovernancePanel.d.ts +50 -0
  192. package/dist/ui/GovernancePanel.js +77 -0
  193. package/dist/ui/GovernanceRun.d.ts +18 -0
  194. package/dist/ui/GovernanceRun.js +11 -0
  195. package/dist/ui/ScrollbackShell.d.ts +35 -7
  196. package/dist/ui/ScrollbackShell.js +1 -1
  197. package/dist/ui/StatusBar.d.ts +15 -2
  198. package/dist/ui/StatusBar.js +10 -4
  199. package/dist/ui/Transcript.js +3 -0
  200. package/dist/ui/entries/GovernanceCard.d.ts +30 -0
  201. package/dist/ui/entries/GovernanceCard.js +32 -0
  202. package/dist/ui/governance-copy.d.ts +69 -0
  203. package/dist/ui/governance-copy.js +104 -0
  204. package/dist/ui/governance-status.d.ts +145 -0
  205. package/dist/ui/governance-status.js +326 -0
  206. package/dist/ui/interaction-copy.d.ts +4 -0
  207. package/dist/ui/interaction-copy.js +5 -0
  208. package/dist/ui/interaction-hints.d.ts +17 -0
  209. package/dist/ui/interaction-hints.js +14 -2
  210. package/dist/ui/layout/governance-board.d.ts +121 -0
  211. package/dist/ui/layout/governance-board.js +382 -0
  212. package/dist/ui/layout/governance-card.d.ts +53 -0
  213. package/dist/ui/layout/governance-card.js +134 -0
  214. package/dist/ui/layout/governance-chip.d.ts +38 -0
  215. package/dist/ui/layout/governance-chip.js +64 -0
  216. package/dist/ui/layout/governance-panel.d.ts +85 -0
  217. package/dist/ui/layout/governance-panel.js +358 -0
  218. package/dist/ui/layout/governance-roster.d.ts +65 -0
  219. package/dist/ui/layout/governance-roster.js +275 -0
  220. package/dist/ui/layout/status-detail-layout.js +3 -3
  221. package/dist/ui/layout/status-layout.d.ts +5 -2
  222. package/dist/ui/layout/status-layout.js +10 -6
  223. package/dist/ui/layout/virtual-window.js +11 -0
  224. package/dist/ui/overlays/GovernanceBoardOverlay.d.ts +41 -0
  225. package/dist/ui/overlays/GovernanceBoardOverlay.js +76 -0
  226. package/dist/ui/overlays/GovernanceSettingsPage.d.ts +48 -0
  227. package/dist/ui/overlays/GovernanceSettingsPage.js +93 -0
  228. package/dist/ui/overlays/HelpOverlay.js +4 -3
  229. package/dist/ui/overlays/QuestionOverlay.d.ts +9 -1
  230. package/dist/ui/overlays/QuestionOverlay.js +4 -2
  231. package/dist/ui/overlays/SettingsScreen.d.ts +7 -0
  232. package/dist/ui/overlays/SettingsScreen.js +21 -1
  233. package/dist/ui/overlays/governance-settings.d.ts +79 -0
  234. package/dist/ui/overlays/governance-settings.js +140 -0
  235. package/dist/ui/overlays/model-profile-state.d.ts +6 -1
  236. package/dist/ui/overlays/model-profile-state.js +10 -0
  237. package/dist/ui/palettes.d.ts +17 -0
  238. package/dist/ui/palettes.js +9 -0
  239. package/dist/ui/scrollback/LiveTail.d.ts +3 -1
  240. package/dist/ui/scrollback/budget.d.ts +12 -6
  241. package/dist/ui/scrollback/budget.js +11 -4
  242. package/dist/ui/scrollback/live-preview.js +2 -0
  243. package/dist/ui/scrollback/settled-boundary.js +3 -0
  244. package/dist/ui/scrollback/tail-anchor.d.ts +5 -2
  245. package/dist/ui/scrollback/tail-anchor.js +3 -1
  246. package/dist/ui/shortcuts.js +2 -2
  247. package/dist/ui/theme.d.ts +7 -0
  248. package/dist/ui/theme.js +1 -0
  249. package/dist/ui/transcript-text.js +9 -0
  250. package/dist/ui/use-wheel-routing.js +3 -1
  251. package/package.json +2 -2
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The status bar's governance chip: pure width planning, no JSX
3
+ * (governance-mode section 10.2).
4
+ *
5
+ * ASCII ONLY - `src/ui/**` is inside `glyphs.test.ts::inScope`.
6
+ *
7
+ * SAME SHAPE AS `kit-chip.ts` / `session-chip.ts`, for the same reason: the status row is
8
+ * measured cell by cell, and a chip appended "just to the right" eats `phase`, the one
9
+ * field a user needs mid-run. The chip therefore competes for the SAME budget as every
10
+ * other field: it takes the longest rung that still leaves the left half its floor.
11
+ *
12
+ * THE LADDER (spec 10.2): `GOV p2/3 REVIEW` -> `GOV p2/3` -> `GOV`. A paused run reads
13
+ * `GOV paused`, one with a `/gov pause` still pending `GOV pausing` (warn tone: the stop is
14
+ * coming), an escalated one `GOV ! escalated` (warn tone - it is the run asking for
15
+ * the user), and a budget at or past 80% appends ` $` at every rung where there is room,
16
+ * because the hint is worth more than the stage name when space is short.
17
+ */
18
+ import type { GovernanceSnapshot } from '../../governance/types.js';
19
+ import { type Tone } from '../governance-status.js';
20
+ export declare const GOVERNANCE_CHIP_LIMITS: {
21
+ /** Blank cells between the chip and the field run. */
22
+ readonly gapCells: 2;
23
+ /** The floor the left half must keep; the same 34 the session and kit chips use. */
24
+ readonly minStatusCells: 34;
25
+ };
26
+ export interface GovernanceChipPlan {
27
+ visible: boolean;
28
+ text: string;
29
+ cells: number;
30
+ gap: number;
31
+ tone: Tone;
32
+ }
33
+ export interface GovernanceChipInput {
34
+ columns: number;
35
+ snapshot?: GovernanceSnapshot | null | undefined;
36
+ }
37
+ /** Plan the chip for `columns` and this session's live run snapshot. */
38
+ export declare function planGovernanceChip(input: GovernanceChipInput): GovernanceChipPlan;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The status bar's governance chip: pure width planning, no JSX
3
+ * (governance-mode section 10.2).
4
+ *
5
+ * ASCII ONLY - `src/ui/**` is inside `glyphs.test.ts::inScope`.
6
+ *
7
+ * SAME SHAPE AS `kit-chip.ts` / `session-chip.ts`, for the same reason: the status row is
8
+ * measured cell by cell, and a chip appended "just to the right" eats `phase`, the one
9
+ * field a user needs mid-run. The chip therefore competes for the SAME budget as every
10
+ * other field: it takes the longest rung that still leaves the left half its floor.
11
+ *
12
+ * THE LADDER (spec 10.2): `GOV p2/3 REVIEW` -> `GOV p2/3` -> `GOV`. A paused run reads
13
+ * `GOV paused`, one with a `/gov pause` still pending `GOV pausing` (warn tone: the stop is
14
+ * coming), an escalated one `GOV ! escalated` (warn tone - it is the run asking for
15
+ * the user), and a budget at or past 80% appends ` $` at every rung where there is room,
16
+ * because the hint is worth more than the stage name when space is short.
17
+ */
18
+ import { budgetState, isFinishedRun, isPausePending, activeStepKey, } from '../governance-status.js';
19
+ import { PIPELINE_LABEL, STATUS_WORD, phaseText } from '../governance-copy.js';
20
+ export const GOVERNANCE_CHIP_LIMITS = {
21
+ /** Blank cells between the chip and the field run. */
22
+ gapCells: 2,
23
+ /** The floor the left half must keep; the same 34 the session and kit chips use. */
24
+ minStatusCells: 34,
25
+ };
26
+ const HIDDEN = { visible: false, text: '', cells: 0, gap: 0, tone: 'muted' };
27
+ /** Candidate texts, longest first. ASCII `!` is the escalation mark in both glyph tiers. */
28
+ function rungs(snapshot) {
29
+ const budget = budgetState(snapshot);
30
+ const hint = budget === 'warn' || budget === 'over' ? ' $' : '';
31
+ if (isPausePending(snapshot)) {
32
+ return [`GOV ${STATUS_WORD.pausing}${hint}`, `GOV${hint}`];
33
+ }
34
+ if (snapshot.status === 'paused')
35
+ return [`GOV paused${hint}`, `GOV${hint}`];
36
+ if (snapshot.status === 'escalated') {
37
+ return [`GOV ! escalated${hint}`, `GOV !${hint}`, 'GOV !'];
38
+ }
39
+ const phase = phaseText(snapshot.phase, snapshot.phaseCount);
40
+ const stage = activeStepKey(snapshot);
41
+ const named = stage === null ? phase : `${phase} ${PIPELINE_LABEL[stage]}`;
42
+ return [`GOV ${named}${hint}`, `GOV ${phase}${hint}`, `GOV${hint}`, 'GOV'];
43
+ }
44
+ function chipTone(snapshot) {
45
+ if (snapshot.status === 'escalated' || budgetState(snapshot) === 'over')
46
+ return 'warn';
47
+ if (isPausePending(snapshot))
48
+ return 'warn';
49
+ return snapshot.status === 'paused' ? 'muted' : 'govern';
50
+ }
51
+ /** Plan the chip for `columns` and this session's live run snapshot. */
52
+ export function planGovernanceChip(input) {
53
+ const snapshot = input.snapshot;
54
+ if (!snapshot || isFinishedRun(snapshot.status))
55
+ return HIDDEN;
56
+ const columns = Number.isFinite(input.columns) ? Math.floor(input.columns) : 0;
57
+ const gap = GOVERNANCE_CHIP_LIMITS.gapCells;
58
+ for (const text of rungs(snapshot)) {
59
+ if (columns - (text.length + gap) >= GOVERNANCE_CHIP_LIMITS.minStatusCells) {
60
+ return { visible: true, text, cells: text.length, gap, tone: chipTone(snapshot) };
61
+ }
62
+ }
63
+ return HIDDEN;
64
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The legion panel's geometry: every decision `GovernancePanel` draws (governance-mode
3
+ * section 10.3), made in pure code so it can be tested without a terminal.
4
+ *
5
+ * Pure and total: no Ink, no clock (`now` is injected), no I/O. ASCII ONLY.
6
+ *
7
+ * THE COMPONENT ONLY COLOURS AND PLACES. Tier, header, step strip, roster columns and
8
+ * cell text, overflow line and ticker are all computed here; a test that wants to know
9
+ * what the panel says at 80 columns asks this module and never renders.
10
+ *
11
+ * FOUR TIERS, chosen from the terminal's size alone (`selectTier`):
12
+ * full >= 100 cols and >= 26 rows header + step strip + roster (with gauge) + ticker
13
+ * standard 80-99 cols (rows >= 26) the same without the activity column
14
+ * compact 60-79 cols, or rows < 26 header with the stage name + a bare roster
15
+ * minimal < 60 cols or rows < 20 ONE line
16
+ * and a tier that does not fit the caller's `availableRows` steps DOWN rather than
17
+ * overflowing - the band clamps the panel's height, and a clipped last row is the one
18
+ * outcome worse than a smaller tier.
19
+ */
20
+ import type { GovernanceSnapshot } from '../../governance/types.js';
21
+ import type { Glyphs } from '../glyphs.js';
22
+ import { type EliminatedSince, type Segment } from '../governance-status.js';
23
+ import { type PanelTier, type RosterColumn, type RosterLine } from './governance-roster.js';
24
+ export type { PanelTier } from './governance-roster.js';
25
+ export declare const PANEL_TIER_COLS: {
26
+ readonly full: 100;
27
+ readonly standard: 80;
28
+ readonly compact: 60;
29
+ };
30
+ export declare const PANEL_TIER_ROWS: {
31
+ readonly full: 26;
32
+ readonly minimal: 20;
33
+ };
34
+ /** Roster rows shown: `clamp(rows - 16, 2, 10)` (spec 10.3). */
35
+ export declare function maxRosterRows(rows: number): number;
36
+ /** The tier the terminal's size asks for, before any height budget is applied. */
37
+ export declare function selectTier(cols: number, rows: number): PanelTier;
38
+ /** One display line: a flexible left run and an optional right-anchored run. */
39
+ export interface PanelLine {
40
+ left: Segment[];
41
+ right: Segment[];
42
+ /** Cells the right run occupies (0 when there is none). */
43
+ rightCells: number;
44
+ }
45
+ export interface GovernancePanelInput {
46
+ cols: number;
47
+ rows: number;
48
+ snapshot: GovernanceSnapshot | null;
49
+ glyphs: Glyphs;
50
+ reducedMotion: boolean;
51
+ now: number;
52
+ /** `panel` while a stage runs; `run-strip` between stages (header + step strip only). */
53
+ mode?: 'panel' | 'run-strip';
54
+ /** Height budget the caller can spare; tiers step down to fit. Default unlimited. */
55
+ availableRows?: number;
56
+ /** First-seen-eliminated phases, so a replaced member leaves after one phase. */
57
+ eliminatedSince?: EliminatedSince;
58
+ }
59
+ export interface GovernancePanelLayout {
60
+ tier: PanelTier;
61
+ mode: 'panel' | 'run-strip';
62
+ /** Terminal columns this layout was built for. */
63
+ cols: number;
64
+ /** `cols` minus the margin: the budget every line is planned against. */
65
+ innerCols: number;
66
+ height: number;
67
+ header: PanelLine | null;
68
+ pipeline: PanelLine | null;
69
+ /** Width of the horizontal rule above and below the roster; 0 = no rules. */
70
+ ruleCells: number;
71
+ columns: RosterColumn[];
72
+ rosterRows: RosterLine[];
73
+ overflow: string | null;
74
+ ticker: PanelLine[];
75
+ }
76
+ export declare function segmentsCells(segments: readonly Segment[]): number;
77
+ /**
78
+ * Plan the panel for a terminal and a snapshot.
79
+ *
80
+ * `null` snapshot, or a finished run, plans to height 0 (nothing mounts - zero rows and
81
+ * zero layout shift, the `TeamPanel` D-11 rule). The caller's `availableRows` is a
82
+ * ceiling: tiers step down until one fits, and `minimal` is a single row or, with no row to
83
+ * spare, nothing.
84
+ */
85
+ export declare function buildGovernancePanelLayout(input: GovernancePanelInput): GovernancePanelLayout;
@@ -0,0 +1,358 @@
1
+ /**
2
+ * The legion panel's geometry: every decision `GovernancePanel` draws (governance-mode
3
+ * section 10.3), made in pure code so it can be tested without a terminal.
4
+ *
5
+ * Pure and total: no Ink, no clock (`now` is injected), no I/O. ASCII ONLY.
6
+ *
7
+ * THE COMPONENT ONLY COLOURS AND PLACES. Tier, header, step strip, roster columns and
8
+ * cell text, overflow line and ticker are all computed here; a test that wants to know
9
+ * what the panel says at 80 columns asks this module and never renders.
10
+ *
11
+ * FOUR TIERS, chosen from the terminal's size alone (`selectTier`):
12
+ * full >= 100 cols and >= 26 rows header + step strip + roster (with gauge) + ticker
13
+ * standard 80-99 cols (rows >= 26) the same without the activity column
14
+ * compact 60-79 cols, or rows < 26 header with the stage name + a bare roster
15
+ * minimal < 60 cols or rows < 20 ONE line
16
+ * and a tier that does not fit the caller's `availableRows` steps DOWN rather than
17
+ * overflowing - the band clamps the panel's height, and a clipped last row is the one
18
+ * outcome worse than a smaller tier.
19
+ */
20
+ import { formatCost, formatDuration, formatTokens } from '../../agent/usage.js';
21
+ import { activeStepKey, isFinishedRun, isPausePending, isRetired, segment, shortRunId, signedDeltaText, sortRoster, teamTokens, workingCount, } from '../governance-status.js';
22
+ import { GOV_TITLE, PANEL_BOARD_HINT, PANEL_HEALTH_LABEL, PANEL_LEDGER_LABEL, PANEL_TOKEN_UNIT, PIPELINE_LABEL, STATUS_WORD, moreText, phaseLongText, pausingText, phaseText, workingCountText, } from '../governance-copy.js';
23
+ import { cellWidth, fitCells } from './cells.js';
24
+ import { PANEL_MARGIN_CELLS, buildRosterLine, columnPlan, markerCells, } from './governance-roster.js';
25
+ export const PANEL_TIER_COLS = { full: 100, standard: 80, compact: 60 };
26
+ export const PANEL_TIER_ROWS = { full: 26, minimal: 20 };
27
+ /** Roster rows shown: `clamp(rows - 16, 2, 10)` (spec 10.3). */
28
+ export function maxRosterRows(rows) {
29
+ const free = Number.isFinite(rows) ? Math.floor(rows) - 16 : 0;
30
+ return Math.min(10, Math.max(2, free));
31
+ }
32
+ /** The tier the terminal's size asks for, before any height budget is applied. */
33
+ export function selectTier(cols, rows) {
34
+ if (cols < PANEL_TIER_COLS.compact || rows < PANEL_TIER_ROWS.minimal)
35
+ return 'minimal';
36
+ if (rows < PANEL_TIER_ROWS.full || cols < PANEL_TIER_COLS.standard)
37
+ return 'compact';
38
+ return cols >= PANEL_TIER_COLS.full ? 'full' : 'standard';
39
+ }
40
+ const NEXT_SMALLER = {
41
+ full: 'standard',
42
+ standard: 'compact',
43
+ compact: 'minimal',
44
+ minimal: null,
45
+ };
46
+ const EMPTY = {
47
+ tier: 'minimal',
48
+ mode: 'panel',
49
+ cols: 0,
50
+ innerCols: 0,
51
+ height: 0,
52
+ header: null,
53
+ pipeline: null,
54
+ ruleCells: 0,
55
+ columns: [],
56
+ rosterRows: [],
57
+ overflow: null,
58
+ ticker: [],
59
+ };
60
+ function nonNegativeInt(value) {
61
+ return Number.isFinite(value) ? Math.max(0, Math.floor(value)) : 0;
62
+ }
63
+ export function segmentsCells(segments) {
64
+ return segments.reduce((sum, part) => sum + cellWidth(part.text), 0);
65
+ }
66
+ function line(left, right = []) {
67
+ return { left, right, rightCells: segmentsCells(right) };
68
+ }
69
+ const SEPARATOR = ' ';
70
+ /** The parts joined by the glyph tier's middle dot, the dot itself in `muted`. */
71
+ function joined(parts, glyphs) {
72
+ const out = [];
73
+ parts.forEach((part, index) => {
74
+ if (index > 0)
75
+ out.push(segment(`${SEPARATOR}${glyphs.midDot}${SEPARATOR}`, 'muted'));
76
+ out.push(part);
77
+ });
78
+ return out;
79
+ }
80
+ // ---------------------------------------------------------------------------
81
+ // Header
82
+ // ---------------------------------------------------------------------------
83
+ function stageWord(snapshot) {
84
+ const key = activeStepKey(snapshot);
85
+ return key === null ? '' : PIPELINE_LABEL[key];
86
+ }
87
+ function statusSegments(snapshot) {
88
+ // A pending `/gov pause` outranks the plain status: the run is still executing, and the
89
+ // one thing the user needs to see is that the stop is coming and nothing is killed.
90
+ if (isPausePending(snapshot)) {
91
+ return [segment(pausingText(stageWord(snapshot)), 'warn', true)];
92
+ }
93
+ if (snapshot.status === 'paused')
94
+ return [segment(STATUS_WORD.paused, 'warn', true)];
95
+ if (snapshot.status === 'escalated')
96
+ return [segment(STATUS_WORD.escalated, 'warn', true)];
97
+ return [];
98
+ }
99
+ /** The right-hand figures, most expendable last: cost, then tokens, then health. */
100
+ function headerFigures(snapshot, withCost) {
101
+ const figures = [];
102
+ if (snapshot.health !== null) {
103
+ figures.push([
104
+ segment(`${PANEL_HEALTH_LABEL} `, 'muted'),
105
+ segment(String(Math.round(snapshot.health)), 'text', true),
106
+ ]);
107
+ }
108
+ figures.push([segment(`${formatTokens(teamTokens(snapshot))} ${PANEL_TOKEN_UNIT}`, 'muted')]);
109
+ if (withCost && snapshot.usage.costUsd !== null) {
110
+ figures.push([segment(formatCost(snapshot.usage.costUsd), 'muted')]);
111
+ }
112
+ return figures;
113
+ }
114
+ function spaced(figures) {
115
+ const out = [];
116
+ figures.forEach((figure, index) => {
117
+ if (index > 0)
118
+ out.push(segment(' ', 'muted'));
119
+ out.push(...figure);
120
+ });
121
+ return out;
122
+ }
123
+ function buildHeader(snapshot, inner, now, glyphs, withCost) {
124
+ const elapsed = formatDuration(Math.max(0, now - snapshot.startedAt));
125
+ const parts = [
126
+ segment(`run ${shortRunId(snapshot.runId)}`, 'muted'),
127
+ segment(phaseLongText(snapshot.phase, snapshot.phaseCount), 'text'),
128
+ ];
129
+ // `pausing after REVIEW` already names the stage; saying it twice is noise on a short row.
130
+ const stage = isPausePending(snapshot) ? '' : stageWord(snapshot);
131
+ if (stage !== '')
132
+ parts.push(segment(stage, 'primary', true));
133
+ parts.push(segment(elapsed, 'muted'));
134
+ const title = [segment(GOV_TITLE, 'govern', true), ...statusSegments(snapshot).flatMap((s) => [
135
+ segment(' ', 'muted'),
136
+ s,
137
+ ])];
138
+ const left = [...title, segment(' ', 'muted'), ...joined(parts, glyphs)];
139
+ const figures = headerFigures(snapshot, withCost);
140
+ while (figures.length > 0) {
141
+ const right = spaced(figures);
142
+ if (segmentsCells(left) + segmentsCells(right) + 2 <= inner)
143
+ return line(left, right);
144
+ figures.pop();
145
+ }
146
+ return line(left);
147
+ }
148
+ /** Compact header: the stage name replaces the step strip (spec 10.3). */
149
+ function buildCompactHeader(snapshot, inner, now, glyphs) {
150
+ const parts = [segment(phaseText(snapshot.phase, snapshot.phaseCount), 'text')];
151
+ const stage = isPausePending(snapshot) ? '' : stageWord(snapshot);
152
+ if (stage !== '')
153
+ parts.push(segment(stage, 'primary', true));
154
+ parts.push(segment(formatDuration(Math.max(0, now - snapshot.startedAt)), 'muted'));
155
+ const title = [segment(GOV_TITLE, 'govern', true), ...statusSegments(snapshot).flatMap((s) => [
156
+ segment(' ', 'muted'),
157
+ s,
158
+ ])];
159
+ const left = [...title, segment(' ', 'muted'), ...joined(parts, glyphs)];
160
+ if (snapshot.health === null)
161
+ return line(left);
162
+ const right = [
163
+ segment(`${PANEL_HEALTH_LABEL} `, 'muted'),
164
+ segment(String(Math.round(snapshot.health)), 'text', true),
165
+ ];
166
+ return segmentsCells(left) + segmentsCells(right) + 2 <= inner ? line(left, right) : line(left);
167
+ }
168
+ // ---------------------------------------------------------------------------
169
+ // Step strip
170
+ // ---------------------------------------------------------------------------
171
+ function stepSegments(snapshot, glyphs) {
172
+ return snapshot.pipeline.map((step) => {
173
+ const label = PIPELINE_LABEL[step.key];
174
+ if (step.state === 'done') {
175
+ return [segment(label, 'ok'), segment(` ${glyphs.check}`, 'ok')];
176
+ }
177
+ if (step.state === 'active')
178
+ return [segment(`${glyphs.cursor}${label}`, 'govern', true)];
179
+ return [segment(label, 'muted')];
180
+ });
181
+ }
182
+ function flattenSteps(steps, glyphs, leadingGap) {
183
+ const out = leadingGap
184
+ ? [segment(`${glyphs.ellipsis} ${glyphs.hrule} `, 'muted')]
185
+ : [];
186
+ steps.forEach((step, index) => {
187
+ if (index > 0)
188
+ out.push(segment(` ${glyphs.hrule} `, 'border'));
189
+ out.push(...step);
190
+ });
191
+ return out;
192
+ }
193
+ /**
194
+ * The step strip, with the rework note right-anchored. A strip too wide for the row loses
195
+ * its OLDEST steps first (they are the ones already done), marked with a leading ellipsis,
196
+ * so the current step and what is still to come always stay visible.
197
+ */
198
+ function buildPipeline(snapshot, inner, glyphs) {
199
+ const steps = stepSegments(snapshot, glyphs);
200
+ if (steps.length === 0)
201
+ return null;
202
+ const note = snapshot.reworkNote === null ? [] : [segment(snapshot.reworkNote, 'warn')];
203
+ const noteCells = segmentsCells(note);
204
+ const activeIndex = Math.max(0, snapshot.pipeline.findIndex((s) => s.state === 'active'));
205
+ for (const withNote of note.length > 0 ? [true, false] : [false]) {
206
+ const budget = inner - (withNote ? noteCells + 2 : 0);
207
+ for (let start = 0; start <= Math.min(activeIndex, steps.length - 1); start += 1) {
208
+ const left = flattenSteps(steps.slice(start), glyphs, start > 0);
209
+ if (segmentsCells(left) <= budget)
210
+ return line(left, withNote ? note : []);
211
+ }
212
+ }
213
+ return line(flattenSteps(steps.slice(activeIndex), glyphs, activeIndex > 0));
214
+ }
215
+ // ---------------------------------------------------------------------------
216
+ // Ticker
217
+ // ---------------------------------------------------------------------------
218
+ function tickerEntry(row) {
219
+ const amount = signedDeltaText(row.delta, row.provisional);
220
+ return `${row.agentId} ${amount} ${row.code} ${row.reason}`.replace(/\s+/g, ' ').trim();
221
+ }
222
+ /**
223
+ * The ledger ticker: the most recent entries, newest first, joined by a middle dot.
224
+ *
225
+ * An ALERT outranks it. A budget warning or an escalation is the one thing the panel
226
+ * cannot afford to scroll past, and the row is already the panel's quiet last line.
227
+ */
228
+ function buildTicker(snapshot, inner, glyphs) {
229
+ const alert = snapshot.alerts[0];
230
+ if (alert !== undefined) {
231
+ const text = fitCells(`${glyphs.warn} ${alert}`, inner, glyphs.ellipsis);
232
+ return [line([segment(text, 'warn')])];
233
+ }
234
+ if (snapshot.recent.length === 0)
235
+ return [];
236
+ const label = `${PANEL_LEDGER_LABEL} `;
237
+ const separator = ` ${glyphs.midDot} `;
238
+ const budget = Math.max(0, inner - cellWidth(label));
239
+ let body = '';
240
+ // Sorted by time here rather than trusting the producer's order: the ticker's whole
241
+ // meaning is "newest first".
242
+ for (const row of [...snapshot.recent].sort((a, b) => b.at - a.at)) {
243
+ const next = body === '' ? tickerEntry(row) : `${body}${separator}${tickerEntry(row)}`;
244
+ if (body !== '' && cellWidth(next) > budget)
245
+ break;
246
+ body = next;
247
+ }
248
+ const shown = fitCells(body, budget, glyphs.ellipsis);
249
+ return [line([segment(label, 'muted'), segment(shown, 'text')])];
250
+ }
251
+ // ---------------------------------------------------------------------------
252
+ // Minimal tier
253
+ // ---------------------------------------------------------------------------
254
+ function minimalCandidates(snapshot, glyphs) {
255
+ const status = isPausePending(snapshot)
256
+ ? ` ${STATUS_WORD.pausing}`
257
+ : snapshot.status === 'paused' || snapshot.status === 'escalated'
258
+ ? ` ${STATUS_WORD[snapshot.status]}`
259
+ : '';
260
+ const stage = stageWord(snapshot);
261
+ const base = `${GOV_TITLE}${status} ${phaseText(snapshot.phase, snapshot.phaseCount)}`;
262
+ const staged = stage === '' ? base : `${base} ${stage}`;
263
+ const dot = ` ${glyphs.midDot} `;
264
+ const working = workingCountText(workingCount(snapshot));
265
+ const health = snapshot.health === null
266
+ ? ''
267
+ : `${dot}${PANEL_HEALTH_LABEL} ${Math.round(snapshot.health)}`;
268
+ return [
269
+ `${staged}${dot}${working}${health}${dot}${PANEL_BOARD_HINT}`,
270
+ `${staged}${dot}${working}${health}`,
271
+ `${staged}${dot}${working}`,
272
+ staged,
273
+ base,
274
+ GOV_TITLE,
275
+ ];
276
+ }
277
+ function buildMinimal(snapshot, inner, glyphs) {
278
+ const fits = (candidate) => cellWidth(candidate) <= inner;
279
+ const text = minimalCandidates(snapshot, glyphs).find(fits)
280
+ ?? fitCells(GOV_TITLE, inner, glyphs.ellipsis);
281
+ const split = text.indexOf(' ');
282
+ const head = split < 0 ? text : text.slice(0, split);
283
+ const rest = split < 0 ? '' : text.slice(split);
284
+ return line([segment(head, 'govern', true), ...(rest === '' ? [] : [segment(rest, 'muted')])]);
285
+ }
286
+ function selectRoster(snapshot, rows, since) {
287
+ const present = sortRoster(snapshot.roster)
288
+ .filter((row) => !isRetired(row, snapshot.phase, since));
289
+ const cap = maxRosterRows(rows);
290
+ if (present.length <= cap)
291
+ return { visible: present, hidden: 0 };
292
+ // One row of the cap is spent on the `+N more` line, so a hidden roster never makes
293
+ // the panel taller than the budget `maxRosterRows` promised.
294
+ const shown = Math.max(1, cap - 1);
295
+ return { visible: present.slice(0, shown), hidden: present.length - shown };
296
+ }
297
+ function buildTier(input, tier) {
298
+ const snapshot = input.snapshot;
299
+ const cols = nonNegativeInt(input.cols);
300
+ const inner = Math.max(0, cols - PANEL_MARGIN_CELLS);
301
+ const mode = input.mode ?? 'panel';
302
+ const base = { ...EMPTY, tier, mode, cols, innerCols: inner };
303
+ if (tier === 'minimal') {
304
+ return { ...base, height: 1, header: buildMinimal(snapshot, inner, input.glyphs) };
305
+ }
306
+ const compact = tier === 'compact';
307
+ const header = compact
308
+ ? buildCompactHeader(snapshot, inner, input.now, input.glyphs)
309
+ : buildHeader(snapshot, inner, input.now, input.glyphs, tier === 'full');
310
+ const pipeline = compact ? null : buildPipeline(snapshot, inner, input.glyphs);
311
+ if (mode === 'run-strip') {
312
+ return { ...base, height: 1 + Number(pipeline !== null), header, pipeline };
313
+ }
314
+ const columns = columnPlan(tier, inner, markerCells(input.glyphs));
315
+ const { visible, hidden } = selectRoster(snapshot, input.rows, input.eliminatedSince ?? {});
316
+ const rosterRows = visible.map((row) => buildRosterLine({
317
+ columns, row, glyphs: input.glyphs, now: input.now, reducedMotion: input.reducedMotion,
318
+ }));
319
+ const ticker = compact ? [] : buildTicker(snapshot, inner, input.glyphs);
320
+ const ruled = !compact && rosterRows.length > 0;
321
+ const overflow = hidden > 0 ? fitCells(moreText(hidden), inner, input.glyphs.ellipsis) : null;
322
+ const height = 1 + Number(pipeline !== null) + 2 * Number(ruled) + rosterRows.length
323
+ + Number(overflow !== null) + ticker.length;
324
+ return {
325
+ ...base,
326
+ height,
327
+ header,
328
+ pipeline,
329
+ ruleCells: ruled ? inner : 0,
330
+ columns,
331
+ rosterRows,
332
+ overflow,
333
+ ticker,
334
+ };
335
+ }
336
+ /**
337
+ * Plan the panel for a terminal and a snapshot.
338
+ *
339
+ * `null` snapshot, or a finished run, plans to height 0 (nothing mounts - zero rows and
340
+ * zero layout shift, the `TeamPanel` D-11 rule). The caller's `availableRows` is a
341
+ * ceiling: tiers step down until one fits, and `minimal` is a single row or, with no row to
342
+ * spare, nothing.
343
+ */
344
+ export function buildGovernancePanelLayout(input) {
345
+ if (input.snapshot === null || isFinishedRun(input.snapshot.status))
346
+ return EMPTY;
347
+ const available = input.availableRows === undefined
348
+ ? Infinity
349
+ : nonNegativeInt(input.availableRows);
350
+ let tier = selectTier(nonNegativeInt(input.cols), nonNegativeInt(input.rows));
351
+ while (tier !== null) {
352
+ const layout = buildTier(input, tier);
353
+ if (layout.height <= available)
354
+ return layout;
355
+ tier = NEXT_SMALLER[tier];
356
+ }
357
+ return { ...EMPTY, cols: nonNegativeInt(input.cols) };
358
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Roster geometry and cell text for the legion panel (governance-mode section 10.3).
3
+ *
4
+ * Pure and total: no Ink, no clock, no terminal. ASCII ONLY.
5
+ *
6
+ * WHY COMPUTED FIXED-WIDTH COLUMNS. Same lesson as `team-row.ts`, whose header records
7
+ * it at length: a fixed-height parent makes Yoga size a flex column to its widest CHILD,
8
+ * so a row placed by `flexGrow` stops short of the terminal and the cells to its right
9
+ * lose their absolute offsets. Every column below therefore has a COMPUTED integer width
10
+ * and exactly ONE column is elastic; it sits between the fixed cluster on its left and
11
+ * the fixed `delta` cell on its right, so the score change always lands in the row's
12
+ * last column whatever the activity text says.
13
+ *
14
+ * `columnPlan` is TOTAL: for any width (including 0 and 400) the widths never sum past
15
+ * the width it was given. `governance-panel-layout.test.ts` runs it for every width.
16
+ */
17
+ import type { RosterRow } from '../../governance/types.js';
18
+ import type { Glyphs } from '../glyphs.js';
19
+ import { type Segment } from '../governance-status.js';
20
+ export type PanelTier = 'full' | 'standard' | 'compact' | 'minimal';
21
+ export type RosterColumnKey = 'marker' | 'id' | 'role' | 'state' | 'gauge' | 'score' | 'prov' | 'tag' | 'wp' | 'activity' | 'delta' | 'note';
22
+ export interface RosterColumn {
23
+ key: RosterColumnKey;
24
+ /** Final integer width in terminal columns (the elastic column's is what is left). */
25
+ width: number;
26
+ elastic: boolean;
27
+ align: 'left' | 'right';
28
+ }
29
+ /** One leading margin column, drawn by the component. */
30
+ export declare const PANEL_MARGIN_CELLS = 1;
31
+ /**
32
+ * The row's columns for a tier at `inner` columns (the terminal width minus the margin).
33
+ *
34
+ * THE DROP LADDER IS THE SPECIFICATION, in the order the cells give way: the activity
35
+ * text first (the only column whose loss costs nothing structural - the work-package cell
36
+ * becomes the elastic one), then the tag, gauge, provisional, role and delta cells. The
37
+ * elastic column keeps at least its floor; when even the fixed cluster does not fit,
38
+ * `squeeze` trims from the right so the sum stays inside `inner` for any input.
39
+ */
40
+ export declare function columnPlan(tier: PanelTier, inner: number, markerCells: number): RosterColumn[];
41
+ export declare function columnsWidth(columns: readonly RosterColumn[]): number;
42
+ export interface RosterCell {
43
+ key: RosterColumnKey;
44
+ width: number;
45
+ elastic: boolean;
46
+ align: 'left' | 'right';
47
+ segments: Segment[];
48
+ }
49
+ export interface RosterLine {
50
+ /** `row.id`; stable across snapshots so React keys do not churn. */
51
+ key: string;
52
+ kind: 'agent' | 'eliminated';
53
+ cells: RosterCell[];
54
+ }
55
+ export interface RosterLineInput {
56
+ columns: readonly RosterColumn[];
57
+ row: RosterRow;
58
+ glyphs: Glyphs;
59
+ now: number;
60
+ reducedMotion: boolean;
61
+ }
62
+ /** One roster row's cells, text already clamped to its cell. */
63
+ export declare function buildRosterLine(input: RosterLineInput): RosterLine;
64
+ /** The marker cell's width in the current glyph tier: 1 + widest marker + 1. */
65
+ export declare function markerCells(glyphs: Glyphs): number;