@astrosheep/keiyaku 4.6.32 → 4.6.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/README.md +18 -7
  2. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +18 -11
  3. package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +8 -6
  4. package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +2 -1
  5. package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +2 -1
  6. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +18 -11
  7. package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +8 -6
  8. package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +2 -1
  9. package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +2 -1
  10. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +18 -11
  11. package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +8 -6
  12. package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +2 -1
  13. package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +2 -1
  14. package/build/plugins/pi/README.md +55 -97
  15. package/build/plugins/pi/keiyaku.ts +1 -142
  16. package/build/skills/keiyaku-akuma/SKILL.md +18 -11
  17. package/build/skills/keiyaku-babysit/SKILL.md +8 -6
  18. package/build/skills/keiyaku-debt/SKILL.md +2 -1
  19. package/build/skills/keiyaku-workflow/SKILL.md +2 -1
  20. package/build/src/akuma/akuma-instance.d.ts +11 -0
  21. package/build/src/akuma/akuma-instance.js +1 -2
  22. package/build/src/akuma/akuma-observe.d.ts +8 -0
  23. package/build/src/akuma/akuma-observe.js +81 -14
  24. package/build/src/akuma/akuma-owner.d.ts +1 -0
  25. package/build/src/akuma/akuma-owner.js +3 -5
  26. package/build/src/akuma/akuma-selection-execution.d.ts +82 -7
  27. package/build/src/akuma/akuma-selection-execution.js +26 -27
  28. package/build/src/akuma/akuma-wait.d.ts +155 -1
  29. package/build/src/akuma/akuma-wait.js +94 -34
  30. package/build/src/akuma/akuma.d.ts +17 -1
  31. package/build/src/akuma/akuma.js +37 -18
  32. package/build/src/akuma/body.js +13 -18
  33. package/build/src/akuma/call-initial-tell.d.ts +0 -1
  34. package/build/src/akuma/call-initial-tell.js +0 -1
  35. package/build/src/akuma/heart/activity-schema.d.ts +16 -0
  36. package/build/src/akuma/heart/activity-schema.js +7 -0
  37. package/build/src/akuma/heart/facts.d.ts +1 -0
  38. package/build/src/akuma/heart/facts.js +14 -0
  39. package/build/src/akuma/heart/index.d.ts +7 -1
  40. package/build/src/akuma/heart/index.js +35 -9
  41. package/build/src/akuma/heart/rows.d.ts +1 -0
  42. package/build/src/akuma/heart/rows.js +4 -0
  43. package/build/src/akuma/heart/timeline.js +4 -4
  44. package/build/src/akuma/lineage-cache.d.ts +7 -2
  45. package/build/src/akuma/lineage-cache.js +48 -24
  46. package/build/src/akuma/projection-read.d.ts +4 -2
  47. package/build/src/akuma/projection-read.js +25 -23
  48. package/build/src/akuma/projection.d.ts +94 -2
  49. package/build/src/akuma/projection.js +47 -47
  50. package/build/src/akuma/provider.d.ts +2 -2
  51. package/build/src/akuma/provider.js +27 -20
  52. package/build/src/akuma/providers/acp/core.js +2 -5
  53. package/build/src/akuma/providers/opencode-sdk/events.d.ts +2 -1
  54. package/build/src/akuma/providers/opencode-sdk/events.js +31 -1
  55. package/build/src/akuma/publication.js +3 -2
  56. package/build/src/akuma/selection-observation.d.ts +645 -0
  57. package/build/src/akuma/selection-observation.js +22 -7
  58. package/build/src/akuma/status-projection.d.ts +14 -1
  59. package/build/src/akuma/status-projection.js +40 -2
  60. package/build/src/akuma/turn-drive.js +21 -15
  61. package/build/src/body/amend.js +5 -17
  62. package/build/src/body/decode.js +11 -1
  63. package/build/src/body/envelope.d.ts +5 -1
  64. package/build/src/body/envelope.js +4 -2
  65. package/build/src/body/render.js +4 -6
  66. package/build/src/bounded-list.d.ts +8 -0
  67. package/build/src/bounded-list.js +10 -0
  68. package/build/src/cli/commands/akuma-grammar.d.ts +5 -8
  69. package/build/src/cli/commands/akuma-grammar.js +52 -77
  70. package/build/src/cli/commands/akuma.d.ts +1 -2
  71. package/build/src/cli/commands/akuma.js +12 -61
  72. package/build/src/cli/commands/contract-grammar.d.ts +1 -0
  73. package/build/src/cli/commands/contract-grammar.js +39 -42
  74. package/build/src/cli/commands/contract-help.d.ts +6 -5
  75. package/build/src/cli/commands/contract-help.js +21 -13
  76. package/build/src/cli/commands/contract.d.ts +3 -3
  77. package/build/src/cli/commands/contract.js +13 -9
  78. package/build/src/cli/commands/debt-grammar.js +2 -4
  79. package/build/src/cli/parse.d.ts +4 -10
  80. package/build/src/cli/parse.js +2 -5
  81. package/build/src/cli/render/akuma-activity.d.ts +12 -34
  82. package/build/src/cli/render/akuma-activity.js +99 -180
  83. package/build/src/cli/render/akuma.d.ts +5 -11
  84. package/build/src/cli/render/akuma.js +22 -30
  85. package/build/src/cli/render/catalog.js +4 -6
  86. package/build/src/cli/render/contract-history.d.ts +1 -3
  87. package/build/src/cli/render/contract-history.js +70 -49
  88. package/build/src/cli/render/contract-observation.d.ts +2 -1
  89. package/build/src/cli/render/contract-observation.js +25 -1
  90. package/build/src/cli/render/contract-wait.d.ts +2 -2
  91. package/build/src/cli/render/contract-wait.js +21 -17
  92. package/build/src/cli/render/contract.js +12 -9
  93. package/build/src/cli/render/debt.js +1 -2
  94. package/build/src/cli/render/execution-progress.js +1 -3
  95. package/build/src/cli/render/kanshi-akuma.d.ts +4 -3
  96. package/build/src/cli/render/kanshi-akuma.js +27 -23
  97. package/build/src/cli/render/kanshi.js +45 -60
  98. package/build/src/cli/render/receipt.d.ts +1 -1
  99. package/build/src/cli/render/receipt.js +33 -28
  100. package/build/src/cli/render/reconcile.js +2 -5
  101. package/build/src/cli/render/refusal.js +3 -6
  102. package/build/src/cli/render/terminal.d.ts +2 -4
  103. package/build/src/cli/render/terminal.js +10 -17
  104. package/build/src/cli/render/verbs.d.ts +1 -0
  105. package/build/src/cli/render/verbs.js +39 -34
  106. package/build/src/cli/runtime.js +12 -32
  107. package/build/src/core/facts/codec.js +7 -2
  108. package/build/src/core/facts/eligibility.d.ts +4 -4
  109. package/build/src/core/facts/eligibility.js +11 -0
  110. package/build/src/core/facts/fold.js +9 -5
  111. package/build/src/core/facts/gate.d.ts +5 -1
  112. package/build/src/core/facts/gate.js +14 -10
  113. package/build/src/core/facts/types.d.ts +5 -1
  114. package/build/src/core/facts/types.js +7 -0
  115. package/build/src/core/subject.d.ts +4 -1
  116. package/build/src/core/subject.js +10 -2
  117. package/build/src/core/verbs/amend.d.ts +15 -4
  118. package/build/src/core/verbs/amend.js +19 -9
  119. package/build/src/debt/board.d.ts +2 -1
  120. package/build/src/debt/board.js +3 -3
  121. package/build/src/debt/catalog.js +2 -1
  122. package/build/src/debt/document.d.ts +1 -0
  123. package/build/src/debt/document.js +3 -0
  124. package/build/src/debt/index.d.ts +2 -2
  125. package/build/src/debt/index.js +9 -14
  126. package/build/src/debt/input.d.ts +2 -1
  127. package/build/src/debt/input.js +6 -4
  128. package/build/src/debt/operations.d.ts +2 -1
  129. package/build/src/dispatch/index.d.ts +0 -17
  130. package/build/src/dispatch/index.js +1 -10
  131. package/build/src/git/identity.js +16 -45
  132. package/build/src/git/nuke.js +13 -23
  133. package/build/src/git/observe.d.ts +7 -3
  134. package/build/src/git/observe.js +29 -26
  135. package/build/src/git/process.js +11 -18
  136. package/build/src/git/read-observation.d.ts +5 -4
  137. package/build/src/git/repository.d.ts +2 -0
  138. package/build/src/git/repository.js +13 -1
  139. package/build/src/git/scratch.js +2 -14
  140. package/build/src/git/terminal-reconcile.js +1 -13
  141. package/build/src/history.d.ts +26 -0
  142. package/build/src/history.js +43 -0
  143. package/build/src/index.d.ts +6 -3
  144. package/build/src/kanshi/counts.d.ts +15 -1
  145. package/build/src/kanshi/counts.js +14 -3
  146. package/build/src/kanshi/index.d.ts +3 -4
  147. package/build/src/kanshi/index.js +2 -3
  148. package/build/src/kanshi/read.d.ts +21 -0
  149. package/build/src/kanshi/read.js +7 -3
  150. package/build/src/kanshi/report.d.ts +94 -0
  151. package/build/src/library/address.d.ts +12 -5
  152. package/build/src/library/address.js +18 -32
  153. package/build/src/library/akuma-creation.d.ts +39 -0
  154. package/build/src/library/akuma-creation.js +3 -9
  155. package/build/src/library/akumas.d.ts +5 -1
  156. package/build/src/library/akumas.js +11 -5
  157. package/build/src/library/continuation.d.ts +10 -0
  158. package/build/src/library/contract-composition.js +10 -10
  159. package/build/src/library/contract-creation.js +12 -13
  160. package/build/src/library/contract-outcomes.d.ts +72 -1
  161. package/build/src/library/contract-outcomes.js +1 -0
  162. package/build/src/library/contract-types.d.ts +233 -25
  163. package/build/src/library/contract-types.js +32 -12
  164. package/build/src/library/contract-wait.d.ts +212 -0
  165. package/build/src/library/contract-wait.js +65 -49
  166. package/build/src/library/delivery.d.ts +25 -0
  167. package/build/src/library/input.d.ts +8 -26
  168. package/build/src/library/input.js +17 -12
  169. package/build/src/library/kei.js +167 -90
  170. package/build/src/library/keiyaku-attribution.d.ts +1 -1
  171. package/build/src/library/keiyaku-attribution.js +3 -1
  172. package/build/src/library/keiyaku-classify.js +8 -4
  173. package/build/src/library/keiyaku-debt.d.ts +8 -7
  174. package/build/src/library/keiyaku-debt.js +1 -2
  175. package/build/src/library/keiyaku-identity.d.ts +4 -3
  176. package/build/src/library/keiyaku-identity.js +35 -7
  177. package/build/src/library/keiyaku-verbs.d.ts +974 -1409
  178. package/build/src/library/keiyaku-verbs.js +154 -161
  179. package/build/src/library/keiyaku-wait.d.ts +753 -0
  180. package/build/src/library/keiyaku-wait.js +230 -0
  181. package/build/src/library/keiyaku.d.ts +3110 -29
  182. package/build/src/library/keiyaku.js +342 -438
  183. package/build/src/library/model-tools.d.ts +754 -0
  184. package/build/src/library/model-tools.js +362 -0
  185. package/build/src/library/outcome.js +5 -6
  186. package/build/src/library/refusal.d.ts +25 -1
  187. package/build/src/library/refusal.js +4 -5
  188. package/build/src/library/selection.d.ts +18 -5
  189. package/build/src/library/selection.js +11 -5
  190. package/build/src/mcp/adapter.d.ts +0 -6
  191. package/build/src/mcp/adapter.js +11 -160
  192. package/build/src/mcp/description.d.ts +2 -0
  193. package/build/src/mcp/description.js +2 -0
  194. package/build/src/mcp/help.d.ts +1 -1
  195. package/build/src/mcp/help.js +10 -7
  196. package/build/src/pi/index.d.ts +5 -0
  197. package/build/src/pi/index.js +99 -0
  198. package/build/src/pi/status.d.ts +12 -0
  199. package/build/src/pi/status.js +140 -0
  200. package/build/src/protocol/amend.d.ts +14 -3
  201. package/build/src/protocol/amend.js +113 -46
  202. package/build/src/protocol/bind.d.ts +1 -1
  203. package/build/src/protocol/bind.js +5 -16
  204. package/build/src/protocol/completion.d.ts +30 -0
  205. package/build/src/protocol/completion.js +8 -5
  206. package/build/src/protocol/deliver.js +7 -20
  207. package/build/src/protocol/delivery-preview.d.ts +5 -0
  208. package/build/src/protocol/execution-observation.d.ts +8 -0
  209. package/build/src/protocol/intent.d.ts +1 -0
  210. package/build/src/protocol/intent.js +4 -1
  211. package/build/src/protocol/operations.d.ts +56 -16
  212. package/build/src/protocol/operations.js +18 -32
  213. package/build/src/protocol/placement.js +7 -1
  214. package/build/src/protocol/progress.js +0 -6
  215. package/build/src/protocol/read/status.d.ts +52 -4
  216. package/build/src/protocol/read/status.js +26 -22
  217. package/build/src/protocol/reintegrate.js +2 -2
  218. package/build/src/protocol/result-leaves.d.ts +56 -8
  219. package/build/src/protocol/result-leaves.js +11 -2
  220. package/build/src/protocol/run.js +1 -4
  221. package/build/src/protocol/verify.d.ts +10 -0
  222. package/build/src/protocol/verify.js +1 -0
  223. package/build/src/runtime/proc/windows-launch.exe +0 -0
  224. package/build/src/settlement/settle.js +19 -68
  225. package/package.json +7 -3
  226. package/plugins/paseo/plugin/index.server.ts +6 -2
  227. package/plugins/paseo/plugin/server/attach.ts +68 -48
  228. package/plugins/paseo/plugin/server/directory.ts +259 -0
  229. package/plugins/paseo/plugin/server/mirror-identity.ts +3 -32
  230. package/plugins/paseo/plugin/server/reopen.ts +52 -38
  231. package/plugins/pi/README.md +55 -97
  232. package/plugins/pi/keiyaku.ts +1 -142
  233. package/skills/keiyaku-akuma/SKILL.md +18 -11
  234. package/skills/keiyaku-babysit/SKILL.md +8 -6
  235. package/skills/keiyaku-debt/SKILL.md +2 -1
  236. package/skills/keiyaku-workflow/SKILL.md +2 -1
  237. package/build/plugins/pi/akuma-tools.ts +0 -283
  238. package/build/src/body/keys.d.ts +0 -4
  239. package/build/src/body/keys.js +0 -11
  240. package/build/src/kanshi/roster.d.ts +0 -2
  241. package/build/src/kanshi/roster.js +0 -2
  242. package/build/src/mcp/output.d.ts +0 -385
  243. package/build/src/mcp/output.js +0 -193
  244. package/plugins/pi/akuma-tools.ts +0 -283
@@ -1,12 +1,76 @@
1
- import { extendContractsForAdmissionAt, observeContractsForAdmissionAt } from "../git/observe.js";
1
+ import { extendContractsForAdmissionAt, observeContractsForAdmissionAt, selectExplicitTarget, } from "../git/observe.js";
2
2
  import { withPrivateStatePublicationSeat } from "../git/private-state-seat.js";
3
3
  import { contractState } from "../core/facts/observation.js";
4
+ import { sameTarget } from "../core/facts/types.js";
5
+ import { readRef } from "../git/repository.js";
6
+ import { resolveContractTarget } from "../git/target.js";
7
+ import { acquireTargetPlacementFence } from "../git/target-placement.js";
4
8
  import { decideAmend } from "../core/verbs/amend.js";
5
9
  import { VERIFIED, } from "../verification/declaration.js";
6
10
  import { admitDecidedOffer, mintAttempts } from "./attempt.js";
7
11
  import { admitted } from "./outcome.js";
8
12
  import { protocolSeatClose } from "./run.js";
9
13
  import { timestamp } from "./operations.js";
14
+ /** No target selection and no document derivation is one amendment that requests no change. */
15
+ function requestsEdit(input) {
16
+ return input.target !== undefined || input.deriveAmendment !== undefined;
17
+ }
18
+ /** Empty intent keeps the owner's existence and terminal judgment and admits nothing. */
19
+ async function unchangedAmend(input) {
20
+ const observation = await observeContractsForAdmissionAt(input.scope, input.channel, [input.contractId]);
21
+ const decision = decideAmend({
22
+ input: { contractId: input.contractId, at: timestamp() },
23
+ attempt: { entryUlids: [] },
24
+ observation: observation.decision,
25
+ });
26
+ return decision.kind === "offer" ? { kind: "unchanged" } : decision;
27
+ }
28
+ async function prepareAmendmentAt(input, selection, amendment, observation) {
29
+ const state = contractState(observation.decision, input.contractId);
30
+ observation = await extendPrerequisiteClosureAt(input.channel, observation, [
31
+ ...new Set([...(state?.terms.after ?? []), ...amendment.terms.after]),
32
+ ]);
33
+ let target;
34
+ let refusal;
35
+ if (selection?.kind === "contract") {
36
+ observation = await extendTargetClosureAt(input.channel, observation, selection.contractId);
37
+ const resolved = await resolveContractTarget(input.scope, selection.contractId);
38
+ if (resolved.kind === "refused")
39
+ refusal = resolved.refusal;
40
+ else
41
+ target = resolved.target;
42
+ }
43
+ else if (selection?.kind === "explicit") {
44
+ if ((await readRef(input.scope, selection.target)) === null)
45
+ refusal = { kind: "target-missing" };
46
+ else
47
+ target = selection.target;
48
+ }
49
+ if (sameTarget(state?.coordinates.target, target))
50
+ target = undefined;
51
+ const preparation = refusal !== undefined
52
+ ? { kind: "refused", refusal }
53
+ : amendment.verification.kind === "prepared" || !amendment.terms.gates.includes(VERIFIED)
54
+ ? { kind: "prepared", data: { ...amendment.terms, ...(target === undefined ? {} : { target }) } }
55
+ : { kind: "refused", refusal: amendment.verification.refusal };
56
+ return {
57
+ observation,
58
+ ...(target === undefined ? {} : { target }),
59
+ preparation,
60
+ };
61
+ }
62
+ async function extendTargetClosureAt(channel, observation, seed) {
63
+ let current = observation;
64
+ const visited = new Set();
65
+ let id = seed;
66
+ while (id !== undefined && !visited.has(id)) {
67
+ visited.add(id);
68
+ current = await extendContractsForAdmissionAt(channel, current, [id]);
69
+ const target = contractState(current.decision, id)?.coordinates.target;
70
+ id = typeof target === "object" ? target.contractId : undefined;
71
+ }
72
+ return current;
73
+ }
10
74
  async function extendPrerequisiteClosureAt(channel, observation, seeds) {
11
75
  let current = observation;
12
76
  const visited = new Set();
@@ -27,6 +91,11 @@ async function extendPrerequisiteClosureAt(channel, observation, seeds) {
27
91
  return current;
28
92
  }
29
93
  export async function amendOperation(input) {
94
+ if (!requestsEdit(input))
95
+ return await unchangedAmend(input);
96
+ const selection = input.target === undefined ? undefined : await selectExplicitTarget(input.scope, input.target);
97
+ if (selection === null)
98
+ return { kind: "refused", refusal: { kind: "invalid-target" } };
30
99
  let source = input.source;
31
100
  if (source === undefined) {
32
101
  const initial = await observeContractsForAdmissionAt(input.scope, input.channel, [input.contractId]);
@@ -36,50 +105,48 @@ export async function amendOperation(input) {
36
105
  const amendment = source === undefined || input.deriveAmendment === undefined
37
106
  ? undefined
38
107
  : { source, ...input.deriveAmendment(source) };
39
- return protocolSeatClose(await withPrivateStatePublicationSeat(input.scope, async (seat) => {
40
- const attempts = mintAttempts({ entryCount: 1 });
41
- for (let index = 0; index < attempts.length; index += 1) {
42
- let observation = await observeContractsForAdmissionAt(input.scope, input.channel, [input.contractId]);
43
- const state = contractState(observation.decision, input.contractId);
44
- if (amendment !== undefined) {
45
- observation = await extendPrerequisiteClosureAt(input.channel, observation, [
46
- ...new Set([...(state?.terms.after ?? []), ...amendment.terms.after]),
47
- ]);
48
- }
49
- const preparation = amendment === undefined
50
- ? undefined
51
- : amendment.verification.kind === "prepared" || !amendment.terms.gates.includes(VERIFIED)
52
- ? { kind: "prepared", data: amendment.terms }
53
- : { kind: "refused", refusal: amendment.verification.refusal };
54
- const decision = decideAmend({
55
- input: {
56
- contractId: input.contractId,
57
- at: timestamp(),
58
- ...(amendment === undefined ? {} : { source: amendment.source }),
59
- ...(preparation === undefined ? {} : { preparation }),
60
- },
61
- attempt: attempts[index],
62
- observation: observation.decision,
63
- });
64
- if (decision.kind === "refused")
65
- return decision;
66
- const admission = await admitDecidedOffer({
67
- ...input,
68
- seat,
69
- observation,
70
- attempt: attempts[index],
71
- offer: decision.offer,
72
- });
73
- if (admission.kind === "accepted") {
74
- if (amendment === undefined)
75
- throw new Error("accepted amendment is missing its document derivation");
76
- return admitted(admission, amendment);
108
+ // A requested edit must carry observed terms; only a Contract that appeared after observation has none.
109
+ if (amendment === undefined)
110
+ throw new Error("requested amendment is missing its observed source terms");
111
+ const incoming = selection?.kind === "contract" ? await acquireTargetPlacementFence(input.scope, selection.contractId) : undefined;
112
+ try {
113
+ return protocolSeatClose(await withPrivateStatePublicationSeat(input.scope, async (seat) => {
114
+ const attempts = mintAttempts({ entryCount: 1 });
115
+ for (let index = 0; index < attempts.length; index += 1) {
116
+ const { observation, target, preparation } = await prepareAmendmentAt(input, selection, amendment, await observeContractsForAdmissionAt(input.scope, input.channel, [input.contractId]));
117
+ const decision = decideAmend({
118
+ input: {
119
+ contractId: input.contractId,
120
+ at: timestamp(),
121
+ edit: {
122
+ source: amendment.source,
123
+ preparation,
124
+ ...(selection?.kind === "contract" ? { targetContract: selection.contractId } : {}),
125
+ },
126
+ },
127
+ attempt: attempts[index],
128
+ observation: observation.decision,
129
+ });
130
+ if (decision.kind !== "offer")
131
+ return decision;
132
+ const admission = await admitDecidedOffer({
133
+ ...input,
134
+ seat,
135
+ observation,
136
+ attempt: attempts[index],
137
+ offer: decision.offer,
138
+ });
139
+ if (admission.kind === "accepted")
140
+ return admitted(admission, { ...amendment, ...(target === undefined ? {} : { target }) });
141
+ if (admission.kind === "publication-failed")
142
+ return { kind: "retry", reason: admission };
143
+ if (admission.kind === "collision" && index + 1 === attempts.length)
144
+ return { kind: "retry", reason: admission };
77
145
  }
78
- if (admission.kind === "publication-failed")
79
- return { kind: "retry", reason: admission };
80
- if (admission.kind === "collision" && index + 1 === attempts.length)
81
- return { kind: "retry", reason: admission };
82
- }
83
- return { kind: "retry", reason: { kind: "exhausted" } };
84
- }));
146
+ return { kind: "retry", reason: { kind: "exhausted" } };
147
+ }));
148
+ }
149
+ finally {
150
+ incoming?.close();
151
+ }
85
152
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { type BindData, type ContractId } from "../core/facts/types.js";
2
+ import type { BindData, ContractId } from "../core/facts/types.js";
3
3
  import { type TargetWorkspaceRefusal } from "../git/target.js";
4
4
  import { type BindRefusal } from "../core/verbs/bind.js";
5
5
  import { type BindTargetSelection } from "../git/observe.js";
@@ -1,10 +1,9 @@
1
1
  import { z } from "zod";
2
- import { contractId } from "../core/facts/types.js";
3
2
  import { resolveContractTarget, targetRef, targetWorkspaceRefusalSchema, } from "../git/target.js";
4
3
  import { acquireTargetPlacementFence } from "../git/target-placement.js";
5
4
  import { decideBind } from "../core/verbs/bind.js";
6
5
  import { gitObjectIdForSnapshot } from "../git/identity.js";
7
- import { normalizeTargetBranch, observeBindCoordinates, } from "../git/observe.js";
6
+ import { selectExplicitTarget, observeBindCoordinates, } from "../git/observe.js";
8
7
  import { VERIFIED, } from "../verification/declaration.js";
9
8
  import { admitPreparedIntent } from "./intent.js";
10
9
  import { complete } from "./outcome.js";
@@ -120,20 +119,10 @@ async function assembleBindInput(input, selection, seed, prepared) {
120
119
  export async function bindOperation(input) {
121
120
  let selection = input.targetSelection;
122
121
  if (selection.kind === "explicit") {
123
- if (selection.target.startsWith("kei/")) {
124
- try {
125
- selection = { kind: "contract", contractId: contractId(selection.target) };
126
- }
127
- catch {
128
- return { kind: "refused", refusal: { kind: "invalid-target" } };
129
- }
130
- }
131
- else {
132
- const normalized = await normalizeTargetBranch(input.scope, selection.target);
133
- if (normalized === null)
134
- return { kind: "refused", refusal: { kind: "invalid-target" } };
135
- selection = { kind: "explicit", target: normalized };
136
- }
122
+ const explicit = await selectExplicitTarget(input.scope, selection.target);
123
+ if (explicit === null)
124
+ return { kind: "refused", refusal: { kind: "invalid-target" } };
125
+ selection = explicit;
137
126
  }
138
127
  const at = new Date().toISOString();
139
128
  const id = input.contractId;
@@ -17,6 +17,11 @@ export declare const requirementProblemSchema: z.ZodUnion<readonly [z.ZodReadonl
17
17
  requirement: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").RequirementId, string>>;
18
18
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
19
19
  state: z.ZodLiteral<"stale">;
20
+ reason: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
21
+ kind: z.ZodLiteral<"snapshot-changed">;
22
+ previousSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
23
+ currentSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
24
+ }, z.core.$strict>>>;
20
25
  previousContentId: z.ZodExactOptional<z.ZodString>;
21
26
  currentContentId: z.ZodExactOptional<z.ZodString>;
22
27
  gate: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -58,6 +63,11 @@ export declare const placementReasonSchema: z.ZodUnion<readonly [z.ZodReadonly<z
58
63
  requirement: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").RequirementId, string>>;
59
64
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
60
65
  state: z.ZodLiteral<"stale">;
66
+ reason: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
67
+ kind: z.ZodLiteral<"snapshot-changed">;
68
+ previousSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
69
+ currentSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
70
+ }, z.core.$strict>>>;
61
71
  previousContentId: z.ZodExactOptional<z.ZodString>;
62
72
  currentContentId: z.ZodExactOptional<z.ZodString>;
63
73
  gate: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -131,6 +141,11 @@ export declare const normalContinuationStopSchema: z.ZodUnion<readonly [z.ZodRea
131
141
  requirement: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").RequirementId, string>>;
132
142
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
133
143
  state: z.ZodLiteral<"stale">;
144
+ reason: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
145
+ kind: z.ZodLiteral<"snapshot-changed">;
146
+ previousSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
147
+ currentSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
148
+ }, z.core.$strict>>>;
134
149
  previousContentId: z.ZodExactOptional<z.ZodString>;
135
150
  currentContentId: z.ZodExactOptional<z.ZodString>;
136
151
  gate: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -164,6 +179,11 @@ export declare const placementStopSchema: z.ZodUnion<readonly [z.ZodReadonly<z.Z
164
179
  requirement: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").RequirementId, string>>;
165
180
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
166
181
  state: z.ZodLiteral<"stale">;
182
+ reason: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
183
+ kind: z.ZodLiteral<"snapshot-changed">;
184
+ previousSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
185
+ currentSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
186
+ }, z.core.$strict>>>;
167
187
  previousContentId: z.ZodExactOptional<z.ZodString>;
168
188
  currentContentId: z.ZodExactOptional<z.ZodString>;
169
189
  gate: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -287,6 +307,11 @@ export declare const normalPlacementSchema: z.ZodUnion<readonly [z.ZodReadonly<z
287
307
  requirement: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").RequirementId, string>>;
288
308
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
289
309
  state: z.ZodLiteral<"stale">;
310
+ reason: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
311
+ kind: z.ZodLiteral<"snapshot-changed">;
312
+ previousSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
313
+ currentSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
314
+ }, z.core.$strict>>>;
290
315
  previousContentId: z.ZodExactOptional<z.ZodString>;
291
316
  currentContentId: z.ZodExactOptional<z.ZodString>;
292
317
  gate: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -323,6 +348,11 @@ export declare const placementSchema: z.ZodUnion<readonly [z.ZodReadonly<z.ZodOb
323
348
  requirement: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").RequirementId, string>>;
324
349
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
325
350
  state: z.ZodLiteral<"stale">;
351
+ reason: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
352
+ kind: z.ZodLiteral<"snapshot-changed">;
353
+ previousSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
354
+ currentSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
355
+ }, z.core.$strict>>>;
326
356
  previousContentId: z.ZodExactOptional<z.ZodString>;
327
357
  currentContentId: z.ZodExactOptional<z.ZodString>;
328
358
  gate: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { targetName } from "../core/facts/types.js";
3
3
  import { snapshotIdSchema, contractIdSchema } from "../git/identity.js";
4
- import { requirementIdSchema, gateSchema } from "./result-leaves.js";
4
+ import { requirementIdSchema, gateSchema, snapshotChangeSchema } from "./result-leaves.js";
5
5
  import { admitPlacement, observeTargetPlacement, observeIntegrationTargetMovement } from "./placement.js";
6
6
  import { reintegrateOperation } from "./reintegrate.js";
7
7
  import { contractCheckpoint, executionStop, isOperationalFailure, isOperationalStop, } from "./progress.js";
@@ -18,6 +18,7 @@ export const requirementProblemSchema = z.union([
18
18
  .strictObject({
19
19
  ...requirementCoordinate,
20
20
  state: z.literal("stale"),
21
+ reason: snapshotChangeSchema.exactOptional(),
21
22
  previousContentId: z.string().min(1).exactOptional(),
22
23
  currentContentId: z.string().min(1).exactOptional(),
23
24
  })
@@ -47,10 +48,12 @@ export function unmetGateProblems(reports) {
47
48
  state: "stale",
48
49
  ...(current.reason === undefined
49
50
  ? {}
50
- : {
51
- previousContentId: current.reason.previousChange,
52
- currentContentId: current.reason.currentChange,
53
- }),
51
+ : current.reason.kind === "snapshot-changed"
52
+ ? { reason: current.reason }
53
+ : {
54
+ previousContentId: current.reason.previousChange,
55
+ currentContentId: current.reason.currentChange,
56
+ }),
54
57
  },
55
58
  ];
56
59
  }));
@@ -59,7 +59,6 @@ export const materializedConflictSchema = z
59
59
  })
60
60
  .strict()
61
61
  .readonly();
62
- const DELIVER_CONFLICT_RECOVERY = conflictRecovery;
63
62
  async function captureAuthorizedDeliveryTender(repository, stage, includeDirty) {
64
63
  const { contractId, coordinates } = stage;
65
64
  const appointed = coordinates.workspace === "worktree"
@@ -120,13 +119,7 @@ async function prepareDeliveryWithWorktree(repository, stage, input, captured) {
120
119
  method: "squash",
121
120
  policy: { requireBranchesToBeUpToDate },
122
121
  },
123
- worktree: {
124
- tree: tender.data.tree,
125
- head: tender.data.head,
126
- ...(tender.data.mergeHead === undefined ? {} : { mergeHead: tender.data.mergeHead }),
127
- dirty: tender.data.dirty,
128
- changeId,
129
- },
122
+ worktree: worktreeWitness(tender.data, changeId),
130
123
  };
131
124
  }
132
125
  export async function prepareDelivery(repository, stage, input) {
@@ -146,13 +139,7 @@ async function recaptureDeliveryWorktree(input, state) {
146
139
  const tender = await captureAuthorizedDeliveryTender(input.scope, { contractId: state.id, coordinates: state.coordinates }, input.includeDirty);
147
140
  if (tender.kind === "refused")
148
141
  return undefined;
149
- return {
150
- tree: tender.data.tree,
151
- head: tender.data.head,
152
- ...(tender.data.mergeHead === undefined ? {} : { mergeHead: tender.data.mergeHead }),
153
- dirty: tender.data.dirty,
154
- changeId: await worktreeChangeId(input.scope, { coordinates: state.coordinates }, tender.data),
155
- };
142
+ return worktreeWitness(tender.data, await worktreeChangeId(input.scope, { coordinates: state.coordinates }, tender.data));
156
143
  }
157
144
  async function mechanicalDeliveryPreparation(input, state, derivation, journal, captured) {
158
145
  const prepared = await prepareDeliveryWithWorktree(input.scope, {
@@ -170,14 +157,14 @@ async function mechanicalDeliveryPreparation(input, state, derivation, journal,
170
157
  worktree: prepared.worktree,
171
158
  };
172
159
  }
173
- function worktreeInput(repository, state, tender) {
174
- return worktreeChangeId(repository, { coordinates: state.coordinates }, tender).then((changeId) => ({
160
+ function worktreeWitness(tender, changeId) {
161
+ return {
175
162
  tree: tender.tree,
176
163
  head: tender.head,
177
164
  ...(tender.mergeHead === undefined ? {} : { mergeHead: tender.mergeHead }),
178
165
  dirty: tender.dirty,
179
166
  changeId,
180
- }));
167
+ };
181
168
  }
182
169
  /**
183
170
  * Repeatable physical delivery work outside the publication seat: locate the appointed worktree from
@@ -195,7 +182,7 @@ async function prepareDeliveryArtifacts(input, observation, state) {
195
182
  const captured = await captureAuthorizedDeliveryTender(input.scope, { contractId: state.id, coordinates: state.coordinates }, input.includeDirty);
196
183
  if (captured.kind === "refused")
197
184
  return { kind: "refused", refusal: captured.refusal };
198
- const worktree = await worktreeInput(input.scope, state, captured.data);
185
+ const worktree = worktreeWitness(captured.data, await worktreeChangeId(input.scope, { coordinates: state.coordinates }, captured.data));
199
186
  if (reusesCurrentCandidate(input, state, worktree.changeId)) {
200
187
  return { kind: "reuse", worktree };
201
188
  }
@@ -477,7 +464,7 @@ async function materializeDeliverConflict(input, refusal) {
477
464
  conflictPaths: refusal.conflictPaths,
478
465
  workspace,
479
466
  handoffBase: handoffHead,
480
- recovery: DELIVER_CONFLICT_RECOVERY,
467
+ recovery: conflictRecovery,
481
468
  };
482
469
  }
483
470
  async function finishDeliverRefusal(input, refusal) {
@@ -30,6 +30,11 @@ export declare const deliveryPreviewReportSchema: z.ZodUnion<readonly [z.ZodRead
30
30
  requirement: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").RequirementId, string>>;
31
31
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
32
32
  state: z.ZodLiteral<"stale">;
33
+ reason: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
34
+ kind: z.ZodLiteral<"snapshot-changed">;
35
+ previousSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
36
+ currentSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
37
+ }, z.core.$strict>>>;
33
38
  previousContentId: z.ZodExactOptional<z.ZodString>;
34
39
  currentContentId: z.ZodExactOptional<z.ZodString>;
35
40
  gate: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -43,6 +43,14 @@ export declare const executionObservationSchema: z.ZodDiscriminatedUnion<[z.ZodR
43
43
  gates: z.ZodReadonly<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
44
44
  requirements: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodReadonly<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").RequirementId, string>>>>>>;
45
45
  after: z.ZodReadonly<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<import("../index.js").ContractId, string>>>>;
46
+ target: z.ZodExactOptional<z.ZodUnion<readonly [z.ZodString, z.ZodReadonly<z.ZodObject<{
47
+ kind: z.ZodLiteral<"contract">;
48
+ contractId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../index.js").ContractId, string>>;
49
+ worktree: z.ZodReadonly<z.ZodObject<{
50
+ id: z.ZodString;
51
+ identity: z.ZodString;
52
+ }, z.core.$strict>>;
53
+ }, z.core.$strict>>]>>;
46
54
  }, z.core.$strict>>;
47
55
  v: z.ZodLiteral<1>;
48
56
  contract: z.ZodPipe<z.ZodString, z.ZodTransform<import("../index.js").ContractId, string>>;
@@ -41,6 +41,7 @@ type VerifyRequirementInput = Readonly<{
41
41
  gates: readonly Gate[];
42
42
  at: string;
43
43
  snapshot: SnapshotId;
44
+ targetRevision?: import("../core/facts/types.js").EntryUlid;
44
45
  requirement: RequirementId;
45
46
  declaration: VerificationDeclaration;
46
47
  index: number;
@@ -136,7 +136,10 @@ async function verificationStep(input, execution, subject) {
136
136
  /** Execute one declaration and record testimony only when its gate is selected. */
137
137
  export async function verifyRequirement(input) {
138
138
  const snapshot = input.snapshot;
139
- const subject = dependencyKeySet([{ kind: "snapshot", value: snapshot }]);
139
+ const subject = dependencyKeySet([
140
+ { kind: "snapshot", value: snapshot },
141
+ ...(input.targetRevision === undefined ? [] : [{ kind: "target", value: input.targetRevision }]),
142
+ ]);
140
143
  const execution = await executeVerification({
141
144
  repository: input.repository,
142
145
  candidate: snapshot,