@ngockhoale/ckit 0.0.0-stage → 0.1.1

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 (246) hide show
  1. package/.env.example +21 -0
  2. package/README.md +70 -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 +384 -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/lifecycle.d.ts +19 -0
  46. package/dist/src/cli/lifecycle.js +90 -0
  47. package/dist/src/cli/sessions.d.ts +10 -0
  48. package/dist/src/cli/sessions.js +381 -0
  49. package/dist/src/cli/setup.d.ts +11 -0
  50. package/dist/src/cli/setup.js +115 -0
  51. package/dist/src/committee/decision.d.ts +84 -0
  52. package/dist/src/committee/decision.js +167 -0
  53. package/dist/src/committee/handover.d.ts +115 -0
  54. package/dist/src/committee/handover.js +191 -0
  55. package/dist/src/committee/no-progress.d.ts +44 -0
  56. package/dist/src/committee/no-progress.js +64 -0
  57. package/dist/src/committee/primary-registry.d.ts +15 -0
  58. package/dist/src/committee/primary-registry.js +60 -0
  59. package/dist/src/committee/reply-parser.d.ts +28 -0
  60. package/dist/src/committee/reply-parser.js +53 -0
  61. package/dist/src/committee/reviewer-scheduler.d.ts +101 -0
  62. package/dist/src/committee/reviewer-scheduler.js +163 -0
  63. package/dist/src/committee/role-epoch.d.ts +91 -0
  64. package/dist/src/committee/role-epoch.js +154 -0
  65. package/dist/src/core/control.d.ts +18 -0
  66. package/dist/src/core/control.js +29 -0
  67. package/dist/src/core/entities.d.ts +166 -0
  68. package/dist/src/core/entities.js +119 -0
  69. package/dist/src/core/errors.d.ts +9 -0
  70. package/dist/src/core/errors.js +17 -0
  71. package/dist/src/core/events.d.ts +72 -0
  72. package/dist/src/core/events.js +125 -0
  73. package/dist/src/core/ids.d.ts +47 -0
  74. package/dist/src/core/ids.js +32 -0
  75. package/dist/src/core/machine.d.ts +55 -0
  76. package/dist/src/core/machine.js +110 -0
  77. package/dist/src/core/policy.d.ts +34 -0
  78. package/dist/src/core/policy.js +59 -0
  79. package/dist/src/core/provenance.d.ts +20 -0
  80. package/dist/src/core/provenance.js +21 -0
  81. package/dist/src/core/record.d.ts +35 -0
  82. package/dist/src/core/record.js +67 -0
  83. package/dist/src/core/replay.d.ts +10 -0
  84. package/dist/src/core/replay.js +36 -0
  85. package/dist/src/core/run-task.d.ts +20 -0
  86. package/dist/src/core/run-task.js +48 -0
  87. package/dist/src/diagnostics/doctor.d.ts +78 -0
  88. package/dist/src/diagnostics/doctor.js +365 -0
  89. package/dist/src/diagnostics/journal-lock.d.ts +38 -0
  90. package/dist/src/diagnostics/journal-lock.js +181 -0
  91. package/dist/src/evidence/linker.d.ts +44 -0
  92. package/dist/src/evidence/linker.js +75 -0
  93. package/dist/src/evidence/report-parser.d.ts +27 -0
  94. package/dist/src/evidence/report-parser.js +17 -0
  95. package/dist/src/evidence/store.d.ts +36 -0
  96. package/dist/src/evidence/store.js +57 -0
  97. package/dist/src/gui/server.d.ts +27 -0
  98. package/dist/src/gui/server.js +497 -0
  99. package/dist/src/host/checkpoint.d.ts +22 -0
  100. package/dist/src/host/checkpoint.js +74 -0
  101. package/dist/src/host/export.d.ts +52 -0
  102. package/dist/src/host/export.js +45 -0
  103. package/dist/src/host/ipc.d.ts +57 -0
  104. package/dist/src/host/ipc.js +124 -0
  105. package/dist/src/host/leases.d.ts +27 -0
  106. package/dist/src/host/leases.js +40 -0
  107. package/dist/src/host/retention.d.ts +47 -0
  108. package/dist/src/host/retention.js +130 -0
  109. package/dist/src/host/supervisor.d.ts +59 -0
  110. package/dist/src/host/supervisor.js +64 -0
  111. package/dist/src/intake/owner-intake.d.ts +31 -0
  112. package/dist/src/intake/owner-intake.js +97 -0
  113. package/dist/src/intake/types.d.ts +46 -0
  114. package/dist/src/intake/types.js +2 -0
  115. package/dist/src/intent/context-packet.d.ts +68 -0
  116. package/dist/src/intent/context-packet.js +76 -0
  117. package/dist/src/intent/idea-ledger.d.ts +50 -0
  118. package/dist/src/intent/idea-ledger.js +136 -0
  119. package/dist/src/intent/ledger.d.ts +35 -0
  120. package/dist/src/intent/ledger.js +40 -0
  121. package/dist/src/intent/registry.d.ts +51 -0
  122. package/dist/src/intent/registry.js +44 -0
  123. package/dist/src/intent/revision.d.ts +37 -0
  124. package/dist/src/intent/revision.js +48 -0
  125. package/dist/src/orchestration/dispatcher.d.ts +32 -0
  126. package/dist/src/orchestration/dispatcher.js +136 -0
  127. package/dist/src/orchestration/milestone-loop.d.ts +149 -0
  128. package/dist/src/orchestration/milestone-loop.js +132 -0
  129. package/dist/src/orchestration/recovery-coordinator.d.ts +74 -0
  130. package/dist/src/orchestration/recovery-coordinator.js +180 -0
  131. package/dist/src/orchestration/work-order-contract.d.ts +44 -0
  132. package/dist/src/orchestration/work-order-contract.js +85 -0
  133. package/dist/src/orchestration/work-queue.d.ts +56 -0
  134. package/dist/src/orchestration/work-queue.js +95 -0
  135. package/dist/src/ports/advisor.d.ts +33 -0
  136. package/dist/src/ports/advisor.js +2 -0
  137. package/dist/src/ports/agent.d.ts +31 -0
  138. package/dist/src/ports/agent.js +2 -0
  139. package/dist/src/ports/capabilities.d.ts +3 -0
  140. package/dist/src/ports/capabilities.js +5 -0
  141. package/dist/src/ports/clock.d.ts +5 -0
  142. package/dist/src/ports/clock.js +5 -0
  143. package/dist/src/ports/store.d.ts +13 -0
  144. package/dist/src/ports/store.js +2 -0
  145. package/dist/src/ports/web.d.ts +29 -0
  146. package/dist/src/ports/web.js +2 -0
  147. package/dist/src/run/api-run.d.ts +49 -0
  148. package/dist/src/run/api-run.js +173 -0
  149. package/dist/src/run/plan-run.d.ts +22 -0
  150. package/dist/src/run/plan-run.js +233 -0
  151. package/dist/src/run/plan.d.ts +36 -0
  152. package/dist/src/run/plan.js +119 -0
  153. package/dist/src/run/verify.d.ts +25 -0
  154. package/dist/src/run/verify.js +81 -0
  155. package/dist/src/security/redact.d.ts +7 -0
  156. package/dist/src/security/redact.js +21 -0
  157. package/dist/src/settings/env-config.d.ts +64 -0
  158. package/dist/src/settings/env-config.js +232 -0
  159. package/dist/src/storage/artifacts.d.ts +30 -0
  160. package/dist/src/storage/artifacts.js +105 -0
  161. package/dist/src/storage/audit.d.ts +6 -0
  162. package/dist/src/storage/audit.js +6 -0
  163. package/dist/src/storage/db.d.ts +9 -0
  164. package/dist/src/storage/db.js +43 -0
  165. package/dist/src/storage/events.d.ts +20 -0
  166. package/dist/src/storage/events.js +69 -0
  167. package/dist/src/storage/migrations.d.ts +8 -0
  168. package/dist/src/storage/migrations.js +48 -0
  169. package/dist/src/storage/outbox.d.ts +25 -0
  170. package/dist/src/storage/outbox.js +40 -0
  171. package/dist/src/storage/projections.d.ts +18 -0
  172. package/dist/src/storage/projections.js +40 -0
  173. package/dist/src/storage/reconcile.d.ts +14 -0
  174. package/dist/src/storage/reconcile.js +93 -0
  175. package/dist/src/storage/reservations.d.ts +12 -0
  176. package/dist/src/storage/reservations.js +80 -0
  177. package/dist/src/storage/store.d.ts +34 -0
  178. package/dist/src/storage/store.js +105 -0
  179. package/dist/src/team/attachments.d.ts +22 -0
  180. package/dist/src/team/attachments.js +211 -0
  181. package/dist/src/team/cli-models.d.ts +24 -0
  182. package/dist/src/team/cli-models.js +72 -0
  183. package/dist/src/team/config.d.ts +20 -0
  184. package/dist/src/team/config.js +113 -0
  185. package/dist/src/team/engine.d.ts +28 -0
  186. package/dist/src/team/engine.js +443 -0
  187. package/dist/src/team/journal.d.ts +30 -0
  188. package/dist/src/team/journal.js +70 -0
  189. package/dist/src/team/runners.d.ts +79 -0
  190. package/dist/src/team/runners.js +436 -0
  191. package/dist/src/team/secrets.d.ts +10 -0
  192. package/dist/src/team/secrets.js +68 -0
  193. package/dist/src/team/types.d.ts +157 -0
  194. package/dist/src/team/types.js +5 -0
  195. package/dist/src/tui/app.d.ts +29 -0
  196. package/dist/src/tui/app.js +96 -0
  197. package/dist/src/tui/control-model.d.ts +101 -0
  198. package/dist/src/tui/control-model.js +109 -0
  199. package/dist/src/tui/control-screens.d.ts +27 -0
  200. package/dist/src/tui/control-screens.js +85 -0
  201. package/dist/src/tui/graph-model.d.ts +34 -0
  202. package/dist/src/tui/graph-model.js +29 -0
  203. package/dist/src/tui/graph-screens.d.ts +13 -0
  204. package/dist/src/tui/graph-screens.js +4 -0
  205. package/dist/src/tui/inspector-model.d.ts +150 -0
  206. package/dist/src/tui/inspector-model.js +15 -0
  207. package/dist/src/tui/inspector-screens.d.ts +14 -0
  208. package/dist/src/tui/inspector-screens.js +61 -0
  209. package/dist/src/tui/live.d.ts +16 -0
  210. package/dist/src/tui/live.js +39 -0
  211. package/dist/src/tui/mission-action-screens.d.ts +15 -0
  212. package/dist/src/tui/mission-action-screens.js +105 -0
  213. package/dist/src/tui/mission-actions.d.ts +46 -0
  214. package/dist/src/tui/mission-actions.js +53 -0
  215. package/dist/src/tui/mission-model.d.ts +120 -0
  216. package/dist/src/tui/mission-model.js +164 -0
  217. package/dist/src/tui/mission-nav.d.ts +82 -0
  218. package/dist/src/tui/mission-nav.js +131 -0
  219. package/dist/src/tui/mission-plan-screens.d.ts +11 -0
  220. package/dist/src/tui/mission-plan-screens.js +40 -0
  221. package/dist/src/tui/mission-plan.d.ts +45 -0
  222. package/dist/src/tui/mission-plan.js +166 -0
  223. package/dist/src/tui/mission-screens.d.ts +7 -0
  224. package/dist/src/tui/mission-screens.js +263 -0
  225. package/dist/src/tui/provenance-label.d.ts +11 -0
  226. package/dist/src/tui/provenance-label.js +16 -0
  227. package/dist/src/tui/screens.d.ts +10 -0
  228. package/dist/src/tui/screens.js +34 -0
  229. package/dist/src/tui/session-outcome.d.ts +14 -0
  230. package/dist/src/tui/session-outcome.js +57 -0
  231. package/dist/src/tui/setup-model.d.ts +159 -0
  232. package/dist/src/tui/setup-model.js +234 -0
  233. package/dist/src/tui/setup-screens.d.ts +66 -0
  234. package/dist/src/tui/setup-screens.js +72 -0
  235. package/dist/src/tui/team/app.d.ts +24 -0
  236. package/dist/src/tui/team/app.js +228 -0
  237. package/dist/src/tui/team/demo-handle.d.ts +22 -0
  238. package/dist/src/tui/team/demo-handle.js +42 -0
  239. package/dist/src/tui/team/model.d.ts +81 -0
  240. package/dist/src/tui/team/model.js +133 -0
  241. package/gui/app.css +177 -0
  242. package/gui/app.js +677 -0
  243. package/gui/index.html +51 -0
  244. package/gui/network.js +413 -0
  245. package/package.json +44 -4
  246. package/src/storage/schema.sql +42 -0
package/.env.example ADDED
@@ -0,0 +1,21 @@
1
+ # CKit KHÔNG cần file .env để chạy: agent dùng đăng nhập của chính codex / claude / omp,
2
+ # còn CLI + model của từng agent chỉnh trong giao diện (nút Config), lưu ở .ckit/team.json.
3
+ #
4
+ # File này chỉ để tùy chỉnh giao diện web "ckit gui". Cần thì sao chép thành .env trong thư mục
5
+ # bạn chạy "ckit gui" (không commit .env), bỏ dấu # ở dòng muốn dùng rồi điền giá trị.
6
+ # Thứ tự ưu tiên: cờ (--host / --port / --lan) > biến môi trường shell > file .env > .ckit/gui.json > mặc định.
7
+ # Đổi xong phải dừng (Ctrl+C) và chạy lại "ckit gui"; mở đúng link mà lệnh in ra.
8
+
9
+ # Địa chỉ lắng nghe. Mặc định 127.0.0.1 = chỉ máy này mở được.
10
+ # 0.0.0.0 = máy khác trong mạng LAN mở được (HTTP thường, không mã hóa; ai có link đều điều khiển được agent).
11
+ # CKIT_GUI_HOST=
12
+
13
+ # Cổng cố định (1..65535). Mặc định 4317; nếu cổng bận và không đặt cố định, CKit tự chọn cổng khác.
14
+ # CKIT_GUI_PORT=
15
+
16
+ # Token cố định để link không đổi sau mỗi lần chạy: 16..128 ký tự, chỉ gồm A-Z a-z 0-9 _ -
17
+ # Bỏ trống hoặc sai định dạng = token ngẫu nhiên mỗi lần chạy. Coi token như mật khẩu, không commit.
18
+ # CKIT_GUI_TOKEN=
19
+
20
+ # Từ máy khác mở: http://<IP-của-máy-này>:<cổng>/?t=<token>
21
+ # (nếu không vào được, kiểm tra Firewall của macOS có chặn "node" không).
package/README.md CHANGED
@@ -1,3 +1,71 @@
1
- # Temporary Holding Version
1
+ # CKit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Local orchestration core for advisor/worker agent sessions. **Scaffold baseline (T01-01)** —
4
+ nothing here is a released product, and no live provider/agent integration is claimed.
5
+
6
+ ## Use it like a normal app
7
+
8
+ ```bash
9
+ npm install -g @ngockhoale/ckit # once per machine
10
+ cd your-project
11
+ ckit install # once per project: writes .ckit/team.json (an existing one is kept)
12
+ ckit # opens the GUI in this folder; agents read and write files here
13
+ ckit update # later: upgrade to the newest version from npm (ckit update --check only looks)
14
+ ```
15
+
16
+ No env file and no API key are needed: every agent uses the login of its own CLI (`codex`, `claude`, `omp`). Pick the CLI and model per agent in the GUI (Config).
17
+
18
+ ## Agent Company (team mode)
19
+
20
+ A Director plus Team BA (2 agents discuss, then write one handoff) → Team Implement → Team QC (2 reviewers; FAIL returns to Implement, up to `limits.qcLoops`) → BA review → Director delivery report. You always talk to the Director; it can continue, redirect or stop the run.
21
+
22
+ ```bash
23
+ ckit # no command, in a terminal: opens the GUI. First time in a project it lands on Config so setup is done there
24
+ ckit gui --lan # optional: reachable from other machines on the network. Same via the shell or the project's env file: CKIT_GUI_HOST=0.0.0.0 (plus CKIT_GUI_PORT, CKIT_GUI_TOKEN for a fixed link) or .ckit/gui.json {"host":"0.0.0.0"}; default is this machine only
25
+ # in the GUI: attach any files (images, PDF, Word, Excel, drawio, XML...) to a mission or a message; they are stored in the run folder and handed to every team
26
+ ckit gui # web Mission Control on 127.0.0.1 (random token URL; --port=<n>, --no-open). Config per agent: cli, model, OpenAI-compatible base URL, API key (stored in ~/.config/ckit/team-secrets.json, 0600, never sent to the browser)
27
+ ckit team --demo # same pipeline in the terminal, fully SIMULATED (no model calls, no cost); --speed=<n> to fast-forward
28
+ ckit team "<goal>" # real run with the agents in <project>/.ckit/team.json (codex / claude-code / omp / api)
29
+ ckit team --init # write the default .ckit/team.json (--force overwrites)
30
+ ```
31
+
32
+ Every run is journaled to `.ckit/team/runs/<runId>/` (`events.jsonl`, `handoff-ba.md`, `qc-report-N.md`, `transcript.md`, `report.md`). Real agents use their own CLI login; codex runs `read-only` unless the agent has `access: "write"` (then `workspace-write`), claude uses `acceptEdits` only for write access, never bypass.
33
+
34
+ `ckit gui` network settings (all optional): flags > shell env > the folder's env file > `.ckit/gui.json` > default `127.0.0.1:4317`; see `.env.example`. The earlier `ckit run` command (API advisor + single executor) was removed on 2026-11-14; use the GUI or `ckit team`.
35
+
36
+ ## Quick start (contributor)
37
+
38
+ ```bash
39
+ npm install # TypeScript dev deps + runtime deps (ink, react)
40
+ npm run build # strict tsc build -> dist/
41
+ npm test # node:test suite over dist/
42
+ npm run demo # minimal task flow through the SIMULATED advisor (offline, no external send)
43
+ npm run demo:fault # same flow with an injected ack-lost fault -> unknown outcome, no resend
44
+ ```
45
+
46
+ Requirements: Node.js >= 22 (observed on v22.22.1, macOS arm64).
47
+
48
+ ## Requirements
49
+
50
+ Requirements: Node.js >= 22 (uses `node:sqlite`, which prints an ExperimentalWarning on 22.x). Runtime deps: `ink`, `react` (MIT; lockfile licenses allowlisted by `test/security-supply-chain.test.ts`). Used on macOS arm64 / Node 22.22.1 only so far; other platforms are unverified. Published on npm as `@ngockhoale/ckit` (owner decision 2026-11-14).
51
+
52
+ ## What exists now
53
+
54
+ - `src/core` — branded IDs, fail-closed event envelope validation (ADR-012 groundwork),
55
+ a pure session/task state machine with deterministic replay, and the minimal task flow.
56
+ - `src/ports` — advisor port contract (T01-04 groundwork; capability-honest per ADR-015).
57
+ - `src/adapters/fake` — **SIMULATED** advisor: offline fixture only. Its output is never
58
+ evidence of live integration; every event is provenance-tagged `simulated`.
59
+ - `test/` — node:test suites (IDs, envelope validation, state machine, task flow).
60
+
61
+ ## Design direction
62
+
63
+ The TUI (React + Ink, compatibility-probed; see `docs/research/receipts/ink-probe-*.txt`)
64
+ will render the agent exchange from the **real event stream** — the demo's JSON envelopes are
65
+ the exact shape the UI will consume. ADR-016 records the hand-written state machine decision.
66
+
67
+ ## Honesty gates (do not remove)
68
+
69
+ - Published as `@ngockhoale/ckit`; publish only on the owner's request, after `npm test` passes.
70
+ - Simulated adapter output must stay labeled `simulated`; live evidence requires a `live` provenance ref.
71
+ - Unknown external outcomes stop the flow (`needsReconciliation`); the core never blind-resends.
@@ -0,0 +1,13 @@
1
+ import { UnknownAgentEventError } from '../normalize.js';
2
+ import { type ClassifiedAgentError } from '../errors.js';
3
+ export interface ClaudeCapabilities {
4
+ readonly version: number;
5
+ readonly capabilities: readonly string[];
6
+ }
7
+ export declare class ClaudeShapeMismatchError extends UnknownAgentEventError {
8
+ readonly adapter = "claude";
9
+ constructor(message: string);
10
+ }
11
+ export { ClaudeShapeMismatchError as UnknownClaudeEventError };
12
+ export declare function assertClaudeCapabilities(actual: ClaudeCapabilities, expected: ClaudeCapabilities): void;
13
+ export declare function classifyClaudeError(cause: unknown): ClassifiedAgentError;
@@ -0,0 +1,16 @@
1
+ import { UnknownAgentEventError } from '../normalize.js';
2
+ import { classifyAgentError } from '../errors.js';
3
+ export class ClaudeShapeMismatchError extends UnknownAgentEventError {
4
+ adapter = 'claude';
5
+ constructor(message) { super(message); this.name = 'ClaudeShapeMismatchError'; }
6
+ }
7
+ export { ClaudeShapeMismatchError as UnknownClaudeEventError };
8
+ export function assertClaudeCapabilities(actual, expected) {
9
+ if (actual.version !== expected.version || actual.capabilities.length !== expected.capabilities.length || expected.capabilities.some(cap => !actual.capabilities.includes(cap)))
10
+ throw new ClaudeShapeMismatchError(`Claude event shape mismatch: version/capability mismatch: expected version ${expected.version}, got ${actual.version}`);
11
+ }
12
+ export function classifyClaudeError(cause) {
13
+ const message = cause instanceof Error ? cause.message : String(cause), sentNoAck = /sent[-_ ]no[-_ ]ack/i.test(message);
14
+ return classifyAgentError(sentNoAck ? new Error(`${message}; acknowledgement lost`) : cause, { phase: sentNoAck ? 'after-dispatch' : 'before-dispatch' });
15
+ }
16
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,11 @@
1
+ import { type Envelope } from '../../../core/events.js';
2
+ import type { OmpReplayContext } from '../normalize.js';
3
+ import { type ClaudeCapabilities } from './errors.js';
4
+ export { ClaudeShapeMismatchError, ClaudeShapeMismatchError as UnknownClaudeEventError, classifyClaudeError, assertClaudeCapabilities } from './errors.js';
5
+ export type { ClaudeCapabilities };
6
+ export declare function normalizeClaudeEvent(raw: unknown, context?: OmpReplayContext, sequence?: number): Envelope;
7
+ export declare function replayClaudeTranscript(transcript: {
8
+ readonly label: 'SIMULATED';
9
+ readonly version: 1;
10
+ readonly events: readonly unknown[];
11
+ }, context: OmpReplayContext): readonly Envelope[];
@@ -0,0 +1,83 @@
1
+ import { EVENT_SCHEMA_VERSION, validateEnvelope } from '../../../core/events.js';
2
+ import { ClaudeShapeMismatchError as UnknownClaudeEventError, assertClaudeCapabilities } from './errors.js';
3
+ export { ClaudeShapeMismatchError, ClaudeShapeMismatchError as UnknownClaudeEventError, classifyClaudeError, assertClaudeCapabilities } from './errors.js';
4
+ const DEFAULT_CONTEXT = { sessionId: 'session-a1b2c3d4', taskId: 'task-a1b2c3d4', projectId: 'project-demo0001', runId: 'run-demo0001' };
5
+ function record(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); }
6
+ export function normalizeClaudeEvent(raw, context = DEFAULT_CONTEXT, sequence = 1) {
7
+ if (!record(raw))
8
+ throw new UnknownClaudeEventError('event must be an object');
9
+ if (raw['version'] !== 1)
10
+ throw new UnknownClaudeEventError(`unsupported Claude event version ${String(raw['version'])}`);
11
+ const type = raw['type'], subtype = raw['subtype'], at = raw['at'];
12
+ if (typeof type !== 'string' || typeof subtype !== 'string' || typeof at !== 'string')
13
+ throw new UnknownClaudeEventError('required type/subtype/at fields missing');
14
+ const key = `${type}:${subtype}`;
15
+ let eventType, status, payload;
16
+ switch (key) {
17
+ case 'system:init':
18
+ if (typeof raw['session_id'] !== 'string' || !raw['session_id'])
19
+ throw new UnknownClaudeEventError('init requires session_id');
20
+ eventType = 'AdvisorAcked';
21
+ status = 'accepted';
22
+ payload = { type: eventType, adapter: 'claude:SIMULATED' };
23
+ break;
24
+ case 'system:running':
25
+ eventType = 'AdvisorUnknownOutcome';
26
+ status = 'running';
27
+ payload = { type: eventType, reason: 'adapter-fault', note: 'running' };
28
+ break;
29
+ case 'assistant:text':
30
+ if (typeof raw['text'] !== 'string')
31
+ throw new UnknownClaudeEventError('assistant text requires text');
32
+ eventType = 'AdvisorUnknownOutcome';
33
+ status = 'partial-stream';
34
+ payload = { type: eventType, reason: 'adapter-fault', note: `partial-stream:${raw['text']}` };
35
+ break;
36
+ case 'tool:result':
37
+ if (typeof raw['name'] !== 'string' || !raw['name'])
38
+ throw new UnknownClaudeEventError('tool result requires name');
39
+ eventType = 'AdvisorUnknownOutcome';
40
+ status = 'tool-finish';
41
+ payload = { type: eventType, reason: 'adapter-fault', note: 'tool-finish' };
42
+ break;
43
+ case 'control_request:permission':
44
+ if (typeof raw['request_id'] !== 'string' || !raw['request_id'])
45
+ throw new UnknownClaudeEventError('permission request requires request_id');
46
+ eventType = 'AdvisorUnknownOutcome';
47
+ status = 'waiting_input';
48
+ payload = { type: eventType, reason: 'adapter-fault', note: `permission-request:${raw['request_id']}` };
49
+ break;
50
+ case 'result:turn_end':
51
+ eventType = 'AdvisorUnknownOutcome';
52
+ status = 'turn-finish';
53
+ payload = { type: eventType, reason: 'adapter-fault', note: 'turn-finish' };
54
+ break;
55
+ case 'result:run_end':
56
+ if (raw['outcome'] !== 'success' && raw['outcome'] !== 'failed')
57
+ throw new UnknownClaudeEventError('run-end requires explicit outcome');
58
+ eventType = raw['outcome'] === 'success' ? 'AdvisorCompleted' : 'AdvisorUnknownOutcome';
59
+ status = raw['outcome'];
60
+ payload = raw['outcome'] === 'success' ? { type: eventType, resultRef: 'artifact-ompresult01' } : { type: eventType, reason: 'adapter-fault', note: 'explicit run failed' };
61
+ break;
62
+ default: throw new UnknownClaudeEventError(`unknown Claude event ${key}`);
63
+ }
64
+ const seq = Math.max(1, sequence);
65
+ try {
66
+ return validateEnvelope({ schemaVersion: EVENT_SCHEMA_VERSION, seq, sessionSequence: seq, sessionId: context.sessionId, taskId: context.taskId, projectId: context.projectId, runId: context.runId, at, sourceAt: at, causality: null, eventId: `event-claude-${String(seq).padStart(6, '0')}`, parentEventId: null, causationId: null, attemptId: null, traceId: 'trace-claude0001', spanId: `span-claude-${String(seq).padStart(6, '0')}`, actor: { role: 'advisor', adapter: 'claude' }, provenance: { source: 'simulated' }, adapter: 'claude', adapterVersion: '1', eventType, status, reasonCode: null, artifactRefs: [], decisionId: null, requirementIds: [], ckitVersion: '0.0.0', policyVersion: '1', promptTemplateVersion: '1', redactedConfigHash: 'simulated-claude', payload });
67
+ }
68
+ catch (e) {
69
+ throw new UnknownClaudeEventError(e instanceof Error ? e.message : String(e));
70
+ }
71
+ }
72
+ export function replayClaudeTranscript(transcript, context) {
73
+ if (!record(transcript) || transcript.label !== 'SIMULATED' || transcript.version !== 1 || !Array.isArray(transcript.events))
74
+ throw new UnknownClaudeEventError('unsupported Claude transcript version/shape');
75
+ try {
76
+ assertClaudeCapabilities({ version: transcript.version, capabilities: ['events-v1'] }, { version: 1, capabilities: ['events-v1'] });
77
+ }
78
+ catch (e) {
79
+ throw new UnknownClaudeEventError(e instanceof Error ? e.message : String(e));
80
+ }
81
+ return Object.freeze(transcript.events.map((event, index) => normalizeClaudeEvent(event, context, index + 1)));
82
+ }
83
+ //# sourceMappingURL=normalize.js.map
@@ -0,0 +1,13 @@
1
+ export type AgentErrorKind = 'executable' | 'shape-mismatch' | 'timeout' | 'cancel' | 'hung' | 'unknown-delivery';
2
+ export type ErrorPhase = 'before-dispatch' | 'after-dispatch';
3
+ export interface ClassifiedAgentError {
4
+ readonly kind: AgentErrorKind;
5
+ readonly message: string;
6
+ readonly phase: ErrorPhase;
7
+ readonly reconcileState: 'UNKNOWN_DELIVERY' | null;
8
+ readonly retry: false;
9
+ readonly cause: unknown;
10
+ }
11
+ export declare function classifyAgentError(cause: unknown, context: {
12
+ readonly phase: ErrorPhase;
13
+ }): ClassifiedAgentError;
@@ -0,0 +1,19 @@
1
+ export function classifyAgentError(cause, context) {
2
+ const message = cause instanceof Error ? cause.message : String(cause);
3
+ const text = message.toLowerCase();
4
+ let kind;
5
+ if (/executable|unrunnable|unavailable|version mismatch/.test(text))
6
+ kind = 'executable';
7
+ else if (/timeout|timed out|deadline/.test(text))
8
+ kind = 'timeout';
9
+ else if (/cancel|aborted/.test(text))
10
+ kind = 'cancel';
11
+ else if (/hung|no progress|stalled/.test(text))
12
+ kind = 'hung';
13
+ else if (/\back(?:nowledg(?:e|ement)?)?\b|unknown[-_ ]delivery|sent[-_ ]no[-_ ]ack\b/.test(text))
14
+ kind = 'unknown-delivery';
15
+ else
16
+ kind = 'shape-mismatch'; // unknown delivery requires explicit acknowledgement-loss evidence; never infer it from phase alone.
17
+ return Object.freeze({ kind, message, phase: context.phase, reconcileState: kind === 'unknown-delivery' ? 'UNKNOWN_DELIVERY' : null, retry: false, cause });
18
+ }
19
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,70 @@
1
+ /** SIMULATED Claude-shaped fixture only; no live Claude Code protocol capability is asserted. */
2
+ export declare const claudeTranscript: Readonly<{
3
+ label: 'SIMULATED';
4
+ version: 1;
5
+ events: readonly ({
6
+ version: number;
7
+ type: string;
8
+ subtype: string;
9
+ session_id: string;
10
+ at: string;
11
+ text?: never;
12
+ name?: never;
13
+ request_id?: never;
14
+ outcome?: never;
15
+ } | {
16
+ session_id?: never;
17
+ version: number;
18
+ type: string;
19
+ subtype: string;
20
+ text: string;
21
+ at: string;
22
+ name?: never;
23
+ request_id?: never;
24
+ outcome?: never;
25
+ } | {
26
+ session_id?: never;
27
+ text?: never;
28
+ version: number;
29
+ type: string;
30
+ subtype: string;
31
+ name: string;
32
+ at: string;
33
+ request_id?: never;
34
+ outcome?: never;
35
+ } | {
36
+ session_id?: never;
37
+ text?: never;
38
+ name?: never;
39
+ version: number;
40
+ type: string;
41
+ subtype: string;
42
+ request_id: string;
43
+ at: string;
44
+ outcome?: never;
45
+ } | {
46
+ session_id?: never;
47
+ text?: never;
48
+ name?: never;
49
+ request_id?: never;
50
+ version: number;
51
+ type: string;
52
+ subtype: string;
53
+ at: string;
54
+ outcome?: never;
55
+ } | {
56
+ session_id?: never;
57
+ text?: never;
58
+ name?: never;
59
+ request_id?: never;
60
+ version: number;
61
+ type: string;
62
+ subtype: string;
63
+ outcome: string;
64
+ at: string;
65
+ })[];
66
+ deliveryBoundary: Readonly<{
67
+ label: 'SIMULATED';
68
+ state: 'sent-no-ack';
69
+ }>;
70
+ }>;
@@ -0,0 +1,15 @@
1
+ /** SIMULATED Claude-shaped fixture only; no live Claude Code protocol capability is asserted. */
2
+ export const claudeTranscript = Object.freeze({
3
+ label: 'SIMULATED',
4
+ version: 1,
5
+ events: Object.freeze([
6
+ { version: 1, type: 'system', subtype: 'init', session_id: 'session-a1b2c3d4', at: '2026-10-23T00:00:00.000Z' },
7
+ { version: 1, type: 'assistant', subtype: 'text', text: 'Inspecting repository…', at: '2026-10-23T00:00:01.000Z' },
8
+ { version: 1, type: 'tool', subtype: 'result', name: 'read', at: '2026-10-23T00:00:02.000Z' },
9
+ { version: 1, type: 'control_request', subtype: 'permission', request_id: 'permission-demo0001', at: '2026-10-23T00:00:03.000Z' },
10
+ { version: 1, type: 'result', subtype: 'turn_end', at: '2026-10-23T00:00:04.000Z' },
11
+ { version: 1, type: 'result', subtype: 'run_end', outcome: 'success', at: '2026-10-23T00:00:05.000Z' },
12
+ ]),
13
+ deliveryBoundary: Object.freeze({ label: 'SIMULATED', state: 'sent-no-ack' }),
14
+ });
15
+ //# sourceMappingURL=claude-transcript.js.map
@@ -0,0 +1,60 @@
1
+ /** SIMULATED OMP-shaped fixture only; no live OMP protocol capability is asserted. */
2
+ export declare const ompTranscript: Readonly<{
3
+ label: 'SIMULATED';
4
+ version: 1;
5
+ events: readonly ({
6
+ version: number;
7
+ type: string;
8
+ runId: string;
9
+ at: string;
10
+ text?: never;
11
+ tool?: never;
12
+ requestId?: never;
13
+ outcome?: never;
14
+ } | {
15
+ runId?: never;
16
+ version: number;
17
+ type: string;
18
+ text: string;
19
+ at: string;
20
+ tool?: never;
21
+ requestId?: never;
22
+ outcome?: never;
23
+ } | {
24
+ runId?: never;
25
+ text?: never;
26
+ version: number;
27
+ type: string;
28
+ tool: string;
29
+ at: string;
30
+ requestId?: never;
31
+ outcome?: never;
32
+ } | {
33
+ runId?: never;
34
+ text?: never;
35
+ tool?: never;
36
+ version: number;
37
+ type: string;
38
+ requestId: string;
39
+ at: string;
40
+ outcome?: never;
41
+ } | {
42
+ runId?: never;
43
+ text?: never;
44
+ tool?: never;
45
+ requestId?: never;
46
+ version: number;
47
+ type: string;
48
+ at: string;
49
+ outcome?: never;
50
+ } | {
51
+ runId?: never;
52
+ text?: never;
53
+ tool?: never;
54
+ requestId?: never;
55
+ version: number;
56
+ type: string;
57
+ outcome: string;
58
+ at: string;
59
+ })[];
60
+ }>;
@@ -0,0 +1,14 @@
1
+ /** SIMULATED OMP-shaped fixture only; no live OMP protocol capability is asserted. */
2
+ export const ompTranscript = Object.freeze({
3
+ label: 'SIMULATED',
4
+ version: 1,
5
+ events: Object.freeze([
6
+ { version: 1, type: 'accepted', runId: 'run-demo0001', at: '2026-10-23T00:00:00.000Z' },
7
+ { version: 1, type: 'partial-stream', text: 'Inspecting repository…', at: '2026-10-23T00:00:01.000Z' },
8
+ { version: 1, type: 'tool-finish', tool: 'read', at: '2026-10-23T00:00:02.000Z' },
9
+ { version: 1, type: 'permission-request', requestId: 'permission-demo0001', at: '2026-10-23T00:00:03.000Z' },
10
+ { version: 1, type: 'turn-finish', at: '2026-10-23T00:00:04.000Z' },
11
+ { version: 1, type: 'run-finish', outcome: 'success', at: '2026-10-23T00:00:05.000Z' },
12
+ ]),
13
+ });
14
+ //# sourceMappingURL=omp-transcript.js.map
@@ -0,0 +1,18 @@
1
+ import { type Envelope } from '../../core/events.js';
2
+ export declare class UnknownAgentEventError extends TypeError {
3
+ readonly code = "AGENT_EVENT_SHAPE_MISMATCH";
4
+ constructor(message: string);
5
+ }
6
+ export interface OmpReplayContext {
7
+ readonly sessionId: string;
8
+ readonly taskId: string;
9
+ readonly projectId: string;
10
+ readonly runId: string;
11
+ readonly at?: string;
12
+ }
13
+ export declare function normalizeOmpEvent(raw: unknown, context?: OmpReplayContext, sequence?: number): Envelope;
14
+ export declare function replayOmpTranscript(transcript: {
15
+ readonly label: 'SIMULATED';
16
+ readonly version: 1;
17
+ readonly events: readonly unknown[];
18
+ }, context: OmpReplayContext): readonly Envelope[];
@@ -0,0 +1,77 @@
1
+ import { EVENT_SCHEMA_VERSION, validateEnvelope } from '../../core/events.js';
2
+ export class UnknownAgentEventError extends TypeError {
3
+ code = 'AGENT_EVENT_SHAPE_MISMATCH';
4
+ constructor(message) { super(message); this.name = 'UnknownAgentEventError'; }
5
+ }
6
+ const REQUIRED_COMMON = ['version', 'type', 'at'];
7
+ function isRecord(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); }
8
+ export function normalizeOmpEvent(raw, context = { sessionId: 'session-a1b2c3d4', taskId: 'task-a1b2c3d4', projectId: 'project-demo0001', runId: 'run-demo0001' }, sequence = 1) {
9
+ if (!isRecord(raw))
10
+ throw new UnknownAgentEventError('OMP event must be an object');
11
+ if (raw['version'] !== 1)
12
+ throw new UnknownAgentEventError(`unsupported OMP event version ${String(raw['version'])}`);
13
+ if (REQUIRED_COMMON.some((key) => !(key in raw)))
14
+ throw new UnknownAgentEventError('OMP event missing required version/type/at shape');
15
+ const type = raw['type'];
16
+ const at = raw['at'];
17
+ if (typeof type !== 'string' || typeof at !== 'string')
18
+ throw new UnknownAgentEventError('OMP event type and at must be strings');
19
+ let payload;
20
+ let eventType;
21
+ let status;
22
+ let actor;
23
+ switch (type) {
24
+ case 'accepted':
25
+ if (typeof raw['runId'] !== 'string' || !raw['runId'])
26
+ throw new UnknownAgentEventError('accepted requires runId');
27
+ payload = { type: 'AdvisorAcked', adapter: 'omp:SIMULATED' };
28
+ eventType = 'AdvisorAcked';
29
+ status = 'accepted';
30
+ actor = { role: 'advisor', adapter: 'omp' };
31
+ break;
32
+ case 'partial-stream':
33
+ case 'tool-finish':
34
+ case 'turn-finish':
35
+ if (type === 'partial-stream' && typeof raw['text'] !== 'string')
36
+ throw new UnknownAgentEventError('partial-stream requires text');
37
+ // Output and tool/turn completion do not assert task-level completion.
38
+ payload = { type: 'AdvisorUnknownOutcome', reason: 'adapter-fault', note: `${type}${typeof raw['text'] === 'string' ? `:${raw['text']}` : ''}` };
39
+ eventType = 'AdvisorUnknownOutcome';
40
+ status = type;
41
+ actor = { role: 'advisor', adapter: 'omp' };
42
+ break;
43
+ case 'permission-request':
44
+ if (typeof raw['requestId'] !== 'string' || !raw['requestId'])
45
+ throw new UnknownAgentEventError('permission-request requires requestId');
46
+ payload = { type: 'AdvisorUnknownOutcome', reason: 'adapter-fault', note: `permission-request:${raw['requestId']}` };
47
+ eventType = 'AdvisorUnknownOutcome';
48
+ status = 'waiting_input';
49
+ actor = { role: 'advisor', adapter: 'omp' };
50
+ break;
51
+ case 'run-finish':
52
+ if (raw['outcome'] !== 'success' && raw['outcome'] !== 'failed')
53
+ throw new UnknownAgentEventError('run-finish requires explicit success or failed outcome');
54
+ payload = raw['outcome'] === 'success' ? { type: 'AdvisorCompleted', resultRef: 'artifact-ompresult01' } : { type: 'AdvisorUnknownOutcome', reason: 'adapter-fault', note: 'explicit run failed' };
55
+ eventType = String(payload['type']);
56
+ status = raw['outcome'];
57
+ actor = { role: 'advisor', adapter: 'omp' };
58
+ break;
59
+ default: throw new UnknownAgentEventError(`unknown OMP event type ${JSON.stringify(type)}`);
60
+ }
61
+ const seq = Math.max(1, sequence);
62
+ try {
63
+ return validateEnvelope({ schemaVersion: EVENT_SCHEMA_VERSION, seq, sessionSequence: seq, sessionId: context.sessionId, taskId: context.taskId, projectId: context.projectId, runId: context.runId, at, sourceAt: at, causality: null,
64
+ eventId: `event-omp-${String(seq).padStart(6, '0')}`, parentEventId: null, causationId: null, attemptId: null, traceId: 'trace-omp000001', spanId: `span-omp-${String(seq).padStart(6, '0')}`,
65
+ actor, provenance: { source: 'simulated' }, adapter: 'omp', adapterVersion: '1', eventType, status, reasonCode: null, artifactRefs: [], decisionId: null, requirementIds: [],
66
+ ckitVersion: '0.0.0', policyVersion: '1', promptTemplateVersion: '1', redactedConfigHash: 'simulated-omp', payload });
67
+ }
68
+ catch (error) {
69
+ throw new UnknownAgentEventError(`OMP event cannot be normalized: ${error instanceof Error ? error.message : String(error)}`);
70
+ }
71
+ }
72
+ export function replayOmpTranscript(transcript, context) {
73
+ if (!isRecord(transcript) || transcript.label !== 'SIMULATED' || transcript.version !== 1 || !Array.isArray(transcript.events))
74
+ throw new UnknownAgentEventError('unsupported transcript version/shape');
75
+ return Object.freeze(transcript.events.map((event, index) => normalizeOmpEvent(event, context, index + 1)));
76
+ }
77
+ //# sourceMappingURL=normalize.js.map
@@ -0,0 +1,35 @@
1
+ import type { AgentPort, AgentRequest } from '../../ports/agent.js';
2
+ import type { LaunchProfile } from '../launch/profile.js';
3
+ import { classifyAgentError } from './errors.js';
4
+ export type AgentLifecycleState = 'enqueued' | 'accepted' | 'running' | 'waiting_input' | 'finished' | 'failed' | 'unknown_delivery';
5
+ export interface TransportReceipt {
6
+ readonly requestId: string;
7
+ readonly state: AgentLifecycleState;
8
+ readonly runId: string | null;
9
+ readonly waitingRequestId: string | null;
10
+ readonly reconcileState: 'UNKNOWN_DELIVERY' | null;
11
+ }
12
+ export interface TransitionResult {
13
+ readonly receipt: TransportReceipt;
14
+ readonly dispatched: boolean;
15
+ }
16
+ export interface TransitionOptions {
17
+ readonly runId?: string;
18
+ readonly requestId?: string;
19
+ readonly cause?: 'explicit-run-completion' | 'explicit-failure' | 'ack-lost' | 'input-resolved';
20
+ }
21
+ export interface TransportLifecycle {
22
+ receipt(): TransportReceipt;
23
+ transition(next: AgentLifecycleState, options?: TransitionOptions): TransitionResult;
24
+ }
25
+ export declare function createTransportLifecycle(requestId: string): TransportLifecycle;
26
+ /** Contract boundary consumed by offline and future live adapters; does not launch a process. */
27
+ export interface AgentTransportContract {
28
+ readonly profile: LaunchProfile;
29
+ readonly port: AgentPort;
30
+ dispatch(request: AgentRequest): AsyncIterable<ReturnType<typeof classifyAgentError> | {
31
+ readonly kind: 'observation';
32
+ readonly value: Awaited<ReturnType<AgentPort['dispatch']> extends AsyncIterable<infer T> ? T : never>;
33
+ }>;
34
+ }
35
+ export declare function classifyPreDispatchFailure(error: unknown): import("./errors.js").ClassifiedAgentError;
@@ -0,0 +1,39 @@
1
+ import { classifyAgentError } from './errors.js';
2
+ const ALLOWED = Object.freeze({
3
+ enqueued: ['accepted', 'failed', 'unknown_delivery'], accepted: ['running', 'failed', 'unknown_delivery'], running: ['waiting_input', 'finished', 'failed', 'unknown_delivery'], waiting_input: ['running', 'failed', 'unknown_delivery'], finished: [], failed: [], unknown_delivery: [],
4
+ });
5
+ export function createTransportLifecycle(requestId) {
6
+ if (!requestId)
7
+ throw new TypeError('requestId required');
8
+ let state = 'enqueued';
9
+ let runId = null;
10
+ let waitingRequestId = null;
11
+ const receipt = () => Object.freeze({ requestId, state, runId, waitingRequestId, reconcileState: state === 'unknown_delivery' ? 'UNKNOWN_DELIVERY' : null });
12
+ const transitionFailure = (next) => { throw new TypeError(`invalid transition ${state} -> ${next}${state === 'unknown_delivery' ? ': reconcile-only; no auto-resend' : ''}`); };
13
+ return Object.freeze({ receipt, transition(next, options = {}) {
14
+ if (!ALLOWED[state].includes(next))
15
+ transitionFailure(next);
16
+ if (state === 'waiting_input' && next === 'running' && options.cause !== 'input-resolved')
17
+ throw new TypeError('waiting_input requires explicit input resolution');
18
+ if (next === 'finished' && options.cause !== 'explicit-run-completion')
19
+ throw new TypeError('finished requires explicit run completion; turn-finish is not run completion');
20
+ if (next === 'failed' && options.cause !== 'explicit-failure')
21
+ transitionFailure(next);
22
+ if (next === 'unknown_delivery' && options.cause !== 'ack-lost')
23
+ transitionFailure(next);
24
+ if (next === 'waiting_input' && !options.requestId)
25
+ throw new TypeError('waiting_input requires requestId');
26
+ if (next === 'accepted' && !options.runId)
27
+ throw new TypeError('accepted requires runId');
28
+ state = next;
29
+ if (options.runId !== undefined)
30
+ runId = options.runId;
31
+ if (next === 'waiting_input')
32
+ waitingRequestId = options.requestId ?? null;
33
+ if (next === 'running')
34
+ waitingRequestId = null;
35
+ return Object.freeze({ receipt: receipt(), dispatched: false });
36
+ } });
37
+ }
38
+ export function classifyPreDispatchFailure(error) { return classifyAgentError(error, { phase: 'before-dispatch' }); }
39
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1,49 @@
1
+ import type { Envelope } from '../../core/events.js';
2
+ import type { AgentRunStatus } from '../../core/entities.js';
3
+ import { type AgentErrorKind, type ClassifiedAgentError, type ErrorPhase } from './errors.js';
4
+ import type { TransportLifecycle, TransportReceipt } from './transport.js';
5
+ export interface LifecycleObservationResult {
6
+ readonly receipt: TransportReceipt;
7
+ readonly transitioned: boolean;
8
+ }
9
+ export declare function applyLifecycleObservation(lifecycle: TransportLifecycle, envelope: Envelope, options?: {
10
+ readonly runId?: string;
11
+ }): LifecycleObservationResult;
12
+ export type ControlIntent = 'pause' | 'interrupt' | 'stop';
13
+ export interface ControlDecision {
14
+ readonly intent: ControlIntent;
15
+ readonly action: 'queued' | 'awaiting-ack' | 'interrupted';
16
+ readonly workState: AgentRunStatus;
17
+ readonly evidence: {
18
+ readonly interruptRequest: string;
19
+ readonly ackToken: string;
20
+ } | null;
21
+ }
22
+ export declare function classifyControlIntent(intent: ControlIntent, receipt: TransportReceipt, evidence?: {
23
+ readonly interruptRequest: string;
24
+ readonly ackToken: string;
25
+ }): ControlDecision;
26
+ export interface PermissionRoute {
27
+ readonly requestId: string;
28
+ readonly taskId: string;
29
+ readonly runId: string | null;
30
+ readonly state: 'waiting_input';
31
+ readonly answered: false;
32
+ }
33
+ export declare function routePermissionRequest(envelope: Envelope, receipt: TransportReceipt): PermissionRoute;
34
+ export interface FailureDecision {
35
+ readonly kind: AgentErrorKind;
36
+ readonly workOutcome: 'failed' | 'unknown';
37
+ readonly reconcileRequired: boolean;
38
+ readonly retryAllowed: false;
39
+ readonly reconcileState: 'UNKNOWN_DELIVERY' | null;
40
+ readonly evidence: ClassifiedAgentError;
41
+ }
42
+ export declare function classifyFailure(cause: unknown, phase: ErrorPhase): FailureDecision;
43
+ export interface TurnResultDecision {
44
+ readonly completion: 'none' | 'completed' | 'unknown';
45
+ readonly resultRef: string | null;
46
+ readonly taskCompleted: false;
47
+ readonly reason: string | null;
48
+ }
49
+ export declare function turnResult(events: readonly Envelope[]): TurnResultDecision;