apex-code 0.0.1-alpha.9 → 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 +150 -2
- package/README.md +9 -8
- package/dist/cli/args.d.ts +25 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +43 -1
- package/dist/cli/args.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.map +1 -1
- package/dist/config.js +24 -5
- 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 +157 -8
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +565 -22
- package/dist/core/agent-session.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 +4 -3
- 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 +19 -5
- package/dist/core/compaction/compaction.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/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 +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 +8 -2
- 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 +22 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.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/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/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/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/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 +22 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +53 -1
- package/dist/core/sdk.js.map +1 -1
- 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 +32 -5
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +163 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +107 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +2 -0
- package/dist/core/slash-commands.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 +30 -15
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +228 -12
- 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 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +215 -3
- 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 +53 -7
- 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 +10 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +3 -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/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/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/provider.d.ts +3 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +27 -6
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +3 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +41 -9
- package/dist/main.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.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +6 -6
- 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 +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 +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/interactive-mode.d.ts +34 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +231 -26
- 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 +15 -5
- package/dist/modes/interactive/theme/theme.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.map +1 -1
- package/dist/package-manager-cli.js +0 -6
- package/dist/package-manager-cli.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/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 +4 -0
- package/docs/custom-provider.md +7 -7
- package/docs/environment-variables.md +1 -1
- package/docs/extensions.md +18 -0
- package/docs/keybindings.md +1 -1
- package/docs/quickstart.md +1 -1
- package/docs/rpc.md +23 -0
- package/docs/sdk.md +25 -0
- package/docs/settings.md +12 -4
- package/docs/terminal-setup.md +12 -0
- package/docs/usage.md +4 -3
- 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/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/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +194 -46
- package/package.json +14 -12
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ls.js","sourceRoot":"","sources":["../../../src/core/tools/ls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE9C,OAAO,QAAQ,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AAIjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAyB,YAAY,EAAE,MAAM,eAAe,CAAC;AAEnG,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,gDAAgD,EAAE,CAAC,CAAC;IACnG,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,oDAAoD,EAAE,CAAC,CAAC;CACxG,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC7C,OAAO,EAAE,yBAAyB;IAClC,UAAU,EAAE,EAAE;CACL,CAAC;AAIX,MAAM,aAAa,GAAG,GAAG,CAAC;AAsB1B,MAAM,mBA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OAAO,EAAE;YAC7C,MAAM,IAAI,GAAI,OAAO,CAAC,aAAkC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/E,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,MAAa,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;YAChF,OAAO,IAAI,CAAC;QAAA,CACZ;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,OAAuB,EAA8B;IAC9F,OAAO,kBAAkB,CAAC,sBAAsB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAChE","sourcesContent":["import { readdir as fsReaddir, stat as fsStat } from \"node:fs/promises\";\nimport { Text } from \"@earendil-works/pi-tui\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport nodePath from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { pathExists, resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, renderToolPath, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, formatSize, type TruncationResult, truncateHead } from \"./truncate.ts\";\n\nconst lsSchema = Type.Object({\n\tpath: Type.Optional(Type.String({ description: \"Directory to list (default: current directory)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of entries to return (default: 500)\" })),\n});\n\nexport const lsToolSystemPromptContribution = {\n\tsnippet: \"List directory contents\",\n\tguidelines: [],\n} as const;\n\nexport type LsToolInput = Static<typeof lsSchema>;\n\nconst DEFAULT_LIMIT = 500;\n\nexport interface LsToolDetails {\n\ttruncation?: TruncationResult;\n\t/** Entries in the directory before the limit was applied. Present only when truncated. */\n\ttotalEntries?: number;\n\tentryLimitReached?: number;\n}\n\n/**\n * Pluggable operations for the ls tool.\n * Override these to delegate directory listing to remote systems (for example SSH).\n */\nexport interface LsOperations {\n\t/** Check if path exists */\n\texists: (absolutePath: string) => Promise<boolean> | boolean;\n\t/** Get file or directory stats. Throws if not found. */\n\tstat: (absolutePath: string) => Promise<{ isDirectory: () => boolean }> | { isDirectory: () => boolean };\n\t/** Read directory entries */\n\treaddir: (absolutePath: string) => Promise<string[]> | string[];\n}\n\nconst defaultLsOperations: LsOperations = {\n\texists: pathExists,\n\tstat: fsStat,\n\treaddir: fsReaddir,\n};\n\nexport interface LsToolOptions {\n\t/** Custom operations for directory listing. Default: local filesystem */\n\toperations?: LsOperations;\n}\n\nfunction formatLsCall(args: { path?: string; limit?: number } | undefined, theme: Theme, cwd: string): string {\n\tconst limit = args?.limit;\n\tconst pathDisplay = renderToolPath(str(args?.path), theme, cwd, { emptyFallback: \".\" });\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"ls\"))} ${pathDisplay}`;\n\tif (limit !== undefined) {\n\t\ttext += theme.fg(\"toolOutput\", ` (limit ${limit})`);\n\t}\n\treturn text;\n}\n\nfunction formatLsResult(\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: LsToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tshowImages: boolean,\n): string {\n\tconst output = getTextOutput(result, showImages).trim();\n\tlet text = \"\";\n\tif (output) {\n\t\tconst lines = output.split(\"\\n\");\n\t\tconst maxLines = options.expanded ? lines.length : 20;\n\t\tconst displayLines = lines.slice(0, maxLines);\n\t\tconst remaining = lines.length - maxLines;\n\t\ttext += `\\n${displayLines.map((line) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t}\n\t}\n\n\tconst entryLimit = result.details?.entryLimitReached;\n\tconst truncation = result.details?.truncation;\n\tif (entryLimit || truncation?.truncated) {\n\t\tconst warnings: string[] = [];\n\t\tif (entryLimit) warnings.push(`${entryLimit} entries limit`);\n\t\tif (truncation?.truncated) warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t}\n\treturn text;\n}\n\nexport function createLsToolDefinition(\n\tcwd: string,\n\toptions?: LsToolOptions,\n): ApexToolDefinition<typeof lsSchema, LsToolDetails | undefined> {\n\tconst ops = options?.operations ?? defaultLsOperations;\n\treturn {\n\t\tname: \"ls\",\n\t\tlabel: \"ls\",\n\t\tdescription: `List directory contents. Returns entries sorted alphabetically, with '/' suffix for directories. Includes dotfiles. Output is truncated to ${DEFAULT_LIMIT} entries or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first).`,\n\t\tpromptSnippet: lsToolSystemPromptContribution.snippet,\n\t\tparameters: lsSchema,\n\t\tcontract: {\n\t\t\tcapabilities: new Set([\"fs.read\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"allow\",\n\t\t\t\tverb: \"List\",\n\t\t\t\tgetPath: (params) => params.path,\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: true },\n\t\t\tevidence: { emits: new Set(), capture: () => [] },\n\t\t},\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, limit }: { path?: string; limit?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst onAbort = () => reject(new Error(\"Operation aborted\"));\n\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst dirPath = resolveToCwd(path || \".\", cwd);\n\t\t\t\t\t\tconst effectiveLimit = limit ?? DEFAULT_LIMIT;\n\n\t\t\t\t\t\t// Check if path exists.\n\t\t\t\t\t\tif (!(await ops.exists(dirPath))) {\n\t\t\t\t\t\t\treject(new Error(`Path not found: ${dirPath}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Check if path is a directory.\n\t\t\t\t\t\tconst stat = await ops.stat(dirPath);\n\t\t\t\t\t\tif (!stat.isDirectory()) {\n\t\t\t\t\t\t\treject(new Error(`Not a directory: ${dirPath}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Read directory entries.\n\t\t\t\t\t\tlet entries: string[];\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tentries = await ops.readdir(dirPath);\n\t\t\t\t\t\t} catch (e: any) {\n\t\t\t\t\t\t\treject(new Error(`Cannot read directory: ${e.message}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Sort alphabetically, case-insensitive.\n\t\t\t\t\t\tentries.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));\n\n\t\t\t\t\t\t// Format entries with directory indicators.\n\t\t\t\t\t\tconst results: string[] = [];\n\t\t\t\t\t\tlet entryLimitReached = false;\n\t\t\t\t\t\tfor (const entry of entries) {\n\t\t\t\t\t\t\tif (results.length >= effectiveLimit) {\n\t\t\t\t\t\t\t\tentryLimitReached = true;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst fullPath = nodePath.join(dirPath, entry);\n\t\t\t\t\t\t\tlet suffix = \"\";\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst entryStat = await ops.stat(fullPath);\n\t\t\t\t\t\t\t\tif (entryStat.isDirectory()) suffix = \"/\";\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t// Skip entries we cannot stat.\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tresults.push(entry + suffix);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\n\t\t\t\t\t\tif (results.length === 0) {\n\t\t\t\t\t\t\tresolve({ content: [{ type: \"text\", text: \"(empty directory)\" }], details: undefined });\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst rawOutput = results.join(\"\\n\");\n\t\t\t\t\t\t// Apply byte truncation. There is no separate line limit because entry count is already capped.\n\t\t\t\t\t\tconst truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });\n\t\t\t\t\t\tlet output = truncation.content;\n\t\t\t\t\t\tconst details: LsToolDetails = {};\n\t\t\t\t\t\t// Build actionable notices for truncation and entry limits.\n\t\t\t\t\t\tconst notices: string[] = [];\n\t\t\t\t\t\tif (entryLimitReached) {\n\t\t\t\t\t\t\t// The whole listing was read before capping, so the total is already in\n\t\t\t\t\t\t\t// hand. Reporting it is what lets the agent decide whether it has seen\n\t\t\t\t\t\t\t// everything instead of spending a second call to find out.\n\t\t\t\t\t\t\tnotices.push(\n\t\t\t\t\t\t\t\t`${results.length} of ${entries.length} total entries shown. Use limit=${effectiveLimit * 2} for more`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tdetails.entryLimitReached = effectiveLimit;\n\t\t\t\t\t\t\tdetails.totalEntries = entries.length;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\t\t\tnotices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);\n\t\t\t\t\t\t\tdetails.truncation = truncation;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (notices.length > 0) {\n\t\t\t\t\t\t\toutput += `\\n\\n[${notices.join(\". \")}]`;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: output }],\n\t\t\t\t\t\t\tdetails: Object.keys(details).length > 0 ? details : undefined,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (e: any) {\n\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\treject(e);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatLsCall(args, theme, context.cwd));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatLsResult(result as any, options, theme, context.showImages));\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createLsTool(cwd: string, options?: LsToolOptions): AgentTool<typeof lsSchema> {\n\treturn wrapToolDefinition(createLsToolDefinition(cwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ls.js","sourceRoot":"","sources":["../../../src/core/tools/ls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE9C,OAAO,QAAQ,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AAGjF,OAAO,EAAE,wBAAwB,EAAE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,CACZ;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,OAAuB,EAA8B;IAC9F,OAAO,kBAAkB,CAAC,sBAAsB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAChE","sourcesContent":["import { readdir as fsReaddir, stat as fsStat } from \"node:fs/promises\";\nimport { Text } from \"@earendil-works/pi-tui\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport nodePath from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { getPreparedPathOperation } from \"../permissions/operations.ts\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { pathExists, resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, renderToolPath, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, formatSize, type TruncationResult, truncateHead } from \"./truncate.ts\";\n\nconst lsSchema = Type.Object({\n\tpath: Type.Optional(Type.String({ description: \"Directory to list (default: current directory)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of entries to return (default: 500)\" })),\n});\n\nexport const lsToolSystemPromptContribution = {\n\tsnippet: \"List directory contents\",\n\tguidelines: [],\n} as const;\n\nexport type LsToolInput = Static<typeof lsSchema>;\n\nconst DEFAULT_LIMIT = 500;\n\nexport interface LsToolDetails {\n\ttruncation?: TruncationResult;\n\t/** Entries in the directory before the limit was applied. Present only when truncated. */\n\ttotalEntries?: number;\n\tentryLimitReached?: number;\n}\n\n/**\n * Pluggable operations for the ls tool.\n * Override these to delegate directory listing to remote systems (for example SSH).\n */\nexport interface LsOperations {\n\t/** Check if path exists */\n\texists: (absolutePath: string) => Promise<boolean> | boolean;\n\t/** Get file or directory stats. Throws if not found. */\n\tstat: (absolutePath: string) => Promise<{ isDirectory: () => boolean }> | { isDirectory: () => boolean };\n\t/** Read directory entries */\n\treaddir: (absolutePath: string) => Promise<string[]> | string[];\n}\n\nconst defaultLsOperations: LsOperations = {\n\texists: pathExists,\n\tstat: fsStat,\n\treaddir: fsReaddir,\n};\n\nexport interface LsToolOptions {\n\t/** Custom operations for directory listing. Default: local filesystem */\n\toperations?: LsOperations;\n}\n\nfunction formatLsCall(args: { path?: string; limit?: number } | undefined, theme: Theme, cwd: string): string {\n\tconst limit = args?.limit;\n\tconst pathDisplay = renderToolPath(str(args?.path), theme, cwd, { emptyFallback: \".\" });\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"ls\"))} ${pathDisplay}`;\n\tif (limit !== undefined) {\n\t\ttext += theme.fg(\"toolOutput\", ` (limit ${limit})`);\n\t}\n\treturn text;\n}\n\nfunction formatLsResult(\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: LsToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tshowImages: boolean,\n): string {\n\tconst output = getTextOutput(result, showImages).trim();\n\tlet text = \"\";\n\tif (output) {\n\t\tconst lines = output.split(\"\\n\");\n\t\tconst maxLines = options.expanded ? lines.length : 20;\n\t\tconst displayLines = lines.slice(0, maxLines);\n\t\tconst remaining = lines.length - maxLines;\n\t\ttext += `\\n${displayLines.map((line) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t}\n\t}\n\n\tconst entryLimit = result.details?.entryLimitReached;\n\tconst truncation = result.details?.truncation;\n\tif (entryLimit || truncation?.truncated) {\n\t\tconst warnings: string[] = [];\n\t\tif (entryLimit) warnings.push(`${entryLimit} entries limit`);\n\t\tif (truncation?.truncated) warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t}\n\treturn text;\n}\n\nexport function createLsToolDefinition(\n\tcwd: string,\n\toptions?: LsToolOptions,\n): ApexToolDefinition<typeof lsSchema, LsToolDetails | undefined> {\n\tconst ops = options?.operations ?? defaultLsOperations;\n\treturn {\n\t\tname: \"ls\",\n\t\tlabel: \"ls\",\n\t\tdescription: `List directory contents. Returns entries sorted alphabetically, with '/' suffix for directories. Includes dotfiles. Output is truncated to ${DEFAULT_LIMIT} entries or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first).`,\n\t\tpromptSnippet: lsToolSystemPromptContribution.snippet,\n\t\tparameters: lsSchema,\n\t\tcontract: {\n\t\t\tcapabilities: new Set([\"fs.read\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"allow\",\n\t\t\t\tverb: \"List\",\n\t\t\t\tgetPath: (params) => params.path,\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: true },\n\t\t\tevidence: { emits: new Set(), capture: () => [] },\n\t\t},\n\t\tasync execute(_toolCallId, input: { path?: string; limit?: number }, signal?: AbortSignal, _onUpdate?, _ctx?) {\n\t\t\tconst { path, limit } = input;\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst onAbort = () => reject(new Error(\"Operation aborted\"));\n\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst prepared = getPreparedPathOperation(input);\n\t\t\t\t\t\tconst dirPath = prepared ? prepared.path.value : resolveToCwd(path || \".\", cwd);\n\t\t\t\t\t\tconst effectiveLimit = limit ?? DEFAULT_LIMIT;\n\n\t\t\t\t\t\t// Check if path exists.\n\t\t\t\t\t\tif (!(await ops.exists(dirPath))) {\n\t\t\t\t\t\t\treject(new Error(`Path not found: ${dirPath}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Check if path is a directory.\n\t\t\t\t\t\tconst stat = await ops.stat(dirPath);\n\t\t\t\t\t\tif (!stat.isDirectory()) {\n\t\t\t\t\t\t\treject(new Error(`Not a directory: ${dirPath}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Read directory entries.\n\t\t\t\t\t\tlet entries: string[];\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tentries = await ops.readdir(dirPath);\n\t\t\t\t\t\t} catch (e: any) {\n\t\t\t\t\t\t\treject(new Error(`Cannot read directory: ${e.message}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Sort alphabetically, case-insensitive.\n\t\t\t\t\t\tentries.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));\n\n\t\t\t\t\t\t// Format entries with directory indicators.\n\t\t\t\t\t\tconst results: string[] = [];\n\t\t\t\t\t\tlet entryLimitReached = false;\n\t\t\t\t\t\tfor (const entry of entries) {\n\t\t\t\t\t\t\tif (results.length >= effectiveLimit) {\n\t\t\t\t\t\t\t\tentryLimitReached = true;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst fullPath = nodePath.join(dirPath, entry);\n\t\t\t\t\t\t\tlet suffix = \"\";\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst entryStat = await ops.stat(fullPath);\n\t\t\t\t\t\t\t\tif (entryStat.isDirectory()) suffix = \"/\";\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t// Skip entries we cannot stat.\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tresults.push(entry + suffix);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\n\t\t\t\t\t\tif (results.length === 0) {\n\t\t\t\t\t\t\tresolve({ content: [{ type: \"text\", text: \"(empty directory)\" }], details: undefined });\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst rawOutput = results.join(\"\\n\");\n\t\t\t\t\t\t// Apply byte truncation. There is no separate line limit because entry count is already capped.\n\t\t\t\t\t\tconst truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });\n\t\t\t\t\t\tlet output = truncation.content;\n\t\t\t\t\t\tconst details: LsToolDetails = {};\n\t\t\t\t\t\t// Build actionable notices for truncation and entry limits.\n\t\t\t\t\t\tconst notices: string[] = [];\n\t\t\t\t\t\tif (entryLimitReached) {\n\t\t\t\t\t\t\t// The whole listing was read before capping, so the total is already in\n\t\t\t\t\t\t\t// hand. Reporting it is what lets the agent decide whether it has seen\n\t\t\t\t\t\t\t// everything instead of spending a second call to find out.\n\t\t\t\t\t\t\tnotices.push(\n\t\t\t\t\t\t\t\t`${results.length} of ${entries.length} total entries shown. Use limit=${effectiveLimit * 2} for more`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tdetails.entryLimitReached = effectiveLimit;\n\t\t\t\t\t\t\tdetails.totalEntries = entries.length;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\t\t\tnotices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);\n\t\t\t\t\t\t\tdetails.truncation = truncation;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (notices.length > 0) {\n\t\t\t\t\t\t\toutput += `\\n\\n[${notices.join(\". \")}]`;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: output }],\n\t\t\t\t\t\t\tdetails: Object.keys(details).length > 0 ? details : undefined,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (e: any) {\n\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\treject(e);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatLsCall(args, theme, context.cwd));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatLsResult(result as any, options, theme, context.showImages));\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createLsTool(cwd: string, options?: LsToolOptions): AgentTool<typeof lsSchema> {\n\treturn wrapToolDefinition(createLsToolDefinition(cwd, options));\n}\n"]}
|
package/dist/core/tools/lsp.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentTool } from "apex-code-agent-core";
|
|
2
2
|
import { type Static, Type } from "typebox";
|
|
3
|
-
import type
|
|
3
|
+
import { type ApexToolDefinition } from "./contract.ts";
|
|
4
4
|
declare const lspSchema: Type.TUnion<[Type.TObject<{
|
|
5
5
|
operation: Type.TUnion<[Type.TLiteral<"definition">, Type.TLiteral<"references">]>;
|
|
6
6
|
path: Type.TString;
|
|
@@ -9,6 +9,9 @@ declare const lspSchema: Type.TUnion<[Type.TObject<{
|
|
|
9
9
|
}>, Type.TObject<{
|
|
10
10
|
operation: Type.TLiteral<"document_symbols">;
|
|
11
11
|
path: Type.TString;
|
|
12
|
+
}>, Type.TObject<{
|
|
13
|
+
operation: Type.TLiteral<"workspace_symbol">;
|
|
14
|
+
query: Type.TString;
|
|
12
15
|
}>]>;
|
|
13
16
|
export type LspToolInput = Static<typeof lspSchema>;
|
|
14
17
|
export interface LspPosition {
|
|
@@ -33,6 +36,14 @@ export interface LspSymbol {
|
|
|
33
36
|
readonly selectionRange: LspRange;
|
|
34
37
|
readonly detail?: string;
|
|
35
38
|
}
|
|
39
|
+
/** A workspace-wide symbol (LSP SymbolInformation) normalized like {@link LspSymbol} without a selection range. */
|
|
40
|
+
export interface LspWorkspaceSymbol {
|
|
41
|
+
readonly name: string;
|
|
42
|
+
readonly kind: number;
|
|
43
|
+
readonly path: string;
|
|
44
|
+
readonly range: LspRange;
|
|
45
|
+
readonly containerName?: string;
|
|
46
|
+
}
|
|
36
47
|
export type LspToolDetails = {
|
|
37
48
|
operation: "definition" | "references";
|
|
38
49
|
locations: LspLocation[];
|
|
@@ -43,6 +54,13 @@ export type LspToolDetails = {
|
|
|
43
54
|
symbols: LspSymbol[];
|
|
44
55
|
omitted: number;
|
|
45
56
|
truncated: number;
|
|
57
|
+
} | {
|
|
58
|
+
operation: "workspace_symbol";
|
|
59
|
+
symbols: LspWorkspaceSymbol[];
|
|
60
|
+
omitted: number;
|
|
61
|
+
truncated: number;
|
|
62
|
+
outsideRoot: number;
|
|
63
|
+
unsupported?: boolean;
|
|
46
64
|
};
|
|
47
65
|
/**
|
|
48
66
|
* Pluggable transport for the `lsp` tool. The executable, its arguments, and the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lsp.d.ts","sourceRoot":"","sources":["../../../src/core/tools/lsp.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAsBxD,QAAA,MAAM,SAAS;;;;;;;;IAA8D,CAAC;AAE9E,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC;AAEpD,MAAM,WAAW,WAAW;IAC3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;AAwJD,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,cAAc,GACrB,kBAAkB,CAAC,OAAO,SAAS,EAAE,cAAc,CAAC,CAwDtD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,SAAS,CAAC,OAAO,SAAS,CAAC,CAE/F","sourcesContent":["import { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst MAX_LOCATIONS = 1_000;\nconst MAX_SYMBOLS = 2_000;\n\nconst lspNavigationSchema = Type.Object({\n\toperation: Type.Union([Type.Literal(\"definition\"), Type.Literal(\"references\")], {\n\t\tdescription: \"Which navigation query to run.\",\n\t}),\n\tpath: Type.String({ description: \"Path to the file (relative or absolute).\" }),\n\tline: Type.Number({ description: \"One-based line number.\" }),\n\tcharacter: Type.Number({ description: \"One-based UTF-16 character offset within the line.\" }),\n});\n\nconst lspDocumentSymbolsSchema = Type.Object({\n\toperation: Type.Literal(\"document_symbols\", { description: \"List the symbols declared in a file.\" }),\n\tpath: Type.String({ description: \"Path to the file (relative or absolute).\" }),\n});\n\nconst lspSchema = Type.Union([lspNavigationSchema, lspDocumentSymbolsSchema]);\n\nexport type LspToolInput = Static<typeof lspSchema>;\n\nexport interface LspPosition {\n\treadonly line: number;\n\treadonly character: number;\n}\n\nexport interface LspRange {\n\treadonly start: LspPosition;\n\treadonly end: LspPosition;\n}\n\n/** A navigation result normalized to a workspace-relative path and one-based range. */\nexport interface LspLocation {\n\treadonly path: string;\n\treadonly range: LspRange;\n}\n\n/** A flattened document symbol normalized to a workspace-relative path and one-based ranges. */\nexport interface LspSymbol {\n\treadonly name: string;\n\treadonly kind: number;\n\treadonly path: string;\n\treadonly range: LspRange;\n\treadonly selectionRange: LspRange;\n\treadonly detail?: string;\n}\n\nexport type LspToolDetails =\n\t| { operation: \"definition\" | \"references\"; locations: LspLocation[]; omitted: number; truncated: number }\n\t| { operation: \"document_symbols\"; symbols: LspSymbol[]; omitted: number; truncated: number };\n\n/**\n * Pluggable transport for the `lsp` tool. The executable, its arguments, and the\n * closed JSON-RPC method set are all fixed by configuration the tool never chooses\n * itself -- see contract.capabilities below for why that keeps this `{fs.read}`\n * rather than `{exec}`.\n */\nexport interface LspOperations {\n\trequest(absolutePath: string, method: string, params: unknown, signal?: AbortSignal): Promise<unknown>;\n}\n\nexport interface LspToolOptions {\n\toperations: LspOperations;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isPosition(value: unknown): value is LspPosition {\n\treturn isRecord(value) && typeof value.line === \"number\" && typeof value.character === \"number\";\n}\n\nfunction isRange(value: unknown): value is LspRange {\n\treturn isRecord(value) && isPosition(value.start) && isPosition(value.end);\n}\n\nfunction toOneBasedPosition(position: LspPosition): LspPosition {\n\treturn { line: position.line + 1, character: position.character + 1 };\n}\n\nfunction toOneBasedRange(range: LspRange): LspRange {\n\treturn { start: toOneBasedPosition(range.start), end: toOneBasedPosition(range.end) };\n}\n\nfunction fileUriToAbsolutePath(uri: string): string | undefined {\n\tif (!uri.startsWith(\"file:\")) return undefined;\n\ttry {\n\t\treturn fileURLToPath(uri);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction rawLocationUriAndRange(value: unknown): { uri: string; range: LspRange } | undefined {\n\tif (!isRecord(value)) return undefined;\n\tif (typeof value.uri === \"string\" && isRange(value.range)) return { uri: value.uri, range: value.range };\n\tif (typeof value.targetUri === \"string\" && isRange(value.targetRange)) {\n\t\treturn { uri: value.targetUri, range: value.targetRange };\n\t}\n\treturn undefined;\n}\n\nfunction normalizeLocations(raw: unknown, cwd: string): { locations: LspLocation[]; omitted: number } {\n\tconst items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];\n\tconst locations: LspLocation[] = [];\n\tlet omitted = 0;\n\tfor (const item of items) {\n\t\tconst parsed = rawLocationUriAndRange(item);\n\t\tconst absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;\n\t\tif (!parsed || !absolutePath) {\n\t\t\tomitted++;\n\t\t\tcontinue;\n\t\t}\n\t\tlocations.push({\n\t\t\tpath: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),\n\t\t\trange: toOneBasedRange(parsed.range),\n\t\t});\n\t}\n\treturn { locations, omitted };\n}\n\nfunction compareLocations(a: LspLocation, b: LspLocation): number {\n\tif (a.path !== b.path) return a.path < b.path ? -1 : 1;\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\tif (a.range.end.line !== b.range.end.line) return a.range.end.line - b.range.end.line;\n\treturn a.range.end.character - b.range.end.character;\n}\n\nfunction dedupeSortAndCap(locations: LspLocation[], max: number): { locations: LspLocation[]; truncated: number } {\n\tconst seen = new Set<string>();\n\tconst unique: LspLocation[] = [];\n\tfor (const location of locations) {\n\t\tconst key = JSON.stringify(location);\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tunique.push(location);\n\t}\n\tunique.sort(compareLocations);\n\tconst capped = unique.slice(0, max);\n\treturn { locations: capped, truncated: unique.length - capped.length };\n}\n\nfunction isRawDocumentSymbol(value: unknown): value is Record<string, unknown> {\n\treturn isRecord(value) && typeof value.name === \"string\" && isRange(value.range) && isRange(value.selectionRange);\n}\n\nfunction flattenSymbols(raw: unknown, path: string): { symbols: LspSymbol[]; omitted: number } {\n\tconst symbols: LspSymbol[] = [];\n\tlet omitted = 0;\n\tconst visit = (value: unknown): void => {\n\t\tif (!Array.isArray(value)) return;\n\t\tfor (const item of value) {\n\t\t\tif (!isRawDocumentSymbol(item)) {\n\t\t\t\tomitted++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tsymbols.push({\n\t\t\t\tname: item.name as string,\n\t\t\t\tkind: typeof item.kind === \"number\" ? item.kind : 0,\n\t\t\t\tpath,\n\t\t\t\trange: toOneBasedRange(item.range as LspRange),\n\t\t\t\tselectionRange: toOneBasedRange(item.selectionRange as LspRange),\n\t\t\t\t...(typeof item.detail === \"string\" ? { detail: item.detail } : {}),\n\t\t\t});\n\t\t\tif (Array.isArray(item.children)) visit(item.children);\n\t\t}\n\t};\n\tvisit(Array.isArray(raw) ? raw : []);\n\treturn { symbols, omitted };\n}\n\nfunction compareSymbols(a: LspSymbol, b: LspSymbol): number {\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\treturn a.name === b.name ? 0 : a.name < b.name ? -1 : 1;\n}\n\nfunction capSymbols(symbols: LspSymbol[], max: number): { symbols: LspSymbol[]; truncated: number } {\n\tconst sorted = [...symbols].sort(compareSymbols);\n\tconst capped = sorted.slice(0, max);\n\treturn { symbols: capped, truncated: sorted.length - capped.length };\n}\n\nfunction formatNotices(omitted: number, truncated: number): string {\n\tconst notices: string[] = [];\n\tif (omitted > 0) notices.push(`${omitted} non-file result(s) omitted`);\n\tif (truncated > 0) notices.push(`${truncated} result(s) truncated`);\n\treturn notices.length > 0 ? `\\n\\n[${notices.join(\", \")}]` : \"\";\n}\n\nfunction formatLocationsText(\n\toperation: \"definition\" | \"references\",\n\tlocations: LspLocation[],\n\tomitted: number,\n\ttruncated: number,\n): string {\n\tif (locations.length === 0) {\n\t\treturn operation === \"definition\" ? \"No definition found.\" : \"No references found.\";\n\t}\n\tconst lines = locations.map(\n\t\t(location) => `${location.path}:${location.range.start.line}:${location.range.start.character}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nfunction formatSymbolsText(symbols: LspSymbol[], omitted: number, truncated: number): string {\n\tif (symbols.length === 0) return \"No symbols found.\";\n\tconst lines = symbols.map(\n\t\t(symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nexport function createLspToolDefinition(\n\tcwd: string,\n\toptions: LspToolOptions,\n): ApexToolDefinition<typeof lspSchema, LspToolDetails> {\n\tconst { operations } = options;\n\treturn {\n\t\tname: \"lsp\",\n\t\tlabel: \"lsp\",\n\t\tdescription: \"Query the configured language server for definitions, references, or symbols.\",\n\t\tparameters: lspSchema,\n\t\tcontract: {\n\t\t\t// `grep` spawns `rg` and declares {fs.read}, not {exec}, because the caller\n\t\t\t// never chooses what runs -- the executable, args, and closed JSON-RPC\n\t\t\t// method set all come from settings.json / this tool's own code. Same\n\t\t\t// reasoning here: {exec} would silently widen a delegation ceiling for no\n\t\t\t// capability the model can actually reach through this tool.\n\t\t\tcapabilities: new Set([\"fs.read\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"allow\",\n\t\t\t\tverb: \"Query\",\n\t\t\t\tgetPath: (params) => params.path,\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: true },\n\t\t\tevidence: { emits: new Set(), capture: () => [] },\n\t\t},\n\t\tasync execute(_toolCallId, input: LspToolInput, signal?: AbortSignal) {\n\t\t\tconst absolutePath = resolveToCwd(input.path, cwd);\n\t\t\tconst uri = pathToFileURL(absolutePath).href;\n\n\t\t\tif (input.operation === \"document_symbols\") {\n\t\t\t\tconst raw = await operations.request(\n\t\t\t\t\tabsolutePath,\n\t\t\t\t\t\"textDocument/documentSymbol\",\n\t\t\t\t\t{ textDocument: { uri } },\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t\tconst relativePath = formatPathRelativeToCwdOrAbsolute(absolutePath, cwd);\n\t\t\t\tconst { symbols, omitted } = flattenSymbols(raw, relativePath);\n\t\t\t\tconst { symbols: capped, truncated } = capSymbols(symbols, MAX_SYMBOLS);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: formatSymbolsText(capped, omitted, truncated) }],\n\t\t\t\t\tdetails: { operation: \"document_symbols\", symbols: capped, omitted, truncated },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst position = { line: input.line - 1, character: input.character - 1 };\n\t\t\tconst method = input.operation === \"definition\" ? \"textDocument/definition\" : \"textDocument/references\";\n\t\t\tconst params: Record<string, unknown> = { textDocument: { uri }, position };\n\t\t\tif (input.operation === \"references\") params.context = { includeDeclaration: true };\n\t\t\tconst raw = await operations.request(absolutePath, method, params, signal);\n\t\t\tconst { locations, omitted } = normalizeLocations(raw, cwd);\n\t\t\tconst { locations: capped, truncated } = dedupeSortAndCap(locations, MAX_LOCATIONS);\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: formatLocationsText(input.operation, capped, omitted, truncated) }],\n\t\t\t\tdetails: { operation: input.operation, locations: capped, omitted, truncated },\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport function createLspTool(cwd: string, options: LspToolOptions): AgentTool<typeof lspSchema> {\n\treturn wrapToolDefinition(createLspToolDefinition(cwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lsp.d.ts","sourceRoot":"","sources":["../../../src/core/tools/lsp.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,KAAK,kBAAkB,EAAa,MAAM,eAAe,CAAC;AA+CnE,QAAA,MAAM,SAAS;;;;;;;;;;;IAGd,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,S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AE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC3F;IACA,SAAS,EAAE,kBAAkB,CAAC;IAC9B,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEL;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC7B,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACvG;AAED,MAAM,WAAW,cAAc;IAC9B,UAAU,EAAE,aAAa,CAAC;CAC1B;AAqQD,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,cAAc,GACrB,kBAAkB,CAAC,OAAO,SAAS,EAAE,cAAc,CAAC,CAuGtD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,SAAS,CAAC,OAAO,SAAS,CAAC,CAE/F","sourcesContent":["import { isAbsolute, relative } from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport { type ApexToolDefinition, toolUnion } from \"./contract.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst MAX_LOCATIONS = 1_000;\nconst MAX_SYMBOLS = 2_000;\n/** Cap on the serialized symbol details so a result can never grow unbounded (spec § 4). */\nconst MAX_DETAILS_BYTES = 256 * 1024;\n\nconst lspNavigationSchema = Type.Object({\n\toperation: Type.Union([Type.Literal(\"definition\"), Type.Literal(\"references\")]),\n\tpath: Type.String(),\n\tline: Type.Number(),\n\tcharacter: Type.Number(),\n});\n\nconst lspDocumentSymbolsSchema = Type.Object({\n\toperation: Type.Literal(\"document_symbols\"),\n\tpath: Type.String(),\n});\n\nconst lspWorkspaceSymbolsSchema = Type.Object({\n\toperation: Type.Literal(\"workspace_symbol\"),\n\tquery: Type.String(),\n});\n\nconst lspSchemaProperties = {\n\toperation: Type.Union(\n\t\t[\n\t\t\tType.Literal(\"definition\"),\n\t\t\tType.Literal(\"references\"),\n\t\t\tType.Literal(\"document_symbols\"),\n\t\t\tType.Literal(\"workspace_symbol\"),\n\t\t],\n\t\t{ description: \"Which query to run.\" },\n\t),\n\tpath: Type.String({\n\t\tdescription: \"Path to the file (relative or absolute). Required by every operation but workspace_symbol.\",\n\t}),\n\tline: Type.Number({ description: \"One-based line number. Required by definition and references.\" }),\n\tcharacter: Type.Number({\n\t\tdescription: \"One-based UTF-16 character offset within the line. Required by definition and references.\",\n\t}),\n\tquery: Type.String({ description: \"The symbol name to search for. Required by workspace_symbol.\" }),\n};\n\nconst lspSchema = toolUnion(\n\t[lspNavigationSchema, lspDocumentSymbolsSchema, lspWorkspaceSymbolsSchema],\n\tlspSchemaProperties,\n);\n\nexport type LspToolInput = Static<typeof lspSchema>;\n\nexport interface LspPosition {\n\treadonly line: number;\n\treadonly character: number;\n}\n\nexport interface LspRange {\n\treadonly start: LspPosition;\n\treadonly end: LspPosition;\n}\n\n/** A navigation result normalized to a workspace-relative path and one-based range. */\nexport interface LspLocation {\n\treadonly path: string;\n\treadonly range: LspRange;\n}\n\n/** A flattened document symbol normalized to a workspace-relative path and one-based ranges. */\nexport interface LspSymbol {\n\treadonly name: string;\n\treadonly kind: number;\n\treadonly path: string;\n\treadonly range: LspRange;\n\treadonly selectionRange: LspRange;\n\treadonly detail?: string;\n}\n\n/** A workspace-wide symbol (LSP SymbolInformation) normalized like {@link LspSymbol} without a selection range. */\nexport interface LspWorkspaceSymbol {\n\treadonly name: string;\n\treadonly kind: number;\n\treadonly path: string;\n\treadonly range: LspRange;\n\treadonly containerName?: string;\n}\n\nexport type LspToolDetails =\n\t| { operation: \"definition\" | \"references\"; locations: LspLocation[]; omitted: number; truncated: number }\n\t| { operation: \"document_symbols\"; symbols: LspSymbol[]; omitted: number; truncated: number }\n\t| {\n\t\t\toperation: \"workspace_symbol\";\n\t\t\tsymbols: LspWorkspaceSymbol[];\n\t\t\tomitted: number;\n\t\t\ttruncated: number;\n\t\t\toutsideRoot: number;\n\t\t\tunsupported?: boolean;\n\t };\n\n/**\n * Pluggable transport for the `lsp` tool. The executable, its arguments, and the\n * closed JSON-RPC method set are all fixed by configuration the tool never chooses\n * itself -- see contract.capabilities below for why that keeps this `{fs.read}`\n * rather than `{exec}`.\n */\nexport interface LspOperations {\n\trequest(absolutePath: string, method: string, params: unknown, signal?: AbortSignal): Promise<unknown>;\n}\n\nexport interface LspToolOptions {\n\toperations: LspOperations;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isPosition(value: unknown): value is LspPosition {\n\treturn isRecord(value) && typeof value.line === \"number\" && typeof value.character === \"number\";\n}\n\nfunction isRange(value: unknown): value is LspRange {\n\treturn isRecord(value) && isPosition(value.start) && isPosition(value.end);\n}\n\nfunction toOneBasedPosition(position: LspPosition): LspPosition {\n\treturn { line: position.line + 1, character: position.character + 1 };\n}\n\nfunction toOneBasedRange(range: LspRange): LspRange {\n\treturn { start: toOneBasedPosition(range.start), end: toOneBasedPosition(range.end) };\n}\n\nfunction fileUriToAbsolutePath(uri: string): string | undefined {\n\tif (!uri.startsWith(\"file:\")) return undefined;\n\ttry {\n\t\treturn fileURLToPath(uri);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction rawLocationUriAndRange(value: unknown): { uri: string; range: LspRange } | undefined {\n\tif (!isRecord(value)) return undefined;\n\tif (typeof value.uri === \"string\" && isRange(value.range)) return { uri: value.uri, range: value.range };\n\tif (typeof value.targetUri === \"string\" && isRange(value.targetRange)) {\n\t\treturn { uri: value.targetUri, range: value.targetRange };\n\t}\n\treturn undefined;\n}\n\nfunction normalizeLocations(raw: unknown, cwd: string): { locations: LspLocation[]; omitted: number } {\n\tconst items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];\n\tconst locations: LspLocation[] = [];\n\tlet omitted = 0;\n\tfor (const item of items) {\n\t\tconst parsed = rawLocationUriAndRange(item);\n\t\tconst absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;\n\t\tif (!parsed || !absolutePath) {\n\t\t\tomitted++;\n\t\t\tcontinue;\n\t\t}\n\t\tlocations.push({\n\t\t\tpath: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),\n\t\t\trange: toOneBasedRange(parsed.range),\n\t\t});\n\t}\n\treturn { locations, omitted };\n}\n\nfunction compareLocations(a: LspLocation, b: LspLocation): number {\n\tif (a.path !== b.path) return a.path < b.path ? -1 : 1;\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\tif (a.range.end.line !== b.range.end.line) return a.range.end.line - b.range.end.line;\n\treturn a.range.end.character - b.range.end.character;\n}\n\nfunction dedupeSortAndCap(locations: LspLocation[], max: number): { locations: LspLocation[]; truncated: number } {\n\tconst seen = new Set<string>();\n\tconst unique: LspLocation[] = [];\n\tfor (const location of locations) {\n\t\tconst key = JSON.stringify(location);\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tunique.push(location);\n\t}\n\tunique.sort(compareLocations);\n\tconst capped = unique.slice(0, max);\n\treturn { locations: capped, truncated: unique.length - capped.length };\n}\n\nfunction isRawDocumentSymbol(value: unknown): value is Record<string, unknown> {\n\treturn isRecord(value) && typeof value.name === \"string\" && isRange(value.range) && isRange(value.selectionRange);\n}\n\nfunction flattenSymbols(raw: unknown, path: string): { symbols: LspSymbol[]; omitted: number } {\n\tconst symbols: LspSymbol[] = [];\n\tlet omitted = 0;\n\tconst visit = (value: unknown): void => {\n\t\tif (!Array.isArray(value)) return;\n\t\tfor (const item of value) {\n\t\t\tif (!isRawDocumentSymbol(item)) {\n\t\t\t\tomitted++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tsymbols.push({\n\t\t\t\tname: item.name as string,\n\t\t\t\tkind: typeof item.kind === \"number\" ? item.kind : 0,\n\t\t\t\tpath,\n\t\t\t\trange: toOneBasedRange(item.range as LspRange),\n\t\t\t\tselectionRange: toOneBasedRange(item.selectionRange as LspRange),\n\t\t\t\t...(typeof item.detail === \"string\" ? { detail: item.detail } : {}),\n\t\t\t});\n\t\t\tif (Array.isArray(item.children)) visit(item.children);\n\t\t}\n\t};\n\tvisit(Array.isArray(raw) ? raw : []);\n\treturn { symbols, omitted };\n}\n\nfunction compareSymbols(a: LspSymbol, b: LspSymbol): number {\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\treturn a.name === b.name ? 0 : a.name < b.name ? -1 : 1;\n}\n\nfunction capSymbols(symbols: LspSymbol[], max: number): { symbols: LspSymbol[]; truncated: number } {\n\tconst sorted = [...symbols].sort(compareSymbols);\n\tconst capped = sorted.slice(0, max);\n\treturn { symbols: capped, truncated: sorted.length - capped.length };\n}\n\nfunction isInsideRoot(absolutePath: string, root: string): boolean {\n\tconst rel = relative(root, absolutePath);\n\treturn rel === \"\" || (!rel.startsWith(\"..\") && !isAbsolute(rel));\n}\n\nfunction rawWorkspaceSymbol(value: unknown): { name: string; kind: number; containerName?: string } | undefined {\n\tif (!isRecord(value) || typeof value.name !== \"string\") return undefined;\n\treturn {\n\t\tname: value.name,\n\t\tkind: typeof value.kind === \"number\" ? value.kind : 0,\n\t\t...(typeof value.containerName === \"string\" ? { containerName: value.containerName } : {}),\n\t};\n}\n\n/**\n * Normalize `workspace/symbol` SymbolInformation results: file URIs to\n * workspace-relative paths, zero-based ranges to one-based, and every result\n * outside the authorized root dropped with an honest count (spec § 4: the\n * root is never widened because a result points outside it).\n */\nfunction normalizeWorkspaceSymbols(\n\traw: unknown,\n\tcwd: string,\n): { symbols: LspWorkspaceSymbol[]; omitted: number; outsideRoot: number } {\n\tconst items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];\n\tconst symbols: LspWorkspaceSymbol[] = [];\n\tlet omitted = 0;\n\tlet outsideRoot = 0;\n\tfor (const item of items) {\n\t\tconst parsed = rawLocationUriAndRange(isRecord(item) ? (item.location ?? item) : undefined);\n\t\tconst absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;\n\t\tconst info = rawWorkspaceSymbol(item);\n\t\tif (!parsed || !absolutePath || !info) {\n\t\t\tomitted++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!isInsideRoot(absolutePath, cwd)) {\n\t\t\toutsideRoot++;\n\t\t\tcontinue;\n\t\t}\n\t\tsymbols.push({\n\t\t\t...info,\n\t\t\tpath: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),\n\t\t\trange: toOneBasedRange(parsed.range),\n\t\t});\n\t}\n\treturn { symbols, omitted, outsideRoot };\n}\n\nfunction compareWorkspaceSymbols(a: LspWorkspaceSymbol, b: LspWorkspaceSymbol): number {\n\tif (a.path !== b.path) return a.path < b.path ? -1 : 1;\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\treturn a.name === b.name ? 0 : a.name < b.name ? -1 : 1;\n}\n\nfunction capWorkspaceSymbolsByCount(\n\tsymbols: LspWorkspaceSymbol[],\n\tmax: number,\n): { symbols: LspWorkspaceSymbol[]; truncated: number } {\n\tconst sorted = [...symbols].sort(compareWorkspaceSymbols);\n\tconst capped = sorted.slice(0, max);\n\treturn { symbols: capped, truncated: sorted.length - capped.length };\n}\n\nfunction capWorkspaceSymbolsByBytes(\n\tsymbols: LspWorkspaceSymbol[],\n\tmaxBytes: number,\n): { symbols: LspWorkspaceSymbol[]; truncated: number } {\n\tlet used = 2; // \"[]\"\n\tfor (let i = 0; i < symbols.length; i++) {\n\t\tconst cost = Buffer.byteLength(JSON.stringify(symbols[i]), \"utf-8\") + 1;\n\t\tif (used + cost > maxBytes) {\n\t\t\treturn { symbols: symbols.slice(0, i), truncated: symbols.length - i };\n\t\t}\n\t\tused += cost;\n\t}\n\treturn { symbols, truncated: 0 };\n}\n\nfunction isUnsupportedMethodError(error: unknown): boolean {\n\tconst message = error instanceof Error ? error.message : String(error);\n\treturn message.includes(\"-32601\") || /method not found/i.test(message);\n}\n\nfunction formatWorkspaceSymbolsNotices(omitted: number, truncated: number, outsideRoot: number): string {\n\tconst notices: string[] = [];\n\tif (omitted > 0) notices.push(`${omitted} non-file result(s) omitted`);\n\tif (outsideRoot > 0) notices.push(`${outsideRoot} result(s) outside the workspace root omitted`);\n\tif (truncated > 0) notices.push(`${truncated} result(s) truncated`);\n\treturn notices.length > 0 ? `\\n\\n[${notices.join(\", \")}]` : \"\";\n}\n\nfunction formatWorkspaceSymbolsText(\n\tsymbols: LspWorkspaceSymbol[],\n\tomitted: number,\n\ttruncated: number,\n\toutsideRoot: number,\n): string {\n\tif (symbols.length === 0) {\n\t\tconst base = \"No symbols found.\";\n\t\tconst notices = formatWorkspaceSymbolsNotices(omitted, truncated, outsideRoot);\n\t\treturn notices ? `${base}${notices}` : base;\n\t}\n\tconst lines = symbols.map(\n\t\t(symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatWorkspaceSymbolsNotices(omitted, truncated, outsideRoot)}`;\n}\n\nfunction formatNotices(omitted: number, truncated: number): string {\n\tconst notices: string[] = [];\n\tif (omitted > 0) notices.push(`${omitted} non-file result(s) omitted`);\n\tif (truncated > 0) notices.push(`${truncated} result(s) truncated`);\n\treturn notices.length > 0 ? `\\n\\n[${notices.join(\", \")}]` : \"\";\n}\n\nfunction formatLocationsText(\n\toperation: \"definition\" | \"references\",\n\tlocations: LspLocation[],\n\tomitted: number,\n\ttruncated: number,\n): string {\n\tif (locations.length === 0) {\n\t\treturn operation === \"definition\" ? \"No definition found.\" : \"No references found.\";\n\t}\n\tconst lines = locations.map(\n\t\t(location) => `${location.path}:${location.range.start.line}:${location.range.start.character}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nfunction formatSymbolsText(symbols: LspSymbol[], omitted: number, truncated: number): string {\n\tif (symbols.length === 0) return \"No symbols found.\";\n\tconst lines = symbols.map(\n\t\t(symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nexport function createLspToolDefinition(\n\tcwd: string,\n\toptions: LspToolOptions,\n): ApexToolDefinition<typeof lspSchema, LspToolDetails> {\n\tconst { operations } = options;\n\treturn {\n\t\tname: \"lsp\",\n\t\tlabel: \"lsp\",\n\t\tdescription: \"Query the configured language server for definitions, references, or symbols.\",\n\t\tparameters: lspSchema,\n\t\tcontract: {\n\t\t\t// `grep` spawns `rg` and declares {fs.read}, not {exec}, because the caller\n\t\t\t// never chooses what runs -- the executable, args, and closed JSON-RPC\n\t\t\t// method set all come from settings.json / this tool's own code. Same\n\t\t\t// reasoning here: {exec} would silently widen a delegation ceiling for no\n\t\t\t// capability the model can actually reach through this tool.\n\t\t\tcapabilities: new Set([\"fs.read\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"allow\",\n\t\t\t\tverb: \"Query\",\n\t\t\t\t// A workspace_symbol call has no path; returning undefined normalizes to\n\t\t\t\t// the workspace root, so the same gate authorizes the root before the\n\t\t\t\t// request is sent and `ruleForCall` stays inside one grammar.\n\t\t\t\tgetPath: (params) => (\"path\" in params ? params.path : undefined),\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: true },\n\t\t\tevidence: { emits: new Set(), capture: () => [] },\n\t\t},\n\t\tasync execute(_toolCallId, input: LspToolInput, signal?: AbortSignal) {\n\t\t\tif (input.operation === \"workspace_symbol\") {\n\t\t\t\t// The permission gate has already authorized the workspace root by the\n\t\t\t\t// time execute runs; only now does the request go out.\n\t\t\t\ttry {\n\t\t\t\t\tconst raw = await operations.request(cwd, \"workspace/symbol\", { query: input.query }, signal);\n\t\t\t\t\tconst { symbols, omitted, outsideRoot } = normalizeWorkspaceSymbols(raw, cwd);\n\t\t\t\t\tconst { symbols: countCapped, truncated: countTruncated } = capWorkspaceSymbolsByCount(\n\t\t\t\t\t\tsymbols,\n\t\t\t\t\t\tMAX_SYMBOLS,\n\t\t\t\t\t);\n\t\t\t\t\tconst { symbols: capped, truncated: byteTruncated } = capWorkspaceSymbolsByBytes(\n\t\t\t\t\t\tcountCapped,\n\t\t\t\t\t\tMAX_DETAILS_BYTES,\n\t\t\t\t\t);\n\t\t\t\t\tconst truncated = countTruncated + byteTruncated;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\", text: formatWorkspaceSymbolsText(capped, omitted, truncated, outsideRoot) },\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { operation: \"workspace_symbol\", symbols: capped, omitted, truncated, outsideRoot },\n\t\t\t\t\t};\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (isUnsupportedMethodError(error)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\t\ttext: \"workspace_symbol is not supported by the configured language server.\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\toperation: \"workspace_symbol\",\n\t\t\t\t\t\t\t\tsymbols: [],\n\t\t\t\t\t\t\t\tomitted: 0,\n\t\t\t\t\t\t\t\ttruncated: 0,\n\t\t\t\t\t\t\t\toutsideRoot: 0,\n\t\t\t\t\t\t\t\tunsupported: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst absolutePath = resolveToCwd(input.path, cwd);\n\t\t\tconst uri = pathToFileURL(absolutePath).href;\n\n\t\t\tif (input.operation === \"document_symbols\") {\n\t\t\t\tconst raw = await operations.request(\n\t\t\t\t\tabsolutePath,\n\t\t\t\t\t\"textDocument/documentSymbol\",\n\t\t\t\t\t{ textDocument: { uri } },\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t\tconst relativePath = formatPathRelativeToCwdOrAbsolute(absolutePath, cwd);\n\t\t\t\tconst { symbols, omitted } = flattenSymbols(raw, relativePath);\n\t\t\t\tconst { symbols: capped, truncated } = capSymbols(symbols, MAX_SYMBOLS);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: formatSymbolsText(capped, omitted, truncated) }],\n\t\t\t\t\tdetails: { operation: \"document_symbols\", symbols: capped, omitted, truncated },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst position = { line: input.line - 1, character: input.character - 1 };\n\t\t\tconst method = input.operation === \"definition\" ? \"textDocument/definition\" : \"textDocument/references\";\n\t\t\tconst params: Record<string, unknown> = { textDocument: { uri }, position };\n\t\t\tif (input.operation === \"references\") params.context = { includeDeclaration: true };\n\t\t\tconst raw = await operations.request(absolutePath, method, params, signal);\n\t\t\tconst { locations, omitted } = normalizeLocations(raw, cwd);\n\t\t\tconst { locations: capped, truncated } = dedupeSortAndCap(locations, MAX_LOCATIONS);\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: formatLocationsText(input.operation, capped, omitted, truncated) }],\n\t\t\t\tdetails: { operation: input.operation, locations: capped, omitted, truncated },\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport function createLspTool(cwd: string, options: LspToolOptions): AgentTool<typeof lspSchema> {\n\treturn wrapToolDefinition(createLspToolDefinition(cwd, options));\n}\n"]}
|
package/dist/core/tools/lsp.js
CHANGED
|
@@ -1,24 +1,46 @@
|
|
|
1
|
+
import { isAbsolute, relative } from "node:path";
|
|
1
2
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
2
3
|
import { Type } from "typebox";
|
|
3
4
|
import { formatPathRelativeToCwdOrAbsolute } from "../../utils/paths.js";
|
|
5
|
+
import { toolUnion } from "./contract.js";
|
|
4
6
|
import { createPathPermissionSpec } from "./path-permission.js";
|
|
5
7
|
import { resolveToCwd } from "./path-utils.js";
|
|
6
8
|
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
7
9
|
const MAX_LOCATIONS = 1_000;
|
|
8
10
|
const MAX_SYMBOLS = 2_000;
|
|
11
|
+
/** Cap on the serialized symbol details so a result can never grow unbounded (spec § 4). */
|
|
12
|
+
const MAX_DETAILS_BYTES = 256 * 1024;
|
|
9
13
|
const lspNavigationSchema = Type.Object({
|
|
10
|
-
operation: Type.Union([Type.Literal("definition"), Type.Literal("references")],
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
line: Type.Number({ description: "One-based line number." }),
|
|
15
|
-
character: Type.Number({ description: "One-based UTF-16 character offset within the line." }),
|
|
14
|
+
operation: Type.Union([Type.Literal("definition"), Type.Literal("references")]),
|
|
15
|
+
path: Type.String(),
|
|
16
|
+
line: Type.Number(),
|
|
17
|
+
character: Type.Number(),
|
|
16
18
|
});
|
|
17
19
|
const lspDocumentSymbolsSchema = Type.Object({
|
|
18
|
-
operation: Type.Literal("document_symbols"
|
|
19
|
-
path: Type.String(
|
|
20
|
+
operation: Type.Literal("document_symbols"),
|
|
21
|
+
path: Type.String(),
|
|
22
|
+
});
|
|
23
|
+
const lspWorkspaceSymbolsSchema = Type.Object({
|
|
24
|
+
operation: Type.Literal("workspace_symbol"),
|
|
25
|
+
query: Type.String(),
|
|
20
26
|
});
|
|
21
|
-
const
|
|
27
|
+
const lspSchemaProperties = {
|
|
28
|
+
operation: Type.Union([
|
|
29
|
+
Type.Literal("definition"),
|
|
30
|
+
Type.Literal("references"),
|
|
31
|
+
Type.Literal("document_symbols"),
|
|
32
|
+
Type.Literal("workspace_symbol"),
|
|
33
|
+
], { description: "Which query to run." }),
|
|
34
|
+
path: Type.String({
|
|
35
|
+
description: "Path to the file (relative or absolute). Required by every operation but workspace_symbol.",
|
|
36
|
+
}),
|
|
37
|
+
line: Type.Number({ description: "One-based line number. Required by definition and references." }),
|
|
38
|
+
character: Type.Number({
|
|
39
|
+
description: "One-based UTF-16 character offset within the line. Required by definition and references.",
|
|
40
|
+
}),
|
|
41
|
+
query: Type.String({ description: "The symbol name to search for. Required by workspace_symbol." }),
|
|
42
|
+
};
|
|
43
|
+
const lspSchema = toolUnion([lspNavigationSchema, lspDocumentSymbolsSchema, lspWorkspaceSymbolsSchema], lspSchemaProperties);
|
|
22
44
|
function isRecord(value) {
|
|
23
45
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24
46
|
}
|
|
@@ -138,6 +160,96 @@ function capSymbols(symbols, max) {
|
|
|
138
160
|
const capped = sorted.slice(0, max);
|
|
139
161
|
return { symbols: capped, truncated: sorted.length - capped.length };
|
|
140
162
|
}
|
|
163
|
+
function isInsideRoot(absolutePath, root) {
|
|
164
|
+
const rel = relative(root, absolutePath);
|
|
165
|
+
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
|
|
166
|
+
}
|
|
167
|
+
function rawWorkspaceSymbol(value) {
|
|
168
|
+
if (!isRecord(value) || typeof value.name !== "string")
|
|
169
|
+
return undefined;
|
|
170
|
+
return {
|
|
171
|
+
name: value.name,
|
|
172
|
+
kind: typeof value.kind === "number" ? value.kind : 0,
|
|
173
|
+
...(typeof value.containerName === "string" ? { containerName: value.containerName } : {}),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Normalize `workspace/symbol` SymbolInformation results: file URIs to
|
|
178
|
+
* workspace-relative paths, zero-based ranges to one-based, and every result
|
|
179
|
+
* outside the authorized root dropped with an honest count (spec § 4: the
|
|
180
|
+
* root is never widened because a result points outside it).
|
|
181
|
+
*/
|
|
182
|
+
function normalizeWorkspaceSymbols(raw, cwd) {
|
|
183
|
+
const items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];
|
|
184
|
+
const symbols = [];
|
|
185
|
+
let omitted = 0;
|
|
186
|
+
let outsideRoot = 0;
|
|
187
|
+
for (const item of items) {
|
|
188
|
+
const parsed = rawLocationUriAndRange(isRecord(item) ? (item.location ?? item) : undefined);
|
|
189
|
+
const absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;
|
|
190
|
+
const info = rawWorkspaceSymbol(item);
|
|
191
|
+
if (!parsed || !absolutePath || !info) {
|
|
192
|
+
omitted++;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (!isInsideRoot(absolutePath, cwd)) {
|
|
196
|
+
outsideRoot++;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
symbols.push({
|
|
200
|
+
...info,
|
|
201
|
+
path: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),
|
|
202
|
+
range: toOneBasedRange(parsed.range),
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
return { symbols, omitted, outsideRoot };
|
|
206
|
+
}
|
|
207
|
+
function compareWorkspaceSymbols(a, b) {
|
|
208
|
+
if (a.path !== b.path)
|
|
209
|
+
return a.path < b.path ? -1 : 1;
|
|
210
|
+
if (a.range.start.line !== b.range.start.line)
|
|
211
|
+
return a.range.start.line - b.range.start.line;
|
|
212
|
+
return a.name === b.name ? 0 : a.name < b.name ? -1 : 1;
|
|
213
|
+
}
|
|
214
|
+
function capWorkspaceSymbolsByCount(symbols, max) {
|
|
215
|
+
const sorted = [...symbols].sort(compareWorkspaceSymbols);
|
|
216
|
+
const capped = sorted.slice(0, max);
|
|
217
|
+
return { symbols: capped, truncated: sorted.length - capped.length };
|
|
218
|
+
}
|
|
219
|
+
function capWorkspaceSymbolsByBytes(symbols, maxBytes) {
|
|
220
|
+
let used = 2; // "[]"
|
|
221
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
222
|
+
const cost = Buffer.byteLength(JSON.stringify(symbols[i]), "utf-8") + 1;
|
|
223
|
+
if (used + cost > maxBytes) {
|
|
224
|
+
return { symbols: symbols.slice(0, i), truncated: symbols.length - i };
|
|
225
|
+
}
|
|
226
|
+
used += cost;
|
|
227
|
+
}
|
|
228
|
+
return { symbols, truncated: 0 };
|
|
229
|
+
}
|
|
230
|
+
function isUnsupportedMethodError(error) {
|
|
231
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
232
|
+
return message.includes("-32601") || /method not found/i.test(message);
|
|
233
|
+
}
|
|
234
|
+
function formatWorkspaceSymbolsNotices(omitted, truncated, outsideRoot) {
|
|
235
|
+
const notices = [];
|
|
236
|
+
if (omitted > 0)
|
|
237
|
+
notices.push(`${omitted} non-file result(s) omitted`);
|
|
238
|
+
if (outsideRoot > 0)
|
|
239
|
+
notices.push(`${outsideRoot} result(s) outside the workspace root omitted`);
|
|
240
|
+
if (truncated > 0)
|
|
241
|
+
notices.push(`${truncated} result(s) truncated`);
|
|
242
|
+
return notices.length > 0 ? `\n\n[${notices.join(", ")}]` : "";
|
|
243
|
+
}
|
|
244
|
+
function formatWorkspaceSymbolsText(symbols, omitted, truncated, outsideRoot) {
|
|
245
|
+
if (symbols.length === 0) {
|
|
246
|
+
const base = "No symbols found.";
|
|
247
|
+
const notices = formatWorkspaceSymbolsNotices(omitted, truncated, outsideRoot);
|
|
248
|
+
return notices ? `${base}${notices}` : base;
|
|
249
|
+
}
|
|
250
|
+
const lines = symbols.map((symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`);
|
|
251
|
+
return `${lines.join("\n")}${formatWorkspaceSymbolsNotices(omitted, truncated, outsideRoot)}`;
|
|
252
|
+
}
|
|
141
253
|
function formatNotices(omitted, truncated) {
|
|
142
254
|
const notices = [];
|
|
143
255
|
if (omitted > 0)
|
|
@@ -177,12 +289,53 @@ export function createLspToolDefinition(cwd, options) {
|
|
|
177
289
|
cwd,
|
|
178
290
|
defaultBehavior: "allow",
|
|
179
291
|
verb: "Query",
|
|
180
|
-
|
|
292
|
+
// A workspace_symbol call has no path; returning undefined normalizes to
|
|
293
|
+
// the workspace root, so the same gate authorizes the root before the
|
|
294
|
+
// request is sent and `ruleForCall` stays inside one grammar.
|
|
295
|
+
getPath: (params) => ("path" in params ? params.path : undefined),
|
|
181
296
|
}),
|
|
182
297
|
context: { resultRecoverable: true, deferSchema: true },
|
|
183
298
|
evidence: { emits: new Set(), capture: () => [] },
|
|
184
299
|
},
|
|
185
300
|
async execute(_toolCallId, input, signal) {
|
|
301
|
+
if (input.operation === "workspace_symbol") {
|
|
302
|
+
// The permission gate has already authorized the workspace root by the
|
|
303
|
+
// time execute runs; only now does the request go out.
|
|
304
|
+
try {
|
|
305
|
+
const raw = await operations.request(cwd, "workspace/symbol", { query: input.query }, signal);
|
|
306
|
+
const { symbols, omitted, outsideRoot } = normalizeWorkspaceSymbols(raw, cwd);
|
|
307
|
+
const { symbols: countCapped, truncated: countTruncated } = capWorkspaceSymbolsByCount(symbols, MAX_SYMBOLS);
|
|
308
|
+
const { symbols: capped, truncated: byteTruncated } = capWorkspaceSymbolsByBytes(countCapped, MAX_DETAILS_BYTES);
|
|
309
|
+
const truncated = countTruncated + byteTruncated;
|
|
310
|
+
return {
|
|
311
|
+
content: [
|
|
312
|
+
{ type: "text", text: formatWorkspaceSymbolsText(capped, omitted, truncated, outsideRoot) },
|
|
313
|
+
],
|
|
314
|
+
details: { operation: "workspace_symbol", symbols: capped, omitted, truncated, outsideRoot },
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
if (isUnsupportedMethodError(error)) {
|
|
319
|
+
return {
|
|
320
|
+
content: [
|
|
321
|
+
{
|
|
322
|
+
type: "text",
|
|
323
|
+
text: "workspace_symbol is not supported by the configured language server.",
|
|
324
|
+
},
|
|
325
|
+
],
|
|
326
|
+
details: {
|
|
327
|
+
operation: "workspace_symbol",
|
|
328
|
+
symbols: [],
|
|
329
|
+
omitted: 0,
|
|
330
|
+
truncated: 0,
|
|
331
|
+
outsideRoot: 0,
|
|
332
|
+
unsupported: true,
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
throw error;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
186
339
|
const absolutePath = resolveToCwd(input.path, cwd);
|
|
187
340
|
const uri = pathToFileURL(absolutePath).href;
|
|
188
341
|
if (input.operation === "document_symbols") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lsp.js","sourceRoot":"","sources":["../../../src/core/tools/lsp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAExD,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,iCAAiC,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,aAAa,GAAG,KAAK,CAAC;AAC5B,MAAM,WAAW,GAAG,KAAK,CAAC;AAE1B,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC;IACvC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE;QAC/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CAAC;YAC5D,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;YACpF,OAAO;gBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC;gBACnG,OAAO,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE;aAC9E,CAAC;QAAA,CACF;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,OAAuB,EAA+B;IAChG,OAAO,kBAAkB,CAAC,uBAAuB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CACjE","sourcesContent":["import { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst MAX_LOCATIONS = 1_000;\nconst MAX_SYMBOLS = 2_000;\n\nconst lspNavigationSchema = Type.Object({\n\toperation: Type.Union([Type.Literal(\"definition\"), Type.Literal(\"references\")], {\n\t\tdescription: \"Which navigation query to run.\",\n\t}),\n\tpath: Type.String({ description: \"Path to the file (relative or absolute).\" }),\n\tline: Type.Number({ description: \"One-based line number.\" }),\n\tcharacter: Type.Number({ description: \"One-based UTF-16 character offset within the line.\" }),\n});\n\nconst lspDocumentSymbolsSchema = Type.Object({\n\toperation: Type.Literal(\"document_symbols\", { description: \"List the symbols declared in a file.\" }),\n\tpath: Type.String({ description: \"Path to the file (relative or absolute).\" }),\n});\n\nconst lspSchema = Type.Union([lspNavigationSchema, lspDocumentSymbolsSchema]);\n\nexport type LspToolInput = Static<typeof lspSchema>;\n\nexport interface LspPosition {\n\treadonly line: number;\n\treadonly character: number;\n}\n\nexport interface LspRange {\n\treadonly start: LspPosition;\n\treadonly end: LspPosition;\n}\n\n/** A navigation result normalized to a workspace-relative path and one-based range. */\nexport interface LspLocation {\n\treadonly path: string;\n\treadonly range: LspRange;\n}\n\n/** A flattened document symbol normalized to a workspace-relative path and one-based ranges. */\nexport interface LspSymbol {\n\treadonly name: string;\n\treadonly kind: number;\n\treadonly path: string;\n\treadonly range: LspRange;\n\treadonly selectionRange: LspRange;\n\treadonly detail?: string;\n}\n\nexport type LspToolDetails =\n\t| { operation: \"definition\" | \"references\"; locations: LspLocation[]; omitted: number; truncated: number }\n\t| { operation: \"document_symbols\"; symbols: LspSymbol[]; omitted: number; truncated: number };\n\n/**\n * Pluggable transport for the `lsp` tool. The executable, its arguments, and the\n * closed JSON-RPC method set are all fixed by configuration the tool never chooses\n * itself -- see contract.capabilities below for why that keeps this `{fs.read}`\n * rather than `{exec}`.\n */\nexport interface LspOperations {\n\trequest(absolutePath: string, method: string, params: unknown, signal?: AbortSignal): Promise<unknown>;\n}\n\nexport interface LspToolOptions {\n\toperations: LspOperations;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isPosition(value: unknown): value is LspPosition {\n\treturn isRecord(value) && typeof value.line === \"number\" && typeof value.character === \"number\";\n}\n\nfunction isRange(value: unknown): value is LspRange {\n\treturn isRecord(value) && isPosition(value.start) && isPosition(value.end);\n}\n\nfunction toOneBasedPosition(position: LspPosition): LspPosition {\n\treturn { line: position.line + 1, character: position.character + 1 };\n}\n\nfunction toOneBasedRange(range: LspRange): LspRange {\n\treturn { start: toOneBasedPosition(range.start), end: toOneBasedPosition(range.end) };\n}\n\nfunction fileUriToAbsolutePath(uri: string): string | undefined {\n\tif (!uri.startsWith(\"file:\")) return undefined;\n\ttry {\n\t\treturn fileURLToPath(uri);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction rawLocationUriAndRange(value: unknown): { uri: string; range: LspRange } | undefined {\n\tif (!isRecord(value)) return undefined;\n\tif (typeof value.uri === \"string\" && isRange(value.range)) return { uri: value.uri, range: value.range };\n\tif (typeof value.targetUri === \"string\" && isRange(value.targetRange)) {\n\t\treturn { uri: value.targetUri, range: value.targetRange };\n\t}\n\treturn undefined;\n}\n\nfunction normalizeLocations(raw: unknown, cwd: string): { locations: LspLocation[]; omitted: number } {\n\tconst items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];\n\tconst locations: LspLocation[] = [];\n\tlet omitted = 0;\n\tfor (const item of items) {\n\t\tconst parsed = rawLocationUriAndRange(item);\n\t\tconst absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;\n\t\tif (!parsed || !absolutePath) {\n\t\t\tomitted++;\n\t\t\tcontinue;\n\t\t}\n\t\tlocations.push({\n\t\t\tpath: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),\n\t\t\trange: toOneBasedRange(parsed.range),\n\t\t});\n\t}\n\treturn { locations, omitted };\n}\n\nfunction compareLocations(a: LspLocation, b: LspLocation): number {\n\tif (a.path !== b.path) return a.path < b.path ? -1 : 1;\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\tif (a.range.end.line !== b.range.end.line) return a.range.end.line - b.range.end.line;\n\treturn a.range.end.character - b.range.end.character;\n}\n\nfunction dedupeSortAndCap(locations: LspLocation[], max: number): { locations: LspLocation[]; truncated: number } {\n\tconst seen = new Set<string>();\n\tconst unique: LspLocation[] = [];\n\tfor (const location of locations) {\n\t\tconst key = JSON.stringify(location);\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tunique.push(location);\n\t}\n\tunique.sort(compareLocations);\n\tconst capped = unique.slice(0, max);\n\treturn { locations: capped, truncated: unique.length - capped.length };\n}\n\nfunction isRawDocumentSymbol(value: unknown): value is Record<string, unknown> {\n\treturn isRecord(value) && typeof value.name === \"string\" && isRange(value.range) && isRange(value.selectionRange);\n}\n\nfunction flattenSymbols(raw: unknown, path: string): { symbols: LspSymbol[]; omitted: number } {\n\tconst symbols: LspSymbol[] = [];\n\tlet omitted = 0;\n\tconst visit = (value: unknown): void => {\n\t\tif (!Array.isArray(value)) return;\n\t\tfor (const item of value) {\n\t\t\tif (!isRawDocumentSymbol(item)) {\n\t\t\t\tomitted++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tsymbols.push({\n\t\t\t\tname: item.name as string,\n\t\t\t\tkind: typeof item.kind === \"number\" ? item.kind : 0,\n\t\t\t\tpath,\n\t\t\t\trange: toOneBasedRange(item.range as LspRange),\n\t\t\t\tselectionRange: toOneBasedRange(item.selectionRange as LspRange),\n\t\t\t\t...(typeof item.detail === \"string\" ? { detail: item.detail } : {}),\n\t\t\t});\n\t\t\tif (Array.isArray(item.children)) visit(item.children);\n\t\t}\n\t};\n\tvisit(Array.isArray(raw) ? raw : []);\n\treturn { symbols, omitted };\n}\n\nfunction compareSymbols(a: LspSymbol, b: LspSymbol): number {\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\treturn a.name === b.name ? 0 : a.name < b.name ? -1 : 1;\n}\n\nfunction capSymbols(symbols: LspSymbol[], max: number): { symbols: LspSymbol[]; truncated: number } {\n\tconst sorted = [...symbols].sort(compareSymbols);\n\tconst capped = sorted.slice(0, max);\n\treturn { symbols: capped, truncated: sorted.length - capped.length };\n}\n\nfunction formatNotices(omitted: number, truncated: number): string {\n\tconst notices: string[] = [];\n\tif (omitted > 0) notices.push(`${omitted} non-file result(s) omitted`);\n\tif (truncated > 0) notices.push(`${truncated} result(s) truncated`);\n\treturn notices.length > 0 ? `\\n\\n[${notices.join(\", \")}]` : \"\";\n}\n\nfunction formatLocationsText(\n\toperation: \"definition\" | \"references\",\n\tlocations: LspLocation[],\n\tomitted: number,\n\ttruncated: number,\n): string {\n\tif (locations.length === 0) {\n\t\treturn operation === \"definition\" ? \"No definition found.\" : \"No references found.\";\n\t}\n\tconst lines = locations.map(\n\t\t(location) => `${location.path}:${location.range.start.line}:${location.range.start.character}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nfunction formatSymbolsText(symbols: LspSymbol[], omitted: number, truncated: number): string {\n\tif (symbols.length === 0) return \"No symbols found.\";\n\tconst lines = symbols.map(\n\t\t(symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nexport function createLspToolDefinition(\n\tcwd: string,\n\toptions: LspToolOptions,\n): ApexToolDefinition<typeof lspSchema, LspToolDetails> {\n\tconst { operations } = options;\n\treturn {\n\t\tname: \"lsp\",\n\t\tlabel: \"lsp\",\n\t\tdescription: \"Query the configured language server for definitions, references, or symbols.\",\n\t\tparameters: lspSchema,\n\t\tcontract: {\n\t\t\t// `grep` spawns `rg` and declares {fs.read}, not {exec}, because the caller\n\t\t\t// never chooses what runs -- the executable, args, and closed JSON-RPC\n\t\t\t// method set all come from settings.json / this tool's own code. Same\n\t\t\t// reasoning here: {exec} would silently widen a delegation ceiling for no\n\t\t\t// capability the model can actually reach through this tool.\n\t\t\tcapabilities: new Set([\"fs.read\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"allow\",\n\t\t\t\tverb: \"Query\",\n\t\t\t\tgetPath: (params) => params.path,\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: true },\n\t\t\tevidence: { emits: new Set(), capture: () => [] },\n\t\t},\n\t\tasync execute(_toolCallId, input: LspToolInput, signal?: AbortSignal) {\n\t\t\tconst absolutePath = resolveToCwd(input.path, cwd);\n\t\t\tconst uri = pathToFileURL(absolutePath).href;\n\n\t\t\tif (input.operation === \"document_symbols\") {\n\t\t\t\tconst raw = await operations.request(\n\t\t\t\t\tabsolutePath,\n\t\t\t\t\t\"textDocument/documentSymbol\",\n\t\t\t\t\t{ textDocument: { uri } },\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t\tconst relativePath = formatPathRelativeToCwdOrAbsolute(absolutePath, cwd);\n\t\t\t\tconst { symbols, omitted } = flattenSymbols(raw, relativePath);\n\t\t\t\tconst { symbols: capped, truncated } = capSymbols(symbols, MAX_SYMBOLS);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: formatSymbolsText(capped, omitted, truncated) }],\n\t\t\t\t\tdetails: { operation: \"document_symbols\", symbols: capped, omitted, truncated },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst position = { line: input.line - 1, character: input.character - 1 };\n\t\t\tconst method = input.operation === \"definition\" ? \"textDocument/definition\" : \"textDocument/references\";\n\t\t\tconst params: Record<string, unknown> = { textDocument: { uri }, position };\n\t\t\tif (input.operation === \"references\") params.context = { includeDeclaration: true };\n\t\t\tconst raw = await operations.request(absolutePath, method, params, signal);\n\t\t\tconst { locations, omitted } = normalizeLocations(raw, cwd);\n\t\t\tconst { locations: capped, truncated } = dedupeSortAndCap(locations, MAX_LOCATIONS);\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: formatLocationsText(input.operation, capped, omitted, truncated) }],\n\t\t\t\tdetails: { operation: input.operation, locations: capped, omitted, truncated },\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport function createLspTool(cwd: string, options: LspToolOptions): AgentTool<typeof lspSchema> {\n\treturn wrapToolDefinition(createLspToolDefinition(cwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lsp.js","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C,CAAC,CAAC;AAAA,CACjE","sourcesContent":["import { isAbsolute, relative } from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport { type ApexToolDefinition, toolUnion } from \"./contract.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst MAX_LOCATIONS = 1_000;\nconst MAX_SYMBOLS = 2_000;\n/** Cap on the serialized symbol details so a result can never grow unbounded (spec § 4). */\nconst MAX_DETAILS_BYTES = 256 * 1024;\n\nconst lspNavigationSchema = Type.Object({\n\toperation: Type.Union([Type.Literal(\"definition\"), Type.Literal(\"references\")]),\n\tpath: Type.String(),\n\tline: Type.Number(),\n\tcharacter: Type.Number(),\n});\n\nconst lspDocumentSymbolsSchema = Type.Object({\n\toperation: Type.Literal(\"document_symbols\"),\n\tpath: Type.String(),\n});\n\nconst lspWorkspaceSymbolsSchema = Type.Object({\n\toperation: Type.Literal(\"workspace_symbol\"),\n\tquery: Type.String(),\n});\n\nconst lspSchemaProperties = {\n\toperation: Type.Union(\n\t\t[\n\t\t\tType.Literal(\"definition\"),\n\t\t\tType.Literal(\"references\"),\n\t\t\tType.Literal(\"document_symbols\"),\n\t\t\tType.Literal(\"workspace_symbol\"),\n\t\t],\n\t\t{ description: \"Which query to run.\" },\n\t),\n\tpath: Type.String({\n\t\tdescription: \"Path to the file (relative or absolute). Required by every operation but workspace_symbol.\",\n\t}),\n\tline: Type.Number({ description: \"One-based line number. Required by definition and references.\" }),\n\tcharacter: Type.Number({\n\t\tdescription: \"One-based UTF-16 character offset within the line. Required by definition and references.\",\n\t}),\n\tquery: Type.String({ description: \"The symbol name to search for. Required by workspace_symbol.\" }),\n};\n\nconst lspSchema = toolUnion(\n\t[lspNavigationSchema, lspDocumentSymbolsSchema, lspWorkspaceSymbolsSchema],\n\tlspSchemaProperties,\n);\n\nexport type LspToolInput = Static<typeof lspSchema>;\n\nexport interface LspPosition {\n\treadonly line: number;\n\treadonly character: number;\n}\n\nexport interface LspRange {\n\treadonly start: LspPosition;\n\treadonly end: LspPosition;\n}\n\n/** A navigation result normalized to a workspace-relative path and one-based range. */\nexport interface LspLocation {\n\treadonly path: string;\n\treadonly range: LspRange;\n}\n\n/** A flattened document symbol normalized to a workspace-relative path and one-based ranges. */\nexport interface LspSymbol {\n\treadonly name: string;\n\treadonly kind: number;\n\treadonly path: string;\n\treadonly range: LspRange;\n\treadonly selectionRange: LspRange;\n\treadonly detail?: string;\n}\n\n/** A workspace-wide symbol (LSP SymbolInformation) normalized like {@link LspSymbol} without a selection range. */\nexport interface LspWorkspaceSymbol {\n\treadonly name: string;\n\treadonly kind: number;\n\treadonly path: string;\n\treadonly range: LspRange;\n\treadonly containerName?: string;\n}\n\nexport type LspToolDetails =\n\t| { operation: \"definition\" | \"references\"; locations: LspLocation[]; omitted: number; truncated: number }\n\t| { operation: \"document_symbols\"; symbols: LspSymbol[]; omitted: number; truncated: number }\n\t| {\n\t\t\toperation: \"workspace_symbol\";\n\t\t\tsymbols: LspWorkspaceSymbol[];\n\t\t\tomitted: number;\n\t\t\ttruncated: number;\n\t\t\toutsideRoot: number;\n\t\t\tunsupported?: boolean;\n\t };\n\n/**\n * Pluggable transport for the `lsp` tool. The executable, its arguments, and the\n * closed JSON-RPC method set are all fixed by configuration the tool never chooses\n * itself -- see contract.capabilities below for why that keeps this `{fs.read}`\n * rather than `{exec}`.\n */\nexport interface LspOperations {\n\trequest(absolutePath: string, method: string, params: unknown, signal?: AbortSignal): Promise<unknown>;\n}\n\nexport interface LspToolOptions {\n\toperations: LspOperations;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isPosition(value: unknown): value is LspPosition {\n\treturn isRecord(value) && typeof value.line === \"number\" && typeof value.character === \"number\";\n}\n\nfunction isRange(value: unknown): value is LspRange {\n\treturn isRecord(value) && isPosition(value.start) && isPosition(value.end);\n}\n\nfunction toOneBasedPosition(position: LspPosition): LspPosition {\n\treturn { line: position.line + 1, character: position.character + 1 };\n}\n\nfunction toOneBasedRange(range: LspRange): LspRange {\n\treturn { start: toOneBasedPosition(range.start), end: toOneBasedPosition(range.end) };\n}\n\nfunction fileUriToAbsolutePath(uri: string): string | undefined {\n\tif (!uri.startsWith(\"file:\")) return undefined;\n\ttry {\n\t\treturn fileURLToPath(uri);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction rawLocationUriAndRange(value: unknown): { uri: string; range: LspRange } | undefined {\n\tif (!isRecord(value)) return undefined;\n\tif (typeof value.uri === \"string\" && isRange(value.range)) return { uri: value.uri, range: value.range };\n\tif (typeof value.targetUri === \"string\" && isRange(value.targetRange)) {\n\t\treturn { uri: value.targetUri, range: value.targetRange };\n\t}\n\treturn undefined;\n}\n\nfunction normalizeLocations(raw: unknown, cwd: string): { locations: LspLocation[]; omitted: number } {\n\tconst items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];\n\tconst locations: LspLocation[] = [];\n\tlet omitted = 0;\n\tfor (const item of items) {\n\t\tconst parsed = rawLocationUriAndRange(item);\n\t\tconst absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;\n\t\tif (!parsed || !absolutePath) {\n\t\t\tomitted++;\n\t\t\tcontinue;\n\t\t}\n\t\tlocations.push({\n\t\t\tpath: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),\n\t\t\trange: toOneBasedRange(parsed.range),\n\t\t});\n\t}\n\treturn { locations, omitted };\n}\n\nfunction compareLocations(a: LspLocation, b: LspLocation): number {\n\tif (a.path !== b.path) return a.path < b.path ? -1 : 1;\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\tif (a.range.end.line !== b.range.end.line) return a.range.end.line - b.range.end.line;\n\treturn a.range.end.character - b.range.end.character;\n}\n\nfunction dedupeSortAndCap(locations: LspLocation[], max: number): { locations: LspLocation[]; truncated: number } {\n\tconst seen = new Set<string>();\n\tconst unique: LspLocation[] = [];\n\tfor (const location of locations) {\n\t\tconst key = JSON.stringify(location);\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tunique.push(location);\n\t}\n\tunique.sort(compareLocations);\n\tconst capped = unique.slice(0, max);\n\treturn { locations: capped, truncated: unique.length - capped.length };\n}\n\nfunction isRawDocumentSymbol(value: unknown): value is Record<string, unknown> {\n\treturn isRecord(value) && typeof value.name === \"string\" && isRange(value.range) && isRange(value.selectionRange);\n}\n\nfunction flattenSymbols(raw: unknown, path: string): { symbols: LspSymbol[]; omitted: number } {\n\tconst symbols: LspSymbol[] = [];\n\tlet omitted = 0;\n\tconst visit = (value: unknown): void => {\n\t\tif (!Array.isArray(value)) return;\n\t\tfor (const item of value) {\n\t\t\tif (!isRawDocumentSymbol(item)) {\n\t\t\t\tomitted++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tsymbols.push({\n\t\t\t\tname: item.name as string,\n\t\t\t\tkind: typeof item.kind === \"number\" ? item.kind : 0,\n\t\t\t\tpath,\n\t\t\t\trange: toOneBasedRange(item.range as LspRange),\n\t\t\t\tselectionRange: toOneBasedRange(item.selectionRange as LspRange),\n\t\t\t\t...(typeof item.detail === \"string\" ? { detail: item.detail } : {}),\n\t\t\t});\n\t\t\tif (Array.isArray(item.children)) visit(item.children);\n\t\t}\n\t};\n\tvisit(Array.isArray(raw) ? raw : []);\n\treturn { symbols, omitted };\n}\n\nfunction compareSymbols(a: LspSymbol, b: LspSymbol): number {\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\treturn a.name === b.name ? 0 : a.name < b.name ? -1 : 1;\n}\n\nfunction capSymbols(symbols: LspSymbol[], max: number): { symbols: LspSymbol[]; truncated: number } {\n\tconst sorted = [...symbols].sort(compareSymbols);\n\tconst capped = sorted.slice(0, max);\n\treturn { symbols: capped, truncated: sorted.length - capped.length };\n}\n\nfunction isInsideRoot(absolutePath: string, root: string): boolean {\n\tconst rel = relative(root, absolutePath);\n\treturn rel === \"\" || (!rel.startsWith(\"..\") && !isAbsolute(rel));\n}\n\nfunction rawWorkspaceSymbol(value: unknown): { name: string; kind: number; containerName?: string } | undefined {\n\tif (!isRecord(value) || typeof value.name !== \"string\") return undefined;\n\treturn {\n\t\tname: value.name,\n\t\tkind: typeof value.kind === \"number\" ? value.kind : 0,\n\t\t...(typeof value.containerName === \"string\" ? { containerName: value.containerName } : {}),\n\t};\n}\n\n/**\n * Normalize `workspace/symbol` SymbolInformation results: file URIs to\n * workspace-relative paths, zero-based ranges to one-based, and every result\n * outside the authorized root dropped with an honest count (spec § 4: the\n * root is never widened because a result points outside it).\n */\nfunction normalizeWorkspaceSymbols(\n\traw: unknown,\n\tcwd: string,\n): { symbols: LspWorkspaceSymbol[]; omitted: number; outsideRoot: number } {\n\tconst items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];\n\tconst symbols: LspWorkspaceSymbol[] = [];\n\tlet omitted = 0;\n\tlet outsideRoot = 0;\n\tfor (const item of items) {\n\t\tconst parsed = rawLocationUriAndRange(isRecord(item) ? (item.location ?? item) : undefined);\n\t\tconst absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;\n\t\tconst info = rawWorkspaceSymbol(item);\n\t\tif (!parsed || !absolutePath || !info) {\n\t\t\tomitted++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!isInsideRoot(absolutePath, cwd)) {\n\t\t\toutsideRoot++;\n\t\t\tcontinue;\n\t\t}\n\t\tsymbols.push({\n\t\t\t...info,\n\t\t\tpath: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),\n\t\t\trange: toOneBasedRange(parsed.range),\n\t\t});\n\t}\n\treturn { symbols, omitted, outsideRoot };\n}\n\nfunction compareWorkspaceSymbols(a: LspWorkspaceSymbol, b: LspWorkspaceSymbol): number {\n\tif (a.path !== b.path) return a.path < b.path ? -1 : 1;\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\treturn a.name === b.name ? 0 : a.name < b.name ? -1 : 1;\n}\n\nfunction capWorkspaceSymbolsByCount(\n\tsymbols: LspWorkspaceSymbol[],\n\tmax: number,\n): { symbols: LspWorkspaceSymbol[]; truncated: number } {\n\tconst sorted = [...symbols].sort(compareWorkspaceSymbols);\n\tconst capped = sorted.slice(0, max);\n\treturn { symbols: capped, truncated: sorted.length - capped.length };\n}\n\nfunction capWorkspaceSymbolsByBytes(\n\tsymbols: LspWorkspaceSymbol[],\n\tmaxBytes: number,\n): { symbols: LspWorkspaceSymbol[]; truncated: number } {\n\tlet used = 2; // \"[]\"\n\tfor (let i = 0; i < symbols.length; i++) {\n\t\tconst cost = Buffer.byteLength(JSON.stringify(symbols[i]), \"utf-8\") + 1;\n\t\tif (used + cost > maxBytes) {\n\t\t\treturn { symbols: symbols.slice(0, i), truncated: symbols.length - i };\n\t\t}\n\t\tused += cost;\n\t}\n\treturn { symbols, truncated: 0 };\n}\n\nfunction isUnsupportedMethodError(error: unknown): boolean {\n\tconst message = error instanceof Error ? error.message : String(error);\n\treturn message.includes(\"-32601\") || /method not found/i.test(message);\n}\n\nfunction formatWorkspaceSymbolsNotices(omitted: number, truncated: number, outsideRoot: number): string {\n\tconst notices: string[] = [];\n\tif (omitted > 0) notices.push(`${omitted} non-file result(s) omitted`);\n\tif (outsideRoot > 0) notices.push(`${outsideRoot} result(s) outside the workspace root omitted`);\n\tif (truncated > 0) notices.push(`${truncated} result(s) truncated`);\n\treturn notices.length > 0 ? `\\n\\n[${notices.join(\", \")}]` : \"\";\n}\n\nfunction formatWorkspaceSymbolsText(\n\tsymbols: LspWorkspaceSymbol[],\n\tomitted: number,\n\ttruncated: number,\n\toutsideRoot: number,\n): string {\n\tif (symbols.length === 0) {\n\t\tconst base = \"No symbols found.\";\n\t\tconst notices = formatWorkspaceSymbolsNotices(omitted, truncated, outsideRoot);\n\t\treturn notices ? `${base}${notices}` : base;\n\t}\n\tconst lines = symbols.map(\n\t\t(symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatWorkspaceSymbolsNotices(omitted, truncated, outsideRoot)}`;\n}\n\nfunction formatNotices(omitted: number, truncated: number): string {\n\tconst notices: string[] = [];\n\tif (omitted > 0) notices.push(`${omitted} non-file result(s) omitted`);\n\tif (truncated > 0) notices.push(`${truncated} result(s) truncated`);\n\treturn notices.length > 0 ? `\\n\\n[${notices.join(\", \")}]` : \"\";\n}\n\nfunction formatLocationsText(\n\toperation: \"definition\" | \"references\",\n\tlocations: LspLocation[],\n\tomitted: number,\n\ttruncated: number,\n): string {\n\tif (locations.length === 0) {\n\t\treturn operation === \"definition\" ? \"No definition found.\" : \"No references found.\";\n\t}\n\tconst lines = locations.map(\n\t\t(location) => `${location.path}:${location.range.start.line}:${location.range.start.character}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nfunction formatSymbolsText(symbols: LspSymbol[], omitted: number, truncated: number): string {\n\tif (symbols.length === 0) return \"No symbols found.\";\n\tconst lines = symbols.map(\n\t\t(symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nexport function createLspToolDefinition(\n\tcwd: string,\n\toptions: LspToolOptions,\n): ApexToolDefinition<typeof lspSchema, LspToolDetails> {\n\tconst { operations } = options;\n\treturn {\n\t\tname: \"lsp\",\n\t\tlabel: \"lsp\",\n\t\tdescription: \"Query the configured language server for definitions, references, or symbols.\",\n\t\tparameters: lspSchema,\n\t\tcontract: {\n\t\t\t// `grep` spawns `rg` and declares {fs.read}, not {exec}, because the caller\n\t\t\t// never chooses what runs -- the executable, args, and closed JSON-RPC\n\t\t\t// method set all come from settings.json / this tool's own code. Same\n\t\t\t// reasoning here: {exec} would silently widen a delegation ceiling for no\n\t\t\t// capability the model can actually reach through this tool.\n\t\t\tcapabilities: new Set([\"fs.read\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"allow\",\n\t\t\t\tverb: \"Query\",\n\t\t\t\t// A workspace_symbol call has no path; returning undefined normalizes to\n\t\t\t\t// the workspace root, so the same gate authorizes the root before the\n\t\t\t\t// request is sent and `ruleForCall` stays inside one grammar.\n\t\t\t\tgetPath: (params) => (\"path\" in params ? params.path : undefined),\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: true },\n\t\t\tevidence: { emits: new Set(), capture: () => [] },\n\t\t},\n\t\tasync execute(_toolCallId, input: LspToolInput, signal?: AbortSignal) {\n\t\t\tif (input.operation === \"workspace_symbol\") {\n\t\t\t\t// The permission gate has already authorized the workspace root by the\n\t\t\t\t// time execute runs; only now does the request go out.\n\t\t\t\ttry {\n\t\t\t\t\tconst raw = await operations.request(cwd, \"workspace/symbol\", { query: input.query }, signal);\n\t\t\t\t\tconst { symbols, omitted, outsideRoot } = normalizeWorkspaceSymbols(raw, cwd);\n\t\t\t\t\tconst { symbols: countCapped, truncated: countTruncated } = capWorkspaceSymbolsByCount(\n\t\t\t\t\t\tsymbols,\n\t\t\t\t\t\tMAX_SYMBOLS,\n\t\t\t\t\t);\n\t\t\t\t\tconst { symbols: capped, truncated: byteTruncated } = capWorkspaceSymbolsByBytes(\n\t\t\t\t\t\tcountCapped,\n\t\t\t\t\t\tMAX_DETAILS_BYTES,\n\t\t\t\t\t);\n\t\t\t\t\tconst truncated = countTruncated + byteTruncated;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\", text: formatWorkspaceSymbolsText(capped, omitted, truncated, outsideRoot) },\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { operation: \"workspace_symbol\", symbols: capped, omitted, truncated, outsideRoot },\n\t\t\t\t\t};\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (isUnsupportedMethodError(error)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\t\ttext: \"workspace_symbol is not supported by the configured language server.\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\toperation: \"workspace_symbol\",\n\t\t\t\t\t\t\t\tsymbols: [],\n\t\t\t\t\t\t\t\tomitted: 0,\n\t\t\t\t\t\t\t\ttruncated: 0,\n\t\t\t\t\t\t\t\toutsideRoot: 0,\n\t\t\t\t\t\t\t\tunsupported: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst absolutePath = resolveToCwd(input.path, cwd);\n\t\t\tconst uri = pathToFileURL(absolutePath).href;\n\n\t\t\tif (input.operation === \"document_symbols\") {\n\t\t\t\tconst raw = await operations.request(\n\t\t\t\t\tabsolutePath,\n\t\t\t\t\t\"textDocument/documentSymbol\",\n\t\t\t\t\t{ textDocument: { uri } },\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t\tconst relativePath = formatPathRelativeToCwdOrAbsolute(absolutePath, cwd);\n\t\t\t\tconst { symbols, omitted } = flattenSymbols(raw, relativePath);\n\t\t\t\tconst { symbols: capped, truncated } = capSymbols(symbols, MAX_SYMBOLS);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: formatSymbolsText(capped, omitted, truncated) }],\n\t\t\t\t\tdetails: { operation: \"document_symbols\", symbols: capped, omitted, truncated },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst position = { line: input.line - 1, character: input.character - 1 };\n\t\t\tconst method = input.operation === \"definition\" ? \"textDocument/definition\" : \"textDocument/references\";\n\t\t\tconst params: Record<string, unknown> = { textDocument: { uri }, position };\n\t\t\tif (input.operation === \"references\") params.context = { includeDeclaration: true };\n\t\t\tconst raw = await operations.request(absolutePath, method, params, signal);\n\t\t\tconst { locations, omitted } = normalizeLocations(raw, cwd);\n\t\t\tconst { locations: capped, truncated } = dedupeSortAndCap(locations, MAX_LOCATIONS);\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: formatLocationsText(input.operation, capped, omitted, truncated) }],\n\t\t\t\tdetails: { operation: input.operation, locations: capped, omitted, truncated },\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport function createLspTool(cwd: string, options: LspToolOptions): AgentTool<typeof lspSchema> {\n\treturn wrapToolDefinition(createLspToolDefinition(cwd, options));\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Shared PermissionSpec construction for the path-shaped tools (read, grep, find, ls, write, edit). */
|
|
2
2
|
import type { Static, TSchema } from "typebox";
|
|
3
|
+
import type { PermissionPreview } from "../permissions/responder.ts";
|
|
3
4
|
import type { PermissionBehavior, PermissionSpec } from "./contract.ts";
|
|
4
5
|
/**
|
|
5
6
|
* Builds a glob-based PermissionSpec over a single path field. `getPath` extracts
|
|
@@ -14,5 +15,7 @@ export declare function createPathPermissionSpec<TParams extends TSchema>(option
|
|
|
14
15
|
defaultBehavior: PermissionBehavior;
|
|
15
16
|
verb: string;
|
|
16
17
|
getPath: (params: Static<TParams>) => string | undefined;
|
|
18
|
+
/** Describes the change for a human about to approve it. See PermissionSpec.previewCall. */
|
|
19
|
+
previewCall?: (params: Static<TParams>) => PermissionPreview;
|
|
17
20
|
}): PermissionSpec<TParams>;
|
|
18
21
|
//# sourceMappingURL=path-permission.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-permission.d.ts","sourceRoot":"","sources":["../../../src/core/tools/path-permission.ts"],"names":[],"mappings":"AAAA,wGAAwG;AAGxG,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"path-permission.d.ts","sourceRoot":"","sources":["../../../src/core/tools/path-permission.ts"],"names":[],"mappings":"AAAA,wGAAwG;AAGxG,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAG/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGxE;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,SAAS,OAAO,EAAE,OAAO,EAAE;IAC1E,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,EAAE,kBAAkB,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,MAAM,GAAG,SAAS,CAAC;IACzD,4FAA4F;IAC5F,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,iBAAiB,CAAC;CAC7D,GAAG,cAAc,CAAC,OAAO,CAAC,CA2B1B","sourcesContent":["/** Shared PermissionSpec construction for the path-shaped tools (read, grep, find, ls, write, edit). */\n\nimport { minimatch } from \"minimatch\";\nimport type { Static, TSchema } from \"typebox\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport { setPreparedPathOperation } from \"../permissions/operations.ts\";\nimport type { PermissionPreview } from \"../permissions/responder.ts\";\nimport type { PermissionBehavior, PermissionSpec } from \"./contract.ts\";\nimport { preparePathOperation, resolveToCwd } from \"./path-utils.ts\";\n\n/**\n * Builds a glob-based PermissionSpec over a single path field. `getPath` extracts\n * the workspace path a call touches (returning undefined defaults to the tool's own\n * cwd-relative root, e.g. `ls` with no `path` argument). Rule content is a\n * cwd-relative glob; `ruleForCall` returns the exact normalized path of the call, so\n * \"always allow this\" authorizes only that path — never a pattern the tool did not\n * generate itself.\n */\nexport function createPathPermissionSpec<TParams extends TSchema>(options: {\n\tcwd: string;\n\tdefaultBehavior: PermissionBehavior;\n\tverb: string;\n\tgetPath: (params: Static<TParams>) => string | undefined;\n\t/** Describes the change for a human about to approve it. See PermissionSpec.previewCall. */\n\tpreviewCall?: (params: Static<TParams>) => PermissionPreview;\n}): PermissionSpec<TParams> {\n\tconst { cwd, defaultBehavior, verb, getPath, previewCall } = options;\n\n\tconst normalize = (path: string | undefined): string => {\n\t\tconst canonical = resolveToCwd(path?.trim() ? path : \".\", cwd);\n\t\treturn formatPathRelativeToCwdOrAbsolute(canonical, cwd);\n\t};\n\tconst escapeExact = (value: string): string => `exact:${value}`;\n\n\treturn {\n\t\tdefaultBehavior,\n\t\tprepareCall(params) {\n\t\t\tsetPreparedPathOperation(params as object, preparePathOperation(getPath(params) ?? \".\", cwd));\n\t\t},\n\t\t...(previewCall ? { previewCall } : {}),\n\t\tmatches(ruleContent, params) {\n\t\t\treturn ruleContent.startsWith(\"exact:\")\n\t\t\t\t? normalize(getPath(params)) === ruleContent.slice(\"exact:\".length)\n\t\t\t\t: minimatch(normalize(getPath(params)), ruleContent, { dot: true });\n\t\t},\n\t\tdescribe(ruleContent) {\n\t\t\treturn `${verb} paths matching \"${ruleContent}\"`;\n\t\t},\n\t\truleForCall(params) {\n\t\t\treturn escapeExact(normalize(getPath(params)));\n\t\t},\n\t};\n}\n"]}
|