@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,216 +1,603 @@
|
|
|
1
1
|
/** @architectureCompositionRoot */
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
4
|
-
import { reconcileEffectSchema } from "../git/reconcile.js";
|
|
3
|
+
import { contractFileLagSchema } from "../contract-worktree.js";
|
|
5
4
|
import { AuthorityCorruptionError } from "../core/facts/errors.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
5
|
+
import { gitReconcileLagSchema } from "../git/reconcile.js";
|
|
6
|
+
import { contractIdSchema, snapshotIdSchema } from "../git/identity.js";
|
|
7
|
+
import { compactPlacement, placedSchema } from "../protocol/completion.js";
|
|
8
|
+
import { worldRootSchema } from "../world.js";
|
|
9
|
+
import { compactDelivery } from "./delivery.js";
|
|
10
|
+
import { compactRetry, retrySchema, executionIssueSchema } from "../protocol/result-reasons.js";
|
|
11
|
+
export { executionIssueSchema } from "../protocol/result-reasons.js";
|
|
12
|
+
export const reconciliationLagSchema = z.union([gitReconcileLagSchema, contractFileLagSchema]);
|
|
13
|
+
function classifyReconcileLag(kind) {
|
|
14
|
+
switch (kind) {
|
|
15
|
+
case "worktree-retained":
|
|
16
|
+
case "unsealed-bytes":
|
|
17
|
+
return { scope: "none", failure: false };
|
|
18
|
+
case "worktree-follow-retained":
|
|
19
|
+
return { scope: "continuation", failure: false };
|
|
20
|
+
case "target-checkout-retained":
|
|
21
|
+
case "target-workspace-retained":
|
|
22
|
+
return { scope: "placement", failure: true };
|
|
23
|
+
case "worktree-hook-failed":
|
|
24
|
+
case "reconcile-failed":
|
|
25
|
+
case "contract-file-failed":
|
|
26
|
+
return { scope: "reconciliation", failure: true };
|
|
27
|
+
default: {
|
|
28
|
+
const exhaustive = kind;
|
|
29
|
+
return exhaustive;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function reconcileLagScope(lag) {
|
|
34
|
+
return classifyReconcileLag(lag.kind).scope;
|
|
35
|
+
}
|
|
36
|
+
export function reconcileLagIsFailure(lag) {
|
|
37
|
+
return classifyReconcileLag(lag.kind).failure;
|
|
38
|
+
}
|
|
39
|
+
const scoped = { contractId: contractIdSchema.exactOptional() };
|
|
40
|
+
const diagnostic = z.string().min(1);
|
|
41
|
+
const path = z.string().min(1);
|
|
42
|
+
export const reconcileIssueSchema = z.union([
|
|
43
|
+
z
|
|
44
|
+
.strictObject({ ...scoped, kind: z.literal("worktree-retained"), path, diagnostic: diagnostic.exactOptional() })
|
|
45
|
+
.readonly(),
|
|
46
|
+
z
|
|
47
|
+
.strictObject({
|
|
48
|
+
...scoped,
|
|
49
|
+
kind: z.literal("worktree-follow-retained"),
|
|
50
|
+
path,
|
|
51
|
+
reason: z.enum(["head-moved", "head-attached", "operation-in-progress"]),
|
|
52
|
+
})
|
|
53
|
+
.readonly(),
|
|
54
|
+
z.strictObject({ ...scoped, kind: z.literal("unsealed-bytes"), path }).readonly(),
|
|
55
|
+
z
|
|
56
|
+
.strictObject({
|
|
57
|
+
...scoped,
|
|
58
|
+
kind: z.literal("target-checkout-retained"),
|
|
59
|
+
path,
|
|
60
|
+
target: z.string().min(1),
|
|
61
|
+
diagnostic,
|
|
62
|
+
})
|
|
63
|
+
.readonly(),
|
|
64
|
+
z
|
|
65
|
+
.strictObject({
|
|
66
|
+
...scoped,
|
|
67
|
+
kind: z.literal("target-workspace-retained"),
|
|
68
|
+
targetContractId: contractIdSchema,
|
|
69
|
+
reason: z.enum(["unappointed", "missing", "association", "replaced", "attached", "uncommitted", "operation"]),
|
|
70
|
+
})
|
|
71
|
+
.readonly(),
|
|
72
|
+
z
|
|
73
|
+
.strictObject({
|
|
74
|
+
...scoped,
|
|
75
|
+
kind: z.literal("worktree-hook-failed"),
|
|
76
|
+
phase: z.enum(["create", "destroy"]),
|
|
77
|
+
path,
|
|
78
|
+
name: z.string().min(1),
|
|
79
|
+
diagnostic,
|
|
80
|
+
})
|
|
81
|
+
.readonly(),
|
|
82
|
+
z.strictObject({ ...scoped, kind: z.literal("reconcile-failed"), diagnostic }).readonly(),
|
|
83
|
+
z.strictObject({ ...scoped, kind: z.literal("contract-file-failed"), path, diagnostic }).readonly(),
|
|
84
|
+
]);
|
|
85
|
+
const checkResource = {
|
|
86
|
+
snapshot: snapshotIdSchema.exactOptional(),
|
|
87
|
+
requirement: z.string().min(1).exactOptional(),
|
|
88
|
+
index: z.number().int().positive().exactOptional(),
|
|
89
|
+
};
|
|
90
|
+
export const cleanupIssueSchema = z.union([
|
|
91
|
+
z.strictObject({ ...scoped, kind: z.literal("decode-channel-retirement"), diagnostic }).readonly(),
|
|
92
|
+
z
|
|
93
|
+
.strictObject({
|
|
94
|
+
...scoped,
|
|
95
|
+
kind: z.literal("verification-cleanup"),
|
|
96
|
+
...checkResource,
|
|
97
|
+
name: z.string().min(1),
|
|
98
|
+
diagnostic,
|
|
99
|
+
})
|
|
100
|
+
.readonly(),
|
|
101
|
+
z
|
|
102
|
+
.strictObject({
|
|
103
|
+
...scoped,
|
|
104
|
+
kind: z.literal("worktree-leak"),
|
|
105
|
+
...checkResource,
|
|
106
|
+
path: path.exactOptional(),
|
|
107
|
+
diagnostic,
|
|
108
|
+
})
|
|
109
|
+
.readonly(),
|
|
110
|
+
z.strictObject({ ...scoped, kind: z.literal("private-state-seat-close"), diagnostic }).readonly(),
|
|
111
|
+
]);
|
|
112
|
+
const settlementIssueSchema = z
|
|
113
|
+
.strictObject({
|
|
114
|
+
...scoped,
|
|
115
|
+
kind: z.literal("settlement-failed"),
|
|
116
|
+
debtId: z.string().min(1).exactOptional(),
|
|
117
|
+
diagnostic,
|
|
118
|
+
})
|
|
119
|
+
.readonly();
|
|
120
|
+
const issueLeaves = [
|
|
121
|
+
...reconcileIssueSchema.options,
|
|
122
|
+
...cleanupIssueSchema.options,
|
|
123
|
+
executionIssueSchema.unwrap().extend(scoped).readonly(),
|
|
124
|
+
settlementIssueSchema,
|
|
125
|
+
];
|
|
126
|
+
export const invocationIssueSchema = z.union(issueLeaves);
|
|
127
|
+
const localLeaves = [
|
|
128
|
+
reconcileIssueSchema.options[0],
|
|
129
|
+
reconcileIssueSchema.options[2],
|
|
130
|
+
reconcileIssueSchema.options[3],
|
|
131
|
+
reconcileIssueSchema.options[4],
|
|
132
|
+
reconcileIssueSchema.options[5],
|
|
133
|
+
reconcileIssueSchema.options[6],
|
|
134
|
+
reconcileIssueSchema.options[7],
|
|
135
|
+
cleanupIssueSchema.options[0],
|
|
136
|
+
cleanupIssueSchema.options[3],
|
|
137
|
+
issueLeaves[12],
|
|
138
|
+
settlementIssueSchema,
|
|
139
|
+
];
|
|
140
|
+
export const localIssueSchema = z.union(localLeaves);
|
|
141
|
+
export const completionIssueSchema = z.union([
|
|
142
|
+
...reconcileIssueSchema.options,
|
|
143
|
+
cleanupIssueSchema.options[0],
|
|
144
|
+
cleanupIssueSchema.options[3],
|
|
145
|
+
issueLeaves[12],
|
|
146
|
+
settlementIssueSchema,
|
|
147
|
+
]);
|
|
148
|
+
export const previewIssueSchema = cleanupIssueSchema.options[0].unwrap().omit({ contractId: true }).readonly();
|
|
149
|
+
export const reconcilePublicIssueSchema = z.union([
|
|
150
|
+
reconcileIssueSchema.options[0],
|
|
151
|
+
reconcileIssueSchema.options[2],
|
|
152
|
+
reconcileIssueSchema.options[3],
|
|
153
|
+
reconcileIssueSchema.options[4],
|
|
154
|
+
reconcileIssueSchema.options[5],
|
|
155
|
+
reconcileIssueSchema.options[6],
|
|
156
|
+
reconcileIssueSchema.options[7],
|
|
157
|
+
cleanupIssueSchema.options[3],
|
|
158
|
+
settlementIssueSchema,
|
|
159
|
+
]);
|
|
160
|
+
export function invocationIssueIsFailure(issue) {
|
|
161
|
+
switch (issue.kind) {
|
|
162
|
+
case "worktree-retained":
|
|
163
|
+
case "unsealed-bytes":
|
|
164
|
+
case "worktree-follow-retained":
|
|
165
|
+
case "verification-cleanup":
|
|
166
|
+
case "worktree-leak":
|
|
167
|
+
case "decode-channel-retirement":
|
|
168
|
+
return false;
|
|
169
|
+
default:
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** Invocation classification consumes owner conclusions, never a fresh authority read. */
|
|
174
|
+
export function contractOutcomeDisposition(result) {
|
|
175
|
+
if (result.kind === "refused")
|
|
176
|
+
return "refused";
|
|
177
|
+
if (result.kind === "retry")
|
|
178
|
+
return "retryable";
|
|
179
|
+
let retry = false;
|
|
180
|
+
const stopped = (stop) => {
|
|
181
|
+
if (stop.kind === "retry") {
|
|
182
|
+
retry = true;
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
return !["placed", "gates-unsatisfied", "prerequisites-unsatisfied", "delivery-missing", "physical-lag"].includes(stop.kind);
|
|
186
|
+
};
|
|
187
|
+
if (result.issues?.some(invocationIssueIsFailure))
|
|
188
|
+
return "failed";
|
|
189
|
+
if (result.placement !== undefined && stopped(result.placement))
|
|
190
|
+
return "failed";
|
|
191
|
+
for (const check of result.checks ?? []) {
|
|
192
|
+
if (check.kind !== "terminal" || check.verdict === "unsatisfied")
|
|
193
|
+
return "failed";
|
|
194
|
+
if (typeof check.admission === "object" && stopped(check.admission))
|
|
195
|
+
return "failed";
|
|
196
|
+
}
|
|
197
|
+
for (const stop of result.continuation?.stopped ?? [])
|
|
198
|
+
if (stopped(stop))
|
|
199
|
+
return "failed";
|
|
200
|
+
return retry ? "retryable" : "accepted";
|
|
201
|
+
}
|
|
14
202
|
const resetOwnerSchema = z.enum(["akuma", "git", "debt", "world"]);
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
203
|
+
export const resetIssueSchema = z.union([
|
|
204
|
+
z
|
|
205
|
+
.strictObject({ kind: z.literal("reset-owner-stopped"), owner: resetOwnerSchema, diagnostic: z.string().min(1) })
|
|
206
|
+
.readonly(),
|
|
207
|
+
z.strictObject({ kind: z.literal("reset-residue"), diagnostic: z.string().min(1) }).readonly(),
|
|
19
208
|
]);
|
|
20
|
-
|
|
209
|
+
export function resetIssueIsRequired(issue) {
|
|
210
|
+
switch (issue.kind) {
|
|
211
|
+
case "reset-owner-stopped":
|
|
212
|
+
return true;
|
|
213
|
+
case "reset-residue":
|
|
214
|
+
return false;
|
|
215
|
+
default: {
|
|
216
|
+
return issue;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const admittedFields = scoped;
|
|
221
|
+
export const admittedEvidenceSchema = z.union([
|
|
222
|
+
z.strictObject({ kind: z.enum(["bind", "amend", "claimed", "abandoned"]), ...admittedFields }).readonly(),
|
|
21
223
|
z
|
|
22
|
-
.
|
|
23
|
-
kind: z.literal("
|
|
24
|
-
|
|
25
|
-
|
|
224
|
+
.strictObject({
|
|
225
|
+
kind: z.literal("deliver"),
|
|
226
|
+
...admittedFields,
|
|
227
|
+
candidate: snapshotIdSchema,
|
|
228
|
+
integration: snapshotIdSchema,
|
|
229
|
+
contentId: z.string().min(1),
|
|
26
230
|
})
|
|
27
|
-
.
|
|
231
|
+
.readonly(),
|
|
28
232
|
z
|
|
29
|
-
.
|
|
30
|
-
kind: z.literal("
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
233
|
+
.strictObject({
|
|
234
|
+
kind: z.literal("reintegrated"),
|
|
235
|
+
...admittedFields,
|
|
236
|
+
integration: snapshotIdSchema,
|
|
237
|
+
predecessor: snapshotIdSchema,
|
|
34
238
|
})
|
|
35
|
-
.
|
|
36
|
-
.refine((value) => value.affects === reconcileLagScope(value.lag), "invalid reconciliation requiredness"),
|
|
239
|
+
.readonly(),
|
|
37
240
|
z
|
|
38
|
-
.
|
|
39
|
-
kind: z.literal("
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
diagnostic: z.string().min(1),
|
|
241
|
+
.strictObject({
|
|
242
|
+
kind: z.literal("attestation"),
|
|
243
|
+
...admittedFields,
|
|
244
|
+
requirement: z.string().exactOptional(),
|
|
245
|
+
verdict: z.enum(["satisfied", "unsatisfied"]).exactOptional(),
|
|
44
246
|
})
|
|
45
|
-
.
|
|
247
|
+
.readonly(),
|
|
46
248
|
z
|
|
47
|
-
.
|
|
48
|
-
.
|
|
49
|
-
|
|
249
|
+
.strictObject({
|
|
250
|
+
kind: z.literal("arc"),
|
|
251
|
+
...admittedFields,
|
|
252
|
+
chapter: z.number().int().positive(),
|
|
253
|
+
})
|
|
254
|
+
.readonly(),
|
|
255
|
+
]);
|
|
256
|
+
export const meaningfulEffectSchema = z.union([
|
|
257
|
+
z.strictObject({ kind: z.enum(["worktree-created", "worktree-removed"]), path }).readonly(),
|
|
50
258
|
z
|
|
51
|
-
.
|
|
52
|
-
.
|
|
53
|
-
|
|
259
|
+
.strictObject({ kind: z.literal("worktree-followed"), path, before: snapshotIdSchema, after: snapshotIdSchema })
|
|
260
|
+
.readonly(),
|
|
261
|
+
z.strictObject({ kind: z.literal("recovery-snapshot"), snapshot: snapshotIdSchema }).readonly(),
|
|
262
|
+
z.strictObject({ kind: z.literal("target-checkout"), path, target: z.string().min(1) }).readonly(),
|
|
54
263
|
z
|
|
55
|
-
.
|
|
56
|
-
kind: z.literal("
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
diagnostic: z.string().refine((value) => value.trim() !== ""),
|
|
264
|
+
.strictObject({
|
|
265
|
+
kind: z.literal("ref"),
|
|
266
|
+
name: z.string().min(1),
|
|
267
|
+
before: z.string().nullable(),
|
|
268
|
+
after: z.string().nullable(),
|
|
61
269
|
})
|
|
62
|
-
.
|
|
63
|
-
z.
|
|
64
|
-
z.object({ kind: z.literal("worktree-retained"), contract: contractIdSchema, path: z.string().min(1) }).strict(),
|
|
270
|
+
.readonly(),
|
|
271
|
+
z.strictObject({ kind: z.literal("debt-settled"), debtId: z.string().min(1) }).readonly(),
|
|
65
272
|
]);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
273
|
+
export function compactEffect(effect) {
|
|
274
|
+
switch (effect.kind) {
|
|
275
|
+
case "worktree":
|
|
276
|
+
if (effect.action === "unchanged")
|
|
277
|
+
return undefined;
|
|
278
|
+
if (effect.action === "followed")
|
|
279
|
+
return { kind: "worktree-followed", path: effect.path, before: effect.before, after: effect.after };
|
|
280
|
+
return { kind: effect.action === "created" ? "worktree-created" : "worktree-removed", path: effect.path };
|
|
281
|
+
case "ref":
|
|
282
|
+
return effect.before === effect.after
|
|
283
|
+
? undefined
|
|
284
|
+
: { kind: "ref", name: effect.name, before: effect.before, after: effect.after };
|
|
285
|
+
case "target-checkout":
|
|
286
|
+
return { kind: effect.kind, path: effect.path, target: effect.target };
|
|
287
|
+
case "recovery-snapshot":
|
|
288
|
+
return { kind: effect.kind, snapshot: effect.snapshot };
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
export const recoverySnapshotSchema = z.strictObject({ ...scoped, snapshot: snapshotIdSchema }).readonly();
|
|
292
|
+
const exceptionalEffectSchema = z.union([
|
|
293
|
+
...meaningfulEffectSchema.options.map((schema) => schema.unwrap().extend(scoped).readonly()),
|
|
294
|
+
placedSchema.unwrap().extend(scoped).readonly(),
|
|
76
295
|
]);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
296
|
+
export function operationOutcomeSchema(fields, refusal, issues) {
|
|
297
|
+
return z.union([
|
|
298
|
+
z
|
|
299
|
+
.strictObject({
|
|
300
|
+
kind: z.literal("accepted"),
|
|
301
|
+
contractId: contractIdSchema,
|
|
302
|
+
issues: z.array(issues).min(1).readonly().exactOptional(),
|
|
303
|
+
recoverySnapshots: z.array(recoverySnapshotSchema).min(1).readonly().exactOptional(),
|
|
304
|
+
...fields,
|
|
305
|
+
})
|
|
306
|
+
.readonly(),
|
|
307
|
+
z.strictObject({ kind: z.literal("refused"), contractId: contractIdSchema, reason: refusal }).readonly(),
|
|
308
|
+
retrySchema.options[0].unwrap().extend({ contractId: contractIdSchema }).readonly(),
|
|
309
|
+
retrySchema.options[1].unwrap().extend({ contractId: contractIdSchema }).readonly(),
|
|
310
|
+
]);
|
|
80
311
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
312
|
+
export const handoffOutcomeSchema = z
|
|
313
|
+
.strictObject({
|
|
314
|
+
kind: z.literal("handoff"),
|
|
315
|
+
contractId: contractIdSchema,
|
|
316
|
+
worktreePath: z.string().min(1),
|
|
317
|
+
targetHead: snapshotIdSchema,
|
|
318
|
+
conflictPaths: z.array(z.string().min(1)).min(1).readonly(),
|
|
319
|
+
handoffBase: snapshotIdSchema,
|
|
320
|
+
})
|
|
321
|
+
.readonly();
|
|
322
|
+
export const resetOutcomeSchema = z.union([
|
|
323
|
+
z
|
|
324
|
+
.strictObject({
|
|
325
|
+
kind: z.literal("accepted"),
|
|
326
|
+
refsRemoved: z.number().int().nonnegative().exactOptional(),
|
|
327
|
+
worktreesRemoved: z.number().int().nonnegative().exactOptional(),
|
|
328
|
+
debtsRemoved: z.number().int().nonnegative().exactOptional(),
|
|
329
|
+
issues: z.array(resetIssueSchema).min(1).readonly().exactOptional(),
|
|
330
|
+
})
|
|
331
|
+
.readonly(),
|
|
332
|
+
z.strictObject({ kind: z.literal("refused"), world: worldRootSchema }).readonly(),
|
|
333
|
+
]);
|
|
334
|
+
export function invocationIssues(effects, primary, snapshot) {
|
|
335
|
+
const issues = [];
|
|
336
|
+
for (const effect of effects) {
|
|
337
|
+
if (effect.kind !== "issue")
|
|
338
|
+
continue;
|
|
339
|
+
const owner = effect.contract === primary ? {} : { contractId: effect.contract };
|
|
340
|
+
const issue = effect.issue;
|
|
341
|
+
if ((issue.kind === "verification-cleanup" || issue.kind === "worktree-leak") &&
|
|
342
|
+
effect.contract === primary &&
|
|
343
|
+
issue.snapshot !== undefined &&
|
|
344
|
+
issue.snapshot === snapshot) {
|
|
345
|
+
const { snapshot: _snapshot, ...rest } = issue;
|
|
346
|
+
issues.push({ ...rest, ...owner });
|
|
347
|
+
}
|
|
348
|
+
else
|
|
349
|
+
issues.push({ ...issue, ...owner });
|
|
350
|
+
}
|
|
351
|
+
return uniqueIssues(issues);
|
|
95
352
|
}
|
|
96
|
-
function
|
|
97
|
-
|
|
353
|
+
function uniqueIssues(issues) {
|
|
354
|
+
const diagnosedRetentions = new Set(issues.flatMap((issue) => issue.kind === "worktree-retained" && issue.diagnostic !== undefined
|
|
355
|
+
? [JSON.stringify([issue.contractId, issue.path])]
|
|
356
|
+
: []));
|
|
357
|
+
return [...new Map(issues.map((issue) => [JSON.stringify(issue), issue])).values()].filter((issue) => issue.kind !== "worktree-retained" ||
|
|
358
|
+
issue.diagnostic !== undefined ||
|
|
359
|
+
!diagnosedRetentions.has(JSON.stringify([issue.contractId, issue.path])));
|
|
98
360
|
}
|
|
99
|
-
function
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
361
|
+
function admissionEvidence(fact, primary) {
|
|
362
|
+
const base = fact.contract === primary ? {} : { contractId: fact.contract };
|
|
363
|
+
switch (fact.kind) {
|
|
364
|
+
case "deliver":
|
|
365
|
+
return {
|
|
366
|
+
...base,
|
|
367
|
+
kind: fact.kind,
|
|
368
|
+
candidate: fact.data.tenderSnapshot,
|
|
369
|
+
integration: fact.data.integration.snapshot,
|
|
370
|
+
contentId: fact.data.integration.changeId,
|
|
371
|
+
};
|
|
372
|
+
case "reintegrated":
|
|
373
|
+
return { ...base, kind: fact.kind, integration: fact.data.snapshot, predecessor: fact.data.predecessor };
|
|
374
|
+
case "attestation":
|
|
375
|
+
return {
|
|
376
|
+
...base,
|
|
377
|
+
kind: fact.kind,
|
|
378
|
+
...(fact.data.gate === "verified" ? { requirement: fact.data.requirement, verdict: fact.data.verdict } : {}),
|
|
379
|
+
};
|
|
380
|
+
case "arc":
|
|
381
|
+
return { ...base, kind: fact.kind, chapter: fact.data.seq };
|
|
382
|
+
default:
|
|
383
|
+
return { ...base, kind: fact.kind };
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
function physicalEvidence(snapshot, primary) {
|
|
387
|
+
const effects = [];
|
|
388
|
+
for (const record of snapshot.effects) {
|
|
389
|
+
if (record.kind !== "settlement-action" && record.kind !== "movement")
|
|
390
|
+
continue;
|
|
391
|
+
const owner = record.contract === primary ? {} : { contractId: record.contract };
|
|
392
|
+
if (record.kind === "settlement-action") {
|
|
393
|
+
effects.push({ ...owner, kind: "debt-settled", debtId: record.action.debtId });
|
|
394
|
+
continue;
|
|
105
395
|
}
|
|
106
|
-
|
|
107
|
-
pending.push(surface("placement", true));
|
|
108
|
-
else if (effect.kind === "settlement-lag")
|
|
109
|
-
pending.push(surface("settlement", true));
|
|
110
|
-
else if (effect.kind === "cleanup")
|
|
111
|
-
pending.push(surface("cleanup", false));
|
|
112
|
-
else if (effect.kind === "execution-stopped")
|
|
113
|
-
pending.push(surface(stopSurface(effect.stage), true));
|
|
114
|
-
else if (effect.kind === "reset-owner-stopped")
|
|
115
|
-
pending.push(surface("reset", true));
|
|
116
|
-
else if (effect.kind === "reset-residue")
|
|
117
|
-
pending.push(surface("reset", false));
|
|
396
|
+
effects.push({ ...record.effect, ...owner });
|
|
118
397
|
}
|
|
119
|
-
return
|
|
398
|
+
return [...new Map(effects.map((effect) => [JSON.stringify(effect), effect])).values()];
|
|
399
|
+
}
|
|
400
|
+
/** Retain witnessed irreversible effects even when the operation never produced a complete value. */
|
|
401
|
+
function partialEvidence(snapshot, primary) {
|
|
402
|
+
const admitted = snapshot.facts.map((fact) => admissionEvidence(fact, primary));
|
|
403
|
+
const effects = [...physicalEvidence(snapshot, primary)];
|
|
404
|
+
let placement;
|
|
405
|
+
for (const [contractId, value] of snapshot.conclusions) {
|
|
406
|
+
const observed = compactPlacement(value);
|
|
407
|
+
if (observed === undefined)
|
|
408
|
+
continue;
|
|
409
|
+
if (contractId === primary)
|
|
410
|
+
placement = observed;
|
|
411
|
+
else if (observed.kind === "placed")
|
|
412
|
+
effects.push({ ...observed, contractId });
|
|
413
|
+
}
|
|
414
|
+
return {
|
|
415
|
+
...(admitted.length === 0 ? {} : { admitted }),
|
|
416
|
+
...(effects.length === 0 ? {} : { effects }),
|
|
417
|
+
...(placement === undefined ? {} : { placement }),
|
|
418
|
+
};
|
|
120
419
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return [...merged].map(([name, required]) => ({ surface: name, required }));
|
|
420
|
+
function acceptedRecoveries(operation, snapshot, contract) {
|
|
421
|
+
const recoveries = physicalEvidence(snapshot, contract).flatMap((effect) => effect.kind === "recovery-snapshot"
|
|
422
|
+
? [{ snapshot: effect.snapshot, ...(effect.contractId === undefined ? {} : { contractId: effect.contractId }) }]
|
|
423
|
+
: []);
|
|
424
|
+
if (recoveries.length === 0)
|
|
425
|
+
return {};
|
|
426
|
+
const local = operation === "bind" || operation === "amend" || operation === "arc" || operation === "abandon";
|
|
427
|
+
return { recoverySnapshots: local ? recoveries.map((recovery) => recovery.snapshot) : recoveries };
|
|
130
428
|
}
|
|
131
|
-
function
|
|
429
|
+
export function compactReview(value) {
|
|
430
|
+
const placement = compactPlacement(value);
|
|
132
431
|
return {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
pending: projectPending(operation, value, snapshot.effects),
|
|
432
|
+
...(placement === undefined ? {} : { placement }),
|
|
433
|
+
...(value.worktreeChanges === undefined ? {} : { worktreeChanges: value.worktreeChanges }),
|
|
434
|
+
...(value.continuation === undefined || Object.keys(value.continuation).length === 0
|
|
435
|
+
? {}
|
|
436
|
+
: { continuation: value.continuation }),
|
|
139
437
|
};
|
|
140
438
|
}
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const value = { removed: snapshot.reset?.removed ?? { refs: 0, worktrees: 0, debts: 0 } };
|
|
147
|
-
const base = { operation, world: projection.world, effects, pending: projectPending(operation, value, effects) };
|
|
148
|
-
if (projection.kind === "failed")
|
|
439
|
+
function partialConclusion(operation, value) {
|
|
440
|
+
if (value === undefined)
|
|
441
|
+
return {};
|
|
442
|
+
switch (operation) {
|
|
443
|
+
case "bind":
|
|
149
444
|
return {
|
|
150
|
-
|
|
151
|
-
|
|
445
|
+
...(typeof value.worktreePath === "string" ? { worktreePath: value.worktreePath } : {}),
|
|
446
|
+
...(value.target === undefined
|
|
447
|
+
? {}
|
|
448
|
+
: { target: value.target }),
|
|
152
449
|
};
|
|
450
|
+
case "amend":
|
|
451
|
+
return {
|
|
452
|
+
...(value.changedSections === undefined ? {} : { changedSections: value.changedSections }),
|
|
453
|
+
...(value.gatesChanged === true ? { gatesChanged: true } : {}),
|
|
454
|
+
...(value.afterChanged === true ? { afterChanged: true } : {}),
|
|
455
|
+
};
|
|
456
|
+
case "deliver":
|
|
457
|
+
return value.tenderSnapshot === undefined || value.integration === undefined
|
|
458
|
+
? {}
|
|
459
|
+
: (() => {
|
|
460
|
+
const compact = compactDelivery(value);
|
|
461
|
+
const placement = compactPlacement(value);
|
|
462
|
+
const { placement: _placement, ...rest } = compact;
|
|
463
|
+
return { ...rest, ...(placement === undefined ? {} : { placement }) };
|
|
464
|
+
})();
|
|
465
|
+
case "verify":
|
|
466
|
+
return {
|
|
467
|
+
...(typeof value.snapshot === "string" ? { snapshot: value.snapshot } : {}),
|
|
468
|
+
...(value.checks === undefined ? {} : { checks: value.checks }),
|
|
469
|
+
...(value.continuation === undefined ? {} : { continuation: value.continuation }),
|
|
470
|
+
};
|
|
471
|
+
case "review":
|
|
472
|
+
return compactReview(value);
|
|
473
|
+
case "arc":
|
|
474
|
+
return {
|
|
475
|
+
...(value.chapter === undefined ? {} : { chapter: value.chapter }),
|
|
476
|
+
};
|
|
477
|
+
case "deliver-preview":
|
|
478
|
+
return { preview: value };
|
|
479
|
+
case "abandon":
|
|
480
|
+
return {};
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
function projectReset(snapshot, projection) {
|
|
484
|
+
const issues = snapshot.effects
|
|
485
|
+
.filter((effect) => effect.kind === "reset-owner-stopped" || effect.kind === "reset-residue")
|
|
486
|
+
.map(({ world: _world, owner, ...issue }) => issue.kind === "reset-residue" ? issue : { ...issue, owner });
|
|
487
|
+
const partial = projection.kind === "failed" || issues.some(resetIssueIsRequired);
|
|
488
|
+
const removed = {};
|
|
489
|
+
const counts = snapshot.reset?.removed;
|
|
490
|
+
if (counts !== undefined)
|
|
491
|
+
for (const key of ["refs", "worktrees", "debts"]) {
|
|
492
|
+
const owner = key === "debts" ? "debt" : "git";
|
|
493
|
+
if (counts[key] > 0 || (partial && snapshot.reset?.attempted.includes(owner)))
|
|
494
|
+
removed[key] = counts[key];
|
|
495
|
+
}
|
|
496
|
+
const evidence = {
|
|
497
|
+
...(Object.keys(removed).length === 0 ? {} : { removed }),
|
|
498
|
+
...(issues.length === 0 ? {} : { issues }),
|
|
499
|
+
};
|
|
500
|
+
if (projection.kind === "failed")
|
|
153
501
|
return {
|
|
154
|
-
kind: "
|
|
155
|
-
|
|
156
|
-
? { ...base, kind: "refused", refusal: projection.refusal }
|
|
157
|
-
: { ...base, kind: "accepted", value },
|
|
502
|
+
kind: "failed",
|
|
503
|
+
error: withOutcomeReceipt(projection.error, { kind: "world", world: projection.world, ...evidence }),
|
|
158
504
|
};
|
|
505
|
+
return {
|
|
506
|
+
kind: "returned",
|
|
507
|
+
outcome: projection.kind === "refused"
|
|
508
|
+
? { kind: "refused", world: projection.world }
|
|
509
|
+
: {
|
|
510
|
+
kind: "accepted",
|
|
511
|
+
...(removed.refs === undefined ? {} : { refsRemoved: removed.refs }),
|
|
512
|
+
...(removed.worktrees === undefined ? {} : { worktreesRemoved: removed.worktrees }),
|
|
513
|
+
...(removed.debts === undefined ? {} : { debtsRemoved: removed.debts }),
|
|
514
|
+
...(issues.length === 0 ? {} : { issues }),
|
|
515
|
+
},
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
export function project(operation, snapshot, projection) {
|
|
519
|
+
if ("world" in projection) {
|
|
520
|
+
if (operation !== "nuke")
|
|
521
|
+
throw new Error("reset projection requires nuke");
|
|
522
|
+
return projectReset(snapshot, projection);
|
|
159
523
|
}
|
|
160
524
|
if (operation === "nuke")
|
|
161
525
|
throw new Error("nuke requires a World projection");
|
|
162
|
-
const contract = projection.contract;
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const base = { operation, ...fields, pending };
|
|
526
|
+
const contract = projection.contract ?? snapshot.facts.find((fact) => fact.kind === "bind")?.contract;
|
|
527
|
+
const captured = contract === undefined ? undefined : snapshot.conclusions.get(contract)?.snapshot;
|
|
528
|
+
const issues = invocationIssues(snapshot.effects, contract, typeof captured === "string" ? captured : undefined);
|
|
529
|
+
const base = {
|
|
530
|
+
...(contract === undefined ? {} : { contractId: contract }),
|
|
531
|
+
...(issues.length === 0 ? {} : { issues }),
|
|
532
|
+
};
|
|
170
533
|
switch (projection.kind) {
|
|
171
|
-
case "accepted":
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
...base,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
},
|
|
534
|
+
case "accepted": {
|
|
535
|
+
if (operation === "deliver-preview")
|
|
536
|
+
return {
|
|
537
|
+
kind: "returned",
|
|
538
|
+
outcome: { ...projection.value, ...base },
|
|
539
|
+
};
|
|
540
|
+
const receipt = {
|
|
541
|
+
kind: "accepted",
|
|
542
|
+
contractId: projection.contract,
|
|
543
|
+
...(issues.length === 0 ? {} : { issues }),
|
|
544
|
+
...acceptedRecoveries(operation, snapshot, projection.contract),
|
|
181
545
|
};
|
|
546
|
+
const outcome = { ...receipt, ...projection.value };
|
|
547
|
+
if (operation === "bind")
|
|
548
|
+
Object.defineProperty(outcome, "kei", {
|
|
549
|
+
value: projection.value.kei,
|
|
550
|
+
enumerable: false,
|
|
551
|
+
});
|
|
552
|
+
return { kind: "returned", outcome: outcome };
|
|
553
|
+
}
|
|
182
554
|
case "handoff":
|
|
183
555
|
return {
|
|
184
556
|
kind: "returned",
|
|
185
557
|
outcome: {
|
|
186
|
-
...base,
|
|
187
558
|
kind: "handoff",
|
|
188
|
-
|
|
189
|
-
|
|
559
|
+
contractId: projection.contract,
|
|
560
|
+
worktreePath: projection.value.workspace.path,
|
|
561
|
+
targetHead: projection.value.targetHead,
|
|
562
|
+
conflictPaths: projection.value.conflictPaths,
|
|
563
|
+
handoffBase: projection.value.handoffBase,
|
|
190
564
|
},
|
|
191
565
|
};
|
|
192
566
|
case "refused":
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
567
|
+
case "retry": {
|
|
568
|
+
const evidence = partialEvidence(snapshot, contract);
|
|
569
|
+
if (Object.keys(evidence).length > 0 || issues.length > 0)
|
|
570
|
+
throw withOutcomeReceipt(new Error("non-admission followed confirmed invocation effects"), {
|
|
571
|
+
kind: "contract",
|
|
572
|
+
...base,
|
|
573
|
+
...evidence,
|
|
574
|
+
});
|
|
575
|
+
const addressed = operation === "bind" ? {} : { contractId: contract };
|
|
576
|
+
return {
|
|
577
|
+
kind: "returned",
|
|
578
|
+
outcome: (projection.kind === "refused"
|
|
579
|
+
? { kind: "refused", ...addressed, reason: projection.refusal }
|
|
580
|
+
: { ...addressed, ...compactRetry(projection.reason) }),
|
|
205
581
|
};
|
|
206
|
-
return { kind: "failed", error: withOutcomeReceipt(projection.error, partial) };
|
|
207
582
|
}
|
|
583
|
+
case "failed":
|
|
584
|
+
return {
|
|
585
|
+
kind: "failed",
|
|
586
|
+
error: withOutcomeReceipt(projection.error, {
|
|
587
|
+
kind: "contract",
|
|
588
|
+
...base,
|
|
589
|
+
...partialConclusion(operation, contract === undefined ? undefined : snapshot.conclusions.get(contract)),
|
|
590
|
+
...partialEvidence(snapshot, contract),
|
|
591
|
+
}),
|
|
592
|
+
};
|
|
208
593
|
}
|
|
209
594
|
}
|
|
210
|
-
|
|
595
|
+
const errorOutcomes = new WeakMap();
|
|
211
596
|
export class KeiyakuError extends Error {
|
|
212
597
|
category;
|
|
213
|
-
outcome
|
|
598
|
+
get outcome() {
|
|
599
|
+
return errorOutcomes.get(this);
|
|
600
|
+
}
|
|
214
601
|
constructor(category, message, options = {}) {
|
|
215
602
|
super(message);
|
|
216
603
|
this.name = "KeiyakuError";
|
|
@@ -218,10 +605,9 @@ export class KeiyakuError extends Error {
|
|
|
218
605
|
if (options.cause !== undefined)
|
|
219
606
|
this.cause = options.cause;
|
|
220
607
|
if (options.outcome !== undefined)
|
|
221
|
-
this
|
|
608
|
+
errorOutcomes.set(this, options.outcome);
|
|
222
609
|
}
|
|
223
610
|
}
|
|
224
|
-
/** One explicit caller-validation phase; its failures are invalid input with a native TypeError cause. */
|
|
225
611
|
export function validated(phase) {
|
|
226
612
|
try {
|
|
227
613
|
return phase();
|
|
@@ -255,20 +641,49 @@ export async function readContractValue(operation) {
|
|
|
255
641
|
function errorDiagnostic(error) {
|
|
256
642
|
return error instanceof Error ? error.message : String(error);
|
|
257
643
|
}
|
|
258
|
-
/** Attach this invocation's partial envelope without changing the error's own identity or category. */
|
|
259
644
|
export function withOutcomeReceipt(error, outcome) {
|
|
260
645
|
if (error instanceof KeiyakuError) {
|
|
261
|
-
|
|
646
|
+
const previous = error.outcome;
|
|
647
|
+
if (previous?.kind === "contract" && outcome.kind === "contract") {
|
|
648
|
+
const merged = { ...previous, ...outcome };
|
|
649
|
+
for (const key of ["admitted", "effects", "issues"]) {
|
|
650
|
+
const values = [...(previous[key] ?? []), ...(outcome[key] ?? [])];
|
|
651
|
+
if (values.length > 0)
|
|
652
|
+
Object.assign(merged, {
|
|
653
|
+
[key]: [...new Map(values.map((value) => [JSON.stringify(value), value])).values()],
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
outcome = merged;
|
|
657
|
+
}
|
|
658
|
+
errorOutcomes.set(error, outcome);
|
|
659
|
+
return error;
|
|
262
660
|
}
|
|
263
661
|
return new KeiyakuError(errorCategory(error), errorDiagnostic(error), { cause: error, outcome });
|
|
264
662
|
}
|
|
663
|
+
const confirmedSpawnFailures = new WeakMap();
|
|
664
|
+
/** Native creation evidence cannot be supplied by an arbitrary error property. */
|
|
665
|
+
export function spawnFailureReceipt(error) {
|
|
666
|
+
return error instanceof Error ? confirmedSpawnFailures.get(error) : undefined;
|
|
667
|
+
}
|
|
668
|
+
/** Retain the native error, including frozen failures, without losing confirmed birth. */
|
|
669
|
+
export function withSpawnFailureReceipt(reason, result) {
|
|
670
|
+
const cause = reason instanceof Error ? reason : new Error(reason === undefined ? "spawn aborted" : String(reason));
|
|
671
|
+
// A shared cancellation reason cannot carry two different invocations' births.
|
|
672
|
+
const error = confirmedSpawnFailures.has(cause) ? new Error(cause.message, { cause }) : cause;
|
|
673
|
+
if (error !== cause)
|
|
674
|
+
error.name = cause.name;
|
|
675
|
+
confirmedSpawnFailures.set(error, result);
|
|
676
|
+
return error;
|
|
677
|
+
}
|
|
265
678
|
export function projectFailure(error) {
|
|
266
679
|
const cause = error instanceof KeiyakuError ? error.cause : error;
|
|
680
|
+
const spawn = spawnFailureReceipt(error) ?? spawnFailureReceipt(cause);
|
|
267
681
|
return {
|
|
268
682
|
kind: "failed",
|
|
269
683
|
category: error instanceof KeiyakuError ? error.category : errorCategory(error),
|
|
270
684
|
diagnostic: errorDiagnostic(error),
|
|
271
685
|
...(cause instanceof Error ? { causeClass: cause.name, causeDiagnostic: cause.message } : {}),
|
|
686
|
+
...(spawn === undefined ? {} : { spawn }),
|
|
272
687
|
...(error instanceof KeiyakuError && error.outcome !== undefined ? { outcome: error.outcome } : {}),
|
|
273
688
|
};
|
|
274
689
|
}
|