@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
@@ -7,14 +7,14 @@ import { prepareDelivery, deliveryIntegrationSnapshots } from "./deliver.js";
7
7
  import { verifyRequirement } from "./intent.js";
8
8
  import { timestamp, unpackVerificationOutcome } from "./operations.js";
9
9
  import { executionStop } from "./progress.js";
10
- import { compactPlacement, placementSchema } from "./completion.js";
10
+ import { placementSchema, normalPlacementSchema } from "./completion.js";
11
11
  import { activeReasonSchema, retrySchema, compactRetry, compactReason } from "./result-reasons.js";
12
12
  const checkCoordinate = {
13
13
  index: z.number().int().positive(),
14
14
  requirement: z.string().min(1),
15
15
  retainedPath: z.string().exactOptional(),
16
16
  };
17
- export const runtimeStopSchema = z.union([
17
+ const runtimeStopSchema = z.union([
18
18
  z
19
19
  .strictObject({ kind: z.enum(["unknown-exit", "cancelled"]), diagnostic: z.string().min(1).exactOptional() })
20
20
  .readonly(),
@@ -32,36 +32,58 @@ export const runtimeStopSchema = z.union([
32
32
  })
33
33
  .readonly(),
34
34
  ]);
35
- export const checkAdmissionStopSchema = z.union([
35
+ const checkAdmissionStopSchema = z
36
+ .union([
36
37
  z.strictObject({ kind: z.literal("refused"), reason: activeReasonSchema }).readonly(),
37
38
  ...retrySchema.options,
38
39
  z.strictObject({ kind: z.literal("cancelled") }).readonly(),
40
+ ])
41
+ .meta({ id: "verificationAdmissionStop" });
42
+ const normalAdmissionSchema = z.enum(["admitted", "reused", "unrecorded"]);
43
+ export function verificationAdmissionOutcome(admission) {
44
+ switch (admission) {
45
+ case "admitted":
46
+ case "reused":
47
+ case "unrecorded":
48
+ return "benign";
49
+ default:
50
+ switch (admission.kind) {
51
+ case "retry":
52
+ return "retry";
53
+ case "refused":
54
+ case "cancelled":
55
+ return "failed";
56
+ default: {
57
+ const exhaustive = admission;
58
+ return exhaustive;
59
+ }
60
+ }
61
+ }
62
+ }
63
+ function terminalCheckSchemas(admission) {
64
+ const terminal = { ...checkCoordinate, kind: z.literal("terminal"), admission };
65
+ return [
66
+ z.strictObject({ ...terminal, verdict: z.literal("satisfied") }).readonly(),
67
+ z.strictObject({ ...terminal, verdict: z.literal("unsatisfied"), summary: z.string() }).readonly(),
68
+ ];
69
+ }
70
+ const normalVerificationCheckSchema = z.union(terminalCheckSchemas(normalAdmissionSchema));
71
+ const verificationCheckSchema = z.union([
72
+ ...terminalCheckSchemas(z.union([normalAdmissionSchema, checkAdmissionStopSchema])),
73
+ z.strictObject({ ...checkCoordinate, kind: z.literal("stopped"), stop: runtimeStopSchema }).readonly(),
39
74
  ]);
40
- export const verificationStopSchema = z.union([runtimeStopSchema, checkAdmissionStopSchema]);
41
- const admission = z.union([z.literal("reused"), checkAdmissionStopSchema]).exactOptional();
42
- export const verificationCheckSchema = z.union([
43
- z
44
- .strictObject({ ...checkCoordinate, kind: z.literal("terminal"), verdict: z.literal("satisfied"), admission })
45
- .readonly(),
46
- z
75
+ function verifyValue(check, placement) {
76
+ return z
47
77
  .strictObject({
48
- ...checkCoordinate,
49
- kind: z.literal("terminal"),
50
- verdict: z.literal("unsatisfied"),
51
- summary: z.string(),
52
- admission,
78
+ snapshot: snapshotIdSchema,
79
+ checks: z.array(check).readonly(),
80
+ placement: placement.exactOptional(),
53
81
  })
54
- .readonly(),
55
- ...runtimeStopSchema.options.map((schema) => schema.unwrap().extend(checkCoordinate).readonly()),
56
- ]);
57
- export const verifyValueSchema = z
58
- .strictObject({
59
- snapshot: snapshotIdSchema,
60
- checks: z.array(verificationCheckSchema).readonly(),
61
- placement: placementSchema.exactOptional(),
62
- })
63
- .readonly();
64
- export function compactVerificationStop(stop) {
82
+ .readonly();
83
+ }
84
+ export const verifyNormalValueSchema = verifyValue(normalVerificationCheckSchema, normalPlacementSchema);
85
+ export const verifyValueSchema = verifyValue(verificationCheckSchema, placementSchema);
86
+ function compactVerificationStop(stop) {
65
87
  if ("refusal" in stop)
66
88
  return { kind: "refused", reason: compactReason(stop.refusal) };
67
89
  if ("retry" in stop)
@@ -81,14 +103,6 @@ export function compactVerificationStop(stop) {
81
103
  return { kind: stop.failure, diagnostic: stop.diagnostic };
82
104
  }
83
105
  }
84
- export function compactVerify(value) {
85
- const placement = compactPlacement(value);
86
- return {
87
- snapshot: value.snapshot,
88
- checks: value.checks,
89
- ...(placement === undefined ? {} : { placement }),
90
- };
91
- }
92
106
  async function prepareVerification(input) {
93
107
  input.signal?.throwIfAborted();
94
108
  const observed = await observeGitForAdmissionAt(input.scope, input.channel, [input.contractId]);
@@ -102,8 +116,6 @@ async function prepareVerification(input) {
102
116
  if (derivation.verification.kind === "refused")
103
117
  return { kind: "refused", refusal: derivation.verification.refusal };
104
118
  const definition = derivation.verification.data;
105
- if (definition === null)
106
- return { kind: "refused", refusal: { kind: "verification-not-selected" } };
107
119
  if (input.index !== undefined && input.index > definition.declarations.length)
108
120
  return {
109
121
  kind: "refused",
@@ -124,7 +136,6 @@ async function prepareVerification(input) {
124
136
  document: derivation.bytes,
125
137
  includeDirty: input.includeDirty,
126
138
  requireBranchesToBeUpToDate: input.requireBranchesToBeUpToDate,
127
- ...(input.actor === undefined ? {} : { actor: input.actor }),
128
139
  });
129
140
  if (prepared.kind === "refused")
130
141
  return prepared;
@@ -139,15 +150,13 @@ function checkReport(coordinate, checked) {
139
150
  const stop = compactVerificationStop(checked.stop);
140
151
  if (stop.kind === "refused" || stop.kind === "retry")
141
152
  throw new Error("nonterminal check requires a runtime stop");
142
- return { ...fields, ...stop };
153
+ return { ...fields, kind: "stopped", stop };
143
154
  }
144
- // A terminal verdict only proves admission when custody holds the matching attestation, reuse, or stop.
145
- const attested = checked.admission?.facts.some((fact) => fact.kind === "attestation" && fact.data.gate === VERIFIED && fact.data.requirement === requirement);
146
155
  let admission;
147
156
  if (checked.reuse !== undefined)
148
157
  admission = "reused";
149
- else if (attested === true)
150
- admission = undefined;
158
+ else if (checked.admission !== undefined)
159
+ admission = "admitted";
151
160
  else if (checked.stop !== undefined) {
152
161
  const stop = compactVerificationStop(checked.stop);
153
162
  if (stop.kind === "refused" || stop.kind === "retry")
@@ -158,15 +167,15 @@ function checkReport(coordinate, checked) {
158
167
  throw new Error("terminal check admission can only refuse, retry or cancel");
159
168
  }
160
169
  else
161
- throw new Error("terminal verification requires its admission conclusion");
162
- const terminal = { ...fields, kind: "terminal", ...(admission === undefined ? {} : { admission }) };
170
+ admission = "unrecorded";
171
+ const terminal = { ...fields, kind: "terminal", admission };
163
172
  if (checked.counts.verdict === "satisfied")
164
173
  return { ...terminal, verdict: "satisfied" };
165
174
  if (checked.counts.summary === undefined)
166
175
  throw new Error("unsatisfied terminal check requires its diagnosis");
167
176
  return { ...terminal, verdict: "unsatisfied", summary: checked.counts.summary };
168
177
  }
169
- /** Capture a prospective delivery without admitting a candidate, then independently attest each check. */
178
+ /** Capture a prospective delivery, then independently execute each selected declaration. */
170
179
  export async function verifyOperation(input) {
171
180
  const prepared = await prepareVerification(input);
172
181
  if (prepared.kind === "refused")
@@ -190,13 +199,13 @@ export async function verifyOperation(input) {
190
199
  channel: input.channel,
191
200
  repository: input.scope,
192
201
  contractId: state.id,
202
+ gates: state.terms.gates,
193
203
  at: timestamp(),
194
204
  snapshot,
195
205
  declaration,
196
206
  requirement,
197
207
  index,
198
208
  total: definition.declarations.length,
199
- ...(input.actor === undefined ? {} : { actor: input.actor }),
200
209
  ...(input.signal === undefined ? {} : { signal: input.signal }),
201
210
  ...(input.progress === undefined ? {} : { progress: input.progress }),
202
211
  });
@@ -214,5 +223,9 @@ export async function verifyOperation(input) {
214
223
  if (checked.stop !== undefined)
215
224
  break;
216
225
  }
217
- return { kind: "accepted", checkpoint, value: { snapshot, checks } };
226
+ return {
227
+ kind: "accepted",
228
+ ...(state.terms.gates.includes(VERIFIED) ? { checkpoint } : {}),
229
+ value: { snapshot, checks },
230
+ };
218
231
  }
@@ -1,15 +1,11 @@
1
+ import { KeiyakuError } from "./errors.js";
1
2
  import { z } from "zod";
2
3
  export type SettingsScope = "project" | "user";
3
4
  export type SettingsScopeState = z.output<typeof settingsScopeStateSchema>;
4
5
  export type SettingsEntry = z.output<typeof settingsEntrySchema>;
5
6
  export type SettingsNamespaceFailure = z.output<typeof settingsNamespaceFailureSchema>;
6
7
  export type SettingsNamespaceView = z.output<typeof settingsNamespaceViewSchema>;
7
- export type Settings = Readonly<{
8
- scopes: Readonly<{
9
- project: SettingsScopeState;
10
- user: SettingsScopeState;
11
- }>;
12
- namespaces?: Readonly<Record<string, SettingsNamespaceView>>;
8
+ export type Settings = z.output<typeof settingsSchema> & Readonly<{
13
9
  namespace(name: string): SettingsNamespaceView;
14
10
  }>;
15
11
  export declare const settingsScopeStateSchema: z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
@@ -132,14 +128,17 @@ export declare const settingsSchema: z.ZodReadonly<z.ZodObject<{
132
128
  }>>>>>;
133
129
  }, z.core.$strict>>;
134
130
  export type SettingsInput = Readonly<{
135
- root?: string;
131
+ cwd?: string;
136
132
  home?: string;
137
133
  }>;
138
- export declare class SettingsError extends Error {
134
+ export declare class SettingsError extends KeiyakuError {
139
135
  readonly kind = "settings";
140
136
  constructor(message: string);
141
137
  }
142
- export declare function settings(input?: SettingsInput): Promise<Settings>;
138
+ declare function loadSettings(input?: SettingsInput): Promise<Settings>;
139
+ export declare const Settings: Readonly<{
140
+ load: typeof loadSettings;
141
+ }>;
143
142
  /** Read only the project scope owned by a materialized candidate snapshot. */
144
143
  export declare function projectSettings(root: string): Promise<Settings>;
145
144
  export {};
@@ -1,3 +1,4 @@
1
+ import { KeiyakuError } from "./errors.js";
1
2
  import { z } from "zod";
2
3
  import { readFile, realpath } from "node:fs/promises";
3
4
  import { homedir } from "node:os";
@@ -60,11 +61,10 @@ export const settingsSchema = z
60
61
  namespaces: keyedValues(settingsNamespaceViewSchema).exactOptional(),
61
62
  })
62
63
  .readonly();
63
- export class SettingsError extends Error {
64
+ export class SettingsError extends KeiyakuError {
64
65
  kind = "settings";
65
66
  constructor(message) {
66
- super(message);
67
- this.name = "SettingsError";
67
+ super("invalid-input", message);
68
68
  }
69
69
  }
70
70
  function object(value) {
@@ -155,7 +155,7 @@ function settingsFromScopes(project, user) {
155
155
  }
156
156
  function namespace(name) {
157
157
  if (typeof name !== "string" || name.trim().length === 0)
158
- throw new TypeError("settings namespace must be nonblank");
158
+ throw new KeiyakuError("invalid-input", "settings namespace must be nonblank");
159
159
  return resolveNamespace(name);
160
160
  }
161
161
  const names = [...new Set([user, project].flatMap((scope) => Object.keys(scope.root ?? {})))].sort();
@@ -176,16 +176,18 @@ async function canonicalCoordinate(path) {
176
176
  return resolvedPath;
177
177
  }
178
178
  }
179
- export async function settings(input = {}) {
179
+ async function loadSettings(input = {}) {
180
180
  if (!object(input))
181
- throw new TypeError("settings input must be an object");
182
- if (input.root !== undefined && (typeof input.root !== "string" || input.root.trim().length === 0)) {
183
- throw new TypeError("settings root must be a nonblank string");
181
+ throw new KeiyakuError("invalid-input", "settings input must be an object");
182
+ for (const key of Object.keys(input))
183
+ if (key !== "cwd" && key !== "home")
184
+ throw new KeiyakuError("invalid-input", `settings input has unknown field: ${key}`);
185
+ for (const field of ["cwd", "home"]) {
186
+ const value = input[field];
187
+ if (value !== undefined && (typeof value !== "string" || value.trim().length === 0))
188
+ throw new KeiyakuError("invalid-input", `settings ${field} must be a nonblank string`);
184
189
  }
185
- if (input.home !== undefined && (typeof input.home !== "string" || input.home.trim().length === 0)) {
186
- throw new TypeError("settings home must be a nonblank string");
187
- }
188
- const projectDirectory = input.root === undefined ? undefined : await canonicalCoordinate(join(input.root, ".keiyaku"));
190
+ const projectDirectory = input.cwd === undefined ? undefined : await canonicalCoordinate(join(input.cwd, ".keiyaku"));
189
191
  const userDirectory = await canonicalCoordinate(input.home ?? join(homedir(), ".keiyaku"));
190
192
  const project = projectDirectory === undefined || projectDirectory === userDirectory
191
193
  ? { state: { kind: "absent" } }
@@ -193,10 +195,11 @@ export async function settings(input = {}) {
193
195
  const user = await readScope(join(userDirectory, "settings.json"));
194
196
  return settingsFromScopes(project, user);
195
197
  }
198
+ export const Settings = Object.freeze({ load: loadSettings });
196
199
  /** Read only the project scope owned by a materialized candidate snapshot. */
197
200
  export async function projectSettings(root) {
198
201
  if (typeof root !== "string" || root.trim().length === 0)
199
- throw new TypeError("settings root must be a nonblank string");
202
+ throw new KeiyakuError("invalid-input", "settings root must be a nonblank string");
200
203
  return settingsFromScopes(await readScope(join(resolve(root), ".keiyaku", "settings.json")), {
201
204
  state: { kind: "absent" },
202
205
  });
@@ -4,7 +4,7 @@ import { contractId } from "../core/facts/types.js";
4
4
  import { GIT_REF, updateGitTree, updateRefsAtomically, writeBlob, writeStateCommit } from "../git/repository.js";
5
5
  import { confirmPrivateStatePublication } from "../git/private-state-seat.js";
6
6
  import { withGitTargetedReadObservation, } from "../git/read-observation.js";
7
- import { parseDebtId } from "../debt/identity.js";
7
+ import { canonicalDebtId } from "../debt/identity.js";
8
8
  import { acquireDebtSettlementFence } from "./fence.js";
9
9
  // The private persisted spelling predates the product rename. Keep its bytes
10
10
  // and path stable so an existing held association still settles after upgrade.
@@ -58,7 +58,7 @@ function decodeHolder(path, bytes) {
58
58
  let owner;
59
59
  try {
60
60
  debtId = `debt/${record.taskId.slice("task/".length)}`;
61
- parseDebtId(debtId);
61
+ canonicalDebtId(debtId);
62
62
  owner = contractId(record.contractId);
63
63
  }
64
64
  catch (error) {
@@ -54,11 +54,5 @@ export type SettlementInput = Readonly<{
54
54
  effects: readonly Effect[];
55
55
  progress?: SettlementProgress;
56
56
  }>;
57
- export type SettlementBatchInput = Readonly<{
58
- repository: GitRepository;
59
- channel: GitDecodeChannel;
60
- contracts: readonly Readonly<Pick<SettlementInput, "state" | "effects">>[];
61
- }>;
62
57
  export declare function settle(input: SettlementInput): Promise<SettlementReport>;
63
- export declare function settleAll(input: SettlementBatchInput): Promise<readonly SettlementReport[]>;
64
58
  export {};
@@ -295,7 +295,3 @@ export async function settle(input) {
295
295
  const repository = onPrimaryWorktree(input.repository);
296
296
  return await settleObserved({ ...input, repository });
297
297
  }
298
- export async function settleAll(input) {
299
- const repository = onPrimaryWorktree(input.repository);
300
- return await Promise.all(input.contracts.map((contract) => settleObserved({ repository, channel: input.channel, ...contract })));
301
- }
@@ -13,13 +13,10 @@ export type VerificationDefinition = Readonly<{
13
13
  export type VerificationDeclarationRefusal = Readonly<{
14
14
  kind: "verification-declaration-invalid";
15
15
  }>;
16
- export type VerificationDeclarationPreparation = Preparation<VerificationDefinition | null, VerificationDeclarationRefusal>;
17
- export declare const VERIFIED: Gate;
16
+ export type VerificationDeclarationPreparation = Preparation<VerificationDefinition, VerificationDeclarationRefusal>;
17
+ export declare const VERIFIED: string;
18
18
  /** The display index and surrounding document never participate in execution identity. */
19
19
  export declare function verificationRequirement(declaration: VerificationDeclaration): RequirementId;
20
20
  export declare function singletonRequirement(declaredGate: Gate): RequirementId;
21
21
  export declare function gateRequirements(gates: readonly Gate[], definition: VerificationDefinition | null): Readonly<Record<string, readonly RequirementId[]>>;
22
- export declare function prepareVerificationDeclaration(input: Readonly<{
23
- gates: readonly Gate[];
24
- definition: VerificationDefinition | null;
25
- }>): VerificationDeclarationPreparation;
22
+ export declare function prepareVerificationDeclaration(definition: VerificationDefinition | null): VerificationDeclarationPreparation;
@@ -17,11 +17,9 @@ export function gateRequirements(gates, definition) {
17
17
  : [singletonRequirement(declaredGate)],
18
18
  ]));
19
19
  }
20
- export function prepareVerificationDeclaration(input) {
21
- if (!input.gates.includes(VERIFIED))
22
- return { kind: "prepared", data: null };
23
- if (input.definition !== null && input.definition.declarations.length > 0)
24
- return { kind: "prepared", data: input.definition };
20
+ export function prepareVerificationDeclaration(definition) {
21
+ if (definition !== null && definition.declarations.length > 0)
22
+ return { kind: "prepared", data: definition };
25
23
  return {
26
24
  kind: "refused",
27
25
  refusal: { kind: "verification-declaration-invalid" },
@@ -7,8 +7,8 @@ export declare const verificationObservationSchema: z.ZodDiscriminatedUnion<[z.Z
7
7
  outcome: z.ZodExactOptional<z.ZodString>;
8
8
  elapsedMs: z.ZodExactOptional<z.ZodNumber>;
9
9
  phase: z.ZodEnum<{
10
- cleanup: "cleanup";
11
10
  materialize: "materialize";
11
+ cleanup: "cleanup";
12
12
  setup: "setup";
13
13
  declaration: "declaration";
14
14
  }>;
@@ -27,8 +27,8 @@ export declare const verificationObservationSchema: z.ZodDiscriminatedUnion<[z.Z
27
27
  }>;
28
28
  text: z.ZodString;
29
29
  phase: z.ZodEnum<{
30
- cleanup: "cleanup";
31
30
  materialize: "materialize";
31
+ cleanup: "cleanup";
32
32
  setup: "setup";
33
33
  declaration: "declaration";
34
34
  }>;
@@ -1,3 +1,4 @@
1
+ import { KeiyakuError } from "./errors.js";
1
2
  import { z } from "zod";
2
3
  declare const WORLD_BRAND: unique symbol;
3
4
  export type WorldRoot = string & {
@@ -19,11 +20,11 @@ export type WorldResolution = Readonly<{
19
20
  candidate: WorldRoot | null;
20
21
  establish: () => Promise<WorldRoot>;
21
22
  }>;
22
- export declare class WorldError extends Error {
23
+ export declare class WorldError extends KeiyakuError {
23
24
  readonly kind: "invalid-world";
24
25
  constructor(message: string);
25
26
  }
26
- type WorldInput = string | WorldResolutionInput;
27
+ export type WorldInput = string | WorldResolutionInput;
27
28
  export declare const World: Readonly<{
28
29
  resolve(input: WorldInput): Promise<WorldResolution>;
29
30
  locate(input: WorldInput): Promise<WorldRoot | null>;
@@ -1,3 +1,4 @@
1
+ import { KeiyakuError } from "./errors.js";
1
2
  import { z } from "zod";
2
3
  import { lstat, mkdir, realpath, stat } from "node:fs/promises";
3
4
  import { dirname, join, parse, resolve } from "node:path";
@@ -8,17 +9,15 @@ export const worldResolutionSchema = z
8
9
  .readonly();
9
10
  export const worldLocationSchema = worldRootSchema.nullable();
10
11
  export const worldEstablishedSchema = z.boolean();
11
- export class WorldError extends Error {
12
+ export class WorldError extends KeiyakuError {
12
13
  kind = "invalid-world";
13
14
  constructor(message) {
14
- super(message);
15
- this.name = "WorldError";
16
- this.kind = "invalid-world";
15
+ super("internal", message);
17
16
  }
18
17
  }
19
18
  async function directory(input, label) {
20
19
  if (typeof input !== "string" || input.trim().length === 0) {
21
- throw new TypeError(`${label} must be a nonblank path`);
20
+ throw new KeiyakuError("invalid-input", `${label} must be a nonblank path`);
22
21
  }
23
22
  const path = resolve(input);
24
23
  let real;
@@ -61,7 +60,7 @@ async function inputValues(input, label) {
61
60
  if (typeof input === "string")
62
61
  return { cwd: await directory(input, label) };
63
62
  if (input === null || typeof input !== "object")
64
- throw new TypeError(`${label} must be a path or resolution input`);
63
+ throw new KeiyakuError("invalid-input", `${label} must be a path or resolution input`);
65
64
  const cwd = await directory(input.cwd, `${label} cwd`);
66
65
  if (input.repositoryRoot === undefined)
67
66
  return { cwd };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrosheep/keiyaku",
3
- "version": "4.6.31",
3
+ "version": "4.6.32",
4
4
  "workspaces": [
5
5
  "plugins/square",
6
6
  "plugins/paseo/forwarder"
@@ -14,7 +14,7 @@ export default function contribute(server: PluginServerContext) {
14
14
  const mirror = createProvider(transport, handoff);
15
15
  server.registerProvider(mirror.provider);
16
16
  server.handle(refreshRpc, (input, context) => refreshOrReopen(context.paseo, input, mirror.refresh));
17
- server.handle(attachRpc, (input, context) => attach(input, context));
17
+ server.handle(attachRpc, (input, context) => attach(input, context, transport.status));
18
18
  const removeModelCorrection = registerModelCorrection(server, transport.status);
19
19
  const removeHooks = registerRegistrationHooks(server, handoff);
20
20
  return async () => {
@@ -3,87 +3,94 @@ import type { PaseoAgent } from "@getpaseo/client";
3
3
  import type { PluginHandlerContext } from "@getpaseo/plugin/server";
4
4
  import type { z } from "zod";
5
5
  import type { attachRpc } from "../shared/attach-rpc.js";
6
+ import { raceAbort, type StatusReader } from "./transport.js";
6
7
  import { listMirrorCandidates, matchesCanonicalMirror } from "./mirror-identity.js";
7
8
 
9
+ type Input = z.output<typeof attachRpc.input>;
10
+ const MAX_ANCESTRY = 32;
11
+
8
12
  function skip(reason: string) {
9
13
  console.warn(`Keiyaku mirror not attached: ${reason}`);
10
14
  return { attached: false };
11
15
  }
12
- export async function attach(input: z.output<typeof attachRpc.input>, { paseo }: PluginHandlerContext) {
13
- const caller = input.caller;
14
- if (caller?.kind === "akuma") return attachToAkuma(input, caller, paseo);
15
- if (caller?.kind !== "external") return skip("caller is not an external host");
16
- const native = ["codex", "pi", "claude"].includes(caller.integration);
17
- let parentId = caller.id;
18
- const matches = (agent: { persistence?: { provider: string; sessionId: string } | null }) =>
19
- agent.persistence?.provider === caller.integration && agent.persistence.sessionId === caller.id;
20
- if (native) {
16
+
17
+ /** Each attempt owns its ancestry; daemon creation owns concurrency/idempotency. */
18
+ export async function attach(input: Input, { paseo }: PluginHandlerContext, readStatus?: StatusReader) {
19
+ const seen = new Set<string>();
20
+ // The installed RPC context has no cancellation signal. Fence local custody
21
+ // with a deadline; list supports cancellation, refresh/create do not.
22
+ const signal = AbortSignal.timeout(4000);
23
+ async function ensure(target: Input): Promise<{ attached: boolean }> {
24
+ signal.throwIfAborted();
25
+ const world = await realpath(target.world);
26
+ const key = `keiyaku:${world}:${target.akuId}`;
27
+ if (seen.has(key) || seen.size >= MAX_ANCESTRY) return skip("cyclic or excessively deep Akuma caller ancestry");
28
+ seen.add(key);
29
+ // Include archived/detached children: host intent forbids a replacement or reparent.
30
+ const existing = await listMirrorCandidates(paseo, world, target.akuId, true, signal);
31
+ if (existing.length > 1) return skip(`ambiguous mirror for ${target.akuId}`);
32
+ if (existing.length === 1) return { attached: true };
33
+
34
+ let caller = target.caller;
35
+ if (caller === undefined && readStatus !== undefined) {
36
+ const retained = (await readStatus(world, target.akuId, signal)).caller;
37
+ caller = retained?.kind === "akuma"
38
+ ? { kind: "akuma", world: retained.world, akuId: retained.akumaId } : retained;
39
+ }
40
+ if (caller?.kind === "akuma") {
41
+ const parentWorld = await realpath(caller.world);
42
+ let candidates = await listMirrorCandidates(paseo, parentWorld, caller.akuId, true, signal);
43
+ if (candidates.length === 0 && readStatus !== undefined) {
44
+ if (!(await ensure({ world: parentWorld, akuId: caller.akuId })).attached) return { attached: false };
45
+ candidates = await listMirrorCandidates(paseo, parentWorld, caller.akuId, true, signal);
46
+ }
47
+ if (candidates.length !== 1) return skip(candidates.length
48
+ ? `ambiguous Akuma parent ${caller.akuId}: multiple mirrors`
49
+ : `no mirror for Akuma parent ${caller.akuId}`);
50
+ const parent = await raceAbort(signal, () => paseo.agents.ref(candidates[0]!.id).refresh());
51
+ if (!parent) return skip(`Akuma parent mirror ${candidates[0]!.id} does not exist`);
52
+ if (parent.agent.archivedAt) return skip(`Akuma parent mirror ${parent.agent.id} is archived`);
53
+ if (parent.agent.id !== candidates[0]!.id || !(await matchesCanonicalMirror(parent.agent, parentWorld, caller.akuId)))
54
+ return skip(`Akuma parent mirror ${parent.agent.id} changed identity`);
55
+ return create(world, target.akuId, parent.agent);
56
+ }
57
+ if (caller?.kind !== "external") return skip("caller is not an external host");
58
+ if (!["codex", "pi", "claude"].includes(caller.integration))
59
+ return skip(`unsupported caller integration ${caller.integration}`);
60
+ const matches = (agent: Pick<PaseoAgent, "persistence">) =>
61
+ agent.persistence?.sessionId === caller.id &&
62
+ (agent.persistence.metadata?.provider ?? agent.persistence.provider) === caller.integration;
21
63
  const candidates: string[] = [];
64
+ const cursors = new Set<string>();
22
65
  let cursor: string | undefined;
23
- do {
24
- const filter = { includeArchived: true };
25
- const page = await paseo.agents.list({ filter, page: { limit: 200, ...(cursor ? { cursor } : {}) } });
66
+ for (;;) {
67
+ signal.throwIfAborted();
68
+ const page = await raceAbort(signal, () => paseo.agents.list({ filter: { includeArchived: true, includeBackground: true }, signal,
69
+ page: { limit: 200, ...(cursor ? { cursor } : {}) } }));
26
70
  for (const { agent } of page.entries) if (matches(agent)) candidates.push(agent.id);
27
71
  if (candidates.length > 1) return skip(`ambiguous ${caller.integration} session ${caller.id}: multiple parents`);
28
72
  if (!page.pageInfo.hasMore) break;
29
73
  const next = page.pageInfo.nextCursor;
30
- if (!next || next === cursor) return skip("incomplete parent directory pagination");
74
+ if (!next || cursors.has(next)) return skip("incomplete parent directory pagination");
75
+ cursors.add(next);
31
76
  cursor = next;
32
- } while (cursor);
77
+ }
33
78
  if (!candidates[0]) return skip(`no parent for ${caller.integration} session ${caller.id}`);
34
- parentId = candidates[0];
35
- } else if (caller.integration !== "paseo") {
36
- return skip(`unsupported caller integration ${caller.integration}`);
37
- }
38
- const parent = await paseo.agents.ref(parentId).refresh();
39
- if (!parent) return skip(`parent ${parentId} does not exist`);
40
- if (parent.agent.archivedAt) return skip(`parent ${parentId} is archived`);
41
- if (native && !matches(parent.agent)) return skip(`parent ${parentId} changed native identity`);
42
- const world = await realpath(input.world);
43
- // Keep the creation fingerprint immutable: aliases belong to the forwarder's
44
- // rename path, not this idempotent request (including retries after rename).
45
- await paseo.agents.create({ parent: parentId, cwd: parent.agent.cwd, title: input.akuId,
46
- config: { provider: "keiyaku/mirror", options: { world, akuId: input.akuId } },
47
- idempotencyKey: `keiyaku:${world}:${input.akuId}`,
48
- });
49
- return { attached: true };
50
- }
51
-
52
- async function attachToAkuma(input: z.output<typeof attachRpc.input>,
53
- caller: Extract<NonNullable<z.output<typeof attachRpc.input>["caller"]>, { kind: "akuma" }>,
54
- paseo: PluginHandlerContext["paseo"]): Promise<{ attached: boolean }> {
55
- let parentWorld: string;
56
- let childWorld: string;
57
- try {
58
- [parentWorld, childWorld] = await Promise.all([realpath(caller.world), realpath(input.world)]);
59
- } catch {
60
- return skip("Akuma parent or child World is unavailable");
61
- }
62
- let candidates: PaseoAgent[];
63
- try {
64
- candidates = await listMirrorCandidates(paseo, parentWorld, caller.akuId, true);
65
- } catch (error) {
66
- return skip(error instanceof Error ? error.message : String(error));
67
- }
68
- if (candidates.length !== 1) return skip(candidates.length
69
- ? `ambiguous Akuma parent ${caller.akuId}: multiple mirrors`
70
- : `no mirror for Akuma parent ${caller.akuId}`);
71
- const candidate = candidates[0]!;
72
- let current: { agent: PaseoAgent } | null;
73
- try {
74
- current = await paseo.agents.ref(candidate.id).refresh();
75
- } catch (error) {
76
- return skip(`Akuma parent mirror ${candidate.id} could not be read: ${error instanceof Error ? error.message : String(error)}`);
79
+ const parent = await raceAbort(signal, () => paseo.agents.ref(candidates[0]!).refresh());
80
+ if (!parent) return skip(`parent ${candidates[0]} does not exist`);
81
+ if (parent.agent.archivedAt) return skip(`parent ${parent.agent.id} is archived`);
82
+ if (parent.agent.id !== candidates[0] || !matches(parent.agent)) return skip(`parent ${parent.agent.id} changed native identity`);
83
+ return create(world, target.akuId, parent.agent);
77
84
  }
78
- if (!current) return skip(`Akuma parent mirror ${candidate.id} does not exist`);
79
- if (current.agent.archivedAt) return skip(`Akuma parent mirror ${candidate.id} is archived`);
80
- if (!(await matchesCanonicalMirror(current.agent, parentWorld, caller.akuId))) {
81
- return skip(`Akuma parent mirror ${candidate.id} changed identity`);
85
+ async function create(world: string, akuId: string, parent: PaseoAgent) {
86
+ signal.throwIfAborted();
87
+ // Aliases never change this creation fingerprint, including after a rename.
88
+ await paseo.agents.create({ parent: parent.id, cwd: parent.cwd, title: akuId,
89
+ config: { provider: "keiyaku/mirror", options: { world, akuId } },
90
+ idempotencyKey: `keiyaku:${world}:${akuId}`,
91
+ });
92
+ return { attached: true };
82
93
  }
83
- const parentId = current.agent.id;
84
- await paseo.agents.create({ parent: parentId, cwd: current.agent.cwd, title: input.akuId,
85
- config: { provider: "keiyaku/mirror", options: { world: childWorld, akuId: input.akuId } },
86
- idempotencyKey: `keiyaku:${childWorld}:${input.akuId}`,
87
- });
88
- return { attached: true };
94
+ try { return await raceAbort(signal, () => ensure(input)); }
95
+ catch (error) { return skip(error instanceof Error ? error.message : String(error)); }
89
96
  }