@astrosheep/keiyaku 4.6.32 → 4.6.34
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/README.md +18 -7
- package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +18 -11
- package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +18 -11
- package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +18 -11
- package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/pi/README.md +55 -97
- package/build/plugins/pi/keiyaku.ts +1 -142
- package/build/skills/keiyaku-akuma/SKILL.md +18 -11
- package/build/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/src/akuma/akuma-instance.d.ts +11 -0
- package/build/src/akuma/akuma-instance.js +1 -2
- package/build/src/akuma/akuma-observe.d.ts +8 -0
- package/build/src/akuma/akuma-observe.js +81 -14
- package/build/src/akuma/akuma-owner.d.ts +1 -0
- package/build/src/akuma/akuma-owner.js +3 -5
- package/build/src/akuma/akuma-selection-execution.d.ts +82 -7
- package/build/src/akuma/akuma-selection-execution.js +26 -27
- package/build/src/akuma/akuma-wait.d.ts +155 -1
- package/build/src/akuma/akuma-wait.js +94 -34
- package/build/src/akuma/akuma.d.ts +17 -1
- package/build/src/akuma/akuma.js +37 -18
- package/build/src/akuma/body.js +13 -18
- package/build/src/akuma/call-initial-tell.d.ts +0 -1
- package/build/src/akuma/call-initial-tell.js +0 -1
- package/build/src/akuma/heart/activity-schema.d.ts +16 -0
- package/build/src/akuma/heart/activity-schema.js +7 -0
- package/build/src/akuma/heart/facts.d.ts +1 -0
- package/build/src/akuma/heart/facts.js +14 -0
- package/build/src/akuma/heart/index.d.ts +7 -1
- package/build/src/akuma/heart/index.js +35 -9
- package/build/src/akuma/heart/rows.d.ts +1 -0
- package/build/src/akuma/heart/rows.js +4 -0
- package/build/src/akuma/heart/timeline.js +4 -4
- package/build/src/akuma/lineage-cache.d.ts +7 -2
- package/build/src/akuma/lineage-cache.js +48 -24
- package/build/src/akuma/projection-read.d.ts +4 -2
- package/build/src/akuma/projection-read.js +25 -23
- package/build/src/akuma/projection.d.ts +94 -2
- package/build/src/akuma/projection.js +47 -47
- package/build/src/akuma/provider.d.ts +2 -2
- package/build/src/akuma/provider.js +27 -20
- package/build/src/akuma/providers/acp/core.js +2 -5
- package/build/src/akuma/providers/opencode-sdk/events.d.ts +2 -1
- package/build/src/akuma/providers/opencode-sdk/events.js +31 -1
- package/build/src/akuma/publication.js +3 -2
- package/build/src/akuma/selection-observation.d.ts +645 -0
- package/build/src/akuma/selection-observation.js +22 -7
- package/build/src/akuma/status-projection.d.ts +14 -1
- package/build/src/akuma/status-projection.js +40 -2
- package/build/src/akuma/turn-drive.js +21 -15
- package/build/src/body/amend.js +5 -17
- package/build/src/body/decode.js +11 -1
- package/build/src/body/envelope.d.ts +5 -1
- package/build/src/body/envelope.js +4 -2
- package/build/src/body/render.js +4 -6
- package/build/src/bounded-list.d.ts +8 -0
- package/build/src/bounded-list.js +10 -0
- package/build/src/cli/commands/akuma-grammar.d.ts +5 -8
- package/build/src/cli/commands/akuma-grammar.js +52 -77
- package/build/src/cli/commands/akuma.d.ts +1 -2
- package/build/src/cli/commands/akuma.js +12 -61
- package/build/src/cli/commands/contract-grammar.d.ts +1 -0
- package/build/src/cli/commands/contract-grammar.js +39 -42
- package/build/src/cli/commands/contract-help.d.ts +6 -5
- package/build/src/cli/commands/contract-help.js +21 -13
- package/build/src/cli/commands/contract.d.ts +3 -3
- package/build/src/cli/commands/contract.js +13 -9
- package/build/src/cli/commands/debt-grammar.js +2 -4
- package/build/src/cli/parse.d.ts +4 -10
- package/build/src/cli/parse.js +2 -5
- package/build/src/cli/render/akuma-activity.d.ts +12 -34
- package/build/src/cli/render/akuma-activity.js +99 -180
- package/build/src/cli/render/akuma.d.ts +5 -11
- package/build/src/cli/render/akuma.js +22 -30
- package/build/src/cli/render/catalog.js +4 -6
- package/build/src/cli/render/contract-history.d.ts +1 -3
- package/build/src/cli/render/contract-history.js +70 -49
- package/build/src/cli/render/contract-observation.d.ts +2 -1
- package/build/src/cli/render/contract-observation.js +25 -1
- package/build/src/cli/render/contract-wait.d.ts +2 -2
- package/build/src/cli/render/contract-wait.js +21 -17
- package/build/src/cli/render/contract.js +12 -9
- package/build/src/cli/render/debt.js +1 -2
- package/build/src/cli/render/execution-progress.js +1 -3
- package/build/src/cli/render/kanshi-akuma.d.ts +4 -3
- package/build/src/cli/render/kanshi-akuma.js +27 -23
- package/build/src/cli/render/kanshi.js +45 -60
- package/build/src/cli/render/receipt.d.ts +1 -1
- package/build/src/cli/render/receipt.js +33 -28
- package/build/src/cli/render/reconcile.js +2 -5
- package/build/src/cli/render/refusal.js +3 -6
- package/build/src/cli/render/terminal.d.ts +2 -4
- package/build/src/cli/render/terminal.js +10 -17
- package/build/src/cli/render/verbs.d.ts +1 -0
- package/build/src/cli/render/verbs.js +39 -34
- package/build/src/cli/runtime.js +12 -32
- package/build/src/core/facts/codec.js +7 -2
- package/build/src/core/facts/eligibility.d.ts +4 -4
- package/build/src/core/facts/eligibility.js +11 -0
- package/build/src/core/facts/fold.js +9 -5
- package/build/src/core/facts/gate.d.ts +5 -1
- package/build/src/core/facts/gate.js +14 -10
- package/build/src/core/facts/types.d.ts +5 -1
- package/build/src/core/facts/types.js +7 -0
- package/build/src/core/subject.d.ts +4 -1
- package/build/src/core/subject.js +10 -2
- package/build/src/core/verbs/amend.d.ts +15 -4
- package/build/src/core/verbs/amend.js +19 -9
- package/build/src/debt/board.d.ts +2 -1
- package/build/src/debt/board.js +3 -3
- package/build/src/debt/catalog.js +2 -1
- package/build/src/debt/document.d.ts +1 -0
- package/build/src/debt/document.js +3 -0
- package/build/src/debt/index.d.ts +2 -2
- package/build/src/debt/index.js +9 -14
- package/build/src/debt/input.d.ts +2 -1
- package/build/src/debt/input.js +6 -4
- package/build/src/debt/operations.d.ts +2 -1
- package/build/src/dispatch/index.d.ts +0 -17
- package/build/src/dispatch/index.js +1 -10
- package/build/src/git/identity.js +16 -45
- package/build/src/git/nuke.js +13 -23
- package/build/src/git/observe.d.ts +7 -3
- package/build/src/git/observe.js +29 -26
- package/build/src/git/process.js +11 -18
- package/build/src/git/read-observation.d.ts +5 -4
- package/build/src/git/repository.d.ts +2 -0
- package/build/src/git/repository.js +13 -1
- package/build/src/git/scratch.js +2 -14
- package/build/src/git/terminal-reconcile.js +1 -13
- package/build/src/history.d.ts +26 -0
- package/build/src/history.js +43 -0
- package/build/src/index.d.ts +6 -3
- package/build/src/kanshi/counts.d.ts +15 -1
- package/build/src/kanshi/counts.js +14 -3
- package/build/src/kanshi/index.d.ts +3 -4
- package/build/src/kanshi/index.js +2 -3
- package/build/src/kanshi/read.d.ts +21 -0
- package/build/src/kanshi/read.js +7 -3
- package/build/src/kanshi/report.d.ts +94 -0
- package/build/src/library/address.d.ts +12 -5
- package/build/src/library/address.js +18 -32
- package/build/src/library/akuma-creation.d.ts +39 -0
- package/build/src/library/akuma-creation.js +3 -9
- package/build/src/library/akumas.d.ts +5 -1
- package/build/src/library/akumas.js +11 -5
- package/build/src/library/continuation.d.ts +10 -0
- package/build/src/library/contract-composition.js +10 -10
- package/build/src/library/contract-creation.js +12 -13
- package/build/src/library/contract-outcomes.d.ts +72 -1
- package/build/src/library/contract-outcomes.js +1 -0
- package/build/src/library/contract-types.d.ts +233 -25
- package/build/src/library/contract-types.js +32 -12
- package/build/src/library/contract-wait.d.ts +212 -0
- package/build/src/library/contract-wait.js +65 -49
- package/build/src/library/delivery.d.ts +25 -0
- package/build/src/library/input.d.ts +8 -26
- package/build/src/library/input.js +17 -12
- package/build/src/library/kei.js +167 -90
- package/build/src/library/keiyaku-attribution.d.ts +1 -1
- package/build/src/library/keiyaku-attribution.js +3 -1
- package/build/src/library/keiyaku-classify.js +8 -4
- package/build/src/library/keiyaku-debt.d.ts +8 -7
- package/build/src/library/keiyaku-debt.js +1 -2
- package/build/src/library/keiyaku-identity.d.ts +4 -3
- package/build/src/library/keiyaku-identity.js +35 -7
- package/build/src/library/keiyaku-verbs.d.ts +974 -1409
- package/build/src/library/keiyaku-verbs.js +154 -161
- package/build/src/library/keiyaku-wait.d.ts +753 -0
- package/build/src/library/keiyaku-wait.js +230 -0
- package/build/src/library/keiyaku.d.ts +3110 -29
- package/build/src/library/keiyaku.js +342 -438
- package/build/src/library/model-tools.d.ts +754 -0
- package/build/src/library/model-tools.js +362 -0
- package/build/src/library/outcome.js +5 -6
- package/build/src/library/refusal.d.ts +25 -1
- package/build/src/library/refusal.js +4 -5
- package/build/src/library/selection.d.ts +18 -5
- package/build/src/library/selection.js +11 -5
- package/build/src/mcp/adapter.d.ts +0 -6
- package/build/src/mcp/adapter.js +11 -160
- package/build/src/mcp/description.d.ts +2 -0
- package/build/src/mcp/description.js +2 -0
- package/build/src/mcp/help.d.ts +1 -1
- package/build/src/mcp/help.js +10 -7
- package/build/src/pi/index.d.ts +5 -0
- package/build/src/pi/index.js +99 -0
- package/build/src/pi/status.d.ts +12 -0
- package/build/src/pi/status.js +140 -0
- package/build/src/protocol/amend.d.ts +14 -3
- package/build/src/protocol/amend.js +113 -46
- package/build/src/protocol/bind.d.ts +1 -1
- package/build/src/protocol/bind.js +5 -16
- package/build/src/protocol/completion.d.ts +30 -0
- package/build/src/protocol/completion.js +8 -5
- package/build/src/protocol/deliver.js +7 -20
- package/build/src/protocol/delivery-preview.d.ts +5 -0
- package/build/src/protocol/execution-observation.d.ts +8 -0
- package/build/src/protocol/intent.d.ts +1 -0
- package/build/src/protocol/intent.js +4 -1
- package/build/src/protocol/operations.d.ts +56 -16
- package/build/src/protocol/operations.js +18 -32
- package/build/src/protocol/placement.js +7 -1
- package/build/src/protocol/progress.js +0 -6
- package/build/src/protocol/read/status.d.ts +52 -4
- package/build/src/protocol/read/status.js +26 -22
- package/build/src/protocol/reintegrate.js +2 -2
- package/build/src/protocol/result-leaves.d.ts +56 -8
- package/build/src/protocol/result-leaves.js +11 -2
- package/build/src/protocol/run.js +1 -4
- package/build/src/protocol/verify.d.ts +10 -0
- package/build/src/protocol/verify.js +1 -0
- package/build/src/runtime/proc/windows-launch.exe +0 -0
- package/build/src/settlement/settle.js +19 -68
- package/package.json +7 -3
- package/plugins/paseo/plugin/index.server.ts +6 -2
- package/plugins/paseo/plugin/server/attach.ts +68 -48
- package/plugins/paseo/plugin/server/directory.ts +259 -0
- package/plugins/paseo/plugin/server/mirror-identity.ts +3 -32
- package/plugins/paseo/plugin/server/reopen.ts +52 -38
- package/plugins/pi/README.md +55 -97
- package/plugins/pi/keiyaku.ts +1 -142
- package/skills/keiyaku-akuma/SKILL.md +18 -11
- package/skills/keiyaku-babysit/SKILL.md +8 -6
- package/skills/keiyaku-debt/SKILL.md +2 -1
- package/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/pi/akuma-tools.ts +0 -283
- package/build/src/body/keys.d.ts +0 -4
- package/build/src/body/keys.js +0 -11
- package/build/src/kanshi/roster.d.ts +0 -2
- package/build/src/kanshi/roster.js +0 -2
- package/build/src/mcp/output.d.ts +0 -385
- package/build/src/mcp/output.js +0 -193
- package/plugins/pi/akuma-tools.ts +0 -283
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** @architectureCompositionRoot */
|
|
2
2
|
import { isAbsolute, resolve } from "node:path";
|
|
3
|
+
import { requireOwner } from "@astrosheep/square";
|
|
3
4
|
import { parseDuration } from "../duration.js";
|
|
4
5
|
import { ZodError } from "zod";
|
|
5
6
|
import { verbs, } from "./keiyaku-verbs.js";
|
|
@@ -8,6 +9,8 @@ import { World, WorldError } from "../world.js";
|
|
|
8
9
|
import { Akuma } from "../akuma/akuma-instance.js";
|
|
9
10
|
import { Kanshi } from "../kanshi/index.js";
|
|
10
11
|
import { Akumas } from "./akumas.js";
|
|
12
|
+
import { observeNamedAddress, resolveNamedAddress } from "./address.js";
|
|
13
|
+
import { waitInvocation } from "./keiyaku-wait.js";
|
|
11
14
|
import { deliveryOwner } from "./keiyaku-attribution.js";
|
|
12
15
|
import { akumaCallerFromEnvironment } from "./keiyaku-identity.js";
|
|
13
16
|
import { contractId } from "../core/facts/types.js";
|
|
@@ -21,19 +24,43 @@ import { nukeKeiyaku } from "./nuke.js";
|
|
|
21
24
|
import * as debt from "./keiyaku-debt.js";
|
|
22
25
|
import { validateAkumaName } from "../identity/normalize.js";
|
|
23
26
|
export { KeiyakuArcDocumentError, KeiyakuUsageError } from "./keiyaku-coordinates.js";
|
|
24
|
-
function
|
|
25
|
-
|
|
27
|
+
function executionSignal(controls) {
|
|
28
|
+
return controls.signal === undefined ? {} : { signal: controls.signal };
|
|
29
|
+
}
|
|
30
|
+
function mutationProgress(controls) {
|
|
31
|
+
return controls.observe === undefined ? undefined : { observe: controls.observe };
|
|
32
|
+
}
|
|
33
|
+
function observationTimeout(timeout) {
|
|
34
|
+
const duration = parseDuration(timeout);
|
|
26
35
|
if (duration.kind !== "parsed")
|
|
27
|
-
throw new KeiyakuUsageError("invalid
|
|
36
|
+
throw new KeiyakuUsageError("invalid timeout duration");
|
|
28
37
|
return duration.milliseconds;
|
|
29
38
|
}
|
|
30
39
|
export class Keiyaku {
|
|
31
40
|
static verbs = verbs;
|
|
32
41
|
#input;
|
|
33
42
|
constructor(input) {
|
|
34
|
-
|
|
43
|
+
let owner;
|
|
44
|
+
const identity = input.identity;
|
|
45
|
+
if (identity !== undefined) {
|
|
46
|
+
try {
|
|
47
|
+
if (typeof identity !== "object" || identity === null || Array.isArray(identity))
|
|
48
|
+
throw new Error("identity must be an object");
|
|
49
|
+
owner = requireOwner(identity.owner);
|
|
50
|
+
if (!owner.trim())
|
|
51
|
+
throw new Error("owner must be nonblank");
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
throw new KeiyakuUsageError(`invalid identity: ${error instanceof Error ? error.message : String(error)}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
this.#input = {
|
|
58
|
+
...input,
|
|
59
|
+
environment: { ...input.environment },
|
|
60
|
+
...(owner === undefined ? {} : { identity: { owner } }),
|
|
61
|
+
};
|
|
35
62
|
}
|
|
36
|
-
static
|
|
63
|
+
static for(input) {
|
|
37
64
|
if (typeof input?.cwd !== "string" || !isAbsolute(input.cwd))
|
|
38
65
|
throw new KeiyakuUsageError("cwd must be an absolute string");
|
|
39
66
|
if (typeof input.environment !== "object" ||
|
|
@@ -69,214 +96,312 @@ export class Keiyaku {
|
|
|
69
96
|
/* Observation cannot affect execution. */
|
|
70
97
|
}
|
|
71
98
|
};
|
|
72
|
-
return
|
|
99
|
+
return this.#execute[name](parsed, {
|
|
100
|
+
...executionSignal(run ?? {}),
|
|
101
|
+
...(observe === undefined ? {} : { observe: notify }),
|
|
102
|
+
});
|
|
73
103
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return this.#whoami();
|
|
107
|
-
case "settings":
|
|
108
|
-
return this.#settings();
|
|
109
|
-
case "nuke":
|
|
110
|
-
return this.#nuke(request.input);
|
|
111
|
-
case "kanshi": {
|
|
112
|
-
const at = await this.#coordinates("optional");
|
|
113
|
-
return Kanshi.of({ world: at.world, ...(at.repo === undefined ? {} : { repo: at.repo }) }).board();
|
|
104
|
+
#execute = {
|
|
105
|
+
bind: async (input) => {
|
|
106
|
+
const { library } = await this.#keis();
|
|
107
|
+
if ("forkOf" in input)
|
|
108
|
+
return await library.bind({
|
|
109
|
+
...input,
|
|
110
|
+
forkOf: this.#fullId(library, input.forkOf),
|
|
111
|
+
});
|
|
112
|
+
const { after, ...rest } = input;
|
|
113
|
+
return await library.bind({
|
|
114
|
+
...rest,
|
|
115
|
+
...(after === undefined ? {} : { after: after.map((id) => this.#fullId(library, id)) }),
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
amend: async ({ contract, ...input }) => {
|
|
119
|
+
const { cwd, library } = await this.#keis();
|
|
120
|
+
const id = await this.#resolve(library, contract, cwd);
|
|
121
|
+
const { after, ...rest } = input;
|
|
122
|
+
return await library.kei({ id }).amend({
|
|
123
|
+
...rest,
|
|
124
|
+
...(after === undefined ? {} : { after: after.map((value) => this.#fullId(library, value)) }),
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
arc: async ({ contract, ...input }) => {
|
|
128
|
+
const selected = await this.#selected(contract);
|
|
129
|
+
try {
|
|
130
|
+
validateArcMarkdown(input.body);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (errorCategory(error) === "invalid-input")
|
|
134
|
+
throw new KeiyakuArcDocumentError(selected.id, error);
|
|
135
|
+
throw error;
|
|
114
136
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
137
|
+
return await selected.contract.arc(input);
|
|
138
|
+
},
|
|
139
|
+
deliver: async ({ contract, ...input }, controls) => {
|
|
140
|
+
const selected = (await this.#selected(contract)).contract;
|
|
141
|
+
const { dryRun, ...native } = input;
|
|
142
|
+
return dryRun
|
|
143
|
+
? await selected.previewDelivery({ ...native, ...executionSignal(controls) }, mutationProgress(controls))
|
|
144
|
+
: await selected.deliver({ ...native, ...executionSignal(controls) }, mutationProgress(controls));
|
|
145
|
+
},
|
|
146
|
+
verify: async ({ contract, ...input }, controls) => {
|
|
147
|
+
return await (await this.#selected(contract)).contract.verify({ ...input, ...executionSignal(controls) }, mutationProgress(controls));
|
|
148
|
+
},
|
|
149
|
+
review: async ({ contract, ...input }, controls) => {
|
|
150
|
+
const selected = await this.#selected(contract);
|
|
151
|
+
return await selected.contract.review({ ...input, ...executionSignal(controls) }, mutationProgress(controls));
|
|
152
|
+
},
|
|
153
|
+
abandon: async ({ contract, ...input }) => {
|
|
154
|
+
const selected = await this.#selected(contract);
|
|
155
|
+
return await selected.contract.abandon(input);
|
|
156
|
+
},
|
|
157
|
+
show: async ({ selector }) => {
|
|
158
|
+
if (selector.startsWith("debt/"))
|
|
159
|
+
return debt.debtShow(this.#input, selector);
|
|
160
|
+
return await (await this.#selected(selector)).contract.guidance();
|
|
161
|
+
},
|
|
162
|
+
reconcile: async (input) => {
|
|
163
|
+
const { cwd, library } = await this.#keis();
|
|
164
|
+
if (input.contract === undefined)
|
|
165
|
+
return await library.reconcile(input);
|
|
166
|
+
const id = await this.#resolve(library, input.contract, cwd);
|
|
167
|
+
return await library.reconcile({ ...input, contract: id });
|
|
168
|
+
},
|
|
169
|
+
spawn: async ({ prompt, contract, workdir, alias, ...input }, controls) => {
|
|
170
|
+
const at = await this.#coordinates(contract === undefined ? "none" : "required");
|
|
171
|
+
const cwd = workdir === undefined
|
|
172
|
+
? at.cwd
|
|
173
|
+
: await canonicalBirthCwd(resolve(at.cwd, workdir), `workdir is not an existing directory: ${workdir}`);
|
|
174
|
+
const caller = await this.#caller();
|
|
175
|
+
const initiator = deliveryOwner(this.#input.environment, this.#input.identity?.owner);
|
|
176
|
+
const world = at.candidateWorld ?? (await at.establishWorld());
|
|
177
|
+
await World.at(world);
|
|
178
|
+
const configuration = await Settings.load({
|
|
179
|
+
cwd: world,
|
|
180
|
+
...(this.#input.home === undefined ? {} : { home: this.#input.home }),
|
|
181
|
+
});
|
|
182
|
+
const selected = contract === undefined ? undefined : Keis.of(at.repo).kei({ id: this.#fullId(Keis.of(at.repo), contract) });
|
|
183
|
+
return await Akumas.of(world).spawn({
|
|
184
|
+
...input,
|
|
185
|
+
...executionSignal(controls),
|
|
186
|
+
cwd,
|
|
187
|
+
settings: configuration,
|
|
188
|
+
...(alias === undefined ? {} : { alias: alias }),
|
|
189
|
+
...(this.#input.home === undefined ? {} : { home: this.#input.home }),
|
|
190
|
+
...(prompt === undefined ? {} : { body: prompt }),
|
|
191
|
+
...(selected === undefined ? {} : { contract: selected }),
|
|
192
|
+
...(caller === undefined ? {} : { caller }),
|
|
193
|
+
...(initiator === undefined ? {} : { initiator }),
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
fork: async (input) => {
|
|
197
|
+
const { at, akumas } = await this.#akumas();
|
|
198
|
+
const caller = await this.#caller();
|
|
199
|
+
const initiator = deliveryOwner(this.#input.environment, this.#input.identity?.owner);
|
|
200
|
+
return await akumas.fork({
|
|
201
|
+
...input,
|
|
202
|
+
...(at.repo === undefined ? {} : { repo: at.repo }),
|
|
203
|
+
...(caller === undefined ? {} : { caller }),
|
|
204
|
+
...(initiator === undefined ? {} : { initiator }),
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
tell: (input, controls) => this.#tell({ name: "tell", input }, executionSignal(controls)),
|
|
208
|
+
ask: (input, controls) => this.#tell({ name: "ask", input }, {
|
|
209
|
+
...executionSignal(controls),
|
|
210
|
+
...(controls.observe === undefined
|
|
211
|
+
? {}
|
|
212
|
+
: {
|
|
213
|
+
observe: {
|
|
214
|
+
admitted: (tell, id) => controls.observe?.({ kind: "admitted", tell, id }),
|
|
215
|
+
observe: (observation) => controls.observe?.({ kind: "live", observation }),
|
|
216
|
+
},
|
|
217
|
+
}),
|
|
218
|
+
}),
|
|
219
|
+
kill: async (input, controls) => {
|
|
220
|
+
const { at, akumas } = await this.#akumas();
|
|
221
|
+
return await akumas.kill({
|
|
222
|
+
...input,
|
|
223
|
+
...executionSignal(controls),
|
|
224
|
+
...(at.repo === undefined ? {} : { repo: at.repo }),
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
wait: async ({ selectors, timeout, ...input }, controls) => {
|
|
228
|
+
const hasContracts = selectors.some((selector) => selector.startsWith("kei/"));
|
|
229
|
+
const contractOnly = selectors.every((selector) => selector.startsWith("kei/"));
|
|
230
|
+
const at = await this.#coordinates(hasContracts ? "required" : "optional", contractOnly);
|
|
231
|
+
if (hasContracts && at.repo === undefined)
|
|
232
|
+
throw new KeiyakuUsageError("Contract wait requires a repository");
|
|
233
|
+
if (!contractOnly && at.world === null)
|
|
234
|
+
throw new KeiyakuUsageError("Akuma wait requires a World");
|
|
235
|
+
return await waitInvocation({
|
|
236
|
+
selectors,
|
|
237
|
+
...input,
|
|
238
|
+
...executionSignal(controls),
|
|
239
|
+
...(at.repo === undefined ? {} : { repo: at.repo }),
|
|
240
|
+
...(at.world === null ? {} : { world: at.world }),
|
|
241
|
+
...(timeout === undefined ? {} : { timeoutMs: observationTimeout(timeout) }),
|
|
242
|
+
});
|
|
243
|
+
},
|
|
244
|
+
history: async ({ selector, ...input }) => {
|
|
245
|
+
if (selector.startsWith("kei/")) {
|
|
246
|
+
const at = await this.#coordinates("required");
|
|
125
247
|
if (at.repo === undefined)
|
|
126
248
|
throw new KeiyakuUsageError("this command requires a resolved Repo");
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
throw new Error("Contract observation with a Repo cannot be absent");
|
|
130
|
-
return report;
|
|
249
|
+
const library = Keis.of(at.repo);
|
|
250
|
+
return await library.kei({ id: this.#fullId(library, selector) }).history(input);
|
|
131
251
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
252
|
+
const { at, akumas } = await this.#akumas();
|
|
253
|
+
return await akumas.history({
|
|
254
|
+
akuma: selector,
|
|
255
|
+
...("item" in input ? (input.item === "answer" ? { last: true } : { id: input.item }) : input),
|
|
256
|
+
...(at.repo === undefined ? {} : { repo: at.repo }),
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
report: async (input, controls) => {
|
|
260
|
+
await this.#coordinates("none");
|
|
261
|
+
let caller;
|
|
262
|
+
try {
|
|
263
|
+
caller = await this.#caller();
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
if (error instanceof WorldError)
|
|
267
|
+
throw new KeiyakuUsageError(error.message);
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
if (caller?.kind !== "akuma")
|
|
271
|
+
throw new KeiyakuUsageError(this.#input.identity === undefined
|
|
272
|
+
? "report requires explicit KEIYAKU_ACTOR_ID and KEIYAKU_ACTOR_WORLD"
|
|
273
|
+
: "report requires explicit Akuma execution identity");
|
|
274
|
+
return Akuma.select(caller.world, caller.akumaId).report(input.text, executionSignal(controls));
|
|
275
|
+
},
|
|
276
|
+
whoami: async () => {
|
|
277
|
+
return await whoami(await this.#coordinates("optional"), this.#input.environment, this.#input.identity?.owner);
|
|
278
|
+
},
|
|
279
|
+
settings: async () => {
|
|
280
|
+
const at = await this.#coordinates("none");
|
|
281
|
+
return await Settings.load({
|
|
282
|
+
...(at.world === null ? {} : { cwd: at.world }),
|
|
283
|
+
...(this.#input.home === undefined ? {} : { home: this.#input.home }),
|
|
284
|
+
});
|
|
285
|
+
},
|
|
286
|
+
nuke: async (input) => {
|
|
287
|
+
const at = await this.#coordinates("none");
|
|
288
|
+
if (at.world === null)
|
|
289
|
+
throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
|
|
290
|
+
return await nukeKeiyaku({ world: at.world, ...input });
|
|
291
|
+
},
|
|
292
|
+
kanshi: async () => {
|
|
293
|
+
const at = await this.#coordinates("optional");
|
|
294
|
+
return Kanshi.of({ world: at.world, ...(at.repo === undefined ? {} : { repo: at.repo }) }).board();
|
|
295
|
+
},
|
|
296
|
+
status: async (input) => {
|
|
297
|
+
const at = await this.#coordinates("optional");
|
|
298
|
+
const selector = input.selector;
|
|
299
|
+
const id = selector.startsWith("@")
|
|
300
|
+
? resolveNamedAddress({
|
|
301
|
+
selector,
|
|
302
|
+
...(await observeNamedAddress({ world: at.world, repo: at.repo ?? null, selectors: [selector] })),
|
|
303
|
+
}).id
|
|
304
|
+
: selector;
|
|
305
|
+
if (id.startsWith("aku/")) {
|
|
306
|
+
if (at.world === null)
|
|
307
|
+
throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
|
|
308
|
+
return Akumas.of(at.world).status({
|
|
309
|
+
akuma: id,
|
|
310
|
+
...(at.repo === undefined ? {} : { repo: at.repo }),
|
|
156
311
|
});
|
|
157
312
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
313
|
+
if (at.repo === undefined)
|
|
314
|
+
throw new KeiyakuUsageError("this command requires a resolved Repo");
|
|
315
|
+
const report = await Kanshi.of({ world: at.world, repo: at.repo }).contract(contractId(id));
|
|
316
|
+
if (report.kind === "contract-absent")
|
|
317
|
+
throw new Error("Contract observation with a Repo cannot be absent");
|
|
318
|
+
return report;
|
|
319
|
+
},
|
|
320
|
+
region: async (input) => {
|
|
321
|
+
const at = await this.#coordinates("required");
|
|
322
|
+
if (at.repo === undefined)
|
|
323
|
+
throw new KeiyakuUsageError("this command requires a resolved Repo");
|
|
324
|
+
const repo = at.repo;
|
|
325
|
+
const selected = input.paths !== undefined
|
|
326
|
+
? { kind: "path", patterns: input.paths }
|
|
327
|
+
: input.contract === undefined
|
|
328
|
+
? { kind: "declarations" }
|
|
329
|
+
: { kind: "contract", contract: await this.#resolve(Keis.of(repo), input.contract, at.cwd) };
|
|
330
|
+
const result = await Kanshi.of({ world: at.world, repo }).region(selected);
|
|
331
|
+
if (result.kind === "absent")
|
|
332
|
+
throw new Error("Region observation with a Repo cannot be absent");
|
|
333
|
+
return result;
|
|
334
|
+
},
|
|
335
|
+
ls: async (input) => {
|
|
336
|
+
const bound = input.limit === undefined ? {} : { limit: input.limit };
|
|
337
|
+
const lifecycle = input.lifecycle === undefined ? {} : { selection: input.lifecycle };
|
|
338
|
+
if (input.selector === "kei" || input.selector === "kei/") {
|
|
339
|
+
const at = await this.#coordinates("required");
|
|
340
|
+
return Keis.of(at.repo).list({ ...bound, ...lifecycle });
|
|
341
|
+
}
|
|
342
|
+
if (input.selector === "debt" || input.selector === "debt/")
|
|
343
|
+
return debt.debtLs(this.#input, {
|
|
344
|
+
...bound,
|
|
345
|
+
...lifecycle,
|
|
173
346
|
});
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
347
|
+
if (input.selector === "aku" || input.selector === "aku/") {
|
|
348
|
+
const at = await this.#coordinates("none");
|
|
349
|
+
return Akumas.akumaNames({
|
|
350
|
+
...bound,
|
|
351
|
+
...(at.world === null ? {} : { cwd: at.world }),
|
|
352
|
+
...(this.#input.home === undefined ? {} : { home: this.#input.home }),
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
const name = input.selector.split("/")[1];
|
|
356
|
+
const akumaName = name === "*" ? undefined : validateAkumaName(name);
|
|
357
|
+
const { at, akumas } = await this.#akumas();
|
|
358
|
+
const caller = await this.#resolveLsCaller(input.mine);
|
|
359
|
+
return akumas.list({
|
|
360
|
+
...bound,
|
|
361
|
+
...lifecycle,
|
|
362
|
+
...(akumaName === undefined ? {} : { akumaName }),
|
|
363
|
+
...(caller === undefined ? {} : { caller }),
|
|
364
|
+
...(at.repo === undefined ? {} : { repo: at.repo }),
|
|
365
|
+
});
|
|
366
|
+
},
|
|
367
|
+
"debt.add": (input, controls) => debt.debtAdd(this.#input, { ...input, ...executionSignal(controls) }, false),
|
|
368
|
+
"debt.addDocument": (input, controls) => debt.debtAdd(this.#input, { ...input, ...executionSignal(controls) }, true),
|
|
369
|
+
"debt.update": (input, controls) => debt.debtUpdate(this.#input, { ...input, ...executionSignal(controls) }),
|
|
370
|
+
"debt.doctor": () => debt.debtDoctor(this.#input),
|
|
371
|
+
};
|
|
196
372
|
bind(input, run) {
|
|
197
373
|
// Generic output describes the wire form; the same execution retains the native handle.
|
|
198
374
|
return this.run("bind", input, run);
|
|
199
375
|
}
|
|
200
|
-
amend(
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return this.run(
|
|
229
|
-
}
|
|
230
|
-
tell(input, run) {
|
|
231
|
-
return this.run("tell", input, run);
|
|
232
|
-
}
|
|
233
|
-
ask(input, run) {
|
|
234
|
-
return this.run("ask", input, run);
|
|
235
|
-
}
|
|
236
|
-
kill(input, run) {
|
|
237
|
-
return this.run("kill", input, run);
|
|
238
|
-
}
|
|
239
|
-
wait(input, run) {
|
|
240
|
-
return this.run("wait", input, run);
|
|
241
|
-
}
|
|
242
|
-
history(input, run) {
|
|
243
|
-
return this.run("history", input, run);
|
|
244
|
-
}
|
|
245
|
-
report(input, run) {
|
|
246
|
-
return this.run("report", input, run);
|
|
247
|
-
}
|
|
248
|
-
ls(input, run) {
|
|
249
|
-
return this.run("ls", input, run);
|
|
250
|
-
}
|
|
251
|
-
debtAdd(input, run) {
|
|
252
|
-
return this.run("debt.add", input, run);
|
|
253
|
-
}
|
|
254
|
-
debtAddDocument(input, run) {
|
|
255
|
-
return this.run("debt.addDocument", input, run);
|
|
256
|
-
}
|
|
257
|
-
debtUpdate(input, run) {
|
|
258
|
-
return this.run("debt.update", input, run);
|
|
259
|
-
}
|
|
260
|
-
debtDoctor(input = {}, run) {
|
|
261
|
-
return this.run("debt.doctor", input, run);
|
|
262
|
-
}
|
|
263
|
-
kanshi(input = {}, run) {
|
|
264
|
-
return this.run("kanshi", input, run);
|
|
265
|
-
}
|
|
266
|
-
status(input, run) {
|
|
267
|
-
return this.run("status", input, run);
|
|
268
|
-
}
|
|
269
|
-
region(input = {}, run) {
|
|
270
|
-
return this.run("region", input, run);
|
|
271
|
-
}
|
|
272
|
-
whoami(input = {}, run) {
|
|
273
|
-
return this.run("whoami", input, run);
|
|
274
|
-
}
|
|
275
|
-
settings(input = {}, run) {
|
|
276
|
-
return this.run("settings", input, run);
|
|
277
|
-
}
|
|
278
|
-
nuke(input = {}, run) {
|
|
279
|
-
return this.run("nuke", input, run);
|
|
376
|
+
amend = this.#verb("amend", {});
|
|
377
|
+
arc = this.#verb("arc");
|
|
378
|
+
deliver = this.#verb("deliver", {});
|
|
379
|
+
verify = this.#verb("verify", {});
|
|
380
|
+
review = this.#verb("review");
|
|
381
|
+
abandon = this.#verb("abandon", {});
|
|
382
|
+
show = this.#verb("show");
|
|
383
|
+
reconcile = this.#verb("reconcile", {});
|
|
384
|
+
spawn = this.#verb("spawn");
|
|
385
|
+
fork = this.#verb("fork");
|
|
386
|
+
tell = this.#verb("tell");
|
|
387
|
+
ask = this.#verb("ask");
|
|
388
|
+
kill = this.#verb("kill");
|
|
389
|
+
wait = this.#verb("wait");
|
|
390
|
+
history = this.#verb("history");
|
|
391
|
+
report = this.#verb("report");
|
|
392
|
+
ls = this.#verb("ls");
|
|
393
|
+
debtAdd = this.#verb("debt.add");
|
|
394
|
+
debtAddDocument = this.#verb("debt.addDocument");
|
|
395
|
+
debtUpdate = this.#verb("debt.update");
|
|
396
|
+
debtDoctor = this.#verb("debt.doctor", {});
|
|
397
|
+
kanshi = this.#verb("kanshi", {});
|
|
398
|
+
status = this.#verb("status");
|
|
399
|
+
region = this.#verb("region", {});
|
|
400
|
+
whoami = this.#verb("whoami", {});
|
|
401
|
+
settings = this.#verb("settings", {});
|
|
402
|
+
nuke = this.#verb("nuke", {});
|
|
403
|
+
#verb(name, empty) {
|
|
404
|
+
return (input = empty, run) => this.run(name, input, run);
|
|
280
405
|
}
|
|
281
406
|
#coordinates(use, contractWait = false) {
|
|
282
407
|
return invocationCoordinates({ ...this.#input, use, contractWait });
|
|
@@ -328,109 +453,8 @@ export class Keiyaku {
|
|
|
328
453
|
const id = await this.#resolve(library, selector, cwd);
|
|
329
454
|
return { id, contract: library.kei({ id }) };
|
|
330
455
|
}
|
|
331
|
-
async #bind(input) {
|
|
332
|
-
const { library } = await this.#keis();
|
|
333
|
-
if ("forkOf" in input)
|
|
334
|
-
return await library.bind({
|
|
335
|
-
...input,
|
|
336
|
-
forkOf: this.#fullId(library, input.forkOf),
|
|
337
|
-
});
|
|
338
|
-
const { after, ...rest } = input;
|
|
339
|
-
return await library.bind({
|
|
340
|
-
...rest,
|
|
341
|
-
...(after === undefined ? {} : { after: after.map((id) => this.#fullId(library, id)) }),
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
async #amend({ contract, ...input }) {
|
|
345
|
-
const { cwd, library } = await this.#keis();
|
|
346
|
-
const id = await this.#resolve(library, contract, cwd);
|
|
347
|
-
const { after, ...rest } = input;
|
|
348
|
-
return await library.kei({ id }).amend({
|
|
349
|
-
...rest,
|
|
350
|
-
...(after === undefined ? {} : { after: after.map((value) => this.#fullId(library, value)) }),
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
async #arc({ contract, ...input }) {
|
|
354
|
-
const selected = await this.#selected(contract);
|
|
355
|
-
try {
|
|
356
|
-
validateArcMarkdown(input.markdown);
|
|
357
|
-
}
|
|
358
|
-
catch (error) {
|
|
359
|
-
if (errorCategory(error) === "invalid-input")
|
|
360
|
-
throw new KeiyakuArcDocumentError(selected.id, error);
|
|
361
|
-
throw error;
|
|
362
|
-
}
|
|
363
|
-
return await selected.contract.arc(input);
|
|
364
|
-
}
|
|
365
|
-
async #deliver({ contract, ...input }, progress) {
|
|
366
|
-
const selected = (await this.#selected(contract)).contract;
|
|
367
|
-
const { dryRun, ...native } = input;
|
|
368
|
-
return dryRun ? await selected.previewDelivery(native, progress) : await selected.deliver(native, progress);
|
|
369
|
-
}
|
|
370
|
-
async #verify({ contract, ...input }, progress) {
|
|
371
|
-
return await (await this.#selected(contract)).contract.verify(input, progress);
|
|
372
|
-
}
|
|
373
|
-
async #review({ contract, ...input }, progress) {
|
|
374
|
-
const selected = await this.#selected(contract);
|
|
375
|
-
return await selected.contract.review(input, progress);
|
|
376
|
-
}
|
|
377
|
-
async #abandon({ contract, ...input }) {
|
|
378
|
-
const selected = await this.#selected(contract);
|
|
379
|
-
return await selected.contract.abandon(input);
|
|
380
|
-
}
|
|
381
|
-
async #show({ id }) {
|
|
382
|
-
if (id?.startsWith("debt/") === true)
|
|
383
|
-
return debt.debtShow(this.#input, id);
|
|
384
|
-
return await (await this.#selected(id)).contract.guidance();
|
|
385
|
-
}
|
|
386
|
-
async #reconcile(input) {
|
|
387
|
-
const { cwd, library } = await this.#keis();
|
|
388
|
-
if (input.contract === undefined)
|
|
389
|
-
return await library.reconcile(input);
|
|
390
|
-
const id = await this.#resolve(library, input.contract, cwd);
|
|
391
|
-
return await library.reconcile({ ...input, contract: id });
|
|
392
|
-
}
|
|
393
|
-
async #spawn({ prompt, wait, contract, workdir, alias, observe, ...input }) {
|
|
394
|
-
const at = await this.#coordinates(contract === undefined ? "none" : "required");
|
|
395
|
-
const cwd = workdir === undefined
|
|
396
|
-
? at.cwd
|
|
397
|
-
: await canonicalBirthCwd(resolve(at.cwd, workdir), `workdir is not an existing directory: ${workdir}`);
|
|
398
|
-
const caller = await this.#caller();
|
|
399
|
-
const initiator = deliveryOwner(this.#input.environment);
|
|
400
|
-
const world = at.candidateWorld ?? (await at.establishWorld());
|
|
401
|
-
await World.at(world);
|
|
402
|
-
const configuration = await Settings.load({
|
|
403
|
-
cwd: world,
|
|
404
|
-
...(this.#input.home === undefined ? {} : { home: this.#input.home }),
|
|
405
|
-
});
|
|
406
|
-
const selected = contract === undefined ? undefined : Keis.of(at.repo).kei({ id: this.#fullId(Keis.of(at.repo), contract) });
|
|
407
|
-
return await Akumas.of(world).spawn({
|
|
408
|
-
...input,
|
|
409
|
-
...(wait === undefined ? {} : { mode: "wait", timeoutMs: waitTimeout(wait) }),
|
|
410
|
-
cwd,
|
|
411
|
-
settings: configuration,
|
|
412
|
-
...(alias === undefined ? {} : { alias: alias }),
|
|
413
|
-
...(this.#input.home === undefined ? {} : { home: this.#input.home }),
|
|
414
|
-
...(prompt === undefined ? {} : { body: prompt }),
|
|
415
|
-
...(selected === undefined ? {} : { contract: selected }),
|
|
416
|
-
...(caller === undefined ? {} : { caller }),
|
|
417
|
-
...(initiator === undefined ? {} : { initiator }),
|
|
418
|
-
...(observe === undefined
|
|
419
|
-
? {}
|
|
420
|
-
: {
|
|
421
|
-
observe: {
|
|
422
|
-
...(observe.observe === undefined ? {} : { observe: observe.observe }),
|
|
423
|
-
...(observe.admitted === undefined
|
|
424
|
-
? {}
|
|
425
|
-
: {
|
|
426
|
-
admitted: (tell, id, head) => observe.admitted(tell, id, { ...head, cwd }),
|
|
427
|
-
}),
|
|
428
|
-
},
|
|
429
|
-
}),
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
456
|
#caller() {
|
|
433
|
-
return akumaCallerFromEnvironment(this.#input.environment);
|
|
457
|
+
return akumaCallerFromEnvironment(this.#input.environment, this.#input.identity?.owner);
|
|
434
458
|
}
|
|
435
459
|
async #akumas(use = "optional") {
|
|
436
460
|
const at = await this.#coordinates(use);
|
|
@@ -438,83 +462,32 @@ export class Keiyaku {
|
|
|
438
462
|
throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
|
|
439
463
|
return { at, akumas: Akumas.of(at.world) };
|
|
440
464
|
}
|
|
441
|
-
async #
|
|
442
|
-
const { at, akumas } = await this.#akumas();
|
|
443
|
-
const caller = await this.#caller();
|
|
444
|
-
const initiator = deliveryOwner(this.#input.environment);
|
|
445
|
-
return await akumas.fork({
|
|
446
|
-
...input,
|
|
447
|
-
...(at.repo === undefined ? {} : { repo: at.repo }),
|
|
448
|
-
...(caller === undefined ? {} : { caller }),
|
|
449
|
-
...(initiator === undefined ? {} : { initiator }),
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
async #tell({ prompt, ...input }) {
|
|
465
|
+
async #tell(request, controls) {
|
|
453
466
|
const { at, akumas } = await this.#akumas();
|
|
454
|
-
const initiator = deliveryOwner(this.#input.environment);
|
|
455
|
-
const
|
|
456
|
-
...
|
|
457
|
-
body: prompt,
|
|
467
|
+
const initiator = deliveryOwner(this.#input.environment, this.#input.identity?.owner);
|
|
468
|
+
const common = {
|
|
469
|
+
...controls,
|
|
470
|
+
body: request.input.prompt,
|
|
458
471
|
...(at.repo === undefined ? {} : { repo: at.repo }),
|
|
459
472
|
...(initiator === undefined ? {} : { initiator }),
|
|
460
473
|
};
|
|
461
|
-
if ("
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
return await akumas.kill({ ...input, ...(at.repo === undefined ? {} : { repo: at.repo }) });
|
|
469
|
-
}
|
|
470
|
-
async #wait({ selectors, ...input }) {
|
|
471
|
-
const contracts = selectors.filter((selector) => selector.startsWith("kei/"));
|
|
472
|
-
if (contracts.length > 0) {
|
|
473
|
-
const at = await this.#coordinates("required", true);
|
|
474
|
-
if (at.repo === undefined)
|
|
475
|
-
throw new KeiyakuUsageError("Contract wait requires a repository");
|
|
476
|
-
return await Keis.of(at.repo).wait({ contracts, ...input });
|
|
477
|
-
}
|
|
478
|
-
const { at, akumas } = await this.#akumas();
|
|
479
|
-
return await akumas.wait({ akuma: selectors, ...input, ...(at.repo === undefined ? {} : { repo: at.repo }) });
|
|
480
|
-
}
|
|
481
|
-
async #history({ selector, ...input }) {
|
|
482
|
-
if (selector.startsWith("kei/")) {
|
|
483
|
-
const at = await this.#coordinates("required");
|
|
484
|
-
if (at.repo === undefined)
|
|
485
|
-
throw new KeiyakuUsageError("this command requires a resolved Repo");
|
|
486
|
-
const library = Keis.of(at.repo);
|
|
487
|
-
return await library
|
|
488
|
-
.kei({ id: this.#fullId(library, selector) })
|
|
489
|
-
.history("full" in input ? { full: input.full } : undefined);
|
|
490
|
-
}
|
|
491
|
-
const { at, akumas } = await this.#akumas();
|
|
492
|
-
return await akumas.history({ akuma: selector, ...input, ...(at.repo === undefined ? {} : { repo: at.repo }) });
|
|
493
|
-
}
|
|
494
|
-
async #report(input) {
|
|
495
|
-
await this.#coordinates("none");
|
|
496
|
-
const environment = this.#input.environment;
|
|
497
|
-
if (environment.KEIYAKU_ACTOR_ID === undefined || environment.KEIYAKU_ACTOR_WORLD === undefined)
|
|
498
|
-
throw new KeiyakuUsageError("report requires explicit KEIYAKU_ACTOR_ID and KEIYAKU_ACTOR_WORLD");
|
|
499
|
-
let caller;
|
|
500
|
-
try {
|
|
501
|
-
caller = await akumaCallerFromEnvironment(environment);
|
|
502
|
-
}
|
|
503
|
-
catch (error) {
|
|
504
|
-
if (error instanceof WorldError)
|
|
505
|
-
throw new KeiyakuUsageError(error.message);
|
|
506
|
-
throw error;
|
|
474
|
+
if (request.name === "ask") {
|
|
475
|
+
const { prompt: _prompt, timeout, ...input } = request.input;
|
|
476
|
+
return akumas.ask({
|
|
477
|
+
...input,
|
|
478
|
+
...common,
|
|
479
|
+
...(timeout === undefined ? {} : { timeoutMs: observationTimeout(timeout) }),
|
|
480
|
+
});
|
|
507
481
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
return Akuma.select(caller.world, caller.akumaId).report(input.text, input.signal === undefined ? {} : { signal: input.signal });
|
|
482
|
+
const { prompt: _prompt, ...input } = request.input;
|
|
483
|
+
return akumas.tell({ ...input, ...common });
|
|
511
484
|
}
|
|
512
485
|
async #resolveLsCaller(mine) {
|
|
513
486
|
if (mine !== true)
|
|
514
487
|
return undefined;
|
|
515
488
|
let caller;
|
|
516
489
|
try {
|
|
517
|
-
caller = await
|
|
490
|
+
caller = await this.#caller();
|
|
518
491
|
}
|
|
519
492
|
catch (error) {
|
|
520
493
|
throw new KeiyakuUsageError(error instanceof Error ? error.message : String(error));
|
|
@@ -524,73 +497,4 @@ export class Keiyaku {
|
|
|
524
497
|
}
|
|
525
498
|
return caller;
|
|
526
499
|
}
|
|
527
|
-
async #ls(input) {
|
|
528
|
-
const bound = input.limit === undefined ? {} : { limit: input.limit };
|
|
529
|
-
if (input.selector === "kei" || input.selector === "kei/") {
|
|
530
|
-
const at = await this.#coordinates("required");
|
|
531
|
-
return Keis.of(at.repo).list(bound);
|
|
532
|
-
}
|
|
533
|
-
if (input.selector === "debt" || input.selector === "debt/")
|
|
534
|
-
return debt.debtLs(this.#input, {
|
|
535
|
-
...bound,
|
|
536
|
-
...("selection" in input && input.selection !== undefined ? { selection: input.selection } : {}),
|
|
537
|
-
});
|
|
538
|
-
if (input.selector === "aku" || input.selector === "aku/") {
|
|
539
|
-
const at = await this.#coordinates("none");
|
|
540
|
-
return Akumas.akumaNames({
|
|
541
|
-
...bound,
|
|
542
|
-
...(at.world === null ? {} : { cwd: at.world }),
|
|
543
|
-
...(this.#input.home === undefined ? {} : { home: this.#input.home }),
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
const name = input.selector.split("/")[1];
|
|
547
|
-
const akumaName = name === "*" ? undefined : validateAkumaName(name);
|
|
548
|
-
const { at, akumas } = await this.#akumas();
|
|
549
|
-
const caller = await this.#resolveLsCaller("mine" in input ? input.mine : undefined);
|
|
550
|
-
return akumas.list({
|
|
551
|
-
...bound,
|
|
552
|
-
...(akumaName === undefined ? {} : { akumaName }),
|
|
553
|
-
...(caller === undefined ? {} : { caller }),
|
|
554
|
-
...(at.repo === undefined ? {} : { repo: at.repo }),
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
async #region(input = {}) {
|
|
558
|
-
const at = await this.#coordinates("required");
|
|
559
|
-
if (at.repo === undefined)
|
|
560
|
-
throw new KeiyakuUsageError("this command requires a resolved Repo");
|
|
561
|
-
const repo = at.repo;
|
|
562
|
-
let selected;
|
|
563
|
-
if (input.paths !== undefined) {
|
|
564
|
-
const [first, ...rest] = input.paths;
|
|
565
|
-
if (first === undefined)
|
|
566
|
-
throw new KeiyakuUsageError("Region query requires one or more path patterns");
|
|
567
|
-
selected = { kind: "path", patterns: [first, ...rest] };
|
|
568
|
-
}
|
|
569
|
-
else {
|
|
570
|
-
selected =
|
|
571
|
-
input.contract === undefined
|
|
572
|
-
? { kind: "declarations" }
|
|
573
|
-
: { kind: "contract", contract: await this.#resolve(Keis.of(repo), input.contract, at.cwd) };
|
|
574
|
-
}
|
|
575
|
-
const result = await Kanshi.of({ world: at.world, repo }).region(selected);
|
|
576
|
-
if (result.kind === "absent")
|
|
577
|
-
throw new Error("Region observation with a Repo cannot be absent");
|
|
578
|
-
return result;
|
|
579
|
-
}
|
|
580
|
-
async #whoami() {
|
|
581
|
-
return await whoami(await this.#coordinates("optional"), this.#input.environment);
|
|
582
|
-
}
|
|
583
|
-
async #settings() {
|
|
584
|
-
const at = await this.#coordinates("none");
|
|
585
|
-
return await Settings.load({
|
|
586
|
-
...(at.world === null ? {} : { cwd: at.world }),
|
|
587
|
-
...(this.#input.home === undefined ? {} : { home: this.#input.home }),
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
async #nuke(input) {
|
|
591
|
-
const at = await this.#coordinates("none");
|
|
592
|
-
if (at.world === null)
|
|
593
|
-
throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
|
|
594
|
-
return await nukeKeiyaku({ world: at.world, ...input });
|
|
595
|
-
}
|
|
596
500
|
}
|