@astrosheep/keiyaku 4.6.30 → 4.6.31

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 (398) hide show
  1. package/README.md +5 -5
  2. package/build/plugins/claude/.claude-plugin/plugin.json +1 -1
  3. package/build/plugins/claude/skills/keiyaku/SKILL.md +12 -12
  4. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +16 -16
  5. package/build/plugins/claude/skills/keiyaku-akuma/references/automation.md +14 -14
  6. package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +10 -10
  7. package/build/plugins/claude/skills/keiyaku-bind/SKILL.md +15 -15
  8. package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +16 -16
  9. package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +21 -21
  10. package/build/plugins/codex/.codex-plugin/plugin.json +1 -1
  11. package/build/plugins/codex/skills/keiyaku/SKILL.md +12 -12
  12. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +16 -16
  13. package/build/plugins/codex/skills/keiyaku-akuma/references/automation.md +14 -14
  14. package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +10 -10
  15. package/build/plugins/codex/skills/keiyaku-bind/SKILL.md +15 -15
  16. package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +16 -16
  17. package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +21 -21
  18. package/build/plugins/opencode/package.json +1 -1
  19. package/build/plugins/opencode/skills/keiyaku/SKILL.md +12 -12
  20. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +16 -16
  21. package/build/plugins/opencode/skills/keiyaku-akuma/references/automation.md +14 -14
  22. package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +10 -10
  23. package/build/plugins/opencode/skills/keiyaku-bind/SKILL.md +15 -15
  24. package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +16 -16
  25. package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +21 -21
  26. package/build/plugins/pi/README.md +5 -5
  27. package/build/plugins/pi/akuma-tools.ts +17 -23
  28. package/build/skills/keiyaku/SKILL.md +12 -12
  29. package/build/skills/keiyaku-akuma/SKILL.md +16 -16
  30. package/build/skills/keiyaku-akuma/references/automation.md +14 -14
  31. package/build/skills/keiyaku-babysit/SKILL.md +10 -10
  32. package/build/skills/keiyaku-bind/SKILL.md +15 -15
  33. package/build/skills/keiyaku-debt/SKILL.md +16 -16
  34. package/build/skills/keiyaku-workflow/SKILL.md +21 -21
  35. package/build/src/akuma/akuma-call.d.ts +1 -1
  36. package/build/src/akuma/akuma-call.js +9 -9
  37. package/build/src/akuma/akuma-errors.d.ts +5 -5
  38. package/build/src/akuma/akuma-instance.d.ts +355 -12
  39. package/build/src/akuma/akuma-instance.js +20 -20
  40. package/build/src/akuma/akuma-observe.d.ts +11 -12
  41. package/build/src/akuma/akuma-observe.js +34 -26
  42. package/build/src/akuma/akuma-owner.d.ts +32 -11
  43. package/build/src/akuma/akuma-owner.js +35 -16
  44. package/build/src/akuma/akuma-probe.d.ts +3 -3
  45. package/build/src/akuma/akuma-probe.js +2 -2
  46. package/build/src/akuma/akuma-selection-execution.d.ts +985 -1
  47. package/build/src/akuma/akuma-selection-execution.js +42 -18
  48. package/build/src/akuma/akuma-stream.d.ts +2 -2
  49. package/build/src/akuma/akuma-stream.js +1 -1
  50. package/build/src/akuma/akuma-wait.d.ts +5 -5
  51. package/build/src/akuma/akuma-wait.js +52 -14
  52. package/build/src/akuma/akuma.d.ts +245 -271
  53. package/build/src/akuma/akuma.js +98 -46
  54. package/build/src/akuma/archetype.d.ts +19 -6
  55. package/build/src/akuma/archetype.js +25 -9
  56. package/build/src/akuma/body-launch.d.ts +2 -2
  57. package/build/src/akuma/body.js +4 -4
  58. package/build/src/akuma/call-initial-tell.d.ts +60 -44
  59. package/build/src/akuma/call-initial-tell.js +41 -2
  60. package/build/src/akuma/caller.d.ts +26 -17
  61. package/build/src/akuma/caller.js +22 -9
  62. package/build/src/akuma/coordinate.d.ts +9 -0
  63. package/build/src/akuma/coordinate.js +13 -0
  64. package/build/src/akuma/detached-body.js +2 -2
  65. package/build/src/akuma/dispatch-association.d.ts +4 -4
  66. package/build/src/akuma/dispatch-association.js +12 -3
  67. package/build/src/akuma/execution-instructions.js +2 -2
  68. package/build/src/akuma/heart/facts.d.ts +29 -7
  69. package/build/src/akuma/heart/facts.js +13 -0
  70. package/build/src/akuma/heart/index.d.ts +0 -3
  71. package/build/src/akuma/heart/index.js +3 -6
  72. package/build/src/akuma/heart/rows.js +2 -2
  73. package/build/src/akuma/heart/soul.js +5 -5
  74. package/build/src/akuma/identity.d.ts +17 -16
  75. package/build/src/akuma/identity.js +20 -19
  76. package/build/src/akuma/index.d.ts +1 -2
  77. package/build/src/akuma/lineage-cache.d.ts +4 -4
  78. package/build/src/akuma/lineage-cache.js +10 -10
  79. package/build/src/akuma/projection-read.d.ts +2 -5
  80. package/build/src/akuma/projection-read.js +34 -47
  81. package/build/src/akuma/projection.d.ts +659 -569
  82. package/build/src/akuma/projection.js +203 -94
  83. package/build/src/akuma/providers/acp/index.js +1 -1
  84. package/build/src/akuma/providers/execution-environment.d.ts +1 -3
  85. package/build/src/akuma/providers/execution-environment.js +0 -4
  86. package/build/src/akuma/publication.d.ts +2 -2
  87. package/build/src/akuma/publication.js +3 -3
  88. package/build/src/akuma/retention.js +2 -2
  89. package/build/src/akuma/selection-observation.d.ts +507 -43
  90. package/build/src/akuma/selection-observation.js +153 -1
  91. package/build/src/akuma/status-projection.d.ts +288 -0
  92. package/build/src/akuma/status-projection.js +154 -0
  93. package/build/src/akuma/turn-drive.js +0 -3
  94. package/build/src/alias/index.d.ts +9 -4
  95. package/build/src/alias/index.js +11 -9
  96. package/build/src/bounded-list.d.ts +8 -0
  97. package/build/src/bounded-list.js +9 -0
  98. package/build/src/cli/commands/akuma-grammar.d.ts +2 -2
  99. package/build/src/cli/commands/akuma-grammar.js +21 -21
  100. package/build/src/cli/commands/akuma.d.ts +1 -2
  101. package/build/src/cli/commands/akuma.js +115 -251
  102. package/build/src/cli/commands/contract-grammar.d.ts +4 -3
  103. package/build/src/cli/commands/contract-grammar.js +39 -22
  104. package/build/src/cli/commands/contract-help.d.ts +3 -1
  105. package/build/src/cli/commands/contract-help.js +4 -3
  106. package/build/src/cli/commands/contract.d.ts +6 -3
  107. package/build/src/cli/commands/contract.js +203 -434
  108. package/build/src/cli/commands/debt.d.ts +2 -3
  109. package/build/src/cli/commands/debt.js +101 -317
  110. package/build/src/cli/commands/report.js +11 -28
  111. package/build/src/cli/commands/whoami.d.ts +3 -43
  112. package/build/src/cli/commands/whoami.js +8 -121
  113. package/build/src/cli/coordinates.d.ts +4 -35
  114. package/build/src/cli/coordinates.js +13 -129
  115. package/build/src/cli/parse.d.ts +0 -6
  116. package/build/src/cli/parse.js +5 -48
  117. package/build/src/cli/render/akuma-activity.d.ts +31 -16
  118. package/build/src/cli/render/akuma-activity.js +157 -149
  119. package/build/src/cli/render/akuma-tool.d.ts +3 -6
  120. package/build/src/cli/render/akuma-tool.js +20 -14
  121. package/build/src/cli/render/akuma.d.ts +25 -26
  122. package/build/src/cli/render/akuma.js +100 -129
  123. package/build/src/cli/render/catalog.d.ts +4 -7
  124. package/build/src/cli/render/catalog.js +52 -99
  125. package/build/src/cli/render/contract-history.d.ts +3 -1
  126. package/build/src/cli/render/contract-history.js +140 -215
  127. package/build/src/cli/render/contract-observation.d.ts +43 -30
  128. package/build/src/cli/render/contract-observation.js +64 -31
  129. package/build/src/cli/render/contract-wait.js +6 -6
  130. package/build/src/cli/render/contract.d.ts +41 -6
  131. package/build/src/cli/render/contract.js +274 -370
  132. package/build/src/cli/render/debt.d.ts +9 -19
  133. package/build/src/cli/render/debt.js +120 -185
  134. package/build/src/cli/render/delivery-preview.d.ts +4 -3
  135. package/build/src/cli/render/delivery-preview.js +68 -96
  136. package/build/src/cli/render/kanshi-akuma.d.ts +4 -4
  137. package/build/src/cli/render/kanshi-akuma.js +70 -59
  138. package/build/src/cli/render/kanshi.d.ts +4 -4
  139. package/build/src/cli/render/kanshi.js +205 -221
  140. package/build/src/cli/render/marks.d.ts +11 -2
  141. package/build/src/cli/render/marks.js +13 -3
  142. package/build/src/cli/render/nuke.d.ts +3 -3
  143. package/build/src/cli/render/nuke.js +13 -16
  144. package/build/src/cli/render/receipt.d.ts +37 -43
  145. package/build/src/cli/render/receipt.js +313 -236
  146. package/build/src/cli/render/reconcile.d.ts +6 -4
  147. package/build/src/cli/render/reconcile.js +53 -137
  148. package/build/src/cli/render/refusal.d.ts +3 -2
  149. package/build/src/cli/render/refusal.js +73 -54
  150. package/build/src/cli/render/region.d.ts +11 -2
  151. package/build/src/cli/render/region.js +17 -23
  152. package/build/src/cli/render/settings.d.ts +0 -1
  153. package/build/src/cli/render/settings.js +8 -17
  154. package/build/src/cli/render/terminal.d.ts +2 -0
  155. package/build/src/cli/render/verbs.d.ts +4 -0
  156. package/build/src/cli/render/verbs.js +312 -0
  157. package/build/src/cli/render/whoami.d.ts +1 -1
  158. package/build/src/cli/render/whoami.js +24 -31
  159. package/build/src/cli/runtime.d.ts +3 -11
  160. package/build/src/cli/runtime.js +96 -79
  161. package/build/src/cli/scan.d.ts +1 -1
  162. package/build/src/cli/streams.js +1 -0
  163. package/build/src/contract-guidance.js +2 -2
  164. package/build/src/contract-worktree.d.ts +2 -15
  165. package/build/src/contract-worktree.js +19 -35
  166. package/build/src/core/facts/observation.d.ts +4 -5
  167. package/build/src/core/facts/observation.js +7 -9
  168. package/build/src/core/verbs/amend.d.ts +0 -1
  169. package/build/src/core/verbs/amend.js +3 -3
  170. package/build/src/core/verbs/bind.d.ts +0 -1
  171. package/build/src/core/verbs/bind.js +5 -5
  172. package/build/src/core/verbs/deliver.d.ts +3 -2
  173. package/build/src/core/verbs/deliver.js +2 -2
  174. package/build/src/core/verbs/placement.d.ts +0 -5
  175. package/build/src/core/verbs/placement.js +4 -6
  176. package/build/src/core/verbs/reintegrate.d.ts +0 -1
  177. package/build/src/core/verbs/reintegrate.js +2 -2
  178. package/build/src/debt/board.d.ts +132 -116
  179. package/build/src/debt/board.js +138 -94
  180. package/build/src/debt/catalog.d.ts +4 -4
  181. package/build/src/debt/catalog.js +2 -18
  182. package/build/src/debt/context.d.ts +15 -3
  183. package/build/src/debt/context.js +12 -1
  184. package/build/src/debt/created-observation.d.ts +5 -17
  185. package/build/src/debt/created-observation.js +14 -6
  186. package/build/src/debt/document.d.ts +20 -15
  187. package/build/src/debt/document.js +18 -1
  188. package/build/src/debt/index.d.ts +346 -23
  189. package/build/src/debt/index.js +68 -22
  190. package/build/src/debt/input.d.ts +2 -1
  191. package/build/src/debt/input.js +14 -0
  192. package/build/src/debt/lifecycle-operations.d.ts +2 -2
  193. package/build/src/debt/lifecycle-operations.js +14 -22
  194. package/build/src/debt/operation-types.d.ts +188 -66
  195. package/build/src/debt/operation-types.js +113 -1
  196. package/build/src/debt/operations.d.ts +11 -10
  197. package/build/src/debt/operations.js +46 -71
  198. package/build/src/debt/query.d.ts +14 -10
  199. package/build/src/debt/query.js +3 -12
  200. package/build/src/debt/store.d.ts +4 -2
  201. package/build/src/debt/store.js +8 -8
  202. package/build/src/debt/view.d.ts +0 -3
  203. package/build/src/debt/view.js +0 -4
  204. package/build/src/dispatch/index.d.ts +22 -5
  205. package/build/src/dispatch/index.js +46 -37
  206. package/build/src/git/admission.d.ts +2 -2
  207. package/build/src/git/admission.js +2 -1
  208. package/build/src/git/hooks.d.ts +14 -35
  209. package/build/src/git/hooks.js +45 -25
  210. package/build/src/git/integration.d.ts +6 -24
  211. package/build/src/git/integration.js +10 -16
  212. package/build/src/git/private-state-seat.d.ts +2 -2
  213. package/build/src/git/private-state-seat.js +2 -1
  214. package/build/src/git/reconcile.d.ts +17 -79
  215. package/build/src/git/reconcile.js +37 -52
  216. package/build/src/git/scratch.d.ts +3 -3
  217. package/build/src/git/scratch.js +4 -1
  218. package/build/src/git/target-placement.d.ts +23 -31
  219. package/build/src/git/target-placement.js +42 -27
  220. package/build/src/git/target.d.ts +2 -2
  221. package/build/src/git/target.js +2 -1
  222. package/build/src/git/tender.d.ts +7 -39
  223. package/build/src/git/tender.js +21 -54
  224. package/build/src/git/terminal-reconcile.js +15 -18
  225. package/build/src/git/terminal-seal.d.ts +2 -4
  226. package/build/src/git/terminal-seal.js +7 -33
  227. package/build/src/git/workspace.d.ts +65 -41
  228. package/build/src/git/workspace.js +45 -14
  229. package/build/src/identity/selector.d.ts +2 -0
  230. package/build/src/identity/selector.js +13 -3
  231. package/build/src/index.d.ts +48 -54
  232. package/build/src/index.js +31 -43
  233. package/build/src/kanshi/counts.d.ts +42 -8
  234. package/build/src/kanshi/counts.js +13 -2
  235. package/build/src/kanshi/index.d.ts +5 -5
  236. package/build/src/kanshi/index.js +4 -3
  237. package/build/src/kanshi/read.d.ts +489 -6
  238. package/build/src/kanshi/read.js +334 -483
  239. package/build/src/kanshi/report.d.ts +2504 -103
  240. package/build/src/kanshi/report.js +165 -1
  241. package/build/src/kanshi/select.d.ts +0 -8
  242. package/build/src/kanshi/select.js +20 -59
  243. package/build/src/library/address.d.ts +8 -8
  244. package/build/src/library/address.js +7 -7
  245. package/build/src/library/akuma-creation.d.ts +690 -84
  246. package/build/src/library/akuma-creation.js +202 -142
  247. package/build/src/library/akuma-retention.d.ts +2 -2
  248. package/build/src/library/akuma-retention.js +2 -2
  249. package/build/src/library/akumas.d.ts +10 -6
  250. package/build/src/library/akumas.js +24 -7
  251. package/build/src/library/bind.d.ts +28 -54
  252. package/build/src/library/bind.js +6 -4
  253. package/build/src/library/continuation.d.ts +197 -479
  254. package/build/src/library/continuation.js +40 -23
  255. package/build/src/library/contract-address.d.ts +6 -5
  256. package/build/src/library/contract-address.js +5 -7
  257. package/build/src/library/contract-composition.d.ts +18 -12
  258. package/build/src/library/contract-composition.js +55 -47
  259. package/build/src/library/contract-creation.d.ts +3 -2
  260. package/build/src/library/contract-creation.js +38 -32
  261. package/build/src/library/contract-execution.js +77 -38
  262. package/build/src/library/contract-outcomes.d.ts +1877 -27
  263. package/build/src/library/contract-outcomes.js +93 -10
  264. package/build/src/library/contract-settings.d.ts +2 -2
  265. package/build/src/library/contract-settings.js +18 -14
  266. package/build/src/library/contract-types.d.ts +238 -61
  267. package/build/src/library/contract-types.js +131 -1
  268. package/build/src/library/contract-wait.d.ts +38 -17
  269. package/build/src/library/contract-wait.js +40 -10
  270. package/build/src/library/delivery.d.ts +588 -36
  271. package/build/src/library/delivery.js +35 -27
  272. package/build/src/library/input.d.ts +1 -1
  273. package/build/src/library/input.js +1 -2
  274. package/build/src/library/invocation.d.ts +11 -7
  275. package/build/src/library/invocation.js +42 -51
  276. package/build/src/library/kei.d.ts +48 -0
  277. package/build/src/library/kei.js +256 -0
  278. package/build/src/library/keiyaku-attribution.d.ts +11 -0
  279. package/build/src/{cli/delivery-identity.js → library/keiyaku-attribution.js} +12 -1
  280. package/build/src/library/keiyaku-classify.d.ts +11 -0
  281. package/build/src/library/keiyaku-classify.js +146 -0
  282. package/build/src/library/keiyaku-coordinates.d.ts +31 -0
  283. package/build/src/library/keiyaku-coordinates.js +103 -0
  284. package/build/src/library/keiyaku-debt.d.ts +142 -0
  285. package/build/src/library/keiyaku-debt.js +188 -0
  286. package/build/src/library/keiyaku-identity.d.ts +58 -0
  287. package/build/src/library/keiyaku-identity.js +176 -0
  288. package/build/src/library/keiyaku-policy.d.ts +27 -0
  289. package/build/src/library/keiyaku-policy.js +44 -0
  290. package/build/src/library/keiyaku-status.d.ts +1487 -0
  291. package/build/src/library/keiyaku-status.js +92 -0
  292. package/build/src/library/keiyaku-verbs.d.ts +6774 -0
  293. package/build/src/library/keiyaku-verbs.js +458 -0
  294. package/build/src/library/keiyaku.d.ts +871 -38
  295. package/build/src/library/keiyaku.js +677 -127
  296. package/build/src/library/nuke.d.ts +22 -0
  297. package/build/src/library/nuke.js +4 -1
  298. package/build/src/library/outcome.d.ts +706 -692
  299. package/build/src/library/outcome.js +582 -167
  300. package/build/src/library/reconcile.d.ts +464 -116
  301. package/build/src/library/reconcile.js +174 -102
  302. package/build/src/library/refusal.d.ts +113 -577
  303. package/build/src/library/refusal.js +64 -51
  304. package/build/src/library/region.d.ts +5 -24
  305. package/build/src/library/region.js +6 -21
  306. package/build/src/library/selection.d.ts +181 -32
  307. package/build/src/library/selection.js +99 -64
  308. package/build/src/mcp/adapter.d.ts +11 -0
  309. package/build/src/mcp/adapter.js +106 -0
  310. package/build/src/mcp/help.d.ts +1 -0
  311. package/build/src/mcp/help.js +26 -0
  312. package/build/src/mcp/index.d.ts +2 -0
  313. package/build/src/mcp/index.js +37 -0
  314. package/build/src/plugin/public.d.ts +1 -1
  315. package/build/src/plugin/runtime.js +17 -14
  316. package/build/src/protocol/arc.d.ts +4 -1
  317. package/build/src/protocol/arc.js +7 -1
  318. package/build/src/protocol/attempt.d.ts +2 -3
  319. package/build/src/protocol/attempt.js +1 -10
  320. package/build/src/protocol/bind.d.ts +6 -7
  321. package/build/src/protocol/bind.js +9 -5
  322. package/build/src/protocol/completion.d.ts +448 -12
  323. package/build/src/protocol/completion.js +164 -26
  324. package/build/src/protocol/deliver.d.ts +26 -24
  325. package/build/src/protocol/deliver.js +24 -52
  326. package/build/src/protocol/delivery-preview.d.ts +97 -247
  327. package/build/src/protocol/delivery-preview.js +132 -128
  328. package/build/src/protocol/execution-observation.d.ts +146 -123
  329. package/build/src/protocol/execution-observation.js +9 -6
  330. package/build/src/protocol/intent.d.ts +9 -48
  331. package/build/src/protocol/intent.js +32 -46
  332. package/build/src/protocol/operations.d.ts +207 -505
  333. package/build/src/protocol/operations.js +81 -134
  334. package/build/src/protocol/placement.d.ts +0 -1
  335. package/build/src/protocol/placement.js +5 -2
  336. package/build/src/protocol/progress.d.ts +7 -97
  337. package/build/src/protocol/progress.js +7 -55
  338. package/build/src/protocol/read/observation.d.ts +13 -6
  339. package/build/src/protocol/read/observation.js +10 -9
  340. package/build/src/protocol/read/status.d.ts +464 -93
  341. package/build/src/protocol/read/status.js +372 -85
  342. package/build/src/protocol/reconcile.d.ts +2 -0
  343. package/build/src/protocol/reconcile.js +12 -11
  344. package/build/src/protocol/reintegrate.d.ts +0 -1
  345. package/build/src/protocol/reintegrate.js +4 -4
  346. package/build/src/protocol/result-leaves.d.ts +528 -0
  347. package/build/src/protocol/result-leaves.js +195 -0
  348. package/build/src/protocol/result-reasons.d.ts +129 -0
  349. package/build/src/protocol/result-reasons.js +87 -0
  350. package/build/src/protocol/review.d.ts +14 -11
  351. package/build/src/protocol/review.js +30 -14
  352. package/build/src/protocol/run.d.ts +4 -4
  353. package/build/src/protocol/run.js +4 -1
  354. package/build/src/protocol/verify.d.ts +359 -30
  355. package/build/src/protocol/verify.js +118 -28
  356. package/build/src/region.d.ts +26 -0
  357. package/build/src/region.js +28 -0
  358. package/build/src/runtime/proc/diagnostic.d.ts +11 -0
  359. package/build/src/runtime/proc/diagnostic.js +20 -0
  360. package/build/src/runtime/proc/windows-launch.exe +0 -0
  361. package/build/src/settings.d.ts +126 -32
  362. package/build/src/settings.js +107 -34
  363. package/build/src/settlement/settle.d.ts +29 -12
  364. package/build/src/settlement/settle.js +22 -15
  365. package/build/src/verification/declaration.d.ts +1 -3
  366. package/build/src/verification/declaration.js +2 -5
  367. package/build/src/verification/execution.d.ts +7 -19
  368. package/build/src/verification/execution.js +37 -16
  369. package/build/src/verification/observation.d.ts +13 -13
  370. package/build/src/verification/observation.js +9 -7
  371. package/build/src/world.d.ts +8 -0
  372. package/build/src/world.js +7 -0
  373. package/package.json +6 -5
  374. package/plugins/paseo/plugin/server/keiyaku.ts +13 -46
  375. package/plugins/paseo/plugin/server/message.ts +8 -30
  376. package/plugins/paseo/plugin/server/mirror.ts +16 -20
  377. package/plugins/paseo/plugin/server/provider.ts +1 -1
  378. package/plugins/paseo/plugin/server/sdk.ts +14 -6
  379. package/plugins/pi/README.md +5 -5
  380. package/plugins/pi/akuma-tools.ts +17 -23
  381. package/skills/keiyaku/SKILL.md +12 -12
  382. package/skills/keiyaku-akuma/SKILL.md +16 -16
  383. package/skills/keiyaku-akuma/references/automation.md +14 -14
  384. package/skills/keiyaku-babysit/SKILL.md +10 -10
  385. package/skills/keiyaku-bind/SKILL.md +15 -15
  386. package/skills/keiyaku-debt/SKILL.md +16 -16
  387. package/skills/keiyaku-workflow/SKILL.md +21 -21
  388. package/build/src/cli/actor.d.ts +0 -10
  389. package/build/src/cli/actor.js +0 -24
  390. package/build/src/cli/akuma-caller.d.ts +0 -3
  391. package/build/src/cli/akuma-caller.js +0 -31
  392. package/build/src/cli/delivery-identity.d.ts +0 -3
  393. package/build/src/cli/render/effects.d.ts +0 -26
  394. package/build/src/cli/render/effects.js +0 -41
  395. package/build/src/cli/selectors.d.ts +0 -10
  396. package/build/src/cli/selectors.js +0 -42
  397. package/build/src/markdown/diff.d.ts +0 -1
  398. package/build/src/markdown/diff.js +0 -4
@@ -1,133 +1,683 @@
1
1
  /** @architectureCompositionRoot */
2
- import { renderContractGuidance } from "../contract-guidance.js";
3
- import { readDispatchesAt } from "../dispatch/index.js";
4
- import { mintSnapshotId } from "../git/identity.js";
5
- import { observeContractsForAdmissionInObservationAt } from "../git/observe.js";
6
- import { withGitDecodeChannel, withGitReadObservation } from "../git/read-observation.js";
7
- import { contractObservationOperation, deliveryOperation, stateOperation, } from "../protocol/operations.js";
8
- import { readManagedWorktreeAppointment } from "../workspace-place.js";
9
- import { composeContractLibrary } from "./contract-composition.js";
10
- import { readContractValue } from "./outcome.js";
11
- import { ContractExecution } from "./contract-execution.js";
12
- import { deliveryForContract } from "./delivery.js";
13
- import { validateContractWaitHandle, waitContractLocal, } from "./contract-wait.js";
14
- const KEIYAKU_HANDLE = Symbol("Keiyaku handle");
15
- const KEIYAKU_SEATS = new WeakMap();
2
+ import { isAbsolute, resolve } from "node:path";
3
+ import { ZodError } from "zod";
4
+ import { Schema } from "../akuma/schema.js";
5
+ import { verbs, } from "./keiyaku-verbs.js";
6
+ import { canonicalBirthCwd } from "../akuma/call-input.js";
7
+ import { World, WorldError } from "../world.js";
8
+ import { Akuma } from "../akuma/akuma-instance.js";
9
+ import { kanshi } from "../kanshi/index.js";
10
+ import { Akumas, } from "./akumas.js";
11
+ import { deliveryOwner, resolveActor } from "./keiyaku-attribution.js";
12
+ import { akumaCallerFromEnvironment } from "./keiyaku-identity.js";
13
+ import { settings } from "../settings.js";
14
+ import { Keis } from "./contract-composition.js";
15
+ import { validateArcMarkdown } from "./input.js";
16
+ import { KeiyakuError } from "./outcome.js";
17
+ import { invocationCoordinates, KeiyakuArcDocumentError, KeiyakuUsageError } from "./keiyaku-coordinates.js";
18
+ import { whoami } from "./keiyaku-identity.js";
19
+ import { nukeKeiyaku } from "./nuke.js";
20
+ import { statusAt } from "./keiyaku-status.js";
21
+ import { listArchetypeDefinitions } from "../akuma/archetype.js";
22
+ import * as debt from "./keiyaku-debt.js";
23
+ export { KeiyakuArcDocumentError, KeiyakuUsageError } from "./keiyaku-coordinates.js";
16
24
  export class Keiyaku {
17
- static with(input) {
18
- return composeContractLibrary(createKeiyakuHandle, input);
19
- }
20
- id;
21
- scope;
22
- operations;
23
- constructor(token, id, scope, composition) {
24
- if (token !== KEIYAKU_HANDLE)
25
- throw new TypeError("Keiyaku handles are created by Keiyaku.with");
26
- this.id = id;
27
- this.scope = scope;
28
- this.operations = new ContractExecution({ id, scope, composition });
29
- // Process-local custody never serializes: identity-only JSON projection.
30
- Object.defineProperties(this, {
31
- id: { value: id, enumerable: false },
32
- scope: { value: scope, enumerable: false },
33
- operations: { value: this.operations, enumerable: false },
34
- composition: { value: composition, enumerable: false },
25
+ static verbs = verbs;
26
+ #input;
27
+ constructor(input) {
28
+ this.#input = { ...input, environment: { ...input.environment } };
29
+ }
30
+ static at(input) {
31
+ if (typeof input?.cwd !== "string" || !isAbsolute(input.cwd))
32
+ throw new TypeError("cwd must be an absolute string");
33
+ if (typeof input.environment !== "object" ||
34
+ input.environment === null ||
35
+ Array.isArray(input.environment) ||
36
+ Object.values(input.environment).some((value) => value !== undefined && typeof value !== "string"))
37
+ throw new TypeError("environment must be a string record");
38
+ if (input.home !== undefined && typeof input.home !== "string")
39
+ throw new TypeError("home must be a string");
40
+ if (input.repo !== undefined && typeof input.repo !== "string")
41
+ throw new TypeError("repo must be a string");
42
+ return new Keiyaku(input);
43
+ }
44
+ async run(name, input, run) {
45
+ let parsed;
46
+ try {
47
+ parsed = verbs[name].input.parse(input);
48
+ }
49
+ catch (error) {
50
+ if (error instanceof ZodError)
51
+ throw new KeiyakuUsageError(error.message);
52
+ throw error;
53
+ }
54
+ return (await this.#dispatch({ name, input: parsed }, run));
55
+ }
56
+ async #dispatch(request, run) {
57
+ const signal = run?.signal === undefined ? {} : { signal: run.signal };
58
+ const observe = run?.observe;
59
+ const notify = (event) => {
60
+ try {
61
+ const result = observe?.(event);
62
+ if (result !== undefined)
63
+ void Promise.resolve(result).catch(() => undefined);
64
+ }
65
+ catch {
66
+ /* Observation cannot affect execution. */
67
+ }
68
+ };
69
+ switch (request.name) {
70
+ case "bind":
71
+ return this.#bind(request.input);
72
+ case "amend":
73
+ return this.#amend(request.input);
74
+ case "arc":
75
+ return this.#arc(request.input);
76
+ case "deliver":
77
+ return this.#deliver({ ...request.input, ...signal }, observe === undefined ? undefined : { observe: (event) => notify(event) });
78
+ case "deliver.preview":
79
+ return this.#previewDelivery({ ...request.input, ...signal }, observe === undefined ? undefined : { observe: (event) => notify(event) });
80
+ case "verify":
81
+ return this.#verify({ ...request.input, ...signal }, observe === undefined ? undefined : { observe: (event) => notify(event) });
82
+ case "review":
83
+ return this.#review({ ...request.input, ...signal }, observe === undefined ? undefined : { observe: (event) => notify(event) });
84
+ case "abandon":
85
+ return this.#abandon(request.input);
86
+ case "show":
87
+ return this.#show(request.input);
88
+ case "reconcile":
89
+ return this.#reconcile(request.input);
90
+ case "spawn":
91
+ case "fork":
92
+ case "tell":
93
+ case "ask":
94
+ case "kill":
95
+ case "wait":
96
+ case "history":
97
+ case "report":
98
+ return this.#dispatchAkuma(request, run, notify);
99
+ case "whoami":
100
+ return this.#whoami();
101
+ case "settings":
102
+ return this.#settings();
103
+ case "nuke":
104
+ return this.#nuke(request.input);
105
+ case "status":
106
+ return this.#status(request.input);
107
+ case "region":
108
+ return this.#region(request.input);
109
+ case "ls":
110
+ return this.#ls(request.input);
111
+ case "debt.add":
112
+ case "debt.addDocument":
113
+ case "debt.update":
114
+ case "debt.show":
115
+ case "debt.done":
116
+ case "debt.drop":
117
+ case "debt.ready":
118
+ case "debt.blocked":
119
+ case "debt.query":
120
+ case "debt.tree":
121
+ case "debt.doctor":
122
+ case "debt.context":
123
+ return this.#dispatchDebt(request, signal);
124
+ }
125
+ }
126
+ #dispatchAkuma(request, run, notify) {
127
+ const signal = run?.signal === undefined ? {} : { signal: run.signal };
128
+ const observe = run?.observe;
129
+ switch (request.name) {
130
+ case "spawn": {
131
+ const { schema, ...input } = request.input;
132
+ const decode = run?.decode ?? ((value) => value);
133
+ return this.#spawn({
134
+ ...input,
135
+ ...signal,
136
+ ...(schema === undefined ? {} : { schema: Schema.json(schema, decode) }),
137
+ ...(observe === undefined
138
+ ? {}
139
+ : {
140
+ observe: {
141
+ admitted: (tell, id, head) => notify({ kind: "admitted", tell, id, head }),
142
+ observe: (observation) => notify({ kind: "live", observation }),
143
+ },
144
+ }),
145
+ });
146
+ }
147
+ case "fork":
148
+ return this.#fork(request.input);
149
+ case "tell":
150
+ return this.#tell({ ...request.input, ...signal });
151
+ case "ask": {
152
+ const { schema, ...input } = request.input;
153
+ const decode = run?.decode ?? ((value) => value);
154
+ return this.#ask({
155
+ ...input,
156
+ ...signal,
157
+ ...(schema === undefined ? {} : { schema: Schema.json(schema, decode) }),
158
+ ...(observe === undefined
159
+ ? {}
160
+ : {
161
+ observe: {
162
+ admitted: (tell, id) => notify({ kind: "admitted", tell, id }),
163
+ observe: (observation) => notify({ kind: "live", observation }),
164
+ },
165
+ }),
166
+ });
167
+ }
168
+ case "kill":
169
+ return this.#kill({ ...request.input, ...signal });
170
+ case "wait":
171
+ return this.#wait({ ...request.input, ...signal });
172
+ case "history":
173
+ return this.#history(request.input);
174
+ case "report":
175
+ return this.#report({ ...request.input, ...signal });
176
+ }
177
+ }
178
+ #dispatchDebt(request, signal) {
179
+ switch (request.name) {
180
+ case "debt.add":
181
+ return debt.debtAdd(this.#input, { ...request.input, ...signal }, false);
182
+ case "debt.addDocument":
183
+ return debt.debtAdd(this.#input, { ...request.input, ...signal }, true);
184
+ case "debt.update":
185
+ return debt.debtUpdate(this.#input, { ...request.input, ...signal });
186
+ case "debt.show":
187
+ return debt.debtShow(this.#input, request.input);
188
+ case "debt.done":
189
+ return debt.debtClose(this.#input, { ...request.input, ...signal }, "done");
190
+ case "debt.drop":
191
+ return debt.debtClose(this.#input, { ...request.input, ...signal }, "drop");
192
+ case "debt.ready":
193
+ return debt.debtReady(this.#input, request.input, false);
194
+ case "debt.blocked":
195
+ return debt.debtReady(this.#input, request.input, true);
196
+ case "debt.query":
197
+ return debt.debtQuery(this.#input, request.input);
198
+ case "debt.tree":
199
+ return debt.debtTree(this.#input, request.input);
200
+ case "debt.doctor":
201
+ return debt.debtDoctor(this.#input);
202
+ case "debt.context":
203
+ return debt.debtContext(this.#input, request.input);
204
+ }
205
+ }
206
+ bind(input) {
207
+ return this.run("bind", input);
208
+ }
209
+ amend(input) {
210
+ return this.run("amend", input);
211
+ }
212
+ arc(input) {
213
+ return this.run("arc", input);
214
+ }
215
+ deliver(input, run) {
216
+ return this.run("deliver", input, run);
217
+ }
218
+ previewDelivery(input, run) {
219
+ return this.run("deliver.preview", input, run);
220
+ }
221
+ verify(input, run) {
222
+ return this.run("verify", input, run);
223
+ }
224
+ review(input, run) {
225
+ return this.run("review", input, run);
226
+ }
227
+ abandon(input) {
228
+ return this.run("abandon", input);
229
+ }
230
+ show(input = {}) {
231
+ return this.run("show", input);
232
+ }
233
+ reconcile(input = {}) {
234
+ return this.run("reconcile", input);
235
+ }
236
+ spawn({ schema, ...input }, run) {
237
+ return this.run("spawn", { ...input, ...(schema === undefined ? {} : { schema: schema.jsonSchema }) }, {
238
+ ...run,
239
+ ...(schema === undefined ? {} : { decode: schema.decode }),
35
240
  });
36
- KEIYAKU_SEATS.set(this, { id, scope });
37
- Object.freeze(this);
38
- }
39
- /** The handle's one durable identity; everything else is process-local custody. */
40
- toJSON() {
41
- return { contract: this.id };
42
- }
43
- async state() {
44
- return await readContractValue(() => withGitDecodeChannel(this.scope, (channel) => stateOperation({ scope: this.scope, channel, contractId: this.id })));
45
- }
46
- async wait(input) {
47
- return await waitContractLocal(validateContractWaitHandle(this.scope, this.id, input));
48
- }
49
- async history() {
50
- return await readContractValue(() => withGitDecodeChannel(this.scope, (channel) => withGitReadObservation(this.scope, channel, async (observation) => {
51
- const [journals, dispatches] = await Promise.all([
52
- observeContractsForAdmissionInObservationAt(observation, [this.id]),
53
- readDispatchesAt(observation),
54
- ]);
55
- const record = journals.journals.get(this.id);
56
- if (record === undefined)
57
- throw new Error(`missing requested contract observation: ${this.id}`);
58
- if (record.state === null)
59
- return null;
60
- const commit = observation.snapshot.commit;
61
- if (commit === null)
62
- throw new Error("contract history requires a keiyaku-state snapshot");
63
- const recordedAt = (event) => event.source === "journal" ? event.fact.at : event.dispatch.dispatchedAt;
64
- const events = [
65
- ...record.entries.map((fact) => ({ source: "journal", fact })),
66
- ...dispatches
67
- .filter((dispatch) => dispatch.contractId === this.id)
68
- .map((dispatch) => ({ source: "dispatch", dispatch })),
69
- ].sort((left, right) => {
70
- const leftAt = recordedAt(left);
71
- const rightAt = recordedAt(right);
72
- if (leftAt !== rightAt)
73
- return leftAt < rightAt ? -1 : 1;
74
- if (left.source !== right.source)
75
- return left.source === "journal" ? -1 : 1;
76
- return 0;
241
+ }
242
+ fork(input) {
243
+ return this.run("fork", input);
244
+ }
245
+ tell(input, run) {
246
+ return this.run("tell", input, run);
247
+ }
248
+ ask({ schema, ...input }, run) {
249
+ return this.run("ask", { ...input, ...(schema === undefined ? {} : { schema: schema.jsonSchema }) }, {
250
+ ...run,
251
+ ...(schema === undefined ? {} : { decode: schema.decode }),
252
+ });
253
+ }
254
+ kill(input, run) {
255
+ return this.run("kill", input, run);
256
+ }
257
+ wait(input, run) {
258
+ return this.run("wait", input, run);
259
+ }
260
+ history(input) {
261
+ return this.run("history", input);
262
+ }
263
+ report(input, run) {
264
+ return this.run("report", input, run);
265
+ }
266
+ ls(input) {
267
+ return this.run("ls", input);
268
+ }
269
+ debtAdd({ signal, ...input }) {
270
+ return this.run("debt.add", input, signal === undefined ? {} : { signal });
271
+ }
272
+ debtAddDocument({ signal, ...input }) {
273
+ return this.run("debt.addDocument", input, signal === undefined ? {} : { signal });
274
+ }
275
+ debtUpdate({ signal, ...input }) {
276
+ return this.run("debt.update", input, signal === undefined ? {} : { signal });
277
+ }
278
+ debtShow(input) {
279
+ return this.run("debt.show", input);
280
+ }
281
+ debtDone({ signal, ...input }) {
282
+ return this.run("debt.done", input, signal === undefined ? {} : { signal });
283
+ }
284
+ debtDrop({ signal, ...input }) {
285
+ return this.run("debt.drop", input, signal === undefined ? {} : { signal });
286
+ }
287
+ debtReady(input = {}) {
288
+ return this.run("debt.ready", input);
289
+ }
290
+ debtBlocked(input = {}) {
291
+ return this.run("debt.blocked", input);
292
+ }
293
+ debtQuery(input = {}) {
294
+ return this.run("debt.query", input);
295
+ }
296
+ debtTree(input) {
297
+ return this.run("debt.tree", input);
298
+ }
299
+ debtDoctor() {
300
+ return this.run("debt.doctor", {});
301
+ }
302
+ debtContext(input = {}) {
303
+ return this.run("debt.context", input);
304
+ }
305
+ status(input = {}) {
306
+ return this.run("status", input);
307
+ }
308
+ region(input = {}) {
309
+ return this.run("region", input);
310
+ }
311
+ whoami() {
312
+ return this.run("whoami", {});
313
+ }
314
+ settings() {
315
+ return this.run("settings", {});
316
+ }
317
+ nuke(input = {}) {
318
+ return this.run("nuke", input);
319
+ }
320
+ #coordinates(use, contractWait = false) {
321
+ return invocationCoordinates({ ...this.#input, use, contractWait });
322
+ }
323
+ #actor(explicit) {
324
+ try {
325
+ const actor = resolveActor({
326
+ env: this.#input.environment,
327
+ ...(explicit === undefined ? {} : { actor: explicit }),
77
328
  });
78
- const workspace = await readManagedWorktreeAppointment(this.scope, this.id);
79
- return {
80
- id: this.id,
81
- state: mintSnapshotId(commit),
82
- ...(workspace.kind === "appointed"
83
- ? { workspace: { kind: "worktree", path: workspace.path } }
84
- : {}),
85
- events,
86
- };
87
- })));
88
- }
89
- async guidance() {
90
- return await readContractValue(() => withGitDecodeChannel(this.scope, async (channel) => {
91
- const observed = await contractObservationOperation({ scope: this.scope, channel, contractId: this.id });
92
- if (observed.kind === "missing")
93
- return null;
94
- const state = await stateOperation({ scope: this.scope, channel, contractId: this.id });
95
- return state === null ? null : renderContractGuidance(state);
96
- }));
97
- }
98
- async delivery() {
99
- const delivery = await readContractValue(() => withGitDecodeChannel(this.scope, (channel) => deliveryOperation({ scope: this.scope, channel, contractId: this.id })));
100
- return delivery === null ? null : deliveryForContract(this.scope, delivery);
101
- }
102
- async amend(input) {
103
- return await this.operations.amend(input);
104
- }
105
- async deliver(input, options) {
106
- return await this.operations.deliver(input, options);
107
- }
108
- async verify(input, options) {
109
- return await this.operations.verify(input, options);
110
- }
111
- async review(input, options) {
112
- return await this.operations.review(input, options);
113
- }
114
- async abandon(input) {
115
- return await this.operations.abandon(input);
116
- }
117
- async arc(input) {
118
- return await this.operations.arc(input);
119
- }
120
- async previewDelivery(input, options) {
121
- return await this.operations.previewDelivery(input, options);
329
+ return actor === undefined ? {} : { actor };
330
+ }
331
+ catch (error) {
332
+ throw new KeiyakuUsageError(error instanceof Error ? error.message : String(error));
333
+ }
334
+ }
335
+ async #keis(actor) {
336
+ const at = await this.#coordinates("required");
337
+ if (at.repo === undefined)
338
+ throw new KeiyakuUsageError("this command requires a resolved Repo");
339
+ const configuration = await settings({
340
+ ...(at.world === null ? {} : { root: at.world }),
341
+ ...(this.#input.home === undefined ? {} : { home: this.#input.home }),
342
+ });
343
+ const selected = this.#actor(actor);
344
+ return {
345
+ cwd: at.cwd,
346
+ actor: selected,
347
+ library: Keis.of(at.repo, { settings: configuration, ...selected }),
348
+ };
349
+ }
350
+ #fullId(library, value) {
351
+ try {
352
+ library.kei({ id: value });
353
+ return value;
354
+ }
355
+ catch (error) {
356
+ throw new KeiyakuUsageError(error instanceof Error ? error.message : String(error));
357
+ }
358
+ }
359
+ async #resolve(library, selector, cwd) {
360
+ const result = await library.resolve({ ...(selector === undefined ? {} : { selector }), cwd });
361
+ if (result.kind === "resolved")
362
+ return result.id;
363
+ const refusal = result.refusal;
364
+ switch (refusal.kind) {
365
+ case "invalid-selector":
366
+ throw new KeiyakuUsageError(refusal.diagnostic);
367
+ case "redundant-short-selector":
368
+ throw new KeiyakuUsageError(`redundant short contract selector: ${refusal.selector}`);
369
+ case "unknown-short-selector":
370
+ throw new KeiyakuUsageError(`unknown contract selector: ${refusal.selector}`);
371
+ case "ambiguous-selector":
372
+ throw new KeiyakuUsageError("selector" in refusal
373
+ ? `ambiguous contract selector: ${refusal.selector}`
374
+ : "ambiguous managed worktree contract selector");
375
+ case "no-contextual-match":
376
+ throw new KeiyakuUsageError("an explicit full or @ contract selector is required outside a managed worktree");
377
+ }
378
+ }
379
+ async #selected(selector, actor) {
380
+ const { cwd, library, actor: selectedActor } = await this.#keis(actor);
381
+ const id = await this.#resolve(library, selector, cwd);
382
+ return { id, contract: library.kei({ id }), actor: selectedActor };
383
+ }
384
+ async #bind(input) {
385
+ const { library, actor } = await this.#keis(input.actor);
386
+ if ("forkOf" in input)
387
+ return await library.bind({
388
+ ...input,
389
+ forkOf: this.#fullId(library, input.forkOf),
390
+ ...actor,
391
+ });
392
+ const { after, ...rest } = input;
393
+ return await library.bind({
394
+ ...rest,
395
+ ...(after === undefined ? {} : { after: after.map((id) => this.#fullId(library, id)) }),
396
+ ...actor,
397
+ });
398
+ }
399
+ async #amend({ contract, ...input }) {
400
+ const { cwd, library, actor } = await this.#keis(input.actor);
401
+ const id = await this.#resolve(library, contract, cwd);
402
+ const { after, ...rest } = input;
403
+ return await library.kei({ id }).amend({
404
+ ...rest,
405
+ ...(after === undefined ? {} : { after: after.map((value) => this.#fullId(library, value)) }),
406
+ ...actor,
407
+ });
408
+ }
409
+ async #arc({ contract, ...input }) {
410
+ const selected = await this.#selected(contract, input.actor);
411
+ try {
412
+ validateArcMarkdown(input.markdown);
413
+ }
414
+ catch (error) {
415
+ if (error instanceof TypeError || (error instanceof KeiyakuError && error.category === "invalid-input"))
416
+ throw new KeiyakuArcDocumentError(selected.id, error);
417
+ throw error;
418
+ }
419
+ return await selected.contract.arc({ ...input, ...selected.actor });
420
+ }
421
+ async #deliver({ contract, ...input }, progress) {
422
+ return await (await this.#selected(contract)).contract.deliver(input, progress);
423
+ }
424
+ async #previewDelivery({ contract, ...input }, progress) {
425
+ return await (await this.#selected(contract)).contract.previewDelivery(input, progress);
426
+ }
427
+ async #verify({ contract, ...input }, progress) {
428
+ return await (await this.#selected(contract)).contract.verify(input, progress);
429
+ }
430
+ async #review({ contract, ...input }, progress) {
431
+ const selected = await this.#selected(contract, input.actor);
432
+ return await selected.contract.review({ ...input, ...selected.actor }, progress);
433
+ }
434
+ async #abandon({ contract, ...input }) {
435
+ const selected = await this.#selected(contract, input.actor);
436
+ return await selected.contract.abandon({ ...input, ...selected.actor });
437
+ }
438
+ async #show(input = {}) {
439
+ return await (await this.#selected(input.contract)).contract.guidance();
440
+ }
441
+ async #reconcile(input = {}) {
442
+ const { cwd, library } = await this.#keis();
443
+ if (input.contract === undefined)
444
+ return await library.reconcile(input);
445
+ const id = await this.#resolve(library, input.contract, cwd);
446
+ return await library.reconcile({ ...input, contract: id });
447
+ }
448
+ async #spawn({ prompt, contract, workdir, writableDirectories, observe, ...input }) {
449
+ if (prompt !== undefined && prompt.trim() === "")
450
+ throw new KeiyakuUsageError("spawn requires a nonblank prompt");
451
+ const at = await this.#coordinates(contract === undefined ? "none" : "required");
452
+ const cwd = workdir === undefined
453
+ ? at.cwd
454
+ : await canonicalBirthCwd(resolve(at.cwd, workdir), `workdir is not an existing directory: ${workdir}`);
455
+ const directories = writableDirectories === undefined
456
+ ? undefined
457
+ : await Promise.all(writableDirectories.map((path) => {
458
+ if (path.trim() === "")
459
+ throw new TypeError("--add-dir requires a nonblank directory");
460
+ return canonicalBirthCwd(resolve(at.cwd, path));
461
+ }));
462
+ const caller = await this.#caller();
463
+ const initiator = deliveryOwner(this.#input.environment);
464
+ const world = at.candidateWorld ?? (await at.establishWorld());
465
+ await World.at(world);
466
+ const configuration = await settings({
467
+ root: world,
468
+ ...(this.#input.home === undefined ? {} : { home: this.#input.home }),
469
+ });
470
+ const selected = contract === undefined ? undefined : Keis.of(at.repo).kei({ id: this.#fullId(Keis.of(at.repo), contract) });
471
+ return await Akumas.of(world).spawn({
472
+ ...input,
473
+ cwd,
474
+ settings: configuration,
475
+ ...(this.#input.home === undefined ? {} : { home: this.#input.home }),
476
+ ...(prompt === undefined ? {} : { body: prompt }),
477
+ ...(directories === undefined ? {} : { writableDirectories: directories }),
478
+ ...(selected === undefined ? {} : { contract: selected }),
479
+ ...(caller === undefined ? {} : { caller }),
480
+ ...(initiator === undefined ? {} : { initiator }),
481
+ ...(observe === undefined
482
+ ? {}
483
+ : {
484
+ observe: {
485
+ ...(observe.observe === undefined ? {} : { observe: observe.observe }),
486
+ ...(observe.admitted === undefined
487
+ ? {}
488
+ : {
489
+ admitted: (tell, id, head) => observe.admitted(tell, id, { ...head, cwd }),
490
+ }),
491
+ },
492
+ }),
493
+ });
494
+ }
495
+ async #caller() {
496
+ try {
497
+ return await akumaCallerFromEnvironment(this.#input.environment);
498
+ }
499
+ catch (error) {
500
+ if (error instanceof TypeError)
501
+ throw new KeiyakuUsageError(error.message);
502
+ throw error;
503
+ }
504
+ }
505
+ async #akumas(use = "optional") {
506
+ const at = await this.#coordinates(use);
507
+ if (at.world === null)
508
+ throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
509
+ return { at, akumas: Akumas.of(at.world) };
510
+ }
511
+ async #fork(input) {
512
+ const { at, akumas } = await this.#akumas();
513
+ const caller = await this.#caller();
514
+ const initiator = deliveryOwner(this.#input.environment);
515
+ return await akumas.fork({
516
+ ...input,
517
+ ...(at.repo === undefined ? {} : { repo: at.repo }),
518
+ ...(caller === undefined ? {} : { caller }),
519
+ ...(initiator === undefined ? {} : { initiator }),
520
+ });
521
+ }
522
+ async #tell({ prompt, ...input }) {
523
+ if (prompt.trim() === "")
524
+ throw new KeiyakuUsageError("tell requires a nonblank prompt");
525
+ const { at, akumas } = await this.#akumas();
526
+ const initiator = deliveryOwner(this.#input.environment);
527
+ return await akumas.tell({
528
+ ...input,
529
+ body: prompt,
530
+ ...(at.repo === undefined ? {} : { repo: at.repo }),
531
+ ...(initiator === undefined ? {} : { initiator }),
532
+ });
533
+ }
534
+ async #ask({ prompt, ...input }) {
535
+ if (prompt.trim() === "")
536
+ throw new KeiyakuUsageError("ask requires a nonblank prompt");
537
+ const { at, akumas } = await this.#akumas();
538
+ const initiator = deliveryOwner(this.#input.environment);
539
+ return await akumas.ask({
540
+ ...input,
541
+ body: prompt,
542
+ ...(at.repo === undefined ? {} : { repo: at.repo }),
543
+ ...(initiator === undefined ? {} : { initiator }),
544
+ });
545
+ }
546
+ async #kill(input) {
547
+ const { at, akumas } = await this.#akumas();
548
+ return await akumas.kill({ ...input, ...(at.repo === undefined ? {} : { repo: at.repo }) });
549
+ }
550
+ async #wait({ selectors, ...input }) {
551
+ const contracts = selectors.filter((selector) => selector.startsWith("kei/"));
552
+ if (contracts.length > 0 && contracts.length !== selectors.length)
553
+ throw new KeiyakuUsageError("wait cannot mix Contract and Akuma selectors");
554
+ if (contracts.length > 0) {
555
+ const at = await this.#coordinates("required", true);
556
+ if (at.repo === undefined)
557
+ throw new KeiyakuUsageError("Contract wait requires a repository");
558
+ return await Keis.of(at.repo).wait({ contracts, ...input });
559
+ }
560
+ const { at, akumas } = await this.#akumas();
561
+ return await akumas.wait({ akuma: selectors, ...input, ...(at.repo === undefined ? {} : { repo: at.repo }) });
562
+ }
563
+ async #history({ selector, full, ...input }) {
564
+ if (selector.startsWith("kei/")) {
565
+ const at = await this.#coordinates("required");
566
+ if (at.repo === undefined)
567
+ throw new KeiyakuUsageError("this command requires a resolved Repo");
568
+ const library = Keis.of(at.repo);
569
+ return await library
570
+ .kei({ id: this.#fullId(library, selector) })
571
+ .history(full === undefined ? undefined : { full });
572
+ }
573
+ const { at, akumas } = await this.#akumas();
574
+ return await akumas.history({ akuma: selector, ...input, ...(at.repo === undefined ? {} : { repo: at.repo }) });
575
+ }
576
+ async #report(input) {
577
+ await this.#coordinates("none");
578
+ const environment = this.#input.environment;
579
+ if (typeof input.text !== "string" || input.text.trim() === "")
580
+ throw new KeiyakuUsageError("report requires nonblank text");
581
+ if (environment.KEIYAKU_ACTOR_ID === undefined || environment.KEIYAKU_ACTOR_WORLD === undefined)
582
+ throw new KeiyakuUsageError("report requires explicit KEIYAKU_ACTOR_ID and KEIYAKU_ACTOR_WORLD");
583
+ let caller;
584
+ try {
585
+ caller = await akumaCallerFromEnvironment(environment);
586
+ }
587
+ catch (error) {
588
+ if (error instanceof TypeError || error instanceof WorldError)
589
+ throw new KeiyakuUsageError(error.message);
590
+ throw error;
591
+ }
592
+ if (caller?.kind !== "akuma")
593
+ throw new KeiyakuUsageError("report requires explicit Akuma identity");
594
+ return Akuma.select(caller.world, caller.akumaId).report(input.text, input.signal === undefined ? {} : { signal: input.signal });
595
+ }
596
+ async #resolveLsCaller(selection, world) {
597
+ if (selection === undefined)
598
+ return undefined;
599
+ if (selection.kind === "external")
600
+ return selection.caller;
601
+ if (selection.kind === "akuma")
602
+ return { kind: "akuma", world, akumaId: selection.akumaId };
603
+ let caller;
604
+ try {
605
+ caller = await akumaCallerFromEnvironment(this.#input.environment);
606
+ }
607
+ catch (error) {
608
+ throw new KeiyakuUsageError(error instanceof Error ? error.message : String(error));
609
+ }
610
+ if (caller === undefined) {
611
+ throw new KeiyakuUsageError("--mine requires a caller identity; set KEIYAKU_ACTOR_ID and KEIYAKU_ACTOR_WORLD or run inside a calling host");
612
+ }
613
+ return caller;
614
+ }
615
+ async #ls(input) {
616
+ if (input.of === "debt")
617
+ return debt.debtList(this.#input, input);
618
+ const at = await this.#coordinates(input.of === "kei" ? "required" : "none");
619
+ const limit = input.limit === undefined ? {} : { limit: input.limit };
620
+ if (input.of === "kei") {
621
+ if (at.repo === undefined)
622
+ throw new KeiyakuUsageError("this command requires a resolved Repo");
623
+ return Keis.of(at.repo).list(limit);
624
+ }
625
+ if (input.of === "akuma-name") {
626
+ return listArchetypeDefinitions({
627
+ ...(at.world === null ? {} : { project: at.world }),
628
+ ...(this.#input.home === undefined ? {} : { home: this.#input.home }),
629
+ ...limit,
630
+ });
631
+ }
632
+ if (at.world === null)
633
+ throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
634
+ const caller = await this.#resolveLsCaller(input.caller, at.world);
635
+ return Akumas.of(at.world).list({
636
+ ...limit,
637
+ ...(input.akumaName === undefined ? {} : { akumaName: input.akumaName }),
638
+ ...(caller === undefined ? {} : { caller }),
639
+ });
640
+ }
641
+ async #status(input = {}) {
642
+ return await statusAt(await this.#coordinates("optional"), input);
643
+ }
644
+ async #region(input = {}) {
645
+ const at = await this.#coordinates("required");
646
+ if (at.repo === undefined)
647
+ throw new KeiyakuUsageError("this command requires a resolved Repo");
648
+ const repo = at.repo;
649
+ let selected;
650
+ if (input.paths !== undefined) {
651
+ const [first, ...rest] = input.paths;
652
+ if (first === undefined)
653
+ throw new TypeError("Region query requires one or more path patterns");
654
+ selected = { kind: "path", patterns: [first, ...rest] };
655
+ }
656
+ else {
657
+ selected =
658
+ input.contract === undefined
659
+ ? { kind: "declarations" }
660
+ : { kind: "contract", contract: await this.#resolve(Keis.of(repo), input.contract, at.cwd) };
661
+ }
662
+ const result = await kanshi({ world: at.world, repo, region: selected });
663
+ if (result.kind === "absent")
664
+ throw new Error("Region observation with a Repo cannot be absent");
665
+ return result;
666
+ }
667
+ async #whoami() {
668
+ return await whoami(await this.#coordinates("optional"), this.#input.environment);
669
+ }
670
+ async #settings() {
671
+ const at = await this.#coordinates("none");
672
+ return await settings({
673
+ ...(at.world === null ? {} : { root: at.world }),
674
+ ...(this.#input.home === undefined ? {} : { home: this.#input.home }),
675
+ });
676
+ }
677
+ async #nuke(input = {}) {
678
+ const at = await this.#coordinates("none");
679
+ if (at.world === null)
680
+ throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
681
+ return await nukeKeiyaku({ world: at.world, ...input });
122
682
  }
123
- }
124
- /** Internal constructor capability; callers select a Contract through Keiyaku.with. */
125
- export function createKeiyakuHandle(id, scope, composition) {
126
- return new Keiyaku(KEIYAKU_HANDLE, id, scope, composition);
127
- }
128
- /** Internal package composition capability; not exported from the package root. */
129
- export function seatForKeiyaku(value) {
130
- return value !== null && (typeof value === "object" || typeof value === "function")
131
- ? (KEIYAKU_SEATS.get(value) ?? null)
132
- : null;
133
683
  }