@astrosheep/keiyaku 4.6.30 → 4.6.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (398) hide show
  1. package/README.md +5 -5
  2. package/build/plugins/claude/.claude-plugin/plugin.json +1 -1
  3. package/build/plugins/claude/skills/keiyaku/SKILL.md +12 -12
  4. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +16 -16
  5. package/build/plugins/claude/skills/keiyaku-akuma/references/automation.md +14 -14
  6. package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +10 -10
  7. package/build/plugins/claude/skills/keiyaku-bind/SKILL.md +15 -15
  8. package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +16 -16
  9. package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +21 -21
  10. package/build/plugins/codex/.codex-plugin/plugin.json +1 -1
  11. package/build/plugins/codex/skills/keiyaku/SKILL.md +12 -12
  12. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +16 -16
  13. package/build/plugins/codex/skills/keiyaku-akuma/references/automation.md +14 -14
  14. package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +10 -10
  15. package/build/plugins/codex/skills/keiyaku-bind/SKILL.md +15 -15
  16. package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +16 -16
  17. package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +21 -21
  18. package/build/plugins/opencode/package.json +1 -1
  19. package/build/plugins/opencode/skills/keiyaku/SKILL.md +12 -12
  20. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +16 -16
  21. package/build/plugins/opencode/skills/keiyaku-akuma/references/automation.md +14 -14
  22. package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +10 -10
  23. package/build/plugins/opencode/skills/keiyaku-bind/SKILL.md +15 -15
  24. package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +16 -16
  25. package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +21 -21
  26. package/build/plugins/pi/README.md +5 -5
  27. package/build/plugins/pi/akuma-tools.ts +17 -23
  28. package/build/skills/keiyaku/SKILL.md +12 -12
  29. package/build/skills/keiyaku-akuma/SKILL.md +16 -16
  30. package/build/skills/keiyaku-akuma/references/automation.md +14 -14
  31. package/build/skills/keiyaku-babysit/SKILL.md +10 -10
  32. package/build/skills/keiyaku-bind/SKILL.md +15 -15
  33. package/build/skills/keiyaku-debt/SKILL.md +16 -16
  34. package/build/skills/keiyaku-workflow/SKILL.md +21 -21
  35. package/build/src/akuma/akuma-call.d.ts +1 -1
  36. package/build/src/akuma/akuma-call.js +9 -9
  37. package/build/src/akuma/akuma-errors.d.ts +5 -5
  38. package/build/src/akuma/akuma-instance.d.ts +355 -12
  39. package/build/src/akuma/akuma-instance.js +20 -20
  40. package/build/src/akuma/akuma-observe.d.ts +11 -12
  41. package/build/src/akuma/akuma-observe.js +34 -26
  42. package/build/src/akuma/akuma-owner.d.ts +32 -11
  43. package/build/src/akuma/akuma-owner.js +35 -16
  44. package/build/src/akuma/akuma-probe.d.ts +3 -3
  45. package/build/src/akuma/akuma-probe.js +2 -2
  46. package/build/src/akuma/akuma-selection-execution.d.ts +985 -1
  47. package/build/src/akuma/akuma-selection-execution.js +42 -18
  48. package/build/src/akuma/akuma-stream.d.ts +2 -2
  49. package/build/src/akuma/akuma-stream.js +1 -1
  50. package/build/src/akuma/akuma-wait.d.ts +5 -5
  51. package/build/src/akuma/akuma-wait.js +52 -14
  52. package/build/src/akuma/akuma.d.ts +245 -271
  53. package/build/src/akuma/akuma.js +98 -46
  54. package/build/src/akuma/archetype.d.ts +19 -6
  55. package/build/src/akuma/archetype.js +25 -9
  56. package/build/src/akuma/body-launch.d.ts +2 -2
  57. package/build/src/akuma/body.js +4 -4
  58. package/build/src/akuma/call-initial-tell.d.ts +60 -44
  59. package/build/src/akuma/call-initial-tell.js +41 -2
  60. package/build/src/akuma/caller.d.ts +26 -17
  61. package/build/src/akuma/caller.js +22 -9
  62. package/build/src/akuma/coordinate.d.ts +9 -0
  63. package/build/src/akuma/coordinate.js +13 -0
  64. package/build/src/akuma/detached-body.js +2 -2
  65. package/build/src/akuma/dispatch-association.d.ts +4 -4
  66. package/build/src/akuma/dispatch-association.js +12 -3
  67. package/build/src/akuma/execution-instructions.js +2 -2
  68. package/build/src/akuma/heart/facts.d.ts +29 -7
  69. package/build/src/akuma/heart/facts.js +13 -0
  70. package/build/src/akuma/heart/index.d.ts +0 -3
  71. package/build/src/akuma/heart/index.js +3 -6
  72. package/build/src/akuma/heart/rows.js +2 -2
  73. package/build/src/akuma/heart/soul.js +5 -5
  74. package/build/src/akuma/identity.d.ts +17 -16
  75. package/build/src/akuma/identity.js +20 -19
  76. package/build/src/akuma/index.d.ts +1 -2
  77. package/build/src/akuma/lineage-cache.d.ts +4 -4
  78. package/build/src/akuma/lineage-cache.js +10 -10
  79. package/build/src/akuma/projection-read.d.ts +2 -5
  80. package/build/src/akuma/projection-read.js +34 -47
  81. package/build/src/akuma/projection.d.ts +659 -569
  82. package/build/src/akuma/projection.js +203 -94
  83. package/build/src/akuma/providers/acp/index.js +1 -1
  84. package/build/src/akuma/providers/execution-environment.d.ts +1 -3
  85. package/build/src/akuma/providers/execution-environment.js +0 -4
  86. package/build/src/akuma/publication.d.ts +2 -2
  87. package/build/src/akuma/publication.js +3 -3
  88. package/build/src/akuma/retention.js +2 -2
  89. package/build/src/akuma/selection-observation.d.ts +507 -43
  90. package/build/src/akuma/selection-observation.js +153 -1
  91. package/build/src/akuma/status-projection.d.ts +288 -0
  92. package/build/src/akuma/status-projection.js +154 -0
  93. package/build/src/akuma/turn-drive.js +0 -3
  94. package/build/src/alias/index.d.ts +9 -4
  95. package/build/src/alias/index.js +11 -9
  96. package/build/src/bounded-list.d.ts +8 -0
  97. package/build/src/bounded-list.js +9 -0
  98. package/build/src/cli/commands/akuma-grammar.d.ts +2 -2
  99. package/build/src/cli/commands/akuma-grammar.js +21 -21
  100. package/build/src/cli/commands/akuma.d.ts +1 -2
  101. package/build/src/cli/commands/akuma.js +115 -251
  102. package/build/src/cli/commands/contract-grammar.d.ts +4 -3
  103. package/build/src/cli/commands/contract-grammar.js +39 -22
  104. package/build/src/cli/commands/contract-help.d.ts +3 -1
  105. package/build/src/cli/commands/contract-help.js +4 -3
  106. package/build/src/cli/commands/contract.d.ts +6 -3
  107. package/build/src/cli/commands/contract.js +203 -434
  108. package/build/src/cli/commands/debt.d.ts +2 -3
  109. package/build/src/cli/commands/debt.js +101 -317
  110. package/build/src/cli/commands/report.js +11 -28
  111. package/build/src/cli/commands/whoami.d.ts +3 -43
  112. package/build/src/cli/commands/whoami.js +8 -121
  113. package/build/src/cli/coordinates.d.ts +4 -35
  114. package/build/src/cli/coordinates.js +13 -129
  115. package/build/src/cli/parse.d.ts +0 -6
  116. package/build/src/cli/parse.js +5 -48
  117. package/build/src/cli/render/akuma-activity.d.ts +31 -16
  118. package/build/src/cli/render/akuma-activity.js +157 -149
  119. package/build/src/cli/render/akuma-tool.d.ts +3 -6
  120. package/build/src/cli/render/akuma-tool.js +20 -14
  121. package/build/src/cli/render/akuma.d.ts +25 -26
  122. package/build/src/cli/render/akuma.js +100 -129
  123. package/build/src/cli/render/catalog.d.ts +4 -7
  124. package/build/src/cli/render/catalog.js +52 -99
  125. package/build/src/cli/render/contract-history.d.ts +3 -1
  126. package/build/src/cli/render/contract-history.js +140 -215
  127. package/build/src/cli/render/contract-observation.d.ts +43 -30
  128. package/build/src/cli/render/contract-observation.js +64 -31
  129. package/build/src/cli/render/contract-wait.js +6 -6
  130. package/build/src/cli/render/contract.d.ts +41 -6
  131. package/build/src/cli/render/contract.js +274 -370
  132. package/build/src/cli/render/debt.d.ts +9 -19
  133. package/build/src/cli/render/debt.js +120 -185
  134. package/build/src/cli/render/delivery-preview.d.ts +4 -3
  135. package/build/src/cli/render/delivery-preview.js +68 -96
  136. package/build/src/cli/render/kanshi-akuma.d.ts +4 -4
  137. package/build/src/cli/render/kanshi-akuma.js +70 -59
  138. package/build/src/cli/render/kanshi.d.ts +4 -4
  139. package/build/src/cli/render/kanshi.js +205 -221
  140. package/build/src/cli/render/marks.d.ts +11 -2
  141. package/build/src/cli/render/marks.js +13 -3
  142. package/build/src/cli/render/nuke.d.ts +3 -3
  143. package/build/src/cli/render/nuke.js +13 -16
  144. package/build/src/cli/render/receipt.d.ts +37 -43
  145. package/build/src/cli/render/receipt.js +313 -236
  146. package/build/src/cli/render/reconcile.d.ts +6 -4
  147. package/build/src/cli/render/reconcile.js +53 -137
  148. package/build/src/cli/render/refusal.d.ts +3 -2
  149. package/build/src/cli/render/refusal.js +73 -54
  150. package/build/src/cli/render/region.d.ts +11 -2
  151. package/build/src/cli/render/region.js +17 -23
  152. package/build/src/cli/render/settings.d.ts +0 -1
  153. package/build/src/cli/render/settings.js +8 -17
  154. package/build/src/cli/render/terminal.d.ts +2 -0
  155. package/build/src/cli/render/verbs.d.ts +4 -0
  156. package/build/src/cli/render/verbs.js +312 -0
  157. package/build/src/cli/render/whoami.d.ts +1 -1
  158. package/build/src/cli/render/whoami.js +24 -31
  159. package/build/src/cli/runtime.d.ts +3 -11
  160. package/build/src/cli/runtime.js +96 -79
  161. package/build/src/cli/scan.d.ts +1 -1
  162. package/build/src/cli/streams.js +1 -0
  163. package/build/src/contract-guidance.js +2 -2
  164. package/build/src/contract-worktree.d.ts +2 -15
  165. package/build/src/contract-worktree.js +19 -35
  166. package/build/src/core/facts/observation.d.ts +4 -5
  167. package/build/src/core/facts/observation.js +7 -9
  168. package/build/src/core/verbs/amend.d.ts +0 -1
  169. package/build/src/core/verbs/amend.js +3 -3
  170. package/build/src/core/verbs/bind.d.ts +0 -1
  171. package/build/src/core/verbs/bind.js +5 -5
  172. package/build/src/core/verbs/deliver.d.ts +3 -2
  173. package/build/src/core/verbs/deliver.js +2 -2
  174. package/build/src/core/verbs/placement.d.ts +0 -5
  175. package/build/src/core/verbs/placement.js +4 -6
  176. package/build/src/core/verbs/reintegrate.d.ts +0 -1
  177. package/build/src/core/verbs/reintegrate.js +2 -2
  178. package/build/src/debt/board.d.ts +132 -116
  179. package/build/src/debt/board.js +138 -94
  180. package/build/src/debt/catalog.d.ts +4 -4
  181. package/build/src/debt/catalog.js +2 -18
  182. package/build/src/debt/context.d.ts +15 -3
  183. package/build/src/debt/context.js +12 -1
  184. package/build/src/debt/created-observation.d.ts +5 -17
  185. package/build/src/debt/created-observation.js +14 -6
  186. package/build/src/debt/document.d.ts +20 -15
  187. package/build/src/debt/document.js +18 -1
  188. package/build/src/debt/index.d.ts +346 -23
  189. package/build/src/debt/index.js +68 -22
  190. package/build/src/debt/input.d.ts +2 -1
  191. package/build/src/debt/input.js +14 -0
  192. package/build/src/debt/lifecycle-operations.d.ts +2 -2
  193. package/build/src/debt/lifecycle-operations.js +14 -22
  194. package/build/src/debt/operation-types.d.ts +188 -66
  195. package/build/src/debt/operation-types.js +113 -1
  196. package/build/src/debt/operations.d.ts +11 -10
  197. package/build/src/debt/operations.js +46 -71
  198. package/build/src/debt/query.d.ts +14 -10
  199. package/build/src/debt/query.js +3 -12
  200. package/build/src/debt/store.d.ts +4 -2
  201. package/build/src/debt/store.js +8 -8
  202. package/build/src/debt/view.d.ts +0 -3
  203. package/build/src/debt/view.js +0 -4
  204. package/build/src/dispatch/index.d.ts +22 -5
  205. package/build/src/dispatch/index.js +46 -37
  206. package/build/src/git/admission.d.ts +2 -2
  207. package/build/src/git/admission.js +2 -1
  208. package/build/src/git/hooks.d.ts +14 -35
  209. package/build/src/git/hooks.js +45 -25
  210. package/build/src/git/integration.d.ts +6 -24
  211. package/build/src/git/integration.js +10 -16
  212. package/build/src/git/private-state-seat.d.ts +2 -2
  213. package/build/src/git/private-state-seat.js +2 -1
  214. package/build/src/git/reconcile.d.ts +17 -79
  215. package/build/src/git/reconcile.js +37 -52
  216. package/build/src/git/scratch.d.ts +3 -3
  217. package/build/src/git/scratch.js +4 -1
  218. package/build/src/git/target-placement.d.ts +23 -31
  219. package/build/src/git/target-placement.js +42 -27
  220. package/build/src/git/target.d.ts +2 -2
  221. package/build/src/git/target.js +2 -1
  222. package/build/src/git/tender.d.ts +7 -39
  223. package/build/src/git/tender.js +21 -54
  224. package/build/src/git/terminal-reconcile.js +15 -18
  225. package/build/src/git/terminal-seal.d.ts +2 -4
  226. package/build/src/git/terminal-seal.js +7 -33
  227. package/build/src/git/workspace.d.ts +65 -41
  228. package/build/src/git/workspace.js +45 -14
  229. package/build/src/identity/selector.d.ts +2 -0
  230. package/build/src/identity/selector.js +13 -3
  231. package/build/src/index.d.ts +48 -54
  232. package/build/src/index.js +31 -43
  233. package/build/src/kanshi/counts.d.ts +42 -8
  234. package/build/src/kanshi/counts.js +13 -2
  235. package/build/src/kanshi/index.d.ts +5 -5
  236. package/build/src/kanshi/index.js +4 -3
  237. package/build/src/kanshi/read.d.ts +489 -6
  238. package/build/src/kanshi/read.js +334 -483
  239. package/build/src/kanshi/report.d.ts +2504 -103
  240. package/build/src/kanshi/report.js +165 -1
  241. package/build/src/kanshi/select.d.ts +0 -8
  242. package/build/src/kanshi/select.js +20 -59
  243. package/build/src/library/address.d.ts +8 -8
  244. package/build/src/library/address.js +7 -7
  245. package/build/src/library/akuma-creation.d.ts +690 -84
  246. package/build/src/library/akuma-creation.js +202 -142
  247. package/build/src/library/akuma-retention.d.ts +2 -2
  248. package/build/src/library/akuma-retention.js +2 -2
  249. package/build/src/library/akumas.d.ts +10 -6
  250. package/build/src/library/akumas.js +24 -7
  251. package/build/src/library/bind.d.ts +28 -54
  252. package/build/src/library/bind.js +6 -4
  253. package/build/src/library/continuation.d.ts +197 -479
  254. package/build/src/library/continuation.js +40 -23
  255. package/build/src/library/contract-address.d.ts +6 -5
  256. package/build/src/library/contract-address.js +5 -7
  257. package/build/src/library/contract-composition.d.ts +18 -12
  258. package/build/src/library/contract-composition.js +55 -47
  259. package/build/src/library/contract-creation.d.ts +3 -2
  260. package/build/src/library/contract-creation.js +38 -32
  261. package/build/src/library/contract-execution.js +77 -38
  262. package/build/src/library/contract-outcomes.d.ts +1877 -27
  263. package/build/src/library/contract-outcomes.js +93 -10
  264. package/build/src/library/contract-settings.d.ts +2 -2
  265. package/build/src/library/contract-settings.js +18 -14
  266. package/build/src/library/contract-types.d.ts +238 -61
  267. package/build/src/library/contract-types.js +131 -1
  268. package/build/src/library/contract-wait.d.ts +38 -17
  269. package/build/src/library/contract-wait.js +40 -10
  270. package/build/src/library/delivery.d.ts +588 -36
  271. package/build/src/library/delivery.js +35 -27
  272. package/build/src/library/input.d.ts +1 -1
  273. package/build/src/library/input.js +1 -2
  274. package/build/src/library/invocation.d.ts +11 -7
  275. package/build/src/library/invocation.js +42 -51
  276. package/build/src/library/kei.d.ts +48 -0
  277. package/build/src/library/kei.js +256 -0
  278. package/build/src/library/keiyaku-attribution.d.ts +11 -0
  279. package/build/src/{cli/delivery-identity.js → library/keiyaku-attribution.js} +12 -1
  280. package/build/src/library/keiyaku-classify.d.ts +11 -0
  281. package/build/src/library/keiyaku-classify.js +146 -0
  282. package/build/src/library/keiyaku-coordinates.d.ts +31 -0
  283. package/build/src/library/keiyaku-coordinates.js +103 -0
  284. package/build/src/library/keiyaku-debt.d.ts +142 -0
  285. package/build/src/library/keiyaku-debt.js +188 -0
  286. package/build/src/library/keiyaku-identity.d.ts +58 -0
  287. package/build/src/library/keiyaku-identity.js +176 -0
  288. package/build/src/library/keiyaku-policy.d.ts +27 -0
  289. package/build/src/library/keiyaku-policy.js +44 -0
  290. package/build/src/library/keiyaku-status.d.ts +1487 -0
  291. package/build/src/library/keiyaku-status.js +92 -0
  292. package/build/src/library/keiyaku-verbs.d.ts +6774 -0
  293. package/build/src/library/keiyaku-verbs.js +458 -0
  294. package/build/src/library/keiyaku.d.ts +871 -38
  295. package/build/src/library/keiyaku.js +677 -127
  296. package/build/src/library/nuke.d.ts +22 -0
  297. package/build/src/library/nuke.js +4 -1
  298. package/build/src/library/outcome.d.ts +706 -692
  299. package/build/src/library/outcome.js +582 -167
  300. package/build/src/library/reconcile.d.ts +464 -116
  301. package/build/src/library/reconcile.js +174 -102
  302. package/build/src/library/refusal.d.ts +113 -577
  303. package/build/src/library/refusal.js +64 -51
  304. package/build/src/library/region.d.ts +5 -24
  305. package/build/src/library/region.js +6 -21
  306. package/build/src/library/selection.d.ts +181 -32
  307. package/build/src/library/selection.js +99 -64
  308. package/build/src/mcp/adapter.d.ts +11 -0
  309. package/build/src/mcp/adapter.js +106 -0
  310. package/build/src/mcp/help.d.ts +1 -0
  311. package/build/src/mcp/help.js +26 -0
  312. package/build/src/mcp/index.d.ts +2 -0
  313. package/build/src/mcp/index.js +37 -0
  314. package/build/src/plugin/public.d.ts +1 -1
  315. package/build/src/plugin/runtime.js +17 -14
  316. package/build/src/protocol/arc.d.ts +4 -1
  317. package/build/src/protocol/arc.js +7 -1
  318. package/build/src/protocol/attempt.d.ts +2 -3
  319. package/build/src/protocol/attempt.js +1 -10
  320. package/build/src/protocol/bind.d.ts +6 -7
  321. package/build/src/protocol/bind.js +9 -5
  322. package/build/src/protocol/completion.d.ts +448 -12
  323. package/build/src/protocol/completion.js +164 -26
  324. package/build/src/protocol/deliver.d.ts +26 -24
  325. package/build/src/protocol/deliver.js +24 -52
  326. package/build/src/protocol/delivery-preview.d.ts +97 -247
  327. package/build/src/protocol/delivery-preview.js +132 -128
  328. package/build/src/protocol/execution-observation.d.ts +146 -123
  329. package/build/src/protocol/execution-observation.js +9 -6
  330. package/build/src/protocol/intent.d.ts +9 -48
  331. package/build/src/protocol/intent.js +32 -46
  332. package/build/src/protocol/operations.d.ts +207 -505
  333. package/build/src/protocol/operations.js +81 -134
  334. package/build/src/protocol/placement.d.ts +0 -1
  335. package/build/src/protocol/placement.js +5 -2
  336. package/build/src/protocol/progress.d.ts +7 -97
  337. package/build/src/protocol/progress.js +7 -55
  338. package/build/src/protocol/read/observation.d.ts +13 -6
  339. package/build/src/protocol/read/observation.js +10 -9
  340. package/build/src/protocol/read/status.d.ts +464 -93
  341. package/build/src/protocol/read/status.js +372 -85
  342. package/build/src/protocol/reconcile.d.ts +2 -0
  343. package/build/src/protocol/reconcile.js +12 -11
  344. package/build/src/protocol/reintegrate.d.ts +0 -1
  345. package/build/src/protocol/reintegrate.js +4 -4
  346. package/build/src/protocol/result-leaves.d.ts +528 -0
  347. package/build/src/protocol/result-leaves.js +195 -0
  348. package/build/src/protocol/result-reasons.d.ts +129 -0
  349. package/build/src/protocol/result-reasons.js +87 -0
  350. package/build/src/protocol/review.d.ts +14 -11
  351. package/build/src/protocol/review.js +30 -14
  352. package/build/src/protocol/run.d.ts +4 -4
  353. package/build/src/protocol/run.js +4 -1
  354. package/build/src/protocol/verify.d.ts +359 -30
  355. package/build/src/protocol/verify.js +118 -28
  356. package/build/src/region.d.ts +26 -0
  357. package/build/src/region.js +28 -0
  358. package/build/src/runtime/proc/diagnostic.d.ts +11 -0
  359. package/build/src/runtime/proc/diagnostic.js +20 -0
  360. package/build/src/runtime/proc/windows-launch.exe +0 -0
  361. package/build/src/settings.d.ts +126 -32
  362. package/build/src/settings.js +107 -34
  363. package/build/src/settlement/settle.d.ts +29 -12
  364. package/build/src/settlement/settle.js +22 -15
  365. package/build/src/verification/declaration.d.ts +1 -3
  366. package/build/src/verification/declaration.js +2 -5
  367. package/build/src/verification/execution.d.ts +7 -19
  368. package/build/src/verification/execution.js +37 -16
  369. package/build/src/verification/observation.d.ts +13 -13
  370. package/build/src/verification/observation.js +9 -7
  371. package/build/src/world.d.ts +8 -0
  372. package/build/src/world.js +7 -0
  373. package/package.json +6 -5
  374. package/plugins/paseo/plugin/server/keiyaku.ts +13 -46
  375. package/plugins/paseo/plugin/server/message.ts +8 -30
  376. package/plugins/paseo/plugin/server/mirror.ts +16 -20
  377. package/plugins/paseo/plugin/server/provider.ts +1 -1
  378. package/plugins/paseo/plugin/server/sdk.ts +14 -6
  379. package/plugins/pi/README.md +5 -5
  380. package/plugins/pi/akuma-tools.ts +17 -23
  381. package/skills/keiyaku/SKILL.md +12 -12
  382. package/skills/keiyaku-akuma/SKILL.md +16 -16
  383. package/skills/keiyaku-akuma/references/automation.md +14 -14
  384. package/skills/keiyaku-babysit/SKILL.md +10 -10
  385. package/skills/keiyaku-bind/SKILL.md +15 -15
  386. package/skills/keiyaku-debt/SKILL.md +16 -16
  387. package/skills/keiyaku-workflow/SKILL.md +21 -21
  388. package/build/src/cli/actor.d.ts +0 -10
  389. package/build/src/cli/actor.js +0 -24
  390. package/build/src/cli/akuma-caller.d.ts +0 -3
  391. package/build/src/cli/akuma-caller.js +0 -31
  392. package/build/src/cli/delivery-identity.d.ts +0 -3
  393. package/build/src/cli/render/effects.d.ts +0 -26
  394. package/build/src/cli/render/effects.js +0 -41
  395. package/build/src/cli/selectors.d.ts +0 -10
  396. package/build/src/cli/selectors.js +0 -42
  397. package/build/src/markdown/diff.d.ts +0 -1
  398. package/build/src/markdown/diff.js +0 -4
@@ -1,216 +1,603 @@
1
1
  /** @architectureCompositionRoot */
2
2
  import { z } from "zod";
3
- import { contractFileEffectSchema } from "../contract-worktree.js";
4
- import { reconcileEffectSchema } from "../git/reconcile.js";
3
+ import { contractFileLagSchema } from "../contract-worktree.js";
5
4
  import { AuthorityCorruptionError } from "../core/facts/errors.js";
6
- import { contractIdSchema } from "../protocol/operations.js";
7
- import { executionCleanupSchema, executionStageSchema } from "../protocol/progress.js";
8
- import { settlementActionSchema, settlementLagSchema } from "../settlement/settle.js";
9
- import { reconcileLagScope, reconciliationLagSchema } from "./reconcile.js";
10
- // ---------------------------------------------------------------------------
11
- // One invocation-wide tagged Effect carrier
12
- // ---------------------------------------------------------------------------
13
- const reconciliationEffectSchema = z.union([reconcileEffectSchema, contractFileEffectSchema]);
5
+ import { gitReconcileLagSchema } from "../git/reconcile.js";
6
+ import { contractIdSchema, snapshotIdSchema } from "../git/identity.js";
7
+ import { compactPlacement, placedSchema } from "../protocol/completion.js";
8
+ import { worldRootSchema } from "../world.js";
9
+ import { compactDelivery } from "./delivery.js";
10
+ import { compactRetry, retrySchema, executionIssueSchema } from "../protocol/result-reasons.js";
11
+ export { executionIssueSchema } from "../protocol/result-reasons.js";
12
+ export const reconciliationLagSchema = z.union([gitReconcileLagSchema, contractFileLagSchema]);
13
+ function classifyReconcileLag(kind) {
14
+ switch (kind) {
15
+ case "worktree-retained":
16
+ case "unsealed-bytes":
17
+ return { scope: "none", failure: false };
18
+ case "worktree-follow-retained":
19
+ return { scope: "continuation", failure: false };
20
+ case "target-checkout-retained":
21
+ case "target-workspace-retained":
22
+ return { scope: "placement", failure: true };
23
+ case "worktree-hook-failed":
24
+ case "reconcile-failed":
25
+ case "contract-file-failed":
26
+ return { scope: "reconciliation", failure: true };
27
+ default: {
28
+ const exhaustive = kind;
29
+ return exhaustive;
30
+ }
31
+ }
32
+ }
33
+ export function reconcileLagScope(lag) {
34
+ return classifyReconcileLag(lag.kind).scope;
35
+ }
36
+ export function reconcileLagIsFailure(lag) {
37
+ return classifyReconcileLag(lag.kind).failure;
38
+ }
39
+ const scoped = { contractId: contractIdSchema.exactOptional() };
40
+ const diagnostic = z.string().min(1);
41
+ const path = z.string().min(1);
42
+ export const reconcileIssueSchema = z.union([
43
+ z
44
+ .strictObject({ ...scoped, kind: z.literal("worktree-retained"), path, diagnostic: diagnostic.exactOptional() })
45
+ .readonly(),
46
+ z
47
+ .strictObject({
48
+ ...scoped,
49
+ kind: z.literal("worktree-follow-retained"),
50
+ path,
51
+ reason: z.enum(["head-moved", "head-attached", "operation-in-progress"]),
52
+ })
53
+ .readonly(),
54
+ z.strictObject({ ...scoped, kind: z.literal("unsealed-bytes"), path }).readonly(),
55
+ z
56
+ .strictObject({
57
+ ...scoped,
58
+ kind: z.literal("target-checkout-retained"),
59
+ path,
60
+ target: z.string().min(1),
61
+ diagnostic,
62
+ })
63
+ .readonly(),
64
+ z
65
+ .strictObject({
66
+ ...scoped,
67
+ kind: z.literal("target-workspace-retained"),
68
+ targetContractId: contractIdSchema,
69
+ reason: z.enum(["unappointed", "missing", "association", "replaced", "attached", "uncommitted", "operation"]),
70
+ })
71
+ .readonly(),
72
+ z
73
+ .strictObject({
74
+ ...scoped,
75
+ kind: z.literal("worktree-hook-failed"),
76
+ phase: z.enum(["create", "destroy"]),
77
+ path,
78
+ name: z.string().min(1),
79
+ diagnostic,
80
+ })
81
+ .readonly(),
82
+ z.strictObject({ ...scoped, kind: z.literal("reconcile-failed"), diagnostic }).readonly(),
83
+ z.strictObject({ ...scoped, kind: z.literal("contract-file-failed"), path, diagnostic }).readonly(),
84
+ ]);
85
+ const checkResource = {
86
+ snapshot: snapshotIdSchema.exactOptional(),
87
+ requirement: z.string().min(1).exactOptional(),
88
+ index: z.number().int().positive().exactOptional(),
89
+ };
90
+ export const cleanupIssueSchema = z.union([
91
+ z.strictObject({ ...scoped, kind: z.literal("decode-channel-retirement"), diagnostic }).readonly(),
92
+ z
93
+ .strictObject({
94
+ ...scoped,
95
+ kind: z.literal("verification-cleanup"),
96
+ ...checkResource,
97
+ name: z.string().min(1),
98
+ diagnostic,
99
+ })
100
+ .readonly(),
101
+ z
102
+ .strictObject({
103
+ ...scoped,
104
+ kind: z.literal("worktree-leak"),
105
+ ...checkResource,
106
+ path: path.exactOptional(),
107
+ diagnostic,
108
+ })
109
+ .readonly(),
110
+ z.strictObject({ ...scoped, kind: z.literal("private-state-seat-close"), diagnostic }).readonly(),
111
+ ]);
112
+ const settlementIssueSchema = z
113
+ .strictObject({
114
+ ...scoped,
115
+ kind: z.literal("settlement-failed"),
116
+ debtId: z.string().min(1).exactOptional(),
117
+ diagnostic,
118
+ })
119
+ .readonly();
120
+ const issueLeaves = [
121
+ ...reconcileIssueSchema.options,
122
+ ...cleanupIssueSchema.options,
123
+ executionIssueSchema.unwrap().extend(scoped).readonly(),
124
+ settlementIssueSchema,
125
+ ];
126
+ export const invocationIssueSchema = z.union(issueLeaves);
127
+ const localLeaves = [
128
+ reconcileIssueSchema.options[0],
129
+ reconcileIssueSchema.options[2],
130
+ reconcileIssueSchema.options[3],
131
+ reconcileIssueSchema.options[4],
132
+ reconcileIssueSchema.options[5],
133
+ reconcileIssueSchema.options[6],
134
+ reconcileIssueSchema.options[7],
135
+ cleanupIssueSchema.options[0],
136
+ cleanupIssueSchema.options[3],
137
+ issueLeaves[12],
138
+ settlementIssueSchema,
139
+ ];
140
+ export const localIssueSchema = z.union(localLeaves);
141
+ export const completionIssueSchema = z.union([
142
+ ...reconcileIssueSchema.options,
143
+ cleanupIssueSchema.options[0],
144
+ cleanupIssueSchema.options[3],
145
+ issueLeaves[12],
146
+ settlementIssueSchema,
147
+ ]);
148
+ export const previewIssueSchema = cleanupIssueSchema.options[0].unwrap().omit({ contractId: true }).readonly();
149
+ export const reconcilePublicIssueSchema = z.union([
150
+ reconcileIssueSchema.options[0],
151
+ reconcileIssueSchema.options[2],
152
+ reconcileIssueSchema.options[3],
153
+ reconcileIssueSchema.options[4],
154
+ reconcileIssueSchema.options[5],
155
+ reconcileIssueSchema.options[6],
156
+ reconcileIssueSchema.options[7],
157
+ cleanupIssueSchema.options[3],
158
+ settlementIssueSchema,
159
+ ]);
160
+ export function invocationIssueIsFailure(issue) {
161
+ switch (issue.kind) {
162
+ case "worktree-retained":
163
+ case "unsealed-bytes":
164
+ case "worktree-follow-retained":
165
+ case "verification-cleanup":
166
+ case "worktree-leak":
167
+ case "decode-channel-retirement":
168
+ return false;
169
+ default:
170
+ return true;
171
+ }
172
+ }
173
+ /** Invocation classification consumes owner conclusions, never a fresh authority read. */
174
+ export function contractOutcomeDisposition(result) {
175
+ if (result.kind === "refused")
176
+ return "refused";
177
+ if (result.kind === "retry")
178
+ return "retryable";
179
+ let retry = false;
180
+ const stopped = (stop) => {
181
+ if (stop.kind === "retry") {
182
+ retry = true;
183
+ return false;
184
+ }
185
+ return !["placed", "gates-unsatisfied", "prerequisites-unsatisfied", "delivery-missing", "physical-lag"].includes(stop.kind);
186
+ };
187
+ if (result.issues?.some(invocationIssueIsFailure))
188
+ return "failed";
189
+ if (result.placement !== undefined && stopped(result.placement))
190
+ return "failed";
191
+ for (const check of result.checks ?? []) {
192
+ if (check.kind !== "terminal" || check.verdict === "unsatisfied")
193
+ return "failed";
194
+ if (typeof check.admission === "object" && stopped(check.admission))
195
+ return "failed";
196
+ }
197
+ for (const stop of result.continuation?.stopped ?? [])
198
+ if (stopped(stop))
199
+ return "failed";
200
+ return retry ? "retryable" : "accepted";
201
+ }
14
202
  const resetOwnerSchema = z.enum(["akuma", "git", "debt", "world"]);
15
- const resetEffectFields = { world: z.string().min(1), owner: resetOwnerSchema, diagnostic: z.string().min(1) };
16
- const resetEffectSchema = z.union([
17
- z.object({ kind: z.literal("reset-owner-stopped"), ...resetEffectFields }).strict(),
18
- z.object({ kind: z.literal("reset-residue"), ...resetEffectFields }).strict(),
203
+ export const resetIssueSchema = z.union([
204
+ z
205
+ .strictObject({ kind: z.literal("reset-owner-stopped"), owner: resetOwnerSchema, diagnostic: z.string().min(1) })
206
+ .readonly(),
207
+ z.strictObject({ kind: z.literal("reset-residue"), diagnostic: z.string().min(1) }).readonly(),
19
208
  ]);
20
- const contractEffectSchema = z.union([
209
+ export function resetIssueIsRequired(issue) {
210
+ switch (issue.kind) {
211
+ case "reset-owner-stopped":
212
+ return true;
213
+ case "reset-residue":
214
+ return false;
215
+ default: {
216
+ return issue;
217
+ }
218
+ }
219
+ }
220
+ const admittedFields = scoped;
221
+ export const admittedEvidenceSchema = z.union([
222
+ z.strictObject({ kind: z.enum(["bind", "amend", "claimed", "abandoned"]), ...admittedFields }).readonly(),
21
223
  z
22
- .object({
23
- kind: z.literal("reconciliation-effect"),
24
- contract: contractIdSchema,
25
- effect: reconciliationEffectSchema,
224
+ .strictObject({
225
+ kind: z.literal("deliver"),
226
+ ...admittedFields,
227
+ candidate: snapshotIdSchema,
228
+ integration: snapshotIdSchema,
229
+ contentId: z.string().min(1),
26
230
  })
27
- .strict(),
231
+ .readonly(),
28
232
  z
29
- .object({
30
- kind: z.literal("reconciliation-lag"),
31
- contract: contractIdSchema,
32
- affects: z.enum(["none", "reconciliation", "placement", "continuation"]),
33
- lag: reconciliationLagSchema,
233
+ .strictObject({
234
+ kind: z.literal("reintegrated"),
235
+ ...admittedFields,
236
+ integration: snapshotIdSchema,
237
+ predecessor: snapshotIdSchema,
34
238
  })
35
- .strict()
36
- .refine((value) => value.affects === reconcileLagScope(value.lag), "invalid reconciliation requiredness"),
239
+ .readonly(),
37
240
  z
38
- .object({
39
- kind: z.literal("checkout-retained"),
40
- contract: contractIdSchema,
41
- path: z.string().min(1),
42
- target: z.string().min(1),
43
- diagnostic: z.string().min(1),
241
+ .strictObject({
242
+ kind: z.literal("attestation"),
243
+ ...admittedFields,
244
+ requirement: z.string().exactOptional(),
245
+ verdict: z.enum(["satisfied", "unsatisfied"]).exactOptional(),
44
246
  })
45
- .strict(),
247
+ .readonly(),
46
248
  z
47
- .object({ kind: z.literal("settlement-action"), contract: contractIdSchema, action: settlementActionSchema })
48
- .strict(),
49
- z.object({ kind: z.literal("settlement-lag"), contract: contractIdSchema, lag: settlementLagSchema }).strict(),
249
+ .strictObject({
250
+ kind: z.literal("arc"),
251
+ ...admittedFields,
252
+ chapter: z.number().int().positive(),
253
+ })
254
+ .readonly(),
255
+ ]);
256
+ export const meaningfulEffectSchema = z.union([
257
+ z.strictObject({ kind: z.enum(["worktree-created", "worktree-removed"]), path }).readonly(),
50
258
  z
51
- .object({ kind: z.literal("cleanup"), contract: contractIdSchema, issue: executionCleanupSchema })
52
- .strict()
53
- .refine((value) => value.contract === value.issue.contractId, "invalid cleanup owner"),
259
+ .strictObject({ kind: z.literal("worktree-followed"), path, before: snapshotIdSchema, after: snapshotIdSchema })
260
+ .readonly(),
261
+ z.strictObject({ kind: z.literal("recovery-snapshot"), snapshot: snapshotIdSchema }).readonly(),
262
+ z.strictObject({ kind: z.literal("target-checkout"), path, target: z.string().min(1) }).readonly(),
54
263
  z
55
- .object({
56
- kind: z.literal("execution-stopped"),
57
- contract: contractIdSchema,
58
- stage: executionStageSchema,
59
- reason: z.enum(["cancelled", "failed"]),
60
- diagnostic: z.string().refine((value) => value.trim() !== ""),
264
+ .strictObject({
265
+ kind: z.literal("ref"),
266
+ name: z.string().min(1),
267
+ before: z.string().nullable(),
268
+ after: z.string().nullable(),
61
269
  })
62
- .strict(),
63
- z.object({ kind: z.literal("worktree-retired"), contract: contractIdSchema, name: z.string().min(1) }).strict(),
64
- z.object({ kind: z.literal("worktree-retained"), contract: contractIdSchema, path: z.string().min(1) }).strict(),
270
+ .readonly(),
271
+ z.strictObject({ kind: z.literal("debt-settled"), debtId: z.string().min(1) }).readonly(),
65
272
  ]);
66
- const invocationEffectSchema = z.union([contractEffectSchema, resetEffectSchema]);
67
- const pendingActionSchema = z.enum([
68
- "reset",
69
- "verification",
70
- "placement",
71
- "continuation",
72
- "reconciliation",
73
- "settlement",
74
- "cleanup",
75
- "execution",
273
+ export function compactEffect(effect) {
274
+ switch (effect.kind) {
275
+ case "worktree":
276
+ if (effect.action === "unchanged")
277
+ return undefined;
278
+ if (effect.action === "followed")
279
+ return { kind: "worktree-followed", path: effect.path, before: effect.before, after: effect.after };
280
+ return { kind: effect.action === "created" ? "worktree-created" : "worktree-removed", path: effect.path };
281
+ case "ref":
282
+ return effect.before === effect.after
283
+ ? undefined
284
+ : { kind: "ref", name: effect.name, before: effect.before, after: effect.after };
285
+ case "target-checkout":
286
+ return { kind: effect.kind, path: effect.path, target: effect.target };
287
+ case "recovery-snapshot":
288
+ return { kind: effect.kind, snapshot: effect.snapshot };
289
+ }
290
+ }
291
+ export const recoverySnapshotSchema = z.strictObject({ ...scoped, snapshot: snapshotIdSchema }).readonly();
292
+ const exceptionalEffectSchema = z.union([
293
+ ...meaningfulEffectSchema.options.map((schema) => schema.unwrap().extend(scoped).readonly()),
294
+ placedSchema.unwrap().extend(scoped).readonly(),
76
295
  ]);
77
- const pendingSurfaceSchema = z.object({ surface: pendingActionSchema, required: z.boolean() }).strict();
78
- function surface(surface, required) {
79
- return { surface, required };
296
+ export function operationOutcomeSchema(fields, refusal, issues) {
297
+ return z.union([
298
+ z
299
+ .strictObject({
300
+ kind: z.literal("accepted"),
301
+ contractId: contractIdSchema,
302
+ issues: z.array(issues).min(1).readonly().exactOptional(),
303
+ recoverySnapshots: z.array(recoverySnapshotSchema).min(1).readonly().exactOptional(),
304
+ ...fields,
305
+ })
306
+ .readonly(),
307
+ z.strictObject({ kind: z.literal("refused"), contractId: contractIdSchema, reason: refusal }).readonly(),
308
+ retrySchema.options[0].unwrap().extend({ contractId: contractIdSchema }).readonly(),
309
+ retrySchema.options[1].unwrap().extend({ contractId: contractIdSchema }).readonly(),
310
+ ]);
80
311
  }
81
- function phasePending(operation, value) {
82
- if (operation !== "review" && operation !== "deliver" && operation !== "verify")
83
- return [];
84
- const concluded = value;
85
- if (concluded === undefined)
86
- return [];
87
- const pending = [];
88
- if (concluded.checks?.some((check) => check.kind === "stopped" || check.admission.kind === "stopped" || check.verdict === "unsatisfied"))
89
- pending.push(surface("verification", true));
90
- if (concluded.placement !== undefined)
91
- pending.push(surface("placement", true));
92
- if (concluded.continuation !== undefined && concluded.continuation.stopped.length > 0)
93
- pending.push(surface("continuation", true));
94
- return pending;
312
+ export const handoffOutcomeSchema = z
313
+ .strictObject({
314
+ kind: z.literal("handoff"),
315
+ contractId: contractIdSchema,
316
+ worktreePath: z.string().min(1),
317
+ targetHead: snapshotIdSchema,
318
+ conflictPaths: z.array(z.string().min(1)).min(1).readonly(),
319
+ handoffBase: snapshotIdSchema,
320
+ })
321
+ .readonly();
322
+ export const resetOutcomeSchema = z.union([
323
+ z
324
+ .strictObject({
325
+ kind: z.literal("accepted"),
326
+ refsRemoved: z.number().int().nonnegative().exactOptional(),
327
+ worktreesRemoved: z.number().int().nonnegative().exactOptional(),
328
+ debtsRemoved: z.number().int().nonnegative().exactOptional(),
329
+ issues: z.array(resetIssueSchema).min(1).readonly().exactOptional(),
330
+ })
331
+ .readonly(),
332
+ z.strictObject({ kind: z.literal("refused"), world: worldRootSchema }).readonly(),
333
+ ]);
334
+ export function invocationIssues(effects, primary, snapshot) {
335
+ const issues = [];
336
+ for (const effect of effects) {
337
+ if (effect.kind !== "issue")
338
+ continue;
339
+ const owner = effect.contract === primary ? {} : { contractId: effect.contract };
340
+ const issue = effect.issue;
341
+ if ((issue.kind === "verification-cleanup" || issue.kind === "worktree-leak") &&
342
+ effect.contract === primary &&
343
+ issue.snapshot !== undefined &&
344
+ issue.snapshot === snapshot) {
345
+ const { snapshot: _snapshot, ...rest } = issue;
346
+ issues.push({ ...rest, ...owner });
347
+ }
348
+ else
349
+ issues.push({ ...issue, ...owner });
350
+ }
351
+ return uniqueIssues(issues);
95
352
  }
96
- function stopSurface(stage) {
97
- return stage === "admission" ? "execution" : stage === "reintegration" ? "placement" : stage;
353
+ function uniqueIssues(issues) {
354
+ const diagnosedRetentions = new Set(issues.flatMap((issue) => issue.kind === "worktree-retained" && issue.diagnostic !== undefined
355
+ ? [JSON.stringify([issue.contractId, issue.path])]
356
+ : []));
357
+ return [...new Map(issues.map((issue) => [JSON.stringify(issue), issue])).values()].filter((issue) => issue.kind !== "worktree-retained" ||
358
+ issue.diagnostic !== undefined ||
359
+ !diagnosedRetentions.has(JSON.stringify([issue.contractId, issue.path])));
98
360
  }
99
- function effectPending(effects) {
100
- const pending = [];
101
- for (const effect of effects) {
102
- if (effect.kind === "reconciliation-lag") {
103
- if (effect.affects !== "none")
104
- pending.push(surface(effect.affects, true));
361
+ function admissionEvidence(fact, primary) {
362
+ const base = fact.contract === primary ? {} : { contractId: fact.contract };
363
+ switch (fact.kind) {
364
+ case "deliver":
365
+ return {
366
+ ...base,
367
+ kind: fact.kind,
368
+ candidate: fact.data.tenderSnapshot,
369
+ integration: fact.data.integration.snapshot,
370
+ contentId: fact.data.integration.changeId,
371
+ };
372
+ case "reintegrated":
373
+ return { ...base, kind: fact.kind, integration: fact.data.snapshot, predecessor: fact.data.predecessor };
374
+ case "attestation":
375
+ return {
376
+ ...base,
377
+ kind: fact.kind,
378
+ ...(fact.data.gate === "verified" ? { requirement: fact.data.requirement, verdict: fact.data.verdict } : {}),
379
+ };
380
+ case "arc":
381
+ return { ...base, kind: fact.kind, chapter: fact.data.seq };
382
+ default:
383
+ return { ...base, kind: fact.kind };
384
+ }
385
+ }
386
+ function physicalEvidence(snapshot, primary) {
387
+ const effects = [];
388
+ for (const record of snapshot.effects) {
389
+ if (record.kind !== "settlement-action" && record.kind !== "movement")
390
+ continue;
391
+ const owner = record.contract === primary ? {} : { contractId: record.contract };
392
+ if (record.kind === "settlement-action") {
393
+ effects.push({ ...owner, kind: "debt-settled", debtId: record.action.debtId });
394
+ continue;
105
395
  }
106
- else if (effect.kind === "checkout-retained")
107
- pending.push(surface("placement", true));
108
- else if (effect.kind === "settlement-lag")
109
- pending.push(surface("settlement", true));
110
- else if (effect.kind === "cleanup")
111
- pending.push(surface("cleanup", false));
112
- else if (effect.kind === "execution-stopped")
113
- pending.push(surface(stopSurface(effect.stage), true));
114
- else if (effect.kind === "reset-owner-stopped")
115
- pending.push(surface("reset", true));
116
- else if (effect.kind === "reset-residue")
117
- pending.push(surface("reset", false));
396
+ effects.push({ ...record.effect, ...owner });
118
397
  }
119
- return pending;
398
+ return [...new Map(effects.map((effect) => [JSON.stringify(effect), effect])).values()];
399
+ }
400
+ /** Retain witnessed irreversible effects even when the operation never produced a complete value. */
401
+ function partialEvidence(snapshot, primary) {
402
+ const admitted = snapshot.facts.map((fact) => admissionEvidence(fact, primary));
403
+ const effects = [...physicalEvidence(snapshot, primary)];
404
+ let placement;
405
+ for (const [contractId, value] of snapshot.conclusions) {
406
+ const observed = compactPlacement(value);
407
+ if (observed === undefined)
408
+ continue;
409
+ if (contractId === primary)
410
+ placement = observed;
411
+ else if (observed.kind === "placed")
412
+ effects.push({ ...observed, contractId });
413
+ }
414
+ return {
415
+ ...(admitted.length === 0 ? {} : { admitted }),
416
+ ...(effects.length === 0 ? {} : { effects }),
417
+ ...(placement === undefined ? {} : { placement }),
418
+ };
120
419
  }
121
- /**
122
- * Pending is computed here and nowhere else, from the operation's conclusions and the invocation's
123
- * effects.
124
- */
125
- function projectPending(operation, value, effects) {
126
- const merged = new Map();
127
- for (const entry of [...phasePending(operation, value), ...effectPending(effects)])
128
- merged.set(entry.surface, entry.required || merged.get(entry.surface) === true);
129
- return [...merged].map(([name, required]) => ({ surface: name, required }));
420
+ function acceptedRecoveries(operation, snapshot, contract) {
421
+ const recoveries = physicalEvidence(snapshot, contract).flatMap((effect) => effect.kind === "recovery-snapshot"
422
+ ? [{ snapshot: effect.snapshot, ...(effect.contractId === undefined ? {} : { contractId: effect.contractId }) }]
423
+ : []);
424
+ if (recoveries.length === 0)
425
+ return {};
426
+ const local = operation === "bind" || operation === "amend" || operation === "arc" || operation === "abandon";
427
+ return { recoverySnapshots: local ? recoveries.map((recovery) => recovery.snapshot) : recoveries };
130
428
  }
131
- function envelopeOf(operation, snapshot, contract, value) {
429
+ export function compactReview(value) {
430
+ const placement = compactPlacement(value);
132
431
  return {
133
- fields: {
134
- ...(contract === undefined ? {} : { contract }),
135
- facts: snapshot.facts,
136
- effects: snapshot.effects.filter((effect) => effect.kind !== "reset-owner-stopped" && effect.kind !== "reset-residue"),
137
- },
138
- pending: projectPending(operation, value, snapshot.effects),
432
+ ...(placement === undefined ? {} : { placement }),
433
+ ...(value.worktreeChanges === undefined ? {} : { worktreeChanges: value.worktreeChanges }),
434
+ ...(value.continuation === undefined || Object.keys(value.continuation).length === 0
435
+ ? {}
436
+ : { continuation: value.continuation }),
139
437
  };
140
438
  }
141
- export function project(operation, snapshot, projection) {
142
- if ("world" in projection) {
143
- if (operation !== "nuke")
144
- throw new Error("reset projection requires nuke");
145
- const effects = snapshot.effects.filter((effect) => effect.kind === "reset-owner-stopped" || effect.kind === "reset-residue");
146
- const value = { removed: snapshot.reset?.removed ?? { refs: 0, worktrees: 0, debts: 0 } };
147
- const base = { operation, world: projection.world, effects, pending: projectPending(operation, value, effects) };
148
- if (projection.kind === "failed")
439
+ function partialConclusion(operation, value) {
440
+ if (value === undefined)
441
+ return {};
442
+ switch (operation) {
443
+ case "bind":
149
444
  return {
150
- kind: "failed",
151
- error: withOutcomeReceipt(projection.error, { ...base, value }),
445
+ ...(typeof value.worktreePath === "string" ? { worktreePath: value.worktreePath } : {}),
446
+ ...(value.target === undefined
447
+ ? {}
448
+ : { target: value.target }),
152
449
  };
450
+ case "amend":
451
+ return {
452
+ ...(value.changedSections === undefined ? {} : { changedSections: value.changedSections }),
453
+ ...(value.gatesChanged === true ? { gatesChanged: true } : {}),
454
+ ...(value.afterChanged === true ? { afterChanged: true } : {}),
455
+ };
456
+ case "deliver":
457
+ return value.tenderSnapshot === undefined || value.integration === undefined
458
+ ? {}
459
+ : (() => {
460
+ const compact = compactDelivery(value);
461
+ const placement = compactPlacement(value);
462
+ const { placement: _placement, ...rest } = compact;
463
+ return { ...rest, ...(placement === undefined ? {} : { placement }) };
464
+ })();
465
+ case "verify":
466
+ return {
467
+ ...(typeof value.snapshot === "string" ? { snapshot: value.snapshot } : {}),
468
+ ...(value.checks === undefined ? {} : { checks: value.checks }),
469
+ ...(value.continuation === undefined ? {} : { continuation: value.continuation }),
470
+ };
471
+ case "review":
472
+ return compactReview(value);
473
+ case "arc":
474
+ return {
475
+ ...(value.chapter === undefined ? {} : { chapter: value.chapter }),
476
+ };
477
+ case "deliver-preview":
478
+ return { preview: value };
479
+ case "abandon":
480
+ return {};
481
+ }
482
+ }
483
+ function projectReset(snapshot, projection) {
484
+ const issues = snapshot.effects
485
+ .filter((effect) => effect.kind === "reset-owner-stopped" || effect.kind === "reset-residue")
486
+ .map(({ world: _world, owner, ...issue }) => issue.kind === "reset-residue" ? issue : { ...issue, owner });
487
+ const partial = projection.kind === "failed" || issues.some(resetIssueIsRequired);
488
+ const removed = {};
489
+ const counts = snapshot.reset?.removed;
490
+ if (counts !== undefined)
491
+ for (const key of ["refs", "worktrees", "debts"]) {
492
+ const owner = key === "debts" ? "debt" : "git";
493
+ if (counts[key] > 0 || (partial && snapshot.reset?.attempted.includes(owner)))
494
+ removed[key] = counts[key];
495
+ }
496
+ const evidence = {
497
+ ...(Object.keys(removed).length === 0 ? {} : { removed }),
498
+ ...(issues.length === 0 ? {} : { issues }),
499
+ };
500
+ if (projection.kind === "failed")
153
501
  return {
154
- kind: "returned",
155
- outcome: projection.kind === "refused"
156
- ? { ...base, kind: "refused", refusal: projection.refusal }
157
- : { ...base, kind: "accepted", value },
502
+ kind: "failed",
503
+ error: withOutcomeReceipt(projection.error, { kind: "world", world: projection.world, ...evidence }),
158
504
  };
505
+ return {
506
+ kind: "returned",
507
+ outcome: projection.kind === "refused"
508
+ ? { kind: "refused", world: projection.world }
509
+ : {
510
+ kind: "accepted",
511
+ ...(removed.refs === undefined ? {} : { refsRemoved: removed.refs }),
512
+ ...(removed.worktrees === undefined ? {} : { worktreesRemoved: removed.worktrees }),
513
+ ...(removed.debts === undefined ? {} : { debtsRemoved: removed.debts }),
514
+ ...(issues.length === 0 ? {} : { issues }),
515
+ },
516
+ };
517
+ }
518
+ export function project(operation, snapshot, projection) {
519
+ if ("world" in projection) {
520
+ if (operation !== "nuke")
521
+ throw new Error("reset projection requires nuke");
522
+ return projectReset(snapshot, projection);
159
523
  }
160
524
  if (operation === "nuke")
161
525
  throw new Error("nuke requires a World projection");
162
- const contract = projection.contract;
163
- const value = projection.kind === "accepted" || projection.kind === "handoff"
164
- ? projection.value
165
- : contract === undefined
166
- ? undefined
167
- : snapshot.conclusions.get(contract);
168
- const { fields, pending } = envelopeOf(operation, snapshot, contract, value);
169
- const base = { operation, ...fields, pending };
526
+ const contract = projection.contract ?? snapshot.facts.find((fact) => fact.kind === "bind")?.contract;
527
+ const captured = contract === undefined ? undefined : snapshot.conclusions.get(contract)?.snapshot;
528
+ const issues = invocationIssues(snapshot.effects, contract, typeof captured === "string" ? captured : undefined);
529
+ const base = {
530
+ ...(contract === undefined ? {} : { contractId: contract }),
531
+ ...(issues.length === 0 ? {} : { issues }),
532
+ };
170
533
  switch (projection.kind) {
171
- case "accepted":
172
- return {
173
- kind: "returned",
174
- outcome: {
175
- ...base,
176
- kind: "accepted",
177
- contract: projection.contract,
178
- head: projection.head,
179
- value: projection.value,
180
- },
534
+ case "accepted": {
535
+ if (operation === "deliver-preview")
536
+ return {
537
+ kind: "returned",
538
+ outcome: { ...projection.value, ...base },
539
+ };
540
+ const receipt = {
541
+ kind: "accepted",
542
+ contractId: projection.contract,
543
+ ...(issues.length === 0 ? {} : { issues }),
544
+ ...acceptedRecoveries(operation, snapshot, projection.contract),
181
545
  };
546
+ const outcome = { ...receipt, ...projection.value };
547
+ if (operation === "bind")
548
+ Object.defineProperty(outcome, "kei", {
549
+ value: projection.value.kei,
550
+ enumerable: false,
551
+ });
552
+ return { kind: "returned", outcome: outcome };
553
+ }
182
554
  case "handoff":
183
555
  return {
184
556
  kind: "returned",
185
557
  outcome: {
186
- ...base,
187
558
  kind: "handoff",
188
- contract: projection.contract,
189
- value: projection.value,
559
+ contractId: projection.contract,
560
+ worktreePath: projection.value.workspace.path,
561
+ targetHead: projection.value.targetHead,
562
+ conflictPaths: projection.value.conflictPaths,
563
+ handoffBase: projection.value.handoffBase,
190
564
  },
191
565
  };
192
566
  case "refused":
193
- return { kind: "returned", outcome: { ...base, kind: "refused", refusal: projection.refusal } };
194
- case "retry":
195
- return { kind: "returned", outcome: { ...base, kind: "retry", reason: projection.reason } };
196
- case "failed": {
197
- const head = contract === undefined ? undefined : snapshot.heads.get(contract);
198
- // This is trusted owner evidence, not wire input. A decoder must never mask the original failure.
199
- const partial = {
200
- operation,
201
- ...fields,
202
- pending,
203
- ...(head === undefined ? {} : { head }),
204
- ...(value === undefined ? {} : { value }),
567
+ case "retry": {
568
+ const evidence = partialEvidence(snapshot, contract);
569
+ if (Object.keys(evidence).length > 0 || issues.length > 0)
570
+ throw withOutcomeReceipt(new Error("non-admission followed confirmed invocation effects"), {
571
+ kind: "contract",
572
+ ...base,
573
+ ...evidence,
574
+ });
575
+ const addressed = operation === "bind" ? {} : { contractId: contract };
576
+ return {
577
+ kind: "returned",
578
+ outcome: (projection.kind === "refused"
579
+ ? { kind: "refused", ...addressed, reason: projection.refusal }
580
+ : { ...addressed, ...compactRetry(projection.reason) }),
205
581
  };
206
- return { kind: "failed", error: withOutcomeReceipt(projection.error, partial) };
207
582
  }
583
+ case "failed":
584
+ return {
585
+ kind: "failed",
586
+ error: withOutcomeReceipt(projection.error, {
587
+ kind: "contract",
588
+ ...base,
589
+ ...partialConclusion(operation, contract === undefined ? undefined : snapshot.conclusions.get(contract)),
590
+ ...partialEvidence(snapshot, contract),
591
+ }),
592
+ };
208
593
  }
209
594
  }
210
- /** The one exceptional failure: a category, the native original cause, and an optional same-envelope receipt. */
595
+ const errorOutcomes = new WeakMap();
211
596
  export class KeiyakuError extends Error {
212
597
  category;
213
- outcome;
598
+ get outcome() {
599
+ return errorOutcomes.get(this);
600
+ }
214
601
  constructor(category, message, options = {}) {
215
602
  super(message);
216
603
  this.name = "KeiyakuError";
@@ -218,10 +605,9 @@ export class KeiyakuError extends Error {
218
605
  if (options.cause !== undefined)
219
606
  this.cause = options.cause;
220
607
  if (options.outcome !== undefined)
221
- this.outcome = options.outcome;
608
+ errorOutcomes.set(this, options.outcome);
222
609
  }
223
610
  }
224
- /** One explicit caller-validation phase; its failures are invalid input with a native TypeError cause. */
225
611
  export function validated(phase) {
226
612
  try {
227
613
  return phase();
@@ -255,20 +641,49 @@ export async function readContractValue(operation) {
255
641
  function errorDiagnostic(error) {
256
642
  return error instanceof Error ? error.message : String(error);
257
643
  }
258
- /** Attach this invocation's partial envelope without changing the error's own identity or category. */
259
644
  export function withOutcomeReceipt(error, outcome) {
260
645
  if (error instanceof KeiyakuError) {
261
- return new KeiyakuError(error.category, error.message, { cause: error.cause, outcome });
646
+ const previous = error.outcome;
647
+ if (previous?.kind === "contract" && outcome.kind === "contract") {
648
+ const merged = { ...previous, ...outcome };
649
+ for (const key of ["admitted", "effects", "issues"]) {
650
+ const values = [...(previous[key] ?? []), ...(outcome[key] ?? [])];
651
+ if (values.length > 0)
652
+ Object.assign(merged, {
653
+ [key]: [...new Map(values.map((value) => [JSON.stringify(value), value])).values()],
654
+ });
655
+ }
656
+ outcome = merged;
657
+ }
658
+ errorOutcomes.set(error, outcome);
659
+ return error;
262
660
  }
263
661
  return new KeiyakuError(errorCategory(error), errorDiagnostic(error), { cause: error, outcome });
264
662
  }
663
+ const confirmedSpawnFailures = new WeakMap();
664
+ /** Native creation evidence cannot be supplied by an arbitrary error property. */
665
+ export function spawnFailureReceipt(error) {
666
+ return error instanceof Error ? confirmedSpawnFailures.get(error) : undefined;
667
+ }
668
+ /** Retain the native error, including frozen failures, without losing confirmed birth. */
669
+ export function withSpawnFailureReceipt(reason, result) {
670
+ const cause = reason instanceof Error ? reason : new Error(reason === undefined ? "spawn aborted" : String(reason));
671
+ // A shared cancellation reason cannot carry two different invocations' births.
672
+ const error = confirmedSpawnFailures.has(cause) ? new Error(cause.message, { cause }) : cause;
673
+ if (error !== cause)
674
+ error.name = cause.name;
675
+ confirmedSpawnFailures.set(error, result);
676
+ return error;
677
+ }
265
678
  export function projectFailure(error) {
266
679
  const cause = error instanceof KeiyakuError ? error.cause : error;
680
+ const spawn = spawnFailureReceipt(error) ?? spawnFailureReceipt(cause);
267
681
  return {
268
682
  kind: "failed",
269
683
  category: error instanceof KeiyakuError ? error.category : errorCategory(error),
270
684
  diagnostic: errorDiagnostic(error),
271
685
  ...(cause instanceof Error ? { causeClass: cause.name, causeDiagnostic: cause.message } : {}),
686
+ ...(spawn === undefined ? {} : { spawn }),
272
687
  ...(error instanceof KeiyakuError && error.outcome !== undefined ? { outcome: error.outcome } : {}),
273
688
  };
274
689
  }