@astrosheep/keiyaku 4.5.29 → 4.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (418) 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 -18
  10. package/build/src/akuma/akuma-instance.js +65 -175
  11. package/build/src/akuma/akuma-observe.d.ts +3 -21
  12. package/build/src/akuma/akuma-observe.js +7 -24
  13. package/build/src/akuma/{akuma-handle.d.ts → akuma-owner.d.ts} +55 -27
  14. package/build/src/akuma/{akuma-handle.js → akuma-owner.js} +24 -23
  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 -44
  18. package/build/src/akuma/akuma-wait.js +113 -0
  19. package/build/src/akuma/akuma.d.ts +35 -89
  20. package/build/src/akuma/akuma.js +148 -30
  21. package/build/src/akuma/archetype.d.ts +12 -0
  22. package/build/src/akuma/archetype.js +47 -19
  23. package/build/src/akuma/body.d.ts +76 -36
  24. package/build/src/akuma/body.js +84 -49
  25. package/build/src/akuma/call-initial-tell.d.ts +131 -22
  26. package/build/src/akuma/call-initial-tell.js +31 -1
  27. package/build/src/akuma/call-request.d.ts +237 -31
  28. package/build/src/akuma/call-request.js +67 -94
  29. package/build/src/akuma/coordinate.d.ts +15 -5
  30. package/build/src/akuma/coordinate.js +12 -22
  31. package/build/src/akuma/dispatch-association.d.ts +1 -1
  32. package/build/src/akuma/dispatch-association.js +1 -10
  33. package/build/src/akuma/heart/activity-schema.d.ts +325 -0
  34. package/build/src/akuma/heart/activity-schema.js +53 -0
  35. package/build/src/akuma/heart/facts.d.ts +1 -6
  36. package/build/src/akuma/heart/index.d.ts +3 -1
  37. package/build/src/akuma/heart/index.js +4 -1
  38. package/build/src/akuma/heart/rows.d.ts +49 -2
  39. package/build/src/akuma/heart/rows.js +16 -2
  40. package/build/src/akuma/heart/soul.d.ts +1 -0
  41. package/build/src/akuma/heart/soul.js +6 -4
  42. package/build/src/akuma/heart/tells.d.ts +1 -0
  43. package/build/src/akuma/heart/tells.js +18 -0
  44. package/build/src/akuma/identity.d.ts +10 -7
  45. package/build/src/akuma/identity.js +23 -0
  46. package/build/src/akuma/index.d.ts +10 -8
  47. package/build/src/akuma/index.js +2 -2
  48. package/build/src/akuma/nuke.d.ts +3 -0
  49. package/build/src/akuma/nuke.js +13 -7
  50. package/build/src/akuma/projection.d.ts +0 -5
  51. package/build/src/akuma/projection.js +22 -43
  52. package/build/src/akuma/provider-recipe.d.ts +58 -13
  53. package/build/src/akuma/provider-recipe.js +62 -80
  54. package/build/src/akuma/provider.d.ts +6 -76
  55. package/build/src/akuma/provider.js +11 -219
  56. package/build/src/akuma/providers/acp/config.d.ts +2 -0
  57. package/build/src/akuma/providers/acp/config.js +26 -1
  58. package/build/src/akuma/providers/acp/core.d.ts +7 -0
  59. package/build/src/akuma/providers/acp/core.js +49 -18
  60. package/build/src/akuma/providers/acp/index.js +14 -6
  61. package/build/src/akuma/providers/grok-build/index.js +44 -13
  62. package/build/src/akuma/providers/index.d.ts +3 -3
  63. package/build/src/akuma/providers/index.js +2 -13
  64. package/build/src/akuma/providers/opencode-sdk/event-stream.d.ts +28 -0
  65. package/build/src/akuma/providers/opencode-sdk/event-stream.js +92 -0
  66. package/build/src/akuma/providers/opencode-sdk/events.d.ts +0 -1
  67. package/build/src/akuma/providers/opencode-sdk/index.js +200 -64
  68. package/build/src/akuma/providers/opencode-sdk/session.d.ts +41 -1
  69. package/build/src/akuma/providers/opencode-sdk/session.js +69 -2
  70. package/build/src/akuma/providers/pi/events.js +5 -2
  71. package/build/src/akuma/providers/pi/index.d.ts +3 -4
  72. package/build/src/akuma/providers/pi/index.js +99 -45
  73. package/build/src/akuma/publication.d.ts +84 -3
  74. package/build/src/akuma/publication.js +145 -2
  75. package/build/src/akuma/read-pool.d.ts +2 -0
  76. package/build/src/akuma/read-pool.js +15 -0
  77. package/build/src/akuma/request-rendezvous.js +10 -0
  78. package/build/src/akuma/request-serve.js +7 -0
  79. package/build/src/akuma/request-wire.d.ts +14 -26
  80. package/build/src/akuma/request-wire.js +4 -0
  81. package/build/src/akuma/requests.d.ts +0 -2
  82. package/build/src/akuma/requests.js +0 -17
  83. package/build/src/akuma/{fleet-observation.d.ts → selection-observation.d.ts} +37 -36
  84. package/build/src/akuma/selection-observation.js +65 -0
  85. package/build/src/akuma/{fleet-owner-port.d.ts → selection-owner-port.d.ts} +3 -3
  86. package/build/src/akuma/{fleet-owner-port.js → selection-owner-port.js} +11 -17
  87. package/build/src/akuma/{fleet-request.d.ts → selection-request.d.ts} +42 -82
  88. package/build/src/akuma/{fleet-request.js → selection-request.js} +92 -136
  89. package/build/src/akuma/turn-drive.js +73 -14
  90. package/build/src/akuma-body.js +91 -56
  91. package/build/src/body/amend.d.ts +5 -0
  92. package/build/src/body/amend.js +26 -50
  93. package/build/src/body/arc.d.ts +4 -2
  94. package/build/src/body/arc.js +19 -26
  95. package/build/src/body/criteria.d.ts +6 -0
  96. package/build/src/body/criteria.js +37 -0
  97. package/build/src/body/decode.js +5 -42
  98. package/build/src/body/region.d.ts +5 -0
  99. package/build/src/body/region.js +45 -2
  100. package/build/src/body/render.js +2 -4
  101. package/build/src/cli/activity.d.ts +26 -0
  102. package/build/src/cli/activity.js +75 -0
  103. package/build/src/cli/actor.d.ts +3 -1
  104. package/build/src/cli/actor.js +15 -2
  105. package/build/src/cli/commands/akuma-grammar.d.ts +75 -0
  106. package/build/src/cli/commands/akuma-grammar.js +414 -0
  107. package/build/src/cli/commands/akuma.d.ts +5 -69
  108. package/build/src/cli/commands/akuma.js +352 -319
  109. package/build/src/cli/commands/amend.d.ts +4 -5
  110. package/build/src/cli/commands/amend.js +1 -2
  111. package/build/src/cli/commands/bind.d.ts +4 -5
  112. package/build/src/cli/commands/bind.js +7 -10
  113. package/build/src/cli/commands/contract-grammar.d.ts +112 -0
  114. package/build/src/cli/commands/contract-grammar.js +282 -0
  115. package/build/src/cli/commands/contract-help.d.ts +17 -22
  116. package/build/src/cli/commands/contract-help.js +37 -24
  117. package/build/src/cli/commands/contract.d.ts +18 -97
  118. package/build/src/cli/commands/contract.js +621 -233
  119. package/build/src/cli/commands/install.d.ts +1 -1
  120. package/build/src/cli/commands/install.js +2 -2
  121. package/build/src/cli/commands/task-grammar.d.ts +19 -0
  122. package/build/src/cli/commands/task-grammar.js +438 -0
  123. package/build/src/cli/commands/task-query.js +23 -104
  124. package/build/src/cli/commands/task.d.ts +5 -20
  125. package/build/src/cli/commands/task.js +414 -364
  126. package/build/src/cli/coordinates.d.ts +10 -0
  127. package/build/src/cli/coordinates.js +20 -0
  128. package/build/src/cli/draft.d.ts +7 -1
  129. package/build/src/cli/main.js +10 -1
  130. package/build/src/cli/parse.d.ts +8 -9
  131. package/build/src/cli/parse.js +62 -62
  132. package/build/src/cli/render/akuma-activity.d.ts +54 -36
  133. package/build/src/cli/render/akuma-activity.js +262 -242
  134. package/build/src/cli/render/akuma-tool.d.ts +8 -4
  135. package/build/src/cli/render/akuma-tool.js +6 -5
  136. package/build/src/cli/render/akuma.d.ts +36 -16
  137. package/build/src/cli/render/akuma.js +65 -132
  138. package/build/src/cli/render/audit.d.ts +6 -2
  139. package/build/src/cli/render/audit.js +59 -28
  140. package/build/src/cli/render/catalog.d.ts +11 -2
  141. package/build/src/cli/render/catalog.js +75 -95
  142. package/build/src/cli/render/contract-history.d.ts +3 -1
  143. package/build/src/cli/render/contract-history.js +215 -22
  144. package/build/src/cli/render/contract-observation.d.ts +10 -5
  145. package/build/src/cli/render/contract-observation.js +29 -46
  146. package/build/src/cli/render/contract.d.ts +10 -3
  147. package/build/src/cli/render/contract.js +252 -103
  148. package/build/src/cli/render/effects.d.ts +26 -0
  149. package/build/src/cli/render/effects.js +41 -0
  150. package/build/src/cli/render/execution-progress.d.ts +18 -6
  151. package/build/src/cli/render/execution-progress.js +34 -31
  152. package/build/src/cli/render/kanshi-akuma.d.ts +1 -2
  153. package/build/src/cli/render/kanshi-akuma.js +5 -26
  154. package/build/src/cli/render/kanshi.js +107 -128
  155. package/build/src/cli/render/marks.d.ts +13 -0
  156. package/build/src/cli/render/marks.js +74 -0
  157. package/build/src/cli/render/nuke.js +18 -7
  158. package/build/src/cli/render/receipt.d.ts +10 -4
  159. package/build/src/cli/render/receipt.js +124 -44
  160. package/build/src/cli/render/reconcile.d.ts +5 -0
  161. package/build/src/cli/render/reconcile.js +152 -0
  162. package/build/src/cli/render/refusal.d.ts +21 -4
  163. package/build/src/cli/render/refusal.js +60 -33
  164. package/build/src/cli/render/region.js +3 -2
  165. package/build/src/cli/render/settings.js +2 -12
  166. package/build/src/cli/render/task.d.ts +37 -6
  167. package/build/src/cli/render/task.js +161 -157
  168. package/build/src/cli/render/terminal.d.ts +20 -1
  169. package/build/src/cli/render/terminal.js +92 -18
  170. package/build/src/cli/runtime.d.ts +32 -8
  171. package/build/src/cli/runtime.js +157 -165
  172. package/build/src/cli/selectors.d.ts +5 -2
  173. package/build/src/cli/selectors.js +11 -3
  174. package/build/src/cli/streams.d.ts +11 -0
  175. package/build/src/cli/streams.js +32 -0
  176. package/build/src/cli/usage.d.ts +2 -0
  177. package/build/src/cli/usage.js +12 -8
  178. package/build/src/contract-guidance.js +3 -7
  179. package/build/src/contract-worktree.d.ts +20 -28
  180. package/build/src/contract-worktree.js +18 -70
  181. package/build/src/coordination/durable-file.d.ts +2 -2
  182. package/build/src/coordination/durable-file.js +0 -27
  183. package/build/src/core/facts/codec.d.ts +1 -2
  184. package/build/src/core/facts/codec.js +6 -7
  185. package/build/src/core/facts/gate.d.ts +0 -1
  186. package/build/src/core/facts/gate.js +0 -82
  187. package/build/src/core/facts/types.d.ts +1 -2
  188. package/build/src/core/verbs/abandon.d.ts +2 -6
  189. package/build/src/core/verbs/abandon.js +0 -16
  190. package/build/src/core/verbs/amend.d.ts +0 -1
  191. package/build/src/core/verbs/amend.js +0 -20
  192. package/build/src/core/verbs/arc.d.ts +7 -8
  193. package/build/src/core/verbs/arc.js +2 -19
  194. package/build/src/core/verbs/attestation.d.ts +2 -6
  195. package/build/src/core/verbs/attestation.js +0 -16
  196. package/build/src/core/verbs/bind.d.ts +0 -1
  197. package/build/src/core/verbs/bind.js +0 -16
  198. package/build/src/core/verbs/deliver.d.ts +0 -1
  199. package/build/src/core/verbs/deliver.js +0 -16
  200. package/build/src/core/verbs/placement.d.ts +2 -1
  201. package/build/src/core/verbs/placement.js +10 -59
  202. package/build/src/git/admission.d.ts +6 -4
  203. package/build/src/git/admission.js +4 -0
  204. package/build/src/git/hooks.d.ts +55 -30
  205. package/build/src/git/hooks.js +30 -3
  206. package/build/src/git/identity.d.ts +6 -0
  207. package/build/src/git/identity.js +47 -0
  208. package/build/src/git/integration.d.ts +31 -13
  209. package/build/src/git/integration.js +32 -1
  210. package/build/src/git/nuke.d.ts +10 -1
  211. package/build/src/git/nuke.js +31 -11
  212. package/build/src/git/observe.js +2 -15
  213. package/build/src/git/private-state-seat.d.ts +6 -7
  214. package/build/src/git/private-state-seat.js +8 -6
  215. package/build/src/git/read-observation.d.ts +6 -1
  216. package/build/src/git/read-observation.js +81 -46
  217. package/build/src/git/reconcile.d.ts +117 -40
  218. package/build/src/git/reconcile.js +169 -40
  219. package/build/src/git/scratch.d.ts +7 -4
  220. package/build/src/git/scratch.js +28 -6
  221. package/build/src/git/target-placement.d.ts +53 -38
  222. package/build/src/git/target-placement.js +69 -54
  223. package/build/src/git/tender.d.ts +37 -28
  224. package/build/src/git/tender.js +39 -0
  225. package/build/src/git/terminal-reconcile.js +21 -23
  226. package/build/src/git/terminal-seal.d.ts +8 -6
  227. package/build/src/git/terminal-seal.js +10 -0
  228. package/build/src/git/workspace.d.ts +29 -15
  229. package/build/src/git/workspace.js +28 -2
  230. package/build/src/identity/normalize.js +19 -6
  231. package/build/src/index.d.ts +78 -7
  232. package/build/src/index.js +52 -4
  233. package/build/src/kanshi/read.d.ts +3 -3
  234. package/build/src/kanshi/read.js +21 -21
  235. package/build/src/kanshi/report.d.ts +9 -8
  236. package/build/src/kanshi/roster.d.ts +2 -0
  237. package/build/src/kanshi/roster.js +2 -0
  238. package/build/src/kanshi/select.js +7 -3
  239. package/build/src/library/address.d.ts +3 -7
  240. package/build/src/library/address.js +7 -7
  241. package/build/src/library/akuma-creation.d.ts +21 -32
  242. package/build/src/library/akuma-creation.js +148 -165
  243. package/build/src/library/akumas.d.ts +20 -22
  244. package/build/src/library/akumas.js +43 -20
  245. package/build/src/library/bind.d.ts +107 -13
  246. package/build/src/library/bind.js +29 -23
  247. package/build/src/library/continuation.d.ts +556 -28
  248. package/build/src/library/continuation.js +29 -54
  249. package/build/src/library/contract-composition.d.ts +40 -0
  250. package/build/src/library/contract-composition.js +105 -0
  251. package/build/src/library/contract-creation.d.ts +7 -0
  252. package/build/src/library/contract-creation.js +192 -0
  253. package/build/src/library/contract-execution.d.ts +29 -40
  254. package/build/src/library/contract-execution.js +503 -128
  255. package/build/src/library/contract-operations.d.ts +275 -134
  256. package/build/src/library/contract-operations.js +83 -92
  257. package/build/src/library/contract-outcomes.d.ts +71 -0
  258. package/build/src/library/contract-outcomes.js +32 -0
  259. package/build/src/library/contract-settings.d.ts +25 -0
  260. package/build/src/library/contract-settings.js +135 -0
  261. package/build/src/library/contract-types.d.ts +17 -38
  262. package/build/src/library/delivery.d.ts +530 -10
  263. package/build/src/library/delivery.js +20 -45
  264. package/build/src/library/input.d.ts +3 -1
  265. package/build/src/library/input.js +11 -16
  266. package/build/src/library/invocation.d.ts +87 -0
  267. package/build/src/library/invocation.js +290 -0
  268. package/build/src/library/keiyaku.d.ts +45 -22
  269. package/build/src/library/keiyaku.js +134 -8
  270. package/build/src/library/nuke.d.ts +2 -11
  271. package/build/src/library/nuke.js +70 -57
  272. package/build/src/library/outcome.d.ts +13196 -0
  273. package/build/src/library/outcome.js +487 -0
  274. package/build/src/library/reconcile.d.ts +96 -24
  275. package/build/src/library/reconcile.js +102 -42
  276. package/build/src/library/refusal.d.ts +470 -42
  277. package/build/src/library/refusal.js +55 -143
  278. package/build/src/library/region.d.ts +15 -7
  279. package/build/src/library/region.js +23 -3
  280. package/build/src/library/repo.d.ts +2 -12
  281. package/build/src/library/repo.js +1 -22
  282. package/build/src/library/selection.d.ts +121 -0
  283. package/build/src/library/{fleet.js → selection.js} +169 -152
  284. package/build/src/plugin/public.d.ts +2 -0
  285. package/build/src/protocol/abandon.d.ts +2 -2
  286. package/build/src/protocol/abandon.js +1 -0
  287. package/build/src/protocol/amend.js +1 -0
  288. package/build/src/protocol/arc.d.ts +6 -4
  289. package/build/src/protocol/attempt.d.ts +4 -2
  290. package/build/src/protocol/attempt.js +10 -0
  291. package/build/src/protocol/audit.d.ts +255 -52
  292. package/build/src/protocol/audit.js +63 -5
  293. package/build/src/protocol/bind.d.ts +18 -17
  294. package/build/src/protocol/bind.js +9 -28
  295. package/build/src/protocol/completion.d.ts +256 -22
  296. package/build/src/protocol/completion.js +100 -12
  297. package/build/src/protocol/deliver.d.ts +34 -23
  298. package/build/src/protocol/deliver.js +39 -25
  299. package/build/src/protocol/execution-observation.d.ts +36 -37
  300. package/build/src/protocol/execution-observation.js +7 -9
  301. package/build/src/protocol/intent.d.ts +101 -30
  302. package/build/src/protocol/intent.js +74 -1
  303. package/build/src/protocol/operations.d.ts +570 -64
  304. package/build/src/protocol/operations.js +189 -9
  305. package/build/src/protocol/outcome.d.ts +2 -1
  306. package/build/src/protocol/placement.d.ts +2 -2
  307. package/build/src/protocol/placement.js +3 -1
  308. package/build/src/protocol/progress.d.ts +108 -65
  309. package/build/src/protocol/progress.js +82 -132
  310. package/build/src/protocol/read/status.d.ts +4 -3
  311. package/build/src/protocol/read/status.js +6 -5
  312. package/build/src/protocol/reconcile.d.ts +3 -3
  313. package/build/src/protocol/reconcile.js +4 -0
  314. package/build/src/protocol/reintegrate.d.ts +2 -2
  315. package/build/src/protocol/review.d.ts +30 -12
  316. package/build/src/protocol/review.js +15 -24
  317. package/build/src/protocol/run.d.ts +34 -5
  318. package/build/src/protocol/run.js +24 -12
  319. package/build/src/runtime/proc/windows-launch.exe +0 -0
  320. package/build/src/settings.d.ts +0 -10
  321. package/build/src/settings.js +0 -76
  322. package/build/src/settlement/holder.d.ts +1 -1
  323. package/build/src/settlement/settle.d.ts +25 -16
  324. package/build/src/settlement/settle.js +80 -20
  325. package/build/src/task/board.d.ts +3 -1
  326. package/build/src/task/board.js +13 -17
  327. package/build/src/task/catalog.d.ts +0 -4
  328. package/build/src/task/catalog.js +0 -15
  329. package/build/src/task/compose-language.d.ts +19 -9
  330. package/build/src/task/compose-language.js +30 -20
  331. package/build/src/task/compose.d.ts +7 -37
  332. package/build/src/task/compose.js +20 -2
  333. package/build/src/task/created-observation.d.ts +0 -1
  334. package/build/src/task/created-observation.js +1 -4
  335. package/build/src/task/document.d.ts +12 -2
  336. package/build/src/task/document.js +4 -0
  337. package/build/src/task/identity.d.ts +4 -1
  338. package/build/src/task/identity.js +21 -17
  339. package/build/src/task/index.d.ts +36 -16
  340. package/build/src/task/index.js +103 -96
  341. package/build/src/task/lifecycle-operations.d.ts +1 -1
  342. package/build/src/task/mutation-result.d.ts +647 -586
  343. package/build/src/task/mutation-result.js +79 -46
  344. package/build/src/task/mutation.d.ts +298 -270
  345. package/build/src/task/mutation.js +93 -110
  346. package/build/src/task/operation-types.d.ts +6 -49
  347. package/build/src/task/operations.d.ts +2 -1
  348. package/build/src/task/operations.js +35 -12
  349. package/build/src/task/query.d.ts +9 -3
  350. package/build/src/task/query.js +42 -16
  351. package/build/src/task/store.d.ts +2 -1
  352. package/build/src/task/store.js +10 -14
  353. package/build/src/verification/declaration.d.ts +0 -1
  354. package/build/src/verification/declaration.js +1 -18
  355. package/build/src/verification/execution.d.ts +6 -2
  356. package/build/src/verification/observation.d.ts +1 -1
  357. package/package.json +2 -18
  358. package/build/src/akuma/akuma-product.d.ts +0 -58
  359. package/build/src/akuma/akuma-product.js +0 -276
  360. package/build/src/akuma/fleet-execution.js +0 -234
  361. package/build/src/akuma/fleet-observation.js +0 -97
  362. package/build/src/cli/accepted.d.ts +0 -24
  363. package/build/src/cli/accepted.js +0 -167
  364. package/build/src/cli/catalog.d.ts +0 -45
  365. package/build/src/cli/catalog.js +0 -1
  366. package/build/src/cli/commands/akuma-invoke.d.ts +0 -114
  367. package/build/src/cli/commands/akuma-invoke.js +0 -375
  368. package/build/src/cli/commands/contract-invoke.d.ts +0 -34
  369. package/build/src/cli/commands/contract-invoke.js +0 -259
  370. package/build/src/cli/commands/nuke.d.ts +0 -10
  371. package/build/src/cli/commands/nuke.js +0 -20
  372. package/build/src/cli/commands/status-set.d.ts +0 -4
  373. package/build/src/cli/commands/status-set.js +0 -52
  374. package/build/src/cli/commands/task-invoke.d.ts +0 -49
  375. package/build/src/cli/commands/task-invoke.js +0 -306
  376. package/build/src/cli/invoke.d.ts +0 -27
  377. package/build/src/cli/invoke.js +0 -521
  378. package/build/src/cli/render/board.d.ts +0 -3
  379. package/build/src/cli/render/board.js +0 -25
  380. package/build/src/cli/render/status-set.d.ts +0 -5
  381. package/build/src/cli/render/status-set.js +0 -19
  382. package/build/src/cli/render/text.d.ts +0 -3
  383. package/build/src/cli/render/text.js +0 -33
  384. package/build/src/cli/result.d.ts +0 -240
  385. package/build/src/cli/result.js +0 -1
  386. package/build/src/git/result-codec.d.ts +0 -29
  387. package/build/src/git/result-codec.js +0 -309
  388. package/build/src/kanshi/fleet.d.ts +0 -6
  389. package/build/src/kanshi/fleet.js +0 -27
  390. package/build/src/library/audit.d.ts +0 -29
  391. package/build/src/library/audit.js +0 -41
  392. package/build/src/library/composition.d.ts +0 -15
  393. package/build/src/library/composition.js +0 -28
  394. package/build/src/library/configuration.d.ts +0 -4
  395. package/build/src/library/configuration.js +0 -2
  396. package/build/src/library/contract-bind.d.ts +0 -31
  397. package/build/src/library/contract-bind.js +0 -140
  398. package/build/src/library/contract-forwarding.d.ts +0 -55
  399. package/build/src/library/contract-forwarding.js +0 -67
  400. package/build/src/library/contract-handle.d.ts +0 -50
  401. package/build/src/library/contract-handle.js +0 -385
  402. package/build/src/library/contract.d.ts +0 -46
  403. package/build/src/library/contract.js +0 -73
  404. package/build/src/library/execution-result.d.ts +0 -243
  405. package/build/src/library/execution-result.js +0 -101
  406. package/build/src/library/execution.d.ts +0 -8
  407. package/build/src/library/execution.js +0 -102
  408. package/build/src/library/fleet.d.ts +0 -83
  409. package/build/src/library/mutation.d.ts +0 -501
  410. package/build/src/library/mutation.js +0 -248
  411. package/build/src/library/result-codec.d.ts +0 -2
  412. package/build/src/library/result-codec.js +0 -12
  413. package/build/src/protocol/result-codec.d.ts +0 -23
  414. package/build/src/protocol/result-codec.js +0 -488
  415. package/build/src/settlement/result-codec.d.ts +0 -2
  416. package/build/src/settlement/result-codec.js +0 -56
  417. package/build/src/task/public.d.ts +0 -2
  418. package/build/src/task/public.js +0 -1
@@ -1,268 +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 (limit !== undefined && (!/^[1-9][0-9]*$/u.test(limit) || !Number.isSafeInteger(Number(limit))))
146
- refuse("ls", "--limit requires a positive safe integer");
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);
120
+ }
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;
147
137
  return {
148
- ...query,
149
- ...(limit === undefined ? {} : { limit: Number(limit) }),
138
+ id,
139
+ contract: library.select({ repo, id }),
140
+ ...(actor === undefined ? {} : { actor }),
150
141
  };
151
142
  }
152
- function listLimit(parts) {
153
- const limit = optionalFlag(parts.flags, "limit");
154
- if (limit !== undefined && (!/^[1-9][0-9]*$/u.test(limit) || !Number.isSafeInteger(Number(limit))))
155
- refuse("ls", "--limit requires a positive safe integer");
156
- return limit === undefined ? undefined : Number(limit);
157
- }
158
- function taskCatalogQuery(path, limit) {
159
- if (path === "task" || path === "task/") {
160
- return { kind: "tasks", namespace: [], ...(limit === undefined ? {} : { limit }) };
161
- }
162
- if (!path.startsWith("task/"))
163
- return null;
164
- if (!path.endsWith("/"))
165
- refuse("ls", `invalid Task namespace selector: ${path}`);
166
- const body = path.slice("task/".length, -1);
167
- if (body.length === 0 || body.split("/").some((segment) => segment.length === 0))
168
- 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");
169
169
  try {
170
- const namespace = parseTaskNamespaceSelector(path);
171
- return { kind: "tasks", namespace, ...(limit === undefined ? {} : { limit }) };
170
+ validateContractMarkdown(markdown);
172
171
  }
173
172
  catch (error) {
174
- refuse("ls", error instanceof Error ? error.message : `invalid Task namespace selector: ${path}`);
175
- }
176
- }
177
- function parseLs(parts) {
178
- const path = parts.positionals[0];
179
- const limit = listLimit(parts);
180
- const taskQuery = taskCatalogQuery(path, limit);
181
- if (taskQuery !== null)
182
- return { command: "ls", query: taskQuery, output: parts.output };
183
- if (path === "kei" || path === "kei/") {
184
- return {
185
- command: "ls",
186
- query: { kind: "contracts", ...(limit === undefined ? {} : { limit }) },
187
- output: parts.output,
188
- };
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));
189
176
  }
190
177
  try {
191
- const query = parseAkumaCatalogPath(path);
192
- if (query === null)
193
- refuse("ls", "ls requires a supported identity directory selector");
194
- return { command: "ls", query: akumaCatalogQuery(query, parts), output: parts.output };
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;
195
193
  }
196
194
  catch (error) {
197
- if (error instanceof CliUsageError)
195
+ if (error instanceof Error && "executionReceipt" in error)
198
196
  throw error;
199
- refuse("ls", error instanceof Error ? error.message : "invalid ls directory");
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));
200
203
  }
201
204
  }
202
- export function parseContractCommand(parts) {
203
- switch (parts.command) {
204
- case "bind":
205
- return parseBind(parts);
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 }) });
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();
259
+ try {
260
+ validateArcMarkdown(markdown);
261
+ }
262
+ catch (error) {
263
+ if (!(error instanceof TypeError) && !(error instanceof KeiyakuError && error.category === "invalid-input"))
264
+ throw error;
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);
298
+ }
299
+ return await finishContractAnswer(answer, command.output, deliverRefusalProjection);
300
+ }
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) {
206
307
  case "amend":
207
- return parseAmend(parts);
308
+ return await runAmend(command, input, seat);
208
309
  case "deliver":
209
- return parseDeliver(parts);
310
+ return await runDeliver(command, input.runtime, seat);
210
311
  case "review":
211
- return parseReview(parts);
212
- case "arc": {
213
- const contract = parts.positionals[0];
214
- return {
215
- command: "arc",
216
- ...(contract === undefined ? {} : { contract }),
217
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
218
- output: parts.output,
219
- };
220
- }
221
- case "abandon": {
222
- const contract = parts.positionals[0];
223
- const note = optionalFlag(parts.flags, "note");
224
- return {
225
- command: "abandon",
226
- ...(contract === undefined ? {} : { contract }),
227
- ...(note === undefined ? {} : { note }),
228
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
229
- output: parts.output,
230
- };
231
- }
232
- case "status":
233
- return parseStatus(parts);
234
- case "show": {
235
- const contract = parts.positionals[0];
236
- return { command: "show", ...(contract === undefined ? {} : { contract }), output: parts.output };
237
- }
238
- case "ls":
239
- return parseLs(parts);
240
- case "audit": {
241
- const contract = parts.positionals[0];
242
- return {
243
- command: "audit",
244
- ...(contract === undefined ? {} : { contract }),
245
- includeDirty: parts.flags["include-dirty"] === true,
246
- showDiff: parts.flags["show-diff"] === true,
247
- output: parts.output,
248
- };
249
- }
250
- case "reconcile": {
251
- const contract = parts.positionals[0];
252
- return {
253
- command: "reconcile",
254
- ...(contract === undefined ? {} : { contract }),
255
- retryHooks: parts.flags["retry-hooks"] === true,
256
- output: parts.output,
257
- };
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;
258
526
  }
259
- case "nuke": {
260
- const confirm = optionalFlag(parts.flags, "confirm");
261
- 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;
262
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) {
263
634
  case "settings":
264
- 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);
265
642
  case "region":
266
- 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
+ }
267
655
  }
268
656
  }