@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,155 @@
1
+ /** How an agent is executed. `api` = OpenAI-compatible chat (no tools, uses the CKit advisor endpoint); `auto` = Director only, rule-based, no model. `simulated` = scripted offline demo agent. */
2
+ export type AgentCli = 'codex' | 'claude-code' | 'omp' | 'api' | 'auto' | 'simulated';
3
+ /** Every agent can read the whole project. read = read only (must not change files); write = read AND change files inside the project (codex workspace-write, claude acceptEdits). Never bypass. */
4
+ export type AgentAccess = 'read' | 'write';
5
+ export type TeamId = 'director' | 'ba' | 'implement' | 'qc';
6
+ export interface AgentConfig {
7
+ readonly id: string;
8
+ readonly name: string;
9
+ readonly team: TeamId;
10
+ readonly cli: AgentCli;
11
+ readonly model: string | null;
12
+ readonly access: AgentAccess;
13
+ readonly persona?: string;
14
+ /** cli 'api' only: per-agent OpenAI-compatible endpoint (must include the version segment, e.g. https://host/v1). Absent = the CKit advisor endpoint. */
15
+ readonly baseUrl?: string;
16
+ /** cli 'api' only: name of the stored secret holding this agent's API key (see src/team/secrets.ts); never the key itself. Absent = the CKit advisor key. */
17
+ readonly apiKeyRef?: string;
18
+ }
19
+ /** What an attached file is, for prompts and the UI: image = picture; document = PDF/Office-like; text = readable as plain text (code, xml, drawio, csv...); file = other binary. */
20
+ export type AttachmentKind = 'image' | 'text' | 'document' | 'file';
21
+ /** An owner attachment stored in the run folder. Paths are project-relative with forward slashes, so agents (cwd = project folder) can open them as written. */
22
+ export interface AttachmentInfo {
23
+ readonly name: string;
24
+ readonly path: string;
25
+ readonly size: number;
26
+ readonly kind: AttachmentKind;
27
+ /** Plain-text version extracted by CKit (.docx/.xlsx/.pptx), when extraction worked. */
28
+ readonly textPath?: string;
29
+ }
30
+ export interface TeamConfig {
31
+ readonly version: 1;
32
+ readonly director: AgentConfig;
33
+ readonly teams: {
34
+ readonly ba: readonly AgentConfig[];
35
+ readonly implement: readonly AgentConfig[];
36
+ readonly qc: readonly AgentConfig[];
37
+ };
38
+ readonly limits: {
39
+ readonly baRounds: number;
40
+ readonly qcLoops: number;
41
+ readonly agentTimeoutMs: number;
42
+ };
43
+ }
44
+ /** Company pipeline stages, in order. */
45
+ export declare const STAGES: readonly ['director-intake', 'ba-discussion', 'implement', 'qc', 'ba-review', 'delivery'];
46
+ export type Stage = typeof STAGES[number];
47
+ export type AgentState = 'idle' | 'thinking' | 'done' | 'failed' | 'waiting';
48
+ /** One journal line (JSONL, append-only, `.ckit/team/runs/<runId>/events.jsonl`). All text is secret-redacted before it is written or emitted. */
49
+ export type TeamEvent = {
50
+ readonly seq: number;
51
+ readonly at: string;
52
+ readonly runId: string;
53
+ } & ({
54
+ readonly type: 'run.started';
55
+ readonly goal: string;
56
+ readonly config: TeamConfig;
57
+ readonly simulated: boolean;
58
+ readonly attachments?: readonly AttachmentInfo[];
59
+ } | {
60
+ readonly type: 'stage.changed';
61
+ readonly stage: Stage;
62
+ readonly loop: number;
63
+ } | {
64
+ readonly type: 'agent.started';
65
+ readonly agentId: string;
66
+ readonly task: string;
67
+ }
68
+ /** Streamed progress while an agent works (tool call, partial thought). Short, one line. */
69
+ | {
70
+ readonly type: 'agent.activity';
71
+ readonly agentId: string;
72
+ readonly text: string;
73
+ }
74
+ /** A finished turn. `to` = addressee agent id, team id, or 'all'. */
75
+ | {
76
+ readonly type: 'agent.message';
77
+ readonly agentId: string;
78
+ readonly to: string;
79
+ readonly text: string;
80
+ readonly tokens: number | null;
81
+ } | {
82
+ readonly type: 'agent.failed';
83
+ readonly agentId: string;
84
+ readonly reason: string;
85
+ }
86
+ /** Current step of an agent's turn, for "who is doing what, how far": e.g. step 2/4 "Writing the settings toggle". */
87
+ | {
88
+ readonly type: 'agent.step';
89
+ readonly agentId: string;
90
+ readonly step: number;
91
+ readonly total: number | null;
92
+ readonly label: string;
93
+ }
94
+ /** A helper spawned by an agent (claude Task subagent, codex sub-process...). childId unique per run. */
95
+ | {
96
+ readonly type: 'subagent.started';
97
+ readonly agentId: string;
98
+ readonly childId: string;
99
+ readonly kind: string | null;
100
+ readonly task: string;
101
+ } | {
102
+ readonly type: 'subagent.activity';
103
+ readonly agentId: string;
104
+ readonly childId: string;
105
+ readonly text: string;
106
+ } | {
107
+ readonly type: 'subagent.finished';
108
+ readonly agentId: string;
109
+ readonly childId: string;
110
+ readonly ok: boolean;
111
+ readonly summary: string;
112
+ } | {
113
+ readonly type: 'handoff.created';
114
+ readonly from: TeamId;
115
+ readonly to: TeamId;
116
+ readonly title: string;
117
+ readonly artifact: string;
118
+ } | {
119
+ readonly type: 'qc.verdict';
120
+ readonly verdict: 'PASS' | 'FAIL';
121
+ readonly loop: number;
122
+ readonly summary: string;
123
+ } | {
124
+ readonly type: 'user.message';
125
+ readonly text: string;
126
+ readonly attachments?: readonly AttachmentInfo[];
127
+ } | {
128
+ readonly type: 'director.decision';
129
+ readonly decision: 'continue' | 'redirect' | 'stop';
130
+ readonly note: string;
131
+ } | {
132
+ readonly type: 'run.completed';
133
+ readonly outcome: 'delivered' | 'failed' | 'stopped';
134
+ readonly report: string;
135
+ });
136
+ export type TeamEventType = TeamEvent['type'];
137
+ /** Distributive Omit so each union member keeps its own fields. */
138
+ export type TeamEventInput = TeamEvent extends infer E ? E extends TeamEvent ? Omit<E, 'seq' | 'at' | 'runId'> : never : never;
139
+ /** What the TUI needs from a running (or replayed) company. */
140
+ export interface TeamRunHandle {
141
+ readonly runId: string;
142
+ readonly runDir: string;
143
+ /** Subscribe to events; replays every event already emitted, then live ones. Returns unsubscribe. */
144
+ subscribe(listener: (event: TeamEvent) => void): () => void;
145
+ /** Owner chat to the Director; journaled as user.message, then the Director decides (continue/redirect/stop). */
146
+ /** `files` (optional): attachments sent with the message; they are copied into the run folder and handed to every later agent turn. */
147
+ sendToDirector(text: string, files?: readonly {
148
+ readonly name: string;
149
+ readonly file: string;
150
+ }[]): void;
151
+ /** Stops all agents (kills their process groups) and completes the run as 'stopped'. */
152
+ stop(): void;
153
+ /** Resolves when the run completes. */
154
+ readonly done: Promise<'delivered' | 'failed' | 'stopped'>;
155
+ }
@@ -0,0 +1,5 @@
1
+ // Agent Company ("team mode") shared contract: config shape, journal events and the engine <-> TUI interface.
2
+ // Engine (src/team/engine.ts, runners.ts, journal.ts, config.ts) and TUI (src/tui/team/*) both import only from here.
3
+ /** Company pipeline stages, in order. */
4
+ export const STAGES = ['director-intake', 'ba-discussion', 'implement', 'qc', 'ba-review', 'delivery'];
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { type InspectorScreenProps } from './inspector-screens.js';
3
+ import { type MissionViewOptions } from './mission-model.js';
4
+ export interface ViewControllerOptions {
5
+ readonly inspector?: InspectorScreenProps;
6
+ readonly viewKeys?: boolean;
7
+ readonly mission?: MissionViewOptions;
8
+ readonly onQuit?: () => void;
9
+ }
10
+ import type { Envelope } from '../core/events.js';
11
+ import type { QueueEvent } from '../orchestration/work-queue.js';
12
+ import type { SetupModel } from './setup-model.js';
13
+ import { type SetupControllerOptions } from './setup-screens.js';
14
+ import { type ControlTask } from './control-model.js';
15
+ import { type ControlActions } from './control-screens.js';
16
+ export interface ControlControllerOptions {
17
+ readonly tasks?: readonly ControlTask[];
18
+ readonly queueEvents?: readonly QueueEvent[];
19
+ readonly actionOptions?: SetupControllerOptions;
20
+ readonly actions?: ControlActions;
21
+ readonly detailId?: string;
22
+ readonly selectDetail?: (id: string) => void;
23
+ }
24
+ export declare function App({ events, setupModel, controlOptions, viewOptions }: {
25
+ readonly events: readonly Envelope[];
26
+ readonly setupModel?: SetupModel;
27
+ readonly controlOptions?: ControlControllerOptions;
28
+ readonly viewOptions?: ViewControllerOptions;
29
+ }): React.JSX.Element;
@@ -0,0 +1,96 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React, { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
3
+ import { Box, Text, useInput, useStdout, useWindowSize, measureElement } from 'ink';
4
+ import { InspectorScreen } from './inspector-screens.js';
5
+ import { GraphScreen } from './graph-screens.js';
6
+ import { buildCausalGraph, graphNodeDetail, graphSelection } from './graph-model.js';
7
+ import { MissionScreen } from './mission-screens.js';
8
+ import { observationsFromJournal, projectMission } from './mission-model.js';
9
+ function MissionFlow({ events, width, options }) { const view = useMemo(() => projectMission(events, observationsFromJournal(events), options?.resolveContent), [events, options?.resolveContent]); return _jsx(MissionScreen, { view: view, width: width, ...options ? { options } : {} }); }
10
+ function GraphFlow({ events, width }) { const graph = useMemo(() => buildCausalGraph(events), [events]); const [index, setIndex] = useState(0); const [detail, setDetail] = useState(null); const selected = graphSelection(graph.nodes, index); useInput((_input, key) => { if (key.upArrow)
11
+ setIndex(value => Math.max(0, value - 1));
12
+ else if (key.downArrow)
13
+ setIndex(value => Math.min(graph.nodes.length - 1, value + 1));
14
+ else if (key.return && selected)
15
+ setDetail(graphNodeDetail(events, selected.id)); }, { isActive: true }); return _jsxs(_Fragment, { children: [_jsx(GraphScreen, { graph: graph, width: width, ...selected ? { selected } : {}, detail: detail }), events.length === 0 ? _jsx(Text, { children: "No recorded events" }) : null] }); }
16
+ function ViewKeys({ enabled, inspector, change, onQuit, capturedRef }) { useInput((input, key) => { if (capturedRef?.current)
17
+ return; if (input === 'q')
18
+ onQuit?.();
19
+ else if (key.escape)
20
+ change('control');
21
+ else if (input === 'g')
22
+ change('graph');
23
+ else if (input === 'm')
24
+ change('mission');
25
+ else if (input === 'i' && inspector)
26
+ change('inspector'); }, { isActive: enabled }); return null; }
27
+ import { realpathSync } from 'node:fs';
28
+ import { resolve } from 'node:path';
29
+ import { projectEvents } from '../core/replay.js';
30
+ import { EventFeed, PhaseState, SessionTaskList } from './screens.js';
31
+ import { BlankStatePicker, SetupScreen, createSetupActions } from './setup-screens.js';
32
+ import { ControlModel } from './control-model.js';
33
+ import { ControlScreen } from './control-screens.js';
34
+ const MIN_CONTROL_ROWS = 10;
35
+ /** A child event can be journaled before its parent, and delegation parents live in another session; the strict per-session machine would throw, so references not resolvable inside the same session are dropped for this projection only (Mission Control renders them as `parent pending`). */
36
+ const withoutDanglingRefs = (events) => { const ids = new Set(events.map(e => `${e.sessionId}\u0000${e.eventId}`)); const ok = (e, r) => r === null || ids.has(`${e.sessionId}\u0000${r}`); return events.map(e => ok(e, e.parentEventId) && ok(e, e.causationId) ? e : { ...e, parentEventId: ok(e, e.parentEventId) ? e.parentEventId : null, causationId: ok(e, e.causationId) ? e.causationId : null }); };
37
+ function setupPicker(events) {
38
+ const cwd = realpathSync(resolve(process.cwd()));
39
+ const choices = [...projectEvents(withoutDanglingRefs(events)).values()].flatMap(state => state.task ? [{ sessionId: state.sessionId, goal: state.task.title, cwd }] : []);
40
+ return choices.length ? null : Object.freeze({ cwd, sessionChoices: Object.freeze([]) });
41
+ }
42
+ function ControlFlow({ events, options, width, rows, chrome }) {
43
+ const [offset, setOffset] = useState(0);
44
+ const model = useMemo(() => new ControlModel({ ...options?.tasks ? { tasks: options.tasks } : {}, events, ...options?.queueEvents ? { queueEvents: options.queueEvents } : {} }), [events, options?.tasks, options?.queueEvents]);
45
+ const local = options?.actionOptions ? createSetupActions(options.actionOptions) : undefined;
46
+ const supplied = options?.actions;
47
+ const send = local?.send ?? supplied?.send;
48
+ const pause = local?.pause ?? supplied?.pause;
49
+ const evidence = local?.evidence ?? supplied?.evidence;
50
+ const resume = local?.resume ?? supplied?.resume;
51
+ const selectDetail = (id) => { options?.selectDetail?.(id); };
52
+ const actions = { ...(send ? { send } : {}), ...(pause ? { pause } : {}), ...(evidence ? { evidence } : {}), ...(resume ? { resume } : {}), scroll: direction => setOffset(value => Math.max(0, Math.min(Math.max(0, model.events().length - 1), value + direction))) };
53
+ const detail = options?.detailId ? model.openDetail(options.detailId) : null;
54
+ return _jsx(ControlScreen, { layout: model.layout(width), tasks: model.tasks(), events: model.events(), detail: detail, usage: model.usage({}), actions: actions, keyboardEnabled: Boolean(local || supplied || options?.selectDetail), onSelectDetail: selectDetail, offset: offset, ...rows !== undefined ? { rows, chrome: chrome ?? 0 } : {} });
55
+ }
56
+ export function App({ events, setupModel, controlOptions, viewOptions }) {
57
+ const { stdout } = useStdout();
58
+ useWindowSize(); // re-render on resize; raw stdout.columns/rows are still read below so undefined rows keeps the legacy path
59
+ const width = Math.max(20, stdout.columns ?? 80);
60
+ const rows = stdout.rows;
61
+ const blank = setupPicker(events);
62
+ const [view, setView] = useState('control');
63
+ const [captured, setCaptured] = useState(false);
64
+ const capturedRef = useRef(false);
65
+ const switchView = (next) => { if (next !== 'mission') {
66
+ capturedRef.current = false;
67
+ setCaptured(false);
68
+ } setView(next); };
69
+ const userCapture = viewOptions?.mission?.onInputCapture;
70
+ const onCapture = useCallback((on) => { capturedRef.current = on; setCaptured(on); userCapture?.(on); }, [userCapture]);
71
+ const missionOptions = { ...viewOptions?.mission, onInputCapture: onCapture };
72
+ const activeView = viewOptions?.viewKeys ? view : 'control';
73
+ const title = _jsx(Text, { bold: true, color: "cyan", wrap: "truncate-end", children: "CKit \u00B7 recorded event view" });
74
+ const setupView = setupModel ? setupModel.view(width - 2) : null;
75
+ const setupEl = setupModel && setupView ? _jsx(SetupScreen, { view: setupView, ...controlOptions?.actionOptions?.model === setupModel ? { actions: createSetupActions(controlOptions.actionOptions) } : {} }) : blank ? _jsx(BlankStatePicker, { cwd: blank.cwd, sessionChoices: blank.sessionChoices }) : null;
76
+ // Chrome rows are measured from the mounted element itself (Ink measureElement), so they cannot drift from setup-screens.tsx.
77
+ const chromeRef = useRef(null);
78
+ const [meas, setMeas] = useState(null);
79
+ const gate = rows !== undefined && activeView === 'control';
80
+ const sig = setupView ? JSON.stringify(setupView) : blank ? JSON.stringify(blank) : '';
81
+ const key = `${width}x${rows}#${sig}`;
82
+ // Compact is decided only from a real measurement of the FULL block taken for the current terminal size; a size change (or no measurement yet) renders full first, then re-decides. The root maxHeight clamp covers that measuring frame.
83
+ const full = meas?.key === key ? meas.h : null;
84
+ const compact = gate && Boolean(setupEl) && full !== null && rows - full < MIN_CONTROL_ROWS;
85
+ useLayoutEffect(() => { if (gate && !compact && chromeRef.current) {
86
+ const h = measureElement(chromeRef.current).height;
87
+ if (meas?.key !== key || meas.h !== h)
88
+ setMeas({ key, h });
89
+ } });
90
+ const sv = compact && setupView ? setupView : null;
91
+ const warn = sv ? [sv.loginRequired ? 'NEEDS_LOGIN' : '', sv.resumeRequiresRebind ? 'rebind check required' : '', sv.pendingOrders > 0 ? `Pending work: ${sv.pendingOrders}.` : ''].filter(Boolean).join(' · ') : '';
92
+ const summary = sv ? `Setup: ${sv.state} · Advisors: ${sv.advisorCount} · Primary: ${sv.primary ?? 'not selected'}` : `CWD: ${blank?.cwd ?? ''} · Sessions: ${blank?.sessionChoices.length ?? 0}`;
93
+ const chrome = gate ? compact ? 2 + (warn ? 1 : 0) : full ?? 1 : 0;
94
+ return _jsxs(Box, { flexDirection: "column", width: width, paddingX: 1, ...gate ? { maxHeight: rows, overflow: 'hidden' } : {}, children: [_jsx(ViewKeys, { enabled: Boolean(viewOptions?.viewKeys) && !captured, capturedRef: capturedRef, inspector: viewOptions?.inspector, change: switchView, ...viewOptions?.onQuit ? { onQuit: viewOptions.onQuit } : {} }), _jsxs(Box, { ref: chromeRef, flexDirection: "column", children: [title, compact ? _jsxs(_Fragment, { children: [_jsxs(Text, { wrap: "truncate-end", children: ["(enlarge terminal for setup) ", summary] }), warn ? _jsx(Text, { wrap: "truncate-end", color: "yellow", children: warn }) : null, _jsx(Box, { display: "none", flexDirection: "column", children: setupEl })] }) : setupEl] }), activeView === 'control' ? _jsx(ControlFlow, { events: events, ...controlOptions ? { options: controlOptions } : {}, width: width - 2, ...rows !== undefined ? { rows, chrome } : {} }) : activeView === 'graph' ? _jsx(GraphFlow, { events: events, width: width - 2 }) : activeView === 'mission' ? _jsx(MissionFlow, { events: events, width: width - 2, options: missionOptions }) : viewOptions?.inspector ? _jsx(InspectorScreen, { ...viewOptions.inspector }) : null, activeView === 'control' && rows === undefined && events.length === 0 ? _jsx(EventFeed, { events: events }) : null, activeView === 'control' && rows === undefined && events.length > 0 ? _jsxs(_Fragment, { children: [_jsx(SessionTaskList, { events: events }), _jsx(EventFeed, { events: events }), _jsx(PhaseState, { events: events })] }) : null] });
95
+ }
96
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1,101 @@
1
+ import type { Envelope } from '../core/events.js';
2
+ import type { SessionProjection } from '../core/replay.js';
3
+ import type { QueueEvent } from '../orchestration/work-queue.js';
4
+ export type ControlTaskStatus = 'current' | 'waiting' | 'blocked' | 'done';
5
+ export interface ControlTask {
6
+ readonly id: string;
7
+ readonly title: string;
8
+ readonly owner: string;
9
+ readonly status: ControlTaskStatus;
10
+ readonly summary: string;
11
+ readonly content: string;
12
+ readonly source: string;
13
+ }
14
+ export type ControlEventType = 'activity' | 'owner' | 'waiting' | 'blocked' | 'done' | 'queued' | 'accepted' | 'running' | 'failed' | 'unknown_delivery';
15
+ export interface ControlEvent {
16
+ readonly id: string;
17
+ readonly seq: number;
18
+ readonly at: string;
19
+ readonly type: ControlEventType;
20
+ readonly label: string;
21
+ readonly summary: string;
22
+ readonly content: string;
23
+ readonly source: string;
24
+ readonly critical: boolean;
25
+ readonly provenance: 'REAL' | 'SIMULATED';
26
+ readonly taskId?: string;
27
+ }
28
+ export interface ControlTaskView extends ControlTask {
29
+ readonly stateLabel: Uppercase<ControlTaskStatus>;
30
+ }
31
+ export interface ControlUsageField {
32
+ readonly kind: 'unknown' | 'estimate';
33
+ readonly label: string;
34
+ readonly value?: number;
35
+ }
36
+ export interface ControlLayout {
37
+ readonly width: number;
38
+ readonly mode: 'tabs' | 'panes';
39
+ readonly panes: readonly string[];
40
+ readonly controls: readonly string[];
41
+ readonly controlsVisible: true;
42
+ }
43
+ export interface ControlDetail {
44
+ readonly content: string;
45
+ readonly source: string;
46
+ readonly label: string;
47
+ }
48
+ export interface ControlActionBindings {
49
+ readonly send?: () => void;
50
+ readonly pause?: () => void;
51
+ readonly evidence?: () => void;
52
+ readonly resume?: () => void;
53
+ }
54
+ /** Headless bounded UI projection; injected callbacks own all external effects. */
55
+ export declare class ControlModel {
56
+ private readonly tasksById;
57
+ private readonly recent;
58
+ private readonly critical;
59
+ private readonly taskStatuses;
60
+ private readonly queueStatuses;
61
+ private readonly contentById;
62
+ private readonly taskIdByCoreId;
63
+ private readonly sessionProjections;
64
+ private actions;
65
+ private droppedCritical;
66
+ private detailValue;
67
+ constructor(input: {
68
+ readonly tasks?: readonly ControlTask[];
69
+ readonly events?: readonly (Envelope | ControlEvent)[];
70
+ readonly projection?: ReadonlyMap<string, SessionProjection>;
71
+ readonly queueEvents?: readonly QueueEvent[];
72
+ });
73
+ layout(width: number): ControlLayout;
74
+ tasks(): readonly ControlTaskView[];
75
+ events(): readonly ControlEvent[];
76
+ statusForTask(id: string): ControlTaskStatus | undefined;
77
+ queueState(id: string): string | undefined;
78
+ projections(): ReadonlyMap<string, SessionProjection>;
79
+ replay(events: readonly (Envelope | ControlEvent)[]): void;
80
+ replayQueue(events: readonly QueueEvent[]): void;
81
+ append(event: ControlEvent): void;
82
+ viewport(offset: number, limit: number): readonly ControlEvent[];
83
+ openDetail(id: string): ControlDetail | null;
84
+ usage(input: {
85
+ readonly tokens?: number;
86
+ readonly quota?: number;
87
+ readonly tokenEstimate?: number;
88
+ readonly quotaEstimate?: number;
89
+ }): {
90
+ readonly tokens: ControlUsageField;
91
+ readonly quota: ControlUsageField;
92
+ };
93
+ bindActions(actions: ControlActionBindings): void;
94
+ handleKey(key: string): boolean;
95
+ metrics(): {
96
+ readonly retainedEvents: number;
97
+ readonly virtualized: boolean;
98
+ readonly criticalEvents: number;
99
+ readonly droppedCritical: number;
100
+ };
101
+ }
@@ -0,0 +1,109 @@
1
+ const MAX_RECENT = 500, MAX_CRITICAL = 128;
2
+ const ACTIONS = Object.freeze({ s: 'send', p: 'pause', e: 'evidence', r: 'resume' });
3
+ const STATUS_LABEL = { current: 'CURRENT', waiting: 'WAITING', blocked: 'BLOCKED', done: 'DONE' };
4
+ const text = (value) => value.replace(/(?:bearer\s+[\w.-]+|(?:api[_-]?key|token|password|secret)\s*[:=]\s*\S+)/gi, '[REDACTED]');
5
+ function fromEnvelope(env) { const p = env.payload; let type = 'activity', label = ''; switch (p.type) {
6
+ case 'TaskCreated':
7
+ type = 'owner';
8
+ label = `Task created: ${p.title}`;
9
+ break;
10
+ case 'AdvisorDispatched':
11
+ type = 'waiting';
12
+ label = `Advisor dispatched (${p.adapter})`;
13
+ break;
14
+ case 'AdvisorAcked':
15
+ type = 'waiting';
16
+ label = `Advisor acknowledged (${p.adapter})`;
17
+ break;
18
+ case 'AdvisorCompleted':
19
+ label = `Advisor completed: ${p.resultRef}`;
20
+ break;
21
+ case 'AdvisorUnknownOutcome':
22
+ type = 'blocked';
23
+ label = `Advisor outcome unknown (${p.reason})`;
24
+ break;
25
+ case 'TaskCompleted':
26
+ type = p.outcome === 'success' ? 'done' : 'blocked';
27
+ label = `Task completed: ${p.outcome}`;
28
+ break;
29
+ case 'ReviewerSelected':
30
+ label = `Reviewer selected: ${p.reviewerId}`;
31
+ break;
32
+ } return Object.freeze({ id: String(env.eventId), seq: env.sessionSequence, at: env.at, type, label: text(label), summary: text(label), content: text(JSON.stringify(p)), source: `event:${env.eventId}`, critical: ['TaskCreated', 'TaskCompleted', 'AdvisorUnknownOutcome'].includes(p.type), provenance: env.provenance.source === 'simulated' ? 'SIMULATED' : 'REAL', taskId: String(env.taskId) }); }
33
+ function fromQueue(item, index) { const type = item.type === 'enqueued' ? 'queued' : item.type === 'accepted' ? 'accepted' : item.type === 'running' ? 'running' : item.type === 'failed' ? 'failed' : item.type === 'unknown_delivery' ? 'unknown_delivery' : item.type === 'rejected' ? 'blocked' : 'activity'; return Object.freeze({ id: `queue:${item.requestId}:${index}`, seq: index + 1, at: '', type, label: `Queue ${item.type}: ${item.workOrderId}`, summary: `Queue ${item.type}`, content: JSON.stringify(item), source: `queue:${item.workOrderId}`, critical: ['rejected', 'failed', 'unknown_delivery', 'cancel_refused'].includes(item.type), provenance: 'REAL' }); }
34
+ /** Headless bounded UI projection; injected callbacks own all external effects. */
35
+ export class ControlModel {
36
+ tasksById = new Map();
37
+ recent = [];
38
+ critical = [];
39
+ taskStatuses = new Map();
40
+ queueStatuses = new Map();
41
+ contentById = new Map();
42
+ taskIdByCoreId = new Map();
43
+ sessionProjections;
44
+ actions = {};
45
+ droppedCritical = 0;
46
+ detailValue = null;
47
+ constructor(input) { this.sessionProjections = input.projection ?? new Map(); for (const task of input.tasks ?? []) {
48
+ this.tasksById.set(task.id, Object.freeze({ ...task }));
49
+ this.taskStatuses.set(task.id, task.status);
50
+ } if (input.events)
51
+ this.replay(input.events); if (input.queueEvents)
52
+ this.replayQueue(input.queueEvents); }
53
+ layout(width) { if (!Number.isSafeInteger(width) || width < 1)
54
+ throw new TypeError('terminal width must be a positive integer'); const panes = width >= 100 ? ['tasks', 'timeline', 'queue', 'detail'] : width >= 60 ? ['tasks', 'timeline', 'queue'] : ['tasks', 'timeline']; return Object.freeze({ width, mode: width < 60 ? 'tabs' : 'panes', panes: Object.freeze(panes), controls: Object.freeze(['send', 'pause', 'evidence', 'resume', 'detail', 'history']), controlsVisible: true }); }
55
+ tasks() { return Object.freeze([...this.tasksById.values()].map(task => { const status = this.taskStatuses.get(task.id) ?? task.status; return Object.freeze({ ...task, status, stateLabel: STATUS_LABEL[status], title: text(task.title), summary: text(task.summary), content: text(task.content), source: text(task.source) }); })); }
56
+ events() { return Object.freeze([...new Map([...this.critical, ...this.recent].map(e => [e.id, e])).values()].sort((a, b) => a.seq - b.seq || a.id.localeCompare(b.id))); }
57
+ statusForTask(id) { return this.taskStatuses.get(id); }
58
+ queueState(id) { return this.queueStatuses.get(id); }
59
+ projections() { return this.sessionProjections; }
60
+ replay(events) { for (const raw of events)
61
+ this.append('eventId' in raw ? fromEnvelope(raw) : raw); }
62
+ replayQueue(events) { events.forEach((item, index) => this.append(fromQueue(item, index))); }
63
+ append(event) { const safe = Object.freeze({ ...event, label: text(event.label), summary: text(event.summary), content: text(event.content), source: text(event.source) }); if (safe.critical) {
64
+ if (this.critical.length < MAX_CRITICAL) {
65
+ this.critical.push(safe);
66
+ this.contentById.set(safe.id, safe);
67
+ }
68
+ else
69
+ this.droppedCritical++;
70
+ } this.recent.push(safe); this.contentById.set(safe.id, safe); if (this.recent.length > MAX_RECENT) {
71
+ const removed = this.recent.splice(0, this.recent.length - MAX_RECENT);
72
+ for (const item of removed)
73
+ if (!item.critical)
74
+ this.contentById.delete(item.id);
75
+ } try {
76
+ const payload = JSON.parse(safe.content);
77
+ if (payload['type'] === 'TaskCreated' && typeof payload['title'] === 'string') {
78
+ const id = safe.taskId ?? String(payload['taskId'] ?? payload['title']);
79
+ this.taskStatuses.set(id, 'current');
80
+ this.taskIdByCoreId.set(id, id);
81
+ }
82
+ if (payload['type'] === 'TaskCompleted') {
83
+ const id = safe.taskId ?? String(payload['taskId'] ?? '');
84
+ if (id)
85
+ this.taskStatuses.set(id, payload['outcome'] === 'success' ? 'done' : 'blocked');
86
+ }
87
+ if (typeof payload['workOrderId'] === 'string')
88
+ this.queueStatuses.set(payload['workOrderId'], safe.type);
89
+ }
90
+ catch { /* preserve opaque source as-is */ } }
91
+ viewport(offset, limit) { if (!Number.isSafeInteger(offset) || offset < 0 || !Number.isSafeInteger(limit) || limit < 0)
92
+ throw new TypeError('viewport offset and limit must be non-negative integers'); return Object.freeze(this.events().slice(offset, offset + limit)); }
93
+ openDetail(id) { const raw = id.startsWith('task:') ? id.slice(5) : id; const task = this.tasksById.get(raw); if (task) {
94
+ this.detailValue = Object.freeze({ content: text(task.content), source: text(task.source), label: text(task.title) });
95
+ return this.detailValue;
96
+ } const event = this.contentById.get(raw); if (event) {
97
+ this.detailValue = Object.freeze({ content: event.content, source: event.source, label: event.label });
98
+ return this.detailValue;
99
+ } return null; }
100
+ usage(input) { const field = (reported, estimate) => { if (reported !== undefined && Number.isFinite(reported) && reported >= 0)
101
+ return Object.freeze({ kind: 'estimate', label: `reported ${reported}`, value: reported }); if (estimate !== undefined && Number.isFinite(estimate) && estimate >= 0)
102
+ return Object.freeze({ kind: 'estimate', label: `estimate ${estimate}`, value: estimate }); return Object.freeze({ kind: 'unknown', label: 'unknown' }); }; return Object.freeze({ tokens: field(input.tokens, input.tokenEstimate), quota: field(input.quota, input.quotaEstimate) }); }
103
+ bindActions(actions) { this.actions = { ...this.actions, ...actions }; }
104
+ handleKey(key) { const action = ACTIONS[key.toLowerCase()]; if (!action)
105
+ return false; const fn = this.actions[action]; if (!fn)
106
+ return false; fn(); return true; }
107
+ metrics() { return Object.freeze({ retainedEvents: this.recent.length + this.critical.length, virtualized: true, criticalEvents: this.critical.length, droppedCritical: this.droppedCritical }); }
108
+ }
109
+ //# sourceMappingURL=control-model.js.map
@@ -0,0 +1,27 @@
1
+ import type { ControlDetail, ControlEvent, ControlLayout, ControlTaskView, ControlUsageField } from './control-model.js';
2
+ export interface ControlActions {
3
+ readonly send?: () => void;
4
+ readonly pause?: () => void;
5
+ readonly evidence?: () => void;
6
+ readonly resume?: () => void;
7
+ readonly openDetail?: (id: string) => void;
8
+ readonly scroll?: (direction: -1 | 1) => void;
9
+ }
10
+ export declare function selectedTimelineEventId(events: readonly ControlEvent[], offset: number): string | undefined;
11
+ export declare function controlRowBudget(rows: number | undefined, chrome: number): number | null;
12
+ export declare function ControlScreen({ layout, tasks, events, detail, usage, actions, keyboardEnabled, offset, onSelectDetail, rows, chrome }: {
13
+ readonly layout: ControlLayout;
14
+ readonly tasks: readonly ControlTaskView[];
15
+ readonly events: readonly ControlEvent[];
16
+ readonly detail: ControlDetail | null;
17
+ readonly usage: {
18
+ readonly tokens: ControlUsageField;
19
+ readonly quota: ControlUsageField;
20
+ };
21
+ readonly actions: ControlActions;
22
+ readonly keyboardEnabled?: boolean;
23
+ readonly offset?: number;
24
+ readonly onSelectDetail?: (id: string) => void;
25
+ readonly rows?: number;
26
+ readonly chrome?: number;
27
+ }): import("react").JSX.Element;
@@ -0,0 +1,85 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useInput, Box, Text } from 'ink';
3
+ export function selectedTimelineEventId(events, offset) { return events[offset]?.id; }
4
+ function Input({ actions, enabled, selectedId, onSelectDetail }) { useInput((input, key) => { if (!enabled)
5
+ return; if (input === 's')
6
+ actions.send?.();
7
+ else if (input === 'p')
8
+ actions.pause?.();
9
+ else if (input === 'e')
10
+ actions.evidence?.();
11
+ else if (input === 'r')
12
+ actions.resume?.();
13
+ else if (key.return && selectedId)
14
+ onSelectDetail?.(selectedId);
15
+ else if (key.upArrow)
16
+ actions.scroll?.(-1);
17
+ else if (key.downArrow)
18
+ actions.scroll?.(1); }, { isActive: enabled }); return null; }
19
+ export function controlRowBudget(rows, chrome) { return rows === undefined ? null : Math.max(1, Math.floor(rows) - chrome); }
20
+ const eventText = (event) => `[${event.provenance}] ${event.type.toUpperCase()} #${event.seq} ${event.summary} · ${event.source}`;
21
+ // Screen receives an explicit selector callback; it does not look up or mutate model state itself.
22
+ export function ControlScreen({ layout, tasks, events, detail, usage, actions, keyboardEnabled = false, offset = 0, onSelectDetail, rows, chrome = 0 }) {
23
+ const budget = controlRowBudget(rows, chrome);
24
+ const w = layout.width;
25
+ const wide = w >= 100;
26
+ const tw = budget !== null ? { wrap: 'truncate-end' } : {}; // rows known: every line truncates to exactly one row, so the budget below is exact.
27
+ let showTasks = true, showQueue = true, showDetail = true, shown = events.slice(offset, offset + Math.max(1, w < 60 ? 8 : 16)), visibleTasks = tasks, hiddenNames = [], hiddenBlocked = 0, showEarlier = false, showMore = false;
28
+ const blockedOf = (list) => list.filter(t => t.stateLabel === 'BLOCKED').length;
29
+ if (budget !== null) {
30
+ const cost = { queue: 3, tasks: 1 + Math.max(1, tasks.length), detail: detail ? 4 : 2 };
31
+ let free = budget - 2 - (events.length ? 0 : 1);
32
+ const rest = events.slice(offset);
33
+ if (wide) {
34
+ showDetail = free - cost.detail >= 4;
35
+ if (showDetail)
36
+ free -= cost.detail;
37
+ else {
38
+ hiddenNames = ['Detail'];
39
+ free -= 1;
40
+ }
41
+ const cap = Math.max(1, free - 1);
42
+ if (tasks.length > cap) {
43
+ const pinned = tasks.filter(t => t.stateLabel === 'BLOCKED'), others = tasks.filter(t => t.stateLabel !== 'BLOCKED');
44
+ const keep = new Set([...pinned, ...others].slice(0, cap));
45
+ visibleTasks = tasks.filter(t => keep.has(t));
46
+ }
47
+ }
48
+ else {
49
+ const dropped = [];
50
+ free -= 1;
51
+ const room = 4;
52
+ showQueue = free - cost.queue >= room;
53
+ if (showQueue)
54
+ free -= cost.queue;
55
+ else
56
+ dropped.push('Queue');
57
+ showTasks = free - cost.tasks >= room;
58
+ if (showTasks)
59
+ free -= cost.tasks;
60
+ else
61
+ dropped.push('Tasks');
62
+ showDetail = free - cost.detail >= room;
63
+ if (showDetail)
64
+ free -= cost.detail;
65
+ else
66
+ dropped.push('Detail');
67
+ if (dropped.length) {
68
+ hiddenNames = dropped;
69
+ hiddenBlocked = dropped.includes('Tasks') ? blockedOf(tasks) : 0;
70
+ }
71
+ else
72
+ free += 1;
73
+ }
74
+ showEarlier = offset > 0 && free >= 3;
75
+ const slots = Math.max(1, free - (showEarlier ? 1 : 0));
76
+ const count = rest.length <= slots ? rest.length : slots >= 2 ? slots - 1 : 1;
77
+ shown = rest.slice(0, count);
78
+ showMore = rest.length > count && slots >= 2;
79
+ }
80
+ const selectedId = selectedTimelineEventId(events, offset);
81
+ const hidden = events.length - offset - shown.length;
82
+ const clipped = tasks.length - visibleTasks.length;
83
+ return _jsxs(Box, { flexDirection: "column", width: layout.width, children: [_jsx(Input, { actions: actions, enabled: keyboardEnabled, selectedId: selectedId, ...onSelectDetail ? { onSelectDetail } : {} }), _jsxs(Text, { bold: true, ...tw, children: ["CKit Mission Control \u00B7 ", layout.mode.toUpperCase()] }), _jsxs(Box, { flexDirection: layout.width >= 100 ? 'row' : 'column', children: [showTasks ? _jsxs(Box, { flexDirection: "column", width: layout.width >= 100 ? Math.floor(layout.width * .25) : layout.width, children: [_jsx(Text, { bold: true, ...tw, children: "Tasks / milestones" }), visibleTasks.map(task => _jsxs(Text, { ...tw, children: ["[", task.stateLabel, "] ", task.owner, " \u00B7 ", task.title] }, task.id)), clipped > 0 ? _jsxs(Text, { ...tw, children: ["\u2026 ", blockedOf(tasks) - blockedOf(visibleTasks) ? `${blockedOf(tasks) - blockedOf(visibleTasks)} BLOCKED · ` : '', clipped, " more tasks"] }) : null, !tasks.length ? _jsx(Text, { ...tw, children: "No task projection available." }) : null] }) : null, _jsxs(Box, { flexDirection: "column", width: layout.width >= 100 ? Math.floor(layout.width * .5) : layout.width, children: [_jsxs(Text, { bold: true, ...tw, children: ["Event timeline \u00B7 ", shown.length, "/", events.length] }), showEarlier ? _jsxs(Text, { ...tw, children: ["\u2191 ", offset, " earlier"] }) : null, shown.map(event => _jsx(Text, { ...tw, children: eventText(event) }, event.id)), showMore ? _jsxs(Text, { ...tw, children: ["\u2193 ", hidden, " more"] }) : null, !events.length ? _jsx(Text, { ...tw, children: "No recorded events" }) : null] }), showQueue ? _jsxs(Box, { flexDirection: "column", width: layout.width >= 100 ? Math.floor(layout.width * .25) : layout.width, children: [_jsx(Text, { bold: true, ...tw, children: "Queue / next action" }), _jsxs(Text, { ...tw, children: ["Usage \u00B7 tokens: ", usage.tokens.label, "; quota: ", usage.quota.label] }), _jsx(Text, { ...tw, children: "Keys: [s] send [p] pause [e] evidence [r] resume \u00B7 arrows history" })] }) : null] }), showDetail ? _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, ...tw, children: "Full content / source" }), detail ? _jsxs(_Fragment, { children: [_jsx(Text, { ...tw, children: detail.label }), _jsx(Text, { ...tw, children: detail.content }), _jsxs(Text, { ...tw, children: ["Source: ", detail.source] })] }) : _jsx(Text, { ...tw, children: "Select a timeline or task item to inspect full content." })] }) : null, hiddenNames.length ? _jsxs(Text, { ...tw, children: ["\u2026 ", hiddenBlocked ? `${hiddenBlocked} BLOCKED · ` : '', "hidden: ", hiddenNames.join(', '), " (enlarge terminal)"] }) : null] });
84
+ }
85
+ //# sourceMappingURL=control-screens.js.map