@astrosheep/keiyaku 4.5.7 → 4.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/README.md +10 -0
  2. package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +1 -1
  3. package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +1 -1
  4. package/build/integrations/marketplace/plugins/keiyaku/opencode.js +3 -2
  5. package/build/integrations/marketplace/plugins/keiyaku/package.json +1 -1
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +12 -11
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +33 -12
  8. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-babysit/SKILL.md +35 -96
  9. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +28 -49
  10. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-task/SKILL.md +21 -15
  11. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +148 -89
  12. package/build/src/akuma/abort.d.ts +2 -1
  13. package/build/src/akuma/abort.js +6 -23
  14. package/build/src/akuma/akuma-handle.js +4 -2
  15. package/build/src/akuma/akuma-observe.d.ts +2 -0
  16. package/build/src/akuma/akuma-observe.js +1 -0
  17. package/build/src/akuma/akuma-product.js +9 -7
  18. package/build/src/akuma/akuma.d.ts +392 -9
  19. package/build/src/akuma/akuma.js +31 -1
  20. package/build/src/akuma/allowed.d.ts +1 -1
  21. package/build/src/akuma/allowed.js +1 -0
  22. package/build/src/akuma/archetype.js +1 -1
  23. package/build/src/akuma/body.d.ts +8 -5
  24. package/build/src/akuma/body.js +12 -5
  25. package/build/src/akuma/call-request.d.ts +80 -0
  26. package/build/src/akuma/call-request.js +211 -0
  27. package/build/src/akuma/heart/facts.d.ts +16 -78
  28. package/build/src/akuma/heart/facts.js +11 -0
  29. package/build/src/akuma/heart/index.d.ts +3 -2
  30. package/build/src/akuma/heart/index.js +4 -1
  31. package/build/src/akuma/heart/request-authority.d.ts +5 -4
  32. package/build/src/akuma/heart/request-authority.js +20 -34
  33. package/build/src/akuma/heart/request-rows.js +12 -23
  34. package/build/src/akuma/heart/schema.d.ts +1 -1
  35. package/build/src/akuma/heart/schema.js +5 -13
  36. package/build/src/akuma/index.d.ts +1 -1
  37. package/build/src/akuma/index.js +1 -1
  38. package/build/src/akuma/projection-read.d.ts +1 -0
  39. package/build/src/akuma/projection-read.js +8 -1
  40. package/build/src/akuma/projection.d.ts +907 -137
  41. package/build/src/akuma/projection.js +193 -9
  42. package/build/src/akuma/provider.d.ts +30 -3
  43. package/build/src/akuma/provider.js +111 -0
  44. package/build/src/akuma/providers/acp/core.d.ts +2 -2
  45. package/build/src/akuma/providers/acp/core.js +13 -6
  46. package/build/src/akuma/providers/acp/index.js +5 -4
  47. package/build/src/akuma/providers/claude/events.d.ts +2 -2
  48. package/build/src/akuma/providers/claude/events.js +16 -3
  49. package/build/src/akuma/providers/claude/index.d.ts +3 -3
  50. package/build/src/akuma/providers/claude/index.js +16 -5
  51. package/build/src/akuma/providers/codex-app-server/events.d.ts +2 -2
  52. package/build/src/akuma/providers/codex-app-server/events.js +25 -4
  53. package/build/src/akuma/providers/codex-app-server/index.js +18 -6
  54. package/build/src/akuma/providers/grok-build/index.js +5 -4
  55. package/build/src/akuma/providers/opencode-sdk/index.js +66 -25
  56. package/build/src/akuma/providers/opencode-sdk/session.d.ts +3 -2
  57. package/build/src/akuma/providers/opencode-sdk/session.js +28 -11
  58. package/build/src/akuma/providers/pi/index.js +72 -58
  59. package/build/src/akuma/request-lifecycle.d.ts +4 -10
  60. package/build/src/akuma/request-lifecycle.js +7 -5
  61. package/build/src/akuma/request-rendezvous.d.ts +26 -0
  62. package/build/src/akuma/request-rendezvous.js +100 -0
  63. package/build/src/akuma/request-serve.d.ts +6 -66
  64. package/build/src/akuma/request-serve.js +83 -210
  65. package/build/src/akuma/request-wire.d.ts +109 -115
  66. package/build/src/akuma/request-wire.js +63 -318
  67. package/build/src/akuma/requests.d.ts +19 -47
  68. package/build/src/akuma/requests.js +51 -107
  69. package/build/src/akuma/turn-drive.d.ts +5 -3
  70. package/build/src/akuma/turn-drive.js +39 -11
  71. package/build/src/akuma-body.d.ts +7 -2
  72. package/build/src/akuma-body.js +68 -46
  73. package/build/src/body/amend.js +18 -19
  74. package/build/src/cli/accepted.d.ts +1 -1
  75. package/build/src/cli/accepted.js +2 -2
  76. package/build/src/cli/commands/akuma-invoke.d.ts +2 -0
  77. package/build/src/cli/commands/akuma-invoke.js +17 -9
  78. package/build/src/cli/commands/akuma.js +8 -8
  79. package/build/src/cli/commands/contract-invoke.d.ts +3 -2
  80. package/build/src/cli/commands/contract-invoke.js +42 -30
  81. package/build/src/cli/commands/contract.d.ts +16 -20
  82. package/build/src/cli/commands/contract.js +58 -25
  83. package/build/src/cli/commands/install.d.ts +2 -1
  84. package/build/src/cli/commands/install.js +3 -2
  85. package/build/src/cli/commands/task-invoke.d.ts +3 -0
  86. package/build/src/cli/commands/task-invoke.js +23 -140
  87. package/build/src/cli/commands/task.js +54 -20
  88. package/build/src/cli/invoke.js +39 -25
  89. package/build/src/cli/main.js +2 -1
  90. package/build/src/cli/parse.d.ts +2 -2
  91. package/build/src/cli/parse.js +56 -27
  92. package/build/src/cli/render/akuma-activity.d.ts +3 -0
  93. package/build/src/cli/render/akuma-activity.js +45 -29
  94. package/build/src/cli/render/akuma-tool.d.ts +5 -1
  95. package/build/src/cli/render/akuma.js +4 -8
  96. package/build/src/cli/render/audit.js +1 -1
  97. package/build/src/cli/render/catalog.js +80 -21
  98. package/build/src/cli/render/contract-observation.d.ts +2 -0
  99. package/build/src/cli/render/contract-observation.js +11 -0
  100. package/build/src/cli/render/contract.js +35 -62
  101. package/build/src/cli/render/kanshi-akuma.d.ts +8 -0
  102. package/build/src/cli/render/kanshi-akuma.js +132 -0
  103. package/build/src/cli/render/kanshi.js +131 -213
  104. package/build/src/cli/render/receipt.d.ts +1 -2
  105. package/build/src/cli/render/receipt.js +76 -26
  106. package/build/src/cli/render/refusal.js +2 -10
  107. package/build/src/cli/render/region.js +5 -2
  108. package/build/src/cli/render/settings.d.ts +1 -1
  109. package/build/src/cli/render/settings.js +27 -8
  110. package/build/src/cli/render/task.js +22 -5
  111. package/build/src/cli/render/terminal.d.ts +32 -1
  112. package/build/src/cli/render/terminal.js +77 -1
  113. package/build/src/cli/result.d.ts +3 -3
  114. package/build/src/cli/runtime.js +4 -2
  115. package/build/src/cli/selectors.d.ts +2 -1
  116. package/build/src/cli/selectors.js +4 -3
  117. package/build/src/cli/square-edge.js +120 -36
  118. package/build/src/cli/usage.js +2 -1
  119. package/build/src/contract-guidance.d.ts +5 -0
  120. package/build/src/contract-guidance.js +121 -0
  121. package/build/src/contract-worktree.d.ts +0 -1
  122. package/build/src/contract-worktree.js +32 -83
  123. package/build/src/coordination/sqlite-transaction-lock.d.ts +1 -0
  124. package/build/src/coordination/sqlite-transaction-lock.js +5 -0
  125. package/build/src/core/facts/codec.d.ts +2 -0
  126. package/build/src/core/facts/codec.js +4 -0
  127. package/build/src/core/verbs/placement.d.ts +6 -1
  128. package/build/src/core/verbs/placement.js +5 -3
  129. package/build/src/dispatch/index.d.ts +0 -2
  130. package/build/src/dispatch/index.js +54 -55
  131. package/build/src/git/admission.js +2 -2
  132. package/build/src/git/hooks.d.ts +9 -15
  133. package/build/src/git/hooks.js +23 -317
  134. package/build/src/git/nuke.d.ts +2 -1
  135. package/build/src/git/nuke.js +39 -21
  136. package/build/src/git/private-state-seat.d.ts +12 -0
  137. package/build/src/git/private-state-seat.js +39 -0
  138. package/build/src/git/process.d.ts +6 -0
  139. package/build/src/git/process.js +26 -11
  140. package/build/src/git/read-observation.js +29 -20
  141. package/build/src/git/reconcile.d.ts +13 -1
  142. package/build/src/git/reconcile.js +70 -11
  143. package/build/src/git/ref-migration.d.ts +22 -0
  144. package/build/src/git/ref-migration.js +55 -0
  145. package/build/src/git/repository.d.ts +10 -6
  146. package/build/src/git/repository.js +16 -8
  147. package/build/src/git/target-placement.d.ts +1 -0
  148. package/build/src/git/target-placement.js +5 -0
  149. package/build/src/git/tender.d.ts +1 -0
  150. package/build/src/git/terminal-reconcile.d.ts +1 -1
  151. package/build/src/git/terminal-reconcile.js +22 -20
  152. package/build/src/git/workspace.d.ts +14 -0
  153. package/build/src/git/workspace.js +44 -0
  154. package/build/src/kanshi/index.d.ts +1 -1
  155. package/build/src/kanshi/read.js +16 -16
  156. package/build/src/kanshi/report.d.ts +2 -2
  157. package/build/src/library/address.d.ts +9 -3
  158. package/build/src/library/address.js +3 -2
  159. package/build/src/library/akuma-creation.d.ts +4 -3
  160. package/build/src/library/akuma-creation.js +19 -13
  161. package/build/src/library/audit.d.ts +14 -6
  162. package/build/src/library/audit.js +13 -23
  163. package/build/src/library/catalog.d.ts +3 -1
  164. package/build/src/library/catalog.js +20 -6
  165. package/build/src/library/composition.d.ts +385 -0
  166. package/build/src/library/composition.js +28 -0
  167. package/build/src/library/configuration.js +8 -2
  168. package/build/src/library/continuation.js +66 -30
  169. package/build/src/library/contract-bind.js +10 -2
  170. package/build/src/library/contract-forwarding-reconciliation-result.d.ts +102 -0
  171. package/build/src/library/contract-forwarding-reconciliation-result.js +92 -0
  172. package/build/src/library/contract-forwarding-result.d.ts +4464 -0
  173. package/build/src/library/contract-forwarding-result.js +521 -0
  174. package/build/src/library/contract-forwarding.d.ts +71 -0
  175. package/build/src/library/contract-forwarding.js +114 -0
  176. package/build/src/library/contract-handle.d.ts +38 -0
  177. package/build/src/library/contract-handle.js +314 -0
  178. package/build/src/library/contract-operations.d.ts +214 -69
  179. package/build/src/library/contract-operations.js +189 -118
  180. package/build/src/library/contract-types.d.ts +7 -3
  181. package/build/src/library/contract.d.ts +21 -34
  182. package/build/src/library/contract.js +29 -287
  183. package/build/src/library/fleet-result.d.ts +1580 -0
  184. package/build/src/library/fleet-result.js +98 -0
  185. package/build/src/library/fleet.d.ts +112 -54
  186. package/build/src/library/fleet.js +211 -71
  187. package/build/src/library/input.d.ts +3 -1
  188. package/build/src/library/input.js +11 -1
  189. package/build/src/library/keiyaku.d.ts +388 -20
  190. package/build/src/library/keiyaku.js +13 -21
  191. package/build/src/library/mutation.d.ts +3 -3
  192. package/build/src/library/mutation.js +5 -9
  193. package/build/src/library/nuke.d.ts +1 -1
  194. package/build/src/library/nuke.js +4 -3
  195. package/build/src/library/reconcile.d.ts +4 -0
  196. package/build/src/library/reconcile.js +2 -0
  197. package/build/src/library/refusal.d.ts +0 -9
  198. package/build/src/library/refusal.js +0 -7
  199. package/build/src/protocol/amend.js +56 -50
  200. package/build/src/protocol/attempt.d.ts +2 -0
  201. package/build/src/protocol/attempt.js +8 -1
  202. package/build/src/protocol/completion.js +7 -0
  203. package/build/src/protocol/deliver.js +6 -2
  204. package/build/src/protocol/operations.d.ts +4 -1
  205. package/build/src/protocol/operations.js +5 -2
  206. package/build/src/protocol/placement.d.ts +1 -0
  207. package/build/src/protocol/placement.js +52 -38
  208. package/build/src/protocol/read/observation.d.ts +1 -4
  209. package/build/src/protocol/read/observation.js +2 -15
  210. package/build/src/protocol/reintegrate.js +62 -58
  211. package/build/src/protocol/review.js +5 -0
  212. package/build/src/protocol/run.js +17 -13
  213. package/build/src/runtime/proc/run.d.ts +9 -0
  214. package/build/src/runtime/proc/run.js +51 -4
  215. package/build/src/runtime/proc/termination.js +26 -22
  216. package/build/src/runtime/proc/windows-launch.exe +0 -0
  217. package/build/src/settlement/holder.d.ts +2 -1
  218. package/build/src/settlement/holder.js +15 -4
  219. package/build/src/settlement/settle.js +99 -33
  220. package/build/src/task/board.d.ts +68 -27
  221. package/build/src/task/board.js +31 -1
  222. package/build/src/task/catalog.d.ts +4 -0
  223. package/build/src/task/catalog.js +23 -0
  224. package/build/src/task/compose-language.js +33 -7
  225. package/build/src/task/compose-parser.d.ts +1 -1
  226. package/build/src/task/compose-parser.js +1 -1
  227. package/build/src/task/compose.js +2 -0
  228. package/build/src/task/index.d.ts +12 -4
  229. package/build/src/task/index.js +97 -16
  230. package/build/src/task/mutation-result.d.ts +923 -0
  231. package/build/src/task/mutation-result.js +140 -0
  232. package/build/src/task/mutation.d.ts +552 -28
  233. package/build/src/task/mutation.js +304 -97
  234. package/build/src/task/operations.d.ts +1 -4
  235. package/build/src/task/operations.js +0 -6
  236. package/build/src/task/public.d.ts +2 -0
  237. package/build/src/task/public.js +1 -0
  238. package/build/src/workspace-place.d.ts +7 -2
  239. package/build/src/workspace-place.js +34 -24
  240. package/build/src/world.d.ts +1 -0
  241. package/build/src/world.js +11 -0
  242. package/package.json +8 -6
  243. package/build/src/akuma/request-execution.d.ts +0 -8
  244. package/build/src/akuma/request-execution.js +0 -98
@@ -1,77 +1,222 @@
1
- import { type RepositoryScope } from "../protocol/operations.js";
2
- import { type IntegrationConflictMaterialized } from "../protocol/deliver.js";
3
- import { type ReviewValue } from "../protocol/review.js";
4
- import { type ContinuationReport } from "./continuation.js";
5
- import { type MutationResult } from "./mutation.js";
6
- import { type KeiyakuRefusal, type KeiyakuRetryReason } from "./refusal.js";
7
- import { actorOption } from "./input.js";
8
- import { type WorktreeHooks } from "./configuration.js";
9
- import { Repo } from "./repo.js";
10
- import { type ContractId } from "../core/facts/types.js";
11
- import type { UpstreamRequestOutcome } from "../akuma/requests.js";
1
+ import { type ErasedRequestCommand, type RequestCommand } from "../akuma/request-wire.js";
2
+ import type { AuditReport } from "../protocol/audit.js";
3
+ import type { IntegrationConflictMaterialized } from "../protocol/deliver.js";
12
4
  import type { DeliveryValue } from "./delivery.js";
13
- export type DeliveryExecutionInput = Readonly<{
14
- scope: RepositoryScope;
15
- contractId: ContractId;
16
- actor?: ReturnType<typeof actorOption>["actor"];
17
- message?: string;
18
- requireBranchesToBeUpToDate: boolean;
5
+ import type { MutationResult } from "./mutation.js";
6
+ import type { DeliveryExecutionInput, Review } from "./contract-forwarding.js";
7
+ import { z } from "zod";
8
+ type DeliveryResult = MutationResult<DeliveryValue> | IntegrationConflictMaterialized;
9
+ type ReviewResult = MutationResult<Review>;
10
+ type AuditResult = MutationResult<AuditReport>;
11
+ type ContractResult = DeliveryResult | ReviewResult | AuditResult;
12
+ type ContractRequester = NonNullable<DeliveryExecutionInput["actor"]>;
13
+ declare const auditRequestSchema: z.ZodPipe<z.ZodObject<{
14
+ repoRoot: z.ZodString;
15
+ contractId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").ContractId, string>>;
16
+ includeDirty: z.ZodBoolean;
17
+ showDiff: z.ZodBoolean;
18
+ }, z.core.$strict>, z.ZodTransform<{
19
+ repoRoot: string;
20
+ contractId: import("../core/facts/types.js").ContractId;
21
+ includeDirty: boolean;
22
+ showDiff: boolean;
23
+ action: "contract.audit";
24
+ }, {
25
+ repoRoot: string;
26
+ contractId: import("../core/facts/types.js").ContractId;
27
+ includeDirty: boolean;
28
+ showDiff: boolean;
29
+ }>>;
30
+ declare const deliverRequestSchema: z.ZodPipe<z.ZodObject<{
31
+ repoRoot: z.ZodString;
32
+ contractId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").ContractId, string>>;
33
+ includeDirty: z.ZodBoolean;
34
+ materializeConflict: z.ZodBoolean;
35
+ message: z.ZodOptional<z.ZodString>;
36
+ }, z.core.$strict>, z.ZodTransform<{
37
+ repoRoot: string;
38
+ contractId: import("../core/facts/types.js").ContractId;
19
39
  includeDirty: boolean;
20
40
  materializeConflict: boolean;
21
- signal?: AbortSignal;
22
- hooks: WorktreeHooks;
41
+ message?: string | undefined;
42
+ action: "contract.deliver";
43
+ }, {
44
+ repoRoot: string;
45
+ contractId: import("../core/facts/types.js").ContractId;
46
+ includeDirty: boolean;
47
+ materializeConflict: boolean;
48
+ message?: string | undefined;
49
+ }>>;
50
+ declare const reviewRequestSchema: z.ZodPipe<z.ZodObject<{
51
+ repoRoot: z.ZodString;
52
+ contractId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").ContractId, string>>;
53
+ verdict: z.ZodEnum<{
54
+ satisfied: "satisfied";
55
+ unsatisfied: "unsatisfied";
56
+ }>;
57
+ summary: z.ZodOptional<z.ZodString>;
58
+ }, z.core.$strict>, z.ZodTransform<{
59
+ repoRoot: string;
60
+ contractId: import("../core/facts/types.js").ContractId;
61
+ verdict: "satisfied" | "unsatisfied";
62
+ summary?: string | undefined;
63
+ action: "contract.review";
64
+ }, {
65
+ repoRoot: string;
66
+ contractId: import("../core/facts/types.js").ContractId;
67
+ verdict: "satisfied" | "unsatisfied";
68
+ summary?: string | undefined;
69
+ }>>;
70
+ export type ContractRequest = z.infer<typeof auditRequestSchema> | z.infer<typeof deliverRequestSchema> | z.infer<typeof reviewRequestSchema>;
71
+ type DeliverRequest = Extract<ContractRequest, {
72
+ action: "contract.deliver";
23
73
  }>;
24
- export type ReviewExecutionInput = Readonly<{
25
- scope: RepositoryScope;
26
- contractId: ContractId;
27
- actor?: ReturnType<typeof actorOption>["actor"];
28
- verdict: AttestationVerdict;
29
- summary?: string;
30
- hooks: WorktreeHooks;
74
+ type ReviewRequest = Extract<ContractRequest, {
75
+ action: "contract.review";
31
76
  }>;
32
- export type AttestationVerdict = "satisfied" | "unsatisfied";
33
- export type Review = ReviewValue & Readonly<{
34
- continuation?: ContinuationReport;
77
+ type AuditRequest = Extract<ContractRequest, {
78
+ action: "contract.audit";
35
79
  }>;
36
- export type ForwardedMutationReceipt<Value> = Readonly<{
37
- kind: "accepted";
38
- result: MutationResult<Value>;
39
- }> | Readonly<{
40
- kind: "refused";
41
- refusal: KeiyakuRefusal;
42
- }> | Readonly<{
43
- kind: "retry";
44
- reason: KeiyakuRetryReason;
80
+ type ContractResultFor<Action extends ContractRequest["action"]> = Action extends "contract.deliver" ? DeliveryResult : Action extends "contract.review" ? ReviewResult : AuditResult;
81
+ type ContractRequestFor<Action extends ContractRequest["action"]> = Extract<ContractRequest, {
82
+ action: Action;
45
83
  }>;
46
- export type ForwardedDeliveryReceipt = ForwardedMutationReceipt<DeliveryValue> | IntegrationConflictMaterialized;
47
- export type ForwardedReviewReceipt = ForwardedMutationReceipt<Review>;
48
- export declare function executeLocalDelivery(input: DeliveryExecutionInput): Promise<MutationResult<DeliveryValue> | IntegrationConflictMaterialized>;
49
- export declare function executeLocalReview(input: ReviewExecutionInput): Promise<MutationResult<Review>>;
50
- export declare function forwardedReceipt<Receipt>(outcome: UpstreamRequestOutcome, action: string): Receipt;
51
- export declare function requireForwarded(receipt: ForwardedDeliveryReceipt): MutationResult<DeliveryValue> | IntegrationConflictMaterialized;
52
- export declare function requireForwarded(receipt: ForwardedReviewReceipt): MutationResult<Review>;
53
- export declare function executeForwardedDeliver(input: Readonly<{
54
- repo: Repo;
55
- contractId: string;
56
- requester: string;
57
- message?: string;
58
- includeDirty: boolean;
59
- materializeConflict: boolean;
60
- requireBranchesToBeUpToDate: boolean;
61
- hooks: WorktreeHooks;
84
+ declare const contractServiceSchema: z.ZodUnion<readonly [z.ZodObject<{
85
+ kind: z.ZodLiteral<"audit-report">;
86
+ repoRoot: z.ZodString;
87
+ contractId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").ContractId, string>>;
88
+ report: z.ZodType<Readonly<{
89
+ candidate: Readonly<{
90
+ kind: "blocked";
91
+ refusal: import("./contract.js").DeliveryPreparationRefusal;
92
+ }> | Readonly<{
93
+ kind: "ready";
94
+ workspace: Readonly<{
95
+ kind: "worktree";
96
+ path: string;
97
+ }>;
98
+ identity: import("../core/facts/types.js").DeliverData;
99
+ scope: Readonly<{
100
+ filesChanged: number;
101
+ insertions: number;
102
+ deletions: number;
103
+ paths?: readonly string[];
104
+ }>;
105
+ diff?: string;
106
+ }>;
107
+ verification: Readonly<{
108
+ kind: "not-run";
109
+ }> | Readonly<{
110
+ kind: "satisfied";
111
+ passed: number;
112
+ total: number;
113
+ summary?: string;
114
+ }> | Readonly<{
115
+ kind: "unsatisfied";
116
+ passed: number;
117
+ total: number;
118
+ summary?: string;
119
+ }> | Readonly<{
120
+ kind: "stopped";
121
+ stop: import("./contract.js").VerificationStop;
122
+ }>;
123
+ target: Readonly<{
124
+ kind: "not-observed";
125
+ }> | import("../git/target-placement.js").AuditTargetAnswer;
126
+ delivery?: Readonly<{
127
+ changeId: import("../core/facts/types.js").ChangeId;
128
+ relation: "identical" | "differs";
129
+ }>;
130
+ }>, unknown, z.core.$ZodTypeInternals<Readonly<{
131
+ candidate: Readonly<{
132
+ kind: "blocked";
133
+ refusal: import("./contract.js").DeliveryPreparationRefusal;
134
+ }> | Readonly<{
135
+ kind: "ready";
136
+ workspace: Readonly<{
137
+ kind: "worktree";
138
+ path: string;
139
+ }>;
140
+ identity: import("../core/facts/types.js").DeliverData;
141
+ scope: Readonly<{
142
+ filesChanged: number;
143
+ insertions: number;
144
+ deletions: number;
145
+ paths?: readonly string[];
146
+ }>;
147
+ diff?: string;
148
+ }>;
149
+ verification: Readonly<{
150
+ kind: "not-run";
151
+ }> | Readonly<{
152
+ kind: "satisfied";
153
+ passed: number;
154
+ total: number;
155
+ summary?: string;
156
+ }> | Readonly<{
157
+ kind: "unsatisfied";
158
+ passed: number;
159
+ total: number;
160
+ summary?: string;
161
+ }> | Readonly<{
162
+ kind: "stopped";
163
+ stop: import("./contract.js").VerificationStop;
164
+ }>;
165
+ target: Readonly<{
166
+ kind: "not-observed";
167
+ }> | import("../git/target-placement.js").AuditTargetAnswer;
168
+ delivery?: Readonly<{
169
+ changeId: import("../core/facts/types.js").ChangeId;
170
+ relation: "identical" | "differs";
171
+ }>;
172
+ }>, unknown>>;
173
+ }, z.core.$strict>, z.ZodObject<{
174
+ kind: z.ZodLiteral<"accepted-reference">;
175
+ repoRoot: z.ZodString;
176
+ contractId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").ContractId, string>>;
177
+ deliveryFactId: z.ZodString;
178
+ }, z.core.$strict>, z.ZodObject<{
179
+ kind: z.ZodLiteral<"accepted-reference">;
180
+ repoRoot: z.ZodString;
181
+ contractId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").ContractId, string>>;
182
+ reviewFactId: z.ZodString;
183
+ }, z.core.$strict>]>;
184
+ export type ContractService = z.infer<typeof contractServiceSchema>;
185
+ export type ContractRequestPort = Readonly<{
186
+ audit(input: AuditRequest & Readonly<{
187
+ requester: ContractRequester;
188
+ signal: AbortSignal;
189
+ }>): Promise<Readonly<{
190
+ result: AuditResult;
191
+ auditReport?: AuditReport;
192
+ }>>;
193
+ deliver(input: DeliverRequest & Readonly<{
194
+ requester: ContractRequester;
195
+ signal: AbortSignal;
196
+ }>): Promise<Readonly<{
197
+ result: DeliveryResult;
198
+ deliveryFactId?: string;
199
+ }>>;
200
+ review(input: ReviewRequest & Readonly<{
201
+ requester: ContractRequester;
202
+ signal: AbortSignal;
203
+ }>): Promise<Readonly<{
204
+ result: ReviewResult;
205
+ reviewFactId?: string;
206
+ }>>;
207
+ }>;
208
+ type ContractExecutionContext = Readonly<{
209
+ requester: ContractRequester;
210
+ signal: AbortSignal;
211
+ upstream: ContractRequestPort;
212
+ }>;
213
+ export declare function contractRequestCommand(action: ContractRequest["action"]): RequestCommand<ContractRequest, ContractResult, ContractService, ContractService, ContractExecutionContext>;
214
+ export declare function contractRequestCommands(): Readonly<Record<"contract.audit" | "contract.deliver" | "contract.review", ErasedRequestCommand>>;
215
+ export declare function requestForwardedContractLive<Action extends ContractRequest["action"]>(input: Readonly<{
216
+ directory: string;
217
+ action: Action;
218
+ request: ContractRequestFor<Action>;
62
219
  signal?: AbortSignal;
63
- }>): Promise<Readonly<{
64
- result: ForwardedDeliveryReceipt;
65
- deliveryFactId?: string;
66
- }>>;
67
- export declare function executeForwardedReview(input: Readonly<{
68
- repo: Repo;
69
- contractId: string;
70
- requester: string;
71
- verdict: AttestationVerdict;
72
- summary?: string;
73
- hooks: WorktreeHooks;
74
- }>): Promise<Readonly<{
75
- result: ForwardedReviewReceipt;
76
- reviewFactId?: string;
77
- }>>;
220
+ }>): Promise<ContractResultFor<Action>>;
221
+ export { executeLocalDelivery, executeLocalReview, executeForwardedAudit, executeForwardedDeliver, executeForwardedReview, } from "./contract-forwarding.js";
222
+ export type { AttestationVerdict, DeliveryExecutionInput, Review, ReviewExecutionInput, } from "./contract-forwarding.js";
@@ -1,130 +1,201 @@
1
- import { decodeContractDocument } from "../body/decode.js";
2
- import { deliverOperation } from "../protocol/deliver.js";
3
- import { reviewOperation } from "../protocol/review.js";
4
- import { continueAcceptedCompletion } from "./continuation.js";
5
- import { completionInput, completeMutation } from "./mutation.js";
6
- import { forwardedMutationFailure, KeiyakuRefused, KeiyakuRetry, requireAccepted, } from "./refusal.js";
7
- import { actorOption, documentDerivation, optionalNonblank } from "./input.js";
8
- import { scopeForRepo } from "./repo.js";
9
1
  import { contractId } from "../core/facts/types.js";
10
- import { withGitDecodeChannel } from "../git/read-observation.js";
11
- function derivedDocument(state) {
12
- return documentDerivation(decodeContractDocument(state.terms.document.bytes), state.terms.gates, state.id);
2
+ import { requestBodyCommand } from "../akuma/request-rendezvous.js";
3
+ import { eraseRequestCommand } from "../akuma/request-wire.js";
4
+ import { auditReportSchema, auditResultSchema, decodeContractLiveFailure, deliveryResultSchema, encodeContractLiveFailure, reviewResultSchema, } from "./contract-forwarding-result.js";
5
+ import { isAbsolute, resolve } from "node:path";
6
+ import { z } from "zod";
7
+ const absolutePathSchema = z.string().refine((value) => isAbsolute(value) && resolve(value) === value);
8
+ const nonblankStringSchema = z.string().refine((value) => value.trim() !== "");
9
+ const contractIdSchema = z.string().transform((value, context) => {
10
+ try {
11
+ return contractId(value);
12
+ }
13
+ catch {
14
+ context.addIssue({ code: "custom", message: "expected ContractId" });
15
+ return z.NEVER;
16
+ }
17
+ });
18
+ const contractRequestBaseSchema = z.object({ repoRoot: absolutePathSchema, contractId: contractIdSchema }).strict();
19
+ const auditRequestSchema = contractRequestBaseSchema
20
+ .extend({
21
+ includeDirty: z.boolean(),
22
+ showDiff: z.boolean(),
23
+ })
24
+ .transform((request) => ({ action: "contract.audit", ...request }));
25
+ const deliverRequestSchema = contractRequestBaseSchema
26
+ .extend({ includeDirty: z.boolean(), materializeConflict: z.boolean(), message: nonblankStringSchema.optional() })
27
+ .transform((request) => ({ action: "contract.deliver", ...request }));
28
+ const reviewRequestSchema = contractRequestBaseSchema
29
+ .extend({ verdict: z.enum(["satisfied", "unsatisfied"]), summary: nonblankStringSchema.optional() })
30
+ .transform((request) => ({ action: "contract.review", ...request }));
31
+ const auditServiceSchema = z
32
+ .object({
33
+ kind: z.literal("audit-report"),
34
+ repoRoot: absolutePathSchema,
35
+ contractId: contractIdSchema,
36
+ report: auditReportSchema,
37
+ })
38
+ .strict();
39
+ const deliveryReferenceSchema = z
40
+ .object({
41
+ kind: z.literal("accepted-reference"),
42
+ repoRoot: absolutePathSchema,
43
+ contractId: contractIdSchema,
44
+ deliveryFactId: nonblankStringSchema,
45
+ })
46
+ .strict();
47
+ const reviewReferenceSchema = z
48
+ .object({
49
+ kind: z.literal("accepted-reference"),
50
+ repoRoot: absolutePathSchema,
51
+ contractId: contractIdSchema,
52
+ reviewFactId: nonblankStringSchema,
53
+ })
54
+ .strict();
55
+ const contractServiceSchema = z.union([auditServiceSchema, deliveryReferenceSchema, reviewReferenceSchema]);
56
+ function decodeContractExecutionContext(value) {
57
+ const context = contractPayload(value);
58
+ if (context === null ||
59
+ typeof context.requester !== "string" ||
60
+ context.requester.trim() === "" ||
61
+ !isAbortSignal(context.signal) ||
62
+ !isContractRequestPort(context.upstream))
63
+ throw new Error("invalid Contract execution context");
64
+ return { requester: context.requester, signal: context.signal, upstream: context.upstream };
13
65
  }
14
- function operationContext(scope, channel, contractId) {
15
- return { scope, channel, contractId, deriveDocument: derivedDocument };
66
+ function isAbortSignal(value) {
67
+ return (value !== null &&
68
+ typeof value === "object" &&
69
+ typeof value.throwIfAborted === "function");
16
70
  }
17
- export async function executeLocalDelivery(input) {
18
- return withGitDecodeChannel(input.scope, async (channel) => {
19
- const operation = operationContext(input.scope, channel, input.contractId);
20
- const outcome = await deliverOperation({
21
- ...operation,
22
- ...(input.actor === undefined ? {} : { actor: input.actor }),
23
- ...(input.message === undefined ? {} : { message: input.message }),
24
- requireBranchesToBeUpToDate: input.requireBranchesToBeUpToDate,
25
- includeDirty: input.includeDirty,
26
- materializeConflict: input.materializeConflict,
27
- ...(input.signal === undefined ? {} : { signal: input.signal }),
28
- });
29
- if (outcome.kind === "integration-conflict-materialized")
30
- return outcome;
31
- const accepted = requireAccepted(outcome);
32
- const continued = await continueAcceptedCompletion({
33
- ...operation,
34
- accepted,
35
- ...(input.actor === undefined ? {} : { actor: input.actor }),
36
- ...(input.signal === undefined ? {} : { signal: input.signal }),
37
- });
38
- return completeMutation({
39
- ...completionInput(input.scope, channel, input.contractId, (delivery) => delivery, input.hooks),
40
- accepted: continued,
41
- });
42
- });
71
+ function isContractRequestPort(value) {
72
+ const port = contractPayload(value);
73
+ return (port !== null &&
74
+ (typeof port.audit === "function" || typeof port.deliver === "function" || typeof port.review === "function"));
43
75
  }
44
- export async function executeLocalReview(input) {
45
- return withGitDecodeChannel(input.scope, async (channel) => {
46
- const operation = operationContext(input.scope, channel, input.contractId);
47
- const accepted = requireAccepted(await reviewOperation({
48
- ...operation,
49
- verdict: input.verdict,
50
- ...(input.summary === undefined ? {} : { summary: input.summary }),
51
- ...(input.actor === undefined ? {} : { actor: input.actor }),
52
- }));
53
- const continued = await continueAcceptedCompletion({
54
- ...operation,
55
- accepted,
56
- ...(input.actor === undefined ? {} : { actor: input.actor }),
57
- });
58
- return completeMutation({
59
- ...completionInput(input.scope, channel, input.contractId, (review) => review, input.hooks),
60
- accepted: continued,
61
- });
62
- });
76
+ function contractPayload(value) {
77
+ return value !== null && typeof value === "object" && !Array.isArray(value)
78
+ ? value
79
+ : null;
63
80
  }
64
- export function forwardedReceipt(outcome, action) {
65
- if (outcome.kind === "failed") {
66
- throw new Error(outcome.failure.kind === "failed"
67
- ? outcome.failure.diagnostic
68
- : `Unexpected Akuma target failure for ${action}: ${outcome.failure.id}`);
69
- }
70
- return outcome.result;
81
+ function decodeContractRequest(action, value) {
82
+ const schema = action === "contract.audit"
83
+ ? auditRequestSchema
84
+ : action === "contract.deliver"
85
+ ? deliverRequestSchema
86
+ : reviewRequestSchema;
87
+ const parsed = schema.safeParse(value);
88
+ return parsed.success ? parsed.data : null;
71
89
  }
72
- export function requireForwarded(receipt) {
73
- if (receipt.kind === "refused")
74
- throw new KeiyakuRefused(receipt.refusal);
75
- if (receipt.kind === "retry")
76
- throw new KeiyakuRetry(receipt.reason);
77
- return receipt.kind === "accepted" ? receipt.result : receipt;
90
+ function decodeContractService(action, value) {
91
+ const schema = action === "contract.audit"
92
+ ? auditServiceSchema
93
+ : action === "contract.deliver"
94
+ ? deliveryReferenceSchema
95
+ : reviewReferenceSchema;
96
+ const parsed = schema.safeParse(value);
97
+ if (!parsed.success)
98
+ throw new Error(`malformed stored Contract service evidence for ${action}`);
99
+ return parsed.data;
78
100
  }
79
- export async function executeForwardedDeliver(input) {
80
- const id = contractId(input.contractId);
81
- const actor = actorOption(input.requester).actor;
82
- const message = optionalNonblank(input.message, "deliver message");
83
- try {
84
- const result = await executeLocalDelivery({
85
- scope: scopeForRepo(input.repo),
86
- contractId: id,
87
- ...(actor === undefined ? {} : { actor }),
88
- ...(message === undefined ? {} : { message }),
89
- requireBranchesToBeUpToDate: input.requireBranchesToBeUpToDate,
90
- includeDirty: input.includeDirty,
91
- materializeConflict: input.materializeConflict,
92
- ...(input.signal === undefined ? {} : { signal: input.signal }),
93
- hooks: input.hooks,
94
- });
95
- if (!("facts" in result))
96
- return { result };
97
- const delivery = result.facts.find((fact) => fact.kind === "deliver");
98
- if (delivery === undefined)
99
- throw new Error("accepted delivery is missing its journal fact");
100
- return { result: { kind: "accepted", result }, deliveryFactId: delivery.entry };
101
+ async function executeContractRequest(request, context) {
102
+ if (request.action === "contract.audit") {
103
+ if (typeof context.upstream.audit !== "function")
104
+ throw new Error("invalid Contract execution context");
105
+ const served = await context.upstream.audit({ ...request, requester: context.requester, signal: context.signal });
106
+ if (served.auditReport === undefined)
107
+ throw new Error(`Contract ${request.action} completed without durable service evidence`);
108
+ return {
109
+ result: served.result,
110
+ service: {
111
+ kind: "audit-report",
112
+ repoRoot: request.repoRoot,
113
+ contractId: request.contractId,
114
+ report: served.auditReport,
115
+ },
116
+ };
101
117
  }
102
- catch (error) {
103
- return forwardedMutationFailure(error);
118
+ if (request.action === "contract.deliver") {
119
+ if (typeof context.upstream.deliver !== "function")
120
+ throw new Error("invalid Contract execution context");
121
+ const served = await context.upstream.deliver({ ...request, requester: context.requester, signal: context.signal });
122
+ if (served.deliveryFactId === undefined)
123
+ throw new Error(`Contract ${request.action} completed without durable service evidence`);
124
+ return {
125
+ result: served.result,
126
+ service: {
127
+ kind: "accepted-reference",
128
+ repoRoot: request.repoRoot,
129
+ contractId: request.contractId,
130
+ deliveryFactId: served.deliveryFactId,
131
+ },
132
+ };
104
133
  }
134
+ if (typeof context.upstream.review !== "function")
135
+ throw new Error("invalid Contract execution context");
136
+ const served = await context.upstream.review({ ...request, requester: context.requester, signal: context.signal });
137
+ if (served.reviewFactId === undefined)
138
+ throw new Error(`Contract ${request.action} completed without durable service evidence`);
139
+ return {
140
+ result: served.result,
141
+ service: {
142
+ kind: "accepted-reference",
143
+ repoRoot: request.repoRoot,
144
+ contractId: request.contractId,
145
+ reviewFactId: served.reviewFactId,
146
+ },
147
+ };
105
148
  }
106
- export async function executeForwardedReview(input) {
107
- const id = contractId(input.contractId);
108
- const actor = actorOption(input.requester).actor;
109
- if (input.verdict !== "satisfied" && input.verdict !== "unsatisfied") {
110
- throw new TypeError("verdict must be satisfied or unsatisfied");
111
- }
112
- const summary = optionalNonblank(input.summary, "review summary");
113
- try {
114
- const result = await executeLocalReview({
115
- scope: scopeForRepo(input.repo),
116
- contractId: id,
117
- ...(actor === undefined ? {} : { actor }),
118
- verdict: input.verdict,
119
- ...(summary === undefined ? {} : { summary }),
120
- hooks: input.hooks,
121
- });
122
- const review = result.facts.find((fact) => fact.kind === "attestation");
123
- if (review === undefined)
124
- throw new Error("accepted review is missing its journal fact");
125
- return { result: { kind: "accepted", result }, reviewFactId: review.entry };
126
- }
127
- catch (error) {
128
- return forwardedMutationFailure(error);
149
+ function decodedContractResult(action, value) {
150
+ const schema = action === "contract.audit"
151
+ ? auditResultSchema
152
+ : action === "contract.deliver"
153
+ ? deliveryResultSchema
154
+ : reviewResultSchema;
155
+ const parsed = schema.safeParse(value);
156
+ if (!parsed.success)
157
+ throw new Error(`transport integrity: Contract ${action} returned an invalid live result`);
158
+ return parsed.data;
159
+ }
160
+ export function contractRequestCommand(action) {
161
+ return {
162
+ action,
163
+ encodeRequest: (request) => {
164
+ const { action: _action, ...payload } = request;
165
+ return payload;
166
+ },
167
+ decodeRequest: (value) => decodeContractRequest(action, value),
168
+ encodeResult: (value) => value,
169
+ decodeResult: (value) => decodedContractResult(action, value),
170
+ encodeFailure: encodeContractLiveFailure,
171
+ decodeFailure: decodeContractLiveFailure,
172
+ encodeService: (service) => service,
173
+ decodeService: (service) => decodeContractService(action, service),
174
+ projectService: (service) => decodeContractService(action, service),
175
+ decodeReference: (reference) => decodeContractService(action, reference),
176
+ isPermitted: (allowed) => allowed.includes(action),
177
+ decodeExecutionContext: decodeContractExecutionContext,
178
+ execute: executeContractRequest,
179
+ };
180
+ }
181
+ export function contractRequestCommands() {
182
+ return {
183
+ "contract.audit": eraseRequestCommand(contractRequestCommand("contract.audit")),
184
+ "contract.deliver": eraseRequestCommand(contractRequestCommand("contract.deliver")),
185
+ "contract.review": eraseRequestCommand(contractRequestCommand("contract.review")),
186
+ };
187
+ }
188
+ export async function requestForwardedContractLive(input) {
189
+ const command = contractRequestCommand(input.action);
190
+ const response = await requestBodyCommand({
191
+ directory: input.directory,
192
+ command,
193
+ value: input.request,
194
+ ...(input.signal === undefined ? {} : { signal: input.signal }),
195
+ });
196
+ if (response.kind === "reference") {
197
+ throw new Error(`transport integrity: request ${response.requestId} action ${response.action} returned a durable reference without a live result`);
129
198
  }
199
+ return response.result;
130
200
  }
201
+ export { executeLocalDelivery, executeLocalReview, executeForwardedAudit, executeForwardedDeliver, executeForwardedReview, } from "./contract-forwarding.js";
@@ -59,6 +59,11 @@ type ActorOptions = Readonly<{
59
59
  actor?: string;
60
60
  hooks?: WorktreeHooks;
61
61
  }>;
62
+ export type LocalContractComposition = Readonly<{
63
+ actor?: string;
64
+ hooks?: WorktreeHooks;
65
+ requireBranchesToBeUpToDate?: boolean;
66
+ }>;
62
67
  export type AmendInput = ActorOptions & Readonly<{
63
68
  markdown?: string;
64
69
  after?: readonly ContractId[];
@@ -78,16 +83,15 @@ export type KeiyakuOfInput = Readonly<{
78
83
  repo: Repo;
79
84
  id: ContractId;
80
85
  }>;
81
- export type ReviewInput = ActorOptions & Readonly<{
86
+ export type ReviewInput = Readonly<{
82
87
  verdict: AttestationVerdict;
83
88
  summary?: string;
84
89
  }>;
85
90
  export type AbandonInput = ActorOptions & Readonly<{
86
91
  note?: string;
87
92
  }>;
88
- export type DeliverInput = ActorOptions & Readonly<{
93
+ export type DeliverInput = Readonly<{
89
94
  message?: string;
90
- requireBranchesToBeUpToDate?: boolean;
91
95
  includeDirty?: boolean;
92
96
  materializeConflict?: boolean;
93
97
  signal?: AbortSignal;