@oh-my-pi/pi-coding-agent 7.0.0 → 8.0.0
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 +87 -0
- package/README.md +1 -1
- package/docs/hooks.md +2 -2
- package/docs/sdk.md +1 -1
- package/package.json +10 -10
- package/scripts/format-prompts.ts +143 -0
- package/scripts/generate-template.ts +1 -1
- package/src/cli/args.ts +3 -3
- package/src/cli/config-cli.ts +4 -4
- package/src/cli/file-processor.ts +3 -3
- package/src/cli/list-models.ts +2 -2
- package/src/cli/plugin-cli.ts +3 -3
- package/src/cli/session-picker.ts +2 -2
- package/src/cli/setup-cli.ts +2 -2
- package/src/cli/stats-cli.ts +1 -1
- package/src/cli/update-cli.ts +2 -2
- package/src/{core → config}/keybindings.ts +1 -1
- package/src/{core → config}/model-registry.ts +1 -1
- package/src/{core → config}/model-resolver.ts +3 -3
- package/src/{core → config}/prompt-templates.ts +2 -2
- package/src/{core → config}/settings-manager.ts +6 -6
- package/src/{core/cursor/exec-bridge.ts → cursor.ts} +4 -4
- package/src/discovery/agents-md.ts +4 -4
- package/src/discovery/builtin.ts +17 -17
- package/src/discovery/claude.ts +12 -12
- package/src/discovery/cline.ts +6 -6
- package/src/discovery/codex.ts +21 -21
- package/src/discovery/cursor.ts +9 -9
- package/src/discovery/gemini.ts +9 -9
- package/src/discovery/github.ts +6 -6
- package/src/discovery/helpers.ts +4 -4
- package/src/discovery/index.ts +16 -16
- package/src/discovery/mcp-json.ts +4 -4
- package/src/discovery/ssh.ts +4 -4
- package/src/discovery/vscode.ts +4 -4
- package/src/discovery/windsurf.ts +6 -6
- package/src/{core/tools/exa → exa}/company.ts +2 -3
- package/src/{core/tools/exa → exa}/index.ts +2 -2
- package/src/{core/tools/exa → exa}/linkedin.ts +2 -3
- package/src/{core/tools/exa → exa}/mcp-client.ts +2 -2
- package/src/{core/tools/exa → exa}/render.ts +3 -3
- package/src/{core/tools/exa → exa}/researcher.ts +1 -1
- package/src/{core/tools/exa → exa}/search.ts +2 -10
- package/src/{core/tools/exa → exa}/websets.ts +1 -1
- package/src/{core → exec}/bash-executor.ts +22 -6
- package/src/{core → export}/custom-share.ts +1 -1
- package/src/{core/export-html → export/html}/index.ts +3 -3
- package/src/{core → export}/ttsr.ts +2 -2
- package/src/{core → extensibility}/custom-commands/bundled/review/index.ts +4 -4
- package/src/{core → extensibility}/custom-commands/loader.ts +3 -3
- package/src/{core → extensibility}/custom-commands/types.ts +1 -1
- package/src/{core → extensibility}/custom-tools/loader.ts +9 -9
- package/src/{core → extensibility}/custom-tools/types.ts +6 -6
- package/src/{core → extensibility}/custom-tools/wrapper.ts +1 -1
- package/src/{core → extensibility}/extensions/loader.ts +8 -8
- package/src/{core → extensibility}/extensions/runner.ts +3 -3
- package/src/{core → extensibility}/extensions/types.ts +15 -15
- package/src/{core → extensibility}/extensions/wrapper.ts +1 -1
- package/src/{core → extensibility}/hooks/index.ts +1 -1
- package/src/{core → extensibility}/hooks/loader.ts +7 -7
- package/src/{core → extensibility}/hooks/runner.ts +4 -4
- package/src/{core → extensibility}/hooks/types.ts +9 -9
- package/src/{core → extensibility}/plugins/doctor.ts +1 -1
- package/src/{core → extensibility}/plugins/installer.ts +2 -3
- package/src/{core → extensibility}/plugins/paths.ts +1 -1
- package/src/{core → extensibility}/skills.ts +8 -48
- package/src/{core → extensibility}/slash-commands.ts +6 -6
- package/src/index.ts +127 -128
- package/src/internal-urls/agent-protocol.ts +126 -0
- package/src/internal-urls/artifact-protocol.ts +93 -0
- package/src/internal-urls/index.ts +28 -0
- package/src/internal-urls/json-query.ts +126 -0
- package/src/internal-urls/router.ts +69 -0
- package/src/internal-urls/rule-protocol.ts +56 -0
- package/src/internal-urls/skill-protocol.ts +112 -0
- package/src/internal-urls/types.ts +48 -0
- package/src/{core/python-executor.ts → ipy/executor.ts} +51 -11
- package/src/{core/python-gateway-coordinator.ts → ipy/gateway-coordinator.ts} +41 -325
- package/src/{core/python-kernel.ts → ipy/kernel.ts} +38 -10
- package/src/ipy/prelude.ts +3 -0
- package/src/{core/tools/lsp → lsp}/client.ts +7 -6
- package/src/{core/tools/lsp → lsp}/clients/biome-client.ts +1 -1
- package/src/{core/tools/lsp → lsp}/clients/index.ts +1 -1
- package/src/{core/tools/lsp → lsp}/clients/lsp-linter-client.ts +4 -4
- package/src/{core/tools/lsp → lsp}/config.ts +1 -1
- package/src/{core/tools/lsp → lsp}/index.ts +16 -15
- package/src/{core/tools/lsp → lsp}/render.ts +2 -2
- package/src/{core/tools/lsp → lsp}/types.ts +14 -16
- package/src/{core/tools/lsp → lsp}/utils.ts +1 -1
- package/src/main.ts +12 -12
- package/src/{core/mcp → mcp}/config.ts +8 -8
- package/src/{core/mcp → mcp}/loader.ts +5 -6
- package/src/{core/mcp → mcp}/manager.ts +2 -2
- package/src/{core/mcp → mcp}/tool-bridge.ts +35 -6
- package/src/{core/mcp → mcp}/tool-cache.ts +1 -1
- package/src/{core/mcp → mcp}/transports/http.ts +7 -1
- package/src/{core/mcp → mcp}/transports/stdio.ts +1 -1
- package/src/{core/mcp → mcp}/types.ts +1 -1
- package/src/migrations.ts +2 -2
- package/src/modes/{interactive/components → components}/armin.ts +1 -1
- package/src/modes/{interactive/components → components}/assistant-message.ts +1 -1
- package/src/modes/{interactive/components → components}/bash-execution.ts +37 -29
- package/src/modes/{interactive/components → components}/bordered-loader.ts +1 -1
- package/src/modes/{interactive/components → components}/branch-summary-message.ts +2 -2
- package/src/modes/{interactive/components → components}/compaction-summary-message.ts +2 -2
- package/src/modes/{interactive/components → components}/custom-message.ts +3 -3
- package/src/modes/{interactive/components → components}/diff.ts +1 -1
- package/src/modes/{interactive/components → components}/dynamic-border.ts +1 -1
- package/src/modes/{interactive/components → components}/extensions/extension-dashboard.ts +3 -3
- package/src/modes/{interactive/components → components}/extensions/extension-list.ts +2 -2
- package/src/modes/{interactive/components → components}/extensions/inspector-panel.ts +1 -1
- package/src/modes/{interactive/components → components}/extensions/state-manager.ts +11 -17
- package/src/modes/{interactive/components → components}/extensions/types.ts +1 -1
- package/src/modes/{interactive/components → components}/footer.ts +3 -3
- package/src/modes/{interactive/components → components}/history-search.ts +2 -2
- package/src/modes/{interactive/components → components}/hook-editor.ts +1 -1
- package/src/modes/{interactive/components → components}/hook-input.ts +1 -1
- package/src/modes/{interactive/components → components}/hook-message.ts +3 -3
- package/src/modes/{interactive/components → components}/hook-selector.ts +1 -1
- package/src/modes/{interactive/components → components}/keybinding-hints.ts +2 -2
- package/src/modes/{interactive/components → components}/login-dialog.ts +1 -1
- package/src/modes/{interactive/components → components}/model-selector.ts +5 -5
- package/src/modes/{interactive/components → components}/oauth-selector.ts +2 -2
- package/src/modes/{interactive/components → components}/plugin-settings.ts +3 -3
- package/src/modes/{interactive/components → components}/python-execution.ts +35 -24
- package/src/modes/{interactive/components → components}/queue-mode-selector.ts +1 -1
- package/src/modes/{interactive/components → components}/read-tool-group.ts +2 -2
- package/src/modes/{interactive/components → components}/session-selector.ts +3 -3
- package/src/modes/{interactive/components → components}/settings-defs.ts +2 -2
- package/src/modes/{interactive/components → components}/settings-selector.ts +2 -2
- package/src/modes/{interactive/components → components}/show-images-selector.ts +1 -1
- package/src/modes/{interactive/components → components}/status-line/segments.ts +2 -2
- package/src/modes/{interactive/components → components}/status-line/separators.ts +1 -1
- package/src/modes/{interactive/components → components}/status-line/types.ts +2 -2
- package/src/modes/{interactive/components → components}/status-line-segment-editor.ts +2 -2
- package/src/modes/{interactive/components → components}/status-line.ts +3 -3
- package/src/modes/{interactive/components → components}/theme-selector.ts +1 -1
- package/src/modes/{interactive/components → components}/thinking-selector.ts +1 -1
- package/src/modes/{interactive/components → components}/todo-display.ts +3 -4
- package/src/modes/{interactive/components → components}/todo-reminder.ts +2 -2
- package/src/modes/{interactive/components → components}/tool-execution.ts +8 -8
- package/src/modes/{interactive/components → components}/tree-selector.ts +3 -3
- package/src/modes/{interactive/components → components}/ttsr-notification.ts +2 -2
- package/src/modes/{interactive/components → components}/user-message-selector.ts +1 -1
- package/src/modes/{interactive/components → components}/user-message.ts +1 -1
- package/src/modes/{interactive/components → components}/welcome.ts +2 -2
- package/src/modes/{interactive/controllers → controllers}/command-controller.ts +32 -30
- package/src/modes/{interactive/controllers → controllers}/event-controller.ts +9 -9
- package/src/modes/{interactive/controllers → controllers}/extension-ui-controller.ts +8 -8
- package/src/modes/{interactive/controllers → controllers}/input-controller.ts +6 -6
- package/src/modes/{interactive/controllers → controllers}/selector-controller.ts +16 -16
- package/src/modes/index.ts +1 -1
- package/src/modes/{interactive/interactive-mode.ts → interactive-mode.ts} +14 -14
- package/src/modes/print-mode.ts +1 -1
- package/src/modes/rpc/rpc-client.ts +3 -3
- package/src/modes/rpc/rpc-mode.ts +3 -3
- package/src/modes/rpc/rpc-types.ts +3 -3
- package/src/modes/{interactive/theme → theme}/theme.ts +1 -1
- package/src/modes/{interactive/types.ts → types.ts} +8 -9
- package/src/modes/{interactive/utils → utils}/ui-helpers.ts +20 -27
- package/src/{core/tools/patch → patch}/applicator.ts +1 -1
- package/src/{core/tools/patch → patch}/diff.ts +1 -1
- package/src/{core/tools/patch → patch}/index.ts +31 -36
- package/src/{core/tools/patch → patch}/shared.ts +9 -6
- package/src/prompts/agents/explore.md +83 -46
- package/src/prompts/agents/init.md +9 -4
- package/src/prompts/agents/plan.md +8 -7
- package/src/prompts/agents/reviewer.md +36 -18
- package/src/prompts/agents/task.md +4 -4
- package/src/prompts/compaction/branch-summary-preamble.md +0 -1
- package/src/prompts/review-request.md +0 -1
- package/src/prompts/system/custom-system-prompt.md +2 -14
- package/src/prompts/system/file-operations.md +0 -2
- package/src/prompts/system/system-prompt.md +147 -138
- package/src/prompts/system/web-search.md +26 -0
- package/src/prompts/tools/ask.md +31 -24
- package/src/prompts/tools/bash.md +20 -17
- package/src/prompts/tools/calculator.md +9 -5
- package/src/prompts/tools/fetch.md +16 -0
- package/src/prompts/tools/find.md +15 -5
- package/src/prompts/tools/gemini-image.md +21 -6
- package/src/prompts/tools/grep.md +28 -12
- package/src/prompts/tools/lsp.md +35 -14
- package/src/prompts/tools/patch.md +39 -41
- package/src/prompts/tools/python.md +59 -76
- package/src/prompts/tools/read.md +23 -22
- package/src/prompts/tools/replace.md +19 -12
- package/src/prompts/tools/ssh.md +21 -28
- package/src/prompts/tools/task.md +54 -44
- package/src/prompts/tools/todo-write.md +52 -163
- package/src/prompts/tools/web-search.md +16 -9
- package/src/prompts/tools/write.md +13 -2
- package/src/{core/sdk.ts → sdk.ts} +65 -34
- package/src/{core → session}/agent-session.ts +45 -37
- package/src/{core → session}/agent-storage.ts +2 -2
- package/src/session/artifacts.ts +110 -0
- package/src/{core → session}/auth-storage.ts +1 -1
- package/src/{core → session}/compaction/branch-summarization.ts +5 -5
- package/src/{core → session}/compaction/compaction.ts +6 -6
- package/src/{core → session}/compaction/utils.ts +3 -3
- package/src/{core → session}/history-storage.ts +1 -1
- package/src/{core → session}/messages.ts +6 -8
- package/src/{core → session}/session-manager.ts +2 -2
- package/src/{core → session}/storage-migration.ts +2 -2
- package/src/session/streaming-output.ts +177 -0
- package/src/{core/ssh → ssh}/connection-manager.ts +1 -1
- package/src/{core/ssh → ssh}/ssh-executor.ts +19 -4
- package/src/{core/ssh → ssh}/sshfs-mount.ts +1 -1
- package/src/{core/system-prompt.ts → system-prompt.ts} +8 -37
- package/src/{core/tools/task → task}/agents.ts +8 -8
- package/src/{core/tools/task → task}/commands.ts +5 -6
- package/src/{core/tools/task → task}/discovery.ts +3 -3
- package/src/{core/tools/task → task}/executor.ts +34 -44
- package/src/{core/tools/task → task}/index.ts +206 -50
- package/src/{core/tools/task → task}/render.ts +80 -23
- package/src/{core/tools/task → task}/subprocess-tool-registry.ts +1 -1
- package/src/task/template.ts +47 -0
- package/src/{core/tools/task → task}/types.ts +19 -27
- package/src/{core/tools/task → task}/worker-protocol.ts +8 -4
- package/src/{core/tools/task → task}/worker.ts +34 -29
- package/src/task/worktree.ts +166 -0
- package/src/{core/tools → tools}/ask.ts +13 -21
- package/src/{core/tools → tools}/bash-interceptor.ts +1 -1
- package/src/{core/tools → tools}/bash.ts +61 -63
- package/src/{core/tools → tools}/calculator.ts +4 -4
- package/src/{core/tools → tools}/complete.ts +1 -1
- package/src/{core/tools → tools}/context.ts +2 -2
- package/src/{core/tools/web-fetch.ts → tools/fetch.ts} +97 -76
- package/src/{core/tools → tools}/find.ts +80 -104
- package/src/{core/tools → tools}/gemini-image.ts +420 -29
- package/src/{core/tools → tools}/grep.ts +155 -164
- package/src/{core/tools → tools}/index.ts +63 -56
- package/src/tools/list-limit.ts +40 -0
- package/src/{core/tools → tools}/ls.ts +44 -35
- package/src/{core/tools → tools}/notebook.ts +3 -3
- package/src/tools/output-meta.ts +443 -0
- package/src/tools/output-utils.ts +63 -0
- package/src/{core/tools → tools}/python.ts +105 -89
- package/src/tools/read.ts +882 -0
- package/src/{core/tools → tools}/render-utils.ts +1 -1
- package/src/{core/tools → tools}/renderers.ts +8 -10
- package/src/{core/tools → tools}/review.ts +2 -2
- package/src/{core/tools → tools}/ssh.ts +56 -59
- package/src/{core/tools → tools}/todo-write.ts +12 -23
- package/src/tools/tool-errors.ts +95 -0
- package/src/tools/tool-result.ts +92 -0
- package/src/{core/tools → tools}/truncate.ts +2 -2
- package/src/{core/tools → tools}/write.ts +15 -13
- package/src/utils/changelog.ts +1 -1
- package/src/{core → utils}/file-mentions.ts +4 -4
- package/src/utils/image-convert.ts +1 -1
- package/src/utils/image-resize.ts +1 -1
- package/src/utils/shell.ts +1 -1
- package/src/{core → utils}/title-generator.ts +4 -4
- package/src/utils/tools-manager.ts +1 -1
- package/src/{core/tools/web-scrapers → web/scrapers}/choosealicense.ts +1 -1
- package/src/{core/tools/web-scrapers → web/scrapers}/twitter.ts +3 -2
- package/src/{core/tools/web-scrapers → web/scrapers}/types.ts +4 -2
- package/src/{core/tools/web-scrapers → web/scrapers}/utils.ts +1 -1
- package/src/{core/tools/web-scrapers → web/scrapers}/youtube.ts +14 -13
- package/src/{core/tools/web-search → web/search}/auth.ts +4 -4
- package/src/{core/tools/web-search → web/search}/index.ts +22 -71
- package/src/{core/tools/web-search → web/search}/providers/anthropic.ts +7 -10
- package/src/{core/tools/web-search → web/search}/providers/exa.ts +2 -2
- package/src/{core/tools/web-search → web/search}/providers/perplexity.ts +4 -16
- package/src/{core/tools/web-search → web/search}/render.ts +3 -3
- package/scripts/migrate-sessions.sh +0 -93
- package/src/core/index.ts +0 -56
- package/src/core/python-prelude.ts +0 -3
- package/src/core/ssh-executor.ts +0 -5
- package/src/core/streaming-output.ts +0 -115
- package/src/core/tools/output.ts +0 -519
- package/src/core/tools/read.ts +0 -717
- package/src/core/tools/task/template.ts +0 -37
- package/src/prompts/tools/output.md +0 -47
- package/src/prompts/tools/web-fetch.md +0 -9
- /package/src/{core/tools/exa → exa}/types.ts +0 -0
- /package/src/{core → exec}/exec.ts +0 -0
- /package/src/{core/export-html → export/html}/template.css +0 -0
- /package/src/{core/export-html → export/html}/template.generated.ts +0 -0
- /package/src/{core/export-html → export/html}/template.html +0 -0
- /package/src/{core/export-html → export/html}/template.js +0 -0
- /package/src/{core/export-html → export/html}/template.macro.ts +0 -0
- /package/src/{core/export-html → export/html}/vendor/highlight.min.js +0 -0
- /package/src/{core/export-html → export/html}/vendor/marked.min.js +0 -0
- /package/src/{core → extensibility}/custom-commands/index.ts +0 -0
- /package/src/{core → extensibility}/custom-tools/index.ts +0 -0
- /package/src/{core → extensibility}/extensions/index.ts +0 -0
- /package/src/{core → extensibility}/hooks/tool-wrapper.ts +0 -0
- /package/src/{core → extensibility}/plugins/index.ts +0 -0
- /package/src/{core → extensibility}/plugins/loader.ts +0 -0
- /package/src/{core → extensibility}/plugins/manager.ts +0 -0
- /package/src/{core → extensibility}/plugins/parser.ts +0 -0
- /package/src/{core → extensibility}/plugins/types.ts +0 -0
- /package/src/{core/python-modules.ts → ipy/modules.ts} +0 -0
- /package/src/{core/python-prelude.py → ipy/prelude.py} +0 -0
- /package/src/{core/tools/lsp → lsp}/defaults.json +0 -0
- /package/src/{core/tools/lsp → lsp}/edits.ts +0 -0
- /package/src/{core/tools/lsp → lsp}/lspmux.ts +0 -0
- /package/src/{core/tools/lsp → lsp}/rust-analyzer.ts +0 -0
- /package/src/{core/mcp → mcp}/client.ts +0 -0
- /package/src/{core/mcp → mcp}/index.ts +0 -0
- /package/src/{core/mcp → mcp}/json-rpc.ts +0 -0
- /package/src/{core/mcp → mcp}/transports/index.ts +0 -0
- /package/src/modes/{interactive/components → components}/countdown-timer.ts +0 -0
- /package/src/modes/{interactive/components → components}/custom-editor.ts +0 -0
- /package/src/modes/{interactive/components → components}/extensions/index.ts +0 -0
- /package/src/modes/{interactive/components → components}/index.ts +0 -0
- /package/src/modes/{interactive/components → components}/status-line/index.ts +0 -0
- /package/src/modes/{interactive/components → components}/status-line/presets.ts +0 -0
- /package/src/modes/{interactive/components → components}/visual-truncate.ts +0 -0
- /package/src/modes/{interactive/theme → theme}/dark.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/alabaster.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/amethyst.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/anthracite.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/basalt.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/birch.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-abyss.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-arctic.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-aurora.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-catppuccin.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-cavern.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-copper.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-cosmos.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-cyberpunk.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-dracula.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-eclipse.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-ember.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-equinox.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-forest.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-github.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-gruvbox.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-lavender.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-lunar.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-midnight.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-monochrome.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-monokai.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-nebula.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-nord.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-ocean.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-one.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-rainforest.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-reef.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-retro.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-rose-pine.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-sakura.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-slate.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-solarized.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-solstice.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-starfall.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-sunset.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-swamp.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-synthwave.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-taiga.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-terminal.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-tokyo-night.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-tundra.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-twilight.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/dark-volcanic.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/graphite.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/index.ts +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-arctic.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-aurora-day.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-canyon.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-catppuccin.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-cirrus.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-coral.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-cyberpunk.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-dawn.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-dunes.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-eucalyptus.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-forest.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-frost.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-github.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-glacier.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-gruvbox.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-haze.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-honeycomb.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-lagoon.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-lavender.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-meadow.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-mint.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-monochrome.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-ocean.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-one.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-opal.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-orchard.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-paper.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-prism.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-retro.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-sand.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-savanna.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-solarized.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-soleil.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-sunset.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-synthwave.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-tokyo-night.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-wetland.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/light-zenith.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/limestone.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/mahogany.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/marble.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/obsidian.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/onyx.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/pearl.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/porcelain.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/quartz.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/sandstone.json +0 -0
- /package/src/modes/{interactive/theme → theme}/defaults/titanium.json +0 -0
- /package/src/modes/{interactive/theme → theme}/light.json +0 -0
- /package/src/modes/{interactive/theme → theme}/theme-schema.json +0 -0
- /package/src/{core/tools/patch → patch}/fuzzy.ts +0 -0
- /package/src/{core/tools/patch → patch}/normalize.ts +0 -0
- /package/src/{core/tools/patch → patch}/normative.ts +0 -0
- /package/src/{core/tools/patch → patch}/parser.ts +0 -0
- /package/src/{core/tools/patch → patch}/types.ts +0 -0
- /package/src/{core → session}/compaction/index.ts +0 -0
- /package/src/{core → session}/session-storage.ts +0 -0
- /package/src/{core/tools/task → task}/name-generator.ts +0 -0
- /package/src/{core/tools/task → task}/omp-command.ts +0 -0
- /package/src/{core/tools/task → task}/parallel.ts +0 -0
- /package/src/{core/tools → tools}/jtd-to-json-schema.ts +0 -0
- /package/src/{core/tools → tools}/path-utils.ts +0 -0
- /package/src/{core → utils}/event-bus.ts +0 -0
- /package/src/{core → utils}/frontmatter.ts +0 -0
- /package/src/{core → utils}/terminal-notify.ts +0 -0
- /package/src/{core → utils}/timings.ts +0 -0
- /package/src/{core → utils}/utils.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/artifacthub.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/arxiv.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/aur.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/biorxiv.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/bluesky.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/brew.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/cheatsh.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/chocolatey.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/cisa-kev.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/clojars.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/coingecko.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/crates-io.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/crossref.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/devto.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/discogs.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/discourse.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/dockerhub.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/fdroid.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/firefox-addons.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/flathub.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/github-gist.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/github.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/gitlab.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/go-pkg.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/hackage.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/hackernews.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/hex.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/huggingface.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/iacr.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/index.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/jetbrains-marketplace.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/lemmy.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/lobsters.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/mastodon.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/maven.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/mdn.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/metacpan.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/musicbrainz.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/npm.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/nuget.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/nvd.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/ollama.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/open-vsx.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/opencorporates.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/openlibrary.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/orcid.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/osv.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/packagist.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/pub-dev.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/pubmed.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/pypi.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/rawg.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/readthedocs.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/reddit.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/repology.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/rfc.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/rubygems.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/searchcode.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/sec-edgar.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/semantic-scholar.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/snapcraft.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/sourcegraph.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/spdx.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/spotify.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/stackoverflow.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/terraform.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/tldr.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/vimeo.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/vscode-marketplace.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/w3c.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/wikidata.ts +0 -0
- /package/src/{core/tools/web-scrapers → web/scrapers}/wikipedia.ts +0 -0
- /package/src/{core/tools/web-search → web/search}/types.ts +0 -0
package/src/core/tools/read.ts
DELETED
|
@@ -1,717 +0,0 @@
|
|
|
1
|
-
import { homedir } from "node:os";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import type { AgentTool, AgentToolContext, AgentToolResult, AgentToolUpdateCallback } from "@oh-my-pi/pi-agent-core";
|
|
4
|
-
import type { ImageContent, TextContent } from "@oh-my-pi/pi-ai";
|
|
5
|
-
import type { Component } from "@oh-my-pi/pi-tui";
|
|
6
|
-
import { Text } from "@oh-my-pi/pi-tui";
|
|
7
|
-
import { ptree, untilAborted } from "@oh-my-pi/pi-utils";
|
|
8
|
-
import { Type } from "@sinclair/typebox";
|
|
9
|
-
import { CONFIG_DIR_NAME } from "../../config";
|
|
10
|
-
import type { Theme } from "../../modes/interactive/theme/theme";
|
|
11
|
-
import readDescription from "../../prompts/tools/read.md" with { type: "text" };
|
|
12
|
-
import { formatDimensionNote, resizeImage } from "../../utils/image-resize";
|
|
13
|
-
import { detectSupportedImageMimeTypeFromFile } from "../../utils/mime";
|
|
14
|
-
import { ensureTool } from "../../utils/tools-manager";
|
|
15
|
-
import type { RenderResultOptions } from "../custom-tools/types";
|
|
16
|
-
import { renderPromptTemplate } from "../prompt-templates";
|
|
17
|
-
import type { ToolSession } from "../sdk";
|
|
18
|
-
import { runFd } from "./find";
|
|
19
|
-
import { LsTool } from "./ls";
|
|
20
|
-
import { resolveReadPath, resolveToCwd } from "./path-utils";
|
|
21
|
-
import { shortenPath, wrapBrackets } from "./render-utils";
|
|
22
|
-
import {
|
|
23
|
-
DEFAULT_MAX_BYTES,
|
|
24
|
-
DEFAULT_MAX_LINES,
|
|
25
|
-
formatSize,
|
|
26
|
-
type TruncationResult,
|
|
27
|
-
truncateHead,
|
|
28
|
-
truncateStringToBytesFromStart,
|
|
29
|
-
} from "./truncate";
|
|
30
|
-
|
|
31
|
-
// Document types convertible via markitdown
|
|
32
|
-
const CONVERTIBLE_EXTENSIONS = new Set([".pdf", ".doc", ".docx", ".ppt", ".pptx", ".xls", ".xlsx", ".rtf", ".epub"]);
|
|
33
|
-
|
|
34
|
-
// Remote mount path prefix (sshfs mounts) - skip fuzzy matching to avoid hangs
|
|
35
|
-
const REMOTE_MOUNT_PREFIX = path.join(homedir(), CONFIG_DIR_NAME, "remote") + path.sep;
|
|
36
|
-
|
|
37
|
-
function isRemoteMountPath(absolutePath: string): boolean {
|
|
38
|
-
return absolutePath.startsWith(REMOTE_MOUNT_PREFIX);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Maximum image file size (20MB) - larger images will be rejected to prevent OOM during serialization
|
|
42
|
-
const MAX_IMAGE_SIZE = 20 * 1024 * 1024;
|
|
43
|
-
const MAX_FUZZY_RESULTS = 5;
|
|
44
|
-
const MAX_FUZZY_CANDIDATES = 20000;
|
|
45
|
-
const MIN_BASE_SIMILARITY = 0.5;
|
|
46
|
-
const MIN_FULL_SIMILARITY = 0.6;
|
|
47
|
-
|
|
48
|
-
function normalizePathForMatch(value: string): string {
|
|
49
|
-
return value
|
|
50
|
-
.replace(/\\/g, "/")
|
|
51
|
-
.replace(/^\.\/+/, "")
|
|
52
|
-
.replace(/\/+$/, "")
|
|
53
|
-
.toLowerCase();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function isNotFoundError(error: unknown): boolean {
|
|
57
|
-
if (!error || typeof error !== "object") return false;
|
|
58
|
-
const code = (error as { code?: string }).code;
|
|
59
|
-
return code === "ENOENT" || code === "ENOTDIR";
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function isPathWithin(basePath: string, targetPath: string): boolean {
|
|
63
|
-
const relativePath = path.relative(basePath, targetPath);
|
|
64
|
-
return relativePath === "" || (!relativePath.startsWith("..") && !path.isAbsolute(relativePath));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async function findExistingDirectory(startDir: string, signal?: AbortSignal): Promise<string | null> {
|
|
68
|
-
let current = startDir;
|
|
69
|
-
const root = path.parse(startDir).root;
|
|
70
|
-
|
|
71
|
-
while (true) {
|
|
72
|
-
signal?.throwIfAborted();
|
|
73
|
-
try {
|
|
74
|
-
const stat = await Bun.file(current).stat();
|
|
75
|
-
if (stat.isDirectory()) {
|
|
76
|
-
return current;
|
|
77
|
-
}
|
|
78
|
-
} catch {
|
|
79
|
-
// Keep walking up.
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (current === root) {
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
current = path.dirname(current);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function formatScopeLabel(searchRoot: string, cwd: string): string {
|
|
92
|
-
const relative = path.relative(cwd, searchRoot).replace(/\\/g, "/");
|
|
93
|
-
if (relative === "" || relative === ".") {
|
|
94
|
-
return ".";
|
|
95
|
-
}
|
|
96
|
-
if (!relative.startsWith("..") && !path.isAbsolute(relative)) {
|
|
97
|
-
return relative;
|
|
98
|
-
}
|
|
99
|
-
return searchRoot;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function buildDisplayPath(searchRoot: string, cwd: string, relativePath: string): string {
|
|
103
|
-
const scopeLabel = formatScopeLabel(searchRoot, cwd);
|
|
104
|
-
const normalized = relativePath.replace(/\\/g, "/");
|
|
105
|
-
if (scopeLabel === ".") {
|
|
106
|
-
return normalized;
|
|
107
|
-
}
|
|
108
|
-
if (scopeLabel.startsWith("..") || path.isAbsolute(scopeLabel)) {
|
|
109
|
-
return path.join(searchRoot, normalized).replace(/\\/g, "/");
|
|
110
|
-
}
|
|
111
|
-
return `${scopeLabel}/${normalized}`;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function levenshteinDistance(a: string, b: string): number {
|
|
115
|
-
if (a === b) return 0;
|
|
116
|
-
const aLen = a.length;
|
|
117
|
-
const bLen = b.length;
|
|
118
|
-
if (aLen === 0) return bLen;
|
|
119
|
-
if (bLen === 0) return aLen;
|
|
120
|
-
|
|
121
|
-
let prev = new Array<number>(bLen + 1);
|
|
122
|
-
let curr = new Array<number>(bLen + 1);
|
|
123
|
-
for (let j = 0; j <= bLen; j++) {
|
|
124
|
-
prev[j] = j;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
for (let i = 1; i <= aLen; i++) {
|
|
128
|
-
curr[0] = i;
|
|
129
|
-
const aCode = a.charCodeAt(i - 1);
|
|
130
|
-
for (let j = 1; j <= bLen; j++) {
|
|
131
|
-
const cost = aCode === b.charCodeAt(j - 1) ? 0 : 1;
|
|
132
|
-
const deletion = prev[j] + 1;
|
|
133
|
-
const insertion = curr[j - 1] + 1;
|
|
134
|
-
const substitution = prev[j - 1] + cost;
|
|
135
|
-
curr[j] = Math.min(deletion, insertion, substitution);
|
|
136
|
-
}
|
|
137
|
-
const tmp = prev;
|
|
138
|
-
prev = curr;
|
|
139
|
-
curr = tmp;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return prev[bLen];
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function similarityScore(a: string, b: string): number {
|
|
146
|
-
if (a.length === 0 && b.length === 0) {
|
|
147
|
-
return 1;
|
|
148
|
-
}
|
|
149
|
-
const maxLen = Math.max(a.length, b.length);
|
|
150
|
-
if (maxLen === 0) {
|
|
151
|
-
return 1;
|
|
152
|
-
}
|
|
153
|
-
const distance = levenshteinDistance(a, b);
|
|
154
|
-
return 1 - distance / maxLen;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async function listCandidateFiles(
|
|
158
|
-
searchRoot: string,
|
|
159
|
-
signal?: AbortSignal,
|
|
160
|
-
): Promise<{ files: string[]; truncated: boolean; error?: string }> {
|
|
161
|
-
let fdPath: string | undefined;
|
|
162
|
-
try {
|
|
163
|
-
fdPath = await ensureTool("fd", true);
|
|
164
|
-
} catch {
|
|
165
|
-
return { files: [], truncated: false, error: "fd not available" };
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (!fdPath) {
|
|
169
|
-
return { files: [], truncated: false, error: "fd not available" };
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const args: string[] = ["--type", "f", "--color=never", "--hidden", "--max-results", String(MAX_FUZZY_CANDIDATES)];
|
|
173
|
-
|
|
174
|
-
const gitignoreFiles = new Set<string>();
|
|
175
|
-
const rootGitignore = path.join(searchRoot, ".gitignore");
|
|
176
|
-
if (await Bun.file(rootGitignore).exists()) {
|
|
177
|
-
gitignoreFiles.add(rootGitignore);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
try {
|
|
181
|
-
const gitignoreArgs = [
|
|
182
|
-
"--type",
|
|
183
|
-
"f",
|
|
184
|
-
"--color=never",
|
|
185
|
-
"--hidden",
|
|
186
|
-
"--absolute-path",
|
|
187
|
-
"--glob",
|
|
188
|
-
".gitignore",
|
|
189
|
-
"--exclude",
|
|
190
|
-
"node_modules",
|
|
191
|
-
"--exclude",
|
|
192
|
-
".git",
|
|
193
|
-
searchRoot,
|
|
194
|
-
];
|
|
195
|
-
const { stdout } = await runFd(fdPath, gitignoreArgs, signal);
|
|
196
|
-
const output = stdout.trim();
|
|
197
|
-
if (output) {
|
|
198
|
-
const nestedGitignores = output
|
|
199
|
-
.split("\n")
|
|
200
|
-
.map((line) => line.replace(/\r$/, "").trim())
|
|
201
|
-
.filter((line) => line.length > 0);
|
|
202
|
-
for (const file of nestedGitignores) {
|
|
203
|
-
const normalized = file.replace(/\\/g, "/");
|
|
204
|
-
if (normalized.includes("/node_modules/") || normalized.includes("/.git/")) {
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
gitignoreFiles.add(file);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
} catch (error) {
|
|
211
|
-
if (error instanceof Error && error.message === "Operation aborted") {
|
|
212
|
-
throw error;
|
|
213
|
-
}
|
|
214
|
-
// Ignore gitignore scan errors.
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
for (const gitignorePath of gitignoreFiles) {
|
|
218
|
-
args.push("--ignore-file", gitignorePath);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
args.push(".", searchRoot);
|
|
222
|
-
|
|
223
|
-
const { stdout, stderr, exitCode } = await runFd(fdPath, args, signal);
|
|
224
|
-
const output = stdout.trim();
|
|
225
|
-
|
|
226
|
-
if (!output) {
|
|
227
|
-
// fd exit codes: 0 = found, 1 = no matches, other = error
|
|
228
|
-
if (exitCode !== 0 && exitCode !== 1) {
|
|
229
|
-
return { files: [], truncated: false, error: stderr.trim() || `fd failed (exit ${exitCode})` };
|
|
230
|
-
}
|
|
231
|
-
return { files: [], truncated: false };
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const files = output
|
|
235
|
-
.split("\n")
|
|
236
|
-
.map((line) => line.replace(/\r$/, "").trim())
|
|
237
|
-
.filter((line) => line.length > 0);
|
|
238
|
-
|
|
239
|
-
return { files, truncated: files.length >= MAX_FUZZY_CANDIDATES };
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
async function findReadPathSuggestions(
|
|
243
|
-
rawPath: string,
|
|
244
|
-
cwd: string,
|
|
245
|
-
signal?: AbortSignal,
|
|
246
|
-
): Promise<{ suggestions: string[]; scopeLabel?: string; truncated?: boolean; error?: string } | null> {
|
|
247
|
-
const resolvedPath = resolveToCwd(rawPath, cwd);
|
|
248
|
-
const searchRoot = await findExistingDirectory(path.dirname(resolvedPath), signal);
|
|
249
|
-
if (!searchRoot) {
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (!isPathWithin(cwd, resolvedPath)) {
|
|
254
|
-
const root = path.parse(searchRoot).root;
|
|
255
|
-
if (searchRoot === root) {
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const { files, truncated, error } = await listCandidateFiles(searchRoot, signal);
|
|
261
|
-
const scopeLabel = formatScopeLabel(searchRoot, cwd);
|
|
262
|
-
|
|
263
|
-
if (error && files.length === 0) {
|
|
264
|
-
return { suggestions: [], scopeLabel, truncated, error };
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (files.length === 0) {
|
|
268
|
-
return null;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const queryPath = (() => {
|
|
272
|
-
if (path.isAbsolute(rawPath)) {
|
|
273
|
-
const relative = path.relative(cwd, resolvedPath).replace(/\\/g, "/");
|
|
274
|
-
if (relative && !relative.startsWith("..") && !path.isAbsolute(relative)) {
|
|
275
|
-
return normalizePathForMatch(relative);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return normalizePathForMatch(rawPath);
|
|
279
|
-
})();
|
|
280
|
-
const baseQuery = path.posix.basename(queryPath);
|
|
281
|
-
|
|
282
|
-
const matches: Array<{ path: string; score: number; baseScore: number; fullScore: number }> = [];
|
|
283
|
-
const seen = new Set<string>();
|
|
284
|
-
|
|
285
|
-
for (const file of files) {
|
|
286
|
-
signal?.throwIfAborted();
|
|
287
|
-
const cleaned = file.replace(/\r$/, "").trim();
|
|
288
|
-
if (!cleaned) continue;
|
|
289
|
-
|
|
290
|
-
const relativePath = path.isAbsolute(cleaned)
|
|
291
|
-
? cleaned.startsWith(searchRoot)
|
|
292
|
-
? cleaned.slice(searchRoot.length + 1)
|
|
293
|
-
: path.relative(searchRoot, cleaned)
|
|
294
|
-
: cleaned;
|
|
295
|
-
|
|
296
|
-
if (!relativePath || relativePath.startsWith("..")) {
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const displayPath = buildDisplayPath(searchRoot, cwd, relativePath);
|
|
301
|
-
if (seen.has(displayPath)) {
|
|
302
|
-
continue;
|
|
303
|
-
}
|
|
304
|
-
seen.add(displayPath);
|
|
305
|
-
|
|
306
|
-
const normalizedDisplay = normalizePathForMatch(displayPath);
|
|
307
|
-
const baseCandidate = path.posix.basename(normalizedDisplay);
|
|
308
|
-
|
|
309
|
-
const fullScore = similarityScore(queryPath, normalizedDisplay);
|
|
310
|
-
const baseScore = baseQuery ? similarityScore(baseQuery, baseCandidate) : 0;
|
|
311
|
-
|
|
312
|
-
if (baseQuery) {
|
|
313
|
-
if (baseScore < MIN_BASE_SIMILARITY && fullScore < MIN_FULL_SIMILARITY) {
|
|
314
|
-
continue;
|
|
315
|
-
}
|
|
316
|
-
} else if (fullScore < MIN_FULL_SIMILARITY) {
|
|
317
|
-
continue;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const score = baseQuery ? baseScore * 0.75 + fullScore * 0.25 : fullScore;
|
|
321
|
-
matches.push({ path: displayPath, score, baseScore, fullScore });
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (matches.length === 0) {
|
|
325
|
-
return { suggestions: [], scopeLabel, truncated };
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
matches.sort((a, b) => {
|
|
329
|
-
if (b.score !== a.score) return b.score - a.score;
|
|
330
|
-
if (b.baseScore !== a.baseScore) return b.baseScore - a.baseScore;
|
|
331
|
-
return a.path.localeCompare(b.path);
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
const suggestions = matches.slice(0, MAX_FUZZY_RESULTS).map((match) => match.path);
|
|
335
|
-
|
|
336
|
-
return { suggestions, scopeLabel, truncated };
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
async function convertWithMarkitdown(
|
|
340
|
-
filePath: string,
|
|
341
|
-
signal?: AbortSignal,
|
|
342
|
-
): Promise<{ content: string; ok: boolean; error?: string }> {
|
|
343
|
-
const cmd = await ensureTool("markitdown", true);
|
|
344
|
-
if (!cmd) {
|
|
345
|
-
return { content: "", ok: false, error: "markitdown not found (uv/pip unavailable)" };
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
const child = ptree.cspawn([cmd, filePath], { signal });
|
|
349
|
-
let stdout: string;
|
|
350
|
-
try {
|
|
351
|
-
stdout = await child.nothrow().text();
|
|
352
|
-
} catch (err) {
|
|
353
|
-
if (err instanceof ptree.Exception && err.aborted) {
|
|
354
|
-
throw new Error("Operation aborted");
|
|
355
|
-
}
|
|
356
|
-
throw err;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if (child.exitCode === 0 && stdout.length > 0) {
|
|
360
|
-
return { content: stdout, ok: true };
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return { content: "", ok: false, error: child.peekStderr().trim() || "Conversion failed" };
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
const readSchema = Type.Object({
|
|
367
|
-
path: Type.String({ description: "Path to the file to read (relative or absolute)" }),
|
|
368
|
-
offset: Type.Optional(Type.Number({ description: "Line number to start reading from (1-indexed)" })),
|
|
369
|
-
limit: Type.Optional(Type.Number({ description: "Maximum number of lines to read" })),
|
|
370
|
-
lines: Type.Optional(Type.Boolean({ description: "Prepend line numbers to output (default: false)" })),
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
export interface ReadToolDetails {
|
|
374
|
-
truncation?: TruncationResult;
|
|
375
|
-
redirectedTo?: "ls";
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
type ReadParams = { path: string; offset?: number; limit?: number; lines?: boolean };
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Read tool implementation.
|
|
382
|
-
*
|
|
383
|
-
* Reads files with support for images, documents (via markitdown), and text.
|
|
384
|
-
* Directories redirect to the ls tool.
|
|
385
|
-
*/
|
|
386
|
-
export class ReadTool implements AgentTool<typeof readSchema, ReadToolDetails> {
|
|
387
|
-
public readonly name = "read";
|
|
388
|
-
public readonly label = "Read";
|
|
389
|
-
public readonly description: string;
|
|
390
|
-
public readonly parameters = readSchema;
|
|
391
|
-
|
|
392
|
-
private readonly session: ToolSession;
|
|
393
|
-
private readonly autoResizeImages: boolean;
|
|
394
|
-
private readonly defaultLineNumbers: boolean;
|
|
395
|
-
private readonly lsTool: LsTool;
|
|
396
|
-
|
|
397
|
-
constructor(session: ToolSession) {
|
|
398
|
-
this.session = session;
|
|
399
|
-
this.autoResizeImages = session.settings?.getImageAutoResize() ?? true;
|
|
400
|
-
this.defaultLineNumbers = session.settings?.getReadLineNumbers?.() ?? false;
|
|
401
|
-
this.lsTool = new LsTool(session);
|
|
402
|
-
this.description = renderPromptTemplate(readDescription, {
|
|
403
|
-
DEFAULT_MAX_LINES: String(DEFAULT_MAX_LINES),
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
public async execute(
|
|
408
|
-
toolCallId: string,
|
|
409
|
-
params: ReadParams,
|
|
410
|
-
signal?: AbortSignal,
|
|
411
|
-
_onUpdate?: AgentToolUpdateCallback<ReadToolDetails>,
|
|
412
|
-
_context?: AgentToolContext,
|
|
413
|
-
): Promise<AgentToolResult<ReadToolDetails>> {
|
|
414
|
-
const { path: readPath, offset, limit, lines } = params;
|
|
415
|
-
const absolutePath = resolveReadPath(readPath, this.session.cwd);
|
|
416
|
-
|
|
417
|
-
return untilAborted(signal, async () => {
|
|
418
|
-
let isDirectory = false;
|
|
419
|
-
let fileSize = 0;
|
|
420
|
-
try {
|
|
421
|
-
const stat = await Bun.file(absolutePath).stat();
|
|
422
|
-
fileSize = stat.size;
|
|
423
|
-
isDirectory = stat.isDirectory();
|
|
424
|
-
} catch (error) {
|
|
425
|
-
if (isNotFoundError(error)) {
|
|
426
|
-
let message = `File not found: ${readPath}`;
|
|
427
|
-
|
|
428
|
-
// Skip fuzzy matching for remote mounts (sshfs) to avoid hangs
|
|
429
|
-
if (!isRemoteMountPath(absolutePath)) {
|
|
430
|
-
const suggestions = await findReadPathSuggestions(readPath, this.session.cwd, signal);
|
|
431
|
-
|
|
432
|
-
if (suggestions?.suggestions.length) {
|
|
433
|
-
const scopeLabel = suggestions.scopeLabel ? ` in ${suggestions.scopeLabel}` : "";
|
|
434
|
-
message += `\n\nClosest matches${scopeLabel}:\n${suggestions.suggestions.map((match) => `- ${match}`).join("\n")}`;
|
|
435
|
-
if (suggestions.truncated) {
|
|
436
|
-
message += `\n[Search truncated to first ${MAX_FUZZY_CANDIDATES} paths. Refine the path if the match isn't listed.]`;
|
|
437
|
-
}
|
|
438
|
-
} else if (suggestions?.error) {
|
|
439
|
-
message += `\n\nFuzzy match failed: ${suggestions.error}`;
|
|
440
|
-
} else if (suggestions?.scopeLabel) {
|
|
441
|
-
message += `\n\nNo similar paths found in ${suggestions.scopeLabel}.`;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
throw new Error(message);
|
|
446
|
-
}
|
|
447
|
-
throw error;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
if (isDirectory) {
|
|
451
|
-
const lsResult = await this.lsTool.execute(toolCallId, { path: readPath, limit }, signal);
|
|
452
|
-
return {
|
|
453
|
-
content: lsResult.content,
|
|
454
|
-
details: { redirectedTo: "ls", truncation: lsResult.details?.truncation },
|
|
455
|
-
};
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
const mimeType = await detectSupportedImageMimeTypeFromFile(absolutePath);
|
|
459
|
-
const ext = path.extname(absolutePath).toLowerCase();
|
|
460
|
-
|
|
461
|
-
// Read the file based on type
|
|
462
|
-
let content: (TextContent | ImageContent)[];
|
|
463
|
-
let details: ReadToolDetails | undefined;
|
|
464
|
-
|
|
465
|
-
if (mimeType) {
|
|
466
|
-
if (fileSize > MAX_IMAGE_SIZE) {
|
|
467
|
-
const sizeStr = formatSize(fileSize);
|
|
468
|
-
const maxStr = formatSize(MAX_IMAGE_SIZE);
|
|
469
|
-
content = [
|
|
470
|
-
{
|
|
471
|
-
type: "text",
|
|
472
|
-
text: `[Image file too large: ${sizeStr} exceeds ${maxStr} limit. Use an image viewer or resize the image.]`,
|
|
473
|
-
},
|
|
474
|
-
];
|
|
475
|
-
} else {
|
|
476
|
-
// Read as image (binary)
|
|
477
|
-
const file = Bun.file(absolutePath);
|
|
478
|
-
const buffer = await file.arrayBuffer();
|
|
479
|
-
|
|
480
|
-
// Check actual buffer size after reading to prevent OOM during serialization
|
|
481
|
-
if (buffer.byteLength > MAX_IMAGE_SIZE) {
|
|
482
|
-
const sizeStr = formatSize(buffer.byteLength);
|
|
483
|
-
const maxStr = formatSize(MAX_IMAGE_SIZE);
|
|
484
|
-
content = [
|
|
485
|
-
{
|
|
486
|
-
type: "text",
|
|
487
|
-
text: `[Image file too large: ${sizeStr} exceeds ${maxStr} limit. Use an image viewer or resize the image.]`,
|
|
488
|
-
},
|
|
489
|
-
];
|
|
490
|
-
} else {
|
|
491
|
-
const base64 = Buffer.from(buffer).toString("base64");
|
|
492
|
-
|
|
493
|
-
if (this.autoResizeImages) {
|
|
494
|
-
// Resize image if needed - catch errors from WASM
|
|
495
|
-
try {
|
|
496
|
-
const resized = await resizeImage({ type: "image", data: base64, mimeType });
|
|
497
|
-
const dimensionNote = formatDimensionNote(resized);
|
|
498
|
-
|
|
499
|
-
let textNote = `Read image file [${resized.mimeType}]`;
|
|
500
|
-
if (dimensionNote) {
|
|
501
|
-
textNote += `\n${dimensionNote}`;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
content = [
|
|
505
|
-
{ type: "text", text: textNote },
|
|
506
|
-
{ type: "image", data: resized.data, mimeType: resized.mimeType },
|
|
507
|
-
];
|
|
508
|
-
} catch {
|
|
509
|
-
// Fall back to original image on resize failure
|
|
510
|
-
content = [
|
|
511
|
-
{ type: "text", text: `Read image file [${mimeType}]` },
|
|
512
|
-
{ type: "image", data: base64, mimeType },
|
|
513
|
-
];
|
|
514
|
-
}
|
|
515
|
-
} else {
|
|
516
|
-
content = [
|
|
517
|
-
{ type: "text", text: `Read image file [${mimeType}]` },
|
|
518
|
-
{ type: "image", data: base64, mimeType },
|
|
519
|
-
];
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
} else if (CONVERTIBLE_EXTENSIONS.has(ext)) {
|
|
524
|
-
// Convert document via markitdown
|
|
525
|
-
const result = await convertWithMarkitdown(absolutePath, signal);
|
|
526
|
-
if (result.ok) {
|
|
527
|
-
// Apply truncation to converted content
|
|
528
|
-
const truncation = truncateHead(result.content);
|
|
529
|
-
let outputText = truncation.content;
|
|
530
|
-
|
|
531
|
-
if (truncation.truncated) {
|
|
532
|
-
outputText += `\n\n[Document converted via markitdown. Output truncated to ${formatSize(DEFAULT_MAX_BYTES)}]`;
|
|
533
|
-
details = { truncation };
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
content = [{ type: "text", text: outputText }];
|
|
537
|
-
} else if (result.error) {
|
|
538
|
-
// markitdown not available or failed
|
|
539
|
-
const errorMsg =
|
|
540
|
-
result.error === "markitdown not found"
|
|
541
|
-
? `markitdown not installed. Install with: pip install markitdown`
|
|
542
|
-
: result.error || "conversion failed";
|
|
543
|
-
content = [{ type: "text", text: `[Cannot read ${ext} file: ${errorMsg}]` }];
|
|
544
|
-
} else {
|
|
545
|
-
content = [{ type: "text", text: `[Cannot read ${ext} file: conversion failed]` }];
|
|
546
|
-
}
|
|
547
|
-
} else {
|
|
548
|
-
// Read as text
|
|
549
|
-
const file = Bun.file(absolutePath);
|
|
550
|
-
const textContent = await file.text();
|
|
551
|
-
const allLines = textContent.split("\n");
|
|
552
|
-
const totalFileLines = allLines.length;
|
|
553
|
-
|
|
554
|
-
// Apply offset if specified (1-indexed to 0-indexed)
|
|
555
|
-
const startLine = offset ? Math.max(0, offset - 1) : 0;
|
|
556
|
-
const startLineDisplay = startLine + 1; // For display (1-indexed)
|
|
557
|
-
|
|
558
|
-
// Check if offset is out of bounds - return graceful message instead of throwing
|
|
559
|
-
if (startLine >= allLines.length) {
|
|
560
|
-
const suggestion =
|
|
561
|
-
allLines.length === 0
|
|
562
|
-
? "The file is empty."
|
|
563
|
-
: `Use offset=1 to read from the start, or offset=${allLines.length} to read the last line.`;
|
|
564
|
-
return {
|
|
565
|
-
content: [
|
|
566
|
-
{
|
|
567
|
-
type: "text",
|
|
568
|
-
text: `Offset ${offset} is beyond end of file (${allLines.length} lines total). ${suggestion}`,
|
|
569
|
-
},
|
|
570
|
-
],
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
// If limit is specified by user, use it; otherwise we'll let truncateHead decide
|
|
575
|
-
let selectedContent: string;
|
|
576
|
-
let userLimitedLines: number | undefined;
|
|
577
|
-
if (limit !== undefined) {
|
|
578
|
-
const endLine = Math.min(startLine + limit, allLines.length);
|
|
579
|
-
selectedContent = allLines.slice(startLine, endLine).join("\n");
|
|
580
|
-
userLimitedLines = endLine - startLine;
|
|
581
|
-
} else {
|
|
582
|
-
selectedContent = allLines.slice(startLine).join("\n");
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
// Apply truncation (respects both line and byte limits)
|
|
586
|
-
const truncation = truncateHead(selectedContent);
|
|
587
|
-
|
|
588
|
-
// Add line numbers if requested (uses setting default if not specified)
|
|
589
|
-
const shouldAddLineNumbers = lines ?? this.defaultLineNumbers;
|
|
590
|
-
const prependLineNumbers = (text: string, startNum: number): string => {
|
|
591
|
-
const textLines = text.split("\n");
|
|
592
|
-
const lastLineNum = startNum + textLines.length - 1;
|
|
593
|
-
const padWidth = String(lastLineNum).length;
|
|
594
|
-
return textLines
|
|
595
|
-
.map((line, i) => {
|
|
596
|
-
const lineNum = String(startNum + i).padStart(padWidth, " ");
|
|
597
|
-
return `${lineNum}\t${line}`;
|
|
598
|
-
})
|
|
599
|
-
.join("\n");
|
|
600
|
-
};
|
|
601
|
-
|
|
602
|
-
let outputText: string;
|
|
603
|
-
|
|
604
|
-
if (truncation.firstLineExceedsLimit) {
|
|
605
|
-
const firstLine = allLines[startLine] ?? "";
|
|
606
|
-
const firstLineBytes = Buffer.byteLength(firstLine, "utf-8");
|
|
607
|
-
const snippet = truncateStringToBytesFromStart(firstLine, DEFAULT_MAX_BYTES);
|
|
608
|
-
const shownSize = formatSize(snippet.bytes);
|
|
609
|
-
|
|
610
|
-
outputText = shouldAddLineNumbers ? prependLineNumbers(snippet.text, startLineDisplay) : snippet.text;
|
|
611
|
-
if (snippet.text.length > 0) {
|
|
612
|
-
outputText += `\n\n[Line ${startLineDisplay} is ${formatSize(
|
|
613
|
-
firstLineBytes,
|
|
614
|
-
)}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Showing first ${shownSize} of the line.]`;
|
|
615
|
-
} else {
|
|
616
|
-
outputText = `[Line ${startLineDisplay} is ${formatSize(
|
|
617
|
-
firstLineBytes,
|
|
618
|
-
)}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Unable to display a valid UTF-8 snippet.]`;
|
|
619
|
-
}
|
|
620
|
-
details = { truncation };
|
|
621
|
-
} else if (truncation.truncated) {
|
|
622
|
-
// Truncation occurred - build actionable notice
|
|
623
|
-
const endLineDisplay = startLineDisplay + truncation.outputLines - 1;
|
|
624
|
-
const nextOffset = endLineDisplay + 1;
|
|
625
|
-
|
|
626
|
-
outputText = shouldAddLineNumbers
|
|
627
|
-
? prependLineNumbers(truncation.content, startLineDisplay)
|
|
628
|
-
: truncation.content;
|
|
629
|
-
|
|
630
|
-
if (truncation.truncatedBy === "lines") {
|
|
631
|
-
outputText += `\n\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines}. Use offset=${nextOffset} to continue]`;
|
|
632
|
-
} else {
|
|
633
|
-
outputText += `\n\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines} (${formatSize(
|
|
634
|
-
DEFAULT_MAX_BYTES,
|
|
635
|
-
)} limit). Use offset=${nextOffset} to continue]`;
|
|
636
|
-
}
|
|
637
|
-
details = { truncation };
|
|
638
|
-
} else if (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {
|
|
639
|
-
// User specified limit, there's more content, but no truncation
|
|
640
|
-
const remaining = allLines.length - (startLine + userLimitedLines);
|
|
641
|
-
const nextOffset = startLine + userLimitedLines + 1;
|
|
642
|
-
|
|
643
|
-
outputText = shouldAddLineNumbers
|
|
644
|
-
? prependLineNumbers(truncation.content, startLineDisplay)
|
|
645
|
-
: truncation.content;
|
|
646
|
-
outputText += `\n\n[${remaining} more lines in file. Use offset=${nextOffset} to continue]`;
|
|
647
|
-
} else {
|
|
648
|
-
// No truncation, no user limit exceeded
|
|
649
|
-
outputText = shouldAddLineNumbers
|
|
650
|
-
? prependLineNumbers(truncation.content, startLineDisplay)
|
|
651
|
-
: truncation.content;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
content = [{ type: "text", text: outputText }];
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
return { content, details };
|
|
658
|
-
});
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
// =============================================================================
|
|
663
|
-
// TUI Renderer
|
|
664
|
-
// =============================================================================
|
|
665
|
-
|
|
666
|
-
interface ReadRenderArgs {
|
|
667
|
-
path?: string;
|
|
668
|
-
file_path?: string;
|
|
669
|
-
offset?: number;
|
|
670
|
-
limit?: number;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
export const readToolRenderer = {
|
|
674
|
-
renderCall(args: ReadRenderArgs, uiTheme: Theme): Component {
|
|
675
|
-
const rawPath = args.file_path || args.path || "";
|
|
676
|
-
const filePath = shortenPath(rawPath);
|
|
677
|
-
const offset = args.offset;
|
|
678
|
-
const limit = args.limit;
|
|
679
|
-
|
|
680
|
-
let pathDisplay = filePath ? uiTheme.fg("accent", filePath) : uiTheme.fg("toolOutput", uiTheme.format.ellipsis);
|
|
681
|
-
if (offset !== undefined || limit !== undefined) {
|
|
682
|
-
const startLine = offset ?? 1;
|
|
683
|
-
const endLine = limit !== undefined ? startLine + limit - 1 : "";
|
|
684
|
-
pathDisplay += uiTheme.fg("warning", `:${startLine}${endLine ? `-${endLine}` : ""}`);
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
const text = `${uiTheme.fg("toolTitle", uiTheme.bold("Read"))} ${pathDisplay}`;
|
|
688
|
-
return new Text(text, 0, 0);
|
|
689
|
-
},
|
|
690
|
-
|
|
691
|
-
renderResult(
|
|
692
|
-
result: { content: Array<{ type: string; text?: string }>; details?: ReadToolDetails },
|
|
693
|
-
_options: RenderResultOptions,
|
|
694
|
-
uiTheme: Theme,
|
|
695
|
-
_args?: ReadRenderArgs,
|
|
696
|
-
): Component {
|
|
697
|
-
const details = result.details;
|
|
698
|
-
const lines: string[] = [];
|
|
699
|
-
|
|
700
|
-
lines.push(uiTheme.fg("dim", "Content hidden"));
|
|
701
|
-
|
|
702
|
-
const truncation = details?.truncation;
|
|
703
|
-
if (truncation?.truncated) {
|
|
704
|
-
let warning: string;
|
|
705
|
-
if (truncation.firstLineExceedsLimit) {
|
|
706
|
-
warning = `First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`;
|
|
707
|
-
} else if (truncation.truncatedBy === "lines") {
|
|
708
|
-
warning = `Truncated: ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)`;
|
|
709
|
-
} else {
|
|
710
|
-
warning = `Truncated: ${truncation.outputLines} lines (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`;
|
|
711
|
-
}
|
|
712
|
-
lines.push(uiTheme.fg("warning", wrapBrackets(warning, uiTheme)));
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
return new Text(lines.join("\n"), 0, 0);
|
|
716
|
-
},
|
|
717
|
-
};
|