@astrosheep/keiyaku 4.0.5 → 4.1.0
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.
- package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +1 -1
- package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +1 -1
- package/build/integrations/marketplace/plugins/keiyaku/package.json +1 -1
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +1 -1
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +15 -7
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +5 -3
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +10 -4
- package/build/src/akuma/akuma.d.ts +2 -0
- package/build/src/akuma/akuma.js +26 -3
- package/build/src/akuma/archetype.d.ts +3 -1
- package/build/src/akuma/archetype.js +19 -7
- package/build/src/akuma/body-turn.d.ts +64 -0
- package/build/src/akuma/body-turn.js +449 -0
- package/build/src/akuma/body.d.ts +3 -7
- package/build/src/akuma/body.js +9 -420
- package/build/src/akuma/heart/facts.d.ts +2 -0
- package/build/src/akuma/heart/facts.js +3 -1
- package/build/src/akuma/heart/index.js +12 -2
- package/build/src/akuma/heart/rows.js +4 -1
- package/build/src/akuma/heart/schema.d.ts +1 -1
- package/build/src/akuma/heart/schema.js +3 -2
- package/build/src/akuma/heart/timeline.d.ts +1 -0
- package/build/src/akuma/heart/timeline.js +19 -0
- package/build/src/akuma/nuke.d.ts +2 -0
- package/build/src/akuma/nuke.js +152 -0
- package/build/src/akuma/provider-recipe.d.ts +2 -0
- package/build/src/akuma/provider-recipe.js +10 -0
- package/build/src/akuma/provider.d.ts +3 -1
- package/build/src/akuma/providers/acp/config.d.ts +10 -0
- package/build/src/akuma/providers/acp/config.js +45 -0
- package/build/src/akuma/providers/acp/core.d.ts +5 -2
- package/build/src/akuma/providers/acp/core.js +35 -16
- package/build/src/akuma/providers/acp/index.d.ts +1 -8
- package/build/src/akuma/providers/acp/index.js +10 -39
- package/build/src/akuma/providers/claude/index.d.ts +1 -1
- package/build/src/akuma/providers/claude/index.js +14 -5
- package/build/src/akuma/providers/codex-app-server/index.js +9 -1
- package/build/src/akuma/providers/grok-build/index.js +16 -2
- package/build/src/akuma/providers/index.d.ts +3 -2
- package/build/src/akuma/providers/index.js +37 -37
- package/build/src/akuma/providers/opencode-sdk/index.js +9 -0
- package/build/src/akuma/providers/opencode-sdk/session.d.ts +1 -1
- package/build/src/akuma/providers/opencode-sdk/session.js +1 -1
- package/build/src/akuma/providers/pi/index.d.ts +1 -1
- package/build/src/akuma/providers/pi/index.js +30 -12
- package/build/src/akuma/request-serve.d.ts +1 -0
- package/build/src/akuma/request-serve.js +31 -31
- package/build/src/akuma/request-wire.d.ts +3 -2
- package/build/src/akuma/request-wire.js +5 -2
- package/build/src/akuma-body.js +15 -1
- package/build/src/alias/index.d.ts +1 -0
- package/build/src/alias/index.js +34 -1
- package/build/src/body/amend.js +0 -9
- package/build/src/body/region.js +2 -2
- package/build/src/cli/accepted.js +6 -0
- package/build/src/cli/commands/akuma-invoke.js +1 -0
- package/build/src/cli/commands/akuma.d.ts +1 -0
- package/build/src/cli/commands/akuma.js +11 -8
- package/build/src/cli/commands/contract.d.ts +28 -15
- package/build/src/cli/commands/contract.js +34 -18
- package/build/src/cli/commands/install.d.ts +2 -2
- package/build/src/cli/commands/install.js +6 -6
- package/build/src/cli/commands/nuke.d.ts +10 -0
- package/build/src/cli/commands/nuke.js +20 -0
- package/build/src/cli/commands/task-invoke.d.ts +19 -1
- package/build/src/cli/commands/task-invoke.js +63 -29
- package/build/src/cli/commands/task-query.d.ts +2 -2
- package/build/src/cli/commands/task-query.js +1 -2
- package/build/src/cli/commands/task.js +30 -22
- package/build/src/cli/coordinates.d.ts +5 -2
- package/build/src/cli/coordinates.js +5 -52
- package/build/src/cli/invoke.d.ts +5 -4
- package/build/src/cli/invoke.js +89 -59
- package/build/src/cli/main.d.ts +0 -2
- package/build/src/cli/main.js +4 -140
- package/build/src/cli/parse.d.ts +15 -2
- package/build/src/cli/parse.js +73 -8
- package/build/src/cli/render/akuma.js +95 -49
- package/build/src/cli/render/catalog.js +5 -1
- package/build/src/cli/render/contract.js +72 -49
- package/build/src/cli/render/kanshi.js +157 -99
- package/build/src/cli/render/nuke.d.ts +3 -0
- package/build/src/cli/render/nuke.js +8 -0
- package/build/src/cli/render/receipt.d.ts +1 -0
- package/build/src/cli/render/receipt.js +18 -14
- package/build/src/cli/render/refusal.d.ts +2 -1
- package/build/src/cli/render/refusal.js +37 -0
- package/build/src/cli/render/task.js +63 -11
- package/build/src/cli/render/text.js +6 -1
- package/build/src/cli/result.d.ts +28 -2
- package/build/src/cli/runtime.d.ts +2 -0
- package/build/src/cli/runtime.js +140 -0
- package/build/src/cli/usage.d.ts +0 -2
- package/build/src/cli/usage.js +0 -4
- package/build/src/contract-worktree.d.ts +26 -12
- package/build/src/contract-worktree.js +119 -64
- package/build/src/git/hooks.d.ts +2 -0
- package/build/src/git/hooks.js +34 -1
- package/build/src/git/integration.d.ts +4 -0
- package/build/src/git/integration.js +38 -0
- package/build/src/git/nuke.d.ts +2 -0
- package/build/src/git/nuke.js +92 -0
- package/build/src/git/process.d.ts +2 -0
- package/build/src/git/repository.js +4 -1
- package/build/src/git/target-placement.d.ts +2 -1
- package/build/src/git/target-placement.js +6 -7
- package/build/src/git/tender.d.ts +14 -2
- package/build/src/git/tender.js +45 -6
- package/build/src/git/workspace.d.ts +3 -0
- package/build/src/kanshi/read.js +37 -13
- package/build/src/kanshi/report.d.ts +2 -1
- package/build/src/library/akuma-creation.d.ts +1 -0
- package/build/src/library/akuma-creation.js +8 -1
- package/build/src/library/audit.d.ts +1 -0
- package/build/src/library/audit.js +1 -0
- package/build/src/library/continuation.d.ts +26 -0
- package/build/src/library/continuation.js +78 -0
- package/build/src/library/contract.d.ts +14 -8
- package/build/src/library/contract.js +82 -35
- package/build/src/library/delivery.d.ts +18 -11
- package/build/src/library/keiyaku.d.ts +5 -1
- package/build/src/library/keiyaku.js +2 -0
- package/build/src/library/mutation.d.ts +1 -0
- package/build/src/library/mutation.js +14 -4
- package/build/src/library/nuke.d.ts +14 -0
- package/build/src/library/nuke.js +54 -0
- package/build/src/library/reconcile.js +5 -2
- package/build/src/library/refusal.d.ts +10 -1
- package/build/src/library/repo.d.ts +1 -0
- package/build/src/library/repo.js +2 -0
- package/build/src/protocol/audit.js +12 -5
- package/build/src/protocol/completion.d.ts +11 -1
- package/build/src/protocol/completion.js +68 -15
- package/build/src/protocol/deliver.d.ts +25 -3
- package/build/src/protocol/deliver.js +148 -14
- package/build/src/protocol/intent.d.ts +1 -0
- package/build/src/protocol/intent.js +7 -1
- package/build/src/protocol/operations.d.ts +36 -4
- package/build/src/protocol/operations.js +2 -2
- package/build/src/protocol/placement.d.ts +9 -1
- package/build/src/protocol/placement.js +5 -4
- package/build/src/protocol/read/status.d.ts +16 -4
- package/build/src/protocol/read/status.js +54 -12
- package/build/src/protocol/review.d.ts +1 -0
- package/build/src/protocol/review.js +8 -0
- package/build/src/runtime/proc/run.js +9 -5
- package/build/src/settlement/settle.js +1 -2
- package/build/src/task/board.d.ts +21 -2
- package/build/src/task/board.js +25 -12
- package/build/src/task/compose.d.ts +1 -1
- package/build/src/task/compose.js +2 -7
- package/build/src/task/context.d.ts +14 -2
- package/build/src/task/context.js +30 -7
- package/build/src/task/identity.js +14 -4
- package/build/src/task/index.d.ts +7 -5
- package/build/src/task/index.js +21 -18
- package/build/src/task/mutation.d.ts +7 -2
- package/build/src/task/mutation.js +14 -6
- package/build/src/task/operations.d.ts +14 -7
- package/build/src/task/operations.js +37 -50
- package/build/src/task/query.js +2 -2
- package/build/src/task/store.d.ts +3 -0
- package/build/src/task/store.js +21 -2
- package/build/src/workspace-place.d.ts +2 -0
- package/build/src/workspace-place.js +27 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Repo } from "../
|
|
1
|
+
import { Repo } from "../library/repo.js";
|
|
2
2
|
import { type WorldRoot } from "../world.js";
|
|
3
3
|
import { type ParsedCommand } from "./parse.js";
|
|
4
4
|
export type CliCoordinates = Readonly<{
|
|
@@ -7,6 +7,10 @@ export type CliCoordinates = Readonly<{
|
|
|
7
7
|
repo?: Repo;
|
|
8
8
|
world: WorldRoot | null;
|
|
9
9
|
candidateWorld: WorldRoot | null;
|
|
10
|
+
taskContext: Readonly<{
|
|
11
|
+
directory: string;
|
|
12
|
+
boundary: string;
|
|
13
|
+
}>;
|
|
10
14
|
establishWorld: () => Promise<WorldRoot>;
|
|
11
15
|
}>;
|
|
12
16
|
export type CliCoordinateInput = Readonly<{
|
|
@@ -16,5 +20,4 @@ export type CliCoordinateInput = Readonly<{
|
|
|
16
20
|
gitPath?: string;
|
|
17
21
|
command: ParsedCommand;
|
|
18
22
|
}>;
|
|
19
|
-
export declare function assertExplicitRepoUse(command: ParsedCommand, repo: string | undefined): void;
|
|
20
23
|
export declare function resolveCliCoordinates(input: CliCoordinateInput): Promise<CliCoordinates>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { realpath } from "node:fs/promises";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
import { NoGitWorldError, Repo } from "../
|
|
3
|
+
import { NoGitWorldError, Repo } from "../library/repo.js";
|
|
4
4
|
import { World, WorldError } from "../world.js";
|
|
5
|
-
import { CliUsageError } from "./parse.js";
|
|
5
|
+
import { CliUsageError, commandRepoPolicy } from "./parse.js";
|
|
6
6
|
async function canonicalInvocationCwd(input) {
|
|
7
7
|
try {
|
|
8
8
|
return await realpath(input);
|
|
@@ -24,55 +24,6 @@ async function discoverRepoAt(coordinate, gitPath) {
|
|
|
24
24
|
throw error;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
function repoPolicy(command) {
|
|
28
|
-
switch (command.command) {
|
|
29
|
-
case "bind":
|
|
30
|
-
case "amend":
|
|
31
|
-
case "deliver":
|
|
32
|
-
case "review":
|
|
33
|
-
case "arc":
|
|
34
|
-
case "abandon":
|
|
35
|
-
case "audit":
|
|
36
|
-
case "reconcile":
|
|
37
|
-
case "show":
|
|
38
|
-
case "region":
|
|
39
|
-
return { use: "required", acceptsExplicit: true };
|
|
40
|
-
case "ls":
|
|
41
|
-
return { use: command.query.kind === "contracts" ? "required" : "none", acceptsExplicit: false };
|
|
42
|
-
case "status":
|
|
43
|
-
case "tell":
|
|
44
|
-
return { use: "optional", acceptsExplicit: false };
|
|
45
|
-
case "history":
|
|
46
|
-
return "contract" in command
|
|
47
|
-
? { use: "required", acceptsExplicit: true }
|
|
48
|
-
: { use: "optional", acceptsExplicit: false };
|
|
49
|
-
case "fork":
|
|
50
|
-
return { use: "optional", acceptsExplicit: true };
|
|
51
|
-
case "wait":
|
|
52
|
-
case "kill": {
|
|
53
|
-
const contractSelector = command.akuma.some((selector) => selector.startsWith("kei/"));
|
|
54
|
-
return { use: contractSelector ? "required" : "optional", acceptsExplicit: contractSelector };
|
|
55
|
-
}
|
|
56
|
-
case "call":
|
|
57
|
-
return {
|
|
58
|
-
use: command.contract === undefined ? "none" : "required",
|
|
59
|
-
acceptsExplicit: command.contract !== undefined,
|
|
60
|
-
};
|
|
61
|
-
case "settings":
|
|
62
|
-
case "task":
|
|
63
|
-
case "install":
|
|
64
|
-
return { use: "none", acceptsExplicit: false };
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function refuseUnusedRepo(command) {
|
|
68
|
-
if (command.command === "call")
|
|
69
|
-
throw new CliUsageError("--repo has no consumer without --contract");
|
|
70
|
-
throw new CliUsageError(`--repo has no consumer for ${command.command}`);
|
|
71
|
-
}
|
|
72
|
-
export function assertExplicitRepoUse(command, repo) {
|
|
73
|
-
if (repo !== undefined && !repoPolicy(command).acceptsExplicit)
|
|
74
|
-
refuseUnusedRepo(command);
|
|
75
|
-
}
|
|
76
27
|
function repoFor(use, discovery) {
|
|
77
28
|
if (use === "none")
|
|
78
29
|
return undefined;
|
|
@@ -114,14 +65,16 @@ export async function resolveCliCoordinates(input) {
|
|
|
114
65
|
? invocationRepo
|
|
115
66
|
: await discoverRepoAt(resolve(cwd, input.repo), input.gitPath);
|
|
116
67
|
const worldRepo = invocationRepo.kind === "present" ? invocationRepo.repo : undefined;
|
|
117
|
-
const repo = repoFor(
|
|
68
|
+
const repo = repoFor(commandRepoPolicy(input.command).use, selectedRepo);
|
|
118
69
|
const world = await resolveWorld(cwd, worldRepo);
|
|
70
|
+
const boundary = worldRepo === undefined ? world.root ?? world.candidate ?? cwd : worldRepo.cwd;
|
|
119
71
|
return {
|
|
120
72
|
cwd,
|
|
121
73
|
cwdSource: input.cwd === undefined ? "process" : "input",
|
|
122
74
|
...(repo === undefined ? {} : { repo }),
|
|
123
75
|
world: world.root,
|
|
124
76
|
candidateWorld: world.candidate,
|
|
77
|
+
taskContext: { directory: cwd, boundary },
|
|
125
78
|
establishWorld: world.establish,
|
|
126
79
|
};
|
|
127
80
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { type TaskInvocationResult } from "./commands/task-invoke.js";
|
|
1
|
+
import type { AkumaInvocationResult } from "./commands/akuma-invoke.js";
|
|
2
|
+
import type { InstallInvocationResult } from "./commands/install.js";
|
|
3
|
+
import type { TaskInvocationResult } from "./commands/task-invoke.js";
|
|
5
4
|
import { type ParsedExecution } from "./parse.js";
|
|
6
5
|
import type { InvocationResult } from "./result.js";
|
|
6
|
+
import type { ActorId, ContractId } from "../index.js";
|
|
7
|
+
import type { Settings } from "../settings.js";
|
|
7
8
|
export type { AcceptedFact, InvocationResult, Lag } from "./result.js";
|
|
8
9
|
type InvokeRuntime = Readonly<{
|
|
9
10
|
cwd?: string;
|
package/build/src/cli/invoke.js
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
...(
|
|
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
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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
|
|
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?.();
|
package/build/src/cli/main.d.ts
CHANGED
package/build/src/cli/main.js
CHANGED
|
@@ -1,151 +1,15 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
144
|
-
|
|
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
|
}
|