@oh-my-pi/pi-coding-agent 0.1.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 +1629 -0
- package/README.md +1041 -0
- package/docs/compaction.md +403 -0
- package/docs/config-usage.md +113 -0
- package/docs/custom-tools.md +541 -0
- package/docs/extension-loading.md +1004 -0
- package/docs/hooks.md +867 -0
- package/docs/rpc.md +1040 -0
- package/docs/sdk.md +994 -0
- package/docs/session-tree-plan.md +441 -0
- package/docs/session.md +240 -0
- package/docs/skills.md +290 -0
- package/docs/theme.md +670 -0
- package/docs/tree.md +197 -0
- package/docs/tui.md +341 -0
- package/examples/README.md +21 -0
- package/examples/custom-tools/README.md +124 -0
- package/examples/custom-tools/hello/index.ts +20 -0
- package/examples/custom-tools/question/index.ts +84 -0
- package/examples/custom-tools/subagent/README.md +172 -0
- package/examples/custom-tools/subagent/agents/planner.md +37 -0
- package/examples/custom-tools/subagent/agents/scout.md +50 -0
- package/examples/custom-tools/subagent/agents/worker.md +24 -0
- package/examples/custom-tools/subagent/agents.ts +156 -0
- package/examples/custom-tools/subagent/commands/implement-and-review.md +10 -0
- package/examples/custom-tools/subagent/commands/implement.md +10 -0
- package/examples/custom-tools/subagent/commands/scout-and-plan.md +9 -0
- package/examples/custom-tools/subagent/index.ts +1002 -0
- package/examples/custom-tools/todo/index.ts +212 -0
- package/examples/hooks/README.md +56 -0
- package/examples/hooks/auto-commit-on-exit.ts +49 -0
- package/examples/hooks/confirm-destructive.ts +59 -0
- package/examples/hooks/custom-compaction.ts +116 -0
- package/examples/hooks/dirty-repo-guard.ts +52 -0
- package/examples/hooks/file-trigger.ts +41 -0
- package/examples/hooks/git-checkpoint.ts +53 -0
- package/examples/hooks/handoff.ts +150 -0
- package/examples/hooks/permission-gate.ts +34 -0
- package/examples/hooks/protected-paths.ts +30 -0
- package/examples/hooks/qna.ts +119 -0
- package/examples/hooks/snake.ts +343 -0
- package/examples/hooks/status-line.ts +40 -0
- package/examples/sdk/01-minimal.ts +22 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +44 -0
- package/examples/sdk/04-skills.ts +44 -0
- package/examples/sdk/05-tools.ts +90 -0
- package/examples/sdk/06-hooks.ts +61 -0
- package/examples/sdk/07-context-files.ts +36 -0
- package/examples/sdk/08-slash-commands.ts +42 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +55 -0
- package/examples/sdk/10-settings.ts +38 -0
- package/examples/sdk/11-sessions.ts +48 -0
- package/examples/sdk/12-full-control.ts +95 -0
- package/examples/sdk/README.md +154 -0
- package/package.json +89 -0
- package/src/bun-imports.d.ts +16 -0
- package/src/capability/context-file.ts +40 -0
- package/src/capability/extension.ts +48 -0
- package/src/capability/hook.ts +40 -0
- package/src/capability/index.ts +616 -0
- package/src/capability/instruction.ts +37 -0
- package/src/capability/mcp.ts +52 -0
- package/src/capability/prompt.ts +35 -0
- package/src/capability/rule.ts +56 -0
- package/src/capability/settings.ts +35 -0
- package/src/capability/skill.ts +49 -0
- package/src/capability/slash-command.ts +40 -0
- package/src/capability/system-prompt.ts +35 -0
- package/src/capability/tool.ts +38 -0
- package/src/capability/types.ts +166 -0
- package/src/cli/args.ts +259 -0
- package/src/cli/file-processor.ts +121 -0
- package/src/cli/list-models.ts +104 -0
- package/src/cli/plugin-cli.ts +661 -0
- package/src/cli/session-picker.ts +41 -0
- package/src/cli/update-cli.ts +274 -0
- package/src/cli.ts +10 -0
- package/src/config.ts +391 -0
- package/src/core/agent-session.ts +2178 -0
- package/src/core/auth-storage.ts +258 -0
- package/src/core/bash-executor.ts +197 -0
- package/src/core/compaction/branch-summarization.ts +315 -0
- package/src/core/compaction/compaction.ts +664 -0
- package/src/core/compaction/index.ts +7 -0
- package/src/core/compaction/utils.ts +153 -0
- package/src/core/custom-commands/bundled/review/index.ts +156 -0
- package/src/core/custom-commands/index.ts +15 -0
- package/src/core/custom-commands/loader.ts +226 -0
- package/src/core/custom-commands/types.ts +112 -0
- package/src/core/custom-tools/index.ts +22 -0
- package/src/core/custom-tools/loader.ts +248 -0
- package/src/core/custom-tools/types.ts +185 -0
- package/src/core/custom-tools/wrapper.ts +29 -0
- package/src/core/exec.ts +139 -0
- package/src/core/export-html/index.ts +159 -0
- package/src/core/export-html/template.css +774 -0
- package/src/core/export-html/template.generated.ts +2 -0
- package/src/core/export-html/template.html +45 -0
- package/src/core/export-html/template.js +1185 -0
- package/src/core/export-html/template.macro.ts +24 -0
- package/src/core/file-mentions.ts +54 -0
- package/src/core/hooks/index.ts +16 -0
- package/src/core/hooks/loader.ts +288 -0
- package/src/core/hooks/runner.ts +434 -0
- package/src/core/hooks/tool-wrapper.ts +98 -0
- package/src/core/hooks/types.ts +770 -0
- package/src/core/index.ts +53 -0
- package/src/core/logger.ts +112 -0
- package/src/core/mcp/client.ts +185 -0
- package/src/core/mcp/config.ts +248 -0
- package/src/core/mcp/index.ts +45 -0
- package/src/core/mcp/loader.ts +99 -0
- package/src/core/mcp/manager.ts +235 -0
- package/src/core/mcp/tool-bridge.ts +156 -0
- package/src/core/mcp/transports/http.ts +316 -0
- package/src/core/mcp/transports/index.ts +6 -0
- package/src/core/mcp/transports/stdio.ts +252 -0
- package/src/core/mcp/types.ts +228 -0
- package/src/core/messages.ts +211 -0
- package/src/core/model-registry.ts +334 -0
- package/src/core/model-resolver.ts +494 -0
- package/src/core/plugins/doctor.ts +67 -0
- package/src/core/plugins/index.ts +38 -0
- package/src/core/plugins/installer.ts +189 -0
- package/src/core/plugins/loader.ts +339 -0
- package/src/core/plugins/manager.ts +672 -0
- package/src/core/plugins/parser.ts +105 -0
- package/src/core/plugins/paths.ts +37 -0
- package/src/core/plugins/types.ts +190 -0
- package/src/core/sdk.ts +900 -0
- package/src/core/session-manager.ts +1837 -0
- package/src/core/settings-manager.ts +860 -0
- package/src/core/skills.ts +352 -0
- package/src/core/slash-commands.ts +132 -0
- package/src/core/system-prompt.ts +442 -0
- package/src/core/timings.ts +25 -0
- package/src/core/title-generator.ts +110 -0
- package/src/core/tools/ask.ts +193 -0
- package/src/core/tools/bash-interceptor.ts +120 -0
- package/src/core/tools/bash.ts +91 -0
- package/src/core/tools/context.ts +32 -0
- package/src/core/tools/edit-diff.ts +487 -0
- package/src/core/tools/edit.ts +140 -0
- package/src/core/tools/exa/company.ts +59 -0
- package/src/core/tools/exa/index.ts +63 -0
- package/src/core/tools/exa/linkedin.ts +59 -0
- package/src/core/tools/exa/mcp-client.ts +368 -0
- package/src/core/tools/exa/render.ts +200 -0
- package/src/core/tools/exa/researcher.ts +90 -0
- package/src/core/tools/exa/search.ts +338 -0
- package/src/core/tools/exa/types.ts +167 -0
- package/src/core/tools/exa/websets.ts +248 -0
- package/src/core/tools/find.ts +244 -0
- package/src/core/tools/grep.ts +584 -0
- package/src/core/tools/index.ts +283 -0
- package/src/core/tools/ls.ts +142 -0
- package/src/core/tools/lsp/client.ts +767 -0
- package/src/core/tools/lsp/clients/biome-client.ts +207 -0
- package/src/core/tools/lsp/clients/index.ts +49 -0
- package/src/core/tools/lsp/clients/lsp-linter-client.ts +98 -0
- package/src/core/tools/lsp/config.ts +845 -0
- package/src/core/tools/lsp/edits.ts +110 -0
- package/src/core/tools/lsp/index.ts +1364 -0
- package/src/core/tools/lsp/render.ts +560 -0
- package/src/core/tools/lsp/rust-analyzer.ts +145 -0
- package/src/core/tools/lsp/types.ts +495 -0
- package/src/core/tools/lsp/utils.ts +526 -0
- package/src/core/tools/notebook.ts +182 -0
- package/src/core/tools/output.ts +198 -0
- package/src/core/tools/path-utils.ts +61 -0
- package/src/core/tools/read.ts +507 -0
- package/src/core/tools/renderers.ts +820 -0
- package/src/core/tools/review.ts +275 -0
- package/src/core/tools/rulebook.ts +124 -0
- package/src/core/tools/task/agents.ts +158 -0
- package/src/core/tools/task/artifacts.ts +114 -0
- package/src/core/tools/task/commands.ts +157 -0
- package/src/core/tools/task/discovery.ts +217 -0
- package/src/core/tools/task/executor.ts +531 -0
- package/src/core/tools/task/index.ts +548 -0
- package/src/core/tools/task/model-resolver.ts +176 -0
- package/src/core/tools/task/parallel.ts +38 -0
- package/src/core/tools/task/render.ts +502 -0
- package/src/core/tools/task/subprocess-tool-registry.ts +89 -0
- package/src/core/tools/task/types.ts +142 -0
- package/src/core/tools/truncate.ts +265 -0
- package/src/core/tools/web-fetch.ts +2511 -0
- package/src/core/tools/web-search/auth.ts +199 -0
- package/src/core/tools/web-search/index.ts +583 -0
- package/src/core/tools/web-search/providers/anthropic.ts +198 -0
- package/src/core/tools/web-search/providers/exa.ts +196 -0
- package/src/core/tools/web-search/providers/perplexity.ts +195 -0
- package/src/core/tools/web-search/render.ts +372 -0
- package/src/core/tools/web-search/types.ts +180 -0
- package/src/core/tools/write.ts +63 -0
- package/src/core/ttsr.ts +211 -0
- package/src/core/utils.ts +187 -0
- package/src/discovery/agents-md.ts +75 -0
- package/src/discovery/builtin.ts +647 -0
- package/src/discovery/claude.ts +623 -0
- package/src/discovery/cline.ts +104 -0
- package/src/discovery/codex.ts +571 -0
- package/src/discovery/cursor.ts +266 -0
- package/src/discovery/gemini.ts +368 -0
- package/src/discovery/github.ts +120 -0
- package/src/discovery/helpers.test.ts +127 -0
- package/src/discovery/helpers.ts +249 -0
- package/src/discovery/index.ts +84 -0
- package/src/discovery/mcp-json.ts +127 -0
- package/src/discovery/vscode.ts +99 -0
- package/src/discovery/windsurf.ts +219 -0
- package/src/index.ts +192 -0
- package/src/main.ts +507 -0
- package/src/migrations.ts +156 -0
- package/src/modes/cleanup.ts +23 -0
- package/src/modes/index.ts +48 -0
- package/src/modes/interactive/components/armin.ts +382 -0
- package/src/modes/interactive/components/assistant-message.ts +86 -0
- package/src/modes/interactive/components/bash-execution.ts +199 -0
- package/src/modes/interactive/components/bordered-loader.ts +41 -0
- package/src/modes/interactive/components/branch-summary-message.ts +42 -0
- package/src/modes/interactive/components/compaction-summary-message.ts +45 -0
- package/src/modes/interactive/components/custom-editor.ts +122 -0
- package/src/modes/interactive/components/diff.ts +147 -0
- package/src/modes/interactive/components/dynamic-border.ts +25 -0
- package/src/modes/interactive/components/extensions/extension-dashboard.ts +296 -0
- package/src/modes/interactive/components/extensions/extension-list.ts +479 -0
- package/src/modes/interactive/components/extensions/index.ts +9 -0
- package/src/modes/interactive/components/extensions/inspector-panel.ts +313 -0
- package/src/modes/interactive/components/extensions/state-manager.ts +558 -0
- package/src/modes/interactive/components/extensions/types.ts +191 -0
- package/src/modes/interactive/components/hook-editor.ts +117 -0
- package/src/modes/interactive/components/hook-input.ts +64 -0
- package/src/modes/interactive/components/hook-message.ts +96 -0
- package/src/modes/interactive/components/hook-selector.ts +91 -0
- package/src/modes/interactive/components/model-selector.ts +560 -0
- package/src/modes/interactive/components/oauth-selector.ts +136 -0
- package/src/modes/interactive/components/plugin-settings.ts +481 -0
- package/src/modes/interactive/components/queue-mode-selector.ts +56 -0
- package/src/modes/interactive/components/session-selector.ts +220 -0
- package/src/modes/interactive/components/settings-defs.ts +597 -0
- package/src/modes/interactive/components/settings-selector.ts +545 -0
- package/src/modes/interactive/components/show-images-selector.ts +45 -0
- package/src/modes/interactive/components/status-line/index.ts +4 -0
- package/src/modes/interactive/components/status-line/presets.ts +94 -0
- package/src/modes/interactive/components/status-line/segments.ts +350 -0
- package/src/modes/interactive/components/status-line/separators.ts +55 -0
- package/src/modes/interactive/components/status-line/types.ts +81 -0
- package/src/modes/interactive/components/status-line-segment-editor.ts +357 -0
- package/src/modes/interactive/components/status-line.ts +384 -0
- package/src/modes/interactive/components/theme-selector.ts +62 -0
- package/src/modes/interactive/components/thinking-selector.ts +64 -0
- package/src/modes/interactive/components/tool-execution.ts +946 -0
- package/src/modes/interactive/components/tree-selector.ts +877 -0
- package/src/modes/interactive/components/ttsr-notification.ts +82 -0
- package/src/modes/interactive/components/user-message-selector.ts +159 -0
- package/src/modes/interactive/components/user-message.ts +18 -0
- package/src/modes/interactive/components/visual-truncate.ts +50 -0
- package/src/modes/interactive/components/welcome.ts +228 -0
- package/src/modes/interactive/interactive-mode.ts +2669 -0
- package/src/modes/interactive/theme/dark.json +102 -0
- package/src/modes/interactive/theme/defaults/dark-arctic.json +111 -0
- package/src/modes/interactive/theme/defaults/dark-catppuccin.json +106 -0
- package/src/modes/interactive/theme/defaults/dark-cyberpunk.json +109 -0
- package/src/modes/interactive/theme/defaults/dark-dracula.json +105 -0
- package/src/modes/interactive/theme/defaults/dark-forest.json +103 -0
- package/src/modes/interactive/theme/defaults/dark-github.json +112 -0
- package/src/modes/interactive/theme/defaults/dark-gruvbox.json +119 -0
- package/src/modes/interactive/theme/defaults/dark-monochrome.json +101 -0
- package/src/modes/interactive/theme/defaults/dark-monokai.json +105 -0
- package/src/modes/interactive/theme/defaults/dark-nord.json +104 -0
- package/src/modes/interactive/theme/defaults/dark-ocean.json +108 -0
- package/src/modes/interactive/theme/defaults/dark-one.json +107 -0
- package/src/modes/interactive/theme/defaults/dark-retro.json +99 -0
- package/src/modes/interactive/theme/defaults/dark-rose-pine.json +95 -0
- package/src/modes/interactive/theme/defaults/dark-solarized.json +96 -0
- package/src/modes/interactive/theme/defaults/dark-sunset.json +106 -0
- package/src/modes/interactive/theme/defaults/dark-synthwave.json +102 -0
- package/src/modes/interactive/theme/defaults/dark-tokyo-night.json +108 -0
- package/src/modes/interactive/theme/defaults/index.ts +67 -0
- package/src/modes/interactive/theme/defaults/light-arctic.json +106 -0
- package/src/modes/interactive/theme/defaults/light-catppuccin.json +105 -0
- package/src/modes/interactive/theme/defaults/light-cyberpunk.json +103 -0
- package/src/modes/interactive/theme/defaults/light-forest.json +107 -0
- package/src/modes/interactive/theme/defaults/light-github.json +114 -0
- package/src/modes/interactive/theme/defaults/light-gruvbox.json +115 -0
- package/src/modes/interactive/theme/defaults/light-monochrome.json +100 -0
- package/src/modes/interactive/theme/defaults/light-ocean.json +106 -0
- package/src/modes/interactive/theme/defaults/light-one.json +105 -0
- package/src/modes/interactive/theme/defaults/light-retro.json +105 -0
- package/src/modes/interactive/theme/defaults/light-solarized.json +101 -0
- package/src/modes/interactive/theme/defaults/light-sunset.json +106 -0
- package/src/modes/interactive/theme/defaults/light-synthwave.json +105 -0
- package/src/modes/interactive/theme/defaults/light-tokyo-night.json +118 -0
- package/src/modes/interactive/theme/light.json +99 -0
- package/src/modes/interactive/theme/theme-schema.json +424 -0
- package/src/modes/interactive/theme/theme.ts +2211 -0
- package/src/modes/print-mode.ts +163 -0
- package/src/modes/rpc/rpc-client.ts +527 -0
- package/src/modes/rpc/rpc-mode.ts +494 -0
- package/src/modes/rpc/rpc-types.ts +203 -0
- package/src/prompts/architect-plan.md +10 -0
- package/src/prompts/branch-summary-preamble.md +3 -0
- package/src/prompts/branch-summary.md +28 -0
- package/src/prompts/browser.md +71 -0
- package/src/prompts/compaction-summary.md +34 -0
- package/src/prompts/compaction-turn-prefix.md +16 -0
- package/src/prompts/compaction-update-summary.md +41 -0
- package/src/prompts/explore.md +82 -0
- package/src/prompts/implement-with-critic.md +11 -0
- package/src/prompts/implement.md +11 -0
- package/src/prompts/init.md +30 -0
- package/src/prompts/plan.md +54 -0
- package/src/prompts/reviewer.md +81 -0
- package/src/prompts/summarization-system.md +3 -0
- package/src/prompts/system-prompt.md +27 -0
- package/src/prompts/task.md +56 -0
- package/src/prompts/title-system.md +8 -0
- package/src/prompts/tools/ask.md +24 -0
- package/src/prompts/tools/bash.md +23 -0
- package/src/prompts/tools/edit.md +9 -0
- package/src/prompts/tools/find.md +6 -0
- package/src/prompts/tools/grep.md +12 -0
- package/src/prompts/tools/lsp.md +14 -0
- package/src/prompts/tools/output.md +23 -0
- package/src/prompts/tools/read.md +25 -0
- package/src/prompts/tools/web-fetch.md +8 -0
- package/src/prompts/tools/web-search.md +10 -0
- package/src/prompts/tools/write.md +10 -0
- package/src/utils/changelog.ts +99 -0
- package/src/utils/clipboard.ts +265 -0
- package/src/utils/fuzzy.ts +108 -0
- package/src/utils/mime.ts +30 -0
- package/src/utils/shell-snapshot.ts +218 -0
- package/src/utils/shell.ts +364 -0
- package/src/utils/tools-manager.ts +265 -0
|
@@ -0,0 +1,820 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TUI renderers for built-in tools.
|
|
3
|
+
*
|
|
4
|
+
* These provide rich visualization for tool calls and results in the TUI.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { Component } from "@oh-my-pi/pi-tui";
|
|
8
|
+
import { Text } from "@oh-my-pi/pi-tui";
|
|
9
|
+
import type { Theme } from "../../modes/interactive/theme/theme";
|
|
10
|
+
import type { RenderResultOptions } from "../custom-tools/types";
|
|
11
|
+
import type { AskToolDetails } from "./ask";
|
|
12
|
+
import type { FindToolDetails } from "./find";
|
|
13
|
+
import type { GrepToolDetails } from "./grep";
|
|
14
|
+
import type { LsToolDetails } from "./ls";
|
|
15
|
+
import { renderCall as renderLspCall, renderResult as renderLspResult } from "./lsp/render";
|
|
16
|
+
import type { LspToolDetails } from "./lsp/types";
|
|
17
|
+
import type { NotebookToolDetails } from "./notebook";
|
|
18
|
+
import type { OutputToolDetails } from "./output";
|
|
19
|
+
import { renderCall as renderTaskCall, renderResult as renderTaskResult } from "./task/render";
|
|
20
|
+
import type { TaskToolDetails } from "./task/types";
|
|
21
|
+
import { renderWebFetchCall, renderWebFetchResult, type WebFetchToolDetails } from "./web-fetch";
|
|
22
|
+
import { renderWebSearchCall, renderWebSearchResult, type WebSearchRenderDetails } from "./web-search/render";
|
|
23
|
+
|
|
24
|
+
// Tree drawing characters
|
|
25
|
+
|
|
26
|
+
interface ToolRenderer<TArgs = any, TDetails = any> {
|
|
27
|
+
renderCall(args: TArgs, theme: Theme): Component;
|
|
28
|
+
renderResult(
|
|
29
|
+
result: { content: Array<{ type: string; text?: string }>; details?: TDetails },
|
|
30
|
+
options: RenderResultOptions,
|
|
31
|
+
theme: Theme,
|
|
32
|
+
): Component;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// Grep Renderer
|
|
37
|
+
// ============================================================================
|
|
38
|
+
|
|
39
|
+
interface GrepArgs {
|
|
40
|
+
pattern: string;
|
|
41
|
+
path?: string;
|
|
42
|
+
glob?: string;
|
|
43
|
+
type?: string;
|
|
44
|
+
ignoreCase?: boolean;
|
|
45
|
+
caseSensitive?: boolean;
|
|
46
|
+
literal?: boolean;
|
|
47
|
+
multiline?: boolean;
|
|
48
|
+
context?: number;
|
|
49
|
+
limit?: number;
|
|
50
|
+
outputMode?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const grepRenderer: ToolRenderer<GrepArgs, GrepToolDetails> = {
|
|
54
|
+
renderCall(args, theme) {
|
|
55
|
+
let text = theme.fg("toolTitle", theme.bold("grep "));
|
|
56
|
+
text += theme.fg("accent", args.pattern || "?");
|
|
57
|
+
|
|
58
|
+
const meta: string[] = [];
|
|
59
|
+
if (args.path) meta.push(args.path);
|
|
60
|
+
if (args.glob) meta.push(`glob:${args.glob}`);
|
|
61
|
+
if (args.type) meta.push(`type:${args.type}`);
|
|
62
|
+
if (args.outputMode && args.outputMode !== "files_with_matches") meta.push(args.outputMode);
|
|
63
|
+
if (args.caseSensitive) {
|
|
64
|
+
meta.push("--case-sensitive");
|
|
65
|
+
} else if (args.ignoreCase) {
|
|
66
|
+
meta.push("-i");
|
|
67
|
+
}
|
|
68
|
+
if (args.multiline) meta.push("multiline");
|
|
69
|
+
|
|
70
|
+
if (meta.length > 0) {
|
|
71
|
+
text += ` ${theme.fg("muted", meta.join(" "))}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return new Text(text, 0, 0);
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
renderResult(result, { expanded }, theme) {
|
|
78
|
+
const details = result.details;
|
|
79
|
+
|
|
80
|
+
// Error case
|
|
81
|
+
if (details?.error) {
|
|
82
|
+
return new Text(`${theme.styledSymbol("status.error", "error")} ${theme.fg("error", details.error)}`, 0, 0);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Check for detailed rendering data - fall back to structured output if not available
|
|
86
|
+
const hasDetailedData = details?.matchCount !== undefined || details?.fileCount !== undefined;
|
|
87
|
+
|
|
88
|
+
if (!hasDetailedData) {
|
|
89
|
+
const textContent = result.content?.find((c) => c.type === "text")?.text;
|
|
90
|
+
if (!textContent || textContent === "No matches found") {
|
|
91
|
+
return new Text(
|
|
92
|
+
`${theme.styledSymbol("status.warning", "warning")} ${theme.fg("muted", "No matches found")}`,
|
|
93
|
+
0,
|
|
94
|
+
0,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const lines = textContent.split("\n").filter((line) => line.trim() !== "");
|
|
99
|
+
const maxLines = expanded ? lines.length : 10;
|
|
100
|
+
const displayLines = lines.slice(0, maxLines);
|
|
101
|
+
const remaining = lines.length - maxLines;
|
|
102
|
+
|
|
103
|
+
let text = `${theme.styledSymbol("status.success", "success")} ${theme.fg("toolTitle", "grep")} ${theme.fg(
|
|
104
|
+
"dim",
|
|
105
|
+
`${lines.length} item${lines.length !== 1 ? "s" : ""}`,
|
|
106
|
+
)}`;
|
|
107
|
+
|
|
108
|
+
for (let i = 0; i < displayLines.length; i++) {
|
|
109
|
+
const isLast = i === displayLines.length - 1 && remaining === 0;
|
|
110
|
+
const branch = isLast ? theme.tree.last : theme.tree.branch;
|
|
111
|
+
text += `\n ${theme.fg("dim", branch)} ${theme.fg("toolOutput", displayLines[i])}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (remaining > 0) {
|
|
115
|
+
text += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg(
|
|
116
|
+
"muted",
|
|
117
|
+
`${theme.format.ellipsis} ${remaining} more items`,
|
|
118
|
+
)}`;
|
|
119
|
+
}
|
|
120
|
+
return new Text(text, 0, 0);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const matchCount = details?.matchCount ?? 0;
|
|
124
|
+
const fileCount = details?.fileCount ?? 0;
|
|
125
|
+
const mode = details?.mode ?? "files_with_matches";
|
|
126
|
+
const truncated = details?.truncated ?? details?.truncation?.truncated ?? false;
|
|
127
|
+
const files = details?.files ?? [];
|
|
128
|
+
|
|
129
|
+
// No matches
|
|
130
|
+
if (matchCount === 0) {
|
|
131
|
+
return new Text(
|
|
132
|
+
`${theme.styledSymbol("status.warning", "warning")} ${theme.fg("muted", "No matches found")}`,
|
|
133
|
+
0,
|
|
134
|
+
0,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Build summary
|
|
139
|
+
const icon = theme.styledSymbol("status.success", "success");
|
|
140
|
+
let summary: string;
|
|
141
|
+
if (mode === "files_with_matches") {
|
|
142
|
+
summary = `${fileCount} file${fileCount !== 1 ? "s" : ""}`;
|
|
143
|
+
} else if (mode === "count") {
|
|
144
|
+
summary = `${matchCount} match${matchCount !== 1 ? "es" : ""} in ${fileCount} file${fileCount !== 1 ? "s" : ""}`;
|
|
145
|
+
} else {
|
|
146
|
+
summary = `${matchCount} match${matchCount !== 1 ? "es" : ""} in ${fileCount} file${fileCount !== 1 ? "s" : ""}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (truncated) {
|
|
150
|
+
summary += theme.fg("warning", " (truncated)");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const expandHint = expanded ? "" : theme.fg("dim", " (Ctrl+O to expand)");
|
|
154
|
+
const scopeLabel = details?.scopePath ? ` ${theme.fg("muted", `in ${details.scopePath}`)}` : "";
|
|
155
|
+
let text = `${icon} ${theme.fg("toolTitle", "grep")} ${theme.fg("dim", summary)}${scopeLabel}${expandHint}`;
|
|
156
|
+
|
|
157
|
+
const truncationReasons: string[] = [];
|
|
158
|
+
if (details?.matchLimitReached) {
|
|
159
|
+
truncationReasons.push(`limit ${details.matchLimitReached} matches`);
|
|
160
|
+
}
|
|
161
|
+
if (details?.headLimitReached) {
|
|
162
|
+
truncationReasons.push(`head limit ${details.headLimitReached}`);
|
|
163
|
+
}
|
|
164
|
+
if (details?.truncation?.truncated) {
|
|
165
|
+
truncationReasons.push("size limit");
|
|
166
|
+
}
|
|
167
|
+
if (details?.linesTruncated) {
|
|
168
|
+
truncationReasons.push("line length");
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const fileEntries: Array<{ path: string; count?: number }> = details?.fileMatches?.length
|
|
172
|
+
? details.fileMatches.map((entry) => ({ path: entry.path, count: entry.count }))
|
|
173
|
+
: files.map((path) => ({ path }));
|
|
174
|
+
|
|
175
|
+
// Show file tree if we have files
|
|
176
|
+
if (fileEntries.length > 0) {
|
|
177
|
+
const maxFiles = expanded ? fileEntries.length : Math.min(fileEntries.length, 8);
|
|
178
|
+
for (let i = 0; i < maxFiles; i++) {
|
|
179
|
+
const entry = fileEntries[i];
|
|
180
|
+
const isLast = i === maxFiles - 1 && (expanded || fileEntries.length <= 8);
|
|
181
|
+
const branch = isLast ? theme.tree.last : theme.tree.branch;
|
|
182
|
+
const countLabel =
|
|
183
|
+
entry.count !== undefined
|
|
184
|
+
? ` ${theme.fg("dim", `(${entry.count} match${entry.count !== 1 ? "es" : ""})`)}`
|
|
185
|
+
: "";
|
|
186
|
+
text += `\n ${theme.fg("dim", branch)} ${theme.fg("accent", entry.path)}${countLabel}`;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (!expanded && fileEntries.length > 8) {
|
|
190
|
+
text += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg(
|
|
191
|
+
"muted",
|
|
192
|
+
`${theme.format.ellipsis} ${fileEntries.length - 8} more files`,
|
|
193
|
+
)}`;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (truncationReasons.length > 0) {
|
|
198
|
+
text += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg(
|
|
199
|
+
"warning",
|
|
200
|
+
`truncated: ${truncationReasons.join(", ")}`,
|
|
201
|
+
)}`;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return new Text(text, 0, 0);
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// ============================================================================
|
|
209
|
+
// Find Renderer
|
|
210
|
+
// ============================================================================
|
|
211
|
+
|
|
212
|
+
interface FindArgs {
|
|
213
|
+
pattern: string;
|
|
214
|
+
path?: string;
|
|
215
|
+
type?: string;
|
|
216
|
+
hidden?: boolean;
|
|
217
|
+
sortByMtime?: boolean;
|
|
218
|
+
limit?: number;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const findRenderer: ToolRenderer<FindArgs, FindToolDetails> = {
|
|
222
|
+
renderCall(args, theme) {
|
|
223
|
+
let text = theme.fg("toolTitle", theme.bold("find "));
|
|
224
|
+
text += theme.fg("accent", args.pattern || "*");
|
|
225
|
+
|
|
226
|
+
const meta: string[] = [];
|
|
227
|
+
if (args.path) meta.push(args.path);
|
|
228
|
+
if (args.type && args.type !== "all") meta.push(`type:${args.type}`);
|
|
229
|
+
if (args.hidden) meta.push("--hidden");
|
|
230
|
+
|
|
231
|
+
if (meta.length > 0) {
|
|
232
|
+
text += ` ${theme.fg("muted", meta.join(" "))}`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return new Text(text, 0, 0);
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
renderResult(result, { expanded }, theme) {
|
|
239
|
+
const details = result.details;
|
|
240
|
+
|
|
241
|
+
// Error case
|
|
242
|
+
if (details?.error) {
|
|
243
|
+
return new Text(`${theme.styledSymbol("status.error", "error")} ${theme.fg("error", details.error)}`, 0, 0);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Check for detailed rendering data - fall back to parsing raw output if not available
|
|
247
|
+
const hasDetailedData = details?.fileCount !== undefined;
|
|
248
|
+
|
|
249
|
+
// Get text content for fallback or to extract file list
|
|
250
|
+
const textContent = result.content?.find((c) => c.type === "text")?.text;
|
|
251
|
+
|
|
252
|
+
if (!hasDetailedData) {
|
|
253
|
+
if (!textContent || textContent.includes("No files matching") || textContent.trim() === "") {
|
|
254
|
+
return new Text(
|
|
255
|
+
`${theme.styledSymbol("status.warning", "warning")} ${theme.fg("muted", "No files found")}`,
|
|
256
|
+
0,
|
|
257
|
+
0,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Parse the raw output as file list
|
|
262
|
+
const lines = textContent.split("\n").filter((l) => l.trim());
|
|
263
|
+
const maxLines = expanded ? lines.length : Math.min(lines.length, 8);
|
|
264
|
+
const displayLines = lines.slice(0, maxLines);
|
|
265
|
+
const remaining = lines.length - maxLines;
|
|
266
|
+
|
|
267
|
+
let text = `${theme.styledSymbol("status.success", "success")} ${theme.fg("toolTitle", "find")} ${theme.fg(
|
|
268
|
+
"dim",
|
|
269
|
+
`${lines.length} file${lines.length !== 1 ? "s" : ""}`,
|
|
270
|
+
)}`;
|
|
271
|
+
for (let i = 0; i < displayLines.length; i++) {
|
|
272
|
+
const isLast = i === displayLines.length - 1 && remaining === 0;
|
|
273
|
+
const branch = isLast ? theme.tree.last : theme.tree.branch;
|
|
274
|
+
text += `\n ${theme.fg("dim", branch)} ${theme.fg("accent", displayLines[i])}`;
|
|
275
|
+
}
|
|
276
|
+
if (remaining > 0) {
|
|
277
|
+
text += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg(
|
|
278
|
+
"muted",
|
|
279
|
+
`${theme.format.ellipsis} ${remaining} more files`,
|
|
280
|
+
)}`;
|
|
281
|
+
}
|
|
282
|
+
return new Text(text, 0, 0);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const fileCount = details?.fileCount ?? 0;
|
|
286
|
+
const truncated = details?.truncated ?? details?.truncation?.truncated ?? false;
|
|
287
|
+
const files = details?.files ?? [];
|
|
288
|
+
|
|
289
|
+
// No matches
|
|
290
|
+
if (fileCount === 0) {
|
|
291
|
+
return new Text(
|
|
292
|
+
`${theme.styledSymbol("status.warning", "warning")} ${theme.fg("muted", "No files found")}`,
|
|
293
|
+
0,
|
|
294
|
+
0,
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Build summary
|
|
299
|
+
const icon = theme.styledSymbol("status.success", "success");
|
|
300
|
+
let summary = `${fileCount} file${fileCount !== 1 ? "s" : ""}`;
|
|
301
|
+
|
|
302
|
+
if (truncated) {
|
|
303
|
+
summary += theme.fg("warning", " (truncated)");
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const expandHint = expanded ? "" : theme.fg("dim", " (Ctrl+O to expand)");
|
|
307
|
+
const scopeLabel = details?.scopePath ? ` ${theme.fg("muted", `in ${details.scopePath}`)}` : "";
|
|
308
|
+
let text = `${icon} ${theme.fg("toolTitle", "find")} ${theme.fg("dim", summary)}${scopeLabel}${expandHint}`;
|
|
309
|
+
|
|
310
|
+
const truncationReasons: string[] = [];
|
|
311
|
+
if (details?.resultLimitReached) {
|
|
312
|
+
truncationReasons.push(`limit ${details.resultLimitReached} results`);
|
|
313
|
+
}
|
|
314
|
+
if (details?.truncation?.truncated) {
|
|
315
|
+
truncationReasons.push("size limit");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Show file tree if we have files
|
|
319
|
+
if (files.length > 0) {
|
|
320
|
+
const maxFiles = expanded ? files.length : Math.min(files.length, 8);
|
|
321
|
+
for (let i = 0; i < maxFiles; i++) {
|
|
322
|
+
const isLast = i === maxFiles - 1 && (expanded || files.length <= 8);
|
|
323
|
+
const branch = isLast ? theme.tree.last : theme.tree.branch;
|
|
324
|
+
text += `\n ${theme.fg("dim", branch)} ${theme.fg("accent", files[i])}`;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (!expanded && files.length > 8) {
|
|
328
|
+
text += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg(
|
|
329
|
+
"muted",
|
|
330
|
+
`${theme.format.ellipsis} ${files.length - 8} more files`,
|
|
331
|
+
)}`;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (truncationReasons.length > 0) {
|
|
336
|
+
text += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg(
|
|
337
|
+
"warning",
|
|
338
|
+
`truncated: ${truncationReasons.join(", ")}`,
|
|
339
|
+
)}`;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return new Text(text, 0, 0);
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// ============================================================================
|
|
347
|
+
// Notebook Renderer
|
|
348
|
+
// ============================================================================
|
|
349
|
+
|
|
350
|
+
interface NotebookArgs {
|
|
351
|
+
action: string;
|
|
352
|
+
notebookPath: string;
|
|
353
|
+
cellNumber?: number;
|
|
354
|
+
cellType?: string;
|
|
355
|
+
content?: string;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function normalizeCellLines(lines: string[]): string[] {
|
|
359
|
+
return lines.map((line) => (line.endsWith("\n") ? line.slice(0, -1) : line));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function renderCellPreview(lines: string[], expanded: boolean, theme: Theme): string {
|
|
363
|
+
const normalized = normalizeCellLines(lines);
|
|
364
|
+
if (normalized.length === 0) {
|
|
365
|
+
return `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg("muted", "(empty cell)")}`;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const maxLines = expanded ? normalized.length : Math.min(normalized.length, 6);
|
|
369
|
+
let text = "";
|
|
370
|
+
|
|
371
|
+
for (let i = 0; i < maxLines; i++) {
|
|
372
|
+
const isLast = i === maxLines - 1 && (expanded || normalized.length <= maxLines);
|
|
373
|
+
const branch = isLast ? theme.tree.last : theme.tree.branch;
|
|
374
|
+
const line = normalized[i];
|
|
375
|
+
text += `\n ${theme.fg("dim", branch)} ${theme.fg("toolOutput", line)}`;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const remaining = normalized.length - maxLines;
|
|
379
|
+
if (remaining > 0) {
|
|
380
|
+
text += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg(
|
|
381
|
+
"muted",
|
|
382
|
+
`${theme.format.ellipsis} ${remaining} more lines`,
|
|
383
|
+
)}`;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return text;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const notebookRenderer: ToolRenderer<NotebookArgs, NotebookToolDetails> = {
|
|
390
|
+
renderCall(args, theme) {
|
|
391
|
+
let text = theme.fg("toolTitle", theme.bold("notebook "));
|
|
392
|
+
text += theme.fg("accent", args.action || "?");
|
|
393
|
+
|
|
394
|
+
const meta: string[] = [];
|
|
395
|
+
meta.push(args.notebookPath || "?");
|
|
396
|
+
if (args.cellNumber !== undefined) meta.push(`cell:${args.cellNumber}`);
|
|
397
|
+
if (args.cellType) meta.push(args.cellType);
|
|
398
|
+
|
|
399
|
+
if (meta.length > 0) {
|
|
400
|
+
text += ` ${theme.fg("muted", meta.join(" "))}`;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return new Text(text, 0, 0);
|
|
404
|
+
},
|
|
405
|
+
|
|
406
|
+
renderResult(result, { expanded }, theme) {
|
|
407
|
+
const details = result.details;
|
|
408
|
+
|
|
409
|
+
// Error case - check for error in content
|
|
410
|
+
const content = result.content?.[0];
|
|
411
|
+
if (content?.type === "text" && content.text?.startsWith("Error:")) {
|
|
412
|
+
return new Text(`${theme.styledSymbol("status.error", "error")} ${theme.fg("error", content.text)}`, 0, 0);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const action = details?.action ?? "edit";
|
|
416
|
+
const cellIndex = details?.cellIndex;
|
|
417
|
+
const cellType = details?.cellType;
|
|
418
|
+
const totalCells = details?.totalCells;
|
|
419
|
+
const cellSource = details?.cellSource;
|
|
420
|
+
const lineCount = cellSource?.length;
|
|
421
|
+
const canExpand = cellSource !== undefined && cellSource.length > 6;
|
|
422
|
+
|
|
423
|
+
// Build summary
|
|
424
|
+
const icon = theme.styledSymbol("status.success", "success");
|
|
425
|
+
let summary: string;
|
|
426
|
+
|
|
427
|
+
switch (action) {
|
|
428
|
+
case "insert":
|
|
429
|
+
summary = `Inserted ${cellType || "cell"} at index ${cellIndex}`;
|
|
430
|
+
break;
|
|
431
|
+
case "delete":
|
|
432
|
+
summary = `Deleted cell at index ${cellIndex}`;
|
|
433
|
+
break;
|
|
434
|
+
default:
|
|
435
|
+
summary = `Edited ${cellType || "cell"} at index ${cellIndex}`;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (lineCount !== undefined) {
|
|
439
|
+
summary += ` (${lineCount} line${lineCount !== 1 ? "s" : ""})`;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (totalCells !== undefined) {
|
|
443
|
+
summary += ` (${totalCells} total)`;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const expandHint = !expanded && canExpand ? theme.fg("dim", " (Ctrl+O to expand)") : "";
|
|
447
|
+
let text = `${icon} ${theme.fg("toolTitle", "notebook")} ${theme.fg("dim", summary)}${expandHint}`;
|
|
448
|
+
|
|
449
|
+
if (cellSource) {
|
|
450
|
+
text += renderCellPreview(cellSource, expanded, theme);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return new Text(text, 0, 0);
|
|
454
|
+
},
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
// ============================================================================
|
|
458
|
+
// Ask Renderer
|
|
459
|
+
// ============================================================================
|
|
460
|
+
|
|
461
|
+
interface AskArgs {
|
|
462
|
+
question: string;
|
|
463
|
+
options?: Array<{ label: string }>;
|
|
464
|
+
multi?: boolean;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const askRenderer: ToolRenderer<AskArgs, AskToolDetails> = {
|
|
468
|
+
renderCall(args, theme) {
|
|
469
|
+
if (!args.question) {
|
|
470
|
+
return new Text(theme.fg("error", "ask: no question provided"), 0, 0);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const multiTag = args.multi ? theme.fg("muted", " [multi-select]") : "";
|
|
474
|
+
let text = theme.fg("toolTitle", "? ") + theme.fg("accent", args.question) + multiTag;
|
|
475
|
+
|
|
476
|
+
if (args.options?.length) {
|
|
477
|
+
for (const opt of args.options) {
|
|
478
|
+
text += `\n${theme.fg("dim", ` ${theme.checkbox.unchecked} `)}${theme.fg("muted", opt.label)}`;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return new Text(text, 0, 0);
|
|
483
|
+
},
|
|
484
|
+
|
|
485
|
+
renderResult(result, _opts, theme) {
|
|
486
|
+
const { details } = result;
|
|
487
|
+
if (!details) {
|
|
488
|
+
const txt = result.content[0];
|
|
489
|
+
return new Text(txt?.type === "text" && txt.text ? txt.text : "", 0, 0);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const hasSelection = details.customInput || details.selectedOptions.length > 0;
|
|
493
|
+
const statusIcon = hasSelection
|
|
494
|
+
? theme.styledSymbol("status.success", "success")
|
|
495
|
+
: theme.styledSymbol("status.warning", "warning");
|
|
496
|
+
|
|
497
|
+
let text = `${statusIcon} ${theme.fg("toolTitle", "ask")} ${theme.fg("accent", details.question)}`;
|
|
498
|
+
|
|
499
|
+
if (details.customInput) {
|
|
500
|
+
text += `\n ${theme.fg("dim", theme.tree.last)} ${theme.styledSymbol(
|
|
501
|
+
"status.success",
|
|
502
|
+
"success",
|
|
503
|
+
)} ${theme.fg("toolOutput", details.customInput)}`;
|
|
504
|
+
} else if (details.selectedOptions.length > 0) {
|
|
505
|
+
const selected = details.selectedOptions;
|
|
506
|
+
for (let i = 0; i < selected.length; i++) {
|
|
507
|
+
const isLast = i === selected.length - 1;
|
|
508
|
+
const branch = isLast ? theme.tree.last : theme.tree.branch;
|
|
509
|
+
text += `\n ${theme.fg("dim", branch)} ${theme.fg(
|
|
510
|
+
"success",
|
|
511
|
+
theme.checkbox.checked,
|
|
512
|
+
)} ${theme.fg("toolOutput", selected[i])}`;
|
|
513
|
+
}
|
|
514
|
+
} else {
|
|
515
|
+
text += `\n ${theme.fg("dim", theme.tree.last)} ${theme.styledSymbol(
|
|
516
|
+
"status.warning",
|
|
517
|
+
"warning",
|
|
518
|
+
)} ${theme.fg("warning", "Cancelled")}`;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
return new Text(text, 0, 0);
|
|
522
|
+
},
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
// ============================================================================
|
|
526
|
+
// Export
|
|
527
|
+
// ============================================================================
|
|
528
|
+
|
|
529
|
+
// ============================================================================
|
|
530
|
+
// LSP Renderer
|
|
531
|
+
// ============================================================================
|
|
532
|
+
|
|
533
|
+
interface LspArgs {
|
|
534
|
+
action: string;
|
|
535
|
+
file?: string;
|
|
536
|
+
files?: string[];
|
|
537
|
+
line?: number;
|
|
538
|
+
column?: number;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
const lspRenderer: ToolRenderer<LspArgs, LspToolDetails> = {
|
|
542
|
+
renderCall: renderLspCall,
|
|
543
|
+
renderResult: renderLspResult,
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
// ============================================================================
|
|
547
|
+
// Output Renderer
|
|
548
|
+
// ============================================================================
|
|
549
|
+
|
|
550
|
+
interface OutputArgs {
|
|
551
|
+
ids: string[];
|
|
552
|
+
format?: "raw" | "json" | "stripped";
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/** Format byte count for display */
|
|
556
|
+
function formatBytes(bytes: number): string {
|
|
557
|
+
if (bytes < 1024) return `${bytes}B`;
|
|
558
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}K`;
|
|
559
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}M`;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function truncateLine(text: string, maxLen: number, ellipsis: string): string {
|
|
563
|
+
if (text.length <= maxLen) return text;
|
|
564
|
+
const sliceLen = Math.max(0, maxLen - ellipsis.length);
|
|
565
|
+
return `${text.slice(0, sliceLen)}${ellipsis}`;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
type OutputEntry = OutputToolDetails["outputs"][number];
|
|
569
|
+
|
|
570
|
+
function formatOutputMeta(entry: OutputEntry, theme: Theme): string {
|
|
571
|
+
const metaParts = [`${entry.lineCount} lines, ${formatBytes(entry.charCount)}`];
|
|
572
|
+
if (entry.provenance) {
|
|
573
|
+
metaParts.push(`agent ${entry.provenance.agent}(${entry.provenance.index})`);
|
|
574
|
+
}
|
|
575
|
+
return theme.fg("dim", metaParts.join(theme.sep.dot));
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
const outputRenderer: ToolRenderer<OutputArgs, OutputToolDetails> = {
|
|
579
|
+
renderCall(args, theme) {
|
|
580
|
+
const ids = args.ids?.join(", ") ?? "?";
|
|
581
|
+
const label = theme.fg("toolTitle", theme.bold("output"));
|
|
582
|
+
const format = args.format && args.format !== "raw" ? theme.fg("muted", ` (${args.format})`) : "";
|
|
583
|
+
return new Text(`${label} ${theme.fg("dim", ids)}${format}`, 0, 0);
|
|
584
|
+
},
|
|
585
|
+
|
|
586
|
+
renderResult(result, { expanded }, theme) {
|
|
587
|
+
const details = result.details;
|
|
588
|
+
|
|
589
|
+
// Error case: some IDs not found
|
|
590
|
+
if (details?.notFound?.length) {
|
|
591
|
+
let text = `${theme.styledSymbol("status.error", "error")} Not found: ${details.notFound.join(", ")}`;
|
|
592
|
+
if (details.availableIds?.length) {
|
|
593
|
+
text += `\n${theme.fg("dim", "Available:")} ${details.availableIds.join(", ")}`;
|
|
594
|
+
} else {
|
|
595
|
+
text += `\n${theme.fg("dim", "No outputs available in current session")}`;
|
|
596
|
+
}
|
|
597
|
+
return new Text(text, 0, 0);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const outputs = details?.outputs ?? [];
|
|
601
|
+
|
|
602
|
+
// No session case
|
|
603
|
+
if (outputs.length === 0) {
|
|
604
|
+
const textContent = result.content?.find((c) => c.type === "text")?.text;
|
|
605
|
+
return new Text(
|
|
606
|
+
`${theme.styledSymbol("status.warning", "warning")} ${theme.fg("muted", textContent || "No outputs")}`,
|
|
607
|
+
0,
|
|
608
|
+
0,
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// Success: summary + tree display
|
|
613
|
+
const expandHint = expanded ? "" : theme.fg("dim", " (Ctrl+O to expand)");
|
|
614
|
+
const icon = theme.styledSymbol("status.success", "success");
|
|
615
|
+
const summary = `read ${outputs.length} output${outputs.length !== 1 ? "s" : ""}`;
|
|
616
|
+
let text = `${icon} ${theme.fg("toolTitle", "output")} ${theme.fg("dim", summary)}${expandHint}`;
|
|
617
|
+
|
|
618
|
+
const previewLimit = expanded ? 3 : 1;
|
|
619
|
+
const maxOutputs = expanded ? outputs.length : Math.min(outputs.length, 5);
|
|
620
|
+
for (let i = 0; i < maxOutputs; i++) {
|
|
621
|
+
const o = outputs[i];
|
|
622
|
+
const isLast = i === maxOutputs - 1 && (expanded || outputs.length <= 5);
|
|
623
|
+
const branch = isLast ? theme.tree.last : theme.tree.branch;
|
|
624
|
+
text += `\n ${theme.fg("dim", branch)} ${theme.fg("accent", o.id)} ${formatOutputMeta(o, theme)}`;
|
|
625
|
+
|
|
626
|
+
const previewLines = o.previewLines ?? [];
|
|
627
|
+
const shownPreview = previewLines.slice(0, previewLimit);
|
|
628
|
+
if (shownPreview.length > 0) {
|
|
629
|
+
const childPrefix = isLast ? " " : ` ${theme.fg("dim", theme.tree.vertical)} `;
|
|
630
|
+
for (const line of shownPreview) {
|
|
631
|
+
const previewText = truncateLine(line, 80, theme.format.ellipsis);
|
|
632
|
+
text += `\n${childPrefix}${theme.fg("dim", theme.tree.hook)} ${theme.fg("muted", "preview:")} ${theme.fg(
|
|
633
|
+
"toolOutput",
|
|
634
|
+
previewText,
|
|
635
|
+
)}`;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
if (!expanded && outputs.length > 5) {
|
|
641
|
+
text += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg(
|
|
642
|
+
"muted",
|
|
643
|
+
`${theme.format.ellipsis} ${outputs.length - 5} more outputs`,
|
|
644
|
+
)}`;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
return new Text(text, 0, 0);
|
|
648
|
+
},
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
// ============================================================================
|
|
652
|
+
// Task Renderer
|
|
653
|
+
// ============================================================================
|
|
654
|
+
|
|
655
|
+
const taskRenderer: ToolRenderer<any, TaskToolDetails> = {
|
|
656
|
+
renderCall: renderTaskCall,
|
|
657
|
+
renderResult: renderTaskResult,
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
// ============================================================================
|
|
661
|
+
// Ls Renderer
|
|
662
|
+
// ============================================================================
|
|
663
|
+
|
|
664
|
+
interface LsArgs {
|
|
665
|
+
path?: string;
|
|
666
|
+
limit?: number;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
const lsRenderer: ToolRenderer<LsArgs, LsToolDetails> = {
|
|
670
|
+
renderCall(args, theme) {
|
|
671
|
+
let text = theme.fg("toolTitle", theme.bold("ls "));
|
|
672
|
+
text += theme.fg("accent", args.path || ".");
|
|
673
|
+
if (args.limit !== undefined) {
|
|
674
|
+
text += ` ${theme.fg("muted", `(limit ${args.limit})`)}`;
|
|
675
|
+
}
|
|
676
|
+
return new Text(text, 0, 0);
|
|
677
|
+
},
|
|
678
|
+
|
|
679
|
+
renderResult(result, { expanded }, theme) {
|
|
680
|
+
const details = result.details;
|
|
681
|
+
const textContent = result.content?.find((c: any) => c.type === "text")?.text ?? "";
|
|
682
|
+
|
|
683
|
+
if (
|
|
684
|
+
(!textContent || textContent.trim() === "" || textContent.trim() === "(empty directory)") &&
|
|
685
|
+
(!details?.entries || details.entries.length === 0)
|
|
686
|
+
) {
|
|
687
|
+
return new Text(
|
|
688
|
+
`${theme.styledSymbol("status.warning", "warning")} ${theme.fg("muted", "Empty directory")}`,
|
|
689
|
+
0,
|
|
690
|
+
0,
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
let entries: string[] = details?.entries ? [...details.entries] : [];
|
|
695
|
+
if (entries.length === 0) {
|
|
696
|
+
const rawLines = textContent.split("\n").filter((l: string) => l.trim());
|
|
697
|
+
entries = rawLines.filter((line) => !/^\[.*\]$/.test(line.trim()));
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
if (entries.length === 0) {
|
|
701
|
+
return new Text(
|
|
702
|
+
`${theme.styledSymbol("status.warning", "warning")} ${theme.fg("muted", "Empty directory")}`,
|
|
703
|
+
0,
|
|
704
|
+
0,
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
let dirCount = details?.dirCount;
|
|
709
|
+
let fileCount = details?.fileCount;
|
|
710
|
+
if (dirCount === undefined || fileCount === undefined) {
|
|
711
|
+
dirCount = 0;
|
|
712
|
+
fileCount = 0;
|
|
713
|
+
for (const entry of entries) {
|
|
714
|
+
if (entry.endsWith("/")) {
|
|
715
|
+
dirCount += 1;
|
|
716
|
+
} else {
|
|
717
|
+
fileCount += 1;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
const truncated = Boolean(details?.truncation?.truncated || details?.entryLimitReached);
|
|
723
|
+
const icon = truncated
|
|
724
|
+
? theme.styledSymbol("status.warning", "warning")
|
|
725
|
+
: theme.styledSymbol("status.success", "success");
|
|
726
|
+
|
|
727
|
+
const dirLabel = `${dirCount} dir${dirCount !== 1 ? "s" : ""}`;
|
|
728
|
+
const fileLabel = `${fileCount} file${fileCount !== 1 ? "s" : ""}`;
|
|
729
|
+
let text = `${icon} ${theme.fg("toolTitle", "ls")} ${theme.fg("dim", `${dirLabel}, ${fileLabel}`)}`;
|
|
730
|
+
|
|
731
|
+
if (truncated) {
|
|
732
|
+
const reasonParts: string[] = [];
|
|
733
|
+
if (details?.entryLimitReached) {
|
|
734
|
+
reasonParts.push(`entry limit ${details.entryLimitReached}`);
|
|
735
|
+
}
|
|
736
|
+
if (details?.truncation?.truncated) {
|
|
737
|
+
reasonParts.push(`output cap ${formatBytes(details.truncation.maxBytes)}`);
|
|
738
|
+
}
|
|
739
|
+
const reasonText = reasonParts.length > 0 ? `truncated: ${reasonParts.join(", ")}` : "truncated";
|
|
740
|
+
text += ` ${theme.fg("warning", `(${reasonText})`)}`;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
if (!expanded) {
|
|
744
|
+
text += `\n${theme.fg("dim", `${theme.nav.expand} Ctrl+O to expand list`)}`;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
const maxEntries = expanded ? entries.length : Math.min(entries.length, 12);
|
|
748
|
+
for (let i = 0; i < maxEntries; i++) {
|
|
749
|
+
const entry = entries[i];
|
|
750
|
+
const isLast = i === maxEntries - 1 && (expanded || entries.length <= 12);
|
|
751
|
+
const branch = isLast ? theme.tree.last : theme.tree.branch;
|
|
752
|
+
const isDir = entry.endsWith("/");
|
|
753
|
+
const entryIcon = isDir ? theme.fg("accent", theme.icon.folder) : theme.fg("muted", theme.icon.file);
|
|
754
|
+
const entryColor = isDir ? "accent" : "toolOutput";
|
|
755
|
+
text += `\n ${theme.fg("dim", branch)} ${entryIcon} ${theme.fg(entryColor, entry)}`;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
if (!expanded && entries.length > 12) {
|
|
759
|
+
text += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg(
|
|
760
|
+
"muted",
|
|
761
|
+
`${theme.format.ellipsis} ${entries.length - 12} more entries`,
|
|
762
|
+
)}`;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
return new Text(text, 0, 0);
|
|
766
|
+
},
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
// ============================================================================
|
|
770
|
+
// Web Fetch Renderer
|
|
771
|
+
// ============================================================================
|
|
772
|
+
|
|
773
|
+
interface WebFetchArgs {
|
|
774
|
+
url: string;
|
|
775
|
+
timeout?: number;
|
|
776
|
+
raw?: boolean;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
const webFetchRenderer: ToolRenderer<WebFetchArgs, WebFetchToolDetails> = {
|
|
780
|
+
renderCall: renderWebFetchCall,
|
|
781
|
+
renderResult: renderWebFetchResult,
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
// ============================================================================
|
|
785
|
+
// Web Search Renderer
|
|
786
|
+
// ============================================================================
|
|
787
|
+
|
|
788
|
+
interface WebSearchArgs {
|
|
789
|
+
query: string;
|
|
790
|
+
provider?: string;
|
|
791
|
+
[key: string]: unknown;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
const webSearchRenderer: ToolRenderer<WebSearchArgs, WebSearchRenderDetails> = {
|
|
795
|
+
renderCall: renderWebSearchCall,
|
|
796
|
+
renderResult: renderWebSearchResult,
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
// ============================================================================
|
|
800
|
+
// Export
|
|
801
|
+
// ============================================================================
|
|
802
|
+
|
|
803
|
+
export const toolRenderers: Record<
|
|
804
|
+
string,
|
|
805
|
+
{
|
|
806
|
+
renderCall: (args: any, theme: Theme) => Component;
|
|
807
|
+
renderResult: (result: any, options: RenderResultOptions, theme: Theme) => Component;
|
|
808
|
+
}
|
|
809
|
+
> = {
|
|
810
|
+
ask: askRenderer,
|
|
811
|
+
grep: grepRenderer,
|
|
812
|
+
find: findRenderer,
|
|
813
|
+
notebook: notebookRenderer,
|
|
814
|
+
ls: lsRenderer,
|
|
815
|
+
lsp: lspRenderer,
|
|
816
|
+
output: outputRenderer,
|
|
817
|
+
task: taskRenderer,
|
|
818
|
+
web_fetch: webFetchRenderer,
|
|
819
|
+
web_search: webSearchRenderer,
|
|
820
|
+
};
|