@astrosheep/keiyaku 4.0.3 → 4.0.5

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 (238) 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 +1 -1
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +15 -1
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-task/SKILL.md +3 -1
  8. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +34 -13
  9. package/build/src/akuma/akuma.d.ts +34 -12
  10. package/build/src/akuma/akuma.js +118 -63
  11. package/build/src/akuma/allowed.d.ts +7 -0
  12. package/build/src/akuma/allowed.js +33 -0
  13. package/build/src/akuma/archetype.d.ts +7 -4
  14. package/build/src/akuma/archetype.js +15 -16
  15. package/build/src/akuma/body.d.ts +6 -1
  16. package/build/src/akuma/body.js +36 -27
  17. package/build/src/akuma/heart/facts.d.ts +82 -14
  18. package/build/src/akuma/heart/index.d.ts +5 -18
  19. package/build/src/akuma/heart/index.js +14 -84
  20. package/build/src/akuma/heart/request-authority.d.ts +12 -0
  21. package/build/src/akuma/heart/request-authority.js +119 -0
  22. package/build/src/akuma/heart/request-rows.d.ts +16 -0
  23. package/build/src/akuma/heart/request-rows.js +88 -0
  24. package/build/src/akuma/heart/rows.d.ts +1 -26
  25. package/build/src/akuma/heart/rows.js +0 -50
  26. package/build/src/akuma/heart/schema.d.ts +1 -1
  27. package/build/src/akuma/heart/schema.js +22 -10
  28. package/build/src/akuma/heart/soul.js +2 -36
  29. package/build/src/akuma/heart/storage.d.ts +1 -0
  30. package/build/src/akuma/heart/storage.js +15 -0
  31. package/build/src/akuma/heart/timeline.d.ts +1 -5
  32. package/build/src/akuma/heart/timeline.js +8 -17
  33. package/build/src/akuma/index.d.ts +5 -2
  34. package/build/src/akuma/index.js +1 -0
  35. package/build/src/akuma/projection.d.ts +17 -3
  36. package/build/src/akuma/projection.js +40 -3
  37. package/build/src/akuma/provider-recipe.js +1 -11
  38. package/build/src/akuma/provider.d.ts +2 -7
  39. package/build/src/akuma/provider.js +2 -1
  40. package/build/src/akuma/providers/acp/core.d.ts +3 -1
  41. package/build/src/akuma/providers/acp/core.js +10 -6
  42. package/build/src/akuma/providers/acp/events.d.ts +11 -3
  43. package/build/src/akuma/providers/acp/events.js +78 -4
  44. package/build/src/akuma/providers/acp/index.js +0 -1
  45. package/build/src/akuma/providers/claude/events.js +62 -3
  46. package/build/src/akuma/providers/claude/index.d.ts +0 -4
  47. package/build/src/akuma/providers/claude/index.js +7 -3
  48. package/build/src/akuma/providers/codex-app-server/events.js +1 -13
  49. package/build/src/akuma/providers/codex-app-server/index.d.ts +2 -27
  50. package/build/src/akuma/providers/codex-app-server/index.js +0 -2
  51. package/build/src/akuma/providers/grok-build/index.d.ts +2 -1
  52. package/build/src/akuma/providers/grok-build/index.js +72 -3
  53. package/build/src/akuma/providers/opencode-sdk/events.js +71 -6
  54. package/build/src/akuma/providers/opencode-sdk/index.d.ts +2 -28
  55. package/build/src/akuma/providers/opencode-sdk/index.js +8 -4
  56. package/build/src/akuma/providers/opencode-sdk/session.d.ts +1 -1
  57. package/build/src/akuma/providers/opencode-sdk/session.js +1 -1
  58. package/build/src/akuma/providers/pi/events.js +17 -3
  59. package/build/src/akuma/providers/pi/index.js +11 -4
  60. package/build/src/akuma/providers/unified-patch.d.ts +4 -0
  61. package/build/src/akuma/providers/unified-patch.js +14 -0
  62. package/build/src/akuma/publication.d.ts +1 -1
  63. package/build/src/akuma/publication.js +1 -1
  64. package/build/src/akuma/request-serve.d.ts +87 -0
  65. package/build/src/akuma/request-serve.js +484 -0
  66. package/build/src/akuma/request-wire.d.ts +124 -0
  67. package/build/src/akuma/request-wire.js +380 -0
  68. package/build/src/akuma/requests.d.ts +41 -41
  69. package/build/src/akuma/requests.js +75 -374
  70. package/build/src/akuma-body.d.ts +8 -0
  71. package/build/src/akuma-body.js +84 -0
  72. package/build/src/body/arc.js +4 -29
  73. package/build/src/body/decode.js +5 -39
  74. package/build/src/body/envelope.d.ts +7 -0
  75. package/build/src/body/envelope.js +37 -0
  76. package/build/src/cli/accepted.d.ts +4 -1
  77. package/build/src/cli/accepted.js +39 -9
  78. package/build/src/cli/commands/akuma-invoke.d.ts +8 -7
  79. package/build/src/cli/commands/akuma-invoke.js +18 -10
  80. package/build/src/cli/commands/akuma.d.ts +11 -2
  81. package/build/src/cli/commands/akuma.js +67 -28
  82. package/build/src/cli/commands/amend.d.ts +1 -1
  83. package/build/src/cli/commands/amend.js +1 -1
  84. package/build/src/cli/commands/contract.d.ts +8 -8
  85. package/build/src/cli/commands/contract.js +3 -3
  86. package/build/src/cli/commands/install.js +2 -2
  87. package/build/src/cli/commands/task-invoke.js +98 -9
  88. package/build/src/cli/commands/task-query.d.ts +1 -1
  89. package/build/src/cli/commands/task-query.js +11 -5
  90. package/build/src/cli/coordinates.d.ts +2 -0
  91. package/build/src/cli/coordinates.js +12 -5
  92. package/build/src/cli/invoke.d.ts +1 -0
  93. package/build/src/cli/invoke.js +116 -75
  94. package/build/src/cli/main.d.ts +2 -0
  95. package/build/src/cli/main.js +29 -4
  96. package/build/src/cli/parse.d.ts +3 -2
  97. package/build/src/cli/parse.js +25 -8
  98. package/build/src/cli/render/akuma.d.ts +2 -2
  99. package/build/src/cli/render/akuma.js +138 -24
  100. package/build/src/cli/render/audit.js +18 -8
  101. package/build/src/cli/render/contract.d.ts +2 -0
  102. package/build/src/cli/render/contract.js +243 -36
  103. package/build/src/cli/render/kanshi.js +64 -29
  104. package/build/src/cli/render/receipt.d.ts +2 -1
  105. package/build/src/cli/render/receipt.js +37 -2
  106. package/build/src/cli/render/terminal.d.ts +0 -2
  107. package/build/src/cli/render/terminal.js +0 -29
  108. package/build/src/cli/render/text.js +3 -1
  109. package/build/src/cli/result.d.ts +52 -9
  110. package/build/src/cli/selectors.d.ts +1 -0
  111. package/build/src/cli/selectors.js +9 -6
  112. package/build/src/contract-worktree.d.ts +1 -2
  113. package/build/src/contract-worktree.js +7 -9
  114. package/build/src/core/facts/codec.js +9 -0
  115. package/build/src/core/facts/fold.js +13 -1
  116. package/build/src/core/facts/types.d.ts +8 -1
  117. package/build/src/core/subject.js +4 -3
  118. package/build/src/core/verbs/placement.d.ts +9 -1
  119. package/build/src/core/verbs/placement.js +24 -6
  120. package/build/src/core/verbs/reintegrate.d.ts +13 -0
  121. package/build/src/core/verbs/reintegrate.js +24 -0
  122. package/build/src/dispatch/index.d.ts +1 -1
  123. package/build/src/dispatch/index.js +50 -39
  124. package/build/src/git/admission.d.ts +2 -1
  125. package/build/src/git/hooks.d.ts +0 -4
  126. package/build/src/git/hooks.js +0 -36
  127. package/build/src/git/integration.d.ts +7 -8
  128. package/build/src/git/integration.js +62 -9
  129. package/build/src/git/observe.d.ts +2 -1
  130. package/build/src/git/observe.js +6 -5
  131. package/build/src/git/process.d.ts +26 -0
  132. package/build/src/git/process.js +94 -0
  133. package/build/src/git/read-observation.d.ts +2 -1
  134. package/build/src/git/read-observation.js +3 -2
  135. package/build/src/git/reconcile.d.ts +8 -2
  136. package/build/src/git/reconcile.js +63 -14
  137. package/build/src/git/repository.d.ts +2 -29
  138. package/build/src/git/repository.js +4 -118
  139. package/build/src/git/scratch.d.ts +1 -1
  140. package/build/src/git/scratch.js +1 -1
  141. package/build/src/git/target-placement.d.ts +1 -1
  142. package/build/src/git/target-placement.js +9 -7
  143. package/build/src/git/tender.d.ts +20 -5
  144. package/build/src/git/tender.js +45 -13
  145. package/build/src/git/terminal-seal.d.ts +16 -2
  146. package/build/src/git/terminal-seal.js +15 -5
  147. package/build/src/git/workspace.d.ts +2 -1
  148. package/build/src/git/workspace.js +13 -5
  149. package/build/src/index.d.ts +1 -2
  150. package/build/src/index.js +1 -1
  151. package/build/src/kanshi/index.d.ts +1 -1
  152. package/build/src/kanshi/index.js +1 -1
  153. package/build/src/kanshi/read.d.ts +9 -1
  154. package/build/src/kanshi/read.js +91 -37
  155. package/build/src/kanshi/report.d.ts +1 -0
  156. package/build/src/library/address.d.ts +5 -14
  157. package/build/src/library/address.js +27 -23
  158. package/build/src/library/akuma-creation.d.ts +4 -2
  159. package/build/src/library/akuma-creation.js +43 -26
  160. package/build/src/library/audit.d.ts +2 -1
  161. package/build/src/library/audit.js +1 -1
  162. package/build/src/library/bind.d.ts +2 -1
  163. package/build/src/library/bind.js +4 -4
  164. package/build/src/library/catalog.d.ts +1 -2
  165. package/build/src/library/catalog.js +11 -6
  166. package/build/src/library/configuration.d.ts +5 -1
  167. package/build/src/library/configuration.js +71 -18
  168. package/build/src/library/contract.d.ts +70 -3
  169. package/build/src/library/contract.js +213 -27
  170. package/build/src/library/delivery.d.ts +1 -1
  171. package/build/src/library/fleet.d.ts +70 -12
  172. package/build/src/library/fleet.js +236 -56
  173. package/build/src/library/input.d.ts +0 -1
  174. package/build/src/library/input.js +1 -5
  175. package/build/src/library/keiyaku.d.ts +4 -4
  176. package/build/src/library/keiyaku.js +1 -2
  177. package/build/src/library/mutation.d.ts +2 -1
  178. package/build/src/library/reconcile.d.ts +2 -1
  179. package/build/src/library/reconcile.js +3 -1
  180. package/build/src/library/region.d.ts +1 -1
  181. package/build/src/library/repo.d.ts +3 -1
  182. package/build/src/library/repo.js +8 -4
  183. package/build/src/protocol/abandon.d.ts +9 -0
  184. package/build/src/protocol/abandon.js +15 -0
  185. package/build/src/protocol/amend.d.ts +16 -0
  186. package/build/src/protocol/amend.js +77 -0
  187. package/build/src/protocol/arc.d.ts +6 -0
  188. package/build/src/protocol/arc.js +12 -0
  189. package/build/src/protocol/attempt.d.ts +2 -1
  190. package/build/src/protocol/audit.d.ts +53 -0
  191. package/build/src/protocol/audit.js +140 -0
  192. package/build/src/protocol/bind.d.ts +2 -3
  193. package/build/src/protocol/bind.js +2 -16
  194. package/build/src/protocol/completion.d.ts +32 -0
  195. package/build/src/protocol/completion.js +130 -0
  196. package/build/src/protocol/deliver.d.ts +37 -0
  197. package/build/src/protocol/deliver.js +160 -0
  198. package/build/src/protocol/intent.d.ts +1 -1
  199. package/build/src/protocol/intent.js +1 -1
  200. package/build/src/protocol/operations.d.ts +65 -198
  201. package/build/src/protocol/operations.js +21 -634
  202. package/build/src/protocol/placement.d.ts +4 -13
  203. package/build/src/protocol/placement.js +3 -15
  204. package/build/src/protocol/read/status.d.ts +4 -2
  205. package/build/src/protocol/read/status.js +27 -15
  206. package/build/src/protocol/reconcile.d.ts +35 -0
  207. package/build/src/protocol/reconcile.js +41 -0
  208. package/build/src/protocol/reintegrate.d.ts +31 -0
  209. package/build/src/protocol/reintegrate.js +74 -0
  210. package/build/src/protocol/review.d.ts +33 -0
  211. package/build/src/protocol/review.js +148 -0
  212. package/build/src/protocol/run.d.ts +1 -1
  213. package/build/src/runtime/proc/run.d.ts +1 -0
  214. package/build/src/runtime/proc/run.js +9 -2
  215. package/build/src/settlement/fence.d.ts +1 -1
  216. package/build/src/settlement/holder.d.ts +1 -1
  217. package/build/src/settlement/settle.d.ts +2 -1
  218. package/build/src/settlement/settle.js +4 -1
  219. package/build/src/task/board.d.ts +18 -4
  220. package/build/src/task/board.js +73 -29
  221. package/build/src/task/compose.d.ts +1 -1
  222. package/build/src/task/compose.js +11 -4
  223. package/build/src/task/index.d.ts +4 -4
  224. package/build/src/task/index.js +8 -131
  225. package/build/src/task/input.d.ts +18 -0
  226. package/build/src/task/input.js +189 -0
  227. package/build/src/task/mutation.d.ts +39 -0
  228. package/build/src/task/mutation.js +85 -0
  229. package/build/src/task/operations.d.ts +4 -19
  230. package/build/src/task/operations.js +64 -18
  231. package/build/src/task/query.d.ts +9 -2
  232. package/build/src/task/query.js +32 -64
  233. package/build/src/task/store.js +0 -2
  234. package/build/src/verification/execution.d.ts +1 -1
  235. package/build/src/verification/execution.js +2 -1
  236. package/build/src/workspace-place.d.ts +1 -4
  237. package/build/src/workspace-place.js +0 -15
  238. package/package.json +5 -3
@@ -1,19 +1,63 @@
1
- import { Akuma, } from "../akuma/index.js";
2
- import { readActionFeedbackStatus, readBudgetedStatus } from "../akuma/akuma.js";
1
+ import { Akuma, AkumaNotBornError, } from "../akuma/index.js";
2
+ import { readBudgetedStatus, tellAkumaWithId } from "../akuma/akuma.js";
3
+ import { injectedBodyRequests, requestBodyKill, requestBodyTell, requestBodyWait, } from "../akuma/requests.js";
3
4
  import { readDispatch } from "../dispatch/index.js";
5
+ import { observeTaskBoard } from "../task/operations.js";
4
6
  import { addressAkuma, addressAkumaSet } from "./address.js";
5
7
  import { requireInput } from "./input.js";
6
8
  import { scopeForRepo } from "./repo.js";
7
- function source(path, settings) {
8
- return Akuma.of(path, settings);
9
+ function source(path) {
10
+ return Akuma.of(path);
9
11
  }
10
- async function contractFor(repo, id) {
11
- const dispatch = repo === undefined ? null : await readDispatch(scopeForRepo(repo), id);
12
- return dispatch?.contractId;
12
+ function observationDiagnostic(error) {
13
+ return error instanceof Error ? error.message : String(error);
13
14
  }
14
- async function statusView(status, repo) {
15
- const contractId = await contractFor(repo, status.id);
16
- return contractId === undefined ? { status } : { status, contractId };
15
+ const NO_DISPATCH = { kind: "none" };
16
+ async function dispatchAssociation(repo, id) {
17
+ if (repo === undefined)
18
+ return NO_DISPATCH;
19
+ try {
20
+ const dispatch = await readDispatch(scopeForRepo(repo), id);
21
+ return dispatch === null ? NO_DISPATCH : { kind: "associated", contractId: dispatch.contractId };
22
+ }
23
+ catch (error) {
24
+ return { kind: "failed", diagnostic: observationDiagnostic(error) };
25
+ }
26
+ }
27
+ function createdTaskDiagnostic(error) {
28
+ return observationDiagnostic(error);
29
+ }
30
+ async function createdTasksFor(path, statuses) {
31
+ let board;
32
+ try {
33
+ board = await observeTaskBoard(path);
34
+ }
35
+ catch (error) {
36
+ const failed = { kind: "failed", diagnostic: createdTaskDiagnostic(error) };
37
+ return statuses.map(() => failed);
38
+ }
39
+ return statuses.map((status) => ({ kind: "present", rows: board.selectCreatedBy(status.id) }));
40
+ }
41
+ async function observeAkuma(status, path, repo) {
42
+ return (await observeAkumaSet([status], path, repo))[0];
43
+ }
44
+ async function observeAkumaStage(path, id, repo) {
45
+ try {
46
+ return { kind: "observed", ...await observeAkuma(await source(path).of({ id }).status(), path, repo) };
47
+ }
48
+ catch (error) {
49
+ if (error instanceof AkumaNotBornError)
50
+ throw error;
51
+ return { kind: "unobserved", diagnostic: observationDiagnostic(error) };
52
+ }
53
+ }
54
+ async function observeAkumaSet(statuses, path, repo) {
55
+ const created = await createdTasksFor(path, statuses);
56
+ return await Promise.all(statuses.map(async (status, index) => ({
57
+ status,
58
+ contract: await dispatchAssociation(repo, status.id),
59
+ createdTasks: created[index],
60
+ })));
17
61
  }
18
62
  function timeout(value) {
19
63
  if (value === undefined)
@@ -23,28 +67,142 @@ function timeout(value) {
23
67
  }
24
68
  return value;
25
69
  }
26
- function delay(milliseconds) {
27
- return new Promise((resolve) => setTimeout(resolve, milliseconds));
70
+ function delay(milliseconds, signal) {
71
+ return new Promise((resolve, reject) => {
72
+ let timer;
73
+ const done = () => {
74
+ signal?.removeEventListener("abort", abort);
75
+ resolve();
76
+ };
77
+ const abort = () => {
78
+ clearTimeout(timer);
79
+ signal?.removeEventListener("abort", abort);
80
+ reject(signal?.reason ?? new Error("upstream request aborted"));
81
+ };
82
+ timer = setTimeout(done, milliseconds);
83
+ if (signal?.aborted)
84
+ abort();
85
+ else
86
+ signal?.addEventListener("abort", abort, { once: true });
87
+ });
28
88
  }
29
89
  const SHARED_ORDINARY_BUDGET = 30;
30
- async function observeWaitStatuses(path, ids, settings) {
90
+ async function observeWaitRound(path, ids, signal) {
91
+ signal?.throwIfAborted();
31
92
  if (ids.length <= 1) {
32
- return await Promise.all(ids.map(async (id) => await source(path, settings).of({ id }).status()));
93
+ return {
94
+ statuses: await Promise.all(ids.map(async (id) => await source(path).of({ id }).status())),
95
+ unobserved: [],
96
+ };
33
97
  }
34
98
  let remaining = SHARED_ORDINARY_BUDGET;
35
99
  const statuses = [];
100
+ const unobserved = [];
36
101
  for (const id of ids) {
37
- const observed = await readBudgetedStatus(path, id, { ordinaryBudget: remaining });
38
- statuses.push(observed.status);
39
- remaining -= observed.ordinarySelected;
102
+ signal?.throwIfAborted();
103
+ try {
104
+ const observed = await readBudgetedStatus(path, id, { ordinaryBudget: remaining });
105
+ statuses.push(observed.status);
106
+ remaining -= observed.ordinarySelected;
107
+ }
108
+ catch (error) {
109
+ if (error instanceof AkumaNotBornError)
110
+ throw error;
111
+ unobserved.push({ id, diagnostic: observationDiagnostic(error) });
112
+ }
40
113
  }
41
- return statuses;
114
+ return { statuses, unobserved };
115
+ }
116
+ export async function executeWaitAkuma(input) {
117
+ const deadline = input.timeoutMs === undefined ? undefined : performance.now() + input.timeoutMs;
118
+ for (;;) {
119
+ const round = await observeWaitRound(input.path, input.ids, input.signal);
120
+ const settled = round.statuses.map((status) => status.life !== "running");
121
+ const completed = round.statuses.length > 0
122
+ && (input.completion === "any" ? settled.some(Boolean) : settled.every(Boolean));
123
+ if (completed
124
+ || (deadline !== undefined && performance.now() >= deadline)) {
125
+ return {
126
+ completion: input.completion,
127
+ observations: await observeAkumaSet(round.statuses, input.path, input.repo),
128
+ unobserved: round.unobserved,
129
+ };
130
+ }
131
+ await delay(deadline === undefined ? 25 : Math.min(25, Math.max(0, deadline - performance.now())), input.signal);
132
+ }
133
+ }
134
+ export async function executeTellAkuma(input) {
135
+ input.signal?.throwIfAborted();
136
+ const handle = source(input.path).of({ id: input.id });
137
+ const tell = input.tellId === undefined
138
+ ? await handle.tell(input.body)
139
+ : await tellAkumaWithId(input.path, input.id, input.body, input.tellId, input.recordedAt);
140
+ input.signal?.throwIfAborted();
141
+ return {
142
+ akuma: input.id,
143
+ tell,
144
+ observation: await observeAkumaStage(input.path, input.id, input.repo),
145
+ };
146
+ }
147
+ export async function executeKillAkuma(input) {
148
+ input.signal?.throwIfAborted();
149
+ const handles = input.ids.map((id) => source(input.path).of({ id }));
150
+ const evidence = await Promise.all(handles.map(async (handle) => await handle.kill()));
151
+ input.signal?.throwIfAborted();
152
+ return {
153
+ results: await Promise.all(input.ids.map(async (id, index) => ({
154
+ id,
155
+ evidence: evidence[index],
156
+ observation: await observeAkumaStage(input.path, id, input.repo),
157
+ }))),
158
+ };
159
+ }
160
+ function upstreamResult(outcome) {
161
+ if (outcome.kind === "returned")
162
+ return outcome.result;
163
+ if (outcome.failure.kind === "akuma-not-born")
164
+ throw new AkumaNotBornError(outcome.failure.id);
165
+ throw new Error(outcome.failure.diagnostic);
166
+ }
167
+ function needsDispatchAttach(association) {
168
+ return association.kind === "none";
169
+ }
170
+ async function attachObservationContract(repo, observation) {
171
+ if (repo === undefined || !needsDispatchAttach(observation.contract))
172
+ return observation;
173
+ return { ...observation, contract: await dispatchAssociation(repo, observation.status.id) };
174
+ }
175
+ async function attachObservationStage(repo, observation) {
176
+ if (repo === undefined || observation.kind !== "observed")
177
+ return observation;
178
+ return { ...observation, ...(await attachObservationContract(repo, observation)) };
179
+ }
180
+ async function attachWaitContracts(repo, result) {
181
+ return repo === undefined
182
+ ? result
183
+ : {
184
+ ...result,
185
+ observations: await Promise.all(result.observations.map((observation) => attachObservationContract(repo, observation))),
186
+ };
187
+ }
188
+ async function attachTellContract(repo, result) {
189
+ return repo === undefined ? result : { ...result, observation: await attachObservationStage(repo, result.observation) };
190
+ }
191
+ async function attachKillContracts(repo, result) {
192
+ return repo === undefined
193
+ ? result
194
+ : {
195
+ ...result,
196
+ results: await Promise.all(result.results.map(async (entry) => ({
197
+ ...entry,
198
+ observation: await attachObservationStage(repo, entry.observation),
199
+ }))),
200
+ };
42
201
  }
43
202
  function directAddress(values) {
44
203
  return {
45
204
  path: values.path,
46
205
  akuma: values.akuma,
47
- ...(values.settings === undefined ? {} : { settings: values.settings }),
48
206
  ...(values.repo === undefined ? {} : { repo: values.repo }),
49
207
  };
50
208
  }
@@ -52,18 +210,17 @@ function setAddress(values) {
52
210
  return {
53
211
  path: values.path,
54
212
  akuma: values.akuma,
55
- ...(values.settings === undefined ? {} : { settings: values.settings }),
56
213
  ...(values.repo === undefined ? {} : { repo: values.repo }),
57
214
  };
58
215
  }
59
216
  export async function statusAkuma(input) {
60
217
  const addressed = await addressAkuma(input);
61
- return await statusView(await source(addressed.path, addressed.settings).of({ id: addressed.id }).status(), input.repo);
218
+ return await observeAkuma(await source(addressed.path).of({ id: addressed.id }).status(), addressed.path, input.repo);
62
219
  }
63
220
  export async function waitAkuma(input) {
64
221
  const values = requireInput(input, "Keiyaku.wait input");
65
222
  for (const key of Object.keys(values)) {
66
- if (!["path", "akuma", "settings", "repo", "completion", "timeoutMs"].includes(key)) {
223
+ if (!["path", "akuma", "repo", "completion", "timeoutMs"].includes(key)) {
67
224
  throw new TypeError(`Keiyaku.wait input has unknown field: ${key}`);
68
225
  }
69
226
  }
@@ -72,82 +229,105 @@ export async function waitAkuma(input) {
72
229
  if (addressed.ids.length > 1 && completion !== "any" && completion !== "all") {
73
230
  throw new TypeError("completion must be any or all when waiting for multiple Akuma");
74
231
  }
75
- if (completion !== undefined && completion !== "any" && completion !== "all")
232
+ if (completion !== undefined && completion !== "any" && completion !== "all") {
76
233
  throw new TypeError("completion must be any or all");
234
+ }
77
235
  const selected = completion ?? "all";
78
236
  const timeoutMs = timeout(values.timeoutMs);
79
- const deadline = timeoutMs === undefined ? undefined : performance.now() + timeoutMs;
80
- for (;;) {
81
- const statuses = await observeWaitStatuses(addressed.path, addressed.ids, addressed.settings);
82
- const settled = statuses.map((status) => status.life !== "running");
83
- if ((selected === "any" ? settled.some(Boolean) : settled.every(Boolean))
84
- || (deadline !== undefined && performance.now() >= deadline)) {
85
- return { completion: selected, statuses: await Promise.all(statuses.map(async (status) => await statusView(status, values.repo))) };
86
- }
87
- await delay(deadline === undefined ? 25 : Math.min(25, Math.max(0, deadline - performance.now())));
237
+ const requests = injectedBodyRequests();
238
+ if (requests !== null) {
239
+ const outcome = await requestBodyWait({
240
+ directory: requests,
241
+ targets: addressed.ids,
242
+ completion: selected,
243
+ ...(timeoutMs === undefined ? {} : { timeoutMs }),
244
+ });
245
+ return await attachWaitContracts(values.repo, upstreamResult(outcome));
88
246
  }
247
+ return await executeWaitAkuma({
248
+ path: addressed.path,
249
+ ids: addressed.ids,
250
+ completion: selected,
251
+ ...(timeoutMs === undefined ? {} : { timeoutMs }),
252
+ ...(values.repo === undefined ? {} : { repo: values.repo }),
253
+ });
89
254
  }
90
255
  export async function killAkuma(input) {
91
256
  const addressed = await addressAkumaSet(input);
92
- const handles = addressed.ids.map((id) => source(addressed.path, addressed.settings).of({ id }));
93
- const evidence = await Promise.all(handles.map(async (handle) => await handle.kill()));
94
- const observations = await Promise.all(addressed.ids.map(async (id) => await statusView(await readActionFeedbackStatus(addressed.path, id), input.repo)));
95
- return {
96
- results: addressed.ids.map((id, index) => ({
97
- id,
98
- evidence: evidence[index],
99
- observation: observations[index],
100
- })),
101
- };
257
+ const requests = injectedBodyRequests();
258
+ if (requests !== null) {
259
+ const outcome = await requestBodyKill({ directory: requests, targets: addressed.ids });
260
+ return await attachKillContracts(input.repo, upstreamResult(outcome));
261
+ }
262
+ return await executeKillAkuma({
263
+ path: addressed.path,
264
+ ids: addressed.ids,
265
+ ...(input.repo === undefined ? {} : { repo: input.repo }),
266
+ });
102
267
  }
103
268
  export async function tellAkuma(input) {
104
269
  const values = requireInput(input, "Keiyaku.tell input");
105
270
  for (const key of Object.keys(values)) {
106
- if (!["path", "akuma", "settings", "body", "repo"].includes(key))
271
+ if (!["path", "akuma", "body", "repo"].includes(key)) {
107
272
  throw new TypeError(`Keiyaku.tell input has unknown field: ${key}`);
273
+ }
108
274
  }
109
275
  if (typeof values.body !== "string")
110
276
  throw new TypeError("body must be a string");
111
277
  const addressed = await addressAkuma(directAddress(values));
112
- const handle = source(addressed.path, addressed.settings).of({ id: addressed.id });
113
- const tell = await handle.tell(values.body);
114
- return { akuma: addressed.id, tell, observation: await statusView(await readActionFeedbackStatus(addressed.path, addressed.id), values.repo) };
278
+ const requests = injectedBodyRequests();
279
+ if (requests !== null) {
280
+ const outcome = await requestBodyTell({
281
+ directory: requests,
282
+ target: addressed.id,
283
+ body: values.body,
284
+ });
285
+ return await attachTellContract(values.repo, upstreamResult(outcome));
286
+ }
287
+ return await executeTellAkuma({
288
+ path: addressed.path,
289
+ id: addressed.id,
290
+ body: values.body,
291
+ ...(values.repo === undefined ? {} : { repo: values.repo }),
292
+ });
115
293
  }
116
294
  export async function interruptAkuma(input) {
117
295
  const values = requireInput(input, "Keiyaku.interrupt input");
118
296
  for (const key of Object.keys(values)) {
119
- if (!["path", "akuma", "settings", "body", "repo"].includes(key))
297
+ if (!["path", "akuma", "body", "repo"].includes(key)) {
120
298
  throw new TypeError(`Keiyaku.interrupt input has unknown field: ${key}`);
299
+ }
121
300
  }
122
301
  if (typeof values.body !== "string")
123
302
  throw new TypeError("body must be a string");
124
303
  const addressed = await addressAkuma(directAddress(values));
125
- const receipt = await source(addressed.path, addressed.settings).of({ id: addressed.id }).interrupt(values.body);
126
- return { id: addressed.id, receipt, observation: await statusView(await readActionFeedbackStatus(addressed.path, addressed.id), values.repo) };
304
+ const handle = source(addressed.path).of({ id: addressed.id });
305
+ const receipt = await handle.interrupt(values.body);
306
+ const observation = await observeAkumaStage(addressed.path, addressed.id, values.repo);
307
+ return { id: addressed.id, receipt, observation };
127
308
  }
128
309
  export async function historyAkuma(input) {
129
310
  const values = requireInput(input, "Keiyaku.history input");
130
311
  for (const key of Object.keys(values)) {
131
- if (!["path", "akuma", "settings", "before", "since", "limit", "last", "repo"].includes(key)) {
312
+ if (!["path", "akuma", "before", "since", "limit", "last", "repo"].includes(key)) {
132
313
  throw new TypeError(`Keiyaku.history input has unknown field: ${key}`);
133
314
  }
134
315
  }
135
316
  if (values.last !== undefined && typeof values.last !== "boolean")
136
317
  throw new TypeError("last must be a boolean");
137
318
  const addressed = await addressAkuma(directAddress(values));
138
- const handle = source(addressed.path, addressed.settings).of({ id: addressed.id });
319
+ const handle = source(addressed.path).of({ id: addressed.id });
320
+ const contract = await dispatchAssociation(values.repo, addressed.id);
139
321
  if (values.last === true) {
140
322
  const answer = await handle.lastAnswer();
141
- const contractId = await contractFor(values.repo, addressed.id);
142
323
  return answer.kind === "answer"
143
- ? { kind: "last", id: addressed.id, answer: answer.answer, ...(contractId === undefined ? {} : { contractId }) }
144
- : { kind: "no-answer", id: addressed.id, ...(contractId === undefined ? {} : { contractId }) };
324
+ ? { kind: "last", id: addressed.id, answer: answer.answer, contract }
325
+ : { kind: "no-answer", id: addressed.id, contract };
145
326
  }
146
327
  const history = await handle.history({
147
328
  ...(values.before === undefined ? {} : { before: values.before }),
148
329
  ...(values.since === undefined ? {} : { since: values.since }),
149
330
  ...(values.limit === undefined ? {} : { limit: values.limit }),
150
331
  });
151
- const contractId = await contractFor(values.repo, addressed.id);
152
- return { kind: "history", id: addressed.id, history, ...(contractId === undefined ? {} : { contractId }) };
332
+ return { kind: "history", id: addressed.id, history, contract };
153
333
  }
@@ -6,7 +6,6 @@ export declare function actorOption(actor: unknown): Readonly<{
6
6
  }>;
7
7
  export declare function requireMarkdown(value: unknown, label?: string): string;
8
8
  export declare function requireInput(value: unknown, label: string): Record<string, unknown>;
9
- export declare function rejectUnknownFields(values: Record<string, unknown>, allowed: readonly string[], label: string): void;
10
9
  export declare function optionalNonblank(value: unknown, label: string): string | undefined;
11
10
  export declare function optionalBoolean(value: unknown, label: string): boolean | undefined;
12
11
  export declare function optionalSignal(value: unknown): AbortSignal | undefined;
@@ -22,11 +22,6 @@ export function requireInput(value, label) {
22
22
  throw new TypeError(`${label} must be an object`);
23
23
  return value;
24
24
  }
25
- export function rejectUnknownFields(values, allowed, label) {
26
- for (const key of Object.keys(values))
27
- if (!allowed.includes(key))
28
- throw new TypeError(`${label} has unknown field: ${key}`);
29
- }
30
25
  export function optionalNonblank(value, label) {
31
26
  if (value === undefined)
32
27
  return undefined;
@@ -91,6 +86,7 @@ export function contractTerms(document, gates, after) {
91
86
  export function documentDerivation(document, gates, contractId) {
92
87
  return {
93
88
  document: document.document.key,
89
+ bytes: document.document.bytes,
94
90
  title: document.title,
95
91
  verification: prepareVerificationDeclaration({
96
92
  gates,
@@ -5,10 +5,9 @@ import { listCatalog } from "./catalog.js";
5
5
  export { AuthorityCorruptionError } from "../core/facts/errors.js";
6
6
  export { Delivery, KeiyakuRefused, KeiyakuRetry, } from "./contract.js";
7
7
  export { NoGitWorldError, Repo } from "./repo.js";
8
- export { gatesFrom, requireBranchesToBeUpToDateFrom, SettingsError, } from "./configuration.js";
9
- export { worktreeHooksFrom } from "../git/hooks.js";
8
+ export { gatesFrom, requireBranchesToBeUpToDateFrom, SettingsError, worktreeHooksFrom, } from "./configuration.js";
10
9
  export { AkumaWorldScopeError } from "./address.js";
11
- export type { AbandonInput, ActorId, AmendInput, AmendResult, ArcInput, AttestationVerdict, AuditInput, AuditReport, DeliveryPreparationRefusal, BindInput, BindResult, ContractBoard, ContractDisposition, ContractGateCurrent, ContractGateReport, ContractListInput, ContractObservation, ContractObservationInput, ContractPhase, ContractRow, DeliverInput, Fact, FactKind, KeiyakuOfInput, KeiyakuRefusal, KeiyakuRetryReason, Lag, MutationResult, PlacementStop, ReconcileReport, Review, ReviewInput, TaskId, TopologyEffect, VerificationReuse, VerificationStop, } from "./contract.js";
10
+ export type { AbandonInput, ActorId, AmendInput, AmendResult, ArcInput, AttestationVerdict, AuditInput, AuditReport, DeliveryPreparationRefusal, BindInput, BindResult, ContractBoard, ContractDisposition, ContractGateCurrent, ContractGateReport, ContractHistory, ContractHistoryEvent, ContractListInput, ContractObservation, ContractObservationInput, ContractPhase, ContractRow, DeliverInput, Fact, FactKind, KeiyakuOfInput, KeiyakuRefusal, KeiyakuRetryReason, Lag, MutationResult, PlacementStop, ReconcileReport, Review, ReviewInput, TaskId, TopologyEffect, VerificationReuse, VerificationStop, } from "./contract.js";
12
11
  export type { ContractId, ContractState, ChangeId, SnapshotId, } from "../core/facts/types.js";
13
12
  export type { Gate, GatesFromInput, HookCommand, RequireBranchesToBeUpToDateFromInput, WorktreeHooks, } from "./configuration.js";
14
13
  export type { RegionOverlap } from "./region.js";
@@ -20,9 +19,10 @@ export type { Dispatch, DispatchFailure } from "../dispatch/index.js";
20
19
  export type { AkumaAlias } from "../identity/selector.js";
21
20
  export type { AkumaGlob } from "../identity/selector.js";
22
21
  export type { AkuId } from "../akuma/identity.js";
22
+ export type { AllowedAction, AllowedActions } from "../akuma/allowed.js";
23
23
  export type { Catalog, CatalogInput, CatalogQuery } from "./catalog.js";
24
24
  export type { AkumaAddressInput, AkumaSetAddressInput, AkumaWorldScopeRefusal, DirectAkumaSelector, SetAkumaSelector, } from "./address.js";
25
- export type { AkumaHistoryInput, AkumaHistoryResult, AkumaInterruptInput, AkumaInterruptResult, AkumaKillResult, AkumaStatusView, AkumaTellInput, AkumaTellResult, AkumaWaitInput, AkumaWaitResult, } from "./fleet.js";
25
+ export type { AkumaHistoryInput, AkumaHistoryResult, AkumaInterruptInput, AkumaInterruptResult, AkumaKillResult, AkumaObservation, AkumaObservationStage, AkumaTellInput, AkumaUnobserved, CreatedTaskObservation, DispatchAssociation, AkumaTellResult, AkumaWaitInput, AkumaWaitResult, } from "./fleet.js";
26
26
  export type Keiyaku = KeiyakuType;
27
27
  export declare const Keiyaku: Readonly<{
28
28
  prototype: KeiyakuHandle;
@@ -5,8 +5,7 @@ import { listCatalog } from "./catalog.js";
5
5
  export { AuthorityCorruptionError } from "../core/facts/errors.js";
6
6
  export { Delivery, KeiyakuRefused, KeiyakuRetry, } from "./contract.js";
7
7
  export { NoGitWorldError, Repo } from "./repo.js";
8
- export { gatesFrom, requireBranchesToBeUpToDateFrom, SettingsError, } from "./configuration.js";
9
- export { worktreeHooksFrom } from "../git/hooks.js";
8
+ export { gatesFrom, requireBranchesToBeUpToDateFrom, SettingsError, worktreeHooksFrom, } from "./configuration.js";
10
9
  export { AkumaWorldScopeError } from "./address.js";
11
10
  export const Keiyaku = Object.freeze({
12
11
  prototype: KeiyakuHandle.prototype,
@@ -1,6 +1,7 @@
1
1
  import type { ContractHead, ContractId, JournalEntry } from "../core/facts/types.js";
2
2
  import type { GitDecodeChannel } from "../git/read-observation.js";
3
- import type { ReconcileReport, RepositoryScope } from "../protocol/operations.js";
3
+ import type { ReconcileReport } from "../protocol/reconcile.js";
4
+ import type { RepositoryScope } from "../protocol/operations.js";
4
5
  import type { IntentOutcome } from "../protocol/operations.js";
5
6
  import type { AcceptedObligations } from "../protocol/outcome.js";
6
7
  import { type SettlementReport } from "../settlement/settle.js";
@@ -1,6 +1,7 @@
1
1
  import type { ContractId } from "../core/facts/types.js";
2
2
  import type { GitDecodeChannel } from "../git/read-observation.js";
3
- import { type ReconcileReport, type RepositoryScope } from "../protocol/operations.js";
3
+ import { type ReconcileReport } from "../protocol/reconcile.js";
4
+ import { type RepositoryScope } from "../protocol/operations.js";
4
5
  import { type SettlementReport } from "../settlement/settle.js";
5
6
  import type { WorktreeHooks } from "./configuration.js";
6
7
  import { type ContractFileEffect, type ContractFileLag } from "../contract-worktree.js";
@@ -1,5 +1,7 @@
1
1
  import { AuthorityCorruptionError } from "../core/facts/errors.js";
2
- import { reconcileAllOperation, reconcileObservationFailure, reconcileOperation, stateOperation, worldContractStates, } from "../protocol/operations.js";
2
+ import { reconcileAllOperation, reconcileOperation, worldContractStates, } from "../protocol/reconcile.js";
3
+ import { reconcileObservationFailure } from "../git/reconcile.js";
4
+ import { stateOperation } from "../protocol/operations.js";
3
5
  import { settle, settleAll } from "../settlement/settle.js";
4
6
  import { projectContractWorktree, } from "../contract-worktree.js";
5
7
  import { appointManagedWorktrees, placeRegisterPath, releaseManagedWorktrees, } from "../workspace-place.js";
@@ -1,7 +1,7 @@
1
1
  import type { ContractId } from "../core/facts/types.js";
2
2
  import type { GitDecodeChannel } from "../git/read-observation.js";
3
3
  import { type RepositoryScope } from "../protocol/operations.js";
4
- import type { ContractDocumentProjection } from "../protocol/operations.js";
4
+ import type { ContractDocumentProjection } from "../protocol/read/documents.js";
5
5
  export type RegionOverlap = Readonly<{
6
6
  contract: ContractId;
7
7
  patterns: readonly Readonly<{
@@ -1,10 +1,12 @@
1
- import { NoGitWorldError, type RepositoryScope } from "../protocol/operations.js";
1
+ import { type RepositoryScope } from "../protocol/operations.js";
2
+ import { NoGitWorldError } from "../git/repository.js";
2
3
  import { type WorktreeHooks } from "./configuration.js";
3
4
  import { type RepoContractReconcileReport, type RepoReconcileReport } from "./reconcile.js";
4
5
  export { NoGitWorldError };
5
6
  export type { RepoContractReconcileReport, RepoReconcileReport };
6
7
  export type RepoAtInput = Readonly<{
7
8
  path?: string;
9
+ gitPath?: string;
8
10
  }>;
9
11
  export type ReconcileInput = Readonly<{
10
12
  hooks?: WorktreeHooks;
@@ -1,12 +1,16 @@
1
- import { currentBranchOperation, NoGitWorldError, scopeOperation, } from "../protocol/operations.js";
1
+ import { currentBranchOperation, scopeOperation, } from "../protocol/operations.js";
2
+ import { NoGitWorldError } from "../git/repository.js";
2
3
  import { optionalNonblank, requireInput } from "./input.js";
3
4
  import { worktreeHooksOption } from "./configuration.js";
4
5
  import { withGitDecodeChannel } from "../git/read-observation.js";
5
6
  import { completeRepoReconcile, } from "./reconcile.js";
6
7
  export { NoGitWorldError };
7
8
  const REPO_SCOPES = new WeakMap();
8
- async function resolvePinnedScope(path) {
9
- return await scopeOperation({ coordinate: path === undefined ? process.cwd() : path });
9
+ async function resolvePinnedScope(path, gitPath) {
10
+ return await scopeOperation({
11
+ coordinate: path === undefined ? process.cwd() : path,
12
+ ...(gitPath === undefined ? {} : { gitPath }),
13
+ });
10
14
  }
11
15
  export function reconcileInput(input) {
12
16
  const values = input === undefined ? undefined : requireInput(input, "reconcile input");
@@ -26,7 +30,7 @@ export class Repo {
26
30
  }
27
31
  static async at(input) {
28
32
  const values = input === undefined ? undefined : requireInput(input, "Repo.at input");
29
- return new Repo(await resolvePinnedScope(optionalNonblank(values?.path, "repository path")));
33
+ return new Repo(await resolvePinnedScope(optionalNonblank(values?.path, "repository path"), optionalNonblank(values?.gitPath, "Git executable path")));
30
34
  }
31
35
  async currentBranch() {
32
36
  return await currentBranchOperation({ scope: scopeForRepo(this) });
@@ -0,0 +1,9 @@
1
+ import { type AbandonRefusal } from "../core/verbs/abandon.js";
2
+ import type { GitTreeSelection } from "../git/read-observation.js";
3
+ import type { CompanionDecorator } from "./run.js";
4
+ import type { IntentOutcome, MutationOperationInput } from "./operations.js";
5
+ export declare function abandonOperation(input: MutationOperationInput & Readonly<{
6
+ note?: string;
7
+ decorateOffer?: CompanionDecorator;
8
+ observationSelection?: GitTreeSelection;
9
+ }>): Promise<IntentOutcome<void, AbandonRefusal>>;
@@ -0,0 +1,15 @@
1
+ import { decideAbandon } from "../core/verbs/abandon.js";
2
+ import { admitIntent } from "./intent.js";
3
+ import { complete } from "./outcome.js";
4
+ import { timestamp } from "./operations.js";
5
+ export async function abandonOperation(input) {
6
+ return complete(await admitIntent(input.channel, input.scope, {
7
+ contractId: input.contractId,
8
+ ...(input.actor === undefined ? {} : { actor: input.actor }),
9
+ at: timestamp(),
10
+ ...(input.note === undefined ? {} : { note: input.note }),
11
+ }, decideAbandon, {
12
+ ...(input.decorateOffer === undefined ? {} : { decorateOffer: input.decorateOffer }),
13
+ ...(input.observationSelection === undefined ? {} : { observationSelection: input.observationSelection }),
14
+ }), undefined);
15
+ }
@@ -0,0 +1,16 @@
1
+ import type { AmendData, ContractTerms } from "../core/facts/types.js";
2
+ import { type AmendRefusal } from "../core/verbs/amend.js";
3
+ import type { VerificationDeclarationPreparation, VerificationDeclarationRefusal } from "../verification/declaration.js";
4
+ import type { MutationOperationInput, IntentOutcome } from "./operations.js";
5
+ type AmendOperationInput = MutationOperationInput & Readonly<{
6
+ source?: ContractTerms;
7
+ deriveAmendment?: (source: ContractTerms) => Readonly<{
8
+ terms: AmendData;
9
+ verification: VerificationDeclarationPreparation;
10
+ }>;
11
+ }>;
12
+ type Amendment = Readonly<{
13
+ source: ContractTerms;
14
+ }> & ReturnType<NonNullable<AmendOperationInput["deriveAmendment"]>>;
15
+ export declare function amendOperation(input: AmendOperationInput): Promise<IntentOutcome<Amendment, AmendRefusal | VerificationDeclarationRefusal>>;
16
+ export {};