@astrosheep/keiyaku 4.0.4 → 4.0.6

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 (233) hide show
  1. package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +1 -1
  2. package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +1 -1
  3. package/build/integrations/marketplace/plugins/keiyaku/package.json +1 -1
  4. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +4 -4
  5. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +15 -7
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +5 -3
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +24 -4
  8. package/build/src/akuma/akuma.d.ts +2 -1
  9. package/build/src/akuma/akuma.js +27 -9
  10. package/build/src/akuma/allowed.d.ts +1 -1
  11. package/build/src/akuma/allowed.js +3 -10
  12. package/build/src/akuma/archetype.d.ts +3 -1
  13. package/build/src/akuma/archetype.js +11 -6
  14. package/build/src/akuma/body-turn.d.ts +64 -0
  15. package/build/src/akuma/body-turn.js +449 -0
  16. package/build/src/akuma/body.d.ts +4 -5
  17. package/build/src/akuma/body.js +9 -414
  18. package/build/src/akuma/heart/facts.d.ts +37 -9
  19. package/build/src/akuma/heart/facts.js +3 -1
  20. package/build/src/akuma/heart/index.d.ts +4 -13
  21. package/build/src/akuma/heart/index.js +14 -135
  22. package/build/src/akuma/heart/request-authority.d.ts +12 -0
  23. package/build/src/akuma/heart/request-authority.js +119 -0
  24. package/build/src/akuma/heart/request-rows.d.ts +16 -0
  25. package/build/src/akuma/heart/request-rows.js +88 -0
  26. package/build/src/akuma/heart/rows.d.ts +1 -28
  27. package/build/src/akuma/heart/rows.js +4 -138
  28. package/build/src/akuma/heart/schema.d.ts +1 -1
  29. package/build/src/akuma/heart/schema.js +11 -3
  30. package/build/src/akuma/heart/soul.js +0 -36
  31. package/build/src/akuma/heart/timeline.d.ts +1 -0
  32. package/build/src/akuma/heart/timeline.js +19 -0
  33. package/build/src/akuma/index.d.ts +1 -1
  34. package/build/src/akuma/nuke.d.ts +2 -0
  35. package/build/src/akuma/nuke.js +152 -0
  36. package/build/src/akuma/provider-recipe.js +1 -11
  37. package/build/src/akuma/provider.d.ts +4 -7
  38. package/build/src/akuma/providers/acp/config.d.ts +8 -0
  39. package/build/src/akuma/providers/acp/config.js +37 -0
  40. package/build/src/akuma/providers/acp/core.js +12 -2
  41. package/build/src/akuma/providers/acp/index.d.ts +1 -8
  42. package/build/src/akuma/providers/acp/index.js +2 -38
  43. package/build/src/akuma/providers/claude/index.d.ts +0 -4
  44. package/build/src/akuma/providers/claude/index.js +12 -3
  45. package/build/src/akuma/providers/codex-app-server/index.d.ts +2 -27
  46. package/build/src/akuma/providers/codex-app-server/index.js +5 -2
  47. package/build/src/akuma/providers/grok-build/index.js +1 -2
  48. package/build/src/akuma/providers/index.d.ts +3 -2
  49. package/build/src/akuma/providers/index.js +36 -36
  50. package/build/src/akuma/providers/opencode-sdk/index.d.ts +2 -28
  51. package/build/src/akuma/providers/opencode-sdk/index.js +14 -4
  52. package/build/src/akuma/providers/opencode-sdk/session.d.ts +2 -2
  53. package/build/src/akuma/providers/opencode-sdk/session.js +2 -2
  54. package/build/src/akuma/providers/pi/index.d.ts +1 -1
  55. package/build/src/akuma/providers/pi/index.js +29 -6
  56. package/build/src/akuma/request-serve.d.ts +88 -0
  57. package/build/src/akuma/request-serve.js +484 -0
  58. package/build/src/akuma/request-wire.d.ts +125 -0
  59. package/build/src/akuma/request-wire.js +383 -0
  60. package/build/src/akuma/requests.d.ts +28 -94
  61. package/build/src/akuma/requests.js +52 -562
  62. package/build/src/akuma-body.d.ts +7 -0
  63. package/build/src/akuma-body.js +69 -2
  64. package/build/src/alias/index.d.ts +1 -0
  65. package/build/src/alias/index.js +34 -1
  66. package/build/src/body/arc.js +4 -29
  67. package/build/src/body/decode.js +5 -39
  68. package/build/src/body/envelope.d.ts +7 -0
  69. package/build/src/body/envelope.js +37 -0
  70. package/build/src/cli/accepted.js +21 -9
  71. package/build/src/cli/commands/akuma-invoke.js +1 -0
  72. package/build/src/cli/commands/akuma.d.ts +1 -0
  73. package/build/src/cli/commands/akuma.js +13 -10
  74. package/build/src/cli/commands/contract.d.ts +28 -17
  75. package/build/src/cli/commands/contract.js +23 -17
  76. package/build/src/cli/commands/install.d.ts +2 -2
  77. package/build/src/cli/commands/install.js +6 -6
  78. package/build/src/cli/commands/nuke.d.ts +10 -0
  79. package/build/src/cli/commands/nuke.js +20 -0
  80. package/build/src/cli/commands/task-invoke.d.ts +15 -0
  81. package/build/src/cli/commands/task-invoke.js +144 -24
  82. package/build/src/cli/commands/task-query.d.ts +2 -2
  83. package/build/src/cli/commands/task-query.js +1 -2
  84. package/build/src/cli/commands/task.js +22 -22
  85. package/build/src/cli/coordinates.d.ts +6 -2
  86. package/build/src/cli/coordinates.js +12 -56
  87. package/build/src/cli/invoke.d.ts +5 -4
  88. package/build/src/cli/invoke.js +112 -58
  89. package/build/src/cli/main.d.ts +0 -2
  90. package/build/src/cli/main.js +4 -140
  91. package/build/src/cli/parse.d.ts +17 -4
  92. package/build/src/cli/parse.js +93 -15
  93. package/build/src/cli/render/akuma.js +111 -53
  94. package/build/src/cli/render/audit.js +2 -6
  95. package/build/src/cli/render/contract.js +61 -20
  96. package/build/src/cli/render/kanshi.js +15 -5
  97. package/build/src/cli/render/nuke.d.ts +3 -0
  98. package/build/src/cli/render/nuke.js +8 -0
  99. package/build/src/cli/render/receipt.js +28 -1
  100. package/build/src/cli/render/refusal.d.ts +2 -1
  101. package/build/src/cli/render/refusal.js +31 -0
  102. package/build/src/cli/render/terminal.d.ts +0 -2
  103. package/build/src/cli/render/terminal.js +0 -29
  104. package/build/src/cli/render/text.js +6 -1
  105. package/build/src/cli/result.d.ts +36 -9
  106. package/build/src/cli/runtime.d.ts +2 -0
  107. package/build/src/cli/runtime.js +140 -0
  108. package/build/src/cli/usage.d.ts +0 -2
  109. package/build/src/cli/usage.js +0 -4
  110. package/build/src/contract-worktree.d.ts +29 -14
  111. package/build/src/contract-worktree.js +131 -70
  112. package/build/src/core/facts/codec.js +9 -0
  113. package/build/src/core/facts/fold.js +13 -1
  114. package/build/src/core/facts/types.d.ts +8 -1
  115. package/build/src/core/subject.js +4 -3
  116. package/build/src/core/verbs/placement.d.ts +9 -1
  117. package/build/src/core/verbs/placement.js +24 -6
  118. package/build/src/core/verbs/reintegrate.d.ts +13 -0
  119. package/build/src/core/verbs/reintegrate.js +24 -0
  120. package/build/src/dispatch/index.d.ts +1 -1
  121. package/build/src/git/admission.d.ts +2 -1
  122. package/build/src/git/hooks.d.ts +2 -0
  123. package/build/src/git/hooks.js +34 -1
  124. package/build/src/git/integration.d.ts +9 -2
  125. package/build/src/git/integration.js +92 -1
  126. package/build/src/git/nuke.d.ts +2 -0
  127. package/build/src/git/nuke.js +97 -0
  128. package/build/src/git/observe.d.ts +2 -1
  129. package/build/src/git/observe.js +6 -5
  130. package/build/src/git/process.d.ts +28 -0
  131. package/build/src/git/process.js +94 -0
  132. package/build/src/git/read-observation.d.ts +2 -1
  133. package/build/src/git/read-observation.js +3 -2
  134. package/build/src/git/reconcile.d.ts +4 -1
  135. package/build/src/git/reconcile.js +42 -8
  136. package/build/src/git/repository.d.ts +2 -29
  137. package/build/src/git/repository.js +7 -118
  138. package/build/src/git/scratch.d.ts +1 -1
  139. package/build/src/git/scratch.js +1 -1
  140. package/build/src/git/target-placement.d.ts +3 -2
  141. package/build/src/git/target-placement.js +15 -14
  142. package/build/src/git/tender.d.ts +2 -1
  143. package/build/src/git/tender.js +4 -3
  144. package/build/src/git/terminal-seal.d.ts +2 -2
  145. package/build/src/git/terminal-seal.js +3 -6
  146. package/build/src/git/workspace.d.ts +4 -1
  147. package/build/src/git/workspace.js +1 -1
  148. package/build/src/index.d.ts +1 -2
  149. package/build/src/index.js +1 -1
  150. package/build/src/kanshi/read.js +5 -1
  151. package/build/src/library/address.js +7 -1
  152. package/build/src/library/akuma-creation.d.ts +1 -0
  153. package/build/src/library/akuma-creation.js +8 -1
  154. package/build/src/library/audit.d.ts +3 -1
  155. package/build/src/library/audit.js +2 -1
  156. package/build/src/library/bind.d.ts +2 -1
  157. package/build/src/library/bind.js +1 -1
  158. package/build/src/library/configuration.d.ts +1 -1
  159. package/build/src/library/configuration.js +52 -18
  160. package/build/src/library/contract.d.ts +59 -4
  161. package/build/src/library/contract.js +195 -34
  162. package/build/src/library/delivery.d.ts +4 -2
  163. package/build/src/library/fleet.d.ts +27 -7
  164. package/build/src/library/fleet.js +79 -39
  165. package/build/src/library/input.d.ts +0 -1
  166. package/build/src/library/input.js +0 -5
  167. package/build/src/library/keiyaku.d.ts +6 -2
  168. package/build/src/library/keiyaku.js +2 -0
  169. package/build/src/library/mutation.d.ts +3 -1
  170. package/build/src/library/mutation.js +3 -0
  171. package/build/src/library/nuke.d.ts +14 -0
  172. package/build/src/library/nuke.js +54 -0
  173. package/build/src/library/reconcile.d.ts +2 -1
  174. package/build/src/library/reconcile.js +8 -3
  175. package/build/src/library/refusal.d.ts +10 -1
  176. package/build/src/library/region.d.ts +1 -1
  177. package/build/src/library/repo.d.ts +4 -1
  178. package/build/src/library/repo.js +10 -4
  179. package/build/src/protocol/abandon.d.ts +9 -0
  180. package/build/src/protocol/abandon.js +15 -0
  181. package/build/src/protocol/amend.d.ts +16 -0
  182. package/build/src/protocol/amend.js +77 -0
  183. package/build/src/protocol/arc.d.ts +6 -0
  184. package/build/src/protocol/arc.js +12 -0
  185. package/build/src/protocol/attempt.d.ts +2 -1
  186. package/build/src/protocol/audit.d.ts +53 -0
  187. package/build/src/protocol/audit.js +147 -0
  188. package/build/src/protocol/bind.d.ts +1 -1
  189. package/build/src/protocol/completion.d.ts +42 -0
  190. package/build/src/protocol/completion.js +183 -0
  191. package/build/src/protocol/deliver.d.ts +49 -0
  192. package/build/src/protocol/deliver.js +261 -0
  193. package/build/src/protocol/intent.d.ts +2 -1
  194. package/build/src/protocol/intent.js +8 -2
  195. package/build/src/protocol/operations.d.ts +93 -202
  196. package/build/src/protocol/operations.js +23 -642
  197. package/build/src/protocol/placement.d.ts +12 -13
  198. package/build/src/protocol/placement.js +8 -19
  199. package/build/src/protocol/read/status.d.ts +17 -5
  200. package/build/src/protocol/read/status.js +57 -13
  201. package/build/src/protocol/reconcile.d.ts +35 -0
  202. package/build/src/protocol/reconcile.js +41 -0
  203. package/build/src/protocol/reintegrate.d.ts +31 -0
  204. package/build/src/protocol/reintegrate.js +74 -0
  205. package/build/src/protocol/review.d.ts +34 -0
  206. package/build/src/protocol/review.js +156 -0
  207. package/build/src/protocol/run.d.ts +1 -1
  208. package/build/src/runtime/proc/run.js +9 -5
  209. package/build/src/settlement/fence.d.ts +3 -1
  210. package/build/src/settlement/fence.js +24 -0
  211. package/build/src/settlement/holder.d.ts +1 -1
  212. package/build/src/settlement/settle.d.ts +1 -1
  213. package/build/src/settlement/settle.js +1 -2
  214. package/build/src/task/board.d.ts +0 -1
  215. package/build/src/task/board.js +0 -3
  216. package/build/src/task/compose.d.ts +2 -2
  217. package/build/src/task/compose.js +13 -11
  218. package/build/src/task/context.d.ts +14 -2
  219. package/build/src/task/context.js +30 -7
  220. package/build/src/task/index.d.ts +7 -6
  221. package/build/src/task/index.js +17 -145
  222. package/build/src/task/input.d.ts +18 -0
  223. package/build/src/task/input.js +189 -0
  224. package/build/src/task/mutation.d.ts +44 -0
  225. package/build/src/task/mutation.js +93 -0
  226. package/build/src/task/operations.d.ts +14 -6
  227. package/build/src/task/operations.js +57 -57
  228. package/build/src/task/store.d.ts +1 -0
  229. package/build/src/task/store.js +91 -3
  230. package/build/src/verification/execution.d.ts +1 -1
  231. package/build/src/workspace-place.d.ts +3 -4
  232. package/build/src/workspace-place.js +26 -15
  233. package/package.json +3 -3
@@ -9,31 +9,65 @@ function namespaceFailure(view) {
9
9
  throw new Error("settings namespace failure expected");
10
10
  throw new SettingsError(view.failures.map((failure) => `${failure.scope}: ${failure.diagnostic}`).join("; "));
11
11
  }
12
+ function bundleGates(name, value) {
13
+ if (!record(value))
14
+ throw new SettingsError(`gate bundle '${name}' must be an object`);
15
+ if (value.kind !== "bundle") {
16
+ throw new SettingsError(`gate bundle '${name}' has unsupported kind: ${String(value.kind)}`);
17
+ }
18
+ for (const field of Object.keys(value)) {
19
+ if (field !== "kind" && field !== "gates") {
20
+ throw new SettingsError(`gate bundle '${name}' has unknown field: ${field}`);
21
+ }
22
+ }
23
+ if (!Array.isArray(value.gates)) {
24
+ throw new SettingsError(`gate bundle '${name}'.gates must be an array`);
25
+ }
26
+ return value.gates.map((gate) => {
27
+ if (!gateWord(gate)) {
28
+ throw new SettingsError(`gate bundle '${name}' contains an invalid gate word`);
29
+ }
30
+ if (gate !== "reviewed" && gate !== "verified") {
31
+ throw new SettingsError(`gate bundle '${name}' contains a gate without a producer: ${gate}`);
32
+ }
33
+ return gate;
34
+ });
35
+ }
12
36
  export function gatesFrom(input) {
13
37
  if (!record(input))
14
38
  throw new TypeError("gatesFrom input must be an object");
15
- const name = input.name ?? "default";
16
- if (!gateWord(name))
17
- throw new SettingsError("gate set name must match ^[a-z][a-z0-9-]{0,63}$");
39
+ if (input.names !== undefined && !Array.isArray(input.names)) {
40
+ throw new TypeError("gatesFrom names must be an array");
41
+ }
42
+ const names = input.names ?? ["default"];
43
+ for (const name of names) {
44
+ if (!gateWord(name))
45
+ throw new SettingsError("gate bundle name must match ^[a-z][a-z0-9-]{0,63}$");
46
+ }
18
47
  const view = input.settings.namespace("gates");
19
48
  if (view.kind === "failed")
20
49
  namespaceFailure(view);
21
- const selected = view.entries.find((entry) => entry.name === name);
22
- if (selected === undefined) {
23
- if (input.name === undefined)
24
- return Object.freeze([]);
25
- throw new SettingsError(`unknown gate set: ${name}`);
50
+ const expanded = [];
51
+ const seen = new Set();
52
+ for (const name of names) {
53
+ const selected = view.entries.find((entry) => entry.name === name);
54
+ if (selected === undefined) {
55
+ if (input.names === undefined) {
56
+ if (!seen.has("reviewed"))
57
+ expanded.push("reviewed");
58
+ seen.add("reviewed");
59
+ continue;
60
+ }
61
+ throw new SettingsError(`unknown gate bundle: ${name}`);
62
+ }
63
+ for (const gate of bundleGates(name, selected.value)) {
64
+ if (seen.has(gate))
65
+ continue;
66
+ seen.add(gate);
67
+ expanded.push(gate);
68
+ }
26
69
  }
27
- if (!Array.isArray(selected.value))
28
- throw new SettingsError(`gate set '${name}' must be an array`);
29
- const values = selected.value.map((value) => {
30
- if (!gateWord(value))
31
- throw new SettingsError(`gate set '${name}' contains an invalid gate word`);
32
- return value;
33
- });
34
- if (new Set(values).size !== values.length)
35
- throw new SettingsError(`gate set '${name}' contains duplicate gates`);
36
- return Object.freeze(values);
70
+ return Object.freeze(expanded);
37
71
  }
38
72
  function command(value, coordinate, ErrorType) {
39
73
  if (!record(value))
@@ -3,7 +3,13 @@ import { type RegionObservation, type RegionOverlap } from "./region.js";
3
3
  import { type Gate, type WorktreeHooks } from "./configuration.js";
4
4
  import { type ChangeId, type ContractId, type ContractState, type JournalEntry, type SnapshotId } from "../core/facts/types.js";
5
5
  export { AuthorityCorruptionError } from "../core/facts/errors.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
+ import { type PlacementStop, type RepositoryScope, type VerificationStop, type DeliveryPreparationRefusal } from "../protocol/operations.js";
7
+ import type { ContractBoard, ContractDisposition, ContractGateCurrent, ContractGateReport, ContractObservation, ContractPhase, ContractRow } from "../protocol/read/status.js";
8
+ import type { AuditReport } from "../protocol/audit.js";
9
+ import { type DeliverValue, type IntegrationConflictMaterialized, type VerificationReuse } from "../protocol/deliver.js";
10
+ import type { ReconcileReport as ProtocolReconcileReport } from "../protocol/reconcile.js";
11
+ import { type ReviewValue } from "../protocol/review.js";
12
+ import type { FactKind } from "../core/facts/types.js";
7
13
  import { type Dispatch } from "../dispatch/index.js";
8
14
  import { type SettlementReport } from "../settlement/settle.js";
9
15
  import { type TaskId } from "../task/identity.js";
@@ -11,7 +17,10 @@ import { Repo, type ReconcileInput } from "./repo.js";
11
17
  import { type AuditInput } from "./audit.js";
12
18
  import { Delivery } from "./delivery.js";
13
19
  import { type MutationResult } from "./mutation.js";
14
- export { KeiyakuRefused, KeiyakuRetry, type ContractAppointmentRefusal, type KeiyakuRefusal, type KeiyakuRetryReason, } from "./refusal.js";
20
+ import { KeiyakuRetry, type KeiyakuRefusal, type KeiyakuRetryReason } from "./refusal.js";
21
+ export { KeiyakuRefused, type ContractAppointmentRefusal, } from "./refusal.js";
22
+ export { KeiyakuRetry };
23
+ export type { KeiyakuRefusal, KeiyakuRetryReason };
15
24
  export { gatesFrom, requireBranchesToBeUpToDateFrom, SettingsError } from "./configuration.js";
16
25
  export type { Gate, GatesFromInput, HookCommand, RequireBranchesToBeUpToDateFromInput, WorktreeHooks } from "./configuration.js";
17
26
  export type { AuditReport, DeliveryPreparationRefusal, ChangeId, ContractId, ContractState, ContractBoard, ContractDisposition, ContractGateCurrent, ContractGateReport, ContractObservation, ContractPhase, ContractRow, FactKind, SnapshotId, };
@@ -33,7 +42,7 @@ export type ContractHistory = Readonly<{
33
42
  export type ActorId = string;
34
43
  export type AttestationVerdict = "satisfied" | "unsatisfied";
35
44
  export type Review = ReviewValue;
36
- export type { PlacementStop, VerificationReuse, VerificationStop };
45
+ export type { PlacementStop, VerificationReuse, VerificationStop, IntegrationConflictMaterialized };
37
46
  export type TopologyEffect = ProtocolReconcileReport["effects"][number] | ContractFileEffect;
38
47
  export type Lag = ProtocolReconcileReport["lag"][number] | ContractFileLag;
39
48
  export type { MutationResult };
@@ -101,9 +110,55 @@ export type DeliverInput = ActorOptions & Readonly<{
101
110
  message?: string;
102
111
  requireBranchesToBeUpToDate?: boolean;
103
112
  includeDirty?: boolean;
113
+ materializeConflict?: boolean;
104
114
  signal?: AbortSignal;
105
115
  }>;
116
+ type ForwardedDeliveryReceipt = Readonly<{
117
+ kind: "accepted";
118
+ result: MutationResult<DeliverValue>;
119
+ }> | Readonly<{
120
+ kind: "refused";
121
+ refusal: KeiyakuRefusal;
122
+ }> | Readonly<{
123
+ kind: "retry";
124
+ reason: KeiyakuRetryReason;
125
+ }> | IntegrationConflictMaterialized;
126
+ type ForwardedReviewReceipt = Readonly<{
127
+ kind: "accepted";
128
+ result: MutationResult<ReviewValue>;
129
+ }> | Readonly<{
130
+ kind: "refused";
131
+ refusal: KeiyakuRefusal;
132
+ }> | Readonly<{
133
+ kind: "retry";
134
+ reason: KeiyakuRetryReason;
135
+ }>;
106
136
  export type { AuditInput };
137
+ export declare function executeForwardedDeliver(input: Readonly<{
138
+ repo: Repo;
139
+ contractId: string;
140
+ requester: string;
141
+ message?: string;
142
+ includeDirty: boolean;
143
+ materializeConflict: boolean;
144
+ requireBranchesToBeUpToDate: boolean;
145
+ hooks: WorktreeHooks;
146
+ signal?: AbortSignal;
147
+ }>): Promise<Readonly<{
148
+ result: ForwardedDeliveryReceipt;
149
+ deliveryFactId?: string;
150
+ }>>;
151
+ export declare function executeForwardedReview(input: Readonly<{
152
+ repo: Repo;
153
+ contractId: string;
154
+ requester: string;
155
+ verdict: AttestationVerdict;
156
+ summary?: string;
157
+ hooks: WorktreeHooks;
158
+ }>): Promise<Readonly<{
159
+ result: ForwardedReviewReceipt;
160
+ reviewFactId?: string;
161
+ }>>;
107
162
  export declare class KeiyakuHandle {
108
163
  private readonly id;
109
164
  private readonly scope;
@@ -113,7 +168,7 @@ export declare class KeiyakuHandle {
113
168
  guidance(): Promise<string>;
114
169
  delivery(): Promise<Delivery | null>;
115
170
  amend(input: AmendInput): Promise<AmendResult>;
116
- deliver(input?: DeliverInput): Promise<MutationResult<Delivery>>;
171
+ deliver(input?: DeliverInput): Promise<MutationResult<Delivery> | IntegrationConflictMaterialized>;
117
172
  review(input: ReviewInput): Promise<MutationResult<Review>>;
118
173
  abandon(input?: AbandonInput): Promise<MutationResult<void>>;
119
174
  arc(input: ArcInput): Promise<MutationResult<void>>;
@@ -2,13 +2,19 @@ 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 { renderContractGuidance, } from "../contract-worktree.js";
5
+ import { renderContractGuidance, resolveHereContractWorkspace, } from "../contract-worktree.js";
6
6
  import { actorOption, contractTerms, documentDerivation, normalizedGates, normalizedList, optionalBoolean, optionalNonblank, optionalSignal, requireInput, requireMarkdown, } from "./input.js";
7
7
  import { observeRegion } from "./region.js";
8
8
  import { worktreeHooksOption } from "./configuration.js";
9
9
  import { contractId, } from "../core/facts/types.js";
10
+ import { AuthorityCorruptionError } from "../core/facts/errors.js";
10
11
  export { AuthorityCorruptionError } from "../core/facts/errors.js";
11
- import { abandonOperation, amendOperation, arcOperation, contractObservationOperation, contractsOperation, deliveryDiffOperation, deliverOperation, deliveryOperation, reviewOperation, stateOperation, } from "../protocol/operations.js";
12
+ import { contractObservationOperation, contractsOperation, deliveryDiffOperation, deliveryOperation, stateOperation, } from "../protocol/operations.js";
13
+ import { abandonOperation } from "../protocol/abandon.js";
14
+ import { amendOperation } from "../protocol/amend.js";
15
+ import { arcOperation } from "../protocol/arc.js";
16
+ import { deliverOperation, } from "../protocol/deliver.js";
17
+ import { reviewOperation } from "../protocol/review.js";
12
18
  import { readDispatchesAt } from "../dispatch/index.js";
13
19
  import { mintSnapshotId } from "../git/identity.js";
14
20
  import { observeContractsForAdmissionInObservationAt } from "../git/observe.js";
@@ -16,13 +22,15 @@ import { withGitDecodeChannel, withGitReadObservation } from "../git/read-observ
16
22
  import { claimTaskHolderWithFence, releaseTaskHolder, releaseTaskHolderWithFence, taskHolderObservationSelection, } from "../settlement/holder.js";
17
23
  import { parseTaskId } from "../task/identity.js";
18
24
  import { reconcileInput, scopeForRepo } from "./repo.js";
25
+ import { injectedBodyRequests, requestBodyDeliver, requestBodyReview, } from "../akuma/requests.js";
19
26
  import { auditContract } from "./audit.js";
20
27
  import { Delivery, deliveryHandle } from "./delivery.js";
21
- import { completeHolderMutation, completeMutation, } from "./mutation.js";
28
+ import { completionInput, completeHolderMutation, completeMutation, } from "./mutation.js";
22
29
  import { completeReconcile } from "./reconcile.js";
23
30
  import { admitBindWithAppointment } from "./bind.js";
24
- import { KeiyakuRefused, requireAccepted } from "./refusal.js";
25
- export { KeiyakuRefused, KeiyakuRetry, } from "./refusal.js";
31
+ import { KeiyakuRefused, KeiyakuRetry, requireAccepted, } from "./refusal.js";
32
+ export { KeiyakuRefused, } from "./refusal.js";
33
+ export { KeiyakuRetry };
26
34
  export { gatesFrom, requireBranchesToBeUpToDateFrom, SettingsError } from "./configuration.js";
27
35
  export { Delivery };
28
36
  function taskOption(value) {
@@ -38,8 +46,140 @@ function taskOption(value) {
38
46
  }
39
47
  return value;
40
48
  }
41
- function completion(scope, channel, id, value, hooks) {
42
- return { scope, channel, contractId: id, value, hooks };
49
+ async function resolveHereWorkspace(scope, id) {
50
+ const appointment = await resolveHereContractWorkspace(scope, id);
51
+ if (appointment.kind === "failed") {
52
+ if (appointment.cause === "duplicate")
53
+ throw new AuthorityCorruptionError(appointment.diagnostic);
54
+ throw new Error(appointment.diagnostic);
55
+ }
56
+ return appointment.kind === "appointed" ? appointment.path : undefined;
57
+ }
58
+ function derivedDocument(state) {
59
+ return documentDerivation(decodeContractDocument(state.terms.document.bytes), state.terms.gates, state.id);
60
+ }
61
+ async function executeLocalDelivery(input) {
62
+ return withGitDecodeChannel(input.scope, async (channel) => {
63
+ const outcome = await deliverOperation({
64
+ scope: input.scope,
65
+ channel,
66
+ contractId: input.contractId,
67
+ deriveDocument: derivedDocument,
68
+ ...(input.actor === undefined ? {} : { actor: input.actor }),
69
+ ...(input.message === undefined ? {} : { message: input.message }),
70
+ requireBranchesToBeUpToDate: input.requireBranchesToBeUpToDate,
71
+ includeDirty: input.includeDirty,
72
+ materializeConflict: input.materializeConflict,
73
+ ...(input.signal === undefined ? {} : { signal: input.signal }),
74
+ resolveHereWorkspace: async (id) => await resolveHereWorkspace(input.scope, id),
75
+ });
76
+ if (outcome.kind === "integration-conflict-materialized")
77
+ return outcome;
78
+ return completeMutation({
79
+ ...completionInput(input.scope, channel, input.contractId, (delivery) => delivery, input.hooks),
80
+ accepted: requireAccepted(outcome),
81
+ });
82
+ });
83
+ }
84
+ async function executeLocalReview(input) {
85
+ return withGitDecodeChannel(input.scope, async (channel) => {
86
+ const accepted = requireAccepted(await reviewOperation({
87
+ scope: input.scope,
88
+ channel,
89
+ contractId: input.contractId,
90
+ deriveDocument: derivedDocument,
91
+ verdict: input.verdict,
92
+ ...(input.summary === undefined ? {} : { summary: input.summary }),
93
+ ...(input.actor === undefined ? {} : { actor: input.actor }),
94
+ resolveHereWorkspace: async (id) => await resolveHereWorkspace(input.scope, id),
95
+ }));
96
+ return completeMutation({
97
+ ...completionInput(input.scope, channel, input.contractId, (review) => review, input.hooks),
98
+ accepted,
99
+ });
100
+ });
101
+ }
102
+ function forwardedReceipt(outcome, action) {
103
+ if (outcome.kind === "failed") {
104
+ throw new Error(outcome.failure.kind === "failed"
105
+ ? outcome.failure.diagnostic
106
+ : `Unexpected Akuma target failure for ${action}: ${outcome.failure.id}`);
107
+ }
108
+ return outcome.result;
109
+ }
110
+ function requireForwardedDelivery(receipt) {
111
+ if (receipt.kind === "refused")
112
+ throw new KeiyakuRefused(receipt.refusal);
113
+ if (receipt.kind === "retry")
114
+ throw new KeiyakuRetry(receipt.reason);
115
+ return receipt.kind === "accepted" ? receipt.result : receipt;
116
+ }
117
+ function requireForwardedReview(receipt) {
118
+ if (receipt.kind === "refused")
119
+ throw new KeiyakuRefused(receipt.refusal);
120
+ if (receipt.kind === "retry")
121
+ throw new KeiyakuRetry(receipt.reason);
122
+ return receipt.result;
123
+ }
124
+ export async function executeForwardedDeliver(input) {
125
+ const id = contractId(input.contractId);
126
+ const actor = actorOption(input.requester).actor;
127
+ const message = optionalNonblank(input.message, "deliver message");
128
+ try {
129
+ const result = await executeLocalDelivery({
130
+ scope: scopeForRepo(input.repo),
131
+ contractId: id,
132
+ ...(actor === undefined ? {} : { actor }),
133
+ ...(message === undefined ? {} : { message }),
134
+ requireBranchesToBeUpToDate: input.requireBranchesToBeUpToDate,
135
+ includeDirty: input.includeDirty,
136
+ materializeConflict: input.materializeConflict,
137
+ ...(input.signal === undefined ? {} : { signal: input.signal }),
138
+ hooks: input.hooks,
139
+ });
140
+ if (!("facts" in result))
141
+ return { result };
142
+ const delivery = result.facts.find((fact) => fact.kind === "deliver");
143
+ if (delivery === undefined)
144
+ throw new Error("accepted delivery is missing its journal fact");
145
+ return { result: { kind: "accepted", result }, deliveryFactId: delivery.entry };
146
+ }
147
+ catch (error) {
148
+ if (error instanceof KeiyakuRefused)
149
+ return { result: { kind: "refused", refusal: error.refusal } };
150
+ if (error instanceof KeiyakuRetry)
151
+ return { result: { kind: "retry", reason: error.reason } };
152
+ throw error;
153
+ }
154
+ }
155
+ export async function executeForwardedReview(input) {
156
+ const id = contractId(input.contractId);
157
+ const actor = actorOption(input.requester).actor;
158
+ if (input.verdict !== "satisfied" && input.verdict !== "unsatisfied") {
159
+ throw new TypeError("verdict must be satisfied or unsatisfied");
160
+ }
161
+ const summary = optionalNonblank(input.summary, "review summary");
162
+ try {
163
+ const result = await executeLocalReview({
164
+ scope: scopeForRepo(input.repo),
165
+ contractId: id,
166
+ ...(actor === undefined ? {} : { actor }),
167
+ verdict: input.verdict,
168
+ ...(summary === undefined ? {} : { summary }),
169
+ hooks: input.hooks,
170
+ });
171
+ const review = result.facts.find((fact) => fact.kind === "attestation");
172
+ if (review === undefined)
173
+ throw new Error("accepted review is missing its journal fact");
174
+ return { result: { kind: "accepted", result }, reviewFactId: review.entry };
175
+ }
176
+ catch (error) {
177
+ if (error instanceof KeiyakuRefused)
178
+ return { result: { kind: "refused", refusal: error.refusal } };
179
+ if (error instanceof KeiyakuRetry)
180
+ return { result: { kind: "retry", reason: error.reason } };
181
+ throw error;
182
+ }
43
183
  }
44
184
  export class KeiyakuHandle {
45
185
  id;
@@ -145,7 +285,7 @@ export class KeiyakuHandle {
145
285
  const document = decodeContractDocument(accepted.value.terms.document.bytes);
146
286
  return {
147
287
  ...await completeMutation({
148
- ...completion(this.scope, channel, this.id, () => undefined, hooks),
288
+ ...completionInput(this.scope, channel, this.id, () => undefined, hooks),
149
289
  accepted,
150
290
  }),
151
291
  documentDiff: documentDiff("before", "after", accepted.value.source.document.bytes, accepted.value.terms.document.bytes),
@@ -159,25 +299,32 @@ export class KeiyakuHandle {
159
299
  const message = optionalNonblank(values?.message, "deliver message");
160
300
  const requireBranchesToBeUpToDate = optionalBoolean(values?.requireBranchesToBeUpToDate, "requireBranchesToBeUpToDate") ?? false;
161
301
  const includeDirty = optionalBoolean(values?.includeDirty, "includeDirty") ?? false;
302
+ const materializeConflict = optionalBoolean(values?.materializeConflict, "materializeConflict") ?? false;
162
303
  const actor = actorOption(values?.actor);
163
304
  const signal = optionalSignal(values?.signal);
164
- return withGitDecodeChannel(this.scope, async (channel) => {
165
- const accepted = requireAccepted(await deliverOperation({
305
+ const requests = injectedBodyRequests();
306
+ const result = requests === null
307
+ ? await executeLocalDelivery({
166
308
  scope: this.scope,
167
- channel,
168
309
  contractId: this.id,
169
- deriveDocument: (state) => documentDerivation(decodeContractDocument(state.terms.document.bytes), state.terms.gates, state.id),
170
310
  ...actor,
171
311
  ...(message === undefined ? {} : { message }),
172
312
  requireBranchesToBeUpToDate,
173
313
  includeDirty,
314
+ materializeConflict,
174
315
  ...(signal === undefined ? {} : { signal }),
175
- }));
176
- return completeMutation({
177
- ...completion(this.scope, channel, this.id, (delivery) => this.deliveryHandle(delivery), hooks),
178
- accepted,
179
- });
180
- });
316
+ hooks,
317
+ })
318
+ : requireForwardedDelivery(forwardedReceipt(await requestBodyDeliver({
319
+ directory: requests,
320
+ repoRoot: this.scope.primaryWorktree,
321
+ contractId: this.id,
322
+ ...(message === undefined ? {} : { message }),
323
+ includeDirty,
324
+ materializeConflict,
325
+ ...(signal === undefined ? {} : { signal }),
326
+ }), "deliver"));
327
+ return "facts" in result ? { ...result, value: this.deliveryHandle(result.value) } : result;
181
328
  }
182
329
  async review(input) {
183
330
  const values = requireInput(input, "review input");
@@ -187,19 +334,24 @@ export class KeiyakuHandle {
187
334
  throw new TypeError("verdict must be satisfied or unsatisfied");
188
335
  }
189
336
  const summary = optionalNonblank(values.summary, "review summary");
190
- return withGitDecodeChannel(this.scope, async (channel) => {
191
- const accepted = requireAccepted(await reviewOperation({
192
- scope: this.scope,
193
- channel,
337
+ const actor = actorOption(values.actor);
338
+ const requests = injectedBodyRequests();
339
+ if (requests !== null) {
340
+ return requireForwardedReview(forwardedReceipt(await requestBodyReview({
341
+ directory: requests,
342
+ repoRoot: this.scope.primaryWorktree,
194
343
  contractId: this.id,
195
344
  verdict,
196
345
  ...(summary === undefined ? {} : { summary }),
197
- ...actorOption(values.actor),
198
- }));
199
- return completeMutation({
200
- ...completion(this.scope, channel, this.id, (value) => value, hooks),
201
- accepted,
202
- });
346
+ }), "review"));
347
+ }
348
+ return await executeLocalReview({
349
+ scope: this.scope,
350
+ contractId: this.id,
351
+ ...actor,
352
+ verdict,
353
+ ...(summary === undefined ? {} : { summary }),
354
+ hooks,
203
355
  });
204
356
  }
205
357
  async abandon(input) {
@@ -220,7 +372,7 @@ export class KeiyakuHandle {
220
372
  },
221
373
  }));
222
374
  return completeHolderMutation({
223
- completion: completion(this.scope, channel, this.id, () => undefined, hooks),
375
+ completion: completionInput(this.scope, channel, this.id, () => undefined, hooks),
224
376
  admission,
225
377
  requireAccepted,
226
378
  });
@@ -239,7 +391,7 @@ export class KeiyakuHandle {
239
391
  chapter,
240
392
  }));
241
393
  return completeMutation({
242
- ...completion(this.scope, channel, this.id, () => undefined, hooks),
394
+ ...completionInput(this.scope, channel, this.id, () => undefined, hooks),
243
395
  accepted,
244
396
  });
245
397
  });
@@ -288,7 +440,11 @@ export async function listKeiyaku(input) {
288
440
  if (key !== "repo")
289
441
  throw new TypeError(`Keiyaku.list input has unknown field: ${key}`);
290
442
  const scope = scopeForRepo(values.repo);
291
- return withGitDecodeChannel(scope, (channel) => contractsOperation({ scope, channel }));
443
+ return withGitDecodeChannel(scope, (channel) => contractsOperation({
444
+ scope,
445
+ channel,
446
+ hereWorkspace: async (id) => await resolveHereContractWorkspace(scope, id),
447
+ }));
292
448
  }
293
449
  export async function observeKeiyaku(input) {
294
450
  const values = requireInput(input, "Keiyaku.observe input");
@@ -305,7 +461,12 @@ export async function observeKeiyaku(input) {
305
461
  catch (error) {
306
462
  throw new TypeError(error instanceof Error ? error.message : "contract ID is invalid");
307
463
  }
308
- return withGitDecodeChannel(scope, (channel) => contractObservationOperation({ scope, channel, contractId: id }));
464
+ return withGitDecodeChannel(scope, (channel) => contractObservationOperation({
465
+ scope,
466
+ channel,
467
+ contractId: id,
468
+ hereWorkspace: async (contract) => await resolveHereContractWorkspace(scope, contract),
469
+ }));
309
470
  }
310
471
  export async function bindKeiyaku(input) {
311
472
  const values = requireInput(input, "Keiyaku.bind input");
@@ -339,9 +500,9 @@ export async function bindKeiyaku(input) {
339
500
  const id = accepted.value.contractId;
340
501
  const toHandle = ({ contractId: contract }) => new KeiyakuHandle(contract, scope);
341
502
  const result = admission === null
342
- ? await completeMutation({ ...completion(scope, channel, id, toHandle, hooks), accepted })
503
+ ? await completeMutation({ ...completionInput(scope, channel, id, toHandle, hooks), accepted })
343
504
  : await completeHolderMutation({
344
- completion: completion(scope, channel, id, toHandle, hooks),
505
+ completion: completionInput(scope, channel, id, toHandle, hooks),
345
506
  admission,
346
507
  requireAccepted,
347
508
  });
@@ -1,9 +1,11 @@
1
1
  import type { SnapshotId } from "../core/facts/types.js";
2
- import type { DeliverValue } from "../protocol/operations.js";
2
+ import type { DeliverValue } from "../protocol/deliver.js";
3
3
  declare class DeliveryHandle {
4
4
  private readonly readDiff;
5
+ readonly completion?: DeliverValue["completion"];
5
6
  readonly verification?: DeliverValue["verification"];
6
7
  readonly verificationReuse?: DeliverValue["verificationReuse"];
8
+ readonly verificationSummary?: DeliverValue["verificationSummary"];
7
9
  readonly placement?: DeliverValue["placement"];
8
10
  readonly cleanup?: DeliverValue["cleanup"];
9
11
  readonly leak?: DeliverValue["leak"];
@@ -11,7 +13,7 @@ declare class DeliveryHandle {
11
13
  readonly integration: DeliverValue["integration"];
12
14
  readonly method: DeliverValue["method"];
13
15
  readonly policy: DeliverValue["policy"];
14
- constructor(identity: Pick<DeliverValue, "tenderSnapshot" | "integration" | "method" | "policy">, readDiff: () => Promise<string | null>, outcomes?: Partial<Pick<DeliverValue, "verification" | "verificationReuse" | "placement" | "cleanup" | "leak">>);
16
+ constructor(identity: Pick<DeliverValue, "tenderSnapshot" | "integration" | "method" | "policy">, readDiff: () => Promise<string | null>, outcomes?: Partial<Pick<DeliverValue, "completion" | "verification" | "verificationReuse" | "verificationSummary" | "placement" | "cleanup" | "leak">>);
15
17
  diff(): Promise<string | null>;
16
18
  }
17
19
  export type Delivery = DeliveryHandle;
@@ -11,11 +11,30 @@ export type CreatedTaskObservation = Readonly<{
11
11
  kind: "failed";
12
12
  diagnostic: string;
13
13
  }>;
14
+ export type DispatchAssociation = Readonly<{
15
+ kind: "none";
16
+ }> | Readonly<{
17
+ kind: "associated";
18
+ contractId: ContractId;
19
+ }> | Readonly<{
20
+ kind: "failed";
21
+ diagnostic: string;
22
+ }>;
14
23
  export type AkumaObservation = Readonly<{
15
24
  status: AkumaStatus;
16
- contractId?: ContractId;
25
+ contract: DispatchAssociation;
17
26
  createdTasks: CreatedTaskObservation;
18
27
  }>;
28
+ export type AkumaObservationStage = (Readonly<{
29
+ kind: "observed";
30
+ }> & AkumaObservation) | Readonly<{
31
+ kind: "unobserved";
32
+ diagnostic: string;
33
+ }>;
34
+ export type AkumaUnobserved = Readonly<{
35
+ id: AkumaStatus["id"];
36
+ diagnostic: string;
37
+ }>;
19
38
  export type AkumaWaitInput = AkumaSetAddressInput & Readonly<{
20
39
  completion?: "any" | "all";
21
40
  timeoutMs?: number;
@@ -23,12 +42,13 @@ export type AkumaWaitInput = AkumaSetAddressInput & Readonly<{
23
42
  export type AkumaWaitResult = Readonly<{
24
43
  completion: "any" | "all";
25
44
  observations: readonly AkumaObservation[];
45
+ unobserved: readonly AkumaUnobserved[];
26
46
  }>;
27
47
  export type AkumaKillResult = Readonly<{
28
48
  results: readonly Readonly<{
29
49
  id: AkumaStatus["id"];
30
50
  evidence: KillEvidence;
31
- observation: AkumaObservation;
51
+ observation: AkumaObservationStage;
32
52
  }>[];
33
53
  }>;
34
54
  export type AkumaTellInput = AkumaAddressInput & Readonly<{
@@ -37,7 +57,7 @@ export type AkumaTellInput = AkumaAddressInput & Readonly<{
37
57
  export type AkumaTellResult = Readonly<{
38
58
  akuma: AkumaStatus["id"];
39
59
  tell: TellResult;
40
- observation: AkumaObservation;
60
+ observation: AkumaObservationStage;
41
61
  }>;
42
62
  export type AkumaInterruptInput = AkumaAddressInput & Readonly<{
43
63
  body: string;
@@ -45,7 +65,7 @@ export type AkumaInterruptInput = AkumaAddressInput & Readonly<{
45
65
  export type AkumaInterruptResult = Readonly<{
46
66
  id: AkumaStatus["id"];
47
67
  receipt: InterruptReceipt;
48
- observation: AkumaObservation;
68
+ observation: AkumaObservationStage;
49
69
  }>;
50
70
  export type AkumaHistoryInput = AkumaAddressInput & Readonly<{
51
71
  before?: number;
@@ -57,16 +77,16 @@ export type AkumaHistoryResult = Readonly<{
57
77
  kind: "history";
58
78
  id: AkumaStatus["id"];
59
79
  history: ActivityHistory;
60
- contractId?: ContractId;
80
+ contract: DispatchAssociation;
61
81
  }> | Readonly<{
62
82
  kind: "last";
63
83
  id: AkumaStatus["id"];
64
84
  answer: string;
65
- contractId?: ContractId;
85
+ contract: DispatchAssociation;
66
86
  }> | Readonly<{
67
87
  kind: "no-answer";
68
88
  id: AkumaStatus["id"];
69
- contractId?: ContractId;
89
+ contract: DispatchAssociation;
70
90
  }>;
71
91
  type WaitExecutionInput = Readonly<{
72
92
  path: WorldRoot;