@astrosheep/keiyaku 4.5.28 → 4.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (425) hide show
  1. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +0 -13
  2. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +47 -78
  3. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/references/automation.md +54 -41
  4. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-babysit/SKILL.md +10 -0
  5. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +27 -9
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +68 -71
  7. package/build/src/akuma/akuma-call.d.ts +53 -0
  8. package/build/src/akuma/akuma-call.js +113 -0
  9. package/build/src/akuma/akuma-instance.d.ts +20 -19
  10. package/build/src/akuma/akuma-instance.js +65 -177
  11. package/build/src/akuma/akuma-observe.d.ts +3 -21
  12. package/build/src/akuma/akuma-observe.js +7 -25
  13. package/build/src/akuma/{akuma-handle.d.ts → akuma-owner.d.ts} +60 -25
  14. package/build/src/akuma/{akuma-handle.js → akuma-owner.js} +43 -29
  15. package/build/src/akuma/akuma-selection-execution.d.ts +51 -0
  16. package/build/src/akuma/akuma-selection-execution.js +134 -0
  17. package/build/src/akuma/{fleet-execution.d.ts → akuma-wait.d.ts} +24 -32
  18. package/build/src/akuma/akuma-wait.js +113 -0
  19. package/build/src/akuma/akuma.d.ts +35 -97
  20. package/build/src/akuma/akuma.js +148 -35
  21. package/build/src/akuma/archetype.d.ts +18 -6
  22. package/build/src/akuma/archetype.js +52 -34
  23. package/build/src/akuma/body.d.ts +79 -61
  24. package/build/src/akuma/body.js +101 -50
  25. package/build/src/akuma/call-initial-tell.d.ts +164 -0
  26. package/build/src/akuma/call-initial-tell.js +62 -0
  27. package/build/src/akuma/call-input.d.ts +0 -3
  28. package/build/src/akuma/call-input.js +0 -7
  29. package/build/src/akuma/call-request.d.ts +247 -38
  30. package/build/src/akuma/call-request.js +77 -92
  31. package/build/src/akuma/coordinate.d.ts +15 -5
  32. package/build/src/akuma/coordinate.js +12 -22
  33. package/build/src/akuma/dispatch-association.d.ts +1 -1
  34. package/build/src/akuma/dispatch-association.js +1 -10
  35. package/build/src/akuma/heart/activity-schema.d.ts +325 -0
  36. package/build/src/akuma/heart/activity-schema.js +53 -0
  37. package/build/src/akuma/heart/facts.d.ts +3 -9
  38. package/build/src/akuma/heart/index.d.ts +3 -1
  39. package/build/src/akuma/heart/index.js +4 -1
  40. package/build/src/akuma/heart/rows.d.ts +49 -2
  41. package/build/src/akuma/heart/rows.js +16 -2
  42. package/build/src/akuma/heart/soul.d.ts +1 -0
  43. package/build/src/akuma/heart/soul.js +7 -10
  44. package/build/src/akuma/heart/tells.d.ts +1 -0
  45. package/build/src/akuma/heart/tells.js +18 -0
  46. package/build/src/akuma/identity.d.ts +10 -7
  47. package/build/src/akuma/identity.js +23 -0
  48. package/build/src/akuma/index.d.ts +10 -8
  49. package/build/src/akuma/index.js +2 -2
  50. package/build/src/akuma/nuke.d.ts +3 -0
  51. package/build/src/akuma/nuke.js +13 -7
  52. package/build/src/akuma/projection-read.js +1 -2
  53. package/build/src/akuma/projection.d.ts +0 -5
  54. package/build/src/akuma/projection.js +22 -43
  55. package/build/src/akuma/provider-recipe.d.ts +58 -23
  56. package/build/src/akuma/provider-recipe.js +62 -103
  57. package/build/src/akuma/provider.d.ts +7 -78
  58. package/build/src/akuma/provider.js +11 -219
  59. package/build/src/akuma/providers/acp/config.d.ts +2 -0
  60. package/build/src/akuma/providers/acp/config.js +26 -1
  61. package/build/src/akuma/providers/acp/core.d.ts +7 -0
  62. package/build/src/akuma/providers/acp/core.js +49 -18
  63. package/build/src/akuma/providers/acp/index.js +14 -17
  64. package/build/src/akuma/providers/claude/index.js +2 -14
  65. package/build/src/akuma/providers/codex-app-server/index.js +0 -22
  66. package/build/src/akuma/providers/grok-build/index.js +44 -24
  67. package/build/src/akuma/providers/index.d.ts +3 -3
  68. package/build/src/akuma/providers/index.js +2 -13
  69. package/build/src/akuma/providers/opencode-sdk/event-stream.d.ts +28 -0
  70. package/build/src/akuma/providers/opencode-sdk/event-stream.js +92 -0
  71. package/build/src/akuma/providers/opencode-sdk/events.d.ts +0 -1
  72. package/build/src/akuma/providers/opencode-sdk/index.js +200 -74
  73. package/build/src/akuma/providers/opencode-sdk/session.d.ts +41 -1
  74. package/build/src/akuma/providers/opencode-sdk/session.js +69 -2
  75. package/build/src/akuma/providers/pi/events.js +5 -2
  76. package/build/src/akuma/providers/pi/index.js +70 -24
  77. package/build/src/akuma/publication.d.ts +84 -3
  78. package/build/src/akuma/publication.js +145 -2
  79. package/build/src/akuma/read-pool.d.ts +2 -0
  80. package/build/src/akuma/read-pool.js +15 -0
  81. package/build/src/akuma/request-rendezvous.js +10 -0
  82. package/build/src/akuma/request-serve.js +7 -0
  83. package/build/src/akuma/request-wire.d.ts +14 -26
  84. package/build/src/akuma/request-wire.js +4 -0
  85. package/build/src/akuma/requests.d.ts +0 -3
  86. package/build/src/akuma/requests.js +0 -24
  87. package/build/src/akuma/{fleet-observation.d.ts → selection-observation.d.ts} +61 -52
  88. package/build/src/akuma/selection-observation.js +65 -0
  89. package/build/src/akuma/{fleet-owner-port.d.ts → selection-owner-port.d.ts} +3 -3
  90. package/build/src/akuma/{fleet-owner-port.js → selection-owner-port.js} +11 -17
  91. package/build/src/akuma/{fleet-request.d.ts → selection-request.d.ts} +42 -82
  92. package/build/src/akuma/{fleet-request.js → selection-request.js} +92 -136
  93. package/build/src/akuma/turn-drive.d.ts +3 -0
  94. package/build/src/akuma/turn-drive.js +75 -16
  95. package/build/src/akuma-body.js +91 -56
  96. package/build/src/body/amend.d.ts +5 -0
  97. package/build/src/body/amend.js +26 -50
  98. package/build/src/body/arc.d.ts +4 -2
  99. package/build/src/body/arc.js +19 -26
  100. package/build/src/body/criteria.d.ts +6 -0
  101. package/build/src/body/criteria.js +37 -0
  102. package/build/src/body/decode.js +5 -42
  103. package/build/src/body/region.d.ts +5 -0
  104. package/build/src/body/region.js +45 -2
  105. package/build/src/body/render.js +2 -4
  106. package/build/src/cli/activity.d.ts +26 -0
  107. package/build/src/cli/activity.js +75 -0
  108. package/build/src/cli/actor.d.ts +3 -1
  109. package/build/src/cli/actor.js +15 -2
  110. package/build/src/cli/commands/akuma-grammar.d.ts +75 -0
  111. package/build/src/cli/commands/akuma-grammar.js +414 -0
  112. package/build/src/cli/commands/akuma.d.ts +5 -69
  113. package/build/src/cli/commands/akuma.js +352 -312
  114. package/build/src/cli/commands/amend.d.ts +4 -5
  115. package/build/src/cli/commands/amend.js +1 -2
  116. package/build/src/cli/commands/bind.d.ts +4 -5
  117. package/build/src/cli/commands/bind.js +5 -9
  118. package/build/src/cli/commands/contract-grammar.d.ts +112 -0
  119. package/build/src/cli/commands/contract-grammar.js +282 -0
  120. package/build/src/cli/commands/contract-help.d.ts +28 -30
  121. package/build/src/cli/commands/contract-help.js +69 -96
  122. package/build/src/cli/commands/contract.d.ts +18 -97
  123. package/build/src/cli/commands/contract.js +620 -237
  124. package/build/src/cli/commands/install.d.ts +1 -1
  125. package/build/src/cli/commands/install.js +2 -2
  126. package/build/src/cli/commands/task-grammar.d.ts +19 -0
  127. package/build/src/cli/commands/task-grammar.js +438 -0
  128. package/build/src/cli/commands/task-query.js +23 -104
  129. package/build/src/cli/commands/task.d.ts +5 -20
  130. package/build/src/cli/commands/task.js +415 -333
  131. package/build/src/cli/coordinates.d.ts +10 -0
  132. package/build/src/cli/coordinates.js +20 -0
  133. package/build/src/cli/draft.d.ts +7 -1
  134. package/build/src/cli/main.js +10 -1
  135. package/build/src/cli/parse.d.ts +8 -9
  136. package/build/src/cli/parse.js +63 -61
  137. package/build/src/cli/render/akuma-activity.d.ts +88 -39
  138. package/build/src/cli/render/akuma-activity.js +465 -263
  139. package/build/src/cli/render/akuma-tool.d.ts +15 -5
  140. package/build/src/cli/render/akuma-tool.js +40 -27
  141. package/build/src/cli/render/akuma.d.ts +40 -24
  142. package/build/src/cli/render/akuma.js +108 -205
  143. package/build/src/cli/render/audit.d.ts +6 -2
  144. package/build/src/cli/render/audit.js +61 -30
  145. package/build/src/cli/render/catalog.d.ts +11 -2
  146. package/build/src/cli/render/catalog.js +75 -94
  147. package/build/src/cli/render/contract-history.d.ts +3 -1
  148. package/build/src/cli/render/contract-history.js +215 -22
  149. package/build/src/cli/render/contract-observation.d.ts +10 -5
  150. package/build/src/cli/render/contract-observation.js +29 -46
  151. package/build/src/cli/render/contract.d.ts +10 -3
  152. package/build/src/cli/render/contract.js +255 -106
  153. package/build/src/cli/render/effects.d.ts +26 -0
  154. package/build/src/cli/render/effects.js +41 -0
  155. package/build/src/cli/render/execution-progress.d.ts +18 -6
  156. package/build/src/cli/render/execution-progress.js +34 -31
  157. package/build/src/cli/render/kanshi-akuma.d.ts +1 -2
  158. package/build/src/cli/render/kanshi-akuma.js +5 -26
  159. package/build/src/cli/render/kanshi.js +108 -129
  160. package/build/src/cli/render/marks.d.ts +13 -0
  161. package/build/src/cli/render/marks.js +74 -0
  162. package/build/src/cli/render/nuke.js +18 -7
  163. package/build/src/cli/render/receipt.d.ts +10 -4
  164. package/build/src/cli/render/receipt.js +126 -46
  165. package/build/src/cli/render/reconcile.d.ts +5 -0
  166. package/build/src/cli/render/reconcile.js +152 -0
  167. package/build/src/cli/render/refusal.d.ts +21 -4
  168. package/build/src/cli/render/refusal.js +61 -34
  169. package/build/src/cli/render/region.js +3 -2
  170. package/build/src/cli/render/settings.js +4 -14
  171. package/build/src/cli/render/task.d.ts +37 -6
  172. package/build/src/cli/render/task.js +162 -158
  173. package/build/src/cli/render/terminal.d.ts +25 -1
  174. package/build/src/cli/render/terminal.js +105 -18
  175. package/build/src/cli/runtime.d.ts +32 -8
  176. package/build/src/cli/runtime.js +161 -163
  177. package/build/src/cli/selectors.d.ts +5 -2
  178. package/build/src/cli/selectors.js +11 -3
  179. package/build/src/cli/streams.d.ts +11 -0
  180. package/build/src/cli/streams.js +32 -0
  181. package/build/src/cli/usage.d.ts +2 -0
  182. package/build/src/cli/usage.js +12 -8
  183. package/build/src/contract-guidance.js +3 -7
  184. package/build/src/contract-worktree.d.ts +20 -28
  185. package/build/src/contract-worktree.js +18 -70
  186. package/build/src/coordination/durable-file.d.ts +2 -2
  187. package/build/src/coordination/durable-file.js +0 -27
  188. package/build/src/core/facts/codec.d.ts +1 -2
  189. package/build/src/core/facts/codec.js +6 -7
  190. package/build/src/core/facts/gate.d.ts +0 -1
  191. package/build/src/core/facts/gate.js +0 -82
  192. package/build/src/core/facts/types.d.ts +1 -2
  193. package/build/src/core/verbs/abandon.d.ts +2 -6
  194. package/build/src/core/verbs/abandon.js +0 -16
  195. package/build/src/core/verbs/amend.d.ts +0 -1
  196. package/build/src/core/verbs/amend.js +0 -20
  197. package/build/src/core/verbs/arc.d.ts +7 -8
  198. package/build/src/core/verbs/arc.js +2 -19
  199. package/build/src/core/verbs/attestation.d.ts +2 -6
  200. package/build/src/core/verbs/attestation.js +0 -16
  201. package/build/src/core/verbs/bind.d.ts +0 -1
  202. package/build/src/core/verbs/bind.js +0 -16
  203. package/build/src/core/verbs/deliver.d.ts +0 -1
  204. package/build/src/core/verbs/deliver.js +0 -16
  205. package/build/src/core/verbs/placement.d.ts +2 -1
  206. package/build/src/core/verbs/placement.js +10 -59
  207. package/build/src/git/admission.d.ts +6 -4
  208. package/build/src/git/admission.js +4 -0
  209. package/build/src/git/hooks.d.ts +55 -30
  210. package/build/src/git/hooks.js +30 -3
  211. package/build/src/git/identity.d.ts +6 -0
  212. package/build/src/git/identity.js +47 -0
  213. package/build/src/git/integration.d.ts +31 -13
  214. package/build/src/git/integration.js +32 -1
  215. package/build/src/git/nuke.d.ts +10 -1
  216. package/build/src/git/nuke.js +31 -11
  217. package/build/src/git/observe.js +2 -15
  218. package/build/src/git/private-state-seat.d.ts +6 -7
  219. package/build/src/git/private-state-seat.js +8 -6
  220. package/build/src/git/read-observation.d.ts +6 -1
  221. package/build/src/git/read-observation.js +81 -46
  222. package/build/src/git/reconcile.d.ts +117 -40
  223. package/build/src/git/reconcile.js +169 -40
  224. package/build/src/git/scratch.d.ts +7 -4
  225. package/build/src/git/scratch.js +28 -6
  226. package/build/src/git/target-placement.d.ts +53 -38
  227. package/build/src/git/target-placement.js +69 -54
  228. package/build/src/git/tender.d.ts +37 -28
  229. package/build/src/git/tender.js +39 -0
  230. package/build/src/git/terminal-reconcile.js +21 -23
  231. package/build/src/git/terminal-seal.d.ts +8 -6
  232. package/build/src/git/terminal-seal.js +10 -0
  233. package/build/src/git/workspace.d.ts +29 -15
  234. package/build/src/git/workspace.js +28 -2
  235. package/build/src/identity/normalize.js +19 -6
  236. package/build/src/index.d.ts +78 -6
  237. package/build/src/index.js +52 -3
  238. package/build/src/kanshi/read.d.ts +3 -3
  239. package/build/src/kanshi/read.js +21 -21
  240. package/build/src/kanshi/report.d.ts +9 -8
  241. package/build/src/kanshi/roster.d.ts +2 -0
  242. package/build/src/kanshi/roster.js +2 -0
  243. package/build/src/kanshi/select.js +7 -3
  244. package/build/src/library/address.d.ts +3 -7
  245. package/build/src/library/address.js +7 -7
  246. package/build/src/library/akuma-creation.d.ts +35 -33
  247. package/build/src/library/akuma-creation.js +184 -167
  248. package/build/src/library/akumas.d.ts +40 -0
  249. package/build/src/library/akumas.js +84 -0
  250. package/build/src/library/bind.d.ts +107 -13
  251. package/build/src/library/bind.js +29 -23
  252. package/build/src/library/continuation.d.ts +556 -28
  253. package/build/src/library/continuation.js +29 -54
  254. package/build/src/library/contract-composition.d.ts +40 -0
  255. package/build/src/library/contract-composition.js +105 -0
  256. package/build/src/library/contract-creation.d.ts +7 -0
  257. package/build/src/library/contract-creation.js +192 -0
  258. package/build/src/library/contract-execution.d.ts +29 -40
  259. package/build/src/library/contract-execution.js +503 -128
  260. package/build/src/library/contract-operations.d.ts +275 -134
  261. package/build/src/library/contract-operations.js +83 -92
  262. package/build/src/library/contract-outcomes.d.ts +71 -0
  263. package/build/src/library/contract-outcomes.js +32 -0
  264. package/build/src/library/contract-settings.d.ts +25 -0
  265. package/build/src/library/contract-settings.js +135 -0
  266. package/build/src/library/contract-types.d.ts +24 -38
  267. package/build/src/library/delivery.d.ts +530 -10
  268. package/build/src/library/delivery.js +20 -45
  269. package/build/src/library/input.d.ts +3 -1
  270. package/build/src/library/input.js +11 -16
  271. package/build/src/library/invocation.d.ts +87 -0
  272. package/build/src/library/invocation.js +290 -0
  273. package/build/src/library/keiyaku.d.ts +44 -437
  274. package/build/src/library/keiyaku.js +132 -20
  275. package/build/src/library/nuke.d.ts +2 -11
  276. package/build/src/library/nuke.js +70 -57
  277. package/build/src/library/outcome.d.ts +13196 -0
  278. package/build/src/library/outcome.js +487 -0
  279. package/build/src/library/reconcile.d.ts +96 -24
  280. package/build/src/library/reconcile.js +102 -42
  281. package/build/src/library/refusal.d.ts +470 -42
  282. package/build/src/library/refusal.js +55 -143
  283. package/build/src/library/region.d.ts +15 -7
  284. package/build/src/library/region.js +23 -3
  285. package/build/src/library/repo.d.ts +2 -12
  286. package/build/src/library/repo.js +1 -22
  287. package/build/src/library/selection.d.ts +121 -0
  288. package/build/src/library/{fleet.js → selection.js} +177 -160
  289. package/build/src/plugin/public.d.ts +2 -0
  290. package/build/src/protocol/abandon.d.ts +2 -2
  291. package/build/src/protocol/abandon.js +1 -0
  292. package/build/src/protocol/amend.js +1 -0
  293. package/build/src/protocol/arc.d.ts +6 -4
  294. package/build/src/protocol/attempt.d.ts +4 -2
  295. package/build/src/protocol/attempt.js +10 -0
  296. package/build/src/protocol/audit.d.ts +255 -52
  297. package/build/src/protocol/audit.js +63 -5
  298. package/build/src/protocol/bind.d.ts +18 -17
  299. package/build/src/protocol/bind.js +9 -28
  300. package/build/src/protocol/completion.d.ts +256 -22
  301. package/build/src/protocol/completion.js +100 -12
  302. package/build/src/protocol/deliver.d.ts +34 -23
  303. package/build/src/protocol/deliver.js +39 -25
  304. package/build/src/protocol/execution-observation.d.ts +36 -37
  305. package/build/src/protocol/execution-observation.js +7 -9
  306. package/build/src/protocol/intent.d.ts +101 -30
  307. package/build/src/protocol/intent.js +74 -1
  308. package/build/src/protocol/operations.d.ts +570 -64
  309. package/build/src/protocol/operations.js +189 -9
  310. package/build/src/protocol/outcome.d.ts +2 -1
  311. package/build/src/protocol/placement.d.ts +2 -2
  312. package/build/src/protocol/placement.js +3 -1
  313. package/build/src/protocol/progress.d.ts +108 -65
  314. package/build/src/protocol/progress.js +82 -132
  315. package/build/src/protocol/read/status.d.ts +4 -3
  316. package/build/src/protocol/read/status.js +6 -5
  317. package/build/src/protocol/reconcile.d.ts +3 -3
  318. package/build/src/protocol/reconcile.js +4 -0
  319. package/build/src/protocol/reintegrate.d.ts +2 -2
  320. package/build/src/protocol/review.d.ts +30 -12
  321. package/build/src/protocol/review.js +15 -24
  322. package/build/src/protocol/run.d.ts +34 -5
  323. package/build/src/protocol/run.js +24 -12
  324. package/build/src/runtime/proc/windows-launch.exe +0 -0
  325. package/build/src/settings.d.ts +0 -10
  326. package/build/src/settings.js +0 -76
  327. package/build/src/settlement/holder.d.ts +1 -1
  328. package/build/src/settlement/settle.d.ts +25 -16
  329. package/build/src/settlement/settle.js +80 -20
  330. package/build/src/task/board.d.ts +3 -1
  331. package/build/src/task/board.js +13 -17
  332. package/build/src/task/catalog.d.ts +0 -4
  333. package/build/src/task/catalog.js +0 -15
  334. package/build/src/task/compose-language.d.ts +19 -9
  335. package/build/src/task/compose-language.js +30 -20
  336. package/build/src/task/compose.d.ts +7 -37
  337. package/build/src/task/compose.js +20 -2
  338. package/build/src/task/created-observation.d.ts +0 -1
  339. package/build/src/task/created-observation.js +1 -4
  340. package/build/src/task/document.d.ts +12 -2
  341. package/build/src/task/document.js +4 -0
  342. package/build/src/task/identity.d.ts +4 -1
  343. package/build/src/task/identity.js +21 -17
  344. package/build/src/task/index.d.ts +36 -16
  345. package/build/src/task/index.js +103 -96
  346. package/build/src/task/lifecycle-operations.d.ts +1 -1
  347. package/build/src/task/mutation-result.d.ts +647 -586
  348. package/build/src/task/mutation-result.js +79 -46
  349. package/build/src/task/mutation.d.ts +298 -270
  350. package/build/src/task/mutation.js +93 -110
  351. package/build/src/task/operation-types.d.ts +6 -49
  352. package/build/src/task/operations.d.ts +2 -1
  353. package/build/src/task/operations.js +35 -12
  354. package/build/src/task/query.d.ts +9 -3
  355. package/build/src/task/query.js +42 -16
  356. package/build/src/task/store.d.ts +2 -1
  357. package/build/src/task/store.js +10 -14
  358. package/build/src/verification/declaration.d.ts +0 -1
  359. package/build/src/verification/declaration.js +1 -18
  360. package/build/src/verification/execution.d.ts +6 -2
  361. package/build/src/verification/observation.d.ts +1 -1
  362. package/package.json +2 -14
  363. package/build/src/akuma/akuma-product-symbols.d.ts +0 -1
  364. package/build/src/akuma/akuma-product-symbols.js +0 -1
  365. package/build/src/akuma/akuma-product.d.ts +0 -62
  366. package/build/src/akuma/akuma-product.js +0 -293
  367. package/build/src/akuma/fleet-execution.js +0 -181
  368. package/build/src/akuma/fleet-observation.js +0 -91
  369. package/build/src/cli/accepted.d.ts +0 -24
  370. package/build/src/cli/accepted.js +0 -167
  371. package/build/src/cli/commands/akuma-invoke.d.ts +0 -114
  372. package/build/src/cli/commands/akuma-invoke.js +0 -402
  373. package/build/src/cli/commands/contract-invoke.d.ts +0 -34
  374. package/build/src/cli/commands/contract-invoke.js +0 -259
  375. package/build/src/cli/commands/nuke.d.ts +0 -10
  376. package/build/src/cli/commands/nuke.js +0 -20
  377. package/build/src/cli/commands/status-set.d.ts +0 -4
  378. package/build/src/cli/commands/status-set.js +0 -52
  379. package/build/src/cli/commands/task-invoke.d.ts +0 -49
  380. package/build/src/cli/commands/task-invoke.js +0 -306
  381. package/build/src/cli/invoke.d.ts +0 -27
  382. package/build/src/cli/invoke.js +0 -484
  383. package/build/src/cli/render/board.d.ts +0 -3
  384. package/build/src/cli/render/board.js +0 -25
  385. package/build/src/cli/render/status-set.d.ts +0 -5
  386. package/build/src/cli/render/status-set.js +0 -19
  387. package/build/src/cli/render/text.d.ts +0 -3
  388. package/build/src/cli/render/text.js +0 -33
  389. package/build/src/cli/result.d.ts +0 -240
  390. package/build/src/cli/result.js +0 -1
  391. package/build/src/git/result-codec.d.ts +0 -29
  392. package/build/src/git/result-codec.js +0 -309
  393. package/build/src/kanshi/fleet.d.ts +0 -6
  394. package/build/src/kanshi/fleet.js +0 -27
  395. package/build/src/library/audit.d.ts +0 -29
  396. package/build/src/library/audit.js +0 -41
  397. package/build/src/library/catalog.d.ts +0 -68
  398. package/build/src/library/catalog.js +0 -130
  399. package/build/src/library/composition.d.ts +0 -403
  400. package/build/src/library/composition.js +0 -29
  401. package/build/src/library/configuration.d.ts +0 -4
  402. package/build/src/library/configuration.js +0 -2
  403. package/build/src/library/contract-bind.d.ts +0 -31
  404. package/build/src/library/contract-bind.js +0 -140
  405. package/build/src/library/contract-forwarding.d.ts +0 -55
  406. package/build/src/library/contract-forwarding.js +0 -67
  407. package/build/src/library/contract-handle.d.ts +0 -45
  408. package/build/src/library/contract-handle.js +0 -373
  409. package/build/src/library/contract.d.ts +0 -53
  410. package/build/src/library/contract.js +0 -91
  411. package/build/src/library/execution-result.d.ts +0 -243
  412. package/build/src/library/execution-result.js +0 -101
  413. package/build/src/library/execution.d.ts +0 -8
  414. package/build/src/library/execution.js +0 -102
  415. package/build/src/library/fleet.d.ts +0 -83
  416. package/build/src/library/mutation.d.ts +0 -501
  417. package/build/src/library/mutation.js +0 -248
  418. package/build/src/library/result-codec.d.ts +0 -2
  419. package/build/src/library/result-codec.js +0 -12
  420. package/build/src/protocol/result-codec.d.ts +0 -23
  421. package/build/src/protocol/result-codec.js +0 -488
  422. package/build/src/settlement/result-codec.d.ts +0 -2
  423. package/build/src/settlement/result-codec.js +0 -56
  424. package/build/src/task/public.d.ts +0 -2
  425. package/build/src/task/public.js +0 -1
@@ -1,273 +1,656 @@
1
- import { archetypeName } from "../../akuma/identity.js";
2
- import { parseTaskNamespaceSelector } from "../../task/catalog.js";
3
- import { CliUsageError, commandGuide } from "../usage.js";
4
- import { CONTRACT_COMMAND_SPECS } from "./contract-help.js";
5
- export { CONTRACT_COMMAND_SPECS, renderContractHelp, renderContractUsage, } from "./contract-help.js";
6
- function parseAkumaCatalogPath(value) {
7
- if (value === "aku" || value === "aku/")
8
- return { kind: "archetypes" };
9
- if (value === "aku/*/*")
10
- return { kind: "akuma" };
11
- const match = /^aku\/([^/]+)\/?$/u.exec(value);
12
- if (match === null)
13
- return null;
14
- return { kind: "akuma", archetype: archetypeName(match[1]) };
15
- }
16
- function optionalFlag(flags, name) {
17
- const value = flags[name];
18
- return typeof value === "string" ? value : undefined;
19
- }
20
- function refuse(command, message) {
21
- throw new CliUsageError(message, commandGuide(command, CONTRACT_COMMAND_SPECS[command].usage));
22
- }
23
- function parseGateNames(parts, command) {
24
- const value = optionalFlag(parts.flags, "gates");
25
- if (value === undefined)
1
+ import { listArchetypeDefinitions } from "../../akuma/archetype.js";
2
+ import { executionChannel } from "../../akuma/requests.js";
3
+ import { Akumas, Keiyaku, KeiyakuError, nuke } from "../../index.js";
4
+ import { kanshi, observeKanshi, selectKanshi, selectRegion } from "../../kanshi/index.js";
5
+ import { resolveNamedAddress } from "../../library/address.js";
6
+ import { composeContractLibrary, observeKeiyaku } from "../../library/contract-composition.js";
7
+ import { validateArcMarkdown, validateContractMarkdown } from "../../library/input.js";
8
+ import { createKeiyakuHandle } from "../../library/keiyaku.js";
9
+ import { SettingsError, settings } from "../../settings.js";
10
+ import { Tasks } from "../../task/index.js";
11
+ import { actorFromEdge } from "../actor.js";
12
+ import { resolveInvocationCwd } from "../coordinates.js";
13
+ import { BindDraftError, preserveBindDraft } from "../draft.js";
14
+ import { snapshotText } from "../render/akuma-activity.js";
15
+ import { renderAkumaCatalogue, renderArchetypeCatalogue, renderContractCatalogue, renderTaskCatalogue, } from "../render/catalog.js";
16
+ import { renderAccepted, renderContractHistory, renderRetry } from "../render/contract.js";
17
+ import { renderKanshiText } from "../render/kanshi.js";
18
+ import { nukeExitCode, renderNukeText } from "../render/nuke.js";
19
+ import { reconcileHasFailure, renderReconcile } from "../render/reconcile.js";
20
+ import { renderConflictMaterialized, renderRefusal } from "../render/refusal.js";
21
+ import { renderRegionText } from "../render/region.js";
22
+ import { renderSettingsText, settingsJsonValue } from "../render/settings.js";
23
+ import { canonicalContractSelector, contractFromInput, resolveContractId, resolveKanshiContract, } from "../selectors.js";
24
+ import { displayContext, writeJson, writeStdout } from "../streams.js";
25
+ import { CliUsageError, isBlankInput } from "../usage.js";
26
+ import { amendFromCommand } from "./amend.js";
27
+ import { bindFromCommand } from "./bind.js";
28
+ function requiredRepo(coordinates) {
29
+ if (coordinates.repo === undefined)
30
+ throw new CliUsageError("this command requires a resolved Repo");
31
+ return coordinates.repo;
32
+ }
33
+ async function settingsAt(root, home) {
34
+ return settings({
35
+ ...(root === undefined ? {} : { root }),
36
+ ...(home === undefined ? {} : { home }),
37
+ });
38
+ }
39
+ /**
40
+ * The process edge loads one Settings value and hands it to the private composition.
41
+ * A forwarded audit/deliver/review is served by its parent, which loads its own.
42
+ */
43
+ async function contractSettings(command, execution, world, home) {
44
+ const forwarded = executionChannel(execution).kind === "body-request" &&
45
+ (command.command === "audit" || command.command === "deliver" || command.command === "review");
46
+ if (forwarded)
26
47
  return undefined;
27
- if (value === "")
28
- return [];
29
- const names = value.split(",");
30
- if (names.some((name) => name.length === 0)) {
31
- refuse(command, '--gates requires comma-separated names or "" to clear gates');
32
- }
33
- return names;
34
- }
35
- function parseBind(parts) {
36
- const forkOf = optionalFlag(parts.flags, "fork-of");
37
- if (forkOf !== undefined) {
38
- if (parts.stdin)
39
- refuse("bind", "fork bind reads no stdin");
40
- for (const option of ["task", "after", "gates"]) {
41
- if (parts.flags[option] !== undefined)
42
- refuse("bind", `--${option} is not valid with --fork-of`);
43
- }
44
- const target = optionalFlag(parts.flags, "target");
45
- return {
46
- command: "bind",
47
- forkOf,
48
- ...(target === undefined ? {} : { target }),
49
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
50
- output: parts.output,
51
- };
52
- }
53
- if (!parts.stdin)
54
- refuse("bind", "bind requires stdin");
55
- const task = optionalFlag(parts.flags, "task");
56
- const target = optionalFlag(parts.flags, "target");
57
- const after = parts.flags.after === undefined ? [] : Array.isArray(parts.flags.after) ? parts.flags.after : [parts.flags.after];
58
- const gates = parseGateNames(parts, "bind");
59
- return {
60
- command: "bind",
61
- ...(task === undefined ? {} : { task }),
62
- ...(target === undefined ? {} : { target }),
63
- ...(parts.flags.after === undefined ? {} : { after }),
64
- ...(gates === undefined ? {} : { gates }),
65
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
66
- output: parts.output,
67
- };
48
+ return await settingsAt(world ?? undefined, home);
68
49
  }
69
- function parseAmend(parts) {
70
- const contract = parts.positionals[0];
71
- const after = parts.flags.after === undefined ? [] : Array.isArray(parts.flags.after) ? parts.flags.after : [parts.flags.after];
72
- if (parts.flags["clear-after"] === true && after.length > 0)
73
- refuse("amend", "--clear-after and --after are mutually exclusive");
74
- const gates = parseGateNames(parts, "amend");
75
- if (!parts.stdin && parts.flags.after === undefined && parts.flags["clear-after"] !== true && gates === undefined) {
76
- refuse("amend", "amend requires stdin or --after, --clear-after, or --gates");
77
- }
78
- return {
79
- command: "amend",
80
- ...(contract === undefined ? {} : { contract }),
81
- ...(parts.flags.after === undefined ? {} : { after }),
82
- ...(parts.flags["clear-after"] === true ? { clearAfter: true } : {}),
83
- ...(gates === undefined ? {} : { gates }),
84
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
85
- ...(parts.stdin ? { stdin: true } : {}),
86
- output: parts.output,
87
- };
50
+ function draftWarning(error) {
51
+ return { warning: `bind draft could not be preserved: ${error instanceof Error ? error.message : String(error)}` };
88
52
  }
89
- function parseDeliver(parts) {
90
- const contract = parts.positionals[0];
91
- const message = optionalFlag(parts.flags, "message");
92
- return {
93
- command: "deliver",
94
- ...(contract === undefined ? {} : { contract }),
95
- ...(message === undefined ? {} : { message }),
96
- includeDirty: parts.flags["include-dirty"] === true,
97
- materializeConflict: parts.flags["materialize-conflict"] === true,
98
- overwrite: parts.flags.overwrite === true,
99
- output: parts.output,
100
- };
53
+ /** Preserve a refused bind draft at the invocation cwd; coordinates are not yet available. */
54
+ async function bindDraftReceiptAtCwd(input, markdown) {
55
+ try {
56
+ return await preserveBindDraft(await resolveInvocationCwd(input), markdown);
57
+ }
58
+ catch (error) {
59
+ if (error instanceof Error && "executionReceipt" in error)
60
+ throw error;
61
+ return draftWarning(error);
62
+ }
101
63
  }
102
- function parseReview(parts) {
103
- if (Number(parts.flags.satisfied === true) + Number(parts.flags.unsatisfied === true) !== 1) {
104
- refuse("review", "review requires exactly one verdict flag");
64
+ /**
65
+ * The one bind-document admission that runs before coordinate resolution, so a malformed document
66
+ * refuses as a draft-bearing refusal instead of a later Repo/Git failure. Reads the memoized stdin.
67
+ */
68
+ export async function admitBindMarkdown(input) {
69
+ if (isBlankInput(input.markdown))
70
+ throw new CliUsageError("bind requires a nonblank stdin document");
71
+ try {
72
+ validateContractMarkdown(input.markdown);
105
73
  }
106
- const summary = optionalFlag(parts.flags, "summary");
107
- if (parts.stdin === (summary !== undefined)) {
108
- refuse("review", "review requires exactly one of --summary <text> or stdin '-'");
74
+ catch (error) {
75
+ if (error instanceof Error && "executionReceipt" in error)
76
+ throw error;
77
+ if (!(error instanceof TypeError) && !(error instanceof KeiyakuError && error.category === "invalid-input"))
78
+ throw error;
79
+ throw new BindDraftError(error, await bindDraftReceiptAtCwd(input, input.markdown));
109
80
  }
110
- const contract = parts.positionals[0];
111
- return {
112
- command: "review",
113
- ...(contract === undefined ? {} : { contract }),
114
- verdict: parts.flags.satisfied === true ? "satisfied" : "unsatisfied",
115
- ...(summary === undefined ? {} : { summary }),
116
- ...(parts.stdin ? { summaryFromStdin: true } : {}),
117
- output: parts.output,
118
- };
119
81
  }
120
- function parseStatus(parts) {
121
- if (parts.positionals.length > 1) {
122
- return { command: "status", selectors: parts.positionals, output: parts.output };
82
+ async function bindDraftReceipt(world, markdown) {
83
+ try {
84
+ return await preserveBindDraft(await world(), markdown);
123
85
  }
124
- const contract = parts.positionals[0];
125
- if (contract?.startsWith("aku/") === true) {
126
- return { command: "status", contract, akuma: true, output: parts.output };
86
+ catch (error) {
87
+ if (error instanceof Error && "executionReceipt" in error)
88
+ throw error;
89
+ return draftWarning(error);
127
90
  }
128
- return { command: "status", ...(contract === undefined ? {} : { contract }), output: parts.output };
129
91
  }
130
- function parseRegion(parts) {
131
- const contract = parts.positionals[0];
132
- const pathFlag = parts.flags.path;
133
- const paths = pathFlag === undefined ? undefined : Array.isArray(pathFlag) ? pathFlag : [pathFlag];
134
- if (paths !== undefined && contract !== undefined)
135
- refuse("region", "--path cannot combine with a contract");
92
+ function refusedInvocation(answer, project) {
93
+ const refusal = project === undefined ? answer.refusal : project(answer.refusal);
136
94
  return {
137
- command: "region",
138
- ...(contract === undefined ? {} : { contract }),
139
- ...(paths === undefined ? {} : { paths: paths }),
140
- output: parts.output,
95
+ operation: answer.operation,
96
+ ...(answer.contract === undefined ? {} : { contract: answer.contract }),
97
+ refusal,
141
98
  };
142
99
  }
143
- function akumaCatalogQuery(query, parts) {
144
- const limit = optionalFlag(parts.flags, "limit");
145
- if (query.kind !== "akuma") {
146
- if (limit !== undefined)
147
- refuse("ls", "--limit requires an Akuma instance directory");
148
- return query;
100
+ /** The CLI's own presentation of a refused dirty delivery: the available opt-in is not SDK evidence. */
101
+ function deliverRefusalProjection(refusal) {
102
+ if (refusal.kind !== "dirty-workspace")
103
+ return refusal;
104
+ const submodules = "submodules" in refusal && Array.isArray(refusal.submodules) ? refusal.submodules : [];
105
+ return { ...refusal, option: { flag: "--include-dirty", available: submodules.length === 0 } };
106
+ }
107
+ function contractExitCode(answer) {
108
+ return answer.kind === "refused" ? 1 : answer.kind === "retry" ? 2 : 0;
109
+ }
110
+ function renderContractAnswer(answer, project, context) {
111
+ switch (answer.kind) {
112
+ case "handoff":
113
+ return renderConflictMaterialized(answer.value, context);
114
+ case "refused":
115
+ return renderRefusal(refusedInvocation(answer, project), undefined, context);
116
+ case "retry":
117
+ return renderRetry(answer, context);
118
+ case "accepted":
119
+ return renderAccepted(answer, context);
149
120
  }
150
- if (limit !== undefined && (!/^[1-9][0-9]*$/u.test(limit) || !Number.isSafeInteger(Number(limit))))
151
- refuse("ls", "--limit requires a positive safe integer");
121
+ }
122
+ async function finishContractAnswer(answer, output, project) {
123
+ if (output === "json")
124
+ writeJson(answer);
125
+ else
126
+ writeStdout(renderContractAnswer(answer, project, displayContext()));
127
+ return contractExitCode(answer);
128
+ }
129
+ async function selectedContract(repo, selector, scope) {
130
+ const id = await resolveContractId(repo, selector, scope);
131
+ return { id, contract: contractFromInput(repo, id).contract };
132
+ }
133
+ async function existingSeat(command, coordinates, runtime, library) {
134
+ const repo = requiredRepo(coordinates);
135
+ const id = await resolveContractId(repo, command.contract, coordinates.cwd);
136
+ const actor = "actor" in command ? actorFromEdge(command.actor, runtime.environment) : undefined;
152
137
  return {
153
- ...query,
154
- ...(limit === undefined ? {} : { limit: Number(limit) }),
138
+ id,
139
+ contract: library.select({ repo, id }),
140
+ ...(actor === undefined ? {} : { actor }),
155
141
  };
156
142
  }
157
- function listLimit(parts) {
158
- const limit = optionalFlag(parts.flags, "limit");
159
- if (limit !== undefined && (!/^[1-9][0-9]*$/u.test(limit) || !Number.isSafeInteger(Number(limit))))
160
- refuse("ls", "--limit requires a positive safe integer");
161
- return limit === undefined ? undefined : Number(limit);
162
- }
163
- function taskCatalogQuery(path, limit) {
164
- if (path === "task" || path === "task/") {
165
- return { kind: "tasks", namespace: [], ...(limit === undefined ? {} : { limit }) };
166
- }
167
- if (!path.startsWith("task/"))
168
- return null;
169
- if (!path.endsWith("/"))
170
- refuse("ls", `invalid Task namespace selector: ${path}`);
171
- const body = path.slice("task/".length, -1);
172
- if (body.length === 0 || body.split("/").some((segment) => segment.length === 0))
173
- refuse("ls", `invalid Task namespace selector: ${path}`);
143
+ /** One composition for every mutation leaf; gates, hooks, and freshness derive lazily inside it. */
144
+ async function contractLibrary(command, execution, configuration, runtime) {
145
+ const actor = executionChannel(execution).kind === "local" && ["audit", "deliver", "review"].includes(command.command)
146
+ ? actorFromEdge(undefined, runtime.environment)
147
+ : undefined;
148
+ return composeContractLibrary(execution, createKeiyakuHandle, {
149
+ ...(configuration === undefined ? {} : { settings: configuration }),
150
+ ...(actor === undefined ? {} : { actor }),
151
+ });
152
+ }
153
+ async function runBind(command, input, library) {
154
+ const { coordinates, runtime } = input;
155
+ const repo = requiredRepo(coordinates);
156
+ const actor = actorFromEdge(command.actor, runtime.environment);
157
+ if (command.forkOf !== undefined) {
158
+ const answer = await bindFromCommand({
159
+ command,
160
+ repo,
161
+ library,
162
+ ...(actor === undefined ? {} : { actor }),
163
+ });
164
+ return await finishContractAnswer(answer, command.output);
165
+ }
166
+ const markdown = await runtime.readStdin();
167
+ if (isBlankInput(markdown))
168
+ throw new CliUsageError("bind requires a nonblank stdin document");
174
169
  try {
175
- const namespace = parseTaskNamespaceSelector(path);
176
- return { kind: "tasks", namespace, ...(limit === undefined ? {} : { limit }) };
170
+ validateContractMarkdown(markdown);
177
171
  }
178
172
  catch (error) {
179
- refuse("ls", error instanceof Error ? error.message : `invalid Task namespace selector: ${path}`);
180
- }
181
- }
182
- function parseLs(parts) {
183
- const path = parts.positionals[0];
184
- const limit = listLimit(parts);
185
- const taskQuery = taskCatalogQuery(path, limit);
186
- if (taskQuery !== null)
187
- return { command: "ls", query: taskQuery, output: parts.output };
188
- if (path === "kei" || path === "kei/") {
189
- return {
190
- command: "ls",
191
- query: { kind: "contracts", ...(limit === undefined ? {} : { limit }) },
192
- output: parts.output,
193
- };
173
+ if (!(error instanceof TypeError) && !(error instanceof KeiyakuError && error.category === "invalid-input"))
174
+ throw error;
175
+ throw new BindDraftError(error, await bindDraftReceipt(coordinates.establishWorld, markdown));
176
+ }
177
+ try {
178
+ const answer = await bindFromCommand({
179
+ command,
180
+ repo,
181
+ library,
182
+ markdown,
183
+ ...(actor === undefined ? {} : { actor }),
184
+ });
185
+ if (answer.kind !== "refused")
186
+ return await finishContractAnswer(answer, command.output);
187
+ const draft = await bindDraftReceipt(coordinates.establishWorld, markdown);
188
+ if (command.output === "json")
189
+ writeJson(answer);
190
+ else
191
+ writeStdout(renderRefusal(refusedInvocation(answer), draft, displayContext()));
192
+ return 1;
193
+ }
194
+ catch (error) {
195
+ if (error instanceof Error && "executionReceipt" in error)
196
+ throw error;
197
+ // A selected Settings namespace failure is the Contract owner's invalid input, not a bad draft.
198
+ if (error instanceof KeiyakuError && error.category === "invalid-input" && error.cause instanceof SettingsError)
199
+ throw error;
200
+ if (!(error instanceof TypeError) && !(error instanceof KeiyakuError && error.category === "invalid-input"))
201
+ throw error;
202
+ throw new BindDraftError(error, await bindDraftReceipt(coordinates.establishWorld, markdown));
203
+ }
204
+ }
205
+ async function runAmend(command, input, seat) {
206
+ const { coordinates, runtime } = input;
207
+ const markdown = command.stdin === true ? await runtime.readStdin() : undefined;
208
+ if (markdown !== undefined && isBlankInput(markdown))
209
+ throw new CliUsageError("amend requires a nonblank stdin document");
210
+ const answer = await amendFromCommand({
211
+ command,
212
+ repo: requiredRepo(coordinates),
213
+ contract: seat.contract,
214
+ ...(markdown === undefined ? {} : { markdown }),
215
+ ...(command.gates === undefined ? {} : { gates: command.gates }),
216
+ ...(seat.actor === undefined ? {} : { actor: seat.actor }),
217
+ });
218
+ return await finishContractAnswer(answer, command.output);
219
+ }
220
+ async function runDeliver(command, runtime, seat) {
221
+ const driver = command.output === "text" ? await runtime.progress() : undefined;
222
+ let answer;
223
+ try {
224
+ answer = await seat.contract.deliver({
225
+ ...(command.message === undefined ? {} : { message: command.message }),
226
+ includeDirty: command.includeDirty,
227
+ materializeConflict: command.materializeConflict,
228
+ overwrite: command.overwrite,
229
+ ...(runtime.signal === undefined ? {} : { signal: runtime.signal }),
230
+ }, { ...(driver === undefined ? {} : { observe: driver.observe }) });
231
+ }
232
+ finally {
233
+ if (driver !== undefined)
234
+ await driver.finish().catch(() => undefined);
235
+ }
236
+ return await finishContractAnswer(answer, command.output, deliverRefusalProjection);
237
+ }
238
+ async function runReview(command, runtime, seat) {
239
+ const summary = command.summaryFromStdin === true ? await runtime.readStdin() : command.summary;
240
+ if (command.summaryFromStdin === true && isBlankInput(summary ?? ""))
241
+ throw new CliUsageError("review requires a nonblank summary");
242
+ const driver = command.output === "text" ? await runtime.progress() : undefined;
243
+ let answer;
244
+ try {
245
+ answer = await seat.contract.review({
246
+ verdict: command.verdict,
247
+ ...(summary === undefined ? {} : { summary }),
248
+ ...(runtime.signal === undefined ? {} : { signal: runtime.signal }),
249
+ }, { ...(driver === undefined ? {} : { observe: driver.observe }) });
194
250
  }
251
+ finally {
252
+ if (driver !== undefined)
253
+ await driver.finish().catch(() => undefined);
254
+ }
255
+ return await finishContractAnswer(answer, command.output);
256
+ }
257
+ async function runArc(command, runtime, seat) {
258
+ const markdown = await runtime.readStdin();
195
259
  try {
196
- const query = parseAkumaCatalogPath(path);
197
- if (query === null)
198
- refuse("ls", "ls requires a supported identity directory selector");
199
- return { command: "ls", query: akumaCatalogQuery(query, parts), output: parts.output };
260
+ validateArcMarkdown(markdown);
200
261
  }
201
262
  catch (error) {
202
- if (error instanceof CliUsageError)
263
+ if (!(error instanceof TypeError) && !(error instanceof KeiyakuError && error.category === "invalid-input"))
203
264
  throw error;
204
- refuse("ls", error instanceof Error ? error.message : "invalid ls directory");
265
+ const refusal = { kind: "invalid-document", diagnostic: error.message };
266
+ if (command.output === "json")
267
+ writeJson({ kind: "refused", operation: "arc", contract: seat.id, refusal });
268
+ else
269
+ writeStdout(renderRefusal({ operation: "arc", contract: seat.id, refusal }, undefined, displayContext()));
270
+ return 1;
271
+ }
272
+ const answer = await seat.contract.arc({
273
+ markdown,
274
+ ...(seat.actor === undefined ? {} : { actor: seat.actor }),
275
+ });
276
+ return await finishContractAnswer(answer, command.output);
277
+ }
278
+ async function runAbandon(command, seat) {
279
+ const answer = await seat.contract.abandon({
280
+ ...(seat.actor === undefined ? {} : { actor: seat.actor }),
281
+ ...(command.note === undefined ? {} : { note: command.note }),
282
+ });
283
+ return await finishContractAnswer(answer, command.output);
284
+ }
285
+ async function runAudit(command, runtime, seat) {
286
+ const driver = command.output === "text" ? await runtime.progress() : undefined;
287
+ let answer;
288
+ try {
289
+ answer = await seat.contract.audit({
290
+ includeDirty: command.includeDirty,
291
+ showDiff: command.showDiff,
292
+ ...(runtime.signal === undefined ? {} : { signal: runtime.signal }),
293
+ }, { ...(driver === undefined ? {} : { observe: driver.observe }) });
294
+ }
295
+ finally {
296
+ if (driver !== undefined)
297
+ await driver.finish().catch(() => undefined);
205
298
  }
299
+ return await finishContractAnswer(answer, command.output, deliverRefusalProjection);
206
300
  }
207
- export function parseContractCommand(parts) {
208
- switch (parts.command) {
209
- case "bind":
210
- return parseBind(parts);
301
+ async function runContractMutation(command, input) {
302
+ const library = await contractLibrary(command, input.execution, input.configuration, input.runtime);
303
+ if (command.command === "bind")
304
+ return await runBind(command, input, library);
305
+ const seat = await existingSeat(command, input.coordinates, input.runtime, library);
306
+ switch (command.command) {
211
307
  case "amend":
212
- return parseAmend(parts);
308
+ return await runAmend(command, input, seat);
213
309
  case "deliver":
214
- return parseDeliver(parts);
310
+ return await runDeliver(command, input.runtime, seat);
215
311
  case "review":
216
- return parseReview(parts);
217
- case "arc": {
218
- const contract = parts.positionals[0];
219
- return {
220
- command: "arc",
221
- ...(contract === undefined ? {} : { contract }),
222
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
223
- output: parts.output,
224
- };
225
- }
226
- case "abandon": {
227
- const contract = parts.positionals[0];
228
- const note = optionalFlag(parts.flags, "note");
229
- return {
230
- command: "abandon",
231
- ...(contract === undefined ? {} : { contract }),
232
- ...(note === undefined ? {} : { note }),
233
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
234
- output: parts.output,
235
- };
236
- }
237
- case "status":
238
- return parseStatus(parts);
239
- case "show": {
240
- const contract = parts.positionals[0];
241
- return { command: "show", ...(contract === undefined ? {} : { contract }), output: parts.output };
242
- }
243
- case "ls":
244
- return parseLs(parts);
245
- case "audit": {
246
- const contract = parts.positionals[0];
247
- return {
248
- command: "audit",
249
- ...(contract === undefined ? {} : { contract }),
250
- includeDirty: parts.flags["include-dirty"] === true,
251
- showDiff: parts.flags.diff === true,
252
- output: parts.output,
253
- };
254
- }
255
- case "reconcile": {
256
- const contract = parts.positionals[0];
257
- return {
258
- command: "reconcile",
259
- ...(contract === undefined ? {} : { contract }),
260
- retryHooks: parts.flags["retry-hooks"] === true,
261
- output: parts.output,
262
- };
312
+ return await runReview(command, input.runtime, seat);
313
+ case "arc":
314
+ return await runArc(command, input.runtime, seat);
315
+ case "abandon":
316
+ return await runAbandon(command, seat);
317
+ case "audit":
318
+ return await runAudit(command, input.runtime, seat);
319
+ }
320
+ }
321
+ function statusRefusal(operation, contract) {
322
+ return { operation, contract, refusal: { kind: "contract-missing", contractId: contract } };
323
+ }
324
+ async function runSettings(coordinates, home, output) {
325
+ const value = await settingsAt(coordinates.world ?? undefined, home);
326
+ if (output === "json")
327
+ writeJson(settingsJsonValue(value));
328
+ else
329
+ writeStdout(renderSettingsText(value, displayContext().columns));
330
+ return 0;
331
+ }
332
+ async function runNuke(command, coordinates) {
333
+ if (coordinates.world === null)
334
+ throw new CliUsageError("no Keiyaku world contains the invocation cwd");
335
+ const result = await nuke({
336
+ world: coordinates.world,
337
+ ...(command.confirm === undefined ? {} : { confirm: command.confirm }),
338
+ });
339
+ if (command.output === "json")
340
+ writeJson(result);
341
+ else
342
+ writeStdout(renderNukeText(result));
343
+ return nukeExitCode(result);
344
+ }
345
+ async function runLs(command, coordinates, home) {
346
+ const query = command.query;
347
+ if (query.kind === "contracts") {
348
+ const list = await Keiyaku.with().list({
349
+ repo: requiredRepo(coordinates),
350
+ ...(query.limit === undefined ? {} : { limit: query.limit }),
351
+ });
352
+ if (command.output === "json")
353
+ writeJson(list);
354
+ else
355
+ writeStdout(renderContractCatalogue(list));
356
+ return 0;
357
+ }
358
+ if (query.kind === "archetypes") {
359
+ const list = await listArchetypeDefinitions({
360
+ ...(coordinates.world === null ? {} : { project: coordinates.world }),
361
+ ...(query.limit === undefined ? {} : { limit: query.limit }),
362
+ ...(home === undefined ? {} : { home }),
363
+ });
364
+ if (command.output === "json")
365
+ writeJson(list);
366
+ else
367
+ writeStdout(renderArchetypeCatalogue(list));
368
+ return 0;
369
+ }
370
+ if (coordinates.world === null)
371
+ throw new CliUsageError("no Keiyaku world contains the invocation cwd");
372
+ if (query.kind === "tasks") {
373
+ const listed = await Tasks.of(coordinates.world).list({
374
+ selection: "all",
375
+ namespace: query.namespace ?? [],
376
+ ...(query.limit === undefined ? {} : { limit: query.limit }),
377
+ });
378
+ if (listed.kind !== "accepted")
379
+ throw new Error("Task list did not return an accepted observation");
380
+ if (command.output === "json")
381
+ writeJson(listed);
382
+ else
383
+ writeStdout(renderTaskCatalogue(listed.value, query.namespace ?? []));
384
+ return 0;
385
+ }
386
+ const listed = await Akumas.of(coordinates.world).list({
387
+ ...(query.archetype === undefined ? {} : { archetype: query.archetype }),
388
+ ...(query.limit === undefined ? {} : { limit: query.limit }),
389
+ });
390
+ if (command.output === "json")
391
+ writeJson(listed);
392
+ else
393
+ writeStdout(renderAkumaCatalogue(listed, query.archetype ?? null));
394
+ return 0;
395
+ }
396
+ async function readAkumaStatus(akuma, alias, coordinates) {
397
+ if (coordinates.world === null)
398
+ throw new CliUsageError("no Keiyaku world contains the Akuma selector");
399
+ const status = await Akumas.of(coordinates.world).status({
400
+ akuma,
401
+ ...(coordinates.repo === undefined ? {} : { repo: coordinates.repo }),
402
+ });
403
+ return {
404
+ value: status,
405
+ project: () => snapshotText(status, displayContext(), ...(alias === undefined ? [{}] : [{ alias }])),
406
+ };
407
+ }
408
+ async function readContractStatus(selector, coordinates, named) {
409
+ const repo = requiredRepo(coordinates);
410
+ if (selector !== undefined && selector.startsWith("@")) {
411
+ if (named === undefined)
412
+ throw new CliUsageError("cannot resolve a named status selector");
413
+ const address = resolveNamedAddress({ selector, report: named.report, aliases: named.aliases });
414
+ if (address.kind === "akuma")
415
+ throw new CliUsageError("named status selector resolved to an Akuma");
416
+ const report = await kanshi({ world: coordinates.world, repo, contract: address.id });
417
+ return { value: report, project: () => renderKanshiText(report, displayContext(), "contract") };
418
+ }
419
+ const contract = selector === undefined ? undefined : canonicalContractSelector(selector);
420
+ const report = await kanshi({ world: coordinates.world, repo, ...(contract === undefined ? {} : { contract }) });
421
+ return { value: report, project: () => renderKanshiText(report, displayContext(), "contract") };
422
+ }
423
+ async function namedStatus(selector, coordinates, named) {
424
+ if (named === undefined)
425
+ throw new CliUsageError("cannot resolve a named status selector");
426
+ const address = resolveNamedAddress({ selector, report: named.report, aliases: named.aliases });
427
+ if (address.kind === "akuma")
428
+ return await readAkumaStatus(address.id, selector, coordinates);
429
+ return await readContractStatus(address.id, coordinates, named);
430
+ }
431
+ async function runStatusGuidance(command, coordinates) {
432
+ const repo = coordinates.repo;
433
+ if (repo === undefined)
434
+ throw new CliUsageError("cannot select a contract while the Contract world is absent");
435
+ const selected = await selectedContract(repo, command.contract, coordinates.cwd);
436
+ const guidance = await selected.contract.guidance();
437
+ if (guidance === null) {
438
+ if (command.output === "json")
439
+ writeJson(null);
440
+ else
441
+ writeStdout(renderRefusal(statusRefusal("status", selected.id), undefined, displayContext()));
442
+ return 1;
443
+ }
444
+ if (command.output === "json")
445
+ writeJson(guidance);
446
+ else
447
+ writeStdout(guidance);
448
+ return 0;
449
+ }
450
+ async function runStatusSelection(command, coordinates) {
451
+ const selectors = command.selectors;
452
+ if (selectors.length < 2)
453
+ throw new CliUsageError("status requires at least two selectors");
454
+ if (selectors.some((selector) => !selector.startsWith("aku/") && !selector.startsWith("@")) &&
455
+ coordinates.repo === undefined)
456
+ throw new CliUsageError("cannot select a contract while the Contract world is absent");
457
+ const named = selectors.some((selector) => selector.startsWith("@"))
458
+ ? await observeKanshi({
459
+ world: coordinates.world,
460
+ ...(coordinates.repo === undefined ? {} : { repo: coordinates.repo }),
461
+ })
462
+ : undefined;
463
+ const values = [];
464
+ const blocks = [];
465
+ for (const selector of selectors) {
466
+ const resolved = selector.startsWith("aku/")
467
+ ? await readAkumaStatus(selector, undefined, coordinates)
468
+ : selector.startsWith("@")
469
+ ? await namedStatus(selector, coordinates, named)
470
+ : await readContractStatus(selector, coordinates, named);
471
+ values.push(resolved.value);
472
+ if (command.output === "text")
473
+ blocks.push(resolved.project());
474
+ }
475
+ if (command.output === "json")
476
+ writeJson(values);
477
+ else
478
+ writeStdout(blocks.join("\n\n"));
479
+ return 0;
480
+ }
481
+ async function runStatus(command, coordinates) {
482
+ if (command.guidance === true)
483
+ return await runStatusGuidance(command, coordinates);
484
+ if ("selectors" in command && command.selectors !== undefined)
485
+ return await runStatusSelection({ ...command, selectors: command.selectors }, coordinates);
486
+ if (command.akuma === true && command.contract !== undefined) {
487
+ const resolved = await readAkumaStatus(command.contract, undefined, coordinates);
488
+ if (command.output === "json")
489
+ writeJson(resolved.value);
490
+ else
491
+ writeStdout(resolved.project());
492
+ return 0;
493
+ }
494
+ if (command.contract === undefined) {
495
+ const report = await kanshi({
496
+ world: coordinates.world,
497
+ ...(coordinates.repo === undefined ? {} : { repo: coordinates.repo }),
498
+ });
499
+ if (command.output === "json")
500
+ writeJson(report);
501
+ else
502
+ writeStdout(renderKanshiText(report, displayContext(), "world"));
503
+ return 0;
504
+ }
505
+ if (command.contract.startsWith("@")) {
506
+ const resolved = await namedStatus(command.contract, coordinates, await observeKanshi({
507
+ world: coordinates.world,
508
+ ...(coordinates.repo === undefined ? {} : { repo: coordinates.repo }),
509
+ }));
510
+ if (command.output === "json")
511
+ writeJson(resolved.value);
512
+ else
513
+ writeStdout(resolved.project());
514
+ return 0;
515
+ }
516
+ if (command.contract.startsWith("kei/")) {
517
+ const repo = requiredRepo(coordinates);
518
+ const contract = canonicalContractSelector(command.contract);
519
+ const report = await kanshi({ world: coordinates.world, repo, contract });
520
+ if (report.contracts.kind === "present" && report.contracts.value.rows.length === 0) {
521
+ if (command.output === "json")
522
+ writeJson(statusRefusal("status", contract).refusal);
523
+ else
524
+ writeStdout(renderRefusal(statusRefusal("status", contract), undefined, displayContext()));
525
+ return 1;
263
526
  }
264
- case "nuke": {
265
- const confirm = optionalFlag(parts.flags, "confirm");
266
- return { command: "nuke", ...(confirm === undefined ? {} : { confirm }), output: parts.output };
527
+ if (command.output === "json")
528
+ writeJson(report);
529
+ else
530
+ writeStdout(renderKanshiText(report, displayContext(), "contract"));
531
+ return 0;
532
+ }
533
+ const report = await kanshi({
534
+ world: coordinates.world,
535
+ ...(coordinates.repo === undefined ? {} : { repo: coordinates.repo }),
536
+ });
537
+ const contract = resolveKanshiContract(report, command.contract);
538
+ const selected = selectKanshi({ report, contract });
539
+ if (command.output === "json")
540
+ writeJson(selected);
541
+ else
542
+ writeStdout(renderKanshiText(selected, displayContext(), "contract"));
543
+ return 0;
544
+ }
545
+ async function runRegion(command, coordinates) {
546
+ const repo = requiredRepo(coordinates);
547
+ const emit = (section) => {
548
+ if (command.output === "json")
549
+ writeJson(section);
550
+ else
551
+ writeStdout(renderRegionText(section));
552
+ return 0;
553
+ };
554
+ if (command.paths !== undefined) {
555
+ const report = await kanshi({ world: coordinates.world, repo, region: { kind: "path", patterns: command.paths } });
556
+ return emit(report.region ?? { kind: "absent" });
557
+ }
558
+ const report = await kanshi({ world: coordinates.world, repo, region: { kind: "declarations" } });
559
+ if (command.contract === undefined)
560
+ return emit(report.region ?? { kind: "absent" });
561
+ const contract = resolveKanshiContract(report, command.contract);
562
+ const observed = await observeKeiyaku({ repo, id: contract });
563
+ if (observed.kind === "missing" || observed.row.phase === "claimed" || observed.row.phase === "abandoned") {
564
+ const refusal = {
565
+ kind: observed.kind === "missing" ? "contract-missing" : "terminal",
566
+ contractId: contract,
567
+ };
568
+ if (command.output === "json")
569
+ writeJson(refusal);
570
+ else
571
+ writeStdout(renderRefusal({ operation: "region", contract, refusal }, undefined, displayContext()));
572
+ return 1;
573
+ }
574
+ if (report.region?.kind !== "present" || report.region.value.kind !== "declarations")
575
+ return emit(report.region ?? { kind: "absent" });
576
+ return emit({
577
+ kind: "present",
578
+ value: selectRegion({
579
+ declarations: report.region.value.declarations,
580
+ selection: { kind: "contract", contract },
581
+ }),
582
+ });
583
+ }
584
+ export async function runContractHistoryCommand(command, coordinates) {
585
+ const repo = requiredRepo(coordinates);
586
+ const selected = contractFromInput(repo, command.contract);
587
+ const history = await selected.contract.history();
588
+ if (history === null) {
589
+ const refusal = { kind: "contract-missing", contractId: selected.id };
590
+ if (command.output === "json")
591
+ writeJson(refusal);
592
+ else
593
+ writeStdout(renderRefusal({ operation: "history", contract: selected.id, refusal }, undefined, displayContext()));
594
+ return 1;
595
+ }
596
+ if (command.output === "json")
597
+ writeJson(history);
598
+ else
599
+ writeStdout(renderContractHistory(history, { full: command.full }));
600
+ return 0;
601
+ }
602
+ async function runReconcile(command, coordinates, execution, home) {
603
+ const repo = requiredRepo(coordinates);
604
+ const configuration = await contractSettings(command, execution, coordinates.world, home);
605
+ const library = composeContractLibrary(execution, createKeiyakuHandle, {
606
+ ...(configuration === undefined ? {} : { settings: configuration }),
607
+ });
608
+ let report;
609
+ if (command.contract === undefined) {
610
+ report = await library.reconcile({ repo, retryHooks: command.retryHooks });
611
+ }
612
+ else {
613
+ const selected = await selectedContract(repo, command.contract, coordinates.cwd);
614
+ const observed = await observeKeiyaku({ repo, id: selected.id });
615
+ if (observed.kind === "missing") {
616
+ if (command.output === "json")
617
+ writeJson(statusRefusal("reconcile", selected.id).refusal);
618
+ else
619
+ writeStdout(renderRefusal(statusRefusal("reconcile", selected.id), undefined, displayContext()));
620
+ return 1;
267
621
  }
622
+ report = await library.reconcile({ repo, contract: selected.id, retryHooks: command.retryHooks });
623
+ }
624
+ if (command.output === "json")
625
+ writeJson(report);
626
+ else
627
+ writeStdout(renderReconcile(report, displayContext()));
628
+ return reconcileHasFailure(report) ? 1 : 0;
629
+ }
630
+ export async function runContractCommand(command, coordinates, runtime) {
631
+ const execution = runtime.execution;
632
+ const home = runtime.home;
633
+ switch (command.command) {
268
634
  case "settings":
269
- return { command: "settings", output: parts.output };
635
+ return await runSettings(coordinates, home, command.output);
636
+ case "nuke":
637
+ return await runNuke(command, coordinates);
638
+ case "ls":
639
+ return await runLs(command, coordinates, home);
640
+ case "status":
641
+ return await runStatus(command, coordinates);
270
642
  case "region":
271
- return parseRegion(parts);
643
+ return await runRegion(command, coordinates);
644
+ case "reconcile":
645
+ return await runReconcile(command, coordinates, execution, home);
646
+ default: {
647
+ const configuration = await contractSettings(command, execution, coordinates.world, home);
648
+ return await runContractMutation(command, {
649
+ coordinates,
650
+ runtime,
651
+ execution,
652
+ ...(configuration === undefined ? {} : { configuration }),
653
+ });
654
+ }
272
655
  }
273
656
  }