@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,3 +1,4 @@
|
|
|
1
|
+
import { KeiyakuError, errorCategory } from "../errors.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { readFile, readdir } from "node:fs/promises";
|
|
3
4
|
import { homedir } from "node:os";
|
|
@@ -6,26 +7,30 @@ import { parseDocument } from "yaml";
|
|
|
6
7
|
import { boundedListLimit } from "../bounded-list.js";
|
|
7
8
|
import { validateAkumaName } from "../identity/normalize.js";
|
|
8
9
|
import { decodeProviderOptions, decodeProviderRecipe, } from "./provider-recipe.js";
|
|
9
|
-
export const
|
|
10
|
+
export const akumaNameCatalogRowSchema = z
|
|
10
11
|
.strictObject({ name: z.string(), model: z.string().exactOptional(), description: z.string().exactOptional() })
|
|
11
12
|
.readonly();
|
|
12
|
-
export const
|
|
13
|
+
export const akumaNameCatalogSchema = z
|
|
13
14
|
.strictObject({
|
|
14
|
-
|
|
15
|
+
kind: z.literal("akuma-name-catalogue"),
|
|
16
|
+
rows: z.array(akumaNameCatalogRowSchema).nonempty().readonly().exactOptional(),
|
|
15
17
|
more: z.literal(true).exactOptional(),
|
|
16
18
|
})
|
|
17
19
|
.readonly();
|
|
18
|
-
export class
|
|
20
|
+
export class AkumaNameError extends KeiyakuError {
|
|
19
21
|
akumaName;
|
|
20
22
|
searched;
|
|
21
23
|
reason;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
absent;
|
|
25
|
+
kind = "akuma-name";
|
|
26
|
+
constructor(akumaName, searched, reason, absent = false) {
|
|
27
|
+
super(absent ? "invalid-input" : "internal", `\`${akumaName}\` ${reason}`, {
|
|
28
|
+
...(absent ? { next: { verb: "ls", input: { selector: "aku/" } } } : {}),
|
|
29
|
+
});
|
|
25
30
|
this.akumaName = akumaName;
|
|
26
31
|
this.searched = searched;
|
|
27
32
|
this.reason = reason;
|
|
28
|
-
this.
|
|
33
|
+
this.absent = absent;
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
function projectArchetypeDirectory(project) {
|
|
@@ -35,7 +40,7 @@ function homeArchetypeDirectory(home) {
|
|
|
35
40
|
return join(home ?? join(homedir(), ".keiyaku"), "akumas");
|
|
36
41
|
}
|
|
37
42
|
function archetypeDirectories(input) {
|
|
38
|
-
return [projectArchetypeDirectory(input.
|
|
43
|
+
return [projectArchetypeDirectory(input.cwd), homeArchetypeDirectory(input.home)].filter((directory) => directory !== undefined);
|
|
39
44
|
}
|
|
40
45
|
async function pathsInDirectory(directory) {
|
|
41
46
|
try {
|
|
@@ -70,33 +75,27 @@ async function archetypePaths(input = {}) {
|
|
|
70
75
|
return [...selected.values()].sort((left, right) => Buffer.compare(Buffer.from(left.name), Buffer.from(right.name)));
|
|
71
76
|
}
|
|
72
77
|
function sourceLookups(name, input, source) {
|
|
73
|
-
if (source === "home" || input.
|
|
78
|
+
if (source === "home" || input.cwd === undefined) {
|
|
74
79
|
return [{ path: join(homeArchetypeDirectory(input.home), `${name}.md`), source: "home" }];
|
|
75
80
|
}
|
|
76
81
|
return [
|
|
77
|
-
{ path: join(projectArchetypeDirectory(input.
|
|
82
|
+
{ path: join(projectArchetypeDirectory(input.cwd), `${name}.md`), source: "project" },
|
|
78
83
|
{ path: join(homeArchetypeDirectory(input.home), `${name}.md`), source: "home" },
|
|
79
84
|
];
|
|
80
85
|
}
|
|
81
|
-
function rootLookups(name, input) {
|
|
82
|
-
return input.project === undefined ? sourceLookups(name, input, "home") : sourceLookups(name, input, "project");
|
|
83
|
-
}
|
|
84
86
|
function chainText(chain) {
|
|
85
87
|
return chain.join(" -> ");
|
|
86
88
|
}
|
|
87
|
-
function archetypeError(name, searched, reason, chain,
|
|
89
|
+
function archetypeError(name, searched, reason, chain, absent = false) {
|
|
88
90
|
const withChain = chain.length === 0 ? reason : `${reason} (base chain: ${chainText(chain)})`;
|
|
89
|
-
return new
|
|
90
|
-
}
|
|
91
|
-
export async function listArchetypes(input = {}) {
|
|
92
|
-
return (await archetypePaths(input)).map(({ name }) => name);
|
|
91
|
+
return new AkumaNameError(name, searched, withChain, absent);
|
|
93
92
|
}
|
|
94
93
|
function archetypeField(values, key, required = false) {
|
|
95
94
|
const value = values[key];
|
|
96
95
|
if (value === undefined && !required)
|
|
97
96
|
return undefined;
|
|
98
97
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
99
|
-
throw new
|
|
98
|
+
throw new KeiyakuError("invalid-input", `Akuma ${key} must be a nonblank string`);
|
|
100
99
|
}
|
|
101
100
|
return value;
|
|
102
101
|
}
|
|
@@ -105,7 +104,7 @@ function archetypeEnum(values, key, allowed) {
|
|
|
105
104
|
if (value === undefined)
|
|
106
105
|
return undefined;
|
|
107
106
|
if (!allowed.includes(value))
|
|
108
|
-
throw new
|
|
107
|
+
throw new KeiyakuError("invalid-input", `Akuma ${key} must be one of ${allowed.join(", ")}`);
|
|
109
108
|
return value;
|
|
110
109
|
}
|
|
111
110
|
function archetypeBoolean(values, key) {
|
|
@@ -113,29 +112,29 @@ function archetypeBoolean(values, key) {
|
|
|
113
112
|
if (value === undefined)
|
|
114
113
|
return undefined;
|
|
115
114
|
if (typeof value !== "boolean")
|
|
116
|
-
throw new
|
|
115
|
+
throw new KeiyakuError("invalid-input", `Akuma ${key} must be a boolean`);
|
|
117
116
|
return value;
|
|
118
117
|
}
|
|
119
118
|
function parseArchetypeFrontmatter(markdown) {
|
|
120
119
|
const lines = markdown.split(/\r?\n/u);
|
|
121
120
|
if (lines[0]?.trim() !== "---")
|
|
122
|
-
throw new
|
|
121
|
+
throw new KeiyakuError("invalid-input", "Akuma file must begin with YAML frontmatter");
|
|
123
122
|
const closing = lines.findIndex((line, index) => index > 0 && line.trim() === "---");
|
|
124
123
|
if (closing < 0)
|
|
125
|
-
throw new
|
|
124
|
+
throw new KeiyakuError("invalid-input", "Akuma frontmatter is not closed");
|
|
126
125
|
const document = parseDocument(lines.slice(1, closing).join("\n"), { uniqueKeys: true });
|
|
127
126
|
if (document.errors.length > 0)
|
|
128
|
-
throw new
|
|
127
|
+
throw new KeiyakuError("invalid-input", `Akuma frontmatter is invalid: ${document.errors[0].message}`);
|
|
129
128
|
const decoded = document.toJS();
|
|
130
129
|
if (decoded === null || typeof decoded !== "object" || Array.isArray(decoded)) {
|
|
131
|
-
throw new
|
|
130
|
+
throw new KeiyakuError("invalid-input", "Akuma frontmatter must be one mapping");
|
|
132
131
|
}
|
|
133
132
|
return { lines, closing, values: decoded };
|
|
134
133
|
}
|
|
135
134
|
function decodeArchetypeFields(values) {
|
|
136
135
|
const unknown = Object.keys(values).find((key) => !["base", "provider", "model", "effort", "network", "description", "hidden", "systemPromptMode"].includes(key));
|
|
137
136
|
if (unknown !== undefined)
|
|
138
|
-
throw new
|
|
137
|
+
throw new KeiyakuError("invalid-input", `Akuma frontmatter has unknown field: ${unknown}`);
|
|
139
138
|
const provider = archetypeField(values, "provider");
|
|
140
139
|
const baseValue = archetypeField(values, "base");
|
|
141
140
|
const base = baseValue === undefined ? undefined : validateAkumaName(baseValue);
|
|
@@ -161,7 +160,7 @@ function decodeArchetype(name, path, markdown) {
|
|
|
161
160
|
const fields = decodeArchetypeFields(values);
|
|
162
161
|
const systemPrompt = lines.slice(closing + 1).join("\n");
|
|
163
162
|
if (fields.systemPromptMode !== undefined && systemPrompt.length === 0) {
|
|
164
|
-
throw new
|
|
163
|
+
throw new KeiyakuError("invalid-input", "Akuma systemPromptMode requires a nonempty Markdown body");
|
|
165
164
|
}
|
|
166
165
|
return Object.freeze({
|
|
167
166
|
name,
|
|
@@ -186,7 +185,7 @@ function decodeArchetype(name, path, markdown) {
|
|
|
186
185
|
function mergeArchetype(base, local) {
|
|
187
186
|
const provider = local.provider ?? base?.provider;
|
|
188
187
|
if (provider === undefined)
|
|
189
|
-
throw new
|
|
188
|
+
throw new KeiyakuError("invalid-input", "Akuma provider must be a nonblank string");
|
|
190
189
|
const options = decodeProviderOptions({ ...(base?.options ?? {}), ...local.options });
|
|
191
190
|
return Object.freeze({
|
|
192
191
|
name: local.name,
|
|
@@ -203,11 +202,10 @@ function mergeArchetype(base, local) {
|
|
|
203
202
|
});
|
|
204
203
|
}
|
|
205
204
|
async function resolveArchetype(name, input, source, chain = []) {
|
|
205
|
+
const lookups = sourceLookups(name, input, source ?? "project");
|
|
206
206
|
if (chain.includes(name)) {
|
|
207
|
-
const lookups = source === undefined ? rootLookups(name, input) : sourceLookups(name, input, source);
|
|
208
207
|
throw archetypeError(name, lookups.map(({ path }) => path), "has a cyclic base reference", [...chain, name]);
|
|
209
208
|
}
|
|
210
|
-
const lookups = source === undefined ? rootLookups(name, input) : sourceLookups(name, input, source);
|
|
211
209
|
const searched = lookups.map(({ path }) => path);
|
|
212
210
|
for (const lookup of lookups) {
|
|
213
211
|
let markdown;
|
|
@@ -238,36 +236,36 @@ async function resolveArchetype(name, input, source, chain = []) {
|
|
|
238
236
|
}
|
|
239
237
|
}
|
|
240
238
|
const missingChain = chain.length === 0 ? chain : [...chain, name];
|
|
241
|
-
throw archetypeError(name, searched, "was not found", missingChain,
|
|
239
|
+
throw archetypeError(name, searched, "was not found", missingChain, true);
|
|
242
240
|
}
|
|
243
241
|
function catalogueCoordinate(value, field) {
|
|
244
242
|
if (value === undefined)
|
|
245
243
|
return undefined;
|
|
246
244
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
247
|
-
throw new
|
|
245
|
+
throw new KeiyakuError("invalid-input", `Akuma catalogue ${field} must be a nonblank string`);
|
|
248
246
|
}
|
|
249
247
|
if (!isAbsolute(value))
|
|
250
|
-
throw new
|
|
248
|
+
throw new KeiyakuError("invalid-input", `Akuma catalogue ${field} must be absolute: ${value}`);
|
|
251
249
|
return value;
|
|
252
250
|
}
|
|
253
251
|
/** Malformed caller input fails here, before any filesystem observation. */
|
|
254
252
|
function catalogueInput(value) {
|
|
255
253
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
256
|
-
throw new
|
|
254
|
+
throw new KeiyakuError("invalid-input", "Akuma catalogue input must be an object");
|
|
257
255
|
}
|
|
258
256
|
const input = value;
|
|
259
|
-
const unknown = Object.keys(input).find((key) => !["
|
|
257
|
+
const unknown = Object.keys(input).find((key) => !["cwd", "home", "limit"].includes(key));
|
|
260
258
|
if (unknown !== undefined)
|
|
261
|
-
throw new
|
|
262
|
-
const
|
|
259
|
+
throw new KeiyakuError("invalid-input", `Akuma catalogue input has unknown field: ${unknown}`);
|
|
260
|
+
const cwd = catalogueCoordinate(input.cwd, "cwd");
|
|
263
261
|
const home = catalogueCoordinate(input.home, "home");
|
|
264
262
|
return {
|
|
265
|
-
...(
|
|
263
|
+
...(cwd === undefined ? {} : { cwd }),
|
|
266
264
|
...(home === undefined ? {} : { home }),
|
|
267
265
|
...(input.limit === undefined ? {} : { limit: boundedListLimit(input.limit) }),
|
|
268
266
|
};
|
|
269
267
|
}
|
|
270
|
-
export async function
|
|
268
|
+
export async function listAkumaNameDefinitions(input = {}) {
|
|
271
269
|
// Reads still run concurrently, but the reported failure is the first invalid
|
|
272
270
|
// definition in catalog byte order, not whichever read happened to finish first.
|
|
273
271
|
const { limit, ...coordinates } = catalogueInput(input);
|
|
@@ -277,9 +275,9 @@ export async function listArchetypeDefinitions(input = {}) {
|
|
|
277
275
|
return await resolveArchetype(name, coordinates, undefined);
|
|
278
276
|
}
|
|
279
277
|
catch (error) {
|
|
280
|
-
if (error instanceof
|
|
278
|
+
if (error instanceof AkumaNameError)
|
|
281
279
|
throw error;
|
|
282
|
-
throw new
|
|
280
|
+
throw new AkumaNameError(name, [path], `is invalid: ${error instanceof Error ? error.message : String(error)}`);
|
|
283
281
|
}
|
|
284
282
|
}));
|
|
285
283
|
const firstInvalid = settled.find((result) => result.status === "rejected");
|
|
@@ -295,6 +293,7 @@ export async function listArchetypeDefinitions(input = {}) {
|
|
|
295
293
|
}));
|
|
296
294
|
const rows = limit === undefined ? visible : visible.slice(0, limit);
|
|
297
295
|
return {
|
|
296
|
+
kind: "akuma-name-catalogue",
|
|
298
297
|
...(rows.length === 0 ? {} : { rows }),
|
|
299
298
|
...(limit !== undefined && visible.length > limit ? { more: true } : {}),
|
|
300
299
|
};
|
|
@@ -309,17 +308,17 @@ function optionalProviderText(value, name, field) {
|
|
|
309
308
|
if (selected === undefined)
|
|
310
309
|
return undefined;
|
|
311
310
|
if (typeof selected !== "string" || selected.trim().length === 0) {
|
|
312
|
-
throw new
|
|
311
|
+
throw new KeiyakuError("invalid-input", `provider ${name} ${field} must be a nonblank string`);
|
|
313
312
|
}
|
|
314
313
|
return selected;
|
|
315
314
|
}
|
|
316
315
|
function configuredProvider(name, selected) {
|
|
317
316
|
const value = record(selected);
|
|
318
317
|
if (value === null)
|
|
319
|
-
throw new
|
|
318
|
+
throw new KeiyakuError("invalid-input", `provider ${name} must be an object`);
|
|
320
319
|
const unknown = Object.keys(value).find((key) => !["kind", "description", "executable", "config", "env"].includes(key));
|
|
321
320
|
if (unknown !== undefined)
|
|
322
|
-
throw new
|
|
321
|
+
throw new KeiyakuError("invalid-input", `provider ${name} has unknown field ${unknown}`);
|
|
323
322
|
optionalProviderText(value, name, "description");
|
|
324
323
|
return decodeProviderRecipe({
|
|
325
324
|
name,
|
|
@@ -348,7 +347,7 @@ const BUILTIN_EXECUTIONS = {
|
|
|
348
347
|
function providerExecution(settings, name) {
|
|
349
348
|
const view = settings.namespace("providers");
|
|
350
349
|
if (view.kind === "failed")
|
|
351
|
-
throw new
|
|
350
|
+
throw new KeiyakuError("invalid-input", view.failures
|
|
352
351
|
.map((failure) => {
|
|
353
352
|
const scope = settings.scopes[failure.scope];
|
|
354
353
|
return `${failure.scope}: ${failure.diagnostic ?? (scope.kind === "failed" ? scope.diagnostic : "providers unavailable")}`;
|
|
@@ -360,7 +359,7 @@ function providerExecution(settings, name) {
|
|
|
360
359
|
const builtin = BUILTIN_EXECUTIONS[name];
|
|
361
360
|
if (builtin !== undefined)
|
|
362
361
|
return decodeProviderRecipe({ name, ...builtin });
|
|
363
|
-
throw new
|
|
362
|
+
throw new KeiyakuError("invalid-input", `unknown provider ${name}`);
|
|
364
363
|
}
|
|
365
364
|
/** Resolve one akumaName and decode its provider execution, leaving option admission to the caller. */
|
|
366
365
|
export async function loadPreparedArchetype(input) {
|
|
@@ -371,8 +370,8 @@ export async function loadPreparedArchetype(input) {
|
|
|
371
370
|
provider = providerExecution(input.settings, definition.provider);
|
|
372
371
|
}
|
|
373
372
|
catch (error) {
|
|
374
|
-
if (error
|
|
375
|
-
throw new
|
|
373
|
+
if (errorCategory(error) === "invalid-input")
|
|
374
|
+
throw new AkumaNameError(definition.name, [definition.path], `uses ${error instanceof Error ? error.message : String(error)}`);
|
|
376
375
|
throw error;
|
|
377
376
|
}
|
|
378
377
|
return Object.freeze({ ...definition, provider });
|
package/build/src/akuma/body.js
CHANGED
|
@@ -232,6 +232,7 @@ function turnOutcomeEmitter(launch, soul, world) {
|
|
|
232
232
|
akumaId: soul.id,
|
|
233
233
|
bodySequence: turn.bodySequence,
|
|
234
234
|
turnSequence,
|
|
235
|
+
at: turn.end.completedAt,
|
|
235
236
|
...(turn.initiator === undefined ? {} : { initiator: turn.initiator }),
|
|
236
237
|
...(participants.length === 0 ? {} : { participants }),
|
|
237
238
|
outcome: outcome.kind === "answered"
|
|
@@ -255,6 +256,8 @@ function bodyEndEmitter(launch, soul, world) {
|
|
|
255
256
|
return async (bodySequence, end, diagnostic) => {
|
|
256
257
|
try {
|
|
257
258
|
const latestTurn = await readLatestTurnForBody(launch.paths, bodySequence);
|
|
259
|
+
const latestBody = (await readHeart(launch.paths)).latestBody;
|
|
260
|
+
const at = latestBody?.sequence === bodySequence ? (latestBody.hung?.at ?? latestBody.endedAt) : undefined;
|
|
258
261
|
const initiator = latestTurn?.initiator;
|
|
259
262
|
const participants = latestTurn === null ? [] : await readTurnParticipants(launch.paths, latestTurn.sequence);
|
|
260
263
|
await emitPluginSignal({ world, reportDiagnostic }, {
|
|
@@ -262,6 +265,7 @@ function bodyEndEmitter(launch, soul, world) {
|
|
|
262
265
|
akumaId: soul.id,
|
|
263
266
|
bodySequence,
|
|
264
267
|
end,
|
|
268
|
+
...(at === undefined ? {} : { at }),
|
|
265
269
|
...(initiator === undefined ? {} : { initiator }),
|
|
266
270
|
...(participants.length === 0 ? {} : { participants }),
|
|
267
271
|
...(diagnostic === undefined ? {} : { diagnostic }),
|
|
@@ -505,34 +509,35 @@ async function settledWake(paths, tellId, after) {
|
|
|
505
509
|
}
|
|
506
510
|
return null;
|
|
507
511
|
}
|
|
508
|
-
async function awaitWake(paths, input) {
|
|
509
|
-
const { tellId, after, child, schedule, signal } = input;
|
|
510
|
-
try {
|
|
511
|
-
const result = await observeBodyLaunch(child, async () => await settledWake(paths, tellId, after), schedule, signal);
|
|
512
|
-
if (result.kind === "completed")
|
|
513
|
-
return launchEndWake(result.end);
|
|
514
|
-
child.release();
|
|
515
|
-
return result.value;
|
|
516
|
-
}
|
|
517
|
-
catch (error) {
|
|
518
|
-
child.release();
|
|
519
|
-
throw error;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
512
|
async function wakePendingTells(paths, tellId, runtime, signal) {
|
|
523
513
|
try {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
514
|
+
for (;;) {
|
|
515
|
+
signal?.throwIfAborted();
|
|
516
|
+
const before = await readHeart(paths);
|
|
517
|
+
if (tellId === undefined && before.pending.length === 0)
|
|
518
|
+
return null;
|
|
519
|
+
const child = await runtime.spawn(paths);
|
|
520
|
+
try {
|
|
521
|
+
const result = await observeBodyLaunch(child, async () => await settledWake(paths, tellId, before.latestBody?.sequence ?? 0), runtime.schedule ?? abortableDelay, signal);
|
|
522
|
+
if (result.kind === "observed") {
|
|
523
|
+
child.release();
|
|
524
|
+
return result.value;
|
|
525
|
+
}
|
|
526
|
+
const wake = launchEndWake(result.end);
|
|
527
|
+
if (wake.kind !== "held")
|
|
528
|
+
return wake;
|
|
529
|
+
const heart = await readHeart(paths);
|
|
530
|
+
if (tellId !== undefined && !heart.pending.some((tell) => tell.id === tellId))
|
|
531
|
+
return { kind: "told" };
|
|
532
|
+
if (heart.pause !== null ||
|
|
533
|
+
(heart.latestBody !== null && heart.latestBody.end === undefined && (await probeLeash(paths)) === "held"))
|
|
534
|
+
return wake;
|
|
535
|
+
}
|
|
536
|
+
catch (error) {
|
|
537
|
+
child.release();
|
|
538
|
+
throw error;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
536
541
|
}
|
|
537
542
|
catch (error) {
|
|
538
543
|
if (signal?.aborted)
|
|
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import type { WorldRoot } from "../world.js";
|
|
3
3
|
import { type TellFact } from "./heart/index.js";
|
|
4
4
|
import { type AkumaId } from "./identity.js";
|
|
5
|
+
export declare const BIRTH_TIMEOUT_MS = 30000;
|
|
5
6
|
export type CallInitialTell = Readonly<{
|
|
6
7
|
tellId: string;
|
|
7
8
|
body: string;
|
|
@@ -34,8 +35,8 @@ export declare const tellResultSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
34
35
|
}, z.core.$strict>>;
|
|
35
36
|
row: z.ZodReadonly<z.ZodObject<{
|
|
36
37
|
at: z.ZodString;
|
|
37
|
-
sequence: z.ZodNumber;
|
|
38
38
|
text: z.ZodString;
|
|
39
|
+
sequence: z.ZodNumber;
|
|
39
40
|
}, z.core.$strict>>;
|
|
40
41
|
wake: z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
41
42
|
kind: z.ZodLiteral<"told">;
|
|
@@ -70,6 +71,8 @@ export declare const tellResultSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
70
71
|
export type TellWake = z.output<typeof tellWakeSchema>;
|
|
71
72
|
/** The progress receipt carries only the Tell coordinates progress needs; Heart keeps the native row. */
|
|
72
73
|
export type TellResult = z.output<typeof tellResultSchema>;
|
|
74
|
+
/** Freeze known admission before waiting for wake; no later read can replace it. */
|
|
75
|
+
export declare function pendingTellReceipt(tell: TellFact): TellResult;
|
|
73
76
|
export type CallInitialTellAdmission = Readonly<{
|
|
74
77
|
kind: "admitted";
|
|
75
78
|
tell: TellFact;
|
|
@@ -3,7 +3,7 @@ import { tellRowSchema } from "./projection.js";
|
|
|
3
3
|
import { bornStatus, defaultWaitComplete, readWaitComplete, waitForObservation } from "./akuma-observe.js";
|
|
4
4
|
import { recordTell } from "./heart/index.js";
|
|
5
5
|
import { pathsForAkumaId } from "./identity.js";
|
|
6
|
-
|
|
6
|
+
export const BIRTH_TIMEOUT_MS = 30_000;
|
|
7
7
|
export const tellWakeSchema = z.union([
|
|
8
8
|
z.strictObject({ kind: z.literal("told") }).readonly(),
|
|
9
9
|
z.strictObject({ kind: z.literal("held") }).readonly(),
|
|
@@ -41,6 +41,14 @@ export const tellResultSchema = z
|
|
|
41
41
|
.exactOptional(),
|
|
42
42
|
})
|
|
43
43
|
.readonly();
|
|
44
|
+
/** Freeze known admission before waiting for wake; no later read can replace it. */
|
|
45
|
+
export function pendingTellReceipt(tell) {
|
|
46
|
+
return {
|
|
47
|
+
admission: { tellId: tell.id },
|
|
48
|
+
row: { sequence: tell.sequence, at: tell.recordedAt, text: tell.body },
|
|
49
|
+
wake: { kind: "pursuing" },
|
|
50
|
+
};
|
|
51
|
+
}
|
|
44
52
|
export async function admitCallInitialTell(input) {
|
|
45
53
|
const paths = pathsForAkumaId(input.world, input.id);
|
|
46
54
|
const birth = await waitForObservation({
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const durationSchema: z.ZodNumber;
|
|
3
|
+
export declare function validateTellObservation(input: Readonly<{
|
|
4
|
+
wait?: unknown;
|
|
5
|
+
timeoutMs?: unknown;
|
|
6
|
+
}>): void;
|
|
7
|
+
/** Native input errors stay caller errors; invocation translates its own schema errors to usage. */
|
|
8
|
+
export declare function validateAkumaInput<S extends z.ZodType>(schema: S, input: unknown): z.output<S>;
|
|
1
9
|
export declare function bareOption(value: unknown): boolean | undefined;
|
|
2
|
-
export declare function writableDirectoriesOption(value: unknown): Promise<readonly string[]>;
|
|
3
10
|
export declare function canonicalBirthCwd(input: string, diagnostic?: string): Promise<string>;
|
|
@@ -1,25 +1,34 @@
|
|
|
1
|
+
import { KeiyakuError } from "../errors.js";
|
|
1
2
|
import { realpath, stat } from "node:fs/promises";
|
|
2
|
-
import {
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
const durationDiagnostic = "timeoutMs must be a nonnegative finite millisecond duration";
|
|
6
|
+
export const durationSchema = z
|
|
7
|
+
.number({ error: durationDiagnostic })
|
|
8
|
+
.nonnegative({ error: durationDiagnostic })
|
|
9
|
+
.multipleOf(1, { error: durationDiagnostic });
|
|
10
|
+
const tellObservationSchema = z.union([
|
|
11
|
+
z.strictObject({ wait: z.literal(true), timeoutMs: durationSchema.max(Number.MAX_SAFE_INTEGER).exactOptional() }),
|
|
12
|
+
z.strictObject({ wait: z.literal(false).exactOptional() }),
|
|
13
|
+
]);
|
|
14
|
+
export function validateTellObservation(input) {
|
|
15
|
+
validateAkumaInput(tellObservationSchema, {
|
|
16
|
+
...(input.wait === undefined ? {} : { wait: input.wait }),
|
|
17
|
+
...(input.timeoutMs === undefined ? {} : { timeoutMs: input.timeoutMs }),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** Native input errors stay caller errors; invocation translates its own schema errors to usage. */
|
|
21
|
+
export function validateAkumaInput(schema, input) {
|
|
22
|
+
const parsed = schema.safeParse(input);
|
|
23
|
+
if (!parsed.success)
|
|
24
|
+
throw new KeiyakuError("invalid-input", parsed.error.message);
|
|
25
|
+
return parsed.data;
|
|
26
|
+
}
|
|
3
27
|
export function bareOption(value) {
|
|
4
28
|
if (value !== undefined && typeof value !== "boolean")
|
|
5
|
-
throw new
|
|
29
|
+
throw new KeiyakuError("invalid-input", "bare must be a boolean");
|
|
6
30
|
return value;
|
|
7
31
|
}
|
|
8
|
-
export async function writableDirectoriesOption(value) {
|
|
9
|
-
if (value === undefined)
|
|
10
|
-
return [];
|
|
11
|
-
if (!Array.isArray(value))
|
|
12
|
-
throw new TypeError("writableDirectories must be an array of canonical directories");
|
|
13
|
-
const directories = await Promise.all(value.map(async (path) => {
|
|
14
|
-
if (typeof path !== "string" || path.trim() === "" || !isAbsolute(path))
|
|
15
|
-
throw new TypeError("writableDirectories must contain nonblank canonical absolute directories");
|
|
16
|
-
const canonical = await canonicalBirthCwd(path);
|
|
17
|
-
if (canonical !== path)
|
|
18
|
-
throw new TypeError(`writableDirectories path is not canonical: ${path}`);
|
|
19
|
-
return canonical;
|
|
20
|
-
}));
|
|
21
|
-
return Object.freeze([...new Set(directories)]);
|
|
22
|
-
}
|
|
23
32
|
export async function canonicalBirthCwd(input, diagnostic = `cwd is not an existing directory: ${input}`) {
|
|
24
33
|
const selected = resolve(input);
|
|
25
34
|
try {
|
|
@@ -29,6 +38,6 @@ export async function canonicalBirthCwd(input, diagnostic = `cwd is not an exist
|
|
|
29
38
|
return canonical;
|
|
30
39
|
}
|
|
31
40
|
catch {
|
|
32
|
-
throw new
|
|
41
|
+
throw new KeiyakuError("invalid-input", diagnostic);
|
|
33
42
|
}
|
|
34
43
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KeiyakuError } from "../errors.js";
|
|
1
2
|
import { isAbsolute, resolve } from "node:path";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { akumaIdSchema } from "./identity.js";
|
|
@@ -44,7 +45,7 @@ export function decodeAkumaCaller(value) {
|
|
|
44
45
|
return undefined;
|
|
45
46
|
const parsed = retainedCallerSchema.safeParse(value);
|
|
46
47
|
if (!parsed.success)
|
|
47
|
-
throw new
|
|
48
|
+
throw new KeiyakuError("invalid-input", `Invalid Akuma caller: ${parsed.error.message}`);
|
|
48
49
|
return parsed.data;
|
|
49
50
|
}
|
|
50
51
|
/** One stable comparison coordinate for stored and queried caller attribution. */
|
|
@@ -46,7 +46,7 @@ async function diagnoseSpawnEnoent(input, cause) {
|
|
|
46
46
|
if (noCwd)
|
|
47
47
|
remedies.push("a missing execution directory likely means its Contract was accepted and the worktree cleaned up, with deliverables already in Git");
|
|
48
48
|
if (noExecutable)
|
|
49
|
-
remedies.push("a missing executable likely means the host removed the running process binary:
|
|
49
|
+
remedies.push("a missing executable likely means the host removed the running process binary: restart the host process and retry");
|
|
50
50
|
const remedy = `kill this Akuma and spawn a fresh one; ${remedies.join("; ")}`;
|
|
51
51
|
const error = new Error(`Body spawn failed: ${missing.join(" and ")}; ${remedy}`, { cause });
|
|
52
52
|
error.code = "ENOENT";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { AkumaCaller } from "../caller.js";
|
|
2
|
+
import { KeiyakuError } from "../../errors.js";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { type AkumaId } from "../identity.js";
|
|
4
5
|
import type { ResumeCoordinate } from "../coordinate.js";
|
|
5
6
|
import type { ProviderExecution, ProviderOptions } from "../provider-recipe.js";
|
|
6
7
|
export type { ResumeCoordinate } from "../coordinate.js";
|
|
7
|
-
export declare class HeartAuthorityCorruptionError extends
|
|
8
|
+
export declare class HeartAuthorityCorruptionError extends KeiyakuError {
|
|
8
9
|
constructor(message: string, options?: ErrorOptions);
|
|
9
10
|
}
|
|
10
11
|
export declare const akumaOriginSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -155,7 +156,7 @@ export type TellRow = Readonly<{
|
|
|
155
156
|
deliveries: readonly TellDelivery[];
|
|
156
157
|
}>;
|
|
157
158
|
export declare function projectTell(fact: TellFact): TellRow;
|
|
158
|
-
export declare class AkumaBusyError extends
|
|
159
|
+
export declare class AkumaBusyError extends KeiyakuError {
|
|
159
160
|
readonly kind = "akuma-busy";
|
|
160
161
|
constructor();
|
|
161
162
|
}
|
|
@@ -182,10 +183,10 @@ export type TellReceiptInput = Readonly<{
|
|
|
182
183
|
fence: string;
|
|
183
184
|
}>);
|
|
184
185
|
export declare const killEvidenceSchema: z.ZodEnum<{
|
|
185
|
-
killed: "killed";
|
|
186
|
-
hung: "hung";
|
|
187
186
|
unavailable: "unavailable";
|
|
187
|
+
hung: "hung";
|
|
188
188
|
untidy: "untidy";
|
|
189
|
+
killed: "killed";
|
|
189
190
|
"already-killed": "already-killed";
|
|
190
191
|
"already-stopped": "already-stopped";
|
|
191
192
|
}>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { KeiyakuError } from "../../errors.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { akumaIdSchema } from "../identity.js";
|
|
3
|
-
export class HeartAuthorityCorruptionError extends
|
|
4
|
+
export class HeartAuthorityCorruptionError extends KeiyakuError {
|
|
4
5
|
constructor(message, options) {
|
|
5
|
-
super(message, options);
|
|
6
|
+
super("authority-corruption", message, options);
|
|
6
7
|
this.name = "HeartAuthorityCorruptionError";
|
|
7
8
|
}
|
|
8
9
|
}
|
|
@@ -37,11 +38,10 @@ export function projectTell(fact) {
|
|
|
37
38
|
deliveries: fact.deliveries,
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
|
-
export class AkumaBusyError extends
|
|
41
|
+
export class AkumaBusyError extends KeiyakuError {
|
|
41
42
|
kind = "akuma-busy";
|
|
42
43
|
constructor() {
|
|
43
|
-
super("Akuma is busy");
|
|
44
|
-
this.name = "AkumaBusyError";
|
|
44
|
+
super("internal", "Akuma is busy");
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
export const killEvidenceSchema = z.enum([
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { decodeAkumaCaller } from "../caller.js";
|
|
2
2
|
import { parseAkumaId } from "../identity.js";
|
|
3
3
|
import { decodeProviderOptions, decodeProviderRecipe } from "../provider-recipe.js";
|
|
4
|
-
import { akumaOriginSchema } from "./facts.js";
|
|
4
|
+
import { akumaOriginSchema, HeartAuthorityCorruptionError } from "./facts.js";
|
|
5
5
|
function record(value) {
|
|
6
6
|
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
7
7
|
? value
|
|
@@ -70,8 +70,24 @@ export function encodeSoul(soul) {
|
|
|
70
70
|
export function encodeSoulRow(soul) {
|
|
71
71
|
return [encodeSoul(soul)];
|
|
72
72
|
}
|
|
73
|
+
function storedSoulJson(row) {
|
|
74
|
+
try {
|
|
75
|
+
return JSON.parse(row.soul_json);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
throw new HeartAuthorityCorruptionError(error instanceof Error ? error.message : String(error), { cause: error });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function decodeStoredSoul(value) {
|
|
82
|
+
try {
|
|
83
|
+
return decodeSoul(value);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw new HeartAuthorityCorruptionError(error instanceof Error ? error.message : String(error), { cause: error });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
73
89
|
export function decodeSoulRow(row) {
|
|
74
|
-
return
|
|
90
|
+
return decodeStoredSoul(storedSoulJson(row));
|
|
75
91
|
}
|
|
76
92
|
export function soulFact(database) {
|
|
77
93
|
const row = database.prepare("SELECT soul_json FROM soul WHERE singleton = 1").get();
|
|
@@ -92,8 +108,8 @@ export function setSoulModel(database, model) {
|
|
|
92
108
|
const row = database.prepare("SELECT soul_json FROM soul WHERE singleton = 1").get();
|
|
93
109
|
if (row === undefined)
|
|
94
110
|
throw new Error("Akuma soul is absent");
|
|
95
|
-
const raw =
|
|
96
|
-
|
|
111
|
+
const raw = storedSoulJson(row);
|
|
112
|
+
decodeStoredSoul(raw);
|
|
97
113
|
const soul = record(raw);
|
|
98
114
|
const options = record(soul.options);
|
|
99
115
|
if (options === null)
|
|
@@ -5,7 +5,7 @@ export type AkumaId = string & {
|
|
|
5
5
|
};
|
|
6
6
|
export declare function parsePublicHistoryId(value: string): number | null;
|
|
7
7
|
export declare function parseExactHistorySelector(value: string): Readonly<{
|
|
8
|
-
kind: "turn" | "report";
|
|
8
|
+
kind: "turn" | "report" | "activity";
|
|
9
9
|
sequence: number;
|
|
10
10
|
}> | null;
|
|
11
11
|
export declare const turnHistoryIdSchema: z.ZodTemplateLiteral<`turn/${number}`>;
|