@astrosheep/keiyaku 4.5.11 → 4.5.13

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 (272) hide show
  1. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +135 -377
  2. package/build/integrations/pi/keiyaku.ts +11 -116
  3. package/build/src/akuma/akuma-errors.d.ts +1 -0
  4. package/build/src/akuma/akuma-errors.js +1 -0
  5. package/build/src/akuma/akuma-handle.d.ts +1 -0
  6. package/build/src/akuma/akuma-handle.js +6 -7
  7. package/build/src/akuma/akuma-product.d.ts +6 -8
  8. package/build/src/akuma/akuma-product.js +141 -57
  9. package/build/src/akuma/akuma.d.ts +5 -7
  10. package/build/src/akuma/akuma.js +1 -22
  11. package/build/src/akuma/archetype.d.ts +6 -5
  12. package/build/src/akuma/archetype.js +137 -38
  13. package/build/src/akuma/body.d.ts +5 -5
  14. package/build/src/akuma/body.js +223 -63
  15. package/build/src/akuma/call-input.d.ts +4 -0
  16. package/build/src/akuma/call-input.js +21 -0
  17. package/build/src/akuma/call-request.d.ts +5 -8
  18. package/build/src/akuma/call-request.js +28 -73
  19. package/build/src/akuma/fleet-execution.d.ts +26 -0
  20. package/build/src/akuma/fleet-execution.js +109 -0
  21. package/build/src/{library/fleet-result.d.ts → akuma/fleet-observation.d.ts} +13 -57
  22. package/build/src/{library/fleet-result.js → akuma/fleet-observation.js} +4 -25
  23. package/build/src/akuma/fleet-request.d.ts +122 -0
  24. package/build/src/akuma/fleet-request.js +168 -0
  25. package/build/src/akuma/heart/facts.d.ts +23 -0
  26. package/build/src/akuma/heart/facts.js +7 -0
  27. package/build/src/akuma/heart/index.d.ts +43 -4
  28. package/build/src/akuma/heart/index.js +107 -7
  29. package/build/src/akuma/heart/request-authority.d.ts +2 -0
  30. package/build/src/akuma/heart/request-authority.js +28 -3
  31. package/build/src/akuma/heart/request-rows.d.ts +2 -0
  32. package/build/src/akuma/heart/request-rows.js +24 -5
  33. package/build/src/akuma/heart/rows.d.ts +4 -1
  34. package/build/src/akuma/heart/rows.js +46 -19
  35. package/build/src/akuma/heart/schema.d.ts +1 -1
  36. package/build/src/akuma/heart/schema.js +28 -6
  37. package/build/src/akuma/heart/storage.d.ts +1 -1
  38. package/build/src/akuma/heart/tells.d.ts +29 -0
  39. package/build/src/akuma/heart/tells.js +136 -5
  40. package/build/src/akuma/heart/timeline.js +9 -3
  41. package/build/src/akuma/projection-read.js +36 -3
  42. package/build/src/akuma/projection.js +3 -4
  43. package/build/src/akuma/provider.d.ts +4 -0
  44. package/build/src/akuma/provider.js +56 -3
  45. package/build/src/akuma/providers/claude/index.js +3 -0
  46. package/build/src/akuma/providers/codex-app-server/index.js +14 -12
  47. package/build/src/akuma/providers/pi/index.js +7 -1
  48. package/build/src/akuma/publication.js +65 -49
  49. package/build/src/akuma/request-lifecycle.d.ts +5 -4
  50. package/build/src/akuma/request-lifecycle.js +29 -16
  51. package/build/src/akuma/request-rendezvous.d.ts +15 -12
  52. package/build/src/akuma/request-rendezvous.js +80 -51
  53. package/build/src/akuma/request-serve.d.ts +1 -2
  54. package/build/src/akuma/request-serve.js +94 -39
  55. package/build/src/akuma/request-wire.d.ts +57 -26
  56. package/build/src/akuma/request-wire.js +64 -25
  57. package/build/src/akuma/turn-drive.d.ts +5 -4
  58. package/build/src/akuma/turn-drive.js +27 -11
  59. package/build/src/akuma-body.d.ts +4 -6
  60. package/build/src/akuma-body.js +19 -17
  61. package/build/src/bounded-list.d.ts +8 -0
  62. package/build/src/bounded-list.js +14 -0
  63. package/build/src/cli/accepted.d.ts +1 -1
  64. package/build/src/cli/accepted.js +1 -0
  65. package/build/src/cli/commands/akuma-invoke.js +1 -25
  66. package/build/src/cli/commands/contract-help.d.ts +5 -2
  67. package/build/src/cli/commands/contract-help.js +62 -12
  68. package/build/src/cli/commands/contract-invoke.d.ts +5 -0
  69. package/build/src/cli/commands/contract-invoke.js +26 -1
  70. package/build/src/cli/commands/contract.js +50 -18
  71. package/build/src/cli/commands/task-invoke.js +10 -2
  72. package/build/src/cli/commands/task-query.js +3 -4
  73. package/build/src/cli/coordinates.d.ts +13 -0
  74. package/build/src/cli/coordinates.js +38 -24
  75. package/build/src/cli/draft.d.ts +1 -1
  76. package/build/src/cli/invoke.js +14 -1
  77. package/build/src/cli/render/akuma-activity.d.ts +0 -1
  78. package/build/src/cli/render/akuma-activity.js +5 -38
  79. package/build/src/cli/render/akuma.js +4 -1
  80. package/build/src/cli/render/audit.js +4 -1
  81. package/build/src/cli/render/catalog.js +13 -39
  82. package/build/src/cli/render/contract.js +4 -14
  83. package/build/src/cli/render/kanshi-akuma.js +3 -8
  84. package/build/src/cli/render/kanshi.js +8 -34
  85. package/build/src/cli/render/nuke.js +7 -3
  86. package/build/src/cli/render/receipt.d.ts +1 -0
  87. package/build/src/cli/render/receipt.js +8 -0
  88. package/build/src/cli/render/refusal.js +4 -3
  89. package/build/src/cli/render/task.js +4 -37
  90. package/build/src/cli/render/terminal.d.ts +2 -6
  91. package/build/src/cli/render/terminal.js +4 -9
  92. package/build/src/cli/result.d.ts +2 -1
  93. package/build/src/contract-guidance.js +13 -3
  94. package/build/src/contract-worktree.d.ts +1 -0
  95. package/build/src/contract-worktree.js +26 -2
  96. package/build/src/core/facts/codec.d.ts +2 -1
  97. package/build/src/core/facts/codec.js +3 -0
  98. package/build/src/core/facts/gate.d.ts +2 -1
  99. package/build/src/core/facts/gate.js +63 -0
  100. package/build/src/core/verbs/abandon.d.ts +2 -1
  101. package/build/src/core/verbs/abandon.js +16 -0
  102. package/build/src/core/verbs/amend.d.ts +2 -1
  103. package/build/src/core/verbs/amend.js +20 -0
  104. package/build/src/core/verbs/arc.d.ts +2 -1
  105. package/build/src/core/verbs/arc.js +16 -0
  106. package/build/src/core/verbs/attestation.d.ts +2 -1
  107. package/build/src/core/verbs/attestation.js +16 -0
  108. package/build/src/core/verbs/bind.d.ts +2 -1
  109. package/build/src/core/verbs/bind.js +16 -0
  110. package/build/src/core/verbs/deliver.d.ts +2 -1
  111. package/build/src/core/verbs/deliver.js +16 -0
  112. package/build/src/core/verbs/placement.d.ts +2 -1
  113. package/build/src/core/verbs/placement.js +58 -1
  114. package/build/src/dispatch/association.d.ts +13 -0
  115. package/build/src/dispatch/association.js +20 -0
  116. package/build/src/dispatch/index.d.ts +6 -0
  117. package/build/src/dispatch/index.js +27 -3
  118. package/build/src/git/hooks.d.ts +9 -1
  119. package/build/src/git/hooks.js +79 -1
  120. package/build/src/git/nuke.d.ts +2 -1
  121. package/build/src/git/nuke.js +6 -11
  122. package/build/src/git/private-state-seat.d.ts +26 -1
  123. package/build/src/git/private-state-seat.js +78 -13
  124. package/build/src/git/process.d.ts +2 -0
  125. package/build/src/git/reconcile.d.ts +1 -2
  126. package/build/src/git/reconcile.js +0 -6
  127. package/build/src/git/repository.d.ts +0 -2
  128. package/build/src/git/repository.js +27 -25
  129. package/build/src/git/result-codec.d.ts +29 -0
  130. package/build/src/git/result-codec.js +306 -0
  131. package/build/src/git/target-placement.js +2 -8
  132. package/build/src/git/workspace.d.ts +2 -0
  133. package/build/src/git/workspace.js +4 -0
  134. package/build/src/index.d.ts +1 -0
  135. package/build/src/kanshi/fleet.js +1 -1
  136. package/build/src/kanshi/read.js +55 -28
  137. package/build/src/kanshi/report.d.ts +4 -3
  138. package/build/src/kanshi/select.js +14 -1
  139. package/build/src/library/address.d.ts +1 -0
  140. package/build/src/library/address.js +4 -7
  141. package/build/src/library/akuma-creation.d.ts +5 -3
  142. package/build/src/library/akuma-creation.js +90 -33
  143. package/build/src/library/audit.js +2 -1
  144. package/build/src/library/catalog.d.ts +10 -2
  145. package/build/src/library/catalog.js +65 -25
  146. package/build/src/library/composition.d.ts +1 -0
  147. package/build/src/library/composition.js +1 -0
  148. package/build/src/library/configuration.d.ts +4 -21
  149. package/build/src/library/configuration.js +2 -158
  150. package/build/src/library/continuation.d.ts +20 -1
  151. package/build/src/library/continuation.js +36 -0
  152. package/build/src/library/contract-bind.d.ts +1 -0
  153. package/build/src/library/contract-bind.js +16 -5
  154. package/build/src/library/contract-forwarding.d.ts +2 -2
  155. package/build/src/library/contract-forwarding.js +18 -4
  156. package/build/src/library/contract-handle.js +4 -3
  157. package/build/src/library/contract-operations.d.ts +5 -9
  158. package/build/src/library/contract-operations.js +34 -47
  159. package/build/src/library/contract.d.ts +11 -2
  160. package/build/src/library/contract.js +21 -1
  161. package/build/src/library/delivery.d.ts +4 -1
  162. package/build/src/library/delivery.js +47 -0
  163. package/build/src/library/fleet.d.ts +4 -136
  164. package/build/src/library/fleet.js +31 -315
  165. package/build/src/library/keiyaku.d.ts +7 -3
  166. package/build/src/library/keiyaku.js +1 -0
  167. package/build/src/library/mutation.d.ts +431 -3
  168. package/build/src/library/mutation.js +192 -19
  169. package/build/src/library/nuke.d.ts +7 -1
  170. package/build/src/library/nuke.js +18 -4
  171. package/build/src/library/reconcile.d.ts +14 -0
  172. package/build/src/library/reconcile.js +22 -8
  173. package/build/src/library/refusal.d.ts +9 -1
  174. package/build/src/library/refusal.js +76 -0
  175. package/build/src/library/region.d.ts +0 -8
  176. package/build/src/library/region.js +1 -29
  177. package/build/src/library/result-codec.d.ts +2 -0
  178. package/build/src/library/result-codec.js +12 -0
  179. package/build/src/markdown/lex.js +9 -2
  180. package/build/src/markdown/types.d.ts +2 -1
  181. package/build/src/markdown/types.js +3 -1
  182. package/build/src/plugin/akuma-signals.d.ts +12 -0
  183. package/build/src/plugin/akuma-signals.js +14 -0
  184. package/build/src/plugin/public.d.ts +51 -0
  185. package/build/src/plugin/public.js +1 -0
  186. package/build/src/plugin/runtime.d.ts +14 -0
  187. package/build/src/plugin/runtime.js +357 -0
  188. package/build/src/protocol/amend.js +3 -3
  189. package/build/src/protocol/attempt.d.ts +2 -1
  190. package/build/src/protocol/attempt.js +1 -1
  191. package/build/src/protocol/audit.d.ts +1 -1
  192. package/build/src/protocol/audit.js +1 -1
  193. package/build/src/protocol/bind.d.ts +3 -1
  194. package/build/src/protocol/bind.js +26 -0
  195. package/build/src/protocol/completion.js +0 -1
  196. package/build/src/protocol/deliver.d.ts +1 -1
  197. package/build/src/protocol/deliver.js +136 -57
  198. package/build/src/protocol/intent.d.ts +0 -1
  199. package/build/src/protocol/intent.js +0 -1
  200. package/build/src/protocol/operations.d.ts +9 -2
  201. package/build/src/protocol/operations.js +16 -1
  202. package/build/src/protocol/outcome.d.ts +3 -0
  203. package/build/src/protocol/outcome.js +17 -1
  204. package/build/src/protocol/placement.js +10 -3
  205. package/build/src/protocol/read/status.d.ts +8 -0
  206. package/build/src/protocol/read/status.js +49 -0
  207. package/build/src/protocol/reintegrate.js +10 -3
  208. package/build/src/protocol/result-codec.d.ts +22 -0
  209. package/build/src/protocol/result-codec.js +442 -0
  210. package/build/src/protocol/review.d.ts +1 -1
  211. package/build/src/protocol/review.js +81 -46
  212. package/build/src/protocol/run.d.ts +22 -2
  213. package/build/src/protocol/run.js +119 -29
  214. package/build/src/runtime/proc/lifecycle.js +1 -1
  215. package/build/src/runtime/proc/line-rpc.d.ts +7 -1
  216. package/build/src/runtime/proc/line-rpc.js +49 -9
  217. package/build/src/runtime/proc/run.d.ts +0 -1
  218. package/build/src/runtime/proc/run.js +1 -11
  219. package/build/src/runtime/proc/termination.d.ts +1 -0
  220. package/build/src/runtime/proc/termination.js +63 -18
  221. package/build/src/runtime/proc/windows-launch.exe +0 -0
  222. package/build/src/settings.d.ts +10 -0
  223. package/build/src/settings.js +88 -2
  224. package/build/src/settlement/result-codec.d.ts +2 -0
  225. package/build/src/settlement/result-codec.js +56 -0
  226. package/build/src/settlement/settle.d.ts +5 -12
  227. package/build/src/settlement/settle.js +60 -55
  228. package/build/src/task/board.d.ts +3 -0
  229. package/build/src/task/board.js +22 -4
  230. package/build/src/task/catalog.d.ts +13 -2
  231. package/build/src/task/catalog.js +59 -5
  232. package/build/src/task/compose.d.ts +4 -2
  233. package/build/src/task/compose.js +56 -30
  234. package/build/src/task/created-observation.d.ts +39 -0
  235. package/build/src/task/created-observation.js +26 -0
  236. package/build/src/task/identity.d.ts +6 -0
  237. package/build/src/task/identity.js +48 -7
  238. package/build/src/task/index.d.ts +4 -3
  239. package/build/src/task/index.js +19 -16
  240. package/build/src/task/input.d.ts +3 -1
  241. package/build/src/task/input.js +7 -4
  242. package/build/src/task/lifecycle-operations.d.ts +6 -0
  243. package/build/src/task/lifecycle-operations.js +116 -0
  244. package/build/src/task/mutation-result.d.ts +762 -20
  245. package/build/src/task/mutation-result.js +34 -9
  246. package/build/src/task/mutation.d.ts +4 -9
  247. package/build/src/task/mutation.js +17 -52
  248. package/build/src/task/operation-types.d.ts +114 -0
  249. package/build/src/task/operation-types.js +1 -0
  250. package/build/src/task/operations.d.ts +6 -113
  251. package/build/src/task/operations.js +75 -117
  252. package/build/src/task/query.d.ts +8 -11
  253. package/build/src/task/query.js +7 -14
  254. package/build/src/task/store.d.ts +11 -1
  255. package/build/src/task/store.js +169 -55
  256. package/build/src/task/view.d.ts +4 -0
  257. package/build/src/task/view.js +7 -0
  258. package/build/src/verification/declaration.d.ts +1 -0
  259. package/build/src/verification/declaration.js +18 -1
  260. package/build/src/verification/execution.d.ts +0 -1
  261. package/build/src/verification/execution.js +5 -5
  262. package/build/src/world.d.ts +0 -2
  263. package/build/src/world.js +3 -7
  264. package/package.json +17 -5
  265. package/build/src/cli/square-edge.d.ts +0 -7
  266. package/build/src/cli/square-edge.js +0 -159
  267. package/build/src/git/ref-migration.d.ts +0 -22
  268. package/build/src/git/ref-migration.js +0 -55
  269. package/build/src/library/contract-forwarding-reconciliation-result.d.ts +0 -102
  270. package/build/src/library/contract-forwarding-reconciliation-result.js +0 -92
  271. package/build/src/library/contract-forwarding-result.d.ts +0 -4270
  272. package/build/src/library/contract-forwarding-result.js +0 -521
@@ -0,0 +1,442 @@
1
+ import { changeId, contractId, entryUlid, snapshotId } from "../core/facts/types.js";
2
+ import { decodeDeliverData } from "../core/facts/codec.js";
3
+ import { decodeAbandonRefusal } from "../core/verbs/abandon.js";
4
+ import { decodeAmendRefusal } from "../core/verbs/amend.js";
5
+ import { decodeArcRefusal } from "../core/verbs/arc.js";
6
+ import { decodeAttestationRefusal } from "../core/verbs/attestation.js";
7
+ import { decodeBindRefusal } from "../core/verbs/bind.js";
8
+ import { decodeDeliverRefusal } from "../core/verbs/deliver.js";
9
+ import { decodePlacementRefusal } from "../core/verbs/placement.js";
10
+ import { decodeAuditTargetAnswer, decodeCheckoutNotFollowableRefusal, decodeDirtyWorkspaceRefusal, decodeHookFailure, decodeIntegrationPreparationRefusal, decodePublicationFailed, decodeUnmergedPathsRefusal, decodeWorktreeLeak, decodeWorktreeMissingRefusal, decodeWorktreeWorkspace, decodeWorkspaceDirtyDelta, } from "../git/result-codec.js";
11
+ import { decodeVerificationDeclarationRefusal } from "../verification/declaration.js";
12
+ import { decodeForkSourceMovedRefusal, decodeTargetInputRefusal } from "./bind.js";
13
+ function fail() {
14
+ throw new Error("malformed protocol result");
15
+ }
16
+ function record(value, required, optional = []) {
17
+ if (value === null || typeof value !== "object" || Array.isArray(value))
18
+ fail();
19
+ const object = value;
20
+ const allowed = new Set([...required, ...optional]);
21
+ for (const key of Object.keys(object))
22
+ if (!allowed.has(key))
23
+ fail();
24
+ for (const key of required)
25
+ if (!(key in object))
26
+ fail();
27
+ return object;
28
+ }
29
+ function nonblank(value) {
30
+ if (typeof value !== "string" || value.trim() === "")
31
+ fail();
32
+ return value;
33
+ }
34
+ function integer(value) {
35
+ if (typeof value !== "number" || !Number.isInteger(value))
36
+ fail();
37
+ return value;
38
+ }
39
+ function boolean(value) {
40
+ if (typeof value !== "boolean")
41
+ fail();
42
+ return value;
43
+ }
44
+ function strings(value) {
45
+ if (!Array.isArray(value))
46
+ fail();
47
+ return value.map(nonblank);
48
+ }
49
+ function decodeContractId(value) {
50
+ try {
51
+ return contractId(nonblank(value));
52
+ }
53
+ catch {
54
+ fail();
55
+ }
56
+ }
57
+ function decodeSnapshotId(value) {
58
+ try {
59
+ return snapshotId(nonblank(value));
60
+ }
61
+ catch {
62
+ fail();
63
+ }
64
+ }
65
+ function first(value, decoders) {
66
+ for (const decode of decoders) {
67
+ try {
68
+ return decode(value);
69
+ }
70
+ catch {
71
+ continue;
72
+ }
73
+ }
74
+ fail();
75
+ }
76
+ export function decodeProtocolTerminal(value) {
77
+ const object = record(value, ["kind"], ["diagnostic"]);
78
+ if (object.kind === "exhausted" || object.kind === "collision") {
79
+ if ("diagnostic" in object)
80
+ fail();
81
+ return { kind: object.kind };
82
+ }
83
+ return decodePublicationFailed(value);
84
+ }
85
+ export function decodeMergeStatePresentRefusal(value) {
86
+ const object = record(value, ["kind", "contractId", "workspace"]);
87
+ if (object.kind !== "merge-state-present")
88
+ fail();
89
+ return {
90
+ kind: "merge-state-present",
91
+ contractId: decodeContractId(object.contractId),
92
+ workspace: decodeWorktreeWorkspace(object.workspace),
93
+ };
94
+ }
95
+ export function decodeDeliverConflictRefusal(value) {
96
+ const object = record(value, ["kind", "contractId", "reason", "targetHead", "conflictPaths", "recovery"]);
97
+ if (object.kind !== "integration-failed" || object.reason !== "conflict")
98
+ fail();
99
+ const recovery = record(object.recovery, ["materialize", "continue"]);
100
+ if (recovery.materialize !== "deliver --materialize-conflict --include-dirty")
101
+ fail();
102
+ if (recovery.continue !== "deliver --include-dirty")
103
+ fail();
104
+ return {
105
+ kind: "integration-failed",
106
+ contractId: decodeContractId(object.contractId),
107
+ reason: "conflict",
108
+ targetHead: decodeSnapshotId(object.targetHead),
109
+ conflictPaths: strings(object.conflictPaths),
110
+ recovery: {
111
+ materialize: "deliver --materialize-conflict --include-dirty",
112
+ continue: "deliver --include-dirty",
113
+ },
114
+ };
115
+ }
116
+ function decodeTargetMissingRefusal(value) {
117
+ const object = record(value, ["kind", "contractId"]);
118
+ if (object.kind !== "target-missing")
119
+ fail();
120
+ return { kind: "target-missing", contractId: decodeContractId(object.contractId) };
121
+ }
122
+ export function decodeDeliveryPreparationRefusal(value) {
123
+ return first(value, [
124
+ decodeTargetMissingRefusal,
125
+ decodeWorktreeMissingRefusal,
126
+ decodeDirtyWorkspaceRefusal,
127
+ decodeUnmergedPathsRefusal,
128
+ decodeIntegrationPreparationRefusal,
129
+ decodeMergeStatePresentRefusal,
130
+ decodeCheckoutNotFollowableRefusal,
131
+ ]);
132
+ }
133
+ export function decodeIntentRefusal(value) {
134
+ return first(value, [
135
+ decodeAbandonRefusal,
136
+ decodeAmendRefusal,
137
+ decodeArcRefusal,
138
+ decodeBindRefusal,
139
+ decodeForkSourceMovedRefusal,
140
+ decodeDeliverRefusal,
141
+ decodeDeliveryPreparationRefusal,
142
+ decodeDeliverConflictRefusal,
143
+ decodePlacementRefusal,
144
+ decodeAttestationRefusal,
145
+ decodeTargetInputRefusal,
146
+ decodeVerificationDeclarationRefusal,
147
+ ]);
148
+ }
149
+ export function decodeVerificationRuntimeStop(value) {
150
+ const object = record(value, ["failure"], ["diagnostic", "command", "detail"]);
151
+ if (object.failure === "unknown-exit" || object.failure === "cancelled") {
152
+ if ("diagnostic" in object || "command" in object || "detail" in object)
153
+ fail();
154
+ return { failure: object.failure };
155
+ }
156
+ if (object.failure === "candidate-unavailable" || object.failure === "spawn-error") {
157
+ if ("command" in object || "detail" in object)
158
+ fail();
159
+ return { failure: object.failure, diagnostic: nonblank(object.diagnostic) };
160
+ }
161
+ if (object.failure !== "environment-failure")
162
+ fail();
163
+ if ("command" in object || "detail" in object) {
164
+ if ("diagnostic" in object)
165
+ fail();
166
+ return {
167
+ failure: "environment-failure",
168
+ command: integer(object.command),
169
+ detail: decodeHookFailure(object.detail),
170
+ };
171
+ }
172
+ return { failure: "environment-failure", diagnostic: nonblank(object.diagnostic) };
173
+ }
174
+ function decodeVerificationStepRefusal(value) {
175
+ const object = record(value, ["refusal"]);
176
+ return {
177
+ refusal: first(object.refusal, [decodeAttestationRefusal, decodeVerificationDeclarationRefusal]),
178
+ };
179
+ }
180
+ function decodeVerificationStepRetry(value) {
181
+ const object = record(value, ["retry"]);
182
+ return { retry: decodeProtocolTerminal(object.retry) };
183
+ }
184
+ export function decodeVerificationStop(value) {
185
+ return first(value, [decodeVerificationStepRefusal, decodeVerificationStepRetry, decodeVerificationRuntimeStop]);
186
+ }
187
+ export function decodeVerificationReuse(value) {
188
+ const object = record(value, ["entry", "verdict"], ["summary"]);
189
+ if (object.verdict !== "satisfied" && object.verdict !== "unsatisfied")
190
+ fail();
191
+ let entry;
192
+ try {
193
+ entry = entryUlid(nonblank(object.entry));
194
+ }
195
+ catch {
196
+ fail();
197
+ }
198
+ return {
199
+ entry,
200
+ verdict: object.verdict,
201
+ ...(object.summary === undefined ? {} : { summary: typeof object.summary === "string" ? object.summary : fail() }),
202
+ };
203
+ }
204
+ function decodePlacementStepRefusal(value) {
205
+ return first(value, [
206
+ decodePlacementRefusal,
207
+ decodeCheckoutNotFollowableRefusal,
208
+ decodeIntegrationPreparationRefusal,
209
+ decodeTargetMissingRefusal,
210
+ ]);
211
+ }
212
+ function decodePlacementRefusalStop(value) {
213
+ const object = record(value, ["refusal"]);
214
+ return { refusal: decodePlacementStepRefusal(object.refusal) };
215
+ }
216
+ function decodePlacementRetryStop(value) {
217
+ const object = record(value, ["retry"]);
218
+ return { retry: decodeProtocolTerminal(object.retry) };
219
+ }
220
+ function decodeTargetPlacementFailedStop(value) {
221
+ const object = record(value, ["failure", "diagnostic"]);
222
+ if (object.failure !== "target-placement-failed")
223
+ fail();
224
+ return { failure: "target-placement-failed", diagnostic: nonblank(object.diagnostic) };
225
+ }
226
+ function decodeTargetMovedWithAttemptsStop(value) {
227
+ const object = record(value, [
228
+ "failure",
229
+ "contractId",
230
+ "target",
231
+ "integratedAt",
232
+ "observed",
233
+ "attempts",
234
+ "observedTreeEqualsCandidate",
235
+ ]);
236
+ if (object.failure !== "target-moved")
237
+ fail();
238
+ return {
239
+ failure: "target-moved",
240
+ contractId: decodeContractId(object.contractId),
241
+ target: nonblank(object.target),
242
+ integratedAt: decodeSnapshotId(object.integratedAt),
243
+ observed: object.observed === null ? null : decodeSnapshotId(object.observed),
244
+ attempts: integer(object.attempts),
245
+ observedTreeEqualsCandidate: boolean(object.observedTreeEqualsCandidate),
246
+ };
247
+ }
248
+ function decodeTargetMovedExpectedStop(value) {
249
+ const object = record(value, [
250
+ "failure",
251
+ "contractId",
252
+ "target",
253
+ "expected",
254
+ "observed",
255
+ "observedTreeEqualsCandidate",
256
+ ]);
257
+ if (object.failure !== "target-moved")
258
+ fail();
259
+ return {
260
+ failure: "target-moved",
261
+ contractId: decodeContractId(object.contractId),
262
+ target: nonblank(object.target),
263
+ expected: decodeSnapshotId(object.expected),
264
+ observed: object.observed === null ? null : decodeSnapshotId(object.observed),
265
+ observedTreeEqualsCandidate: boolean(object.observedTreeEqualsCandidate),
266
+ };
267
+ }
268
+ export function decodePlacementStop(value) {
269
+ return first(value, [
270
+ decodePlacementRefusalStop,
271
+ decodePlacementRetryStop,
272
+ decodeTargetPlacementFailedStop,
273
+ decodeTargetMovedWithAttemptsStop,
274
+ decodeTargetMovedExpectedStop,
275
+ ]);
276
+ }
277
+ export function decodeVerificationCleanupFailure(value) {
278
+ const object = record(value, ["phase", "command", "detail"]);
279
+ if (object.phase !== "destroy")
280
+ fail();
281
+ return { phase: "destroy", command: integer(object.command), detail: decodeHookFailure(object.detail) };
282
+ }
283
+ export function decodeCandidateCompletion(value) {
284
+ const object = record(value, ["integration"], ["verification"]);
285
+ const completion = {
286
+ integration: decodeSnapshotId(object.integration),
287
+ ...(object.verification === undefined
288
+ ? {}
289
+ : {
290
+ verification: (() => {
291
+ const verification = record(object.verification, ["mode", "verdict"]);
292
+ if (verification.mode !== "ran" && verification.mode !== "reused")
293
+ fail();
294
+ if (verification.verdict !== "satisfied" && verification.verdict !== "unsatisfied")
295
+ fail();
296
+ return { mode: verification.mode, verdict: verification.verdict };
297
+ })(),
298
+ }),
299
+ };
300
+ return completion;
301
+ }
302
+ export function decodeCompletionEvidence(value) {
303
+ const object = record(value, [], ["completion", "verification", "verificationReuse", "verificationSummary", "placement", "cleanup", "leak"]);
304
+ return {
305
+ ...(object.completion === undefined ? {} : { completion: decodeCandidateCompletion(object.completion) }),
306
+ ...(object.verification === undefined ? {} : { verification: decodeVerificationStop(object.verification) }),
307
+ ...(object.verificationReuse === undefined
308
+ ? {}
309
+ : { verificationReuse: decodeVerificationReuse(object.verificationReuse) }),
310
+ ...(object.verificationSummary === undefined ? {} : { verificationSummary: nonblank(object.verificationSummary) }),
311
+ ...(object.placement === undefined ? {} : { placement: decodePlacementStop(object.placement) }),
312
+ ...(object.cleanup === undefined ? {} : { cleanup: decodeVerificationCleanupFailure(object.cleanup) }),
313
+ ...(object.leak === undefined ? {} : { leak: decodeWorktreeLeak(object.leak) }),
314
+ };
315
+ }
316
+ export function decodeMaterializedConflict(value) {
317
+ const object = record(value, ["kind", "targetHead", "conflictPaths", "workspace"]);
318
+ if (object.kind !== "integration-conflict-materialized")
319
+ fail();
320
+ return {
321
+ kind: "integration-conflict-materialized",
322
+ targetHead: decodeSnapshotId(object.targetHead),
323
+ conflictPaths: strings(object.conflictPaths),
324
+ workspace: decodeWorktreeWorkspace(object.workspace),
325
+ };
326
+ }
327
+ function decodeAuditReadyCandidate(value) {
328
+ const object = record(value, ["kind", "workspace", "identity", "scope"], ["diff"]);
329
+ if (object.kind !== "ready")
330
+ fail();
331
+ const scope = record(object.scope, ["filesChanged", "insertions", "deletions"], ["paths"]);
332
+ return {
333
+ kind: "ready",
334
+ workspace: decodeWorktreeWorkspace(object.workspace),
335
+ identity: decodeDeliverData(object.identity),
336
+ scope: {
337
+ filesChanged: integer(scope.filesChanged),
338
+ insertions: integer(scope.insertions),
339
+ deletions: integer(scope.deletions),
340
+ ...(scope.paths === undefined
341
+ ? {}
342
+ : {
343
+ paths: Array.isArray(scope.paths)
344
+ ? scope.paths.map((path) => (typeof path === "string" ? path : fail()))
345
+ : fail(),
346
+ }),
347
+ },
348
+ ...(object.diff === undefined ? {} : { diff: typeof object.diff === "string" ? object.diff : fail() }),
349
+ };
350
+ }
351
+ function decodeAuditBlockedCandidate(value) {
352
+ const object = record(value, ["kind", "refusal"]);
353
+ if (object.kind !== "blocked")
354
+ fail();
355
+ return { kind: "blocked", refusal: decodeDeliveryPreparationRefusal(object.refusal) };
356
+ }
357
+ function decodeAuditVerification(value) {
358
+ return first(value, [
359
+ (input) => {
360
+ const object = record(input, ["kind"]);
361
+ if (object.kind !== "not-run")
362
+ fail();
363
+ return { kind: "not-run" };
364
+ },
365
+ (input) => {
366
+ const object = record(input, ["kind", "stop"]);
367
+ if (object.kind !== "stopped")
368
+ fail();
369
+ return { kind: "stopped", stop: decodeVerificationStop(object.stop) };
370
+ },
371
+ (input) => {
372
+ const object = record(input, ["kind", "passed", "total"], ["summary"]);
373
+ if (object.kind !== "satisfied" && object.kind !== "unsatisfied")
374
+ fail();
375
+ return {
376
+ kind: object.kind,
377
+ passed: typeof object.passed === "number" ? object.passed : fail(),
378
+ total: typeof object.total === "number" ? object.total : fail(),
379
+ ...(object.summary === undefined
380
+ ? {}
381
+ : { summary: typeof object.summary === "string" ? object.summary : fail() }),
382
+ };
383
+ },
384
+ ]);
385
+ }
386
+ function decodeNotObservedAuditTarget(value) {
387
+ const object = record(value, ["kind"]);
388
+ if (object.kind !== "not-observed")
389
+ fail();
390
+ return { kind: "not-observed" };
391
+ }
392
+ function decodeAuditTarget(value) {
393
+ return first(value, [decodeNotObservedAuditTarget, decodeAuditTargetAnswer]);
394
+ }
395
+ export function decodeAuditReport(value) {
396
+ const object = record(value, ["candidate", "verification", "target"], ["delivery"]);
397
+ return {
398
+ candidate: first(object.candidate, [decodeAuditBlockedCandidate, decodeAuditReadyCandidate]),
399
+ verification: decodeAuditVerification(object.verification),
400
+ target: decodeAuditTarget(object.target),
401
+ ...(object.delivery === undefined
402
+ ? {}
403
+ : {
404
+ delivery: (() => {
405
+ const delivery = record(object.delivery, ["changeId", "relation"]);
406
+ if (delivery.relation !== "identical" && delivery.relation !== "differs")
407
+ fail();
408
+ try {
409
+ return { changeId: changeId(nonblank(delivery.changeId)), relation: delivery.relation };
410
+ }
411
+ catch {
412
+ fail();
413
+ }
414
+ })(),
415
+ }),
416
+ };
417
+ }
418
+ export function decodeReviewValue(value) {
419
+ const object = record(value, [], [
420
+ "completion",
421
+ "verification",
422
+ "verificationReuse",
423
+ "verificationSummary",
424
+ "placement",
425
+ "cleanup",
426
+ "leak",
427
+ "workspace",
428
+ ]);
429
+ const evidence = decodeCompletionEvidence({
430
+ ...(object.completion === undefined ? {} : { completion: object.completion }),
431
+ ...(object.verification === undefined ? {} : { verification: object.verification }),
432
+ ...(object.verificationReuse === undefined ? {} : { verificationReuse: object.verificationReuse }),
433
+ ...(object.verificationSummary === undefined ? {} : { verificationSummary: object.verificationSummary }),
434
+ ...(object.placement === undefined ? {} : { placement: object.placement }),
435
+ ...(object.cleanup === undefined ? {} : { cleanup: object.cleanup }),
436
+ ...(object.leak === undefined ? {} : { leak: object.leak }),
437
+ });
438
+ return {
439
+ ...evidence,
440
+ ...(object.workspace === undefined ? {} : { workspace: decodeWorkspaceDirtyDelta(object.workspace) }),
441
+ };
442
+ }
@@ -16,6 +16,7 @@ type ReviewOperationInput = MutationOperationInput & Readonly<{
16
16
  export type ReviewValue = CompletionEvidence & Readonly<{
17
17
  workspace?: WorkspaceDirtyDelta;
18
18
  }>;
19
+ export { decodeReviewValue } from "./result-codec.js";
19
20
  export declare function prepareReview(repository: RepositoryScope, stage: Readonly<{
20
21
  contractId: import("../core/facts/types.js").ContractId;
21
22
  coordinates: ContractState["coordinates"];
@@ -30,4 +31,3 @@ export declare function prepareReview(repository: RepositoryScope, stage: Readon
30
31
  refusal: ReviewPreparationRefusal;
31
32
  }>;
32
33
  export declare function reviewOperation(input: ReviewOperationInput): Promise<IntentOutcome<ReviewValue, ReviewRefusal>>;
33
- export {};
@@ -1,7 +1,7 @@
1
1
  import { worktreeChangeId } from "../git/integration.js";
2
2
  import { captureTender, dirtyTenderDelta, dirtyTenderRefusal, } from "../git/tender.js";
3
3
  import { observeContractsForAdmissionAt } from "../git/observe.js";
4
- import { withPrivateStatePublicationSeat } from "../git/private-state-seat.js";
4
+ import { matchingPrivateRootObservation, privateStateSeatAttempt, sameSpeculativeWorktreeInput, } from "./run.js";
5
5
  import { dependencyKeySet } from "../core/subject.js";
6
6
  import { contractState } from "../core/facts/observation.js";
7
7
  import { gate } from "../core/facts/types.js";
@@ -10,8 +10,9 @@ import { admitDecidedOffer, mintAttempts } from "./attempt.js";
10
10
  import { admitted } from "./outcome.js";
11
11
  import { completeCandidate } from "./completion.js";
12
12
  import { appointmentFor, readPlaceRegister } from "../workspace-place.js";
13
- import { timestamp } from "./operations.js";
13
+ import { attemptDecisionWithSeatClose, timestamp } from "./operations.js";
14
14
  const REVIEWED = gate("reviewed");
15
+ export { decodeReviewValue } from "./result-codec.js";
15
16
  async function captureReviewableWorktree(repository, stage) {
16
17
  const appointed = stage.coordinates.workspace === "worktree"
17
18
  ? appointmentFor(await readPlaceRegister(repository), stage.contractId)
@@ -53,49 +54,66 @@ function reviewValue(value, completion = {}) {
53
54
  ...completion,
54
55
  };
55
56
  }
56
- async function reviewAttempt(input, attempt) {
57
- return await withPrivateStatePublicationSeat(input.scope, async (seat) => await reviewAttemptInPrivateStateSeat(input, attempt, seat));
57
+ function preparedReviewCapture(input, state, prepared) {
58
+ return {
59
+ kind: "prepared",
60
+ data: {
61
+ gate: REVIEWED,
62
+ subject: dependencyKeySet([
63
+ { kind: "document", value: state.terms.document.key },
64
+ { kind: "change", value: prepared.data.changeId },
65
+ ]),
66
+ verdict: input.verdict,
67
+ ...(input.summary === undefined ? {} : { summary: input.summary }),
68
+ },
69
+ };
58
70
  }
59
- async function reviewAttemptInPrivateStateSeat(input, attempt, seat) {
60
- const decisionObservation = await observeContractsForAdmissionAt(input.scope, input.channel, [input.contractId]);
61
- const state = contractState(decisionObservation.decision, input.contractId);
62
- let preparation;
63
- let workspace;
64
- let tender;
65
- if (state !== null) {
66
- const prepared = await captureReviewableWorktree(input.scope, {
67
- contractId: state.id,
68
- coordinates: state.coordinates,
69
- });
70
- preparation =
71
- prepared.kind === "refused"
72
- ? { kind: "refused", refusal: prepared.refusal }
73
- : {
74
- kind: "prepared",
75
- data: {
76
- gate: REVIEWED,
77
- subject: dependencyKeySet([
78
- { kind: "document", value: state.terms.document.key },
79
- { kind: "change", value: prepared.data.changeId },
80
- ]),
81
- verdict: input.verdict,
82
- ...(input.summary === undefined ? {} : { summary: input.summary }),
83
- },
84
- };
85
- if (prepared.kind === "prepared") {
86
- workspace = prepared.data.workspace;
87
- tender = prepared.data.tender;
88
- }
71
+ function reviewWorktreeInput(prepared) {
72
+ return {
73
+ tree: prepared.data.tender.tree,
74
+ head: prepared.data.tender.head,
75
+ ...(prepared.data.tender.mergeHead === undefined ? {} : { mergeHead: prepared.data.tender.mergeHead }),
76
+ dirty: prepared.data.tender.dirty,
77
+ changeId: prepared.data.changeId,
78
+ };
79
+ }
80
+ async function recaptureReviewWorktree(input, state) {
81
+ const prepared = await captureReviewableWorktree(input.scope, {
82
+ contractId: state.id,
83
+ coordinates: state.coordinates,
84
+ });
85
+ return prepared.kind === "prepared" ? reviewWorktreeInput(prepared) : undefined;
86
+ }
87
+ async function speculateReview(input) {
88
+ const observation = await observeContractsForAdmissionAt(input.scope, input.channel, [input.contractId]);
89
+ const state = contractState(observation.decision, input.contractId);
90
+ if (state === null)
91
+ return { observation };
92
+ const prepared = await captureReviewableWorktree(input.scope, {
93
+ contractId: state.id,
94
+ coordinates: state.coordinates,
95
+ });
96
+ if (prepared.kind === "refused") {
97
+ return { observation, preparation: { kind: "refused", refusal: prepared.refusal } };
89
98
  }
99
+ return {
100
+ observation,
101
+ preparation: preparedReviewCapture(input, state, prepared),
102
+ ...(prepared.data.workspace === undefined ? {} : { workspace: prepared.data.workspace }),
103
+ tender: prepared.data.tender,
104
+ worktree: reviewWorktreeInput(prepared),
105
+ };
106
+ }
107
+ async function decideAndAdmitReview(input, attempt, seat, observation, speculated) {
90
108
  const decision = decideAttestation({
91
109
  input: {
92
110
  contractId: input.contractId,
93
111
  ...(input.actor === undefined ? {} : { actor: input.actor }),
94
112
  at: timestamp(),
95
- ...(preparation === undefined ? {} : { preparation }),
113
+ ...(speculated.preparation === undefined ? {} : { preparation: speculated.preparation }),
96
114
  },
97
115
  attempt,
98
- observation: decisionObservation.decision,
116
+ observation: observation.decision,
99
117
  });
100
118
  if (decision.kind === "refused")
101
119
  return { kind: "refused", refusal: decision.refusal };
@@ -103,20 +121,37 @@ async function reviewAttemptInPrivateStateSeat(input, attempt, seat) {
103
121
  channel: input.channel,
104
122
  repository: input.scope,
105
123
  seat,
106
- decisionObservation,
124
+ decisionObservation: observation,
107
125
  attempt,
108
126
  offer: decision.offer,
109
127
  primaryContract: input.contractId,
110
128
  });
111
- if (admission.kind === "accepted")
112
- return {
113
- ...admission,
114
- value: {
115
- ...(workspace === undefined ? {} : { workspace }),
116
- ...(tender === undefined ? {} : { tender }),
117
- },
118
- };
119
- return admission;
129
+ if (admission.kind !== "accepted")
130
+ return admission;
131
+ return {
132
+ ...admission,
133
+ value: {
134
+ ...(speculated.workspace === undefined ? {} : { workspace: speculated.workspace }),
135
+ ...(speculated.tender === undefined ? {} : { tender: speculated.tender }),
136
+ },
137
+ };
138
+ }
139
+ async function reviewAttemptInPrivateStateSeat(input, attempt, seat, speculated) {
140
+ const observation = await matchingPrivateRootObservation(input.scope, input.channel, input.contractId, speculated.observation, async (fresh) => {
141
+ if (speculated.worktree === undefined)
142
+ return true;
143
+ const state = contractState(fresh.decision, input.contractId);
144
+ if (state === null)
145
+ return false;
146
+ return sameSpeculativeWorktreeInput(speculated.worktree, await recaptureReviewWorktree(input, state));
147
+ });
148
+ return "kind" in observation
149
+ ? observation
150
+ : await decideAndAdmitReview(input, attempt, seat, observation, speculated);
151
+ }
152
+ async function reviewAttempt(input, attempt) {
153
+ const speculated = await speculateReview(input);
154
+ return await privateStateSeatAttempt(input.scope, async (seat) => await reviewAttemptInPrivateStateSeat(input, attempt, seat, speculated), attemptDecisionWithSeatClose);
120
155
  }
121
156
  export async function reviewOperation(input) {
122
157
  const git = input.scope;
@@ -1,11 +1,17 @@
1
1
  import { type GitDecisionObservation } from "../git/observe.js";
2
+ import { type PrivateStatePublicationSeat, type PrivateStateSeatOutcome } from "../git/private-state-seat.js";
2
3
  import type { GitDecodeChannel, GitTreeSelection } from "../git/read-observation.js";
3
4
  import type { GitRepository } from "../git/process.js";
4
- import type { GitRefAssertion } from "../git/repository.js";
5
+ import { type GitOid, type GitRefAssertion } from "../git/repository.js";
5
6
  import type { AttemptContext, DecideInput, OfferDecision } from "../core/decide.js";
6
7
  import type { Offer, TreeUpdate } from "../core/facts/offer.js";
7
- import { type ContractId } from "../core/facts/types.js";
8
+ import { type ChangeId, type ContractId, type SnapshotId } from "../core/facts/types.js";
8
9
  import { type AcceptedAdmission, type AttemptTerminal } from "./attempt.js";
10
+ import type { GitObjectId } from "../git/identity.js";
11
+ export declare const STALE_PRIVATE_STATE_PREPARATION: {
12
+ readonly kind: "publication-failed";
13
+ readonly diagnostic: "stale private-state preparation";
14
+ };
9
15
  export type ProtocolTerminal = Readonly<{
10
16
  kind: "exhausted";
11
17
  }> | AttemptTerminal;
@@ -68,6 +74,20 @@ export type PreparedProtocolAttempt<Refusal> = Readonly<{
68
74
  offer: Offer;
69
75
  assertions: readonly GitRefAssertion[];
70
76
  }>;
77
+ export declare function privateRootCommit(observation: GitDecisionObservation): GitOid | null;
78
+ export declare function samePrivateRootObservation(prepared: GitDecisionObservation, fresh: GitDecisionObservation): boolean;
79
+ export type SpeculativeWorktreeInput = Readonly<{
80
+ tree: GitObjectId;
81
+ head: SnapshotId;
82
+ mergeHead?: SnapshotId;
83
+ dirty: boolean;
84
+ changeId: ChangeId;
85
+ }>;
86
+ export declare function sameSpeculativeWorktreeInput(prepared: SpeculativeWorktreeInput | undefined, fresh: SpeculativeWorktreeInput | undefined): boolean;
87
+ export declare function privateStateAssertionsMatch(repository: GitRepository, assertions: readonly GitRefAssertion[]): Promise<boolean>;
88
+ export declare function publicationFailedFromSeatError(error: unknown): AttemptTerminal;
89
+ export declare function matchingPrivateRootObservation(repository: GitRepository, channel: GitDecodeChannel, contractId: ContractId, prepared: GitDecisionObservation, revalidate?: (fresh: GitDecisionObservation) => boolean | Promise<boolean>): Promise<GitDecisionObservation | typeof STALE_PRIVATE_STATE_PREPARATION>;
90
+ export declare function privateStateSeatAttempt<T>(repository: GitRepository, action: (seat: PrivateStatePublicationSeat) => Promise<T>, wrap: (outcome: PrivateStateSeatOutcome<T>) => T): Promise<T | AttemptTerminal>;
71
91
  /** Form one decided offer without admitting or reinterpreting it. */
72
92
  export declare function prepareProtocolAttempt<Input extends Readonly<{
73
93
  contractId: ContractId;