@astrosheep/keiyaku 4.6.31 → 4.6.33
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 +42 -23
- package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +24 -15
- package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +12 -8
- 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 +6 -4
- package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +24 -15
- package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +12 -8
- 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 +6 -4
- package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +24 -15
- package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +12 -8
- 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 +6 -4
- package/build/plugins/pi/README.md +53 -97
- package/build/plugins/pi/keiyaku.ts +10 -6
- package/build/skills/keiyaku-akuma/SKILL.md +24 -15
- package/build/skills/keiyaku-babysit/SKILL.md +12 -8
- 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 +6 -4
- 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 +50 -303
- package/build/src/akuma/akuma-instance.js +48 -49
- package/build/src/akuma/akuma-observe.d.ts +5 -4
- package/build/src/akuma/akuma-observe.js +74 -21
- 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 +97 -19
- package/build/src/akuma/akuma-selection-execution.js +79 -133
- package/build/src/akuma/akuma-wait.d.ts +43 -4
- package/build/src/akuma/akuma-wait.js +58 -29
- package/build/src/akuma/akuma.d.ts +58 -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 +44 -44
- package/build/src/akuma/call-initial-tell.d.ts +4 -2
- package/build/src/akuma/call-initial-tell.js +9 -2
- 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/activity-schema.d.ts +16 -0
- package/build/src/akuma/heart/activity-schema.js +7 -0
- package/build/src/akuma/heart/facts.d.ts +5 -4
- package/build/src/akuma/heart/facts.js +5 -5
- package/build/src/akuma/heart/index.d.ts +1 -1
- package/build/src/akuma/heart/index.js +9 -1
- package/build/src/akuma/heart/soul.js +20 -4
- package/build/src/akuma/heart/timeline.js +4 -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-read.d.ts +4 -2
- package/build/src/akuma/projection-read.js +21 -14
- package/build/src/akuma/projection.d.ts +97 -2
- package/build/src/akuma/projection.js +47 -47
- package/build/src/akuma/provider-recipe.js +3 -2
- package/build/src/akuma/provider.d.ts +2 -2
- package/build/src/akuma/provider.js +27 -20
- package/build/src/akuma/providers/acp/config.js +11 -10
- package/build/src/akuma/providers/acp/core.js +2 -5
- 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/opencode-sdk/events.d.ts +2 -1
- package/build/src/akuma/providers/opencode-sdk/events.js +31 -1
- 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 +19 -16
- 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 +304 -240
- package/build/src/akuma/selection-observation.js +135 -70
- package/build/src/akuma/status-projection.d.ts +61 -284
- package/build/src/akuma/status-projection.js +216 -138
- package/build/src/akuma/turn-drive.js +21 -15
- package/build/src/body/amend.js +7 -18
- package/build/src/body/arc.js +3 -2
- package/build/src/body/criteria.js +4 -3
- package/build/src/body/decode.js +13 -2
- package/build/src/body/envelope.d.ts +5 -1
- package/build/src/body/envelope.js +6 -3
- package/build/src/body/region.d.ts +1 -3
- package/build/src/body/region.js +3 -8
- package/build/src/body/render.js +4 -6
- 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 +107 -66
- package/build/src/cli/commands/akuma-grammar.js +66 -104
- package/build/src/cli/commands/akuma.d.ts +7 -3
- package/build/src/cli/commands/akuma.js +49 -160
- package/build/src/cli/commands/contract-grammar.d.ts +4 -135
- package/build/src/cli/commands/contract-grammar.js +126 -223
- package/build/src/cli/commands/contract-help.d.ts +26 -22
- package/build/src/cli/commands/contract-help.js +52 -38
- package/build/src/cli/commands/contract.d.ts +6 -18
- package/build/src/cli/commands/contract.js +68 -272
- package/build/src/cli/commands/debt-grammar.d.ts +2 -4
- package/build/src/cli/commands/debt-grammar.js +23 -193
- 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 -19
- package/build/src/cli/render/akuma-activity.d.ts +18 -35
- package/build/src/cli/render/akuma-activity.js +141 -290
- package/build/src/cli/render/akuma.d.ts +2 -8
- package/build/src/cli/render/akuma.js +50 -65
- package/build/src/cli/render/catalog.d.ts +2 -5
- package/build/src/cli/render/catalog.js +3 -37
- package/build/src/cli/render/contract-history.js +3 -2
- package/build/src/cli/render/contract-observation.d.ts +2 -8
- package/build/src/cli/render/contract-observation.js +25 -4
- package/build/src/cli/render/contract-wait.d.ts +2 -2
- package/build/src/cli/render/contract-wait.js +13 -17
- package/build/src/cli/render/contract.d.ts +7 -9
- package/build/src/cli/render/contract.js +46 -72
- package/build/src/cli/render/debt.d.ts +3 -11
- package/build/src/cli/render/debt.js +17 -89
- package/build/src/cli/render/delivery-preview.js +4 -4
- package/build/src/cli/render/execution-progress.js +1 -3
- package/build/src/cli/render/kanshi-akuma.d.ts +5 -3
- package/build/src/cli/render/kanshi-akuma.js +23 -20
- package/build/src/cli/render/kanshi.d.ts +1 -3
- package/build/src/cli/render/kanshi.js +27 -56
- package/build/src/cli/render/receipt.d.ts +21 -12
- package/build/src/cli/render/receipt.js +78 -68
- package/build/src/cli/render/reconcile.js +2 -5
- package/build/src/cli/render/refusal.d.ts +4 -3
- package/build/src/cli/render/refusal.js +17 -22
- package/build/src/cli/render/settings.d.ts +1 -1
- package/build/src/cli/render/terminal.d.ts +11 -12
- package/build/src/cli/render/terminal.js +53 -44
- package/build/src/cli/render/verbs.d.ts +4 -1
- package/build/src/cli/render/verbs.js +88 -128
- package/build/src/cli/runtime.js +65 -70
- 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 +16 -25
- package/build/src/core/facts/eligibility.d.ts +4 -4
- package/build/src/core/facts/eligibility.js +11 -0
- package/build/src/core/facts/errors.d.ts +2 -1
- package/build/src/core/facts/errors.js +3 -3
- package/build/src/core/facts/fold.js +9 -5
- package/build/src/core/facts/gate.d.ts +5 -1
- package/build/src/core/facts/gate.js +14 -10
- package/build/src/core/facts/types.d.ts +7 -14
- package/build/src/core/facts/types.js +8 -6
- package/build/src/core/subject.d.ts +4 -1
- package/build/src/core/subject.js +10 -2
- package/build/src/core/verbs/abandon.d.ts +1 -2
- package/build/src/core/verbs/amend.d.ts +16 -6
- package/build/src/core/verbs/amend.js +19 -9
- 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 -220
- package/build/src/debt/index.js +61 -115
- package/build/src/debt/input.d.ts +21 -6
- package/build/src/debt/input.js +56 -180
- 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/dispatch/index.d.ts +0 -17
- package/build/src/dispatch/index.js +1 -10
- 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/identity.js +16 -45
- package/build/src/git/nuke.js +13 -23
- package/build/src/git/observe.d.ts +6 -0
- package/build/src/git/observe.js +40 -24
- package/build/src/git/process.js +11 -18
- package/build/src/git/read-observation.d.ts +5 -4
- package/build/src/git/reconcile.d.ts +3 -16
- package/build/src/git/reconcile.js +0 -18
- package/build/src/git/repository.d.ts +4 -1
- package/build/src/git/repository.js +16 -4
- package/build/src/git/scratch.js +2 -14
- 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/git/terminal-reconcile.js +1 -13
- 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 +36 -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 +21 -7
- package/build/src/kanshi/index.js +29 -4
- package/build/src/kanshi/read.d.ts +101 -269
- package/build/src/kanshi/read.js +41 -200
- package/build/src/kanshi/report.d.ts +443 -1628
- package/build/src/kanshi/report.js +19 -31
- package/build/src/library/address.d.ts +20 -13
- package/build/src/library/address.js +48 -55
- package/build/src/library/akuma-creation.d.ts +249 -79
- package/build/src/library/akuma-creation.js +200 -247
- 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 +151 -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 +35 -37
- package/build/src/library/contract-outcomes.d.ts +1349 -806
- package/build/src/library/contract-outcomes.js +12 -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 +60 -67
- package/build/src/library/contract-types.js +17 -56
- package/build/src/library/contract-wait.d.ts +47 -3
- package/build/src/library/contract-wait.js +81 -70
- package/build/src/library/delivery.d.ts +391 -389
- package/build/src/library/delivery.js +5 -25
- package/build/src/library/input.d.ts +13 -5
- package/build/src/library/input.js +43 -38
- 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 +484 -25
- 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 +43 -62
- 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 +9 -159
- package/build/src/library/keiyaku-identity.d.ts +3 -3
- package/build/src/library/keiyaku-identity.js +16 -10
- package/build/src/library/keiyaku-verbs.d.ts +4102 -4889
- package/build/src/library/keiyaku-verbs.js +317 -291
- package/build/src/library/keiyaku-wait.d.ts +183 -0
- package/build/src/library/keiyaku-wait.js +213 -0
- package/build/src/library/keiyaku.d.ts +32 -860
- package/build/src/library/keiyaku.js +203 -314
- package/build/src/library/model-tools.d.ts +556 -0
- package/build/src/library/model-tools.js +347 -0
- 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 +166 -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 +45 -29
- package/build/src/library/refusal.js +5 -16
- package/build/src/library/repo.js +4 -3
- package/build/src/library/selection.d.ts +44 -21
- package/build/src/library/selection.js +63 -88
- package/build/src/mcp/adapter.js +37 -51
- package/build/src/mcp/description.d.ts +2 -0
- package/build/src/mcp/description.js +2 -0
- package/build/src/mcp/help.d.ts +1 -1
- package/build/src/mcp/help.js +16 -9
- package/build/src/pi/index.d.ts +3 -0
- package/build/src/pi/index.js +83 -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 +15 -4
- package/build/src/protocol/amend.js +114 -47
- package/build/src/protocol/bind.d.ts +5 -7
- package/build/src/protocol/bind.js +8 -19
- package/build/src/protocol/completion.d.ts +188 -195
- package/build/src/protocol/completion.js +63 -24
- package/build/src/protocol/deliver.d.ts +11 -6
- package/build/src/protocol/deliver.js +37 -50
- package/build/src/protocol/delivery-preview.d.ts +18 -11
- package/build/src/protocol/delivery-preview.js +2 -2
- package/build/src/protocol/execution-observation.d.ts +13 -13
- package/build/src/protocol/intent.d.ts +7 -9
- package/build/src/protocol/intent.js +22 -32
- package/build/src/protocol/operations.d.ts +102 -69
- package/build/src/protocol/operations.js +33 -56
- package/build/src/protocol/outcome.d.ts +3 -1
- package/build/src/protocol/placement.d.ts +1 -2
- package/build/src/protocol/placement.js +7 -1
- package/build/src/protocol/progress.d.ts +1 -0
- package/build/src/protocol/progress.js +0 -6
- package/build/src/protocol/read/status.d.ts +69 -112
- package/build/src/protocol/read/status.js +59 -88
- package/build/src/protocol/reintegrate.d.ts +1 -2
- package/build/src/protocol/reintegrate.js +2 -3
- package/build/src/protocol/result-leaves.d.ts +67 -40
- package/build/src/protocol/result-leaves.js +28 -58
- package/build/src/protocol/result-reasons.d.ts +6 -6
- package/build/src/protocol/review.js +0 -1
- package/build/src/protocol/run.js +1 -4
- package/build/src/protocol/verify.d.ts +202 -146
- package/build/src/protocol/verify.js +61 -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 +19 -72
- 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 +7 -3
- 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 +53 -97
- package/plugins/pi/keiyaku.ts +10 -6
- package/skills/keiyaku-akuma/SKILL.md +24 -15
- package/skills/keiyaku-babysit/SKILL.md +12 -8
- package/skills/keiyaku-bind/SKILL.md +4 -3
- package/skills/keiyaku-debt/SKILL.md +17 -17
- package/skills/keiyaku-workflow/SKILL.md +6 -4
- package/build/plugins/pi/akuma-tools.ts +0 -290
- 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/body/keys.d.ts +0 -4
- package/build/src/body/keys.js +0 -11
- 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/kanshi/roster.d.ts +0 -2
- package/build/src/kanshi/roster.js +0 -2
- 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
- package/plugins/pi/akuma-tools.ts +0 -290
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import { KeiyakuError } from "../errors.js";
|
|
1
2
|
import { z } from "zod";
|
|
3
|
+
import { durationSchema, validateAkumaInput, validateTellObservation } from "./call-input.js";
|
|
2
4
|
import { akumaStatusSchema } from "./akuma.js";
|
|
3
5
|
import { emitPluginSignal, outcomePluginObserver, stderrPluginDiagnostic, withAkumaWaitDeferrals, } from "../plugin/akuma-signals.js";
|
|
4
6
|
import { abortable } from "./abort.js";
|
|
5
7
|
import { admitAkumaCall } from "./akuma-call.js";
|
|
6
8
|
import { defaultWaitComplete } from "./akuma-observe.js";
|
|
7
9
|
import { AkumaOwner } from "./akuma-owner.js";
|
|
8
|
-
import {
|
|
10
|
+
import { executeAskAkuma, executeTellAkuma } from "./akuma-selection-execution.js";
|
|
9
11
|
import { captureAkumaHost } from "../body-host.js";
|
|
10
12
|
import { parseAkumaId } from "./identity.js";
|
|
11
|
-
import {
|
|
13
|
+
import { projectCurrentWork } from "./status-projection.js";
|
|
14
|
+
import { canonicalDocument } from "./schema.js";
|
|
12
15
|
export const akumaIdleResultSchema = z
|
|
13
16
|
.strictObject({ reason: z.enum(["completed", "deadline"]), status: akumaStatusSchema })
|
|
14
17
|
.readonly();
|
|
@@ -24,7 +27,7 @@ function signalOption(value) {
|
|
|
24
27
|
if (value === undefined)
|
|
25
28
|
return undefined;
|
|
26
29
|
if (!(value instanceof AbortSignal))
|
|
27
|
-
throw new
|
|
30
|
+
throw new KeiyakuError("invalid-input", "signal must be an AbortSignal");
|
|
28
31
|
return value;
|
|
29
32
|
}
|
|
30
33
|
class AkumaHandle {
|
|
@@ -44,64 +47,64 @@ class AkumaHandle {
|
|
|
44
47
|
}
|
|
45
48
|
async tell(text, options = {}) {
|
|
46
49
|
if (typeof text !== "string")
|
|
47
|
-
throw new
|
|
50
|
+
throw new KeiyakuError("invalid-input", "Akuma tell text must be a string");
|
|
48
51
|
if (typeof options !== "object" || options === null || Array.isArray(options))
|
|
49
|
-
throw new
|
|
52
|
+
throw new KeiyakuError("invalid-input", "Akuma tell options must be an object");
|
|
50
53
|
if ("schema" in options)
|
|
51
|
-
throw new
|
|
52
|
-
const unknown = Object.keys(options).find((key) => !["interrupt", "initiator", "signal"].includes(key));
|
|
54
|
+
throw new KeiyakuError("invalid-input", "Akuma tell does not accept schema; use ask");
|
|
55
|
+
const unknown = Object.keys(options).find((key) => !["interrupt", "initiator", "signal", "timeoutMs", "wait"].includes(key));
|
|
53
56
|
if (unknown !== undefined)
|
|
54
|
-
throw new
|
|
57
|
+
throw new KeiyakuError("invalid-input", `Akuma tell options has unknown field: ${unknown}`);
|
|
58
|
+
validateTellObservation(options);
|
|
55
59
|
const signal = signalOption(options.signal);
|
|
56
60
|
signal?.throwIfAborted();
|
|
57
|
-
|
|
61
|
+
const input = {
|
|
62
|
+
...options,
|
|
58
63
|
spawn: this.spawn,
|
|
59
64
|
path: this.root,
|
|
60
65
|
id: this.id,
|
|
61
66
|
body: text,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
outcomeObserved: outcomePluginObserver({ world: this.root, reportDiagnostic: this.reportDiagnostic }),
|
|
68
|
+
};
|
|
69
|
+
return options.wait === true
|
|
70
|
+
? await withAkumaWaitDeferrals({ world: this.root, reportDiagnostic: this.reportDiagnostic }, { akumaIds: [this.id] }, signal, async () => await executeTellAkuma(input))
|
|
71
|
+
: await executeTellAkuma(input);
|
|
66
72
|
}
|
|
67
|
-
async ask(text, options
|
|
73
|
+
async ask(text, options) {
|
|
68
74
|
if (typeof text !== "string")
|
|
69
|
-
throw new
|
|
75
|
+
throw new KeiyakuError("invalid-input", "Akuma ask text must be a string");
|
|
70
76
|
if (typeof options !== "object" || options === null || Array.isArray(options))
|
|
71
|
-
throw new
|
|
77
|
+
throw new KeiyakuError("invalid-input", "Akuma ask options must be an object");
|
|
72
78
|
const unknown = Object.keys(options).find((key) => !["schema", "timeoutMs", "interrupt", "initiator", "signal"].includes(key));
|
|
73
79
|
if (unknown !== undefined)
|
|
74
|
-
throw new
|
|
75
|
-
|
|
76
|
-
(!Number.isFinite(options.timeoutMs) || !Number.isInteger(options.timeoutMs) || options.timeoutMs < 0))
|
|
77
|
-
throw new TypeError("Akuma ask timeoutMs must be a nonnegative finite millisecond duration");
|
|
80
|
+
throw new KeiyakuError("invalid-input", `Akuma ask options has unknown field: ${unknown}`);
|
|
81
|
+
validateAkumaInput(durationSchema.optional(), options.timeoutMs);
|
|
78
82
|
const signal = signalOption(options.signal);
|
|
79
83
|
signal?.throwIfAborted();
|
|
80
|
-
const schema =
|
|
84
|
+
const schema = canonicalDocument(options.schema);
|
|
81
85
|
return await withAkumaWaitDeferrals({ world: this.root, reportDiagnostic: this.reportDiagnostic }, { akumaIds: [this.id] }, signal, async () => {
|
|
82
|
-
|
|
86
|
+
return await executeAskAkuma({
|
|
83
87
|
spawn: this.spawn,
|
|
84
88
|
path: this.root,
|
|
85
89
|
id: this.id,
|
|
86
90
|
outcomeObserved: outcomePluginObserver({ world: this.root, reportDiagnostic: this.reportDiagnostic }),
|
|
87
91
|
body: text,
|
|
88
92
|
...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
|
|
89
|
-
|
|
93
|
+
schemaJson: schema.jsonText,
|
|
90
94
|
...(options.interrupt === true ? { interrupt: true } : {}),
|
|
91
95
|
...(options.initiator === undefined ? {} : { initiator: options.initiator }),
|
|
92
96
|
...(signal === undefined ? {} : { signal }),
|
|
93
97
|
});
|
|
94
|
-
return (schema === undefined ? result : decodeAskObservation(result, schema));
|
|
95
98
|
});
|
|
96
99
|
}
|
|
97
100
|
async report(text, options = {}) {
|
|
98
101
|
if (typeof text !== "string" || text.trim() === "")
|
|
99
|
-
throw new
|
|
102
|
+
throw new KeiyakuError("invalid-input", "Akuma report text must be nonblank");
|
|
100
103
|
if (typeof options !== "object" || options === null || Array.isArray(options))
|
|
101
|
-
throw new
|
|
104
|
+
throw new KeiyakuError("invalid-input", "Akuma report options must be an object");
|
|
102
105
|
const unknown = Object.keys(options).find((key) => !["signal"].includes(key));
|
|
103
106
|
if (unknown !== undefined)
|
|
104
|
-
throw new
|
|
107
|
+
throw new KeiyakuError("invalid-input", `Akuma report options has unknown field: ${unknown}`);
|
|
105
108
|
const signal = signalOption(options.signal);
|
|
106
109
|
const result = await this.owner().report({ text, at: new Date().toISOString() }, signal);
|
|
107
110
|
if (result.kind !== "recorded")
|
|
@@ -120,37 +123,34 @@ class AkumaHandle {
|
|
|
120
123
|
return { kind: "recorded", reportId: `report/${report.sequence}` };
|
|
121
124
|
}
|
|
122
125
|
async status() {
|
|
123
|
-
|
|
126
|
+
const { timeline, ...status } = await this.owner(true).status();
|
|
127
|
+
return { ...status, work: projectCurrentWork(timeline) };
|
|
124
128
|
}
|
|
125
129
|
async idle(options = {}) {
|
|
126
130
|
if (typeof options !== "object" || options === null || Array.isArray(options)) {
|
|
127
|
-
throw new
|
|
131
|
+
throw new KeiyakuError("invalid-input", "Akuma idle options must be an object");
|
|
128
132
|
}
|
|
129
133
|
const unknown = Object.keys(options).find((key) => key !== "timeoutMs" && key !== "signal");
|
|
130
134
|
if (unknown !== undefined)
|
|
131
|
-
throw new
|
|
132
|
-
|
|
133
|
-
throw new TypeError("Akuma idle timeoutMs must be a nonnegative finite millisecond duration");
|
|
134
|
-
}
|
|
135
|
+
throw new KeiyakuError("invalid-input", `Akuma idle options has unknown field: ${unknown}`);
|
|
136
|
+
validateAkumaInput(durationSchema.optional(), options.timeoutMs);
|
|
135
137
|
const signal = signalOption(options.signal);
|
|
136
138
|
return await withAkumaWaitDeferrals({ world: this.root, reportDiagnostic: this.reportDiagnostic }, { akumaIds: [this.id] }, signal, async () => {
|
|
137
139
|
const waited = await this.owner(true).waitReceipt(defaultWaitComplete, {
|
|
138
140
|
...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
|
|
139
141
|
...(signal === undefined ? {} : { signal }),
|
|
140
142
|
});
|
|
141
|
-
|
|
143
|
+
const { timeline, ...status } = waited.status;
|
|
144
|
+
return { reason: waited.reason, status: { ...status, work: projectCurrentWork(timeline) } };
|
|
142
145
|
});
|
|
143
146
|
}
|
|
144
147
|
async history(options = {}) {
|
|
145
148
|
if (typeof options !== "object" || options === null || Array.isArray(options)) {
|
|
146
|
-
throw new
|
|
149
|
+
throw new KeiyakuError("invalid-input", "Akuma history options must be an object");
|
|
147
150
|
}
|
|
148
151
|
const unknown = Object.keys(options).find((key) => !["before", "since", "limit"].includes(key));
|
|
149
152
|
if (unknown !== undefined)
|
|
150
|
-
throw new
|
|
151
|
-
if (options.before !== undefined && options.since !== undefined) {
|
|
152
|
-
throw new TypeError("Akuma history before and since are mutually exclusive");
|
|
153
|
-
}
|
|
153
|
+
throw new KeiyakuError("invalid-input", `Akuma history options has unknown field: ${unknown}`);
|
|
154
154
|
return (await this.owner(true).history({
|
|
155
155
|
...(options.before === undefined ? {} : { before: options.before }),
|
|
156
156
|
...(options.since === undefined ? {} : { since: options.since }),
|
|
@@ -159,17 +159,17 @@ class AkumaHandle {
|
|
|
159
159
|
}
|
|
160
160
|
stream(options = {}) {
|
|
161
161
|
if (typeof options !== "object" || options === null || Array.isArray(options)) {
|
|
162
|
-
throw new
|
|
162
|
+
throw new KeiyakuError("invalid-input", "Akuma stream options must be an object");
|
|
163
163
|
}
|
|
164
164
|
const unknown = Object.keys(options).find((key) => key !== "signal");
|
|
165
165
|
if (unknown !== undefined)
|
|
166
|
-
throw new
|
|
166
|
+
throw new KeiyakuError("invalid-input", `Akuma stream options has unknown field: ${unknown}`);
|
|
167
167
|
const signal = signalOption(options.signal);
|
|
168
168
|
return this.owner(true).stream(signal === undefined ? {} : { signal });
|
|
169
169
|
}
|
|
170
170
|
async kill(options = {}) {
|
|
171
171
|
if (typeof options !== "object" || options === null || Array.isArray(options)) {
|
|
172
|
-
throw new
|
|
172
|
+
throw new KeiyakuError("invalid-input", "Akuma kill options must be an object");
|
|
173
173
|
}
|
|
174
174
|
const signal = signalOption(options.signal);
|
|
175
175
|
signal?.throwIfAborted();
|
|
@@ -182,13 +182,13 @@ export class Akuma extends AkumaHandle {
|
|
|
182
182
|
}
|
|
183
183
|
static async birth(akumaName, input) {
|
|
184
184
|
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
185
|
-
throw new
|
|
185
|
+
throw new KeiyakuError("invalid-input", "Akuma birth input must be an object");
|
|
186
186
|
}
|
|
187
|
-
const unknown = Object.keys(input).find((key) => !["root", "cwd", "home", "settings", "
|
|
187
|
+
const unknown = Object.keys(input).find((key) => !["root", "cwd", "home", "settings", "bare", "caller", "initiator", "host"].includes(key));
|
|
188
188
|
if (unknown !== undefined)
|
|
189
|
-
throw new
|
|
189
|
+
throw new KeiyakuError("invalid-input", `Akuma birth input has unknown field: ${unknown}`);
|
|
190
190
|
if (typeof input.root !== "string")
|
|
191
|
-
throw new
|
|
191
|
+
throw new KeiyakuError("invalid-input", "Akuma birth root must be a WorldRoot");
|
|
192
192
|
const { spawn, reportDiagnostic = stderrPluginDiagnostic } = captureAkumaHost(input.host);
|
|
193
193
|
const admitted = await admitAkumaCall(input.root, {
|
|
194
194
|
...(input.home === undefined ? {} : { home: input.home }),
|
|
@@ -196,7 +196,6 @@ export class Akuma extends AkumaHandle {
|
|
|
196
196
|
}, {
|
|
197
197
|
akumaName,
|
|
198
198
|
...(input.cwd === undefined ? {} : { cwd: input.cwd }),
|
|
199
|
-
...(input.writableDirectories === undefined ? {} : { writableDirectories: input.writableDirectories }),
|
|
200
199
|
...(input.bare === undefined ? {} : { bare: input.bare }),
|
|
201
200
|
...(input.caller === undefined ? {} : { caller: input.caller }),
|
|
202
201
|
...(input.initiator === undefined ? {} : { initiator: input.initiator }),
|
|
@@ -207,7 +206,7 @@ export class Akuma extends AkumaHandle {
|
|
|
207
206
|
}
|
|
208
207
|
static select(root, selector, host) {
|
|
209
208
|
if (typeof root !== "string")
|
|
210
|
-
throw new
|
|
209
|
+
throw new KeiyakuError("invalid-input", "Akuma.select root must be a WorldRoot");
|
|
211
210
|
const { spawn, reportDiagnostic = stderrPluginDiagnostic } = captureAkumaHost(host);
|
|
212
211
|
return new Akuma(parseAkumaId(selector).id, root, reportDiagnostic, spawn);
|
|
213
212
|
}
|
|
@@ -215,7 +214,7 @@ export class Akuma extends AkumaHandle {
|
|
|
215
214
|
/** Internal product composition; hosting is captured independently of public operation inputs. */
|
|
216
215
|
export function akumaWithLauncher(root, selector, spawn, host) {
|
|
217
216
|
if (typeof root !== "string")
|
|
218
|
-
throw new
|
|
217
|
+
throw new KeiyakuError("invalid-input", "Akuma.select root must be a WorldRoot");
|
|
219
218
|
const reportDiagnostic = captureAkumaHostDiagnostic(host) ?? stderrPluginDiagnostic;
|
|
220
219
|
return new AkumaHandle(parseAkumaId(selector).id, root, reportDiagnostic, spawn);
|
|
221
220
|
}
|
|
@@ -6,9 +6,11 @@ export declare function rosterListRow(paths: AkumaPaths, expected: AkumaId): Pro
|
|
|
6
6
|
/** Optional semantic seam; the observer composition owns delivery and deduplication. */
|
|
7
7
|
export type OutcomeObserver = (akumaId: AkumaId, historyIds: readonly string[]) => Promise<void>;
|
|
8
8
|
export declare function observeOutcomeRows(id: AkumaId, rows: readonly ActivityRow[], observer?: OutcomeObserver): Promise<void>;
|
|
9
|
-
export declare function observeStatusOutcome(status:
|
|
9
|
+
export declare function observeStatusOutcome(status: LiveStatusObservation["status"], observer?: OutcomeObserver): Promise<void>;
|
|
10
10
|
type BudgetedStatusObservation = Readonly<{
|
|
11
|
-
status: AkumaStatus
|
|
11
|
+
status: Omit<AkumaStatus, "work"> & Readonly<{
|
|
12
|
+
timeline: ActivitySnapshot;
|
|
13
|
+
}>;
|
|
12
14
|
ordinarySelected: number;
|
|
13
15
|
}>;
|
|
14
16
|
/**
|
|
@@ -59,7 +61,7 @@ export declare function readLiveStatus(worldPath: WorldRoot, id: AkumaId, input:
|
|
|
59
61
|
export type ExecutionProgress = "settled" | "advancing" | "stopped";
|
|
60
62
|
/** Pending input is not execution. An owned launch can bridge the admission gap. */
|
|
61
63
|
export declare function executionProgress(life: AkumaStatus["life"], pending: boolean, wake?: "launching" | "settled" | "failed"): ExecutionProgress;
|
|
62
|
-
export declare function defaultWaitComplete(status:
|
|
64
|
+
export declare function defaultWaitComplete(status: LiveStatusObservation["status"]): boolean;
|
|
63
65
|
/** Probe completion only; returned statuses still come from a full observation. */
|
|
64
66
|
export declare function readWaitComplete(worldPath: WorldRoot, ids: readonly AkumaId[], completion: "any" | "all", signal?: AbortSignal, probe?: (id: AkumaId) => Promise<boolean>): Promise<boolean>;
|
|
65
67
|
export type WaitReason = "completed" | "deadline";
|
|
@@ -82,5 +84,4 @@ export declare function waitForObservation<T>(input: Readonly<{
|
|
|
82
84
|
reason: WaitReason;
|
|
83
85
|
value: T;
|
|
84
86
|
}>>;
|
|
85
|
-
export declare function readAkumaBirthCwd(worldPath: WorldRoot, id: AkumaId): Promise<string>;
|
|
86
87
|
export { selectHistory, type ActivityHistory, type ActivitySnapshot };
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { realpath } from "node:fs
|
|
1
|
+
import { realpath } from "node:fs";
|
|
2
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
3
|
+
import { promisify } from "node:util";
|
|
2
4
|
import { projectAkumaBirth } from "./caller.js";
|
|
3
|
-
import { createStatusFactReader, readLifeSnapshot, HeldAkumaLeash, heartExists, isHeartAbsent, life, lifeAt, probeLeash, readHeart, readSeal,
|
|
5
|
+
import { createStatusFactReader, readLifeSnapshot, HeldAkumaLeash, heartExists, isHeartAbsent, life, lifeAt, probeLeash, readHeart, readSeal, } from "./heart/index.js";
|
|
4
6
|
import { pathsForAkumaId } from "./identity.js";
|
|
5
|
-
import { DEFAULT_TAIL, projectTurns, selectHistory, selectSnapshot, } from "./projection.js";
|
|
7
|
+
import { DEFAULT_TAIL, projectTurns, reportedChangePaths, selectHistory, selectSnapshot, } from "./projection.js";
|
|
6
8
|
import { resolveProviderExecution } from "./providers/index.js";
|
|
7
9
|
import { abortableDelay } from "./abort.js";
|
|
8
10
|
import { AkumaNotBornError } from "./akuma-errors.js";
|
|
11
|
+
/** Native resolution answers on-disk case as well as symlinks; the portable form keeps the caller's spelling. */
|
|
12
|
+
const realpathNative = promisify(realpath.native);
|
|
9
13
|
export async function rosterListRow(paths, expected) {
|
|
10
14
|
const snapshot = await readHeart(paths);
|
|
11
15
|
if (snapshot.soul !== null) {
|
|
@@ -79,22 +83,79 @@ export async function observeStatusOutcome(status, observer) {
|
|
|
79
83
|
if (snapshot.kind === "idle" && snapshot.outcome !== undefined)
|
|
80
84
|
await observer?.(status.id, [`turn/${snapshot.outcome.turnSequence}`]);
|
|
81
85
|
}
|
|
82
|
-
function snapshotSelection(input, executionDir) {
|
|
86
|
+
function snapshotSelection(input, executionDir, canonicalize) {
|
|
83
87
|
if (input.ordinaryBudget !== undefined && (!Number.isSafeInteger(input.ordinaryBudget) || input.ordinaryBudget < 0))
|
|
84
88
|
throw new TypeError("ordinary budget must be a nonnegative safe integer");
|
|
85
89
|
return {
|
|
86
90
|
aperture: input.aperture,
|
|
87
91
|
budget: { tail: Math.min(DEFAULT_TAIL, input.ordinaryBudget ?? DEFAULT_TAIL) },
|
|
88
92
|
...(executionDir === undefined ? {} : { executionDir }),
|
|
93
|
+
...(canonicalize === undefined ? {} : { canonicalize }),
|
|
89
94
|
...(input.admittedTellId === undefined ? {} : { admittedTellId: input.admittedTellId }),
|
|
90
95
|
};
|
|
91
96
|
}
|
|
97
|
+
/** Canonical resolutions of reported-change anchors, so projection itself stays synchronous. */
|
|
98
|
+
function createCanonicalAnchors() {
|
|
99
|
+
const resolved = new Map();
|
|
100
|
+
let changed = 0;
|
|
101
|
+
return {
|
|
102
|
+
changed: () => changed,
|
|
103
|
+
clear: () => {
|
|
104
|
+
resolved.clear();
|
|
105
|
+
changed = 0;
|
|
106
|
+
},
|
|
107
|
+
/** Answer from what is already resolved; an unresolved directory stays lexical. */
|
|
108
|
+
canonicalize(absolutePath) {
|
|
109
|
+
const hit = resolved.get(absolutePath);
|
|
110
|
+
if (hit !== undefined)
|
|
111
|
+
return hit;
|
|
112
|
+
const dir = resolved.get(dirname(absolutePath));
|
|
113
|
+
return dir === undefined ? absolutePath : join(dir, basename(absolutePath));
|
|
114
|
+
},
|
|
115
|
+
async resolve(absolutePaths) {
|
|
116
|
+
for (const absolutePath of new Set(absolutePaths)) {
|
|
117
|
+
if (resolved.has(absolutePath))
|
|
118
|
+
continue;
|
|
119
|
+
try {
|
|
120
|
+
resolved.set(absolutePath, await realpathNative(absolutePath));
|
|
121
|
+
changed += 1;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// A deleted or not-yet-existing leaf still belongs to its canonical directory.
|
|
126
|
+
}
|
|
127
|
+
const dir = dirname(absolutePath);
|
|
128
|
+
if (resolved.has(dir))
|
|
129
|
+
continue;
|
|
130
|
+
try {
|
|
131
|
+
resolved.set(dir, await realpathNative(dir));
|
|
132
|
+
changed += 1;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// An unresolvable directory stays lexical without caching the transient error.
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function reusableSelection(memo, ledger, options, anchorsChanged) {
|
|
142
|
+
if (memo === undefined || memo.ledger !== ledger || memo.anchorsChanged !== anchorsChanged)
|
|
143
|
+
return undefined;
|
|
144
|
+
if (memo.options.aperture !== options.aperture ||
|
|
145
|
+
memo.options.admittedTellId !== options.admittedTellId ||
|
|
146
|
+
memo.options.budget.tail !== options.budget.tail ||
|
|
147
|
+
memo.options.executionDir !== options.executionDir)
|
|
148
|
+
return undefined;
|
|
149
|
+
return memo.selected;
|
|
150
|
+
}
|
|
92
151
|
/** Private to a live wait: retain only this member's current frontier and last selection. */
|
|
93
152
|
export function createLiveStatusReader(paths, expected) {
|
|
94
153
|
const reader = createStatusFactReader(paths);
|
|
154
|
+
const anchors = createCanonicalAnchors();
|
|
95
155
|
let memo;
|
|
96
156
|
const clear = () => {
|
|
97
157
|
reader.clear();
|
|
158
|
+
anchors.clear();
|
|
98
159
|
memo = undefined;
|
|
99
160
|
};
|
|
100
161
|
return {
|
|
@@ -121,16 +182,14 @@ export function createLiveStatusReader(paths, expected) {
|
|
|
121
182
|
(await resolveProviderExecution(soul.provider)).adapter.resume === undefined;
|
|
122
183
|
const facts = await reader.read(input, signal);
|
|
123
184
|
const ledger = memo?.facts === facts ? memo.ledger : projectTurns(facts);
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
memo = { facts, ledger, options, selected };
|
|
133
|
-
const lastActivityAt = ledger.rows.findLast((row) => row.kind !== "turn")?.at;
|
|
185
|
+
const executionDir = await realpathNative(soul.cwd).catch(() => undefined);
|
|
186
|
+
if (executionDir !== undefined)
|
|
187
|
+
await anchors.resolve(reportedChangePaths(ledger).map((reported) => resolve(executionDir, reported)));
|
|
188
|
+
const options = snapshotSelection(input, executionDir, executionDir === undefined ? undefined : anchors.canonicalize);
|
|
189
|
+
const anchorsChanged = anchors.changed();
|
|
190
|
+
const selected = reusableSelection(memo, ledger, options, anchorsChanged) ?? selectSnapshot(ledger, options);
|
|
191
|
+
memo = { facts, ledger, options, selected, anchorsChanged };
|
|
192
|
+
const lastActivityAt = snapshot.lastActivityAt;
|
|
134
193
|
return {
|
|
135
194
|
status: {
|
|
136
195
|
id: soul.id,
|
|
@@ -144,7 +203,7 @@ export function createLiveStatusReader(paths, expected) {
|
|
|
144
203
|
...(soul.options.model === undefined ? {} : { model: soul.options.model }),
|
|
145
204
|
...(resumeUnsupported ? { strandedReason: "resume-unsupported" } : {}),
|
|
146
205
|
timeline: selected.snapshot,
|
|
147
|
-
...(lastActivityAt ===
|
|
206
|
+
...(lastActivityAt === null ? {} : { lastActivityAt }),
|
|
148
207
|
},
|
|
149
208
|
ordinarySelected: selected.ordinaryCount,
|
|
150
209
|
rows: ledger.rows,
|
|
@@ -240,10 +299,4 @@ export async function waitForObservation(input) {
|
|
|
240
299
|
: Math.min(input.pollMs ?? OBSERVATION_POLL_MS, Math.max(0, deadline - performance.now())), input.signal);
|
|
241
300
|
}
|
|
242
301
|
}
|
|
243
|
-
export async function readAkumaBirthCwd(worldPath, id) {
|
|
244
|
-
const soul = await readSoul(pathsForAkumaId(worldPath, id));
|
|
245
|
-
if (soul === null)
|
|
246
|
-
throw new AkumaNotBornError(id);
|
|
247
|
-
return soul.cwd;
|
|
248
|
-
}
|
|
249
302
|
export { selectHistory };
|
|
@@ -2,7 +2,6 @@ import { type AkumaCaller } from "./caller.js";
|
|
|
2
2
|
import type { WorldRoot } from "../world.js";
|
|
3
3
|
import { type OutcomeObserver, type LiveStatusObservation, type WaitReason } from "./akuma-observe.js";
|
|
4
4
|
import { type AkumaStreamSnapshot } from "./akuma-stream.js";
|
|
5
|
-
import type { AkumaStatus } from "./akuma.js";
|
|
6
5
|
import type { BodyLauncher } from "./body-launch.js";
|
|
7
6
|
import { type TellResult, type TellWakeRuntime } from "./body.js";
|
|
8
7
|
import { type CallInitialTell, type CallInitialTellAdmission } from "./call-initial-tell.js";
|
|
@@ -12,6 +11,15 @@ import type { ReportAdmission } from "./heart/facts.js";
|
|
|
12
11
|
import type { ActivityHistory, ExactHistory } from "./projection.js";
|
|
13
12
|
import { z } from "zod";
|
|
14
13
|
import { type PublicSessionCoordinate } from "./coordinate.js";
|
|
14
|
+
export declare const historyInputSchemas: readonly [z.ZodObject<{
|
|
15
|
+
id: z.ZodString;
|
|
16
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
17
|
+
before: z.ZodExactOptional<z.ZodNumber>;
|
|
18
|
+
limit: z.ZodExactOptional<z.ZodNumber>;
|
|
19
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
20
|
+
since: z.ZodNumber;
|
|
21
|
+
limit: z.ZodExactOptional<z.ZodNumber>;
|
|
22
|
+
}, z.core.$strict>];
|
|
15
23
|
export type InterruptReceipt = TellResult | Extract<InterruptTellAdmission, {
|
|
16
24
|
kind: "unavailable";
|
|
17
25
|
}>;
|
|
@@ -97,7 +105,7 @@ export declare class AkumaOwner {
|
|
|
97
105
|
text: string;
|
|
98
106
|
at: string;
|
|
99
107
|
}>, signal?: AbortSignal): Promise<ReportAdmission>;
|
|
100
|
-
status(): Promise<
|
|
108
|
+
status(): Promise<LiveStatusObservation["status"]>;
|
|
101
109
|
history(input?: Readonly<{
|
|
102
110
|
id?: string;
|
|
103
111
|
before?: number;
|
|
@@ -112,17 +120,17 @@ export declare class AkumaOwner {
|
|
|
112
120
|
stream(options?: Readonly<{
|
|
113
121
|
signal?: AbortSignal;
|
|
114
122
|
}>): AsyncIterable<AkumaStreamSnapshot>;
|
|
115
|
-
waitReceipt(predicate?: (status:
|
|
123
|
+
waitReceipt(predicate?: (status: LiveStatusObservation["status"]) => boolean, options?: Readonly<{
|
|
116
124
|
timeoutMs?: number;
|
|
117
125
|
signal?: AbortSignal;
|
|
118
126
|
}>): Promise<Readonly<{
|
|
119
127
|
reason: WaitReason;
|
|
120
|
-
status:
|
|
128
|
+
status: LiveStatusObservation["status"];
|
|
121
129
|
}>>;
|
|
122
|
-
wait(predicate?: (status:
|
|
130
|
+
wait(predicate?: (status: LiveStatusObservation["status"]) => boolean, options?: Readonly<{
|
|
123
131
|
timeoutMs?: number;
|
|
124
132
|
signal?: AbortSignal;
|
|
125
|
-
}>): Promise<
|
|
133
|
+
}>): Promise<LiveStatusObservation["status"]>;
|
|
126
134
|
admitInitialTell(initialTell: CallInitialTell, options: Readonly<{
|
|
127
135
|
signal?: AbortSignal;
|
|
128
136
|
runtime: TellWakeRuntime;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KeiyakuError } from "../errors.js";
|
|
2
|
+
import { bareOption, durationSchema, validateAkumaInput } from "./call-input.js";
|
|
2
3
|
import { decodeAkumaCaller } from "./caller.js";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
4
5
|
import { AkumaNotBornError, AkumaProviderError } from "./akuma-errors.js";
|
|
@@ -15,6 +16,21 @@ import { resolveProviderExecution } from "./providers/index.js";
|
|
|
15
16
|
import { publishAkuma } from "./publication.js";
|
|
16
17
|
import { z } from "zod";
|
|
17
18
|
import { publicSessionCoordinate, publicSessionCoordinateSchema } from "./coordinate.js";
|
|
19
|
+
const historySequence = z.number().int().positive();
|
|
20
|
+
const historyLimit = historySequence.max(5_000).exactOptional();
|
|
21
|
+
export const historyInputSchemas = [
|
|
22
|
+
z.strictObject({
|
|
23
|
+
id: z
|
|
24
|
+
.string()
|
|
25
|
+
.regex(/^(?:(?:turn|report)\/)?[1-9][0-9]*$/u)
|
|
26
|
+
.refine((id) => parseExactHistorySelector(id) !== null, {
|
|
27
|
+
message: "id must be a positive safe decimal integer, turn/<positive safe integer> or report/<positive safe integer>",
|
|
28
|
+
}),
|
|
29
|
+
}),
|
|
30
|
+
z.strictObject({ before: historySequence.exactOptional(), limit: historyLimit }),
|
|
31
|
+
z.strictObject({ since: historySequence, limit: historyLimit }),
|
|
32
|
+
];
|
|
33
|
+
const historyInputSchema = z.union(historyInputSchemas);
|
|
18
34
|
export const forkFailureSchemas = {
|
|
19
35
|
unsupported: z.strictObject({ kind: z.literal("provider-cannot-fork") }).readonly(),
|
|
20
36
|
unknownHistory: z.strictObject({ kind: z.literal("unknown-history") }).readonly(),
|
|
@@ -140,15 +156,20 @@ export class AkumaOwner {
|
|
|
140
156
|
const slice = await activitySlice(this.paths);
|
|
141
157
|
return projectTurns(slice.rows, { lowestRetained: slice.lowestRetained, highest: slice.highest });
|
|
142
158
|
}
|
|
143
|
-
async exactHistory(
|
|
144
|
-
|
|
145
|
-
throw new TypeError("Akuma history id must be a nonblank string");
|
|
146
|
-
if (input.before !== undefined || input.since !== undefined || input.limit !== undefined)
|
|
147
|
-
throw new TypeError("Akuma history id cannot be combined with before, since, or limit");
|
|
148
|
-
const selector = parseExactHistorySelector(input.id);
|
|
159
|
+
async exactHistory(id) {
|
|
160
|
+
const selector = parseExactHistorySelector(id);
|
|
149
161
|
if (selector === null)
|
|
150
|
-
throw new
|
|
151
|
-
|
|
162
|
+
throw new KeiyakuError("invalid-input", "Akuma history id must be a positive safe decimal integer, turn/<positive safe integer> or report/<positive safe integer>");
|
|
163
|
+
const slice = await activitySlice(this.paths);
|
|
164
|
+
const ledger = projectTurns(slice.rows, { lowestRetained: slice.lowestRetained, highest: slice.highest });
|
|
165
|
+
if (selector.kind !== "activity")
|
|
166
|
+
return selectExactHistory(ledger.rows, { kind: selector.kind, sequence: selector.sequence });
|
|
167
|
+
const fact = slice.rows.find((row) => row.sequence === selector.sequence);
|
|
168
|
+
const row = ledger.rows.find((row) => row.sequence === selector.sequence) ??
|
|
169
|
+
(fact === undefined ? undefined : projectTurns([fact]).rows.find((row) => row.sequence === selector.sequence));
|
|
170
|
+
return row === undefined || row.kind === "turn" || row.kind === "outcome"
|
|
171
|
+
? { kind: "unknown-history", id }
|
|
172
|
+
: { kind: "exact-activity", row };
|
|
152
173
|
}
|
|
153
174
|
async report(input, signal) {
|
|
154
175
|
return await recordReport(this.paths, input, signal);
|
|
@@ -159,27 +180,14 @@ export class AkumaOwner {
|
|
|
159
180
|
return status;
|
|
160
181
|
}
|
|
161
182
|
async history(input = {}) {
|
|
183
|
+
validateAkumaInput(historyInputSchema, input);
|
|
162
184
|
if (input.id !== undefined) {
|
|
163
|
-
const exact = await this.exactHistory(input);
|
|
185
|
+
const exact = await this.exactHistory(input.id);
|
|
164
186
|
if (exact.kind === "exact")
|
|
165
187
|
await this.outcomeObserved?.(this.id, [`turn/${exact.outcome.turnSequence}`]);
|
|
166
188
|
return exact;
|
|
167
189
|
}
|
|
168
|
-
if (input.before !== undefined && input.since !== undefined) {
|
|
169
|
-
throw new TypeError("Akuma history before and since are mutually exclusive");
|
|
170
|
-
}
|
|
171
|
-
for (const [name, value] of [
|
|
172
|
-
["before", input.before],
|
|
173
|
-
["since", input.since],
|
|
174
|
-
]) {
|
|
175
|
-
if (value !== undefined && (!Number.isSafeInteger(value) || value <= 0)) {
|
|
176
|
-
throw new TypeError(`Akuma history ${name} must be a positive safe integer`);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
190
|
const limit = input.limit ?? 12;
|
|
180
|
-
if (!Number.isSafeInteger(limit) || limit <= 0 || limit > 5_000) {
|
|
181
|
-
throw new TypeError("Akuma history limit must be a positive safe integer no greater than 5000");
|
|
182
|
-
}
|
|
183
191
|
const history = selectHistory(await this.projectHistoryTurns(), {
|
|
184
192
|
...(input.before === undefined ? {} : { before: input.before }),
|
|
185
193
|
...(input.since === undefined ? {} : { since: input.since }),
|
|
@@ -197,9 +205,7 @@ export class AkumaOwner {
|
|
|
197
205
|
return createAkumaStream(this.paths, this.id, options, this.outcomeObserved);
|
|
198
206
|
}
|
|
199
207
|
async waitReceipt(predicate = defaultWaitComplete, options = {}) {
|
|
200
|
-
|
|
201
|
-
throw new TypeError("Akuma wait timeoutMs must be a nonnegative finite millisecond duration");
|
|
202
|
-
}
|
|
208
|
+
validateAkumaInput(durationSchema.optional(), options.timeoutMs);
|
|
203
209
|
const waited = await executeWaitAkuma({
|
|
204
210
|
path: this.worldPath,
|
|
205
211
|
ids: [this.id],
|