@dirgha/code 1.2.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/LICENSE +101 -0
- package/README.md +674 -0
- package/dist/dirgha.mjs +2185 -0
- package/dist_v2/acp/index.d.ts +1 -0
- package/dist_v2/acp/index.js +2 -0
- package/dist_v2/acp/server.d.ts +31 -0
- package/dist_v2/acp/server.js +137 -0
- package/dist_v2/cli/auth-cmd.d.ts +10 -0
- package/dist_v2/cli/auth-cmd.js +69 -0
- package/dist_v2/cli/config.d.ts +46 -0
- package/dist_v2/cli/config.js +70 -0
- package/dist_v2/cli/flags.d.ts +10 -0
- package/dist_v2/cli/flags.js +49 -0
- package/dist_v2/cli/flows/full-cycle.d.ts +30 -0
- package/dist_v2/cli/flows/full-cycle.js +39 -0
- package/dist_v2/cli/flows/index.d.ts +2 -0
- package/dist_v2/cli/flows/index.js +3 -0
- package/dist_v2/cli/flows/tarball.d.ts +10 -0
- package/dist_v2/cli/flows/tarball.js +47 -0
- package/dist_v2/cli/index.d.ts +4 -0
- package/dist_v2/cli/index.js +5 -0
- package/dist_v2/cli/interactive.d.ts +21 -0
- package/dist_v2/cli/interactive.js +207 -0
- package/dist_v2/cli/main.d.ts +10 -0
- package/dist_v2/cli/main.js +173 -0
- package/dist_v2/cli/models-cmd.d.ts +6 -0
- package/dist_v2/cli/models-cmd.js +50 -0
- package/dist_v2/cli/setup.d.ts +13 -0
- package/dist_v2/cli/setup.js +128 -0
- package/dist_v2/cli/slash/account.d.ts +10 -0
- package/dist_v2/cli/slash/account.js +59 -0
- package/dist_v2/cli/slash/clear.d.ts +8 -0
- package/dist_v2/cli/slash/clear.js +15 -0
- package/dist_v2/cli/slash/compact.d.ts +7 -0
- package/dist_v2/cli/slash/compact.js +13 -0
- package/dist_v2/cli/slash/config.d.ts +8 -0
- package/dist_v2/cli/slash/config.js +49 -0
- package/dist_v2/cli/slash/exit.d.ts +7 -0
- package/dist_v2/cli/slash/exit.js +16 -0
- package/dist_v2/cli/slash/fleet.d.ts +7 -0
- package/dist_v2/cli/slash/fleet.js +22 -0
- package/dist_v2/cli/slash/help.d.ts +9 -0
- package/dist_v2/cli/slash/help.js +31 -0
- package/dist_v2/cli/slash/history.d.ts +7 -0
- package/dist_v2/cli/slash/history.js +42 -0
- package/dist_v2/cli/slash/index.d.ts +30 -0
- package/dist_v2/cli/slash/index.js +52 -0
- package/dist_v2/cli/slash/init.d.ts +8 -0
- package/dist_v2/cli/slash/init.js +57 -0
- package/dist_v2/cli/slash/keys.d.ts +8 -0
- package/dist_v2/cli/slash/keys.js +101 -0
- package/dist_v2/cli/slash/login.d.ts +10 -0
- package/dist_v2/cli/slash/login.js +47 -0
- package/dist_v2/cli/slash/memory.d.ts +8 -0
- package/dist_v2/cli/slash/memory.js +101 -0
- package/dist_v2/cli/slash/mode.d.ts +8 -0
- package/dist_v2/cli/slash/mode.js +30 -0
- package/dist_v2/cli/slash/models.d.ts +8 -0
- package/dist_v2/cli/slash/models.js +73 -0
- package/dist_v2/cli/slash/resume.d.ts +8 -0
- package/dist_v2/cli/slash/resume.js +24 -0
- package/dist_v2/cli/slash/session.d.ts +8 -0
- package/dist_v2/cli/slash/session.js +74 -0
- package/dist_v2/cli/slash/setup.d.ts +8 -0
- package/dist_v2/cli/slash/setup.js +50 -0
- package/dist_v2/cli/slash/status.d.ts +7 -0
- package/dist_v2/cli/slash/status.js +37 -0
- package/dist_v2/cli/slash/theme.d.ts +9 -0
- package/dist_v2/cli/slash/theme.js +53 -0
- package/dist_v2/cli/slash/types.d.ts +14 -0
- package/dist_v2/cli/slash/types.js +9 -0
- package/dist_v2/cli/slash/upgrade.d.ts +9 -0
- package/dist_v2/cli/slash/upgrade.js +66 -0
- package/dist_v2/cli/slash.d.ts +72 -0
- package/dist_v2/cli/slash.js +77 -0
- package/dist_v2/cli/subcommands/ask.d.ts +17 -0
- package/dist_v2/cli/subcommands/ask.js +76 -0
- package/dist_v2/cli/subcommands/audit.d.ts +15 -0
- package/dist_v2/cli/subcommands/audit.js +128 -0
- package/dist_v2/cli/subcommands/chat.d.ts +13 -0
- package/dist_v2/cli/subcommands/chat.js +72 -0
- package/dist_v2/cli/subcommands/compact.d.ts +14 -0
- package/dist_v2/cli/subcommands/compact.js +114 -0
- package/dist_v2/cli/subcommands/doctor.d.ts +11 -0
- package/dist_v2/cli/subcommands/doctor.js +103 -0
- package/dist_v2/cli/subcommands/export-session.d.ts +10 -0
- package/dist_v2/cli/subcommands/export-session.js +60 -0
- package/dist_v2/cli/subcommands/import-session.d.ts +11 -0
- package/dist_v2/cli/subcommands/import-session.js +77 -0
- package/dist_v2/cli/subcommands/index.d.ts +40 -0
- package/dist_v2/cli/subcommands/index.js +38 -0
- package/dist_v2/cli/subcommands/init.d.ts +10 -0
- package/dist_v2/cli/subcommands/init.js +74 -0
- package/dist_v2/cli/subcommands/keys.d.ts +12 -0
- package/dist_v2/cli/subcommands/keys.js +136 -0
- package/dist_v2/cli/subcommands/login.d.ts +10 -0
- package/dist_v2/cli/subcommands/login.js +60 -0
- package/dist_v2/cli/subcommands/logout.d.ts +10 -0
- package/dist_v2/cli/subcommands/logout.js +21 -0
- package/dist_v2/cli/subcommands/models.d.ts +14 -0
- package/dist_v2/cli/subcommands/models.js +144 -0
- package/dist_v2/cli/subcommands/setup.d.ts +11 -0
- package/dist_v2/cli/subcommands/setup.js +107 -0
- package/dist_v2/cli/subcommands/stats.d.ts +13 -0
- package/dist_v2/cli/subcommands/stats.js +148 -0
- package/dist_v2/cli/subcommands/status.d.ts +14 -0
- package/dist_v2/cli/subcommands/status.js +91 -0
- package/dist_v2/cli/submit-paper.d.ts +15 -0
- package/dist_v2/cli/submit-paper.js +68 -0
- package/dist_v2/context/_fts.d.ts +62 -0
- package/dist_v2/context/_fts.js +195 -0
- package/dist_v2/context/branch.d.ts +18 -0
- package/dist_v2/context/branch.js +66 -0
- package/dist_v2/context/compaction.d.ts +26 -0
- package/dist_v2/context/compaction.js +120 -0
- package/dist_v2/context/index.d.ts +5 -0
- package/dist_v2/context/index.js +6 -0
- package/dist_v2/context/knowledge.d.ts +38 -0
- package/dist_v2/context/knowledge.js +146 -0
- package/dist_v2/context/memory.d.ts +80 -0
- package/dist_v2/context/memory.js +276 -0
- package/dist_v2/context/mode.d.ts +25 -0
- package/dist_v2/context/mode.js +81 -0
- package/dist_v2/context/session.d.ts +56 -0
- package/dist_v2/context/session.js +108 -0
- package/dist_v2/daemon/index.d.ts +2 -0
- package/dist_v2/daemon/index.js +3 -0
- package/dist_v2/daemon/protocol.d.ts +73 -0
- package/dist_v2/daemon/protocol.js +6 -0
- package/dist_v2/daemon/server.d.ts +35 -0
- package/dist_v2/daemon/server.js +191 -0
- package/dist_v2/eval/index.d.ts +5 -0
- package/dist_v2/eval/index.js +6 -0
- package/dist_v2/eval/regression.d.ts +14 -0
- package/dist_v2/eval/regression.js +106 -0
- package/dist_v2/eval/reporter.d.ts +7 -0
- package/dist_v2/eval/reporter.js +34 -0
- package/dist_v2/eval/swe-bench.d.ts +18 -0
- package/dist_v2/eval/swe-bench.js +23 -0
- package/dist_v2/eval/terminal-bench.d.ts +13 -0
- package/dist_v2/eval/terminal-bench.js +19 -0
- package/dist_v2/eval/types.d.ts +36 -0
- package/dist_v2/eval/types.js +5 -0
- package/dist_v2/fleet/apply-back.d.ts +27 -0
- package/dist_v2/fleet/apply-back.js +191 -0
- package/dist_v2/fleet/cli-command.d.ts +61 -0
- package/dist_v2/fleet/cli-command.js +329 -0
- package/dist_v2/fleet/index.d.ts +21 -0
- package/dist_v2/fleet/index.js +21 -0
- package/dist_v2/fleet/runner.d.ts +28 -0
- package/dist_v2/fleet/runner.js +347 -0
- package/dist_v2/fleet/tripleshot.d.ts +21 -0
- package/dist_v2/fleet/tripleshot.js +222 -0
- package/dist_v2/fleet/types.d.ts +193 -0
- package/dist_v2/fleet/types.js +24 -0
- package/dist_v2/fleet/worktree.d.ts +51 -0
- package/dist_v2/fleet/worktree.js +176 -0
- package/dist_v2/hooks/index.d.ts +1 -0
- package/dist_v2/hooks/index.js +2 -0
- package/dist_v2/hooks/registry.d.ts +21 -0
- package/dist_v2/hooks/registry.js +40 -0
- package/dist_v2/index.d.ts +12 -0
- package/dist_v2/index.js +11 -0
- package/dist_v2/integrations/arniko-client.d.ts +42 -0
- package/dist_v2/integrations/arniko-client.js +86 -0
- package/dist_v2/integrations/auth.d.ts +45 -0
- package/dist_v2/integrations/auth.js +54 -0
- package/dist_v2/integrations/billing.d.ts +71 -0
- package/dist_v2/integrations/billing.js +107 -0
- package/dist_v2/integrations/bucky-client.d.ts +105 -0
- package/dist_v2/integrations/bucky-client.js +76 -0
- package/dist_v2/integrations/deploy-client.d.ts +60 -0
- package/dist_v2/integrations/deploy-client.js +87 -0
- package/dist_v2/integrations/device-auth.d.ts +48 -0
- package/dist_v2/integrations/device-auth.js +192 -0
- package/dist_v2/integrations/entitlements.d.ts +34 -0
- package/dist_v2/integrations/entitlements.js +43 -0
- package/dist_v2/integrations/http.d.ts +22 -0
- package/dist_v2/integrations/http.js +114 -0
- package/dist_v2/integrations/index.d.ts +8 -0
- package/dist_v2/integrations/index.js +15 -0
- package/dist_v2/intelligence/cost.d.ts +28 -0
- package/dist_v2/intelligence/cost.js +58 -0
- package/dist_v2/intelligence/error-classifier.d.ts +8 -0
- package/dist_v2/intelligence/error-classifier.js +71 -0
- package/dist_v2/intelligence/index.d.ts +5 -0
- package/dist_v2/intelligence/index.js +6 -0
- package/dist_v2/intelligence/prices.d.ts +13 -0
- package/dist_v2/intelligence/prices.js +26 -0
- package/dist_v2/intelligence/smart-router.d.ts +21 -0
- package/dist_v2/intelligence/smart-router.js +59 -0
- package/dist_v2/intelligence/telemetry.d.ts +22 -0
- package/dist_v2/intelligence/telemetry.js +31 -0
- package/dist_v2/kernel/agent-loop.d.ts +32 -0
- package/dist_v2/kernel/agent-loop.js +151 -0
- package/dist_v2/kernel/event-stream.d.ts +18 -0
- package/dist_v2/kernel/event-stream.js +102 -0
- package/dist_v2/kernel/index.d.ts +4 -0
- package/dist_v2/kernel/index.js +5 -0
- package/dist_v2/kernel/message.d.ts +29 -0
- package/dist_v2/kernel/message.js +118 -0
- package/dist_v2/kernel/types.d.ts +206 -0
- package/dist_v2/kernel/types.js +9 -0
- package/dist_v2/mcp/client.d.ts +44 -0
- package/dist_v2/mcp/client.js +63 -0
- package/dist_v2/mcp/index.d.ts +3 -0
- package/dist_v2/mcp/index.js +4 -0
- package/dist_v2/mcp/tool-bridge.d.ts +11 -0
- package/dist_v2/mcp/tool-bridge.js +33 -0
- package/dist_v2/mcp/transport.d.ts +29 -0
- package/dist_v2/mcp/transport.js +73 -0
- package/dist_v2/parity/index.d.ts +3 -0
- package/dist_v2/parity/index.js +4 -0
- package/dist_v2/parity/mock-openai-compat.d.ts +15 -0
- package/dist_v2/parity/mock-openai-compat.js +35 -0
- package/dist_v2/parity/runner.d.ts +21 -0
- package/dist_v2/parity/runner.js +76 -0
- package/dist_v2/parity/scenarios.d.ts +20 -0
- package/dist_v2/parity/scenarios.js +70 -0
- package/dist_v2/providers/anthropic.d.ts +21 -0
- package/dist_v2/providers/anthropic.js +191 -0
- package/dist_v2/providers/dispatch.d.ts +11 -0
- package/dist_v2/providers/dispatch.js +45 -0
- package/dist_v2/providers/fireworks.d.ts +18 -0
- package/dist_v2/providers/fireworks.js +44 -0
- package/dist_v2/providers/gemini.d.ts +19 -0
- package/dist_v2/providers/gemini.js +188 -0
- package/dist_v2/providers/http.d.ts +41 -0
- package/dist_v2/providers/http.js +188 -0
- package/dist_v2/providers/iface.d.ts +18 -0
- package/dist_v2/providers/iface.js +18 -0
- package/dist_v2/providers/index.d.ts +39 -0
- package/dist_v2/providers/index.js +51 -0
- package/dist_v2/providers/nvidia.d.ts +27 -0
- package/dist_v2/providers/nvidia.js +142 -0
- package/dist_v2/providers/ollama.d.ts +15 -0
- package/dist_v2/providers/ollama.js +37 -0
- package/dist_v2/providers/openai-compat.d.ts +29 -0
- package/dist_v2/providers/openai-compat.js +239 -0
- package/dist_v2/providers/openai.d.ts +20 -0
- package/dist_v2/providers/openai.js +107 -0
- package/dist_v2/providers/openrouter.d.ts +24 -0
- package/dist_v2/providers/openrouter.js +69 -0
- package/dist_v2/safety/approval-bus.d.ts +26 -0
- package/dist_v2/safety/approval-bus.js +48 -0
- package/dist_v2/safety/audit-log.d.ts +27 -0
- package/dist_v2/safety/audit-log.js +71 -0
- package/dist_v2/safety/index.d.ts +4 -0
- package/dist_v2/safety/index.js +5 -0
- package/dist_v2/safety/policy.d.ts +32 -0
- package/dist_v2/safety/policy.js +131 -0
- package/dist_v2/safety/sandbox/bwrap.d.ts +11 -0
- package/dist_v2/safety/sandbox/bwrap.js +52 -0
- package/dist_v2/safety/sandbox/iface.d.ts +29 -0
- package/dist_v2/safety/sandbox/iface.js +8 -0
- package/dist_v2/safety/sandbox/index.d.ts +7 -0
- package/dist_v2/safety/sandbox/index.js +8 -0
- package/dist_v2/safety/sandbox/landlock.d.ts +17 -0
- package/dist_v2/safety/sandbox/landlock.js +26 -0
- package/dist_v2/safety/sandbox/noop.d.ts +12 -0
- package/dist_v2/safety/sandbox/noop.js +52 -0
- package/dist_v2/safety/sandbox/seatbelt.d.ts +11 -0
- package/dist_v2/safety/sandbox/seatbelt.js +49 -0
- package/dist_v2/safety/sandbox/select.d.ts +6 -0
- package/dist_v2/safety/sandbox/select.js +42 -0
- package/dist_v2/safety/sandbox/windows.d.ts +13 -0
- package/dist_v2/safety/sandbox/windows.js +22 -0
- package/dist_v2/skills/index.d.ts +3 -0
- package/dist_v2/skills/index.js +4 -0
- package/dist_v2/skills/loader.d.ts +38 -0
- package/dist_v2/skills/loader.js +102 -0
- package/dist_v2/skills/matcher.d.ts +14 -0
- package/dist_v2/skills/matcher.js +72 -0
- package/dist_v2/skills/runtime.d.ts +13 -0
- package/dist_v2/skills/runtime.js +40 -0
- package/dist_v2/subagents/delegator.d.ts +36 -0
- package/dist_v2/subagents/delegator.js +82 -0
- package/dist_v2/subagents/index.d.ts +2 -0
- package/dist_v2/subagents/index.js +3 -0
- package/dist_v2/subagents/pool.d.ts +18 -0
- package/dist_v2/subagents/pool.js +31 -0
- package/dist_v2/tools/browser.d.ts +27 -0
- package/dist_v2/tools/browser.js +179 -0
- package/dist_v2/tools/checkpoint.d.ts +25 -0
- package/dist_v2/tools/checkpoint.js +222 -0
- package/dist_v2/tools/cron.d.ts +32 -0
- package/dist_v2/tools/cron.js +160 -0
- package/dist_v2/tools/diff.d.ts +18 -0
- package/dist_v2/tools/diff.js +117 -0
- package/dist_v2/tools/exec.d.ts +19 -0
- package/dist_v2/tools/exec.js +49 -0
- package/dist_v2/tools/fs-edit.d.ts +11 -0
- package/dist_v2/tools/fs-edit.js +81 -0
- package/dist_v2/tools/fs-ls.d.ts +7 -0
- package/dist_v2/tools/fs-ls.js +57 -0
- package/dist_v2/tools/fs-read.d.ts +7 -0
- package/dist_v2/tools/fs-read.js +60 -0
- package/dist_v2/tools/fs-write.d.ts +8 -0
- package/dist_v2/tools/fs-write.js +46 -0
- package/dist_v2/tools/git.d.ts +8 -0
- package/dist_v2/tools/git.js +57 -0
- package/dist_v2/tools/index.d.ts +25 -0
- package/dist_v2/tools/index.js +39 -0
- package/dist_v2/tools/multimodal.d.ts +41 -0
- package/dist_v2/tools/multimodal.js +381 -0
- package/dist_v2/tools/permission.d.ts +27 -0
- package/dist_v2/tools/permission.js +43 -0
- package/dist_v2/tools/registry.d.ts +44 -0
- package/dist_v2/tools/registry.js +62 -0
- package/dist_v2/tools/search-glob.d.ts +7 -0
- package/dist_v2/tools/search-glob.js +98 -0
- package/dist_v2/tools/search-grep.d.ts +7 -0
- package/dist_v2/tools/search-grep.js +109 -0
- package/dist_v2/tools/shell.d.ts +10 -0
- package/dist_v2/tools/shell.js +76 -0
- package/dist_v2/tools/task.d.ts +8 -0
- package/dist_v2/tools/task.js +37 -0
- package/dist_v2/tui/approval.d.ts +7 -0
- package/dist_v2/tui/approval.js +55 -0
- package/dist_v2/tui/index.d.ts +4 -0
- package/dist_v2/tui/index.js +5 -0
- package/dist_v2/tui/ink/App.d.ts +39 -0
- package/dist_v2/tui/ink/App.js +206 -0
- package/dist_v2/tui/ink/components/AtFileComplete.d.ts +25 -0
- package/dist_v2/tui/ink/components/AtFileComplete.js +158 -0
- package/dist_v2/tui/ink/components/HelpOverlay.d.ts +24 -0
- package/dist_v2/tui/ink/components/HelpOverlay.js +130 -0
- package/dist_v2/tui/ink/components/InputBox.d.ts +35 -0
- package/dist_v2/tui/ink/components/InputBox.js +153 -0
- package/dist_v2/tui/ink/components/Logo.d.ts +12 -0
- package/dist_v2/tui/ink/components/Logo.js +27 -0
- package/dist_v2/tui/ink/components/ModelPicker.d.ts +26 -0
- package/dist_v2/tui/ink/components/ModelPicker.js +80 -0
- package/dist_v2/tui/ink/components/PasteCollapse.d.ts +36 -0
- package/dist_v2/tui/ink/components/PasteCollapse.js +59 -0
- package/dist_v2/tui/ink/components/StatusBar.d.ts +18 -0
- package/dist_v2/tui/ink/components/StatusBar.js +41 -0
- package/dist_v2/tui/ink/components/StreamingText.d.ts +14 -0
- package/dist_v2/tui/ink/components/StreamingText.js +11 -0
- package/dist_v2/tui/ink/components/ThinkingBlock.d.ts +13 -0
- package/dist_v2/tui/ink/components/ThinkingBlock.js +13 -0
- package/dist_v2/tui/ink/components/ToolBox.d.ts +20 -0
- package/dist_v2/tui/ink/components/ToolBox.js +63 -0
- package/dist_v2/tui/ink/components/vim-bindings.d.ts +43 -0
- package/dist_v2/tui/ink/components/vim-bindings.js +135 -0
- package/dist_v2/tui/ink/index.d.ts +39 -0
- package/dist_v2/tui/ink/index.js +47 -0
- package/dist_v2/tui/ink/use-event-projection.d.ts +51 -0
- package/dist_v2/tui/ink/use-event-projection.js +126 -0
- package/dist_v2/tui/ink/use-overlays.d.ts +24 -0
- package/dist_v2/tui/ink/use-overlays.js +50 -0
- package/dist_v2/tui/renderer.d.ts +19 -0
- package/dist_v2/tui/renderer.js +64 -0
- package/dist_v2/tui/status-bar.d.ts +12 -0
- package/dist_v2/tui/status-bar.js +16 -0
- package/dist_v2/tui/theme.d.ts +27 -0
- package/dist_v2/tui/theme.js +56 -0
- package/dist_v2/utils/json-repair.d.ts +7 -0
- package/dist_v2/utils/json-repair.js +45 -0
- package/package.json +113 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code search using ripgrep when available, with a conservative fallback
|
|
3
|
+
* to a Node-native line scan. Always returns file:line:match triples,
|
|
4
|
+
* capped by resultLimit to keep the LLM reply compact.
|
|
5
|
+
*/
|
|
6
|
+
import { spawn } from 'node:child_process';
|
|
7
|
+
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
8
|
+
import { resolve, join } from 'node:path';
|
|
9
|
+
const DEFAULT_LIMIT = 200;
|
|
10
|
+
export const searchGrepTool = {
|
|
11
|
+
name: 'search_grep',
|
|
12
|
+
description: 'Search for a regex pattern across files under a directory. Prefers ripgrep when installed.',
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
pattern: { type: 'string' },
|
|
17
|
+
path: { type: 'string' },
|
|
18
|
+
resultLimit: { type: 'integer', minimum: 1 },
|
|
19
|
+
ignoreCase: { type: 'boolean' },
|
|
20
|
+
filePattern: { type: 'string', description: 'Glob to limit files (ripgrep --glob).' },
|
|
21
|
+
},
|
|
22
|
+
required: ['pattern'],
|
|
23
|
+
},
|
|
24
|
+
async execute(rawInput, ctx) {
|
|
25
|
+
const input = rawInput;
|
|
26
|
+
const root = resolve(ctx.cwd, input.path ?? '.');
|
|
27
|
+
const limit = input.resultLimit ?? DEFAULT_LIMIT;
|
|
28
|
+
const rg = await runRipgrep(input, root, limit);
|
|
29
|
+
if (rg)
|
|
30
|
+
return rg;
|
|
31
|
+
return nodeScan(input, root, limit);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
async function runRipgrep(input, root, limit) {
|
|
35
|
+
const args = ['--line-number', '--no-heading', '--color', 'never', `--max-count=${limit}`];
|
|
36
|
+
if (input.ignoreCase)
|
|
37
|
+
args.push('--ignore-case');
|
|
38
|
+
if (input.filePattern)
|
|
39
|
+
args.push('--glob', input.filePattern);
|
|
40
|
+
args.push('--', input.pattern, root);
|
|
41
|
+
const child = spawn('rg', args, { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
42
|
+
const out = [];
|
|
43
|
+
const errChunks = [];
|
|
44
|
+
child.stdout.on('data', (buf) => { out.push(buf.toString('utf8')); });
|
|
45
|
+
child.stderr.on('data', (buf) => { errChunks.push(buf); });
|
|
46
|
+
const exitCode = await new Promise((resolveExit, rejectExit) => {
|
|
47
|
+
child.on('error', err => rejectExit(err));
|
|
48
|
+
child.on('exit', code => resolveExit(code ?? -1));
|
|
49
|
+
}).catch(() => -1);
|
|
50
|
+
if (exitCode === -1 || exitCode === 2)
|
|
51
|
+
return undefined;
|
|
52
|
+
const joined = out.join('');
|
|
53
|
+
const lines = joined.length > 0 ? joined.split('\n').filter(l => l.length > 0) : [];
|
|
54
|
+
const truncated = lines.length >= limit;
|
|
55
|
+
return {
|
|
56
|
+
content: lines.length > 0 ? lines.join('\n') : '(no matches)',
|
|
57
|
+
data: { matches: lines.length, truncated, engine: 'ripgrep' },
|
|
58
|
+
isError: false,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async function nodeScan(input, root, limit) {
|
|
62
|
+
const flags = input.ignoreCase ? 'gi' : 'g';
|
|
63
|
+
let regex;
|
|
64
|
+
try {
|
|
65
|
+
regex = new RegExp(input.pattern, flags);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
return { content: `Invalid regex: ${String(err)}`, isError: true };
|
|
69
|
+
}
|
|
70
|
+
const matches = [];
|
|
71
|
+
let truncated = false;
|
|
72
|
+
async function walk(dir) {
|
|
73
|
+
if (matches.length >= limit) {
|
|
74
|
+
truncated = true;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const names = await readdir(dir).catch(() => []);
|
|
78
|
+
for (const name of names) {
|
|
79
|
+
if (name === 'node_modules' || name === '.git' || name === 'dist')
|
|
80
|
+
continue;
|
|
81
|
+
const abs = join(dir, name);
|
|
82
|
+
const info = await stat(abs).catch(() => undefined);
|
|
83
|
+
if (!info)
|
|
84
|
+
continue;
|
|
85
|
+
if (info.isDirectory())
|
|
86
|
+
await walk(abs);
|
|
87
|
+
else if (info.isFile() && info.size < 512 * 1024) {
|
|
88
|
+
const text = await readFile(abs, 'utf8').catch(() => '');
|
|
89
|
+
const lines = text.split('\n');
|
|
90
|
+
for (let i = 0; i < lines.length; i++) {
|
|
91
|
+
if (regex.test(lines[i])) {
|
|
92
|
+
matches.push(`${abs}:${i + 1}:${lines[i]}`);
|
|
93
|
+
if (matches.length >= limit) {
|
|
94
|
+
truncated = true;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
await walk(root);
|
|
103
|
+
return {
|
|
104
|
+
content: matches.length > 0 ? matches.join('\n') : '(no matches)',
|
|
105
|
+
data: { matches: matches.length, truncated, engine: 'node' },
|
|
106
|
+
isError: false,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=search-grep.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell command execution.
|
|
3
|
+
*
|
|
4
|
+
* Runs through a sandbox adapter when one is configured; otherwise
|
|
5
|
+
* spawns a child process with inherited env. Output is captured with a
|
|
6
|
+
* byte cap; on overflow we truncate and indicate the remaining size so
|
|
7
|
+
* the model does not misread a capped stream as a complete one.
|
|
8
|
+
*/
|
|
9
|
+
import type { Tool } from './registry.js';
|
|
10
|
+
export declare const shellTool: Tool;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell command execution.
|
|
3
|
+
*
|
|
4
|
+
* Runs through a sandbox adapter when one is configured; otherwise
|
|
5
|
+
* spawns a child process with inherited env. Output is captured with a
|
|
6
|
+
* byte cap; on overflow we truncate and indicate the remaining size so
|
|
7
|
+
* the model does not misread a capped stream as a complete one.
|
|
8
|
+
*/
|
|
9
|
+
import { spawn } from 'node:child_process';
|
|
10
|
+
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
11
|
+
const MAX_OUTPUT_BYTES = 256 * 1024;
|
|
12
|
+
export const shellTool = {
|
|
13
|
+
name: 'shell',
|
|
14
|
+
description: 'Execute a shell command via /bin/sh. Returns stdout, stderr, and exit code. Long-running commands time out.',
|
|
15
|
+
inputSchema: {
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
command: { type: 'string' },
|
|
19
|
+
cwd: { type: 'string' },
|
|
20
|
+
timeoutMs: { type: 'integer', minimum: 1000 },
|
|
21
|
+
},
|
|
22
|
+
required: ['command'],
|
|
23
|
+
},
|
|
24
|
+
requiresApproval: () => true,
|
|
25
|
+
async execute(rawInput, ctx) {
|
|
26
|
+
const input = rawInput;
|
|
27
|
+
const cwd = input.cwd ?? ctx.cwd;
|
|
28
|
+
const timeoutMs = input.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
29
|
+
const child = spawn('/bin/sh', ['-c', input.command], {
|
|
30
|
+
cwd,
|
|
31
|
+
env: ctx.env,
|
|
32
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
33
|
+
});
|
|
34
|
+
const stdoutChunks = [];
|
|
35
|
+
const stderrChunks = [];
|
|
36
|
+
let stdoutBytes = 0;
|
|
37
|
+
let stderrBytes = 0;
|
|
38
|
+
let truncated = false;
|
|
39
|
+
const onData = (chunks, counter) => (buf) => {
|
|
40
|
+
const remaining = MAX_OUTPUT_BYTES - counter(0);
|
|
41
|
+
if (remaining <= 0) {
|
|
42
|
+
truncated = true;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const slice = buf.length <= remaining ? buf : buf.subarray(0, remaining);
|
|
46
|
+
chunks.push(slice);
|
|
47
|
+
counter(slice.length);
|
|
48
|
+
if (buf.length > remaining)
|
|
49
|
+
truncated = true;
|
|
50
|
+
};
|
|
51
|
+
const stdoutCount = ((acc = 0) => (add) => { acc += add; stdoutBytes = acc; return acc; })();
|
|
52
|
+
const stderrCount = ((acc = 0) => (add) => { acc += add; stderrBytes = acc; return acc; })();
|
|
53
|
+
child.stdout.on('data', onData(stdoutChunks, stdoutCount));
|
|
54
|
+
child.stderr.on('data', onData(stderrChunks, stderrCount));
|
|
55
|
+
const timer = setTimeout(() => { child.kill('SIGKILL'); }, timeoutMs);
|
|
56
|
+
const exitCode = await new Promise(resolveExit => {
|
|
57
|
+
child.on('error', () => resolveExit(-1));
|
|
58
|
+
child.on('exit', code => resolveExit(code ?? -1));
|
|
59
|
+
});
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
const stdout = Buffer.concat(stdoutChunks).toString('utf8');
|
|
62
|
+
const stderr = Buffer.concat(stderrChunks).toString('utf8');
|
|
63
|
+
const banner = `exit=${exitCode}${truncated ? ' [output truncated]' : ''}`;
|
|
64
|
+
const body = [
|
|
65
|
+
banner,
|
|
66
|
+
stdout.length > 0 ? `STDOUT:\n${stdout}` : '',
|
|
67
|
+
stderr.length > 0 ? `STDERR:\n${stderr}` : '',
|
|
68
|
+
].filter(Boolean).join('\n\n');
|
|
69
|
+
return {
|
|
70
|
+
content: body.length > 0 ? body : banner,
|
|
71
|
+
data: { exitCode, stdoutBytes, stderrBytes, truncated },
|
|
72
|
+
isError: exitCode !== 0,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `task` tool: lets the parent agent delegate a well-scoped sub-problem
|
|
3
|
+
* to a fresh agent instance. Returns only the final text output so the
|
|
4
|
+
* parent's context stays clean.
|
|
5
|
+
*/
|
|
6
|
+
import type { Tool } from './registry.js';
|
|
7
|
+
import type { SubagentDelegator } from '../subagents/delegator.js';
|
|
8
|
+
export declare function createTaskTool(delegator: SubagentDelegator): Tool;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `task` tool: lets the parent agent delegate a well-scoped sub-problem
|
|
3
|
+
* to a fresh agent instance. Returns only the final text output so the
|
|
4
|
+
* parent's context stays clean.
|
|
5
|
+
*/
|
|
6
|
+
export function createTaskTool(delegator) {
|
|
7
|
+
return {
|
|
8
|
+
name: 'task',
|
|
9
|
+
description: 'Delegate a sub-problem to a fresh agent with its own conversation, tool set, and budget. Returns only the sub-agent\'s final text answer.',
|
|
10
|
+
inputSchema: {
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
prompt: { type: 'string', description: 'The sub-agent\'s goal.' },
|
|
14
|
+
system: { type: 'string', description: 'System prompt for the sub-agent (optional).' },
|
|
15
|
+
toolAllowlist: { type: 'array', items: { type: 'string' }, description: 'Optional subset of tool names the sub-agent may use.' },
|
|
16
|
+
maxTurns: { type: 'integer', minimum: 1, maximum: 24 },
|
|
17
|
+
model: { type: 'string' },
|
|
18
|
+
},
|
|
19
|
+
required: ['prompt'],
|
|
20
|
+
},
|
|
21
|
+
async execute(rawInput, _ctx) {
|
|
22
|
+
const input = rawInput;
|
|
23
|
+
const result = await delegator.delegate(input);
|
|
24
|
+
return {
|
|
25
|
+
content: result.output || '(sub-agent produced no output)',
|
|
26
|
+
isError: result.stopReason === 'error',
|
|
27
|
+
metadata: {
|
|
28
|
+
subSessionId: result.sessionId,
|
|
29
|
+
inputTokens: result.usage.inputTokens,
|
|
30
|
+
outputTokens: result.usage.outputTokens,
|
|
31
|
+
stopReason: result.stopReason,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=task.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approval prompt. Synchronously reads a single-char response from
|
|
3
|
+
* stdin; falls back to a line-based prompt when stdin is not a TTY
|
|
4
|
+
* (e.g., piped invocations).
|
|
5
|
+
*/
|
|
6
|
+
import type { ApprovalBus } from '../kernel/types.js';
|
|
7
|
+
export declare function createTuiApprovalBus(autoApproveTools?: Set<string>): ApprovalBus;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approval prompt. Synchronously reads a single-char response from
|
|
3
|
+
* stdin; falls back to a line-based prompt when stdin is not a TTY
|
|
4
|
+
* (e.g., piped invocations).
|
|
5
|
+
*/
|
|
6
|
+
import { style, defaultTheme } from './theme.js';
|
|
7
|
+
import { createInterface } from 'node:readline';
|
|
8
|
+
export function createTuiApprovalBus(autoApproveTools = new Set()) {
|
|
9
|
+
return {
|
|
10
|
+
requiresApproval(toolName) {
|
|
11
|
+
return !autoApproveTools.has(toolName);
|
|
12
|
+
},
|
|
13
|
+
async request(req) {
|
|
14
|
+
const banner = style(defaultTheme.warning, `\n⚠ Approve ${req.tool}? (y/n/a=always/d=deny-all) [y]`);
|
|
15
|
+
process.stdout.write(`${banner}\n`);
|
|
16
|
+
process.stdout.write(style(defaultTheme.muted, ` ${req.summary}\n`));
|
|
17
|
+
if (req.diff) {
|
|
18
|
+
const preview = truncate(req.diff, 1200);
|
|
19
|
+
process.stdout.write(`${preview}\n`);
|
|
20
|
+
}
|
|
21
|
+
process.stdout.write('> ');
|
|
22
|
+
const answer = await readOneChar();
|
|
23
|
+
switch (answer.toLowerCase()) {
|
|
24
|
+
case 'a':
|
|
25
|
+
autoApproveTools.add(req.tool);
|
|
26
|
+
return 'approve_once';
|
|
27
|
+
case 'd': return 'deny_always';
|
|
28
|
+
case 'n': return 'deny';
|
|
29
|
+
default: return 'approve';
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function readOneChar() {
|
|
35
|
+
return new Promise(resolve => {
|
|
36
|
+
if (!process.stdin.isTTY) {
|
|
37
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
38
|
+
rl.question('', ans => { rl.close(); resolve(ans.trim()); });
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const onData = (buf) => {
|
|
42
|
+
process.stdin.setRawMode(false);
|
|
43
|
+
process.stdin.pause();
|
|
44
|
+
process.stdin.off('data', onData);
|
|
45
|
+
resolve(buf.toString('utf8'));
|
|
46
|
+
};
|
|
47
|
+
process.stdin.setRawMode(true);
|
|
48
|
+
process.stdin.resume();
|
|
49
|
+
process.stdin.once('data', onData);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function truncate(s, max) {
|
|
53
|
+
return s.length <= max ? s : `${s.slice(0, max - 1)}…`;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=approval.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ink root component for the dirgha TUI.
|
|
3
|
+
*
|
|
4
|
+
* Layout is a single vertical stack:
|
|
5
|
+
* 1. Logo (rendered once inside <Static>, never re-renders)
|
|
6
|
+
* 2. Transcript (finalised user messages + completed turn blocks)
|
|
7
|
+
* 3. LiveTurn (the currently streaming turn, if any)
|
|
8
|
+
* 4. InputBox
|
|
9
|
+
* 5. StatusBar
|
|
10
|
+
* 6. Optional overlay (ModelPicker / HelpOverlay / AtFileComplete)
|
|
11
|
+
*
|
|
12
|
+
* Event → transcript projection lives in `use-event-projection.ts`;
|
|
13
|
+
* overlay state lives in `use-overlays.ts`. This component stays
|
|
14
|
+
* focused on layout and lifecycle.
|
|
15
|
+
*/
|
|
16
|
+
import * as React from 'react';
|
|
17
|
+
import type { Message } from '../../kernel/types.js';
|
|
18
|
+
import type { EventStream } from '../../kernel/event-stream.js';
|
|
19
|
+
import type { ProviderRegistry } from '../../providers/index.js';
|
|
20
|
+
import type { ToolRegistry } from '../../tools/registry.js';
|
|
21
|
+
import type { SessionStore } from '../../context/session.js';
|
|
22
|
+
import type { DirghaConfig } from '../../cli/config.js';
|
|
23
|
+
import { type ModelEntry } from './components/ModelPicker.js';
|
|
24
|
+
import { type HelpSlashCommand } from './components/HelpOverlay.js';
|
|
25
|
+
export interface AppProps {
|
|
26
|
+
events: EventStream;
|
|
27
|
+
registry: ToolRegistry;
|
|
28
|
+
providers: ProviderRegistry;
|
|
29
|
+
sessions: SessionStore;
|
|
30
|
+
config: DirghaConfig;
|
|
31
|
+
cwd: string;
|
|
32
|
+
systemPrompt?: string;
|
|
33
|
+
initialMessages?: Message[];
|
|
34
|
+
/** Slash commands to render in the help overlay. Defaults to []. */
|
|
35
|
+
slashCommands?: HelpSlashCommand[];
|
|
36
|
+
/** Model catalogue. Defaults to the prices registry. */
|
|
37
|
+
models?: ModelEntry[];
|
|
38
|
+
}
|
|
39
|
+
export declare function App(props: AppProps): React.JSX.Element;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Ink root component for the dirgha TUI.
|
|
4
|
+
*
|
|
5
|
+
* Layout is a single vertical stack:
|
|
6
|
+
* 1. Logo (rendered once inside <Static>, never re-renders)
|
|
7
|
+
* 2. Transcript (finalised user messages + completed turn blocks)
|
|
8
|
+
* 3. LiveTurn (the currently streaming turn, if any)
|
|
9
|
+
* 4. InputBox
|
|
10
|
+
* 5. StatusBar
|
|
11
|
+
* 6. Optional overlay (ModelPicker / HelpOverlay / AtFileComplete)
|
|
12
|
+
*
|
|
13
|
+
* Event → transcript projection lives in `use-event-projection.ts`;
|
|
14
|
+
* overlay state lives in `use-overlays.ts`. This component stays
|
|
15
|
+
* focused on layout and lifecycle.
|
|
16
|
+
*/
|
|
17
|
+
import * as React from 'react';
|
|
18
|
+
import { Box, Static, Text, useApp, useInput } from 'ink';
|
|
19
|
+
import { randomUUID } from 'node:crypto';
|
|
20
|
+
import { runAgentLoop } from '../../kernel/agent-loop.js';
|
|
21
|
+
import { createToolExecutor } from '../../tools/exec.js';
|
|
22
|
+
import { createTuiApprovalBus } from '../approval.js';
|
|
23
|
+
import { PRICES } from '../../intelligence/prices.js';
|
|
24
|
+
import { Logo } from './components/Logo.js';
|
|
25
|
+
import { StatusBar } from './components/StatusBar.js';
|
|
26
|
+
import { StreamingText } from './components/StreamingText.js';
|
|
27
|
+
import { ThinkingBlock } from './components/ThinkingBlock.js';
|
|
28
|
+
import { ToolBox } from './components/ToolBox.js';
|
|
29
|
+
import { InputBox } from './components/InputBox.js';
|
|
30
|
+
import { ModelPicker } from './components/ModelPicker.js';
|
|
31
|
+
import { HelpOverlay } from './components/HelpOverlay.js';
|
|
32
|
+
import { AtFileComplete } from './components/AtFileComplete.js';
|
|
33
|
+
import { useEventProjection } from './use-event-projection.js';
|
|
34
|
+
import { useOverlays } from './use-overlays.js';
|
|
35
|
+
const VERSION = '0.2.0';
|
|
36
|
+
export function App(props) {
|
|
37
|
+
const { exit } = useApp();
|
|
38
|
+
const sessionIdRef = React.useRef(randomUUID());
|
|
39
|
+
const historyRef = React.useRef(initialHistory(props));
|
|
40
|
+
const abortRef = React.useRef(null);
|
|
41
|
+
const [transcript, setTranscript] = React.useState([]);
|
|
42
|
+
const [input, setInput] = React.useState('');
|
|
43
|
+
const [busy, setBusy] = React.useState(false);
|
|
44
|
+
const [currentModel, setCurrentModel] = React.useState(props.config.model);
|
|
45
|
+
const projection = useEventProjection(props.events);
|
|
46
|
+
const overlays = useOverlays();
|
|
47
|
+
const models = React.useMemo(() => props.models ?? defaultModelCatalogue(), [props.models]);
|
|
48
|
+
const slashCommands = props.slashCommands ?? [];
|
|
49
|
+
const handleSubmit = React.useCallback((raw) => {
|
|
50
|
+
const value = raw.trim();
|
|
51
|
+
if (value.length === 0 || busy)
|
|
52
|
+
return;
|
|
53
|
+
setInput('');
|
|
54
|
+
if (value === '/exit' || value === '/quit') {
|
|
55
|
+
exit();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (value === '/clear') {
|
|
59
|
+
historyRef.current = initialHistory(props);
|
|
60
|
+
setTranscript([]);
|
|
61
|
+
projection.clear();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// `/model` with no args opens the picker; `/model <id>` sets directly.
|
|
65
|
+
if (value === '/model' || value === '/models') {
|
|
66
|
+
overlays.openOverlay('models');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (value.startsWith('/model ')) {
|
|
70
|
+
const id = value.slice('/model '.length).trim();
|
|
71
|
+
if (id !== '') {
|
|
72
|
+
setCurrentModel(id);
|
|
73
|
+
const note = { kind: 'notice', id: randomUUID(), text: `Model set to ${id}` };
|
|
74
|
+
setTranscript(prev => [...prev, note]);
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (value === '/help' || value === '/?') {
|
|
79
|
+
overlays.openOverlay('help');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const userItem = { kind: 'user', id: randomUUID(), text: value };
|
|
83
|
+
setTranscript(prev => [...prev, userItem]);
|
|
84
|
+
historyRef.current.push({ role: 'user', content: value });
|
|
85
|
+
void runTurn();
|
|
86
|
+
}, [busy, exit, props, projection, overlays]);
|
|
87
|
+
const runTurn = async () => {
|
|
88
|
+
setBusy(true);
|
|
89
|
+
const abort = new AbortController();
|
|
90
|
+
abortRef.current = abort;
|
|
91
|
+
try {
|
|
92
|
+
const executor = createToolExecutor({
|
|
93
|
+
registry: props.registry,
|
|
94
|
+
cwd: props.cwd,
|
|
95
|
+
sessionId: sessionIdRef.current,
|
|
96
|
+
});
|
|
97
|
+
const sanitized = props.registry.sanitize({ descriptionLimit: 200 });
|
|
98
|
+
const provider = props.providers.forModel(currentModel);
|
|
99
|
+
const approvalBus = createTuiApprovalBus(new Set(props.config.autoApproveTools));
|
|
100
|
+
const result = await runAgentLoop({
|
|
101
|
+
sessionId: sessionIdRef.current,
|
|
102
|
+
model: currentModel,
|
|
103
|
+
messages: historyRef.current,
|
|
104
|
+
tools: sanitized.definitions,
|
|
105
|
+
maxTurns: props.config.maxTurns,
|
|
106
|
+
provider,
|
|
107
|
+
toolExecutor: executor,
|
|
108
|
+
approvalBus,
|
|
109
|
+
events: props.events,
|
|
110
|
+
signal: abort.signal,
|
|
111
|
+
});
|
|
112
|
+
historyRef.current = result.messages;
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
116
|
+
projection.appendLive({ kind: 'error', id: randomUUID(), message: msg });
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
const committed = projection.commitLive();
|
|
120
|
+
if (committed.length > 0)
|
|
121
|
+
setTranscript(prev => [...prev, ...committed]);
|
|
122
|
+
setBusy(false);
|
|
123
|
+
abortRef.current = null;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
// Overlay-level keybindings: Esc closes when one is up. Ctrl+M and
|
|
127
|
+
// Ctrl+H are captured here only while an overlay is absent;
|
|
128
|
+
// InputBox handles them while focused.
|
|
129
|
+
useInput((_ch, key) => {
|
|
130
|
+
if (overlays.active !== null && overlays.active !== 'atfile') {
|
|
131
|
+
if (key.escape)
|
|
132
|
+
overlays.closeOverlay();
|
|
133
|
+
}
|
|
134
|
+
}, { isActive: overlays.active !== null && overlays.active !== 'atfile' });
|
|
135
|
+
const handleModelPick = React.useCallback((id) => {
|
|
136
|
+
setCurrentModel(id);
|
|
137
|
+
overlays.closeOverlay();
|
|
138
|
+
const note = { kind: 'notice', id: randomUUID(), text: `Model set to ${id}` };
|
|
139
|
+
setTranscript(prev => [...prev, note]);
|
|
140
|
+
}, [overlays]);
|
|
141
|
+
const handleAtPick = React.useCallback((path) => {
|
|
142
|
+
setInput(current => overlays.spliceAtSelection(current, path));
|
|
143
|
+
overlays.setAtQuery(null);
|
|
144
|
+
overlays.setActive(null);
|
|
145
|
+
}, [overlays]);
|
|
146
|
+
const inputFocus = overlays.active === null || overlays.active === 'atfile';
|
|
147
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Static, { items: [{ key: 'logo' }], children: (_item) => _jsx(Logo, { version: VERSION }, "logo") }), _jsxs(Box, { flexDirection: "column", children: [transcript.map(item => (_jsx(TranscriptRow, { item: item }, item.id))), projection.liveItems.map(item => (_jsx(TranscriptRow, { item: item }, item.id)))] }), _jsx(InputBox, { value: input, onChange: setInput, onSubmit: handleSubmit, busy: busy, vimMode: props.config.vimMode === true, onAtQueryChange: overlays.setAtQuery, onRequestOverlay: overlays.openOverlay, inputFocus: inputFocus && !busy }), overlays.active === 'atfile' && overlays.atQuery !== null && (_jsx(AtFileComplete, { cwd: props.cwd, query: overlays.atQuery, onPick: handleAtPick, onCancel: () => { overlays.setAtQuery(null); overlays.setActive(null); } })), overlays.active === 'models' && (_jsx(ModelPicker, { models: models, current: currentModel, onPick: handleModelPick, onCancel: overlays.closeOverlay })), overlays.active === 'help' && (_jsx(HelpOverlay, { slashCommands: slashCommands, onClose: overlays.closeOverlay })), _jsx(StatusBar, { model: currentModel, provider: providerIdForModel(currentModel), inputTokens: projection.totals.inputTokens, outputTokens: projection.totals.outputTokens, costUsd: projection.totals.costUsd, cwd: props.cwd, busy: busy })] }));
|
|
148
|
+
}
|
|
149
|
+
function TranscriptRow({ item }) {
|
|
150
|
+
switch (item.kind) {
|
|
151
|
+
case 'user':
|
|
152
|
+
return (_jsxs(Box, { gap: 2, marginBottom: 1, children: [_jsx(Text, { color: "magenta", children: "\u276F" }), _jsx(Text, { color: "white", children: item.text })] }));
|
|
153
|
+
case 'text':
|
|
154
|
+
return _jsx(StreamingText, { content: item.content });
|
|
155
|
+
case 'thinking':
|
|
156
|
+
return _jsx(ThinkingBlock, { content: item.content });
|
|
157
|
+
case 'tool':
|
|
158
|
+
return (_jsx(ToolBox, { name: item.name, status: item.status, argSummary: item.argSummary, outputPreview: item.outputPreview, startedAt: item.startedAt, durationMs: item.durationMs }));
|
|
159
|
+
case 'error':
|
|
160
|
+
return (_jsxs(Box, { gap: 1, marginBottom: 1, children: [_jsx(Text, { color: "red", bold: true, children: "\u2717" }), _jsx(Text, { color: "red", children: item.message })] }));
|
|
161
|
+
case 'notice':
|
|
162
|
+
return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: "yellow", children: item.text }) }));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function initialHistory(props) {
|
|
166
|
+
const base = props.initialMessages ? [...props.initialMessages] : [];
|
|
167
|
+
if (props.systemPrompt)
|
|
168
|
+
base.unshift({ role: 'system', content: props.systemPrompt });
|
|
169
|
+
return base;
|
|
170
|
+
}
|
|
171
|
+
function providerIdForModel(model) {
|
|
172
|
+
// Light heuristic so StatusBar has a hint without importing dispatch.
|
|
173
|
+
// Real routing still lives in providers/dispatch.ts at run time.
|
|
174
|
+
if (model.includes('claude'))
|
|
175
|
+
return 'anthropic';
|
|
176
|
+
if (model.includes('gpt') || model.startsWith('o1') || model.startsWith('o3'))
|
|
177
|
+
return 'openai';
|
|
178
|
+
if (model.includes('gemini'))
|
|
179
|
+
return 'gemini';
|
|
180
|
+
if (model.includes('kimi') || model.includes('moonshot'))
|
|
181
|
+
return 'nvidia';
|
|
182
|
+
if (model.includes('llama') || model.includes('nvidia') || model.includes('minimax'))
|
|
183
|
+
return 'nvidia';
|
|
184
|
+
if (model.includes('fireworks'))
|
|
185
|
+
return 'fireworks';
|
|
186
|
+
if (model.includes('/'))
|
|
187
|
+
return 'openrouter';
|
|
188
|
+
return 'local';
|
|
189
|
+
}
|
|
190
|
+
function defaultModelCatalogue() {
|
|
191
|
+
return PRICES.map(p => ({
|
|
192
|
+
id: p.model,
|
|
193
|
+
provider: p.provider,
|
|
194
|
+
tier: tierFromPrice(p.inputPerM),
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
function tierFromPrice(inputPerM) {
|
|
198
|
+
if (inputPerM === 0)
|
|
199
|
+
return 'free';
|
|
200
|
+
if (inputPerM < 0.5)
|
|
201
|
+
return 'basic';
|
|
202
|
+
if (inputPerM < 5)
|
|
203
|
+
return 'pro';
|
|
204
|
+
return 'premium';
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=App.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dropdown shown below the InputBox while the user is typing an
|
|
3
|
+
* `@…` file reference. The list is fuzzy-matched against a cached
|
|
4
|
+
* snapshot of the working tree (walked once on first open).
|
|
5
|
+
*
|
|
6
|
+
* Contract with App/InputBox:
|
|
7
|
+
* - Parent renders this component when `query !== null`.
|
|
8
|
+
* - Parent extracts the query token itself (substring after last `@`).
|
|
9
|
+
* - Parent calls `onPick(path)` to splice the chosen path back into
|
|
10
|
+
* the input buffer, replacing the `@query` segment.
|
|
11
|
+
* - Parent calls `onCancel()` on Esc.
|
|
12
|
+
*
|
|
13
|
+
* Matching: a simple subsequence filter — every character of the
|
|
14
|
+
* query must appear in the candidate in order, case-insensitive.
|
|
15
|
+
* Score = negative distance between matched positions, so tight
|
|
16
|
+
* matches float to the top.
|
|
17
|
+
*/
|
|
18
|
+
import * as React from 'react';
|
|
19
|
+
export interface AtFileCompleteProps {
|
|
20
|
+
cwd: string;
|
|
21
|
+
query: string;
|
|
22
|
+
onPick: (path: string) => void;
|
|
23
|
+
onCancel: () => void;
|
|
24
|
+
}
|
|
25
|
+
export declare function AtFileComplete(props: AtFileCompleteProps): React.JSX.Element;
|