@draht/coding-agent 2026.7.30 → 2026.9.5-1
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/CHANGELOG.md +154 -0
- package/README.md +46 -2
- package/agents/debugger.md +12 -1
- package/agents/git-committer.md +1 -0
- package/agents/implementer.md +20 -0
- package/agents/investigator.md +75 -0
- package/agents/reviewer.md +7 -0
- package/agents/spec-reviewer.md +66 -0
- package/agents/verifier.md +4 -3
- package/bin/draht-tools.cjs +472 -41
- package/dist/agents/debugger.md +12 -1
- package/dist/agents/git-committer.md +1 -0
- package/dist/agents/implementer.md +20 -0
- package/dist/agents/investigator.md +75 -0
- package/dist/agents/reviewer.md +7 -0
- package/dist/agents/spec-reviewer.md +66 -0
- package/dist/agents/verifier.md +4 -3
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +69 -2
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/attach-mode.d.ts +61 -0
- package/dist/cli/attach-mode.d.ts.map +1 -1
- package/dist/cli/attach-mode.js +243 -5
- package/dist/cli/attach-mode.js.map +1 -1
- package/dist/cli/credential-print.d.ts +1 -1
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +5 -4
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +31 -4
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +17 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +87 -30
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +35 -16
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +149 -64
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +5 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +72 -15
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/builtins/checkpoints.d.ts +20 -0
- package/dist/core/builtins/checkpoints.d.ts.map +1 -0
- package/dist/core/builtins/checkpoints.js +161 -0
- package/dist/core/builtins/checkpoints.js.map +1 -0
- package/dist/core/builtins/duet.d.ts +26 -0
- package/dist/core/builtins/duet.d.ts.map +1 -0
- package/dist/core/builtins/duet.js +660 -0
- package/dist/core/builtins/duet.js.map +1 -0
- package/dist/core/builtins/index.d.ts.map +1 -1
- package/dist/core/builtins/index.js +7 -1
- package/dist/core/builtins/index.js.map +1 -1
- package/dist/core/builtins/subagent.d.ts +24 -4
- package/dist/core/builtins/subagent.d.ts.map +1 -1
- package/dist/core/builtins/subagent.js +278 -35
- package/dist/core/builtins/subagent.js.map +1 -1
- package/dist/core/checkpoints/checkpoint-cli.d.ts +17 -0
- package/dist/core/checkpoints/checkpoint-cli.d.ts.map +1 -0
- package/dist/core/checkpoints/checkpoint-cli.js +78 -0
- package/dist/core/checkpoints/checkpoint-cli.js.map +1 -0
- package/dist/core/checkpoints/checkpoint-manager.d.ts +294 -0
- package/dist/core/checkpoints/checkpoint-manager.d.ts.map +1 -0
- package/dist/core/checkpoints/checkpoint-manager.js +865 -0
- package/dist/core/checkpoints/checkpoint-manager.js.map +1 -0
- package/dist/core/checkpoints/rewind.d.ts +141 -0
- package/dist/core/checkpoints/rewind.d.ts.map +1 -0
- package/dist/core/checkpoints/rewind.js +246 -0
- package/dist/core/checkpoints/rewind.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +9 -4
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +5 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +25 -4
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +83 -20
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +13 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +37 -2
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +189 -6
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +7 -0
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts +5 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +1 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts +3 -2
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +8 -8
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +34 -7
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +7 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +30 -10
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
- package/dist/core/multi-agent/permission-gate.js +4 -3
- package/dist/core/multi-agent/permission-gate.js.map +1 -1
- package/dist/core/multi-agent/worktree.d.ts +2 -0
- package/dist/core/multi-agent/worktree.d.ts.map +1 -1
- package/dist/core/multi-agent/worktree.js +2 -2
- package/dist/core/multi-agent/worktree.js.map +1 -1
- package/dist/core/package-manager.d.ts +7 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +21 -44
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/permission-relay/index.d.ts +19 -0
- package/dist/core/permission-relay/index.d.ts.map +1 -0
- package/dist/core/permission-relay/index.js +49 -0
- package/dist/core/permission-relay/index.js.map +1 -0
- package/dist/core/permission-relay/relay-ui-context.d.ts +39 -0
- package/dist/core/permission-relay/relay-ui-context.d.ts.map +1 -0
- package/dist/core/permission-relay/relay-ui-context.js +788 -0
- package/dist/core/permission-relay/relay-ui-context.js.map +1 -0
- package/dist/core/permission-relay/types.d.ts +222 -0
- package/dist/core/permission-relay/types.d.ts.map +1 -0
- package/dist/core/permission-relay/types.js +15 -0
- package/dist/core/permission-relay/types.js.map +1 -0
- package/dist/core/pi-manifest.d.ts +14 -0
- package/dist/core/pi-manifest.d.ts.map +1 -0
- package/dist/core/pi-manifest.js +35 -0
- package/dist/core/pi-manifest.js.map +1 -0
- package/dist/core/project-trust.js +2 -2
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/resource-loader.d.ts +21 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +101 -24
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sandbox/bash-operations.d.ts +149 -0
- package/dist/core/sandbox/bash-operations.d.ts.map +1 -0
- package/dist/core/sandbox/bash-operations.js +163 -0
- package/dist/core/sandbox/bash-operations.js.map +1 -0
- package/dist/core/sandbox/env.d.ts +83 -0
- package/dist/core/sandbox/env.d.ts.map +1 -0
- package/dist/core/sandbox/env.js +123 -0
- package/dist/core/sandbox/env.js.map +1 -0
- package/dist/core/sandbox/executor.d.ts +104 -0
- package/dist/core/sandbox/executor.d.ts.map +1 -0
- package/dist/core/sandbox/executor.js +92 -0
- package/dist/core/sandbox/executor.js.map +1 -0
- package/dist/core/sandbox/index.d.ts +36 -0
- package/dist/core/sandbox/index.d.ts.map +1 -0
- package/dist/core/sandbox/index.js +36 -0
- package/dist/core/sandbox/index.js.map +1 -0
- package/dist/core/sandbox/linux.d.ts +121 -0
- package/dist/core/sandbox/linux.d.ts.map +1 -0
- package/dist/core/sandbox/linux.js +260 -0
- package/dist/core/sandbox/linux.js.map +1 -0
- package/dist/core/sandbox/policy.d.ts +142 -0
- package/dist/core/sandbox/policy.d.ts.map +1 -0
- package/dist/core/sandbox/policy.js +297 -0
- package/dist/core/sandbox/policy.js.map +1 -0
- package/dist/core/sandbox/real-path.d.ts +112 -0
- package/dist/core/sandbox/real-path.d.ts.map +1 -0
- package/dist/core/sandbox/real-path.js +158 -0
- package/dist/core/sandbox/real-path.js.map +1 -0
- package/dist/core/sandbox/seatbelt-profile.d.ts +95 -0
- package/dist/core/sandbox/seatbelt-profile.d.ts.map +1 -0
- package/dist/core/sandbox/seatbelt-profile.js +239 -0
- package/dist/core/sandbox/seatbelt-profile.js.map +1 -0
- package/dist/core/sandbox/seatbelt.d.ts +95 -0
- package/dist/core/sandbox/seatbelt.d.ts.map +1 -0
- package/dist/core/sandbox/seatbelt.js +154 -0
- package/dist/core/sandbox/seatbelt.js.map +1 -0
- package/dist/core/sandbox/self-test.d.ts +109 -0
- package/dist/core/sandbox/self-test.d.ts.map +1 -0
- package/dist/core/sandbox/self-test.js +369 -0
- package/dist/core/sandbox/self-test.js.map +1 -0
- package/dist/core/sandbox/spawn.d.ts +33 -0
- package/dist/core/sandbox/spawn.d.ts.map +1 -0
- package/dist/core/sandbox/spawn.js +87 -0
- package/dist/core/sandbox/spawn.js.map +1 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +3 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +60 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +53 -6
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +21 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +36 -16
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts +3 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +19 -6
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/soak/soak-log.d.ts +298 -0
- package/dist/core/soak/soak-log.d.ts.map +1 -0
- package/dist/core/soak/soak-log.js +660 -0
- package/dist/core/soak/soak-log.js.map +1 -0
- package/dist/core/soak/soak-reader.d.ts +60 -0
- package/dist/core/soak/soak-reader.d.ts.map +1 -0
- package/dist/core/soak/soak-reader.js +106 -0
- package/dist/core/soak/soak-reader.js.map +1 -0
- package/dist/core/socket-server/discovery.d.ts +78 -1
- package/dist/core/socket-server/discovery.d.ts.map +1 -1
- package/dist/core/socket-server/discovery.js +356 -37
- package/dist/core/socket-server/discovery.js.map +1 -1
- package/dist/core/socket-server/index.d.ts +10 -4
- package/dist/core/socket-server/index.d.ts.map +1 -1
- package/dist/core/socket-server/index.js +6 -3
- package/dist/core/socket-server/index.js.map +1 -1
- package/dist/core/socket-server/permission-delivery.d.ts +125 -0
- package/dist/core/socket-server/permission-delivery.d.ts.map +1 -0
- package/dist/core/socket-server/permission-delivery.js +152 -0
- package/dist/core/socket-server/permission-delivery.js.map +1 -0
- package/dist/core/socket-server/permission-registry.d.ts +301 -0
- package/dist/core/socket-server/permission-registry.d.ts.map +1 -0
- package/dist/core/socket-server/permission-registry.js +410 -0
- package/dist/core/socket-server/permission-registry.js.map +1 -0
- package/dist/core/socket-server/permission-relay.d.ts +81 -0
- package/dist/core/socket-server/permission-relay.d.ts.map +1 -0
- package/dist/core/socket-server/permission-relay.js +528 -0
- package/dist/core/socket-server/permission-relay.js.map +1 -0
- package/dist/core/socket-server/safe-text.d.ts +83 -0
- package/dist/core/socket-server/safe-text.d.ts.map +1 -0
- package/dist/core/socket-server/safe-text.js +277 -0
- package/dist/core/socket-server/safe-text.js.map +1 -0
- package/dist/core/socket-server/session-integration.d.ts +65 -2
- package/dist/core/socket-server/session-integration.d.ts.map +1 -1
- package/dist/core/socket-server/session-integration.js +434 -32
- package/dist/core/socket-server/session-integration.js.map +1 -1
- package/dist/core/socket-server/socket-client.d.ts +21 -2
- package/dist/core/socket-server/socket-client.d.ts.map +1 -1
- package/dist/core/socket-server/socket-client.js +52 -1
- package/dist/core/socket-server/socket-client.js.map +1 -1
- package/dist/core/socket-server/socket-server.d.ts +152 -1
- package/dist/core/socket-server/socket-server.d.ts.map +1 -1
- package/dist/core/socket-server/socket-server.js +775 -26
- package/dist/core/socket-server/socket-server.js.map +1 -1
- package/dist/core/socket-server/types.d.ts +106 -2
- package/dist/core/socket-server/types.d.ts.map +1 -1
- package/dist/core/socket-server/types.js +13 -1
- package/dist/core/socket-server/types.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +8 -9
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +5 -2
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +17 -2
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +3 -0
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +11 -18
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/trust-manager.d.ts +6 -4
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +55 -21
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +5 -1
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +5 -1
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/extensions/stub-provider/index.d.ts +9 -0
- package/dist/extensions/stub-provider/index.d.ts.map +1 -0
- package/dist/extensions/stub-provider/index.js +13 -0
- package/dist/extensions/stub-provider/index.js.map +1 -0
- package/dist/extensions/stub-provider/provider.d.ts +77 -0
- package/dist/extensions/stub-provider/provider.d.ts.map +1 -0
- package/dist/extensions/stub-provider/provider.js +193 -0
- package/dist/extensions/stub-provider/provider.js.map +1 -0
- package/dist/hooks/gsd/draht-quality-gate.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +242 -45
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +3 -2
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +49 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +202 -5
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +10 -2
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +10 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +10 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +20 -2
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +21 -5
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +97 -3
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +394 -24
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +165 -7
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +68 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/prompts/commands/atomic-commit.md +1 -12
- package/dist/prompts/commands/brainstorm.md +12 -15
- package/dist/prompts/commands/create-verification-skill.md +108 -0
- package/dist/prompts/commands/discuss-phase.md +3 -14
- package/dist/prompts/commands/execute-phase.md +3 -11
- package/dist/prompts/commands/fix.md +41 -18
- package/dist/prompts/commands/grill.md +66 -0
- package/dist/prompts/commands/init-project.md +5 -15
- package/dist/prompts/commands/map-codebase.md +1 -13
- package/dist/prompts/commands/new-project.md +5 -15
- package/dist/prompts/commands/next-milestone.md +1 -13
- package/dist/prompts/commands/orchestrate.md +1 -1
- package/dist/prompts/commands/pause-work.md +1 -13
- package/dist/prompts/commands/plan-phase.md +2 -11
- package/dist/prompts/commands/progress.md +0 -13
- package/dist/prompts/commands/quick.md +3 -11
- package/dist/prompts/commands/resolve-conflicts.md +71 -0
- package/dist/prompts/commands/resume-work.md +0 -13
- package/dist/prompts/commands/review.md +4 -13
- package/dist/prompts/commands/triage.md +159 -0
- package/dist/prompts/commands/verify-work.md +4 -14
- package/dist/prompts/commands/why.md +135 -0
- package/dist/skills/atomic-reasoning/SKILL.md +115 -0
- package/dist/skills/blast-radius/SKILL.md +55 -0
- package/dist/skills/epistemics/SKILL.md +99 -0
- package/dist/skills/hexagon-animation/SKILL.md +49 -0
- package/dist/skills/hexagon-animation/generate.mjs +81 -0
- package/dist/skills/hexagon-animation/template.html +361 -0
- package/dist/skills/typescript-discipline/SKILL.md +50 -0
- package/dist/skills/typescript-discipline/references/patterns.md +294 -0
- package/dist/skills/unslop/SKILL.md +101 -0
- package/dist/utils/canonical-path.d.ts +28 -0
- package/dist/utils/canonical-path.d.ts.map +1 -0
- package/dist/utils/canonical-path.js +90 -0
- package/dist/utils/canonical-path.js.map +1 -0
- package/dist/utils/child-process.d.ts +12 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +25 -8
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard.d.ts +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +22 -2
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/exif-orientation.d.ts.map +1 -1
- package/dist/utils/exif-orientation.js +2 -3
- package/dist/utils/exif-orientation.js.map +1 -1
- package/dist/utils/paths.d.ts +2 -7
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +13 -15
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +6 -4
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +3 -5
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/attachable-sessions.md +79 -0
- package/docs/compaction.md +21 -21
- package/docs/containerization.md +23 -23
- package/docs/custom-provider.md +16 -16
- package/docs/development.md +9 -9
- package/docs/docs.json +6 -2
- package/docs/duet.md +42 -0
- package/docs/extensions.md +58 -58
- package/docs/index.md +10 -10
- package/docs/json.md +7 -7
- package/docs/keybindings.md +6 -5
- package/docs/llama-cpp.md +6 -6
- package/docs/models.md +6 -6
- package/docs/packages.md +43 -43
- package/docs/prompt-templates.md +4 -4
- package/docs/providers.md +12 -12
- package/docs/quickstart.md +32 -32
- package/docs/rpc.md +83 -12
- package/docs/sdk.md +15 -15
- package/docs/security.md +18 -18
- package/docs/session-format.md +35 -13
- package/docs/sessions.md +17 -14
- package/docs/settings.md +25 -18
- package/docs/shell-aliases.md +2 -2
- package/docs/skills.md +12 -11
- package/docs/terminal-setup.md +12 -12
- package/docs/termux.md +6 -6
- package/docs/themes.md +11 -11
- package/docs/tmux.md +4 -4
- package/docs/tui.md +5 -5
- package/docs/usage.md +50 -50
- package/docs/windows.md +2 -2
- package/examples/extensions/overlay-qa-tests.ts +3 -3
- package/hooks/gsd/draht-quality-gate.js +3 -3
- package/package.json +11 -10
- package/prompts/commands/atomic-commit.md +1 -12
- package/prompts/commands/brainstorm.md +12 -15
- package/prompts/commands/create-verification-skill.md +108 -0
- package/prompts/commands/discuss-phase.md +3 -14
- package/prompts/commands/execute-phase.md +3 -11
- package/prompts/commands/fix.md +41 -18
- package/prompts/commands/grill.md +66 -0
- package/prompts/commands/init-project.md +5 -15
- package/prompts/commands/map-codebase.md +1 -13
- package/prompts/commands/new-project.md +5 -15
- package/prompts/commands/next-milestone.md +1 -13
- package/prompts/commands/orchestrate.md +1 -1
- package/prompts/commands/pause-work.md +1 -13
- package/prompts/commands/plan-phase.md +2 -11
- package/prompts/commands/progress.md +0 -13
- package/prompts/commands/quick.md +3 -11
- package/prompts/commands/resolve-conflicts.md +71 -0
- package/prompts/commands/resume-work.md +0 -13
- package/prompts/commands/review.md +4 -13
- package/prompts/commands/triage.md +159 -0
- package/prompts/commands/verify-work.md +4 -14
- package/prompts/commands/why.md +135 -0
- package/skills/atomic-reasoning/SKILL.md +115 -0
- package/skills/blast-radius/SKILL.md +55 -0
- package/skills/epistemics/SKILL.md +99 -0
- package/skills/hexagon-animation/SKILL.md +49 -0
- package/skills/hexagon-animation/generate.mjs +81 -0
- package/skills/hexagon-animation/template.html +361 -0
- package/skills/typescript-discipline/SKILL.md +50 -0
- package/skills/typescript-discipline/references/patterns.md +294 -0
- package/skills/unslop/SKILL.md +101 -0
- package/dist/prompts/agents/build.md +0 -86
- package/dist/prompts/agents/plan.md +0 -79
- package/dist/prompts/agents/verify.md +0 -69
- package/prompts/agents/build.md +0 -86
- package/prompts/agents/plan.md +0 -79
- package/prompts/agents/verify.md +0 -69
|
@@ -0,0 +1,788 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RelayUIContext — the decorator that lets a remote surface answer a local dialog.
|
|
3
|
+
*
|
|
4
|
+
* It wraps EXACTLY `confirm`, `select` and `input`. Every other `ExtensionUIContext` member is
|
|
5
|
+
* hand-delegated verbatim. This is deliberately NOT a Proxy: `getEditorText`, `theme`,
|
|
6
|
+
* `getAllThemes`, `getTheme`, `getToolsExpanded` and `getEditorComponent` are synchronous reads of
|
|
7
|
+
* the base's local state, and `setWidget`/`setFooter`/`setHeader`/`custom` take component
|
|
8
|
+
* factories that cannot be serialized. `editor` and `custom` therefore stay purely local by
|
|
9
|
+
* documented exception.
|
|
10
|
+
*
|
|
11
|
+
* THE INVARIANT THIS FILE EXISTS TO HOLD: an offered option CARRIES the value the caller receives
|
|
12
|
+
* when it comes back. Nothing derives that value later — not from the option's index, not from its
|
|
13
|
+
* position relative to its siblings, not by matching labels across two arrays, not from a magic id.
|
|
14
|
+
* Every past defect here (an approval read as a denial, a denial read as an approval, an answered
|
|
15
|
+
* "Deny" resolved to the string "Allow") was one of those derivations. There is exactly one
|
|
16
|
+
* constructor of an offered option, {@link offer}, and it takes the caller-side value as an
|
|
17
|
+
* argument — so an option with no resolution cannot be built at all.
|
|
18
|
+
*
|
|
19
|
+
* ITS COROLLARY: a caller vocabulary this file cannot honour is REJECTED, never repaired.
|
|
20
|
+
* {@link classifyVocabulary} is the one gate, and it has exactly three outcomes — absent, valid,
|
|
21
|
+
* invalid. Invalid offers nothing remotely at all, so the ask falls to the local surface or to the
|
|
22
|
+
* raising method's own fail-closed default. Quietly substituting our default pair for a caller's
|
|
23
|
+
* rejected one would broadcast an approval that caller never authorised, and a human tapping it
|
|
24
|
+
* would run the gated call.
|
|
25
|
+
*/
|
|
26
|
+
import { randomUUID } from "node:crypto";
|
|
27
|
+
import { isRelayEnded, RELAY_ANSWERED, RELAY_CANCELLED, } from "./types.js";
|
|
28
|
+
/**
|
|
29
|
+
* The caller-side meaning of each declared decision.
|
|
30
|
+
*
|
|
31
|
+
* A total map from the vocabulary's own word to the boolean a `confirm` caller receives. It is not
|
|
32
|
+
* a test of an id and not a position rule: the option says what it means, this only translates.
|
|
33
|
+
*/
|
|
34
|
+
const CONFIRM_RESOLUTION = Object.freeze({
|
|
35
|
+
approve: true,
|
|
36
|
+
deny: false,
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* The frozen two-way vocabulary a bare `confirm` offers when the caller supplied no
|
|
40
|
+
* `detail.options`.
|
|
41
|
+
*
|
|
42
|
+
* These ids are a DEFAULT, never a test: a caller may offer any vocabulary it likes (T5's tool
|
|
43
|
+
* permission ask does), and every vocabulary states its own semantics through `decision`. Nothing
|
|
44
|
+
* in this file compares an answered id against a literal.
|
|
45
|
+
*/
|
|
46
|
+
export const APPROVE_OPTION_ID = "approve";
|
|
47
|
+
export const DENY_OPTION_ID = "deny";
|
|
48
|
+
const DEFAULT_CONFIRM_OPTIONS = Object.freeze([
|
|
49
|
+
Object.freeze({ id: APPROVE_OPTION_ID, label: "Yes", decision: "approve" }),
|
|
50
|
+
Object.freeze({ id: DENY_OPTION_ID, label: "No", decision: "deny" }),
|
|
51
|
+
]);
|
|
52
|
+
/**
|
|
53
|
+
* Nobody decided: the ask was dismissed from outside via the caller's own AbortSignal, the relay
|
|
54
|
+
* gave up while no local surface existed to fall back to, or the caller's own declared timeout
|
|
55
|
+
* expired with the decorator holding the only arm.
|
|
56
|
+
*/
|
|
57
|
+
const SYSTEM_DECIDER = { surface: "system", clientId: null };
|
|
58
|
+
/**
|
|
59
|
+
* The ONE place an offered option is constructed.
|
|
60
|
+
*
|
|
61
|
+
* The caller-side value is an argument, supplied at construction from data the caller actually
|
|
62
|
+
* gave us — the option's own declared decision, or the very string the caller listed. No other
|
|
63
|
+
* function in this file builds an `OfferedOption`, so there is no second path where a resolution
|
|
64
|
+
* could be inferred after the fact.
|
|
65
|
+
*
|
|
66
|
+
* `declares` is optional and purely descriptive: `select` and `input` have no permission semantics
|
|
67
|
+
* to state. Passing it never changes `resolution`.
|
|
68
|
+
*/
|
|
69
|
+
function offer(id, label, value, declares) {
|
|
70
|
+
return { id, label, resolution: { value }, declares };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Index a freshly minted list by id. Ids are wire handles; they are never parsed or ordered.
|
|
74
|
+
*
|
|
75
|
+
* Callers must have proved the ids unique first — `new Map` is last-wins, and letting array
|
|
76
|
+
* position silently pick which of two same-id options survives is precisely the inference this
|
|
77
|
+
* file exists to abolish. {@link classifyVocabulary} is that proof for caller-supplied
|
|
78
|
+
* vocabularies; the other two mints generate their own ids and cannot collide.
|
|
79
|
+
*/
|
|
80
|
+
function offeredSet(options) {
|
|
81
|
+
// Callers must hand this a DENSE array. `new Map` iterates, so a hole reaches it as `undefined`
|
|
82
|
+
// and throws. Both mints guarantee density: `classifyVocabulary` builds its own frozen snapshot,
|
|
83
|
+
// and `mintSelectOptions` skips holes by index.
|
|
84
|
+
return new Map(options.map((option) => [option.id, option]));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The offered set of an ask with NO remote answerable option.
|
|
88
|
+
*
|
|
89
|
+
* Two asks reach it: a free-text `input`, whose answer is the text itself, and a `confirm` whose
|
|
90
|
+
* caller-supplied vocabulary did not survive validation. Both broadcast zero options, so both are
|
|
91
|
+
* decided by the local surface or by the method's own fail-closed default — never by a fabrication.
|
|
92
|
+
*/
|
|
93
|
+
const NO_OFFERED_OPTIONS = new Map();
|
|
94
|
+
/**
|
|
95
|
+
* What a `confirm` answered on the LOCAL surface means, when the surface DID NOT SAY.
|
|
96
|
+
*
|
|
97
|
+
* `true` is unambiguous: no fail-closed path in this file, in the barrel's no-op, in interactive
|
|
98
|
+
* mode or in RPC mode ever produces `true`, so a `true` is always somebody approving.
|
|
99
|
+
*
|
|
100
|
+
* `false` is NOT unambiguous, and no cleverness about the boolean can make it so:
|
|
101
|
+
* `ExtensionUIContext.confirm` returns `Promise<boolean>`, so a human pressing "No" and a surface
|
|
102
|
+
* GIVING UP (RPC's `cancelPendingExtensionRequests` on shutdown, on stdin EOF, on abort;
|
|
103
|
+
* interactive's Esc) arrive here as the same value. ANY derivation from that boolean fabricates
|
|
104
|
+
* something, and this one fabricated a human's refusal for asks nobody ever saw.
|
|
105
|
+
*
|
|
106
|
+
* That is why this function is now the FALLBACK and not the rule. A surface states its own outcome
|
|
107
|
+
* through {@link ExtensionUIDialogOptions.reportOutcome} — the honest four-way `RelayOutcome` —
|
|
108
|
+
* and {@link race} prefers what it was told over what can be guessed. This runs only for a base
|
|
109
|
+
* that never called it, where today's behaviour is kept exactly as it was rather than replaced by
|
|
110
|
+
* a different guess. `chosenOptionId` is null because a surface that answered with a bare boolean
|
|
111
|
+
* never named one of the offered ids.
|
|
112
|
+
*/
|
|
113
|
+
function confirmOutcome(value) {
|
|
114
|
+
return value ? { kind: "approved", chosenOptionId: null } : { kind: "denied", chosenOptionId: null };
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* What a `select` or `input` answered on the LOCAL surface means.
|
|
118
|
+
*
|
|
119
|
+
* These two methods have NO permission semantics, so neither `approved` nor `denied` may be said
|
|
120
|
+
* about them. `undefined` is both surfaces' documented "dismissed" value and is also this file's
|
|
121
|
+
* fail-closed fallback, so the two coincide honestly: either way nobody answered.
|
|
122
|
+
*/
|
|
123
|
+
function choiceOutcome(value) {
|
|
124
|
+
return value === undefined ? RELAY_CANCELLED : RELAY_ANSWERED;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* What an ANSWERED offered option means, read off that option and nothing else.
|
|
128
|
+
*
|
|
129
|
+
* `declares` is the option's own `decision` word, copied out when the option was minted and frozen
|
|
130
|
+
* with it — the same word the registry reads on its own side, so the two halves of a round trip
|
|
131
|
+
* cannot disagree. An option that declares nothing is a `select` entry: it ends the ask by being
|
|
132
|
+
* answered, and says nothing about permission.
|
|
133
|
+
*/
|
|
134
|
+
function answeredOutcome(declares, chosenOptionId) {
|
|
135
|
+
if (declares === "approve")
|
|
136
|
+
return { kind: "approved", chosenOptionId };
|
|
137
|
+
if (declares === "deny")
|
|
138
|
+
return { kind: "denied", chosenOptionId };
|
|
139
|
+
return RELAY_ANSWERED;
|
|
140
|
+
}
|
|
141
|
+
export function createRelayUIContext(base, relay, baseIsLive, localSurface) {
|
|
142
|
+
/**
|
|
143
|
+
* The local surface, named for what it ACTUALLY is.
|
|
144
|
+
*
|
|
145
|
+
* Passed in rather than hardcoded: this decorator wraps whatever context the binding mode
|
|
146
|
+
* installed, and a literal `tui` here recorded an answer typed into the RPC surface — a process
|
|
147
|
+
* with no terminal UI at all — as a human at a terminal.
|
|
148
|
+
*/
|
|
149
|
+
const localDecider = { surface: localSurface, clientId: null };
|
|
150
|
+
/** Evaluated LIVE on every call: clients attach and detach while a session is running. */
|
|
151
|
+
const hasAnswerSurface = () => baseIsLive || relay.readWriteClientCount() > 0;
|
|
152
|
+
function race(spec) {
|
|
153
|
+
// (f) Nobody can answer. Do not raise anything anywhere — hand back the base's own value so
|
|
154
|
+
// the caller's fail-closed branch fires exactly as it does with no relay installed.
|
|
155
|
+
if (!baseIsLive && relay.readWriteClientCount() === 0) {
|
|
156
|
+
return spec.runBase(spec.opts);
|
|
157
|
+
}
|
|
158
|
+
const externalSignal = spec.opts?.signal;
|
|
159
|
+
if (externalSignal?.aborted === true) {
|
|
160
|
+
// The undecorated surfaces check this upfront too; nothing should be shown at all.
|
|
161
|
+
return Promise.resolve(spec.fallback);
|
|
162
|
+
}
|
|
163
|
+
// (a) One id and one AbortController per ask.
|
|
164
|
+
const requestId = randomUUID();
|
|
165
|
+
const controller = new AbortController();
|
|
166
|
+
let settled = false;
|
|
167
|
+
let resolveOuter;
|
|
168
|
+
let rejectOuter;
|
|
169
|
+
const outer = new Promise((resolve, reject) => {
|
|
170
|
+
resolveOuter = resolve;
|
|
171
|
+
rejectOuter = reject;
|
|
172
|
+
});
|
|
173
|
+
// The caller's own signal is replaced below by ours, so forward it or an extension's
|
|
174
|
+
// programmatic dismissal would silently stop working under the decorator. It is removed
|
|
175
|
+
// again the moment the ask settles: a caller-owned signal outlives the ask and would
|
|
176
|
+
// otherwise collect one dead listener per dialog.
|
|
177
|
+
const onExternalAbort = () => {
|
|
178
|
+
settle(SYSTEM_DECIDER, spec.fallback, RELAY_CANCELLED);
|
|
179
|
+
};
|
|
180
|
+
const releaseExternalSignal = () => {
|
|
181
|
+
externalSignal?.removeEventListener("abort", onExternalAbort);
|
|
182
|
+
};
|
|
183
|
+
/** (g) The caller's declared timeout, armed only when the decorator owns the only arm. */
|
|
184
|
+
let expiry;
|
|
185
|
+
const releaseTimeout = () => {
|
|
186
|
+
if (expiry !== undefined) {
|
|
187
|
+
clearTimeout(expiry);
|
|
188
|
+
expiry = undefined;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* (c) SYNCHRONOUS from the settled check through resolve(). A single `await` between the
|
|
193
|
+
* check and the assignment lets both answers through and produces two conflicting
|
|
194
|
+
* resolutions with no error at all, because the second resolve() is a silent no-op.
|
|
195
|
+
*
|
|
196
|
+
* (d) Order after a winner: mark settled -> resolve -> abort the losing surfaces ->
|
|
197
|
+
* withdraw. Aborting BEFORE resolving is a real defect: interactive mode honours
|
|
198
|
+
* `opts.signal` by resolving its selector to `undefined`, which its confirm wrapper maps to
|
|
199
|
+
* `false` — an abort-first implementation would feed a FABRICATED local deny back through
|
|
200
|
+
* this decorator and overwrite a remote approve.
|
|
201
|
+
*
|
|
202
|
+
* (e) Each teardown step is wrapped on its own, and this is what that does and does not buy.
|
|
203
|
+
*
|
|
204
|
+
* GUARANTEED: a `withdraw` that throws synchronously, a `withdraw` that returns a rejected
|
|
205
|
+
* promise (the shape a socket-writing registry naturally has), and a throwing `interpret`
|
|
206
|
+
* cannot escape this discarded `.then` as an unhandled rejection — fatal under Node's default
|
|
207
|
+
* --unhandled-rejections=throw — and cannot prevent the teardown steps behind them from
|
|
208
|
+
* running. The caller already has its answer before any of this executes.
|
|
209
|
+
*
|
|
210
|
+
* NOT GUARANTEED: `quietly(() => controller.abort())` does NOT contain a throw from an abort
|
|
211
|
+
* listener the BASE surface registered. `AbortController.abort()` dispatches synchronously
|
|
212
|
+
* through EventTarget, which reports a listener exception as an `uncaughtException` — it never
|
|
213
|
+
* propagates to the `abort()` call site, so neither try/catch nor `.catch()` can see it. That
|
|
214
|
+
* is inherent to EventTarget dispatch and is not something this decorator can fix.
|
|
215
|
+
*/
|
|
216
|
+
const settle = (decidedBy, value, outcome) => {
|
|
217
|
+
if (settled) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
settled = true;
|
|
221
|
+
resolveOuter(value);
|
|
222
|
+
quietly(releaseExternalSignal);
|
|
223
|
+
quietly(releaseTimeout);
|
|
224
|
+
quietly(() => controller.abort());
|
|
225
|
+
// The outcome is an ARGUMENT, never something the relay may reconstruct. THIS call site
|
|
226
|
+
// has just settled the ask and holds the value; the relay holds neither, and when it
|
|
227
|
+
// guessed it wrote `cancelled` over an approval whose command had already run.
|
|
228
|
+
quietly(() => relay.withdraw(requestId, decidedBy, outcome));
|
|
229
|
+
};
|
|
230
|
+
let relayDone = false;
|
|
231
|
+
let baseFailure;
|
|
232
|
+
/** Both sides are spent and the only outcome was an error from the local surface. */
|
|
233
|
+
const rejectIfExhausted = () => {
|
|
234
|
+
if (settled || !relayDone || baseFailure === undefined) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
settled = true;
|
|
238
|
+
rejectOuter(baseFailure.error);
|
|
239
|
+
quietly(releaseExternalSignal);
|
|
240
|
+
quietly(releaseTimeout);
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* The relay is spent without a usable answer: nobody answered, it was withdrawn, it
|
|
244
|
+
* expired, it failed, or the answer named an option that was never offered.
|
|
245
|
+
*
|
|
246
|
+
* With a live local surface we simply keep waiting on it. With NO local surface there is
|
|
247
|
+
* nothing left to wait for, so the ask ends on its own fail-closed default — the wrapped
|
|
248
|
+
* no-op's `false` must never stand in as a decision, because a caller reports that as a
|
|
249
|
+
* user action in the transcript.
|
|
250
|
+
*/
|
|
251
|
+
const relayExhausted = () => {
|
|
252
|
+
if (!baseIsLive) {
|
|
253
|
+
settle(SYSTEM_DECIDER, spec.fallback, RELAY_CANCELLED);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
rejectIfExhausted();
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* The offered set is the ONLY interpreter, and it is a plain lookup by the id that was
|
|
260
|
+
* broadcast: the answered option already carries its caller-side value. A free-text ask
|
|
261
|
+
* carries its answer verbatim instead.
|
|
262
|
+
*
|
|
263
|
+
* The OUTCOME comes back with the value, read off the very option that was answered — its own
|
|
264
|
+
* `declares` word and its own id. It is not derived from the value: two options of one
|
|
265
|
+
* vocabulary can share a caller-side value (`[allow, deny-once, deny-always]` has two `false`
|
|
266
|
+
* denials), so a value can never name the option that produced it. An option that declares
|
|
267
|
+
* nothing is a plain `select` entry and a free-text answer is an `input`: neither approves nor
|
|
268
|
+
* denies anything, and both report `answered`.
|
|
269
|
+
*/
|
|
270
|
+
const interpret = (optionId) => {
|
|
271
|
+
const chosen = spec.offered.get(optionId);
|
|
272
|
+
if (chosen !== undefined) {
|
|
273
|
+
return { value: chosen.resolution.value, outcome: answeredOutcome(chosen.declares, chosen.id) };
|
|
274
|
+
}
|
|
275
|
+
try {
|
|
276
|
+
return spec.fromFreeText === undefined
|
|
277
|
+
? undefined
|
|
278
|
+
: { value: spec.fromFreeText(optionId), outcome: RELAY_ANSWERED };
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
// An interpreter that blows up produced no answer. It must not settle the ask, and
|
|
282
|
+
// it must not escape this discarded `.then` as an unhandled rejection.
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* WHAT THE LOCAL SURFACE SAYS IT DID, when it is willing to say.
|
|
288
|
+
*
|
|
289
|
+
* `ExtensionUIContext.confirm` returns a bare `Promise<boolean>`: a human's "no" and a
|
|
290
|
+
* surface giving up are the same value, so anything derived from it fabricates something.
|
|
291
|
+
* The fix is not a cleverer derivation, it is asking. A surface calls `reportOutcome` with
|
|
292
|
+
* its own honest {@link RelayOutcome} just before it resolves, and that is what gets
|
|
293
|
+
* recorded — an rpc-mode shutdown becomes `cancelled` by the system instead of a human's
|
|
294
|
+
* refusal, and an operator who tapped `deny-once` gets that very id into the audit row
|
|
295
|
+
* instead of a `null` the boolean could never have carried.
|
|
296
|
+
*
|
|
297
|
+
* FIRST STATEMENT WINS, and a late one is ignored: this decorator aborts the losing surface
|
|
298
|
+
* as part of settling, and a surface that reports `cancelled` from its own abort listener
|
|
299
|
+
* must not overwrite the answer that just won. Totally non-throwing, because the base calls
|
|
300
|
+
* it synchronously from inside its own code.
|
|
301
|
+
*/
|
|
302
|
+
let reported;
|
|
303
|
+
const callerReport = spec.opts?.reportOutcome;
|
|
304
|
+
const reportOutcome = (outcome) => {
|
|
305
|
+
if (reported === undefined && isRelayOutcome(outcome)) {
|
|
306
|
+
reported = outcome;
|
|
307
|
+
}
|
|
308
|
+
// A caller that supplied its own callback still hears from its surface: this decorator
|
|
309
|
+
// replaces the field on the way down and would otherwise silently swallow it.
|
|
310
|
+
if (callerReport !== undefined) {
|
|
311
|
+
try {
|
|
312
|
+
callerReport(outcome);
|
|
313
|
+
}
|
|
314
|
+
catch {
|
|
315
|
+
// A caller's own callback must not break the surface that called it.
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* WHO to name for an ask the local side settled. ONE rule, and it is total.
|
|
321
|
+
*
|
|
322
|
+
* `cancelled` means NOBODY ANSWERED — a shutdown, a stdin EOF, an abort, a surface's own
|
|
323
|
+
* timeout, a dismissal. Naming the surface for one of those puts a decision in the audit
|
|
324
|
+
* trail against a person who never made it, which is the same falsehood as calling it a
|
|
325
|
+
* denial, merely moved into a different field. It is the rule this module already applies
|
|
326
|
+
* to every OTHER cancellation — the caller's own abort, the declared timeout, an exhausted
|
|
327
|
+
* relay all settle with {@link SYSTEM_DECIDER} — so applying it here too is what makes
|
|
328
|
+
* "cancelled is attributed to the system, never to a surface that did not act" a property
|
|
329
|
+
* of this file rather than a habit of four call sites.
|
|
330
|
+
*
|
|
331
|
+
* Every other outcome names the surface that produced it: `approved`, `denied` and
|
|
332
|
+
* `answered` all report that somebody DID act, on this surface.
|
|
333
|
+
*/
|
|
334
|
+
const deciderFor = (outcome) => outcome.kind === "cancelled" ? SYSTEM_DECIDER : localDecider;
|
|
335
|
+
externalSignal?.addEventListener("abort", onExternalAbort, { once: true });
|
|
336
|
+
// ONE usability verdict, read by the advisory `deadline` just below AND by the real clock at
|
|
337
|
+
// the bottom of this function. Guarding the two expressions separately is how a `NaN` timeout
|
|
338
|
+
// (an unset `Number(process.env.DRAHT_PERMISSION_TIMEOUT_MS)`) and an `Infinity` timeout (the
|
|
339
|
+
// idiomatic "never expire") reached `new Date(...).toISOString()` and threw a RangeError
|
|
340
|
+
// SYNCHRONOUSLY out of `confirm()`. Such an ask never reaches the relay and never fails
|
|
341
|
+
// closed: it propagates as an exception the permission gate reports as a TOOL ERROR rather
|
|
342
|
+
// than as a denial. A permission ask must fail closed; it must never throw. The verdict also
|
|
343
|
+
// bounds the MAGNITUDE, for the same reason and in the same one place — see
|
|
344
|
+
// {@link MAX_USABLE_TIMEOUT_MS}.
|
|
345
|
+
const declaredTimeout = usableTimeout(spec.opts?.timeout);
|
|
346
|
+
const ask = {
|
|
347
|
+
requestId,
|
|
348
|
+
method: spec.method,
|
|
349
|
+
title: spec.title,
|
|
350
|
+
message: spec.message,
|
|
351
|
+
detail: spec.opts?.detail,
|
|
352
|
+
// Derived from the offered set itself: nothing can be shown that cannot be answered.
|
|
353
|
+
// `decision` rides along for rendering — see OfferedOption.declares.
|
|
354
|
+
options: [...spec.offered.values()].map(({ id, label, declares }) => declares === undefined ? { id, label } : { id, label, decision: declares }),
|
|
355
|
+
requestedAt: new Date().toISOString(),
|
|
356
|
+
// Advisory rendering data only. Real expiry binds to the clock below, never to this.
|
|
357
|
+
deadline: declaredTimeout === undefined ? null : new Date(Date.now() + declaredTimeout).toISOString(),
|
|
358
|
+
};
|
|
359
|
+
// (b) Start BOTH surfaces — but ONLY when the mode actually bound one. A base that is not
|
|
360
|
+
// live is the barrel's no-op, whose `confirm` resolves `false` on the very next microtask:
|
|
361
|
+
// started, it wins every race outright and fabricates a user denial before the phone can
|
|
362
|
+
// even render the ask. (e) Both handlers swallow late results and late REJECTIONS against a
|
|
363
|
+
// settled ask — an unswallowed rejection is fatal under --unhandled-rejections=throw.
|
|
364
|
+
if (baseIsLive) {
|
|
365
|
+
callSafely(() => spec.runBase({ ...spec.opts, signal: controller.signal, reportOutcome })).then((value) => {
|
|
366
|
+
// TOLD beats DERIVED. `spec.localOutcome` is a reading of an ambiguous value and
|
|
367
|
+
// runs only for a base that stated nothing, which is what keeps every existing
|
|
368
|
+
// `ExtensionUIContext` implementer behaving exactly as it does today.
|
|
369
|
+
const outcome = reported ?? spec.localOutcome(value);
|
|
370
|
+
settle(deciderFor(outcome), value, outcome);
|
|
371
|
+
}, (error) => {
|
|
372
|
+
baseFailure = { error };
|
|
373
|
+
rejectIfExhausted();
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
callSafely(() => relay.raise(ask)).then((answer) => {
|
|
377
|
+
relayDone = true;
|
|
378
|
+
if (isRelayEnded(answer) && answer.requestId === requestId) {
|
|
379
|
+
// THE ASK IS OVER, not merely unanswerable HERE. The relay's clock ran out, or
|
|
380
|
+
// the session was stopped: it has already broadcast the ending and written the
|
|
381
|
+
// audit row. Waiting on the local surface now is the fail-OPEN defect — the
|
|
382
|
+
// dialog stayed on screen, a human tapped Approve, and the command ran against
|
|
383
|
+
// a durable record that says `expired`. `settle` aborts the local surface.
|
|
384
|
+
settle(answer.decidedBy, spec.fallback, RELAY_CANCELLED);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
if (answer === undefined || isRelayEnded(answer) || answer.requestId !== requestId) {
|
|
388
|
+
relayExhausted();
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const decided = interpret(answer.optionId);
|
|
392
|
+
if (decided === undefined) {
|
|
393
|
+
// An id nobody offered is not a choice anybody made: it is silence, not a dismissal.
|
|
394
|
+
relayExhausted();
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
settle(answer.decidedBy, decided.value, decided.outcome);
|
|
398
|
+
}, () => {
|
|
399
|
+
relayDone = true;
|
|
400
|
+
relayExhausted();
|
|
401
|
+
});
|
|
402
|
+
// (g) With a live base, the local surface runs the caller's timeout itself (interactive mode
|
|
403
|
+
// shows the countdown) and this decorator must not add a second clock. With NO live base the
|
|
404
|
+
// decorator holds the only arm, so an unhonoured `opts.timeout` means the caller waits
|
|
405
|
+
// forever whenever the relay never resolves — where without a relay it would have failed
|
|
406
|
+
// closed instantly. On expiry the ask ends on the method's own fail-closed default,
|
|
407
|
+
// attributed to the system: nobody decided.
|
|
408
|
+
//
|
|
409
|
+
// This is deliberately NOT a default clock. When the caller declares no timeout — or declares
|
|
410
|
+
// one too large to arm honestly, see usableTimeout — the bound is the pending registry's own
|
|
411
|
+
// fail-closed timer (R34-PERM.6, a later task): one clock, owned there. All that happens here
|
|
412
|
+
// is that the caller's OWN declared timeout is respected, when it is a duration we can keep.
|
|
413
|
+
if (!baseIsLive && declaredTimeout !== undefined) {
|
|
414
|
+
expiry = setTimeout(() => {
|
|
415
|
+
settle(SYSTEM_DECIDER, spec.fallback, RELAY_CANCELLED);
|
|
416
|
+
}, declaredTimeout);
|
|
417
|
+
}
|
|
418
|
+
return outer;
|
|
419
|
+
}
|
|
420
|
+
return {
|
|
421
|
+
select(title, options, opts) {
|
|
422
|
+
return race({
|
|
423
|
+
method: "select",
|
|
424
|
+
title,
|
|
425
|
+
offered: mintSelectOptions(options),
|
|
426
|
+
opts,
|
|
427
|
+
fallback: undefined,
|
|
428
|
+
localOutcome: choiceOutcome,
|
|
429
|
+
runBase: (baseOpts) => base.select(title, options, baseOpts),
|
|
430
|
+
});
|
|
431
|
+
},
|
|
432
|
+
confirm(title, message, opts) {
|
|
433
|
+
return race({
|
|
434
|
+
method: "confirm",
|
|
435
|
+
title,
|
|
436
|
+
message,
|
|
437
|
+
offered: mintConfirmOptions(opts?.detail?.options),
|
|
438
|
+
opts,
|
|
439
|
+
fallback: false,
|
|
440
|
+
localOutcome: confirmOutcome,
|
|
441
|
+
runBase: (baseOpts) => base.confirm(title, message, baseOpts),
|
|
442
|
+
});
|
|
443
|
+
},
|
|
444
|
+
input(title, placeholder, opts) {
|
|
445
|
+
return race({
|
|
446
|
+
method: "input",
|
|
447
|
+
title,
|
|
448
|
+
message: placeholder,
|
|
449
|
+
// A free-text ask offers NOTHING answerable, exactly as `select` takes nothing from
|
|
450
|
+
// `detail.options`. Minting suggestions by id put the id namespace and the free-text
|
|
451
|
+
// namespace in one map, and the map was consulted first: a human who TYPED the literal
|
|
452
|
+
// text "allow-once" into an ask carrying a suggestion with that id got the suggestion's
|
|
453
|
+
// LABEL back instead of what they typed. `detail` still travels, for rendering only.
|
|
454
|
+
offered: NO_OFFERED_OPTIONS,
|
|
455
|
+
// The answer IS the text, verbatim.
|
|
456
|
+
fromFreeText: (text) => text,
|
|
457
|
+
opts,
|
|
458
|
+
fallback: undefined,
|
|
459
|
+
localOutcome: choiceOutcome,
|
|
460
|
+
runBase: (baseOpts) => base.input(title, placeholder, baseOpts),
|
|
461
|
+
});
|
|
462
|
+
},
|
|
463
|
+
// ---------------------------------------------------------------------------------------
|
|
464
|
+
// Hand-delegated, verbatim. Not a Proxy — see the file header.
|
|
465
|
+
// ---------------------------------------------------------------------------------------
|
|
466
|
+
notify(message, type) {
|
|
467
|
+
base.notify(message, type);
|
|
468
|
+
},
|
|
469
|
+
onTerminalInput(handler) {
|
|
470
|
+
return base.onTerminalInput(handler);
|
|
471
|
+
},
|
|
472
|
+
setStatus(key, text) {
|
|
473
|
+
base.setStatus(key, text);
|
|
474
|
+
},
|
|
475
|
+
setWorkingMessage(message) {
|
|
476
|
+
base.setWorkingMessage(message);
|
|
477
|
+
},
|
|
478
|
+
setWorkingVisible(visible) {
|
|
479
|
+
base.setWorkingVisible(visible);
|
|
480
|
+
},
|
|
481
|
+
setWorkingIndicator(options) {
|
|
482
|
+
base.setWorkingIndicator(options);
|
|
483
|
+
},
|
|
484
|
+
setHiddenThinkingLabel(label) {
|
|
485
|
+
base.setHiddenThinkingLabel(label);
|
|
486
|
+
},
|
|
487
|
+
// `content` is `never` so this single implementation satisfies both declared overloads.
|
|
488
|
+
setWidget(key, content, options) {
|
|
489
|
+
base.setWidget(key, content, options);
|
|
490
|
+
},
|
|
491
|
+
setFooter(factory) {
|
|
492
|
+
base.setFooter(factory);
|
|
493
|
+
},
|
|
494
|
+
setHeader(factory) {
|
|
495
|
+
base.setHeader(factory);
|
|
496
|
+
},
|
|
497
|
+
setTitle(title) {
|
|
498
|
+
base.setTitle(title);
|
|
499
|
+
},
|
|
500
|
+
/** Local by documented exception: the factory produces a live component. */
|
|
501
|
+
custom(factory, options) {
|
|
502
|
+
return base.custom(factory, options);
|
|
503
|
+
},
|
|
504
|
+
pasteToEditor(text) {
|
|
505
|
+
base.pasteToEditor(text);
|
|
506
|
+
},
|
|
507
|
+
setEditorText(text) {
|
|
508
|
+
base.setEditorText(text);
|
|
509
|
+
},
|
|
510
|
+
getEditorText() {
|
|
511
|
+
return base.getEditorText();
|
|
512
|
+
},
|
|
513
|
+
/** Local by documented exception: a multi-line editor is not a one-shot answerable ask. */
|
|
514
|
+
editor(title, prefill) {
|
|
515
|
+
return base.editor(title, prefill);
|
|
516
|
+
},
|
|
517
|
+
addAutocompleteProvider(factory) {
|
|
518
|
+
base.addAutocompleteProvider(factory);
|
|
519
|
+
},
|
|
520
|
+
setEditorComponent(factory) {
|
|
521
|
+
base.setEditorComponent(factory);
|
|
522
|
+
},
|
|
523
|
+
getEditorComponent() {
|
|
524
|
+
return base.getEditorComponent();
|
|
525
|
+
},
|
|
526
|
+
get theme() {
|
|
527
|
+
return base.theme;
|
|
528
|
+
},
|
|
529
|
+
getAllThemes() {
|
|
530
|
+
return base.getAllThemes();
|
|
531
|
+
},
|
|
532
|
+
getTheme(name) {
|
|
533
|
+
return base.getTheme(name);
|
|
534
|
+
},
|
|
535
|
+
setTheme(newTheme) {
|
|
536
|
+
return base.setTheme(newTheme);
|
|
537
|
+
},
|
|
538
|
+
getToolsExpanded() {
|
|
539
|
+
return base.getToolsExpanded();
|
|
540
|
+
},
|
|
541
|
+
setToolsExpanded(expanded) {
|
|
542
|
+
base.setToolsExpanded(expanded);
|
|
543
|
+
},
|
|
544
|
+
hasAnswerSurface,
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Whether a surface's self-reported outcome is a {@link RelayOutcome} AT ALL.
|
|
549
|
+
*
|
|
550
|
+
* A VALIDITY test, not a meaning rule — the same discipline {@link classifyVocabulary} applies to a
|
|
551
|
+
* caller's vocabulary. `ExtensionUIContext` is implemented by third parties and by untyped JS
|
|
552
|
+
* extensions, so `reportOutcome("approved")` or `reportOutcome({kind: "maybe"})` is reachable, and
|
|
553
|
+
* a malformed report must fall back to today's derivation rather than become a decision word
|
|
554
|
+
* nothing downstream can read.
|
|
555
|
+
*
|
|
556
|
+
* What it deliberately does NOT do is cross-check the report against the value the surface
|
|
557
|
+
* resolved with. They are two different facts about the same act, the surface owns both, and
|
|
558
|
+
* inventing a tie-breaker between them would be exactly the derivation this file exists to
|
|
559
|
+
* abolish. A surface that lies about itself is a bug in that surface, not something a decorator
|
|
560
|
+
* can adjudicate.
|
|
561
|
+
*/
|
|
562
|
+
function isRelayOutcome(value) {
|
|
563
|
+
if (typeof value !== "object" || value === null)
|
|
564
|
+
return false;
|
|
565
|
+
const { kind, chosenOptionId } = value;
|
|
566
|
+
if (kind === "answered" || kind === "cancelled")
|
|
567
|
+
return true;
|
|
568
|
+
if (kind !== "approved" && kind !== "denied")
|
|
569
|
+
return false;
|
|
570
|
+
// `chosenOptionId` is REQUIRED on these two — `null` is the honest report of a surface that
|
|
571
|
+
// answered without naming an offered id, and `undefined` is a field somebody forgot.
|
|
572
|
+
return chosenOptionId === null || typeof chosenOptionId === "string";
|
|
573
|
+
}
|
|
574
|
+
/** Turn a synchronous throw into a rejected promise so both race arms behave identically. */
|
|
575
|
+
function callSafely(fn) {
|
|
576
|
+
try {
|
|
577
|
+
return fn();
|
|
578
|
+
}
|
|
579
|
+
catch (error) {
|
|
580
|
+
return Promise.reject(error);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Run one teardown step and swallow whatever it fails with — synchronously OR asynchronously.
|
|
585
|
+
*
|
|
586
|
+
* Teardown happens after the caller already has its answer, from inside a discarded `.then`: a
|
|
587
|
+
* surface that blows up while being torn down cannot un-answer a settled ask, and must not become
|
|
588
|
+
* an unhandled rejection. `relay.withdraw` is declared `void` but the real registry writes to a
|
|
589
|
+
* socket, so the natural implementation is `async` — catching only synchronous throws would leave
|
|
590
|
+
* exactly that shape fatal. Each step is wrapped on its own so a failure in one does not skip the
|
|
591
|
+
* rest.
|
|
592
|
+
*/
|
|
593
|
+
function quietly(step) {
|
|
594
|
+
try {
|
|
595
|
+
void Promise.resolve(step()).catch(() => {
|
|
596
|
+
// Deliberately ignored — see above.
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
catch {
|
|
600
|
+
// Deliberately ignored — see above.
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* The only words a permission vocabulary may use, as RUNTIME values rather than as a type.
|
|
605
|
+
*
|
|
606
|
+
* Derived from {@link CONFIRM_RESOLUTION}'s own keys so the two cannot drift: a word passes this
|
|
607
|
+
* gate if and only if there is a caller-side value to translate it into.
|
|
608
|
+
*/
|
|
609
|
+
const DECISION_WORDS = new Set(Object.keys(CONFIRM_RESOLUTION));
|
|
610
|
+
/** Narrow a value read out of untyped data to a decision word. */
|
|
611
|
+
function isDecisionWord(value) {
|
|
612
|
+
return typeof value === "string" && DECISION_WORDS.has(value);
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* THE ONE PLACE a caller's vocabulary is validated.
|
|
616
|
+
*
|
|
617
|
+
* `CONFIRM_RESOLUTION` is total over the declared TYPE but not over runtime values: a detail that
|
|
618
|
+
* crossed a wire or came from an untyped JS extension can carry `decision: "maybe"`, and without
|
|
619
|
+
* this gate that option was offered, broadcast, answerable, and resolved a `Promise<boolean>` with
|
|
620
|
+
* `undefined`. Ids likewise must be unique before {@link offeredSet}'s last-wins `new Map` sees
|
|
621
|
+
* them, or ARRAY POSITION decides which of two same-id options survives while `detail.options` —
|
|
622
|
+
* the documented rendering carrier — still shows both, letting a tapped "Deny" resolve `true`.
|
|
623
|
+
*
|
|
624
|
+
* This is a validity test, not a meaning rule: no branch here reads an option's COUNT, POSITION or
|
|
625
|
+
* ID to decide what that option means. The emptiness check asks "is this a vocabulary at all", and
|
|
626
|
+
* a vocabulary of zero words is not one.
|
|
627
|
+
*
|
|
628
|
+
* It is TOTAL over runtime values, and its parameter is `unknown` to say so. The declared type is
|
|
629
|
+
* exactly what a detail crossing a wire or coming from an untyped JS extension need not honour, and
|
|
630
|
+
* every expression this gate writes must survive being handed the data it exists to police:
|
|
631
|
+
* `vocabulary.length` threw a TypeError on `null`, `for...of` threw "is not iterable" on an
|
|
632
|
+
* array-like `{0: {…}, length: 1}`, and a non-object entry threw on the first property read. A
|
|
633
|
+
* malformed container is INVALID — an outcome this file already knows how to fail closed on — and
|
|
634
|
+
* never an exception out of `confirm()`.
|
|
635
|
+
*
|
|
636
|
+
* Every field is read EXACTLY ONCE, here, and the verdict carries {@link ValidatedOption} copies
|
|
637
|
+
* rather than the caller's array. See {@link ValidatedOption} for what that buys.
|
|
638
|
+
*/
|
|
639
|
+
function classifyVocabulary(vocabulary) {
|
|
640
|
+
if (vocabulary === undefined) {
|
|
641
|
+
return { kind: "absent" };
|
|
642
|
+
}
|
|
643
|
+
if (!Array.isArray(vocabulary)) {
|
|
644
|
+
return { kind: "invalid" };
|
|
645
|
+
}
|
|
646
|
+
const entries = vocabulary;
|
|
647
|
+
// A caller whose policy layer filtered its vocabulary down to nothing offered nothing. It did
|
|
648
|
+
// not ask for OUR yes/no pair, and must never have a "Yes" broadcast in its name.
|
|
649
|
+
if (entries.length === 0) {
|
|
650
|
+
return { kind: "invalid" };
|
|
651
|
+
}
|
|
652
|
+
const ids = new Set();
|
|
653
|
+
const snapshot = [];
|
|
654
|
+
for (const entry of entries) {
|
|
655
|
+
if (typeof entry !== "object" || entry === null) {
|
|
656
|
+
return { kind: "invalid" };
|
|
657
|
+
}
|
|
658
|
+
// The decision must be the option's OWN word. A bare `DECISION_WORDS.has(option.decision)`
|
|
659
|
+
// walks the prototype chain: with `Object.prototype.decision = "approve"` set anywhere in the
|
|
660
|
+
// process, an option that declared NOTHING was broadcast as an approval, and tapping its
|
|
661
|
+
// "Deny" label resolved `true`.
|
|
662
|
+
if (!Object.hasOwn(entry, "decision")) {
|
|
663
|
+
return { kind: "invalid" };
|
|
664
|
+
}
|
|
665
|
+
// One read per field, into locals. Everything below inspects these locals, never `entry`.
|
|
666
|
+
const { id, label, decision } = entry;
|
|
667
|
+
// `RelayAnswer.optionId` is typed `string`, so a non-string id is a promise the wire cannot
|
|
668
|
+
// keep: `[{id: 1, …deny}, {id: "1", …approve}]` passed the SameValueZero uniqueness proof
|
|
669
|
+
// (1 !== "1"), broadcast both, and a client honouring its own wire type by sending
|
|
670
|
+
// `String(1)` named the APPROVAL while the human had tapped "Deny". The type-conforming
|
|
671
|
+
// client was the one that got it wrong. An empty id is no handle at all.
|
|
672
|
+
if (typeof id !== "string" || id.length === 0) {
|
|
673
|
+
return { kind: "invalid" };
|
|
674
|
+
}
|
|
675
|
+
if (typeof label !== "string") {
|
|
676
|
+
return { kind: "invalid" };
|
|
677
|
+
}
|
|
678
|
+
if (!isDecisionWord(decision)) {
|
|
679
|
+
return { kind: "invalid" };
|
|
680
|
+
}
|
|
681
|
+
// KNOWN LATENT (accepted, not fixed): this proof is exact-string, so two ids differing only
|
|
682
|
+
// by Unicode normalisation form ("café" NFC vs NFD) are two distinct options here and one
|
|
683
|
+
// option in any client that normalises. Harmless for a hand-written vocabulary; a real risk
|
|
684
|
+
// the moment option ids are DERIVED from tool, path or command data — normalise here then.
|
|
685
|
+
if (ids.has(id)) {
|
|
686
|
+
return { kind: "invalid" };
|
|
687
|
+
}
|
|
688
|
+
ids.add(id);
|
|
689
|
+
snapshot.push(Object.freeze({ id, label, decision }));
|
|
690
|
+
}
|
|
691
|
+
return { kind: "valid", options: Object.freeze(snapshot) };
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Mint the vocabulary of a `confirm`, ONCE, behind the one validation gate.
|
|
695
|
+
*
|
|
696
|
+
* Each offered option's caller-side value is read off the option ITSELF, from the `decision` its
|
|
697
|
+
* vocabulary declares. There is no position rule, so a denial in the middle of the list, a
|
|
698
|
+
* vocabulary with several denials, and a single-option vocabulary are all simply what they say they
|
|
699
|
+
* are. With NO caller vocabulary, the default yes/no pair is minted through the same one path.
|
|
700
|
+
*
|
|
701
|
+
* With an INVALID caller vocabulary, nothing is offered at all: the ask broadcasts an empty option
|
|
702
|
+
* list, so it is decided by the local surface if one is live and otherwise by `confirm`'s own
|
|
703
|
+
* fail-closed `false`. An invalid vocabulary is never silently replaced by a fabricated one, and it
|
|
704
|
+
* can never approve anything.
|
|
705
|
+
*
|
|
706
|
+
* Nothing is logged here on purpose. This decorator runs under a TUI that owns the terminal, and a
|
|
707
|
+
* stray `console.warn` mid-render corrupts the screen; the rejection is visible instead as an ask
|
|
708
|
+
* that carries the caller's `detail` but offers no remote option.
|
|
709
|
+
*
|
|
710
|
+
* An id that is not in the set at all is not an answer, which is where fail-closed lives: it can
|
|
711
|
+
* never become a decision attributed to a human who never touched it.
|
|
712
|
+
*/
|
|
713
|
+
function mintConfirmOptions(vocabulary) {
|
|
714
|
+
const verdict = classifyVocabulary(vocabulary);
|
|
715
|
+
if (verdict.kind === "invalid") {
|
|
716
|
+
return NO_OFFERED_OPTIONS;
|
|
717
|
+
}
|
|
718
|
+
// BOTH arms are frozen data this file owns — the gate's snapshot, or our own default pair. The
|
|
719
|
+
// caller's array is never read again past validation, so what is minted here is exactly what was
|
|
720
|
+
// proved valid there.
|
|
721
|
+
const options = verdict.kind === "absent" ? DEFAULT_CONFIRM_OPTIONS : verdict.options;
|
|
722
|
+
return offeredSet(options.map((option) => offer(option.id, option.label, CONFIRM_RESOLUTION[option.decision], option.decision)));
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* The largest timeout this decorator will arm: `2^31-1` ms, about 24.85 days.
|
|
726
|
+
*
|
|
727
|
+
* ONE bound, because it is the smaller of the two real ceilings and therefore covers both.
|
|
728
|
+
*
|
|
729
|
+
* `setTimeout` stores its delay in a signed 32-bit int: anything larger is CLAMPED to 1ms with a
|
|
730
|
+
* `TimeoutOverflowWarning`. A 30-day timeout therefore advertised a deadline a month out and then
|
|
731
|
+
* settled `false` two milliseconds later, attributed to nobody — with no live base, every such ask
|
|
732
|
+
* fabricated a system denial before the phone could render it. Fail-closed, so it could not
|
|
733
|
+
* approve, but it contradicted this file's own promise that real expiry binds to the clock, and it
|
|
734
|
+
* broke the walk-away premise the relay exists for.
|
|
735
|
+
*
|
|
736
|
+
* Far above that, `new Date(Date.now() + t)` leaves the representable range (~8.64e15 ms from the
|
|
737
|
+
* epoch) and `.toISOString()` throws `RangeError: Invalid time value` SYNCHRONOUSLY, so
|
|
738
|
+
* `{ timeout: Number.MAX_SAFE_INTEGER }` — the idiomatic "never expire", which compiles cleanly —
|
|
739
|
+
* never reached either surface and arrived at the permission gate as a tool error, not a decision.
|
|
740
|
+
*/
|
|
741
|
+
const MAX_USABLE_TIMEOUT_MS = 2_147_483_647;
|
|
742
|
+
/**
|
|
743
|
+
* ONE verdict for a caller's declared timeout: a real, ARMABLE duration, or nothing at all.
|
|
744
|
+
*
|
|
745
|
+
* A DELIBERATE choice, stated because both readings are defensible: a declared timeout above
|
|
746
|
+
* {@link MAX_USABLE_TIMEOUT_MS} is treated as NO timeout at all, not as one capped to the maximum.
|
|
747
|
+
* Capping invents a bound the caller never asked for and then acts on it — "never expire" would
|
|
748
|
+
* become a fabricated system denial 24 days in, which is the very defect above, merely postponed.
|
|
749
|
+
* And `Number.MAX_SAFE_INTEGER` and `Infinity` are two spellings of one intent, so they must not
|
|
750
|
+
* behave differently. "No usable timeout" already has a documented meaning here: the ask carries
|
|
751
|
+
* `deadline: null`, this decorator arms no clock of its own, and the bound falls to the pending
|
|
752
|
+
* registry's own fail-closed timer (R34-PERM.6) — one clock, owned there.
|
|
753
|
+
*/
|
|
754
|
+
function usableTimeout(timeout) {
|
|
755
|
+
return typeof timeout === "number" && Number.isFinite(timeout) && timeout > 0 && timeout <= MAX_USABLE_TIMEOUT_MS
|
|
756
|
+
? timeout
|
|
757
|
+
: undefined;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Mint the vocabulary of a `select`, ONCE, from the caller's OWN option list and nothing else.
|
|
761
|
+
*
|
|
762
|
+
* Every offered option resolves to the very string it was minted from, bound at construction. The
|
|
763
|
+
* id is a wire handle and nothing more: it is never parsed back into a position, and two identical
|
|
764
|
+
* labels stay two distinct answers.
|
|
765
|
+
*
|
|
766
|
+
* `detail.options` is a permission-DETAIL carrier and deliberately contributes nothing here. Laying
|
|
767
|
+
* a permission vocabulary over a label list — by position, or by label match — is exactly the
|
|
768
|
+
* inference that once resolved an answered "Deny" to the caller-side string "Allow". The detail
|
|
769
|
+
* still travels on the ask for rendering; it just never decides anything.
|
|
770
|
+
*/
|
|
771
|
+
function mintSelectOptions(labels) {
|
|
772
|
+
// Iterate by index rather than with `labels.map`, which PRESERVES array holes: `new Map` then
|
|
773
|
+
// iterates the array iterator, hits the hole's `undefined` and throws "Iterator value undefined
|
|
774
|
+
// is not an entry object" synchronously out of the caller's `ui.select`. A caller reaches that
|
|
775
|
+
// with ordinary TypeScript — `for (…) if (keep) labels[i] = name` builds a sparse `string[]` —
|
|
776
|
+
// and the undecorated base does not throw, so the decorator would be introducing the crash.
|
|
777
|
+
// A hole has no label to render and no value to resolve to, so it is not offered at all; the
|
|
778
|
+
// surviving positions keep their own index in the id, so what IS offered stays answerable.
|
|
779
|
+
const options = [];
|
|
780
|
+
for (let position = 0; position < labels.length; position++) {
|
|
781
|
+
const label = labels[position];
|
|
782
|
+
if (typeof label !== "string")
|
|
783
|
+
continue;
|
|
784
|
+
options.push(offer(`option-${position}`, label, label));
|
|
785
|
+
}
|
|
786
|
+
return offeredSet(options);
|
|
787
|
+
}
|
|
788
|
+
//# sourceMappingURL=relay-ui-context.js.map
|