@astrosheep/keiyaku 4.0.0 → 4.0.2

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 (308) hide show
  1. package/README.md +133 -8
  2. package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +2 -2
  3. package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +4 -4
  4. package/build/integrations/marketplace/plugins/keiyaku/opencode.js +2 -2
  5. package/build/integrations/marketplace/plugins/keiyaku/package.json +2 -2
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +13 -5
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +91 -32
  8. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +134 -0
  9. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/agents/openai.yaml +4 -0
  10. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-task/SKILL.md +41 -6
  11. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +262 -46
  12. package/build/src/akuma/abort.d.ts +2 -0
  13. package/build/src/akuma/abort.js +50 -0
  14. package/build/src/akuma/akuma.d.ts +50 -33
  15. package/build/src/akuma/akuma.js +175 -127
  16. package/build/src/akuma/archetype.d.ts +14 -5
  17. package/build/src/akuma/archetype.js +85 -39
  18. package/build/src/akuma/body.d.ts +3 -5
  19. package/build/src/akuma/body.js +490 -183
  20. package/build/src/akuma/coordinate.d.ts +9 -0
  21. package/build/src/akuma/coordinate.js +22 -0
  22. package/build/src/akuma/heart/facts.d.ts +88 -45
  23. package/build/src/akuma/heart/facts.js +19 -8
  24. package/build/src/akuma/heart/index.d.ts +64 -55
  25. package/build/src/akuma/heart/index.js +172 -252
  26. package/build/src/akuma/heart/rows.d.ts +38 -83
  27. package/build/src/akuma/heart/rows.js +117 -155
  28. package/build/src/akuma/heart/schema.d.ts +1 -1
  29. package/build/src/akuma/heart/schema.js +61 -22
  30. package/build/src/akuma/heart/soul.d.ts +8 -0
  31. package/build/src/akuma/heart/soul.js +136 -0
  32. package/build/src/akuma/heart/storage.d.ts +47 -0
  33. package/build/src/akuma/heart/storage.js +224 -0
  34. package/build/src/akuma/heart/tells.d.ts +12 -0
  35. package/build/src/akuma/heart/tells.js +79 -0
  36. package/build/src/akuma/heart/timeline.d.ts +15 -0
  37. package/build/src/akuma/heart/timeline.js +86 -0
  38. package/build/src/akuma/identity.d.ts +2 -2
  39. package/build/src/akuma/identity.js +9 -9
  40. package/build/src/akuma/index.d.ts +10 -3
  41. package/build/src/akuma/index.js +7 -1
  42. package/build/src/akuma/projection.d.ts +176 -0
  43. package/build/src/akuma/projection.js +256 -0
  44. package/build/src/akuma/provider-recipe.d.ts +24 -0
  45. package/build/src/akuma/provider-recipe.js +100 -0
  46. package/build/src/akuma/provider.d.ts +67 -13
  47. package/build/src/akuma/provider.js +172 -105
  48. package/build/src/akuma/providers/acp/core.d.ts +19 -0
  49. package/build/src/akuma/providers/acp/core.js +159 -0
  50. package/build/src/akuma/providers/acp/events.d.ts +20 -0
  51. package/build/src/akuma/providers/acp/events.js +73 -0
  52. package/build/src/akuma/providers/acp/index.d.ts +12 -0
  53. package/build/src/akuma/providers/acp/index.js +94 -0
  54. package/build/src/akuma/providers/{claude.d.ts → claude/events.d.ts} +9 -41
  55. package/build/src/akuma/providers/claude/events.js +238 -0
  56. package/build/src/akuma/providers/claude/index.d.ts +47 -0
  57. package/build/src/akuma/providers/claude/index.js +279 -0
  58. package/build/src/akuma/providers/claude/input.d.ts +13 -0
  59. package/build/src/akuma/providers/claude/input.js +109 -0
  60. package/build/src/akuma/providers/codex-app-server/events.d.ts +1 -1
  61. package/build/src/akuma/providers/codex-app-server/events.js +15 -12
  62. package/build/src/akuma/providers/codex-app-server/index.d.ts +15 -13
  63. package/build/src/akuma/providers/codex-app-server/index.js +77 -33
  64. package/build/src/akuma/providers/grok-build/index.d.ts +4 -0
  65. package/build/src/akuma/providers/grok-build/index.js +70 -0
  66. package/build/src/akuma/providers/index.d.ts +5 -3
  67. package/build/src/akuma/providers/index.js +35 -56
  68. package/build/src/akuma/providers/opencode-sdk/events.d.ts +54 -0
  69. package/build/src/akuma/providers/opencode-sdk/events.js +235 -0
  70. package/build/src/akuma/providers/opencode-sdk/index.d.ts +33 -0
  71. package/build/src/akuma/providers/opencode-sdk/index.js +308 -0
  72. package/build/src/akuma/providers/opencode-sdk/session.d.ts +26 -0
  73. package/build/src/akuma/providers/opencode-sdk/session.js +63 -0
  74. package/build/src/akuma/providers/pi/events.d.ts +33 -0
  75. package/build/src/akuma/providers/pi/events.js +166 -0
  76. package/build/src/akuma/providers/pi/index.d.ts +11 -0
  77. package/build/src/akuma/providers/pi/index.js +191 -0
  78. package/build/src/akuma/publication.d.ts +3 -3
  79. package/build/src/akuma/publication.js +28 -40
  80. package/build/src/akuma/requests.d.ts +9 -6
  81. package/build/src/akuma/requests.js +95 -65
  82. package/build/src/alias/index.d.ts +4 -3
  83. package/build/src/alias/index.js +12 -13
  84. package/build/src/body/decode.js +7 -1
  85. package/build/src/body/region.d.ts +2 -0
  86. package/build/src/body/region.js +77 -7
  87. package/build/src/body/render.js +2 -1
  88. package/build/src/body/shape.js +7 -1
  89. package/build/src/body/verification.js +19 -4
  90. package/build/src/cli/accepted.d.ts +18 -12
  91. package/build/src/cli/accepted.js +73 -34
  92. package/build/src/cli/actor.js +3 -3
  93. package/build/src/cli/commands/akuma-invoke.d.ts +44 -19
  94. package/build/src/cli/commands/akuma-invoke.js +101 -52
  95. package/build/src/cli/commands/akuma.d.ts +27 -9
  96. package/build/src/cli/commands/akuma.js +151 -80
  97. package/build/src/cli/commands/contract.d.ts +155 -0
  98. package/build/src/cli/commands/contract.js +20 -0
  99. package/build/src/cli/commands/install.js +2 -0
  100. package/build/src/cli/commands/task-invoke.d.ts +19 -4
  101. package/build/src/cli/commands/task-invoke.js +65 -17
  102. package/build/src/cli/commands/task-query.d.ts +5 -0
  103. package/build/src/cli/commands/task-query.js +247 -0
  104. package/build/src/cli/commands/task.d.ts +3 -1
  105. package/build/src/cli/commands/task.js +52 -14
  106. package/build/src/cli/coordinates.d.ts +18 -0
  107. package/build/src/cli/coordinates.js +120 -0
  108. package/build/src/cli/draft.d.ts +8 -0
  109. package/build/src/cli/draft.js +96 -0
  110. package/build/src/cli/invoke.d.ts +9 -3
  111. package/build/src/cli/invoke.js +287 -108
  112. package/build/src/cli/main.js +54 -7
  113. package/build/src/cli/parse.d.ts +21 -117
  114. package/build/src/cli/parse.js +79 -84
  115. package/build/src/cli/render/akuma-tool-command.d.ts +6 -0
  116. package/build/src/cli/render/akuma-tool-command.js +144 -0
  117. package/build/src/cli/render/akuma-tool.d.ts +4 -2
  118. package/build/src/cli/render/akuma-tool.js +35 -5
  119. package/build/src/cli/render/akuma.d.ts +3 -1
  120. package/build/src/cli/render/akuma.js +247 -212
  121. package/build/src/cli/render/audit.d.ts +3 -0
  122. package/build/src/cli/render/audit.js +104 -0
  123. package/build/src/cli/render/catalog.d.ts +2 -0
  124. package/build/src/cli/render/catalog.js +16 -0
  125. package/build/src/cli/render/contract.d.ts +3 -3
  126. package/build/src/cli/render/contract.js +200 -54
  127. package/build/src/cli/render/kanshi.js +272 -129
  128. package/build/src/cli/render/receipt.d.ts +19 -0
  129. package/build/src/cli/render/receipt.js +106 -0
  130. package/build/src/cli/render/refusal.d.ts +16 -2
  131. package/build/src/cli/render/refusal.js +88 -3
  132. package/build/src/cli/render/region.d.ts +2 -0
  133. package/build/src/cli/render/region.js +17 -0
  134. package/build/src/cli/render/task.d.ts +2 -1
  135. package/build/src/cli/render/task.js +223 -60
  136. package/build/src/cli/render/terminal.d.ts +20 -0
  137. package/build/src/cli/render/terminal.js +121 -0
  138. package/build/src/cli/render/text.js +11 -3
  139. package/build/src/cli/result.d.ts +126 -19
  140. package/build/src/cli/usage.d.ts +1 -0
  141. package/build/src/cli/usage.js +3 -0
  142. package/build/src/contract-worktree.d.ts +44 -0
  143. package/build/src/contract-worktree.js +251 -0
  144. package/build/src/coordination/durable-file.d.ts +5 -1
  145. package/build/src/coordination/durable-file.js +57 -10
  146. package/build/src/coordination/sqlite-transaction-lock.d.ts +4 -0
  147. package/build/src/coordination/sqlite-transaction-lock.js +22 -5
  148. package/build/src/core/facts/codec.js +23 -4
  149. package/build/src/core/facts/eligibility.d.ts +1 -10
  150. package/build/src/core/facts/eligibility.js +0 -49
  151. package/build/src/core/facts/fold.js +1 -6
  152. package/build/src/core/facts/gate.d.ts +1 -0
  153. package/build/src/core/facts/gate.js +1 -0
  154. package/build/src/core/facts/observation.d.ts +3 -0
  155. package/build/src/core/facts/observation.js +12 -0
  156. package/build/src/core/facts/types.d.ts +10 -3
  157. package/build/src/core/subject.js +2 -2
  158. package/build/src/core/verbs/amend.d.ts +1 -1
  159. package/build/src/core/verbs/amend.js +3 -18
  160. package/build/src/core/verbs/bind.js +2 -16
  161. package/build/src/core/verbs/deliver.d.ts +1 -1
  162. package/build/src/core/verbs/deliver.js +14 -4
  163. package/build/src/core/verbs/placement.d.ts +1 -1
  164. package/build/src/core/verbs/placement.js +7 -9
  165. package/build/src/dispatch/index.d.ts +5 -3
  166. package/build/src/dispatch/index.js +30 -21
  167. package/build/src/duration.d.ts +10 -0
  168. package/build/src/duration.js +22 -0
  169. package/build/src/git/admission.d.ts +2 -2
  170. package/build/src/git/admission.js +33 -23
  171. package/build/src/git/hooks.d.ts +15 -0
  172. package/build/src/git/hooks.js +70 -18
  173. package/build/src/git/identity.d.ts +5 -1
  174. package/build/src/git/identity.js +23 -4
  175. package/build/src/git/integration.d.ts +48 -0
  176. package/build/src/git/integration.js +250 -0
  177. package/build/src/git/observe.d.ts +29 -15
  178. package/build/src/git/observe.js +185 -76
  179. package/build/src/git/read-observation.d.ts +41 -0
  180. package/build/src/git/read-observation.js +361 -0
  181. package/build/src/git/reconcile.d.ts +17 -5
  182. package/build/src/git/reconcile.js +305 -109
  183. package/build/src/git/repository.d.ts +41 -18
  184. package/build/src/git/repository.js +220 -114
  185. package/build/src/git/scratch.d.ts +17 -0
  186. package/build/src/git/scratch.js +73 -0
  187. package/build/src/git/target-placement.d.ts +92 -0
  188. package/build/src/git/target-placement.js +375 -0
  189. package/build/src/git/tender.d.ts +49 -0
  190. package/build/src/git/tender.js +63 -0
  191. package/build/src/git/terminal-seal.d.ts +24 -0
  192. package/build/src/git/terminal-seal.js +89 -0
  193. package/build/src/git/tree.d.ts +2 -2
  194. package/build/src/git/tree.js +4 -0
  195. package/build/src/git/workspace.d.ts +53 -0
  196. package/build/src/git/workspace.js +139 -0
  197. package/build/src/identity/selector.d.ts +6 -0
  198. package/build/src/identity/selector.js +19 -0
  199. package/build/src/index.d.ts +4 -2
  200. package/build/src/index.js +2 -1
  201. package/build/src/kanshi/index.d.ts +2 -2
  202. package/build/src/kanshi/index.js +1 -1
  203. package/build/src/kanshi/read.d.ts +7 -3
  204. package/build/src/kanshi/read.js +245 -45
  205. package/build/src/kanshi/report.d.ts +81 -6
  206. package/build/src/kanshi/select.d.ts +5 -0
  207. package/build/src/kanshi/select.js +33 -1
  208. package/build/src/library/address.d.ts +57 -0
  209. package/build/src/library/address.js +165 -0
  210. package/build/src/library/akuma-creation.d.ts +16 -7
  211. package/build/src/library/akuma-creation.js +96 -22
  212. package/build/src/library/audit.d.ts +18 -0
  213. package/build/src/library/audit.js +44 -0
  214. package/build/src/library/bind.d.ts +21 -0
  215. package/build/src/library/bind.js +56 -0
  216. package/build/src/library/catalog.d.ts +58 -0
  217. package/build/src/library/catalog.js +69 -0
  218. package/build/src/library/configuration.d.ts +6 -15
  219. package/build/src/library/configuration.js +14 -17
  220. package/build/src/library/contract.d.ts +23 -49
  221. package/build/src/library/contract.js +171 -185
  222. package/build/src/library/delivery.d.ts +24 -0
  223. package/build/src/library/delivery.js +21 -0
  224. package/build/src/library/fleet.d.ts +65 -0
  225. package/build/src/library/fleet.js +153 -0
  226. package/build/src/library/input.d.ts +3 -0
  227. package/build/src/library/input.js +19 -0
  228. package/build/src/library/keiyaku.d.ts +18 -3
  229. package/build/src/library/keiyaku.js +12 -1
  230. package/build/src/library/mutation.d.ts +39 -0
  231. package/build/src/library/mutation.js +37 -0
  232. package/build/src/library/reconcile.d.ts +29 -0
  233. package/build/src/library/reconcile.js +179 -0
  234. package/build/src/library/refusal.d.ts +21 -0
  235. package/build/src/library/refusal.js +29 -0
  236. package/build/src/library/region.d.ts +14 -1
  237. package/build/src/library/region.js +18 -4
  238. package/build/src/library/repo.d.ts +4 -13
  239. package/build/src/library/repo.js +14 -24
  240. package/build/src/protocol/attempt.d.ts +16 -3
  241. package/build/src/protocol/attempt.js +41 -10
  242. package/build/src/protocol/bind.d.ts +9 -2
  243. package/build/src/protocol/bind.js +48 -40
  244. package/build/src/protocol/intent.d.ts +57 -20
  245. package/build/src/protocol/intent.js +55 -79
  246. package/build/src/protocol/operations.d.ts +152 -43
  247. package/build/src/protocol/operations.js +482 -166
  248. package/build/src/protocol/outcome.d.ts +14 -3
  249. package/build/src/protocol/outcome.js +11 -3
  250. package/build/src/protocol/placement.d.ts +41 -0
  251. package/build/src/protocol/placement.js +147 -0
  252. package/build/src/protocol/read/documents.d.ts +2 -2
  253. package/build/src/protocol/read/documents.js +4 -4
  254. package/build/src/protocol/read/status.d.ts +18 -5
  255. package/build/src/protocol/read/status.js +73 -13
  256. package/build/src/protocol/run.d.ts +49 -7
  257. package/build/src/protocol/run.js +53 -25
  258. package/build/src/runtime/proc/line-rpc.d.ts +4 -8
  259. package/build/src/runtime/proc/line-rpc.js +22 -28
  260. package/build/src/runtime/proc/run.d.ts +23 -21
  261. package/build/src/runtime/proc/run.js +123 -89
  262. package/build/src/runtime/proc/stdio.d.ts +18 -0
  263. package/build/src/runtime/proc/stdio.js +58 -0
  264. package/build/src/settings.d.ts +7 -1
  265. package/build/src/settings.js +32 -17
  266. package/build/src/settlement/fence.d.ts +5 -0
  267. package/build/src/settlement/fence.js +14 -0
  268. package/build/src/settlement/holder.d.ts +35 -4
  269. package/build/src/settlement/holder.js +127 -28
  270. package/build/src/settlement/settle.d.ts +9 -1
  271. package/build/src/settlement/settle.js +74 -37
  272. package/build/src/task/board.d.ts +23 -5
  273. package/build/src/task/board.js +17 -10
  274. package/build/src/task/compose.d.ts +2 -2
  275. package/build/src/task/compose.js +18 -10
  276. package/build/src/task/context.d.ts +3 -3
  277. package/build/src/task/context.js +15 -20
  278. package/build/src/task/document.d.ts +2 -1
  279. package/build/src/task/document.js +15 -5
  280. package/build/src/task/index.d.ts +27 -15
  281. package/build/src/task/index.js +57 -35
  282. package/build/src/task/operations.d.ts +38 -13
  283. package/build/src/task/operations.js +80 -46
  284. package/build/src/task/query.d.ts +67 -0
  285. package/build/src/task/query.js +279 -0
  286. package/build/src/task/store.d.ts +5 -7
  287. package/build/src/task/store.js +43 -28
  288. package/build/src/verification/declaration.d.ts +1 -0
  289. package/build/src/verification/execution.d.ts +51 -0
  290. package/build/src/verification/execution.js +108 -0
  291. package/build/src/workspace-place.d.ts +41 -0
  292. package/build/src/workspace-place.js +386 -0
  293. package/build/src/world.d.ts +24 -0
  294. package/build/src/world.js +136 -0
  295. package/package.json +8 -4
  296. package/build/src/akuma/activity.d.ts +0 -66
  297. package/build/src/akuma/activity.js +0 -139
  298. package/build/src/akuma/providers/claude.js +0 -305
  299. package/build/src/context-root.d.ts +0 -4
  300. package/build/src/context-root.js +0 -15
  301. package/build/src/git/delivery.d.ts +0 -20
  302. package/build/src/git/delivery.js +0 -109
  303. package/build/src/git/verification.d.ts +0 -14
  304. package/build/src/git/verification.js +0 -56
  305. package/build/src/protocol/read/audit.d.ts +0 -25
  306. package/build/src/protocol/read/audit.js +0 -39
  307. package/build/src/verification/producer.d.ts +0 -23
  308. package/build/src/verification/producer.js +0 -54
@@ -0,0 +1,47 @@
1
+ import type { Options, Query, SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
2
+ import { type ProviderAdapter, type Session } from "../../provider.js";
3
+ import type { ProviderOptions } from "../../provider-recipe.js";
4
+ import type { ResumeCoordinate } from "../../provider.js";
5
+ export { CLAUDE_MESSAGE_DISPOSITIONS, CLAUDE_SYSTEM_DISPOSITIONS } from "./events.js";
6
+ type ClaudeExecution = Readonly<{
7
+ executable?: string;
8
+ env?: Readonly<Record<string, string>>;
9
+ }>;
10
+ export type ClaudeSdk = Readonly<{
11
+ query(input: Readonly<{
12
+ prompt: string | AsyncIterable<SDKUserMessage>;
13
+ options?: Options;
14
+ }>): Query;
15
+ forkSession?(sessionId: string, options: Readonly<{
16
+ dir: string;
17
+ upToMessageId: string;
18
+ }>): Promise<Readonly<{
19
+ sessionId: string;
20
+ }>>;
21
+ }>;
22
+ export declare function createClaudeProvider(load: () => Promise<ClaudeSdk>, execution?: ClaudeExecution): ProviderAdapter;
23
+ export declare const claudeProvider: Readonly<{
24
+ confinement(input: Readonly<{
25
+ cwd: string;
26
+ options: ProviderOptions;
27
+ }>): import("../../index.js").Confinement;
28
+ admitOptions(options: ProviderOptions): import("../../provider.js").ProviderOptionAdmission;
29
+ fork?(input: Readonly<{
30
+ session: ResumeCoordinate;
31
+ at: string;
32
+ cwd: string;
33
+ }>): Promise<Readonly<{
34
+ session: ResumeCoordinate;
35
+ }>>;
36
+ start(input: import("../../provider.js").DriveInput & Readonly<{
37
+ session: Readonly<{
38
+ kind: "fresh";
39
+ }>;
40
+ }>): Promise<Session>;
41
+ resume?(input: import("../../provider.js").DriveInput & Readonly<{
42
+ session: Readonly<{
43
+ kind: "resume";
44
+ coordinate: ResumeCoordinate;
45
+ }>;
46
+ }>): Promise<Session>;
47
+ }>;
@@ -0,0 +1,279 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { abortable } from "../../abort.js";
3
+ import { AgentEventChannel, } from "../../provider.js";
4
+ import { emitClaudeMessage, } from "./events.js";
5
+ import { claudeUserMessage, createClaudeInput, isClaudeTurnEnded } from "./input.js";
6
+ export { CLAUDE_MESSAGE_DISPOSITIONS, CLAUDE_SYSTEM_DISPOSITIONS } from "./events.js";
7
+ class ReceiptChannel {
8
+ queued = [];
9
+ waiters = [];
10
+ ended = false;
11
+ emit(receipt) {
12
+ if (this.ended)
13
+ throw new Error("Claude receipt stream already ended");
14
+ const waiter = this.waiters.shift();
15
+ if (waiter === undefined)
16
+ this.queued.push(receipt);
17
+ else
18
+ waiter.resolve({ done: false, value: receipt });
19
+ }
20
+ end() {
21
+ if (this.ended)
22
+ return;
23
+ this.ended = true;
24
+ for (const waiter of this.waiters.splice(0))
25
+ waiter.resolve({ done: true, value: undefined });
26
+ }
27
+ [Symbol.asyncIterator]() {
28
+ return {
29
+ next: () => {
30
+ const receipt = this.queued.shift();
31
+ if (receipt !== undefined)
32
+ return Promise.resolve({ done: false, value: receipt });
33
+ if (this.ended)
34
+ return Promise.resolve({ done: true, value: undefined });
35
+ return new Promise((resolve) => this.waiters.push({ resolve }));
36
+ },
37
+ };
38
+ }
39
+ }
40
+ function admitClaudeOptions(options) {
41
+ if (options.network !== undefined) {
42
+ return { kind: "refused", diagnostic: "Claude provider does not support the network option" };
43
+ }
44
+ return {
45
+ kind: "admitted",
46
+ options: Object.freeze({ ...options }),
47
+ ...(options.readonly === undefined ? {} : { readonly: { enforcement: "native" } }),
48
+ };
49
+ }
50
+ function permissionMode(readonly) {
51
+ return readonly === true ? "plan" : "bypassPermissions";
52
+ }
53
+ function claudeSessionId(coordinate) {
54
+ if (!("sessionId" in coordinate) || coordinate.sessionId === undefined) {
55
+ throw new Error("Claude resume requires sessionId");
56
+ }
57
+ return coordinate.sessionId;
58
+ }
59
+ function claudeQueryOptions(input, execution, abortController) {
60
+ const mode = permissionMode(input.options.readonly);
61
+ return {
62
+ cwd: input.cwd,
63
+ abortController,
64
+ ...(execution.executable === undefined ? {} : { pathToClaudeCodeExecutable: execution.executable }),
65
+ ...(execution.env === undefined ? {} : { env: { ...process.env, ...execution.env } }),
66
+ permissionMode: mode,
67
+ ...(mode === "bypassPermissions" ? { allowDangerouslySkipPermissions: true } : {}),
68
+ settingSources: ["user", "project", "local"],
69
+ ...(input.options.model === undefined ? {} : { model: input.options.model }),
70
+ ...(input.options.effort === undefined ? {} : { effort: input.options.effort }),
71
+ ...(input.options.systemPrompt === undefined || input.options.systemPrompt.length === 0 ? {} : {
72
+ systemPrompt: { type: "preset", preset: "claude_code", append: input.options.systemPrompt },
73
+ }),
74
+ ...(input.session.kind === "fresh" ? {} : { resume: claudeSessionId(input.session.coordinate) }),
75
+ };
76
+ }
77
+ async function forkClaude(load, execution, input) {
78
+ const sessionId = claudeSessionId(input.session);
79
+ if (execution.env !== undefined)
80
+ throw new Error("Claude fork cannot apply the frozen provider environment");
81
+ const sdk = await load();
82
+ if (sdk.forkSession === undefined)
83
+ throw new Error("Claude SDK does not expose forkSession");
84
+ const forked = await sdk.forkSession(sessionId, { dir: input.cwd, upToMessageId: input.at });
85
+ if (forked.sessionId.trim().length === 0)
86
+ throw new Error("Claude fork returned an empty child session id");
87
+ if (forked.sessionId === sessionId)
88
+ throw new Error("Claude fork reused the source session id");
89
+ return { session: { sessionId: forked.sessionId } };
90
+ }
91
+ function launchText(input) {
92
+ return [input.body, ...input.launchTells.map((tell) => tell.text)]
93
+ .filter((part) => part.length > 0).join("\n\n");
94
+ }
95
+ function successfulResult(message, historyId) {
96
+ return {
97
+ kind: "answered",
98
+ answer: message.subtype === "success" ? message.result : "",
99
+ ...(historyId === undefined ? {} : { historyId }),
100
+ };
101
+ }
102
+ function finishClaudeInput(input, terminal) {
103
+ if (terminal?.kind === "answered")
104
+ input.end();
105
+ else
106
+ input.close();
107
+ }
108
+ function observeClaudeQuery(context) {
109
+ const { query, input, events, receipts, accepted, state } = context;
110
+ const observation = { tools: new Map() };
111
+ let admit;
112
+ let rejectAdmission;
113
+ const admission = new Promise((resolve, reject) => { admit = resolve; rejectAdmission = reject; });
114
+ let settle;
115
+ const completion = new Promise((resolve) => { settle = resolve; });
116
+ let checkpoint = 0, ended = false;
117
+ const settleReceipts = () => {
118
+ if (ended && state.openSubmissions === 0 && accepted.every((tell) => tell.visible))
119
+ receipts.end();
120
+ };
121
+ const flushReceipts = () => {
122
+ for (let index = 0; index < accepted.length;) {
123
+ const tell = accepted[index];
124
+ if (!tell.visible || tell.afterCheckpoint >= checkpoint) {
125
+ index += 1;
126
+ continue;
127
+ }
128
+ accepted.splice(index, 1);
129
+ receipts.emit({ evidence: "exact", tellId: tell.id, kind: "consumed" });
130
+ }
131
+ closeWhenIdle();
132
+ settleReceipts();
133
+ };
134
+ const closeWhenIdle = () => {
135
+ if (state.openSubmissions === 0 && accepted.length === 0 && input.pending === 0)
136
+ input.close();
137
+ };
138
+ void (async () => {
139
+ let admitted = false;
140
+ let terminal = null;
141
+ let historyId;
142
+ try {
143
+ for await (const message of query) {
144
+ if (!admitted && "session_id" in message && typeof message.session_id === "string") {
145
+ admitted = true;
146
+ events.emit({ type: "session", coordinate: { sessionId: message.session_id } });
147
+ admit();
148
+ }
149
+ emitClaudeMessage(message, events, observation);
150
+ if (message.type === "assistant" && message.parent_tool_use_id === null
151
+ && typeof message.uuid === "string" && message.uuid.length > 0)
152
+ historyId = message.uuid;
153
+ if (message.type !== "result")
154
+ continue;
155
+ if (message.subtype === "success") {
156
+ terminal = successfulResult(message, historyId);
157
+ checkpoint += 1;
158
+ flushReceipts();
159
+ queueMicrotask(closeWhenIdle);
160
+ }
161
+ else {
162
+ terminal = { kind: "failed", diagnostic: message.errors.join("; ") || message.subtype };
163
+ input.close();
164
+ }
165
+ }
166
+ ended = true;
167
+ const result = terminal ?? { kind: "failed", diagnostic: "Claude query ended without a result" };
168
+ if (!admitted)
169
+ rejectAdmission(new Error(result.kind === "failed" ? result.diagnostic : "Claude query ended before session admission"));
170
+ settle(result);
171
+ }
172
+ catch (error) {
173
+ ended = true;
174
+ input.fail(error);
175
+ const failure = error instanceof Error ? error : new Error(String(error));
176
+ if (!admitted)
177
+ rejectAdmission(failure);
178
+ settle({ kind: "failed", diagnostic: failure.message });
179
+ }
180
+ finally {
181
+ finishClaudeInput(input, terminal);
182
+ events.end();
183
+ settleReceipts();
184
+ }
185
+ })();
186
+ return {
187
+ admission,
188
+ completion,
189
+ get ended() { return ended; },
190
+ get checkpoint() { return checkpoint; },
191
+ flushReceipts,
192
+ settleReceipts,
193
+ };
194
+ }
195
+ async function driveClaude(load, execution, drive) {
196
+ if (drive.session.kind === "resume")
197
+ claudeSessionId(drive.session.coordinate);
198
+ const signal = drive.signal ?? new AbortController().signal;
199
+ signal.throwIfAborted();
200
+ const sdk = await abortable(load(), signal);
201
+ signal.throwIfAborted();
202
+ const events = new AgentEventChannel();
203
+ const receipts = new ReceiptChannel();
204
+ const input = createClaudeInput();
205
+ const abortController = new AbortController();
206
+ const run = randomUUID();
207
+ const accepted = [];
208
+ let submission = 0;
209
+ let openSubmissions = 0;
210
+ const launchAcknowledged = input.push(claudeUserMessage(launchText(drive)));
211
+ const query = sdk.query({
212
+ prompt: input.iterable,
213
+ options: claudeQueryOptions(drive, execution, abortController),
214
+ });
215
+ const shutDown = (error) => {
216
+ abortController.abort(error);
217
+ input.fail(error);
218
+ query.close();
219
+ };
220
+ const abortSetup = () => shutDown(signal.reason);
221
+ signal.addEventListener("abort", abortSetup, { once: true });
222
+ const observed = observeClaudeQuery({
223
+ query, input, events, receipts, accepted,
224
+ state: { get openSubmissions() { return openSubmissions; } },
225
+ });
226
+ try {
227
+ await Promise.all([launchAcknowledged, observed.admission]);
228
+ }
229
+ finally {
230
+ signal.removeEventListener("abort", abortSetup);
231
+ }
232
+ return {
233
+ admission: { fence: `claude:${run}:0` },
234
+ events,
235
+ receipts,
236
+ completion: observed.completion,
237
+ tell(tell) {
238
+ if (observed.ended || input.closed)
239
+ return Promise.resolve({ kind: "turn-ended" });
240
+ openSubmissions += 1;
241
+ const ordinal = ++submission;
242
+ return new Promise((resolve, reject) => {
243
+ const pending = { id: tell.id, afterCheckpoint: 0, visible: false };
244
+ void input.push(claudeUserMessage(tell.text), () => {
245
+ pending.afterCheckpoint = observed.checkpoint;
246
+ accepted.push(pending);
247
+ }).then(() => {
248
+ openSubmissions -= 1;
249
+ resolve({ kind: "accepted", fence: `claude:${run}:${ordinal}` });
250
+ queueMicrotask(() => {
251
+ pending.visible = true;
252
+ observed.flushReceipts();
253
+ observed.settleReceipts();
254
+ });
255
+ }, (error) => {
256
+ openSubmissions -= 1;
257
+ if (isClaudeTurnEnded(error))
258
+ resolve({ kind: "turn-ended" });
259
+ else
260
+ reject(error);
261
+ observed.settleReceipts();
262
+ });
263
+ });
264
+ },
265
+ async abort() {
266
+ shutDown(new Error("Claude query aborted"));
267
+ },
268
+ };
269
+ }
270
+ export function createClaudeProvider(load, execution = {}) {
271
+ return {
272
+ confinement: () => ({ kind: "unconfined" }),
273
+ admitOptions: admitClaudeOptions,
274
+ fork: (input) => forkClaude(load, execution, input),
275
+ start: (input) => driveClaude(load, execution, input),
276
+ resume: (input) => driveClaude(load, execution, input),
277
+ };
278
+ }
279
+ export const claudeProvider = createClaudeProvider(async () => await import("@anthropic-ai/claude-agent-sdk"));
@@ -0,0 +1,13 @@
1
+ import type { SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
2
+ export declare function isClaudeTurnEnded(error: unknown): boolean;
3
+ export type ClaudeInput = Readonly<{
4
+ iterable: AsyncIterable<SDKUserMessage>;
5
+ get closed(): boolean;
6
+ get pending(): number;
7
+ push(message: SDKUserMessage, onPulled?: () => void): Promise<void>;
8
+ end(): void;
9
+ close(): void;
10
+ fail(error: unknown): void;
11
+ }>;
12
+ export declare function claudeUserMessage(text: string): SDKUserMessage;
13
+ export declare function createClaudeInput(): ClaudeInput;
@@ -0,0 +1,109 @@
1
+ function deferred() {
2
+ let resolve;
3
+ let reject;
4
+ const promise = new Promise((accept, refuse) => {
5
+ resolve = accept;
6
+ reject = refuse;
7
+ });
8
+ return { promise, resolve, reject };
9
+ }
10
+ function ended() {
11
+ return new Error("Claude input ended before the SDK acknowledged the message");
12
+ }
13
+ const turnEnded = Symbol("claude-turn-ended");
14
+ class ClaudeTurnEndedError extends Error {
15
+ [turnEnded] = true;
16
+ }
17
+ function turnEndedError() {
18
+ return new ClaudeTurnEndedError("Claude query ended before the SDK acknowledged the message");
19
+ }
20
+ export function isClaudeTurnEnded(error) {
21
+ return typeof error === "object" && error !== null && error[turnEnded] === true;
22
+ }
23
+ export function claudeUserMessage(text) {
24
+ return {
25
+ type: "user",
26
+ message: { role: "user", content: text },
27
+ parent_tool_use_id: null,
28
+ };
29
+ }
30
+ export function createClaudeInput() {
31
+ const queue = [];
32
+ const waiters = [];
33
+ let previous;
34
+ let failure;
35
+ let closed = false;
36
+ const acknowledgePrevious = () => {
37
+ previous?.onPulled?.();
38
+ previous?.pulled.resolve();
39
+ previous = undefined;
40
+ };
41
+ const take = (entry) => {
42
+ previous = entry;
43
+ return { done: false, value: entry.message };
44
+ };
45
+ const rejectUnresolved = (error) => {
46
+ previous?.pulled.reject(error);
47
+ previous = undefined;
48
+ for (const entry of queue.splice(0))
49
+ entry.pulled.reject(error);
50
+ };
51
+ return {
52
+ get closed() { return closed; },
53
+ get pending() { return queue.length + (previous === undefined ? 0 : 1); },
54
+ push(message, onPulled) {
55
+ if (closed)
56
+ return Promise.reject(failure ?? ended());
57
+ const entry = { message, pulled: deferred(), ...(onPulled === undefined ? {} : { onPulled }) };
58
+ const waiter = waiters.shift();
59
+ if (waiter === undefined)
60
+ queue.push(entry);
61
+ else
62
+ waiter.resolve(take(entry));
63
+ return entry.pulled.promise;
64
+ },
65
+ end() {
66
+ if (closed)
67
+ return;
68
+ closed = true;
69
+ rejectUnresolved(turnEndedError());
70
+ for (const waiter of waiters.splice(0))
71
+ waiter.resolve({ done: true, value: undefined });
72
+ },
73
+ close() {
74
+ if (closed)
75
+ return;
76
+ closed = true;
77
+ const error = ended();
78
+ rejectUnresolved(error);
79
+ for (const waiter of waiters.splice(0))
80
+ waiter.resolve({ done: true, value: undefined });
81
+ },
82
+ fail(error) {
83
+ if (closed)
84
+ return;
85
+ closed = true;
86
+ failure = error;
87
+ rejectUnresolved(error);
88
+ for (const waiter of waiters.splice(0))
89
+ waiter.reject(error);
90
+ },
91
+ iterable: {
92
+ [Symbol.asyncIterator]() {
93
+ return {
94
+ next() {
95
+ acknowledgePrevious();
96
+ const entry = queue.shift();
97
+ if (entry !== undefined)
98
+ return Promise.resolve(take(entry));
99
+ if (failure !== undefined)
100
+ return Promise.reject(failure);
101
+ if (closed)
102
+ return Promise.resolve({ done: true, value: undefined });
103
+ return new Promise((resolve, reject) => waiters.push({ resolve, reject }));
104
+ },
105
+ };
106
+ },
107
+ },
108
+ };
109
+ }
@@ -3,7 +3,7 @@ import { AgentEventChannel, type ToolCall, type TurnResult } from "../../provide
3
3
  export type CodexTurnState = {
4
4
  threadId?: string;
5
5
  turnId?: string;
6
- answers: string[];
6
+ lastAnswer?: string;
7
7
  error?: string;
8
8
  settled: boolean;
9
9
  tools: Map<string, Readonly<{
@@ -1,4 +1,4 @@
1
- import { boundedEventText, boundedThoughtText, noteEvent, unknownEvent, } from "../../provider.js";
1
+ import { noteEvent, unknownEvent, } from "../../provider.js";
2
2
  export const CODEX_NOTIFICATION_DISPOSITIONS = {
3
3
  "account/login/completed": "drop",
4
4
  "account/rateLimits/updated": "drop",
@@ -160,7 +160,7 @@ function itemChanges(item) {
160
160
  const diffstat = typeof change?.diff === "string" ? diffstatFromUnifiedPatch(change.diff) : undefined;
161
161
  return [{
162
162
  op,
163
- path: boundedEventText(path),
163
+ path,
164
164
  ...(diffstat === undefined ? {} : { diffstat }),
165
165
  }];
166
166
  });
@@ -179,20 +179,23 @@ function reasoningSummary(item) {
179
179
  }
180
180
  function itemToolCall(item, kind) {
181
181
  if (kind === "commandExecution") {
182
- return { kind: "run", command: boundedEventText(codexText(item.command) ?? "command") };
182
+ return { kind: "run", command: codexText(item.command) ?? "command" };
183
183
  }
184
184
  if (kind === "imageView") {
185
185
  const path = codexText(item.path);
186
- return path === undefined ? { kind: "other", display: "image view" } : { kind: "read", path: boundedEventText(path) };
186
+ return path === undefined ? { kind: "other", display: "image view" } : { kind: "read", path };
187
187
  }
188
188
  if (kind === "webSearch") {
189
- return { kind: "search", query: boundedEventText(codexText(item.query) ?? "web search") };
189
+ const query = codexText(item.query);
190
+ return query === undefined
191
+ ? { kind: "other", display: "web search" }
192
+ : { kind: "search", query, scope: "web" };
190
193
  }
191
194
  if (kind === "fileChange") {
192
195
  const changes = itemChanges(item);
193
196
  return changes.length === 0 ? { kind: "other", display: "fileChange" } : { kind: "fileChange", changes };
194
197
  }
195
- return { kind: "other", display: boundedEventText(itemToolName(item, kind)) };
198
+ return { kind: "other", display: itemToolName(item, kind) };
196
199
  }
197
200
  function itemToolResult(item) {
198
201
  const error = codexObject(item.error);
@@ -202,7 +205,7 @@ function itemToolResult(item) {
202
205
  const exitCode = typeof item.exitCode === "number" && Number.isSafeInteger(item.exitCode) ? item.exitCode : undefined;
203
206
  return {
204
207
  status: failed || (exitCode !== undefined && exitCode !== 0) ? "error" : "ok",
205
- ...(detail === undefined ? {} : { message: boundedEventText(detail) }),
208
+ ...(detail === undefined ? {} : { message: detail }),
206
209
  ...(exitCode === undefined ? {} : { exitCode }),
207
210
  };
208
211
  }
@@ -216,10 +219,10 @@ function emitItem(item, completed, events, state) {
216
219
  if (disposition === "assistant") {
217
220
  if (!completed)
218
221
  return;
219
- const message = codexText(item.text);
222
+ const message = typeof item.text === "string" ? item.text : undefined;
220
223
  if (message !== undefined) {
221
- state.answers.push(message);
222
- events.emit({ type: "assistant", text: boundedEventText(message) });
224
+ state.lastAnswer = message;
225
+ events.emit({ type: "assistant", text: message });
223
226
  }
224
227
  return;
225
228
  }
@@ -233,7 +236,7 @@ function emitItem(item, completed, events, state) {
233
236
  return;
234
237
  const summary = reasoningSummary(item);
235
238
  if (summary !== undefined)
236
- events.emit({ type: "thought", text: boundedThoughtText(summary) });
239
+ events.emit({ type: "thought", text: summary });
237
240
  return;
238
241
  }
239
242
  if (disposition === "note") {
@@ -300,7 +303,7 @@ function terminalResult(params, state) {
300
303
  return { kind: "failed", diagnostic: "codex app-server completed a different turn" };
301
304
  }
302
305
  return status === "completed"
303
- ? { kind: "answered", answer: state.answers.join("\n\n"), historyId: completedId }
306
+ ? { kind: "answered", answer: state.lastAnswer ?? "", historyId: completedId }
304
307
  : { kind: "failed", diagnostic: turnError(turn?.error) ?? state.error ?? `codex app-server turn ended ${status}` };
305
308
  }
306
309
  export function codexNotificationResult(notification, state, events) {
@@ -1,27 +1,29 @@
1
- import { type Drive, type ProviderAdapter, type ProviderOptions } from "../../provider.js";
2
- import type { ProviderExecution } from "../../heart/index.js";
1
+ import { type Session, type ProviderAdapter } from "../../provider.js";
2
+ import type { ProviderExecution, ProviderOptions } from "../../provider-recipe.js";
3
3
  export { CODEX_ITEM_DISPOSITIONS, CODEX_NOTIFICATION_DISPOSITIONS } from "./events.js";
4
4
  export declare function createCodexAppServerProvider(input?: string | ProviderExecution): ProviderAdapter;
5
5
  export declare const codexAppServerProvider: Readonly<{
6
6
  confinement(input: Readonly<{
7
7
  cwd: string;
8
8
  options: ProviderOptions;
9
- }>): import("../../heart/facts.js").Confinement;
9
+ }>): import("../../index.js").Confinement;
10
10
  admitOptions(options: ProviderOptions): import("../../provider.js").ProviderOptionAdmission;
11
11
  fork?(input: Readonly<{
12
- session: import("../../provider.js").ResumeCoordinate;
12
+ session: import("../../coordinate.js").ResumeCoordinate;
13
13
  at: string;
14
14
  cwd: string;
15
15
  }>): Promise<Readonly<{
16
- session: import("../../provider.js").ResumeCoordinate;
16
+ session: import("../../coordinate.js").ResumeCoordinate;
17
17
  }>>;
18
- start(input: Readonly<{
19
- prompt: string;
20
- cwd: string;
21
- options: ProviderOptions;
22
- session?: import("../../provider.js").ResumeCoordinate;
23
- requests?: Readonly<{
24
- dir: string;
18
+ start(input: import("../../provider.js").DriveInput & Readonly<{
19
+ session: Readonly<{
20
+ kind: "fresh";
21
+ }>;
22
+ }>): Promise<Session>;
23
+ resume?(input: import("../../provider.js").DriveInput & Readonly<{
24
+ session: Readonly<{
25
+ kind: "resume";
26
+ coordinate: import("../../coordinate.js").ResumeCoordinate;
25
27
  }>;
26
- }>): Promise<Drive>;
28
+ }>): Promise<Session>;
27
29
  }>;