@astrosheep/keiyaku 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/README.md +133 -8
  2. package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +2 -2
  3. package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +4 -4
  4. package/build/integrations/marketplace/plugins/keiyaku/opencode.js +2 -2
  5. package/build/integrations/marketplace/plugins/keiyaku/package.json +2 -2
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +13 -5
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +91 -32
  8. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +134 -0
  9. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/agents/openai.yaml +4 -0
  10. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-task/SKILL.md +41 -6
  11. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +262 -46
  12. package/build/src/akuma/abort.d.ts +2 -0
  13. package/build/src/akuma/abort.js +50 -0
  14. package/build/src/akuma/akuma.d.ts +50 -33
  15. package/build/src/akuma/akuma.js +175 -127
  16. package/build/src/akuma/archetype.d.ts +14 -5
  17. package/build/src/akuma/archetype.js +85 -39
  18. package/build/src/akuma/body.d.ts +3 -5
  19. package/build/src/akuma/body.js +490 -183
  20. package/build/src/akuma/coordinate.d.ts +9 -0
  21. package/build/src/akuma/coordinate.js +22 -0
  22. package/build/src/akuma/heart/facts.d.ts +88 -45
  23. package/build/src/akuma/heart/facts.js +19 -8
  24. package/build/src/akuma/heart/index.d.ts +64 -55
  25. package/build/src/akuma/heart/index.js +172 -252
  26. package/build/src/akuma/heart/rows.d.ts +38 -83
  27. package/build/src/akuma/heart/rows.js +117 -155
  28. package/build/src/akuma/heart/schema.d.ts +1 -1
  29. package/build/src/akuma/heart/schema.js +61 -22
  30. package/build/src/akuma/heart/soul.d.ts +8 -0
  31. package/build/src/akuma/heart/soul.js +136 -0
  32. package/build/src/akuma/heart/storage.d.ts +47 -0
  33. package/build/src/akuma/heart/storage.js +224 -0
  34. package/build/src/akuma/heart/tells.d.ts +12 -0
  35. package/build/src/akuma/heart/tells.js +79 -0
  36. package/build/src/akuma/heart/timeline.d.ts +15 -0
  37. package/build/src/akuma/heart/timeline.js +86 -0
  38. package/build/src/akuma/identity.d.ts +2 -2
  39. package/build/src/akuma/identity.js +9 -9
  40. package/build/src/akuma/index.d.ts +10 -3
  41. package/build/src/akuma/index.js +7 -1
  42. package/build/src/akuma/projection.d.ts +176 -0
  43. package/build/src/akuma/projection.js +256 -0
  44. package/build/src/akuma/provider-recipe.d.ts +24 -0
  45. package/build/src/akuma/provider-recipe.js +100 -0
  46. package/build/src/akuma/provider.d.ts +67 -13
  47. package/build/src/akuma/provider.js +172 -105
  48. package/build/src/akuma/providers/acp/core.d.ts +19 -0
  49. package/build/src/akuma/providers/acp/core.js +159 -0
  50. package/build/src/akuma/providers/acp/events.d.ts +20 -0
  51. package/build/src/akuma/providers/acp/events.js +73 -0
  52. package/build/src/akuma/providers/acp/index.d.ts +12 -0
  53. package/build/src/akuma/providers/acp/index.js +94 -0
  54. package/build/src/akuma/providers/{claude.d.ts → claude/events.d.ts} +9 -41
  55. package/build/src/akuma/providers/claude/events.js +238 -0
  56. package/build/src/akuma/providers/claude/index.d.ts +47 -0
  57. package/build/src/akuma/providers/claude/index.js +279 -0
  58. package/build/src/akuma/providers/claude/input.d.ts +13 -0
  59. package/build/src/akuma/providers/claude/input.js +109 -0
  60. package/build/src/akuma/providers/codex-app-server/events.d.ts +1 -1
  61. package/build/src/akuma/providers/codex-app-server/events.js +15 -12
  62. package/build/src/akuma/providers/codex-app-server/index.d.ts +15 -13
  63. package/build/src/akuma/providers/codex-app-server/index.js +77 -33
  64. package/build/src/akuma/providers/grok-build/index.d.ts +4 -0
  65. package/build/src/akuma/providers/grok-build/index.js +70 -0
  66. package/build/src/akuma/providers/index.d.ts +5 -3
  67. package/build/src/akuma/providers/index.js +35 -56
  68. package/build/src/akuma/providers/opencode-sdk/events.d.ts +54 -0
  69. package/build/src/akuma/providers/opencode-sdk/events.js +235 -0
  70. package/build/src/akuma/providers/opencode-sdk/index.d.ts +33 -0
  71. package/build/src/akuma/providers/opencode-sdk/index.js +308 -0
  72. package/build/src/akuma/providers/opencode-sdk/session.d.ts +26 -0
  73. package/build/src/akuma/providers/opencode-sdk/session.js +63 -0
  74. package/build/src/akuma/providers/pi/events.d.ts +33 -0
  75. package/build/src/akuma/providers/pi/events.js +166 -0
  76. package/build/src/akuma/providers/pi/index.d.ts +11 -0
  77. package/build/src/akuma/providers/pi/index.js +191 -0
  78. package/build/src/akuma/publication.d.ts +3 -3
  79. package/build/src/akuma/publication.js +28 -40
  80. package/build/src/akuma/requests.d.ts +9 -6
  81. package/build/src/akuma/requests.js +95 -65
  82. package/build/src/alias/index.d.ts +4 -3
  83. package/build/src/alias/index.js +12 -13
  84. package/build/src/body/decode.js +7 -1
  85. package/build/src/body/region.d.ts +2 -0
  86. package/build/src/body/region.js +77 -7
  87. package/build/src/body/render.js +2 -1
  88. package/build/src/body/shape.js +7 -1
  89. package/build/src/body/verification.js +19 -4
  90. package/build/src/cli/accepted.d.ts +18 -12
  91. package/build/src/cli/accepted.js +73 -34
  92. package/build/src/cli/actor.js +3 -3
  93. package/build/src/cli/commands/akuma-invoke.d.ts +44 -19
  94. package/build/src/cli/commands/akuma-invoke.js +101 -52
  95. package/build/src/cli/commands/akuma.d.ts +27 -9
  96. package/build/src/cli/commands/akuma.js +151 -80
  97. package/build/src/cli/commands/contract.d.ts +155 -0
  98. package/build/src/cli/commands/contract.js +20 -0
  99. package/build/src/cli/commands/install.js +2 -0
  100. package/build/src/cli/commands/task-invoke.d.ts +19 -4
  101. package/build/src/cli/commands/task-invoke.js +65 -17
  102. package/build/src/cli/commands/task-query.d.ts +5 -0
  103. package/build/src/cli/commands/task-query.js +247 -0
  104. package/build/src/cli/commands/task.d.ts +3 -1
  105. package/build/src/cli/commands/task.js +52 -14
  106. package/build/src/cli/coordinates.d.ts +18 -0
  107. package/build/src/cli/coordinates.js +120 -0
  108. package/build/src/cli/draft.d.ts +8 -0
  109. package/build/src/cli/draft.js +96 -0
  110. package/build/src/cli/invoke.d.ts +9 -3
  111. package/build/src/cli/invoke.js +287 -108
  112. package/build/src/cli/main.js +54 -7
  113. package/build/src/cli/parse.d.ts +21 -117
  114. package/build/src/cli/parse.js +79 -84
  115. package/build/src/cli/render/akuma-tool-command.d.ts +6 -0
  116. package/build/src/cli/render/akuma-tool-command.js +144 -0
  117. package/build/src/cli/render/akuma-tool.d.ts +4 -2
  118. package/build/src/cli/render/akuma-tool.js +35 -5
  119. package/build/src/cli/render/akuma.d.ts +3 -1
  120. package/build/src/cli/render/akuma.js +247 -212
  121. package/build/src/cli/render/audit.d.ts +3 -0
  122. package/build/src/cli/render/audit.js +104 -0
  123. package/build/src/cli/render/catalog.d.ts +2 -0
  124. package/build/src/cli/render/catalog.js +16 -0
  125. package/build/src/cli/render/contract.d.ts +3 -3
  126. package/build/src/cli/render/contract.js +200 -54
  127. package/build/src/cli/render/kanshi.js +272 -129
  128. package/build/src/cli/render/receipt.d.ts +19 -0
  129. package/build/src/cli/render/receipt.js +106 -0
  130. package/build/src/cli/render/refusal.d.ts +16 -2
  131. package/build/src/cli/render/refusal.js +88 -3
  132. package/build/src/cli/render/region.d.ts +2 -0
  133. package/build/src/cli/render/region.js +17 -0
  134. package/build/src/cli/render/task.d.ts +2 -1
  135. package/build/src/cli/render/task.js +223 -60
  136. package/build/src/cli/render/terminal.d.ts +20 -0
  137. package/build/src/cli/render/terminal.js +121 -0
  138. package/build/src/cli/render/text.js +11 -3
  139. package/build/src/cli/result.d.ts +126 -19
  140. package/build/src/cli/usage.d.ts +1 -0
  141. package/build/src/cli/usage.js +3 -0
  142. package/build/src/contract-worktree.d.ts +44 -0
  143. package/build/src/contract-worktree.js +251 -0
  144. package/build/src/coordination/durable-file.d.ts +5 -1
  145. package/build/src/coordination/durable-file.js +57 -10
  146. package/build/src/coordination/sqlite-transaction-lock.d.ts +4 -0
  147. package/build/src/coordination/sqlite-transaction-lock.js +22 -5
  148. package/build/src/core/facts/codec.js +23 -4
  149. package/build/src/core/facts/eligibility.d.ts +1 -10
  150. package/build/src/core/facts/eligibility.js +0 -49
  151. package/build/src/core/facts/fold.js +1 -6
  152. package/build/src/core/facts/gate.d.ts +1 -0
  153. package/build/src/core/facts/gate.js +1 -0
  154. package/build/src/core/facts/observation.d.ts +3 -0
  155. package/build/src/core/facts/observation.js +12 -0
  156. package/build/src/core/facts/types.d.ts +10 -3
  157. package/build/src/core/subject.js +2 -2
  158. package/build/src/core/verbs/amend.d.ts +1 -1
  159. package/build/src/core/verbs/amend.js +3 -18
  160. package/build/src/core/verbs/bind.js +2 -16
  161. package/build/src/core/verbs/deliver.d.ts +1 -1
  162. package/build/src/core/verbs/deliver.js +14 -4
  163. package/build/src/core/verbs/placement.d.ts +1 -1
  164. package/build/src/core/verbs/placement.js +7 -9
  165. package/build/src/dispatch/index.d.ts +5 -3
  166. package/build/src/dispatch/index.js +30 -21
  167. package/build/src/duration.d.ts +10 -0
  168. package/build/src/duration.js +22 -0
  169. package/build/src/git/admission.d.ts +2 -2
  170. package/build/src/git/admission.js +33 -23
  171. package/build/src/git/hooks.d.ts +15 -0
  172. package/build/src/git/hooks.js +70 -18
  173. package/build/src/git/identity.d.ts +5 -1
  174. package/build/src/git/identity.js +23 -4
  175. package/build/src/git/integration.d.ts +48 -0
  176. package/build/src/git/integration.js +250 -0
  177. package/build/src/git/observe.d.ts +29 -15
  178. package/build/src/git/observe.js +185 -76
  179. package/build/src/git/read-observation.d.ts +41 -0
  180. package/build/src/git/read-observation.js +361 -0
  181. package/build/src/git/reconcile.d.ts +17 -5
  182. package/build/src/git/reconcile.js +305 -109
  183. package/build/src/git/repository.d.ts +41 -18
  184. package/build/src/git/repository.js +220 -114
  185. package/build/src/git/scratch.d.ts +17 -0
  186. package/build/src/git/scratch.js +73 -0
  187. package/build/src/git/target-placement.d.ts +92 -0
  188. package/build/src/git/target-placement.js +375 -0
  189. package/build/src/git/tender.d.ts +49 -0
  190. package/build/src/git/tender.js +63 -0
  191. package/build/src/git/terminal-seal.d.ts +24 -0
  192. package/build/src/git/terminal-seal.js +89 -0
  193. package/build/src/git/tree.d.ts +2 -2
  194. package/build/src/git/tree.js +4 -0
  195. package/build/src/git/workspace.d.ts +53 -0
  196. package/build/src/git/workspace.js +139 -0
  197. package/build/src/identity/selector.d.ts +6 -0
  198. package/build/src/identity/selector.js +19 -0
  199. package/build/src/index.d.ts +4 -2
  200. package/build/src/index.js +2 -1
  201. package/build/src/kanshi/index.d.ts +2 -2
  202. package/build/src/kanshi/index.js +1 -1
  203. package/build/src/kanshi/read.d.ts +7 -3
  204. package/build/src/kanshi/read.js +245 -45
  205. package/build/src/kanshi/report.d.ts +81 -6
  206. package/build/src/kanshi/select.d.ts +5 -0
  207. package/build/src/kanshi/select.js +33 -1
  208. package/build/src/library/address.d.ts +57 -0
  209. package/build/src/library/address.js +165 -0
  210. package/build/src/library/akuma-creation.d.ts +16 -7
  211. package/build/src/library/akuma-creation.js +96 -22
  212. package/build/src/library/audit.d.ts +18 -0
  213. package/build/src/library/audit.js +44 -0
  214. package/build/src/library/bind.d.ts +21 -0
  215. package/build/src/library/bind.js +56 -0
  216. package/build/src/library/catalog.d.ts +58 -0
  217. package/build/src/library/catalog.js +69 -0
  218. package/build/src/library/configuration.d.ts +6 -15
  219. package/build/src/library/configuration.js +14 -17
  220. package/build/src/library/contract.d.ts +23 -49
  221. package/build/src/library/contract.js +171 -185
  222. package/build/src/library/delivery.d.ts +24 -0
  223. package/build/src/library/delivery.js +21 -0
  224. package/build/src/library/fleet.d.ts +65 -0
  225. package/build/src/library/fleet.js +153 -0
  226. package/build/src/library/input.d.ts +3 -0
  227. package/build/src/library/input.js +19 -0
  228. package/build/src/library/keiyaku.d.ts +18 -3
  229. package/build/src/library/keiyaku.js +12 -1
  230. package/build/src/library/mutation.d.ts +39 -0
  231. package/build/src/library/mutation.js +37 -0
  232. package/build/src/library/reconcile.d.ts +29 -0
  233. package/build/src/library/reconcile.js +179 -0
  234. package/build/src/library/refusal.d.ts +21 -0
  235. package/build/src/library/refusal.js +29 -0
  236. package/build/src/library/region.d.ts +14 -1
  237. package/build/src/library/region.js +18 -4
  238. package/build/src/library/repo.d.ts +4 -13
  239. package/build/src/library/repo.js +14 -24
  240. package/build/src/protocol/attempt.d.ts +16 -3
  241. package/build/src/protocol/attempt.js +41 -10
  242. package/build/src/protocol/bind.d.ts +9 -2
  243. package/build/src/protocol/bind.js +48 -40
  244. package/build/src/protocol/intent.d.ts +57 -20
  245. package/build/src/protocol/intent.js +55 -79
  246. package/build/src/protocol/operations.d.ts +152 -43
  247. package/build/src/protocol/operations.js +482 -166
  248. package/build/src/protocol/outcome.d.ts +14 -3
  249. package/build/src/protocol/outcome.js +11 -3
  250. package/build/src/protocol/placement.d.ts +41 -0
  251. package/build/src/protocol/placement.js +147 -0
  252. package/build/src/protocol/read/documents.d.ts +2 -2
  253. package/build/src/protocol/read/documents.js +4 -4
  254. package/build/src/protocol/read/status.d.ts +18 -5
  255. package/build/src/protocol/read/status.js +73 -13
  256. package/build/src/protocol/run.d.ts +49 -7
  257. package/build/src/protocol/run.js +53 -25
  258. package/build/src/runtime/proc/line-rpc.d.ts +4 -8
  259. package/build/src/runtime/proc/line-rpc.js +22 -28
  260. package/build/src/runtime/proc/run.d.ts +23 -21
  261. package/build/src/runtime/proc/run.js +123 -89
  262. package/build/src/runtime/proc/stdio.d.ts +18 -0
  263. package/build/src/runtime/proc/stdio.js +58 -0
  264. package/build/src/settings.d.ts +7 -1
  265. package/build/src/settings.js +32 -17
  266. package/build/src/settlement/fence.d.ts +5 -0
  267. package/build/src/settlement/fence.js +14 -0
  268. package/build/src/settlement/holder.d.ts +35 -4
  269. package/build/src/settlement/holder.js +127 -28
  270. package/build/src/settlement/settle.d.ts +9 -1
  271. package/build/src/settlement/settle.js +74 -37
  272. package/build/src/task/board.d.ts +23 -5
  273. package/build/src/task/board.js +17 -10
  274. package/build/src/task/compose.d.ts +2 -2
  275. package/build/src/task/compose.js +18 -10
  276. package/build/src/task/context.d.ts +3 -3
  277. package/build/src/task/context.js +15 -20
  278. package/build/src/task/document.d.ts +2 -1
  279. package/build/src/task/document.js +15 -5
  280. package/build/src/task/index.d.ts +27 -15
  281. package/build/src/task/index.js +57 -35
  282. package/build/src/task/operations.d.ts +38 -13
  283. package/build/src/task/operations.js +80 -46
  284. package/build/src/task/query.d.ts +67 -0
  285. package/build/src/task/query.js +279 -0
  286. package/build/src/task/store.d.ts +5 -7
  287. package/build/src/task/store.js +43 -28
  288. package/build/src/verification/declaration.d.ts +1 -0
  289. package/build/src/verification/execution.d.ts +51 -0
  290. package/build/src/verification/execution.js +108 -0
  291. package/build/src/workspace-place.d.ts +41 -0
  292. package/build/src/workspace-place.js +386 -0
  293. package/build/src/world.d.ts +24 -0
  294. package/build/src/world.js +136 -0
  295. package/package.json +8 -4
  296. package/build/src/akuma/activity.d.ts +0 -66
  297. package/build/src/akuma/activity.js +0 -139
  298. package/build/src/akuma/providers/claude.js +0 -305
  299. package/build/src/context-root.d.ts +0 -4
  300. package/build/src/context-root.js +0 -15
  301. package/build/src/git/delivery.d.ts +0 -20
  302. package/build/src/git/delivery.js +0 -109
  303. package/build/src/git/verification.d.ts +0 -14
  304. package/build/src/git/verification.js +0 -56
  305. package/build/src/protocol/read/audit.d.ts +0 -25
  306. package/build/src/protocol/read/audit.js +0 -39
  307. package/build/src/verification/producer.d.ts +0 -23
  308. package/build/src/verification/producer.js +0 -54
@@ -1,52 +1,89 @@
1
- import { type GitDecisionObservation } from "../git/observe.js";
1
+ import type { GitDecisionObservation } from "../git/observe.js";
2
+ import type { GitDecodeChannel, GitTreeSelection } from "../git/read-observation.js";
2
3
  import type { GitRepository } from "../git/repository.js";
3
- import type { WorktreeLeak } from "../git/verification.js";
4
- import type { AttemptContext, DecideInput, OfferDecision } from "../core/decide.js";
5
- import type { ActorId, ContractId, ContractState } from "../core/facts/types.js";
6
- import { type PlacementRefusal } from "../core/verbs/placement.js";
4
+ import type { GitRefAssertion } from "../git/repository.js";
5
+ import { type WorktreeLeak } from "../git/scratch.js";
6
+ import type { HookFailure } from "../git/hooks.js";
7
+ import type { DecideInput, OfferDecision } from "../core/decide.js";
8
+ import type { ActorId, ContractId, ContractState, EntryUlid, SnapshotId } from "../core/facts/types.js";
7
9
  import { type AttestationRefusal } from "../core/verbs/attestation.js";
8
- import { type ProduceVerificationInput, type VerificationOutcome } from "../verification/producer.js";
9
10
  import { type VerificationDefinition } from "../verification/declaration.js";
10
11
  import { type CompanionDecorator, type ProtocolResult } from "./run.js";
11
- export declare function mintAttempts(input: Readonly<{
12
- entryCount: number;
13
- }>): readonly AttemptContext[];
14
- type IntentAdmissionOptions = Readonly<{
12
+ type IntentAdmissionOptions<Input, Refusal, Seed> = Readonly<{
15
13
  observedContracts?: readonly ContractId[];
16
- observe?: (repository: GitRepository, contracts: readonly ContractId[]) => GitDecisionObservation;
14
+ observe?: (repository: GitRepository, channel: GitDecodeChannel, contracts: readonly ContractId[]) => Promise<GitDecisionObservation>;
17
15
  decorateOffer?: CompanionDecorator;
16
+ observationSelection?: GitTreeSelection;
17
+ prepareInput?: (observation: GitDecisionObservation, input: Seed) => Readonly<{
18
+ kind: "prepared";
19
+ input: Input;
20
+ assertions?: readonly GitRefAssertion[];
21
+ }> | Readonly<{
22
+ kind: "refused";
23
+ refusal: Refusal;
24
+ }> | Promise<Readonly<{
25
+ kind: "prepared";
26
+ input: Input;
27
+ assertions?: readonly GitRefAssertion[];
28
+ }> | Readonly<{
29
+ kind: "refused";
30
+ refusal: Refusal;
31
+ }>>;
18
32
  }>;
19
33
  /** Observe, decide, and atomically admit one intent with bounded Git retries. */
20
34
  export declare function admitIntent<Input extends Readonly<{
21
35
  contractId: ContractId;
22
- }>, Refusal>(repository: GitRepository, input: Input, decide: (input: DecideInput<Input>) => OfferDecision<Refusal>, options?: IntentAdmissionOptions): ProtocolResult<Refusal>;
23
- /** Run the sole placement adjudicator; a gates-unsatisfied refusal is normal pending state. */
24
- export declare function admitPlacement(repository: GitRepository, input: Readonly<{
36
+ }>, Refusal, Seed extends Readonly<{
25
37
  contractId: ContractId;
26
- actor?: ActorId;
27
- at: string;
28
- }>): ProtocolResult<PlacementRefusal>;
38
+ }> = Input>(channel: GitDecodeChannel, repository: GitRepository, input: Seed, decide: (input: DecideInput<Input>) => OfferDecision<Refusal>, options?: IntentAdmissionOptions<Input, Refusal, Seed>): Promise<ProtocolResult<Refusal>>;
29
39
  type VerifyDeliveryInput = Readonly<{
40
+ channel: GitDecodeChannel;
30
41
  repository: GitRepository;
31
42
  contractId: ContractId;
32
43
  actor?: ActorId;
33
44
  at: string;
34
45
  state: ContractState;
46
+ snapshot?: SnapshotId;
35
47
  environment: NodeJS.ProcessEnv;
36
- produce: (input: ProduceVerificationInput) => Promise<VerificationOutcome>;
48
+ signal?: AbortSignal;
37
49
  verification?: VerificationDefinition;
38
50
  }>;
39
51
  export type VerificationRuntimeStop = Readonly<{
40
- failure: "timeout" | "unknown-exit";
52
+ failure: "unknown-exit" | "cancelled";
41
53
  }> | Readonly<{
42
54
  failure: "candidate-unavailable" | "spawn-error";
43
55
  diagnostic: string;
56
+ }> | Readonly<{
57
+ failure: "environment-failure";
58
+ diagnostic: string;
59
+ }> | Readonly<{
60
+ failure: "environment-failure";
61
+ command: number;
62
+ detail: HookFailure;
63
+ }>;
64
+ export type VerificationCleanupFailure = Readonly<{
65
+ phase: "destroy";
66
+ command: number;
67
+ detail: HookFailure;
44
68
  }>;
45
69
  export type VerificationStep = ProtocolResult<AttestationRefusal> | VerificationRuntimeStop;
46
70
  export type VerificationResult = Readonly<{
47
71
  step: VerificationStep;
72
+ counts?: Readonly<{
73
+ passed: number;
74
+ total: number;
75
+ verdict: "satisfied" | "unsatisfied";
76
+ summary?: string;
77
+ }>;
78
+ cleanup?: VerificationCleanupFailure;
48
79
  leak?: WorktreeLeak;
49
80
  }>;
50
- /** Run Verification for an observed delivery, then tender its fact. */
81
+ export type CurrentVerifiedAttestation = Readonly<{
82
+ entry: EntryUlid;
83
+ verdict: "satisfied" | "unsatisfied";
84
+ }>;
85
+ /** Read the latest current verified attestation through the generic currentness judge. */
86
+ export declare function currentVerifiedAttestation(state: ContractState): CurrentVerifiedAttestation | undefined;
87
+ /** Run Verification against an explicit or admitted integration snapshot. */
51
88
  export declare function verifyDelivery(input: VerifyDeliveryInput): Promise<VerificationResult | null>;
52
89
  export {};
@@ -1,63 +1,26 @@
1
- import { randomBytes } from "node:crypto";
2
- import { observeGitForAdmission } from "../git/observe.js";
3
- import { materializeVerificationCandidate } from "../git/verification.js";
1
+ import { materializeScratchCandidate } from "../git/scratch.js";
2
+ import { projectSettings } from "../settings.js";
4
3
  import { dependencyKeySet } from "../core/subject.js";
5
- import { entryUlid } from "../core/facts/types.js";
6
- import { decidePlacement } from "../core/verbs/placement.js";
4
+ import { latestCurrentAttestations } from "../core/facts/gate.js";
7
5
  import { decideAttestation } from "../core/verbs/attestation.js";
6
+ import { executeVerification } from "../verification/execution.js";
8
7
  import { VERIFIED } from "../verification/declaration.js";
9
8
  import { runProtocol } from "./run.js";
10
- const ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
11
- const VERIFICATION_TIMEOUT_MS = 5 * 60 * 1_000;
12
- function nextEntryUlid() {
13
- let value = "";
14
- let time = BigInt(Date.now());
15
- for (let index = 0; index < 10; index += 1) {
16
- value = ALPHABET[Number(time & 31n)] + value;
17
- time >>= 5n;
18
- }
19
- let random = BigInt(`0x${randomBytes(10).toString("hex")}`);
20
- for (let index = 0; index < 16; index += 1) {
21
- value += ALPHABET[Number(random & 31n)];
22
- random >>= 5n;
23
- }
24
- return entryUlid(value);
25
- }
26
- const MAX_SEMANTIC_ATTEMPTS = 3;
27
- export function mintAttempts(input) {
28
- return Array.from({ length: MAX_SEMANTIC_ATTEMPTS }, () => ({
29
- entryUlids: Array.from({ length: input.entryCount }, nextEntryUlid),
30
- }));
31
- }
9
+ import { mintAttempts } from "./attempt.js";
32
10
  /** Observe, decide, and atomically admit one intent with bounded Git retries. */
33
- export function admitIntent(repository, input, decide, options = {}) {
11
+ export function admitIntent(channel, repository, input, decide, options = {}) {
34
12
  const contracts = options.observedContracts ?? [input.contractId];
35
13
  return runProtocol({
36
14
  input,
15
+ channel,
37
16
  repository,
38
17
  contracts,
39
18
  attempts: mintAttempts({ entryCount: 2 }),
40
19
  decide,
41
20
  ...(options.observe === undefined ? {} : { observe: options.observe }),
42
21
  ...(options.decorateOffer === undefined ? {} : { decorateOffer: options.decorateOffer }),
43
- });
44
- }
45
- /** Run the sole placement adjudicator; a gates-unsatisfied refusal is normal pending state. */
46
- export function admitPlacement(repository, input) {
47
- return runProtocol({
48
- input,
49
- repository,
50
- contracts: [input.contractId],
51
- attempts: mintAttempts({ entryCount: 2 }),
52
- observe: observeGitForAdmission,
53
- extendAttempt: (attempt, observedContractCount) => ({
54
- ...attempt,
55
- entryUlids: [
56
- ...attempt.entryUlids,
57
- ...Array.from({ length: Math.max(0, observedContractCount - attempt.entryUlids.length) }, nextEntryUlid),
58
- ],
59
- }),
60
- decide: decidePlacement,
22
+ ...(options.observationSelection === undefined ? {} : { observationSelection: options.observationSelection }),
23
+ ...(options.prepareInput === undefined ? {} : { prepareInput: options.prepareInput }),
61
24
  });
62
25
  }
63
26
  function runtimeStop(outcome) {
@@ -81,49 +44,62 @@ function verificationInput(outcome, input, subject) {
81
44
  },
82
45
  };
83
46
  }
84
- /** Run Verification for an observed delivery, then tender its fact. */
47
+ /** Read the latest current verified attestation through the generic currentness judge. */
48
+ export function currentVerifiedAttestation(state) {
49
+ const current = latestCurrentAttestations(state, new Set([VERIFIED])).get(VERIFIED);
50
+ return current === undefined ? undefined : { entry: current.entry, verdict: current.data.verdict };
51
+ }
52
+ /** Run Verification against an explicit or admitted integration snapshot. */
85
53
  export async function verifyDelivery(input) {
86
- const state = input.state;
87
- if (state.delivery === null
88
- || input.verification === undefined)
54
+ const snapshot = input.snapshot ?? input.state.delivery?.data.integration.snapshot;
55
+ if (snapshot === undefined || input.verification === undefined)
89
56
  return null;
90
57
  const subject = dependencyKeySet([
91
- { kind: "snapshot", value: state.delivery.data.candidate },
58
+ { kind: "snapshot", value: snapshot },
92
59
  { kind: "segment", value: input.verification.segment },
93
60
  ]);
94
- let prepared;
95
- try {
96
- prepared = materializeVerificationCandidate(input.repository, state.delivery.data.candidate);
61
+ const execution = await executeVerification({
62
+ repository: input.repository,
63
+ candidate: snapshot,
64
+ declarations: input.verification.declarations,
65
+ environment: input.environment,
66
+ materializeScratchCandidate,
67
+ projectSettings,
68
+ ...(input.signal === undefined ? {} : { signal: input.signal }),
69
+ });
70
+ let step;
71
+ if (execution.outcome.kind === "terminal") {
72
+ step = await admitIntent(input.channel, input.repository, verificationInput(execution.outcome, input, subject), decideAttestation);
97
73
  }
98
- catch (error) {
99
- return {
100
- step: {
101
- failure: "candidate-unavailable",
102
- diagnostic: error instanceof Error ? error.message : String(error),
103
- },
104
- };
74
+ else if (execution.outcome.kind === "candidate-unavailable") {
75
+ step = { failure: "candidate-unavailable", diagnostic: execution.outcome.diagnostic };
105
76
  }
106
- let step;
107
- let leak = null;
108
- try {
109
- const outcome = await input.produce({
110
- declarations: input.verification.declarations,
111
- cwd: prepared.cwd,
112
- timeoutMs: VERIFICATION_TIMEOUT_MS,
113
- env: input.environment,
114
- });
115
- if (outcome.kind === "terminal") {
116
- step = admitIntent(input.repository, verificationInput(outcome, input, subject), decideAttestation);
117
- }
118
- else {
119
- step = runtimeStop(outcome);
120
- }
77
+ else if (execution.outcome.kind === "environment-failure") {
78
+ step = "diagnostic" in execution.outcome
79
+ ? { failure: "environment-failure", diagnostic: execution.outcome.diagnostic }
80
+ : { failure: "environment-failure", command: execution.outcome.command, detail: execution.outcome.detail };
81
+ }
82
+ else if (execution.outcome.kind === "unknown-exit"
83
+ || execution.outcome.kind === "cancelled"
84
+ || execution.outcome.kind === "spawn-error") {
85
+ step = runtimeStop(execution.outcome);
121
86
  }
122
- finally {
123
- leak = prepared.dispose();
87
+ else {
88
+ throw new Error("Verification execution returned an invalid outcome");
124
89
  }
125
90
  return {
126
91
  step,
127
- ...(leak === null ? {} : { leak }),
92
+ ...(execution.outcome.kind === "terminal"
93
+ ? {
94
+ counts: {
95
+ passed: execution.outcome.passed,
96
+ total: execution.outcome.total,
97
+ verdict: execution.outcome.verdict,
98
+ ...(execution.outcome.summary === undefined ? {} : { summary: execution.outcome.summary }),
99
+ },
100
+ }
101
+ : {}),
102
+ ...(execution.cleanup === undefined ? {} : { cleanup: execution.cleanup }),
103
+ ...(execution.leak === undefined ? {} : { leak: execution.leak }),
128
104
  };
129
105
  }
@@ -1,9 +1,11 @@
1
- import { type DeliveryPreparationRefusal, type ReviewPreparationRefusal } from "../git/delivery.js";
1
+ import { type DeliveryDiffScope, type IntegrationPreparationRefusal } from "../git/integration.js";
2
+ import { type DirtyWorkspaceRefusal, type WorkspaceDirtyDelta } from "../git/tender.js";
2
3
  import { type ReconcileResult } from "../git/reconcile.js";
3
4
  import type { WorktreeHooks } from "../git/hooks.js";
4
5
  import { NoGitWorldError, type GitRepository } from "../git/repository.js";
5
- import type { WorktreeLeak } from "../git/verification.js";
6
- import type { ActorId, AmendData, ArcData, AttestationData, ChangeId, ContractId, ContractState, ContractTerms, DocumentKey, SnapshotId } from "../core/facts/types.js";
6
+ import { type GitDecodeChannel, type GitTreeSelection } from "../git/read-observation.js";
7
+ 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";
7
9
  import { type AbandonRefusal } from "../core/verbs/abandon.js";
8
10
  import { type AmendRefusal } from "../core/verbs/amend.js";
9
11
  import { type ArcRefusal } from "../core/verbs/arc.js";
@@ -11,17 +13,27 @@ import { type DeliverRefusal } from "../core/verbs/deliver.js";
11
13
  import type { PlacementRefusal } from "../core/verbs/placement.js";
12
14
  import { type AttestationRefusal } from "../core/verbs/attestation.js";
13
15
  import type { VerificationDeclarationPreparation, VerificationDeclarationRefusal } from "../verification/declaration.js";
14
- import { type VerificationRuntimeStop } from "./intent.js";
15
- import { type AuditReport as AuditReadReport } from "./read/audit.js";
16
+ import { type CurrentVerifiedAttestation, type VerificationRuntimeStop, type VerificationCleanupFailure } from "./intent.js";
17
+ import { type AuditTargetAnswer, type TargetPlacementRefusal } from "../git/target-placement.js";
16
18
  import { type ContractDocumentProjection } from "./read/documents.js";
17
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";
18
21
  export { bindOperation } from "./bind.js";
22
+ export { reconcileObservationFailure } from "../git/reconcile.js";
19
23
  import type { BindRefusal, TargetInputRefusal } from "./bind.js";
20
24
  import { type IntentOutcome as ProtocolIntentOutcome } from "./outcome.js";
21
25
  import type { ProtocolTerminal } from "./run.js";
22
26
  import type { CompanionDecorator } from "./run.js";
23
- export type { FactKind, TimelineEntry } from "./read/audit.js";
27
+ export type { FactKind } from "../core/facts/types.js";
24
28
  export type { ContractDocumentProjection } from "./read/documents.js";
29
+ export type DeliveryPreparationRefusal = Readonly<{
30
+ kind: "target-missing" | "worktree-missing";
31
+ contractId: ContractId;
32
+ }> | DirtyWorkspaceRefusal | IntegrationPreparationRefusal | TargetPlacementRefusal;
33
+ type ReviewPreparationRefusal = Readonly<{
34
+ kind: "worktree-missing";
35
+ contractId: ContractId;
36
+ }> | DirtyWorkspaceRefusal;
25
37
  type ReviewRefusal = AttestationRefusal | ReviewPreparationRefusal;
26
38
  export type IntentRefusal = AbandonRefusal | AmendRefusal | ArcRefusal | BindRefusal | DeliverRefusal | DeliveryPreparationRefusal | PlacementRefusal | ReviewRefusal | TargetInputRefusal | VerificationDeclarationRefusal;
27
39
  export type { TargetInputRefusal } from "./bind.js";
@@ -32,10 +44,50 @@ type OperationInput = Readonly<{
32
44
  contractId: ContractId;
33
45
  actor?: ActorId;
34
46
  }>;
35
- export type AuditReport = AuditReadReport & Readonly<{
36
- attempt?: VerificationStop;
37
- leak?: WorktreeLeak;
47
+ type MutationOperationInput = OperationInput & Readonly<{
48
+ channel: GitDecodeChannel;
49
+ }>;
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
+ }>;
38
89
  }>;
90
+ export type VerificationReuse = CurrentVerifiedAttestation;
39
91
  export type DocumentDerivation = Readonly<{
40
92
  document: DocumentKey;
41
93
  title: string;
@@ -49,74 +101,123 @@ export type StepStop<R> = Readonly<{
49
101
  refusal?: never;
50
102
  }>;
51
103
  export type VerificationStop = StepStop<AttestationRefusal> | VerificationRuntimeStop;
52
- export type PlacementStop = StepStop<PlacementRefusal>;
104
+ export type PlacementStop = StepStop<PlacementRefusal | TargetPlacementRefusal | IntegrationPreparationRefusal> | Readonly<{
105
+ failure: "target-moved";
106
+ contractId: ContractId;
107
+ target: string;
108
+ expected: SnapshotId;
109
+ observed: SnapshotId | null;
110
+ }> | Readonly<{
111
+ failure: "target-placement-failed";
112
+ diagnostic: string;
113
+ }>;
53
114
  type ScopeOperationInput = Readonly<{
54
115
  coordinate: string;
55
116
  }>;
56
117
  export type RepositoryScope = GitRepository;
57
118
  export { NoGitWorldError };
58
- export declare function scopeOperation(input: ScopeOperationInput): RepositoryScope;
119
+ export declare function scopeOperation(input: ScopeOperationInput): Promise<RepositoryScope>;
59
120
  export declare function currentBranchOperation(input: Readonly<{
60
121
  scope: RepositoryScope;
61
- }>): string | null;
122
+ }>): Promise<string | null>;
62
123
  export declare function contractsOperation(input: Readonly<{
63
124
  scope: RepositoryScope;
64
- }>): ContractBoard;
65
- export declare function contractObservationOperation(input: OperationInput): ContractObservation;
125
+ channel: GitDecodeChannel;
126
+ }>): Promise<ContractBoard>;
127
+ export declare function contractObservationOperation(input: MutationOperationInput): Promise<ContractObservation>;
66
128
  export type { ContractBoard, ContractDisposition, ContractGateCurrent, ContractGateReport, ContractObservation, ContractPhase, ContractRow };
67
- export declare function documentsOperation(input: Readonly<{
68
- scope: RepositoryScope;
69
- }>): readonly ContractDocumentProjection[];
70
- export declare function stateOperation(input: OperationInput): ContractState;
71
- export declare function readStateOperation(input: OperationInput): ContractState | null;
72
- type DeliveryIdentity = Readonly<{
73
- snapshotId: SnapshotId;
74
- changeId: ChangeId;
75
- expectedPredecessor: SnapshotId;
76
- }>;
77
- export declare function deliveryOperation(input: OperationInput): DeliveryIdentity | null;
129
+ export declare function documentsOperationAt(scope: RepositoryScope, channel: GitDecodeChannel): Promise<readonly ContractDocumentProjection[]>;
130
+ export declare function stateOperation(input: MutationOperationInput): Promise<ContractState>;
131
+ type DeliveryIdentity = DeliverData;
132
+ export declare function deliveryOperation(input: MutationOperationInput): Promise<DeliveryIdentity | null>;
78
133
  type DeliveryDiffOperationInput = Readonly<{
79
134
  scope: RepositoryScope;
80
- expectedPredecessor: SnapshotId;
81
- snapshotId: SnapshotId;
135
+ integrationPredecessor: SnapshotId;
136
+ integrationSnapshot: SnapshotId;
82
137
  }>;
83
138
  export declare function deliveryDiffOperation(input: DeliveryDiffOperationInput): Promise<string | null>;
84
- type AmendOperationInput = OperationInput & Readonly<{
85
- amendment?: Readonly<{
86
- source: ContractTerms;
139
+ type AmendOperationInput = MutationOperationInput & Readonly<{
140
+ source?: ContractTerms;
141
+ deriveAmendment?: (source: ContractTerms) => Readonly<{
87
142
  terms: AmendData;
88
143
  verification: VerificationDeclarationPreparation;
89
144
  }>;
90
145
  }>;
91
- export declare function amendOperation(input: AmendOperationInput): IntentOutcome<void, AmendRefusal | VerificationDeclarationRefusal>;
146
+ type Amendment = Readonly<{
147
+ source: ContractTerms;
148
+ }> & ReturnType<NonNullable<AmendOperationInput["deriveAmendment"]>>;
149
+ export declare function amendOperation(input: AmendOperationInput): Promise<IntentOutcome<Amendment, AmendRefusal | VerificationDeclarationRefusal>>;
92
150
  export type DeliverValue = DeliveryIdentity & Readonly<{
93
151
  verification?: VerificationStop;
152
+ verificationReuse?: VerificationReuse;
94
153
  placement?: PlacementStop;
154
+ cleanup?: VerificationCleanupFailure;
95
155
  leak?: WorktreeLeak;
96
156
  }>;
97
- type DeliverOperationInput = OperationInput & Readonly<{
98
- derivation?: DocumentDerivation;
157
+ type DeliverOperationInput = MutationOperationInput & Readonly<{
158
+ deriveDocument?: (state: ContractState) => DocumentDerivation;
99
159
  message?: string;
160
+ requireBranchesToBeUpToDate: boolean;
161
+ includeDirty: boolean;
162
+ signal?: AbortSignal;
163
+ }>;
164
+ export declare function prepareDelivery(repository: GitRepository, stage: Readonly<{
165
+ contractId: ContractId;
166
+ coordinates: ContractState["coordinates"];
167
+ appointment?: Extract<ManagedWorktreeAppointment, {
168
+ kind: "appointed";
169
+ }>;
170
+ }>, input: Readonly<{
171
+ title: string;
172
+ message?: string;
173
+ requireBranchesToBeUpToDate?: boolean;
174
+ includeDirty?: boolean;
175
+ }>): Promise<{
176
+ kind: "prepared";
177
+ data: DeliverData;
178
+ } | {
179
+ kind: "refused";
180
+ refusal: DeliveryPreparationRefusal;
181
+ }>;
182
+ export declare function prepareReview(repository: GitRepository, stage: Readonly<{
183
+ contractId: ContractId;
184
+ coordinates: ContractState["coordinates"];
185
+ }>): Promise<{
186
+ kind: "prepared";
187
+ data: Readonly<{
188
+ changeId: DeliverData["integration"]["changeId"];
189
+ workspace?: WorkspaceDirtyDelta;
190
+ }>;
191
+ } | {
192
+ kind: "refused";
193
+ refusal: ReviewPreparationRefusal;
100
194
  }>;
101
195
  export declare function deliverOperation(input: DeliverOperationInput): Promise<IntentOutcome<DeliverValue>>;
102
- export declare function abandonOperation(input: OperationInput & Readonly<{
196
+ export declare function abandonOperation(input: MutationOperationInput & Readonly<{
103
197
  note?: string;
104
198
  decorateOffer?: CompanionDecorator;
105
- }>): IntentOutcome<void, AbandonRefusal>;
106
- export declare function arcOperation(input: OperationInput & Readonly<{
199
+ observationSelection?: GitTreeSelection;
200
+ }>): Promise<IntentOutcome<void, AbandonRefusal>>;
201
+ export declare function arcOperation(input: MutationOperationInput & Readonly<{
107
202
  chapter: Omit<ArcData, "seq">;
108
- }>): IntentOutcome<void, ArcRefusal>;
109
- type ReviewOperationInput = OperationInput & Readonly<{
203
+ }>): Promise<IntentOutcome<void, ArcRefusal>>;
204
+ type ReviewOperationInput = MutationOperationInput & Readonly<{
110
205
  verdict: AttestationData["verdict"];
111
206
  summary?: string;
112
207
  }>;
113
208
  export type ReviewValue = Readonly<{
114
209
  placement?: PlacementStop;
210
+ workspace?: WorkspaceDirtyDelta;
115
211
  }>;
116
- export declare function reviewOperation(input: ReviewOperationInput): IntentOutcome<ReviewValue, ReviewRefusal>;
117
- export declare function auditOperation(input: OperationInput & Readonly<{
118
- derivation?: DocumentDerivation;
119
- }>): Promise<IntentOutcome<AuditReport>>;
212
+ export declare function reviewOperation(input: ReviewOperationInput): Promise<IntentOutcome<ReviewValue, ReviewRefusal>>;
213
+ type AuditOperationInput = MutationOperationInput & Readonly<{
214
+ deriveDocument?: (state: ContractState) => DocumentDerivation;
215
+ requireBranchesToBeUpToDate?: boolean;
216
+ includeDirty?: boolean;
217
+ showDiff?: boolean;
218
+ signal?: AbortSignal;
219
+ }>;
220
+ export declare function auditOperation(input: AuditOperationInput): Promise<IntentOutcome<AuditReport>>;
120
221
  export type ReconcileReport = ReconcileResult;
121
222
  export type ReconcileObservation = Readonly<{
122
223
  state: ContractState | null;
@@ -125,8 +226,11 @@ export type ReconcileObservation = Readonly<{
125
226
  type ReconcileOptions = Readonly<{
126
227
  hooks: WorktreeHooks;
127
228
  retryHooks: boolean;
229
+ retainTerminalWorktree?: boolean;
230
+ place?: string;
231
+ places?: ReadonlyMap<ContractId, string>;
128
232
  }>;
129
- export declare function reconcileOperation(input: OperationInput & ReconcileOptions): Promise<ReconcileObservation>;
233
+ export declare function reconcileOperation(input: MutationOperationInput & ReconcileOptions): Promise<ReconcileObservation>;
130
234
  type RepoReconcileItem = Readonly<{
131
235
  contractId: ContractId;
132
236
  state: ContractState | null;
@@ -135,6 +239,11 @@ type RepoReconcileItem = Readonly<{
135
239
  export type RepoReconcileReport = Readonly<{
136
240
  contracts: readonly RepoReconcileItem[];
137
241
  }>;
242
+ export declare function worldContractStates(input: Readonly<{
243
+ scope: RepositoryScope;
244
+ channel: GitDecodeChannel;
245
+ }>): Promise<readonly ContractState[]>;
138
246
  export declare function reconcileAllOperation(input: Readonly<{
139
247
  scope: RepositoryScope;
248
+ channel: GitDecodeChannel;
140
249
  }> & ReconcileOptions): Promise<RepoReconcileReport>;