@astrosheep/keiyaku 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/README.md +133 -8
  2. package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +2 -2
  3. package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +4 -4
  4. package/build/integrations/marketplace/plugins/keiyaku/opencode.js +2 -2
  5. package/build/integrations/marketplace/plugins/keiyaku/package.json +2 -2
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +13 -5
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +91 -32
  8. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +134 -0
  9. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/agents/openai.yaml +4 -0
  10. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-task/SKILL.md +41 -6
  11. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +262 -46
  12. package/build/src/akuma/abort.d.ts +2 -0
  13. package/build/src/akuma/abort.js +50 -0
  14. package/build/src/akuma/akuma.d.ts +50 -33
  15. package/build/src/akuma/akuma.js +175 -127
  16. package/build/src/akuma/archetype.d.ts +14 -5
  17. package/build/src/akuma/archetype.js +85 -39
  18. package/build/src/akuma/body.d.ts +3 -5
  19. package/build/src/akuma/body.js +490 -183
  20. package/build/src/akuma/coordinate.d.ts +9 -0
  21. package/build/src/akuma/coordinate.js +22 -0
  22. package/build/src/akuma/heart/facts.d.ts +88 -45
  23. package/build/src/akuma/heart/facts.js +19 -8
  24. package/build/src/akuma/heart/index.d.ts +64 -55
  25. package/build/src/akuma/heart/index.js +172 -252
  26. package/build/src/akuma/heart/rows.d.ts +38 -83
  27. package/build/src/akuma/heart/rows.js +117 -155
  28. package/build/src/akuma/heart/schema.d.ts +1 -1
  29. package/build/src/akuma/heart/schema.js +61 -22
  30. package/build/src/akuma/heart/soul.d.ts +8 -0
  31. package/build/src/akuma/heart/soul.js +136 -0
  32. package/build/src/akuma/heart/storage.d.ts +47 -0
  33. package/build/src/akuma/heart/storage.js +224 -0
  34. package/build/src/akuma/heart/tells.d.ts +12 -0
  35. package/build/src/akuma/heart/tells.js +79 -0
  36. package/build/src/akuma/heart/timeline.d.ts +15 -0
  37. package/build/src/akuma/heart/timeline.js +86 -0
  38. package/build/src/akuma/identity.d.ts +2 -2
  39. package/build/src/akuma/identity.js +9 -9
  40. package/build/src/akuma/index.d.ts +10 -3
  41. package/build/src/akuma/index.js +7 -1
  42. package/build/src/akuma/projection.d.ts +176 -0
  43. package/build/src/akuma/projection.js +256 -0
  44. package/build/src/akuma/provider-recipe.d.ts +24 -0
  45. package/build/src/akuma/provider-recipe.js +100 -0
  46. package/build/src/akuma/provider.d.ts +67 -13
  47. package/build/src/akuma/provider.js +172 -105
  48. package/build/src/akuma/providers/acp/core.d.ts +19 -0
  49. package/build/src/akuma/providers/acp/core.js +159 -0
  50. package/build/src/akuma/providers/acp/events.d.ts +20 -0
  51. package/build/src/akuma/providers/acp/events.js +73 -0
  52. package/build/src/akuma/providers/acp/index.d.ts +12 -0
  53. package/build/src/akuma/providers/acp/index.js +94 -0
  54. package/build/src/akuma/providers/{claude.d.ts → claude/events.d.ts} +9 -41
  55. package/build/src/akuma/providers/claude/events.js +238 -0
  56. package/build/src/akuma/providers/claude/index.d.ts +47 -0
  57. package/build/src/akuma/providers/claude/index.js +279 -0
  58. package/build/src/akuma/providers/claude/input.d.ts +13 -0
  59. package/build/src/akuma/providers/claude/input.js +109 -0
  60. package/build/src/akuma/providers/codex-app-server/events.d.ts +1 -1
  61. package/build/src/akuma/providers/codex-app-server/events.js +15 -12
  62. package/build/src/akuma/providers/codex-app-server/index.d.ts +15 -13
  63. package/build/src/akuma/providers/codex-app-server/index.js +77 -33
  64. package/build/src/akuma/providers/grok-build/index.d.ts +4 -0
  65. package/build/src/akuma/providers/grok-build/index.js +70 -0
  66. package/build/src/akuma/providers/index.d.ts +5 -3
  67. package/build/src/akuma/providers/index.js +35 -56
  68. package/build/src/akuma/providers/opencode-sdk/events.d.ts +54 -0
  69. package/build/src/akuma/providers/opencode-sdk/events.js +235 -0
  70. package/build/src/akuma/providers/opencode-sdk/index.d.ts +33 -0
  71. package/build/src/akuma/providers/opencode-sdk/index.js +308 -0
  72. package/build/src/akuma/providers/opencode-sdk/session.d.ts +26 -0
  73. package/build/src/akuma/providers/opencode-sdk/session.js +63 -0
  74. package/build/src/akuma/providers/pi/events.d.ts +33 -0
  75. package/build/src/akuma/providers/pi/events.js +166 -0
  76. package/build/src/akuma/providers/pi/index.d.ts +11 -0
  77. package/build/src/akuma/providers/pi/index.js +191 -0
  78. package/build/src/akuma/publication.d.ts +3 -3
  79. package/build/src/akuma/publication.js +28 -40
  80. package/build/src/akuma/requests.d.ts +9 -6
  81. package/build/src/akuma/requests.js +95 -65
  82. package/build/src/alias/index.d.ts +4 -3
  83. package/build/src/alias/index.js +12 -13
  84. package/build/src/body/decode.js +7 -1
  85. package/build/src/body/region.d.ts +2 -0
  86. package/build/src/body/region.js +77 -7
  87. package/build/src/body/render.js +2 -1
  88. package/build/src/body/shape.js +7 -1
  89. package/build/src/body/verification.js +19 -4
  90. package/build/src/cli/accepted.d.ts +18 -12
  91. package/build/src/cli/accepted.js +73 -34
  92. package/build/src/cli/actor.js +3 -3
  93. package/build/src/cli/commands/akuma-invoke.d.ts +44 -19
  94. package/build/src/cli/commands/akuma-invoke.js +101 -52
  95. package/build/src/cli/commands/akuma.d.ts +27 -9
  96. package/build/src/cli/commands/akuma.js +151 -80
  97. package/build/src/cli/commands/contract.d.ts +155 -0
  98. package/build/src/cli/commands/contract.js +20 -0
  99. package/build/src/cli/commands/install.js +2 -0
  100. package/build/src/cli/commands/task-invoke.d.ts +19 -4
  101. package/build/src/cli/commands/task-invoke.js +65 -17
  102. package/build/src/cli/commands/task-query.d.ts +5 -0
  103. package/build/src/cli/commands/task-query.js +247 -0
  104. package/build/src/cli/commands/task.d.ts +3 -1
  105. package/build/src/cli/commands/task.js +52 -14
  106. package/build/src/cli/coordinates.d.ts +18 -0
  107. package/build/src/cli/coordinates.js +120 -0
  108. package/build/src/cli/draft.d.ts +8 -0
  109. package/build/src/cli/draft.js +96 -0
  110. package/build/src/cli/invoke.d.ts +9 -3
  111. package/build/src/cli/invoke.js +287 -108
  112. package/build/src/cli/main.js +54 -7
  113. package/build/src/cli/parse.d.ts +21 -117
  114. package/build/src/cli/parse.js +79 -84
  115. package/build/src/cli/render/akuma-tool-command.d.ts +6 -0
  116. package/build/src/cli/render/akuma-tool-command.js +144 -0
  117. package/build/src/cli/render/akuma-tool.d.ts +4 -2
  118. package/build/src/cli/render/akuma-tool.js +35 -5
  119. package/build/src/cli/render/akuma.d.ts +3 -1
  120. package/build/src/cli/render/akuma.js +247 -212
  121. package/build/src/cli/render/audit.d.ts +3 -0
  122. package/build/src/cli/render/audit.js +104 -0
  123. package/build/src/cli/render/catalog.d.ts +2 -0
  124. package/build/src/cli/render/catalog.js +16 -0
  125. package/build/src/cli/render/contract.d.ts +3 -3
  126. package/build/src/cli/render/contract.js +200 -54
  127. package/build/src/cli/render/kanshi.js +272 -129
  128. package/build/src/cli/render/receipt.d.ts +19 -0
  129. package/build/src/cli/render/receipt.js +106 -0
  130. package/build/src/cli/render/refusal.d.ts +16 -2
  131. package/build/src/cli/render/refusal.js +88 -3
  132. package/build/src/cli/render/region.d.ts +2 -0
  133. package/build/src/cli/render/region.js +17 -0
  134. package/build/src/cli/render/task.d.ts +2 -1
  135. package/build/src/cli/render/task.js +223 -60
  136. package/build/src/cli/render/terminal.d.ts +20 -0
  137. package/build/src/cli/render/terminal.js +121 -0
  138. package/build/src/cli/render/text.js +11 -3
  139. package/build/src/cli/result.d.ts +126 -19
  140. package/build/src/cli/usage.d.ts +1 -0
  141. package/build/src/cli/usage.js +3 -0
  142. package/build/src/contract-worktree.d.ts +44 -0
  143. package/build/src/contract-worktree.js +251 -0
  144. package/build/src/coordination/durable-file.d.ts +5 -1
  145. package/build/src/coordination/durable-file.js +57 -10
  146. package/build/src/coordination/sqlite-transaction-lock.d.ts +4 -0
  147. package/build/src/coordination/sqlite-transaction-lock.js +22 -5
  148. package/build/src/core/facts/codec.js +23 -4
  149. package/build/src/core/facts/eligibility.d.ts +1 -10
  150. package/build/src/core/facts/eligibility.js +0 -49
  151. package/build/src/core/facts/fold.js +1 -6
  152. package/build/src/core/facts/gate.d.ts +1 -0
  153. package/build/src/core/facts/gate.js +1 -0
  154. package/build/src/core/facts/observation.d.ts +3 -0
  155. package/build/src/core/facts/observation.js +12 -0
  156. package/build/src/core/facts/types.d.ts +10 -3
  157. package/build/src/core/subject.js +2 -2
  158. package/build/src/core/verbs/amend.d.ts +1 -1
  159. package/build/src/core/verbs/amend.js +3 -18
  160. package/build/src/core/verbs/bind.js +2 -16
  161. package/build/src/core/verbs/deliver.d.ts +1 -1
  162. package/build/src/core/verbs/deliver.js +14 -4
  163. package/build/src/core/verbs/placement.d.ts +1 -1
  164. package/build/src/core/verbs/placement.js +7 -9
  165. package/build/src/dispatch/index.d.ts +5 -3
  166. package/build/src/dispatch/index.js +30 -21
  167. package/build/src/duration.d.ts +10 -0
  168. package/build/src/duration.js +22 -0
  169. package/build/src/git/admission.d.ts +2 -2
  170. package/build/src/git/admission.js +33 -23
  171. package/build/src/git/hooks.d.ts +15 -0
  172. package/build/src/git/hooks.js +70 -18
  173. package/build/src/git/identity.d.ts +5 -1
  174. package/build/src/git/identity.js +23 -4
  175. package/build/src/git/integration.d.ts +48 -0
  176. package/build/src/git/integration.js +250 -0
  177. package/build/src/git/observe.d.ts +29 -15
  178. package/build/src/git/observe.js +185 -76
  179. package/build/src/git/read-observation.d.ts +41 -0
  180. package/build/src/git/read-observation.js +361 -0
  181. package/build/src/git/reconcile.d.ts +17 -5
  182. package/build/src/git/reconcile.js +305 -109
  183. package/build/src/git/repository.d.ts +41 -18
  184. package/build/src/git/repository.js +220 -114
  185. package/build/src/git/scratch.d.ts +17 -0
  186. package/build/src/git/scratch.js +73 -0
  187. package/build/src/git/target-placement.d.ts +92 -0
  188. package/build/src/git/target-placement.js +375 -0
  189. package/build/src/git/tender.d.ts +49 -0
  190. package/build/src/git/tender.js +63 -0
  191. package/build/src/git/terminal-seal.d.ts +24 -0
  192. package/build/src/git/terminal-seal.js +89 -0
  193. package/build/src/git/tree.d.ts +2 -2
  194. package/build/src/git/tree.js +4 -0
  195. package/build/src/git/workspace.d.ts +53 -0
  196. package/build/src/git/workspace.js +139 -0
  197. package/build/src/identity/selector.d.ts +6 -0
  198. package/build/src/identity/selector.js +19 -0
  199. package/build/src/index.d.ts +4 -2
  200. package/build/src/index.js +2 -1
  201. package/build/src/kanshi/index.d.ts +2 -2
  202. package/build/src/kanshi/index.js +1 -1
  203. package/build/src/kanshi/read.d.ts +7 -3
  204. package/build/src/kanshi/read.js +245 -45
  205. package/build/src/kanshi/report.d.ts +81 -6
  206. package/build/src/kanshi/select.d.ts +5 -0
  207. package/build/src/kanshi/select.js +33 -1
  208. package/build/src/library/address.d.ts +57 -0
  209. package/build/src/library/address.js +165 -0
  210. package/build/src/library/akuma-creation.d.ts +16 -7
  211. package/build/src/library/akuma-creation.js +96 -22
  212. package/build/src/library/audit.d.ts +18 -0
  213. package/build/src/library/audit.js +44 -0
  214. package/build/src/library/bind.d.ts +21 -0
  215. package/build/src/library/bind.js +56 -0
  216. package/build/src/library/catalog.d.ts +58 -0
  217. package/build/src/library/catalog.js +69 -0
  218. package/build/src/library/configuration.d.ts +6 -15
  219. package/build/src/library/configuration.js +14 -17
  220. package/build/src/library/contract.d.ts +23 -49
  221. package/build/src/library/contract.js +171 -185
  222. package/build/src/library/delivery.d.ts +24 -0
  223. package/build/src/library/delivery.js +21 -0
  224. package/build/src/library/fleet.d.ts +65 -0
  225. package/build/src/library/fleet.js +153 -0
  226. package/build/src/library/input.d.ts +3 -0
  227. package/build/src/library/input.js +19 -0
  228. package/build/src/library/keiyaku.d.ts +18 -3
  229. package/build/src/library/keiyaku.js +12 -1
  230. package/build/src/library/mutation.d.ts +39 -0
  231. package/build/src/library/mutation.js +37 -0
  232. package/build/src/library/reconcile.d.ts +29 -0
  233. package/build/src/library/reconcile.js +179 -0
  234. package/build/src/library/refusal.d.ts +21 -0
  235. package/build/src/library/refusal.js +29 -0
  236. package/build/src/library/region.d.ts +14 -1
  237. package/build/src/library/region.js +18 -4
  238. package/build/src/library/repo.d.ts +4 -13
  239. package/build/src/library/repo.js +14 -24
  240. package/build/src/protocol/attempt.d.ts +16 -3
  241. package/build/src/protocol/attempt.js +41 -10
  242. package/build/src/protocol/bind.d.ts +9 -2
  243. package/build/src/protocol/bind.js +48 -40
  244. package/build/src/protocol/intent.d.ts +57 -20
  245. package/build/src/protocol/intent.js +55 -79
  246. package/build/src/protocol/operations.d.ts +152 -43
  247. package/build/src/protocol/operations.js +482 -166
  248. package/build/src/protocol/outcome.d.ts +14 -3
  249. package/build/src/protocol/outcome.js +11 -3
  250. package/build/src/protocol/placement.d.ts +41 -0
  251. package/build/src/protocol/placement.js +147 -0
  252. package/build/src/protocol/read/documents.d.ts +2 -2
  253. package/build/src/protocol/read/documents.js +4 -4
  254. package/build/src/protocol/read/status.d.ts +18 -5
  255. package/build/src/protocol/read/status.js +73 -13
  256. package/build/src/protocol/run.d.ts +49 -7
  257. package/build/src/protocol/run.js +53 -25
  258. package/build/src/runtime/proc/line-rpc.d.ts +4 -8
  259. package/build/src/runtime/proc/line-rpc.js +22 -28
  260. package/build/src/runtime/proc/run.d.ts +23 -21
  261. package/build/src/runtime/proc/run.js +123 -89
  262. package/build/src/runtime/proc/stdio.d.ts +18 -0
  263. package/build/src/runtime/proc/stdio.js +58 -0
  264. package/build/src/settings.d.ts +7 -1
  265. package/build/src/settings.js +32 -17
  266. package/build/src/settlement/fence.d.ts +5 -0
  267. package/build/src/settlement/fence.js +14 -0
  268. package/build/src/settlement/holder.d.ts +35 -4
  269. package/build/src/settlement/holder.js +127 -28
  270. package/build/src/settlement/settle.d.ts +9 -1
  271. package/build/src/settlement/settle.js +74 -37
  272. package/build/src/task/board.d.ts +23 -5
  273. package/build/src/task/board.js +17 -10
  274. package/build/src/task/compose.d.ts +2 -2
  275. package/build/src/task/compose.js +18 -10
  276. package/build/src/task/context.d.ts +3 -3
  277. package/build/src/task/context.js +15 -20
  278. package/build/src/task/document.d.ts +2 -1
  279. package/build/src/task/document.js +15 -5
  280. package/build/src/task/index.d.ts +27 -15
  281. package/build/src/task/index.js +57 -35
  282. package/build/src/task/operations.d.ts +38 -13
  283. package/build/src/task/operations.js +80 -46
  284. package/build/src/task/query.d.ts +67 -0
  285. package/build/src/task/query.js +279 -0
  286. package/build/src/task/store.d.ts +5 -7
  287. package/build/src/task/store.js +43 -28
  288. package/build/src/verification/declaration.d.ts +1 -0
  289. package/build/src/verification/execution.d.ts +51 -0
  290. package/build/src/verification/execution.js +108 -0
  291. package/build/src/workspace-place.d.ts +41 -0
  292. package/build/src/workspace-place.js +386 -0
  293. package/build/src/world.d.ts +24 -0
  294. package/build/src/world.js +136 -0
  295. package/package.json +8 -4
  296. package/build/src/akuma/activity.d.ts +0 -66
  297. package/build/src/akuma/activity.js +0 -139
  298. package/build/src/akuma/providers/claude.js +0 -305
  299. package/build/src/context-root.d.ts +0 -4
  300. package/build/src/context-root.js +0 -15
  301. package/build/src/git/delivery.d.ts +0 -20
  302. package/build/src/git/delivery.js +0 -109
  303. package/build/src/git/verification.d.ts +0 -14
  304. package/build/src/git/verification.js +0 -56
  305. package/build/src/protocol/read/audit.d.ts +0 -25
  306. package/build/src/protocol/read/audit.js +0 -39
  307. package/build/src/verification/producer.d.ts +0 -23
  308. package/build/src/verification/producer.js +0 -54
@@ -1,26 +1,17 @@
1
- import type { Settings } from "../settings.js";
1
+ import { SettingsError, type Settings } from "../settings.js";
2
+ import type { WorktreeHooks } from "../git/hooks.js";
3
+ export type { HookCommand, WorktreeHooks } from "../git/hooks.js";
2
4
  export type Gate = string;
3
5
  export type GatesFromInput = Readonly<{
4
6
  settings: Settings;
5
7
  name?: string;
6
8
  }>;
7
- export type HookCommand = Readonly<{
8
- argv: readonly string[];
9
- timeoutMs: number;
10
- }>;
11
- export type WorktreeHooks = Readonly<{
12
- create: readonly HookCommand[];
13
- destroy: readonly HookCommand[];
14
- }>;
15
- export type WorktreeHooksFromInput = Readonly<{
9
+ export type RequireBranchesToBeUpToDateFromInput = Readonly<{
16
10
  settings: Settings;
17
11
  }>;
18
- export declare class SettingsError extends Error {
19
- readonly kind = "settings";
20
- constructor(message: string);
21
- }
12
+ export { SettingsError };
22
13
  export declare function gatesFrom(input: GatesFromInput): readonly Gate[];
23
- export declare function worktreeHooksFrom(input: WorktreeHooksFromInput): WorktreeHooks;
14
+ export declare function requireBranchesToBeUpToDateFrom(input: RequireBranchesToBeUpToDateFromInput): boolean;
24
15
  export declare function normalizedWorktreeHooks(value: unknown): WorktreeHooks;
25
16
  export declare const EMPTY_WORKTREE_HOOKS: WorktreeHooks;
26
17
  export declare function worktreeHooksOption(value: unknown): WorktreeHooks;
@@ -1,11 +1,6 @@
1
1
  import { gateWord } from "../core/facts/types.js";
2
- export class SettingsError extends Error {
3
- kind = "settings";
4
- constructor(message) {
5
- super(message);
6
- this.name = "SettingsError";
7
- }
8
- }
2
+ import { SettingsError } from "../settings.js";
3
+ export { SettingsError };
9
4
  function record(value) {
10
5
  return value !== null && typeof value === "object" && !Array.isArray(value);
11
6
  }
@@ -62,22 +57,24 @@ function commands(value, coordinate, ErrorType) {
62
57
  throw new ErrorType(`${coordinate} must be an array`);
63
58
  return Object.freeze(value.map((item, index) => command(item, `${coordinate}[${index}]`, ErrorType)));
64
59
  }
65
- export function worktreeHooksFrom(input) {
60
+ export function requireBranchesToBeUpToDateFrom(input) {
66
61
  if (!record(input))
67
- throw new TypeError("worktreeHooksFrom input must be an object");
68
- const view = input.settings.namespace("worktree");
62
+ throw new TypeError("requireBranchesToBeUpToDateFrom input must be an object");
63
+ const view = input.settings.namespace("git");
69
64
  if (view.kind === "failed")
70
65
  namespaceFailure(view);
71
66
  for (const entry of view.entries) {
72
- if (entry.name !== "create" && entry.name !== "destroy") {
73
- throw new SettingsError(`worktree has unknown entry: ${entry.name}`);
67
+ if (entry.name !== "requireBranchesToBeUpToDate") {
68
+ throw new SettingsError(`git has unknown entry: ${entry.name}`);
74
69
  }
75
70
  }
76
- const value = (phase) => {
77
- const selected = view.entries.find((entry) => entry.name === phase);
78
- return selected === undefined ? Object.freeze([]) : commands(selected.value, `worktree.${phase}`, SettingsError);
79
- };
80
- return Object.freeze({ create: value("create"), destroy: value("destroy") });
71
+ const selected = view.entries.find((entry) => entry.name === "requireBranchesToBeUpToDate");
72
+ if (selected === undefined)
73
+ return false;
74
+ if (typeof selected.value !== "boolean") {
75
+ throw new SettingsError("git.requireBranchesToBeUpToDate must be a boolean");
76
+ }
77
+ return selected.value;
81
78
  }
82
79
  export function normalizedWorktreeHooks(value) {
83
80
  if (!record(value))
@@ -1,54 +1,42 @@
1
+ import { type ContractFileEffect, type ContractFileLag } from "../contract-worktree.js";
1
2
  import { type RegionObservation, type RegionOverlap } from "./region.js";
2
3
  import { type Gate, type WorktreeHooks } from "./configuration.js";
3
- import { type ChangeId, type ContractHead, type ContractId, type ContractState, type JournalEntry, type SnapshotId } from "../core/facts/types.js";
4
+ import { type ChangeId, type ContractId, type ContractState, type JournalEntry, type SnapshotId } from "../core/facts/types.js";
4
5
  export { AuthorityCorruptionError } from "../core/facts/errors.js";
5
- import { type AuditReport, type ContractBoard, type ContractDisposition, type ContractGateCurrent, type ContractGateReport, type ContractObservation, type ContractPhase, type ContractRow, type DeliverValue, type FactKind, type IntentRefusal, type IntentRetry, type PlacementStop, type ReconcileReport as ProtocolReconcileReport, type RepositoryScope, type ReviewValue, type TimelineEntry, type VerificationStop } from "../protocol/operations.js";
6
+ import { type AuditReport, type ContractBoard, type ContractDisposition, type ContractGateCurrent, type ContractGateReport, type ContractObservation, type ContractPhase, type ContractRow, type FactKind, type PlacementStop, type ReconcileReport as ProtocolReconcileReport, type RepositoryScope, type ReviewValue, type VerificationReuse, type VerificationStop, type DeliveryPreparationRefusal } from "../protocol/operations.js";
6
7
  import { type SettlementReport } from "../settlement/settle.js";
7
- import { type TaskHolder } from "../settlement/holder.js";
8
8
  import { type TaskId } from "../task/identity.js";
9
9
  import { Repo, type ReconcileInput } from "./repo.js";
10
- export { gatesFrom, SettingsError, worktreeHooksFrom } from "./configuration.js";
11
- export type { Gate, GatesFromInput, HookCommand, WorktreeHooks, WorktreeHooksFromInput } from "./configuration.js";
12
- export type { AuditReport, ChangeId, ContractId, ContractState, ContractBoard, ContractDisposition, ContractGateCurrent, ContractGateReport, ContractObservation, ContractPhase, ContractRow, FactKind, SnapshotId, TimelineEntry, };
10
+ import { type AuditInput } from "./audit.js";
11
+ import { Delivery } from "./delivery.js";
12
+ import { type MutationResult } from "./mutation.js";
13
+ export { KeiyakuRefused, KeiyakuRetry, type ContractAppointmentRefusal, type KeiyakuRefusal, type KeiyakuRetryReason, } from "./refusal.js";
14
+ export { gatesFrom, requireBranchesToBeUpToDateFrom, SettingsError } from "./configuration.js";
15
+ export type { Gate, GatesFromInput, HookCommand, RequireBranchesToBeUpToDateFromInput, WorktreeHooks } from "./configuration.js";
16
+ export type { AuditReport, DeliveryPreparationRefusal, ChangeId, ContractId, ContractState, ContractBoard, ContractDisposition, ContractGateCurrent, ContractGateReport, ContractObservation, ContractPhase, ContractRow, FactKind, SnapshotId, };
13
17
  export type { TaskId };
14
18
  export type { RegionOverlap };
15
19
  export type Fact = JournalEntry;
16
20
  export type ActorId = string;
17
21
  export type AttestationVerdict = "satisfied" | "unsatisfied";
18
22
  export type Review = ReviewValue;
19
- export type KeiyakuRefusal = IntentRefusal;
20
- export type KeiyakuRetryReason = IntentRetry;
21
- export type { PlacementStop, VerificationStop };
22
- export type TopologyEffect = ProtocolReconcileReport["effects"][number];
23
- export type Lag = ProtocolReconcileReport["lag"][number];
24
- export type MutationResult<Value> = Readonly<{
25
- facts: readonly Fact[];
26
- head: ContractHead;
27
- value: Value;
28
- effects: readonly TopologyEffect[];
29
- lags: readonly Lag[];
30
- settlement: SettlementReport;
31
- }>;
23
+ export type { PlacementStop, VerificationReuse, VerificationStop };
24
+ export type TopologyEffect = ProtocolReconcileReport["effects"][number] | ContractFileEffect;
25
+ export type Lag = ProtocolReconcileReport["lag"][number] | ContractFileLag;
26
+ export type { MutationResult };
27
+ export { Delivery };
32
28
  export type BindResult = Readonly<Omit<MutationResult<Keiyaku>, "value"> & {
33
29
  keiyaku: Keiyaku;
34
30
  } & RegionObservation>;
35
31
  export type AmendResult = Readonly<MutationResult<void> & RegionObservation & {
36
32
  documentDiff: string;
37
33
  }>;
38
- export type ReconcileReport = Readonly<ProtocolReconcileReport & {
34
+ export type ReconcileReport = Readonly<{
35
+ effects: readonly TopologyEffect[];
36
+ lag: readonly Lag[];
39
37
  settlement: SettlementReport;
40
38
  }>;
41
39
  export type { SettlementAction, SettlementLag, SettlementReport } from "../settlement/settle.js";
42
- export declare class KeiyakuRefused extends Error {
43
- readonly refusal: KeiyakuRefusal;
44
- constructor(refusal: KeiyakuRefusal);
45
- get code(): KeiyakuRefusal["kind"];
46
- }
47
- export declare class KeiyakuRetry extends Error {
48
- readonly reason: KeiyakuRetryReason;
49
- constructor(reason: KeiyakuRetryReason);
50
- get code(): KeiyakuRetryReason["kind"];
51
- }
52
40
  export type BindInput = Readonly<{
53
41
  repo: Repo;
54
42
  markdown: string;
@@ -98,29 +86,17 @@ export type AbandonInput = ActorOptions & Readonly<{
98
86
  }>;
99
87
  export type DeliverInput = ActorOptions & Readonly<{
100
88
  message?: string;
89
+ requireBranchesToBeUpToDate?: boolean;
90
+ includeDirty?: boolean;
91
+ signal?: AbortSignal;
101
92
  }>;
102
- export type AuditInput = ActorOptions;
103
- declare class DeliveryHandle {
104
- readonly snapshotId: SnapshotId;
105
- readonly changeId: ChangeId;
106
- readonly expectedPredecessor: SnapshotId;
107
- private readonly readDiff;
108
- readonly verification?: DeliverValue["verification"];
109
- readonly placement?: DeliverValue["placement"];
110
- readonly leak?: DeliverValue["leak"];
111
- constructor(snapshotId: SnapshotId, changeId: ChangeId, expectedPredecessor: SnapshotId, readDiff: () => Promise<string | null>, outcomes?: Partial<Pick<DeliverValue, "verification" | "placement" | "leak">>);
112
- diff(): Promise<string | null>;
113
- }
114
- export type Delivery = DeliveryHandle;
115
- export declare const Delivery: Readonly<{
116
- prototype: DeliveryHandle;
117
- [Symbol.hasInstance](value: unknown): boolean;
118
- }>;
93
+ export type { AuditInput };
119
94
  export declare class KeiyakuHandle {
120
95
  private readonly id;
121
96
  private readonly scope;
122
97
  constructor(id: ContractId, scope: RepositoryScope);
123
98
  state(): Promise<ContractState>;
99
+ guidance(): Promise<string>;
124
100
  delivery(): Promise<Delivery | null>;
125
101
  amend(input: AmendInput): Promise<AmendResult>;
126
102
  deliver(input?: DeliverInput): Promise<MutationResult<Delivery>>;
@@ -141,5 +117,3 @@ export declare function keiyakuOf(input: KeiyakuOfInput): Keiyaku;
141
117
  export declare function listKeiyaku(input: ContractListInput): Promise<ContractBoard>;
142
118
  export declare function observeKeiyaku(input: ContractObservationInput): Promise<ContractObservation>;
143
119
  export declare function bindKeiyaku(input: BindInput): Promise<BindResult>;
144
- /** Internal package composition read used by Kanshi; not a package-root export. */
145
- export declare function taskHoldersForRepo(repo: Repo): readonly TaskHolder[];
@@ -2,46 +2,26 @@ import { documentDiff } from "../markdown/diff.js";
2
2
  import { applyAmendDocument } from "../body/amend.js";
3
3
  import { decodeArcDocument } from "../body/arc.js";
4
4
  import { decodeContractDocument } from "../body/decode.js";
5
- import { actorOption, contractTerms, documentDerivation, normalizedGates, normalizedList, optionalNonblank, requireInput, requireMarkdown, } from "./input.js";
5
+ import { renderContractGuidance, } from "../contract-worktree.js";
6
+ import { actorOption, contractTerms, documentDerivation, normalizedGates, normalizedList, optionalBoolean, optionalNonblank, optionalSignal, requireInput, requireMarkdown, } from "./input.js";
6
7
  import { observeRegion } from "./region.js";
7
- import { worktreeHooksOption, } from "./configuration.js";
8
+ import { worktreeHooksOption } from "./configuration.js";
8
9
  import { contractId, } from "../core/facts/types.js";
9
10
  export { AuthorityCorruptionError } from "../core/facts/errors.js";
10
- import { abandonOperation, amendOperation, arcOperation, auditOperation, bindOperation, contractObservationOperation, contractsOperation, deliveryDiffOperation, deliverOperation, deliveryOperation, readStateOperation, reconcileOperation, reviewOperation, stateOperation, } from "../protocol/operations.js";
11
- import { settle } from "../settlement/settle.js";
12
- import { claimTaskHolder, readTaskHolders, releaseTaskHolder } from "../settlement/holder.js";
11
+ import { abandonOperation, amendOperation, arcOperation, contractObservationOperation, contractsOperation, deliveryDiffOperation, deliverOperation, deliveryOperation, reviewOperation, stateOperation, } from "../protocol/operations.js";
12
+ import { withGitDecodeChannel } from "../git/read-observation.js";
13
+ import { claimTaskHolderWithFence, releaseTaskHolder, releaseTaskHolderWithFence, taskHolderObservationSelection, } from "../settlement/holder.js";
13
14
  import { parseTaskId } from "../task/identity.js";
14
15
  import { reconcileInput, scopeForRepo } from "./repo.js";
15
- export { gatesFrom, SettingsError, worktreeHooksFrom } from "./configuration.js";
16
- export class KeiyakuRefused extends Error {
17
- refusal;
18
- constructor(refusal) {
19
- super(`Keiyaku refused: ${refusal.kind}`);
20
- this.refusal = refusal;
21
- this.name = "KeiyakuRefused";
22
- }
23
- get code() {
24
- return this.refusal.kind;
25
- }
26
- }
27
- export class KeiyakuRetry extends Error {
28
- reason;
29
- constructor(reason) {
30
- super(reason.kind === "publication-failed" ? reason.diagnostic : `Keiyaku retry required: ${reason.kind}`);
31
- this.reason = reason;
32
- this.name = "KeiyakuRetry";
33
- }
34
- get code() {
35
- return this.reason.kind;
36
- }
37
- }
38
- function requireAccepted(result) {
39
- if (result.kind === "refused")
40
- throw new KeiyakuRefused(result.refusal);
41
- if (result.kind === "retry")
42
- throw new KeiyakuRetry(result.reason);
43
- return result;
44
- }
16
+ import { auditContract } from "./audit.js";
17
+ import { Delivery, deliveryHandle } from "./delivery.js";
18
+ import { completeHolderMutation, completeMutation, } from "./mutation.js";
19
+ import { completeReconcile } from "./reconcile.js";
20
+ import { admitBindWithAppointment } from "./bind.js";
21
+ import { KeiyakuRefused, requireAccepted } from "./refusal.js";
22
+ export { KeiyakuRefused, KeiyakuRetry, } from "./refusal.js";
23
+ export { gatesFrom, requireBranchesToBeUpToDateFrom, SettingsError } from "./configuration.js";
24
+ export { Delivery };
45
25
  function taskOption(value) {
46
26
  if (value === undefined)
47
27
  return undefined;
@@ -55,38 +35,9 @@ function taskOption(value) {
55
35
  }
56
36
  return value;
57
37
  }
58
- async function mutationResult(scope, id, accepted, value, hooks) {
59
- const reconciled = await reconcileOperation({ scope, contractId: id, hooks, retryHooks: false });
60
- const settlement = await settle({ repository: scope, state: reconciled.state, effects: reconciled.report.effects });
61
- return {
62
- facts: accepted.facts,
63
- head: accepted.head,
64
- value: value(accepted.value),
65
- effects: reconciled.report.effects,
66
- lags: reconciled.report.lag,
67
- settlement,
68
- };
38
+ function completion(scope, channel, id, value, hooks) {
39
+ return { scope, channel, contractId: id, value, hooks };
69
40
  }
70
- class DeliveryHandle {
71
- snapshotId;
72
- changeId;
73
- expectedPredecessor;
74
- readDiff;
75
- constructor(snapshotId, changeId, expectedPredecessor, readDiff, outcomes = {}) {
76
- this.snapshotId = snapshotId;
77
- this.changeId = changeId;
78
- this.expectedPredecessor = expectedPredecessor;
79
- this.readDiff = readDiff;
80
- Object.assign(this, outcomes);
81
- }
82
- diff() {
83
- return this.readDiff();
84
- }
85
- }
86
- function handleType(prototype, hasInstance) {
87
- return Object.freeze({ prototype, [Symbol.hasInstance]: hasInstance });
88
- }
89
- export const Delivery = handleType(DeliveryHandle.prototype, (value) => value instanceof DeliveryHandle);
90
41
  export class KeiyakuHandle {
91
42
  id;
92
43
  scope;
@@ -96,10 +47,26 @@ export class KeiyakuHandle {
96
47
  KEIYAKU_SEATS.set(this, { id, scope });
97
48
  }
98
49
  async state() {
99
- return stateOperation({ scope: this.scope, contractId: this.id });
50
+ return withGitDecodeChannel(this.scope, (channel) => stateOperation({
51
+ scope: this.scope,
52
+ channel,
53
+ contractId: this.id,
54
+ }));
55
+ }
56
+ async guidance() {
57
+ return withGitDecodeChannel(this.scope, async (channel) => {
58
+ const observed = await contractObservationOperation({ scope: this.scope, channel, contractId: this.id });
59
+ if (observed.kind === "missing")
60
+ throw new KeiyakuRefused({ kind: "contract-missing", contractId: this.id });
61
+ return renderContractGuidance(await stateOperation({ scope: this.scope, channel, contractId: this.id }));
62
+ });
100
63
  }
101
64
  async delivery() {
102
- const delivery = deliveryOperation({ scope: this.scope, contractId: this.id });
65
+ const delivery = await withGitDecodeChannel(this.scope, (channel) => deliveryOperation({
66
+ scope: this.scope,
67
+ channel,
68
+ contractId: this.id,
69
+ }));
103
70
  return delivery === null
104
71
  ? null
105
72
  : this.deliveryHandle(delivery);
@@ -113,53 +80,57 @@ export class KeiyakuHandle {
113
80
  const prerequisites = values.after === undefined
114
81
  ? undefined
115
82
  : normalizedList(values.after, "after", contractId);
116
- const current = readStateOperation({ scope: this.scope, contractId: this.id });
117
- let document;
118
- let terms;
119
- let verification;
120
- if (current !== null) {
121
- const before = current.terms.document.bytes;
122
- const currentDocument = decodeContractDocument(before);
123
- document = decodeContractDocument(applyAmendDocument(markdown, currentDocument));
124
- terms = contractTerms(document, gates ?? current.terms.gates, prerequisites ?? current.terms.after);
125
- verification = documentDerivation(document, terms.gates, this.id).verification;
126
- }
127
- const accepted = requireAccepted(amendOperation({
128
- scope: this.scope,
129
- contractId: this.id,
130
- ...actor,
131
- ...(current === null || terms === undefined || verification === undefined
132
- ? {}
133
- : { amendment: { source: current.terms, terms, verification } }),
134
- }));
135
- if (document === undefined || current === null) {
136
- throw new Error("accepted amendment is missing its document derivation");
137
- }
138
- const before = current.terms.document.bytes;
139
- const after = document.document.bytes;
140
- return {
141
- ...await mutationResult(this.scope, this.id, accepted, () => undefined, hooks),
142
- documentDiff: documentDiff("before", "after", before, after),
143
- ...observeRegion(this.scope, this.id, document.region),
144
- };
83
+ return withGitDecodeChannel(this.scope, async (channel) => {
84
+ const accepted = requireAccepted(await amendOperation({
85
+ scope: this.scope,
86
+ channel,
87
+ contractId: this.id,
88
+ ...actor,
89
+ deriveAmendment: (source) => {
90
+ const document = decodeContractDocument(applyAmendDocument(markdown, decodeContractDocument(source.document.bytes)));
91
+ const terms = contractTerms(document, gates ?? source.gates, prerequisites ?? source.after);
92
+ return {
93
+ terms,
94
+ verification: documentDerivation(document, terms.gates, this.id).verification,
95
+ };
96
+ },
97
+ }));
98
+ const document = decodeContractDocument(accepted.value.terms.document.bytes);
99
+ return {
100
+ ...await completeMutation({
101
+ ...completion(this.scope, channel, this.id, () => undefined, hooks),
102
+ accepted,
103
+ }),
104
+ documentDiff: documentDiff("before", "after", accepted.value.source.document.bytes, accepted.value.terms.document.bytes),
105
+ ...await observeRegion(this.scope, channel, this.id, document.region),
106
+ };
107
+ });
145
108
  }
146
109
  async deliver(input) {
147
110
  const values = input === undefined ? undefined : requireInput(input, "deliver input");
148
111
  const hooks = worktreeHooksOption(values?.hooks);
149
112
  const message = optionalNonblank(values?.message, "deliver message");
113
+ const requireBranchesToBeUpToDate = optionalBoolean(values?.requireBranchesToBeUpToDate, "requireBranchesToBeUpToDate") ?? false;
114
+ const includeDirty = optionalBoolean(values?.includeDirty, "includeDirty") ?? false;
150
115
  const actor = actorOption(values?.actor);
151
- const state = readStateOperation({ scope: this.scope, contractId: this.id });
152
- const derivation = state === null
153
- ? undefined
154
- : documentDerivation(decodeContractDocument(state.terms.document.bytes), state.terms.gates, state.id);
155
- const accepted = requireAccepted(await deliverOperation({
156
- scope: this.scope,
157
- contractId: this.id,
158
- ...(derivation === undefined ? {} : { derivation }),
159
- ...actor,
160
- ...(message === undefined ? {} : { message }),
161
- }));
162
- return mutationResult(this.scope, this.id, accepted, (delivery) => this.deliveryHandle(delivery), hooks);
116
+ const signal = optionalSignal(values?.signal);
117
+ return withGitDecodeChannel(this.scope, async (channel) => {
118
+ const accepted = requireAccepted(await deliverOperation({
119
+ scope: this.scope,
120
+ channel,
121
+ contractId: this.id,
122
+ deriveDocument: (state) => documentDerivation(decodeContractDocument(state.terms.document.bytes), state.terms.gates, state.id),
123
+ ...actor,
124
+ ...(message === undefined ? {} : { message }),
125
+ requireBranchesToBeUpToDate,
126
+ includeDirty,
127
+ ...(signal === undefined ? {} : { signal }),
128
+ }));
129
+ return completeMutation({
130
+ ...completion(this.scope, channel, this.id, (delivery) => this.deliveryHandle(delivery), hooks),
131
+ accepted,
132
+ });
133
+ });
163
134
  }
164
135
  async review(input) {
165
136
  const values = requireInput(input, "review input");
@@ -169,73 +140,82 @@ export class KeiyakuHandle {
169
140
  throw new TypeError("verdict must be satisfied or unsatisfied");
170
141
  }
171
142
  const summary = optionalNonblank(values.summary, "review summary");
172
- const accepted = requireAccepted(reviewOperation({
173
- scope: this.scope,
174
- contractId: this.id,
175
- verdict,
176
- ...(summary === undefined ? {} : { summary }),
177
- ...actorOption(values.actor),
178
- }));
179
- return mutationResult(this.scope, this.id, accepted, (value) => value, hooks);
143
+ return withGitDecodeChannel(this.scope, async (channel) => {
144
+ const accepted = requireAccepted(await reviewOperation({
145
+ scope: this.scope,
146
+ channel,
147
+ contractId: this.id,
148
+ verdict,
149
+ ...(summary === undefined ? {} : { summary }),
150
+ ...actorOption(values.actor),
151
+ }));
152
+ return completeMutation({
153
+ ...completion(this.scope, channel, this.id, (value) => value, hooks),
154
+ accepted,
155
+ });
156
+ });
180
157
  }
181
158
  async abandon(input) {
182
159
  const values = input === undefined ? undefined : requireInput(input, "abandon input");
183
160
  const hooks = worktreeHooksOption(values?.hooks);
184
161
  const note = optionalNonblank(values?.note, "abandon note");
185
- const accepted = requireAccepted(abandonOperation({
186
- scope: this.scope,
187
- contractId: this.id,
188
- ...actorOption(values?.actor),
189
- ...(note === undefined ? {} : { note }),
190
- decorateOffer: ({ repository, observation, contractId: owner }) => {
191
- const companion = releaseTaskHolder(repository, observation.admission.snapshot, owner);
192
- return companion === null ? [] : [companion];
193
- },
194
- }));
195
- return mutationResult(this.scope, this.id, accepted, () => undefined, hooks);
162
+ return withGitDecodeChannel(this.scope, async (channel) => {
163
+ const admission = await releaseTaskHolderWithFence(this.scope, channel, this.id, () => abandonOperation({
164
+ scope: this.scope,
165
+ channel,
166
+ contractId: this.id,
167
+ ...actorOption(values?.actor),
168
+ ...(note === undefined ? {} : { note }),
169
+ observationSelection: taskHolderObservationSelection(),
170
+ decorateOffer: async ({ observation, contractId: owner }) => {
171
+ const companion = await releaseTaskHolder(channel, observation, owner);
172
+ return companion === null ? [] : [companion];
173
+ },
174
+ }));
175
+ return completeHolderMutation({
176
+ completion: completion(this.scope, channel, this.id, () => undefined, hooks),
177
+ admission,
178
+ requireAccepted,
179
+ });
180
+ });
196
181
  }
197
182
  async arc(input) {
198
183
  const values = requireInput(input, "arc input");
199
184
  const hooks = worktreeHooksOption(values.hooks);
200
185
  const chapter = decodeArcDocument(requireMarkdown(values.markdown));
201
- const accepted = requireAccepted(arcOperation({
202
- scope: this.scope,
203
- contractId: this.id,
204
- ...actorOption(values.actor),
205
- chapter,
206
- }));
207
- return mutationResult(this.scope, this.id, accepted, () => undefined, hooks);
186
+ return withGitDecodeChannel(this.scope, async (channel) => {
187
+ const accepted = requireAccepted(await arcOperation({
188
+ scope: this.scope,
189
+ channel,
190
+ contractId: this.id,
191
+ ...actorOption(values.actor),
192
+ chapter,
193
+ }));
194
+ return completeMutation({
195
+ ...completion(this.scope, channel, this.id, () => undefined, hooks),
196
+ accepted,
197
+ });
198
+ });
208
199
  }
209
200
  async audit(input) {
210
- const values = input === undefined ? undefined : requireInput(input, "audit input");
211
- const hooks = worktreeHooksOption(values?.hooks);
212
- const actor = actorOption(values?.actor);
213
- const state = readStateOperation({ scope: this.scope, contractId: this.id });
214
- const derivation = state === null
215
- ? undefined
216
- : documentDerivation(decodeContractDocument(state.terms.document.bytes), state.terms.gates, state.id);
217
- const accepted = requireAccepted(await auditOperation({
201
+ return auditContract({
218
202
  scope: this.scope,
219
203
  contractId: this.id,
220
- ...(derivation === undefined ? {} : { derivation }),
221
- ...actor,
222
- }));
223
- return mutationResult(this.scope, this.id, accepted, (report) => report, hooks);
204
+ ...(input === undefined ? {} : { input }),
205
+ });
224
206
  }
225
207
  async reconcile(input) {
226
208
  const options = reconcileInput(input);
227
- const reconciled = await reconcileOperation({ scope: this.scope, contractId: this.id, ...options });
228
- return {
229
- ...reconciled.report,
230
- settlement: await settle({ repository: this.scope, state: reconciled.state, effects: reconciled.report.effects }),
231
- };
209
+ return withGitDecodeChannel(this.scope, (channel) => completeReconcile({
210
+ scope: this.scope, channel, contractId: this.id, ...options,
211
+ }));
232
212
  }
233
213
  deliveryHandle(delivery) {
234
- return new DeliveryHandle(delivery.snapshotId, delivery.changeId, delivery.expectedPredecessor, () => deliveryDiffOperation({
214
+ return deliveryHandle(delivery, () => deliveryDiffOperation({
235
215
  scope: this.scope,
236
- expectedPredecessor: delivery.expectedPredecessor,
237
- snapshotId: delivery.snapshotId,
238
- }), delivery);
216
+ integrationPredecessor: delivery.integration.predecessor,
217
+ integrationSnapshot: delivery.integration.snapshot,
218
+ }));
239
219
  }
240
220
  }
241
221
  const KEIYAKU_SEATS = new WeakMap();
@@ -260,7 +240,8 @@ export async function listKeiyaku(input) {
260
240
  for (const key of Object.keys(values))
261
241
  if (key !== "repo")
262
242
  throw new TypeError(`Keiyaku.list input has unknown field: ${key}`);
263
- return contractsOperation({ scope: scopeForRepo(values.repo) });
243
+ const scope = scopeForRepo(values.repo);
244
+ return withGitDecodeChannel(scope, (channel) => contractsOperation({ scope, channel }));
264
245
  }
265
246
  export async function observeKeiyaku(input) {
266
247
  const values = requireInput(input, "Keiyaku.observe input");
@@ -277,7 +258,7 @@ export async function observeKeiyaku(input) {
277
258
  catch (error) {
278
259
  throw new TypeError(error instanceof Error ? error.message : "contract ID is invalid");
279
260
  }
280
- return contractObservationOperation({ scope, contractId: id });
261
+ return withGitDecodeChannel(scope, (channel) => contractObservationOperation({ scope, channel, contractId: id }));
281
262
  }
282
263
  export async function bindKeiyaku(input) {
283
264
  const values = requireInput(input, "Keiyaku.bind input");
@@ -294,32 +275,37 @@ export async function bindKeiyaku(input) {
294
275
  throw new TypeError("target must be a string");
295
276
  const actor = actorOption(values.actor);
296
277
  const terms = contractTerms(document, normalizedGates(values.gates), normalizedList(values.after, "after", contractId));
297
- const admitted = bindOperation({
298
- scope,
299
- title: document.title,
300
- terms,
301
- verification: documentDerivation(document, terms.gates).verification,
302
- workspace,
303
- ...(target === undefined ? {} : { target }),
304
- ...(task === undefined ? {} : {
305
- decorateOffer: ({ contractId: owner }) => [claimTaskHolder(task, owner)],
306
- }),
307
- ...actor,
278
+ return withGitDecodeChannel(scope, async (channel) => {
279
+ const admitCandidate = () => admitBindWithAppointment({
280
+ scope,
281
+ channel,
282
+ title: document.title,
283
+ terms,
284
+ verification: documentDerivation(document, terms.gates).verification,
285
+ workspace,
286
+ ...(target === undefined ? {} : { target }),
287
+ ...(task === undefined ? {} : { task }),
288
+ ...actor,
289
+ });
290
+ const admission = task === undefined ? null : await claimTaskHolderWithFence(scope, task, admitCandidate);
291
+ const accepted = requireAccepted(admission === null ? await admitCandidate() : admission.result);
292
+ const id = accepted.value.contractId;
293
+ const toHandle = ({ contractId: contract }) => new KeiyakuHandle(contract, scope);
294
+ const result = admission === null
295
+ ? await completeMutation({ ...completion(scope, channel, id, toHandle, hooks), accepted })
296
+ : await completeHolderMutation({
297
+ completion: completion(scope, channel, id, toHandle, hooks),
298
+ admission,
299
+ requireAccepted,
300
+ });
301
+ return {
302
+ facts: result.facts,
303
+ head: result.head,
304
+ keiyaku: result.value,
305
+ effects: result.effects,
306
+ lags: result.lags,
307
+ settlement: result.settlement,
308
+ ...await observeRegion(scope, channel, id, document.region),
309
+ };
308
310
  });
309
- const accepted = requireAccepted(admitted);
310
- const id = accepted.value.contractId;
311
- const result = await mutationResult(scope, id, accepted, ({ contractId: contract }) => new KeiyakuHandle(contract, scope), hooks);
312
- return {
313
- facts: result.facts,
314
- head: result.head,
315
- keiyaku: result.value,
316
- effects: result.effects,
317
- lags: result.lags,
318
- settlement: result.settlement,
319
- ...observeRegion(scope, id, document.region),
320
- };
321
- }
322
- /** Internal package composition read used by Kanshi; not a package-root export. */
323
- export function taskHoldersForRepo(repo) {
324
- return readTaskHolders(scopeForRepo(repo));
325
311
  }