@ngockhoale/ckit 0.0.0-stage → 0.1.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 (244) hide show
  1. package/.env.example +42 -0
  2. package/README.md +116 -2
  3. package/dist/src/adapters/agent/claude/errors.d.ts +13 -0
  4. package/dist/src/adapters/agent/claude/errors.js +16 -0
  5. package/dist/src/adapters/agent/claude/normalize.d.ts +11 -0
  6. package/dist/src/adapters/agent/claude/normalize.js +83 -0
  7. package/dist/src/adapters/agent/errors.d.ts +13 -0
  8. package/dist/src/adapters/agent/errors.js +19 -0
  9. package/dist/src/adapters/agent/fixtures/claude-transcript.d.ts +70 -0
  10. package/dist/src/adapters/agent/fixtures/claude-transcript.js +15 -0
  11. package/dist/src/adapters/agent/fixtures/omp-transcript.d.ts +60 -0
  12. package/dist/src/adapters/agent/fixtures/omp-transcript.js +14 -0
  13. package/dist/src/adapters/agent/normalize.d.ts +18 -0
  14. package/dist/src/adapters/agent/normalize.js +77 -0
  15. package/dist/src/adapters/agent/transport.d.ts +35 -0
  16. package/dist/src/adapters/agent/transport.js +39 -0
  17. package/dist/src/adapters/agent/worker-service.d.ts +49 -0
  18. package/dist/src/adapters/agent/worker-service.js +77 -0
  19. package/dist/src/adapters/fake/fake-advisor.d.ts +15 -0
  20. package/dist/src/adapters/fake/fake-advisor.js +29 -0
  21. package/dist/src/adapters/fake/fake-agent.d.ts +12 -0
  22. package/dist/src/adapters/fake/fake-agent.js +21 -0
  23. package/dist/src/adapters/fake/fake-store.d.ts +13 -0
  24. package/dist/src/adapters/fake/fake-store.js +23 -0
  25. package/dist/src/adapters/fake/fake-web.d.ts +12 -0
  26. package/dist/src/adapters/fake/fake-web.js +21 -0
  27. package/dist/src/adapters/fake/fault-injector.d.ts +18 -0
  28. package/dist/src/adapters/fake/fault-injector.js +64 -0
  29. package/dist/src/adapters/fake/virtual-clock.d.ts +12 -0
  30. package/dist/src/adapters/fake/virtual-clock.js +35 -0
  31. package/dist/src/adapters/launch/discover.d.ts +18 -0
  32. package/dist/src/adapters/launch/discover.js +55 -0
  33. package/dist/src/adapters/launch/executor.d.ts +117 -0
  34. package/dist/src/adapters/launch/executor.js +383 -0
  35. package/dist/src/adapters/launch/profile.d.ts +35 -0
  36. package/dist/src/adapters/launch/profile.js +73 -0
  37. package/dist/src/adapters/launch/spawn.d.ts +29 -0
  38. package/dist/src/adapters/launch/spawn.js +18 -0
  39. package/dist/src/adapters/openai/openai-advisor.d.ts +56 -0
  40. package/dist/src/adapters/openai/openai-advisor.js +146 -0
  41. package/dist/src/cli/ckit.d.ts +5 -0
  42. package/dist/src/cli/ckit.js +472 -0
  43. package/dist/src/cli/demo.d.ts +1 -0
  44. package/dist/src/cli/demo.js +30 -0
  45. package/dist/src/cli/sessions.d.ts +10 -0
  46. package/dist/src/cli/sessions.js +381 -0
  47. package/dist/src/cli/setup.d.ts +11 -0
  48. package/dist/src/cli/setup.js +115 -0
  49. package/dist/src/committee/decision.d.ts +84 -0
  50. package/dist/src/committee/decision.js +167 -0
  51. package/dist/src/committee/handover.d.ts +115 -0
  52. package/dist/src/committee/handover.js +191 -0
  53. package/dist/src/committee/no-progress.d.ts +44 -0
  54. package/dist/src/committee/no-progress.js +64 -0
  55. package/dist/src/committee/primary-registry.d.ts +15 -0
  56. package/dist/src/committee/primary-registry.js +60 -0
  57. package/dist/src/committee/reply-parser.d.ts +28 -0
  58. package/dist/src/committee/reply-parser.js +53 -0
  59. package/dist/src/committee/reviewer-scheduler.d.ts +101 -0
  60. package/dist/src/committee/reviewer-scheduler.js +163 -0
  61. package/dist/src/committee/role-epoch.d.ts +91 -0
  62. package/dist/src/committee/role-epoch.js +154 -0
  63. package/dist/src/core/control.d.ts +18 -0
  64. package/dist/src/core/control.js +29 -0
  65. package/dist/src/core/entities.d.ts +166 -0
  66. package/dist/src/core/entities.js +119 -0
  67. package/dist/src/core/errors.d.ts +9 -0
  68. package/dist/src/core/errors.js +17 -0
  69. package/dist/src/core/events.d.ts +72 -0
  70. package/dist/src/core/events.js +125 -0
  71. package/dist/src/core/ids.d.ts +47 -0
  72. package/dist/src/core/ids.js +32 -0
  73. package/dist/src/core/machine.d.ts +55 -0
  74. package/dist/src/core/machine.js +110 -0
  75. package/dist/src/core/policy.d.ts +34 -0
  76. package/dist/src/core/policy.js +59 -0
  77. package/dist/src/core/provenance.d.ts +20 -0
  78. package/dist/src/core/provenance.js +21 -0
  79. package/dist/src/core/record.d.ts +35 -0
  80. package/dist/src/core/record.js +67 -0
  81. package/dist/src/core/replay.d.ts +10 -0
  82. package/dist/src/core/replay.js +36 -0
  83. package/dist/src/core/run-task.d.ts +20 -0
  84. package/dist/src/core/run-task.js +48 -0
  85. package/dist/src/diagnostics/doctor.d.ts +78 -0
  86. package/dist/src/diagnostics/doctor.js +365 -0
  87. package/dist/src/diagnostics/journal-lock.d.ts +38 -0
  88. package/dist/src/diagnostics/journal-lock.js +181 -0
  89. package/dist/src/evidence/linker.d.ts +44 -0
  90. package/dist/src/evidence/linker.js +75 -0
  91. package/dist/src/evidence/report-parser.d.ts +27 -0
  92. package/dist/src/evidence/report-parser.js +17 -0
  93. package/dist/src/evidence/store.d.ts +36 -0
  94. package/dist/src/evidence/store.js +57 -0
  95. package/dist/src/gui/server.d.ts +27 -0
  96. package/dist/src/gui/server.js +497 -0
  97. package/dist/src/host/checkpoint.d.ts +22 -0
  98. package/dist/src/host/checkpoint.js +74 -0
  99. package/dist/src/host/export.d.ts +52 -0
  100. package/dist/src/host/export.js +45 -0
  101. package/dist/src/host/ipc.d.ts +57 -0
  102. package/dist/src/host/ipc.js +124 -0
  103. package/dist/src/host/leases.d.ts +27 -0
  104. package/dist/src/host/leases.js +40 -0
  105. package/dist/src/host/retention.d.ts +47 -0
  106. package/dist/src/host/retention.js +130 -0
  107. package/dist/src/host/supervisor.d.ts +59 -0
  108. package/dist/src/host/supervisor.js +64 -0
  109. package/dist/src/intake/owner-intake.d.ts +31 -0
  110. package/dist/src/intake/owner-intake.js +97 -0
  111. package/dist/src/intake/types.d.ts +46 -0
  112. package/dist/src/intake/types.js +2 -0
  113. package/dist/src/intent/context-packet.d.ts +68 -0
  114. package/dist/src/intent/context-packet.js +76 -0
  115. package/dist/src/intent/idea-ledger.d.ts +50 -0
  116. package/dist/src/intent/idea-ledger.js +136 -0
  117. package/dist/src/intent/ledger.d.ts +35 -0
  118. package/dist/src/intent/ledger.js +40 -0
  119. package/dist/src/intent/registry.d.ts +51 -0
  120. package/dist/src/intent/registry.js +44 -0
  121. package/dist/src/intent/revision.d.ts +37 -0
  122. package/dist/src/intent/revision.js +48 -0
  123. package/dist/src/orchestration/dispatcher.d.ts +32 -0
  124. package/dist/src/orchestration/dispatcher.js +136 -0
  125. package/dist/src/orchestration/milestone-loop.d.ts +149 -0
  126. package/dist/src/orchestration/milestone-loop.js +132 -0
  127. package/dist/src/orchestration/recovery-coordinator.d.ts +74 -0
  128. package/dist/src/orchestration/recovery-coordinator.js +180 -0
  129. package/dist/src/orchestration/work-order-contract.d.ts +44 -0
  130. package/dist/src/orchestration/work-order-contract.js +85 -0
  131. package/dist/src/orchestration/work-queue.d.ts +56 -0
  132. package/dist/src/orchestration/work-queue.js +95 -0
  133. package/dist/src/ports/advisor.d.ts +33 -0
  134. package/dist/src/ports/advisor.js +2 -0
  135. package/dist/src/ports/agent.d.ts +31 -0
  136. package/dist/src/ports/agent.js +2 -0
  137. package/dist/src/ports/capabilities.d.ts +3 -0
  138. package/dist/src/ports/capabilities.js +5 -0
  139. package/dist/src/ports/clock.d.ts +5 -0
  140. package/dist/src/ports/clock.js +5 -0
  141. package/dist/src/ports/store.d.ts +13 -0
  142. package/dist/src/ports/store.js +2 -0
  143. package/dist/src/ports/web.d.ts +29 -0
  144. package/dist/src/ports/web.js +2 -0
  145. package/dist/src/run/api-run.d.ts +49 -0
  146. package/dist/src/run/api-run.js +173 -0
  147. package/dist/src/run/plan-run.d.ts +22 -0
  148. package/dist/src/run/plan-run.js +233 -0
  149. package/dist/src/run/plan.d.ts +36 -0
  150. package/dist/src/run/plan.js +119 -0
  151. package/dist/src/run/verify.d.ts +25 -0
  152. package/dist/src/run/verify.js +81 -0
  153. package/dist/src/security/redact.d.ts +7 -0
  154. package/dist/src/security/redact.js +21 -0
  155. package/dist/src/settings/env-config.d.ts +64 -0
  156. package/dist/src/settings/env-config.js +232 -0
  157. package/dist/src/storage/artifacts.d.ts +30 -0
  158. package/dist/src/storage/artifacts.js +105 -0
  159. package/dist/src/storage/audit.d.ts +6 -0
  160. package/dist/src/storage/audit.js +6 -0
  161. package/dist/src/storage/db.d.ts +9 -0
  162. package/dist/src/storage/db.js +43 -0
  163. package/dist/src/storage/events.d.ts +20 -0
  164. package/dist/src/storage/events.js +69 -0
  165. package/dist/src/storage/migrations.d.ts +8 -0
  166. package/dist/src/storage/migrations.js +48 -0
  167. package/dist/src/storage/outbox.d.ts +25 -0
  168. package/dist/src/storage/outbox.js +40 -0
  169. package/dist/src/storage/projections.d.ts +18 -0
  170. package/dist/src/storage/projections.js +40 -0
  171. package/dist/src/storage/reconcile.d.ts +14 -0
  172. package/dist/src/storage/reconcile.js +93 -0
  173. package/dist/src/storage/reservations.d.ts +12 -0
  174. package/dist/src/storage/reservations.js +80 -0
  175. package/dist/src/storage/store.d.ts +34 -0
  176. package/dist/src/storage/store.js +105 -0
  177. package/dist/src/team/attachments.d.ts +22 -0
  178. package/dist/src/team/attachments.js +211 -0
  179. package/dist/src/team/cli-models.d.ts +24 -0
  180. package/dist/src/team/cli-models.js +72 -0
  181. package/dist/src/team/config.d.ts +20 -0
  182. package/dist/src/team/config.js +111 -0
  183. package/dist/src/team/engine.d.ts +28 -0
  184. package/dist/src/team/engine.js +443 -0
  185. package/dist/src/team/journal.d.ts +30 -0
  186. package/dist/src/team/journal.js +70 -0
  187. package/dist/src/team/runners.d.ts +79 -0
  188. package/dist/src/team/runners.js +436 -0
  189. package/dist/src/team/secrets.d.ts +10 -0
  190. package/dist/src/team/secrets.js +68 -0
  191. package/dist/src/team/types.d.ts +155 -0
  192. package/dist/src/team/types.js +5 -0
  193. package/dist/src/tui/app.d.ts +29 -0
  194. package/dist/src/tui/app.js +96 -0
  195. package/dist/src/tui/control-model.d.ts +101 -0
  196. package/dist/src/tui/control-model.js +109 -0
  197. package/dist/src/tui/control-screens.d.ts +27 -0
  198. package/dist/src/tui/control-screens.js +85 -0
  199. package/dist/src/tui/graph-model.d.ts +34 -0
  200. package/dist/src/tui/graph-model.js +29 -0
  201. package/dist/src/tui/graph-screens.d.ts +13 -0
  202. package/dist/src/tui/graph-screens.js +4 -0
  203. package/dist/src/tui/inspector-model.d.ts +150 -0
  204. package/dist/src/tui/inspector-model.js +15 -0
  205. package/dist/src/tui/inspector-screens.d.ts +14 -0
  206. package/dist/src/tui/inspector-screens.js +61 -0
  207. package/dist/src/tui/live.d.ts +16 -0
  208. package/dist/src/tui/live.js +39 -0
  209. package/dist/src/tui/mission-action-screens.d.ts +15 -0
  210. package/dist/src/tui/mission-action-screens.js +105 -0
  211. package/dist/src/tui/mission-actions.d.ts +46 -0
  212. package/dist/src/tui/mission-actions.js +53 -0
  213. package/dist/src/tui/mission-model.d.ts +120 -0
  214. package/dist/src/tui/mission-model.js +164 -0
  215. package/dist/src/tui/mission-nav.d.ts +82 -0
  216. package/dist/src/tui/mission-nav.js +131 -0
  217. package/dist/src/tui/mission-plan-screens.d.ts +11 -0
  218. package/dist/src/tui/mission-plan-screens.js +40 -0
  219. package/dist/src/tui/mission-plan.d.ts +45 -0
  220. package/dist/src/tui/mission-plan.js +166 -0
  221. package/dist/src/tui/mission-screens.d.ts +7 -0
  222. package/dist/src/tui/mission-screens.js +263 -0
  223. package/dist/src/tui/provenance-label.d.ts +11 -0
  224. package/dist/src/tui/provenance-label.js +16 -0
  225. package/dist/src/tui/screens.d.ts +10 -0
  226. package/dist/src/tui/screens.js +34 -0
  227. package/dist/src/tui/session-outcome.d.ts +14 -0
  228. package/dist/src/tui/session-outcome.js +57 -0
  229. package/dist/src/tui/setup-model.d.ts +159 -0
  230. package/dist/src/tui/setup-model.js +234 -0
  231. package/dist/src/tui/setup-screens.d.ts +66 -0
  232. package/dist/src/tui/setup-screens.js +72 -0
  233. package/dist/src/tui/team/app.d.ts +24 -0
  234. package/dist/src/tui/team/app.js +228 -0
  235. package/dist/src/tui/team/demo-handle.d.ts +22 -0
  236. package/dist/src/tui/team/demo-handle.js +42 -0
  237. package/dist/src/tui/team/model.d.ts +81 -0
  238. package/dist/src/tui/team/model.js +133 -0
  239. package/gui/app.css +177 -0
  240. package/gui/app.js +675 -0
  241. package/gui/index.html +51 -0
  242. package/gui/network.js +413 -0
  243. package/package.json +45 -4
  244. package/src/storage/schema.sql +42 -0
@@ -0,0 +1,34 @@
1
+ import type { Envelope } from '../core/events.js';
2
+ export type GraphNodeKind = 'task' | 'dispatch' | 'ack' | 'result' | 'review' | 'completion' | 'unknown';
3
+ export interface GraphNode {
4
+ readonly id: string;
5
+ readonly seq: number;
6
+ readonly kind: GraphNodeKind;
7
+ readonly statusLabel: string;
8
+ readonly label: string;
9
+ readonly provenance: 'REAL' | 'SIMULATED';
10
+ readonly taskId: string;
11
+ }
12
+ export interface GraphEdge {
13
+ readonly from: string;
14
+ readonly to: string;
15
+ readonly kind: 'parent' | 'causation';
16
+ }
17
+ export interface GraphProjection {
18
+ readonly nodes: readonly GraphNode[];
19
+ readonly edges: readonly GraphEdge[];
20
+ readonly totalNodes: number;
21
+ readonly truncated: number;
22
+ readonly danglingEdges: number;
23
+ }
24
+ export declare const GRAPH_MAX_NODES = 128;
25
+ export declare function redactText(value: string): string;
26
+ export declare function buildCausalGraph(events: readonly Envelope[], options?: {
27
+ readonly maxNodes?: number;
28
+ }): GraphProjection;
29
+ export declare function graphSelection(nodes: readonly GraphNode[], index: number): GraphNode | null;
30
+ export declare function graphNodeDetail(events: readonly Envelope[], id: string): {
31
+ readonly label: string;
32
+ readonly content: string;
33
+ readonly source: string;
34
+ } | null;
@@ -0,0 +1,29 @@
1
+ export const GRAPH_MAX_NODES = 128;
2
+ export function redactText(value) { return value.replace(/(?:bearer\s+[\w.-]+|(?:api[_-]?key|token|password|secret)\s*[:=]\s*\S+)/gi, '[REDACTED]'); }
3
+ function describe(event) { const p = event.payload; switch (p.type) {
4
+ case 'TaskCreated': return { kind: 'task', statusLabel: 'open', label: `Task created: ${redactText(p.title)}` };
5
+ case 'AdvisorDispatched': return { kind: 'dispatch', statusLabel: 'waiting', label: `Advisor dispatched (${redactText(p.adapter)})` };
6
+ case 'AdvisorAcked': return { kind: 'ack', statusLabel: 'acknowledged', label: `Advisor acknowledged (${redactText(p.adapter)})` };
7
+ case 'AdvisorCompleted': return { kind: 'result', statusLabel: 'result reported', label: `Advisor completed: ${redactText(p.resultRef)}` };
8
+ case 'AdvisorUnknownOutcome': return { kind: 'unknown', statusLabel: 'unknown', label: `Advisor outcome unknown (${p.reason})` };
9
+ case 'TaskCompleted': return { kind: 'completion', statusLabel: p.outcome === 'success' ? 'done' : 'blocked', label: `Task completed: ${p.outcome}` };
10
+ case 'ReviewerSelected': return { kind: 'review', statusLabel: 'review selected', label: `Reviewer selected: ${redactText(p.reviewerId)} (evidence revision ${p.evidenceRevision})` };
11
+ } }
12
+ export function buildCausalGraph(events, options) { const all = events.map(event => { const desc = describe(event); return Object.freeze({ id: String(event.eventId), seq: event.sessionSequence, ...desc, provenance: event.provenance.source === 'simulated' ? 'SIMULATED' : 'REAL', taskId: String(event.taskId) }); }); const cap = options?.maxNodes ?? GRAPH_MAX_NODES; if (!Number.isSafeInteger(cap) || cap < 0)
13
+ throw new TypeError('maxNodes must be a non-negative safe integer'); const nodes = all.slice(Math.max(0, all.length - cap)); const kept = new Set(nodes.map(node => node.id)); const edges = []; const missing = new Set(); for (const event of events.slice(Math.max(0, events.length - cap))) {
14
+ const to = String(event.eventId);
15
+ for (const [ref, kind] of [[event.parentEventId, 'parent'], [event.causationId, 'causation']]) {
16
+ if (ref === null)
17
+ continue;
18
+ const from = String(ref);
19
+ if (kept.has(from))
20
+ edges.push(Object.freeze({ from, to, kind }));
21
+ else
22
+ missing.add(from);
23
+ }
24
+ } return Object.freeze({ nodes: Object.freeze(nodes), edges: Object.freeze(edges), totalNodes: all.length, truncated: all.length - nodes.length, danglingEdges: missing.size }); }
25
+ export function graphSelection(nodes, index) { if (nodes.length === 0)
26
+ return null; return nodes[Math.max(0, Math.min(nodes.length - 1, Number.isFinite(index) ? Math.trunc(index) : 0))] ?? null; }
27
+ export function graphNodeDetail(events, id) { const event = events.find(item => String(item.eventId) === id); if (!event)
28
+ return null; const { label } = describe(event); return Object.freeze({ label, content: redactText(JSON.stringify(event.payload)), source: `event:${event.eventId}` }); }
29
+ //# sourceMappingURL=graph-model.js.map
@@ -0,0 +1,13 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { GraphProjection, GraphNode } from './graph-model.js';
3
+ export interface GraphScreenProps {
4
+ readonly graph: GraphProjection;
5
+ readonly width: number;
6
+ readonly selected?: GraphNode;
7
+ readonly detail?: {
8
+ readonly label: string;
9
+ readonly content: string;
10
+ readonly source: string;
11
+ } | null;
12
+ }
13
+ export declare function GraphScreen({ graph, width, selected, detail }: GraphScreenProps): ReactElement;
@@ -0,0 +1,4 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text } from 'ink';
3
+ export function GraphScreen({ graph, width, selected, detail }) { return _jsxs(Box, { flexDirection: "column", width: width, children: [_jsxs(Text, { bold: true, children: ["Causal graph \u00B7 ", graph.nodes.length, " of ", graph.totalNodes, " nodes \u00B7 ", graph.edges.length, " edges (", graph.truncated, " omitted, ", graph.danglingEdges, " dangling)"] }), graph.nodes.map(node => _jsxs(Text, { children: [node.id === selected?.id ? '> ' : '', "[", node.kind.toUpperCase(), " ", node.statusLabel.toUpperCase(), "] ", node.label, " \u00B7 #", node.seq, " \u00B7 ", node.id, " \u00B7 ", node.provenance] }, node.id)), graph.edges.map((edge, index) => _jsxs(Text, { children: [edge.from, " -> ", edge.to, " (", edge.kind, ")"] }, `${edge.from}:${edge.to}:${edge.kind}:${index}`)), detail ? _jsxs(_Fragment, { children: [_jsx(Text, { children: detail.label }), _jsx(Text, { children: detail.content }), _jsxs(Text, { children: ["Source: ", detail.source] })] }) : null] }); }
4
+ //# sourceMappingURL=graph-screens.js.map
@@ -0,0 +1,150 @@
1
+ import type { LedgerEntry } from '../intent/ledger.js';
2
+ import type { RequirementRevision } from '../intent/revision.js';
3
+ import type { IdeaRecord } from '../intent/idea-ledger.js';
4
+ import type { ReviewerAudit, ScheduledReviewer, FinalDecision, SchedulerAccounting } from '../committee/reviewer-scheduler.js';
5
+ import type { PrimaryEpoch, RoleEpochEvent } from '../committee/role-epoch.js';
6
+ import type { PacketBudget, PrimaryContextPacket, ReviewerContextPacket } from '../intent/context-packet.js';
7
+ import type { CriterionEvaluation } from '../evidence/linker.js';
8
+ import type { EvidenceRecord, VerificationLevel } from '../evidence/store.js';
9
+ import type { CompletionResult } from '../orchestration/work-order-contract.js';
10
+ export interface IntentDiffView {
11
+ readonly number: number;
12
+ readonly revisionId: string;
13
+ readonly supersedesRevisionId: string | null;
14
+ readonly textBefore: string | null;
15
+ readonly textAfter: string;
16
+ readonly scopeChanged: boolean;
17
+ readonly scopeBefore: string | null;
18
+ readonly scopeAfter: string | null;
19
+ }
20
+ export interface IntentSourceView {
21
+ readonly entryId: string;
22
+ readonly kind: string;
23
+ readonly status: string;
24
+ readonly text: string;
25
+ readonly executionAuthorized: false;
26
+ readonly sourceId: string;
27
+ readonly origin: string;
28
+ readonly role: string;
29
+ readonly observedAt: string;
30
+ }
31
+ export interface IdeaDispositionSourceView {
32
+ readonly sourceId: string;
33
+ readonly origin: string;
34
+ readonly role: string;
35
+ readonly disposition: string | null;
36
+ readonly dispositionReason: string | null;
37
+ readonly evidenceCount: number;
38
+ }
39
+ export interface IdeaDispositionView {
40
+ readonly ideaId: string;
41
+ readonly text: string;
42
+ readonly status: string;
43
+ readonly dispositionReason: string | null;
44
+ readonly inContext: boolean;
45
+ readonly sources: readonly IdeaDispositionSourceView[];
46
+ }
47
+ export interface ReviewerRationaleView {
48
+ readonly audit: readonly {
49
+ readonly kind: string;
50
+ readonly reason: string | null;
51
+ readonly evidenceRevision: number | null;
52
+ readonly reviewerIds: readonly string[];
53
+ readonly late: boolean;
54
+ }[];
55
+ readonly reviewers: readonly {
56
+ readonly requestId: string;
57
+ readonly reviewerId: string;
58
+ readonly reason: string;
59
+ readonly status: string;
60
+ }[];
61
+ readonly finalDecision: {
62
+ readonly outcome: string;
63
+ readonly rationale: string;
64
+ } | null;
65
+ readonly lateCount: number;
66
+ }
67
+ export interface RoleSwitchView {
68
+ readonly currentEpoch: {
69
+ readonly epoch: number;
70
+ readonly primaryId: string;
71
+ readonly active: boolean;
72
+ };
73
+ readonly switches: readonly {
74
+ readonly from: string | null;
75
+ readonly to: string;
76
+ readonly epoch: number;
77
+ }[];
78
+ readonly responsesByEpoch: readonly {
79
+ readonly epoch: number;
80
+ readonly classification: 'current' | 'stale';
81
+ }[];
82
+ readonly primarySlotsRemaining: number;
83
+ }
84
+ export interface BudgetView {
85
+ readonly limit: number;
86
+ readonly measuredBytes: number;
87
+ readonly overflow: boolean;
88
+ readonly strategy: string;
89
+ readonly message: string;
90
+ readonly omittedEvidence: readonly string[];
91
+ readonly counters: readonly {
92
+ readonly label: string;
93
+ readonly value: number;
94
+ }[];
95
+ readonly quotaLabel: 'unknown';
96
+ readonly tokenLabel: 'unknown';
97
+ }
98
+ export interface EvidenceStatusSection {
99
+ readonly criterionId: string;
100
+ readonly requiredLevel: VerificationLevel;
101
+ readonly satisfied: boolean;
102
+ readonly escalation: string | null;
103
+ readonly links: readonly {
104
+ readonly evidenceId: string;
105
+ readonly verification: VerificationLevel;
106
+ readonly revision: string;
107
+ readonly cwd: string;
108
+ readonly raw: string;
109
+ readonly note: string;
110
+ }[];
111
+ }
112
+ export interface PacketPreviewView {
113
+ readonly kind: 'primary' | 'reviewer';
114
+ readonly headline: string;
115
+ readonly constraints: readonly string[];
116
+ readonly openAcceptanceCriteria: readonly {
117
+ readonly id: string;
118
+ readonly text: string;
119
+ readonly status: string;
120
+ }[];
121
+ readonly delta: string | null;
122
+ readonly question: string | null;
123
+ readonly evidence: readonly string[];
124
+ readonly budget: PacketBudget;
125
+ }
126
+ export declare function intentDiffView(revisions: readonly RequirementRevision[]): readonly IntentDiffView[];
127
+ export declare function intentSourceView(entries: readonly LedgerEntry[]): readonly IntentSourceView[];
128
+ export declare function ideaDispositionView(records: readonly IdeaRecord[]): readonly IdeaDispositionView[];
129
+ export declare function reviewerRationaleView(input: {
130
+ readonly audit: readonly ReviewerAudit[];
131
+ readonly reviewers: readonly ScheduledReviewer[];
132
+ readonly finalDecision: FinalDecision | null;
133
+ readonly lateResponses: readonly unknown[];
134
+ }): ReviewerRationaleView;
135
+ export declare function roleSwitchView(input: {
136
+ readonly epochs: readonly PrimaryEpoch[];
137
+ readonly events: readonly RoleEpochEvent[];
138
+ readonly responseHistory: readonly {
139
+ readonly epoch: number;
140
+ readonly classification: 'current' | 'stale';
141
+ }[];
142
+ readonly primarySlotsRemaining: number;
143
+ }): RoleSwitchView;
144
+ export declare function budgetView(input: {
145
+ readonly budget: PacketBudget;
146
+ readonly accounting?: SchedulerAccounting;
147
+ }): BudgetView;
148
+ export declare function evidenceStatusSection(criterionId: string, requiredLevel: VerificationLevel, evaluation: CriterionEvaluation, records: readonly EvidenceRecord[]): EvidenceStatusSection;
149
+ export declare function completionReasonView(result: CompletionResult): readonly string[];
150
+ export declare function packetPreviewView(packet: PrimaryContextPacket | ReviewerContextPacket): PacketPreviewView;
@@ -0,0 +1,15 @@
1
+ const freeze = (value) => Object.freeze(value);
2
+ export function intentDiffView(revisions) { return Object.freeze(revisions.map(revision => freeze({ number: revision.number, revisionId: revision.id, supersedesRevisionId: revision.supersedesRevisionId, textBefore: revision.diff?.text.before ?? null, textAfter: revision.diff?.text.after ?? revision.text, scopeChanged: revision.diff?.scope !== undefined, scopeBefore: revision.diff?.scope ? JSON.stringify(revision.diff.scope.before) : null, scopeAfter: revision.diff?.scope ? JSON.stringify(revision.diff.scope.after) : null }))); }
3
+ export function intentSourceView(entries) { return Object.freeze(entries.map(entry => freeze({ entryId: entry.id, kind: entry.kind, status: entry.status, text: entry.text, executionAuthorized: false, sourceId: entry.source.sourceId, origin: entry.source.origin, role: entry.source.role, observedAt: entry.source.observedAt }))); }
4
+ export function ideaDispositionView(records) { return Object.freeze(records.map(record => freeze({ ideaId: record.ideaId, text: record.text, status: record.status, dispositionReason: record.dispositionReason, inContext: record.status !== 'rejected', sources: Object.freeze(record.sourceTraces.map(trace => freeze({ sourceId: trace.source.sourceId, origin: trace.source.origin, role: trace.source.role, disposition: trace.disposition, dispositionReason: trace.dispositionReason, evidenceCount: trace.evidenceRefs.length }))) }))); }
5
+ export function reviewerRationaleView(input) { return freeze({ audit: Object.freeze(input.audit.map(item => freeze({ kind: item.kind, reason: item.reason ?? null, evidenceRevision: item.evidenceRevision ?? null, reviewerIds: Object.freeze([...(item.reviewerIds ?? [])]), late: item.late ?? false }))), reviewers: Object.freeze(input.reviewers.map(item => freeze({ requestId: item.requestId, reviewerId: item.reviewerId, reason: item.reason, status: item.status }))), finalDecision: input.finalDecision ? freeze({ outcome: input.finalDecision.outcome, rationale: input.finalDecision.rationale }) : null, lateCount: input.lateResponses.length }); }
6
+ export function roleSwitchView(input) { const current = input.epochs[input.epochs.length - 1]; return freeze({ currentEpoch: freeze({ epoch: current?.epoch ?? 0, primaryId: current?.primaryId ?? '', active: current?.active ?? false }), switches: Object.freeze(input.events.filter((event) => event.kind === 'role-switched').map(event => freeze({ from: event.from, to: event.to, epoch: event.epoch }))), responsesByEpoch: Object.freeze(input.responseHistory.map(item => freeze({ epoch: item.epoch, classification: item.classification }))), primarySlotsRemaining: input.primarySlotsRemaining }); }
7
+ export function budgetView(input) { const counters = []; if (input.accounting) {
8
+ counters.push({ label: 'primaryCalls', value: input.accounting.primaryCalls }, { label: 'acknowledgementCalls', value: input.accounting.acknowledgementCalls }, { label: 'workOrders', value: input.accounting.workOrders });
9
+ for (const [label, value] of Object.entries(input.accounting.reviewerCalls))
10
+ counters.push({ label: `reviewerCalls:${label}`, value });
11
+ } return freeze({ limit: input.budget.limit, measuredBytes: input.budget.measuredBytes, overflow: input.budget.overflow, strategy: input.budget.strategy, message: input.budget.message, omittedEvidence: Object.freeze([...input.budget.omittedEvidence]), counters: Object.freeze(counters.map(item => freeze(item))), quotaLabel: 'unknown', tokenLabel: 'unknown' }); }
12
+ export function evidenceStatusSection(criterionId, requiredLevel, evaluation, records) { const byId = new Map(records.map(record => [record.id, record])); return freeze({ criterionId, requiredLevel, satisfied: evaluation.satisfied, escalation: evaluation.escalation, links: Object.freeze(evaluation.links.map(link => { const record = byId.get(link.evidenceId); return freeze({ evidenceId: link.evidenceId, verification: record?.verification ?? link.verification, revision: record?.revision ?? link.revision, cwd: record?.cwd ?? link.cwd, raw: record?.raw ?? '', note: record?.verification === 'reported' ? 'needs observation/verification' : record?.verification === 'observed' && requiredLevel === 'verified' ? 'needs verification' : record ? `verification ${record.verification}` : 'evidence record unavailable' }); })) }); }
13
+ export function completionReasonView(result) { return Object.freeze([...result.reasonIds]); }
14
+ export function packetPreviewView(packet) { return freeze({ kind: packet.kind, headline: packet.kind === 'primary' ? packet.intent : packet.question, constraints: Object.freeze([...packet.constraints]), openAcceptanceCriteria: packet.kind === 'primary' ? Object.freeze(packet.openAcceptanceCriteria.map(item => freeze({ id: item.id, text: item.text, status: item.status }))) : Object.freeze([]), delta: packet.kind === 'primary' ? packet.delta : null, question: packet.kind === 'reviewer' ? packet.question : null, evidence: Object.freeze([...packet.evidence]), budget: freeze({ ...packet.budget, omittedEvidence: Object.freeze([...packet.budget.omittedEvidence]) }) }); }
15
+ //# sourceMappingURL=inspector-model.js.map
@@ -0,0 +1,14 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { BudgetView, EvidenceStatusSection, IdeaDispositionView, IntentDiffView, IntentSourceView, PacketPreviewView, ReviewerRationaleView, RoleSwitchView } from './inspector-model.js';
3
+ export interface InspectorScreenProps {
4
+ readonly intent?: readonly IntentDiffView[];
5
+ readonly intentSources?: readonly IntentSourceView[];
6
+ readonly ideas?: readonly IdeaDispositionView[];
7
+ readonly reviewers?: ReviewerRationaleView;
8
+ readonly roles?: RoleSwitchView;
9
+ readonly budgets?: readonly BudgetView[];
10
+ readonly evidence?: readonly EvidenceStatusSection[];
11
+ readonly completionReasons?: readonly string[];
12
+ readonly packet?: PacketPreviewView;
13
+ }
14
+ export declare function InspectorScreen(props: InspectorScreenProps): ReactElement;
@@ -0,0 +1,61 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Box, Text } from 'ink';
3
+ export function InspectorScreen(props) {
4
+ const lines = [];
5
+ for (const item of props.intent ?? [])
6
+ lines.push(`Intent revision ${item.number} · ${item.revisionId} · supersedes ${item.supersedesRevisionId ?? 'none'} · scope changed ${item.scopeChanged ? 'yes' : 'no'} · scope before ${item.scopeBefore ?? 'none'} · scope after ${item.scopeAfter ?? 'none'} · text before ${item.textBefore ?? 'none'} · text after ${item.textAfter}`);
7
+ for (const item of props.intentSources ?? [])
8
+ lines.push(`Intent source ${item.sourceId} · ${item.origin} · ${item.role} · ${item.status} · execution authorized ${item.executionAuthorized ? 'yes' : 'no'} · observed ${item.observedAt} · ${item.text}`);
9
+ for (const idea of props.ideas ?? []) {
10
+ lines.push(`Idea ${idea.ideaId} · ${idea.status} · ${idea.inContext ? 'included in context' : 'suppressed from context'} · ${idea.dispositionReason ?? 'no disposition reason'} · ${idea.text}`);
11
+ for (const source of idea.sources)
12
+ lines.push(`Idea source ${source.sourceId} · ${source.origin} · ${source.role} · disposition ${source.disposition ?? 'none'} · reason ${source.dispositionReason ?? 'none'} · evidence count ${source.evidenceCount}`);
13
+ }
14
+ for (const item of props.reviewers?.audit ?? [])
15
+ lines.push(`Reviewer audit ${item.kind} · reason ${item.reason ?? 'none'} · evidence revision ${item.evidenceRevision ?? 'unknown'} · reviewers ${item.reviewerIds.join(', ') || 'none'} · late ${item.late ? 'yes' : 'no'}`);
16
+ for (const item of props.reviewers?.reviewers ?? [])
17
+ lines.push(`Reviewer ${item.reviewerId} · ${item.status} · request ${item.requestId} · rationale ${item.reason}`);
18
+ if (props.reviewers?.finalDecision)
19
+ lines.push(`Final decision ${props.reviewers.finalDecision.outcome} · ${props.reviewers.finalDecision.rationale}`);
20
+ if (props.reviewers)
21
+ lines.push(`Late responses ${props.reviewers.lateCount}`);
22
+ if (props.roles) {
23
+ lines.push(`Primary epoch ${props.roles.currentEpoch.epoch} · ${props.roles.currentEpoch.primaryId} · active ${props.roles.currentEpoch.active ? 'yes' : 'no'} · slots remaining ${props.roles.primarySlotsRemaining}`);
24
+ for (const item of props.roles.switches)
25
+ lines.push(`Role switched epoch ${item.epoch} · from ${item.from ?? 'none'} · to ${item.to}`);
26
+ for (const item of props.roles.responsesByEpoch)
27
+ lines.push(`Response epoch ${item.epoch} · ${item.classification}`);
28
+ }
29
+ for (const item of props.budgets ?? []) {
30
+ lines.push(`Budget ${item.measuredBytes}/${item.limit} bytes · ${item.overflow ? 'overflow' : 'within budget'} · strategy ${item.strategy} · quota ${item.quotaLabel} · tokens ${item.tokenLabel} · ${item.message}`);
31
+ for (const counter of item.counters)
32
+ lines.push(`Counter ${counter.label}: ${counter.value}`);
33
+ for (const evidence of item.omittedEvidence)
34
+ lines.push(`Omitted evidence: ${evidence}`);
35
+ }
36
+ for (const item of props.evidence ?? []) {
37
+ lines.push(`Evidence criterion ${item.criterionId} · required ${item.requiredLevel} · ${item.satisfied ? 'satisfied' : 'not satisfied'} · escalation ${item.escalation ?? 'none'}`);
38
+ for (const link of item.links)
39
+ lines.push(`Evidence ${link.evidenceId} · ${link.verification} · revision ${link.revision} · cwd ${link.cwd} · ${link.note} · raw ${link.raw}`);
40
+ }
41
+ for (const reason of props.completionReasons ?? [])
42
+ lines.push(`Completion reason: ${reason}`);
43
+ if (props.packet) {
44
+ lines.push(`Packet ${props.packet.kind} · ${props.packet.headline}`);
45
+ if (props.packet.question !== null)
46
+ lines.push(`Question: ${props.packet.question}`);
47
+ for (const constraint of props.packet.constraints)
48
+ lines.push(`Constraint: ${constraint}`);
49
+ for (const criterion of props.packet.openAcceptanceCriteria)
50
+ lines.push(`Open acceptance ${criterion.id} · ${criterion.status} · ${criterion.text}`);
51
+ if (props.packet.delta !== null)
52
+ lines.push(`Delta: ${props.packet.delta}`);
53
+ for (const evidence of props.packet.evidence)
54
+ lines.push(`Evidence: ${evidence}`);
55
+ lines.push(`Packet budget ${props.packet.budget.measuredBytes}/${props.packet.budget.limit} bytes · ${props.packet.budget.overflow ? 'overflow' : 'within budget'} · ${props.packet.budget.strategy} · ${props.packet.budget.message}`);
56
+ for (const omitted of props.packet.budget.omittedEvidence)
57
+ lines.push(`Omitted evidence: ${omitted}`);
58
+ }
59
+ return _jsx(Box, { flexDirection: "column", children: lines.length ? lines.map((line, index) => _jsx(Text, { children: line }, `${index}:${line}`)) : _jsx(Text, { children: "No inspector data available." }) });
60
+ }
61
+ //# sourceMappingURL=inspector-screens.js.map
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import type { Envelope } from '../core/events.js';
3
+ import { type ViewControllerOptions } from './app.js';
4
+ import type { SetupModel } from './setup-model.js';
5
+ export declare const LIVE_POLL_MS = 700;
6
+ export interface LiveAppProps {
7
+ readonly initial: readonly Envelope[];
8
+ readonly load: () => Promise<readonly Envelope[]>;
9
+ readonly intervalMs?: number;
10
+ readonly setupModel?: SetupModel;
11
+ readonly viewOptions?: ViewControllerOptions;
12
+ readonly now?: () => Date;
13
+ }
14
+ /** Journal identity: count + last event id per session order. Cheap and stable across identical re-reads. */
15
+ export declare const journalSignature: (events: readonly Envelope[]) => string;
16
+ export declare function LiveApp({ initial, load, intervalMs, setupModel, viewOptions, now }: LiveAppProps): React.JSX.Element;
@@ -0,0 +1,39 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // `ckit tui` live follow: re-reads the recorded journal on an interval and re-renders App when it changes.
3
+ // Read-only: the loader only reads; nothing is sent, resent or written. A failed read keeps the last good frame.
4
+ import React, { useEffect, useRef, useState } from 'react';
5
+ import { Box, Text } from 'ink';
6
+ import { App } from './app.js';
7
+ export const LIVE_POLL_MS = 700;
8
+ /** Journal identity: count + last event id per session order. Cheap and stable across identical re-reads. */
9
+ export const journalSignature = (events) => `${events.length}:${events.at(-1)?.eventId ?? ''}`;
10
+ const isRunning = (events) => { const open = new Set(); for (const e of events) {
11
+ if (e.payload.type === 'TaskCreated')
12
+ open.add(e.sessionId);
13
+ else if (e.payload.type === 'TaskCompleted')
14
+ open.delete(e.sessionId);
15
+ } return open.size > 0; };
16
+ const clock = (d) => d.toTimeString().slice(0, 8);
17
+ export function LiveApp({ initial, load, intervalMs = LIVE_POLL_MS, setupModel, viewOptions, now = () => new Date() }) {
18
+ const [events, setEvents] = useState(initial);
19
+ const [status, setStatus] = useState({ at: clock(now()), error: false });
20
+ const sig = useRef(journalSignature(initial)), busy = useRef(false);
21
+ useEffect(() => {
22
+ let alive = true;
23
+ const timer = setInterval(() => {
24
+ if (busy.current)
25
+ return;
26
+ busy.current = true;
27
+ load().then(next => { if (!alive)
28
+ return; const s = journalSignature(next); if (s !== sig.current) {
29
+ sig.current = s;
30
+ setEvents(next);
31
+ } setStatus({ at: clock(now()), error: false }); }, () => { if (alive)
32
+ setStatus(prev => ({ at: prev.at, error: true })); }).finally(() => { busy.current = false; });
33
+ }, intervalMs);
34
+ return () => { alive = false; clearInterval(timer); };
35
+ }, [load, intervalMs, now]);
36
+ const running = isRunning(events);
37
+ return _jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { children: [running ? '● LIVE · run in progress' : '○ LIVE · idle (waiting for a run)', " \u00B7 ", events.length, " events \u00B7 updated ", status.at, status.error ? ' · journal read failed, showing last good frame' : '', " \u00B7 q quit"] }), _jsx(App, { events: events, ...setupModel ? { setupModel } : {}, ...viewOptions ? { viewOptions } : {} })] });
38
+ }
39
+ //# sourceMappingURL=live.js.map
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { type MissionMode, type MissionSelection, type MissionView } from './mission-model.js';
3
+ import { type MissionBindings } from './mission-actions.js';
4
+ export declare function MissionActionPanel({ active, selection, mode, bindings, view, revision, maxRows: maxRowsProp }: {
5
+ active: boolean;
6
+ selection: MissionSelection;
7
+ mode: MissionMode;
8
+ bindings: MissionBindings;
9
+ view: MissionView;
10
+ revision?: {
11
+ request: number;
12
+ current: number;
13
+ };
14
+ maxRows?: number;
15
+ }): React.JSX.Element;
@@ -0,0 +1,105 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import stringWidth from 'string-width';
3
+ import React, { useContext, useState } from 'react';
4
+ import { Box, Text, useInput, useStdout } from 'ink';
5
+ import { redactSecretText } from '../security/redact.js';
6
+ import { InspectorBudgetContext, bindingLabel } from './mission-model.js';
7
+ import { ACTION_LABEL, MISSION_ACTIONS, invokeMissionAction, missionActionState, receiptLabel } from './mission-actions.js';
8
+ const clean = (v) => redactSecretText(v).replace(/\s+/g, ' ').trim();
9
+ const KEY_ACTION = { s: 'send', p: 'pause-dispatch', r: 'resume' };
10
+ function resolveTarget(sel, view) {
11
+ if (sel === null)
12
+ return null;
13
+ if (sel.kind === 'agent') {
14
+ const a = view.agents.find(x => x.id === sel.id);
15
+ if (!a)
16
+ return null;
17
+ const e = view.entries.find(x => x.sessionId === a.sessionId && (x.sender === a.id || x.recipients.includes(a.id))) ?? view.entries.find(x => x.sessionId === a.sessionId);
18
+ return { agentId: a.id, sessionId: a.sessionId, taskId: e?.taskId ?? 'unknown' };
19
+ }
20
+ if (sel.kind === 'entry') {
21
+ const e = view.entries.find(x => x.id === sel.id);
22
+ if (!e)
23
+ return null;
24
+ return { agentId: e.recipients[0] ?? e.sender ?? 'unknown', sessionId: e.sessionId, taskId: e.taskId };
25
+ }
26
+ const e = view.entries.find(x => x.taskId === sel.id);
27
+ return e ? { agentId: e.recipients[0] ?? e.sender ?? 'unknown', sessionId: e.sessionId, taskId: sel.id } : null;
28
+ }
29
+ export function MissionActionPanel({ active, selection, mode, bindings, view, revision, maxRows: maxRowsProp }) {
30
+ const ctxRows = useContext(InspectorBudgetContext);
31
+ const maxRows = maxRowsProp ?? ctxRows;
32
+ const [cursor, setCursor] = useState(0);
33
+ const [pending, setPending] = useState(null);
34
+ const [receipt, setReceipt] = useState(null);
35
+ const [notice, setNotice] = useState(null);
36
+ const target = resolveTarget(selection, view);
37
+ const unknownDelivery = target !== null && view.entries.some(e => e.sessionId === target.sessionId && e.taskId === target.taskId && e.facets.some(f => f.facet === 'unknown_delivery'));
38
+ const live = mode === 'LIVE';
39
+ const state = (a) => target === null ? { enabled: false, reason: 'no selection' } : missionActionState(mode, a, bindings, { unknownDelivery });
40
+ const begin = (a) => { setCursor(MISSION_ACTIONS.indexOf(a)); setNotice(null); if (state(a).enabled)
41
+ setPending(a);
42
+ else
43
+ setNotice(`${ACTION_LABEL[a]}: ${state(a).reason}`); };
44
+ useInput((input, key) => {
45
+ if (!active || !live || key.ctrl || key.meta)
46
+ return;
47
+ if (pending !== null) {
48
+ if (input === 'y' || input === 'Y') {
49
+ const a = pending;
50
+ setPending(null);
51
+ if (target === null) {
52
+ setNotice('not invoked: no target selected');
53
+ return;
54
+ }
55
+ const res = invokeMissionAction(a, target, mode, bindings, { confirmed: true, unknownDelivery, ...revision ? { revision } : {} });
56
+ if (res.invoked && res.receipt) {
57
+ setReceipt({ action: a, r: res.receipt });
58
+ setNotice(null);
59
+ }
60
+ else
61
+ setNotice(res.reason === 'stale-revision' ? 'refresh required — request revision is stale; nothing was sent' : `not invoked: ${res.reason}`);
62
+ }
63
+ else {
64
+ setPending(null);
65
+ setNotice(null);
66
+ }
67
+ return;
68
+ }
69
+ if (key.upArrow || input === 'k')
70
+ setCursor(c => Math.max(0, c - 1));
71
+ else if (key.downArrow || input === 'j')
72
+ setCursor(c => Math.min(MISSION_ACTIONS.length - 1, c + 1));
73
+ else if (input === 'x' || key.return)
74
+ begin(MISSION_ACTIONS[cursor]);
75
+ else if (KEY_ACTION[input])
76
+ begin(KEY_ACTION[input]);
77
+ }, { isActive: active && live });
78
+ const head = live ? 'Actions · LIVE' : `Actions · ${mode} — controls disabled`;
79
+ const who = target === null ? '' : clean(`${bindingLabel(target.agentId)} · session ${target.sessionId} · task ${target.taskId}`);
80
+ const items = [
81
+ _jsx(Text, { bold: true, wrap: "truncate-end", children: head }, "head"),
82
+ ...(target !== null ? [_jsxs(Text, { dimColor: true, wrap: "truncate-end", children: ["Target: ", who] }, "target")] : []),
83
+ ...MISSION_ACTIONS.map((a, i) => { const st = state(a); return _jsxs(Text, { wrap: "truncate-end", dimColor: !st.enabled, children: [live && i === cursor ? '> ' : ' ', ACTION_LABEL[a], st.enabled ? ' · available' : ` · unavailable: ${st.reason}`] }, a); }),
84
+ ...(pending !== null && target !== null ? [_jsxs(Text, { color: "yellow", wrap: "wrap", children: [pending === 'send' ? 'Send' : ACTION_LABEL[pending], " to ", who, "? [y/N]"] }, "pending")] : []),
85
+ ...(notice !== null ? [_jsx(Text, { color: "yellow", wrap: "wrap", children: notice }, "notice")] : []),
86
+ receipt !== null && target !== null ? _jsxs(Text, { wrap: "wrap", children: ["Receipt: ", ACTION_LABEL[receipt.action], " \u00B7 ", receiptLabel(receipt.r), " \u00B7 ", clean(bindingLabel(receipt.r.target.agentId))] }, "receipt") : _jsx(Text, { dimColor: true, children: "No receipts yet" }, "receipt"),
87
+ ...(live && pending === null ? [_jsx(Text, { dimColor: true, wrap: "truncate-end", children: "j/k move \u00B7 x or Enter run row \u00B7 s send \u00B7 p pause dispatch \u00B7 r resume \u00B7 y confirm \u00B7 any other key cancels" }, "help")] : [])
88
+ ];
89
+ // Wrapped rows (pending/notice/receipt) can span several terminal lines: count them, so truncation is announced rather than silently clipped.
90
+ const cols = Math.max(10, (useStdout().stdout.columns ?? 80) - 4);
91
+ const text = { pending: `${pending === 'send' ? 'Send' : pending ? ACTION_LABEL[pending] : ''} to ${who}? [y/N]`, notice: notice ?? '', receipt: receipt ? `Receipt: ${ACTION_LABEL[receipt.action]} · ${receiptLabel(receipt.r)} · ${clean(bindingLabel(receipt.r.target.agentId))}` : '' };
92
+ const height = (el) => { const t = text[String(el.key)]; return t === undefined ? 1 : Math.max(1, Math.ceil(stringWidth(t) / cols)); };
93
+ let used = 0, keep = 0;
94
+ const budget = maxRows === undefined ? Infinity : maxRows;
95
+ for (const el of items) {
96
+ const h = height(el);
97
+ const last = keep === items.length - 1;
98
+ if (used + h + (last ? 0 : 1) > budget && !(last && used + h <= budget))
99
+ break;
100
+ used += h;
101
+ keep++;
102
+ }
103
+ return _jsxs(Box, { flexDirection: "column", children: [items.slice(0, keep), keep < items.length ? _jsxs(Text, { dimColor: true, wrap: "truncate-end", children: ["\u2026 ", items.length - keep, " more"] }, "more") : null] });
104
+ }
105
+ //# sourceMappingURL=mission-action-screens.js.map
@@ -0,0 +1,46 @@
1
+ import type { ControlDecision } from '../adapters/agent/worker-service.js';
2
+ import type { MissionMode } from './mission-model.js';
3
+ export type MissionAction = 'send' | 'pause-dispatch' | 'interrupt' | 'resume' | 'approve' | 'reject' | 'open-native';
4
+ export declare const MISSION_ACTIONS: readonly MissionAction[];
5
+ export interface MissionTarget {
6
+ agentId: string;
7
+ sessionId: string;
8
+ taskId: string;
9
+ }
10
+ /** Only existing injected callbacks can be invoked. approve/reject are accepted only when a caller injects them (no runtime port exists yet). */
11
+ export interface MissionBindings {
12
+ readonly send?: () => void;
13
+ readonly pause?: () => void;
14
+ readonly resume?: () => void;
15
+ readonly approve?: () => void;
16
+ readonly reject?: () => void;
17
+ }
18
+ export interface MissionReceipt {
19
+ state: 'requested' | 'pending-ack' | 'acknowledged' | 'unknown';
20
+ target: MissionTarget;
21
+ ackToken?: string;
22
+ }
23
+ export type MissionRefusal = 'mode' | 'unbound' | 'unsupported' | 'stale-revision' | 'unconfirmed';
24
+ export interface MissionInvocation {
25
+ invoked: boolean;
26
+ reason: MissionRefusal | null;
27
+ receipt: MissionReceipt | null;
28
+ }
29
+ export declare const ACTION_LABEL: Record<MissionAction, string>;
30
+ export declare function missionActionState(mode: MissionMode, action: MissionAction, bindings: MissionBindings, facts: {
31
+ unknownDelivery: boolean;
32
+ }): {
33
+ enabled: boolean;
34
+ reason: string | null;
35
+ };
36
+ export declare function invokeMissionAction(action: MissionAction, target: MissionTarget, mode: MissionMode, bindings: MissionBindings, opts: {
37
+ confirmed: boolean;
38
+ revision?: {
39
+ request: number;
40
+ current: number;
41
+ };
42
+ unknownDelivery?: boolean;
43
+ }): MissionInvocation;
44
+ /** Maps an existing ControlDecision to a receipt. Only decision.evidence with an ackToken may read as acknowledged. */
45
+ export declare function receiptFromDecision(d: ControlDecision, target: MissionTarget): MissionReceipt;
46
+ export declare function receiptLabel(r: MissionReceipt): string;
@@ -0,0 +1,53 @@
1
+ export const MISSION_ACTIONS = ['send', 'pause-dispatch', 'interrupt', 'resume', 'approve', 'reject', 'open-native'];
2
+ export const ACTION_LABEL = { send: 'Send', 'pause-dispatch': 'Pause dispatch (no new assignments)', interrupt: 'Interrupt', resume: 'Resume', approve: 'Approve', reject: 'Reject', 'open-native': 'Open native' };
3
+ const NO_PORT = 'no runtime interrupt port (T09-03/T05-04/T08-04)';
4
+ const NO_NATIVE = 'no native-open port (T09-03/T05-04/T08-04)';
5
+ const modeReason = (m) => `${m} — controls disabled`;
6
+ const bound = (a, b) => a === 'send' ? b.send : a === 'pause-dispatch' ? b.pause : a === 'resume' ? b.resume : a === 'approve' ? b.approve : a === 'reject' ? b.reject : undefined;
7
+ /** Gate order: mode -> capability/binding -> revision -> confirmation -> callback. */
8
+ function gate(action, mode, b, o) {
9
+ if (mode !== 'LIVE')
10
+ return 'mode';
11
+ if (action === 'interrupt' || action === 'open-native')
12
+ return 'unsupported';
13
+ if (bound(action, b) === undefined)
14
+ return 'unbound';
15
+ if (o?.revision && o.revision.request !== o.revision.current)
16
+ return 'stale-revision';
17
+ if (o && !o.confirmed)
18
+ return 'unconfirmed';
19
+ return null;
20
+ }
21
+ export function missionActionState(mode, action, bindings, facts) {
22
+ const g = gate(action, mode, bindings);
23
+ if (g === 'mode')
24
+ return { enabled: false, reason: modeReason(mode) };
25
+ if (g === 'unsupported')
26
+ return { enabled: false, reason: action === 'interrupt' ? NO_PORT : NO_NATIVE };
27
+ if (g === 'unbound')
28
+ return { enabled: false, reason: action === 'approve' || action === 'reject' ? 'no approval port bound (T09-03/T05-04/T08-04)' : 'not bound in this session' };
29
+ if (action === 'send' && facts.unknownDelivery)
30
+ return { enabled: false, reason: 'Resend disabled: delivery unknown — reconcile first' };
31
+ return { enabled: true, reason: null };
32
+ }
33
+ export function invokeMissionAction(action, target, mode, bindings, opts) {
34
+ const g = gate(action, mode, bindings, opts);
35
+ if (g !== null)
36
+ return { invoked: false, reason: g, receipt: null };
37
+ if (action === 'send' && opts.unknownDelivery === true)
38
+ return { invoked: false, reason: 'unsupported', receipt: null };
39
+ bound(action, bindings)();
40
+ return { invoked: true, reason: null, receipt: { state: 'requested', target } };
41
+ }
42
+ /** Maps an existing ControlDecision to a receipt. Only decision.evidence with an ackToken may read as acknowledged. */
43
+ export function receiptFromDecision(d, target) {
44
+ if (d.action === 'interrupted' && d.evidence !== null)
45
+ return { state: 'acknowledged', target, ackToken: d.evidence.ackToken };
46
+ if (d.action === 'awaiting-ack')
47
+ return { state: 'pending-ack', target };
48
+ return { state: 'requested', target };
49
+ }
50
+ export function receiptLabel(r) {
51
+ return r.state === 'requested' ? 'requested' : r.state === 'pending-ack' ? 'pending runtime acknowledgement' : r.state === 'acknowledged' ? `runtime-acknowledged · ${r.ackToken ?? 'unknown'}` : 'unknown';
52
+ }
53
+ //# sourceMappingURL=mission-actions.js.map