@aragon-agent/cli 0.6.44 → 0.6.46

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 (255) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +120 -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/invocation-card.d.ts +77 -0
  10. package/dist/agent/invocation-card.js +169 -0
  11. package/dist/agent/plan-prompt.d.ts +7 -0
  12. package/dist/agent/plan-prompt.js +2 -1
  13. package/dist/agent/prompt-options.d.ts +6 -0
  14. package/dist/agent/queued-messages.d.ts +3 -0
  15. package/dist/agent/queued-messages.js +4 -1
  16. package/dist/agent/reducer.d.ts +38 -1
  17. package/dist/agent/reducer.js +57 -12
  18. package/dist/agent/system-prompt.d.ts +19 -0
  19. package/dist/agent/system-prompt.js +9 -1
  20. package/dist/cli.js +45 -1
  21. package/dist/commands/builtins.js +22 -4
  22. package/dist/commands/governance-command.d.ts +35 -0
  23. package/dist/commands/governance-command.js +304 -0
  24. package/dist/commands/governance-runs-table.d.ts +40 -0
  25. package/dist/commands/governance-runs-table.js +130 -0
  26. package/dist/commands/index-build.d.ts +8 -0
  27. package/dist/commands/index-build.js +11 -0
  28. package/dist/commands/registry.d.ts +35 -0
  29. package/dist/commands/registry.js +20 -7
  30. package/dist/commands/skills.js +36 -2
  31. package/dist/commands/subagent-command.js +3 -1
  32. package/dist/commands/team-command.d.ts +6 -0
  33. package/dist/commands/team-command.js +40 -3
  34. package/dist/config/app-paths.d.ts +10 -0
  35. package/dist/config/app-paths.js +12 -0
  36. package/dist/config/cli-commands.d.ts +18 -0
  37. package/dist/config/cli-commands.js +47 -1
  38. package/dist/config/env.d.ts +2 -1
  39. package/dist/config/env.js +10 -1
  40. package/dist/config/governance-config.d.ts +125 -0
  41. package/dist/config/governance-config.js +164 -0
  42. package/dist/config/governance-launch.d.ts +71 -0
  43. package/dist/config/governance-launch.js +58 -0
  44. package/dist/config/load.d.ts +15 -0
  45. package/dist/config/load.js +26 -1
  46. package/dist/config/model-profile-store.d.ts +4 -2
  47. package/dist/config/schema.d.ts +22 -0
  48. package/dist/config/schema.js +6 -0
  49. package/dist/config/store.js +14 -1
  50. package/dist/config/ui-state.d.ts +11 -0
  51. package/dist/config/ui-state.js +11 -0
  52. package/dist/diagnostics/doctor.js +20 -0
  53. package/dist/governance/card-normalize.d.ts +24 -0
  54. package/dist/governance/card-normalize.js +76 -0
  55. package/dist/governance/copy.d.ts +109 -0
  56. package/dist/governance/copy.js +223 -0
  57. package/dist/governance/engine/aftermath.d.ts +49 -0
  58. package/dist/governance/engine/aftermath.js +134 -0
  59. package/dist/governance/engine/artifact-persist.d.ts +35 -0
  60. package/dist/governance/engine/artifact-persist.js +86 -0
  61. package/dist/governance/engine/budget.d.ts +52 -0
  62. package/dist/governance/engine/budget.js +112 -0
  63. package/dist/governance/engine/cards.d.ts +18 -0
  64. package/dist/governance/engine/cards.js +186 -0
  65. package/dist/governance/engine/digest.d.ts +32 -0
  66. package/dist/governance/engine/digest.js +63 -0
  67. package/dist/governance/engine/engine-core.d.ts +219 -0
  68. package/dist/governance/engine/engine-core.js +562 -0
  69. package/dist/governance/engine/engine.d.ts +68 -0
  70. package/dist/governance/engine/engine.js +314 -0
  71. package/dist/governance/engine/estimate.d.ts +38 -0
  72. package/dist/governance/engine/estimate.js +46 -0
  73. package/dist/governance/engine/inspector.d.ts +16 -0
  74. package/dist/governance/engine/inspector.js +396 -0
  75. package/dist/governance/engine/integration.d.ts +35 -0
  76. package/dist/governance/engine/integration.js +220 -0
  77. package/dist/governance/engine/lifecycle.d.ts +29 -0
  78. package/dist/governance/engine/lifecycle.js +656 -0
  79. package/dist/governance/engine/pause.d.ts +56 -0
  80. package/dist/governance/engine/pause.js +107 -0
  81. package/dist/governance/engine/phase-members.d.ts +15 -0
  82. package/dist/governance/engine/phase-members.js +34 -0
  83. package/dist/governance/engine/phase-planner.d.ts +53 -0
  84. package/dist/governance/engine/phase-planner.js +282 -0
  85. package/dist/governance/engine/rebuild.d.ts +27 -0
  86. package/dist/governance/engine/rebuild.js +57 -0
  87. package/dist/governance/engine/report.d.ts +66 -0
  88. package/dist/governance/engine/report.js +220 -0
  89. package/dist/governance/engine/run-digest.d.ts +20 -0
  90. package/dist/governance/engine/run-digest.js +42 -0
  91. package/dist/governance/engine/spec-builder.d.ts +117 -0
  92. package/dist/governance/engine/spec-builder.js +321 -0
  93. package/dist/governance/engine/stage-runner.d.ts +22 -0
  94. package/dist/governance/engine/stage-runner.js +664 -0
  95. package/dist/governance/engine/start-input.d.ts +19 -0
  96. package/dist/governance/engine/start-input.js +111 -0
  97. package/dist/governance/engine/state-machine.d.ts +101 -0
  98. package/dist/governance/engine/state-machine.js +586 -0
  99. package/dist/governance/engine/submission-queries.d.ts +42 -0
  100. package/dist/governance/engine/submission-queries.js +97 -0
  101. package/dist/governance/engine/submission-render.d.ts +12 -0
  102. package/dist/governance/engine/submission-render.js +92 -0
  103. package/dist/governance/engine/submissions.d.ts +27 -0
  104. package/dist/governance/engine/submissions.js +455 -0
  105. package/dist/governance/engine/visibility.d.ts +104 -0
  106. package/dist/governance/engine/visibility.js +223 -0
  107. package/dist/governance/governed-dispatch.d.ts +19 -0
  108. package/dist/governance/governed-dispatch.js +17 -0
  109. package/dist/governance/limits.d.ts +107 -0
  110. package/dist/governance/limits.js +131 -0
  111. package/dist/governance/posture-transition.d.ts +38 -0
  112. package/dist/governance/posture-transition.js +44 -0
  113. package/dist/governance/posture.d.ts +35 -0
  114. package/dist/governance/posture.js +59 -0
  115. package/dist/governance/profiles.d.ts +48 -0
  116. package/dist/governance/profiles.js +140 -0
  117. package/dist/governance/prompts/orchestrator-block.d.ts +40 -0
  118. package/dist/governance/prompts/orchestrator-block.js +128 -0
  119. package/dist/governance/prompts/plan-addendum.d.ts +22 -0
  120. package/dist/governance/prompts/plan-addendum.js +60 -0
  121. package/dist/governance/prompts/refusals.d.ts +48 -0
  122. package/dist/governance/prompts/refusals.js +82 -0
  123. package/dist/governance/prompts/role-blocks.d.ts +40 -0
  124. package/dist/governance/prompts/role-blocks.js +255 -0
  125. package/dist/governance/report-reader.d.ts +31 -0
  126. package/dist/governance/report-reader.js +57 -0
  127. package/dist/governance/roles.d.ts +83 -0
  128. package/dist/governance/roles.js +142 -0
  129. package/dist/governance/rules/claims.d.ts +83 -0
  130. package/dist/governance/rules/claims.js +250 -0
  131. package/dist/governance/rules/elimination.d.ts +66 -0
  132. package/dist/governance/rules/elimination.js +105 -0
  133. package/dist/governance/rules/events-table.d.ts +46 -0
  134. package/dist/governance/rules/events-table.js +94 -0
  135. package/dist/governance/rules/failure-analysis.d.ts +28 -0
  136. package/dist/governance/rules/failure-analysis.js +93 -0
  137. package/dist/governance/rules/ledger-replay.d.ts +53 -0
  138. package/dist/governance/rules/ledger-replay.js +53 -0
  139. package/dist/governance/rules/ledger-state.d.ts +85 -0
  140. package/dist/governance/rules/ledger-state.js +175 -0
  141. package/dist/governance/rules/ledger.d.ts +228 -0
  142. package/dist/governance/rules/ledger.js +560 -0
  143. package/dist/governance/rules/rca.d.ts +68 -0
  144. package/dist/governance/rules/rca.js +220 -0
  145. package/dist/governance/rules/settlement.d.ts +129 -0
  146. package/dist/governance/rules/settlement.js +363 -0
  147. package/dist/governance/rules/suspicion.d.ts +66 -0
  148. package/dist/governance/rules/suspicion.js +169 -0
  149. package/dist/governance/store/artifacts.d.ts +81 -0
  150. package/dist/governance/store/artifacts.js +173 -0
  151. package/dist/governance/store/atomic.d.ts +79 -0
  152. package/dist/governance/store/atomic.js +119 -0
  153. package/dist/governance/store/events-log.d.ts +35 -0
  154. package/dist/governance/store/events-log.js +86 -0
  155. package/dist/governance/store/run-lock.d.ts +51 -0
  156. package/dist/governance/store/run-lock.js +122 -0
  157. package/dist/governance/store/run-store.d.ts +229 -0
  158. package/dist/governance/store/run-store.js +644 -0
  159. package/dist/governance/store/scoreboard-export.d.ts +53 -0
  160. package/dist/governance/store/scoreboard-export.js +65 -0
  161. package/dist/governance/tools/child-tools.d.ts +31 -0
  162. package/dist/governance/tools/child-tools.js +65 -0
  163. package/dist/governance/tools/guard.d.ts +71 -0
  164. package/dist/governance/tools/guard.js +194 -0
  165. package/dist/governance/tools/inspector-tools.d.ts +63 -0
  166. package/dist/governance/tools/inspector-tools.js +424 -0
  167. package/dist/governance/tools/lead-tools.d.ts +42 -0
  168. package/dist/governance/tools/lead-tools.js +226 -0
  169. package/dist/governance/tools/normalize-util.d.ts +101 -0
  170. package/dist/governance/tools/normalize-util.js +230 -0
  171. package/dist/governance/tools/scan-incomplete.d.ts +79 -0
  172. package/dist/governance/tools/scan-incomplete.js +486 -0
  173. package/dist/governance/tools/shared-tools.d.ts +44 -0
  174. package/dist/governance/tools/shared-tools.js +125 -0
  175. package/dist/governance/tools/submit-normalizers.d.ts +28 -0
  176. package/dist/governance/tools/submit-normalizers.js +474 -0
  177. package/dist/governance/tools/submit-tools.d.ts +26 -0
  178. package/dist/governance/tools/submit-tools.js +171 -0
  179. package/dist/governance/types.d.ts +661 -0
  180. package/dist/governance/types.js +27 -0
  181. package/dist/session/persist.js +10 -0
  182. package/dist/session/validate-session.js +36 -3
  183. package/dist/team/forced-mode.d.ts +19 -0
  184. package/dist/team/forced-mode.js +42 -20
  185. package/dist/team/runtime.d.ts +8 -0
  186. package/dist/team/runtime.js +9 -0
  187. package/dist/team/subagent.d.ts +23 -0
  188. package/dist/team/subagent.js +14 -3
  189. package/dist/team/types.d.ts +6 -0
  190. package/dist/tools/index.d.ts +30 -7
  191. package/dist/tools/index.js +14 -0
  192. package/dist/tools/plan-tools.d.ts +14 -2
  193. package/dist/tools/plan-tools.js +5 -2
  194. package/dist/ui/App.js +170 -31
  195. package/dist/ui/BottomStatusRow.js +1 -1
  196. package/dist/ui/Composer.d.ts +7 -1
  197. package/dist/ui/Composer.js +9 -6
  198. package/dist/ui/GovernancePanel.d.ts +50 -0
  199. package/dist/ui/GovernancePanel.js +77 -0
  200. package/dist/ui/GovernanceRun.d.ts +18 -0
  201. package/dist/ui/GovernanceRun.js +11 -0
  202. package/dist/ui/StatusBar.d.ts +15 -2
  203. package/dist/ui/StatusBar.js +10 -4
  204. package/dist/ui/Transcript.js +7 -1
  205. package/dist/ui/entries/GovernanceCard.d.ts +30 -0
  206. package/dist/ui/entries/GovernanceCard.js +32 -0
  207. package/dist/ui/entries/InvocationCard.d.ts +20 -0
  208. package/dist/ui/entries/InvocationCard.js +32 -0
  209. package/dist/ui/governance-copy.d.ts +69 -0
  210. package/dist/ui/governance-copy.js +104 -0
  211. package/dist/ui/governance-status.d.ts +145 -0
  212. package/dist/ui/governance-status.js +326 -0
  213. package/dist/ui/interaction-copy.d.ts +4 -0
  214. package/dist/ui/interaction-copy.js +5 -0
  215. package/dist/ui/interaction-hints.d.ts +17 -0
  216. package/dist/ui/interaction-hints.js +14 -2
  217. package/dist/ui/layout/governance-board.d.ts +121 -0
  218. package/dist/ui/layout/governance-board.js +382 -0
  219. package/dist/ui/layout/governance-card.d.ts +53 -0
  220. package/dist/ui/layout/governance-card.js +134 -0
  221. package/dist/ui/layout/governance-chip.d.ts +38 -0
  222. package/dist/ui/layout/governance-chip.js +64 -0
  223. package/dist/ui/layout/governance-panel.d.ts +85 -0
  224. package/dist/ui/layout/governance-panel.js +358 -0
  225. package/dist/ui/layout/governance-roster.d.ts +65 -0
  226. package/dist/ui/layout/governance-roster.js +275 -0
  227. package/dist/ui/layout/invocation-card.d.ts +41 -0
  228. package/dist/ui/layout/invocation-card.js +91 -0
  229. package/dist/ui/layout/status-detail-layout.js +3 -3
  230. package/dist/ui/layout/status-layout.d.ts +5 -2
  231. package/dist/ui/layout/status-layout.js +10 -6
  232. package/dist/ui/layout/virtual-window.js +22 -1
  233. package/dist/ui/overlays/GovernanceBoardOverlay.d.ts +41 -0
  234. package/dist/ui/overlays/GovernanceBoardOverlay.js +76 -0
  235. package/dist/ui/overlays/GovernanceSettingsPage.d.ts +48 -0
  236. package/dist/ui/overlays/GovernanceSettingsPage.js +93 -0
  237. package/dist/ui/overlays/HelpOverlay.js +4 -3
  238. package/dist/ui/overlays/QuestionOverlay.d.ts +9 -1
  239. package/dist/ui/overlays/QuestionOverlay.js +4 -2
  240. package/dist/ui/overlays/SettingsScreen.d.ts +7 -0
  241. package/dist/ui/overlays/SettingsScreen.js +21 -1
  242. package/dist/ui/overlays/governance-settings.d.ts +79 -0
  243. package/dist/ui/overlays/governance-settings.js +140 -0
  244. package/dist/ui/overlays/model-profile-state.d.ts +6 -1
  245. package/dist/ui/overlays/model-profile-state.js +10 -0
  246. package/dist/ui/palettes.d.ts +17 -0
  247. package/dist/ui/palettes.js +9 -0
  248. package/dist/ui/scrollback/live-preview.js +2 -0
  249. package/dist/ui/scrollback/settled-boundary.js +3 -0
  250. package/dist/ui/shortcuts.js +2 -2
  251. package/dist/ui/theme.d.ts +7 -0
  252. package/dist/ui/theme.js +1 -0
  253. package/dist/ui/transcript-text.js +13 -1
  254. package/dist/ui/use-wheel-routing.js +3 -1
  255. package/package.json +2 -2
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Fixed-size text the orchestrator and the user read (governance-mode D-16, 8.6).
3
+ *
4
+ * ASCII ONLY (`governance/` is glyph-scanned).
5
+ *
6
+ * Two outputs with two different readers and two different budgets:
7
+ * - `buildDigest` is the TOOL RESULT of every `gov_run` / `gov_dispatch`. It lands in the
8
+ * orchestrator's context for the rest of a run that may last hours, so it is bounded in
9
+ * BYTES (`ToolExecutor` truncates combined tool text at 100 000 bytes, and a long CJK
10
+ * request turns into three bytes per character) and it always ends with `NEXT:` - the
11
+ * legal next actions - so a compacted or `/clear`ed orchestrator can resume by reading
12
+ * its own last tool result.
13
+ * - `buildBoardMarkdown` / `buildFinalReport` are human documents written to disk.
14
+ *
15
+ * When a digest must be clipped, the MIDDLE is dropped: the head (what happened) and the
16
+ * tail (`NEXT:`) are the two parts the reader cannot do without.
17
+ */
18
+ import type { Claim, Escalation, LedgerEntry, RunState, StandingRow, WorkPackage } from '../types.js';
19
+ export declare function wpStatusWord(status: WorkPackage['status']): string;
20
+ /** Clip a string to `maxBytes` UTF-8 bytes without splitting a code point. */
21
+ export declare function clipBytes(text: string, maxBytes: number): string;
22
+ export declare function formatScore(row: StandingRow): string;
23
+ export declare function renderStandings(rows: StandingRow[], health: number | null): string;
24
+ export declare function renderWpTable(run: RunState): string;
25
+ export declare function renderPhases(run: RunState): string;
26
+ export declare function renderLedgerLine(entry: LedgerEntry, agentId: string): string;
27
+ export interface DigestInput {
28
+ /** First line, begins with `OK:` / `NOT ACCEPTED:` / `ESCALATION:`. */
29
+ headline: string;
30
+ /** Result lines (per WP / per agent). */
31
+ results: string[];
32
+ /** Ledger lines booked by this call. */
33
+ ledger: string[];
34
+ standings?: string;
35
+ warnings: string[];
36
+ nextActions: string[];
37
+ /** Always printed, e.g. limits and usage. */
38
+ footer?: string[];
39
+ }
40
+ /**
41
+ * Compose a digest under `GOV_LIMITS.digestMaxBytes`. `NEXT:` is the only part that is
42
+ * never clipped; over budget, results are dropped from the end first, then ledger lines.
43
+ */
44
+ export declare function buildDigest(input: DigestInput, maxBytes?: number): string;
45
+ export interface BoardInput {
46
+ run: RunState;
47
+ standings: StandingRow[];
48
+ health: number | null;
49
+ recent: Array<{
50
+ entry: LedgerEntry;
51
+ agentId: string;
52
+ }>;
53
+ }
54
+ /** The human-readable projection rewritten at stage end and at close (`board.md`). */
55
+ export declare function buildBoardMarkdown(input: BoardInput): string;
56
+ export declare function renderClaim(c: Claim): string;
57
+ export declare function renderEscalation(e: Escalation): string;
58
+ export interface FinalReportInput extends BoardInput {
59
+ summary?: string;
60
+ wallMs: number;
61
+ }
62
+ /**
63
+ * The closing report: what was delivered, what was accepted with known issues, what was
64
+ * dropped, final standings. Bounded by `finalReportMaxBytes`.
65
+ */
66
+ export declare function buildFinalReport(input: FinalReportInput): string;
@@ -0,0 +1,220 @@
1
+ /**
2
+ * Fixed-size text the orchestrator and the user read (governance-mode D-16, 8.6).
3
+ *
4
+ * ASCII ONLY (`governance/` is glyph-scanned).
5
+ *
6
+ * Two outputs with two different readers and two different budgets:
7
+ * - `buildDigest` is the TOOL RESULT of every `gov_run` / `gov_dispatch`. It lands in the
8
+ * orchestrator's context for the rest of a run that may last hours, so it is bounded in
9
+ * BYTES (`ToolExecutor` truncates combined tool text at 100 000 bytes, and a long CJK
10
+ * request turns into three bytes per character) and it always ends with `NEXT:` - the
11
+ * legal next actions - so a compacted or `/clear`ed orchestrator can resume by reading
12
+ * its own last tool result.
13
+ * - `buildBoardMarkdown` / `buildFinalReport` are human documents written to disk.
14
+ *
15
+ * When a digest must be clipped, the MIDDLE is dropped: the head (what happened) and the
16
+ * tail (`NEXT:`) are the two parts the reader cannot do without.
17
+ */
18
+ import { GOV_LIMITS } from '../limits.js';
19
+ const WP_STATUS_WORD = {
20
+ pending: 'pending',
21
+ dev_running: 'developing',
22
+ awaiting_review: 'awaiting review',
23
+ review_running: 'in review',
24
+ awaiting_test: 'awaiting test',
25
+ test_running: 'in test',
26
+ rework: 'rework',
27
+ tested_ok: 'tested ok',
28
+ integrated: 'integrated',
29
+ blocked: 'BLOCKED',
30
+ dropped: 'dropped',
31
+ };
32
+ export function wpStatusWord(status) {
33
+ return WP_STATUS_WORD[status];
34
+ }
35
+ function byteLength(text) {
36
+ return Buffer.byteLength(text, 'utf8');
37
+ }
38
+ /** Clip a string to `maxBytes` UTF-8 bytes without splitting a code point. */
39
+ export function clipBytes(text, maxBytes) {
40
+ if (byteLength(text) <= maxBytes)
41
+ return text;
42
+ let out = '';
43
+ let used = 0;
44
+ for (const ch of text) {
45
+ const size = byteLength(ch);
46
+ if (used + size > maxBytes)
47
+ break;
48
+ out += ch;
49
+ used += size;
50
+ }
51
+ return out;
52
+ }
53
+ export function formatScore(row) {
54
+ const conf = row.confirmed;
55
+ if (row.provisional > 0)
56
+ return `${conf + row.provisional} (${conf} + ${row.provisional}P)`;
57
+ return String(conf);
58
+ }
59
+ export function renderStandings(rows, health) {
60
+ if (rows.length === 0)
61
+ return 'Standings: (no scored agents yet)';
62
+ const lines = rows.map((r) => {
63
+ const gen = r.generation > 0 ? ` gen${r.generation}` : '';
64
+ const tail = r.status === 'eliminated'
65
+ ? `ELIMINATED${r.replacedBy ? ` (replaced by ${r.replacedBy})` : ''}`
66
+ : r.label;
67
+ return ` ${r.id.padEnd(8)} ${r.role.padEnd(4)}${gen} ${formatScore(r).padEnd(14)} ${tail}`;
68
+ });
69
+ const healthLine = health === null ? '' : `\n team health: ${Math.round(health)}`;
70
+ return `Standings (GT = governance tokens, unrelated to LLM context tokens):\n${lines.join('\n')}${healthLine}`;
71
+ }
72
+ export function renderWpTable(run) {
73
+ const lines = run.wpOrder
74
+ .map((id) => run.workPackages[id])
75
+ .filter((w) => w !== undefined)
76
+ .map((w) => {
77
+ const extra = [];
78
+ if (w.reworkCount > 0)
79
+ extra.push(`rework ${w.reworkCount}`);
80
+ if (w.status === 'blocked' && w.blockedAt)
81
+ extra.push(`blocked at ${w.blockedAt}`);
82
+ if (w.acceptedWithIssues)
83
+ extra.push('accepted with issues');
84
+ return ` ${w.id.padEnd(16)} p${w.phase + 1} ${wpStatusWord(w.status)}${extra.length > 0 ? ` (${extra.join(', ')})` : ''}`;
85
+ });
86
+ return `Work packages:\n${lines.join('\n')}`;
87
+ }
88
+ function describePhase(p) {
89
+ const flags = [];
90
+ if (p.settled)
91
+ flags.push('settled');
92
+ if (p.integrated) {
93
+ flags.push(p.integrationAccepted ? 'integrated' : 'integration FAILED, accepted by user');
94
+ }
95
+ if (p.fixCycles > 0)
96
+ flags.push(`fix cycles ${p.fixCycles}`);
97
+ return ` phase ${p.index + 1}: ${p.wpIds.join(', ')}${flags.length > 0 ? ` [${flags.join(', ')}]` : ''}`;
98
+ }
99
+ export function renderPhases(run) {
100
+ return `Phases:\n${run.phases.map(describePhase).join('\n')}`;
101
+ }
102
+ export function renderLedgerLine(entry, agentId) {
103
+ const sign = entry.delta > 0 ? '+' : '';
104
+ const pool = entry.settlement === 'provisional' ? 'P' : '';
105
+ const cap = entry.capped ? ` (capped from ${entry.capped.requested})` : '';
106
+ return `${agentId} ${sign}${entry.delta}${pool} ${entry.code} ${entry.reason}${cap}`;
107
+ }
108
+ /**
109
+ * Compose a digest under `GOV_LIMITS.digestMaxBytes`. `NEXT:` is the only part that is
110
+ * never clipped; over budget, results are dropped from the end first, then ledger lines.
111
+ */
112
+ export function buildDigest(input, maxBytes = GOV_LIMITS.digestMaxBytes) {
113
+ const tail = [
114
+ ...(input.footer ?? []),
115
+ input.nextActions.length > 0 ? `NEXT:\n${input.nextActions.map((n) => ` ${n}`).join('\n')}` : 'NEXT: (none)',
116
+ ].join('\n');
117
+ const warn = input.warnings.map((w) => `${w}`);
118
+ const parts = (results, ledger, standings) => [
119
+ input.headline,
120
+ ...results,
121
+ ...(ledger.length > 0 ? ['Ledger:', ...ledger.map((l) => ` ${l}`)] : []),
122
+ ...(standings && input.standings ? [input.standings] : []),
123
+ ...warn,
124
+ tail,
125
+ ].join('\n');
126
+ let results = [...input.results];
127
+ let ledger = [...input.ledger];
128
+ let text = parts(results, ledger, true);
129
+ if (byteLength(text) <= maxBytes)
130
+ return text;
131
+ text = parts(results, ledger, false);
132
+ while (byteLength(text) > maxBytes && ledger.length > 3) {
133
+ ledger = ledger.slice(0, ledger.length - 1);
134
+ text = parts(results, [...ledger, `(+ more ledger rows; see gov_run status)`], false);
135
+ }
136
+ while (byteLength(text) > maxBytes && results.length > 4) {
137
+ results = results.slice(0, results.length - 1);
138
+ text = parts([...results, '(+ more results omitted)'], ledger, false);
139
+ }
140
+ if (byteLength(text) > maxBytes) {
141
+ const headBudget = Math.max(200, maxBytes - byteLength(tail) - 40);
142
+ const head = clipBytes(parts(results, [], false).replace(tail, '').trimEnd(), headBudget);
143
+ text = `${head}\n(clipped)\n${tail}`;
144
+ }
145
+ return text;
146
+ }
147
+ /** The human-readable projection rewritten at stage end and at close (`board.md`). */
148
+ export function buildBoardMarkdown(input) {
149
+ const { run } = input;
150
+ const lines = [
151
+ `# Governance run ${run.runId}`,
152
+ '',
153
+ `Goal: ${run.goal}`,
154
+ `Status: ${run.status} Profile: ${run.profile}`,
155
+ '',
156
+ '```',
157
+ renderPhases(run),
158
+ '',
159
+ renderWpTable(run),
160
+ '',
161
+ renderStandings(input.standings, input.health),
162
+ '```',
163
+ ];
164
+ if (run.escalations.length > 0) {
165
+ lines.push('', '## Escalations');
166
+ for (const e of run.escalations)
167
+ lines.push(renderEscalation(e));
168
+ }
169
+ if (run.claims.length > 0) {
170
+ lines.push('', '## Claims');
171
+ for (const c of run.claims)
172
+ lines.push(renderClaim(c));
173
+ }
174
+ if (input.recent.length > 0) {
175
+ lines.push('', '## Recent ledger');
176
+ for (const r of input.recent.slice(-40))
177
+ lines.push(`- ${renderLedgerLine(r.entry, r.agentId)}`);
178
+ }
179
+ return `${lines.join('\n')}\n`;
180
+ }
181
+ export function renderClaim(c) {
182
+ const ruling = c.rulingText ? ` - ${c.rulingText}` : '';
183
+ return `- ${c.id} [${c.kind}] ${c.raisedBy} vs ${c.against} on ${c.wpId}: ${c.status}${ruling}`;
184
+ }
185
+ export function renderEscalation(e) {
186
+ const ruling = e.ruling ? ` - ruling: ${e.ruling}` : '';
187
+ return `- ${e.id} [${e.kind}] ${e.topic}: ${e.status}${ruling}`;
188
+ }
189
+ /**
190
+ * The closing report: what was delivered, what was accepted with known issues, what was
191
+ * dropped, final standings. Bounded by `finalReportMaxBytes`.
192
+ */
193
+ export function buildFinalReport(input) {
194
+ const { run } = input;
195
+ const wps = run.wpOrder.map((id) => run.workPackages[id]).filter((w) => !!w);
196
+ const delivered = wps.filter((w) => w.status === 'integrated' && !w.acceptedWithIssues);
197
+ const withIssues = wps.filter((w) => w.acceptedWithIssues);
198
+ const dropped = wps.filter((w) => w.status === 'dropped');
199
+ const open = wps.filter((w) => !['integrated', 'dropped'].includes(w.status));
200
+ const lines = [`# Final report - run ${run.runId}`, '', `Goal: ${run.goal}`, ''];
201
+ if (input.summary)
202
+ lines.push(`Orchestrator summary: ${input.summary}`, '');
203
+ lines.push(`Delivered (${delivered.length}): ${delivered.map((w) => w.id).join(', ') || '(none)'}`);
204
+ if (withIssues.length > 0) {
205
+ lines.push(`Accepted WITH ISSUES (${withIssues.length}): ${withIssues.map((w) => w.id).join(', ')}`);
206
+ }
207
+ if (dropped.length > 0)
208
+ lines.push(`Not delivered (dropped): ${dropped.map((w) => w.id).join(', ')}`);
209
+ if (open.length > 0)
210
+ lines.push(`UNFINISHED: ${open.map((w) => w.id).join(', ')}`);
211
+ const failedPhases = run.phases.filter((p) => p.integrated && !p.integrationAccepted);
212
+ if (failedPhases.length > 0) {
213
+ lines.push(`Integration FAILED but accepted by the user in phase(s): ${failedPhases
214
+ .map((p) => p.index + 1)
215
+ .join(', ')}`);
216
+ }
217
+ lines.push('', renderStandings(input.standings, input.health), '');
218
+ lines.push(`Team tokens: input ${run.usage.inputTokens}, output ${run.usage.outputTokens}, cost ${run.usage.costUsd === null ? 'pricing unknown' : `$${run.usage.costUsd.toFixed(4)}`}; wall ${Math.round(input.wallMs / 1000)}s`);
219
+ return clipBytes(`${lines.join('\n')}\n`, GOV_LIMITS.finalReportMaxBytes);
220
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `RunDigest` - one run reduced to eight scalars for `/gov runs` (governance-mode-v1-1 7.1).
3
+ *
4
+ * ASCII ONLY (`governance/` is glyph-scanned). Pure.
5
+ *
6
+ * WHY A DIGEST AND NOT THE RUN. `index.jsonl` is append-only and read whole by
7
+ * `listRuns()`, so a row must stay small (< 400 B) and must not need `run.json`: listing ten
8
+ * runs by opening ten run folders would race the engine that holds one of them. The digest
9
+ * is derived from the same in-memory copies `checkpoint()` already clones, so it costs no
10
+ * extra disk read and cannot disagree with the checkpoint it rides.
11
+ *
12
+ * UNKNOWN IS NOT ZERO. `costUsd` is `null` whenever the run's price is unknown (v1 8.5 /
13
+ * C-11): a run whose dispatches could not be priced must read as `n/a`, never `$0.00`.
14
+ *
15
+ * HEALTH IS ROUNDED TO A WHOLE NUMBER. Every ledger delta moves the mean, and a digest that
16
+ * changed on every fraction would append an index row per booking instead of per stage.
17
+ */
18
+ import type { LedgerState, RunDigest, RunState } from '../types.js';
19
+ export type { RunDigest };
20
+ export declare function buildRunDigest(run: RunState, ledger: LedgerState): RunDigest;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * `RunDigest` - one run reduced to eight scalars for `/gov runs` (governance-mode-v1-1 7.1).
3
+ *
4
+ * ASCII ONLY (`governance/` is glyph-scanned). Pure.
5
+ *
6
+ * WHY A DIGEST AND NOT THE RUN. `index.jsonl` is append-only and read whole by
7
+ * `listRuns()`, so a row must stay small (< 400 B) and must not need `run.json`: listing ten
8
+ * runs by opening ten run folders would race the engine that holds one of them. The digest
9
+ * is derived from the same in-memory copies `checkpoint()` already clones, so it costs no
10
+ * extra disk read and cannot disagree with the checkpoint it rides.
11
+ *
12
+ * UNKNOWN IS NOT ZERO. `costUsd` is `null` whenever the run's price is unknown (v1 8.5 /
13
+ * C-11): a run whose dispatches could not be priced must read as `n/a`, never `$0.00`.
14
+ *
15
+ * HEALTH IS ROUNDED TO A WHOLE NUMBER. Every ledger delta moves the mean, and a digest that
16
+ * changed on every fraction would append an index row per booking instead of per stage.
17
+ */
18
+ import { teamHealth } from '../rules/ledger-state.js';
19
+ /** The phase to show: the first not-integrated one, else the last (mirrors the panel). */
20
+ function displayPhase(run) {
21
+ if (run.phases.length === 0)
22
+ return 1;
23
+ const open = run.phases.find((p) => !p.integrated);
24
+ return (open ? open.index : run.phases.length - 1) + 1;
25
+ }
26
+ function finiteOrNull(value) {
27
+ return typeof value === 'number' && Number.isFinite(value) ? value : null;
28
+ }
29
+ export function buildRunDigest(run, ledger) {
30
+ const records = Object.values(ledger.agents);
31
+ const health = teamHealth(ledger);
32
+ return {
33
+ phase: displayPhase(run),
34
+ phaseCount: run.phases.length,
35
+ agents: records.length,
36
+ health: health === null ? null : Math.round(health),
37
+ tokens: run.usage.inputTokens + run.usage.outputTokens,
38
+ costUsd: finiteOrNull(run.usage.costUsd),
39
+ dispatches: run.dispatches,
40
+ eliminations: records.filter((a) => a.status === 'eliminated').length,
41
+ };
42
+ }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Sub-agent spec construction (governance-mode 8.3).
3
+ *
4
+ * ASCII ONLY (`governance/` is glyph-scanned).
5
+ *
6
+ * THE ENGINE BUILDS EVERY BRIEF; THE ORCHESTRATOR NEVER DOES (6.2 rule 5). That is what
7
+ * makes the information boundary real: a role sees exactly the sections this module is
8
+ * handed, and the CALLER (the engine) is the one who decides what each role may be
9
+ * handed, from `visibility.ts`. This module is deliberately a pure assembler with no
10
+ * access to the store, so it cannot leak a section it was not given.
11
+ *
12
+ * It also re-applies the three length clamps `normalizeSubagentSpecs` applies to the
13
+ * orchestrator's own specs (D-24 / RV-4): the engine bypasses that function, so the
14
+ * `label` / `description` / `prompt` bounds have to hold here or nowhere.
15
+ */
16
+ import type { SubagentSpec } from '../../team/types.js';
17
+ import type { Contract, FailureAnalysis, GovRole, ProfileId, ReviewSubmission, ReviewVerdict, StageKind, WorkPackage, WorkSubmission } from '../types.js';
18
+ /** Marker appended to any clipped section. Stable: tests and models rely on it. */
19
+ export declare const TRUNCATION_MARK = "[truncated]";
20
+ export interface RequiredChange {
21
+ file: string;
22
+ issue: string;
23
+ change: string;
24
+ }
25
+ export interface BriefRun {
26
+ runId: string;
27
+ goal: string;
28
+ profile: ProfileId;
29
+ /** The verbatim spec (plus approved plan snapshot). */
30
+ spec: string;
31
+ contracts: Contract[];
32
+ integrationCommands: string[];
33
+ }
34
+ /**
35
+ * Everything one child may see. EVERY optional field is a section the caller chose to
36
+ * disclose to this role; absent means "not part of this role's view".
37
+ */
38
+ export interface ChildBrief {
39
+ run: BriefRun;
40
+ /** Roster id, e.g. `dev1`. */
41
+ identity: string;
42
+ role: GovRole;
43
+ generation: number;
44
+ tokens: number;
45
+ /** 1-based phase number. */
46
+ phase: number;
47
+ stage: StageKind;
48
+ /** The WPs this child handles, in the fixed order they must be submitted. */
49
+ wps: WorkPackage[];
50
+ predecessor?: FailureAnalysis;
51
+ /** Same-batch peers, for the `team_send` hint (same role only, D-3). */
52
+ peers?: string[];
53
+ /** DEV / FIX: per-WP rework items written by the reviewer (the only feedback, D-7). */
54
+ requiredChanges?: Record<string, RequiredChange[]>;
55
+ /** FIX: the full RCA text. */
56
+ rcaText?: string;
57
+ /** REV / INSP: the DEV's submission per WP. TEST gets `changeLists` instead. */
58
+ workSubmissions?: Record<string, WorkSubmission>;
59
+ /** TEST: the changed-file list per WP (and nothing else of the DEV's report). */
60
+ changeLists?: Record<string, string[]>;
61
+ /** TEST / INSP: the review CONCLUSION per WP (never the comments, D-7). */
62
+ reviewVerdicts?: Record<string, ReviewVerdict>;
63
+ /** REV: the DEV's appeal per WP, plus the prior review's finding ids. */
64
+ appeals?: Record<string, {
65
+ findingIds: string[];
66
+ argument: string;
67
+ }>;
68
+ /** DEV: the developer's own previous submission summary on rework. */
69
+ previousOwn?: Record<string, string>;
70
+ /** Orchestrator notes, accepted for dev and fix only (6.2 rule 5). */
71
+ notes?: Record<string, string>;
72
+ /** Re-dispatch after a missing submission: only these WPs are listed. */
73
+ missingOnly?: string[];
74
+ /** INSP-only material. */
75
+ inspector?: InspectorMaterial;
76
+ }
77
+ export interface InspectorMaterial {
78
+ /** Compact lines of the events the engine already booked this phase. */
79
+ autoEvents: string[];
80
+ openClaims: Array<{
81
+ id: string;
82
+ kind: string;
83
+ raisedBy: string;
84
+ against: string;
85
+ wpId: string;
86
+ text: string;
87
+ }>;
88
+ /** Mechanical suspicion flags (D17 / R12 signatures, ownership violations). */
89
+ flags: string[];
90
+ /** Review findings per WP (full text), inspector has full visibility. */
91
+ reviewDigest: Record<string, string>;
92
+ testDigest: Record<string, string>;
93
+ /** Integration attempt context for `integrate`. */
94
+ integrationAttempt?: number;
95
+ healthWarning?: boolean;
96
+ viewEvents?: string[];
97
+ }
98
+ interface Section {
99
+ priority: number;
100
+ title: string;
101
+ body: string;
102
+ }
103
+ /**
104
+ * Join sections by priority under `budget` characters, clipping from the LOW-priority end
105
+ * and marking every clipped section. The task instruction is never clipped: a brief
106
+ * without its instruction is a brief that cannot be followed.
107
+ */
108
+ export declare function assemblePrompt(sections: Section[], budget: number): string;
109
+ /**
110
+ * Build one `SubagentSpec`. The label IS the roster identity, which already satisfies
111
+ * `[a-z0-9-]{1,12}`; the guard below catches a future identity scheme that does not,
112
+ * rather than letting `TeamRuntime` discover it as a dropped child.
113
+ */
114
+ export declare function buildSubagentSpec(brief: ChildBrief): SubagentSpec;
115
+ /** Convenience for tests and the engine: render derived required changes from a review. */
116
+ export declare function requiredChangesOf(review: ReviewSubmission): RequiredChange[];
117
+ export {};