@astrosheep/keiyaku 4.6.7 → 4.6.9

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 (336) hide show
  1. package/README.md +46 -16
  2. package/build/plugins/claude/.claude-plugin/plugin.json +1 -1
  3. package/build/plugins/claude/skills/keiyaku/SKILL.md +5 -6
  4. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +1 -1
  5. package/build/plugins/claude/skills/keiyaku-akuma/references/automation.md +8 -8
  6. package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +1 -1
  7. package/build/plugins/claude/skills/keiyaku-bind/SKILL.md +9 -9
  8. package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +91 -0
  9. package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +2 -2
  10. package/build/plugins/codex/.codex-plugin/plugin.json +1 -1
  11. package/build/plugins/codex/skills/keiyaku/SKILL.md +5 -6
  12. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +1 -1
  13. package/build/plugins/codex/skills/keiyaku-akuma/references/automation.md +8 -8
  14. package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +1 -1
  15. package/build/plugins/codex/skills/keiyaku-bind/SKILL.md +9 -9
  16. package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +91 -0
  17. package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +2 -2
  18. package/build/plugins/opencode/index.js +1 -1
  19. package/build/plugins/opencode/skills/keiyaku/SKILL.md +5 -6
  20. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +1 -1
  21. package/build/plugins/opencode/skills/keiyaku-akuma/references/automation.md +8 -8
  22. package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +1 -1
  23. package/build/plugins/opencode/skills/keiyaku-bind/SKILL.md +9 -9
  24. package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +91 -0
  25. package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +2 -2
  26. package/build/plugins/pi/keiyaku.ts +0 -5
  27. package/build/skills/keiyaku/SKILL.md +5 -6
  28. package/build/skills/keiyaku-akuma/SKILL.md +1 -1
  29. package/build/skills/keiyaku-akuma/references/automation.md +8 -8
  30. package/build/skills/keiyaku-babysit/SKILL.md +1 -1
  31. package/build/skills/keiyaku-bind/SKILL.md +9 -9
  32. package/build/skills/keiyaku-debt/SKILL.md +91 -0
  33. package/build/skills/keiyaku-workflow/SKILL.md +2 -2
  34. package/build/src/akuma/akuma-call.d.ts +2 -0
  35. package/build/src/akuma/akuma-call.js +8 -2
  36. package/build/src/akuma/akuma-instance.d.ts +14 -1
  37. package/build/src/akuma/akuma-instance.js +37 -7
  38. package/build/src/akuma/akuma-observe.d.ts +33 -8
  39. package/build/src/akuma/akuma-observe.js +89 -63
  40. package/build/src/akuma/akuma-owner.d.ts +14 -2
  41. package/build/src/akuma/akuma-owner.js +49 -35
  42. package/build/src/akuma/akuma-selection-execution.js +9 -1
  43. package/build/src/akuma/akuma-stream.d.ts +22 -0
  44. package/build/src/akuma/akuma-stream.js +116 -0
  45. package/build/src/akuma/akuma-wait.d.ts +1 -40
  46. package/build/src/akuma/akuma-wait.js +23 -84
  47. package/build/src/akuma/akuma.d.ts +52 -16
  48. package/build/src/akuma/akuma.js +10 -10
  49. package/build/src/akuma/allowed.d.ts +7 -12
  50. package/build/src/akuma/allowed.js +13 -4
  51. package/build/src/akuma/archetype.d.ts +7 -15
  52. package/build/src/akuma/archetype.js +36 -35
  53. package/build/src/akuma/body-supervisor.d.ts +5 -5
  54. package/build/src/akuma/body-supervisor.js +22 -20
  55. package/build/src/akuma/body.d.ts +5 -3
  56. package/build/src/akuma/body.js +57 -8
  57. package/build/src/akuma/call-request.d.ts +30 -32
  58. package/build/src/akuma/call-request.js +10 -3
  59. package/build/src/akuma/caller.d.ts +39 -0
  60. package/build/src/akuma/caller.js +36 -0
  61. package/build/src/akuma/dispatch-association.d.ts +0 -1
  62. package/build/src/akuma/dispatch-association.js +0 -3
  63. package/build/src/akuma/heart/activity-schema.d.ts +12 -0
  64. package/build/src/akuma/heart/activity-schema.js +6 -0
  65. package/build/src/akuma/heart/facts.d.ts +16 -12
  66. package/build/src/akuma/heart/facts.js +8 -0
  67. package/build/src/akuma/heart/index.d.ts +61 -9
  68. package/build/src/akuma/heart/index.js +89 -24
  69. package/build/src/akuma/heart/rows.d.ts +3 -3
  70. package/build/src/akuma/heart/rows.js +5 -3
  71. package/build/src/akuma/heart/soul.d.ts +10 -1
  72. package/build/src/akuma/heart/soul.js +34 -24
  73. package/build/src/akuma/heart/storage.d.ts +20 -0
  74. package/build/src/akuma/heart/storage.js +62 -3
  75. package/build/src/akuma/heart/timeline.d.ts +7 -0
  76. package/build/src/akuma/heart/timeline.js +10 -0
  77. package/build/src/akuma/identity.d.ts +0 -1
  78. package/build/src/akuma/identity.js +2 -5
  79. package/build/src/akuma/index.d.ts +6 -2
  80. package/build/src/akuma/index.js +1 -0
  81. package/build/src/akuma/nuke.js +6 -28
  82. package/build/src/akuma/projection.d.ts +25 -11
  83. package/build/src/akuma/projection.js +24 -7
  84. package/build/src/akuma/provider-recipe.d.ts +18 -6
  85. package/build/src/akuma/provider-recipe.js +24 -1
  86. package/build/src/akuma/provider.d.ts +31 -10
  87. package/build/src/akuma/provider.js +105 -14
  88. package/build/src/akuma/providers/acp/events.js +29 -19
  89. package/build/src/akuma/providers/acp/index.js +2 -3
  90. package/build/src/akuma/providers/claude/events.js +110 -69
  91. package/build/src/akuma/providers/claude/index.d.ts +2 -2
  92. package/build/src/akuma/providers/claude/index.js +4 -8
  93. package/build/src/akuma/providers/codex-app-server/events.js +17 -2
  94. package/build/src/akuma/providers/codex-app-server/index.js +17 -11
  95. package/build/src/akuma/providers/decode.d.ts +33 -0
  96. package/build/src/akuma/providers/decode.js +65 -0
  97. package/build/src/akuma/providers/execution-environment.d.ts +2 -1
  98. package/build/src/akuma/providers/execution-environment.js +3 -0
  99. package/build/src/akuma/providers/grok-build/index.js +16 -48
  100. package/build/src/akuma/providers/index.js +2 -0
  101. package/build/src/akuma/providers/lifecycle.d.ts +9 -0
  102. package/build/src/akuma/providers/lifecycle.js +10 -0
  103. package/build/src/akuma/providers/opencode-sdk/event-stream.d.ts +3 -3
  104. package/build/src/akuma/providers/opencode-sdk/event-stream.js +2 -25
  105. package/build/src/akuma/providers/opencode-sdk/events.d.ts +7 -43
  106. package/build/src/akuma/providers/opencode-sdk/events.js +146 -296
  107. package/build/src/akuma/providers/opencode-sdk/index.js +270 -431
  108. package/build/src/akuma/providers/opencode-sdk/native-http.d.ts +9 -0
  109. package/build/src/akuma/providers/opencode-sdk/native-http.js +69 -0
  110. package/build/src/akuma/providers/opencode-sdk/session.d.ts +42 -36
  111. package/build/src/akuma/providers/opencode-sdk/session.js +75 -84
  112. package/build/src/akuma/providers/paseo/events.d.ts +33 -0
  113. package/build/src/akuma/providers/paseo/events.js +204 -0
  114. package/build/src/akuma/providers/paseo/index.d.ts +9 -0
  115. package/build/src/akuma/providers/paseo/index.js +357 -0
  116. package/build/src/akuma/providers/pi/events.d.ts +2 -0
  117. package/build/src/akuma/providers/pi/events.js +36 -38
  118. package/build/src/akuma/providers/pi/index.js +21 -35
  119. package/build/src/akuma/publication.d.ts +2 -0
  120. package/build/src/akuma/publication.js +5 -0
  121. package/build/src/akuma/request-lifecycle.d.ts +4 -2
  122. package/build/src/akuma/request-lifecycle.js +27 -12
  123. package/build/src/akuma/request-rendezvous.js +38 -55
  124. package/build/src/akuma/request-serve.d.ts +1 -1
  125. package/build/src/akuma/request-serve.js +77 -113
  126. package/build/src/akuma/requests.d.ts +3 -1
  127. package/build/src/akuma/requests.js +32 -0
  128. package/build/src/akuma/selection-observation.d.ts +129 -53
  129. package/build/src/akuma/selection-observation.js +3 -9
  130. package/build/src/akuma/turn-drive.d.ts +3 -0
  131. package/build/src/akuma/turn-drive.js +28 -10
  132. package/build/src/akuma-body.js +12 -22
  133. package/build/src/cli/akuma-caller.d.ts +3 -0
  134. package/build/src/cli/akuma-caller.js +31 -0
  135. package/build/src/cli/commands/akuma-grammar.js +10 -16
  136. package/build/src/cli/commands/akuma.js +25 -55
  137. package/build/src/cli/commands/contract-grammar.d.ts +9 -7
  138. package/build/src/cli/commands/contract-grammar.js +40 -47
  139. package/build/src/cli/commands/contract-help.d.ts +17 -7
  140. package/build/src/cli/commands/contract-help.js +50 -11
  141. package/build/src/cli/commands/contract.js +34 -63
  142. package/build/src/cli/commands/debt-grammar.d.ts +19 -0
  143. package/build/src/cli/commands/debt-grammar.js +323 -0
  144. package/build/src/cli/commands/debt-query.d.ts +5 -0
  145. package/build/src/cli/commands/{task-query.js → debt-query.js} +9 -9
  146. package/build/src/cli/commands/{task.d.ts → debt.d.ts} +2 -2
  147. package/build/src/cli/commands/{task.js → debt.js} +87 -164
  148. package/build/src/cli/coordinates.d.ts +1 -1
  149. package/build/src/cli/coordinates.js +1 -1
  150. package/build/src/cli/parse.d.ts +5 -5
  151. package/build/src/cli/parse.js +17 -16
  152. package/build/src/cli/render/akuma-activity.d.ts +11 -83
  153. package/build/src/cli/render/akuma-activity.js +20 -382
  154. package/build/src/cli/render/catalog.d.ts +4 -7
  155. package/build/src/cli/render/catalog.js +5 -5
  156. package/build/src/cli/render/contract-history.js +3 -6
  157. package/build/src/cli/render/contract.js +17 -52
  158. package/build/src/cli/render/debt.d.ts +28 -0
  159. package/build/src/cli/render/{task.js → debt.js} +55 -133
  160. package/build/src/cli/render/kanshi.js +28 -28
  161. package/build/src/cli/render/marks.d.ts +5 -5
  162. package/build/src/cli/render/marks.js +4 -10
  163. package/build/src/cli/render/nuke.js +1 -1
  164. package/build/src/cli/render/receipt.js +3 -10
  165. package/build/src/cli/runtime.d.ts +1 -1
  166. package/build/src/cli/runtime.js +14 -20
  167. package/build/src/cli/scan.d.ts +1 -1
  168. package/build/src/cli/selectors.d.ts +3 -6
  169. package/build/src/cli/selectors.js +22 -53
  170. package/build/src/cli/usage.d.ts +1 -1
  171. package/build/src/cli/usage.js +4 -4
  172. package/build/src/contract-worktree.js +3 -3
  173. package/build/src/debt/board.d.ts +160 -0
  174. package/build/src/{task → debt}/board.js +89 -89
  175. package/build/src/debt/catalog.d.ts +11 -0
  176. package/build/src/debt/catalog.js +59 -0
  177. package/build/src/{task → debt}/context.d.ts +1 -1
  178. package/build/src/{task → debt}/context.js +1 -1
  179. package/build/src/{task → debt}/created-observation.d.ts +6 -10
  180. package/build/src/{task → debt}/created-observation.js +7 -7
  181. package/build/src/debt/document.d.ts +37 -0
  182. package/build/src/{task → debt}/document.js +37 -37
  183. package/build/src/debt/identity.d.ts +21 -0
  184. package/build/src/{task → debt}/identity.js +35 -35
  185. package/build/src/debt/index.d.ts +111 -0
  186. package/build/src/debt/index.js +203 -0
  187. package/build/src/{task → debt}/input.d.ts +8 -8
  188. package/build/src/{task → debt}/input.js +21 -21
  189. package/build/src/debt/lifecycle-operations.d.ts +6 -0
  190. package/build/src/{task → debt}/lifecycle-operations.js +27 -31
  191. package/build/src/debt/mutation-result.d.ts +981 -0
  192. package/build/src/debt/mutation-result.js +109 -0
  193. package/build/src/debt/mutation.d.ts +424 -0
  194. package/build/src/debt/mutation.js +223 -0
  195. package/build/src/debt/operation-types.d.ts +71 -0
  196. package/build/src/debt/operations.d.ts +28 -0
  197. package/build/src/{task → debt}/operations.js +59 -60
  198. package/build/src/debt/query.d.ts +76 -0
  199. package/build/src/{task → debt}/query.js +55 -55
  200. package/build/src/{task → debt}/store.d.ts +13 -13
  201. package/build/src/{task → debt}/store.js +58 -49
  202. package/build/src/debt/view.d.ts +4 -0
  203. package/build/src/debt/view.js +7 -0
  204. package/build/src/dispatch/index.d.ts +3 -3
  205. package/build/src/dispatch/index.js +1 -2
  206. package/build/src/git/observe.d.ts +6 -2
  207. package/build/src/git/observe.js +6 -2
  208. package/build/src/identity/coordinates.d.ts +1 -1
  209. package/build/src/index.d.ts +17 -17
  210. package/build/src/index.js +11 -11
  211. package/build/src/kanshi/index.d.ts +2 -2
  212. package/build/src/kanshi/read.js +54 -39
  213. package/build/src/kanshi/report.d.ts +7 -7
  214. package/build/src/kanshi/select.js +4 -4
  215. package/build/src/library/address.js +2 -4
  216. package/build/src/library/akuma-creation.d.ts +5 -1
  217. package/build/src/library/akuma-creation.js +27 -47
  218. package/build/src/library/akumas.d.ts +7 -7
  219. package/build/src/library/akumas.js +13 -9
  220. package/build/src/library/bind.d.ts +17 -17
  221. package/build/src/library/bind.js +16 -12
  222. package/build/src/library/contract-address.d.ts +9 -0
  223. package/build/src/library/contract-address.js +71 -0
  224. package/build/src/library/contract-composition.d.ts +4 -7
  225. package/build/src/library/contract-composition.js +6 -18
  226. package/build/src/library/contract-creation.d.ts +3 -5
  227. package/build/src/library/contract-creation.js +24 -22
  228. package/build/src/library/contract-execution.js +21 -26
  229. package/build/src/library/contract-outcomes.d.ts +2 -14
  230. package/build/src/library/contract-outcomes.js +2 -13
  231. package/build/src/library/contract-types.d.ts +38 -4
  232. package/build/src/library/delivery.d.ts +0 -2
  233. package/build/src/library/delivery.js +2 -5
  234. package/build/src/library/input.d.ts +2 -2
  235. package/build/src/library/input.js +5 -5
  236. package/build/src/library/invocation.js +2 -2
  237. package/build/src/library/keiyaku.d.ts +0 -5
  238. package/build/src/library/keiyaku.js +6 -12
  239. package/build/src/library/nuke.js +3 -3
  240. package/build/src/library/outcome.d.ts +626 -625
  241. package/build/src/library/outcome.js +13 -3
  242. package/build/src/library/reconcile.js +8 -16
  243. package/build/src/library/refusal.d.ts +2 -2
  244. package/build/src/library/repo.d.ts +3 -2
  245. package/build/src/library/repo.js +10 -5
  246. package/build/src/library/selection.d.ts +5 -8
  247. package/build/src/library/selection.js +22 -73
  248. package/build/src/plugin/akuma-signals.d.ts +2 -0
  249. package/build/src/plugin/akuma-signals.js +4 -0
  250. package/build/src/plugin/public.d.ts +32 -2
  251. package/build/src/plugin/runtime.js +5 -3
  252. package/build/src/protocol/amend.js +3 -2
  253. package/build/src/protocol/attempt.js +3 -8
  254. package/build/src/protocol/bind.d.ts +2 -2
  255. package/build/src/protocol/bind.js +1 -1
  256. package/build/src/protocol/deliver.js +3 -3
  257. package/build/src/protocol/operations.d.ts +1 -3
  258. package/build/src/protocol/operations.js +0 -8
  259. package/build/src/protocol/outcome.d.ts +1 -2
  260. package/build/src/protocol/outcome.js +1 -13
  261. package/build/src/protocol/placement.js +3 -10
  262. package/build/src/protocol/read/status.js +31 -70
  263. package/build/src/protocol/reintegrate.js +3 -10
  264. package/build/src/protocol/review.js +3 -3
  265. package/build/src/protocol/run.d.ts +5 -1
  266. package/build/src/protocol/run.js +3 -3
  267. package/build/src/runtime/proc/windows-launch.exe +0 -0
  268. package/build/src/settlement/fence.d.ts +3 -3
  269. package/build/src/settlement/fence.js +4 -4
  270. package/build/src/settlement/holder.d.ts +16 -16
  271. package/build/src/settlement/holder.js +69 -63
  272. package/build/src/settlement/settle.d.ts +5 -5
  273. package/build/src/settlement/settle.js +53 -53
  274. package/package.json +19 -9
  275. package/plugins/paseo/plugin/index.server.ts +17 -0
  276. package/plugins/paseo/plugin/paseo-plugin.json +4 -0
  277. package/plugins/paseo/plugin/server/attach.ts +52 -0
  278. package/plugins/paseo/plugin/server/keiyaku.ts +44 -0
  279. package/plugins/paseo/plugin/server/message.ts +60 -0
  280. package/plugins/paseo/plugin/server/mirror.ts +193 -0
  281. package/plugins/paseo/plugin/server/model.ts +14 -0
  282. package/plugins/paseo/plugin/server/provider.ts +276 -0
  283. package/plugins/paseo/plugin/server/sdk-worker.ts +237 -0
  284. package/plugins/paseo/plugin/server/sdk.ts +289 -0
  285. package/plugins/paseo/plugin/server/stop.ts +26 -0
  286. package/plugins/paseo/plugin/server/transport.ts +35 -0
  287. package/plugins/paseo/plugin/shared/attach-rpc.ts +10 -0
  288. package/plugins/paseo/plugin/shared/refresh-rpc.ts +6 -0
  289. package/plugins/paseo/plugin/tsconfig.json +6 -0
  290. package/plugins/pi/keiyaku.ts +57 -0
  291. package/skills/keiyaku/SKILL.md +43 -0
  292. package/skills/keiyaku-akuma/SKILL.md +130 -0
  293. package/skills/keiyaku-akuma/references/automation.md +269 -0
  294. package/skills/keiyaku-babysit/SKILL.md +65 -0
  295. package/skills/keiyaku-bind/SKILL.md +216 -0
  296. package/skills/keiyaku-bind/agents/openai.yaml +4 -0
  297. package/skills/keiyaku-debt/SKILL.md +91 -0
  298. package/skills/keiyaku-workflow/SKILL.md +129 -0
  299. package/build/plugins/claude/skills/keiyaku-task/SKILL.md +0 -104
  300. package/build/plugins/codex/skills/keiyaku-task/SKILL.md +0 -104
  301. package/build/plugins/opencode/skills/keiyaku-task/SKILL.md +0 -104
  302. package/build/skills/keiyaku-task/SKILL.md +0 -104
  303. package/build/src/cli/commands/amend.d.ts +0 -12
  304. package/build/src/cli/commands/amend.js +0 -10
  305. package/build/src/cli/commands/bind.d.ts +0 -11
  306. package/build/src/cli/commands/bind.js +0 -23
  307. package/build/src/cli/commands/task-grammar.d.ts +0 -19
  308. package/build/src/cli/commands/task-grammar.js +0 -384
  309. package/build/src/cli/commands/task-query.d.ts +0 -5
  310. package/build/src/cli/render/task.d.ts +0 -41
  311. package/build/src/dispatch/association.d.ts +0 -1
  312. package/build/src/dispatch/association.js +0 -1
  313. package/build/src/task/board.d.ts +0 -168
  314. package/build/src/task/catalog.d.ts +0 -11
  315. package/build/src/task/catalog.js +0 -59
  316. package/build/src/task/compose-language.d.ts +0 -57
  317. package/build/src/task/compose-language.js +0 -364
  318. package/build/src/task/compose-parser.d.ts +0 -32
  319. package/build/src/task/compose-parser.js +0 -180
  320. package/build/src/task/compose.d.ts +0 -16
  321. package/build/src/task/compose.js +0 -189
  322. package/build/src/task/document.d.ts +0 -39
  323. package/build/src/task/identity.d.ts +0 -21
  324. package/build/src/task/index.d.ts +0 -138
  325. package/build/src/task/index.js +0 -269
  326. package/build/src/task/lifecycle-operations.d.ts +0 -6
  327. package/build/src/task/mutation-result.d.ts +0 -1726
  328. package/build/src/task/mutation-result.js +0 -198
  329. package/build/src/task/mutation.d.ts +0 -590
  330. package/build/src/task/mutation.js +0 -262
  331. package/build/src/task/operation-types.d.ts +0 -71
  332. package/build/src/task/operations.d.ts +0 -28
  333. package/build/src/task/query.d.ts +0 -76
  334. package/build/src/task/view.d.ts +0 -4
  335. package/build/src/task/view.js +0 -7
  336. /package/build/src/{task → debt}/operation-types.js +0 -0
@@ -1,11 +1,11 @@
1
1
  /** @architectureCompositionRoot */
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { appendFile } from "node:fs/promises";
4
+ import { decodeAkumaCaller } from "../akuma/caller.js";
4
5
  import { admitAkumaCall } from "../akuma/akuma-call.js";
5
6
  import { AkumaOwner } from "../akuma/akuma-owner.js";
6
7
  import { decodeAskObservation, observeAdmittedAskAkuma } from "../akuma/akuma-selection-execution.js";
7
8
  import { canonicalBirthCwd } from "../akuma/call-input.js";
8
- import { readSoul } from "../akuma/heart/index.js";
9
9
  import { pathsForAkuId } from "../akuma/identity.js";
10
10
  import { localExecutionContext } from "../akuma/requests.js";
11
11
  import { schemaJsonText } from "../akuma/schema.js";
@@ -13,7 +13,7 @@ import { moveAlias } from "../alias/index.js";
13
13
  import { AuthorityCorruptionError } from "../core/facts/errors.js";
14
14
  import { publishDispatch, readDispatch } from "../dispatch/index.js";
15
15
  import { parseAkumaAlias } from "../identity/selector.js";
16
- import { emitPluginSignal, outcomePluginObserver } from "../plugin/akuma-signals.js";
16
+ import { outcomePluginObserver } from "../plugin/akuma-signals.js";
17
17
  import { World } from "../world.js";
18
18
  import { addressAkuma } from "./address.js";
19
19
  import { requireInput } from "./input.js";
@@ -100,15 +100,11 @@ function callSeat(contract) {
100
100
  throw new TypeError("contract must be a Keiyaku");
101
101
  return seat;
102
102
  }
103
- async function requestedParent(path, id) {
104
- const soul = await readSoul(pathsForAkuId(path, id));
105
- return soul?.origin.kind === "request" ? soul.origin.parent : undefined;
106
- }
107
103
  function pluginDiagnostic(error) {
108
104
  const message = error instanceof Error ? error.message : String(error);
109
105
  return message.length <= 500 ? message : `${message.slice(0, 500)}...`;
110
106
  }
111
- async function recordPluginDiagnostic(paths, error, occurrence = "call admission") {
107
+ async function recordPluginDiagnostic(paths, error, occurrence) {
112
108
  try {
113
109
  await appendFile(paths.log, `plugin ${occurrence} failed: ${pluginDiagnostic(error)}\n`);
114
110
  }
@@ -116,30 +112,12 @@ async function recordPluginDiagnostic(paths, error, occurrence = "call admission
116
112
  // Plugin diagnostic loss must not change an already admitted call.
117
113
  }
118
114
  }
119
- /**
120
- * The submitting process's optional called-plugin observation. It runs once,
121
- * after the prepared executor returned its local value or the forwarded caller
122
- * received its exact live output, and it never gates birth, initial Tell, or a
123
- * later integration stage. A failed delivery stays a diagnostic.
124
- */
125
- async function emitCalledSignal(input) {
126
- try {
127
- const paths = pathsForAkuId(input.path, input.admitted.id);
128
- const callerAkumaId = input.admitted.requested ? await requestedParent(input.path, input.admitted.id) : undefined;
129
- await emitPluginSignal({
130
- world: input.path,
131
- ...(input.settings === undefined ? {} : { settings: input.settings }),
132
- reportDiagnostic: (message) => void recordPluginDiagnostic(paths, message),
133
- }, {
134
- kind: "akuma.called",
135
- akumaId: input.admitted.id,
136
- ...(callerAkumaId === undefined ? {} : { callerAkumaId }),
137
- ...(input.contractId === undefined ? {} : { contractId: input.contractId }),
138
- });
139
- }
140
- catch {
141
- // Plugin delivery must not change an already admitted call.
142
- }
115
+ function callDiagnosticSink(paths, occurrence, reportDiagnostic) {
116
+ return (message) => {
117
+ void recordPluginDiagnostic(paths, message, occurrence);
118
+ // Return the host's possible Promise for the plugin diagnostic isolation boundary.
119
+ return reportDiagnostic?.(message);
120
+ };
143
121
  }
144
122
  async function dispatchStage(input) {
145
123
  try {
@@ -204,6 +182,7 @@ const CALL_INPUT_KEYS = [
204
182
  "allowed",
205
183
  "schema",
206
184
  "initiator",
185
+ "caller",
207
186
  "signal",
208
187
  "observe",
209
188
  ];
@@ -214,6 +193,7 @@ async function parseCallInput(input) {
214
193
  const archetype = nonblank(values.archetype, "archetype");
215
194
  const body = callBody(values.body);
216
195
  const initiator = values.initiator === undefined ? undefined : text(values.initiator, "initiator");
196
+ const caller = decodeAkumaCaller(values.caller);
217
197
  const cwd = values.cwd === undefined ? undefined : nonblank(values.cwd, "cwd");
218
198
  const mode = callMode(values.mode);
219
199
  validateCallBodyOptions(body, values, mode);
@@ -247,6 +227,8 @@ async function parseCallInput(input) {
247
227
  ...(alias === undefined ? {} : { alias }),
248
228
  ...(values.allowed === undefined ? {} : { allowed: values.allowed }),
249
229
  seat,
230
+ ...(caller === undefined ? {} : { caller }),
231
+ ...(initiator === undefined ? {} : { initiator }),
250
232
  ...(initialTell === undefined ? {} : { initialTell }),
251
233
  ...(observe === undefined ? {} : { observe }),
252
234
  };
@@ -261,6 +243,8 @@ function callConfiguration(input, execution) {
261
243
  function callAdmissionInput(input, execution) {
262
244
  return {
263
245
  archetype: input.archetype,
246
+ ...(input.caller === undefined ? {} : { caller: input.caller }),
247
+ ...(input.initiator === undefined ? {} : { initiator: input.initiator }),
264
248
  ...(input.initialTell === undefined
265
249
  ? {}
266
250
  : {
@@ -297,7 +281,7 @@ function failedCall(result, tellId, error, tell) {
297
281
  },
298
282
  };
299
283
  }
300
- async function observeCall(input) {
284
+ async function observeCall(input, reportDiagnostic) {
301
285
  const onObserve = {
302
286
  admitted: async (receipt, id) => {
303
287
  await input.observe?.admitted?.(receipt, id, {
@@ -317,9 +301,7 @@ async function observeCall(input) {
317
301
  outcomeObserved: outcomePluginObserver({
318
302
  world: input.path,
319
303
  ...(input.settings === undefined ? {} : { settings: input.settings }),
320
- reportDiagnostic: (message) => {
321
- void recordPluginDiagnostic(pathsForAkuId(input.path, input.akuma), message, "outcome observation");
322
- },
304
+ reportDiagnostic: callDiagnosticSink(pathsForAkuId(input.path, input.akuma), "outcome observation", reportDiagnostic),
323
305
  }),
324
306
  ...(input.signal === undefined ? {} : { signal: input.signal }),
325
307
  onObserve,
@@ -352,7 +334,7 @@ function knownChildFailure(reason, akuma) {
352
334
  function asError(failure) {
353
335
  return failure instanceof Error ? failure : new Error(failure === undefined ? "call failed" : String(failure));
354
336
  }
355
- export async function callAkumas(input, execution = localExecutionContext()) {
337
+ export async function callAkumas(input, execution = localExecutionContext(), reportDiagnostic) {
356
338
  const parsed = await parseCallInput(input);
357
339
  const selectedExecution = await resolveCallExecution(parsed.cwd === undefined ? {} : { cwd: parsed.cwd });
358
340
  const seat = parsed.seat;
@@ -360,14 +342,6 @@ export async function callAkumas(input, execution = localExecutionContext()) {
360
342
  ...callAdmissionInput(parsed, selectedExecution),
361
343
  ...(seat === undefined ? {} : { contractId: seat.id }),
362
344
  }, selectedExecution === undefined ? {} : { cwdCanonical: true });
363
- // One caller-wiring sequence, after the prepared executor returned its local value
364
- // or the forwarded caller received its exact live output, before outcome observation.
365
- await emitCalledSignal({
366
- path: parsed.path,
367
- ...(parsed.settings === undefined ? {} : { settings: parsed.settings }),
368
- admitted,
369
- ...(seat === undefined ? {} : { contractId: seat.id }),
370
- });
371
345
  const dispatch = seat === undefined
372
346
  ? { kind: "none" }
373
347
  : await dispatchStage({ repository: seat.scope, akuId: admitted.id, contractId: seat.id });
@@ -404,16 +378,22 @@ export async function callAkumas(input, execution = localExecutionContext()) {
404
378
  ...(parsed.settings === undefined ? {} : { settings: parsed.settings }),
405
379
  ...(parsed.signal === undefined ? {} : { signal: parsed.signal }),
406
380
  ...(parsed.observe === undefined ? {} : { observe: parsed.observe }),
407
- });
381
+ }, reportDiagnostic);
408
382
  }
409
383
  export async function forkAkumas(input) {
410
384
  const values = requireInput(input, "Akumas.fork input");
411
- onlyKeys(values, ["path", "akuma", "at", "repo"], "Akumas.fork input");
385
+ onlyKeys(values, ["path", "akuma", "at", "repo", "caller", "initiator"], "Akumas.fork input");
386
+ const caller = decodeAkumaCaller(values.caller);
387
+ const initiator = values.initiator === undefined ? undefined : text(values.initiator, "initiator");
412
388
  const at = nonblank(values.at, "at");
413
389
  const addressed = await addressAkuma({ path: values.path, akuma: nonblank(values.akuma, "akuma") });
414
390
  const { path, id: akuma } = addressed;
415
391
  const repository = values.repo === undefined ? undefined : scopeForRepo(values.repo);
416
- const receipt = await new AkumaOwner(akuma, path).fork({ at });
392
+ const receipt = await new AkumaOwner(akuma, path).fork({
393
+ at,
394
+ ...(caller === undefined ? {} : { caller }),
395
+ ...(initiator === undefined ? {} : { initiator }),
396
+ });
417
397
  if (receipt.kind !== "forked")
418
398
  return { ...receipt, parent: akuma };
419
399
  const dispatch = repository === undefined
@@ -1,9 +1,10 @@
1
1
  /** @architectureCompositionRoot */
2
+ import { type AkumaHostOptions } from "../akuma/akuma-instance.js";
2
3
  import type { AkumaList, AkumaListInput } from "../akuma/akuma.js";
3
4
  import type { TellResult, TellWake } from "../akuma/body.js";
4
5
  import { type ExecutionContext } from "../akuma/requests.js";
5
- import type { DispatchAssociation } from "../dispatch/association.js";
6
- import type { CreatedTaskObservation } from "../task/created-observation.js";
6
+ import type { DispatchAssociation } from "../akuma/dispatch-association.js";
7
+ import type { CreatedDebtObservation } from "../debt/created-observation.js";
7
8
  import { type WorldRoot } from "../world.js";
8
9
  import type { AkumaAddressInput, AkumaWorldScopeRefusal } from "./address.js";
9
10
  import type { CallInput, CallResult, CallWaitHead, DispatchStage, ForkInput, ForkResult } from "./akuma-creation.js";
@@ -12,13 +13,12 @@ export { AkumaAddressError, AkumaWorldScopeError } from "./address.js";
12
13
  export type { AkumaAddressInput } from "./address.js";
13
14
  export type { CallInput, ForkInput } from "./akuma-creation.js";
14
15
  export type { AkumaAskInput, AkumaHistoryInput, AkumaKillInput, AkumaTellInput, AkumaWaitInput } from "./selection.js";
15
- export type { AkumaAskResult, AkumaHistoryResult, AkumaKillResult, AkumaList, AkumaListInput, AkumaObservation, AkumaObservationStage, AkumaTellResult, AkumaWaitResult, AkumaWorldScopeRefusal, CallResult, CallWaitHead, CreatedTaskObservation, DispatchAssociation, DispatchStage, ForkResult, TellResult, TellWake, };
16
+ export type { AkumaAskResult, AkumaHistoryResult, AkumaKillResult, AkumaList, AkumaListInput, AkumaObservation, AkumaObservationStage, AkumaTellResult, AkumaWaitResult, AkumaWorldScopeRefusal, CallResult, CallWaitHead, CreatedDebtObservation, DispatchAssociation, DispatchStage, ForkResult, TellResult, TellWake, };
16
17
  /** The existing native wait-observation seam, exposed type-only for CLI composition. */
17
- export type { WaitObservedAkuma, WaitObserver, WaitSelectedAkuma } from "../akuma/akuma-wait.js";
18
18
  export type Akumas = AkumasHandle;
19
19
  declare class AkumasHandle {
20
20
  #private;
21
- constructor(world: WorldRoot, execution: ExecutionContext);
21
+ constructor(world: WorldRoot, execution: ExecutionContext, host?: AkumaHostOptions);
22
22
  list(input?: AkumaListInput): Promise<AkumaList>;
23
23
  call(input: CallInput): Promise<CallResult>;
24
24
  fork(input: ForkInput): Promise<ForkResult>;
@@ -34,7 +34,7 @@ declare class AkumasHandle {
34
34
  * The one Akumas composition. Public `of` fixes local execution; CLI and Body pass their captured
35
35
  * internal channel through `akumasWithExecution` instead of a second constructor.
36
36
  */
37
- export declare function akumasWithExecution(world: WorldRoot, execution: ExecutionContext): Akumas;
37
+ export declare function akumasWithExecution(world: WorldRoot, execution: ExecutionContext, host?: AkumaHostOptions): Akumas;
38
38
  export declare const Akumas: Readonly<{
39
- of(world: WorldRoot): Akumas;
39
+ of(world: WorldRoot, host?: AkumaHostOptions): Akumas;
40
40
  }>;
@@ -1,3 +1,5 @@
1
+ /** @architectureCompositionRoot */
2
+ import { captureAkumaHostDiagnostic } from "../akuma/akuma-instance.js";
1
3
  import { readAkumaRoster } from "../akuma/akuma.js";
2
4
  import { localExecutionContext } from "../akuma/requests.js";
3
5
  import { readAliases } from "../alias/index.js";
@@ -10,11 +12,13 @@ class AkumasHandle {
10
12
  #world;
11
13
  #execution;
12
14
  #selection;
13
- constructor(world, execution) {
15
+ #reportDiagnostic;
16
+ constructor(world, execution, host) {
14
17
  this.#world = world;
15
18
  this.#execution = execution;
16
19
  // One typed route seam captured at construction: no operation re-derives it.
17
- this.#selection = selectionSeam(execution);
20
+ this.#reportDiagnostic = captureAkumaHostDiagnostic(host);
21
+ this.#selection = selectionSeam(execution, this.#reportDiagnostic);
18
22
  Object.freeze(this);
19
23
  }
20
24
  async list(input) {
@@ -25,13 +29,13 @@ class AkumasHandle {
25
29
  return withRosterAliases(roster, await readAliases(path));
26
30
  }
27
31
  call(input) {
28
- return callAkumas(this.withWorld(input, "Akumas.call input"), this.#execution);
32
+ return callAkumas(this.withWorld(input, "Akumas.call input"), this.#execution, this.#reportDiagnostic);
29
33
  }
30
34
  fork(input) {
31
35
  return forkAkumas(this.withWorld(input, "Akumas.fork input"));
32
36
  }
33
37
  status(input) {
34
- return statusAkuma(this.withWorld(input, "Akumas.status input"));
38
+ return statusAkuma(this.withWorld(input, "Akumas.status input"), this.#reportDiagnostic);
35
39
  }
36
40
  tell(input) {
37
41
  return tellAkumaOn(this.#selection, this.withWorld(input, "Akumas.tell input"));
@@ -46,7 +50,7 @@ class AkumasHandle {
46
50
  return killAkumaOn(this.#selection, this.withWorld(input, "Akumas.kill input"));
47
51
  }
48
52
  history(input) {
49
- return historyAkuma(this.withWorld(input, "Akumas.history input"));
53
+ return historyAkuma(this.withWorld(input, "Akumas.history input"), this.#reportDiagnostic);
50
54
  }
51
55
  withWorld(input, label) {
52
56
  const values = requireInput(input, label);
@@ -72,13 +76,13 @@ function withRosterAliases(roster, bindings) {
72
76
  * The one Akumas composition. Public `of` fixes local execution; CLI and Body pass their captured
73
77
  * internal channel through `akumasWithExecution` instead of a second constructor.
74
78
  */
75
- export function akumasWithExecution(world, execution) {
79
+ export function akumasWithExecution(world, execution, host) {
76
80
  if (typeof world !== "string")
77
81
  throw new TypeError("Akumas.of world must be a WorldRoot");
78
- return new AkumasHandle(world, execution);
82
+ return new AkumasHandle(world, execution, host);
79
83
  }
80
84
  export const Akumas = Object.freeze({
81
- of(world) {
82
- return akumasWithExecution(world, localExecutionContext());
85
+ of(world, host) {
86
+ return akumasWithExecution(world, localExecutionContext(), host);
83
87
  },
84
88
  });
@@ -4,7 +4,7 @@ import type { GitDecodeChannel } from "../git/read-observation.js";
4
4
  import { type BindTargetSelection } from "../protocol/bind.js";
5
5
  import { type IntentOutcome, type RepositoryScope } from "../protocol/operations.js";
6
6
  import type { ProtocolProgress } from "../protocol/progress.js";
7
- import type { TaskId } from "../task/identity.js";
7
+ import type { DebtId } from "../debt/identity.js";
8
8
  import type { ForkSourceRefusal, OperationRefusals } from "./refusal.js";
9
9
  type ForkBindAdmission = Readonly<{
10
10
  kind: "document";
@@ -21,7 +21,7 @@ export declare function admitForkBindWithAppointment(input: Readonly<{
21
21
  scope: RepositoryScope;
22
22
  channel: GitDecodeChannel;
23
23
  sourceId: ContractId;
24
- target?: string;
24
+ target?: string | null;
25
25
  progress?: ProtocolProgress;
26
26
  actor?: ActorId;
27
27
  }>): Promise<Readonly<{
@@ -35,8 +35,8 @@ export declare function prepareMarkdownBind(input: Readonly<{
35
35
  gates: readonly import("../core/facts/types.js").Gate[];
36
36
  after: readonly ContractId[];
37
37
  workspace: "worktree";
38
- targetSelection?: BindTargetSelection;
39
- task?: TaskId;
38
+ targetSelection: BindTargetSelection;
39
+ debt?: DebtId;
40
40
  progress?: ProtocolProgress;
41
41
  actor?: ActorId;
42
42
  }>): Promise<{
@@ -45,16 +45,16 @@ export declare function prepareMarkdownBind(input: Readonly<{
45
45
  result: IntentOutcome<Readonly<{
46
46
  contractId: ContractId;
47
47
  }>, {
48
- kind: "contract-exists" | "invalid-after" | "unknown-prerequisite";
49
- contractId: ContractId;
50
- } | {
51
48
  kind: "verification-declaration-invalid";
52
49
  contractId?: ContractId | undefined;
50
+ } | {
51
+ kind: "target-missing" | "unborn-head" | "invalid-target";
53
52
  } | {
54
53
  kind: "fork-source-moved";
55
54
  contractId: ContractId;
56
55
  } | {
57
- kind: "unborn-head" | "target-missing" | "invalid-target";
56
+ kind: "contract-exists" | "invalid-after" | "unknown-prerequisite";
57
+ contractId: ContractId;
58
58
  } | {
59
59
  kind: "fork-source-missing" | "fork-source-unavailable";
60
60
  contractId: ContractId;
@@ -64,36 +64,36 @@ export declare function prepareMarkdownBind(input: Readonly<{
64
64
  result: IntentOutcome<Readonly<{
65
65
  contractId: ContractId;
66
66
  }>, {
67
- kind: "contract-exists" | "invalid-after" | "unknown-prerequisite";
68
- contractId: ContractId;
69
- } | {
70
67
  kind: "verification-declaration-invalid";
71
68
  contractId?: ContractId | undefined;
69
+ } | {
70
+ kind: "target-missing" | "unborn-head" | "invalid-target";
72
71
  } | {
73
72
  kind: "fork-source-moved";
74
73
  contractId: ContractId;
75
74
  } | {
76
- kind: "unborn-head" | "target-missing" | "invalid-target";
75
+ kind: "contract-exists" | "invalid-after" | "unknown-prerequisite";
76
+ contractId: ContractId;
77
77
  } | {
78
78
  kind: "fork-source-missing" | "fork-source-unavailable";
79
79
  contractId: ContractId;
80
80
  }>;
81
- taskId: TaskId;
81
+ debtId: DebtId;
82
82
  diagnostic: string;
83
83
  }>) | null;
84
84
  result: IntentOutcome<Readonly<{
85
85
  contractId: ContractId;
86
86
  }>, {
87
- kind: "contract-exists" | "invalid-after" | "unknown-prerequisite";
88
- contractId: ContractId;
89
- } | {
90
87
  kind: "verification-declaration-invalid";
91
88
  contractId?: ContractId | undefined;
89
+ } | {
90
+ kind: "target-missing" | "unborn-head" | "invalid-target";
92
91
  } | {
93
92
  kind: "fork-source-moved";
94
93
  contractId: ContractId;
95
94
  } | {
96
- kind: "unborn-head" | "target-missing" | "invalid-target";
95
+ kind: "contract-exists" | "invalid-after" | "unknown-prerequisite";
96
+ contractId: ContractId;
97
97
  } | {
98
98
  kind: "fork-source-missing" | "fork-source-unavailable";
99
99
  contractId: ContractId;
@@ -7,11 +7,19 @@ import { mintIdentitySegment } from "../identity/mint.js";
7
7
  import { fitIdentityStemWords, normalizeIdentityStem } from "../identity/normalize.js";
8
8
  import { bindOperation } from "../protocol/bind.js";
9
9
  import { stateOperation } from "../protocol/operations.js";
10
- import { admitWithTaskHolderFence, claimTaskHolder } from "../settlement/holder.js";
10
+ import { admitWithDebtHolderFence, claimDebtHolder } from "../settlement/holder.js";
11
11
  import { KeiyakuError } from "./outcome.js";
12
12
  import { contractTerms, documentDerivation } from "./input.js";
13
13
  const CONTRACT_ID_CODE_POINTS = 32;
14
14
  const CONTRACT_ID_ATTEMPTS = 4;
15
+ /** A fork with no target copies its source; `null` clears it and a string overrides it. */
16
+ function forkTargetSelection(target, sourceTarget) {
17
+ if (target === null)
18
+ return { kind: "targetless" };
19
+ if (target !== undefined)
20
+ return { kind: "explicit", target };
21
+ return sourceTarget === undefined ? { kind: "targetless" } : { kind: "explicit", target: sourceTarget };
22
+ }
15
23
  function drawContractSuffix() {
16
24
  return randomBytes(2).toString("hex");
17
25
  }
@@ -22,14 +30,14 @@ async function attempt(input, id) {
22
30
  terms: input.terms,
23
31
  verification: input.verification,
24
32
  workspace: input.workspace,
33
+ targetSelection: input.targetSelection,
25
34
  ...(input.coordinates === undefined ? {} : { coordinates: input.coordinates }),
26
35
  ...(input.source === undefined ? {} : { source: input.source }),
27
36
  contractId: id,
28
- ...(input.targetSelection === undefined ? {} : { targetSelection: input.targetSelection }),
29
- ...(input.task === undefined
37
+ ...(input.debt === undefined
30
38
  ? {}
31
39
  : {
32
- decorateOffer: ({ contractId: owner }) => [claimTaskHolder(input.task, owner)],
40
+ decorateOffer: ({ contractId: owner }) => [claimDebtHolder(input.debt, owner)],
33
41
  }),
34
42
  ...(input.actor === undefined ? {} : { actor: input.actor }),
35
43
  ...(input.progress === undefined ? {} : { progress: input.progress }),
@@ -99,11 +107,7 @@ export async function admitForkBindWithAppointment(input) {
99
107
  terms,
100
108
  verification: documentDerivation(document, terms.gates).verification,
101
109
  workspace: "worktree",
102
- targetSelection: input.target === undefined
103
- ? source.coordinates.target === undefined
104
- ? { kind: "targetless" }
105
- : { kind: "explicit", target: source.coordinates.target }
106
- : { kind: "explicit", target: input.target },
110
+ targetSelection: forkTargetSelection(input.target, source.coordinates.target),
107
111
  coordinates: { start: source.coordinates.start },
108
112
  source: {
109
113
  contractId: input.sourceId,
@@ -125,11 +129,11 @@ export async function prepareMarkdownBind(input) {
125
129
  terms,
126
130
  verification: documentDerivation(input.document, terms.gates).verification,
127
131
  workspace: input.workspace,
128
- ...(input.targetSelection === undefined ? {} : { targetSelection: input.targetSelection }),
129
- ...(input.task === undefined ? {} : { task: input.task }),
132
+ targetSelection: input.targetSelection,
133
+ ...(input.debt === undefined ? {} : { debt: input.debt }),
130
134
  ...(input.actor === undefined ? {} : { actor: input.actor }),
131
135
  ...(input.progress === undefined ? {} : { progress: input.progress }),
132
136
  });
133
- const admission = input.task === undefined ? null : await admitWithTaskHolderFence(input.scope, input.task, admitCandidate);
137
+ const admission = input.debt === undefined ? null : await admitWithDebtHolderFence(input.scope, input.debt, admitCandidate);
134
138
  return { admission, result: admission === null ? await admitCandidate() : admission.result };
135
139
  }
@@ -0,0 +1,9 @@
1
+ import type { ContractRow } from "../protocol/read/status.js";
2
+ import type { ContractResolution, ContractResolveInput } from "./contract-types.js";
3
+ /** Pure Contract membership shared with mixed Address; no cross-family judgment. */
4
+ export declare function matchContractCandidates(rows: readonly ContractRow[], selection: Readonly<{
5
+ selector: string;
6
+ }> | Readonly<{
7
+ cwd: string;
8
+ }>): readonly ContractRow[];
9
+ export declare function resolveContract(input: ContractResolveInput): Promise<ContractResolution>;
@@ -0,0 +1,71 @@
1
+ import { realpath, stat } from "node:fs/promises";
2
+ import { isAbsolute, normalize } from "node:path";
3
+ import { contractId } from "../core/facts/types.js";
4
+ import { withGitDecodeChannel } from "../git/read-observation.js";
5
+ import { contractsOperation } from "../protocol/operations.js";
6
+ import { requireInput } from "./input.js";
7
+ import { readContractValue } from "./outcome.js";
8
+ import { scopeForRepo } from "./repo.js";
9
+ /** Pure Contract membership shared with mixed Address; no cross-family judgment. */
10
+ export function matchContractCandidates(rows, selection) {
11
+ return rows.filter((row) => row.disposition === "active" &&
12
+ row.workspace === "worktree" &&
13
+ row.worktreePath !== null &&
14
+ ("selector" in selection
15
+ ? `@${row.id.slice("kei/".length)}` === selection.selector
16
+ : normalize(row.worktreePath) === selection.cwd));
17
+ }
18
+ export async function resolveContract(input) {
19
+ const values = requireInput(input, "Keiyaku.with().resolve input", ["repo", "selector", "cwd"]);
20
+ const scope = scopeForRepo(values.repo);
21
+ const selector = values.selector;
22
+ if (selector !== undefined && typeof selector !== "string")
23
+ throw new TypeError("selector must be a string");
24
+ const suppliedCwd = values.cwd;
25
+ if (suppliedCwd !== undefined && (typeof suppliedCwd !== "string" || !isAbsolute(suppliedCwd)))
26
+ throw new TypeError("cwd must be an absolute directory coordinate");
27
+ let cwd = scope.invocationWorktree;
28
+ if (typeof suppliedCwd === "string") {
29
+ try {
30
+ cwd = await realpath(suppliedCwd);
31
+ if (!(await stat(cwd)).isDirectory())
32
+ throw new TypeError("cwd must be a directory");
33
+ }
34
+ catch (cause) {
35
+ throw new TypeError("cwd must be an absolute directory coordinate", { cause });
36
+ }
37
+ }
38
+ if (selector !== undefined) {
39
+ if (selector.startsWith("@kei/"))
40
+ return { kind: "refused", refusal: { kind: "redundant-short-selector", selector } };
41
+ try {
42
+ const id = contractId(selector.startsWith("@") ? `kei/${selector.slice(1)}` : selector);
43
+ if (!selector.startsWith("@"))
44
+ return { kind: "resolved", id };
45
+ }
46
+ catch (error) {
47
+ return {
48
+ kind: "refused",
49
+ refusal: {
50
+ kind: "invalid-selector",
51
+ selector,
52
+ diagnostic: error instanceof Error ? error.message : String(error),
53
+ },
54
+ };
55
+ }
56
+ }
57
+ const board = await readContractValue(() => withGitDecodeChannel(scope, (channel) => contractsOperation({ scope, channel })));
58
+ const candidates = matchContractCandidates(board.rows, selector === undefined ? { cwd } : { selector });
59
+ if (candidates.length === 1)
60
+ return { kind: "resolved", id: candidates[0].id };
61
+ if (selector === undefined) {
62
+ return {
63
+ kind: "refused",
64
+ refusal: candidates.length === 0 ? { kind: "no-contextual-match", cwd } : { kind: "ambiguous-selector", cwd },
65
+ };
66
+ }
67
+ return {
68
+ kind: "refused",
69
+ refusal: candidates.length === 0 ? { kind: "unknown-short-selector", selector } : { kind: "ambiguous-selector", selector },
70
+ };
71
+ }
@@ -1,9 +1,8 @@
1
1
  /** @architectureCompositionRoot */
2
2
  import { type LibraryExecution } from "../akuma/requests.js";
3
- import type { BindTargetSelection } from "../protocol/bind.js";
4
3
  import type { ContractObservation } from "../protocol/read/status.js";
5
4
  import type { BindOutcome } from "./contract-outcomes.js";
6
- import type { BindInput, ContractList, ContractListInput, ContractObservationInput, KeiyakuSelectInput, LocalContractComposition } from "./contract-types.js";
5
+ import type { BindInput, ContractList, ContractListInput, ContractObservationInput, ContractResolveInput, ContractResolution, KeiyakuSelectInput, LocalContractComposition } from "./contract-types.js";
7
6
  import type { Keiyaku, createKeiyakuHandle } from "./keiyaku.js";
8
7
  import { type ReconcileCompletion, type RepoReconcileReport } from "./reconcile.js";
9
8
  import { type Repo } from "./repo.js";
@@ -24,6 +23,7 @@ interface KeiyakuLibraryReconcile {
24
23
  export type KeiyakuLibrary = Readonly<{
25
24
  bind(input: BindInput): Promise<BindOutcome>;
26
25
  select(input: KeiyakuSelectInput): Keiyaku;
26
+ resolve(input: ContractResolveInput): Promise<ContractResolution>;
27
27
  list(input: ContractListInput): Promise<ContractList>;
28
28
  observe(input: ContractObservationInput): Promise<ContractObservation>;
29
29
  reconcile: KeiyakuLibraryReconcile;
@@ -32,12 +32,9 @@ export type KeiyakuLibrary = Readonly<{
32
32
  * The one private Contract composition constructor. `Keiyaku.with` fixes local execution; CLI and
33
33
  * Body pass their captured internal channel explicitly here instead of a second constructor. The
34
34
  * carrier is a positional argument, never a field of the public construction input, so no runtime
35
- * value reaching the public surface can select a private channel. `omittedMarkdownTarget` is the
36
- * internal bind intent an edge supplies for a Markdown bind whose caller omitted the target; the
37
- * public package-root composition leaves it targetless.
35
+ * value reaching the public surface can select a private channel.
38
36
  */
39
- export declare function composeContractLibrary(execution: LibraryExecution, createHandle: typeof createKeiyakuHandle, input?: LocalContractComposition, omittedMarkdownTarget?: BindTargetSelection): KeiyakuLibrary;
37
+ export declare function composeContractLibrary(execution: LibraryExecution, createHandle: typeof createKeiyakuHandle, input?: LocalContractComposition): KeiyakuLibrary;
40
38
  export declare function listKeiyaku(input: ContractListInput): Promise<ContractList>;
41
39
  export declare function observeKeiyaku(input: ContractObservationInput): Promise<ContractObservation>;
42
- export declare function readContractValue<Value>(operation: () => Promise<Value>): Promise<Value>;
43
40
  export {};
@@ -3,25 +3,25 @@ import { localExecutionContext } from "../akuma/requests.js";
3
3
  import { contractId } from "../core/facts/types.js";
4
4
  import { withGitDecodeChannel } from "../git/read-observation.js";
5
5
  import { contractCatalogueOperation, contractObservationOperation, contractsOperation, } from "../protocol/operations.js";
6
+ import { resolveContract } from "./contract-address.js";
6
7
  import { bindKeiyaku } from "./contract-creation.js";
7
8
  import { captureLocalContractComposition, derivedHooks, } from "./contract-settings.js";
8
9
  import { requireInput } from "./input.js";
9
- import { KeiyakuError, errorCategory } from "./outcome.js";
10
+ import { readContractValue } from "./outcome.js";
10
11
  import { completeReconcile, completeRepoReconcile, } from "./reconcile.js";
11
12
  import { scopeForRepo } from "./repo.js";
12
13
  /**
13
14
  * The one private Contract composition constructor. `Keiyaku.with` fixes local execution; CLI and
14
15
  * Body pass their captured internal channel explicitly here instead of a second constructor. The
15
16
  * carrier is a positional argument, never a field of the public construction input, so no runtime
16
- * value reaching the public surface can select a private channel. `omittedMarkdownTarget` is the
17
- * internal bind intent an edge supplies for a Markdown bind whose caller omitted the target; the
18
- * public package-root composition leaves it targetless.
17
+ * value reaching the public surface can select a private channel.
19
18
  */
20
- export function composeContractLibrary(execution, createHandle, input, omittedMarkdownTarget = { kind: "targetless" }) {
19
+ export function composeContractLibrary(execution, createHandle, input) {
21
20
  const composition = captureLocalContractComposition(input);
22
21
  return Object.freeze({
23
- bind: (operation) => bindKeiyaku(operation, createHandle, execution, composition, omittedMarkdownTarget),
22
+ bind: (operation) => bindKeiyaku(operation, createHandle, execution, composition),
24
23
  select: (operation) => selectKeiyaku(operation, createHandle, execution, composition),
24
+ resolve: resolveContract,
25
25
  list: (operation) => listKeiyaku(operation),
26
26
  observe: (operation) => observeKeiyaku(operation),
27
27
  reconcile: reconcileOperation(composition),
@@ -93,15 +93,3 @@ export async function observeKeiyaku(input) {
93
93
  }
94
94
  return readContractValue(() => withGitDecodeChannel(scope, (channel) => contractObservationOperation({ scope, channel, contractId: id })));
95
95
  }
96
- export async function readContractValue(operation) {
97
- try {
98
- return await operation();
99
- }
100
- catch (error) {
101
- if (error instanceof KeiyakuError)
102
- throw error;
103
- throw new KeiyakuError(errorCategory(error), error instanceof Error ? error.message : String(error), {
104
- cause: error,
105
- });
106
- }
107
- }
@@ -1,13 +1,11 @@
1
1
  /** @architectureCompositionRoot */
2
2
  import { type ExecutionContext } from "../akuma/requests.js";
3
- import type { BindTargetSelection } from "../protocol/bind.js";
4
3
  import type { BindOutcome } from "./contract-outcomes.js";
5
4
  import { type LocalContractCompositionCapture } from "./contract-settings.js";
6
5
  import type { BindInput } from "./contract-types.js";
7
6
  import type { createKeiyakuHandle } from "./keiyaku.js";
8
7
  /**
9
- * One Contract bind. `omittedMarkdownTarget` is the internal composition input an edge
10
- * supplies for a Markdown bind whose caller omitted the target: the public package-root
11
- * composition leaves it targetless, while the CLI names the invocation branch.
8
+ * One Contract bind. An omitted Markdown target names the current branch of the caller's explicit
9
+ * Repo worktree coordinate, `null` is deliberately targetless, and a string is that literal target.
12
10
  */
13
- export declare function bindKeiyaku(input: BindInput, createHandle: typeof createKeiyakuHandle, execution?: ExecutionContext, composition?: LocalContractCompositionCapture, omittedMarkdownTarget?: BindTargetSelection): Promise<BindOutcome>;
11
+ export declare function bindKeiyaku(input: BindInput, createHandle: typeof createKeiyakuHandle, execution?: ExecutionContext, composition?: LocalContractCompositionCapture): Promise<BindOutcome>;