@astrosheep/keiyaku 4.0.5 → 4.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) 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 +1 -1
  5. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +15 -7
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +5 -3
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +10 -4
  8. package/build/src/akuma/akuma.d.ts +2 -0
  9. package/build/src/akuma/akuma.js +26 -3
  10. package/build/src/akuma/archetype.d.ts +3 -1
  11. package/build/src/akuma/archetype.js +11 -6
  12. package/build/src/akuma/body-turn.d.ts +64 -0
  13. package/build/src/akuma/body-turn.js +449 -0
  14. package/build/src/akuma/body.d.ts +3 -7
  15. package/build/src/akuma/body.js +9 -420
  16. package/build/src/akuma/heart/facts.d.ts +2 -0
  17. package/build/src/akuma/heart/facts.js +3 -1
  18. package/build/src/akuma/heart/index.js +12 -2
  19. package/build/src/akuma/heart/rows.js +4 -1
  20. package/build/src/akuma/heart/schema.d.ts +1 -1
  21. package/build/src/akuma/heart/schema.js +3 -2
  22. package/build/src/akuma/heart/timeline.d.ts +1 -0
  23. package/build/src/akuma/heart/timeline.js +19 -0
  24. package/build/src/akuma/nuke.d.ts +2 -0
  25. package/build/src/akuma/nuke.js +152 -0
  26. package/build/src/akuma/provider.d.ts +3 -1
  27. package/build/src/akuma/providers/acp/config.d.ts +8 -0
  28. package/build/src/akuma/providers/acp/config.js +37 -0
  29. package/build/src/akuma/providers/acp/core.js +6 -0
  30. package/build/src/akuma/providers/acp/index.d.ts +1 -8
  31. package/build/src/akuma/providers/acp/index.js +2 -37
  32. package/build/src/akuma/providers/claude/index.js +5 -0
  33. package/build/src/akuma/providers/codex-app-server/index.js +5 -0
  34. package/build/src/akuma/providers/grok-build/index.js +1 -1
  35. package/build/src/akuma/providers/index.d.ts +3 -2
  36. package/build/src/akuma/providers/index.js +36 -36
  37. package/build/src/akuma/providers/opencode-sdk/index.js +6 -0
  38. package/build/src/akuma/providers/opencode-sdk/session.d.ts +1 -1
  39. package/build/src/akuma/providers/opencode-sdk/session.js +1 -1
  40. package/build/src/akuma/providers/pi/index.d.ts +1 -1
  41. package/build/src/akuma/providers/pi/index.js +27 -11
  42. package/build/src/akuma/request-serve.d.ts +1 -0
  43. package/build/src/akuma/request-serve.js +31 -31
  44. package/build/src/akuma/request-wire.d.ts +3 -2
  45. package/build/src/akuma/request-wire.js +5 -2
  46. package/build/src/akuma-body.js +15 -1
  47. package/build/src/alias/index.d.ts +1 -0
  48. package/build/src/alias/index.js +34 -1
  49. package/build/src/cli/accepted.js +4 -0
  50. package/build/src/cli/commands/akuma-invoke.js +1 -0
  51. package/build/src/cli/commands/akuma.d.ts +1 -0
  52. package/build/src/cli/commands/akuma.js +11 -8
  53. package/build/src/cli/commands/contract.d.ts +25 -14
  54. package/build/src/cli/commands/contract.js +23 -17
  55. package/build/src/cli/commands/install.d.ts +2 -2
  56. package/build/src/cli/commands/install.js +6 -6
  57. package/build/src/cli/commands/nuke.d.ts +10 -0
  58. package/build/src/cli/commands/nuke.js +20 -0
  59. package/build/src/cli/commands/task-invoke.d.ts +15 -0
  60. package/build/src/cli/commands/task-invoke.js +57 -26
  61. package/build/src/cli/commands/task-query.d.ts +2 -2
  62. package/build/src/cli/commands/task-query.js +1 -2
  63. package/build/src/cli/commands/task.js +22 -22
  64. package/build/src/cli/coordinates.d.ts +5 -2
  65. package/build/src/cli/coordinates.js +5 -52
  66. package/build/src/cli/invoke.d.ts +5 -4
  67. package/build/src/cli/invoke.js +89 -59
  68. package/build/src/cli/main.d.ts +0 -2
  69. package/build/src/cli/main.js +4 -140
  70. package/build/src/cli/parse.d.ts +15 -2
  71. package/build/src/cli/parse.js +73 -8
  72. package/build/src/cli/render/akuma.js +55 -40
  73. package/build/src/cli/render/contract.js +49 -48
  74. package/build/src/cli/render/kanshi.js +15 -5
  75. package/build/src/cli/render/nuke.d.ts +3 -0
  76. package/build/src/cli/render/nuke.js +8 -0
  77. package/build/src/cli/render/refusal.d.ts +2 -1
  78. package/build/src/cli/render/refusal.js +31 -0
  79. package/build/src/cli/render/text.js +6 -1
  80. package/build/src/cli/result.d.ts +21 -2
  81. package/build/src/cli/runtime.d.ts +2 -0
  82. package/build/src/cli/runtime.js +140 -0
  83. package/build/src/cli/usage.d.ts +0 -2
  84. package/build/src/cli/usage.js +0 -4
  85. package/build/src/contract-worktree.d.ts +28 -12
  86. package/build/src/contract-worktree.js +129 -63
  87. package/build/src/git/hooks.d.ts +2 -0
  88. package/build/src/git/hooks.js +34 -1
  89. package/build/src/git/integration.d.ts +4 -0
  90. package/build/src/git/integration.js +38 -0
  91. package/build/src/git/nuke.d.ts +2 -0
  92. package/build/src/git/nuke.js +97 -0
  93. package/build/src/git/process.d.ts +2 -0
  94. package/build/src/git/reconcile.d.ts +2 -0
  95. package/build/src/git/reconcile.js +33 -2
  96. package/build/src/git/repository.js +4 -1
  97. package/build/src/git/target-placement.d.ts +2 -1
  98. package/build/src/git/target-placement.js +6 -7
  99. package/build/src/git/tender.d.ts +1 -0
  100. package/build/src/git/tender.js +2 -2
  101. package/build/src/git/workspace.d.ts +3 -0
  102. package/build/src/kanshi/read.js +5 -1
  103. package/build/src/library/akuma-creation.d.ts +1 -0
  104. package/build/src/library/akuma-creation.js +8 -1
  105. package/build/src/library/audit.d.ts +1 -0
  106. package/build/src/library/audit.js +1 -0
  107. package/build/src/library/contract.d.ts +6 -4
  108. package/build/src/library/contract.js +56 -34
  109. package/build/src/library/delivery.d.ts +3 -1
  110. package/build/src/library/keiyaku.d.ts +5 -1
  111. package/build/src/library/keiyaku.js +2 -0
  112. package/build/src/library/mutation.d.ts +1 -0
  113. package/build/src/library/mutation.js +3 -0
  114. package/build/src/library/nuke.d.ts +14 -0
  115. package/build/src/library/nuke.js +54 -0
  116. package/build/src/library/reconcile.js +5 -2
  117. package/build/src/library/refusal.d.ts +10 -1
  118. package/build/src/library/repo.d.ts +1 -0
  119. package/build/src/library/repo.js +2 -0
  120. package/build/src/protocol/audit.js +12 -5
  121. package/build/src/protocol/completion.d.ts +11 -1
  122. package/build/src/protocol/completion.js +68 -15
  123. package/build/src/protocol/deliver.d.ts +14 -2
  124. package/build/src/protocol/deliver.js +107 -6
  125. package/build/src/protocol/intent.d.ts +1 -0
  126. package/build/src/protocol/intent.js +7 -1
  127. package/build/src/protocol/operations.d.ts +30 -3
  128. package/build/src/protocol/operations.js +2 -2
  129. package/build/src/protocol/placement.d.ts +9 -1
  130. package/build/src/protocol/placement.js +5 -4
  131. package/build/src/protocol/read/status.d.ts +16 -4
  132. package/build/src/protocol/read/status.js +54 -12
  133. package/build/src/protocol/review.d.ts +1 -0
  134. package/build/src/protocol/review.js +8 -0
  135. package/build/src/runtime/proc/run.js +9 -5
  136. package/build/src/settlement/fence.d.ts +2 -0
  137. package/build/src/settlement/fence.js +24 -0
  138. package/build/src/settlement/settle.js +1 -2
  139. package/build/src/task/compose.d.ts +1 -1
  140. package/build/src/task/compose.js +2 -7
  141. package/build/src/task/context.d.ts +14 -2
  142. package/build/src/task/context.js +30 -7
  143. package/build/src/task/index.d.ts +6 -5
  144. package/build/src/task/index.js +15 -18
  145. package/build/src/task/mutation.d.ts +7 -2
  146. package/build/src/task/mutation.js +14 -6
  147. package/build/src/task/operations.d.ts +12 -6
  148. package/build/src/task/operations.js +22 -46
  149. package/build/src/task/store.d.ts +1 -0
  150. package/build/src/task/store.js +91 -1
  151. package/build/src/workspace-place.d.ts +2 -0
  152. package/build/src/workspace-place.js +27 -1
  153. package/package.json +1 -1
@@ -1,21 +1,7 @@
1
- import { AkumaWorldScopeError, gatesFrom, Keiyaku, KeiyakuRefused, requireBranchesToBeUpToDateFrom, settings, SettingsError, worktreeHooksFrom, } from "../index.js";
2
- import { kanshi, observeKanshi, selectKanshi, selectRegion, } from "../kanshi/index.js";
3
1
  import { resolveActor } from "./actor.js";
4
- import { acceptedAbandon, acceptedAmend, acceptedArc, acceptedAudit, acceptedBind, acceptedDeliver, acceptedReview, resultFromMutationCall, } from "./accepted.js";
5
- import { amendFromCommand } from "./commands/amend.js";
6
- import { invokeAkuma, invokeAkumaStatus } from "./commands/akuma-invoke.js";
7
2
  import { isParsedAkumaCommand } from "./commands/akuma.js";
8
- import { bindFromCommand } from "./commands/bind.js";
9
- import { installHarnesses } from "./commands/install.js";
10
- import { invokeTask } from "./commands/task-invoke.js";
11
- import { CliUsageError, renderCommandUsage } from "./parse.js";
3
+ import { assertExplicitRepoUse, CliUsageError, renderCommandUsage, } from "./parse.js";
12
4
  import { isBlankInput } from "./usage.js";
13
- import { canonicalContractSelector, contractFromInput, resolveContextualContract, resolveKanshiContract, } from "./selectors.js";
14
- import { resolveNamedAddress } from "../library/address.js";
15
- import { injectedBodyRequests } from "../akuma/requests.js";
16
- import { EMPTY_WORKTREE_HOOKS } from "../library/configuration.js";
17
- import { assertExplicitRepoUse, resolveCliCoordinates } from "./coordinates.js";
18
- import { BindDraftError, preserveBindDraft } from "./draft.js";
19
5
  async function readStdin() {
20
6
  const chunks = [];
21
7
  for await (const chunk of process.stdin)
@@ -56,24 +42,27 @@ async function withAcquiredStdin(command, runtime) {
56
42
  throw new CliUsageError(diagnostic);
57
43
  return { ...runtime, readStdin: async () => bytes };
58
44
  }
59
- function settingsAt(root, home) {
45
+ async function settingsAt(root, home) {
46
+ const { settings } = await import("../settings.js");
60
47
  return settings({ ...(root === undefined ? {} : { root }), ...(home === undefined ? {} : { home }) });
61
48
  }
62
- function consumeSettings(run) {
49
+ function consumeSettings(run, ErrorType) {
63
50
  try {
64
51
  return run();
65
52
  }
66
53
  catch (error) {
67
- if (error instanceof SettingsError)
54
+ if (error instanceof ErrorType)
68
55
  throw new CliUsageError(error.message);
69
56
  throw error;
70
57
  }
71
58
  }
72
- function selectedGates(value, names) {
73
- return consumeSettings(() => gatesFrom({ settings: value, ...(names === undefined ? {} : { names }) }));
59
+ async function selectedGates(value, names) {
60
+ const { gatesFrom, SettingsError } = await import("../library/configuration.js");
61
+ return consumeSettings(() => gatesFrom({ settings: value, ...(names === undefined ? {} : { names }) }), SettingsError);
74
62
  }
75
- function selectedGitPolicy(value) {
76
- return consumeSettings(() => requireBranchesToBeUpToDateFrom({ settings: value }));
63
+ async function selectedGitPolicy(value) {
64
+ const { requireBranchesToBeUpToDateFrom, SettingsError } = await import("../library/configuration.js");
65
+ return consumeSettings(() => requireBranchesToBeUpToDateFrom({ settings: value }), SettingsError);
77
66
  }
78
67
  function actorFromEdge(actor, environment) {
79
68
  let resolved;
@@ -94,12 +83,15 @@ function gitPathFromEdge(environment) {
94
83
  return value;
95
84
  }
96
85
  async function selectContract(repo, selector, scope) {
86
+ const { contractFromInput, resolveContextualContract } = await import("./selectors.js");
97
87
  if (selector !== undefined && !selector.startsWith("@"))
98
88
  return contractFromInput(repo, selector);
89
+ const { Keiyaku } = await import("../library/keiyaku.js");
99
90
  const id = resolveContextualContract(await Keiyaku.list({ repo }), selector, scope);
100
91
  return contractFromInput(repo, id);
101
92
  }
102
93
  async function bindDraftReceipt(establishWorld, markdown) {
94
+ const { preserveBindDraft } = await import("./draft.js");
103
95
  try {
104
96
  return preserveBindDraft(await establishWorld(), markdown);
105
97
  }
@@ -109,8 +101,10 @@ async function bindDraftReceipt(establishWorld, markdown) {
109
101
  }
110
102
  async function invokeBind({ parsed, repo, edge, configuration, hooks, establishWorld }) {
111
103
  const markdown = await edge.readStdin();
112
- const gates = selectedGates(configuration, parsed.gates);
104
+ const gates = await selectedGates(configuration, parsed.gates);
113
105
  const actor = actorFromEdge(parsed.actor, edge.environment);
106
+ const { bindFromCommand } = await import("./commands/bind.js");
107
+ const { acceptedBind, resultFromMutationCall } = await import("./accepted.js");
114
108
  try {
115
109
  const result = await resultFromMutationCall("bind", () => bindFromCommand({
116
110
  command: parsed,
@@ -132,6 +126,7 @@ async function invokeBind({ parsed, repo, edge, configuration, hooks, establishW
132
126
  catch (error) {
133
127
  if (!(error instanceof TypeError))
134
128
  throw error;
129
+ const { BindDraftError } = await import("./draft.js");
135
130
  throw new BindDraftError(error, await bindDraftReceipt(establishWorld, markdown));
136
131
  }
137
132
  }
@@ -143,19 +138,34 @@ function deliverRefusal(refusal) {
143
138
  return { ...refusal, option: { flag: "--include-dirty", available: submodules.length === 0 } };
144
139
  }
145
140
  async function invokeDeliver(parsed, seat, requireBranchesToBeUpToDate) {
146
- return resultFromMutationCall("deliver", () => seat.contract.deliver({
147
- ...(seat.actor === undefined ? {} : { actor: seat.actor }),
148
- ...(parsed.message === undefined ? {} : { message: parsed.message }),
149
- requireBranchesToBeUpToDate,
150
- includeDirty: parsed.includeDirty,
151
- hooks: seat.hooks,
152
- }), (result) => acceptedDeliver(result, seat.id), {
153
- coordinate: seat.id,
154
- projectRefusal: deliverRefusal,
155
- });
141
+ const { acceptedDeliver } = await import("./accepted.js");
142
+ try {
143
+ const delivered = await seat.contract.deliver({
144
+ ...(seat.actor === undefined ? {} : { actor: seat.actor }),
145
+ ...(parsed.message === undefined ? {} : { message: parsed.message }),
146
+ requireBranchesToBeUpToDate,
147
+ includeDirty: parsed.includeDirty,
148
+ materializeConflict: parsed.materializeConflict,
149
+ hooks: seat.hooks,
150
+ });
151
+ if (!("facts" in delivered))
152
+ return delivered;
153
+ return acceptedDeliver(delivered, seat.id);
154
+ }
155
+ catch (error) {
156
+ const { KeiyakuRefused, KeiyakuRetry } = await import("../library/keiyaku.js");
157
+ if (error instanceof KeiyakuRefused) {
158
+ return { kind: "refused", verb: "deliver", contract: seat.id, refusal: deliverRefusal(error.refusal) };
159
+ }
160
+ if (error instanceof KeiyakuRetry) {
161
+ return { kind: "retry", verb: "deliver", contract: seat.id, detail: error.reason };
162
+ }
163
+ throw error;
164
+ }
156
165
  }
157
166
  async function invokeReview(parsed, seat, readStdin) {
158
167
  const summary = parsed.summaryFromStdin === true ? await readStdin() : parsed.summary;
168
+ const { acceptedReview, resultFromMutationCall } = await import("./accepted.js");
159
169
  return resultFromMutationCall("review", () => seat.contract.review({
160
170
  verdict: parsed.verdict,
161
171
  ...(seat.actor === undefined ? {} : { actor: seat.actor }),
@@ -164,6 +174,7 @@ async function invokeReview(parsed, seat, readStdin) {
164
174
  }), (result) => acceptedReview(result, seat.id), { coordinate: seat.id });
165
175
  }
166
176
  async function invokeAudit(parsed, seat, requireBranchesToBeUpToDate) {
177
+ const { acceptedAudit, resultFromMutationCall } = await import("./accepted.js");
167
178
  return resultFromMutationCall("audit", () => seat.contract.audit({
168
179
  ...(seat.actor === undefined ? {} : { actor: seat.actor }),
169
180
  includeDirty: parsed.includeDirty,
@@ -186,7 +197,9 @@ async function invokeExisting(input) {
186
197
  const markdown = parsed.stdin === true ? await edge.readStdin() : undefined;
187
198
  const gates = parsed.gates === undefined
188
199
  ? undefined
189
- : selectedGates(configuration, parsed.gates);
200
+ : await selectedGates(configuration, parsed.gates);
201
+ const { amendFromCommand } = await import("./commands/amend.js");
202
+ const { acceptedAmend, resultFromMutationCall } = await import("./accepted.js");
190
203
  return resultFromMutationCall("amend", () => amendFromCommand({
191
204
  command: parsed,
192
205
  repo,
@@ -198,25 +211,28 @@ async function invokeExisting(input) {
198
211
  }), (result) => acceptedAmend(result, id), { coordinate: id });
199
212
  }
200
213
  case "deliver":
201
- return invokeDeliver(parsed, seat, selectedGitPolicy(configuration));
214
+ return invokeDeliver(parsed, seat, await selectedGitPolicy(configuration));
202
215
  case "review":
203
216
  return invokeReview(parsed, seat, edge.readStdin);
204
217
  case "arc": {
205
218
  const markdown = await edge.readStdin();
219
+ const { acceptedArc, resultFromMutationCall } = await import("./accepted.js");
206
220
  return resultFromMutationCall("arc", () => contract.arc({
207
221
  markdown,
208
222
  ...(actor === undefined ? {} : { actor }),
209
223
  hooks,
210
224
  }), (result) => acceptedArc(result, id), { coordinate: id });
211
225
  }
212
- case "abandon":
226
+ case "abandon": {
227
+ const { acceptedAbandon, resultFromMutationCall } = await import("./accepted.js");
213
228
  return resultFromMutationCall("abandon", () => contract.abandon({
214
229
  ...(actor === undefined ? {} : { actor }),
215
230
  ...(parsed.note === undefined ? {} : { note: parsed.note }),
216
231
  hooks,
217
232
  }), (result) => acceptedAbandon(result, id), { coordinate: id });
233
+ }
218
234
  case "audit":
219
- return invokeAudit(parsed, seat, selectedGitPolicy(configuration));
235
+ return invokeAudit(parsed, seat, await selectedGitPolicy(configuration));
220
236
  default:
221
237
  return parsed;
222
238
  }
@@ -227,18 +243,21 @@ async function invokeAkumaFromEdge(parsed, input) {
227
243
  if (parsed.command === "call" && parsed.contract !== undefined && repo === undefined) {
228
244
  throw new Error("call with Contract requires a resolved Repo");
229
245
  }
246
+ const { invokeAkuma } = await import("./commands/akuma-invoke.js");
247
+ const contract = parsed.command === "call" && parsed.contract !== undefined
248
+ ? (await import("./selectors.js")).contractFromInput(repo, parsed.contract).contract
249
+ : undefined;
230
250
  return await invokeAkuma(parsed, {
231
251
  path,
232
252
  ...(statedCwd === undefined ? {} : { statedCwd }),
233
253
  ...(home === undefined ? {} : { home }),
234
254
  ...(configuration === undefined ? {} : { settings: configuration }),
235
- ...(parsed.command === "call" && parsed.contract !== undefined
236
- ? { contract: contractFromInput(repo, parsed.contract).contract }
237
- : repo === undefined ? {} : { repo }),
255
+ ...(contract === undefined ? repo === undefined ? {} : { repo } : { contract }),
238
256
  readStdin: edge.readStdin,
239
257
  });
240
258
  }
241
259
  catch (error) {
260
+ const { AkumaWorldScopeError } = await import("../library/address.js");
242
261
  if (error instanceof AkumaWorldScopeError)
243
262
  throw error;
244
263
  if (error instanceof TypeError)
@@ -254,6 +273,7 @@ async function akumaWorldFor(parsed, located, candidate, establish) {
254
273
  }
255
274
  async function invokeCatalog(parsed, world, repo, home) {
256
275
  try {
276
+ const { Keiyaku } = await import("../library/keiyaku.js");
257
277
  if (parsed.query.kind === "contracts") {
258
278
  if (repo === undefined)
259
279
  throw new Error("Contract catalog requires a resolved Repo");
@@ -282,8 +302,9 @@ async function invokeStatus(parsed, world, repo) {
282
302
  if (parsed.akuma === true) {
283
303
  if (world === null)
284
304
  throw new CliUsageError("no Keiyaku world contains the invocation cwd");
285
- return invokeAkumaStatus(world, parsed.contract, undefined, repo);
305
+ return (await import("./commands/akuma-invoke.js")).invokeAkumaStatus(world, parsed.contract, undefined, repo);
286
306
  }
307
+ const { kanshi, observeKanshi, selectKanshi } = await import("../kanshi/index.js");
287
308
  if (parsed.contract === undefined) {
288
309
  const report = await kanshi({ world, ...(repo === undefined ? {} : { repo }) });
289
310
  return { kind: "status", report, selection: "world" };
@@ -291,6 +312,7 @@ async function invokeStatus(parsed, world, repo) {
291
312
  if (parsed.contract.startsWith("@")) {
292
313
  try {
293
314
  const observation = await observeKanshi({ world, ...(repo === undefined ? {} : { repo }) });
315
+ const { resolveNamedAddress } = await import("../library/address.js");
294
316
  const address = resolveNamedAddress({
295
317
  selector: parsed.contract,
296
318
  report: observation.report,
@@ -299,7 +321,7 @@ async function invokeStatus(parsed, world, repo) {
299
321
  if (address.kind === "akuma") {
300
322
  if (world === null)
301
323
  throw new CliUsageError("no Keiyaku world contains the invocation cwd");
302
- return invokeAkumaStatus(world, address.id, parsed.contract, repo);
324
+ return (await import("./commands/akuma-invoke.js")).invokeAkumaStatus(world, address.id, parsed.contract, repo);
303
325
  }
304
326
  return { kind: "status", report: selectKanshi({ report: observation.report, contract: address.id }), selection: "contract" };
305
327
  }
@@ -312,6 +334,7 @@ async function invokeStatus(parsed, world, repo) {
312
334
  if (parsed.contract.startsWith("kei/")) {
313
335
  if (repo === undefined)
314
336
  throw new CliUsageError("cannot select a contract while the Contract world is absent");
337
+ const { canonicalContractSelector } = await import("./selectors.js");
315
338
  const contract = canonicalContractSelector(parsed.contract);
316
339
  return {
317
340
  kind: "status",
@@ -320,10 +343,12 @@ async function invokeStatus(parsed, world, repo) {
320
343
  };
321
344
  }
322
345
  const report = await kanshi({ world, ...(repo === undefined ? {} : { repo }) });
346
+ const { resolveKanshiContract } = await import("./selectors.js");
323
347
  const contract = resolveKanshiContract(report, parsed.contract);
324
348
  return { kind: "status", report: selectKanshi({ report, contract }), selection: "contract" };
325
349
  }
326
350
  async function invokeRegion(parsed, world, repo) {
351
+ const { kanshi, selectRegion } = await import("../kanshi/index.js");
327
352
  const read = async (region) => {
328
353
  try {
329
354
  return await kanshi({ world, repo, region });
@@ -342,6 +367,7 @@ async function invokeRegion(parsed, world, repo) {
342
367
  return { kind: "region", region: report.region ?? { kind: "absent" } };
343
368
  }
344
369
  const report = await read({ kind: "declarations" });
370
+ const { resolveKanshiContract } = await import("./selectors.js");
345
371
  const contract = resolveKanshiContract(report, parsed.contract);
346
372
  if (report.contracts.kind !== "present" || report.contracts.value.rows.every((row) => row.id !== contract || row.disposition !== "active")) {
347
373
  throw new CliUsageError(`unknown contract selector: ${parsed.contract}`);
@@ -355,6 +381,7 @@ async function invokeRegion(parsed, world, repo) {
355
381
  async function invokeContractHistory(repo, contract) {
356
382
  if (repo === undefined)
357
383
  throw new Error("history kei/... requires a resolved Repo");
384
+ const { contractFromInput } = await import("./selectors.js");
358
385
  const selected = contractFromInput(repo, contract);
359
386
  try {
360
387
  return { kind: "contract-history", history: await selected.contract.history() };
@@ -362,6 +389,7 @@ async function invokeContractHistory(repo, contract) {
362
389
  catch (error) {
363
390
  if (error instanceof TypeError)
364
391
  throw new CliUsageError(error.message);
392
+ const { KeiyakuRefused } = await import("../library/keiyaku.js");
365
393
  if (error instanceof KeiyakuRefused) {
366
394
  return { kind: "refused", verb: "history", contract: selected.id, refusal: error.refusal };
367
395
  }
@@ -372,6 +400,7 @@ async function invokeContractHistory(repo, contract) {
372
400
  async function invokeParsed(invocation, runtime) {
373
401
  const environment = runtime.environment ?? process.env;
374
402
  const gitPath = gitPathFromEdge(environment);
403
+ const { resolveCliCoordinates } = await import("./coordinates.js");
375
404
  const coordinates = await resolveCliCoordinates({
376
405
  ...(runtime.cwd === undefined ? {} : { processCwd: runtime.cwd }),
377
406
  ...(invocation.cwd === undefined ? {} : { cwd: invocation.cwd }),
@@ -379,7 +408,7 @@ async function invokeParsed(invocation, runtime) {
379
408
  ...(gitPath === undefined ? {} : { gitPath }),
380
409
  command: invocation.command,
381
410
  });
382
- const { cwd, cwdSource, repo, world, candidateWorld, establishWorld } = coordinates;
411
+ const { cwd, cwdSource, repo, world, candidateWorld, establishWorld, taskContext } = coordinates;
383
412
  const edge = {
384
413
  environment: runtime.environment ?? process.env,
385
414
  readStdin: runtime.readStdin ?? readStdin,
@@ -390,20 +419,19 @@ async function invokeParsed(invocation, runtime) {
390
419
  if (parsed.command === "settings") {
391
420
  return { kind: "settings", value: await settingsAt(world ?? undefined, home) };
392
421
  }
422
+ if (parsed.command === "nuke") {
423
+ return await (await import("./commands/nuke.js")).invokeNuke(parsed, world);
424
+ }
393
425
  if (parsed.command === "task") {
394
- try {
395
- return await invokeTask(parsed, {
396
- world,
397
- establish: coordinates.establishWorld,
398
- readStdin: edge.readStdin,
399
- ...(runtime.actor === undefined ? {} : { actor: runtime.actor }),
400
- });
401
- }
402
- catch (error) {
403
- if (error instanceof TypeError)
404
- throw new CliUsageError(error.message);
405
- throw error;
406
- }
426
+ const actor = runtime.actor ?? actorFromEdge(typeof parsed.flags.actor === "string" ? parsed.flags.actor : undefined, edge.environment);
427
+ return await (await import("./commands/task-invoke.js")).invokeTaskFromEdge({
428
+ parsed,
429
+ world,
430
+ context: taskContext,
431
+ establish: coordinates.establishWorld,
432
+ readStdin: edge.readStdin,
433
+ actor,
434
+ });
407
435
  }
408
436
  if (parsed.command === "history" && "contract" in parsed)
409
437
  return await invokeContractHistory(repo, parsed.contract);
@@ -428,14 +456,16 @@ async function invokeParsed(invocation, runtime) {
428
456
  if (parsed.command === "region")
429
457
  return invokeRegion(parsed, world, repo);
430
458
  const scope = cwd;
431
- if ((parsed.command === "deliver" || parsed.command === "review") && injectedBodyRequests() !== null) {
459
+ if ((parsed.command === "deliver" || parsed.command === "review") && (await import("../akuma/requests.js")).injectedBodyRequests() !== null) {
460
+ const { EMPTY_WORKTREE_HOOKS } = await import("../library/configuration.js");
432
461
  const seat = await existingSeat({ parsed, repo, edge, scope, hooks: EMPTY_WORKTREE_HOOKS });
433
462
  return parsed.command === "deliver"
434
463
  ? await invokeDeliver(parsed, seat, false)
435
464
  : await invokeReview(parsed, seat, edge.readStdin);
436
465
  }
437
466
  const configuration = await settingsAt(world ?? undefined, home);
438
- const hooks = consumeSettings(() => worktreeHooksFrom({ settings: configuration }));
467
+ const { worktreeHooksFrom, SettingsError } = await import("../library/configuration.js");
468
+ const hooks = consumeSettings(() => worktreeHooksFrom({ settings: configuration }), SettingsError);
439
469
  if (parsed.command === "show") {
440
470
  const selected = await selectContract(repo, parsed.contract, scope);
441
471
  return { kind: "guidance", contract: selected.id, guidance: await selected.contract.guidance() };
@@ -466,7 +496,7 @@ export async function invoke(invocation, runtime = {}) {
466
496
  assertExplicitRepoUse(command, invocation.repo);
467
497
  if (command.command === "install") {
468
498
  runtime.onOperationStart?.();
469
- return installHarnesses(command.harnesses, runtime.environment ?? process.env);
499
+ return (await import("./commands/install.js")).installHarnesses(command.harnesses, runtime.environment ?? process.env);
470
500
  }
471
501
  const acquiredRuntime = await withAcquiredStdin(command, withResolvedTaskActor(command, runtime));
472
502
  runtime.onOperationStart?.();
@@ -1,3 +1 @@
1
- import { type ParsedCommand } from "./parse.js";
2
- export declare function invocationStart(command: ParsedCommand): string | undefined;
3
1
  export declare function main(argv?: readonly string[]): Promise<number>;
@@ -1,151 +1,15 @@
1
- import { AkumaWorldScopeError } from "../index.js";
2
- import { CliUsageError, parseArgv, renderContractHelp, renderRootHelp, } from "./parse.js";
3
- import { renderText } from "./render/text.js";
4
- import { renderTaskIncompleteDiagnostic, renderTaskText, taskExitCode } from "./render/task.js";
5
- import { akumaExitCode, akumaRawAnswer, renderAkumaJson, renderAkumaText } from "./render/akuma.js";
6
- import { isParsedAkumaCommand, renderAkumaHelp } from "./commands/akuma.js";
7
- import { installExitCode, renderInstallHelp, renderInstallText } from "./commands/install.js";
8
- import { renderTaskHelp } from "./commands/task.js";
9
- import { renderSettingsText, settingsJsonValue } from "./render/settings.js";
10
- import { renderCatalogText } from "./render/catalog.js";
11
- import { BindDraftError } from "./draft.js";
12
- import { renderBindDraftReceipt } from "./render/refusal.js";
13
- function writeTask(command, result) {
14
- const context = {
15
- columns: process.stdout.isTTY === true && Number.isInteger(process.stdout.columns) ? process.stdout.columns : 80,
16
- color: false,
17
- };
18
- if (command.output === "json")
19
- process.stdout.write(`${JSON.stringify(result)}\n`);
20
- else if (command.action === "compose" && typeof result === "object" && result !== null && "kind" in result && result.kind === "incomplete") {
21
- const diagnostic = renderTaskIncompleteDiagnostic(result);
22
- if (diagnostic.length > 0)
23
- process.stderr.write(`${diagnostic}\n`);
24
- process.stdout.write(result.draft);
25
- }
26
- else
27
- process.stdout.write(`${renderTaskText(command, result, context)}\n`);
28
- return taskExitCode(result);
29
- }
30
- function writeAkuma(command, result) {
31
- const output = command.output === "json" ? renderAkumaJson(result) : renderAkumaText(command, result, {
32
- columns: process.stdout.isTTY === true && Number.isInteger(process.stdout.columns) ? process.stdout.columns : 80,
33
- color: process.stdout.isTTY === true && process.env.NO_COLOR === undefined,
34
- });
35
- const raw = command.output === "text"
36
- && ((command.command === "history" && command.last) || akumaRawAnswer(result) !== undefined);
37
- process.stdout.write(raw ? output : `${output}\n`);
38
- return akumaExitCode(result);
39
- }
40
- function renderHelp(coordinate) {
41
- switch (coordinate.kind) {
42
- case "root": return renderRootHelp();
43
- case "contract": return renderContractHelp(coordinate.command);
44
- case "task": return renderTaskHelp(coordinate.action);
45
- case "install": return renderInstallHelp();
46
- case "akuma": return renderAkumaHelp(coordinate.action);
47
- }
48
- }
49
- export function invocationStart(command) {
50
- if (command.output === "json")
51
- return undefined;
52
- switch (command.command) {
53
- case "bind": return "⧖ preparing keiyaku";
54
- case "deliver": return "⧖ delivering";
55
- case "audit": return "⧖ auditing";
56
- case "reconcile": return "⧖ reconciling";
57
- case "install": return "⧖ installing skills";
58
- default: return undefined;
59
- }
60
- }
61
- function writeGuidance(command, result) {
62
- if (command.output === "json")
63
- process.stdout.write(`${JSON.stringify({ contract: result.contract, guidance: result.guidance })}\n`);
64
- else
65
- process.stdout.write(result.guidance.endsWith("\n") ? result.guidance : `${result.guidance}\n`);
66
- return 0;
67
- }
68
- function writeCatalog(command, result) {
69
- process.stdout.write(`${command.output === "json" ? JSON.stringify(result.catalog) : renderCatalogText(result.catalog)}\n`);
70
- return 0;
71
- }
72
- // eslint-disable-next-line complexity -- output dispatch is the single CLI presentation boundary.
73
- function writeResult(command, result) {
74
- if (command.command === "install") {
75
- const value = result;
76
- process.stdout.write(`${command.output === "json" ? JSON.stringify(value) : renderInstallText(value)}\n`);
77
- return installExitCode(value);
78
- }
79
- if (command.command === "task")
80
- return writeTask(command, result);
81
- if (command.command === "settings") {
82
- const value = result.value;
83
- process.stdout.write(`${command.output === "json" ? JSON.stringify(settingsJsonValue(value)) : renderSettingsText(value)}\n`);
84
- return 0;
85
- }
86
- if (typeof result === "object" && result !== null && "kind" in result && result.kind === "contract-history") {
87
- const history = result.history;
88
- const output = command.output === "json" ? JSON.stringify(history) : renderText(result);
89
- process.stdout.write(`${output}\n`);
90
- return 0;
91
- }
92
- const akumaResult = typeof result === "object" && result !== null && "kind" in result && result.kind === "akuma";
93
- if (isParsedAkumaCommand(command)) {
94
- return writeAkuma(command, result);
95
- }
96
- if (akumaResult && command.command === "status") {
97
- return writeAkuma(command, result);
98
- }
99
- const contractResult = result;
100
- if (contractResult.kind === "guidance")
101
- return writeGuidance(command, contractResult);
102
- if (contractResult.kind === "catalog")
103
- return writeCatalog(command, contractResult);
104
- if (contractResult.kind === "region") {
105
- const output = command.output === "json" ? JSON.stringify(contractResult.region) : renderText(contractResult);
106
- process.stdout.write(`${output}\n`);
107
- return 0;
108
- }
109
- const output = command.output === "json"
110
- ? JSON.stringify(contractResult.kind === "status" ? contractResult.report : contractResult)
111
- : renderText(contractResult, {
112
- columns: process.stdout.isTTY === true && Number.isInteger(process.stdout.columns) ? process.stdout.columns : 80,
113
- color: process.stdout.isTTY === true && process.env.NO_COLOR === undefined,
114
- });
115
- process.stdout.write(`${output}\n`);
116
- return contractResult.kind === "refused" ? 1 : contractResult.kind === "retry" ? 2 : 0;
117
- }
118
- function writeWorldScopeRefusal(error, output) {
119
- const body = output === "json"
120
- ? JSON.stringify(error.refusal)
121
- : `${error.refusal.kind} ${error.refusal.world} ${error.refusal.ids.join(" ")}`;
122
- process.stderr.write(`${body}\n`);
123
- return 1;
124
- }
1
+ import { CliUsageError, parseArgv, renderHelp } from "./parse.js";
125
2
  export async function main(argv = process.argv.slice(2)) {
126
- let output = "text";
127
3
  try {
128
4
  const parsed = parseArgv(argv);
129
5
  if ("help" in parsed) {
130
6
  process.stdout.write(`${renderHelp(parsed.help)}\n`);
131
7
  return 0;
132
8
  }
133
- output = parsed.command.output;
134
- const { invoke } = await import("./invoke.js");
135
- const start = invocationStart(parsed.command);
136
- const result = await invoke(parsed, {
137
- cwd: process.cwd(),
138
- ...(start === undefined ? {} : { onOperationStart: () => { process.stderr.write(`${start}\n`); } }),
139
- });
140
- return writeResult(parsed.command, result);
9
+ return await (await import("./runtime.js")).runCliCommand(parsed);
141
10
  }
142
11
  catch (error) {
143
- if (error instanceof AkumaWorldScopeError)
144
- return writeWorldScopeRefusal(error, output);
145
- const original = error instanceof BindDraftError ? error.original : error;
146
- process.stderr.write(`${original instanceof Error ? original.message : String(original)}\n`);
147
- if (error instanceof BindDraftError)
148
- process.stderr.write(`${renderBindDraftReceipt(error.draft)}\n`);
149
- return original instanceof CliUsageError ? 1 : 3;
12
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
13
+ return error instanceof CliUsageError ? 1 : 3;
150
14
  }
151
15
  }
@@ -1,6 +1,6 @@
1
1
  import { type ParsedTaskCommand, type TaskAction } from "./commands/task.js";
2
2
  import { type AkumaAction, type ParsedAkumaCommand } from "./commands/akuma.js";
3
- import type { CatalogQuery } from "../index.js";
3
+ import type { CatalogQuery } from "../library/catalog.js";
4
4
  import { type ParsedInstallCommand } from "./commands/install.js";
5
5
  import { type ContractCommand as Command } from "./commands/contract.js";
6
6
  export { CliUsageError } from "./usage.js";
@@ -8,6 +8,7 @@ export type { Command };
8
8
  export declare function renderRootHelp(): string;
9
9
  export declare function renderContractHelp(command: Command): string;
10
10
  export declare function renderCommandUsage(command: ParsedCommand): string;
11
+ export declare function renderHelp(coordinate: CliHelpCoordinate): string;
11
12
  type Output = Readonly<{
12
13
  output: "text" | "json";
13
14
  }>;
@@ -35,6 +36,7 @@ export type ParsedDeliver = Output & Actor & Readonly<{
35
36
  contract?: string;
36
37
  message?: string;
37
38
  includeDirty: boolean;
39
+ materializeConflict: boolean;
38
40
  }>;
39
41
  export type ParsedReview = Output & Actor & Readonly<{
40
42
  command: "review";
@@ -77,6 +79,10 @@ type ParsedReconcile = Output & Readonly<{
77
79
  contract?: string;
78
80
  retryHooks: boolean;
79
81
  }>;
82
+ export type ParsedNuke = Output & Readonly<{
83
+ command: "nuke";
84
+ confirm?: string;
85
+ }>;
80
86
  export type ParsedSettings = Output & Readonly<{
81
87
  command: "settings";
82
88
  }>;
@@ -89,7 +95,7 @@ export type ParsedRegion = Output & Readonly<{
89
95
  export type ParsedCommand = ParsedBind | ParsedAmend | ParsedDeliver | ParsedReview | ParsedArc | ParsedAbandon | ParsedStatus | (Output & Readonly<{
90
96
  command: "show";
91
97
  contract?: string;
92
- }>) | ParsedLs | ParsedAudit | ParsedReconcile | ParsedSettings | ParsedRegion | ParsedInstallCommand | ParsedAkumaCommand | ParsedTaskCommand;
98
+ }>) | ParsedLs | ParsedAudit | ParsedReconcile | ParsedNuke | ParsedSettings | ParsedRegion | ParsedInstallCommand | ParsedAkumaCommand | ParsedTaskCommand;
93
99
  export type CliHelpCoordinate = Readonly<{
94
100
  kind: "root";
95
101
  }> | Readonly<{
@@ -112,4 +118,11 @@ export type ParsedExecution = Readonly<{
112
118
  export type ParsedInvocation = ParsedExecution | Readonly<{
113
119
  help: CliHelpCoordinate;
114
120
  }>;
121
+ type RepoUse = "none" | "optional" | "required";
122
+ export type CommandRepoPolicy = Readonly<{
123
+ use: RepoUse;
124
+ acceptsExplicit: boolean;
125
+ }>;
126
+ export declare function commandRepoPolicy(command: ParsedCommand): CommandRepoPolicy;
127
+ export declare function assertExplicitRepoUse(command: ParsedCommand, repo: string | undefined): void;
115
128
  export declare function parseArgv(argv: readonly string[]): ParsedInvocation;