@astrosheep/keiyaku 4.1.0 → 4.1.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 (278) hide show
  1. package/README.md +1 -1
  2. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +3 -0
  3. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +3 -0
  4. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +3 -6
  5. package/build/src/akuma/akuma-errors.d.ts +6 -0
  6. package/build/src/akuma/akuma-errors.js +9 -0
  7. package/build/src/akuma/akuma-handle.d.ts +39 -0
  8. package/build/src/akuma/akuma-handle.js +263 -0
  9. package/build/src/akuma/akuma-observe.d.ts +19 -0
  10. package/build/src/akuma/akuma-observe.js +74 -0
  11. package/build/src/akuma/akuma-product-symbols.d.ts +1 -0
  12. package/build/src/akuma/akuma-product-symbols.js +1 -0
  13. package/build/src/akuma/akuma-product.d.ts +18 -0
  14. package/build/src/akuma/akuma-product.js +154 -0
  15. package/build/src/akuma/akuma.d.ts +37 -81
  16. package/build/src/akuma/akuma.js +39 -447
  17. package/build/src/akuma/allowed.d.ts +1 -0
  18. package/build/src/akuma/allowed.js +6 -0
  19. package/build/src/akuma/archetype.js +8 -5
  20. package/build/src/akuma/body-supervisor.d.ts +26 -0
  21. package/build/src/akuma/body-supervisor.js +89 -0
  22. package/build/src/akuma/body.d.ts +45 -4
  23. package/build/src/akuma/body.js +145 -35
  24. package/build/src/akuma/coordinate.js +17 -7
  25. package/build/src/akuma/heart/facts.js +1 -1
  26. package/build/src/akuma/heart/index.d.ts +1 -1
  27. package/build/src/akuma/heart/index.js +2 -4
  28. package/build/src/akuma/heart/request-authority.js +4 -4
  29. package/build/src/akuma/heart/request-rows.js +27 -16
  30. package/build/src/akuma/heart/rows.js +79 -41
  31. package/build/src/akuma/heart/soul.js +1 -1
  32. package/build/src/akuma/heart/storage.d.ts +1 -0
  33. package/build/src/akuma/heart/storage.js +76 -11
  34. package/build/src/akuma/heart/tells.js +35 -18
  35. package/build/src/akuma/heart/timeline.js +19 -11
  36. package/build/src/akuma/identity.d.ts +1 -0
  37. package/build/src/akuma/identity.js +1 -0
  38. package/build/src/akuma/index.d.ts +3 -3
  39. package/build/src/akuma/index.js +1 -1
  40. package/build/src/akuma/nuke.js +106 -14
  41. package/build/src/akuma/projection-read.d.ts +17 -0
  42. package/build/src/akuma/projection-read.js +135 -0
  43. package/build/src/akuma/projection.d.ts +1 -16
  44. package/build/src/akuma/projection.js +77 -154
  45. package/build/src/akuma/provider-recipe.js +11 -5
  46. package/build/src/akuma/provider.js +105 -62
  47. package/build/src/akuma/providers/acp/config.js +5 -6
  48. package/build/src/akuma/providers/acp/core.js +17 -10
  49. package/build/src/akuma/providers/acp/events.js +38 -29
  50. package/build/src/akuma/providers/acp/index.js +13 -9
  51. package/build/src/akuma/providers/claude/events.js +8 -12
  52. package/build/src/akuma/providers/claude/index.d.ts +1 -0
  53. package/build/src/akuma/providers/claude/index.js +55 -26
  54. package/build/src/akuma/providers/claude/input.js +6 -2
  55. package/build/src/akuma/providers/codex-app-server/events.js +61 -36
  56. package/build/src/akuma/providers/codex-app-server/index.js +25 -13
  57. package/build/src/akuma/providers/grok-build/index.js +22 -25
  58. package/build/src/akuma/providers/index.js +2 -18
  59. package/build/src/akuma/providers/opencode-sdk/events.js +32 -18
  60. package/build/src/akuma/providers/opencode-sdk/index.js +26 -17
  61. package/build/src/akuma/providers/opencode-sdk/session.js +21 -5
  62. package/build/src/akuma/providers/pi/events.js +26 -19
  63. package/build/src/akuma/providers/pi/index.js +58 -40
  64. package/build/src/akuma/publication.js +9 -9
  65. package/build/src/akuma/request-execution.d.ts +6 -0
  66. package/build/src/akuma/request-execution.js +86 -0
  67. package/build/src/akuma/request-serve.d.ts +12 -1
  68. package/build/src/akuma/request-serve.js +19 -122
  69. package/build/src/akuma/request-wire.d.ts +2 -2
  70. package/build/src/akuma/request-wire.js +75 -102
  71. package/build/src/akuma/requests.js +2 -2
  72. package/build/src/akuma/{body-turn.d.ts → turn-drive.d.ts} +2 -25
  73. package/build/src/akuma/{body-turn.js → turn-drive.js} +20 -103
  74. package/build/src/akuma-body.js +6 -5
  75. package/build/src/body/amend.d.ts +4 -1
  76. package/build/src/body/amend.js +14 -6
  77. package/build/src/body/decode.js +2 -4
  78. package/build/src/body/envelope.js +2 -4
  79. package/build/src/body/region.d.ts +1 -2
  80. package/build/src/body/region.js +2 -70
  81. package/build/src/body/render.js +17 -12
  82. package/build/src/body/shape.js +1 -7
  83. package/build/src/cli/accepted.d.ts +1 -1
  84. package/build/src/cli/accepted.js +8 -1
  85. package/build/src/cli/commands/akuma-invoke.js +18 -6
  86. package/build/src/cli/commands/akuma.d.ts +0 -6
  87. package/build/src/cli/commands/akuma.js +11 -24
  88. package/build/src/cli/commands/amend.d.ts +2 -2
  89. package/build/src/cli/commands/amend.js +2 -4
  90. package/build/src/cli/commands/bind.d.ts +4 -4
  91. package/build/src/cli/commands/bind.js +16 -6
  92. package/build/src/cli/commands/contract-invoke.d.ts +25 -0
  93. package/build/src/cli/commands/contract-invoke.js +193 -0
  94. package/build/src/cli/commands/contract.d.ts +109 -10
  95. package/build/src/cli/commands/contract.js +339 -16
  96. package/build/src/cli/commands/install.d.ts +1 -1
  97. package/build/src/cli/commands/install.js +23 -15
  98. package/build/src/cli/commands/task-invoke.js +187 -67
  99. package/build/src/cli/commands/task-query.js +48 -24
  100. package/build/src/cli/commands/task.js +150 -38
  101. package/build/src/cli/coordinates.js +2 -4
  102. package/build/src/cli/invoke.js +92 -208
  103. package/build/src/cli/main.js +4 -2
  104. package/build/src/cli/parse.d.ts +3 -90
  105. package/build/src/cli/parse.js +27 -233
  106. package/build/src/cli/render/akuma-activity.d.ts +38 -0
  107. package/build/src/cli/render/akuma-activity.js +362 -0
  108. package/build/src/cli/render/akuma-tool-command.js +6 -7
  109. package/build/src/cli/render/akuma-tool.js +10 -8
  110. package/build/src/cli/render/akuma.d.ts +1 -1
  111. package/build/src/cli/render/akuma.js +61 -353
  112. package/build/src/cli/render/audit.js +5 -15
  113. package/build/src/cli/render/board.d.ts +1 -0
  114. package/build/src/cli/render/board.js +17 -0
  115. package/build/src/cli/render/catalog.js +81 -8
  116. package/build/src/cli/render/contract-history.d.ts +2 -0
  117. package/build/src/cli/render/contract-history.js +83 -0
  118. package/build/src/cli/render/contract-observation.d.ts +10 -0
  119. package/build/src/cli/render/contract-observation.js +58 -0
  120. package/build/src/cli/render/contract.d.ts +1 -2
  121. package/build/src/cli/render/contract.js +41 -142
  122. package/build/src/cli/render/kanshi.js +239 -215
  123. package/build/src/cli/render/receipt.js +2 -9
  124. package/build/src/cli/render/refusal.js +10 -15
  125. package/build/src/cli/render/region.js +22 -6
  126. package/build/src/cli/render/settings.js +4 -4
  127. package/build/src/cli/render/task.js +34 -14
  128. package/build/src/cli/render/terminal.js +16 -5
  129. package/build/src/cli/result.d.ts +3 -3
  130. package/build/src/cli/runtime.d.ts +6 -1
  131. package/build/src/cli/runtime.js +84 -63
  132. package/build/src/cli/selectors.js +2 -4
  133. package/build/src/cli/usage.js +6 -5
  134. package/build/src/contract-worktree.d.ts +1 -23
  135. package/build/src/contract-worktree.js +79 -155
  136. package/build/src/coordination/durable-file.js +7 -3
  137. package/build/src/coordination/sqlite-transaction-lock.js +29 -12
  138. package/build/src/core/facts/codec.js +7 -3
  139. package/build/src/core/facts/types.d.ts +1 -1
  140. package/build/src/core/subject.js +16 -9
  141. package/build/src/core/verbs/abandon.d.ts +1 -1
  142. package/build/src/core/verbs/abandon.js +1 -1
  143. package/build/src/core/verbs/amend.d.ts +1 -1
  144. package/build/src/core/verbs/amend.js +7 -7
  145. package/build/src/core/verbs/attestation.js +4 -1
  146. package/build/src/core/verbs/bind.d.ts +1 -1
  147. package/build/src/core/verbs/bind.js +1 -1
  148. package/build/src/core/verbs/placement.d.ts +1 -1
  149. package/build/src/core/verbs/placement.js +10 -8
  150. package/build/src/dispatch/index.js +8 -6
  151. package/build/src/duration.js +5 -1
  152. package/build/src/git/admission.js +5 -3
  153. package/build/src/git/hooks.d.ts +8 -0
  154. package/build/src/git/hooks.js +63 -14
  155. package/build/src/git/identity.js +1 -4
  156. package/build/src/git/integration.d.ts +2 -3
  157. package/build/src/git/integration.js +32 -39
  158. package/build/src/git/nuke.d.ts +1 -1
  159. package/build/src/git/nuke.js +110 -57
  160. package/build/src/git/observe.d.ts +13 -1
  161. package/build/src/git/observe.js +51 -44
  162. package/build/src/git/process.js +4 -2
  163. package/build/src/git/read-observation.js +10 -8
  164. package/build/src/git/reconcile.d.ts +22 -2
  165. package/build/src/git/reconcile.js +38 -274
  166. package/build/src/git/repository.d.ts +2 -0
  167. package/build/src/git/repository.js +13 -22
  168. package/build/src/git/scratch.d.ts +8 -5
  169. package/build/src/git/scratch.js +29 -2
  170. package/build/src/git/target-placement.d.ts +9 -10
  171. package/build/src/git/target-placement.js +59 -62
  172. package/build/src/git/tender.js +13 -46
  173. package/build/src/git/terminal-reconcile.d.ts +21 -0
  174. package/build/src/git/terminal-reconcile.js +278 -0
  175. package/build/src/git/terminal-seal.js +15 -12
  176. package/build/src/git/tree.js +5 -2
  177. package/build/src/git/workspace.d.ts +24 -2
  178. package/build/src/git/workspace.js +120 -16
  179. package/build/src/identity/coordinates.js +3 -1
  180. package/build/src/identity/selector.js +6 -3
  181. package/build/src/kanshi/fleet.d.ts +6 -0
  182. package/build/src/kanshi/fleet.js +27 -0
  183. package/build/src/kanshi/index.d.ts +1 -1
  184. package/build/src/kanshi/read.js +60 -48
  185. package/build/src/kanshi/report.d.ts +11 -23
  186. package/build/src/kanshi/select.js +25 -24
  187. package/build/src/library/address.d.ts +2 -1
  188. package/build/src/library/address.js +7 -8
  189. package/build/src/library/akuma-creation.js +20 -12
  190. package/build/src/library/audit.d.ts +0 -1
  191. package/build/src/library/audit.js +1 -2
  192. package/build/src/library/bind.d.ts +53 -5
  193. package/build/src/library/bind.js +98 -22
  194. package/build/src/library/catalog.d.ts +1 -0
  195. package/build/src/library/catalog.js +6 -3
  196. package/build/src/library/configuration.js +3 -1
  197. package/build/src/library/continuation.d.ts +15 -4
  198. package/build/src/library/continuation.js +24 -16
  199. package/build/src/library/contract-bind.d.ts +26 -0
  200. package/build/src/library/contract-bind.js +106 -0
  201. package/build/src/library/contract-operations.d.ts +77 -0
  202. package/build/src/library/contract-operations.js +130 -0
  203. package/build/src/library/contract-types.d.ts +95 -0
  204. package/build/src/library/contract-types.js +1 -0
  205. package/build/src/library/contract.d.ts +19 -154
  206. package/build/src/library/contract.js +46 -261
  207. package/build/src/library/fleet.d.ts +1 -1
  208. package/build/src/library/fleet.js +19 -11
  209. package/build/src/library/input.d.ts +2 -0
  210. package/build/src/library/input.js +14 -0
  211. package/build/src/library/keiyaku.d.ts +8 -7
  212. package/build/src/library/keiyaku.js +3 -3
  213. package/build/src/library/nuke.js +14 -5
  214. package/build/src/library/reconcile.d.ts +9 -4
  215. package/build/src/library/reconcile.js +30 -24
  216. package/build/src/library/refusal.d.ts +13 -5
  217. package/build/src/library/refusal.js +7 -0
  218. package/build/src/library/region.d.ts +8 -7
  219. package/build/src/library/region.js +31 -11
  220. package/build/src/library/repo.js +2 -2
  221. package/build/src/markdown/lex.js +9 -2
  222. package/build/src/markdown/parse.js +11 -7
  223. package/build/src/markdown/query.js +4 -2
  224. package/build/src/protocol/amend.js +3 -1
  225. package/build/src/protocol/attempt.d.ts +7 -3
  226. package/build/src/protocol/attempt.js +9 -5
  227. package/build/src/protocol/audit.d.ts +1 -1
  228. package/build/src/protocol/audit.js +4 -14
  229. package/build/src/protocol/bind.d.ts +19 -6
  230. package/build/src/protocol/bind.js +28 -13
  231. package/build/src/protocol/completion.d.ts +0 -1
  232. package/build/src/protocol/completion.js +1 -3
  233. package/build/src/protocol/deliver.d.ts +1 -3
  234. package/build/src/protocol/deliver.js +15 -39
  235. package/build/src/protocol/intent.d.ts +1 -0
  236. package/build/src/protocol/intent.js +9 -7
  237. package/build/src/protocol/operations.d.ts +3 -7
  238. package/build/src/protocol/operations.js +5 -3
  239. package/build/src/protocol/placement.d.ts +0 -1
  240. package/build/src/protocol/placement.js +6 -6
  241. package/build/src/protocol/read/observation.d.ts +11 -0
  242. package/build/src/protocol/read/observation.js +37 -0
  243. package/build/src/protocol/read/status.d.ts +23 -12
  244. package/build/src/protocol/read/status.js +90 -72
  245. package/build/src/protocol/reconcile.d.ts +1 -0
  246. package/build/src/protocol/reconcile.js +2 -3
  247. package/build/src/protocol/reintegrate.js +1 -1
  248. package/build/src/protocol/review.d.ts +0 -1
  249. package/build/src/protocol/review.js +15 -22
  250. package/build/src/protocol/run.d.ts +1 -0
  251. package/build/src/protocol/run.js +4 -5
  252. package/build/src/runtime/proc/launch.d.ts +33 -0
  253. package/build/src/runtime/proc/launch.js +98 -0
  254. package/build/src/runtime/proc/line-rpc.js +9 -3
  255. package/build/src/runtime/proc/run.d.ts +12 -6
  256. package/build/src/runtime/proc/run.js +78 -21
  257. package/build/src/runtime/proc/stdio.js +7 -10
  258. package/build/src/settings.js +6 -2
  259. package/build/src/settlement/holder.js +13 -10
  260. package/build/src/settlement/settle.js +39 -6
  261. package/build/src/task/board.js +12 -6
  262. package/build/src/task/compose.js +85 -22
  263. package/build/src/task/context.js +21 -8
  264. package/build/src/task/document.js +46 -10
  265. package/build/src/task/identity.js +5 -2
  266. package/build/src/task/index.d.ts +0 -1
  267. package/build/src/task/index.js +119 -34
  268. package/build/src/task/input.js +29 -7
  269. package/build/src/task/mutation.js +61 -19
  270. package/build/src/task/operations.d.ts +6 -1
  271. package/build/src/task/operations.js +83 -29
  272. package/build/src/task/query.js +55 -26
  273. package/build/src/task/store.d.ts +3 -1
  274. package/build/src/task/store.js +81 -17
  275. package/build/src/verification/execution.js +14 -11
  276. package/build/src/workspace-place.js +19 -7
  277. package/build/src/world.js +16 -6
  278. package/package.json +8 -3
@@ -1,8 +1,6 @@
1
1
  import { contractFromInput } from "../selectors.js";
2
- export function amendFromCommand({ command, repo, contract, markdown, gates, actor, hooks }) {
3
- const after = command.clearAfter === true
4
- ? []
5
- : command.after?.map((id) => contractFromInput(repo, id).id);
2
+ export function amendFromCommand({ command, repo, contract, markdown, gates, actor, hooks, }) {
3
+ const after = command.clearAfter === true ? [] : command.after?.map((id) => contractFromInput(repo, id).id);
6
4
  return contract.amend({
7
5
  ...(markdown === undefined ? {} : { markdown }),
8
6
  ...(actor === undefined ? {} : { actor }),
@@ -1,12 +1,12 @@
1
1
  import { type ActorId, type BindResult, type Gate, type Repo, type WorktreeHooks } from "../../index.js";
2
- import type { ParsedBind } from "../parse.js";
2
+ import type { ParsedBind } from "./contract.js";
3
3
  type BindCommandInput = Readonly<{
4
4
  command: ParsedBind;
5
5
  repo: Repo;
6
- markdown: string;
7
- gates: readonly Gate[];
6
+ markdown?: string;
7
+ gates?: readonly Gate[];
8
8
  actor?: ActorId;
9
9
  hooks?: WorktreeHooks;
10
10
  }>;
11
- export declare function bindFromCommand({ command, repo, markdown, gates, actor, hooks }: BindCommandInput): Promise<BindResult>;
11
+ export declare function bindFromCommand({ command, repo, markdown, gates, actor, hooks, }: BindCommandInput): Promise<BindResult>;
12
12
  export {};
@@ -1,14 +1,24 @@
1
- import { Keiyaku } from "../../index.js";
1
+ import { Keiyaku, } from "../../index.js";
2
+ import { bindFromCli } from "../../library/contract.js";
2
3
  import { contractFromInput } from "../selectors.js";
3
- export async function bindFromCommand({ command, repo, markdown, gates, actor, hooks }) {
4
+ export async function bindFromCommand({ command, repo, markdown, gates, actor, hooks, }) {
5
+ if (command.forkOf !== undefined) {
6
+ return Keiyaku.bind({
7
+ repo,
8
+ forkOf: contractFromInput(repo, command.forkOf).id,
9
+ ...(command.target === undefined ? {} : { target: command.target }),
10
+ ...(actor === undefined ? {} : { actor }),
11
+ ...(hooks === undefined ? {} : { hooks }),
12
+ });
13
+ }
4
14
  const after = command.after?.map((id) => contractFromInput(repo, id).id);
5
- const target = command.target ?? await repo.currentBranch();
6
- return Keiyaku.bind({
15
+ if (markdown === undefined || gates === undefined)
16
+ throw new Error("Markdown bind command is missing stdin terms");
17
+ return bindFromCli({
7
18
  repo,
8
19
  markdown,
9
20
  ...(command.task === undefined ? {} : { task: command.task }),
10
- ...(target === null ? {} : { target }),
11
- ...(command.workspace === undefined ? {} : { workspace: command.workspace }),
21
+ ...(command.target === undefined ? {} : { target: command.target }),
12
22
  ...(actor === undefined ? {} : { actor }),
13
23
  ...(hooks === undefined ? {} : { hooks }),
14
24
  ...(after === undefined ? {} : { after }),
@@ -0,0 +1,25 @@
1
+ import type { InvocationResult } from "../result.js";
2
+ import type { ParsedCommand } from "../parse.js";
3
+ import type { WorktreeHooks } from "../../library/configuration.js";
4
+ import type { Repo } from "../../library/repo.js";
5
+ import type { Settings } from "../../settings.js";
6
+ import type { WorldRoot } from "../../world.js";
7
+ type ContractMutation = Extract<ParsedCommand, {
8
+ command: "bind" | "amend" | "deliver" | "review" | "arc" | "abandon" | "audit";
9
+ }>;
10
+ type InvocationEdge = Readonly<{
11
+ environment: NodeJS.ProcessEnv;
12
+ readStdin: () => Promise<string>;
13
+ }>;
14
+ export type ContractMutationInput = Readonly<{
15
+ parsed: ContractMutation;
16
+ repo: Repo;
17
+ edge: InvocationEdge;
18
+ scope: string;
19
+ configuration?: Settings;
20
+ hooks: WorktreeHooks;
21
+ establishWorld: () => Promise<WorldRoot>;
22
+ forwarded?: true;
23
+ }>;
24
+ export declare function invokeContractMutation(input: ContractMutationInput): Promise<InvocationResult>;
25
+ export {};
@@ -0,0 +1,193 @@
1
+ import { resolveActor } from "../actor.js";
2
+ import { CliUsageError } from "../usage.js";
3
+ function actorFromEdge(actor, environment) {
4
+ try {
5
+ return resolveActor({ env: environment, ...(actor === undefined ? {} : { actor }) });
6
+ }
7
+ catch (error) {
8
+ throw new CliUsageError(error instanceof Error ? error.message : String(error));
9
+ }
10
+ }
11
+ function consumeSettings(run, ErrorType) {
12
+ try {
13
+ return run();
14
+ }
15
+ catch (error) {
16
+ if (error instanceof ErrorType)
17
+ throw new CliUsageError(error.message);
18
+ throw error;
19
+ }
20
+ }
21
+ async function selectedGates(value, names) {
22
+ const { gatesFrom, SettingsError } = await import("../../library/configuration.js");
23
+ return consumeSettings(() => gatesFrom({ settings: value, ...(names === undefined ? {} : { names }) }), SettingsError);
24
+ }
25
+ async function selectedGitPolicy(value) {
26
+ const { requireBranchesToBeUpToDateFrom, SettingsError } = await import("../../library/configuration.js");
27
+ return consumeSettings(() => requireBranchesToBeUpToDateFrom({ settings: value }), SettingsError);
28
+ }
29
+ async function selectContract(repo, selector, scope) {
30
+ const { contractFromInput, resolveContextualContract } = await import("../selectors.js");
31
+ if (selector !== undefined && !selector.startsWith("@"))
32
+ return contractFromInput(repo, selector);
33
+ const { Keiyaku } = await import("../../library/keiyaku.js");
34
+ const id = resolveContextualContract(await Keiyaku.list({ repo }), selector, scope);
35
+ return contractFromInput(repo, id);
36
+ }
37
+ async function bindDraftReceipt(establishWorld, markdown) {
38
+ const { preserveBindDraft } = await import("../draft.js");
39
+ try {
40
+ return preserveBindDraft(await establishWorld(), markdown);
41
+ }
42
+ catch (error) {
43
+ return { warning: `bind draft could not be preserved: ${error instanceof Error ? error.message : String(error)}` };
44
+ }
45
+ }
46
+ async function invokeBind(input) {
47
+ const { parsed, repo, edge, configuration, hooks, establishWorld } = input;
48
+ if (parsed.command !== "bind")
49
+ throw new Error("bind invocation requires bind syntax");
50
+ const actor = actorFromEdge(parsed.actor, edge.environment);
51
+ const { bindFromCommand } = await import("./bind.js");
52
+ const { acceptedBind, resultFromMutationCall } = await import("../accepted.js");
53
+ if (parsed.forkOf !== undefined) {
54
+ return resultFromMutationCall("bind", () => bindFromCommand({ command: parsed, repo, ...(actor === undefined ? {} : { actor }), hooks }), (accepted) => {
55
+ const bound = accepted.facts.find((fact) => fact.kind === "bind");
56
+ if (bound === undefined || bound.kind !== "bind")
57
+ throw new Error("accepted bind is missing its bind fact");
58
+ return acceptedBind(accepted, bound.data.coordinates);
59
+ });
60
+ }
61
+ if (configuration === undefined)
62
+ throw new Error("bind invocation requires Settings");
63
+ const markdown = await edge.readStdin();
64
+ const gates = await selectedGates(configuration, parsed.gates);
65
+ try {
66
+ const result = await resultFromMutationCall("bind", () => bindFromCommand({
67
+ command: parsed,
68
+ repo,
69
+ markdown,
70
+ gates,
71
+ ...(actor === undefined ? {} : { actor }),
72
+ hooks,
73
+ }), (accepted) => {
74
+ const bound = accepted.facts.find((fact) => fact.kind === "bind");
75
+ if (bound === undefined || bound.kind !== "bind")
76
+ throw new Error("accepted bind is missing its bind fact");
77
+ return acceptedBind(accepted, bound.data.coordinates);
78
+ });
79
+ if (result.kind !== "refused")
80
+ return result;
81
+ return { ...result, draft: await bindDraftReceipt(establishWorld, markdown) };
82
+ }
83
+ catch (error) {
84
+ if (!(error instanceof TypeError))
85
+ throw error;
86
+ const { BindDraftError } = await import("../draft.js");
87
+ throw new BindDraftError(error, await bindDraftReceipt(establishWorld, markdown));
88
+ }
89
+ }
90
+ function deliverRefusal(refusal) {
91
+ if (typeof refusal !== "object" || refusal === null || !("kind" in refusal) || refusal.kind !== "dirty-workspace") {
92
+ return refusal;
93
+ }
94
+ const submodules = "submodules" in refusal && Array.isArray(refusal.submodules) ? refusal.submodules : [];
95
+ return { ...refusal, option: { flag: "--include-dirty", available: submodules.length === 0 } };
96
+ }
97
+ async function existingSeat(input, parsed) {
98
+ const { repo, edge, scope, hooks } = input;
99
+ const { id, contract } = await selectContract(repo, parsed.contract, scope);
100
+ const actor = actorFromEdge(parsed.actor, edge.environment);
101
+ return { contract, id, ...(actor === undefined ? {} : { actor }), hooks };
102
+ }
103
+ async function invokeDeliver(parsed, seat, requireBranchesToBeUpToDate) {
104
+ const { acceptedDeliver } = await import("../accepted.js");
105
+ try {
106
+ const delivered = await seat.contract.deliver({
107
+ ...(seat.actor === undefined ? {} : { actor: seat.actor }),
108
+ ...(parsed.message === undefined ? {} : { message: parsed.message }),
109
+ requireBranchesToBeUpToDate,
110
+ includeDirty: parsed.includeDirty,
111
+ materializeConflict: parsed.materializeConflict,
112
+ hooks: seat.hooks,
113
+ });
114
+ if (!("facts" in delivered))
115
+ return delivered;
116
+ return acceptedDeliver(delivered, seat.id);
117
+ }
118
+ catch (error) {
119
+ const { KeiyakuRefused, KeiyakuRetry } = await import("../../library/keiyaku.js");
120
+ if (error instanceof KeiyakuRefused) {
121
+ return { kind: "refused", verb: "deliver", contract: seat.id, refusal: deliverRefusal(error.refusal) };
122
+ }
123
+ if (error instanceof KeiyakuRetry)
124
+ return { kind: "retry", verb: "deliver", contract: seat.id, detail: error.reason };
125
+ throw error;
126
+ }
127
+ }
128
+ async function invokeReview(parsed, seat, readStdin) {
129
+ const summary = parsed.summaryFromStdin === true ? await readStdin() : parsed.summary;
130
+ const { acceptedReview, resultFromMutationCall } = await import("../accepted.js");
131
+ return resultFromMutationCall("review", () => seat.contract.review({
132
+ verdict: parsed.verdict,
133
+ ...(seat.actor === undefined ? {} : { actor: seat.actor }),
134
+ ...(summary === undefined ? {} : { summary }),
135
+ hooks: seat.hooks,
136
+ }), (result) => acceptedReview(result, seat.id), { coordinate: seat.id });
137
+ }
138
+ export async function invokeContractMutation(input) {
139
+ const { parsed, repo, edge, configuration, hooks, forwarded } = input;
140
+ if (parsed.command === "bind")
141
+ return invokeBind(input);
142
+ const seat = await existingSeat(input, parsed);
143
+ const { id, contract, actor } = seat;
144
+ switch (parsed.command) {
145
+ case "amend": {
146
+ if (configuration === undefined)
147
+ throw new Error("amend invocation requires Settings");
148
+ const markdown = parsed.stdin === true ? await edge.readStdin() : undefined;
149
+ const gates = parsed.gates === undefined ? undefined : await selectedGates(configuration, parsed.gates);
150
+ const { amendFromCommand } = await import("./amend.js");
151
+ const { acceptedAmend, resultFromMutationCall } = await import("../accepted.js");
152
+ return resultFromMutationCall("amend", () => amendFromCommand({
153
+ command: parsed,
154
+ repo,
155
+ contract,
156
+ ...(markdown === undefined ? {} : { markdown }),
157
+ gates,
158
+ ...(actor === undefined ? {} : { actor }),
159
+ hooks,
160
+ }), (result) => acceptedAmend(result, id), { coordinate: id });
161
+ }
162
+ case "deliver":
163
+ return invokeDeliver(parsed, seat, forwarded === true ? false : await selectedGitPolicy(configuration));
164
+ case "review":
165
+ return invokeReview(parsed, seat, edge.readStdin);
166
+ case "arc": {
167
+ const markdown = await edge.readStdin();
168
+ const { acceptedArc, resultFromMutationCall } = await import("../accepted.js");
169
+ return resultFromMutationCall("arc", () => contract.arc({ markdown, ...(actor === undefined ? {} : { actor }), hooks }), (result) => acceptedArc(result, id), { coordinate: id });
170
+ }
171
+ case "abandon": {
172
+ const { acceptedAbandon, resultFromMutationCall } = await import("../accepted.js");
173
+ return resultFromMutationCall("abandon", () => contract.abandon({
174
+ ...(actor === undefined ? {} : { actor }),
175
+ ...(parsed.note === undefined ? {} : { note: parsed.note }),
176
+ hooks,
177
+ }), (result) => acceptedAbandon(result, id), { coordinate: id });
178
+ }
179
+ case "audit": {
180
+ if (configuration === undefined)
181
+ throw new Error("audit invocation requires Settings");
182
+ const requireBranchesToBeUpToDate = await selectedGitPolicy(configuration);
183
+ const { acceptedAudit, resultFromMutationCall } = await import("../accepted.js");
184
+ return resultFromMutationCall("audit", () => contract.audit({
185
+ ...(actor === undefined ? {} : { actor }),
186
+ includeDirty: parsed.includeDirty,
187
+ showDiff: parsed.showDiff,
188
+ requireBranchesToBeUpToDate,
189
+ hooks,
190
+ }), (result) => acceptedAudit(result, id), { coordinate: id });
191
+ }
192
+ }
193
+ }
@@ -1,3 +1,4 @@
1
+ import type { CatalogQuery } from "../../library/catalog.js";
1
2
  export type ContractFlagKind = "boolean" | "value" | "raw-value" | "repeat-value";
2
3
  export type ContractCommandSpec = Readonly<{
3
4
  positional: "none" | "optional";
@@ -5,23 +6,109 @@ export type ContractCommandSpec = Readonly<{
5
6
  flags: Readonly<Record<string, ContractFlagKind>>;
6
7
  usage: string;
7
8
  purpose: string;
8
- help?: string;
9
+ details?: string;
10
+ }>;
11
+ type Output = Readonly<{
12
+ output: "text" | "json";
13
+ }>;
14
+ type Actor = Readonly<{
15
+ actor?: string;
16
+ }>;
17
+ export type ParsedBind = Output & Actor & Readonly<{
18
+ command: "bind";
19
+ forkOf?: string;
20
+ task?: string;
21
+ target?: string;
22
+ after?: readonly string[];
23
+ gates?: readonly string[];
24
+ }>;
25
+ export type ParsedAmend = Output & Actor & Readonly<{
26
+ command: "amend";
27
+ contract?: string;
28
+ after?: readonly string[];
29
+ clearAfter?: true;
30
+ gates?: readonly string[];
31
+ stdin?: true;
32
+ }>;
33
+ export type ParsedDeliver = Output & Actor & Readonly<{
34
+ command: "deliver";
35
+ contract?: string;
36
+ message?: string;
37
+ includeDirty: boolean;
38
+ materializeConflict: boolean;
39
+ }>;
40
+ export type ParsedReview = Output & Actor & Readonly<{
41
+ command: "review";
42
+ contract?: string;
43
+ verdict: "satisfied" | "unsatisfied";
44
+ summary?: string;
45
+ summaryFromStdin?: true;
46
+ }>;
47
+ export type ParsedArc = Output & Actor & Readonly<{
48
+ command: "arc";
49
+ contract?: string;
50
+ }>;
51
+ export type ParsedAbandon = Output & Actor & Readonly<{
52
+ command: "abandon";
53
+ contract?: string;
54
+ note?: string;
55
+ }>;
56
+ export type ParsedStatus = Output & (Readonly<{
57
+ command: "status";
58
+ contract?: string;
59
+ akuma?: never;
60
+ }> | Readonly<{
61
+ command: "status";
62
+ contract: string;
63
+ akuma: true;
64
+ }>);
65
+ export type ParsedLs = Output & Readonly<{
66
+ command: "ls";
67
+ query: CatalogQuery;
68
+ }>;
69
+ export type ParsedAudit = Output & Readonly<{
70
+ command: "audit";
71
+ contract?: string;
72
+ includeDirty: boolean;
73
+ showDiff: boolean;
74
+ actor?: string;
75
+ }>;
76
+ export type ParsedReconcile = Output & Readonly<{
77
+ command: "reconcile";
78
+ contract?: string;
79
+ retryHooks: boolean;
80
+ }>;
81
+ export type ParsedNuke = Output & Readonly<{
82
+ command: "nuke";
83
+ confirm?: string;
84
+ }>;
85
+ export type ParsedSettings = Output & Readonly<{
86
+ command: "settings";
87
+ }>;
88
+ export type ParsedRegion = Output & Readonly<{
89
+ command: "region";
90
+ contract?: string;
91
+ paths?: readonly [string, ...string[]];
92
+ }>;
93
+ export type ParsedShow = Output & Readonly<{
94
+ command: "show";
95
+ contract?: string;
9
96
  }>;
10
97
  export declare const CONTRACT_COMMAND_SPECS: {
11
98
  readonly bind: {
12
99
  readonly positional: "none";
13
- readonly stdin: "required";
100
+ readonly stdin: "optional";
14
101
  readonly flags: {
15
102
  readonly actor: "value";
16
103
  readonly task: "value";
17
104
  readonly target: "value";
18
- readonly here: "boolean";
19
105
  readonly after: "repeat-value";
20
106
  readonly gates: "raw-value";
107
+ readonly "fork-of": "value";
21
108
  readonly json: "boolean";
22
109
  };
23
- readonly usage: "bind [--task <task/...>] [--target <ref>] [--here] [--after <kei/...> ...] [--gates <name,...>] [--actor <actor>] -";
24
- readonly purpose: "Create one Contract from stdin Markdown.";
110
+ readonly usage: "bind [--task <task/...>] [--target <ref>] [--after <kei/...> ...] [--gates <name,...>] [--actor <actor>] - | bind --fork-of <kei/...> [--target <ref>] [--actor <actor>]";
111
+ readonly purpose: "Create one Contract from stdin Markdown or a sibling fork.";
25
112
  };
26
113
  readonly amend: {
27
114
  readonly positional: "optional";
@@ -35,7 +122,7 @@ export declare const CONTRACT_COMMAND_SPECS: {
35
122
  };
36
123
  readonly usage: "amend [<contract>|@<contract>] [--after <kei/...> ... | --clear-after] [--gates <name,...>] [--actor <actor>] [-]";
37
124
  readonly purpose: "Amend one Contract's document operations or structured terms.";
38
- readonly help: string;
125
+ readonly details: string;
39
126
  };
40
127
  readonly deliver: {
41
128
  readonly positional: "optional";
@@ -49,7 +136,7 @@ export declare const CONTRACT_COMMAND_SPECS: {
49
136
  };
50
137
  readonly usage: "deliver [<contract>|@<contract>] [--message <text>] [--include-dirty] [--materialize-conflict] [--actor <actor>]";
51
138
  readonly purpose: "Deliver one Contract candidate from the appointed worktree.";
52
- readonly help: string;
139
+ readonly details: string;
53
140
  };
54
141
  readonly review: {
55
142
  readonly positional: "optional";
@@ -157,12 +244,24 @@ export declare const CONTRACT_COMMAND_SPECS: {
157
244
  readonly positional: "optional";
158
245
  readonly stdin: "none";
159
246
  readonly flags: {
160
- readonly overlap: "boolean";
161
- readonly path: "value";
247
+ readonly path: "repeat-value";
162
248
  readonly json: "boolean";
163
249
  };
164
- readonly usage: "region [<contract>] [--overlap]\n region --path <repo-relative-path>";
250
+ readonly usage: "region [<contract>]\n region --path <pattern> [--path <pattern> ...]";
165
251
  readonly purpose: "Read active declared Contract Regions.";
166
252
  };
167
253
  };
168
254
  export type ContractCommand = keyof typeof CONTRACT_COMMAND_SPECS;
255
+ export type ParsedContractParts = Readonly<{
256
+ command: ContractCommand;
257
+ flags: Readonly<Record<string, string | true | readonly string[]>>;
258
+ positionals: readonly string[];
259
+ stdin: boolean;
260
+ output: "text" | "json";
261
+ actor?: string;
262
+ }>;
263
+ export type ParsedContractCommand = ParsedBind | ParsedAmend | ParsedDeliver | ParsedReview | ParsedArc | ParsedAbandon | ParsedStatus | ParsedShow | ParsedLs | ParsedAudit | ParsedReconcile | ParsedNuke | ParsedSettings | ParsedRegion;
264
+ export declare function renderContractHelp(command: ContractCommand): string;
265
+ export declare function renderContractUsage(command: ContractCommand): string;
266
+ export declare function parseContractCommand(parts: ParsedContractParts): ParsedContractCommand;
267
+ export {};