@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
package/dist/cli/attach-mode.js
CHANGED
|
@@ -3,12 +3,164 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides tmux-style attachment where you can see output and send input
|
|
5
5
|
* to a running session. Multiple clients can attach simultaneously.
|
|
6
|
+
*
|
|
7
|
+
* It is also the THIRD renderer of a permission ask (R34-PERM.2), and the one that used to
|
|
8
|
+
* swallow answers: every typed line went out as an `input` frame, so a human typing "Yes" at a
|
|
9
|
+
* dialog the session had raised did not answer it — the word arrived as a queued chat prompt
|
|
10
|
+
* while the agent sat parked inside `beforeToolCall` waiting for a decision that could never
|
|
11
|
+
* come. The answer mode below is that bug's fix: while an ask is outstanding, a typed line is an
|
|
12
|
+
* ANSWER or it is nothing at all.
|
|
6
13
|
*/
|
|
7
14
|
import path from "node:path";
|
|
8
15
|
import { createInterface } from "node:readline";
|
|
9
16
|
import chalk from "chalk";
|
|
10
|
-
import { getAgentDir } from "../config.js";
|
|
11
|
-
import {
|
|
17
|
+
import { APP_NAME, getAgentDir } from "../config.js";
|
|
18
|
+
import { assertValidSessionId } from "../core/session-manager.js";
|
|
19
|
+
import { SocketClient, } from "../core/socket-server/index.js";
|
|
20
|
+
/**
|
|
21
|
+
* Build the socket path for a session id supplied on the command line.
|
|
22
|
+
*
|
|
23
|
+
* The value is validated with the same rule the session manager applies when creating
|
|
24
|
+
* ids, so a `--attach` argument can never traverse out of the socket directory.
|
|
25
|
+
*
|
|
26
|
+
* @throws {Error} When the session id is not a valid session id.
|
|
27
|
+
*/
|
|
28
|
+
export function resolveAttachSocketPath(sessionId, socketDir) {
|
|
29
|
+
assertValidSessionId(sessionId);
|
|
30
|
+
return path.join(socketDir, `${sessionId}.sock`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Error frames that report a recoverable condition rather than a dead session.
|
|
34
|
+
*
|
|
35
|
+
* `PROMPT_FAILED` means one prompt was rejected (no model, no credentials),
|
|
36
|
+
* `PROMPT_QUEUED` means a prompt sent mid-turn was accepted and runs when the current
|
|
37
|
+
* turn finishes (R32-FLEET.7), and `SESSION_REPLACED` means the runtime switched
|
|
38
|
+
* sessions - in all three cases the client is still attached and the session is still
|
|
39
|
+
* there, so the client prints the message and stays.
|
|
40
|
+
*
|
|
41
|
+
* The `PERMISSION_*` codes are every way the session can REFUSE ONE ANSWER (R34-PERM.1): the
|
|
42
|
+
* ask is gone, the option was never offered, somebody else already decided, this connection is
|
|
43
|
+
* read-only or never declared the capability. A refusal is a statement about that one keystroke
|
|
44
|
+
* and about nothing else — the session is still running and this client is still attached — so
|
|
45
|
+
* exiting on it would turn "you named an option I did not offer" into a lost session.
|
|
46
|
+
*/
|
|
47
|
+
const NON_FATAL_ERROR_CODES = new Set([
|
|
48
|
+
"PROMPT_FAILED",
|
|
49
|
+
"PROMPT_QUEUED",
|
|
50
|
+
"SESSION_REPLACED",
|
|
51
|
+
"PERMISSION_UNKNOWN_REQUEST",
|
|
52
|
+
"PERMISSION_INVALID_OPTION",
|
|
53
|
+
"PERMISSION_ALREADY_RESOLVED",
|
|
54
|
+
"PERMISSION_NOT_ATTACHED",
|
|
55
|
+
"PERMISSION_READ_ONLY",
|
|
56
|
+
"PERMISSION_NOT_CAPABLE",
|
|
57
|
+
]);
|
|
58
|
+
/**
|
|
59
|
+
* Whether an `error` frame from the server should end the attached client.
|
|
60
|
+
*
|
|
61
|
+
* Uncoded frames stay fatal: they report protocol or attach failures.
|
|
62
|
+
*/
|
|
63
|
+
export function isFatalAttachError(code) {
|
|
64
|
+
return code === undefined || !NON_FATAL_ERROR_CODES.has(code);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Codes that ride the `error` channel while reporting something that went RIGHT.
|
|
68
|
+
*
|
|
69
|
+
* The socket wire has one server→client channel for out-of-band messages, so
|
|
70
|
+
* R32-FLEET.7's "your prompt was queued" arrives as an `error` frame. Printing
|
|
71
|
+
* it in red under an "Error:" heading would tell the operator their prompt
|
|
72
|
+
* failed at the exact moment it did not.
|
|
73
|
+
*/
|
|
74
|
+
const NOTICE_ERROR_CODES = new Set(["PROMPT_QUEUED"]);
|
|
75
|
+
/** Whether an `error` frame is a notice rather than a failure. */
|
|
76
|
+
export function isAttachNotice(code) {
|
|
77
|
+
return code !== undefined && NOTICE_ERROR_CODES.has(code);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resolve a typed line against the options an ask actually offered.
|
|
81
|
+
*
|
|
82
|
+
* Three spellings are accepted, and all three name an OFFERED option: its id, its label, or its
|
|
83
|
+
* 1-based position in the rendered list. Nothing else resolves — there is deliberately no
|
|
84
|
+
* "y"/"yes" fallback, no prefix match and no default, because every one of those invents an
|
|
85
|
+
* option the session did not offer and the whole point of answering by id is that the ask
|
|
86
|
+
* decides what may happen, not the renderer.
|
|
87
|
+
*
|
|
88
|
+
* Id and label are tried BEFORE the ordinal, so an ask that offers an option literally called
|
|
89
|
+
* "1" is answered by naming it rather than by whatever happens to sit first in the list.
|
|
90
|
+
*
|
|
91
|
+
* Exported for the option-matching tests; `runAttachMode` is the only production caller.
|
|
92
|
+
*/
|
|
93
|
+
export function matchPermissionAnswer(line, options) {
|
|
94
|
+
const typed = line.trim();
|
|
95
|
+
if (typed === "")
|
|
96
|
+
return undefined;
|
|
97
|
+
const folded = typed.toLowerCase();
|
|
98
|
+
const named = options.find((option) => option.id.toLowerCase() === folded || option.label.trim().toLowerCase() === folded);
|
|
99
|
+
if (named !== undefined)
|
|
100
|
+
return named;
|
|
101
|
+
if (!/^\d+$/.test(typed))
|
|
102
|
+
return undefined;
|
|
103
|
+
const ordinal = Number.parseInt(typed, 10);
|
|
104
|
+
if (ordinal < 1 || ordinal > options.length)
|
|
105
|
+
return undefined;
|
|
106
|
+
return options[ordinal - 1];
|
|
107
|
+
}
|
|
108
|
+
/** The one-line "that was not one of the choices" reminder, listing what IS on offer. */
|
|
109
|
+
export function permissionAnswerReminder(options) {
|
|
110
|
+
const offered = options.map((option, index) => `${index + 1}) ${option.label} [${option.id}]`).join(" ");
|
|
111
|
+
return `Not one of the offered answers — nothing was sent. Answer with: ${offered}`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Render one permission ask from its TYPED fields.
|
|
115
|
+
*
|
|
116
|
+
* Deliberately NOT built from the legacy `title`/`message` prose: that sentence is
|
|
117
|
+
* `${toolName}: ${reason}`, which cannot say which directory the command would run in or what
|
|
118
|
+
* the command actually is, and a human approving a `bash` call needs both. The typed fields are
|
|
119
|
+
* already neutralized and bounded where the frame was CONSTRUCTED (`safe-text.ts`), so nothing
|
|
120
|
+
* here re-sanitizes them — doing so twice is how a doubly-escaped command stops being the
|
|
121
|
+
* command the human is deciding about.
|
|
122
|
+
*
|
|
123
|
+
* NOTE ON `reason`: the socket frame carries no dedicated field for it. The permission gate
|
|
124
|
+
* folds it into `message` as `${toolName}: ${reason}`, so that field is rendered under its own
|
|
125
|
+
* name, on its own line, AFTER the typed facts rather than instead of them.
|
|
126
|
+
*
|
|
127
|
+
* Returned as lines rather than printed so the shape is testable without a socket.
|
|
128
|
+
*/
|
|
129
|
+
export function renderPermissionAsk(message) {
|
|
130
|
+
const lines = [];
|
|
131
|
+
lines.push("");
|
|
132
|
+
lines.push(chalk.bold.yellow("Permission required"));
|
|
133
|
+
lines.push(` Tool: ${message.toolName}`);
|
|
134
|
+
lines.push(` Directory: ${message.cwd}`);
|
|
135
|
+
if (message.command !== undefined) {
|
|
136
|
+
lines.push(` Command: ${message.command}`);
|
|
137
|
+
}
|
|
138
|
+
if (message.path !== undefined) {
|
|
139
|
+
lines.push(` Path: ${message.path}`);
|
|
140
|
+
}
|
|
141
|
+
if (message.operation !== undefined) {
|
|
142
|
+
lines.push(` Operation: ${message.operation}`);
|
|
143
|
+
}
|
|
144
|
+
if (message.message !== "") {
|
|
145
|
+
lines.push(` Reason: ${message.message}`);
|
|
146
|
+
}
|
|
147
|
+
if (message.truncated) {
|
|
148
|
+
// Said out loud: a decision made on an elided string is a decision made on less than the
|
|
149
|
+
// whole truth, and the human is entitled to know that before answering.
|
|
150
|
+
lines.push(chalk.yellow(" (some fields were too long and were shortened for display)"));
|
|
151
|
+
}
|
|
152
|
+
for (const [index, option] of message.options.entries()) {
|
|
153
|
+
lines.push(` ${index + 1}) ${option.label} [${option.id}]`);
|
|
154
|
+
}
|
|
155
|
+
lines.push(chalk.dim("Type the number, the label or the id to answer. Anything else is not sent."));
|
|
156
|
+
return lines;
|
|
157
|
+
}
|
|
158
|
+
/** How a settled ask is reported back to the operator, naming who actually decided it. */
|
|
159
|
+
export function renderPermissionResolution(message) {
|
|
160
|
+
const who = message.clientId === null ? message.surface : `${message.surface} (${message.clientId})`;
|
|
161
|
+
const chosen = message.chosenOptionId === null ? "" : ` [${message.chosenOptionId}]`;
|
|
162
|
+
return `Permission ${message.decision}${chosen} — answered on ${who}`;
|
|
163
|
+
}
|
|
12
164
|
/**
|
|
13
165
|
* Run attach mode - connect to an existing socket session.
|
|
14
166
|
*
|
|
@@ -17,12 +169,36 @@ import { SocketClient } from "../core/socket-server/index.js";
|
|
|
17
169
|
export async function runAttachMode(sessionId) {
|
|
18
170
|
const agentDir = getAgentDir();
|
|
19
171
|
const socketDir = path.join(agentDir, "sockets");
|
|
20
|
-
|
|
172
|
+
let socketPath;
|
|
173
|
+
try {
|
|
174
|
+
socketPath = resolveAttachSocketPath(sessionId, socketDir);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
const message = error instanceof Error ? error.message : "Invalid session id";
|
|
178
|
+
console.error(chalk.red(`Invalid --attach value: ${sessionId}`));
|
|
179
|
+
console.error(chalk.dim(message));
|
|
180
|
+
console.error(chalk.dim(`\nList running sessions with: ${APP_NAME} --list-sessions\n`));
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
21
183
|
console.log(chalk.dim(`Attaching to session ${chalk.cyan(sessionId)}...`));
|
|
22
184
|
const client = new SocketClient({
|
|
23
185
|
socketPath,
|
|
24
186
|
mode: "read-write",
|
|
25
187
|
});
|
|
188
|
+
/**
|
|
189
|
+
* Asks this client has been shown and that nobody has settled yet, oldest first.
|
|
190
|
+
*
|
|
191
|
+
* A list rather than a single slot because the session may legitimately have several asks in
|
|
192
|
+
* flight, and because a REPLAY after reconnect re-sends everything still pending: keying by
|
|
193
|
+
* `requestId` is what makes the same ask arriving twice re-render once instead of queueing a
|
|
194
|
+
* phantom second dialog whose answer would be refused as `PERMISSION_ALREADY_RESOLVED`.
|
|
195
|
+
*
|
|
196
|
+
* Only the head is answerable. Answer mode ends for an ask when its `permission_resolved`
|
|
197
|
+
* arrives — never when this client sends an answer, because the answer may be refused, and a
|
|
198
|
+
* client that dropped out of answer mode on send would forward the operator's second attempt
|
|
199
|
+
* to the model as a chat prompt.
|
|
200
|
+
*/
|
|
201
|
+
const pendingAsks = [];
|
|
26
202
|
// Handle session metadata
|
|
27
203
|
client.onMetadata((sessionId, cwd, createdAt) => {
|
|
28
204
|
console.log(chalk.dim(`Connected to session ${chalk.cyan(sessionId)}`));
|
|
@@ -51,10 +227,54 @@ export async function runAttachMode(sessionId) {
|
|
|
51
227
|
client.onClientLeft((clientId) => {
|
|
52
228
|
console.log(chalk.dim(`\n[${clientId} left]\n`));
|
|
53
229
|
});
|
|
230
|
+
// A permission ask raised by the session. Printed on its own, never spliced into the output
|
|
231
|
+
// stream: the output stream is the agent talking, and this is the session asking THIS human a
|
|
232
|
+
// question it will block on until somebody answers.
|
|
233
|
+
client.onPermissionRequest((message) => {
|
|
234
|
+
const known = pendingAsks.findIndex((ask) => ask.requestId === message.requestId);
|
|
235
|
+
if (known >= 0) {
|
|
236
|
+
// A replay of something already outstanding (a reconnect shows every pending ask again).
|
|
237
|
+
// Refresh what is on file and re-render only if it is the one being answered right now.
|
|
238
|
+
pendingAsks[known] = message;
|
|
239
|
+
if (known === 0) {
|
|
240
|
+
for (const line of renderPermissionAsk(message))
|
|
241
|
+
console.log(line);
|
|
242
|
+
}
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
pendingAsks.push(message);
|
|
246
|
+
if (pendingAsks.length === 1) {
|
|
247
|
+
for (const line of renderPermissionAsk(message))
|
|
248
|
+
console.log(line);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
console.log(chalk.dim(`[${pendingAsks.length - 1} more permission ask(s) waiting]`));
|
|
252
|
+
});
|
|
253
|
+
// How an ask ended, whoever ended it. This is R34-PERM.2's echo arriving at this surface: when
|
|
254
|
+
// a phone answered first, the operator sitting here must be told that, not left holding a
|
|
255
|
+
// dialog that has already been decided somewhere else.
|
|
256
|
+
client.onPermissionResolved((message) => {
|
|
257
|
+
const index = pendingAsks.findIndex((ask) => ask.requestId === message.requestId);
|
|
258
|
+
console.log(chalk.cyan(`\n${renderPermissionResolution(message)}\n`));
|
|
259
|
+
if (index < 0)
|
|
260
|
+
return;
|
|
261
|
+
pendingAsks.splice(index, 1);
|
|
262
|
+
const next = pendingAsks[0];
|
|
263
|
+
if (index === 0 && next !== undefined) {
|
|
264
|
+
for (const line of renderPermissionAsk(next))
|
|
265
|
+
console.log(line);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
54
268
|
// Handle errors
|
|
55
|
-
client.onError((message) => {
|
|
269
|
+
client.onError((message, code) => {
|
|
270
|
+
if (isAttachNotice(code)) {
|
|
271
|
+
console.log(chalk.dim(`\n[${message}]\n`));
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
56
274
|
console.error(chalk.red(`\nError: ${message}\n`));
|
|
57
|
-
|
|
275
|
+
if (isFatalAttachError(code)) {
|
|
276
|
+
process.exit(1);
|
|
277
|
+
}
|
|
58
278
|
});
|
|
59
279
|
// Handle disconnect
|
|
60
280
|
client.onDisconnect(() => {
|
|
@@ -79,6 +299,24 @@ export async function runAttachMode(sessionId) {
|
|
|
79
299
|
});
|
|
80
300
|
rl.prompt();
|
|
81
301
|
rl.on("line", (line) => {
|
|
302
|
+
const ask = pendingAsks[0];
|
|
303
|
+
if (ask !== undefined) {
|
|
304
|
+
// ANSWER MODE. The session is blocked on a decision, so this line is a decision or it
|
|
305
|
+
// is nothing — it is never forwarded as a prompt. A line that names no offered option
|
|
306
|
+
// is refused HERE, locally, and costs the ask nothing: bouncing it off the session
|
|
307
|
+
// would either be rejected there anyway or, worse, land in the model's context as a
|
|
308
|
+
// chat message the human meant as an answer.
|
|
309
|
+
const option = matchPermissionAnswer(line, ask.options);
|
|
310
|
+
if (option === undefined) {
|
|
311
|
+
console.log(chalk.yellow(permissionAnswerReminder(ask.options)));
|
|
312
|
+
rl.prompt();
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
client.sendPermissionResponse(ask.requestId, option.id);
|
|
316
|
+
console.log(chalk.dim(`Answered "${option.label}" — waiting for the session to confirm...`));
|
|
317
|
+
rl.prompt();
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
82
320
|
if (line.trim()) {
|
|
83
321
|
client.sendInput(`${line}\n`);
|
|
84
322
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attach-mode.js","sourceRoot":"","sources":["../../src/cli/attach-mode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE9D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,SAAiB;IACpD,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACjD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,SAAS,OAAO,CAAC,CAAC;IAE7D,OAAO,C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C,GAAG,CAAC,kBAAkB,UAAU,EAAE,CAAC,CAAC,CAAC;QACzD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,iEAAiE,CAAC,CAAC,CAAC;QAC5F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;IAED,4BAA4B;IAC5B,MAAM,EAAE,GAAG,eAAe,CAAC;QAC1B,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;KACvB,CAAC,CAAC;IAEH,EAAE,CAAC,MAAM,EAAE,CAAC;IAEZ,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QACtB,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YACjB,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;QAC/B,CAAC;QACD,EAAE,CAAC,MAAM,EAAE,CAAC;IACb,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;QACnB,MAAM,CAAC,UAAU,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,gBAAgB;IAChB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACzB,MAAM,CAAC,UAAU,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Attach mode - Connect to an existing socket-based draht session\n *\n * Provides tmux-style attachment where you can see output and send input\n * to a running session. Multiple clients can attach simultaneously.\n */\n\nimport path from \"node:path\";\nimport { createInterface } from \"node:readline\";\nimport chalk from \"chalk\";\nimport { getAgentDir } from \"../config.js\";\nimport { SocketClient } from \"../core/socket-server/index.js\";\n\n/**\n * Run attach mode - connect to an existing socket session.\n *\n * @param sessionId - Session ID to attach to\n */\nexport async function runAttachMode(sessionId: string): Promise<void> {\n\tconst agentDir = getAgentDir();\n\tconst socketDir = path.join(agentDir, \"sockets\");\n\tconst socketPath = path.join(socketDir, `${sessionId}.sock`);\n\n\tconsole.log(chalk.dim(`Attaching to session ${chalk.cyan(sessionId)}...`));\n\n\tconst client = new SocketClient({\n\t\tsocketPath,\n\t\tmode: \"read-write\",\n\t});\n\n\t// Handle session metadata\n\tclient.onMetadata((sessionId, cwd, createdAt) => {\n\t\tconsole.log(chalk.dim(`Connected to session ${chalk.cyan(sessionId)}`));\n\t\tconsole.log(chalk.dim(`CWD: ${cwd}`));\n\t\tconsole.log(chalk.dim(`Created: ${createdAt.toLocaleString()}`));\n\t\tconsole.log(chalk.dim(`\\nType messages to send input, Ctrl+D to detach\\n`));\n\t});\n\n\t// Handle output from session\n\tclient.onOutput((data, stream) => {\n\t\tif (stream === \"stderr\") {\n\t\t\tprocess.stderr.write(chalk.red(data));\n\t\t} else {\n\t\t\tprocess.stdout.write(data);\n\t\t}\n\t});\n\n\t// Handle input echo from other clients\n\tclient.onInputEcho((data, clientId) => {\n\t\t// Show who typed what (tmux-style)\n\t\tconsole.log(chalk.dim(`[${clientId}] `) + chalk.yellow(data));\n\t});\n\n\t// Handle other clients joining/leaving\n\tclient.onClientJoined((clientId, mode) => {\n\t\tconsole.log(chalk.dim(`\\n[${clientId} joined (${mode})]\\n`));\n\t});\n\n\tclient.onClientLeft((clientId) => {\n\t\tconsole.log(chalk.dim(`\\n[${clientId} left]\\n`));\n\t});\n\n\t// Handle errors\n\tclient.onError((message) => {\n\t\tconsole.error(chalk.red(`\\nError: ${message}\\n`));\n\t\tprocess.exit(1);\n\t});\n\n\t// Handle disconnect\n\tclient.onDisconnect(() => {\n\t\tconsole.log(chalk.dim(\"\\nDisconnected from session.\\n\"));\n\t\tprocess.exit(0);\n\t});\n\n\t// Connect to socket\n\ttry {\n\t\tawait client.connect();\n\t} catch (err) {\n\t\tconsole.error(chalk.red(`Failed to connect: ${err instanceof Error ? err.message : \"Unknown error\"}`));\n\t\tconsole.error(chalk.dim(`\\nSocket path: ${socketPath}`));\n\t\tconsole.error(chalk.dim(`\\nCheck if the session is running with: draht --list-sessions\\n`));\n\t\tprocess.exit(1);\n\t}\n\n\t// Set up readline for input\n\tconst rl = createInterface({\n\t\tinput: process.stdin,\n\t\toutput: process.stdout,\n\t\tprompt: chalk.dim(\"> \"),\n\t});\n\n\trl.prompt();\n\n\trl.on(\"line\", (line) => {\n\t\tif (line.trim()) {\n\t\t\tclient.sendInput(`${line}\\n`);\n\t\t}\n\t\trl.prompt();\n\t});\n\n\trl.on(\"close\", () => {\n\t\tclient.disconnect();\n\t\tprocess.exit(0);\n\t});\n\n\t// Handle Ctrl+C\n\tprocess.on(\"SIGINT\", () => {\n\t\tclient.disconnect();\n\t\tprocess.exit(0);\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"attach-mode.js","sourceRoot":"","sources":["../../src/cli/attach-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAIN,YAAY,GACZ,MAAM,gCAAgC,CAAC;AAExC;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,SAAiB,EAAE,SAAiB;IAC3E,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,SAAS,OAAO,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,M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CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,MAAM,CAAC,KAAK,2CAA2C,CAAC,CAAC,CAAC;YAC7F,EAAE,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;QACR,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YACjB,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;QAC/B,CAAC;QACD,EAAE,CAAC,MAAM,EAAE,CAAC;IACb,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;QACnB,MAAM,CAAC,UAAU,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,gBAAgB;IAChB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACzB,MAAM,CAAC,UAAU,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Attach mode - Connect to an existing socket-based draht session\n *\n * Provides tmux-style attachment where you can see output and send input\n * to a running session. Multiple clients can attach simultaneously.\n *\n * It is also the THIRD renderer of a permission ask (R34-PERM.2), and the one that used to\n * swallow answers: every typed line went out as an `input` frame, so a human typing \"Yes\" at a\n * dialog the session had raised did not answer it — the word arrived as a queued chat prompt\n * while the agent sat parked inside `beforeToolCall` waiting for a decision that could never\n * come. The answer mode below is that bug's fix: while an ask is outstanding, a typed line is an\n * ANSWER or it is nothing at all.\n */\n\nimport path from \"node:path\";\nimport { createInterface } from \"node:readline\";\nimport chalk from \"chalk\";\nimport { APP_NAME, getAgentDir } from \"../config.js\";\nimport { assertValidSessionId } from \"../core/session-manager.js\";\nimport {\n\ttype PermissionOption,\n\ttype PermissionRequestMessage,\n\ttype PermissionResolvedMessage,\n\tSocketClient,\n} from \"../core/socket-server/index.js\";\n\n/**\n * Build the socket path for a session id supplied on the command line.\n *\n * The value is validated with the same rule the session manager applies when creating\n * ids, so a `--attach` argument can never traverse out of the socket directory.\n *\n * @throws {Error} When the session id is not a valid session id.\n */\nexport function resolveAttachSocketPath(sessionId: string, socketDir: string): string {\n\tassertValidSessionId(sessionId);\n\treturn path.join(socketDir, `${sessionId}.sock`);\n}\n\n/**\n * Error frames that report a recoverable condition rather than a dead session.\n *\n * `PROMPT_FAILED` means one prompt was rejected (no model, no credentials),\n * `PROMPT_QUEUED` means a prompt sent mid-turn was accepted and runs when the current\n * turn finishes (R32-FLEET.7), and `SESSION_REPLACED` means the runtime switched\n * sessions - in all three cases the client is still attached and the session is still\n * there, so the client prints the message and stays.\n *\n * The `PERMISSION_*` codes are every way the session can REFUSE ONE ANSWER (R34-PERM.1): the\n * ask is gone, the option was never offered, somebody else already decided, this connection is\n * read-only or never declared the capability. A refusal is a statement about that one keystroke\n * and about nothing else — the session is still running and this client is still attached — so\n * exiting on it would turn \"you named an option I did not offer\" into a lost session.\n */\nconst NON_FATAL_ERROR_CODES = new Set([\n\t\"PROMPT_FAILED\",\n\t\"PROMPT_QUEUED\",\n\t\"SESSION_REPLACED\",\n\t\"PERMISSION_UNKNOWN_REQUEST\",\n\t\"PERMISSION_INVALID_OPTION\",\n\t\"PERMISSION_ALREADY_RESOLVED\",\n\t\"PERMISSION_NOT_ATTACHED\",\n\t\"PERMISSION_READ_ONLY\",\n\t\"PERMISSION_NOT_CAPABLE\",\n]);\n\n/**\n * Whether an `error` frame from the server should end the attached client.\n *\n * Uncoded frames stay fatal: they report protocol or attach failures.\n */\nexport function isFatalAttachError(code?: string): boolean {\n\treturn code === undefined || !NON_FATAL_ERROR_CODES.has(code);\n}\n\n/**\n * Codes that ride the `error` channel while reporting something that went RIGHT.\n *\n * The socket wire has one server→client channel for out-of-band messages, so\n * R32-FLEET.7's \"your prompt was queued\" arrives as an `error` frame. Printing\n * it in red under an \"Error:\" heading would tell the operator their prompt\n * failed at the exact moment it did not.\n */\nconst NOTICE_ERROR_CODES = new Set([\"PROMPT_QUEUED\"]);\n\n/** Whether an `error` frame is a notice rather than a failure. */\nexport function isAttachNotice(code?: string): boolean {\n\treturn code !== undefined && NOTICE_ERROR_CODES.has(code);\n}\n\n/**\n * Resolve a typed line against the options an ask actually offered.\n *\n * Three spellings are accepted, and all three name an OFFERED option: its id, its label, or its\n * 1-based position in the rendered list. Nothing else resolves — there is deliberately no\n * \"y\"/\"yes\" fallback, no prefix match and no default, because every one of those invents an\n * option the session did not offer and the whole point of answering by id is that the ask\n * decides what may happen, not the renderer.\n *\n * Id and label are tried BEFORE the ordinal, so an ask that offers an option literally called\n * \"1\" is answered by naming it rather than by whatever happens to sit first in the list.\n *\n * Exported for the option-matching tests; `runAttachMode` is the only production caller.\n */\nexport function matchPermissionAnswer(\n\tline: string,\n\toptions: readonly PermissionOption[],\n): PermissionOption | undefined {\n\tconst typed = line.trim();\n\tif (typed === \"\") return undefined;\n\n\tconst folded = typed.toLowerCase();\n\tconst named = options.find(\n\t\t(option) => option.id.toLowerCase() === folded || option.label.trim().toLowerCase() === folded,\n\t);\n\tif (named !== undefined) return named;\n\n\tif (!/^\\d+$/.test(typed)) return undefined;\n\tconst ordinal = Number.parseInt(typed, 10);\n\tif (ordinal < 1 || ordinal > options.length) return undefined;\n\treturn options[ordinal - 1];\n}\n\n/** The one-line \"that was not one of the choices\" reminder, listing what IS on offer. */\nexport function permissionAnswerReminder(options: readonly PermissionOption[]): string {\n\tconst offered = options.map((option, index) => `${index + 1}) ${option.label} [${option.id}]`).join(\" \");\n\treturn `Not one of the offered answers — nothing was sent. Answer with: ${offered}`;\n}\n\n/**\n * Render one permission ask from its TYPED fields.\n *\n * Deliberately NOT built from the legacy `title`/`message` prose: that sentence is\n * `${toolName}: ${reason}`, which cannot say which directory the command would run in or what\n * the command actually is, and a human approving a `bash` call needs both. The typed fields are\n * already neutralized and bounded where the frame was CONSTRUCTED (`safe-text.ts`), so nothing\n * here re-sanitizes them — doing so twice is how a doubly-escaped command stops being the\n * command the human is deciding about.\n *\n * NOTE ON `reason`: the socket frame carries no dedicated field for it. The permission gate\n * folds it into `message` as `${toolName}: ${reason}`, so that field is rendered under its own\n * name, on its own line, AFTER the typed facts rather than instead of them.\n *\n * Returned as lines rather than printed so the shape is testable without a socket.\n */\nexport function renderPermissionAsk(message: PermissionRequestMessage): string[] {\n\tconst lines: string[] = [];\n\tlines.push(\"\");\n\tlines.push(chalk.bold.yellow(\"Permission required\"));\n\tlines.push(` Tool: ${message.toolName}`);\n\tlines.push(` Directory: ${message.cwd}`);\n\tif (message.command !== undefined) {\n\t\tlines.push(` Command: ${message.command}`);\n\t}\n\tif (message.path !== undefined) {\n\t\tlines.push(` Path: ${message.path}`);\n\t}\n\tif (message.operation !== undefined) {\n\t\tlines.push(` Operation: ${message.operation}`);\n\t}\n\tif (message.message !== \"\") {\n\t\tlines.push(` Reason: ${message.message}`);\n\t}\n\tif (message.truncated) {\n\t\t// Said out loud: a decision made on an elided string is a decision made on less than the\n\t\t// whole truth, and the human is entitled to know that before answering.\n\t\tlines.push(chalk.yellow(\" (some fields were too long and were shortened for display)\"));\n\t}\n\tfor (const [index, option] of message.options.entries()) {\n\t\tlines.push(` ${index + 1}) ${option.label} [${option.id}]`);\n\t}\n\tlines.push(chalk.dim(\"Type the number, the label or the id to answer. Anything else is not sent.\"));\n\treturn lines;\n}\n\n/** How a settled ask is reported back to the operator, naming who actually decided it. */\nexport function renderPermissionResolution(message: PermissionResolvedMessage): string {\n\tconst who = message.clientId === null ? message.surface : `${message.surface} (${message.clientId})`;\n\tconst chosen = message.chosenOptionId === null ? \"\" : ` [${message.chosenOptionId}]`;\n\treturn `Permission ${message.decision}${chosen} — answered on ${who}`;\n}\n\n/**\n * Run attach mode - connect to an existing socket session.\n *\n * @param sessionId - Session ID to attach to\n */\nexport async function runAttachMode(sessionId: string): Promise<void> {\n\tconst agentDir = getAgentDir();\n\tconst socketDir = path.join(agentDir, \"sockets\");\n\n\tlet socketPath: string;\n\ttry {\n\t\tsocketPath = resolveAttachSocketPath(sessionId, socketDir);\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : \"Invalid session id\";\n\t\tconsole.error(chalk.red(`Invalid --attach value: ${sessionId}`));\n\t\tconsole.error(chalk.dim(message));\n\t\tconsole.error(chalk.dim(`\\nList running sessions with: ${APP_NAME} --list-sessions\\n`));\n\t\tprocess.exit(1);\n\t}\n\n\tconsole.log(chalk.dim(`Attaching to session ${chalk.cyan(sessionId)}...`));\n\n\tconst client = new SocketClient({\n\t\tsocketPath,\n\t\tmode: \"read-write\",\n\t});\n\n\t/**\n\t * Asks this client has been shown and that nobody has settled yet, oldest first.\n\t *\n\t * A list rather than a single slot because the session may legitimately have several asks in\n\t * flight, and because a REPLAY after reconnect re-sends everything still pending: keying by\n\t * `requestId` is what makes the same ask arriving twice re-render once instead of queueing a\n\t * phantom second dialog whose answer would be refused as `PERMISSION_ALREADY_RESOLVED`.\n\t *\n\t * Only the head is answerable. Answer mode ends for an ask when its `permission_resolved`\n\t * arrives — never when this client sends an answer, because the answer may be refused, and a\n\t * client that dropped out of answer mode on send would forward the operator's second attempt\n\t * to the model as a chat prompt.\n\t */\n\tconst pendingAsks: PermissionRequestMessage[] = [];\n\n\t// Handle session metadata\n\tclient.onMetadata((sessionId, cwd, createdAt) => {\n\t\tconsole.log(chalk.dim(`Connected to session ${chalk.cyan(sessionId)}`));\n\t\tconsole.log(chalk.dim(`CWD: ${cwd}`));\n\t\tconsole.log(chalk.dim(`Created: ${createdAt.toLocaleString()}`));\n\t\tconsole.log(chalk.dim(`\\nType messages to send input, Ctrl+D to detach\\n`));\n\t});\n\n\t// Handle output from session\n\tclient.onOutput((data, stream) => {\n\t\tif (stream === \"stderr\") {\n\t\t\tprocess.stderr.write(chalk.red(data));\n\t\t} else {\n\t\t\tprocess.stdout.write(data);\n\t\t}\n\t});\n\n\t// Handle input echo from other clients\n\tclient.onInputEcho((data, clientId) => {\n\t\t// Show who typed what (tmux-style)\n\t\tconsole.log(chalk.dim(`[${clientId}] `) + chalk.yellow(data));\n\t});\n\n\t// Handle other clients joining/leaving\n\tclient.onClientJoined((clientId, mode) => {\n\t\tconsole.log(chalk.dim(`\\n[${clientId} joined (${mode})]\\n`));\n\t});\n\n\tclient.onClientLeft((clientId) => {\n\t\tconsole.log(chalk.dim(`\\n[${clientId} left]\\n`));\n\t});\n\n\t// A permission ask raised by the session. Printed on its own, never spliced into the output\n\t// stream: the output stream is the agent talking, and this is the session asking THIS human a\n\t// question it will block on until somebody answers.\n\tclient.onPermissionRequest((message) => {\n\t\tconst known = pendingAsks.findIndex((ask) => ask.requestId === message.requestId);\n\t\tif (known >= 0) {\n\t\t\t// A replay of something already outstanding (a reconnect shows every pending ask again).\n\t\t\t// Refresh what is on file and re-render only if it is the one being answered right now.\n\t\t\tpendingAsks[known] = message;\n\t\t\tif (known === 0) {\n\t\t\t\tfor (const line of renderPermissionAsk(message)) console.log(line);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tpendingAsks.push(message);\n\t\tif (pendingAsks.length === 1) {\n\t\t\tfor (const line of renderPermissionAsk(message)) console.log(line);\n\t\t\treturn;\n\t\t}\n\t\tconsole.log(chalk.dim(`[${pendingAsks.length - 1} more permission ask(s) waiting]`));\n\t});\n\n\t// How an ask ended, whoever ended it. This is R34-PERM.2's echo arriving at this surface: when\n\t// a phone answered first, the operator sitting here must be told that, not left holding a\n\t// dialog that has already been decided somewhere else.\n\tclient.onPermissionResolved((message) => {\n\t\tconst index = pendingAsks.findIndex((ask) => ask.requestId === message.requestId);\n\t\tconsole.log(chalk.cyan(`\\n${renderPermissionResolution(message)}\\n`));\n\t\tif (index < 0) return;\n\t\tpendingAsks.splice(index, 1);\n\t\tconst next = pendingAsks[0];\n\t\tif (index === 0 && next !== undefined) {\n\t\t\tfor (const line of renderPermissionAsk(next)) console.log(line);\n\t\t}\n\t});\n\n\t// Handle errors\n\tclient.onError((message, code) => {\n\t\tif (isAttachNotice(code)) {\n\t\t\tconsole.log(chalk.dim(`\\n[${message}]\\n`));\n\t\t\treturn;\n\t\t}\n\t\tconsole.error(chalk.red(`\\nError: ${message}\\n`));\n\t\tif (isFatalAttachError(code)) {\n\t\t\tprocess.exit(1);\n\t\t}\n\t});\n\n\t// Handle disconnect\n\tclient.onDisconnect(() => {\n\t\tconsole.log(chalk.dim(\"\\nDisconnected from session.\\n\"));\n\t\tprocess.exit(0);\n\t});\n\n\t// Connect to socket\n\ttry {\n\t\tawait client.connect();\n\t} catch (err) {\n\t\tconsole.error(chalk.red(`Failed to connect: ${err instanceof Error ? err.message : \"Unknown error\"}`));\n\t\tconsole.error(chalk.dim(`\\nSocket path: ${socketPath}`));\n\t\tconsole.error(chalk.dim(`\\nCheck if the session is running with: draht --list-sessions\\n`));\n\t\tprocess.exit(1);\n\t}\n\n\t// Set up readline for input\n\tconst rl = createInterface({\n\t\tinput: process.stdin,\n\t\toutput: process.stdout,\n\t\tprompt: chalk.dim(\"> \"),\n\t});\n\n\trl.prompt();\n\n\trl.on(\"line\", (line) => {\n\t\tconst ask = pendingAsks[0];\n\t\tif (ask !== undefined) {\n\t\t\t// ANSWER MODE. The session is blocked on a decision, so this line is a decision or it\n\t\t\t// is nothing — it is never forwarded as a prompt. A line that names no offered option\n\t\t\t// is refused HERE, locally, and costs the ask nothing: bouncing it off the session\n\t\t\t// would either be rejected there anyway or, worse, land in the model's context as a\n\t\t\t// chat message the human meant as an answer.\n\t\t\tconst option = matchPermissionAnswer(line, ask.options);\n\t\t\tif (option === undefined) {\n\t\t\t\tconsole.log(chalk.yellow(permissionAnswerReminder(ask.options)));\n\t\t\t\trl.prompt();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tclient.sendPermissionResponse(ask.requestId, option.id);\n\t\t\tconsole.log(chalk.dim(`Answered \"${option.label}\" — waiting for the session to confirm...`));\n\t\t\trl.prompt();\n\t\t\treturn;\n\t\t}\n\n\t\tif (line.trim()) {\n\t\t\tclient.sendInput(`${line}\\n`);\n\t\t}\n\t\trl.prompt();\n\t});\n\n\trl.on(\"close\", () => {\n\t\tclient.disconnect();\n\t\tprocess.exit(0);\n\t});\n\n\t// Handle Ctrl+C\n\tprocess.on(\"SIGINT\", () => {\n\t\tclient.disconnect();\n\t\tprocess.exit(0);\n\t});\n}\n"]}
|
|
@@ -10,7 +10,7 @@ export declare class CredentialPrintError extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
export declare function isCredentialPrintHelp(args: string[]): boolean;
|
|
12
12
|
export declare function printCredentialPrintHelp(): void;
|
|
13
|
-
/** Parse the small, extensible `
|
|
13
|
+
/** Parse the small, extensible `auth` command surface before normal startup. */
|
|
14
14
|
export declare function parseCredentialPrintCommand(args: string[]): CredentialPrintCommand | undefined;
|
|
15
15
|
export declare function validateCredentialPrintArgs(args: Args): void;
|
|
16
16
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential-print.d.ts","sourceRoot":"","sources":["../../src/cli/credential-print.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"credential-print.d.ts","sourceRoot":"","sources":["../../src/cli/credential-print.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,cAAc,CAAC;AAI7D,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,oBAAqB,SAAQ,KAAK;CAAG;AAElD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAI7D;AAED,wBAAgB,wBAAwB,IAAI,IAAI,CAM/C;AAED,gFAAgF;AAChF,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,sBAAsB,GAAG,SAAS,CA+B9F;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAU5D;AAED;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC9C,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAE,mBAAmB,EACzB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CA+DjB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { APP_NAME } from "../config.js";
|
|
1
2
|
import { resolveCliModel } from "../core/model-resolver.js";
|
|
2
3
|
const DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS = 30 * 60_000;
|
|
3
4
|
export class CredentialPrintError extends Error {
|
|
@@ -7,18 +8,18 @@ export function isCredentialPrintHelp(args) {
|
|
|
7
8
|
}
|
|
8
9
|
export function printCredentialPrintHelp() {
|
|
9
10
|
console.log(`Usage:
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
${APP_NAME} auth print-api-key --model <model> [--provider <provider>]
|
|
12
|
+
${APP_NAME} auth print-bearer-token --model <model> [--provider <provider>] [--min-expiry <duration>]
|
|
12
13
|
|
|
13
14
|
Prints the configured credential alone on stdout. Provider inference uses configured credentials; specify --provider to select explicitly. Bearer tokens have a 30-minute minimum expiry by default. --min-expiry accepts ms, s, m, or h (for example, 30m).`);
|
|
14
15
|
}
|
|
15
|
-
/** Parse the small, extensible `
|
|
16
|
+
/** Parse the small, extensible `auth` command surface before normal startup. */
|
|
16
17
|
export function parseCredentialPrintCommand(args) {
|
|
17
18
|
if (args[0] !== "auth")
|
|
18
19
|
return undefined;
|
|
19
20
|
const kind = args[1] === "print-api-key" ? "api_key" : args[1] === "print-bearer-token" ? "bearer_token" : undefined;
|
|
20
21
|
if (!kind) {
|
|
21
|
-
throw new CredentialPrintError(`Unknown auth command "${args[1] ?? ""}". Use "
|
|
22
|
+
throw new CredentialPrintError(`Unknown auth command "${args[1] ?? ""}". Use "${APP_NAME} auth print-api-key" or "${APP_NAME} auth print-bearer-token".`);
|
|
22
23
|
}
|
|
23
24
|
const commandArgs = [];
|
|
24
25
|
let minExpiryMs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential-print.js","sourceRoot":"","sources":["../../src/cli/credential-print.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAM5D,MAAM,kCAAkC,GAAG,EAAE,GAAG,MAAM,CAAC;AAQvD,MAAM,OAAO,oBAAqB,SAAQ,KAAK;CAAG;AAElD,MAAM,UAAU,qBAAqB,CAAC,IAAc;IACnD,OAAO,CACN,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAC/G,CAAC;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB;IACvC,OAAO,CAAC,GAAG,CAAC;;;;6PAIgP,CAAC,CAAC;AAC/P,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,2BAA2B,CAAC,IAAc;IACzD,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM;QAAE,OAAO,SAAS,CAAC;IAEzC,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,oBAAoB,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC;IACrH,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,MAAM,IAAI,oBAAoB,CAC7B,yBAAyB,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,iEAAiE,CAC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,4CAA4C,CAAC,CAAC;QACrG,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,KAAK,cAAc,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YAClE,MAAM,IAAI,oBAAoB,CAAC,aAAa,UAAU,gDAAgD,CAAC,CAAC;QACzG,CAAC;QACD,MAAM,IAAI,oBAAoB,CAC7B,aAAa,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,oBAAoB,gBAAgB,CAClF,CAAC;IACH,CAAC;IACD,MAAM,IAAI,oBAAoB,CAC7B,UAAU,IAAI,CAAC,KAAK,wCAAwC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAC9I,CAAC;AACH,CAAC","sourcesContent":["import type { Api, CredentialInfo, Model } from \"@draht/ai\";\nimport { resolveCliModel } from \"../core/model-resolver.ts\";\nimport type { ModelRuntime } from \"../core/model-runtime.ts\";\nimport type { Args } from \"./args.ts\";\n\nexport type CredentialPrintKind = \"api_key\" | \"bearer_token\";\n\nconst DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS = 30 * 60_000;\n\nexport interface CredentialPrintCommand {\n\tkind: CredentialPrintKind;\n\targs: string[];\n\tminExpiryMs?: number;\n}\n\nexport class CredentialPrintError extends Error {}\n\nexport function isCredentialPrintHelp(args: string[]): boolean {\n\treturn (\n\t\targs[0] === \"auth\" && (args[1] === undefined || args[1] === \"help\" || args[1] === \"--help\" || args[1] === \"-h\")\n\t);\n}\n\nexport function printCredentialPrintHelp(): void {\n\tconsole.log(`Usage:\n pi auth print-api-key --model <model> [--provider <provider>]\n pi auth print-bearer-token --model <model> [--provider <provider>] [--min-expiry <duration>]\n\nPrints the configured credential alone on stdout. Provider inference uses configured credentials; specify --provider to select explicitly. Bearer tokens have a 30-minute minimum expiry by default. --min-expiry accepts ms, s, m, or h (for example, 30m).`);\n}\n\n/** Parse the small, extensible `pi auth` command surface before normal startup. */\nexport function parseCredentialPrintCommand(args: string[]): CredentialPrintCommand | undefined {\n\tif (args[0] !== \"auth\") return undefined;\n\n\tconst kind = args[1] === \"print-api-key\" ? \"api_key\" : args[1] === \"print-bearer-token\" ? \"bearer_token\" : undefined;\n\tif (!kind) {\n\t\tthrow new CredentialPrintError(\n\t\t\t`Unknown auth command \"${args[1] ?? \"\"}\". Use \"pi auth print-api-key\" or \"pi auth print-bearer-token\".`,\n\t\t);\n\t}\n\n\tconst commandArgs: string[] = [];\n\tlet minExpiryMs: number | undefined;\n\tfor (let index = 2; index < args.length; index++) {\n\t\tif (args[index] !== \"--min-expiry\") {\n\t\t\tcommandArgs.push(args[index]);\n\t\t\tcontinue;\n\t\t}\n\t\tif (kind !== \"bearer_token\") {\n\t\t\tthrow new CredentialPrintError(\"--min-expiry is only supported by print-bearer-token\");\n\t\t}\n\t\tconst value = args[++index];\n\t\tconst match = value ? /^(\\d+)(ms|s|m|h)$/iu.exec(value) : undefined;\n\t\tif (!match) {\n\t\t\tthrow new CredentialPrintError(\"--min-expiry must use a duration such as 30m or 1h\");\n\t\t}\n\t\tconst amount = Number(match[1]);\n\t\tconst unit = match[2];\n\t\tminExpiryMs = amount * (unit === \"ms\" ? 1 : unit === \"s\" ? 1_000 : unit === \"m\" ? 60_000 : 3_600_000);\n\t}\n\n\treturn minExpiryMs === undefined ? { kind, args: commandArgs } : { kind, args: commandArgs, minExpiryMs };\n}\n\nexport function validateCredentialPrintArgs(args: Args): void {\n\tif (!args.model?.trim()) {\n\t\tthrow new CredentialPrintError(\"Credential printing requires --model <model>\");\n\t}\n\tif (args.apiKey !== undefined) {\n\t\tthrow new CredentialPrintError(\"Credential printing reads configured credentials; --api-key is not supported\");\n\t}\n\tif (args.messages.length > 0 || args.fileArgs.length > 0 || args.unknownFlags.size > 0) {\n\t\tthrow new CredentialPrintError(\"Credential printing only accepts --provider and --model\");\n\t}\n}\n\n/**\n * Resolve one request credential for a specific provider/model pair.\n *\n * This intentionally calls ModelRuntime.getAuth(), which refreshes and persists\n * OAuth credentials with less than five minutes remaining through the normal request-auth path.\n */\nexport async function resolveCredentialForPrint(\n\targs: Args,\n\tmodelRuntime: ModelRuntime,\n\tkind: CredentialPrintKind,\n\tminExpiryMs?: number,\n): Promise<string> {\n\tvalidateCredentialPrintArgs(args);\n\n\tconst credentialTypes = new Map<string, CredentialInfo[\"type\"]>(\n\t\t(await modelRuntime.listCredentials()).map((credential) => [credential.providerId, credential.type]),\n\t);\n\tconst models: Model<Api>[] = [];\n\tif (args.provider) {\n\t\tconst resolved = resolveCliModel({ cliProvider: args.provider, cliModel: args.model, modelRuntime });\n\t\tif (resolved.error || !resolved.model) {\n\t\t\tthrow new CredentialPrintError(resolved.error ?? \"Unable to resolve the requested provider/model\");\n\t\t}\n\t\tmodels.push(resolved.model);\n\t} else {\n\t\tfor (const provider of modelRuntime.getProviders()) {\n\t\t\tif (!credentialTypes.has(provider.id)) continue;\n\t\t\tconst resolved = resolveCliModel({ cliProvider: provider.id, cliModel: args.model, modelRuntime });\n\t\t\tif (resolved.model && !resolved.error && !resolved.warning?.includes(\"Using custom model id\")) {\n\t\t\t\tmodels.push(resolved.model);\n\t\t\t}\n\t\t}\n\t\tif (models.length === 0) {\n\t\t\tthrow new CredentialPrintError(`Model \"${args.model}\" not found. Use --list-models to see available models.`);\n\t\t}\n\t}\n\n\tconst credentials: Array<{ providerId: string; value: string }> = [];\n\tfor (const model of models) {\n\t\tconst type = credentialTypes.get(model.provider);\n\t\tif (kind === \"api_key\" && type === \"oauth\") continue;\n\t\tif (kind === \"bearer_token\" && type !== \"oauth\") continue;\n\n\t\tconst auth = await modelRuntime.getAuth(\n\t\t\tmodel,\n\t\t\tkind === \"bearer_token\"\n\t\t\t\t? { minOAuthValidityMs: minExpiryMs ?? DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS }\n\t\t\t\t: undefined,\n\t\t);\n\t\tconst authorization = Object.entries(auth?.auth.headers ?? {}).find(\n\t\t\t([name]) => name.toLowerCase() === \"authorization\",\n\t\t)?.[1];\n\t\tconst bearerToken = typeof authorization === \"string\" ? /^Bearer\\s+(.+)$/iu.exec(authorization)?.[1] : undefined;\n\t\tconst value = kind === \"bearer_token\" ? (auth?.auth.apiKey ?? bearerToken) : auth?.auth.apiKey;\n\t\tif (value) credentials.push({ providerId: model.provider, value });\n\t}\n\n\tif (credentials.length === 1) return credentials[0].value;\n\tif (credentials.length === 0) {\n\t\tconst providerId = models[0]?.provider;\n\t\tconst type = providerId ? credentialTypes.get(providerId) : undefined;\n\t\tif (args.provider && kind === \"api_key\" && type === \"oauth\") {\n\t\t\tthrow new CredentialPrintError(`Provider \"${providerId}\" is configured with OAuth, not an API key`);\n\t\t}\n\t\tif (args.provider && kind === \"bearer_token\" && type !== \"oauth\") {\n\t\t\tthrow new CredentialPrintError(`Provider \"${providerId}\" is not configured with an OAuth bearer token`);\n\t\t}\n\t\tthrow new CredentialPrintError(\n\t\t\t`No usable ${kind === \"api_key\" ? \"API key\" : \"OAuth bearer token\"} is configured`,\n\t\t);\n\t}\n\tthrow new CredentialPrintError(\n\t\t`Model \"${args.model}\" has multiple configured providers (${credentials.map(({ providerId }) => providerId).join(\", \")}). Specify --provider.`,\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"credential-print.js","sourceRoot":"","sources":["../../src/cli/credential-print.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAM5D,MAAM,kCAAkC,GAAG,EAAE,GAAG,MAAM,CAAC;AAQvD,MAAM,OAAO,oBAAqB,SAAQ,KAAK;CAAG;AAElD,MAAM,UAAU,qBAAqB,CAAC,IAAc;IACnD,OAAO,CACN,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,I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IAAI,CAAC,IAAI,CAAC,wBAAwB,CAC9I,CAAC;AACH,CAAC","sourcesContent":["import type { Api, CredentialInfo, Model } from \"@draht/ai\";\nimport { APP_NAME } from \"../config.ts\";\nimport { resolveCliModel } from \"../core/model-resolver.ts\";\nimport type { ModelRuntime } from \"../core/model-runtime.ts\";\nimport type { Args } from \"./args.ts\";\n\nexport type CredentialPrintKind = \"api_key\" | \"bearer_token\";\n\nconst DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS = 30 * 60_000;\n\nexport interface CredentialPrintCommand {\n\tkind: CredentialPrintKind;\n\targs: string[];\n\tminExpiryMs?: number;\n}\n\nexport class CredentialPrintError extends Error {}\n\nexport function isCredentialPrintHelp(args: string[]): boolean {\n\treturn (\n\t\targs[0] === \"auth\" && (args[1] === undefined || args[1] === \"help\" || args[1] === \"--help\" || args[1] === \"-h\")\n\t);\n}\n\nexport function printCredentialPrintHelp(): void {\n\tconsole.log(`Usage:\n ${APP_NAME} auth print-api-key --model <model> [--provider <provider>]\n ${APP_NAME} auth print-bearer-token --model <model> [--provider <provider>] [--min-expiry <duration>]\n\nPrints the configured credential alone on stdout. Provider inference uses configured credentials; specify --provider to select explicitly. Bearer tokens have a 30-minute minimum expiry by default. --min-expiry accepts ms, s, m, or h (for example, 30m).`);\n}\n\n/** Parse the small, extensible `auth` command surface before normal startup. */\nexport function parseCredentialPrintCommand(args: string[]): CredentialPrintCommand | undefined {\n\tif (args[0] !== \"auth\") return undefined;\n\n\tconst kind = args[1] === \"print-api-key\" ? \"api_key\" : args[1] === \"print-bearer-token\" ? \"bearer_token\" : undefined;\n\tif (!kind) {\n\t\tthrow new CredentialPrintError(\n\t\t\t`Unknown auth command \"${args[1] ?? \"\"}\". Use \"${APP_NAME} auth print-api-key\" or \"${APP_NAME} auth print-bearer-token\".`,\n\t\t);\n\t}\n\n\tconst commandArgs: string[] = [];\n\tlet minExpiryMs: number | undefined;\n\tfor (let index = 2; index < args.length; index++) {\n\t\tif (args[index] !== \"--min-expiry\") {\n\t\t\tcommandArgs.push(args[index]);\n\t\t\tcontinue;\n\t\t}\n\t\tif (kind !== \"bearer_token\") {\n\t\t\tthrow new CredentialPrintError(\"--min-expiry is only supported by print-bearer-token\");\n\t\t}\n\t\tconst value = args[++index];\n\t\tconst match = value ? /^(\\d+)(ms|s|m|h)$/iu.exec(value) : undefined;\n\t\tif (!match) {\n\t\t\tthrow new CredentialPrintError(\"--min-expiry must use a duration such as 30m or 1h\");\n\t\t}\n\t\tconst amount = Number(match[1]);\n\t\tconst unit = match[2];\n\t\tminExpiryMs = amount * (unit === \"ms\" ? 1 : unit === \"s\" ? 1_000 : unit === \"m\" ? 60_000 : 3_600_000);\n\t}\n\n\treturn minExpiryMs === undefined ? { kind, args: commandArgs } : { kind, args: commandArgs, minExpiryMs };\n}\n\nexport function validateCredentialPrintArgs(args: Args): void {\n\tif (!args.model?.trim()) {\n\t\tthrow new CredentialPrintError(\"Credential printing requires --model <model>\");\n\t}\n\tif (args.apiKey !== undefined) {\n\t\tthrow new CredentialPrintError(\"Credential printing reads configured credentials; --api-key is not supported\");\n\t}\n\tif (args.messages.length > 0 || args.fileArgs.length > 0 || args.unknownFlags.size > 0) {\n\t\tthrow new CredentialPrintError(\"Credential printing only accepts --provider and --model\");\n\t}\n}\n\n/**\n * Resolve one request credential for a specific provider/model pair.\n *\n * This intentionally calls ModelRuntime.getAuth(), which refreshes and persists\n * OAuth credentials with less than five minutes remaining through the normal request-auth path.\n */\nexport async function resolveCredentialForPrint(\n\targs: Args,\n\tmodelRuntime: ModelRuntime,\n\tkind: CredentialPrintKind,\n\tminExpiryMs?: number,\n): Promise<string> {\n\tvalidateCredentialPrintArgs(args);\n\n\tconst credentialTypes = new Map<string, CredentialInfo[\"type\"]>(\n\t\t(await modelRuntime.listCredentials()).map((credential) => [credential.providerId, credential.type]),\n\t);\n\tconst models: Model<Api>[] = [];\n\tif (args.provider) {\n\t\tconst resolved = resolveCliModel({ cliProvider: args.provider, cliModel: args.model, modelRuntime });\n\t\tif (resolved.error || !resolved.model) {\n\t\t\tthrow new CredentialPrintError(resolved.error ?? \"Unable to resolve the requested provider/model\");\n\t\t}\n\t\tmodels.push(resolved.model);\n\t} else {\n\t\tfor (const provider of modelRuntime.getProviders()) {\n\t\t\tif (!credentialTypes.has(provider.id)) continue;\n\t\t\tconst resolved = resolveCliModel({ cliProvider: provider.id, cliModel: args.model, modelRuntime });\n\t\t\tif (resolved.model && !resolved.error && !resolved.warning?.includes(\"Using custom model id\")) {\n\t\t\t\tmodels.push(resolved.model);\n\t\t\t}\n\t\t}\n\t\tif (models.length === 0) {\n\t\t\tthrow new CredentialPrintError(`Model \"${args.model}\" not found. Use --list-models to see available models.`);\n\t\t}\n\t}\n\n\tconst credentials: Array<{ providerId: string; value: string }> = [];\n\tfor (const model of models) {\n\t\tconst type = credentialTypes.get(model.provider);\n\t\tif (kind === \"api_key\" && type === \"oauth\") continue;\n\t\tif (kind === \"bearer_token\" && type !== \"oauth\") continue;\n\n\t\tconst auth = await modelRuntime.getAuth(\n\t\t\tmodel,\n\t\t\tkind === \"bearer_token\"\n\t\t\t\t? { minOAuthValidityMs: minExpiryMs ?? DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS }\n\t\t\t\t: undefined,\n\t\t);\n\t\tconst authorization = Object.entries(auth?.auth.headers ?? {}).find(\n\t\t\t([name]) => name.toLowerCase() === \"authorization\",\n\t\t)?.[1];\n\t\tconst bearerToken = typeof authorization === \"string\" ? /^Bearer\\s+(.+)$/iu.exec(authorization)?.[1] : undefined;\n\t\tconst value = kind === \"bearer_token\" ? (auth?.auth.apiKey ?? bearerToken) : auth?.auth.apiKey;\n\t\tif (value) credentials.push({ providerId: model.provider, value });\n\t}\n\n\tif (credentials.length === 1) return credentials[0].value;\n\tif (credentials.length === 0) {\n\t\tconst providerId = models[0]?.provider;\n\t\tconst type = providerId ? credentialTypes.get(providerId) : undefined;\n\t\tif (args.provider && kind === \"api_key\" && type === \"oauth\") {\n\t\t\tthrow new CredentialPrintError(`Provider \"${providerId}\" is configured with OAuth, not an API key`);\n\t\t}\n\t\tif (args.provider && kind === \"bearer_token\" && type !== \"oauth\") {\n\t\t\tthrow new CredentialPrintError(`Provider \"${providerId}\" is not configured with an OAuth bearer token`);\n\t\t}\n\t\tthrow new CredentialPrintError(\n\t\t\t`No usable ${kind === \"api_key\" ? \"API key\" : \"OAuth bearer token\"} is configured`,\n\t\t);\n\t}\n\tthrow new CredentialPrintError(\n\t\t`Model \"${args.model}\" has multiple configured providers (${credentials.map(({ providerId }) => providerId).join(\", \")}). Specify --provider.`,\n\t);\n}\n"]}
|
package/dist/config.d.ts
CHANGED
|
@@ -29,6 +29,13 @@ export declare function getUpdateInstruction(packageName: string): string;
|
|
|
29
29
|
* - For tsx (src/): returns parent directory (the package root)
|
|
30
30
|
*/
|
|
31
31
|
export declare function getPackageDir(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Nearest ancestor of `startDir` (inclusive) that is a real package root.
|
|
34
|
+
*
|
|
35
|
+
* @param startDir - Directory to start the upward walk from.
|
|
36
|
+
* @returns The package root, or `startDir` when no `package.json` exists above it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function findPackageRoot(startDir: string): string;
|
|
32
39
|
/**
|
|
33
40
|
* Get path to built-in themes directory (shipped with package)
|
|
34
41
|
* - For Bun binary: theme/ next to executable
|
|
@@ -100,6 +107,8 @@ export declare function getBinDir(): string;
|
|
|
100
107
|
export declare function getPromptsDir(): string;
|
|
101
108
|
/** Get path to shipped prompts directory (bundled with the package). */
|
|
102
109
|
export declare function getShippedPromptsDir(): string;
|
|
110
|
+
/** Get path to shipped skills directory (bundled with the package). */
|
|
111
|
+
export declare function getShippedSkillsDir(): string;
|
|
103
112
|
/** Get path to sessions directory */
|
|
104
113
|
export declare function getSessionsDir(): string;
|
|
105
114
|
/** Get path to debug log file */
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,eAAO,MAAM,WAAW,SACqF,CAAC;AAE9G,gEAAgE;AAChE,eAAO,MAAM,YAAY,SAAyB,CAAC;AAMnD,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC;AAEvF,UAAU,qBAAqB;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAkB,SAAQ,qBAAqB;IAC/D,KAAK,CAAC,EAAE,qBAAqB,EAAE,CAAC;CAChC;AAED,MAAM,MAAM,uBAAuB,GAAG,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAgC7F,wBAAgB,mBAAmB,IAAI,aAAa,CAqBnD;AA6ND,wBAAgB,oBAAoB,CACnC,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,EAAE,EACrB,mBAAmB,GAAE,uBAAqC,GACxD,iBAAiB,GAAG,SAAS,CAO/B;AAED,wBAAgB,mCAAmC,CAClD,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,EAAE,EACrB,mBAAmB,GAAE,uBAAqC,GACxD,MAAM,CAcR;AAED,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAOhE;AAMD;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,eAAO,MAAM,WAAW,SACqF,CAAC;AAE9G,gEAAgE;AAChE,eAAO,MAAM,YAAY,SAAyB,CAAC;AAMnD,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,KA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BAAgB,SAAS,IAAI,MAAM,CAElC;AAED,6CAA6C;AAC7C,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,wEAAwE;AACxE,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED,uEAAuE;AACvE,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED,qCAAqC;AACrC,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,iCAAiC;AACjC,wBAAgB,eAAe,IAAI,MAAM,CAExC"}
|
package/dist/config.js
CHANGED
|
@@ -262,7 +262,7 @@ export function getSelfUpdateUnavailableInstruction(packageName, npmCommand, upd
|
|
|
262
262
|
const method = detectInstallMethod();
|
|
263
263
|
const target = normalizeSelfUpdatePackageTarget(updatePackageTarget);
|
|
264
264
|
if (method === "bun-binary") {
|
|
265
|
-
return `Download from: https://github.com/
|
|
265
|
+
return `Download from: https://github.com/draht-dev/draht/releases/latest`;
|
|
266
266
|
}
|
|
267
267
|
const command = getSelfUpdateCommandForMethod(method, packageName, target, npmCommand);
|
|
268
268
|
if (command) {
|
|
@@ -301,15 +301,38 @@ export function getPackageDir() {
|
|
|
301
301
|
return dirname(process.execPath);
|
|
302
302
|
}
|
|
303
303
|
// Node.js: walk up from __dirname until we find package.json
|
|
304
|
-
|
|
304
|
+
return findPackageRoot(__dirname);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Is `dir` the emitted `dist/` bundle rather than the package root?
|
|
308
|
+
*
|
|
309
|
+
* `build:binary` copies `package.json` into `dist/` because the compiled binary
|
|
310
|
+
* lives there and resolves its assets relative to itself. That copy is not a
|
|
311
|
+
* package root: the Node entrypoint `dist/cli.js` sits beside it, so a naive
|
|
312
|
+
* upward walk stops one level too low and every asset path gains a phantom
|
|
313
|
+
* `dist/` segment (`dist/dist/modes/interactive/theme/dark.json`). Recognising
|
|
314
|
+
* the copy is what lets `node dist/cli.js` and the compiled `dist/draht` both
|
|
315
|
+
* work from one build tree instead of one invalidating the other.
|
|
316
|
+
*/
|
|
317
|
+
function isEmittedBundleDir(dir) {
|
|
318
|
+
return basename(dir) === "dist" && existsSync(join(dirname(dir), "package.json"));
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Nearest ancestor of `startDir` (inclusive) that is a real package root.
|
|
322
|
+
*
|
|
323
|
+
* @param startDir - Directory to start the upward walk from.
|
|
324
|
+
* @returns The package root, or `startDir` when no `package.json` exists above it.
|
|
325
|
+
*/
|
|
326
|
+
export function findPackageRoot(startDir) {
|
|
327
|
+
let dir = startDir;
|
|
305
328
|
while (dir !== dirname(dir)) {
|
|
306
|
-
if (existsSync(join(dir, "package.json"))) {
|
|
329
|
+
if (existsSync(join(dir, "package.json")) && !isEmittedBundleDir(dir)) {
|
|
307
330
|
return dir;
|
|
308
331
|
}
|
|
309
332
|
dir = dirname(dir);
|
|
310
333
|
}
|
|
311
334
|
// Fallback (shouldn't happen)
|
|
312
|
-
return
|
|
335
|
+
return startDir;
|
|
313
336
|
}
|
|
314
337
|
/**
|
|
315
338
|
* Get path to built-in themes directory (shipped with package)
|
|
@@ -466,6 +489,10 @@ export function getPromptsDir() {
|
|
|
466
489
|
export function getShippedPromptsDir() {
|
|
467
490
|
return join(getPackageDir(), "prompts");
|
|
468
491
|
}
|
|
492
|
+
/** Get path to shipped skills directory (bundled with the package). */
|
|
493
|
+
export function getShippedSkillsDir() {
|
|
494
|
+
return join(getPackageDir(), "skills");
|
|
495
|
+
}
|
|
469
496
|
/** Get path to sessions directory */
|
|
470
497
|
export function getSessionsDir() {
|
|
471
498
|
return join(getAgentDir(), "sessions");
|