@astrosheep/keiyaku 4.6.31 → 4.6.32
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 +34 -17
- package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +16 -11
- package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +5 -3
- package/build/plugins/claude/skills/keiyaku-bind/SKILL.md +4 -3
- package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +17 -17
- package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +16 -11
- package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +5 -3
- package/build/plugins/codex/skills/keiyaku-bind/SKILL.md +4 -3
- package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +17 -17
- package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +16 -11
- package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +5 -3
- package/build/plugins/opencode/skills/keiyaku-bind/SKILL.md +4 -3
- package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +17 -17
- package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/plugins/pi/README.md +16 -18
- package/build/plugins/pi/akuma-tools.ts +31 -38
- package/build/plugins/pi/keiyaku.ts +15 -4
- package/build/skills/keiyaku-akuma/SKILL.md +16 -11
- package/build/skills/keiyaku-babysit/SKILL.md +5 -3
- package/build/skills/keiyaku-bind/SKILL.md +4 -3
- package/build/skills/keiyaku-debt/SKILL.md +17 -17
- package/build/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/src/akuma/akuma-call.d.ts +3 -5
- package/build/src/akuma/akuma-call.js +7 -10
- package/build/src/akuma/akuma-errors.d.ts +7 -4
- package/build/src/akuma/akuma-errors.js +16 -12
- package/build/src/akuma/akuma-instance.d.ts +39 -303
- package/build/src/akuma/akuma-instance.js +48 -48
- package/build/src/akuma/akuma-observe.d.ts +5 -4
- package/build/src/akuma/akuma-observe.js +1 -7
- package/build/src/akuma/akuma-owner.d.ts +14 -6
- package/build/src/akuma/akuma-owner.js +33 -27
- package/build/src/akuma/akuma-selection-execution.d.ts +22 -19
- package/build/src/akuma/akuma-selection-execution.js +71 -124
- package/build/src/akuma/akuma-wait.d.ts +3 -3
- package/build/src/akuma/akuma.d.ts +47 -384
- package/build/src/akuma/akuma.js +8 -58
- package/build/src/akuma/archetype.d.ts +16 -19
- package/build/src/akuma/archetype.js +48 -49
- package/build/src/akuma/body.js +31 -26
- package/build/src/akuma/call-initial-tell.d.ts +4 -1
- package/build/src/akuma/call-initial-tell.js +9 -1
- package/build/src/akuma/call-input.d.ts +8 -1
- package/build/src/akuma/call-input.js +27 -18
- package/build/src/akuma/caller.js +2 -1
- package/build/src/akuma/detached-body.js +1 -1
- package/build/src/akuma/heart/facts.d.ts +5 -4
- package/build/src/akuma/heart/facts.js +5 -5
- package/build/src/akuma/heart/soul.js +20 -4
- package/build/src/akuma/identity.d.ts +1 -1
- package/build/src/akuma/identity.js +9 -4
- package/build/src/akuma/index.d.ts +6 -7
- package/build/src/akuma/index.js +2 -3
- package/build/src/akuma/projection.d.ts +3 -0
- package/build/src/akuma/provider-recipe.js +3 -2
- package/build/src/akuma/providers/acp/config.js +11 -10
- package/build/src/akuma/providers/acp/index.js +2 -1
- package/build/src/akuma/providers/codex-app-server/index.js +7 -1
- package/build/src/akuma/providers/grok-build/index.js +2 -1
- package/build/src/akuma/providers/index.d.ts +0 -1
- package/build/src/akuma/providers/index.js +0 -8
- package/build/src/akuma/providers/paseo/index.js +7 -4
- package/build/src/akuma/providers/pi/index.js +4 -3
- package/build/src/akuma/publication.d.ts +1 -2
- package/build/src/akuma/publication.js +16 -14
- package/build/src/akuma/schema.d.ts +3 -49
- package/build/src/akuma/schema.js +6 -147
- package/build/src/akuma/selection-observation.d.ts +281 -240
- package/build/src/akuma/selection-observation.js +122 -68
- package/build/src/akuma/status-projection.d.ts +49 -285
- package/build/src/akuma/status-projection.js +178 -138
- package/build/src/body/amend.js +2 -1
- package/build/src/body/arc.js +3 -2
- package/build/src/body/criteria.js +4 -3
- package/build/src/body/decode.js +2 -1
- package/build/src/body/envelope.js +2 -1
- package/build/src/body/region.d.ts +1 -3
- package/build/src/body/region.js +3 -8
- package/build/src/body-host.d.ts +4 -11
- package/build/src/body-host.js +5 -4
- package/build/src/bounded-list.js +2 -1
- package/build/src/cli/commands/akuma-grammar.d.ts +109 -66
- package/build/src/cli/commands/akuma-grammar.js +75 -95
- package/build/src/cli/commands/akuma.d.ts +8 -3
- package/build/src/cli/commands/akuma.js +63 -122
- package/build/src/cli/commands/contract-grammar.d.ts +3 -135
- package/build/src/cli/commands/contract-grammar.js +125 -218
- package/build/src/cli/commands/contract-help.d.ts +24 -21
- package/build/src/cli/commands/contract-help.js +43 -35
- package/build/src/cli/commands/contract.d.ts +6 -18
- package/build/src/cli/commands/contract.js +65 -272
- package/build/src/cli/commands/debt-grammar.d.ts +2 -4
- package/build/src/cli/commands/debt-grammar.js +22 -190
- package/build/src/cli/commands/debt.js +10 -87
- package/build/src/cli/commands/report.d.ts +2 -4
- package/build/src/cli/coordinates.d.ts +1 -1
- package/build/src/cli/coordinates.js +1 -1
- package/build/src/cli/main.js +9 -3
- package/build/src/cli/parse.d.ts +80 -3
- package/build/src/cli/parse.js +76 -16
- package/build/src/cli/render/akuma-activity.d.ts +19 -24
- package/build/src/cli/render/akuma-activity.js +164 -259
- package/build/src/cli/render/akuma.d.ts +3 -3
- package/build/src/cli/render/akuma.js +36 -43
- package/build/src/cli/render/catalog.d.ts +2 -5
- package/build/src/cli/render/catalog.js +2 -33
- package/build/src/cli/render/contract-history.js +1 -2
- package/build/src/cli/render/contract-observation.d.ts +0 -7
- package/build/src/cli/render/contract-observation.js +0 -3
- package/build/src/cli/render/contract.d.ts +7 -9
- package/build/src/cli/render/contract.js +35 -64
- package/build/src/cli/render/debt.d.ts +3 -11
- package/build/src/cli/render/debt.js +17 -88
- package/build/src/cli/render/delivery-preview.js +4 -4
- package/build/src/cli/render/kanshi-akuma.d.ts +5 -3
- package/build/src/cli/render/kanshi-akuma.js +22 -18
- package/build/src/cli/render/kanshi.d.ts +1 -3
- package/build/src/cli/render/kanshi.js +16 -39
- package/build/src/cli/render/receipt.d.ts +21 -12
- package/build/src/cli/render/receipt.js +49 -44
- package/build/src/cli/render/refusal.d.ts +4 -3
- package/build/src/cli/render/refusal.js +15 -17
- package/build/src/cli/render/settings.d.ts +1 -1
- package/build/src/cli/render/terminal.d.ts +9 -8
- package/build/src/cli/render/terminal.js +48 -32
- package/build/src/cli/render/verbs.d.ts +3 -1
- package/build/src/cli/render/verbs.js +74 -116
- package/build/src/cli/runtime.js +66 -65
- package/build/src/cli/streams.d.ts +2 -9
- package/build/src/cli/streams.js +8 -1
- package/build/src/cli/usage.d.ts +2 -1
- package/build/src/cli/usage.js +3 -2
- package/build/src/contract-worktree.js +2 -10
- package/build/src/core/facts/codec.js +9 -23
- package/build/src/core/facts/errors.d.ts +2 -1
- package/build/src/core/facts/errors.js +3 -3
- package/build/src/core/facts/types.d.ts +2 -13
- package/build/src/core/facts/types.js +1 -6
- package/build/src/core/verbs/abandon.d.ts +1 -2
- package/build/src/core/verbs/amend.d.ts +1 -2
- package/build/src/core/verbs/arc.d.ts +1 -2
- package/build/src/core/verbs/attestation.d.ts +1 -2
- package/build/src/core/verbs/bind.d.ts +1 -2
- package/build/src/core/verbs/deliver.d.ts +1 -2
- package/build/src/core/verbs/placement.d.ts +1 -2
- package/build/src/core/verbs/reintegrate.d.ts +1 -2
- package/build/src/debt/board.d.ts +14 -94
- package/build/src/debt/board.js +25 -160
- package/build/src/debt/catalog.d.ts +0 -2
- package/build/src/debt/catalog.js +1 -22
- package/build/src/debt/document.d.ts +8 -11
- package/build/src/debt/document.js +19 -62
- package/build/src/debt/identity.d.ts +2 -14
- package/build/src/debt/identity.js +19 -49
- package/build/src/debt/index.d.ts +81 -219
- package/build/src/debt/index.js +61 -110
- package/build/src/debt/input.d.ts +19 -5
- package/build/src/debt/input.js +51 -177
- package/build/src/debt/lifecycle-operations.d.ts +1 -3
- package/build/src/debt/lifecycle-operations.js +1 -73
- package/build/src/debt/operation-types.d.ts +24 -128
- package/build/src/debt/operation-types.js +6 -62
- package/build/src/debt/operations.d.ts +8 -17
- package/build/src/debt/operations.js +58 -154
- package/build/src/debt/store.d.ts +0 -2
- package/build/src/debt/store.js +32 -87
- package/build/src/errors.d.ts +28 -0
- package/build/src/errors.js +26 -0
- package/build/src/git/hooks.d.ts +1 -1
- package/build/src/git/observe.d.ts +3 -0
- package/build/src/git/observe.js +19 -5
- package/build/src/git/reconcile.d.ts +3 -16
- package/build/src/git/reconcile.js +0 -18
- package/build/src/git/repository.d.ts +2 -1
- package/build/src/git/repository.js +3 -3
- package/build/src/git/target-placement.d.ts +4 -4
- package/build/src/git/target.d.ts +2 -2
- package/build/src/git/tender.d.ts +1 -2
- package/build/src/git/tender.js +5 -12
- package/build/src/identity/coordinates.d.ts +1 -1
- package/build/src/identity/coordinates.js +3 -2
- package/build/src/identity/normalize.js +2 -1
- package/build/src/identity/selector.js +4 -3
- package/build/src/index.d.ts +34 -57
- package/build/src/index.js +11 -36
- package/build/src/kanshi/counts.d.ts +3 -8
- package/build/src/kanshi/counts.js +6 -14
- package/build/src/kanshi/index.d.ts +22 -7
- package/build/src/kanshi/index.js +30 -4
- package/build/src/kanshi/read.d.ts +81 -270
- package/build/src/kanshi/read.js +39 -199
- package/build/src/kanshi/report.d.ts +340 -1619
- package/build/src/kanshi/report.js +19 -31
- package/build/src/library/address.d.ts +11 -11
- package/build/src/library/address.js +34 -27
- package/build/src/library/akuma-creation.d.ts +210 -79
- package/build/src/library/akuma-creation.js +201 -242
- package/build/src/library/akumas.d.ts +24 -5
- package/build/src/library/akumas.js +96 -29
- package/build/src/library/bind.d.ts +7 -10
- package/build/src/library/bind.js +2 -8
- package/build/src/library/continuation.d.ts +141 -231
- package/build/src/library/continuation.js +22 -31
- package/build/src/library/contract-address.d.ts +6 -9
- package/build/src/library/contract-address.js +11 -16
- package/build/src/library/contract-composition.d.ts +2 -3
- package/build/src/library/contract-composition.js +12 -19
- package/build/src/library/contract-creation.js +33 -34
- package/build/src/library/contract-outcomes.d.ts +1278 -806
- package/build/src/library/contract-outcomes.js +11 -37
- package/build/src/library/contract-settings.d.ts +1 -2
- package/build/src/library/contract-settings.js +5 -7
- package/build/src/library/contract-types.d.ts +42 -67
- package/build/src/library/contract-types.js +15 -56
- package/build/src/library/contract-wait.d.ts +40 -3
- package/build/src/library/contract-wait.js +28 -21
- package/build/src/library/delivery.d.ts +366 -389
- package/build/src/library/delivery.js +5 -25
- package/build/src/library/input.d.ts +31 -5
- package/build/src/library/input.js +40 -40
- package/build/src/library/invocation.d.ts +13 -11
- package/build/src/library/invocation.js +69 -58
- package/build/src/library/kei.d.ts +16 -8
- package/build/src/library/kei.js +459 -19
- package/build/src/library/keiyaku-attribution.d.ts +0 -8
- package/build/src/library/keiyaku-attribution.js +0 -11
- package/build/src/library/keiyaku-classify.d.ts +2 -2
- package/build/src/library/keiyaku-classify.js +40 -59
- package/build/src/library/keiyaku-coordinates.d.ts +3 -8
- package/build/src/library/keiyaku-coordinates.js +6 -26
- package/build/src/library/keiyaku-debt.d.ts +21 -93
- package/build/src/library/keiyaku-debt.js +8 -157
- package/build/src/library/keiyaku-identity.js +5 -4
- package/build/src/library/keiyaku-verbs.d.ts +4004 -3885
- package/build/src/library/keiyaku-verbs.js +309 -271
- package/build/src/library/keiyaku.d.ts +30 -860
- package/build/src/library/keiyaku.js +169 -256
- package/build/src/library/nuke.d.ts +4 -2
- package/build/src/library/nuke.js +5 -1
- package/build/src/library/outcome.d.ts +424 -307
- package/build/src/library/outcome.js +167 -362
- package/build/src/library/reconcile.d.ts +331 -143
- package/build/src/library/reconcile.js +38 -72
- package/build/src/library/refusal.d.ts +20 -28
- package/build/src/library/refusal.js +1 -11
- package/build/src/library/repo.js +4 -3
- package/build/src/library/selection.d.ts +32 -21
- package/build/src/library/selection.js +63 -87
- package/build/src/mcp/adapter.d.ts +6 -0
- package/build/src/mcp/adapter.js +177 -42
- package/build/src/mcp/help.d.ts +1 -1
- package/build/src/mcp/help.js +12 -7
- package/build/src/mcp/output.d.ts +385 -0
- package/build/src/mcp/output.js +193 -0
- package/build/src/plugin/public.d.ts +4 -0
- package/build/src/plugin/runtime.d.ts +1 -1
- package/build/src/plugin/runtime.js +2 -2
- package/build/src/protocol/amend.d.ts +1 -1
- package/build/src/protocol/amend.js +2 -2
- package/build/src/protocol/bind.d.ts +5 -7
- package/build/src/protocol/bind.js +3 -3
- package/build/src/protocol/completion.d.ts +158 -195
- package/build/src/protocol/completion.js +55 -19
- package/build/src/protocol/deliver.d.ts +11 -6
- package/build/src/protocol/deliver.js +30 -30
- package/build/src/protocol/delivery-preview.d.ts +13 -11
- package/build/src/protocol/delivery-preview.js +2 -2
- package/build/src/protocol/execution-observation.d.ts +5 -13
- package/build/src/protocol/intent.d.ts +6 -9
- package/build/src/protocol/intent.js +18 -31
- package/build/src/protocol/operations.d.ts +48 -53
- package/build/src/protocol/operations.js +16 -25
- package/build/src/protocol/outcome.d.ts +3 -1
- package/build/src/protocol/placement.d.ts +1 -2
- package/build/src/protocol/placement.js +1 -1
- package/build/src/protocol/progress.d.ts +1 -0
- package/build/src/protocol/read/status.d.ts +29 -112
- package/build/src/protocol/read/status.js +52 -78
- package/build/src/protocol/reintegrate.d.ts +1 -2
- package/build/src/protocol/reintegrate.js +0 -1
- package/build/src/protocol/result-leaves.d.ts +11 -32
- package/build/src/protocol/result-leaves.js +18 -57
- package/build/src/protocol/result-reasons.d.ts +6 -6
- package/build/src/protocol/review.js +0 -1
- package/build/src/protocol/verify.d.ts +192 -146
- package/build/src/protocol/verify.js +60 -47
- package/build/src/runtime/proc/windows-launch.exe +0 -0
- package/build/src/settings.d.ts +8 -9
- package/build/src/settings.js +16 -13
- package/build/src/settlement/holder.js +2 -2
- package/build/src/settlement/settle.d.ts +0 -6
- package/build/src/settlement/settle.js +0 -4
- package/build/src/verification/declaration.d.ts +3 -6
- package/build/src/verification/declaration.js +3 -5
- package/build/src/verification/observation.d.ts +2 -2
- package/build/src/world.d.ts +3 -2
- package/build/src/world.js +5 -6
- package/package.json +1 -1
- package/plugins/paseo/plugin/index.server.ts +1 -1
- package/plugins/paseo/plugin/server/attach.ts +74 -67
- package/plugins/paseo/plugin/server/keiyaku.ts +80 -14
- package/plugins/paseo/plugin/server/message.ts +2 -1
- package/plugins/paseo/plugin/server/mirror-identity.ts +6 -4
- package/plugins/paseo/plugin/server/sdk.ts +9 -11
- package/plugins/paseo/plugin/server/transport.ts +24 -1
- package/plugins/pi/README.md +16 -18
- package/plugins/pi/akuma-tools.ts +31 -38
- package/plugins/pi/keiyaku.ts +15 -4
- package/skills/keiyaku-akuma/SKILL.md +16 -11
- package/skills/keiyaku-babysit/SKILL.md +5 -3
- package/skills/keiyaku-bind/SKILL.md +4 -3
- package/skills/keiyaku-debt/SKILL.md +17 -17
- package/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/src/akuma/providers/codex-app-server/configuration.d.ts +0 -5
- package/build/src/akuma/providers/codex-app-server/configuration.js +0 -72
- package/build/src/cli/commands/debt-query.d.ts +0 -5
- package/build/src/cli/commands/debt-query.js +0 -194
- package/build/src/cli/render/akuma-tool-command.d.ts +0 -6
- package/build/src/cli/render/akuma-tool-command.js +0 -143
- package/build/src/cli/render/akuma-tool.d.ts +0 -29
- package/build/src/cli/render/akuma-tool.js +0 -225
- package/build/src/debt/context.d.ts +0 -28
- package/build/src/debt/context.js +0 -102
- package/build/src/debt/created-observation.d.ts +0 -26
- package/build/src/debt/created-observation.js +0 -38
- package/build/src/debt/query.d.ts +0 -80
- package/build/src/debt/query.js +0 -283
- package/build/src/library/contract-execution.d.ts +0 -28
- package/build/src/library/contract-execution.js +0 -506
- package/build/src/library/keiyaku-policy.d.ts +0 -27
- package/build/src/library/keiyaku-policy.js +0 -44
- package/build/src/library/keiyaku-status.d.ts +0 -1487
- package/build/src/library/keiyaku-status.js +0 -92
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
/** @architectureCompositionRoot */
|
|
2
2
|
import { isAbsolute, resolve } from "node:path";
|
|
3
|
+
import { parseDuration } from "../duration.js";
|
|
3
4
|
import { ZodError } from "zod";
|
|
4
|
-
import { Schema } from "../akuma/schema.js";
|
|
5
5
|
import { verbs, } from "./keiyaku-verbs.js";
|
|
6
6
|
import { canonicalBirthCwd } from "../akuma/call-input.js";
|
|
7
7
|
import { World, WorldError } from "../world.js";
|
|
8
8
|
import { Akuma } from "../akuma/akuma-instance.js";
|
|
9
|
-
import {
|
|
10
|
-
import { Akumas
|
|
11
|
-
import { deliveryOwner
|
|
9
|
+
import { Kanshi } from "../kanshi/index.js";
|
|
10
|
+
import { Akumas } from "./akumas.js";
|
|
11
|
+
import { deliveryOwner } from "./keiyaku-attribution.js";
|
|
12
12
|
import { akumaCallerFromEnvironment } from "./keiyaku-identity.js";
|
|
13
|
-
import {
|
|
13
|
+
import { contractId } from "../core/facts/types.js";
|
|
14
|
+
import { Settings } from "../settings.js";
|
|
14
15
|
import { Keis } from "./contract-composition.js";
|
|
15
16
|
import { validateArcMarkdown } from "./input.js";
|
|
16
|
-
import {
|
|
17
|
+
import { errorCategory } from "../errors.js";
|
|
17
18
|
import { invocationCoordinates, KeiyakuArcDocumentError, KeiyakuUsageError } from "./keiyaku-coordinates.js";
|
|
18
19
|
import { whoami } from "./keiyaku-identity.js";
|
|
19
20
|
import { nukeKeiyaku } from "./nuke.js";
|
|
20
|
-
import { statusAt } from "./keiyaku-status.js";
|
|
21
|
-
import { listArchetypeDefinitions } from "../akuma/archetype.js";
|
|
22
21
|
import * as debt from "./keiyaku-debt.js";
|
|
22
|
+
import { validateAkumaName } from "../identity/normalize.js";
|
|
23
23
|
export { KeiyakuArcDocumentError, KeiyakuUsageError } from "./keiyaku-coordinates.js";
|
|
24
|
+
function waitTimeout(wait) {
|
|
25
|
+
const duration = parseDuration(wait);
|
|
26
|
+
if (duration.kind !== "parsed")
|
|
27
|
+
throw new KeiyakuUsageError("invalid wait duration");
|
|
28
|
+
return duration.milliseconds;
|
|
29
|
+
}
|
|
24
30
|
export class Keiyaku {
|
|
25
31
|
static verbs = verbs;
|
|
26
32
|
#input;
|
|
@@ -29,19 +35,20 @@ export class Keiyaku {
|
|
|
29
35
|
}
|
|
30
36
|
static at(input) {
|
|
31
37
|
if (typeof input?.cwd !== "string" || !isAbsolute(input.cwd))
|
|
32
|
-
throw new
|
|
38
|
+
throw new KeiyakuUsageError("cwd must be an absolute string");
|
|
33
39
|
if (typeof input.environment !== "object" ||
|
|
34
40
|
input.environment === null ||
|
|
35
41
|
Array.isArray(input.environment) ||
|
|
36
42
|
Object.values(input.environment).some((value) => value !== undefined && typeof value !== "string"))
|
|
37
|
-
throw new
|
|
43
|
+
throw new KeiyakuUsageError("environment must be a string record");
|
|
38
44
|
if (input.home !== undefined && typeof input.home !== "string")
|
|
39
|
-
throw new
|
|
45
|
+
throw new KeiyakuUsageError("home must be a string");
|
|
40
46
|
if (input.repo !== undefined && typeof input.repo !== "string")
|
|
41
|
-
throw new
|
|
47
|
+
throw new KeiyakuUsageError("repo must be a string");
|
|
42
48
|
return new Keiyaku(input);
|
|
43
49
|
}
|
|
44
50
|
async run(name, input, run) {
|
|
51
|
+
run?.signal?.throwIfAborted();
|
|
45
52
|
let parsed;
|
|
46
53
|
try {
|
|
47
54
|
parsed = verbs[name].input.parse(input);
|
|
@@ -51,10 +58,6 @@ export class Keiyaku {
|
|
|
51
58
|
throw new KeiyakuUsageError(error.message);
|
|
52
59
|
throw error;
|
|
53
60
|
}
|
|
54
|
-
return (await this.#dispatch({ name, input: parsed }, run));
|
|
55
|
-
}
|
|
56
|
-
async #dispatch(request, run) {
|
|
57
|
-
const signal = run?.signal === undefined ? {} : { signal: run.signal };
|
|
58
61
|
const observe = run?.observe;
|
|
59
62
|
const notify = (event) => {
|
|
60
63
|
try {
|
|
@@ -66,6 +69,11 @@ export class Keiyaku {
|
|
|
66
69
|
/* Observation cannot affect execution. */
|
|
67
70
|
}
|
|
68
71
|
};
|
|
72
|
+
return (await this.#dispatch({ name, input: parsed }, run, notify));
|
|
73
|
+
}
|
|
74
|
+
async #dispatch(request, run, notify) {
|
|
75
|
+
const signal = run?.signal === undefined ? {} : { signal: run.signal };
|
|
76
|
+
const progress = run?.observe === undefined ? undefined : { observe: notify };
|
|
69
77
|
switch (request.name) {
|
|
70
78
|
case "bind":
|
|
71
79
|
return this.#bind(request.input);
|
|
@@ -74,13 +82,11 @@ export class Keiyaku {
|
|
|
74
82
|
case "arc":
|
|
75
83
|
return this.#arc(request.input);
|
|
76
84
|
case "deliver":
|
|
77
|
-
return this.#deliver({ ...request.input, ...signal },
|
|
78
|
-
case "deliver.preview":
|
|
79
|
-
return this.#previewDelivery({ ...request.input, ...signal }, observe === undefined ? undefined : { observe: (event) => notify(event) });
|
|
85
|
+
return this.#deliver({ ...request.input, ...signal }, progress);
|
|
80
86
|
case "verify":
|
|
81
|
-
return this.#verify({ ...request.input, ...signal },
|
|
87
|
+
return this.#verify({ ...request.input, ...signal }, progress);
|
|
82
88
|
case "review":
|
|
83
|
-
return this.#review({ ...request.input, ...signal },
|
|
89
|
+
return this.#review({ ...request.input, ...signal }, progress);
|
|
84
90
|
case "abandon":
|
|
85
91
|
return this.#abandon(request.input);
|
|
86
92
|
case "show":
|
|
@@ -102,38 +108,43 @@ export class Keiyaku {
|
|
|
102
108
|
return this.#settings();
|
|
103
109
|
case "nuke":
|
|
104
110
|
return this.#nuke(request.input);
|
|
105
|
-
case "
|
|
106
|
-
|
|
111
|
+
case "kanshi": {
|
|
112
|
+
const at = await this.#coordinates("optional");
|
|
113
|
+
return Kanshi.of({ world: at.world, ...(at.repo === undefined ? {} : { repo: at.repo }) }).board();
|
|
114
|
+
}
|
|
115
|
+
case "status": {
|
|
116
|
+
const at = await this.#coordinates("optional");
|
|
117
|
+
if (request.input.id.startsWith("aku/")) {
|
|
118
|
+
if (at.world === null)
|
|
119
|
+
throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
|
|
120
|
+
return Akumas.of(at.world).status({
|
|
121
|
+
akuma: request.input.id,
|
|
122
|
+
...(at.repo === undefined ? {} : { repo: at.repo }),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (at.repo === undefined)
|
|
126
|
+
throw new KeiyakuUsageError("this command requires a resolved Repo");
|
|
127
|
+
const report = await Kanshi.of({ world: at.world, repo: at.repo }).contract(contractId(request.input.id));
|
|
128
|
+
if (report.kind === "contract-absent")
|
|
129
|
+
throw new Error("Contract observation with a Repo cannot be absent");
|
|
130
|
+
return report;
|
|
131
|
+
}
|
|
107
132
|
case "region":
|
|
108
133
|
return this.#region(request.input);
|
|
109
134
|
case "ls":
|
|
110
135
|
return this.#ls(request.input);
|
|
111
|
-
|
|
112
|
-
case "debt.addDocument":
|
|
113
|
-
case "debt.update":
|
|
114
|
-
case "debt.show":
|
|
115
|
-
case "debt.done":
|
|
116
|
-
case "debt.drop":
|
|
117
|
-
case "debt.ready":
|
|
118
|
-
case "debt.blocked":
|
|
119
|
-
case "debt.query":
|
|
120
|
-
case "debt.tree":
|
|
121
|
-
case "debt.doctor":
|
|
122
|
-
case "debt.context":
|
|
136
|
+
default:
|
|
123
137
|
return this.#dispatchDebt(request, signal);
|
|
124
138
|
}
|
|
125
139
|
}
|
|
126
|
-
#dispatchAkuma(request, run, notify) {
|
|
140
|
+
async #dispatchAkuma(request, run, notify) {
|
|
127
141
|
const signal = run?.signal === undefined ? {} : { signal: run.signal };
|
|
128
142
|
const observe = run?.observe;
|
|
129
143
|
switch (request.name) {
|
|
130
144
|
case "spawn": {
|
|
131
|
-
const { schema, ...input } = request.input;
|
|
132
|
-
const decode = run?.decode ?? ((value) => value);
|
|
133
145
|
return this.#spawn({
|
|
134
|
-
...input,
|
|
146
|
+
...request.input,
|
|
135
147
|
...signal,
|
|
136
|
-
...(schema === undefined ? {} : { schema: Schema.json(schema, decode) }),
|
|
137
148
|
...(observe === undefined
|
|
138
149
|
? {}
|
|
139
150
|
: {
|
|
@@ -147,14 +158,10 @@ export class Keiyaku {
|
|
|
147
158
|
case "fork":
|
|
148
159
|
return this.#fork(request.input);
|
|
149
160
|
case "tell":
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const decode = run?.decode ?? ((value) => value);
|
|
154
|
-
return this.#ask({
|
|
155
|
-
...input,
|
|
161
|
+
case "ask":
|
|
162
|
+
return this.#tell({
|
|
163
|
+
...request.input,
|
|
156
164
|
...signal,
|
|
157
|
-
...(schema === undefined ? {} : { schema: Schema.json(schema, decode) }),
|
|
158
165
|
...(observe === undefined
|
|
159
166
|
? {}
|
|
160
167
|
: {
|
|
@@ -164,7 +171,6 @@ export class Keiyaku {
|
|
|
164
171
|
},
|
|
165
172
|
}),
|
|
166
173
|
});
|
|
167
|
-
}
|
|
168
174
|
case "kill":
|
|
169
175
|
return this.#kill({ ...request.input, ...signal });
|
|
170
176
|
case "wait":
|
|
@@ -183,73 +189,49 @@ export class Keiyaku {
|
|
|
183
189
|
return debt.debtAdd(this.#input, { ...request.input, ...signal }, true);
|
|
184
190
|
case "debt.update":
|
|
185
191
|
return debt.debtUpdate(this.#input, { ...request.input, ...signal });
|
|
186
|
-
case "debt.show":
|
|
187
|
-
return debt.debtShow(this.#input, request.input);
|
|
188
|
-
case "debt.done":
|
|
189
|
-
return debt.debtClose(this.#input, { ...request.input, ...signal }, "done");
|
|
190
|
-
case "debt.drop":
|
|
191
|
-
return debt.debtClose(this.#input, { ...request.input, ...signal }, "drop");
|
|
192
|
-
case "debt.ready":
|
|
193
|
-
return debt.debtReady(this.#input, request.input, false);
|
|
194
|
-
case "debt.blocked":
|
|
195
|
-
return debt.debtReady(this.#input, request.input, true);
|
|
196
|
-
case "debt.query":
|
|
197
|
-
return debt.debtQuery(this.#input, request.input);
|
|
198
|
-
case "debt.tree":
|
|
199
|
-
return debt.debtTree(this.#input, request.input);
|
|
200
192
|
case "debt.doctor":
|
|
201
193
|
return debt.debtDoctor(this.#input);
|
|
202
|
-
case "debt.context":
|
|
203
|
-
return debt.debtContext(this.#input, request.input);
|
|
204
194
|
}
|
|
205
195
|
}
|
|
206
|
-
bind(input) {
|
|
207
|
-
|
|
196
|
+
bind(input, run) {
|
|
197
|
+
// Generic output describes the wire form; the same execution retains the native handle.
|
|
198
|
+
return this.run("bind", input, run);
|
|
208
199
|
}
|
|
209
|
-
amend(input) {
|
|
210
|
-
return this.run("amend", input);
|
|
200
|
+
amend(input, run) {
|
|
201
|
+
return this.run("amend", input, run);
|
|
211
202
|
}
|
|
212
|
-
arc(input) {
|
|
213
|
-
return this.run("arc", input);
|
|
203
|
+
arc(input, run) {
|
|
204
|
+
return this.run("arc", input, run);
|
|
214
205
|
}
|
|
215
|
-
deliver(input, run) {
|
|
206
|
+
deliver(input = {}, run) {
|
|
216
207
|
return this.run("deliver", input, run);
|
|
217
208
|
}
|
|
218
|
-
|
|
219
|
-
return this.run("deliver.preview", input, run);
|
|
220
|
-
}
|
|
221
|
-
verify(input, run) {
|
|
209
|
+
verify(input = {}, run) {
|
|
222
210
|
return this.run("verify", input, run);
|
|
223
211
|
}
|
|
224
212
|
review(input, run) {
|
|
225
213
|
return this.run("review", input, run);
|
|
226
214
|
}
|
|
227
|
-
abandon(input) {
|
|
228
|
-
return this.run("abandon", input);
|
|
215
|
+
abandon(input = {}, run) {
|
|
216
|
+
return this.run("abandon", input, run);
|
|
229
217
|
}
|
|
230
|
-
show(input = {}) {
|
|
231
|
-
return this.run("show", input);
|
|
218
|
+
show(input = {}, run) {
|
|
219
|
+
return this.run("show", input, run);
|
|
232
220
|
}
|
|
233
|
-
reconcile(input = {}) {
|
|
234
|
-
return this.run("reconcile", input);
|
|
221
|
+
reconcile(input = {}, run) {
|
|
222
|
+
return this.run("reconcile", input, run);
|
|
235
223
|
}
|
|
236
|
-
spawn(
|
|
237
|
-
return this.run("spawn",
|
|
238
|
-
...run,
|
|
239
|
-
...(schema === undefined ? {} : { decode: schema.decode }),
|
|
240
|
-
});
|
|
224
|
+
spawn(input, run) {
|
|
225
|
+
return this.run("spawn", input, run);
|
|
241
226
|
}
|
|
242
|
-
fork(input) {
|
|
243
|
-
return this.run("fork", input);
|
|
227
|
+
fork(input, run) {
|
|
228
|
+
return this.run("fork", input, run);
|
|
244
229
|
}
|
|
245
230
|
tell(input, run) {
|
|
246
231
|
return this.run("tell", input, run);
|
|
247
232
|
}
|
|
248
|
-
ask(
|
|
249
|
-
return this.run("ask",
|
|
250
|
-
...run,
|
|
251
|
-
...(schema === undefined ? {} : { decode: schema.decode }),
|
|
252
|
-
});
|
|
233
|
+
ask(input, run) {
|
|
234
|
+
return this.run("ask", input, run);
|
|
253
235
|
}
|
|
254
236
|
kill(input, run) {
|
|
255
237
|
return this.run("kill", input, run);
|
|
@@ -257,94 +239,59 @@ export class Keiyaku {
|
|
|
257
239
|
wait(input, run) {
|
|
258
240
|
return this.run("wait", input, run);
|
|
259
241
|
}
|
|
260
|
-
history(input) {
|
|
261
|
-
return this.run("history", input);
|
|
242
|
+
history(input, run) {
|
|
243
|
+
return this.run("history", input, run);
|
|
262
244
|
}
|
|
263
245
|
report(input, run) {
|
|
264
246
|
return this.run("report", input, run);
|
|
265
247
|
}
|
|
266
|
-
ls(input) {
|
|
267
|
-
return this.run("ls", input);
|
|
268
|
-
}
|
|
269
|
-
debtAdd({ signal, ...input }) {
|
|
270
|
-
return this.run("debt.add", input, signal === undefined ? {} : { signal });
|
|
271
|
-
}
|
|
272
|
-
debtAddDocument({ signal, ...input }) {
|
|
273
|
-
return this.run("debt.addDocument", input, signal === undefined ? {} : { signal });
|
|
274
|
-
}
|
|
275
|
-
debtUpdate({ signal, ...input }) {
|
|
276
|
-
return this.run("debt.update", input, signal === undefined ? {} : { signal });
|
|
277
|
-
}
|
|
278
|
-
debtShow(input) {
|
|
279
|
-
return this.run("debt.show", input);
|
|
280
|
-
}
|
|
281
|
-
debtDone({ signal, ...input }) {
|
|
282
|
-
return this.run("debt.done", input, signal === undefined ? {} : { signal });
|
|
283
|
-
}
|
|
284
|
-
debtDrop({ signal, ...input }) {
|
|
285
|
-
return this.run("debt.drop", input, signal === undefined ? {} : { signal });
|
|
248
|
+
ls(input, run) {
|
|
249
|
+
return this.run("ls", input, run);
|
|
286
250
|
}
|
|
287
|
-
|
|
288
|
-
return this.run("debt.
|
|
251
|
+
debtAdd(input, run) {
|
|
252
|
+
return this.run("debt.add", input, run);
|
|
289
253
|
}
|
|
290
|
-
|
|
291
|
-
return this.run("debt.
|
|
254
|
+
debtAddDocument(input, run) {
|
|
255
|
+
return this.run("debt.addDocument", input, run);
|
|
292
256
|
}
|
|
293
|
-
|
|
294
|
-
return this.run("debt.
|
|
257
|
+
debtUpdate(input, run) {
|
|
258
|
+
return this.run("debt.update", input, run);
|
|
295
259
|
}
|
|
296
|
-
|
|
297
|
-
return this.run("debt.
|
|
260
|
+
debtDoctor(input = {}, run) {
|
|
261
|
+
return this.run("debt.doctor", input, run);
|
|
298
262
|
}
|
|
299
|
-
|
|
300
|
-
return this.run("
|
|
263
|
+
kanshi(input = {}, run) {
|
|
264
|
+
return this.run("kanshi", input, run);
|
|
301
265
|
}
|
|
302
|
-
|
|
303
|
-
return this.run("
|
|
266
|
+
status(input, run) {
|
|
267
|
+
return this.run("status", input, run);
|
|
304
268
|
}
|
|
305
|
-
|
|
306
|
-
return this.run("
|
|
269
|
+
region(input = {}, run) {
|
|
270
|
+
return this.run("region", input, run);
|
|
307
271
|
}
|
|
308
|
-
|
|
309
|
-
return this.run("
|
|
272
|
+
whoami(input = {}, run) {
|
|
273
|
+
return this.run("whoami", input, run);
|
|
310
274
|
}
|
|
311
|
-
|
|
312
|
-
return this.run("
|
|
275
|
+
settings(input = {}, run) {
|
|
276
|
+
return this.run("settings", input, run);
|
|
313
277
|
}
|
|
314
|
-
|
|
315
|
-
return this.run("
|
|
316
|
-
}
|
|
317
|
-
nuke(input = {}) {
|
|
318
|
-
return this.run("nuke", input);
|
|
278
|
+
nuke(input = {}, run) {
|
|
279
|
+
return this.run("nuke", input, run);
|
|
319
280
|
}
|
|
320
281
|
#coordinates(use, contractWait = false) {
|
|
321
282
|
return invocationCoordinates({ ...this.#input, use, contractWait });
|
|
322
283
|
}
|
|
323
|
-
#
|
|
324
|
-
try {
|
|
325
|
-
const actor = resolveActor({
|
|
326
|
-
env: this.#input.environment,
|
|
327
|
-
...(explicit === undefined ? {} : { actor: explicit }),
|
|
328
|
-
});
|
|
329
|
-
return actor === undefined ? {} : { actor };
|
|
330
|
-
}
|
|
331
|
-
catch (error) {
|
|
332
|
-
throw new KeiyakuUsageError(error instanceof Error ? error.message : String(error));
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
async #keis(actor) {
|
|
284
|
+
async #keis() {
|
|
336
285
|
const at = await this.#coordinates("required");
|
|
337
286
|
if (at.repo === undefined)
|
|
338
287
|
throw new KeiyakuUsageError("this command requires a resolved Repo");
|
|
339
|
-
const configuration = await
|
|
340
|
-
...(at.world === null ? {} : {
|
|
288
|
+
const configuration = await Settings.load({
|
|
289
|
+
...(at.world === null ? {} : { cwd: at.world }),
|
|
341
290
|
...(this.#input.home === undefined ? {} : { home: this.#input.home }),
|
|
342
291
|
});
|
|
343
|
-
const selected = this.#actor(actor);
|
|
344
292
|
return {
|
|
345
293
|
cwd: at.cwd,
|
|
346
|
-
|
|
347
|
-
library: Keis.of(at.repo, { settings: configuration, ...selected }),
|
|
294
|
+
library: Keis.of(at.repo, { settings: configuration }),
|
|
348
295
|
};
|
|
349
296
|
}
|
|
350
297
|
#fullId(library, value) {
|
|
@@ -376,105 +323,95 @@ export class Keiyaku {
|
|
|
376
323
|
throw new KeiyakuUsageError("an explicit full or @ contract selector is required outside a managed worktree");
|
|
377
324
|
}
|
|
378
325
|
}
|
|
379
|
-
async #selected(selector
|
|
380
|
-
const { cwd, library
|
|
326
|
+
async #selected(selector) {
|
|
327
|
+
const { cwd, library } = await this.#keis();
|
|
381
328
|
const id = await this.#resolve(library, selector, cwd);
|
|
382
|
-
return { id, contract: library.kei({ id })
|
|
329
|
+
return { id, contract: library.kei({ id }) };
|
|
383
330
|
}
|
|
384
331
|
async #bind(input) {
|
|
385
|
-
const { library
|
|
332
|
+
const { library } = await this.#keis();
|
|
386
333
|
if ("forkOf" in input)
|
|
387
334
|
return await library.bind({
|
|
388
335
|
...input,
|
|
389
336
|
forkOf: this.#fullId(library, input.forkOf),
|
|
390
|
-
...actor,
|
|
391
337
|
});
|
|
392
338
|
const { after, ...rest } = input;
|
|
393
339
|
return await library.bind({
|
|
394
340
|
...rest,
|
|
395
341
|
...(after === undefined ? {} : { after: after.map((id) => this.#fullId(library, id)) }),
|
|
396
|
-
...actor,
|
|
397
342
|
});
|
|
398
343
|
}
|
|
399
344
|
async #amend({ contract, ...input }) {
|
|
400
|
-
const { cwd, library
|
|
345
|
+
const { cwd, library } = await this.#keis();
|
|
401
346
|
const id = await this.#resolve(library, contract, cwd);
|
|
402
347
|
const { after, ...rest } = input;
|
|
403
348
|
return await library.kei({ id }).amend({
|
|
404
349
|
...rest,
|
|
405
350
|
...(after === undefined ? {} : { after: after.map((value) => this.#fullId(library, value)) }),
|
|
406
|
-
...actor,
|
|
407
351
|
});
|
|
408
352
|
}
|
|
409
353
|
async #arc({ contract, ...input }) {
|
|
410
|
-
const selected = await this.#selected(contract
|
|
354
|
+
const selected = await this.#selected(contract);
|
|
411
355
|
try {
|
|
412
356
|
validateArcMarkdown(input.markdown);
|
|
413
357
|
}
|
|
414
358
|
catch (error) {
|
|
415
|
-
if (
|
|
359
|
+
if (errorCategory(error) === "invalid-input")
|
|
416
360
|
throw new KeiyakuArcDocumentError(selected.id, error);
|
|
417
361
|
throw error;
|
|
418
362
|
}
|
|
419
|
-
return await selected.contract.arc(
|
|
363
|
+
return await selected.contract.arc(input);
|
|
420
364
|
}
|
|
421
365
|
async #deliver({ contract, ...input }, progress) {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
return await (await this.#selected(contract)).contract.previewDelivery(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);
|
|
426
369
|
}
|
|
427
370
|
async #verify({ contract, ...input }, progress) {
|
|
428
371
|
return await (await this.#selected(contract)).contract.verify(input, progress);
|
|
429
372
|
}
|
|
430
373
|
async #review({ contract, ...input }, progress) {
|
|
431
|
-
const selected = await this.#selected(contract
|
|
432
|
-
return await selected.contract.review(
|
|
374
|
+
const selected = await this.#selected(contract);
|
|
375
|
+
return await selected.contract.review(input, progress);
|
|
433
376
|
}
|
|
434
377
|
async #abandon({ contract, ...input }) {
|
|
435
|
-
const selected = await this.#selected(contract
|
|
436
|
-
return await selected.contract.abandon(
|
|
378
|
+
const selected = await this.#selected(contract);
|
|
379
|
+
return await selected.contract.abandon(input);
|
|
437
380
|
}
|
|
438
|
-
async #show(
|
|
439
|
-
|
|
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();
|
|
440
385
|
}
|
|
441
|
-
async #reconcile(input
|
|
386
|
+
async #reconcile(input) {
|
|
442
387
|
const { cwd, library } = await this.#keis();
|
|
443
388
|
if (input.contract === undefined)
|
|
444
389
|
return await library.reconcile(input);
|
|
445
390
|
const id = await this.#resolve(library, input.contract, cwd);
|
|
446
391
|
return await library.reconcile({ ...input, contract: id });
|
|
447
392
|
}
|
|
448
|
-
async #spawn({ prompt, contract, workdir,
|
|
449
|
-
if (prompt !== undefined && prompt.trim() === "")
|
|
450
|
-
throw new KeiyakuUsageError("spawn requires a nonblank prompt");
|
|
393
|
+
async #spawn({ prompt, wait, contract, workdir, alias, observe, ...input }) {
|
|
451
394
|
const at = await this.#coordinates(contract === undefined ? "none" : "required");
|
|
452
395
|
const cwd = workdir === undefined
|
|
453
396
|
? at.cwd
|
|
454
397
|
: await canonicalBirthCwd(resolve(at.cwd, workdir), `workdir is not an existing directory: ${workdir}`);
|
|
455
|
-
const directories = writableDirectories === undefined
|
|
456
|
-
? undefined
|
|
457
|
-
: await Promise.all(writableDirectories.map((path) => {
|
|
458
|
-
if (path.trim() === "")
|
|
459
|
-
throw new TypeError("--add-dir requires a nonblank directory");
|
|
460
|
-
return canonicalBirthCwd(resolve(at.cwd, path));
|
|
461
|
-
}));
|
|
462
398
|
const caller = await this.#caller();
|
|
463
399
|
const initiator = deliveryOwner(this.#input.environment);
|
|
464
400
|
const world = at.candidateWorld ?? (await at.establishWorld());
|
|
465
401
|
await World.at(world);
|
|
466
|
-
const configuration = await
|
|
467
|
-
|
|
402
|
+
const configuration = await Settings.load({
|
|
403
|
+
cwd: world,
|
|
468
404
|
...(this.#input.home === undefined ? {} : { home: this.#input.home }),
|
|
469
405
|
});
|
|
470
406
|
const selected = contract === undefined ? undefined : Keis.of(at.repo).kei({ id: this.#fullId(Keis.of(at.repo), contract) });
|
|
471
407
|
return await Akumas.of(world).spawn({
|
|
472
408
|
...input,
|
|
409
|
+
...(wait === undefined ? {} : { mode: "wait", timeoutMs: waitTimeout(wait) }),
|
|
473
410
|
cwd,
|
|
474
411
|
settings: configuration,
|
|
412
|
+
...(alias === undefined ? {} : { alias: alias }),
|
|
475
413
|
...(this.#input.home === undefined ? {} : { home: this.#input.home }),
|
|
476
414
|
...(prompt === undefined ? {} : { body: prompt }),
|
|
477
|
-
...(directories === undefined ? {} : { writableDirectories: directories }),
|
|
478
415
|
...(selected === undefined ? {} : { contract: selected }),
|
|
479
416
|
...(caller === undefined ? {} : { caller }),
|
|
480
417
|
...(initiator === undefined ? {} : { initiator }),
|
|
@@ -492,15 +429,8 @@ export class Keiyaku {
|
|
|
492
429
|
}),
|
|
493
430
|
});
|
|
494
431
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
return await akumaCallerFromEnvironment(this.#input.environment);
|
|
498
|
-
}
|
|
499
|
-
catch (error) {
|
|
500
|
-
if (error instanceof TypeError)
|
|
501
|
-
throw new KeiyakuUsageError(error.message);
|
|
502
|
-
throw error;
|
|
503
|
-
}
|
|
432
|
+
#caller() {
|
|
433
|
+
return akumaCallerFromEnvironment(this.#input.environment);
|
|
504
434
|
}
|
|
505
435
|
async #akumas(use = "optional") {
|
|
506
436
|
const at = await this.#coordinates(use);
|
|
@@ -520,28 +450,18 @@ export class Keiyaku {
|
|
|
520
450
|
});
|
|
521
451
|
}
|
|
522
452
|
async #tell({ prompt, ...input }) {
|
|
523
|
-
if (prompt.trim() === "")
|
|
524
|
-
throw new KeiyakuUsageError("tell requires a nonblank prompt");
|
|
525
453
|
const { at, akumas } = await this.#akumas();
|
|
526
454
|
const initiator = deliveryOwner(this.#input.environment);
|
|
527
|
-
|
|
455
|
+
const native = {
|
|
528
456
|
...input,
|
|
529
457
|
body: prompt,
|
|
530
458
|
...(at.repo === undefined ? {} : { repo: at.repo }),
|
|
531
459
|
...(initiator === undefined ? {} : { initiator }),
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
const { at, akumas } = await this.#akumas();
|
|
538
|
-
const initiator = deliveryOwner(this.#input.environment);
|
|
539
|
-
return await akumas.ask({
|
|
540
|
-
...input,
|
|
541
|
-
body: prompt,
|
|
542
|
-
...(at.repo === undefined ? {} : { repo: at.repo }),
|
|
543
|
-
...(initiator === undefined ? {} : { initiator }),
|
|
544
|
-
});
|
|
460
|
+
};
|
|
461
|
+
if ("schema" in native)
|
|
462
|
+
return akumas.ask(native);
|
|
463
|
+
const { wait, ...tell } = native;
|
|
464
|
+
return akumas.tell({ ...tell, ...(wait === undefined ? {} : { wait: true, timeoutMs: waitTimeout(wait) }) });
|
|
545
465
|
}
|
|
546
466
|
async #kill(input) {
|
|
547
467
|
const { at, akumas } = await this.#akumas();
|
|
@@ -549,8 +469,6 @@ export class Keiyaku {
|
|
|
549
469
|
}
|
|
550
470
|
async #wait({ selectors, ...input }) {
|
|
551
471
|
const contracts = selectors.filter((selector) => selector.startsWith("kei/"));
|
|
552
|
-
if (contracts.length > 0 && contracts.length !== selectors.length)
|
|
553
|
-
throw new KeiyakuUsageError("wait cannot mix Contract and Akuma selectors");
|
|
554
472
|
if (contracts.length > 0) {
|
|
555
473
|
const at = await this.#coordinates("required", true);
|
|
556
474
|
if (at.repo === undefined)
|
|
@@ -560,7 +478,7 @@ export class Keiyaku {
|
|
|
560
478
|
const { at, akumas } = await this.#akumas();
|
|
561
479
|
return await akumas.wait({ akuma: selectors, ...input, ...(at.repo === undefined ? {} : { repo: at.repo }) });
|
|
562
480
|
}
|
|
563
|
-
async #history({ selector,
|
|
481
|
+
async #history({ selector, ...input }) {
|
|
564
482
|
if (selector.startsWith("kei/")) {
|
|
565
483
|
const at = await this.#coordinates("required");
|
|
566
484
|
if (at.repo === undefined)
|
|
@@ -568,7 +486,7 @@ export class Keiyaku {
|
|
|
568
486
|
const library = Keis.of(at.repo);
|
|
569
487
|
return await library
|
|
570
488
|
.kei({ id: this.#fullId(library, selector) })
|
|
571
|
-
.history(full
|
|
489
|
+
.history("full" in input ? { full: input.full } : undefined);
|
|
572
490
|
}
|
|
573
491
|
const { at, akumas } = await this.#akumas();
|
|
574
492
|
return await akumas.history({ akuma: selector, ...input, ...(at.repo === undefined ? {} : { repo: at.repo }) });
|
|
@@ -576,8 +494,6 @@ export class Keiyaku {
|
|
|
576
494
|
async #report(input) {
|
|
577
495
|
await this.#coordinates("none");
|
|
578
496
|
const environment = this.#input.environment;
|
|
579
|
-
if (typeof input.text !== "string" || input.text.trim() === "")
|
|
580
|
-
throw new KeiyakuUsageError("report requires nonblank text");
|
|
581
497
|
if (environment.KEIYAKU_ACTOR_ID === undefined || environment.KEIYAKU_ACTOR_WORLD === undefined)
|
|
582
498
|
throw new KeiyakuUsageError("report requires explicit KEIYAKU_ACTOR_ID and KEIYAKU_ACTOR_WORLD");
|
|
583
499
|
let caller;
|
|
@@ -585,7 +501,7 @@ export class Keiyaku {
|
|
|
585
501
|
caller = await akumaCallerFromEnvironment(environment);
|
|
586
502
|
}
|
|
587
503
|
catch (error) {
|
|
588
|
-
if (error instanceof
|
|
504
|
+
if (error instanceof WorldError)
|
|
589
505
|
throw new KeiyakuUsageError(error.message);
|
|
590
506
|
throw error;
|
|
591
507
|
}
|
|
@@ -593,13 +509,9 @@ export class Keiyaku {
|
|
|
593
509
|
throw new KeiyakuUsageError("report requires explicit Akuma identity");
|
|
594
510
|
return Akuma.select(caller.world, caller.akumaId).report(input.text, input.signal === undefined ? {} : { signal: input.signal });
|
|
595
511
|
}
|
|
596
|
-
async #resolveLsCaller(
|
|
597
|
-
if (
|
|
512
|
+
async #resolveLsCaller(mine) {
|
|
513
|
+
if (mine !== true)
|
|
598
514
|
return undefined;
|
|
599
|
-
if (selection.kind === "external")
|
|
600
|
-
return selection.caller;
|
|
601
|
-
if (selection.kind === "akuma")
|
|
602
|
-
return { kind: "akuma", world, akumaId: selection.akumaId };
|
|
603
515
|
let caller;
|
|
604
516
|
try {
|
|
605
517
|
caller = await akumaCallerFromEnvironment(this.#input.environment);
|
|
@@ -608,39 +520,40 @@ export class Keiyaku {
|
|
|
608
520
|
throw new KeiyakuUsageError(error instanceof Error ? error.message : String(error));
|
|
609
521
|
}
|
|
610
522
|
if (caller === undefined) {
|
|
611
|
-
throw new KeiyakuUsageError("
|
|
523
|
+
throw new KeiyakuUsageError("listing the caller's own Akumas requires a caller identity; set KEIYAKU_ACTOR_ID and KEIYAKU_ACTOR_WORLD or run inside a calling host");
|
|
612
524
|
}
|
|
613
525
|
return caller;
|
|
614
526
|
}
|
|
615
527
|
async #ls(input) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
if (input.of === "kei") {
|
|
621
|
-
if (at.repo === undefined)
|
|
622
|
-
throw new KeiyakuUsageError("this command requires a resolved Repo");
|
|
623
|
-
return Keis.of(at.repo).list(limit);
|
|
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);
|
|
624
532
|
}
|
|
625
|
-
if (input.
|
|
626
|
-
return
|
|
627
|
-
...
|
|
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 }),
|
|
628
543
|
...(this.#input.home === undefined ? {} : { home: this.#input.home }),
|
|
629
|
-
...limit,
|
|
630
544
|
});
|
|
631
545
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
const
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
...
|
|
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 }),
|
|
638
553
|
...(caller === undefined ? {} : { caller }),
|
|
554
|
+
...(at.repo === undefined ? {} : { repo: at.repo }),
|
|
639
555
|
});
|
|
640
556
|
}
|
|
641
|
-
async #status(input = {}) {
|
|
642
|
-
return await statusAt(await this.#coordinates("optional"), input);
|
|
643
|
-
}
|
|
644
557
|
async #region(input = {}) {
|
|
645
558
|
const at = await this.#coordinates("required");
|
|
646
559
|
if (at.repo === undefined)
|
|
@@ -650,7 +563,7 @@ export class Keiyaku {
|
|
|
650
563
|
if (input.paths !== undefined) {
|
|
651
564
|
const [first, ...rest] = input.paths;
|
|
652
565
|
if (first === undefined)
|
|
653
|
-
throw new
|
|
566
|
+
throw new KeiyakuUsageError("Region query requires one or more path patterns");
|
|
654
567
|
selected = { kind: "path", patterns: [first, ...rest] };
|
|
655
568
|
}
|
|
656
569
|
else {
|
|
@@ -659,7 +572,7 @@ export class Keiyaku {
|
|
|
659
572
|
? { kind: "declarations" }
|
|
660
573
|
: { kind: "contract", contract: await this.#resolve(Keis.of(repo), input.contract, at.cwd) };
|
|
661
574
|
}
|
|
662
|
-
const result = await
|
|
575
|
+
const result = await Kanshi.of({ world: at.world, repo }).region(selected);
|
|
663
576
|
if (result.kind === "absent")
|
|
664
577
|
throw new Error("Region observation with a Repo cannot be absent");
|
|
665
578
|
return result;
|
|
@@ -669,12 +582,12 @@ export class Keiyaku {
|
|
|
669
582
|
}
|
|
670
583
|
async #settings() {
|
|
671
584
|
const at = await this.#coordinates("none");
|
|
672
|
-
return await
|
|
673
|
-
...(at.world === null ? {} : {
|
|
585
|
+
return await Settings.load({
|
|
586
|
+
...(at.world === null ? {} : { cwd: at.world }),
|
|
674
587
|
...(this.#input.home === undefined ? {} : { home: this.#input.home }),
|
|
675
588
|
});
|
|
676
589
|
}
|
|
677
|
-
async #nuke(input
|
|
590
|
+
async #nuke(input) {
|
|
678
591
|
const at = await this.#coordinates("none");
|
|
679
592
|
if (at.world === null)
|
|
680
593
|
throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
|