apex-code 0.0.1-alpha.8 → 0.0.4
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 +231 -0
- package/README.md +9 -8
- package/dist/cli/args.d.ts +26 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +72 -10
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +2 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/mcp-command.d.ts +9 -0
- package/dist/cli/mcp-command.d.ts.map +1 -0
- package/dist/cli/mcp-command.js +53 -0
- package/dist/cli/mcp-command.js.map +1 -0
- package/dist/cli/project-trust.d.ts.map +1 -1
- package/dist/cli/project-trust.js +3 -1
- package/dist/cli/project-trust.js.map +1 -1
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js +2 -1
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +94 -5
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +3 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +45 -18
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +3 -0
- 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 +183 -15
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +728 -117
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +6 -7
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +7 -0
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/checkpoints/git-checkpoints.d.ts +39 -0
- package/dist/core/checkpoints/git-checkpoints.d.ts.map +1 -0
- package/dist/core/checkpoints/git-checkpoints.js +251 -0
- package/dist/core/checkpoints/git-checkpoints.js.map +1 -0
- package/dist/core/checkpoints/session-checkpoints.d.ts +23 -0
- package/dist/core/checkpoints/session-checkpoints.d.ts.map +1 -0
- package/dist/core/checkpoints/session-checkpoints.js +36 -0
- package/dist/core/checkpoints/session-checkpoints.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +7 -3
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +9 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +59 -36
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/defaults.d.ts +1 -0
- package/dist/core/defaults.d.ts.map +1 -1
- package/dist/core/defaults.js +9 -0
- package/dist/core/defaults.js.map +1 -1
- package/dist/core/delegation/runtime.d.ts +6 -5
- package/dist/core/delegation/runtime.d.ts.map +1 -1
- package/dist/core/delegation/runtime.js +4 -3
- package/dist/core/delegation/runtime.js.map +1 -1
- package/dist/core/durable-state/sqlite.d.ts.map +1 -1
- package/dist/core/durable-state/sqlite.js +26 -2
- package/dist/core/durable-state/sqlite.js.map +1 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +5 -2
- package/dist/core/exec.js.map +1 -1
- package/dist/core/extensions/index.d.ts +2 -2
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +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 +123 -50
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +5 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +45 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/source-runtime.d.ts +14 -0
- package/dist/core/extensions/source-runtime.d.ts.map +1 -0
- package/dist/core/extensions/source-runtime.js +56 -0
- package/dist/core/extensions/source-runtime.js.map +1 -0
- package/dist/core/extensions/types.d.ts +60 -11
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +3 -0
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +1 -1
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +1 -1
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/formatter-lifecycle.d.ts +69 -0
- package/dist/core/formatter-lifecycle.d.ts.map +1 -0
- package/dist/core/formatter-lifecycle.js +360 -0
- package/dist/core/formatter-lifecycle.js.map +1 -0
- package/dist/core/hooks/command-handler.d.ts +19 -0
- package/dist/core/hooks/command-handler.d.ts.map +1 -0
- package/dist/core/hooks/command-handler.js +112 -0
- package/dist/core/hooks/command-handler.js.map +1 -0
- package/dist/core/hooks/http-handler.d.ts +10 -0
- package/dist/core/hooks/http-handler.d.ts.map +1 -0
- package/dist/core/hooks/http-handler.js +36 -0
- package/dist/core/hooks/http-handler.js.map +1 -0
- package/dist/core/hooks/loader.d.ts +29 -0
- package/dist/core/hooks/loader.d.ts.map +1 -0
- package/dist/core/hooks/loader.js +139 -0
- package/dist/core/hooks/loader.js.map +1 -0
- package/dist/core/hooks/runtime.d.ts +13 -0
- package/dist/core/hooks/runtime.d.ts.map +1 -0
- package/dist/core/hooks/runtime.js +63 -0
- package/dist/core/hooks/runtime.js.map +1 -0
- package/dist/core/hooks/types.d.ts +83 -0
- package/dist/core/hooks/types.d.ts.map +1 -0
- package/dist/core/hooks/types.js +24 -0
- package/dist/core/hooks/types.js.map +1 -0
- package/dist/core/keybindings.d.ts +20 -19
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +26 -5
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/mcp/config.d.ts +16 -0
- package/dist/core/mcp/config.d.ts.map +1 -0
- package/dist/core/mcp/config.js +166 -0
- package/dist/core/mcp/config.js.map +1 -0
- package/dist/core/mcp/connector.d.ts +35 -0
- package/dist/core/mcp/connector.d.ts.map +1 -0
- package/dist/core/mcp/connector.js +105 -0
- package/dist/core/mcp/connector.js.map +1 -0
- package/dist/core/mcp/contract.d.ts +19 -0
- package/dist/core/mcp/contract.d.ts.map +1 -0
- package/dist/core/mcp/contract.js +89 -0
- package/dist/core/mcp/contract.js.map +1 -0
- package/dist/core/mcp/mcp-tool.d.ts +32 -0
- package/dist/core/mcp/mcp-tool.d.ts.map +1 -0
- package/dist/core/mcp/mcp-tool.js +171 -0
- package/dist/core/mcp/mcp-tool.js.map +1 -0
- package/dist/core/mcp/metadata-cache.d.ts +29 -0
- package/dist/core/mcp/metadata-cache.d.ts.map +1 -0
- package/dist/core/mcp/metadata-cache.js +99 -0
- package/dist/core/mcp/metadata-cache.js.map +1 -0
- package/dist/core/mcp/oauth/authorize.d.ts +21 -0
- package/dist/core/mcp/oauth/authorize.d.ts.map +1 -0
- package/dist/core/mcp/oauth/authorize.js +32 -0
- package/dist/core/mcp/oauth/authorize.js.map +1 -0
- package/dist/core/mcp/oauth/discover.d.ts +27 -0
- package/dist/core/mcp/oauth/discover.d.ts.map +1 -0
- package/dist/core/mcp/oauth/discover.js +116 -0
- package/dist/core/mcp/oauth/discover.js.map +1 -0
- package/dist/core/mcp/oauth/flow.d.ts +31 -0
- package/dist/core/mcp/oauth/flow.d.ts.map +1 -0
- package/dist/core/mcp/oauth/flow.js +175 -0
- package/dist/core/mcp/oauth/flow.js.map +1 -0
- package/dist/core/mcp/oauth/mcp-token.d.ts +51 -0
- package/dist/core/mcp/oauth/mcp-token.d.ts.map +1 -0
- package/dist/core/mcp/oauth/mcp-token.js +129 -0
- package/dist/core/mcp/oauth/mcp-token.js.map +1 -0
- package/dist/core/mcp/oauth/pkce.d.ts +12 -0
- package/dist/core/mcp/oauth/pkce.d.ts.map +1 -0
- package/dist/core/mcp/oauth/pkce.js +11 -0
- package/dist/core/mcp/oauth/pkce.js.map +1 -0
- package/dist/core/mcp/oauth/register.d.ts +16 -0
- package/dist/core/mcp/oauth/register.d.ts.map +1 -0
- package/dist/core/mcp/oauth/register.js +42 -0
- package/dist/core/mcp/oauth/register.js.map +1 -0
- package/dist/core/mcp/oauth/token-client.d.ts +33 -0
- package/dist/core/mcp/oauth/token-client.d.ts.map +1 -0
- package/dist/core/mcp/oauth/token-client.js +65 -0
- package/dist/core/mcp/oauth/token-client.js.map +1 -0
- package/dist/core/mcp/runtime.d.ts +20 -0
- package/dist/core/mcp/runtime.d.ts.map +1 -0
- package/dist/core/mcp/runtime.js +37 -0
- package/dist/core/mcp/runtime.js.map +1 -0
- package/dist/core/mcp/schema.d.ts +22 -0
- package/dist/core/mcp/schema.d.ts.map +1 -0
- package/dist/core/mcp/schema.js +20 -0
- package/dist/core/mcp/schema.js.map +1 -0
- package/dist/core/mcp/server-manager.d.ts +43 -0
- package/dist/core/mcp/server-manager.d.ts.map +1 -0
- package/dist/core/mcp/server-manager.js +142 -0
- package/dist/core/mcp/server-manager.js.map +1 -0
- package/dist/core/mcp/types.d.ts +100 -0
- package/dist/core/mcp/types.d.ts.map +1 -0
- package/dist/core/mcp/types.js +8 -0
- package/dist/core/mcp/types.js.map +1 -0
- package/dist/core/model-config.d.ts +5 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +3 -1
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -0
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +14 -8
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +2 -1
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +22 -14
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/permissions/gate.d.ts.map +1 -1
- package/dist/core/permissions/gate.js +45 -4
- package/dist/core/permissions/gate.js.map +1 -1
- package/dist/core/permissions/operations.d.ts +20 -0
- package/dist/core/permissions/operations.d.ts.map +1 -0
- package/dist/core/permissions/operations.js +9 -0
- package/dist/core/permissions/operations.js.map +1 -0
- package/dist/core/permissions/policy-command.d.ts +42 -0
- package/dist/core/permissions/policy-command.d.ts.map +1 -0
- package/dist/core/permissions/policy-command.js +44 -0
- package/dist/core/permissions/policy-command.js.map +1 -0
- package/dist/core/permissions/responder.d.ts +49 -2
- package/dist/core/permissions/responder.d.ts.map +1 -1
- package/dist/core/permissions/responder.js +20 -8
- package/dist/core/permissions/responder.js.map +1 -1
- package/dist/core/permissions/rules.d.ts.map +1 -1
- package/dist/core/permissions/rules.js +11 -1
- package/dist/core/permissions/rules.js.map +1 -1
- package/dist/core/permissions/store.d.ts +18 -0
- package/dist/core/permissions/store.d.ts.map +1 -1
- package/dist/core/permissions/store.js +89 -8
- package/dist/core/permissions/store.js.map +1 -1
- package/dist/core/pi-manifest.d.ts.map +1 -1
- package/dist/core/pi-manifest.js +2 -1
- package/dist/core/pi-manifest.js.map +1 -1
- package/dist/core/policy-executor.d.ts +47 -0
- package/dist/core/policy-executor.d.ts.map +1 -0
- package/dist/core/policy-executor.js +228 -0
- package/dist/core/policy-executor.js.map +1 -0
- package/dist/core/policy-loader.d.ts +72 -0
- package/dist/core/policy-loader.d.ts.map +1 -0
- package/dist/core/policy-loader.js +195 -0
- package/dist/core/policy-loader.js.map +1 -0
- package/dist/core/project-trust.d.ts +1 -1
- package/dist/core/project-trust.d.ts.map +1 -1
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +2 -1
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +3 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sandbox/bwrap-arguments.d.ts +41 -0
- package/dist/core/sandbox/bwrap-arguments.d.ts.map +1 -0
- package/dist/core/sandbox/bwrap-arguments.js +136 -0
- package/dist/core/sandbox/bwrap-arguments.js.map +1 -0
- package/dist/core/sandbox/child-entry.d.ts.map +1 -1
- package/dist/core/sandbox/child-entry.js +3 -1
- package/dist/core/sandbox/child-entry.js.map +1 -1
- package/dist/core/sandbox/cli-launch.d.ts +84 -4
- package/dist/core/sandbox/cli-launch.d.ts.map +1 -1
- package/dist/core/sandbox/cli-launch.js +115 -16
- package/dist/core/sandbox/cli-launch.js.map +1 -1
- package/dist/core/sandbox/cli-supervisor.d.ts +2 -0
- package/dist/core/sandbox/cli-supervisor.d.ts.map +1 -1
- package/dist/core/sandbox/cli-supervisor.js +50 -2
- package/dist/core/sandbox/cli-supervisor.js.map +1 -1
- package/dist/core/sandbox/full-access.d.ts +28 -0
- package/dist/core/sandbox/full-access.d.ts.map +1 -0
- package/dist/core/sandbox/full-access.js +63 -0
- package/dist/core/sandbox/full-access.js.map +1 -0
- package/dist/core/sandbox/git-identity.d.ts +57 -0
- package/dist/core/sandbox/git-identity.d.ts.map +1 -0
- package/dist/core/sandbox/git-identity.js +78 -0
- package/dist/core/sandbox/git-identity.js.map +1 -0
- package/dist/core/sandbox/host-approval.d.ts +42 -0
- package/dist/core/sandbox/host-approval.d.ts.map +1 -0
- package/dist/core/sandbox/host-approval.js +99 -0
- package/dist/core/sandbox/host-approval.js.map +1 -0
- package/dist/core/sandbox/linux-backend.d.ts +14 -0
- package/dist/core/sandbox/linux-backend.d.ts.map +1 -1
- package/dist/core/sandbox/linux-backend.js +158 -80
- package/dist/core/sandbox/linux-backend.js.map +1 -1
- package/dist/core/sandbox/macos-backend.d.ts +5 -0
- package/dist/core/sandbox/macos-backend.d.ts.map +1 -1
- package/dist/core/sandbox/macos-backend.js +164 -5
- package/dist/core/sandbox/macos-backend.js.map +1 -1
- package/dist/core/sandbox/network-proxy.d.ts +19 -0
- package/dist/core/sandbox/network-proxy.d.ts.map +1 -1
- package/dist/core/sandbox/network-proxy.js +93 -19
- package/dist/core/sandbox/network-proxy.js.map +1 -1
- package/dist/core/sandbox/policy.d.ts +8 -0
- package/dist/core/sandbox/policy.d.ts.map +1 -1
- package/dist/core/sandbox/policy.js +29 -12
- package/dist/core/sandbox/policy.js.map +1 -1
- package/dist/core/sandbox/profiles.d.ts +25 -0
- package/dist/core/sandbox/profiles.d.ts.map +1 -0
- package/dist/core/sandbox/profiles.js +23 -0
- package/dist/core/sandbox/profiles.js.map +1 -0
- package/dist/core/sandbox/rpc/command-client.d.ts +28 -0
- package/dist/core/sandbox/rpc/command-client.d.ts.map +1 -0
- package/dist/core/sandbox/rpc/command-client.js +86 -0
- package/dist/core/sandbox/rpc/command-client.js.map +1 -0
- package/dist/core/sandbox/rpc/command-proxy.d.ts +48 -0
- package/dist/core/sandbox/rpc/command-proxy.d.ts.map +1 -0
- package/dist/core/sandbox/rpc/command-proxy.js +120 -0
- package/dist/core/sandbox/rpc/command-proxy.js.map +1 -0
- package/dist/core/sandbox/rpc/credential-proxy.d.ts.map +1 -1
- package/dist/core/sandbox/rpc/credential-proxy.js +2 -96
- package/dist/core/sandbox/rpc/credential-proxy.js.map +1 -1
- package/dist/core/sandbox/rpc/framing.d.ts +35 -0
- package/dist/core/sandbox/rpc/framing.d.ts.map +1 -0
- package/dist/core/sandbox/rpc/framing.js +114 -0
- package/dist/core/sandbox/rpc/framing.js.map +1 -0
- package/dist/core/sandbox/rpc/git-credential-helper.d.ts +47 -0
- package/dist/core/sandbox/rpc/git-credential-helper.d.ts.map +1 -0
- package/dist/core/sandbox/rpc/git-credential-helper.js +222 -0
- package/dist/core/sandbox/rpc/git-credential-helper.js.map +1 -0
- package/dist/core/sandbox/rpc/git-credential-proxy.d.ts +66 -0
- package/dist/core/sandbox/rpc/git-credential-proxy.d.ts.map +1 -0
- package/dist/core/sandbox/rpc/git-credential-proxy.js +209 -0
- package/dist/core/sandbox/rpc/git-credential-proxy.js.map +1 -0
- package/dist/core/sandbox/supervisor-temp.d.ts +18 -0
- package/dist/core/sandbox/supervisor-temp.d.ts.map +1 -0
- package/dist/core/sandbox/supervisor-temp.js +21 -0
- package/dist/core/sandbox/supervisor-temp.js.map +1 -0
- package/dist/core/sandbox/supervisor.d.ts +12 -1
- package/dist/core/sandbox/supervisor.d.ts.map +1 -1
- package/dist/core/sandbox/supervisor.js +15 -1
- package/dist/core/sandbox/supervisor.js.map +1 -1
- package/dist/core/sandbox/terminal-handoff.d.ts +68 -0
- package/dist/core/sandbox/terminal-handoff.d.ts.map +1 -0
- package/dist/core/sandbox/terminal-handoff.js +221 -0
- package/dist/core/sandbox/terminal-handoff.js.map +1 -0
- package/dist/core/sandbox/terminal-size.d.ts +13 -0
- package/dist/core/sandbox/terminal-size.d.ts.map +1 -1
- package/dist/core/sandbox/terminal-size.js +23 -2
- package/dist/core/sandbox/terminal-size.js.map +1 -1
- package/dist/core/sdk.d.ts +24 -2
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +63 -4
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-export.d.ts +4 -0
- package/dist/core/session-export.d.ts.map +1 -0
- package/dist/core/session-export.js +32 -0
- package/dist/core/session-export.js.map +1 -0
- package/dist/core/session-manager.d.ts +13 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +34 -6
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-diagnostics.d.ts +9 -0
- package/dist/core/settings-diagnostics.d.ts.map +1 -0
- package/dist/core/settings-diagnostics.js +21 -0
- package/dist/core/settings-diagnostics.js.map +1 -0
- package/dist/core/settings-manager.d.ts +172 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +160 -11
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +51 -33
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +4 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +8 -2
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/background-shell.d.ts +39 -0
- package/dist/core/tools/background-shell.d.ts.map +1 -0
- package/dist/core/tools/background-shell.js +81 -0
- package/dist/core/tools/background-shell.js.map +1 -0
- package/dist/core/tools/bash-command-segments.d.ts.map +1 -1
- package/dist/core/tools/bash-command-segments.js +2 -0
- package/dist/core/tools/bash-command-segments.js.map +1 -1
- package/dist/core/tools/bash.d.ts +44 -16
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +264 -32
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/contract-snapshot.d.ts +58 -0
- package/dist/core/tools/contract-snapshot.d.ts.map +1 -0
- package/dist/core/tools/contract-snapshot.js +51 -0
- package/dist/core/tools/contract-snapshot.js.map +1 -0
- package/dist/core/tools/contract.d.ts +53 -5
- package/dist/core/tools/contract.d.ts.map +1 -1
- package/dist/core/tools/contract.js +22 -2
- package/dist/core/tools/contract.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +6 -4
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +21 -11
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +48 -5
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +217 -8
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +8 -0
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +72 -10
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +5 -2
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +5 -2
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +14 -2
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +12 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +5 -2
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/lsp.d.ts +19 -1
- package/dist/core/tools/lsp.d.ts.map +1 -1
- package/dist/core/tools/lsp.js +163 -10
- package/dist/core/tools/lsp.js.map +1 -1
- package/dist/core/tools/path-permission.d.ts +3 -0
- package/dist/core/tools/path-permission.d.ts.map +1 -1
- package/dist/core/tools/path-permission.js +16 -4
- package/dist/core/tools/path-permission.js.map +1 -1
- package/dist/core/tools/path-utils.d.ts +27 -2
- package/dist/core/tools/path-utils.d.ts.map +1 -1
- package/dist/core/tools/path-utils.js +221 -4
- package/dist/core/tools/path-utils.js.map +1 -1
- package/dist/core/tools/powershell.d.ts +16 -0
- package/dist/core/tools/powershell.d.ts.map +1 -0
- package/dist/core/tools/powershell.js +39 -0
- package/dist/core/tools/powershell.js.map +1 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +20 -11
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/test.d.ts +54 -9
- package/dist/core/tools/test.d.ts.map +1 -1
- package/dist/core/tools/test.js +239 -19
- package/dist/core/tools/test.js.map +1 -1
- package/dist/core/tools/write.d.ts +7 -0
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +64 -9
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +2 -1
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/verification-lifecycle.d.ts +77 -0
- package/dist/core/verification-lifecycle.d.ts.map +1 -0
- package/dist/core/verification-lifecycle.js +146 -0
- package/dist/core/verification-lifecycle.js.map +1 -0
- package/dist/core/workspace/artifacts.d.ts +45 -0
- package/dist/core/workspace/artifacts.d.ts.map +1 -0
- package/dist/core/workspace/artifacts.js +165 -0
- package/dist/core/workspace/artifacts.js.map +1 -0
- package/dist/core/workspace/comparison.d.ts +27 -0
- package/dist/core/workspace/comparison.d.ts.map +1 -0
- package/dist/core/workspace/comparison.js +94 -0
- package/dist/core/workspace/comparison.js.map +1 -0
- package/dist/core/workspace/git-observer.d.ts +48 -0
- package/dist/core/workspace/git-observer.d.ts.map +1 -0
- package/dist/core/workspace/git-observer.js +346 -0
- package/dist/core/workspace/git-observer.js.map +1 -0
- package/dist/core/workspace/projection.d.ts +3 -0
- package/dist/core/workspace/projection.d.ts.map +1 -0
- package/dist/core/workspace/projection.js +56 -0
- package/dist/core/workspace/projection.js.map +1 -0
- package/dist/core/workspace/state.d.ts +133 -0
- package/dist/core/workspace/state.d.ts.map +1 -0
- package/dist/core/workspace/state.js +96 -0
- package/dist/core/workspace/state.js.map +1 -0
- package/dist/extensions/llama/client.d.ts +6 -0
- package/dist/extensions/llama/client.d.ts.map +1 -1
- package/dist/extensions/llama/client.js +7 -0
- package/dist/extensions/llama/client.js.map +1 -1
- package/dist/extensions/llama/index.d.ts.map +1 -1
- package/dist/extensions/llama/index.js +2 -0
- package/dist/extensions/llama/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts +3 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +29 -4
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +6 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +58 -23
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +4 -3
- package/dist/migrations.js.map +1 -1
- package/dist/modes/acp/server.d.ts +55 -0
- package/dist/modes/acp/server.d.ts.map +1 -0
- package/dist/modes/acp/server.js +244 -0
- package/dist/modes/acp/server.js.map +1 -0
- package/dist/modes/acp/translate.d.ts +37 -0
- package/dist/modes/acp/translate.d.ts.map +1 -0
- package/dist/modes/acp/translate.js +50 -0
- package/dist/modes/acp/translate.js.map +1 -0
- package/dist/modes/index.d.ts +1 -0
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js +1 -0
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +29 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +182 -23
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +7 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +20 -0
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +9 -4
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +20 -9
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +7 -1
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +7 -3
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +19 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +70 -10
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +10 -3
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +56 -14
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/permission-preview.d.ts +15 -0
- package/dist/modes/interactive/components/permission-preview.d.ts.map +1 -0
- package/dist/modes/interactive/components/permission-preview.js +33 -0
- package/dist/modes/interactive/components/permission-preview.js.map +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +2 -2
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +9 -2
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +128 -56
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.d.ts +72 -0
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-submenu.js +165 -0
- package/dist/modes/interactive/components/settings-submenu.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +15 -3
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +74 -17
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +23 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +64 -10
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +2 -1
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +45 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +395 -43
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +12 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +20 -9
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/json-event.d.ts +16 -13
- package/dist/modes/json-event.d.ts.map +1 -1
- package/dist/modes/json-event.js +20 -6
- package/dist/modes/json-event.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +27 -12
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +7 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +7 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +3 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +12 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts +1 -0
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +196 -10
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +2 -1
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/management-http.d.ts +5 -3
- package/dist/utils/management-http.d.ts.map +1 -1
- package/dist/utils/management-http.js +14 -10
- package/dist/utils/management-http.js.map +1 -1
- package/dist/utils/shell.d.ts +3 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +23 -9
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts +1 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +60 -1
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/text.d.ts +8 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +9 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +6 -4
- package/dist/utils/version-check.js.map +1 -1
- package/docs/compaction.md +19 -0
- package/docs/custom-provider.md +12 -9
- package/docs/environment-variables.md +1 -1
- package/docs/extensions.md +35 -7
- package/docs/json.md +7 -2
- package/docs/keybindings.md +9 -9
- package/docs/llama-cpp.md +2 -0
- package/docs/models.md +8 -2
- package/docs/packages.md +2 -2
- package/docs/quickstart.md +1 -1
- package/docs/rpc.md +32 -3
- package/docs/sdk.md +32 -2
- package/docs/settings.md +23 -7
- package/docs/skills.md +4 -3
- package/docs/terminal-setup.md +23 -7
- package/docs/usage.md +10 -5
- package/docs/windows.md +24 -2
- package/examples/extensions/border-status-editor.ts +1 -1
- package/examples/extensions/built-in-tool-renderer.ts +8 -4
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/git-checkpoint.ts +24 -36
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/minimal-mode.ts +2 -2
- package/examples/extensions/notify.ts +3 -1
- package/examples/extensions/permission-gate.ts +1 -1
- package/examples/extensions/plan-mode/index.ts +1 -1
- package/examples/extensions/rpc-demo.ts +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/subagent/README.md +1 -1
- package/examples/extensions/subagent/index.ts +6 -1
- package/examples/extensions/titlebar-spinner.ts +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/rpc-extension-ui.ts +1 -1
- package/examples/sdk/06-extensions.ts +1 -1
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +439 -405
- package/package.json +17 -17
- package/dist/server/create-harness.d.ts +0 -26
- package/dist/server/create-harness.d.ts.map +0 -1
- package/dist/server/create-harness.js +0 -107
- package/dist/server/create-harness.js.map +0 -1
package/dist/core/tools/bash.js
CHANGED
|
@@ -11,7 +11,10 @@ import { waitForChildProcess } from "../../utils/child-process.js";
|
|
|
11
11
|
import { getShellConfig, getShellEnv, killProcessTree, trackDetachedChildPid, untrackDetachedChildPid, } from "../../utils/shell.js";
|
|
12
12
|
import { setApexEnvironment } from "../environment.js";
|
|
13
13
|
import { getExperimentalToolSampling } from "../experimental.js";
|
|
14
|
+
import { escalationRootFor, extractRefusedPath, looksLikeSandboxRefusal, requestCommandEscalation, } from "../sandbox/rpc/command-client.js";
|
|
15
|
+
import { createBackgroundShellRegistry } from "./background-shell.js";
|
|
14
16
|
import { classifyBashCommand } from "./bash-command-segments.js";
|
|
17
|
+
import { toolUnion } from "./contract.js";
|
|
15
18
|
import { OutputAccumulator } from "./output-accumulator.js";
|
|
16
19
|
import { getTextOutput, invalidArgText, str } from "./render-utils.js";
|
|
17
20
|
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
@@ -30,10 +33,26 @@ function resolveTimeoutMs(timeout) {
|
|
|
30
33
|
}
|
|
31
34
|
return timeoutMs;
|
|
32
35
|
}
|
|
33
|
-
const
|
|
34
|
-
command: Type.String({ description: "
|
|
36
|
+
const bashSchemaProperties = {
|
|
37
|
+
command: Type.String({ description: "Shell command to execute" }),
|
|
35
38
|
timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional, no default timeout)" })),
|
|
36
|
-
|
|
39
|
+
background: Type.Optional(Type.Boolean({
|
|
40
|
+
description: "Run in the background and return a handle immediately. Retrieve with { handle }; kill with { handle, kill: true }.",
|
|
41
|
+
})),
|
|
42
|
+
handle: Type.String({
|
|
43
|
+
description: "Handle from a background launch. Supply it alone to retrieve output and status; add kill: true to terminate.",
|
|
44
|
+
}),
|
|
45
|
+
kill: Type.Literal(true, { description: "Set to true with a background handle to terminate its command." }),
|
|
46
|
+
};
|
|
47
|
+
const bashSchema = toolUnion([
|
|
48
|
+
Type.Object({
|
|
49
|
+
command: Type.String(),
|
|
50
|
+
timeout: Type.Optional(Type.Number()),
|
|
51
|
+
background: Type.Optional(Type.Boolean()),
|
|
52
|
+
}),
|
|
53
|
+
Type.Object({ handle: Type.String() }),
|
|
54
|
+
Type.Object({ handle: Type.String(), kill: Type.Literal(true) }),
|
|
55
|
+
], bashSchemaProperties);
|
|
37
56
|
export const bashToolSystemPromptContribution = {
|
|
38
57
|
snippet: "Execute bash commands (ls, grep, find, etc.)",
|
|
39
58
|
guidelines: ["You can inspect PI_* environment variables for current model and session details."],
|
|
@@ -48,9 +67,13 @@ function normalizeSegment(text) {
|
|
|
48
67
|
* matches `git commit` and `git commit -m x`, but not `git commitment` (word
|
|
49
68
|
* boundary enforced) and not an unrelated segment in the same chained command.
|
|
50
69
|
*/
|
|
70
|
+
function hasGrammarSensitiveStructure(value) {
|
|
71
|
+
return /["'\\\t\n#]/.test(value);
|
|
72
|
+
}
|
|
51
73
|
function segmentMatchesRule(segment, ruleContent) {
|
|
52
|
-
const
|
|
53
|
-
const
|
|
74
|
+
const sensitive = hasGrammarSensitiveStructure(segment) || hasGrammarSensitiveStructure(ruleContent);
|
|
75
|
+
const normalizedSegment = sensitive ? segment : normalizeSegment(segment);
|
|
76
|
+
const normalizedRule = sensitive ? ruleContent : normalizeSegment(ruleContent);
|
|
54
77
|
if (normalizedRule.endsWith(":*")) {
|
|
55
78
|
const prefix = normalizedRule.slice(0, -2).trim();
|
|
56
79
|
if (!prefix)
|
|
@@ -71,45 +94,78 @@ function segmentMatchesRule(segment, ruleContent) {
|
|
|
71
94
|
* one would either over-authorize (if loose) or be indistinguishable from an exact
|
|
72
95
|
* match (if not) — `null` correctly forces `ask` for "always allow this" on a chain.
|
|
73
96
|
*/
|
|
97
|
+
/**
|
|
98
|
+
* Reserved rule content for retrieve/kill calls on background handles. These
|
|
99
|
+
* perform no new execution -- the command they operate on was already gated at
|
|
100
|
+
* launch -- so `defaultBehaviorFor` allows them when no rule matches, while a
|
|
101
|
+
* `Bash(background-handle)` rule (allow *or* deny) still governs them
|
|
102
|
+
* explicitly.
|
|
103
|
+
*/
|
|
104
|
+
const BACKGROUND_HANDLE_RULE = "background-handle";
|
|
74
105
|
export function createBashPermissionSpec() {
|
|
75
106
|
return {
|
|
76
107
|
defaultBehavior: "ask",
|
|
108
|
+
defaultBehaviorFor(params) {
|
|
109
|
+
return "command" in params ? undefined : "allow";
|
|
110
|
+
},
|
|
77
111
|
matches(ruleContent, params) {
|
|
112
|
+
if (!("command" in params))
|
|
113
|
+
return ruleContent === BACKGROUND_HANDLE_RULE;
|
|
78
114
|
const classification = classifyBashCommand(params.command);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
115
|
+
return (classification.type === "segments" &&
|
|
116
|
+
classification.segments.every((segment) => segmentMatchesRule(segment, ruleContent)));
|
|
117
|
+
},
|
|
118
|
+
matchesDeny(ruleContent, params) {
|
|
119
|
+
if (!("command" in params))
|
|
120
|
+
return ruleContent === BACKGROUND_HANDLE_RULE;
|
|
121
|
+
const classification = classifyBashCommand(params.command);
|
|
122
|
+
return (classification.type === "segments" &&
|
|
123
|
+
classification.segments.some((segment) => segmentMatchesRule(segment, ruleContent)));
|
|
124
|
+
},
|
|
125
|
+
isUnknown(params) {
|
|
126
|
+
return "command" in params && classifyBashCommand(params.command).type !== "segments";
|
|
82
127
|
},
|
|
83
128
|
describe(ruleContent) {
|
|
129
|
+
if (ruleContent === BACKGROUND_HANDLE_RULE) {
|
|
130
|
+
return "Retrieve or kill background shell commands";
|
|
131
|
+
}
|
|
84
132
|
return `Run bash commands matching "${ruleContent}"`;
|
|
85
133
|
},
|
|
134
|
+
previewCall(params) {
|
|
135
|
+
// The command string is the entire effect being authorized. There is
|
|
136
|
+
// nothing to read and nothing to summarise: showing it exactly, including
|
|
137
|
+
// whitespace the rule grammar treats as significant, is the preview.
|
|
138
|
+
if (!("command" in params)) {
|
|
139
|
+
return { kind: "summary", lines: ["Retrieve or kill a background shell command"] };
|
|
140
|
+
}
|
|
141
|
+
return { kind: "summary", lines: [String(params.command)] };
|
|
142
|
+
},
|
|
86
143
|
ruleForCall(params) {
|
|
144
|
+
if (!("command" in params)) {
|
|
145
|
+
return BACKGROUND_HANDLE_RULE;
|
|
146
|
+
}
|
|
87
147
|
const classification = classifyBashCommand(params.command);
|
|
88
148
|
if (classification.type !== "segments" || classification.segments.length !== 1)
|
|
89
149
|
return null;
|
|
90
|
-
|
|
150
|
+
const segment = classification.segments[0];
|
|
151
|
+
return hasGrammarSensitiveStructure(segment) ? segment : normalizeSegment(segment);
|
|
91
152
|
},
|
|
92
153
|
};
|
|
93
154
|
}
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
*
|
|
97
|
-
* This is useful for extensions that intercept user_bash and still want pi's
|
|
98
|
-
* standard local shell behavior while wrapping or rewriting commands.
|
|
99
|
-
*/
|
|
100
|
-
export function createLocalBashOperations(options) {
|
|
155
|
+
/** Shared process execution used by the built-in shell tools. */
|
|
156
|
+
export function createLocalShellOperations(shellName, resolveShellConfig) {
|
|
101
157
|
return {
|
|
102
158
|
exec: async (command, cwd, { onData, signal, timeout, env }) => {
|
|
103
159
|
const timeoutMs = resolveTimeoutMs(timeout);
|
|
104
160
|
if (signal?.aborted) {
|
|
105
161
|
throw new Error("aborted");
|
|
106
162
|
}
|
|
107
|
-
const shellConfig =
|
|
163
|
+
const shellConfig = resolveShellConfig();
|
|
108
164
|
try {
|
|
109
165
|
await fsAccess(cwd, constants.F_OK);
|
|
110
166
|
}
|
|
111
167
|
catch {
|
|
112
|
-
throw new Error(`Working directory does not exist: ${cwd}\nCannot execute
|
|
168
|
+
throw new Error(`Working directory does not exist: ${cwd}\nCannot execute ${shellName} commands.`);
|
|
113
169
|
}
|
|
114
170
|
const commandFromStdin = shellConfig.commandTransport === "stdin";
|
|
115
171
|
const child = spawn(shellConfig.shell, commandFromStdin ? shellConfig.args : [...shellConfig.args, command], {
|
|
@@ -174,8 +230,47 @@ export function createLocalBashOperations(options) {
|
|
|
174
230
|
signal.removeEventListener("abort", onAbort);
|
|
175
231
|
}
|
|
176
232
|
},
|
|
233
|
+
spawnBackground: async (command, cwd, { onData, env }) => {
|
|
234
|
+
const shellConfig = resolveShellConfig();
|
|
235
|
+
try {
|
|
236
|
+
await fsAccess(cwd, constants.F_OK);
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
throw new Error(`Working directory does not exist: ${cwd}\nCannot execute ${shellName} commands.`);
|
|
240
|
+
}
|
|
241
|
+
const commandFromStdin = shellConfig.commandTransport === "stdin";
|
|
242
|
+
const child = spawn(shellConfig.shell, commandFromStdin ? shellConfig.args : [...shellConfig.args, command], {
|
|
243
|
+
cwd,
|
|
244
|
+
detached: process.platform !== "win32",
|
|
245
|
+
env: env ?? getShellEnv(),
|
|
246
|
+
stdio: [commandFromStdin ? "pipe" : "ignore", "pipe", "pipe"],
|
|
247
|
+
windowsHide: true,
|
|
248
|
+
});
|
|
249
|
+
if (commandFromStdin) {
|
|
250
|
+
child.stdin?.on("error", () => { });
|
|
251
|
+
child.stdin?.end(command);
|
|
252
|
+
}
|
|
253
|
+
if (child.pid)
|
|
254
|
+
trackDetachedChildPid(child.pid);
|
|
255
|
+
child.stdout?.on("data", onData);
|
|
256
|
+
child.stderr?.on("data", onData);
|
|
257
|
+
const exited = waitForChildProcess(child).finally(() => {
|
|
258
|
+
if (child.pid)
|
|
259
|
+
untrackDetachedChildPid(child.pid);
|
|
260
|
+
});
|
|
261
|
+
return { pid: child.pid, exited };
|
|
262
|
+
},
|
|
177
263
|
};
|
|
178
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Create bash operations using pi's built-in local shell execution backend.
|
|
267
|
+
*
|
|
268
|
+
* This is useful for extensions that intercept user_bash and still want pi's
|
|
269
|
+
* standard local shell behavior while wrapping or rewriting commands.
|
|
270
|
+
*/
|
|
271
|
+
export function createLocalBashOperations(options) {
|
|
272
|
+
return createLocalShellOperations("bash", () => getShellConfig(options?.shellPath));
|
|
273
|
+
}
|
|
179
274
|
function resolveSpawnContext(command, cwd, spawnHook, exposeSessionEnvironment, ctx) {
|
|
180
275
|
const env = { ...getShellEnv() };
|
|
181
276
|
setApexEnvironment("APEX_CODE_SESSION_ID", undefined, env);
|
|
@@ -211,12 +306,17 @@ class BashResultRenderComponent extends Container {
|
|
|
211
306
|
function formatDuration(ms) {
|
|
212
307
|
return `${(ms / 1000).toFixed(1)}s`;
|
|
213
308
|
}
|
|
214
|
-
function
|
|
309
|
+
function formatShellCall(args, prompt) {
|
|
215
310
|
const command = str(args?.command);
|
|
311
|
+
const handle = str(args?.handle);
|
|
312
|
+
if (!command && handle) {
|
|
313
|
+
const suffix = args?.kill === true ? " · kill" : "";
|
|
314
|
+
return theme.fg("toolTitle", theme.bold(`${prompt} ${handle}${suffix}`));
|
|
315
|
+
}
|
|
216
316
|
const timeout = args?.timeout;
|
|
217
317
|
const timeoutSuffix = timeout ? theme.fg("muted", ` (timeout ${timeout}s)`) : "";
|
|
218
318
|
const commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg("toolOutput", "...");
|
|
219
|
-
return theme.fg("toolTitle", theme.bold(`$ ${commandDisplay}`)) + timeoutSuffix;
|
|
319
|
+
return theme.fg("toolTitle", theme.bold(`${prompt} ${commandDisplay}`)) + timeoutSuffix;
|
|
220
320
|
}
|
|
221
321
|
function rebuildBashResultRenderComponent(component, result, options, showImages, startedAt, endedAt) {
|
|
222
322
|
const state = component.state;
|
|
@@ -283,17 +383,63 @@ function rebuildBashResultRenderComponent(component, result, options, showImages
|
|
|
283
383
|
component.addChild(new Text(`\n${theme.fg("muted", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));
|
|
284
384
|
}
|
|
285
385
|
}
|
|
286
|
-
export function
|
|
386
|
+
export function createShellToolDefinition(cwd, config, options) {
|
|
287
387
|
const ops = options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath });
|
|
288
388
|
const commandPrefix = options?.commandPrefix;
|
|
289
389
|
const exposeSessionEnvironment = options?.exposeSessionEnvironment ?? true;
|
|
290
390
|
const spawnHook = options?.spawnHook;
|
|
391
|
+
const registry = options?.backgroundRegistry ?? createBackgroundShellRegistry();
|
|
392
|
+
// Background handle calls (retrieve and kill) never touch the foreground
|
|
393
|
+
// execution path, so the post-hoc escalation offer below is unreachable from
|
|
394
|
+
// them by construction; the refusal note in `executeHandleCall` tells the
|
|
395
|
+
// model a foreground rerun gets the offer (spec, Non-goals).
|
|
396
|
+
const unknownHandleError = (handle) => {
|
|
397
|
+
const known = registry.handles();
|
|
398
|
+
return new ToolExecutionError(`Unknown background handle: ${handle}.${known.length > 0 ? ` Known handles: ${known.join(", ")}` : " No background commands have been launched."}`, undefined);
|
|
399
|
+
};
|
|
400
|
+
const executeHandleCall = async (handleInput) => {
|
|
401
|
+
if ("kill" in handleInput && handleInput.kill) {
|
|
402
|
+
const status = registry.kill(handleInput.handle);
|
|
403
|
+
if (!status)
|
|
404
|
+
throw unknownHandleError(handleInput.handle);
|
|
405
|
+
const state = status.running ? "kill signal sent" : `already exited (code ${status.exitCode})`;
|
|
406
|
+
return {
|
|
407
|
+
content: [{ type: "text", text: `[background] ${handleInput.handle}: ${state}` }],
|
|
408
|
+
details: undefined,
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
const retrieved = await registry.retrieve(handleInput.handle);
|
|
412
|
+
if (!retrieved)
|
|
413
|
+
throw unknownHandleError(handleInput.handle);
|
|
414
|
+
const { status, snapshot } = retrieved;
|
|
415
|
+
const elapsed = ((Date.now() - status.startedAt) / 1000).toFixed(1);
|
|
416
|
+
const header = status.running
|
|
417
|
+
? `[background] ${handleInput.handle}: running ${elapsed}s`
|
|
418
|
+
: `[background] ${handleInput.handle}: ${status.killed ? "killed" : "exited"} (code ${status.exitCode}) after ${elapsed}s`;
|
|
419
|
+
let text = `${header}\n\n${snapshot.content || "(no output)"}`;
|
|
420
|
+
const truncation = snapshot.truncation;
|
|
421
|
+
if (truncation.truncated && snapshot.fullOutputPath) {
|
|
422
|
+
const startLine = truncation.totalLines - truncation.outputLines + 1;
|
|
423
|
+
text += `\n\n[Showing lines ${startLine}-${truncation.totalLines} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;
|
|
424
|
+
}
|
|
425
|
+
if (!status.running && looksLikeSandboxRefusal(snapshot.content)) {
|
|
426
|
+
text += `\n\n[Sandbox refusal: background runs are not offered escalation. Rerun this command in the foreground to get the escalation offer.]`;
|
|
427
|
+
}
|
|
428
|
+
return {
|
|
429
|
+
content: [{ type: "text", text }],
|
|
430
|
+
details: {
|
|
431
|
+
truncation: truncation.truncated ? truncation : undefined,
|
|
432
|
+
fullOutputPath: snapshot.fullOutputPath,
|
|
433
|
+
execution: { cwd, exitCode: status.exitCode ?? null },
|
|
434
|
+
},
|
|
435
|
+
};
|
|
436
|
+
};
|
|
291
437
|
return {
|
|
292
|
-
name:
|
|
293
|
-
label:
|
|
294
|
-
description: `Execute a
|
|
295
|
-
promptSnippet:
|
|
296
|
-
promptGuidelines: exposeSessionEnvironment ? [...
|
|
438
|
+
name: config.name,
|
|
439
|
+
label: config.label,
|
|
440
|
+
description: `Execute a ${config.shellName} command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,
|
|
441
|
+
promptSnippet: config.promptSnippet,
|
|
442
|
+
promptGuidelines: exposeSessionEnvironment && config.promptGuidelines ? [...config.promptGuidelines] : undefined,
|
|
297
443
|
parameters: bashSchema,
|
|
298
444
|
contract: {
|
|
299
445
|
capabilities: new Set(["exec"]),
|
|
@@ -303,17 +449,48 @@ export function createBashToolDefinition(cwd, options) {
|
|
|
303
449
|
emits: new Set(["command"]),
|
|
304
450
|
capture: (params, result) => {
|
|
305
451
|
const execution = result.details?.execution;
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
452
|
+
// Retrieve and kill calls carry a handle; resolve it back to the
|
|
453
|
+
// command that produced the output so the record shows what ran.
|
|
454
|
+
const command = "command" in params ? params.command : (registry.commandFor(params.handle) ?? params.handle);
|
|
455
|
+
return execution ? [{ kind: "command", command, ...execution }] : [{ kind: "command", command }];
|
|
309
456
|
},
|
|
310
457
|
},
|
|
311
458
|
},
|
|
312
459
|
constrainedSampling: getExperimentalToolSampling(),
|
|
313
|
-
async execute(_toolCallId,
|
|
460
|
+
async execute(_toolCallId, input, signal, onUpdate, ctx) {
|
|
461
|
+
if ("handle" in input) {
|
|
462
|
+
return await executeHandleCall(input);
|
|
463
|
+
}
|
|
464
|
+
const { command, timeout, background } = input;
|
|
314
465
|
const resolvedCommand = commandPrefix ? `${commandPrefix}\n${command}` : command;
|
|
315
466
|
const spawnContext = resolveSpawnContext(resolvedCommand, cwd, spawnHook, exposeSessionEnvironment, ctx);
|
|
316
|
-
|
|
467
|
+
if (background) {
|
|
468
|
+
const spawnBg = ops.spawnBackground;
|
|
469
|
+
if (!spawnBg) {
|
|
470
|
+
throw new ToolExecutionError("This shell backend does not support background execution. Run the command in the foreground instead.", undefined);
|
|
471
|
+
}
|
|
472
|
+
const output = new OutputAccumulator({ tempFilePrefix: config.tempFilePrefix });
|
|
473
|
+
const launched = await spawnBg(spawnContext.command, spawnContext.cwd, {
|
|
474
|
+
env: spawnContext.env,
|
|
475
|
+
onData: (data) => output.append(data),
|
|
476
|
+
});
|
|
477
|
+
const handle = registry.launch({
|
|
478
|
+
command: spawnContext.command,
|
|
479
|
+
pid: launched.pid,
|
|
480
|
+
output,
|
|
481
|
+
exited: launched.exited,
|
|
482
|
+
});
|
|
483
|
+
return {
|
|
484
|
+
content: [
|
|
485
|
+
{
|
|
486
|
+
type: "text",
|
|
487
|
+
text: `[background] launched with handle ${handle}\nRetrieve its output: { "handle": "${handle}" }\nKill it: { "handle": "${handle}", "kill": true }`,
|
|
488
|
+
},
|
|
489
|
+
],
|
|
490
|
+
details: { execution: { cwd: spawnContext.cwd, exitCode: null } },
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
const output = new OutputAccumulator({ tempFilePrefix: config.tempFilePrefix });
|
|
317
494
|
let acceptingOutput = true;
|
|
318
495
|
let updateTimer;
|
|
319
496
|
let updateDirty = false;
|
|
@@ -432,6 +609,24 @@ export function createBashToolDefinition(cwd, options) {
|
|
|
432
609
|
const { text: outputText, details } = formatOutput(snapshot);
|
|
433
610
|
const resultDetails = { ...details, execution };
|
|
434
611
|
if (exitCode !== 0 && exitCode !== null) {
|
|
612
|
+
// The OS boundary refuses a write in the kernel, so by the time this runs
|
|
613
|
+
// the syscall has already failed and nothing inside this namespace can
|
|
614
|
+
// widen it. Offering the command to the supervisor is the only remaining
|
|
615
|
+
// move, and it is the supervisor that shows the human the exact command
|
|
616
|
+
// and root before anything runs -- so a wrong guess at the path is
|
|
617
|
+
// refused by someone reading it, never granted quietly.
|
|
618
|
+
const escalated = await escalateRefusedCommand(command, outputText);
|
|
619
|
+
if (escalated) {
|
|
620
|
+
// The reported exit code has to be the escalated run's, not the
|
|
621
|
+
// refused one's. Leaving the original would have the details say the
|
|
622
|
+
// command failed while the content says it succeeded, and anything
|
|
623
|
+
// reading the facts rather than the text would disagree with the
|
|
624
|
+
// model about what happened.
|
|
625
|
+
return {
|
|
626
|
+
content: [{ type: "text", text: escalated.text }],
|
|
627
|
+
details: { ...resultDetails, execution: { ...execution, exitCode: 0 } },
|
|
628
|
+
};
|
|
629
|
+
}
|
|
435
630
|
throw new ToolExecutionError(appendStatus(outputText, `Command exited with code ${exitCode}`), {
|
|
436
631
|
execution,
|
|
437
632
|
});
|
|
@@ -449,7 +644,7 @@ export function createBashToolDefinition(cwd, options) {
|
|
|
449
644
|
state.endedAt = undefined;
|
|
450
645
|
}
|
|
451
646
|
const text = context.lastComponent ?? new Text("", 0, 0);
|
|
452
|
-
text.setText(
|
|
647
|
+
text.setText(formatShellCall(args, config.prompt));
|
|
453
648
|
return text;
|
|
454
649
|
},
|
|
455
650
|
renderResult(result, options, _theme, context) {
|
|
@@ -471,6 +666,18 @@ export function createBashToolDefinition(cwd, options) {
|
|
|
471
666
|
},
|
|
472
667
|
};
|
|
473
668
|
}
|
|
669
|
+
const bashToolConfig = {
|
|
670
|
+
name: "bash",
|
|
671
|
+
label: "bash",
|
|
672
|
+
shellName: "bash",
|
|
673
|
+
prompt: "$",
|
|
674
|
+
promptSnippet: bashToolSystemPromptContribution.snippet,
|
|
675
|
+
promptGuidelines: bashToolSystemPromptContribution.guidelines,
|
|
676
|
+
tempFilePrefix: "apex-code-bash",
|
|
677
|
+
};
|
|
678
|
+
export function createBashToolDefinition(cwd, options) {
|
|
679
|
+
return createShellToolDefinition(cwd, bashToolConfig, options);
|
|
680
|
+
}
|
|
474
681
|
export function createBashTool(cwd, options) {
|
|
475
682
|
const definition = createBashToolDefinition(cwd, options);
|
|
476
683
|
const tool = wrapToolDefinition(definition);
|
|
@@ -480,4 +687,29 @@ export function createBashTool(cwd, options) {
|
|
|
480
687
|
});
|
|
481
688
|
return tool;
|
|
482
689
|
}
|
|
690
|
+
/**
|
|
691
|
+
* Offer a command the sandbox refused to the supervisor, once.
|
|
692
|
+
*
|
|
693
|
+
* Returns the escalated output when a human approved it and it ran, and undefined for
|
|
694
|
+
* every other outcome -- no channel, no recognisable refusal, no path in the message, a
|
|
695
|
+
* refused prompt -- because the caller's behaviour is the same in all of them: report
|
|
696
|
+
* what originally happened.
|
|
697
|
+
*/
|
|
698
|
+
async function escalateRefusedCommand(command, output) {
|
|
699
|
+
if (!looksLikeSandboxRefusal(output))
|
|
700
|
+
return undefined;
|
|
701
|
+
const refusedPath = extractRefusedPath(output);
|
|
702
|
+
if (!refusedPath)
|
|
703
|
+
return undefined;
|
|
704
|
+
const outcome = await requestCommandEscalation({ command, writableRoot: escalationRootFor(refusedPath) });
|
|
705
|
+
if (!outcome || outcome.code !== 0)
|
|
706
|
+
return undefined;
|
|
707
|
+
const combined = [outcome.stdout, outcome.stderr]
|
|
708
|
+
.filter((part) => part.length > 0)
|
|
709
|
+
.join("\n")
|
|
710
|
+
.trim();
|
|
711
|
+
// A silent success still has to say something, or the model reads an empty result as
|
|
712
|
+
// the command having had no effect.
|
|
713
|
+
return { text: combined.length > 0 ? combined : "Command ran with approved escalated access." };
|
|
714
|
+
}
|
|
483
715
|
//# sourceMappingURL=bash.js.map
|