@astrosheep/keiyaku 4.1.1 → 4.1.3

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 (75) hide show
  1. package/build/src/akuma/akuma-errors.d.ts +6 -0
  2. package/build/src/akuma/akuma-errors.js +9 -0
  3. package/build/src/akuma/akuma-handle.d.ts +39 -0
  4. package/build/src/akuma/akuma-handle.js +263 -0
  5. package/build/src/akuma/akuma-observe.d.ts +19 -0
  6. package/build/src/akuma/akuma-observe.js +74 -0
  7. package/build/src/akuma/akuma-product-symbols.d.ts +1 -0
  8. package/build/src/akuma/akuma-product-symbols.js +1 -0
  9. package/build/src/akuma/akuma-product.d.ts +18 -0
  10. package/build/src/akuma/akuma-product.js +154 -0
  11. package/build/src/akuma/akuma.d.ts +23 -70
  12. package/build/src/akuma/akuma.js +17 -433
  13. package/build/src/akuma/body-supervisor.d.ts +26 -0
  14. package/build/src/akuma/body-supervisor.js +89 -0
  15. package/build/src/akuma/body.d.ts +1 -1
  16. package/build/src/akuma/body.js +7 -3
  17. package/build/src/akuma/heart/index.d.ts +1 -1
  18. package/build/src/akuma/heart/index.js +1 -1
  19. package/build/src/akuma/heart/schema.d.ts +1 -0
  20. package/build/src/akuma/heart/schema.js +9 -0
  21. package/build/src/akuma/heart/storage.d.ts +1 -0
  22. package/build/src/akuma/heart/storage.js +18 -1
  23. package/build/src/akuma/nuke.js +6 -2
  24. package/build/src/akuma/projection-read.d.ts +17 -0
  25. package/build/src/akuma/projection-read.js +135 -0
  26. package/build/src/akuma/projection.d.ts +1 -18
  27. package/build/src/akuma/projection.js +21 -155
  28. package/build/src/akuma/providers/claude/index.js +101 -89
  29. package/build/src/akuma/providers/codex-app-server/index.js +9 -6
  30. package/build/src/akuma/providers/opencode-sdk/index.js +22 -15
  31. package/build/src/akuma/providers/pi/index.js +45 -43
  32. package/build/src/akuma/publication.d.ts +2 -1
  33. package/build/src/akuma/publication.js +72 -11
  34. package/build/src/akuma/request-execution.d.ts +8 -0
  35. package/build/src/akuma/request-execution.js +98 -0
  36. package/build/src/akuma/request-serve.d.ts +14 -2
  37. package/build/src/akuma/request-serve.js +3 -103
  38. package/build/src/akuma/{body-turn.d.ts → turn-drive.d.ts} +4 -26
  39. package/build/src/akuma/{body-turn.js → turn-drive.js} +14 -100
  40. package/build/src/cli/commands/akuma.d.ts +0 -6
  41. package/build/src/cli/commands/akuma.js +1 -11
  42. package/build/src/cli/commands/contract-invoke.d.ts +25 -0
  43. package/build/src/cli/commands/contract-invoke.js +193 -0
  44. package/build/src/cli/commands/contract.d.ts +12 -0
  45. package/build/src/cli/commands/contract.js +229 -0
  46. package/build/src/cli/invoke.js +24 -184
  47. package/build/src/cli/parse.d.ts +1 -1
  48. package/build/src/cli/parse.js +8 -222
  49. package/build/src/cli/render/akuma-activity.d.ts +38 -0
  50. package/build/src/cli/render/akuma-activity.js +362 -0
  51. package/build/src/cli/render/akuma.d.ts +1 -1
  52. package/build/src/cli/render/akuma.js +14 -371
  53. package/build/src/cli/render/contract-history.d.ts +2 -0
  54. package/build/src/cli/render/contract-history.js +83 -0
  55. package/build/src/cli/render/contract.d.ts +1 -2
  56. package/build/src/cli/render/contract.js +1 -83
  57. package/build/src/git/read-observation.js +15 -10
  58. package/build/src/git/reconcile.d.ts +8 -1
  59. package/build/src/git/reconcile.js +13 -301
  60. package/build/src/git/scratch.d.ts +8 -5
  61. package/build/src/git/scratch.js +29 -2
  62. package/build/src/git/terminal-reconcile.d.ts +21 -0
  63. package/build/src/git/terminal-reconcile.js +278 -0
  64. package/build/src/kanshi/read.js +32 -27
  65. package/build/src/library/contract-bind.d.ts +26 -0
  66. package/build/src/library/contract-bind.js +106 -0
  67. package/build/src/library/contract-operations.d.ts +77 -0
  68. package/build/src/library/contract-operations.js +130 -0
  69. package/build/src/library/contract-types.d.ts +95 -0
  70. package/build/src/library/contract-types.js +1 -0
  71. package/build/src/library/contract.d.ts +11 -136
  72. package/build/src/library/contract.js +9 -222
  73. package/build/src/library/fleet.js +2 -1
  74. package/build/src/runtime/proc/windows-launch.exe +0 -0
  75. package/package.json +1 -1
@@ -1,5 +1,6 @@
1
1
  import { resolveActor } from "./actor.js";
2
2
  import { isParsedAkumaCommand } from "./commands/akuma.js";
3
+ import { invokeContractMutation } from "./commands/contract-invoke.js";
3
4
  import { assertExplicitRepoUse, CliUsageError, renderCommandUsage, } from "./parse.js";
4
5
  import { isBlankInput } from "./usage.js";
5
6
  async function readStdin() {
@@ -65,14 +66,6 @@ function consumeSettings(run, ErrorType) {
65
66
  throw error;
66
67
  }
67
68
  }
68
- async function selectedGates(value, names) {
69
- const { gatesFrom, SettingsError } = await import("../library/configuration.js");
70
- return consumeSettings(() => gatesFrom({ settings: value, ...(names === undefined ? {} : { names }) }), SettingsError);
71
- }
72
- async function selectedGitPolicy(value) {
73
- const { requireBranchesToBeUpToDateFrom, SettingsError } = await import("../library/configuration.js");
74
- return consumeSettings(() => requireBranchesToBeUpToDateFrom({ settings: value }), SettingsError);
75
- }
76
69
  function actorFromEdge(actor, environment) {
77
70
  let resolved;
78
71
  try {
@@ -99,162 +92,6 @@ async function selectContract(repo, selector, scope) {
99
92
  const id = resolveContextualContract(await Keiyaku.list({ repo }), selector, scope);
100
93
  return contractFromInput(repo, id);
101
94
  }
102
- async function bindDraftReceipt(establishWorld, markdown) {
103
- const { preserveBindDraft } = await import("./draft.js");
104
- try {
105
- return preserveBindDraft(await establishWorld(), markdown);
106
- }
107
- catch (error) {
108
- return { warning: `bind draft could not be preserved: ${error instanceof Error ? error.message : String(error)}` };
109
- }
110
- }
111
- async function invokeBind({ parsed, repo, edge, configuration, hooks, establishWorld, }) {
112
- if (parsed.forkOf !== undefined) {
113
- const actor = actorFromEdge(parsed.actor, edge.environment);
114
- const { bindFromCommand } = await import("./commands/bind.js");
115
- const { acceptedBind, resultFromMutationCall } = await import("./accepted.js");
116
- return resultFromMutationCall("bind", () => bindFromCommand({ command: parsed, repo, ...(actor === undefined ? {} : { actor }), hooks }), (accepted) => {
117
- const bound = accepted.facts.find((fact) => fact.kind === "bind");
118
- if (bound === undefined || bound.kind !== "bind")
119
- throw new Error("accepted bind is missing its bind fact");
120
- return acceptedBind(accepted, bound.data.coordinates);
121
- });
122
- }
123
- const markdown = await edge.readStdin();
124
- const gates = await selectedGates(configuration, parsed.gates);
125
- const actor = actorFromEdge(parsed.actor, edge.environment);
126
- const { bindFromCommand } = await import("./commands/bind.js");
127
- const { acceptedBind, resultFromMutationCall } = await import("./accepted.js");
128
- try {
129
- const result = await resultFromMutationCall("bind", () => bindFromCommand({
130
- command: parsed,
131
- repo,
132
- markdown,
133
- gates,
134
- ...(actor === undefined ? {} : { actor }),
135
- hooks,
136
- }), (accepted) => {
137
- const bound = accepted.facts.find((fact) => fact.kind === "bind");
138
- if (bound === undefined || bound.kind !== "bind")
139
- throw new Error("accepted bind is missing its bind fact");
140
- return acceptedBind(accepted, bound.data.coordinates);
141
- });
142
- if (result.kind !== "refused")
143
- return result;
144
- return { ...result, draft: await bindDraftReceipt(establishWorld, markdown) };
145
- }
146
- catch (error) {
147
- if (!(error instanceof TypeError))
148
- throw error;
149
- const { BindDraftError } = await import("./draft.js");
150
- throw new BindDraftError(error, await bindDraftReceipt(establishWorld, markdown));
151
- }
152
- }
153
- function deliverRefusal(refusal) {
154
- if (typeof refusal !== "object" || refusal === null || !("kind" in refusal) || refusal.kind !== "dirty-workspace") {
155
- return refusal;
156
- }
157
- const submodules = "submodules" in refusal && Array.isArray(refusal.submodules) ? refusal.submodules : [];
158
- return { ...refusal, option: { flag: "--include-dirty", available: submodules.length === 0 } };
159
- }
160
- async function invokeDeliver(parsed, seat, requireBranchesToBeUpToDate) {
161
- const { acceptedDeliver } = await import("./accepted.js");
162
- try {
163
- const delivered = await seat.contract.deliver({
164
- ...(seat.actor === undefined ? {} : { actor: seat.actor }),
165
- ...(parsed.message === undefined ? {} : { message: parsed.message }),
166
- requireBranchesToBeUpToDate,
167
- includeDirty: parsed.includeDirty,
168
- materializeConflict: parsed.materializeConflict,
169
- hooks: seat.hooks,
170
- });
171
- if (!("facts" in delivered))
172
- return delivered;
173
- return acceptedDeliver(delivered, seat.id);
174
- }
175
- catch (error) {
176
- const { KeiyakuRefused, KeiyakuRetry } = await import("../library/keiyaku.js");
177
- if (error instanceof KeiyakuRefused) {
178
- return { kind: "refused", verb: "deliver", contract: seat.id, refusal: deliverRefusal(error.refusal) };
179
- }
180
- if (error instanceof KeiyakuRetry) {
181
- return { kind: "retry", verb: "deliver", contract: seat.id, detail: error.reason };
182
- }
183
- throw error;
184
- }
185
- }
186
- async function invokeReview(parsed, seat, readStdin) {
187
- const summary = parsed.summaryFromStdin === true ? await readStdin() : parsed.summary;
188
- const { acceptedReview, resultFromMutationCall } = await import("./accepted.js");
189
- return resultFromMutationCall("review", () => seat.contract.review({
190
- verdict: parsed.verdict,
191
- ...(seat.actor === undefined ? {} : { actor: seat.actor }),
192
- ...(summary === undefined ? {} : { summary }),
193
- hooks: seat.hooks,
194
- }), (result) => acceptedReview(result, seat.id), { coordinate: seat.id });
195
- }
196
- async function invokeAudit(parsed, seat, requireBranchesToBeUpToDate) {
197
- const { acceptedAudit, resultFromMutationCall } = await import("./accepted.js");
198
- return resultFromMutationCall("audit", () => seat.contract.audit({
199
- ...(seat.actor === undefined ? {} : { actor: seat.actor }),
200
- includeDirty: parsed.includeDirty,
201
- showDiff: parsed.showDiff,
202
- requireBranchesToBeUpToDate,
203
- hooks: seat.hooks,
204
- }), (result) => acceptedAudit(result, seat.id), { coordinate: seat.id });
205
- }
206
- async function existingSeat({ parsed, repo, edge, scope, hooks, }) {
207
- const { id, contract } = await selectContract(repo, parsed.contract, scope);
208
- const actor = actorFromEdge(parsed.actor, edge.environment);
209
- return { contract, id, ...(actor === undefined ? {} : { actor }), hooks };
210
- }
211
- async function invokeExisting(input) {
212
- const { parsed, repo, edge, configuration, hooks } = input;
213
- const seat = await existingSeat(input);
214
- const { id, contract, actor } = seat;
215
- switch (parsed.command) {
216
- case "amend": {
217
- const markdown = parsed.stdin === true ? await edge.readStdin() : undefined;
218
- const gates = parsed.gates === undefined ? undefined : await selectedGates(configuration, parsed.gates);
219
- const { amendFromCommand } = await import("./commands/amend.js");
220
- const { acceptedAmend, resultFromMutationCall } = await import("./accepted.js");
221
- return resultFromMutationCall("amend", () => amendFromCommand({
222
- command: parsed,
223
- repo,
224
- contract,
225
- ...(markdown === undefined ? {} : { markdown }),
226
- gates,
227
- ...(actor === undefined ? {} : { actor }),
228
- hooks,
229
- }), (result) => acceptedAmend(result, id), { coordinate: id });
230
- }
231
- case "deliver":
232
- return invokeDeliver(parsed, seat, await selectedGitPolicy(configuration));
233
- case "review":
234
- return invokeReview(parsed, seat, edge.readStdin);
235
- case "arc": {
236
- const markdown = await edge.readStdin();
237
- const { acceptedArc, resultFromMutationCall } = await import("./accepted.js");
238
- return resultFromMutationCall("arc", () => contract.arc({
239
- markdown,
240
- ...(actor === undefined ? {} : { actor }),
241
- hooks,
242
- }), (result) => acceptedArc(result, id), { coordinate: id });
243
- }
244
- case "abandon": {
245
- const { acceptedAbandon, resultFromMutationCall } = await import("./accepted.js");
246
- return resultFromMutationCall("abandon", () => contract.abandon({
247
- ...(actor === undefined ? {} : { actor }),
248
- ...(parsed.note === undefined ? {} : { note: parsed.note }),
249
- hooks,
250
- }), (result) => acceptedAbandon(result, id), { coordinate: id });
251
- }
252
- case "audit":
253
- return invokeAudit(parsed, seat, await selectedGitPolicy(configuration));
254
- default:
255
- return parsed;
256
- }
257
- }
258
95
  async function invokeAkumaFromEdge(parsed, input) {
259
96
  try {
260
97
  const { statedCwd, repo, edge } = input;
@@ -433,6 +270,18 @@ async function invokeContractHistory(repo, contract) {
433
270
  throw error;
434
271
  }
435
272
  }
273
+ async function invokeForwardedContractMutation(parsed, repo, edge, scope, establishWorld) {
274
+ const { EMPTY_WORKTREE_HOOKS } = await import("../library/configuration.js");
275
+ return invokeContractMutation({
276
+ parsed,
277
+ repo,
278
+ edge,
279
+ scope,
280
+ hooks: EMPTY_WORKTREE_HOOKS,
281
+ establishWorld,
282
+ forwarded: true,
283
+ });
284
+ }
436
285
  async function resolveInvocationCoordinates(invocation, runtime) {
437
286
  const environment = runtime.environment ?? process.env, gitPath = gitPathFromEdge(environment);
438
287
  const { resolveCliCoordinates } = await import("./coordinates.js");
@@ -493,11 +342,7 @@ async function invokeParsed(invocation, runtime) {
493
342
  const scope = cwd;
494
343
  if ((parsed.command === "deliver" || parsed.command === "review") &&
495
344
  (await import("../akuma/requests.js")).injectedBodyRequests() !== null) {
496
- const { EMPTY_WORKTREE_HOOKS } = await import("../library/configuration.js");
497
- const seat = await existingSeat({ parsed, repo, edge, scope, hooks: EMPTY_WORKTREE_HOOKS });
498
- return parsed.command === "deliver"
499
- ? await invokeDeliver(parsed, seat, false)
500
- : await invokeReview(parsed, seat, edge.readStdin);
345
+ return invokeForwardedContractMutation(parsed, repo, edge, scope, establishWorld);
501
346
  }
502
347
  const configuration = await settingsAt(world ?? undefined, home);
503
348
  const { worktreeHooksFrom, SettingsError } = await import("../library/configuration.js");
@@ -506,27 +351,22 @@ async function invokeParsed(invocation, runtime) {
506
351
  const selected = await selectContract(repo, parsed.contract, scope);
507
352
  return { kind: "guidance", contract: selected.id, guidance: await selected.contract.guidance() };
508
353
  }
509
- switch (parsed.command) {
510
- case "reconcile": {
511
- if (parsed.contract === undefined) {
512
- return {
513
- kind: "observation",
514
- command: "reconcile",
515
- report: await repo.reconcile({ hooks, retryHooks: parsed.retryHooks }),
516
- };
517
- }
518
- const { contract } = await selectContract(repo, parsed.contract, scope);
354
+ if (parsed.command === "reconcile") {
355
+ if (parsed.contract === undefined) {
519
356
  return {
520
357
  kind: "observation",
521
358
  command: "reconcile",
522
- ...(await contract.reconcile({ hooks, retryHooks: parsed.retryHooks })),
359
+ report: await repo.reconcile({ hooks, retryHooks: parsed.retryHooks }),
523
360
  };
524
361
  }
525
- case "bind":
526
- return invokeBind({ parsed, repo, edge, configuration, hooks, establishWorld });
527
- default:
528
- return invokeExisting({ parsed, repo, edge, scope, configuration, hooks });
362
+ const { contract } = await selectContract(repo, parsed.contract, scope);
363
+ return {
364
+ kind: "observation",
365
+ command: "reconcile",
366
+ ...(await contract.reconcile({ hooks, retryHooks: parsed.retryHooks })),
367
+ };
529
368
  }
369
+ return invokeContractMutation({ parsed, repo, edge, scope, configuration, hooks, establishWorld });
530
370
  }
531
371
  function withResolvedTaskActor(command, runtime) {
532
372
  if (command.command !== "task" || (command.action !== "add" && command.action !== "compose"))
@@ -3,9 +3,9 @@ import { type AkumaAction, type ParsedAkumaCommand } from "./commands/akuma.js";
3
3
  import { type ParsedInstallCommand } from "./commands/install.js";
4
4
  import { type ContractCommand as Command, type ParsedAbandon, type ParsedAmend, type ParsedArc, type ParsedAudit, type ParsedBind, type ParsedDeliver, type ParsedLs, type ParsedNuke, type ParsedReconcile, type ParsedRegion, type ParsedReview, type ParsedSettings, type ParsedShow, type ParsedStatus } from "./commands/contract.js";
5
5
  export { CliUsageError } from "./usage.js";
6
+ export { renderContractHelp } from "./commands/contract.js";
6
7
  export type { Command };
7
8
  export declare function renderRootHelp(): string;
8
- export declare function renderContractHelp(command: Command): string;
9
9
  export declare function renderCommandUsage(command: ParsedCommand): string;
10
10
  export declare function renderHelp(coordinate: CliHelpCoordinate): string;
11
11
  export type ParsedCommand = ParsedBind | ParsedAmend | ParsedDeliver | ParsedReview | ParsedArc | ParsedAbandon | ParsedStatus | ParsedShow | ParsedLs | ParsedAudit | ParsedReconcile | ParsedNuke | ParsedSettings | ParsedRegion | ParsedInstallCommand | ParsedAkumaCommand | ParsedTaskCommand;
@@ -1,9 +1,10 @@
1
1
  import { isTaskAction, parseTaskCommand, renderTaskHelp, renderTaskUsage, } from "./commands/task.js";
2
- import { isAkumaAction, parseAkumaCatalogPath, parseAkumaCommand, renderAkumaHelp, renderAkumaRootRows, renderAkumaUsage, } from "./commands/akuma.js";
2
+ import { isAkumaAction, parseAkumaCommand, renderAkumaHelp, renderAkumaRootRows, renderAkumaUsage, } from "./commands/akuma.js";
3
3
  import { INSTALL_USAGE, parseInstallCommand, renderInstallHelp, } from "./commands/install.js";
4
- import { CONTRACT_COMMAND_SPECS, } from "./commands/contract.js";
5
- import { CliUsageError, isBlankInput, usageLine } from "./usage.js";
4
+ import { CONTRACT_COMMAND_SPECS, parseContractCommand, renderContractHelp as renderContractHelpForOwner, renderContractUsage, } from "./commands/contract.js";
5
+ import { CliUsageError, isBlankInput } from "./usage.js";
6
6
  export { CliUsageError } from "./usage.js";
7
+ export { renderContractHelp } from "./commands/contract.js";
7
8
  const ROOT_USAGE = "usage: keiyaku [-C <path>] [--repo <path>] <command> [<contract>|@<contract>] [--flag ...] [-]";
8
9
  export function renderRootHelp() {
9
10
  return [
@@ -22,13 +23,8 @@ export function renderRootHelp() {
22
23
  ...renderAkumaRootRows(),
23
24
  ].join("\n");
24
25
  }
25
- export function renderContractHelp(command) {
26
- const spec = CONTRACT_COMMAND_SPECS[command];
27
- const help = `${spec.purpose}\n\n${usageLine(spec.usage)}`;
28
- return spec.details === undefined ? help : `${help}\n\n${spec.details}`;
29
- }
30
26
  function contractUsage(command) {
31
- return usageLine(CONTRACT_COMMAND_SPECS[command].usage);
27
+ return renderContractUsage(command);
32
28
  }
33
29
  export function renderCommandUsage(command) {
34
30
  if (command.command === "install")
@@ -44,7 +40,7 @@ export function renderHelp(coordinate) {
44
40
  case "root":
45
41
  return renderRootHelp();
46
42
  case "contract":
47
- return renderContractHelp(coordinate.command);
43
+ return renderContractHelpForOwner(coordinate.command);
48
44
  case "task":
49
45
  return renderTaskHelp(coordinate.action);
50
46
  case "install":
@@ -103,10 +99,6 @@ export function assertExplicitRepoUse(command, repo) {
103
99
  if (repo !== undefined && !commandRepoPolicy(command).acceptsExplicit)
104
100
  refuseUnusedRepo(command);
105
101
  }
106
- function optionalFlag(flags, name) {
107
- const value = flags[name];
108
- return typeof value === "string" ? value : undefined;
109
- }
110
102
  function refuse(command, message) {
111
103
  throw new CliUsageError(message, contractUsage(command));
112
104
  }
@@ -179,147 +171,9 @@ function scanArgv(argv) {
179
171
  refuse(command, `${command} requires stdin`);
180
172
  }
181
173
  const output = state.flags.json === true ? "json" : "text";
182
- const actor = optionalFlag(state.flags, "actor");
174
+ const actor = typeof state.flags.actor === "string" ? state.flags.actor : undefined;
183
175
  return { command, ...state, output, ...(actor === undefined ? {} : { actor }) };
184
176
  }
185
- function parseBind(parts) {
186
- const forkOf = optionalFlag(parts.flags, "fork-of");
187
- if (forkOf !== undefined) {
188
- if (parts.stdin)
189
- refuse("bind", "fork bind reads no stdin");
190
- for (const option of ["task", "after", "gates"]) {
191
- if (parts.flags[option] !== undefined)
192
- refuse("bind", `--${option} is not valid with --fork-of`);
193
- }
194
- const target = optionalFlag(parts.flags, "target");
195
- return {
196
- command: "bind",
197
- forkOf,
198
- ...(target === undefined ? {} : { target }),
199
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
200
- output: parts.output,
201
- };
202
- }
203
- if (!parts.stdin)
204
- refuse("bind", "bind requires stdin");
205
- const task = optionalFlag(parts.flags, "task");
206
- const target = optionalFlag(parts.flags, "target");
207
- const after = parts.flags.after === undefined ? [] : Array.isArray(parts.flags.after) ? parts.flags.after : [parts.flags.after];
208
- const gates = parseGateBundleNames(parts, "bind");
209
- return {
210
- command: "bind",
211
- ...(task === undefined ? {} : { task }),
212
- ...(target === undefined ? {} : { target }),
213
- ...(parts.flags.after === undefined ? {} : { after }),
214
- ...(gates === undefined ? {} : { gates }),
215
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
216
- output: parts.output,
217
- };
218
- }
219
- function parseAmend(parts) {
220
- const contract = parts.positionals[0];
221
- const after = parts.flags.after === undefined ? [] : Array.isArray(parts.flags.after) ? parts.flags.after : [parts.flags.after];
222
- if (parts.flags["clear-after"] === true && after.length > 0)
223
- refuse("amend", "--clear-after and --after are mutually exclusive");
224
- const gates = parseGateBundleNames(parts, "amend");
225
- if (!parts.stdin && parts.flags.after === undefined && parts.flags["clear-after"] !== true && gates === undefined) {
226
- refuse("amend", "amend requires stdin or --after, --clear-after, or --gates");
227
- }
228
- return {
229
- command: "amend",
230
- ...(contract === undefined ? {} : { contract }),
231
- ...(parts.flags.after === undefined ? {} : { after }),
232
- ...(parts.flags["clear-after"] === true ? { clearAfter: true } : {}),
233
- ...(gates === undefined ? {} : { gates }),
234
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
235
- ...(parts.stdin ? { stdin: true } : {}),
236
- output: parts.output,
237
- };
238
- }
239
- function parseGateBundleNames(parts, command) {
240
- const value = optionalFlag(parts.flags, "gates");
241
- if (value === undefined)
242
- return undefined;
243
- const names = value.split(",");
244
- if (names.some((name) => name.length === 0)) {
245
- refuse(command, "--gates requires nonempty comma-separated names");
246
- }
247
- return names;
248
- }
249
- function parseDeliver(parts) {
250
- const contract = parts.positionals[0];
251
- const message = optionalFlag(parts.flags, "message");
252
- return {
253
- command: "deliver",
254
- ...(contract === undefined ? {} : { contract }),
255
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
256
- ...(message === undefined ? {} : { message }),
257
- includeDirty: parts.flags["include-dirty"] === true,
258
- materializeConflict: parts.flags["materialize-conflict"] === true,
259
- output: parts.output,
260
- };
261
- }
262
- function parseReview(parts) {
263
- if (Number(parts.flags.satisfied === true) + Number(parts.flags.unsatisfied === true) !== 1) {
264
- refuse("review", "review requires exactly one verdict flag");
265
- }
266
- const summary = optionalFlag(parts.flags, "summary");
267
- if (parts.stdin === (summary !== undefined)) {
268
- refuse("review", "review requires exactly one of --summary <text> or stdin '-'");
269
- }
270
- const contract = parts.positionals[0];
271
- return {
272
- command: "review",
273
- ...(contract === undefined ? {} : { contract }),
274
- verdict: parts.flags.satisfied === true ? "satisfied" : "unsatisfied",
275
- ...(summary === undefined ? {} : { summary }),
276
- ...(parts.stdin ? { summaryFromStdin: true } : {}),
277
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
278
- output: parts.output,
279
- };
280
- }
281
- function parseStatus(parts) {
282
- const contract = parts.positionals[0];
283
- if (contract?.startsWith("aku/") === true) {
284
- return { command: "status", contract, akuma: true, output: parts.output };
285
- }
286
- return {
287
- command: "status",
288
- ...(contract === undefined ? {} : { contract }),
289
- output: parts.output,
290
- };
291
- }
292
- function parseRegion(parts) {
293
- const contract = parts.positionals[0];
294
- const pathFlag = parts.flags.path;
295
- const paths = pathFlag === undefined ? undefined : Array.isArray(pathFlag) ? pathFlag : [pathFlag];
296
- if (paths !== undefined && contract !== undefined)
297
- refuse("region", "--path cannot combine with a contract");
298
- return {
299
- command: "region",
300
- ...(contract === undefined ? {} : { contract }),
301
- ...(paths === undefined ? {} : { paths: paths }),
302
- output: parts.output,
303
- };
304
- }
305
- function parseLs(parts) {
306
- const path = parts.positionals[0];
307
- if (path === "task" || path === "task/")
308
- return { command: "ls", query: { kind: "tasks" }, output: parts.output };
309
- if (path === "kei" || path === "kei/")
310
- return { command: "ls", query: { kind: "contracts" }, output: parts.output };
311
- try {
312
- const query = parseAkumaCatalogPath(path);
313
- if (query === null)
314
- refuse("ls", "ls requires a supported identity directory selector");
315
- return { command: "ls", query, output: parts.output };
316
- }
317
- catch (error) {
318
- if (error instanceof CliUsageError)
319
- throw error;
320
- refuse("ls", error instanceof Error ? error.message : "invalid ls directory");
321
- }
322
- }
323
177
  function invocationOptions(argv) {
324
178
  let cwd;
325
179
  let repo;
@@ -371,74 +225,6 @@ function helpCoordinate(argv) {
371
225
  }
372
226
  return { kind: "root" };
373
227
  }
374
- function parseCommand(parts) {
375
- switch (parts.command) {
376
- case "bind":
377
- return parseBind(parts);
378
- case "amend":
379
- return parseAmend(parts);
380
- case "deliver":
381
- return parseDeliver(parts);
382
- case "review":
383
- return parseReview(parts);
384
- case "arc": {
385
- const contract = parts.positionals[0];
386
- return {
387
- command: "arc",
388
- ...(contract === undefined ? {} : { contract }),
389
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
390
- output: parts.output,
391
- };
392
- }
393
- case "abandon": {
394
- const contract = parts.positionals[0];
395
- const note = optionalFlag(parts.flags, "note");
396
- return {
397
- command: "abandon",
398
- ...(contract === undefined ? {} : { contract }),
399
- ...(note === undefined ? {} : { note }),
400
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
401
- output: parts.output,
402
- };
403
- }
404
- case "status":
405
- return parseStatus(parts);
406
- case "show": {
407
- const contract = parts.positionals[0];
408
- return { command: "show", ...(contract === undefined ? {} : { contract }), output: parts.output };
409
- }
410
- case "ls":
411
- return parseLs(parts);
412
- case "audit": {
413
- const contract = parts.positionals[0];
414
- return {
415
- command: "audit",
416
- ...(contract === undefined ? {} : { contract }),
417
- includeDirty: parts.flags["include-dirty"] === true,
418
- showDiff: parts.flags.diff === true,
419
- ...(parts.actor === undefined ? {} : { actor: parts.actor }),
420
- output: parts.output,
421
- };
422
- }
423
- case "reconcile": {
424
- const contract = parts.positionals[0];
425
- return {
426
- command: "reconcile",
427
- ...(contract === undefined ? {} : { contract }),
428
- retryHooks: parts.flags["retry-hooks"] === true,
429
- output: parts.output,
430
- };
431
- }
432
- case "nuke": {
433
- const confirm = optionalFlag(parts.flags, "confirm");
434
- return { command: "nuke", ...(confirm === undefined ? {} : { confirm }), output: parts.output };
435
- }
436
- case "settings":
437
- return { command: "settings", output: parts.output };
438
- case "region":
439
- return parseRegion(parts);
440
- }
441
- }
442
228
  export function parseArgv(argv) {
443
229
  const invocation = invocationOptions(argv);
444
230
  const help = helpCoordinate(invocation.commandArgv);
@@ -455,6 +241,6 @@ export function parseArgv(argv) {
455
241
  return {
456
242
  ...(invocation.cwd === undefined ? {} : { cwd: invocation.cwd }),
457
243
  ...(invocation.repo === undefined ? {} : { repo: invocation.repo }),
458
- command: task ?? akuma ?? install ?? parseCommand(scanArgv(invocation.commandArgv)),
244
+ command: task ?? akuma ?? install ?? parseContractCommand(scanArgv(invocation.commandArgv)),
459
245
  };
460
246
  }
@@ -0,0 +1,38 @@
1
+ import type { AkumaObservation, AkumaObservationStage, CreatedTaskObservation, DispatchAssociation } from "../../index.js";
2
+ import type { AkumaInvocationResult } from "../commands/akuma-invoke.js";
3
+ import type { ParsedCommand } from "../parse.js";
4
+ import { type TextRenderContext } from "./terminal.js";
5
+ export declare const DEFAULT_CONTEXT: TextRenderContext;
6
+ export declare function associatedIdentity(id: string, alias?: string, contract?: DispatchAssociation): string;
7
+ export declare function snapshotHeading(id: string, alias: string | undefined, contract: DispatchAssociation | undefined): readonly string[];
8
+ type SnapshotView = Readonly<{
9
+ status: AkumaObservation["status"];
10
+ contract: DispatchAssociation;
11
+ createdTasks?: CreatedTaskObservation;
12
+ }>;
13
+ type SnapshotCoreOptions = Readonly<{
14
+ alias?: string;
15
+ facts?: readonly string[];
16
+ }>;
17
+ export declare function snapshotText(view: SnapshotView, context: TextRenderContext, options?: SnapshotCoreOptions): string;
18
+ export declare function mutationObservationStageText(id: string, observation: AkumaObservationStage, context: TextRenderContext, options?: SnapshotCoreOptions & Readonly<{
19
+ showLife?: boolean;
20
+ }>): string;
21
+ export declare function statusAnswer(view: Readonly<{
22
+ status: AkumaObservation["status"];
23
+ }>): string | undefined;
24
+ export declare function akumaRawAnswer(result: AkumaInvocationResult): string | undefined;
25
+ export declare function waitText(result: Extract<AkumaInvocationResult, {
26
+ action: "wait";
27
+ }>, context: TextRenderContext): string;
28
+ export declare function historyText(command: Extract<ParsedCommand, {
29
+ command: "history";
30
+ last: boolean;
31
+ }>, result: Extract<AkumaInvocationResult, {
32
+ action: "history";
33
+ }>, context: TextRenderContext): string;
34
+ export declare function tellText(result: Extract<AkumaInvocationResult, {
35
+ action: "tell";
36
+ mode: "ordinary";
37
+ }>, context: TextRenderContext): string;
38
+ export {};