@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
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured metadata for tool outputs.
|
|
3
|
+
*
|
|
4
|
+
* Tools populate details.meta using the fluent OutputMetaBuilder.
|
|
5
|
+
* The tool wrapper automatically formats and appends notices at message boundary.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { AgentTool, AgentToolResult } from "@oh-my-pi/pi-agent-core";
|
|
9
|
+
import type { ImageContent, TextContent } from "@oh-my-pi/pi-ai";
|
|
10
|
+
import type { OutputSummary } from "$c/session/streaming-output";
|
|
11
|
+
import type { TruncationResult } from "$c/tools/truncate";
|
|
12
|
+
import { formatSize } from "$c/tools/truncate";
|
|
13
|
+
import { renderError } from "./tool-errors";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Truncation metadata for the output notice.
|
|
17
|
+
*/
|
|
18
|
+
export interface TruncationMeta {
|
|
19
|
+
direction: "head" | "tail";
|
|
20
|
+
truncatedBy: "lines" | "bytes";
|
|
21
|
+
totalLines: number;
|
|
22
|
+
totalBytes: number;
|
|
23
|
+
outputLines: number;
|
|
24
|
+
outputBytes: number;
|
|
25
|
+
/** Line range shown (1-indexed, inclusive) */
|
|
26
|
+
shownRange?: { start: number; end: number };
|
|
27
|
+
/** Artifact ID if full output was saved */
|
|
28
|
+
artifactId?: string;
|
|
29
|
+
/** Next offset for pagination (head truncation only) */
|
|
30
|
+
nextOffset?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Source resolution info for the output.
|
|
35
|
+
*/
|
|
36
|
+
export type SourceMeta =
|
|
37
|
+
| { type: "path"; value: string }
|
|
38
|
+
| { type: "url"; value: string }
|
|
39
|
+
| { type: "internal"; value: string };
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* LSP diagnostic info (for edit/write tools).
|
|
43
|
+
*/
|
|
44
|
+
export interface DiagnosticMeta {
|
|
45
|
+
summary: string;
|
|
46
|
+
messages: string[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Limit-specific notices.
|
|
51
|
+
*/
|
|
52
|
+
export interface LimitsMeta {
|
|
53
|
+
matchLimit?: { reached: number; suggestion: number };
|
|
54
|
+
resultLimit?: { reached: number; suggestion: number };
|
|
55
|
+
headLimit?: { reached: number; suggestion: number };
|
|
56
|
+
columnTruncated?: { maxColumn: number };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Structured metadata for tool outputs.
|
|
61
|
+
*/
|
|
62
|
+
export interface OutputMeta {
|
|
63
|
+
truncation?: TruncationMeta;
|
|
64
|
+
source?: SourceMeta;
|
|
65
|
+
diagnostics?: DiagnosticMeta;
|
|
66
|
+
limits?: LimitsMeta;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// =============================================================================
|
|
70
|
+
// OutputMetaBuilder - Fluent API for building OutputMeta
|
|
71
|
+
// =============================================================================
|
|
72
|
+
|
|
73
|
+
export interface TruncationOptions {
|
|
74
|
+
direction: "head" | "tail";
|
|
75
|
+
startLine?: number;
|
|
76
|
+
totalFileLines?: number;
|
|
77
|
+
artifactId?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface TruncationSummaryOptions {
|
|
81
|
+
direction: "head" | "tail";
|
|
82
|
+
startLine?: number;
|
|
83
|
+
totalFileLines?: number;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface TruncationTextOptions {
|
|
87
|
+
direction: "head" | "tail";
|
|
88
|
+
totalLines?: number;
|
|
89
|
+
totalBytes?: number;
|
|
90
|
+
maxBytes?: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Fluent builder for OutputMeta.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* details.meta = outputMeta()
|
|
99
|
+
* .truncation(truncation, { direction: "head" })
|
|
100
|
+
* .matchLimit(limitReached ? effectiveLimit : 0)
|
|
101
|
+
* .columnTruncated(linesTruncated ? DEFAULT_MAX_COLUMN : 0)
|
|
102
|
+
* .get();
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export class OutputMetaBuilder {
|
|
106
|
+
#meta: OutputMeta = {};
|
|
107
|
+
|
|
108
|
+
/** Add truncation info from TruncationResult. No-op if not truncated. */
|
|
109
|
+
truncation(result: TruncationResult, options: TruncationOptions): this {
|
|
110
|
+
if (!result.truncated) return this;
|
|
111
|
+
|
|
112
|
+
const { direction, startLine = 1, totalFileLines, artifactId } = options;
|
|
113
|
+
|
|
114
|
+
let shownStart: number;
|
|
115
|
+
let shownEnd: number;
|
|
116
|
+
|
|
117
|
+
if (direction === "tail") {
|
|
118
|
+
shownStart = result.totalLines - result.outputLines + 1;
|
|
119
|
+
shownEnd = result.totalLines;
|
|
120
|
+
} else {
|
|
121
|
+
shownStart = startLine;
|
|
122
|
+
shownEnd = startLine + result.outputLines - 1;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.#meta.truncation = {
|
|
126
|
+
direction,
|
|
127
|
+
truncatedBy: result.truncatedBy!,
|
|
128
|
+
totalLines: totalFileLines ?? result.totalLines,
|
|
129
|
+
totalBytes: result.totalBytes,
|
|
130
|
+
outputLines: result.outputLines,
|
|
131
|
+
outputBytes: result.outputBytes,
|
|
132
|
+
shownRange: { start: shownStart, end: shownEnd },
|
|
133
|
+
artifactId,
|
|
134
|
+
nextOffset: direction === "head" ? shownEnd + 1 : undefined,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Add truncation info from OutputSummary. No-op if not truncated. */
|
|
141
|
+
truncationFromSummary(summary: OutputSummary, options: TruncationSummaryOptions): this {
|
|
142
|
+
if (!summary.truncated) return this;
|
|
143
|
+
|
|
144
|
+
const { direction, startLine = 1, totalFileLines } = options;
|
|
145
|
+
const totalLines = totalFileLines ?? summary.totalLines;
|
|
146
|
+
const truncatedBy: "lines" | "bytes" =
|
|
147
|
+
summary.outputBytes < summary.totalBytes
|
|
148
|
+
? "bytes"
|
|
149
|
+
: summary.outputLines < summary.totalLines
|
|
150
|
+
? "lines"
|
|
151
|
+
: "bytes";
|
|
152
|
+
|
|
153
|
+
let shownStart: number;
|
|
154
|
+
let shownEnd: number;
|
|
155
|
+
|
|
156
|
+
if (direction === "tail") {
|
|
157
|
+
shownStart = totalLines - summary.outputLines + 1;
|
|
158
|
+
shownEnd = totalLines;
|
|
159
|
+
} else {
|
|
160
|
+
shownStart = startLine;
|
|
161
|
+
shownEnd = startLine + summary.outputLines - 1;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
this.#meta.truncation = {
|
|
165
|
+
direction,
|
|
166
|
+
truncatedBy,
|
|
167
|
+
totalLines,
|
|
168
|
+
totalBytes: summary.totalBytes,
|
|
169
|
+
outputLines: summary.outputLines,
|
|
170
|
+
outputBytes: summary.outputBytes,
|
|
171
|
+
shownRange: { start: shownStart, end: shownEnd },
|
|
172
|
+
artifactId: summary.artifactId,
|
|
173
|
+
nextOffset: direction === "head" ? shownEnd + 1 : undefined,
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Add truncation info from truncated output text. No-op if truncation not detected. */
|
|
180
|
+
truncationFromText(text: string, options: TruncationTextOptions): this {
|
|
181
|
+
const outputLines = text.length > 0 ? text.split("\n").length : 0;
|
|
182
|
+
const outputBytes = Buffer.byteLength(text, "utf-8");
|
|
183
|
+
const totalLines = options.totalLines ?? outputLines;
|
|
184
|
+
const totalBytes = options.totalBytes ?? outputBytes;
|
|
185
|
+
|
|
186
|
+
const truncated = totalLines > outputLines || totalBytes > outputBytes || false;
|
|
187
|
+
if (!truncated) return this;
|
|
188
|
+
|
|
189
|
+
const truncatedBy: "lines" | "bytes" =
|
|
190
|
+
options.maxBytes && outputBytes >= options.maxBytes
|
|
191
|
+
? "bytes"
|
|
192
|
+
: totalBytes > outputBytes
|
|
193
|
+
? "bytes"
|
|
194
|
+
: totalLines > outputLines
|
|
195
|
+
? "lines"
|
|
196
|
+
: "bytes";
|
|
197
|
+
|
|
198
|
+
let shownStart: number;
|
|
199
|
+
let shownEnd: number;
|
|
200
|
+
|
|
201
|
+
if (options.direction === "tail") {
|
|
202
|
+
shownStart = totalLines - outputLines + 1;
|
|
203
|
+
shownEnd = totalLines;
|
|
204
|
+
} else {
|
|
205
|
+
shownStart = 1;
|
|
206
|
+
shownEnd = outputLines;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
this.#meta.truncation = {
|
|
210
|
+
direction: options.direction,
|
|
211
|
+
truncatedBy,
|
|
212
|
+
totalLines,
|
|
213
|
+
totalBytes,
|
|
214
|
+
outputLines,
|
|
215
|
+
outputBytes,
|
|
216
|
+
shownRange: { start: shownStart, end: shownEnd },
|
|
217
|
+
nextOffset: options.direction === "head" ? shownEnd + 1 : undefined,
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Add match limit notice. No-op if reached <= 0. */
|
|
224
|
+
matchLimit(reached: number, suggestion = reached * 2): this {
|
|
225
|
+
if (reached <= 0) return this;
|
|
226
|
+
this.#meta.limits = { ...this.#meta.limits, matchLimit: { reached, suggestion } };
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Add limit notices in one call. */
|
|
231
|
+
limits(limits: { matchLimit?: number; resultLimit?: number; headLimit?: number; columnMax?: number }): this {
|
|
232
|
+
if (limits.matchLimit !== undefined) {
|
|
233
|
+
this.matchLimit(limits.matchLimit);
|
|
234
|
+
}
|
|
235
|
+
if (limits.resultLimit !== undefined) {
|
|
236
|
+
this.resultLimit(limits.resultLimit);
|
|
237
|
+
}
|
|
238
|
+
if (limits.headLimit !== undefined) {
|
|
239
|
+
this.headLimit(limits.headLimit);
|
|
240
|
+
}
|
|
241
|
+
if (limits.columnMax !== undefined) {
|
|
242
|
+
this.columnTruncated(limits.columnMax);
|
|
243
|
+
}
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Add result limit notice. No-op if reached <= 0. */
|
|
248
|
+
resultLimit(reached: number, suggestion = reached * 2): this {
|
|
249
|
+
if (reached <= 0) return this;
|
|
250
|
+
this.#meta.limits = { ...this.#meta.limits, resultLimit: { reached, suggestion } };
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Add head_limit notice. No-op if reached <= 0. */
|
|
255
|
+
headLimit(reached: number, suggestion = reached * 2): this {
|
|
256
|
+
if (reached <= 0) return this;
|
|
257
|
+
this.#meta.limits = { ...this.#meta.limits, headLimit: { reached, suggestion } };
|
|
258
|
+
return this;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Add column truncation notice. No-op if maxColumn <= 0. */
|
|
262
|
+
columnTruncated(maxColumn: number): this {
|
|
263
|
+
if (maxColumn <= 0) return this;
|
|
264
|
+
this.#meta.limits = { ...this.#meta.limits, columnTruncated: { maxColumn } };
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** Add source path info. */
|
|
269
|
+
sourcePath(value: string): this {
|
|
270
|
+
this.#meta.source = { type: "path", value };
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** Add source URL info. */
|
|
275
|
+
sourceUrl(value: string): this {
|
|
276
|
+
this.#meta.source = { type: "url", value };
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Add internal URL source info (skill://, agent://, artifact://). */
|
|
281
|
+
sourceInternal(value: string): this {
|
|
282
|
+
this.#meta.source = { type: "internal", value };
|
|
283
|
+
return this;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** Add LSP diagnostics. No-op if no messages. */
|
|
287
|
+
diagnostics(summary: string, messages: string[]): this {
|
|
288
|
+
if (messages.length === 0) return this;
|
|
289
|
+
this.#meta.diagnostics = { summary, messages };
|
|
290
|
+
return this;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Get the built OutputMeta, or undefined if empty. */
|
|
294
|
+
get(): OutputMeta | undefined {
|
|
295
|
+
return Object.keys(this.#meta).length > 0 ? this.#meta : undefined;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Create a new OutputMetaBuilder. */
|
|
300
|
+
export function outputMeta(): OutputMetaBuilder {
|
|
301
|
+
return new OutputMetaBuilder();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// =============================================================================
|
|
305
|
+
// Notice formatting
|
|
306
|
+
// =============================================================================
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Format notices from OutputMeta for LLM consumption.
|
|
310
|
+
* Returns empty string if no notices needed.
|
|
311
|
+
*/
|
|
312
|
+
export function formatOutputNotice(meta: OutputMeta | undefined): string {
|
|
313
|
+
if (!meta) return "";
|
|
314
|
+
|
|
315
|
+
const parts: string[] = [];
|
|
316
|
+
|
|
317
|
+
// Truncation notice
|
|
318
|
+
if (meta.truncation) {
|
|
319
|
+
const t = meta.truncation;
|
|
320
|
+
const range = t.shownRange;
|
|
321
|
+
let notice: string;
|
|
322
|
+
|
|
323
|
+
if (range) {
|
|
324
|
+
notice = `Showing lines ${range.start}-${range.end} of ${t.totalLines}`;
|
|
325
|
+
} else {
|
|
326
|
+
notice = `Showing ${t.outputLines} of ${t.totalLines} lines`;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (t.truncatedBy === "bytes") {
|
|
330
|
+
notice += ` (${formatSize(t.outputBytes)} limit)`;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (t.nextOffset != null) {
|
|
334
|
+
notice += `. Use offset=${t.nextOffset} to continue`;
|
|
335
|
+
} else if (t.artifactId != null) {
|
|
336
|
+
notice += `. Full: artifact://${t.artifactId}`;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
parts.push(notice);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Limit notices
|
|
343
|
+
if (meta.limits?.matchLimit) {
|
|
344
|
+
const l = meta.limits.matchLimit;
|
|
345
|
+
parts.push(`${l.reached} matches limit reached. Use limit=${l.suggestion} for more`);
|
|
346
|
+
}
|
|
347
|
+
if (meta.limits?.resultLimit) {
|
|
348
|
+
const l = meta.limits.resultLimit;
|
|
349
|
+
parts.push(`${l.reached} results limit reached. Use limit=${l.suggestion} for more`);
|
|
350
|
+
}
|
|
351
|
+
if (meta.limits?.headLimit) {
|
|
352
|
+
const l = meta.limits.headLimit;
|
|
353
|
+
parts.push(`${l.reached} results limit reached. Use head_limit=${l.suggestion} for more`);
|
|
354
|
+
}
|
|
355
|
+
if (meta.limits?.columnTruncated) {
|
|
356
|
+
parts.push(`Some lines truncated to ${meta.limits.columnTruncated.maxColumn} chars`);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Diagnostics
|
|
360
|
+
let diagnosticsNotice = "";
|
|
361
|
+
if (meta.diagnostics && meta.diagnostics.messages.length > 0) {
|
|
362
|
+
const d = meta.diagnostics;
|
|
363
|
+
diagnosticsNotice = `\n\nLSP Diagnostics (${d.summary}):\n ${d.messages.join("\n ")}`;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const notice = parts.length ? `\n\n[${parts.join(". ")}]` : "";
|
|
367
|
+
return notice + diagnosticsNotice;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// =============================================================================
|
|
371
|
+
// Tool wrapper
|
|
372
|
+
// =============================================================================
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Append output notice to tool result content if meta is present.
|
|
376
|
+
*/
|
|
377
|
+
function appendOutputNotice(
|
|
378
|
+
content: Array<{ type: string; text?: string }>,
|
|
379
|
+
meta: OutputMeta | undefined,
|
|
380
|
+
): Array<{ type: string; text?: string }> {
|
|
381
|
+
const notice = formatOutputNotice(meta);
|
|
382
|
+
if (!notice) return content;
|
|
383
|
+
|
|
384
|
+
const result = [...content];
|
|
385
|
+
for (let i = result.length - 1; i >= 0; i--) {
|
|
386
|
+
if (result[i].type === "text" && result[i].text != null) {
|
|
387
|
+
result[i] = { ...result[i], text: result[i].text + notice };
|
|
388
|
+
return result;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
result.push({ type: "text", text: notice.trim() });
|
|
393
|
+
return result;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Wrap a tool to:
|
|
398
|
+
* 1. Automatically append output notices based on details.meta
|
|
399
|
+
* 2. Handle ToolError rendering
|
|
400
|
+
*/
|
|
401
|
+
export function wrapToolWithMetaNotice<T extends AgentTool<any, any, any>>(tool: T): T {
|
|
402
|
+
const originalExecute = tool.execute.bind(tool);
|
|
403
|
+
|
|
404
|
+
const wrappedExecute: typeof tool.execute = async (
|
|
405
|
+
toolCallId,
|
|
406
|
+
params,
|
|
407
|
+
signal,
|
|
408
|
+
onUpdate,
|
|
409
|
+
context,
|
|
410
|
+
): Promise<AgentToolResult<any, any>> => {
|
|
411
|
+
let result: AgentToolResult<any, any>;
|
|
412
|
+
|
|
413
|
+
try {
|
|
414
|
+
result = await originalExecute(toolCallId, params, signal, onUpdate, context);
|
|
415
|
+
} catch (e) {
|
|
416
|
+
// Re-throw with formatted message so agent-loop sets isError flag
|
|
417
|
+
throw new Error(renderError(e));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Append notices from meta
|
|
421
|
+
const meta = (result.details as { meta?: OutputMeta } | undefined)?.meta;
|
|
422
|
+
if (meta) {
|
|
423
|
+
return {
|
|
424
|
+
...result,
|
|
425
|
+
content: appendOutputNotice(result.content, meta) as (TextContent | ImageContent)[],
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return result;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
return {
|
|
433
|
+
...tool,
|
|
434
|
+
execute: wrappedExecute,
|
|
435
|
+
} as T;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Wrap all tools with meta notice formatting and error handling.
|
|
440
|
+
*/
|
|
441
|
+
export function wrapToolsWithMetaNotice<T extends AgentTool<any, any, any>>(tools: T[]): T[] {
|
|
442
|
+
return tools.map(wrapToolWithMetaNotice);
|
|
443
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ArtifactManager } from "$c/session/artifacts";
|
|
2
|
+
import type { ToolSession } from "./index";
|
|
3
|
+
|
|
4
|
+
export interface TailBuffer {
|
|
5
|
+
append(chunk: string): void;
|
|
6
|
+
text(): string;
|
|
7
|
+
bytes(): number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function createTailBuffer(maxBytes: number): TailBuffer {
|
|
11
|
+
let buffer = "";
|
|
12
|
+
let bufferBytes = 0;
|
|
13
|
+
|
|
14
|
+
const append = (text: string) => {
|
|
15
|
+
if (!text) return;
|
|
16
|
+
const chunkBytes = Buffer.byteLength(text, "utf-8");
|
|
17
|
+
buffer += text;
|
|
18
|
+
bufferBytes += chunkBytes;
|
|
19
|
+
|
|
20
|
+
if (bufferBytes > maxBytes) {
|
|
21
|
+
const buf = Buffer.from(buffer, "utf-8");
|
|
22
|
+
let start = Math.max(0, buf.length - maxBytes);
|
|
23
|
+
while (start < buf.length && (buf[start] & 0xc0) === 0x80) {
|
|
24
|
+
start++;
|
|
25
|
+
}
|
|
26
|
+
buffer = buf.subarray(start).toString("utf-8");
|
|
27
|
+
bufferBytes = Buffer.byteLength(buffer, "utf-8");
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
append,
|
|
33
|
+
text: () => buffer,
|
|
34
|
+
bytes: () => bufferBytes,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getArtifactManager(session: ToolSession): ArtifactManager | null {
|
|
39
|
+
if (session.artifactManager) {
|
|
40
|
+
return session.artifactManager;
|
|
41
|
+
}
|
|
42
|
+
const sessionFile = session.getSessionFile();
|
|
43
|
+
if (!sessionFile) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const manager = new ArtifactManager(sessionFile);
|
|
47
|
+
session.artifactManager = manager;
|
|
48
|
+
return manager;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function allocateOutputArtifact(
|
|
52
|
+
session: ToolSession,
|
|
53
|
+
toolType: string,
|
|
54
|
+
): Promise<{ artifactPath?: string; artifactId?: string }> {
|
|
55
|
+
const manager = getArtifactManager(session);
|
|
56
|
+
if (!manager) return {};
|
|
57
|
+
try {
|
|
58
|
+
const allocation = await manager.allocatePath(toolType);
|
|
59
|
+
return { artifactPath: allocation.path, artifactId: allocation.id };
|
|
60
|
+
} catch {
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
}
|