@astrosheep/keiyaku 4.6.31 → 4.6.32

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 (335) hide show
  1. package/README.md +34 -17
  2. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +16 -11
  3. package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +5 -3
  4. package/build/plugins/claude/skills/keiyaku-bind/SKILL.md +4 -3
  5. package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +17 -17
  6. package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +4 -3
  7. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +16 -11
  8. package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +5 -3
  9. package/build/plugins/codex/skills/keiyaku-bind/SKILL.md +4 -3
  10. package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +17 -17
  11. package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +4 -3
  12. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +16 -11
  13. package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +5 -3
  14. package/build/plugins/opencode/skills/keiyaku-bind/SKILL.md +4 -3
  15. package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +17 -17
  16. package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +4 -3
  17. package/build/plugins/pi/README.md +16 -18
  18. package/build/plugins/pi/akuma-tools.ts +31 -38
  19. package/build/plugins/pi/keiyaku.ts +15 -4
  20. package/build/skills/keiyaku-akuma/SKILL.md +16 -11
  21. package/build/skills/keiyaku-babysit/SKILL.md +5 -3
  22. package/build/skills/keiyaku-bind/SKILL.md +4 -3
  23. package/build/skills/keiyaku-debt/SKILL.md +17 -17
  24. package/build/skills/keiyaku-workflow/SKILL.md +4 -3
  25. package/build/src/akuma/akuma-call.d.ts +3 -5
  26. package/build/src/akuma/akuma-call.js +7 -10
  27. package/build/src/akuma/akuma-errors.d.ts +7 -4
  28. package/build/src/akuma/akuma-errors.js +16 -12
  29. package/build/src/akuma/akuma-instance.d.ts +39 -303
  30. package/build/src/akuma/akuma-instance.js +48 -48
  31. package/build/src/akuma/akuma-observe.d.ts +5 -4
  32. package/build/src/akuma/akuma-observe.js +1 -7
  33. package/build/src/akuma/akuma-owner.d.ts +14 -6
  34. package/build/src/akuma/akuma-owner.js +33 -27
  35. package/build/src/akuma/akuma-selection-execution.d.ts +22 -19
  36. package/build/src/akuma/akuma-selection-execution.js +71 -124
  37. package/build/src/akuma/akuma-wait.d.ts +3 -3
  38. package/build/src/akuma/akuma.d.ts +47 -384
  39. package/build/src/akuma/akuma.js +8 -58
  40. package/build/src/akuma/archetype.d.ts +16 -19
  41. package/build/src/akuma/archetype.js +48 -49
  42. package/build/src/akuma/body.js +31 -26
  43. package/build/src/akuma/call-initial-tell.d.ts +4 -1
  44. package/build/src/akuma/call-initial-tell.js +9 -1
  45. package/build/src/akuma/call-input.d.ts +8 -1
  46. package/build/src/akuma/call-input.js +27 -18
  47. package/build/src/akuma/caller.js +2 -1
  48. package/build/src/akuma/detached-body.js +1 -1
  49. package/build/src/akuma/heart/facts.d.ts +5 -4
  50. package/build/src/akuma/heart/facts.js +5 -5
  51. package/build/src/akuma/heart/soul.js +20 -4
  52. package/build/src/akuma/identity.d.ts +1 -1
  53. package/build/src/akuma/identity.js +9 -4
  54. package/build/src/akuma/index.d.ts +6 -7
  55. package/build/src/akuma/index.js +2 -3
  56. package/build/src/akuma/projection.d.ts +3 -0
  57. package/build/src/akuma/provider-recipe.js +3 -2
  58. package/build/src/akuma/providers/acp/config.js +11 -10
  59. package/build/src/akuma/providers/acp/index.js +2 -1
  60. package/build/src/akuma/providers/codex-app-server/index.js +7 -1
  61. package/build/src/akuma/providers/grok-build/index.js +2 -1
  62. package/build/src/akuma/providers/index.d.ts +0 -1
  63. package/build/src/akuma/providers/index.js +0 -8
  64. package/build/src/akuma/providers/paseo/index.js +7 -4
  65. package/build/src/akuma/providers/pi/index.js +4 -3
  66. package/build/src/akuma/publication.d.ts +1 -2
  67. package/build/src/akuma/publication.js +16 -14
  68. package/build/src/akuma/schema.d.ts +3 -49
  69. package/build/src/akuma/schema.js +6 -147
  70. package/build/src/akuma/selection-observation.d.ts +281 -240
  71. package/build/src/akuma/selection-observation.js +122 -68
  72. package/build/src/akuma/status-projection.d.ts +49 -285
  73. package/build/src/akuma/status-projection.js +178 -138
  74. package/build/src/body/amend.js +2 -1
  75. package/build/src/body/arc.js +3 -2
  76. package/build/src/body/criteria.js +4 -3
  77. package/build/src/body/decode.js +2 -1
  78. package/build/src/body/envelope.js +2 -1
  79. package/build/src/body/region.d.ts +1 -3
  80. package/build/src/body/region.js +3 -8
  81. package/build/src/body-host.d.ts +4 -11
  82. package/build/src/body-host.js +5 -4
  83. package/build/src/bounded-list.js +2 -1
  84. package/build/src/cli/commands/akuma-grammar.d.ts +109 -66
  85. package/build/src/cli/commands/akuma-grammar.js +75 -95
  86. package/build/src/cli/commands/akuma.d.ts +8 -3
  87. package/build/src/cli/commands/akuma.js +63 -122
  88. package/build/src/cli/commands/contract-grammar.d.ts +3 -135
  89. package/build/src/cli/commands/contract-grammar.js +125 -218
  90. package/build/src/cli/commands/contract-help.d.ts +24 -21
  91. package/build/src/cli/commands/contract-help.js +43 -35
  92. package/build/src/cli/commands/contract.d.ts +6 -18
  93. package/build/src/cli/commands/contract.js +65 -272
  94. package/build/src/cli/commands/debt-grammar.d.ts +2 -4
  95. package/build/src/cli/commands/debt-grammar.js +22 -190
  96. package/build/src/cli/commands/debt.js +10 -87
  97. package/build/src/cli/commands/report.d.ts +2 -4
  98. package/build/src/cli/coordinates.d.ts +1 -1
  99. package/build/src/cli/coordinates.js +1 -1
  100. package/build/src/cli/main.js +9 -3
  101. package/build/src/cli/parse.d.ts +80 -3
  102. package/build/src/cli/parse.js +76 -16
  103. package/build/src/cli/render/akuma-activity.d.ts +19 -24
  104. package/build/src/cli/render/akuma-activity.js +164 -259
  105. package/build/src/cli/render/akuma.d.ts +3 -3
  106. package/build/src/cli/render/akuma.js +36 -43
  107. package/build/src/cli/render/catalog.d.ts +2 -5
  108. package/build/src/cli/render/catalog.js +2 -33
  109. package/build/src/cli/render/contract-history.js +1 -2
  110. package/build/src/cli/render/contract-observation.d.ts +0 -7
  111. package/build/src/cli/render/contract-observation.js +0 -3
  112. package/build/src/cli/render/contract.d.ts +7 -9
  113. package/build/src/cli/render/contract.js +35 -64
  114. package/build/src/cli/render/debt.d.ts +3 -11
  115. package/build/src/cli/render/debt.js +17 -88
  116. package/build/src/cli/render/delivery-preview.js +4 -4
  117. package/build/src/cli/render/kanshi-akuma.d.ts +5 -3
  118. package/build/src/cli/render/kanshi-akuma.js +22 -18
  119. package/build/src/cli/render/kanshi.d.ts +1 -3
  120. package/build/src/cli/render/kanshi.js +16 -39
  121. package/build/src/cli/render/receipt.d.ts +21 -12
  122. package/build/src/cli/render/receipt.js +49 -44
  123. package/build/src/cli/render/refusal.d.ts +4 -3
  124. package/build/src/cli/render/refusal.js +15 -17
  125. package/build/src/cli/render/settings.d.ts +1 -1
  126. package/build/src/cli/render/terminal.d.ts +9 -8
  127. package/build/src/cli/render/terminal.js +48 -32
  128. package/build/src/cli/render/verbs.d.ts +3 -1
  129. package/build/src/cli/render/verbs.js +74 -116
  130. package/build/src/cli/runtime.js +66 -65
  131. package/build/src/cli/streams.d.ts +2 -9
  132. package/build/src/cli/streams.js +8 -1
  133. package/build/src/cli/usage.d.ts +2 -1
  134. package/build/src/cli/usage.js +3 -2
  135. package/build/src/contract-worktree.js +2 -10
  136. package/build/src/core/facts/codec.js +9 -23
  137. package/build/src/core/facts/errors.d.ts +2 -1
  138. package/build/src/core/facts/errors.js +3 -3
  139. package/build/src/core/facts/types.d.ts +2 -13
  140. package/build/src/core/facts/types.js +1 -6
  141. package/build/src/core/verbs/abandon.d.ts +1 -2
  142. package/build/src/core/verbs/amend.d.ts +1 -2
  143. package/build/src/core/verbs/arc.d.ts +1 -2
  144. package/build/src/core/verbs/attestation.d.ts +1 -2
  145. package/build/src/core/verbs/bind.d.ts +1 -2
  146. package/build/src/core/verbs/deliver.d.ts +1 -2
  147. package/build/src/core/verbs/placement.d.ts +1 -2
  148. package/build/src/core/verbs/reintegrate.d.ts +1 -2
  149. package/build/src/debt/board.d.ts +14 -94
  150. package/build/src/debt/board.js +25 -160
  151. package/build/src/debt/catalog.d.ts +0 -2
  152. package/build/src/debt/catalog.js +1 -22
  153. package/build/src/debt/document.d.ts +8 -11
  154. package/build/src/debt/document.js +19 -62
  155. package/build/src/debt/identity.d.ts +2 -14
  156. package/build/src/debt/identity.js +19 -49
  157. package/build/src/debt/index.d.ts +81 -219
  158. package/build/src/debt/index.js +61 -110
  159. package/build/src/debt/input.d.ts +19 -5
  160. package/build/src/debt/input.js +51 -177
  161. package/build/src/debt/lifecycle-operations.d.ts +1 -3
  162. package/build/src/debt/lifecycle-operations.js +1 -73
  163. package/build/src/debt/operation-types.d.ts +24 -128
  164. package/build/src/debt/operation-types.js +6 -62
  165. package/build/src/debt/operations.d.ts +8 -17
  166. package/build/src/debt/operations.js +58 -154
  167. package/build/src/debt/store.d.ts +0 -2
  168. package/build/src/debt/store.js +32 -87
  169. package/build/src/errors.d.ts +28 -0
  170. package/build/src/errors.js +26 -0
  171. package/build/src/git/hooks.d.ts +1 -1
  172. package/build/src/git/observe.d.ts +3 -0
  173. package/build/src/git/observe.js +19 -5
  174. package/build/src/git/reconcile.d.ts +3 -16
  175. package/build/src/git/reconcile.js +0 -18
  176. package/build/src/git/repository.d.ts +2 -1
  177. package/build/src/git/repository.js +3 -3
  178. package/build/src/git/target-placement.d.ts +4 -4
  179. package/build/src/git/target.d.ts +2 -2
  180. package/build/src/git/tender.d.ts +1 -2
  181. package/build/src/git/tender.js +5 -12
  182. package/build/src/identity/coordinates.d.ts +1 -1
  183. package/build/src/identity/coordinates.js +3 -2
  184. package/build/src/identity/normalize.js +2 -1
  185. package/build/src/identity/selector.js +4 -3
  186. package/build/src/index.d.ts +34 -57
  187. package/build/src/index.js +11 -36
  188. package/build/src/kanshi/counts.d.ts +3 -8
  189. package/build/src/kanshi/counts.js +6 -14
  190. package/build/src/kanshi/index.d.ts +22 -7
  191. package/build/src/kanshi/index.js +30 -4
  192. package/build/src/kanshi/read.d.ts +81 -270
  193. package/build/src/kanshi/read.js +39 -199
  194. package/build/src/kanshi/report.d.ts +340 -1619
  195. package/build/src/kanshi/report.js +19 -31
  196. package/build/src/library/address.d.ts +11 -11
  197. package/build/src/library/address.js +34 -27
  198. package/build/src/library/akuma-creation.d.ts +210 -79
  199. package/build/src/library/akuma-creation.js +201 -242
  200. package/build/src/library/akumas.d.ts +24 -5
  201. package/build/src/library/akumas.js +96 -29
  202. package/build/src/library/bind.d.ts +7 -10
  203. package/build/src/library/bind.js +2 -8
  204. package/build/src/library/continuation.d.ts +141 -231
  205. package/build/src/library/continuation.js +22 -31
  206. package/build/src/library/contract-address.d.ts +6 -9
  207. package/build/src/library/contract-address.js +11 -16
  208. package/build/src/library/contract-composition.d.ts +2 -3
  209. package/build/src/library/contract-composition.js +12 -19
  210. package/build/src/library/contract-creation.js +33 -34
  211. package/build/src/library/contract-outcomes.d.ts +1278 -806
  212. package/build/src/library/contract-outcomes.js +11 -37
  213. package/build/src/library/contract-settings.d.ts +1 -2
  214. package/build/src/library/contract-settings.js +5 -7
  215. package/build/src/library/contract-types.d.ts +42 -67
  216. package/build/src/library/contract-types.js +15 -56
  217. package/build/src/library/contract-wait.d.ts +40 -3
  218. package/build/src/library/contract-wait.js +28 -21
  219. package/build/src/library/delivery.d.ts +366 -389
  220. package/build/src/library/delivery.js +5 -25
  221. package/build/src/library/input.d.ts +31 -5
  222. package/build/src/library/input.js +40 -40
  223. package/build/src/library/invocation.d.ts +13 -11
  224. package/build/src/library/invocation.js +69 -58
  225. package/build/src/library/kei.d.ts +16 -8
  226. package/build/src/library/kei.js +459 -19
  227. package/build/src/library/keiyaku-attribution.d.ts +0 -8
  228. package/build/src/library/keiyaku-attribution.js +0 -11
  229. package/build/src/library/keiyaku-classify.d.ts +2 -2
  230. package/build/src/library/keiyaku-classify.js +40 -59
  231. package/build/src/library/keiyaku-coordinates.d.ts +3 -8
  232. package/build/src/library/keiyaku-coordinates.js +6 -26
  233. package/build/src/library/keiyaku-debt.d.ts +21 -93
  234. package/build/src/library/keiyaku-debt.js +8 -157
  235. package/build/src/library/keiyaku-identity.js +5 -4
  236. package/build/src/library/keiyaku-verbs.d.ts +4004 -3885
  237. package/build/src/library/keiyaku-verbs.js +309 -271
  238. package/build/src/library/keiyaku.d.ts +30 -860
  239. package/build/src/library/keiyaku.js +169 -256
  240. package/build/src/library/nuke.d.ts +4 -2
  241. package/build/src/library/nuke.js +5 -1
  242. package/build/src/library/outcome.d.ts +424 -307
  243. package/build/src/library/outcome.js +167 -362
  244. package/build/src/library/reconcile.d.ts +331 -143
  245. package/build/src/library/reconcile.js +38 -72
  246. package/build/src/library/refusal.d.ts +20 -28
  247. package/build/src/library/refusal.js +1 -11
  248. package/build/src/library/repo.js +4 -3
  249. package/build/src/library/selection.d.ts +32 -21
  250. package/build/src/library/selection.js +63 -87
  251. package/build/src/mcp/adapter.d.ts +6 -0
  252. package/build/src/mcp/adapter.js +177 -42
  253. package/build/src/mcp/help.d.ts +1 -1
  254. package/build/src/mcp/help.js +12 -7
  255. package/build/src/mcp/output.d.ts +385 -0
  256. package/build/src/mcp/output.js +193 -0
  257. package/build/src/plugin/public.d.ts +4 -0
  258. package/build/src/plugin/runtime.d.ts +1 -1
  259. package/build/src/plugin/runtime.js +2 -2
  260. package/build/src/protocol/amend.d.ts +1 -1
  261. package/build/src/protocol/amend.js +2 -2
  262. package/build/src/protocol/bind.d.ts +5 -7
  263. package/build/src/protocol/bind.js +3 -3
  264. package/build/src/protocol/completion.d.ts +158 -195
  265. package/build/src/protocol/completion.js +55 -19
  266. package/build/src/protocol/deliver.d.ts +11 -6
  267. package/build/src/protocol/deliver.js +30 -30
  268. package/build/src/protocol/delivery-preview.d.ts +13 -11
  269. package/build/src/protocol/delivery-preview.js +2 -2
  270. package/build/src/protocol/execution-observation.d.ts +5 -13
  271. package/build/src/protocol/intent.d.ts +6 -9
  272. package/build/src/protocol/intent.js +18 -31
  273. package/build/src/protocol/operations.d.ts +48 -53
  274. package/build/src/protocol/operations.js +16 -25
  275. package/build/src/protocol/outcome.d.ts +3 -1
  276. package/build/src/protocol/placement.d.ts +1 -2
  277. package/build/src/protocol/placement.js +1 -1
  278. package/build/src/protocol/progress.d.ts +1 -0
  279. package/build/src/protocol/read/status.d.ts +29 -112
  280. package/build/src/protocol/read/status.js +52 -78
  281. package/build/src/protocol/reintegrate.d.ts +1 -2
  282. package/build/src/protocol/reintegrate.js +0 -1
  283. package/build/src/protocol/result-leaves.d.ts +11 -32
  284. package/build/src/protocol/result-leaves.js +18 -57
  285. package/build/src/protocol/result-reasons.d.ts +6 -6
  286. package/build/src/protocol/review.js +0 -1
  287. package/build/src/protocol/verify.d.ts +192 -146
  288. package/build/src/protocol/verify.js +60 -47
  289. package/build/src/runtime/proc/windows-launch.exe +0 -0
  290. package/build/src/settings.d.ts +8 -9
  291. package/build/src/settings.js +16 -13
  292. package/build/src/settlement/holder.js +2 -2
  293. package/build/src/settlement/settle.d.ts +0 -6
  294. package/build/src/settlement/settle.js +0 -4
  295. package/build/src/verification/declaration.d.ts +3 -6
  296. package/build/src/verification/declaration.js +3 -5
  297. package/build/src/verification/observation.d.ts +2 -2
  298. package/build/src/world.d.ts +3 -2
  299. package/build/src/world.js +5 -6
  300. package/package.json +1 -1
  301. package/plugins/paseo/plugin/index.server.ts +1 -1
  302. package/plugins/paseo/plugin/server/attach.ts +74 -67
  303. package/plugins/paseo/plugin/server/keiyaku.ts +80 -14
  304. package/plugins/paseo/plugin/server/message.ts +2 -1
  305. package/plugins/paseo/plugin/server/mirror-identity.ts +6 -4
  306. package/plugins/paseo/plugin/server/sdk.ts +9 -11
  307. package/plugins/paseo/plugin/server/transport.ts +24 -1
  308. package/plugins/pi/README.md +16 -18
  309. package/plugins/pi/akuma-tools.ts +31 -38
  310. package/plugins/pi/keiyaku.ts +15 -4
  311. package/skills/keiyaku-akuma/SKILL.md +16 -11
  312. package/skills/keiyaku-babysit/SKILL.md +5 -3
  313. package/skills/keiyaku-bind/SKILL.md +4 -3
  314. package/skills/keiyaku-debt/SKILL.md +17 -17
  315. package/skills/keiyaku-workflow/SKILL.md +4 -3
  316. package/build/src/akuma/providers/codex-app-server/configuration.d.ts +0 -5
  317. package/build/src/akuma/providers/codex-app-server/configuration.js +0 -72
  318. package/build/src/cli/commands/debt-query.d.ts +0 -5
  319. package/build/src/cli/commands/debt-query.js +0 -194
  320. package/build/src/cli/render/akuma-tool-command.d.ts +0 -6
  321. package/build/src/cli/render/akuma-tool-command.js +0 -143
  322. package/build/src/cli/render/akuma-tool.d.ts +0 -29
  323. package/build/src/cli/render/akuma-tool.js +0 -225
  324. package/build/src/debt/context.d.ts +0 -28
  325. package/build/src/debt/context.js +0 -102
  326. package/build/src/debt/created-observation.d.ts +0 -26
  327. package/build/src/debt/created-observation.js +0 -38
  328. package/build/src/debt/query.d.ts +0 -80
  329. package/build/src/debt/query.js +0 -283
  330. package/build/src/library/contract-execution.d.ts +0 -28
  331. package/build/src/library/contract-execution.js +0 -506
  332. package/build/src/library/keiyaku-policy.d.ts +0 -27
  333. package/build/src/library/keiyaku-policy.js +0 -44
  334. package/build/src/library/keiyaku-status.d.ts +0 -1487
  335. package/build/src/library/keiyaku-status.js +0 -92
@@ -2,22 +2,27 @@
2
2
  import { z } from "zod";
3
3
  import { akumaIdSchema } from "../akuma/identity.js";
4
4
  import { activityRowSchema, outcomeRowSchema, reportRowSchema } from "../akuma/projection.js";
5
- import { projectStatusTimeline } from "../akuma/status-projection.js";
5
+ import { projectCurrentWork } from "../akuma/status-projection.js";
6
6
  import { withoutReportedChanges } from "../akuma/projection.js";
7
7
  import { AkumaNotBornError, AkumaObservationError } from "../akuma/akuma-errors.js";
8
- import { AkumaOwner } from "../akuma/akuma-owner.js";
9
- import { decodeAskObservation, executeAskAkuma, executeKillAkuma, executeTellAkuma, } from "../akuma/akuma-selection-execution.js";
8
+ import { AkumaOwner, historyInputSchemas } from "../akuma/akuma-owner.js";
9
+ import { durationSchema, validateTellObservation, validateAkumaInput } from "../akuma/call-input.js";
10
+ import { executeAskAkuma, executeKillAkuma, executeTellAkuma, } from "../akuma/akuma-selection-execution.js";
10
11
  import { executeWaitAkuma } from "../akuma/akuma-wait.js";
11
- import { parseExactHistorySelector } from "../akuma/identity.js";
12
- import { schemaJsonText } from "../akuma/schema.js";
12
+ import { canonicalDocument } from "../akuma/schema.js";
13
13
  import { observeDispatchAssociations } from "../dispatch/index.js";
14
14
  import { observeContractAt } from "../git/observe.js";
15
15
  import { withGitDecodeChannel } from "../git/read-observation.js";
16
- import { observeCreatedDebtObservations } from "../debt/created-observation.js";
16
+ import { KeiyakuError } from "../errors.js";
17
17
  import { outcomePluginObserver, stderrPluginDiagnostic, withAkumaWaitDeferrals } from "../plugin/akuma-signals.js";
18
18
  import { addressAkuma, addressAkumaSet } from "./address.js";
19
19
  import { requireInput } from "./input.js";
20
20
  import { scopeForRepo } from "./repo.js";
21
+ export const historySelectionSchemas = [
22
+ ...historyInputSchemas.map((branch) => branch.extend({ last: z.literal(false).exactOptional() })),
23
+ z.strictObject({ last: z.literal(true) }),
24
+ ];
25
+ const historySelectionSchema = z.union(historySelectionSchemas);
21
26
  const historyCommon = { akumaId: akumaIdSchema };
22
27
  export const akumaHistoryResultSchema = z.union([
23
28
  z
@@ -31,19 +36,13 @@ export const akumaHistoryResultSchema = z.union([
31
36
  highestSequence: z.number().int().positive().exactOptional(),
32
37
  })
33
38
  .readonly(),
34
- z
35
- .strictObject({
36
- ...outcomeRowSchema.unwrap().omit({ kind: true }).shape,
37
- kind: z.literal("akuma-exact"),
38
- ...historyCommon,
39
- })
39
+ outcomeRowSchema
40
+ .unwrap()
41
+ .extend({ kind: z.literal("akuma-exact"), ...historyCommon })
40
42
  .readonly(),
41
- z
42
- .strictObject({
43
- ...reportRowSchema.unwrap().omit({ kind: true }).shape,
44
- kind: z.literal("akuma-report"),
45
- ...historyCommon,
46
- })
43
+ reportRowSchema
44
+ .unwrap()
45
+ .extend({ kind: z.literal("akuma-report"), ...historyCommon })
47
46
  .readonly(),
48
47
  z.strictObject({ kind: z.literal("akuma-unknown-history"), ...historyCommon }).readonly(),
49
48
  z.strictObject({ kind: z.literal("akuma-last"), ...historyCommon, answer: z.string() }).readonly(),
@@ -86,9 +85,8 @@ function placementDischarged(repo) {
86
85
  return claimed;
87
86
  };
88
87
  }
89
- async function observeAkuma(status, path, repo) {
88
+ async function observeAkuma(status, repo) {
90
89
  const contract = (await dispatchAssociations(repo, [status.id])).get(status.id);
91
- const createdDebts = (await observeCreatedDebtObservations(path, [status.id]))[0];
92
90
  if (status.cwd === undefined || status.provider === undefined)
93
91
  throw new Error(`Born Akuma ${status.id} lacks its frozen execution context`);
94
92
  const composed = (await placementDischarged(repo)(contract))
@@ -102,15 +100,10 @@ async function observeAkuma(status, path, repo) {
102
100
  cwd: status.cwd,
103
101
  provider: status.provider,
104
102
  ...(status.model === undefined ? {} : { model: status.model }),
105
- timeline: projectStatusTimeline(composed.timeline),
103
+ work: projectCurrentWork(composed.timeline),
106
104
  ...(status.lastActivityAt === undefined ? {} : { lastActivityAt: status.lastActivityAt }),
107
105
  ...(status.strandedReason === undefined ? {} : { strandedReason: status.strandedReason }),
108
106
  ...(contract.kind === "none" ? {} : { contract }),
109
- ...(createdDebts.kind === "failed"
110
- ? { createdDebts }
111
- : createdDebts.rows === undefined
112
- ? {}
113
- : { createdDebts: createdDebts.rows }),
114
107
  ...(changes.length === 0 ? {} : { changes }),
115
108
  ...(composed.timeline.reportedChangesOmitted === 0 ? {} : { moreChanges: true }),
116
109
  ...(composed.timeline.reportedChangesOutside === undefined
@@ -119,18 +112,13 @@ async function observeAkuma(status, path, repo) {
119
112
  };
120
113
  }
121
114
  function timeout(value) {
122
- if (value === undefined)
123
- return undefined;
124
- if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
125
- throw new TypeError("timeoutMs must be a nonnegative finite number");
126
- }
127
- return value;
115
+ return validateAkumaInput(durationSchema.optional(), value);
128
116
  }
129
117
  function signal(value) {
130
118
  if (value === undefined)
131
119
  return undefined;
132
120
  if (!(value instanceof AbortSignal))
133
- throw new TypeError("signal must be an AbortSignal");
121
+ throw new KeiyakuError("invalid-input", "signal must be an AbortSignal");
134
122
  return value;
135
123
  }
136
124
  function directAddress(values) {
@@ -150,7 +138,7 @@ function setAddress(values) {
150
138
  export async function statusAkuma(input, reportDiagnostic = stderrPluginDiagnostic) {
151
139
  const addressed = await addressAkuma(input);
152
140
  try {
153
- return await observeAkuma(await new AkumaOwner(addressed.id, addressed.path, outcomePluginObserver({ world: addressed.path, reportDiagnostic })).status(), addressed.path, input.repo);
141
+ return await observeAkuma(await new AkumaOwner(addressed.id, addressed.path, outcomePluginObserver({ world: addressed.path, reportDiagnostic })).status(), input.repo);
154
142
  }
155
143
  catch (error) {
156
144
  throw observationError(addressed.id, error);
@@ -161,7 +149,7 @@ function completionMode(value) {
161
149
  if (value === undefined)
162
150
  return "any";
163
151
  if (value !== "any" && value !== "all")
164
- throw new TypeError("completion must be any or all");
152
+ throw new KeiyakuError("invalid-input", "completion must be any or all");
165
153
  return value;
166
154
  }
167
155
  async function localWait(addressed, input) {
@@ -186,17 +174,13 @@ export async function waitAkuma(input, reportDiagnostic = stderrPluginDiagnostic
186
174
  const values = requireInput(input, "Akumas.wait input");
187
175
  for (const key of Object.keys(values)) {
188
176
  if (!["path", "akuma", "repo", "completion", "timeoutMs", "signal"].includes(key)) {
189
- throw new TypeError(`Akumas.wait input has unknown field: ${key}`);
177
+ throw new KeiyakuError("invalid-input", `Akumas.wait input has unknown field: ${key}`);
190
178
  }
191
179
  }
192
- if (Array.isArray(values.akuma) &&
193
- values.akuma.some((selector) => typeof selector === "string" && selector.startsWith("kei/"))) {
194
- throw new TypeError("Akumas.wait does not accept Contract selectors; use Keis.wait");
195
- }
196
180
  const selected = completionMode(values.completion);
197
181
  const timeoutMs = timeout(values.timeoutMs);
198
182
  const callerSignal = signal(values.signal);
199
- const addressed = await addressAkumaSet(setAddress(values));
183
+ const addressed = await addressAkumaSet(setAddress(values), { contractSelectors: false });
200
184
  return await withAkumaWaitDeferrals({ world: addressed.path, reportDiagnostic }, { akumaIds: addressed.orderedIds }, callerSignal, async () => {
201
185
  return await localWait(addressed, {
202
186
  completion: selected,
@@ -210,11 +194,17 @@ export async function killAkuma(input, spawn) {
210
194
  const values = requireInput(input, "Akumas.kill input");
211
195
  for (const key of Object.keys(values)) {
212
196
  if (!["path", "akuma", "repo", "signal"].includes(key)) {
213
- throw new TypeError(`Akumas.kill input has unknown field: ${key}`);
197
+ throw new KeiyakuError("invalid-input", `Akumas.kill input has unknown field: ${key}`);
214
198
  }
215
199
  }
200
+ if (typeof values.akuma !== "string" || values.akuma.trim().length === 0)
201
+ throw new KeiyakuError("invalid-input", "akuma must be a nonblank string");
216
202
  const callerSignal = signal(values.signal);
217
- const addressed = await addressAkumaSet(setAddress(values));
203
+ const addressed = await addressAkumaSet({
204
+ path: values.path,
205
+ akuma: [values.akuma],
206
+ ...(values.repo === undefined ? {} : { repo: values.repo }),
207
+ });
218
208
  return await executeKillAkuma({
219
209
  spawn,
220
210
  path: addressed.path,
@@ -222,52 +212,55 @@ export async function killAkuma(input, spawn) {
222
212
  ...(callerSignal === undefined ? {} : { signal: callerSignal }),
223
213
  });
224
214
  }
225
- export async function tellAkuma(input, spawn) {
215
+ export async function tellAkuma(input, spawn, reportDiagnostic = stderrPluginDiagnostic) {
226
216
  const values = requireInput(input, "Akumas.tell input");
227
217
  for (const key of Object.keys(values)) {
228
218
  if (key === "schema")
229
- throw new TypeError("Akumas.tell does not accept schema; use Akumas.ask");
230
- if (!["path", "akuma", "body", "repo", "interrupt", "initiator", "signal"].includes(key)) {
231
- throw new TypeError(`Akumas.tell input has unknown field: ${key}`);
219
+ throw new KeiyakuError("invalid-input", "Akumas.tell does not accept schema; use Akumas.ask");
220
+ if (!["path", "akuma", "body", "repo", "interrupt", "initiator", "signal", "wait", "timeoutMs", "observe"].includes(key)) {
221
+ throw new KeiyakuError("invalid-input", `Akumas.tell input has unknown field: ${key}`);
232
222
  }
233
223
  }
234
224
  if (typeof values.body !== "string")
235
- throw new TypeError("body must be a string");
225
+ throw new KeiyakuError("invalid-input", "body must be a string");
236
226
  if (values.interrupt !== undefined && typeof values.interrupt !== "boolean")
237
- throw new TypeError("interrupt must be a boolean");
227
+ throw new KeiyakuError("invalid-input", "interrupt must be a boolean");
228
+ validateTellObservation(values);
238
229
  const callerSignal = signal(values.signal);
239
230
  const addressed = await addressAkuma(directAddress(values));
240
- return await executeTellAkuma({
231
+ const execution = {
241
232
  spawn,
242
233
  path: addressed.path,
243
234
  id: addressed.id,
244
235
  body: input.body,
236
+ ...(input.wait === undefined ? {} : { wait: input.wait }),
237
+ ...(input.timeoutMs === undefined ? {} : { timeoutMs: input.timeoutMs }),
238
+ ...(input.observe === undefined ? {} : { onObserve: input.observe }),
239
+ outcomeObserved: outcomePluginObserver({ world: addressed.path, reportDiagnostic }),
245
240
  ...(input.interrupt === true ? { interrupt: true } : {}),
246
241
  ...(input.initiator === undefined ? {} : { initiator: input.initiator }),
247
242
  ...(callerSignal === undefined ? {} : { signal: callerSignal }),
248
- });
243
+ };
244
+ return input.wait === true
245
+ ? await withAkumaWaitDeferrals({ world: addressed.path, reportDiagnostic }, { akumaIds: [addressed.id] }, callerSignal, async () => await executeTellAkuma(execution))
246
+ : await executeTellAkuma(execution);
249
247
  }
250
248
  function validateAskInput(values) {
251
249
  for (const key of Object.keys(values)) {
252
250
  if (!["path", "akuma", "body", "repo", "timeoutMs", "schema", "interrupt", "initiator", "signal", "observe"].includes(key)) {
253
- throw new TypeError(`Akumas.ask input has unknown field: ${key}`);
251
+ throw new KeiyakuError("invalid-input", `Akumas.ask input has unknown field: ${key}`);
254
252
  }
255
253
  }
256
254
  if (typeof values.body !== "string")
257
- throw new TypeError("body must be a string");
258
- if (values.timeoutMs !== undefined &&
259
- (typeof values.timeoutMs !== "number" ||
260
- !Number.isFinite(values.timeoutMs) ||
261
- !Number.isInteger(values.timeoutMs) ||
262
- values.timeoutMs < 0)) {
263
- throw new TypeError("timeoutMs must be a nonnegative finite millisecond duration");
264
- }
255
+ throw new KeiyakuError("invalid-input", "body must be a string");
256
+ timeout(values.timeoutMs);
265
257
  if (values.interrupt !== undefined && typeof values.interrupt !== "boolean")
266
- throw new TypeError("interrupt must be a boolean");
258
+ throw new KeiyakuError("invalid-input", "interrupt must be a boolean");
267
259
  }
268
260
  export async function askAkuma(input, spawn, reportDiagnostic = stderrPluginDiagnostic) {
269
261
  const values = requireInput(input, "Akumas.ask input");
270
262
  validateAskInput(values);
263
+ const schema = canonicalDocument(input.schema);
271
264
  const callerSignal = signal(values.signal);
272
265
  const addressed = await addressAkuma(directAddress(values));
273
266
  return await withAkumaWaitDeferrals({ world: addressed.path, reportDiagnostic }, { akumaIds: [addressed.id] }, callerSignal, async () => {
@@ -278,30 +271,15 @@ export async function askAkuma(input, spawn, reportDiagnostic = stderrPluginDiag
278
271
  outcomeObserved: outcomePluginObserver({ world: addressed.path, reportDiagnostic }),
279
272
  body: input.body,
280
273
  ...(input.timeoutMs === undefined ? {} : { timeoutMs: input.timeoutMs }),
281
- ...(input.schema === undefined ? {} : { schemaJson: schemaJsonText(input.schema) }),
274
+ schemaJson: schema.jsonText,
282
275
  ...(input.interrupt === true ? { interrupt: true } : {}),
283
276
  ...(input.initiator === undefined ? {} : { initiator: input.initiator }),
284
277
  ...(input.observe === undefined ? {} : { onObserve: input.observe }),
285
278
  ...(callerSignal === undefined ? {} : { signal: callerSignal }),
286
279
  });
287
- return (input.schema === undefined ? result : decodeAskObservation(result, input.schema));
280
+ return result.kind === "answered" ? { ...result, answer: JSON.parse(result.answer) } : result;
288
281
  });
289
282
  }
290
- function validateHistoryInput(values) {
291
- for (const key of Object.keys(values)) {
292
- if (!["path", "akuma", "id", "before", "since", "limit", "last", "repo"].includes(key))
293
- throw new TypeError(`Akumas.history input has unknown field: ${key}`);
294
- }
295
- if (values.last !== undefined && typeof values.last !== "boolean")
296
- throw new TypeError("last must be a boolean");
297
- if (values.id !== undefined && (typeof values.id !== "string" || values.id.trim() === ""))
298
- throw new TypeError("id must be a nonblank string");
299
- if (values.id !== undefined && parseExactHistorySelector(values.id) === null)
300
- throw new TypeError("id must match turn/<positive safe integer> or report/<positive safe integer>");
301
- if (values.id !== undefined &&
302
- (values.last === true || values.before !== undefined || values.since !== undefined || values.limit !== undefined))
303
- throw new TypeError("id cannot be combined with last, before, since, or limit");
304
- }
305
283
  function historyPage(subject, page) {
306
284
  return {
307
285
  kind: "akuma",
@@ -315,24 +293,22 @@ function historyPage(subject, page) {
315
293
  }
316
294
  export async function historyAkuma(input, reportDiagnostic = stderrPluginDiagnostic) {
317
295
  const values = requireInput(input, "Akumas.history input");
318
- validateHistoryInput(values);
296
+ const { path: _path, akuma: _akuma, repo: _repo, ...selection } = values;
297
+ const { last, ...options } = validateAkumaInput(historySelectionSchema, selection);
319
298
  const addressed = await addressAkuma(directAddress(values));
320
299
  try {
321
300
  const handle = new AkumaOwner(addressed.id, addressed.path, outcomePluginObserver({ world: addressed.path, reportDiagnostic }));
322
301
  const subject = { akumaId: addressed.id };
323
- if (values.last === true) {
302
+ if (last === true) {
324
303
  const answer = await handle.lastAnswer();
325
304
  return answer.kind === "answer"
326
305
  ? { kind: "akuma-last", ...subject, answer: answer.answer }
327
306
  : { kind: "akuma-no-answer", ...subject };
328
307
  }
329
- const history = await handle.history({
330
- ...(values.id === undefined ? {} : { id: values.id }),
331
- ...(values.before === undefined ? {} : { before: values.before }),
332
- ...(values.since === undefined ? {} : { since: values.since }),
333
- ...(values.limit === undefined ? {} : { limit: values.limit }),
334
- });
335
- if (values.id !== undefined) {
308
+ const history = await handle.history(options);
309
+ if ("id" in options) {
310
+ if ("kind" in history && history.kind === "exact-activity")
311
+ return { kind: "akuma", ...subject, events: [history.row] };
336
312
  if ("kind" in history && history.kind === "exact") {
337
313
  const { kind: _kind, ...row } = history.outcome;
338
314
  return { kind: "akuma-exact", ...subject, ...row };
@@ -1,9 +1,15 @@
1
+ import { z } from "zod";
1
2
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
3
  type McpAdapterInput = Readonly<{
3
4
  cwd: string;
4
5
  environment: Readonly<Record<string, string | undefined>>;
5
6
  version: string;
6
7
  }>;
8
+ /** Compose at the declaration boundary so every strict business alternative stays strict. */
9
+ export declare function mcpInputSchema(input: z.core.$ZodType, worldOnly?: boolean): z.ZodType;
10
+ type JsonSchema = z.core.JSONSchema.BaseSchema;
11
+ /** Advertise shared structure; native verb validation owns cross-field admission. */
12
+ export declare function normalizeMcpSchema(schema: JsonSchema, input?: boolean): JsonSchema;
7
13
  export declare function createKeiyakuMcpServer(input: McpAdapterInput): Readonly<{
8
14
  server: Server;
9
15
  close(): Promise<void>;
@@ -1,4 +1,5 @@
1
1
  import { resolve } from "node:path";
2
+ import { isDeepStrictEqual } from "node:util";
2
3
  import { z } from "zod";
3
4
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
4
5
  import { CallToolRequestSchema, ListToolsRequestSchema, McpError, ErrorCode, } from "@modelcontextprotocol/sdk/types.js";
@@ -6,56 +7,194 @@ import { Keiyaku, KeiyakuUsageError } from "../library/keiyaku.js";
6
7
  import { classifyVerb, } from "../library/keiyaku-verbs.js";
7
8
  import { projectFailure } from "../library/outcome.js";
8
9
  import { renderVerb } from "../cli/render/verbs.js";
10
+ import { mcpOutputSchemas, projectMcpOutput } from "./output.js";
9
11
  import { DEFAULT_CLI_COLUMNS } from "../cli/render/terminal.js";
12
+ function hasOutputSchema(name) {
13
+ return Object.hasOwn(mcpOutputSchemas, name);
14
+ }
15
+ const SERVER_DESCRIPTION = "Agent work ledger for a Git repository. Contracts: bind, amend, arc, deliver, verify, review, abandon, reconcile. Akumas: spawn, fork, tell, ask, kill, wait, history, report. Read and inspect: show, status, ls, region, kanshi, whoami. Debts: debt_add, debt_update. show and ls also read Debts; wait and history also support Contracts.";
16
+ const NO_REPO_TOOLS = new Set(["debt.add", "debt.update", "report"]);
17
+ const excluded = new Set(["nuke", "settings", "debt.doctor", "debt.addDocument"]);
18
+ const coordinates = {
19
+ cwd: z
20
+ .string()
21
+ .regex(/\S/u)
22
+ .exactOptional()
23
+ .describe("Invocation directory (relative paths resolve from the MCP server startup directory); selects the World."),
24
+ repo: z
25
+ .string()
26
+ .regex(/\S/u)
27
+ .exactOptional()
28
+ .describe("Contract repository path (resolved from cwd when relative); selects the Contract repo without changing the World."),
29
+ };
30
+ /** Compose at the declaration boundary so every strict business alternative stays strict. */
31
+ export function mcpInputSchema(input, worldOnly = false) {
32
+ if (input instanceof z.ZodReadonly)
33
+ return mcpInputSchema(input.unwrap(), worldOnly).readonly();
34
+ if (input instanceof z.ZodUnion)
35
+ return z.union(input.options.map((branch) => mcpInputSchema(branch, worldOnly)));
36
+ if (!(input instanceof z.ZodObject) || !(input.def.catchall instanceof z.ZodNever))
37
+ throw new Error("MCP business inputs must be strict objects or unions of strict objects");
38
+ for (const key of Object.keys(coordinates)) {
39
+ if (Object.hasOwn(input.shape, key))
40
+ throw new Error(`MCP coordinate collides with business field: ${key}`);
41
+ }
42
+ return input.safeExtend(worldOnly ? { cwd: coordinates.cwd } : coordinates);
43
+ }
44
+ /** Remove annotations only at schema positions; property names and authored JSON stay intact. */
45
+ function cleanSchema(schema) {
46
+ const cleaned = {};
47
+ for (const [key, value] of Object.entries(schema)) {
48
+ if (key === "$schema" || (key === "readOnly" && typeof value === "boolean"))
49
+ continue;
50
+ if (["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"].includes(key)) {
51
+ cleaned[key] = Object.fromEntries(Object.entries(value).map(([name, child]) => [
52
+ name,
53
+ typeof child === "boolean" ? child : cleanSchema(child),
54
+ ]));
55
+ }
56
+ else if (["anyOf", "oneOf", "allOf", "prefixItems"].includes(key)) {
57
+ cleaned[key] = value.map((child) => typeof child === "boolean" ? child : cleanSchema(child));
58
+ }
59
+ else if ([
60
+ "items",
61
+ "additionalProperties",
62
+ "unevaluatedProperties",
63
+ "not",
64
+ "if",
65
+ "then",
66
+ "else",
67
+ "contains",
68
+ "propertyNames",
69
+ ].includes(key) &&
70
+ typeof value === "object" &&
71
+ value !== null) {
72
+ cleaned[key] = cleanSchema(value);
73
+ }
74
+ else
75
+ cleaned[key] = value;
76
+ }
77
+ if (cleaned.anyOf?.every((branch) => typeof branch === "object" && branch.type === "string") &&
78
+ cleaned.anyOf.some((branch) => typeof branch === "object" && Object.keys(branch).length === 1) &&
79
+ (cleaned.type === undefined || cleaned.type === "string")) {
80
+ delete cleaned.anyOf;
81
+ cleaned.type = "string";
82
+ }
83
+ return cleaned;
84
+ }
85
+ function sharedSchema(alternatives) {
86
+ const first = alternatives[0];
87
+ if (alternatives.every((value) => isDeepStrictEqual(value, first)))
88
+ return first;
89
+ if (alternatives.some((value) => typeof value === "boolean"))
90
+ return {};
91
+ const objects = alternatives;
92
+ const shared = {};
93
+ for (const [key, value] of Object.entries(first)) {
94
+ if (key === "description" || !objects.every((schema) => Object.hasOwn(schema, key)))
95
+ continue;
96
+ if (key === "items" && objects.every((schema) => typeof schema.items === "object")) {
97
+ shared.items = sharedSchema(objects.map((schema) => schema.items));
98
+ }
99
+ else if (key === "properties") {
100
+ shared.properties = Object.fromEntries(Object.keys(value)
101
+ .filter((name) => objects.every((schema) => Object.hasOwn(schema.properties, name)))
102
+ .map((name) => [name, sharedSchema(objects.map((schema) => schema.properties[name]))]));
103
+ }
104
+ else if (objects.every((schema) => isDeepStrictEqual(schema[key], value)))
105
+ shared[key] = value;
106
+ }
107
+ if (objects.every((schema) => Object.hasOwn(schema, "const"))) {
108
+ const values = [...new Set(objects.map((schema) => schema.const).filter((value) => value !== undefined))];
109
+ delete shared.const;
110
+ if (values.length === 2 && values.every((value) => typeof value === "boolean"))
111
+ shared.type = "boolean";
112
+ else
113
+ shared.enum = values;
114
+ }
115
+ const description = objects.find((schema) => schema.description)?.description;
116
+ if (description !== undefined)
117
+ shared.description = description;
118
+ return shared;
119
+ }
120
+ /** Advertise shared structure; native verb validation owns cross-field admission. */
121
+ export function normalizeMcpSchema(schema, input = false) {
122
+ const cleaned = cleanSchema(schema);
123
+ if (!input || cleaned.anyOf === undefined)
124
+ return cleaned;
125
+ const { anyOf: branches, ...root } = cleaned;
126
+ if (!branches.every((branch) => typeof branch === "object" && branch.type === "object" && branch.additionalProperties === false))
127
+ throw new Error("MCP input alternatives must be strict objects");
128
+ const objects = branches;
129
+ const keys = [...new Set(objects.flatMap((branch) => Object.keys(branch.properties ?? {})))];
130
+ const properties = Object.fromEntries(keys.map((key) => [
131
+ key,
132
+ sharedSchema(objects.flatMap((branch) => (branch.properties?.[key] === undefined ? [] : [branch.properties[key]]))),
133
+ ]));
134
+ const required = (objects[0].required ?? []).filter((key) => objects.every((branch) => branch.required?.includes(key)));
135
+ return {
136
+ ...root,
137
+ type: "object",
138
+ properties,
139
+ ...(required.length === 0 ? {} : { required }),
140
+ additionalProperties: false,
141
+ };
142
+ }
10
143
  function describeTools() {
11
- return Object.entries(Keiyaku.verbs).map(([name, entry]) => {
12
- const schema = z.toJSONSchema(z.object({ cwd: z.string().min(1).optional(), repo: z.string().min(1).optional(), input: entry.input }).strict(), { io: "input" });
13
- const output = z.toJSONSchema(entry.output, { io: "input" });
144
+ const entries = Object.entries(Keiyaku.verbs).filter(([name]) => !excluded.has(name));
145
+ return entries.map(([name, entry]) => {
146
+ const schema = normalizeMcpSchema(z.toJSONSchema(mcpInputSchema(entry.input, NO_REPO_TOOLS.has(name)), { io: "input" }), true);
147
+ const outputSchema = hasOutputSchema(name)
148
+ ? normalizeMcpSchema(z.toJSONSchema(mcpOutputSchemas[name], { io: "input" }))
149
+ : undefined;
14
150
  return {
15
- name,
151
+ name: name.replaceAll(".", "_"),
16
152
  description: entry.description,
17
- inputSchema: schema,
18
- ...(output.type === "object" ? { outputSchema: output } : {}),
19
- annotations: { readOnlyHint: entry.effect === "read", destructiveHint: entry.effect !== "read" },
153
+ inputSchema: { ...schema, type: "object" },
154
+ ...(outputSchema === undefined
155
+ ? {}
156
+ : { outputSchema: { ...outputSchema, type: "object" } }),
157
+ annotations: { readOnlyHint: entry.effect === "read", destructiveHint: entry.effect === "destroy" },
20
158
  };
21
159
  });
22
160
  }
23
- function validateArguments(args) {
24
- if (args === undefined ||
25
- !Object.hasOwn(args, "input") ||
26
- Object.keys(args).some((key) => !["cwd", "repo", "input"].includes(key)) ||
27
- (args.cwd !== undefined && (typeof args.cwd !== "string" || !args.cwd.trim())) ||
28
- (args.repo !== undefined && (typeof args.repo !== "string" || !args.repo.trim()))) {
29
- throw new KeiyakuUsageError("expected input and optional nonblank cwd and repo");
30
- }
161
+ function createMcpServer(version) {
162
+ return new Server({ name: "keiyaku", version, description: SERVER_DESCRIPTION }, { capabilities: { tools: {} } });
31
163
  }
32
164
  export function createKeiyakuMcpServer(input) {
33
165
  const cwd = input.cwd;
34
166
  const environment = { ...input.environment };
35
167
  const home = environment.KEIYAKU_HOME?.trim() || undefined;
36
- const server = new Server({ name: "keiyaku", version: input.version }, { capabilities: { tools: {} } });
168
+ const actorContext = environment.KEIYAKU_ACTOR_ID === undefined ? {} : { actor: environment.KEIYAKU_ACTOR_ID };
169
+ const server = createMcpServer(input.version);
37
170
  const tools = describeTools();
38
171
  const pending = new Set();
39
172
  let closing;
40
173
  server.setRequestHandler(ListToolsRequestSchema, () => ({ tools }));
41
174
  server.setRequestHandler(CallToolRequestSchema, (request, extra) => {
42
- const name = request.params.name;
43
- if (!Object.hasOwn(Keiyaku.verbs, name))
44
- throw new McpError(ErrorCode.InvalidParams, `Unknown tool: ${name}`);
175
+ const name = request.params.name.replaceAll("_", ".");
176
+ if (request.params.name.includes(".") || !Object.hasOwn(Keiyaku.verbs, name) || excluded.has(name))
177
+ throw new McpError(ErrorCode.InvalidParams, `Unknown tool: ${request.params.name}`);
45
178
  const operation = call(name, request.params.arguments, extra.signal);
46
179
  pending.add(operation);
47
- void operation.then(() => pending.delete(operation), () => pending.delete(operation));
180
+ void operation.finally(() => pending.delete(operation)).catch(() => { });
48
181
  return operation;
49
182
  });
50
183
  async function call(name, args, signal) {
51
- const value = args?.input;
184
+ const { cwd: callCwd, repo, ...business } = args ?? {};
185
+ const value = business;
52
186
  let completion;
53
187
  try {
54
- validateArguments(args);
188
+ const parsed = z.strictObject(NO_REPO_TOOLS.has(name) ? { cwd: coordinates.cwd } : coordinates).safeParse({
189
+ ...(callCwd === undefined ? {} : { cwd: callCwd }),
190
+ ...(repo === undefined ? {} : { repo }),
191
+ });
192
+ if (!parsed.success)
193
+ throw new KeiyakuUsageError(parsed.error.message);
55
194
  const facet = Keiyaku.at({
56
- cwd: resolve(cwd, args.cwd ?? "."),
195
+ cwd: resolve(cwd, parsed.data.cwd ?? "."),
57
196
  environment,
58
- ...(args.repo === undefined ? {} : { repo: args.repo }),
197
+ ...(!("repo" in parsed.data) || parsed.data.repo === undefined ? {} : { repo: parsed.data.repo }),
59
198
  ...(home === undefined ? {} : { home }),
60
199
  });
61
200
  completion = { kind: "returned", value: await facet.run(name, value, { signal }) };
@@ -66,26 +205,24 @@ export function createKeiyakuMcpServer(input) {
66
205
  try {
67
206
  const disposition = classifyVerb(name, value, completion);
68
207
  const text = renderVerb(name, value, completion, {
208
+ surface: "mcp",
69
209
  columns: DEFAULT_CLI_COLUMNS,
70
210
  color: false,
71
211
  now: Date.now(),
72
- ...(name === "report" && environment.KEIYAKU_ACTOR_ID !== undefined
73
- ? { actor: environment.KEIYAKU_ACTOR_ID }
74
- : {}),
212
+ ...(name === "report" || name === "ls" ? actorContext : {}),
75
213
  });
76
- const projected = completion.kind === "threw" ? projectFailure(completion.error) : JSON.parse(JSON.stringify(completion.value));
214
+ const isError = disposition !== "accepted" && disposition !== "unsatisfied";
77
215
  return {
78
216
  content: [
79
- { type: "text", text },
80
- ...(completion.kind === "threw" ? [{ type: "text", text: JSON.stringify(projected) }] : []),
217
+ { type: "text", text: isError ? `${disposition}\n${text}` : text },
218
+ ...(completion.kind === "threw"
219
+ ? [{ type: "text", text: JSON.stringify(projectFailure(completion.error)) }]
220
+ : []),
81
221
  ],
82
- isError: disposition !== "accepted",
222
+ isError,
83
223
  _meta: { "keiyaku/disposition": disposition },
84
- ...(completion.kind === "returned" &&
85
- typeof projected === "object" &&
86
- projected !== null &&
87
- !Array.isArray(projected)
88
- ? { structuredContent: projected }
224
+ ...(!isError && hasOutputSchema(name) && completion.kind === "returned"
225
+ ? { structuredContent: JSON.parse(JSON.stringify(projectMcpOutput(name, completion.value))) }
89
226
  : {}),
90
227
  };
91
228
  }
@@ -96,11 +233,9 @@ export function createKeiyakuMcpServer(input) {
96
233
  }
97
234
  return {
98
235
  server,
99
- close() {
100
- return (closing ??= (async () => {
101
- await server.close();
102
- await Promise.allSettled([...pending]);
103
- })());
104
- },
236
+ close: () => (closing ??= (async () => {
237
+ await server.close();
238
+ await Promise.allSettled([...pending]);
239
+ })()),
105
240
  };
106
241
  }
@@ -1 +1 @@
1
- export declare const MCP_HELP = "keiyaku-mcp \u2014 standalone Keiyaku MCP server over stdio\n\nusage keiyaku-mcp [--help]\n\nEach tool accepts { cwd?, repo?, input }. Input is required, even when empty.\nRelative cwd is resolved from the server startup directory. Tool results share\nKeiyaku's CLI text and native JSON facts.\n\nPi has built-in MCP. Add a server to ~/.pi/agent/mcp.json or the project's\n.pi/mcp.json, for example:\n\n{\n \"mcpServers\": {\n \"keiyaku\": {\n \"command\": \"keiyaku-mcp\",\n \"exposure\": \"direct\",\n \"timeout\": 600\n }\n }\n}\n\nExposure applies to the whole server; direct exposes every tool. The example's\n600-second client request timeout is independent of Keiyaku timeoutMs. Long\nask, wait, or verify calls may need a larger client timeout. Reload Pi after\nchanging configuration. This command never changes configuration.\n";
1
+ export declare const MCP_HELP = "keiyaku-mcp \u2014 standalone Keiyaku MCP server over stdio\n\nusage keiyaku-mcp [--help]\n\nEach tool accepts coordinates and business fields as one object. World-only\nDebt mutations and report accept cwd; other tools accept cwd and repo.\nKanshi has no business fields; status requires id. Unknown fields and incompatible\noptions are usage errors. Relative cwd is resolved from the server startup\ndirectory; repo independently selects the Contract repository. Tool results share\nKeiyaku's CLI text. Nine routing tools publish compact JSON decision facts;\nother tools return text only. Show returns complete unclipped guidance or Debt\ndetail. Native calls and CLI --json retain complete owner answers. Errors return text led by their\nclassification. An unsatisfied verification verdict is a normal answer.\nAdministration and raw import stay on the CLI.\n\nPi has built-in MCP. Add a server to ~/.pi/agent/mcp.json or the project's\n.pi/mcp.json, for example:\n\n{\n \"mcpServers\": {\n \"keiyaku\": {\n \"command\": \"keiyaku-mcp\",\n \"exposure\": \"direct\",\n \"timeout\": 600\n }\n }\n}\n\nExposure applies to the whole server. The client timeout is independent of Keiyaku\ntimeoutMs; ask, wait, or verify may need longer. Reload Pi after configuration changes.\n";
@@ -2,9 +2,16 @@ export const MCP_HELP = `keiyaku-mcp — standalone Keiyaku MCP server over stdi
2
2
 
3
3
  usage keiyaku-mcp [--help]
4
4
 
5
- Each tool accepts { cwd?, repo?, input }. Input is required, even when empty.
6
- Relative cwd is resolved from the server startup directory. Tool results share
7
- Keiyaku's CLI text and native JSON facts.
5
+ Each tool accepts coordinates and business fields as one object. World-only
6
+ Debt mutations and report accept cwd; other tools accept cwd and repo.
7
+ Kanshi has no business fields; status requires id. Unknown fields and incompatible
8
+ options are usage errors. Relative cwd is resolved from the server startup
9
+ directory; repo independently selects the Contract repository. Tool results share
10
+ Keiyaku's CLI text. Nine routing tools publish compact JSON decision facts;
11
+ other tools return text only. Show returns complete unclipped guidance or Debt
12
+ detail. Native calls and CLI --json retain complete owner answers. Errors return text led by their
13
+ classification. An unsatisfied verification verdict is a normal answer.
14
+ Administration and raw import stay on the CLI.
8
15
 
9
16
  Pi has built-in MCP. Add a server to ~/.pi/agent/mcp.json or the project's
10
17
  .pi/mcp.json, for example:
@@ -19,8 +26,6 @@ Pi has built-in MCP. Add a server to ~/.pi/agent/mcp.json or the project's
19
26
  }
20
27
  }
21
28
 
22
- Exposure applies to the whole server; direct exposes every tool. The example's
23
- 600-second client request timeout is independent of Keiyaku timeoutMs. Long
24
- ask, wait, or verify calls may need a larger client timeout. Reload Pi after
25
- changing configuration. This command never changes configuration.
29
+ Exposure applies to the whole server. The client timeout is independent of Keiyaku
30
+ timeoutMs; ask, wait, or verify may need longer. Reload Pi after configuration changes.
26
31
  `;