@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
@@ -0,0 +1,261 @@
1
+ import { materializeIntegrationSnapshot, materializeJudgedConflict, planIntegration, workspaceMergeStatePresent, worktreeChangeId, } from "../git/integration.js";
2
+ import { captureTender, dirtyTenderRefusal, materializeTenderSnapshot, prepareDeliveryCommitMetadata, } from "../git/tender.js";
3
+ import { worktreePath } from "../git/workspace.js";
4
+ import { currentBranch, observeContractsForAdmissionAt } from "../git/observe.js";
5
+ import { contractState } from "../core/facts/observation.js";
6
+ import { decideDeliver } from "../core/verbs/deliver.js";
7
+ import { admitDecidedOffer, mintAttempts } from "./attempt.js";
8
+ import { admitted } from "./outcome.js";
9
+ import { completeCandidate } from "./completion.js";
10
+ import { appointmentFor, readPlaceRegister } from "../workspace-place.js";
11
+ import { timestamp } from "./operations.js";
12
+ const DELIVER_CONFLICT_RECOVERY = Object.freeze({
13
+ materialize: "deliver --materialize-conflict",
14
+ continue: "deliver",
15
+ });
16
+ export async function prepareDelivery(repository, stage, input) {
17
+ const { contractId, coordinates } = stage;
18
+ if (coordinates.workspace === "here" && coordinates.target !== undefined) {
19
+ const branch = await currentBranch(repository, stage.workspacePath);
20
+ if (branch !== coordinates.target) {
21
+ return {
22
+ kind: "refused",
23
+ refusal: { kind: "workspace-not-on-target", contractId, target: coordinates.target, branch },
24
+ };
25
+ }
26
+ }
27
+ const appointed = coordinates.workspace === "worktree"
28
+ ? stage.appointment === undefined
29
+ ? appointmentFor(await readPlaceRegister(repository), contractId)
30
+ : { contract: contractId, place: stage.appointment.place }
31
+ : undefined;
32
+ const tender = await captureTender(repository, {
33
+ contractId,
34
+ coordinates,
35
+ ...(appointed === undefined ? {} : { place: appointed.place }),
36
+ ...(stage.workspacePath === undefined ? {} : { workspacePath: stage.workspacePath }),
37
+ });
38
+ if (tender.kind === "refused")
39
+ return tender;
40
+ if ((tender.data.dirty && input.includeDirty !== true) || tender.data.changes.submodules.length > 0) {
41
+ return { kind: "refused", refusal: await dirtyTenderRefusal(repository, contractId, tender.data) };
42
+ }
43
+ const commit = await prepareDeliveryCommitMetadata(repository, {
44
+ contractId,
45
+ title: input.title,
46
+ document: input.document,
47
+ at: tender.data.at,
48
+ ...(input.actor === undefined ? {} : { actor: input.actor }),
49
+ ...(input.message === undefined ? {} : { message: input.message }),
50
+ });
51
+ const tenderSnapshot = await materializeTenderSnapshot(repository, tender.data, commit);
52
+ const requireBranchesToBeUpToDate = input.requireBranchesToBeUpToDate ?? false;
53
+ const integration = await planIntegration(repository, { contractId, coordinates }, { ...tender.data, head: tenderSnapshot }, requireBranchesToBeUpToDate);
54
+ if (integration.kind === "refused")
55
+ return integration;
56
+ const integrationSnapshot = coordinates.target === undefined
57
+ ? tenderSnapshot
58
+ : await materializeIntegrationSnapshot(repository, integration.data.tree, integration.data.predecessor, commit);
59
+ return {
60
+ kind: "prepared",
61
+ data: {
62
+ tenderSnapshot,
63
+ integration: {
64
+ predecessor: integration.data.predecessor,
65
+ snapshot: integrationSnapshot,
66
+ changeId: await worktreeChangeId(repository, { contractId, coordinates }, tender.data),
67
+ },
68
+ method: "squash",
69
+ policy: { requireBranchesToBeUpToDate },
70
+ },
71
+ };
72
+ }
73
+ async function deliverAttempt(input, attempt) {
74
+ const decisionObservation = await observeContractsForAdmissionAt(input.scope, input.channel, [input.contractId]);
75
+ const state = contractState(decisionObservation.decision, input.contractId);
76
+ const derivation = state === null ? undefined : input.deriveDocument(state);
77
+ let preparation;
78
+ let workspacePath;
79
+ if (state === null || derivation === undefined) {
80
+ preparation = { kind: "unavailable" };
81
+ }
82
+ else if (derivation.verification.kind === "refused") {
83
+ preparation = { kind: "refused", document: derivation.document, refusal: derivation.verification.refusal };
84
+ }
85
+ else {
86
+ workspacePath = state.terminal === null && state.coordinates.workspace === "here"
87
+ ? await input.resolveHereWorkspace?.(state.id)
88
+ : undefined;
89
+ const prepared = await prepareDelivery(input.scope, {
90
+ contractId: state.id,
91
+ coordinates: state.coordinates,
92
+ ...(workspacePath === undefined ? {} : { workspacePath }),
93
+ }, {
94
+ title: derivation.title,
95
+ document: derivation.bytes,
96
+ ...(input.actor === undefined ? {} : { actor: input.actor }),
97
+ ...(input.message === undefined ? {} : { message: input.message }),
98
+ requireBranchesToBeUpToDate: input.requireBranchesToBeUpToDate,
99
+ includeDirty: input.includeDirty,
100
+ });
101
+ preparation = prepared.kind === "refused"
102
+ ? { kind: "refused", document: derivation.document, refusal: prepared.refusal }
103
+ : {
104
+ kind: "prepared",
105
+ document: derivation.document,
106
+ data: prepared.data,
107
+ ...(workspacePath === undefined ? {} : { workspacePath }),
108
+ };
109
+ }
110
+ const decision = decideDeliver({
111
+ input: {
112
+ contractId: input.contractId,
113
+ ...(input.actor === undefined ? {} : { actor: input.actor }),
114
+ at: timestamp(),
115
+ preparation,
116
+ },
117
+ attempt,
118
+ observation: decisionObservation.decision,
119
+ });
120
+ if (decision.kind === "refused")
121
+ return { kind: "refused", refusal: decision.refusal };
122
+ if (preparation.kind !== "prepared")
123
+ throw new Error("offered delivery is missing its mechanical preparation");
124
+ const admission = await admitDecidedOffer({
125
+ channel: input.channel,
126
+ repository: input.scope,
127
+ decisionObservation,
128
+ attempt,
129
+ offer: decision.offer,
130
+ primaryContract: input.contractId,
131
+ });
132
+ if (admission.kind === "accepted") {
133
+ if (derivation === undefined)
134
+ throw new Error("accepted delivery is missing its document derivation");
135
+ return {
136
+ ...admission,
137
+ value: {
138
+ delivery: preparation.data,
139
+ derivation,
140
+ ...(workspacePath === undefined ? {} : { workspacePath }),
141
+ },
142
+ };
143
+ }
144
+ return admission;
145
+ }
146
+ async function completeDelivery(input, first) {
147
+ const derivation = first.value.derivation;
148
+ if (derivation.verification.kind !== "prepared") {
149
+ throw new Error("accepted delivery is missing its Verification preparation");
150
+ }
151
+ const completed = await completeCandidate({
152
+ channel: input.channel,
153
+ repository: input.scope,
154
+ contractId: input.contractId,
155
+ ...(input.actor === undefined ? {} : { actor: input.actor }),
156
+ ...(input.signal === undefined ? {} : { signal: input.signal }),
157
+ ...(first.value.workspacePath === undefined ? {} : { hereWorkspacePath: first.value.workspacePath }),
158
+ ...(first.state.coordinates.target === undefined ? {} : { target: first.state.coordinates.target }),
159
+ verification: derivation.verification,
160
+ initial: first,
161
+ verifyInitial: true,
162
+ });
163
+ return admitted(completed.admission, {
164
+ ...first.value.delivery,
165
+ ...completed.evidence,
166
+ });
167
+ }
168
+ function isIntegrationConflict(refusal) {
169
+ return refusal.kind === "integration-failed" && refusal.reason === "conflict";
170
+ }
171
+ function conflictDeliverRefusal(refusal) {
172
+ if (refusal.conflictPaths === undefined)
173
+ throw new Error("conflicted integration is missing conflict paths");
174
+ return {
175
+ kind: "integration-failed",
176
+ contractId: refusal.contractId,
177
+ reason: "conflict",
178
+ targetHead: refusal.targetHead,
179
+ conflictPaths: refusal.conflictPaths,
180
+ recovery: DELIVER_CONFLICT_RECOVERY,
181
+ };
182
+ }
183
+ async function appointedDeliverWorkspace(input) {
184
+ const observation = await observeContractsForAdmissionAt(input.scope, input.channel, [input.contractId]);
185
+ const state = contractState(observation.decision, input.contractId);
186
+ if (state === null)
187
+ return { kind: "refused", refusal: { kind: "worktree-missing", contractId: input.contractId } };
188
+ if (state.coordinates.workspace === "here") {
189
+ const path = await input.resolveHereWorkspace?.(state.id);
190
+ if (path === undefined) {
191
+ return { kind: "refused", refusal: { kind: "worktree-missing", contractId: input.contractId } };
192
+ }
193
+ return { workspace: { kind: "here", path }, coordinates: state.coordinates };
194
+ }
195
+ const appointment = appointmentFor(await readPlaceRegister(input.scope), input.contractId);
196
+ if (appointment === undefined) {
197
+ return { kind: "refused", refusal: { kind: "worktree-missing", contractId: input.contractId } };
198
+ }
199
+ return {
200
+ workspace: { kind: "worktree", path: worktreePath(input.scope, appointment.place) },
201
+ coordinates: state.coordinates,
202
+ };
203
+ }
204
+ async function materializeDeliverConflict(input, refusal) {
205
+ if (refusal.conflictPaths === undefined)
206
+ throw new Error("conflicted integration is missing conflict paths");
207
+ const appointed = await appointedDeliverWorkspace(input);
208
+ if ("kind" in appointed)
209
+ return appointed;
210
+ const { workspace, coordinates } = appointed;
211
+ if (await workspaceMergeStatePresent(input.scope, workspace.path)) {
212
+ return {
213
+ kind: "refused",
214
+ refusal: { kind: "merge-state-present", contractId: input.contractId, workspace },
215
+ };
216
+ }
217
+ const tender = await captureTender(input.scope, {
218
+ contractId: input.contractId,
219
+ coordinates,
220
+ workspacePath: workspace.path,
221
+ });
222
+ if (tender.kind === "refused")
223
+ return tender;
224
+ if (tender.data.dirty || tender.data.changes.submodules.length > 0) {
225
+ return { kind: "refused", refusal: await dirtyTenderRefusal(input.scope, input.contractId, tender.data) };
226
+ }
227
+ await materializeJudgedConflict(input.scope, workspace.path, refusal.targetHead);
228
+ return {
229
+ kind: "integration-conflict-materialized",
230
+ targetHead: refusal.targetHead,
231
+ conflictPaths: refusal.conflictPaths,
232
+ workspace,
233
+ };
234
+ }
235
+ async function finishDeliverRefusal(input, refusal) {
236
+ if (!isIntegrationConflict(refusal))
237
+ return { kind: "refused", refusal };
238
+ if (input.materializeConflict !== true)
239
+ return { kind: "refused", refusal: conflictDeliverRefusal(refusal) };
240
+ return await materializeDeliverConflict(input, refusal);
241
+ }
242
+ export async function deliverOperation(input) {
243
+ const attempts = mintAttempts({ entryCount: 2 });
244
+ let first = null;
245
+ for (let index = 0; index < attempts.length; index += 1) {
246
+ const result = await deliverAttempt(input, attempts[index]);
247
+ if (result.kind === "accepted") {
248
+ first = result;
249
+ break;
250
+ }
251
+ if (result.kind === "refused")
252
+ return await finishDeliverRefusal(input, result.refusal);
253
+ if (result.kind === "publication-failed")
254
+ return { kind: "retry", reason: result };
255
+ if (result.kind === "collision" && index + 1 === attempts.length)
256
+ return { kind: "retry", reason: result };
257
+ }
258
+ if (first === null)
259
+ return { kind: "retry", reason: { kind: "exhausted" } };
260
+ return await completeDelivery(input, first);
261
+ }
@@ -1,6 +1,6 @@
1
1
  import type { GitDecisionObservation } from "../git/observe.js";
2
2
  import type { GitDecodeChannel, GitTreeSelection } from "../git/read-observation.js";
3
- import type { GitRepository } from "../git/repository.js";
3
+ import type { GitRepository } from "../git/process.js";
4
4
  import type { GitRefAssertion } from "../git/repository.js";
5
5
  import { type WorktreeLeak } from "../git/scratch.js";
6
6
  import type { HookFailure } from "../git/hooks.js";
@@ -81,6 +81,7 @@ export type VerificationResult = Readonly<{
81
81
  export type CurrentVerifiedAttestation = Readonly<{
82
82
  entry: EntryUlid;
83
83
  verdict: "satisfied" | "unsatisfied";
84
+ summary?: string;
84
85
  }>;
85
86
  /** Read the latest current verified attestation through the generic currentness judge. */
86
87
  export declare function currentVerifiedAttestation(state: ContractState): CurrentVerifiedAttestation | undefined;
@@ -47,11 +47,17 @@ function verificationInput(outcome, input, subject) {
47
47
  /** Read the latest current verified attestation through the generic currentness judge. */
48
48
  export function currentVerifiedAttestation(state) {
49
49
  const current = latestCurrentAttestations(state, new Set([VERIFIED])).get(VERIFIED);
50
- return current === undefined ? undefined : { entry: current.entry, verdict: current.data.verdict };
50
+ return current === undefined
51
+ ? undefined
52
+ : {
53
+ entry: current.entry,
54
+ verdict: current.data.verdict,
55
+ ...(current.data.summary === undefined ? {} : { summary: current.data.summary }),
56
+ };
51
57
  }
52
58
  /** Run Verification against an explicit or admitted integration snapshot. */
53
59
  export async function verifyDelivery(input) {
54
- const snapshot = input.snapshot ?? input.state.delivery?.data.integration.snapshot;
60
+ const snapshot = input.snapshot ?? input.state.currentIntegration?.snapshot;
55
61
  if (snapshot === undefined || input.verification === undefined)
56
62
  return null;
57
63
  const subject = dependencyKeySet([
@@ -1,252 +1,143 @@
1
- import { type DeliveryDiffScope, type IntegrationPreparationRefusal } from "../git/integration.js";
2
- import { type DirtyWorkspaceRefusal, type WorkspaceDirtyDelta } from "../git/tender.js";
3
- import { type ReconcileResult } from "../git/reconcile.js";
4
- import type { WorktreeHooks } from "../git/hooks.js";
5
- import { NoGitWorldError, type GitRepository } from "../git/repository.js";
6
- import { type GitDecodeChannel, type GitTreeSelection } from "../git/read-observation.js";
1
+ import { type DirtyWorkspaceRefusal } from "../git/tender.js";
2
+ import type { GitRepository } from "../git/process.js";
3
+ import { type GitDecodeChannel } from "../git/read-observation.js";
7
4
  import type { WorktreeLeak } from "../git/scratch.js";
8
- import type { ActorId, AmendData, ArcData, AttestationData, ChangeId, ContractId, ContractState, ContractTerms, DeliverData, DocumentKey, SnapshotId } from "../core/facts/types.js";
9
- import { type AbandonRefusal } from "../core/verbs/abandon.js";
10
- import { type AmendRefusal } from "../core/verbs/amend.js";
11
- import { type ArcRefusal } from "../core/verbs/arc.js";
12
- import { type DeliverRefusal } from "../core/verbs/deliver.js";
5
+ import type { AbandonRefusal } from "../core/verbs/abandon.js";
6
+ import type { AmendRefusal } from "../core/verbs/amend.js";
7
+ import type { ArcRefusal } from "../core/verbs/arc.js";
8
+ import type { DeliverRefusal } from "../core/verbs/deliver.js";
13
9
  import type { PlacementRefusal } from "../core/verbs/placement.js";
14
- import { type AttestationRefusal } from "../core/verbs/attestation.js";
10
+ import type { AttestationRefusal } from "../core/verbs/attestation.js";
11
+ import type { ContractId, ContractState, DeliverData, DocumentKey, SnapshotId } from "../core/facts/types.js";
12
+ import type { BindRefusal, TargetInputRefusal } from "./bind.js";
13
+ import type { IntegrationPreparationRefusal } from "../git/integration.js";
14
+ import type { TargetPlacementRefusal } from "../git/target-placement.js";
15
+ import type { VerificationCleanupFailure, VerificationRuntimeStop, VerificationResult } from "./intent.js";
15
16
  import type { VerificationDeclarationPreparation, VerificationDeclarationRefusal } from "../verification/declaration.js";
16
- import { type CurrentVerifiedAttestation, type VerificationRuntimeStop, type VerificationCleanupFailure } from "./intent.js";
17
- import { type AuditTargetAnswer, type TargetPlacementRefusal } from "../git/target-placement.js";
17
+ import type { PlacementProtocolResult } from "./placement.js";
18
+ import type { AcceptedAdmission, DecidedOfferResult } from "./attempt.js";
19
+ import type { AcceptedProtocolStep, IntentOutcome as ProtocolIntentOutcome } from "./outcome.js";
20
+ import type { ProtocolResult, ProtocolTerminal } from "./run.js";
18
21
  import { type ContractDocumentProjection } from "./read/documents.js";
19
- import { type ContractBoard, type ContractDisposition, type ContractGateCurrent, type ContractGateReport, type ContractObservation, type ContractPhase, type ContractRow } from "./read/status.js";
20
- import { type ManagedWorktreeAppointment } from "../workspace-place.js";
21
- export { bindOperation } from "./bind.js";
22
- export { reconcileObservationFailure } from "../git/reconcile.js";
23
- import type { BindRefusal, TargetInputRefusal } from "./bind.js";
24
- import { type IntentOutcome as ProtocolIntentOutcome } from "./outcome.js";
25
- import type { ProtocolTerminal } from "./run.js";
26
- import type { CompanionDecorator } from "./run.js";
27
- export type { FactKind } from "../core/facts/types.js";
28
- export type { ContractDocumentProjection } from "./read/documents.js";
22
+ import { type ContractBoard, type ContractObservation } from "./read/status.js";
23
+ export type MergeStatePresentRefusal = Readonly<{
24
+ kind: "merge-state-present";
25
+ contractId: ContractId;
26
+ workspace: Readonly<{
27
+ kind: "here" | "worktree";
28
+ path: string;
29
+ }>;
30
+ }>;
31
+ export type DeliverConflictRefusal = Readonly<{
32
+ kind: "integration-failed";
33
+ contractId: ContractId;
34
+ reason: "conflict";
35
+ targetHead: SnapshotId;
36
+ conflictPaths: readonly string[];
37
+ recovery: Readonly<{
38
+ materialize: "deliver --materialize-conflict";
39
+ continue: "deliver";
40
+ }>;
41
+ }>;
29
42
  export type DeliveryPreparationRefusal = Readonly<{
30
43
  kind: "target-missing" | "worktree-missing";
31
44
  contractId: ContractId;
32
- }> | DirtyWorkspaceRefusal | IntegrationPreparationRefusal | TargetPlacementRefusal;
33
- type ReviewPreparationRefusal = Readonly<{
34
- kind: "worktree-missing";
35
- contractId: ContractId;
36
- }> | DirtyWorkspaceRefusal;
37
- type ReviewRefusal = AttestationRefusal | ReviewPreparationRefusal;
38
- export type IntentRefusal = AbandonRefusal | AmendRefusal | ArcRefusal | BindRefusal | DeliverRefusal | DeliveryPreparationRefusal | PlacementRefusal | ReviewRefusal | TargetInputRefusal | VerificationDeclarationRefusal;
39
- export type { TargetInputRefusal } from "./bind.js";
45
+ }> | DirtyWorkspaceRefusal | IntegrationPreparationRefusal | MergeStatePresentRefusal | TargetPlacementRefusal;
46
+ export type IntentRefusal = AbandonRefusal | AmendRefusal | ArcRefusal | BindRefusal | DeliverRefusal | DeliveryPreparationRefusal | DeliverConflictRefusal | PlacementRefusal | AttestationRefusal | TargetInputRefusal | VerificationDeclarationRefusal;
40
47
  export type IntentRetry = ProtocolTerminal;
41
48
  export type IntentOutcome<Value, Refusal = IntentRefusal> = ProtocolIntentOutcome<Value, Refusal>;
42
49
  type OperationInput = Readonly<{
43
50
  scope: RepositoryScope;
44
51
  contractId: ContractId;
45
- actor?: ActorId;
52
+ actor?: import("../core/facts/types.js").ActorId;
46
53
  }>;
47
- type MutationOperationInput = OperationInput & Readonly<{
54
+ export type HereWorkspaceResolver = (contractId: ContractId) => Promise<string | undefined>;
55
+ export type MutationOperationInput = OperationInput & Readonly<{
48
56
  channel: GitDecodeChannel;
57
+ resolveHereWorkspace?: HereWorkspaceResolver;
49
58
  }>;
50
- export type AuditWorkspace = Readonly<{
51
- kind: "worktree" | "here";
52
- path: string;
53
- }>;
54
- export type DiffScope = DeliveryDiffScope;
55
- export type AuditReport = Readonly<{
56
- candidate: Readonly<{
57
- kind: "blocked";
58
- refusal: DeliveryPreparationRefusal;
59
- }> | Readonly<{
60
- kind: "ready";
61
- workspace: AuditWorkspace;
62
- identity: DeliveryIdentity;
63
- scope: DiffScope;
64
- diff?: string;
65
- }>;
66
- verification: Readonly<{
67
- kind: "not-run";
68
- }> | Readonly<{
69
- kind: "satisfied";
70
- passed: number;
71
- total: number;
72
- summary?: string;
73
- }> | Readonly<{
74
- kind: "unsatisfied";
75
- passed: number;
76
- total: number;
77
- summary?: string;
78
- }> | Readonly<{
79
- kind: "stopped";
80
- stop: VerificationStop;
81
- }>;
82
- target: Readonly<{
83
- kind: "not-observed";
84
- }> | AuditTargetAnswer;
85
- delivery?: Readonly<{
86
- changeId: ChangeId;
87
- relation: "identical" | "differs";
88
- }>;
89
- }>;
90
- export type VerificationReuse = CurrentVerifiedAttestation;
91
59
  export type DocumentDerivation = Readonly<{
92
60
  document: DocumentKey;
93
61
  bytes: string;
94
62
  title: string;
95
63
  verification: VerificationDeclarationPreparation;
96
64
  }>;
97
- export type StepStop<R> = Readonly<{
65
+ type StepStop<R> = Readonly<{
98
66
  refusal: R;
99
67
  retry?: never;
100
68
  } | {
101
69
  retry: IntentRetry;
102
70
  refusal?: never;
103
71
  }>;
104
- export type VerificationStop = StepStop<AttestationRefusal> | VerificationRuntimeStop;
105
- export type PlacementStop = StepStop<PlacementRefusal | TargetPlacementRefusal | IntegrationPreparationRefusal> | Readonly<{
72
+ export type VerificationStop = StepStop<AttestationRefusal | VerificationDeclarationRefusal> | VerificationRuntimeStop;
73
+ export type PlacementStop = StepStop<PlacementRefusal | TargetPlacementRefusal | IntegrationPreparationRefusal | Readonly<{
74
+ kind: "target-missing";
75
+ contractId: ContractId;
76
+ }>> | Readonly<{
106
77
  failure: "target-moved";
107
78
  contractId: ContractId;
108
79
  target: string;
109
80
  expected: SnapshotId;
110
81
  observed: SnapshotId | null;
82
+ }> | Readonly<{
83
+ failure: "target-moved";
84
+ contractId: ContractId;
85
+ target: string;
86
+ integratedAt: SnapshotId;
87
+ observed: SnapshotId | null;
88
+ attempts: number;
111
89
  }> | Readonly<{
112
90
  failure: "target-placement-failed";
113
91
  diagnostic: string;
114
92
  }>;
115
- type ScopeOperationInput = Readonly<{
116
- coordinate: string;
93
+ export type AttemptDecision<Value, Refusal = IntentRefusal> = (AcceptedAdmission & Readonly<{
94
+ value: Value;
95
+ }>) | Readonly<{
96
+ kind: "refused";
97
+ refusal: Refusal;
98
+ }> | Readonly<{
99
+ kind: "redecide";
100
+ }> | Readonly<{
101
+ kind: "collision";
102
+ }> | Extract<DecidedOfferResult, {
103
+ kind: "publication-failed";
104
+ }>;
105
+ export declare function timestamp(): string;
106
+ export declare function mergeAdmissions(current: AcceptedProtocolStep, next: AcceptedProtocolStep): AcceptedProtocolStep;
107
+ export declare function stepStop<Refusal>(result: ProtocolResult<Refusal>): StepStop<Refusal> | undefined;
108
+ export declare function unpackVerificationOutcome(verification: VerificationResult): Readonly<{
109
+ cleanup?: VerificationCleanupFailure;
110
+ leak?: WorktreeLeak;
111
+ stop?: VerificationStop;
112
+ admission?: AcceptedProtocolStep;
113
+ counts?: NonNullable<VerificationResult["counts"]>;
117
114
  }>;
115
+ export declare function placementStop(result: PlacementProtocolResult<IntegrationPreparationRefusal>): PlacementStop | undefined;
118
116
  export type RepositoryScope = GitRepository;
119
- export { NoGitWorldError };
120
- export declare function scopeOperation(input: ScopeOperationInput): Promise<RepositoryScope>;
117
+ export declare function scopeOperation(input: Readonly<{
118
+ coordinate: string;
119
+ gitPath?: string;
120
+ }>): Promise<RepositoryScope>;
121
121
  export declare function currentBranchOperation(input: Readonly<{
122
122
  scope: RepositoryScope;
123
123
  }>): Promise<string | null>;
124
124
  export declare function contractsOperation(input: Readonly<{
125
125
  scope: RepositoryScope;
126
126
  channel: GitDecodeChannel;
127
+ hereWorkspace?: import("./read/status.js").HereWorkspaceObservationResolver;
127
128
  }>): Promise<ContractBoard>;
128
- export declare function contractObservationOperation(input: MutationOperationInput): Promise<ContractObservation>;
129
- export type { ContractBoard, ContractDisposition, ContractGateCurrent, ContractGateReport, ContractObservation, ContractPhase, ContractRow };
129
+ export declare function contractObservationOperation(input: Readonly<{
130
+ scope: RepositoryScope;
131
+ channel: GitDecodeChannel;
132
+ contractId: ContractId;
133
+ hereWorkspace?: import("./read/status.js").HereWorkspaceObservationResolver;
134
+ }>): Promise<ContractObservation>;
130
135
  export declare function documentsOperationAt(scope: RepositoryScope, channel: GitDecodeChannel): Promise<readonly ContractDocumentProjection[]>;
131
136
  export declare function stateOperation(input: MutationOperationInput): Promise<ContractState>;
132
- type DeliveryIdentity = DeliverData;
133
- export declare function deliveryOperation(input: MutationOperationInput): Promise<DeliveryIdentity | null>;
134
- type DeliveryDiffOperationInput = Readonly<{
137
+ export declare function deliveryOperation(input: MutationOperationInput): Promise<DeliverData | null>;
138
+ export declare function deliveryDiffOperation(input: Readonly<{
135
139
  scope: RepositoryScope;
136
140
  integrationPredecessor: SnapshotId;
137
141
  integrationSnapshot: SnapshotId;
138
- }>;
139
- export declare function deliveryDiffOperation(input: DeliveryDiffOperationInput): Promise<string | null>;
140
- type AmendOperationInput = MutationOperationInput & Readonly<{
141
- source?: ContractTerms;
142
- deriveAmendment?: (source: ContractTerms) => Readonly<{
143
- terms: AmendData;
144
- verification: VerificationDeclarationPreparation;
145
- }>;
146
- }>;
147
- type Amendment = Readonly<{
148
- source: ContractTerms;
149
- }> & ReturnType<NonNullable<AmendOperationInput["deriveAmendment"]>>;
150
- export declare function amendOperation(input: AmendOperationInput): Promise<IntentOutcome<Amendment, AmendRefusal | VerificationDeclarationRefusal>>;
151
- export type DeliverValue = DeliveryIdentity & Readonly<{
152
- verification?: VerificationStop;
153
- verificationReuse?: VerificationReuse;
154
- placement?: PlacementStop;
155
- cleanup?: VerificationCleanupFailure;
156
- leak?: WorktreeLeak;
157
- }>;
158
- type DeliverOperationInput = MutationOperationInput & Readonly<{
159
- deriveDocument: (state: ContractState) => DocumentDerivation;
160
- message?: string;
161
- requireBranchesToBeUpToDate: boolean;
162
- includeDirty: boolean;
163
- signal?: AbortSignal;
164
- }>;
165
- export declare function prepareDelivery(repository: GitRepository, stage: Readonly<{
166
- contractId: ContractId;
167
- coordinates: ContractState["coordinates"];
168
- appointment?: Extract<ManagedWorktreeAppointment, {
169
- kind: "appointed";
170
- }>;
171
- }>, input: Readonly<{
172
- title: string;
173
- document: string;
174
- actor?: ActorId;
175
- message?: string;
176
- requireBranchesToBeUpToDate?: boolean;
177
- includeDirty?: boolean;
178
- }>): Promise<{
179
- kind: "prepared";
180
- data: DeliverData;
181
- } | {
182
- kind: "refused";
183
- refusal: DeliveryPreparationRefusal;
184
- }>;
185
- export declare function prepareReview(repository: GitRepository, stage: Readonly<{
186
- contractId: ContractId;
187
- coordinates: ContractState["coordinates"];
188
- }>): Promise<{
189
- kind: "prepared";
190
- data: Readonly<{
191
- changeId: DeliverData["integration"]["changeId"];
192
- workspace?: WorkspaceDirtyDelta;
193
- }>;
194
- } | {
195
- kind: "refused";
196
- refusal: ReviewPreparationRefusal;
197
- }>;
198
- export declare function deliverOperation(input: DeliverOperationInput): Promise<IntentOutcome<DeliverValue>>;
199
- export declare function abandonOperation(input: MutationOperationInput & Readonly<{
200
- note?: string;
201
- decorateOffer?: CompanionDecorator;
202
- observationSelection?: GitTreeSelection;
203
- }>): Promise<IntentOutcome<void, AbandonRefusal>>;
204
- export declare function arcOperation(input: MutationOperationInput & Readonly<{
205
- chapter: Omit<ArcData, "seq">;
206
- }>): Promise<IntentOutcome<void, ArcRefusal>>;
207
- type ReviewOperationInput = MutationOperationInput & Readonly<{
208
- verdict: AttestationData["verdict"];
209
- summary?: string;
210
- }>;
211
- export type ReviewValue = Readonly<{
212
- placement?: PlacementStop;
213
- workspace?: WorkspaceDirtyDelta;
214
- }>;
215
- export declare function reviewOperation(input: ReviewOperationInput): Promise<IntentOutcome<ReviewValue, ReviewRefusal>>;
216
- type AuditOperationInput = MutationOperationInput & Readonly<{
217
- deriveDocument?: (state: ContractState) => DocumentDerivation;
218
- requireBranchesToBeUpToDate?: boolean;
219
- includeDirty?: boolean;
220
- showDiff?: boolean;
221
- signal?: AbortSignal;
222
- }>;
223
- export declare function auditOperation(input: AuditOperationInput): Promise<IntentOutcome<AuditReport>>;
224
- export type ReconcileReport = ReconcileResult;
225
- export type ReconcileObservation = Readonly<{
226
- state: ContractState | null;
227
- report: ReconcileReport;
228
- }>;
229
- type ReconcileOptions = Readonly<{
230
- hooks: WorktreeHooks;
231
- retryHooks: boolean;
232
- retainTerminalWorktree?: boolean;
233
- place?: string;
234
- places?: ReadonlyMap<ContractId, string>;
235
- }>;
236
- export declare function reconcileOperation(input: MutationOperationInput & ReconcileOptions): Promise<ReconcileObservation>;
237
- type RepoReconcileItem = Readonly<{
238
- contractId: ContractId;
239
- state: ContractState | null;
240
- report: ReconcileReport;
241
- }>;
242
- export type RepoReconcileReport = Readonly<{
243
- contracts: readonly RepoReconcileItem[];
244
- }>;
245
- export declare function worldContractStates(input: Readonly<{
246
- scope: RepositoryScope;
247
- channel: GitDecodeChannel;
248
- }>): Promise<readonly ContractState[]>;
249
- export declare function reconcileAllOperation(input: Readonly<{
250
- scope: RepositoryScope;
251
- channel: GitDecodeChannel;
252
- }> & ReconcileOptions): Promise<RepoReconcileReport>;
142
+ }>): Promise<string | null>;
143
+ export {};