@astrosheep/keiyaku 4.6.30 → 4.6.31
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 +5 -5
- package/build/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/build/plugins/claude/skills/keiyaku/SKILL.md +12 -12
- package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +16 -16
- package/build/plugins/claude/skills/keiyaku-akuma/references/automation.md +14 -14
- package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +10 -10
- package/build/plugins/claude/skills/keiyaku-bind/SKILL.md +15 -15
- package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +16 -16
- package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +21 -21
- package/build/plugins/codex/.codex-plugin/plugin.json +1 -1
- package/build/plugins/codex/skills/keiyaku/SKILL.md +12 -12
- package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +16 -16
- package/build/plugins/codex/skills/keiyaku-akuma/references/automation.md +14 -14
- package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +10 -10
- package/build/plugins/codex/skills/keiyaku-bind/SKILL.md +15 -15
- package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +16 -16
- package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +21 -21
- package/build/plugins/opencode/package.json +1 -1
- package/build/plugins/opencode/skills/keiyaku/SKILL.md +12 -12
- package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +16 -16
- package/build/plugins/opencode/skills/keiyaku-akuma/references/automation.md +14 -14
- package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +10 -10
- package/build/plugins/opencode/skills/keiyaku-bind/SKILL.md +15 -15
- package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +16 -16
- package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +21 -21
- package/build/plugins/pi/README.md +5 -5
- package/build/plugins/pi/akuma-tools.ts +17 -23
- package/build/skills/keiyaku/SKILL.md +12 -12
- package/build/skills/keiyaku-akuma/SKILL.md +16 -16
- package/build/skills/keiyaku-akuma/references/automation.md +14 -14
- package/build/skills/keiyaku-babysit/SKILL.md +10 -10
- package/build/skills/keiyaku-bind/SKILL.md +15 -15
- package/build/skills/keiyaku-debt/SKILL.md +16 -16
- package/build/skills/keiyaku-workflow/SKILL.md +21 -21
- package/build/src/akuma/akuma-call.d.ts +1 -1
- package/build/src/akuma/akuma-call.js +9 -9
- package/build/src/akuma/akuma-errors.d.ts +5 -5
- package/build/src/akuma/akuma-instance.d.ts +355 -12
- package/build/src/akuma/akuma-instance.js +20 -20
- package/build/src/akuma/akuma-observe.d.ts +11 -12
- package/build/src/akuma/akuma-observe.js +34 -26
- package/build/src/akuma/akuma-owner.d.ts +32 -11
- package/build/src/akuma/akuma-owner.js +35 -16
- package/build/src/akuma/akuma-probe.d.ts +3 -3
- package/build/src/akuma/akuma-probe.js +2 -2
- package/build/src/akuma/akuma-selection-execution.d.ts +985 -1
- package/build/src/akuma/akuma-selection-execution.js +42 -18
- package/build/src/akuma/akuma-stream.d.ts +2 -2
- package/build/src/akuma/akuma-stream.js +1 -1
- package/build/src/akuma/akuma-wait.d.ts +5 -5
- package/build/src/akuma/akuma-wait.js +52 -14
- package/build/src/akuma/akuma.d.ts +245 -271
- package/build/src/akuma/akuma.js +98 -46
- package/build/src/akuma/archetype.d.ts +19 -6
- package/build/src/akuma/archetype.js +25 -9
- package/build/src/akuma/body-launch.d.ts +2 -2
- package/build/src/akuma/body.js +4 -4
- package/build/src/akuma/call-initial-tell.d.ts +60 -44
- package/build/src/akuma/call-initial-tell.js +41 -2
- package/build/src/akuma/caller.d.ts +26 -17
- package/build/src/akuma/caller.js +22 -9
- package/build/src/akuma/coordinate.d.ts +9 -0
- package/build/src/akuma/coordinate.js +13 -0
- package/build/src/akuma/detached-body.js +2 -2
- package/build/src/akuma/dispatch-association.d.ts +4 -4
- package/build/src/akuma/dispatch-association.js +12 -3
- package/build/src/akuma/execution-instructions.js +2 -2
- package/build/src/akuma/heart/facts.d.ts +29 -7
- package/build/src/akuma/heart/facts.js +13 -0
- package/build/src/akuma/heart/index.d.ts +0 -3
- package/build/src/akuma/heart/index.js +3 -6
- package/build/src/akuma/heart/rows.js +2 -2
- package/build/src/akuma/heart/soul.js +5 -5
- package/build/src/akuma/identity.d.ts +17 -16
- package/build/src/akuma/identity.js +20 -19
- package/build/src/akuma/index.d.ts +1 -2
- package/build/src/akuma/lineage-cache.d.ts +4 -4
- package/build/src/akuma/lineage-cache.js +10 -10
- package/build/src/akuma/projection-read.d.ts +2 -5
- package/build/src/akuma/projection-read.js +34 -47
- package/build/src/akuma/projection.d.ts +659 -569
- package/build/src/akuma/projection.js +203 -94
- package/build/src/akuma/providers/acp/index.js +1 -1
- package/build/src/akuma/providers/execution-environment.d.ts +1 -3
- package/build/src/akuma/providers/execution-environment.js +0 -4
- package/build/src/akuma/publication.d.ts +2 -2
- package/build/src/akuma/publication.js +3 -3
- package/build/src/akuma/retention.js +2 -2
- package/build/src/akuma/selection-observation.d.ts +507 -43
- package/build/src/akuma/selection-observation.js +153 -1
- package/build/src/akuma/status-projection.d.ts +288 -0
- package/build/src/akuma/status-projection.js +154 -0
- package/build/src/akuma/turn-drive.js +0 -3
- package/build/src/alias/index.d.ts +9 -4
- package/build/src/alias/index.js +11 -9
- package/build/src/bounded-list.d.ts +8 -0
- package/build/src/bounded-list.js +9 -0
- package/build/src/cli/commands/akuma-grammar.d.ts +2 -2
- package/build/src/cli/commands/akuma-grammar.js +21 -21
- package/build/src/cli/commands/akuma.d.ts +1 -2
- package/build/src/cli/commands/akuma.js +115 -251
- package/build/src/cli/commands/contract-grammar.d.ts +4 -3
- package/build/src/cli/commands/contract-grammar.js +39 -22
- package/build/src/cli/commands/contract-help.d.ts +3 -1
- package/build/src/cli/commands/contract-help.js +4 -3
- package/build/src/cli/commands/contract.d.ts +6 -3
- package/build/src/cli/commands/contract.js +203 -434
- package/build/src/cli/commands/debt.d.ts +2 -3
- package/build/src/cli/commands/debt.js +101 -317
- package/build/src/cli/commands/report.js +11 -28
- package/build/src/cli/commands/whoami.d.ts +3 -43
- package/build/src/cli/commands/whoami.js +8 -121
- package/build/src/cli/coordinates.d.ts +4 -35
- package/build/src/cli/coordinates.js +13 -129
- package/build/src/cli/parse.d.ts +0 -6
- package/build/src/cli/parse.js +5 -48
- package/build/src/cli/render/akuma-activity.d.ts +31 -16
- package/build/src/cli/render/akuma-activity.js +157 -149
- package/build/src/cli/render/akuma-tool.d.ts +3 -6
- package/build/src/cli/render/akuma-tool.js +20 -14
- package/build/src/cli/render/akuma.d.ts +25 -26
- package/build/src/cli/render/akuma.js +100 -129
- package/build/src/cli/render/catalog.d.ts +4 -7
- package/build/src/cli/render/catalog.js +52 -99
- package/build/src/cli/render/contract-history.d.ts +3 -1
- package/build/src/cli/render/contract-history.js +140 -215
- package/build/src/cli/render/contract-observation.d.ts +43 -30
- package/build/src/cli/render/contract-observation.js +64 -31
- package/build/src/cli/render/contract-wait.js +6 -6
- package/build/src/cli/render/contract.d.ts +41 -6
- package/build/src/cli/render/contract.js +274 -370
- package/build/src/cli/render/debt.d.ts +9 -19
- package/build/src/cli/render/debt.js +120 -185
- package/build/src/cli/render/delivery-preview.d.ts +4 -3
- package/build/src/cli/render/delivery-preview.js +68 -96
- package/build/src/cli/render/kanshi-akuma.d.ts +4 -4
- package/build/src/cli/render/kanshi-akuma.js +70 -59
- package/build/src/cli/render/kanshi.d.ts +4 -4
- package/build/src/cli/render/kanshi.js +205 -221
- package/build/src/cli/render/marks.d.ts +11 -2
- package/build/src/cli/render/marks.js +13 -3
- package/build/src/cli/render/nuke.d.ts +3 -3
- package/build/src/cli/render/nuke.js +13 -16
- package/build/src/cli/render/receipt.d.ts +37 -43
- package/build/src/cli/render/receipt.js +313 -236
- package/build/src/cli/render/reconcile.d.ts +6 -4
- package/build/src/cli/render/reconcile.js +53 -137
- package/build/src/cli/render/refusal.d.ts +3 -2
- package/build/src/cli/render/refusal.js +73 -54
- package/build/src/cli/render/region.d.ts +11 -2
- package/build/src/cli/render/region.js +17 -23
- package/build/src/cli/render/settings.d.ts +0 -1
- package/build/src/cli/render/settings.js +8 -17
- package/build/src/cli/render/terminal.d.ts +2 -0
- package/build/src/cli/render/verbs.d.ts +4 -0
- package/build/src/cli/render/verbs.js +312 -0
- package/build/src/cli/render/whoami.d.ts +1 -1
- package/build/src/cli/render/whoami.js +24 -31
- package/build/src/cli/runtime.d.ts +3 -11
- package/build/src/cli/runtime.js +96 -79
- package/build/src/cli/scan.d.ts +1 -1
- package/build/src/cli/streams.js +1 -0
- package/build/src/contract-guidance.js +2 -2
- package/build/src/contract-worktree.d.ts +2 -15
- package/build/src/contract-worktree.js +19 -35
- package/build/src/core/facts/observation.d.ts +4 -5
- package/build/src/core/facts/observation.js +7 -9
- package/build/src/core/verbs/amend.d.ts +0 -1
- package/build/src/core/verbs/amend.js +3 -3
- package/build/src/core/verbs/bind.d.ts +0 -1
- package/build/src/core/verbs/bind.js +5 -5
- package/build/src/core/verbs/deliver.d.ts +3 -2
- package/build/src/core/verbs/deliver.js +2 -2
- package/build/src/core/verbs/placement.d.ts +0 -5
- package/build/src/core/verbs/placement.js +4 -6
- package/build/src/core/verbs/reintegrate.d.ts +0 -1
- package/build/src/core/verbs/reintegrate.js +2 -2
- package/build/src/debt/board.d.ts +132 -116
- package/build/src/debt/board.js +138 -94
- package/build/src/debt/catalog.d.ts +4 -4
- package/build/src/debt/catalog.js +2 -18
- package/build/src/debt/context.d.ts +15 -3
- package/build/src/debt/context.js +12 -1
- package/build/src/debt/created-observation.d.ts +5 -17
- package/build/src/debt/created-observation.js +14 -6
- package/build/src/debt/document.d.ts +20 -15
- package/build/src/debt/document.js +18 -1
- package/build/src/debt/index.d.ts +346 -23
- package/build/src/debt/index.js +68 -22
- package/build/src/debt/input.d.ts +2 -1
- package/build/src/debt/input.js +14 -0
- package/build/src/debt/lifecycle-operations.d.ts +2 -2
- package/build/src/debt/lifecycle-operations.js +14 -22
- package/build/src/debt/operation-types.d.ts +188 -66
- package/build/src/debt/operation-types.js +113 -1
- package/build/src/debt/operations.d.ts +11 -10
- package/build/src/debt/operations.js +46 -71
- package/build/src/debt/query.d.ts +14 -10
- package/build/src/debt/query.js +3 -12
- package/build/src/debt/store.d.ts +4 -2
- package/build/src/debt/store.js +8 -8
- package/build/src/debt/view.d.ts +0 -3
- package/build/src/debt/view.js +0 -4
- package/build/src/dispatch/index.d.ts +22 -5
- package/build/src/dispatch/index.js +46 -37
- package/build/src/git/admission.d.ts +2 -2
- package/build/src/git/admission.js +2 -1
- package/build/src/git/hooks.d.ts +14 -35
- package/build/src/git/hooks.js +45 -25
- package/build/src/git/integration.d.ts +6 -24
- package/build/src/git/integration.js +10 -16
- package/build/src/git/private-state-seat.d.ts +2 -2
- package/build/src/git/private-state-seat.js +2 -1
- package/build/src/git/reconcile.d.ts +17 -79
- package/build/src/git/reconcile.js +37 -52
- package/build/src/git/scratch.d.ts +3 -3
- package/build/src/git/scratch.js +4 -1
- package/build/src/git/target-placement.d.ts +23 -31
- package/build/src/git/target-placement.js +42 -27
- package/build/src/git/target.d.ts +2 -2
- package/build/src/git/target.js +2 -1
- package/build/src/git/tender.d.ts +7 -39
- package/build/src/git/tender.js +21 -54
- package/build/src/git/terminal-reconcile.js +15 -18
- package/build/src/git/terminal-seal.d.ts +2 -4
- package/build/src/git/terminal-seal.js +7 -33
- package/build/src/git/workspace.d.ts +65 -41
- package/build/src/git/workspace.js +45 -14
- package/build/src/identity/selector.d.ts +2 -0
- package/build/src/identity/selector.js +13 -3
- package/build/src/index.d.ts +48 -54
- package/build/src/index.js +31 -43
- package/build/src/kanshi/counts.d.ts +42 -8
- package/build/src/kanshi/counts.js +13 -2
- package/build/src/kanshi/index.d.ts +5 -5
- package/build/src/kanshi/index.js +4 -3
- package/build/src/kanshi/read.d.ts +489 -6
- package/build/src/kanshi/read.js +334 -483
- package/build/src/kanshi/report.d.ts +2504 -103
- package/build/src/kanshi/report.js +165 -1
- package/build/src/kanshi/select.d.ts +0 -8
- package/build/src/kanshi/select.js +20 -59
- package/build/src/library/address.d.ts +8 -8
- package/build/src/library/address.js +7 -7
- package/build/src/library/akuma-creation.d.ts +690 -84
- package/build/src/library/akuma-creation.js +202 -142
- package/build/src/library/akuma-retention.d.ts +2 -2
- package/build/src/library/akuma-retention.js +2 -2
- package/build/src/library/akumas.d.ts +10 -6
- package/build/src/library/akumas.js +24 -7
- package/build/src/library/bind.d.ts +28 -54
- package/build/src/library/bind.js +6 -4
- package/build/src/library/continuation.d.ts +197 -479
- package/build/src/library/continuation.js +40 -23
- package/build/src/library/contract-address.d.ts +6 -5
- package/build/src/library/contract-address.js +5 -7
- package/build/src/library/contract-composition.d.ts +18 -12
- package/build/src/library/contract-composition.js +55 -47
- package/build/src/library/contract-creation.d.ts +3 -2
- package/build/src/library/contract-creation.js +38 -32
- package/build/src/library/contract-execution.js +77 -38
- package/build/src/library/contract-outcomes.d.ts +1877 -27
- package/build/src/library/contract-outcomes.js +93 -10
- package/build/src/library/contract-settings.d.ts +2 -2
- package/build/src/library/contract-settings.js +18 -14
- package/build/src/library/contract-types.d.ts +238 -61
- package/build/src/library/contract-types.js +131 -1
- package/build/src/library/contract-wait.d.ts +38 -17
- package/build/src/library/contract-wait.js +40 -10
- package/build/src/library/delivery.d.ts +588 -36
- package/build/src/library/delivery.js +35 -27
- package/build/src/library/input.d.ts +1 -1
- package/build/src/library/input.js +1 -2
- package/build/src/library/invocation.d.ts +11 -7
- package/build/src/library/invocation.js +42 -51
- package/build/src/library/kei.d.ts +48 -0
- package/build/src/library/kei.js +256 -0
- package/build/src/library/keiyaku-attribution.d.ts +11 -0
- package/build/src/{cli/delivery-identity.js → library/keiyaku-attribution.js} +12 -1
- package/build/src/library/keiyaku-classify.d.ts +11 -0
- package/build/src/library/keiyaku-classify.js +146 -0
- package/build/src/library/keiyaku-coordinates.d.ts +31 -0
- package/build/src/library/keiyaku-coordinates.js +103 -0
- package/build/src/library/keiyaku-debt.d.ts +142 -0
- package/build/src/library/keiyaku-debt.js +188 -0
- package/build/src/library/keiyaku-identity.d.ts +58 -0
- package/build/src/library/keiyaku-identity.js +176 -0
- package/build/src/library/keiyaku-policy.d.ts +27 -0
- package/build/src/library/keiyaku-policy.js +44 -0
- package/build/src/library/keiyaku-status.d.ts +1487 -0
- package/build/src/library/keiyaku-status.js +92 -0
- package/build/src/library/keiyaku-verbs.d.ts +6774 -0
- package/build/src/library/keiyaku-verbs.js +458 -0
- package/build/src/library/keiyaku.d.ts +871 -38
- package/build/src/library/keiyaku.js +677 -127
- package/build/src/library/nuke.d.ts +22 -0
- package/build/src/library/nuke.js +4 -1
- package/build/src/library/outcome.d.ts +706 -692
- package/build/src/library/outcome.js +582 -167
- package/build/src/library/reconcile.d.ts +464 -116
- package/build/src/library/reconcile.js +174 -102
- package/build/src/library/refusal.d.ts +113 -577
- package/build/src/library/refusal.js +64 -51
- package/build/src/library/region.d.ts +5 -24
- package/build/src/library/region.js +6 -21
- package/build/src/library/selection.d.ts +181 -32
- package/build/src/library/selection.js +99 -64
- package/build/src/mcp/adapter.d.ts +11 -0
- package/build/src/mcp/adapter.js +106 -0
- package/build/src/mcp/help.d.ts +1 -0
- package/build/src/mcp/help.js +26 -0
- package/build/src/mcp/index.d.ts +2 -0
- package/build/src/mcp/index.js +37 -0
- package/build/src/plugin/public.d.ts +1 -1
- package/build/src/plugin/runtime.js +17 -14
- package/build/src/protocol/arc.d.ts +4 -1
- package/build/src/protocol/arc.js +7 -1
- package/build/src/protocol/attempt.d.ts +2 -3
- package/build/src/protocol/attempt.js +1 -10
- package/build/src/protocol/bind.d.ts +6 -7
- package/build/src/protocol/bind.js +9 -5
- package/build/src/protocol/completion.d.ts +448 -12
- package/build/src/protocol/completion.js +164 -26
- package/build/src/protocol/deliver.d.ts +26 -24
- package/build/src/protocol/deliver.js +24 -52
- package/build/src/protocol/delivery-preview.d.ts +97 -247
- package/build/src/protocol/delivery-preview.js +132 -128
- package/build/src/protocol/execution-observation.d.ts +146 -123
- package/build/src/protocol/execution-observation.js +9 -6
- package/build/src/protocol/intent.d.ts +9 -48
- package/build/src/protocol/intent.js +32 -46
- package/build/src/protocol/operations.d.ts +207 -505
- package/build/src/protocol/operations.js +81 -134
- package/build/src/protocol/placement.d.ts +0 -1
- package/build/src/protocol/placement.js +5 -2
- package/build/src/protocol/progress.d.ts +7 -97
- package/build/src/protocol/progress.js +7 -55
- package/build/src/protocol/read/observation.d.ts +13 -6
- package/build/src/protocol/read/observation.js +10 -9
- package/build/src/protocol/read/status.d.ts +464 -93
- package/build/src/protocol/read/status.js +372 -85
- package/build/src/protocol/reconcile.d.ts +2 -0
- package/build/src/protocol/reconcile.js +12 -11
- package/build/src/protocol/reintegrate.d.ts +0 -1
- package/build/src/protocol/reintegrate.js +4 -4
- package/build/src/protocol/result-leaves.d.ts +528 -0
- package/build/src/protocol/result-leaves.js +195 -0
- package/build/src/protocol/result-reasons.d.ts +129 -0
- package/build/src/protocol/result-reasons.js +87 -0
- package/build/src/protocol/review.d.ts +14 -11
- package/build/src/protocol/review.js +30 -14
- package/build/src/protocol/run.d.ts +4 -4
- package/build/src/protocol/run.js +4 -1
- package/build/src/protocol/verify.d.ts +359 -30
- package/build/src/protocol/verify.js +118 -28
- package/build/src/region.d.ts +26 -0
- package/build/src/region.js +28 -0
- package/build/src/runtime/proc/diagnostic.d.ts +11 -0
- package/build/src/runtime/proc/diagnostic.js +20 -0
- package/build/src/runtime/proc/windows-launch.exe +0 -0
- package/build/src/settings.d.ts +126 -32
- package/build/src/settings.js +107 -34
- package/build/src/settlement/settle.d.ts +29 -12
- package/build/src/settlement/settle.js +22 -15
- package/build/src/verification/declaration.d.ts +1 -3
- package/build/src/verification/declaration.js +2 -5
- package/build/src/verification/execution.d.ts +7 -19
- package/build/src/verification/execution.js +37 -16
- package/build/src/verification/observation.d.ts +13 -13
- package/build/src/verification/observation.js +9 -7
- package/build/src/world.d.ts +8 -0
- package/build/src/world.js +7 -0
- package/package.json +6 -5
- package/plugins/paseo/plugin/server/keiyaku.ts +13 -46
- package/plugins/paseo/plugin/server/message.ts +8 -30
- package/plugins/paseo/plugin/server/mirror.ts +16 -20
- package/plugins/paseo/plugin/server/provider.ts +1 -1
- package/plugins/paseo/plugin/server/sdk.ts +14 -6
- package/plugins/pi/README.md +5 -5
- package/plugins/pi/akuma-tools.ts +17 -23
- package/skills/keiyaku/SKILL.md +12 -12
- package/skills/keiyaku-akuma/SKILL.md +16 -16
- package/skills/keiyaku-akuma/references/automation.md +14 -14
- package/skills/keiyaku-babysit/SKILL.md +10 -10
- package/skills/keiyaku-bind/SKILL.md +15 -15
- package/skills/keiyaku-debt/SKILL.md +16 -16
- package/skills/keiyaku-workflow/SKILL.md +21 -21
- package/build/src/cli/actor.d.ts +0 -10
- package/build/src/cli/actor.js +0 -24
- package/build/src/cli/akuma-caller.d.ts +0 -3
- package/build/src/cli/akuma-caller.js +0 -31
- package/build/src/cli/delivery-identity.d.ts +0 -3
- package/build/src/cli/render/effects.d.ts +0 -26
- package/build/src/cli/render/effects.js +0 -41
- package/build/src/cli/selectors.d.ts +0 -10
- package/build/src/cli/selectors.js +0 -42
- package/build/src/markdown/diff.d.ts +0 -1
- package/build/src/markdown/diff.js +0 -4
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { harnessOwner } from "@astrosheep/square";
|
|
2
|
+
import { actorId as mintActorId } from "../core/facts/types.js";
|
|
3
|
+
/** Resolve optional caller testimony from explicit invocation input. */
|
|
4
|
+
export function resolveActor(input = {}) {
|
|
5
|
+
if (input.actor !== undefined) {
|
|
6
|
+
if (input.actor.trim().length === 0)
|
|
7
|
+
throw new TypeError("actor must be a nonblank string");
|
|
8
|
+
return mintActorId(input.actor);
|
|
9
|
+
}
|
|
10
|
+
const actorId = input.env?.KEIYAKU_ACTOR_ID;
|
|
11
|
+
return actorId !== undefined && actorId.trim().length > 0 ? mintActorId(actorId) : undefined;
|
|
12
|
+
}
|
|
2
13
|
/** Select attribution at the submitting edge; no host or artifact lookup. */
|
|
3
14
|
export function deliveryOwner(environment) {
|
|
4
15
|
const explicit = environment.KEIYAKU_INITIATOR?.trim();
|
|
5
16
|
if (explicit)
|
|
6
17
|
return explicit;
|
|
7
|
-
if (environment.CLAUDE_CODE_CHILD_SESSION === "1")
|
|
18
|
+
if (environment.CLAUDE_CODE_CHILD_SESSION === "1" && !environment.CLAUDE_CODE_SESSION_ID?.trim())
|
|
8
19
|
return undefined;
|
|
9
20
|
const coordinates = [
|
|
10
21
|
["CLAUDE_CODE_SESSION_ID", "claude-code"],
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { VerbInput, VerbName, VerbOutput } from "./keiyaku-verbs.js";
|
|
2
|
+
export type VerbDisposition = "accepted" | "refused" | "retryable" | "failed" | "usage";
|
|
3
|
+
export type VerbCompletion<O> = Readonly<{
|
|
4
|
+
kind: "returned";
|
|
5
|
+
value: O;
|
|
6
|
+
}> | Readonly<{
|
|
7
|
+
kind: "threw";
|
|
8
|
+
error: unknown;
|
|
9
|
+
}>;
|
|
10
|
+
/** Classify the native completion without changing or reconstructing its evidence. */
|
|
11
|
+
export declare function classifyVerb<K extends VerbName>(name: K, input: VerbInput<K>, completion: VerbCompletion<VerbOutput<K>>): VerbDisposition;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { AkumaNotBornError } from "../akuma/akuma-errors.js";
|
|
2
|
+
import { AkumaArchetypeError } from "../akuma/archetype.js";
|
|
3
|
+
import { AkumaAddressError, AkumaWorldScopeError } from "./address.js";
|
|
4
|
+
import { KeiyakuArcDocumentError, KeiyakuUsageError } from "./keiyaku-coordinates.js";
|
|
5
|
+
import { KeiyakuError, contractOutcomeDisposition, invocationIssueIsFailure, resetIssueIsRequired, spawnFailureReceipt, } from "./outcome.js";
|
|
6
|
+
function classifyDebt(result) {
|
|
7
|
+
if ("items" in result) {
|
|
8
|
+
if (result.items.some((item) => item.kind === "retry"))
|
|
9
|
+
return "retryable";
|
|
10
|
+
return result.items.some((item) => item.kind === "refused" || item.kind === "missing") ? "refused" : "accepted";
|
|
11
|
+
}
|
|
12
|
+
if (result.kind === "retry")
|
|
13
|
+
return "retryable";
|
|
14
|
+
if (result.kind === "refused" ||
|
|
15
|
+
result.kind === "absent" ||
|
|
16
|
+
result.kind === "missing" ||
|
|
17
|
+
result.kind === "invalid-namespace-context")
|
|
18
|
+
return "refused";
|
|
19
|
+
return "issues" in result && (result.issues?.length ?? 0) > 0 ? "failed" : "accepted";
|
|
20
|
+
}
|
|
21
|
+
function classifyThrown(name, error) {
|
|
22
|
+
if (spawnFailureReceipt(error) !== undefined || (error instanceof KeiyakuError && error.outcome !== undefined))
|
|
23
|
+
return "failed";
|
|
24
|
+
if (error instanceof KeiyakuUsageError)
|
|
25
|
+
return "usage";
|
|
26
|
+
if (error instanceof AkumaAddressError ||
|
|
27
|
+
error instanceof AkumaNotBornError ||
|
|
28
|
+
error instanceof AkumaWorldScopeError ||
|
|
29
|
+
error instanceof KeiyakuArcDocumentError ||
|
|
30
|
+
(name === "spawn" && error instanceof AkumaArchetypeError))
|
|
31
|
+
return "refused";
|
|
32
|
+
return "failed";
|
|
33
|
+
}
|
|
34
|
+
function classifySpawn(result) {
|
|
35
|
+
return result.failure !== undefined ||
|
|
36
|
+
result.dispatchFailure !== undefined ||
|
|
37
|
+
(result.alias !== undefined && result.alias.kind !== "moved") ||
|
|
38
|
+
result.wake?.kind === "failed" ||
|
|
39
|
+
result.input?.kind === "failed" ||
|
|
40
|
+
result.input?.kind === "invalid-output"
|
|
41
|
+
? "failed"
|
|
42
|
+
: "accepted";
|
|
43
|
+
}
|
|
44
|
+
function classifyFork(result) {
|
|
45
|
+
if (result.kind === "forked")
|
|
46
|
+
return result.dispatchFailure === undefined ? "accepted" : "failed";
|
|
47
|
+
return result.kind === "fork-failed" || result.kind === "provider-forked-local-birth-failed" ? "failed" : "refused";
|
|
48
|
+
}
|
|
49
|
+
function classifyStatus(value) {
|
|
50
|
+
return "kind" in value && value.kind === "contract-missing" ? "refused" : "accepted";
|
|
51
|
+
}
|
|
52
|
+
function classifyRegion(value) {
|
|
53
|
+
return value.kind === "contract-missing" || value.kind === "contract-terminal" ? "refused" : "accepted";
|
|
54
|
+
}
|
|
55
|
+
function classifyReconcile(result) {
|
|
56
|
+
switch (result.kind) {
|
|
57
|
+
case "missing":
|
|
58
|
+
return "refused";
|
|
59
|
+
case "world-observation-failed":
|
|
60
|
+
return "failed";
|
|
61
|
+
case "contract":
|
|
62
|
+
return result.issues?.some(invocationIssueIsFailure) === true ? "failed" : "accepted";
|
|
63
|
+
case "world":
|
|
64
|
+
return result.contracts?.some((item) => item.issues?.some(invocationIssueIsFailure) === true) === true
|
|
65
|
+
? "failed"
|
|
66
|
+
: "accepted";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function classifyWait(result) {
|
|
70
|
+
if (result.kind === "contract")
|
|
71
|
+
return result.reason === "missing" ? "refused" : "accepted";
|
|
72
|
+
return result.results.some((item) => item.kind !== "observed") ? "failed" : "accepted";
|
|
73
|
+
}
|
|
74
|
+
function classifyHistory(value) {
|
|
75
|
+
return value.kind === "contract-missing" || value.kind === "akuma-unknown-history" ? "refused" : "accepted";
|
|
76
|
+
}
|
|
77
|
+
function classifyNuke(result) {
|
|
78
|
+
if (result.kind === "refused")
|
|
79
|
+
return "refused";
|
|
80
|
+
return result.issues?.some(resetIssueIsRequired) === true ? "retryable" : "accepted";
|
|
81
|
+
}
|
|
82
|
+
/** Classify the native completion without changing or reconstructing its evidence. */
|
|
83
|
+
export function classifyVerb(name, input, completion) {
|
|
84
|
+
if (completion.kind === "threw")
|
|
85
|
+
return classifyThrown(name, completion.error);
|
|
86
|
+
const value = completion.value;
|
|
87
|
+
switch (name) {
|
|
88
|
+
case "ls":
|
|
89
|
+
return input.of === "debt" ? classifyDebt(value) : "accepted";
|
|
90
|
+
case "debt.add":
|
|
91
|
+
case "debt.addDocument":
|
|
92
|
+
case "debt.update":
|
|
93
|
+
case "debt.show":
|
|
94
|
+
case "debt.done":
|
|
95
|
+
case "debt.drop":
|
|
96
|
+
case "debt.ready":
|
|
97
|
+
case "debt.blocked":
|
|
98
|
+
case "debt.query":
|
|
99
|
+
case "debt.tree":
|
|
100
|
+
case "debt.doctor":
|
|
101
|
+
case "debt.context":
|
|
102
|
+
return classifyDebt(value);
|
|
103
|
+
case "bind":
|
|
104
|
+
case "amend":
|
|
105
|
+
case "arc":
|
|
106
|
+
case "deliver":
|
|
107
|
+
case "deliver.preview":
|
|
108
|
+
case "verify":
|
|
109
|
+
case "review":
|
|
110
|
+
case "abandon": {
|
|
111
|
+
return contractOutcomeDisposition(value);
|
|
112
|
+
}
|
|
113
|
+
case "spawn":
|
|
114
|
+
return classifySpawn(value);
|
|
115
|
+
case "fork":
|
|
116
|
+
return classifyFork(value);
|
|
117
|
+
case "tell":
|
|
118
|
+
return value.wake?.kind === "failed" ? "failed" : "accepted";
|
|
119
|
+
case "ask": {
|
|
120
|
+
const reason = value.kind;
|
|
121
|
+
return reason === "failed" || reason === "invalid-output" ? "failed" : "accepted";
|
|
122
|
+
}
|
|
123
|
+
case "kill":
|
|
124
|
+
return value.results.some(({ outcome }) => outcome === "unavailable" || outcome === "hung" || outcome === "untidy")
|
|
125
|
+
? "failed"
|
|
126
|
+
: "accepted";
|
|
127
|
+
case "wait":
|
|
128
|
+
return classifyWait(value);
|
|
129
|
+
case "history":
|
|
130
|
+
return classifyHistory(value);
|
|
131
|
+
case "show":
|
|
132
|
+
return value.kind === "missing" ? "refused" : "accepted";
|
|
133
|
+
case "status":
|
|
134
|
+
return classifyStatus(value);
|
|
135
|
+
case "region":
|
|
136
|
+
return classifyRegion(value);
|
|
137
|
+
case "reconcile":
|
|
138
|
+
return classifyReconcile(value);
|
|
139
|
+
case "nuke":
|
|
140
|
+
return classifyNuke(value);
|
|
141
|
+
case "report":
|
|
142
|
+
return value.kind === "refused" ? "refused" : "accepted";
|
|
143
|
+
default:
|
|
144
|
+
return "accepted";
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type WorldRoot } from "../world.js";
|
|
2
|
+
import { Repo } from "./repo.js";
|
|
3
|
+
import type { ContractId } from "../core/facts/types.js";
|
|
4
|
+
/** Invalid arc material retains the resolved subject for the process-edge refusal. */
|
|
5
|
+
export declare class KeiyakuArcDocumentError extends Error {
|
|
6
|
+
readonly contract: ContractId;
|
|
7
|
+
constructor(contract: ContractId, cause: Error);
|
|
8
|
+
}
|
|
9
|
+
export declare class KeiyakuUsageError extends TypeError {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
export type InvocationCoordinates = Readonly<{
|
|
13
|
+
cwd: string;
|
|
14
|
+
repo?: Repo;
|
|
15
|
+
world: WorldRoot | null;
|
|
16
|
+
candidateWorld: WorldRoot | null;
|
|
17
|
+
debtContext: Readonly<{
|
|
18
|
+
directory: string;
|
|
19
|
+
boundary: string;
|
|
20
|
+
writeRoot: string;
|
|
21
|
+
managed: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
establishWorld: () => Promise<WorldRoot>;
|
|
24
|
+
}>;
|
|
25
|
+
export declare function invocationCoordinates(input: Readonly<{
|
|
26
|
+
cwd: string;
|
|
27
|
+
repo?: string;
|
|
28
|
+
environment: Readonly<Record<string, string | undefined>>;
|
|
29
|
+
use: "none" | "optional" | "required";
|
|
30
|
+
contractWait?: boolean;
|
|
31
|
+
}>): Promise<InvocationCoordinates>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { lstat, realpath } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { World, WorldError } from "../world.js";
|
|
4
|
+
import { NoGitWorldError, Repo } from "./repo.js";
|
|
5
|
+
/** Invalid arc material retains the resolved subject for the process-edge refusal. */
|
|
6
|
+
export class KeiyakuArcDocumentError extends Error {
|
|
7
|
+
contract;
|
|
8
|
+
constructor(contract, cause) {
|
|
9
|
+
super(cause.message, { cause });
|
|
10
|
+
this.contract = contract;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class KeiyakuUsageError extends TypeError {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "KeiyakuUsageError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function discoverRepo(path, gitPath) {
|
|
20
|
+
try {
|
|
21
|
+
return { kind: "present", repo: await Repo.at({ path, ...(gitPath === undefined ? {} : { gitPath }) }) };
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error instanceof NoGitWorldError)
|
|
25
|
+
return { kind: "absent", error };
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function managedContractWorktree(root) {
|
|
30
|
+
try {
|
|
31
|
+
const stat = await lstat(resolve(root, ".keiyaku", "KEIYAKU.md"));
|
|
32
|
+
return stat.isFile() && !stat.isSymbolicLink();
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error.code === "ENOENT")
|
|
36
|
+
return false;
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// eslint-disable-next-line complexity -- coordinate discovery preserves independent Repo and World policies.
|
|
41
|
+
export async function invocationCoordinates(input) {
|
|
42
|
+
const gitPath = input.environment.KEIYAKU_GIT_PATH;
|
|
43
|
+
if (gitPath !== undefined && gitPath.trim() === "")
|
|
44
|
+
throw new KeiyakuUsageError("KEIYAKU_GIT_PATH requires a nonblank value");
|
|
45
|
+
let cwd;
|
|
46
|
+
try {
|
|
47
|
+
cwd = await realpath(input.cwd);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
throw new KeiyakuUsageError(`invocation cwd is not an existing directory: ${input.cwd}`);
|
|
51
|
+
}
|
|
52
|
+
const invocation = input.contractWait === true ? undefined : await discoverRepo(cwd, gitPath);
|
|
53
|
+
const selected = input.repo === undefined && invocation !== undefined
|
|
54
|
+
? invocation
|
|
55
|
+
: await discoverRepo(input.repo === undefined ? cwd : resolve(cwd, input.repo), gitPath);
|
|
56
|
+
if (input.use === "required" && selected.kind === "absent")
|
|
57
|
+
throw selected.error;
|
|
58
|
+
const repo = input.use !== "none" && selected.kind === "present" ? selected.repo : undefined;
|
|
59
|
+
if (input.contractWait === true) {
|
|
60
|
+
return {
|
|
61
|
+
cwd,
|
|
62
|
+
...(repo === undefined ? {} : { repo }),
|
|
63
|
+
world: null,
|
|
64
|
+
candidateWorld: null,
|
|
65
|
+
debtContext: { directory: cwd, boundary: cwd, writeRoot: cwd, managed: false },
|
|
66
|
+
establishWorld: async () => {
|
|
67
|
+
throw new Error("Contract wait has no World");
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const worldRepo = invocation?.kind === "present" ? invocation.repo : undefined;
|
|
72
|
+
try {
|
|
73
|
+
const world = await World.resolve({ cwd, ...(worldRepo === undefined ? {} : { repositoryRoot: worldRepo.root }) });
|
|
74
|
+
const boundary = worldRepo === undefined ? (world.root ?? world.candidate ?? cwd) : worldRepo.cwd;
|
|
75
|
+
return {
|
|
76
|
+
cwd,
|
|
77
|
+
...(repo === undefined ? {} : { repo }),
|
|
78
|
+
world: world.root,
|
|
79
|
+
candidateWorld: world.candidate,
|
|
80
|
+
debtContext: {
|
|
81
|
+
directory: cwd,
|
|
82
|
+
boundary,
|
|
83
|
+
writeRoot: worldRepo === undefined ? boundary : cwd,
|
|
84
|
+
managed: await managedContractWorktree(boundary),
|
|
85
|
+
},
|
|
86
|
+
establishWorld: async () => {
|
|
87
|
+
try {
|
|
88
|
+
return await world.establish();
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (error instanceof WorldError)
|
|
92
|
+
throw new KeiyakuUsageError(error.message);
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
if (error instanceof WorldError)
|
|
100
|
+
throw new KeiyakuUsageError(error.message);
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { type AddDebtInput, type AddDebtDocumentInput, type UpdateDebtInput, type DebtQueryExpression, type DebtQuerySort, type DebtAbsent, type DebtCatalogue, type DebtShowResult } from "../debt/index.js";
|
|
2
|
+
import type { KeiyakuAt } from "./keiyaku.js";
|
|
3
|
+
export type DebtSelection = "active" | "closed" | "all";
|
|
4
|
+
export type DebtReadScope = Readonly<{
|
|
5
|
+
scope?: "namespace" | "world";
|
|
6
|
+
namespace?: readonly string[];
|
|
7
|
+
limit?: number;
|
|
8
|
+
}>;
|
|
9
|
+
export type DebtLsInvocation = DebtReadScope & Readonly<{
|
|
10
|
+
of: "debt";
|
|
11
|
+
selection?: DebtSelection;
|
|
12
|
+
}>;
|
|
13
|
+
export type DebtReadyInvocation = DebtReadScope & Readonly<{
|
|
14
|
+
parent?: string;
|
|
15
|
+
}>;
|
|
16
|
+
export type DebtQueryInvocation = DebtReadScope & Readonly<{
|
|
17
|
+
selection?: DebtSelection;
|
|
18
|
+
where?: DebtQueryExpression;
|
|
19
|
+
sort?: DebtQuerySort;
|
|
20
|
+
}>;
|
|
21
|
+
export type DebtUpdateInvocation = UpdateDebtInput & Readonly<{
|
|
22
|
+
id: string;
|
|
23
|
+
}>;
|
|
24
|
+
export type DebtCloseInvocation = Readonly<{
|
|
25
|
+
ids: readonly string[];
|
|
26
|
+
note?: string;
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
}>;
|
|
29
|
+
export type DebtShowInvocation = Readonly<{
|
|
30
|
+
id: string;
|
|
31
|
+
ids?: never;
|
|
32
|
+
}> | Readonly<{
|
|
33
|
+
ids: readonly string[];
|
|
34
|
+
id?: never;
|
|
35
|
+
}>;
|
|
36
|
+
export type DebtContextInvocation = Readonly<{
|
|
37
|
+
namespace?: readonly string[];
|
|
38
|
+
}>;
|
|
39
|
+
declare const absent: DebtAbsent;
|
|
40
|
+
export declare function debtAdd(at: KeiyakuAt, input: AddDebtInput | AddDebtDocumentInput, document: boolean): Promise<Readonly<{
|
|
41
|
+
kind: "refused";
|
|
42
|
+
reason: "invalid-graph";
|
|
43
|
+
diagnostic: string;
|
|
44
|
+
}> | Readonly<{
|
|
45
|
+
kind: "refused";
|
|
46
|
+
reason: "invalid-namespace-context";
|
|
47
|
+
path?: string;
|
|
48
|
+
}> | Readonly<{
|
|
49
|
+
kind: "retry";
|
|
50
|
+
reason: "busy" | "concurrent-modification";
|
|
51
|
+
}> | Readonly<{
|
|
52
|
+
kind: "accepted";
|
|
53
|
+
id: `debt/${string}`;
|
|
54
|
+
warning?: string;
|
|
55
|
+
}>>;
|
|
56
|
+
export declare function debtUpdate(at: KeiyakuAt, input: DebtUpdateInvocation): Promise<Readonly<{
|
|
57
|
+
kind: "refused";
|
|
58
|
+
reason: "debt-missing";
|
|
59
|
+
}> | Readonly<{
|
|
60
|
+
kind: "refused";
|
|
61
|
+
reason: "invalid-graph";
|
|
62
|
+
diagnostic: string;
|
|
63
|
+
}> | Readonly<{
|
|
64
|
+
kind: "refused";
|
|
65
|
+
reason: "relation-owned-by-other";
|
|
66
|
+
related: `debt/${string}`;
|
|
67
|
+
}> | Readonly<{
|
|
68
|
+
kind: "retry";
|
|
69
|
+
reason: "busy" | "concurrent-modification";
|
|
70
|
+
}> | Readonly<{
|
|
71
|
+
kind: "accepted";
|
|
72
|
+
changes?: readonly ("note" | "body" | "parent" | "title" | "priority" | "needs" | "supersedes" | "relates")[];
|
|
73
|
+
warning?: string;
|
|
74
|
+
}>>;
|
|
75
|
+
export declare function debtShow(at: KeiyakuAt, input: DebtShowInvocation): Promise<DebtShowResult | DebtAbsent>;
|
|
76
|
+
export declare function debtClose(at: KeiyakuAt, input: DebtCloseInvocation, verb: "done" | "drop"): Promise<Readonly<{
|
|
77
|
+
items: readonly (Readonly<{
|
|
78
|
+
kind: "refused";
|
|
79
|
+
reason: "debt-missing";
|
|
80
|
+
}> | Readonly<{
|
|
81
|
+
kind: "refused";
|
|
82
|
+
reason: "invalid-lifecycle-transition";
|
|
83
|
+
state: "drop" | "done";
|
|
84
|
+
}> | Readonly<{
|
|
85
|
+
kind: "retry";
|
|
86
|
+
reason: "busy" | "concurrent-modification";
|
|
87
|
+
}> | Readonly<{
|
|
88
|
+
kind: "accepted";
|
|
89
|
+
warning?: string;
|
|
90
|
+
}>)[];
|
|
91
|
+
}>>;
|
|
92
|
+
export declare function debtList(at: KeiyakuAt, input: DebtLsInvocation): Promise<DebtCatalogue>;
|
|
93
|
+
export declare function debtReady(at: KeiyakuAt, input: DebtReadyInvocation, blocked: false): Promise<import("../debt/index.js").DebtReadyList | typeof absent>;
|
|
94
|
+
export declare function debtReady(at: KeiyakuAt, input: DebtReadyInvocation, blocked: true): Promise<import("../debt/index.js").BlockedDebtList | typeof absent>;
|
|
95
|
+
export declare function debtQuery(at: KeiyakuAt, input: DebtQueryInvocation): Promise<import("../debt/index.js").DebtQueryResult>;
|
|
96
|
+
export declare function debtTree(at: KeiyakuAt, input: Readonly<{
|
|
97
|
+
id: string;
|
|
98
|
+
}>): Promise<Readonly<{
|
|
99
|
+
kind: "absent";
|
|
100
|
+
}> | Readonly<{
|
|
101
|
+
title: string;
|
|
102
|
+
state: "open" | "drop" | "done";
|
|
103
|
+
priority: 0 | 1 | 2 | 3;
|
|
104
|
+
kind: "present";
|
|
105
|
+
children?: readonly import("../debt/board.js").DebtTreeNode[];
|
|
106
|
+
}> | Readonly<{
|
|
107
|
+
kind: "missing";
|
|
108
|
+
}>>;
|
|
109
|
+
export declare function debtDoctor(at: KeiyakuAt): Promise<Readonly<{
|
|
110
|
+
kind: "absent";
|
|
111
|
+
}> | Readonly<{
|
|
112
|
+
kind: "present";
|
|
113
|
+
issues?: readonly (Readonly<{
|
|
114
|
+
kind: "missing-target";
|
|
115
|
+
debtId: `debt/${string}`;
|
|
116
|
+
relation: "parent" | "needs" | "supersedes" | "relates";
|
|
117
|
+
target: `debt/${string}`;
|
|
118
|
+
}> | Readonly<{
|
|
119
|
+
kind: "self-relation";
|
|
120
|
+
debtId: `debt/${string}`;
|
|
121
|
+
relation: "parent" | "needs" | "supersedes" | "relates";
|
|
122
|
+
}> | Readonly<{
|
|
123
|
+
kind: "cycle";
|
|
124
|
+
relation: "parent" | "needs" | "supersedes";
|
|
125
|
+
debts: readonly `debt/${string}`[];
|
|
126
|
+
}>)[];
|
|
127
|
+
}>>;
|
|
128
|
+
export declare function debtContext(at: KeiyakuAt, input: DebtContextInvocation): Promise<{
|
|
129
|
+
readonly kind: "present";
|
|
130
|
+
readonly source: "default-root";
|
|
131
|
+
readonly path?: never;
|
|
132
|
+
} | {
|
|
133
|
+
readonly kind: "refused";
|
|
134
|
+
readonly path: string;
|
|
135
|
+
readonly source?: never;
|
|
136
|
+
} | {
|
|
137
|
+
readonly namespace?: string;
|
|
138
|
+
readonly kind: "present";
|
|
139
|
+
readonly source: "contract-installed" | "local-override";
|
|
140
|
+
readonly path?: never;
|
|
141
|
+
}>;
|
|
142
|
+
export {};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { Debts, debtRowViewLimit, } from "../debt/index.js";
|
|
2
|
+
import { addDebt, addDebtDocument } from "../debt/operations.js";
|
|
3
|
+
import { addInput, addDocumentInput, closed, record, namespace, debtId, debtIds, text, signal, updateInput, sort, } from "../debt/input.js";
|
|
4
|
+
import { parseDebtCreationDocument } from "../debt/document.js";
|
|
5
|
+
import { debtQuerySelection, normalizeDebtQuery } from "../debt/query.js";
|
|
6
|
+
import { installNamespaceContext, resolveDebtNamespaceContext, validateNamespaceContext } from "../debt/context.js";
|
|
7
|
+
import { invocationCoordinates, KeiyakuUsageError } from "./keiyaku-coordinates.js";
|
|
8
|
+
import { resolveActor } from "./keiyaku-attribution.js";
|
|
9
|
+
const coordinates = (at) => invocationCoordinates({ ...at, use: "none" });
|
|
10
|
+
const absent = { kind: "absent" };
|
|
11
|
+
const missing = () => ({ kind: "refused", reason: "debt-missing" });
|
|
12
|
+
function selection(value) {
|
|
13
|
+
if (value === undefined)
|
|
14
|
+
return "active";
|
|
15
|
+
if (value !== "active" && value !== "closed" && value !== "all")
|
|
16
|
+
throw new TypeError("selection must be active, closed, or all");
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function readInput(input, label, extra) {
|
|
20
|
+
const v = record(input, `${label} input`);
|
|
21
|
+
closed(v, ["scope", "namespace", "limit", ...extra], `${label} input`);
|
|
22
|
+
if (v.scope !== undefined && v.scope !== "namespace" && v.scope !== "world")
|
|
23
|
+
throw new TypeError("scope must be namespace or world");
|
|
24
|
+
const ns = namespace(v.namespace);
|
|
25
|
+
if (v.scope === "world" && ns !== undefined)
|
|
26
|
+
throw new TypeError("namespace and world scope are mutually exclusive");
|
|
27
|
+
debtRowViewLimit(v.limit);
|
|
28
|
+
return v;
|
|
29
|
+
}
|
|
30
|
+
async function selectedScope(at, input) {
|
|
31
|
+
if (input.scope === "world")
|
|
32
|
+
return { scope: "world" };
|
|
33
|
+
if (input.namespace !== undefined)
|
|
34
|
+
return { namespace: input.namespace };
|
|
35
|
+
const context = await resolveDebtNamespaceContext(at.debtContext);
|
|
36
|
+
return "kind" in context
|
|
37
|
+
? { kind: "refused", reason: context.kind, path: context.path }
|
|
38
|
+
: { namespace: context.namespace };
|
|
39
|
+
}
|
|
40
|
+
export async function debtAdd(at, input, document) {
|
|
41
|
+
const parsed = document ? addDocumentInput(input) : addInput(input);
|
|
42
|
+
if (document)
|
|
43
|
+
parseDebtCreationDocument(parsed.markdown);
|
|
44
|
+
const actor = resolveActor({ env: at.environment, ...(parsed.actor === undefined ? {} : { actor: parsed.actor }) });
|
|
45
|
+
const coord = await coordinates(at);
|
|
46
|
+
const world = coord.world ?? (await coord.establishWorld());
|
|
47
|
+
const scope = parsed.namespace === undefined ? await selectedScope(coord, {}) : { namespace: parsed.namespace };
|
|
48
|
+
if ("kind" in scope)
|
|
49
|
+
return scope;
|
|
50
|
+
const composed = { ...parsed, ...scope, ...(actor === undefined ? {} : { actor }) };
|
|
51
|
+
return document ? addDebtDocument(world, composed) : addDebt(world, composed);
|
|
52
|
+
}
|
|
53
|
+
export async function debtUpdate(at, input) {
|
|
54
|
+
const { id: raw, ...rest } = record(input, "update input");
|
|
55
|
+
const id = debtId(raw), coord = await coordinates(at);
|
|
56
|
+
if (coord.world !== null)
|
|
57
|
+
return Debts.of(coord.world)
|
|
58
|
+
.debt({ id })
|
|
59
|
+
.update(rest);
|
|
60
|
+
updateInput(rest).signal?.throwIfAborted();
|
|
61
|
+
return missing();
|
|
62
|
+
}
|
|
63
|
+
export async function debtShow(at, input) {
|
|
64
|
+
const v = record(input, "show input");
|
|
65
|
+
closed(v, ["id", "ids"], "show input");
|
|
66
|
+
if ((v.id === undefined) === (v.ids === undefined))
|
|
67
|
+
throw new TypeError("show requires id or ids");
|
|
68
|
+
const plural = v.ids !== undefined;
|
|
69
|
+
if (plural && (!Array.isArray(v.ids) || v.ids.length === 0))
|
|
70
|
+
throw new TypeError("ids requires at least one DebtId");
|
|
71
|
+
const ids = plural ? v.ids.map(debtId) : [debtId(v.id)];
|
|
72
|
+
const coord = await coordinates(at);
|
|
73
|
+
if (coord.world === null)
|
|
74
|
+
return absent;
|
|
75
|
+
const items = [];
|
|
76
|
+
for (const id of ids) {
|
|
77
|
+
const result = await Debts.of(coord.world).debt({ id }).read();
|
|
78
|
+
items.push(result.kind === "present" ? { ...result, kind: "found" } : result);
|
|
79
|
+
}
|
|
80
|
+
return { kind: "present", items };
|
|
81
|
+
}
|
|
82
|
+
export async function debtClose(at, input, verb) {
|
|
83
|
+
const v = record(input, "close input");
|
|
84
|
+
closed(v, ["ids", "note", "signal"], "close input");
|
|
85
|
+
const coord = await coordinates(at);
|
|
86
|
+
if (coord.world !== null)
|
|
87
|
+
return Debts.of(coord.world).batch({ ...input, verb });
|
|
88
|
+
const ids = debtIds(v.ids, "ids");
|
|
89
|
+
if (ids === undefined || ids.length === 0)
|
|
90
|
+
throw new TypeError("ids requires at least one DebtId");
|
|
91
|
+
text(v.note, "note");
|
|
92
|
+
signal(v.signal)?.throwIfAborted();
|
|
93
|
+
return { items: ids.map(() => missing()) };
|
|
94
|
+
}
|
|
95
|
+
export async function debtList(at, input) {
|
|
96
|
+
const v = readInput(input, "list", ["of", "selection"]);
|
|
97
|
+
if (v.of !== "debt")
|
|
98
|
+
throw new TypeError("of must be debt");
|
|
99
|
+
const selected = selection(v.selection), coord = await coordinates(at);
|
|
100
|
+
if (coord.world === null)
|
|
101
|
+
return absent;
|
|
102
|
+
const scope = await selectedScope(coord, input);
|
|
103
|
+
if ("kind" in scope)
|
|
104
|
+
return { kind: scope.reason, path: scope.path };
|
|
105
|
+
return Debts.of(coord.world).list({
|
|
106
|
+
...scope,
|
|
107
|
+
selection: selected,
|
|
108
|
+
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
export async function debtReady(at, input, blocked) {
|
|
112
|
+
const v = readInput(input, blocked ? "blocked" : "ready", ["parent"]);
|
|
113
|
+
if (v.parent !== undefined)
|
|
114
|
+
debtId(v.parent);
|
|
115
|
+
const coord = await coordinates(at);
|
|
116
|
+
if (coord.world === null)
|
|
117
|
+
return absent;
|
|
118
|
+
const scope = await selectedScope(coord, input);
|
|
119
|
+
if ("kind" in scope)
|
|
120
|
+
return scope;
|
|
121
|
+
const args = {
|
|
122
|
+
...scope,
|
|
123
|
+
...(input.parent === undefined ? {} : { parent: input.parent }),
|
|
124
|
+
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
125
|
+
};
|
|
126
|
+
return blocked ? Debts.of(coord.world).blocked(args) : Debts.of(coord.world).ready(args);
|
|
127
|
+
}
|
|
128
|
+
export async function debtQuery(at, input) {
|
|
129
|
+
const v = readInput(input, "query", ["selection", "where", "sort"]);
|
|
130
|
+
const selected = selection(v.selection);
|
|
131
|
+
if (v.where !== undefined)
|
|
132
|
+
normalizeDebtQuery(v.where);
|
|
133
|
+
sort(v.sort);
|
|
134
|
+
const coord = await coordinates(at);
|
|
135
|
+
if (coord.world === null)
|
|
136
|
+
return absent;
|
|
137
|
+
const scope = await selectedScope(coord, input);
|
|
138
|
+
if ("kind" in scope)
|
|
139
|
+
return scope;
|
|
140
|
+
return Debts.of(coord.world).query({
|
|
141
|
+
...scope,
|
|
142
|
+
where: debtQuerySelection(selected, input.where),
|
|
143
|
+
...(input.sort === undefined ? {} : { sort: input.sort }),
|
|
144
|
+
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
export async function debtTree(at, input) {
|
|
148
|
+
const v = record(input, "tree input");
|
|
149
|
+
closed(v, ["id"], "tree input");
|
|
150
|
+
const id = debtId(v.id), coord = await coordinates(at);
|
|
151
|
+
return coord.world === null ? absent : Debts.of(coord.world).debt({ id }).tree();
|
|
152
|
+
}
|
|
153
|
+
export async function debtDoctor(at) {
|
|
154
|
+
const coord = await coordinates(at);
|
|
155
|
+
return coord.world === null ? absent : Debts.of(coord.world).doctor();
|
|
156
|
+
}
|
|
157
|
+
export async function debtContext(at, input) {
|
|
158
|
+
const v = record(input, "context input");
|
|
159
|
+
closed(v, ["namespace"], "context input");
|
|
160
|
+
if (v.namespace !== undefined) {
|
|
161
|
+
try {
|
|
162
|
+
validateNamespaceContext(v.namespace);
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
if (error instanceof TypeError)
|
|
166
|
+
throw new KeiyakuUsageError(error.message);
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const coord = await coordinates(at);
|
|
171
|
+
if (v.namespace !== undefined) {
|
|
172
|
+
if (coord.world === null)
|
|
173
|
+
await coord.establishWorld();
|
|
174
|
+
await installNamespaceContext(coord.debtContext.writeRoot, v.namespace);
|
|
175
|
+
}
|
|
176
|
+
else if (coord.world === null)
|
|
177
|
+
return { kind: "present", source: "default-root" };
|
|
178
|
+
const resolved = await resolveDebtNamespaceContext(coord.debtContext);
|
|
179
|
+
if ("kind" in resolved)
|
|
180
|
+
return { kind: "refused", path: resolved.path };
|
|
181
|
+
if (resolved.source === "default-root")
|
|
182
|
+
return { kind: "present", source: resolved.source };
|
|
183
|
+
return {
|
|
184
|
+
kind: "present",
|
|
185
|
+
source: resolved.source,
|
|
186
|
+
...(resolved.namespace.length === 0 ? {} : { namespace: resolved.namespace.join("/") }),
|
|
187
|
+
};
|
|
188
|
+
}
|