@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,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slash command registry used by the interactive REPL. Handlers receive
|
|
3
|
+
* a parsed command plus an ambient session context; they return a
|
|
4
|
+
* string that the REPL prints, or nothing when the handler produced
|
|
5
|
+
* output directly.
|
|
6
|
+
*/
|
|
7
|
+
import type { Token } from '../integrations/device-auth.js';
|
|
8
|
+
import type { Mode } from '../context/mode.js';
|
|
9
|
+
import type { ThemeName } from '../tui/theme.js';
|
|
10
|
+
import type { Session, SessionStore } from '../context/session.js';
|
|
11
|
+
import type { Provider } from '../kernel/types.js';
|
|
12
|
+
export interface SlashContext {
|
|
13
|
+
model: string;
|
|
14
|
+
sessionId: string;
|
|
15
|
+
setModel(model: string): void;
|
|
16
|
+
showHelp(): string;
|
|
17
|
+
compact(): Promise<string>;
|
|
18
|
+
clear(): void;
|
|
19
|
+
listSessions(): Promise<string>;
|
|
20
|
+
loadSession(id: string): Promise<string>;
|
|
21
|
+
listSkills(): Promise<string>;
|
|
22
|
+
showCost(): string;
|
|
23
|
+
exit(code?: number): void;
|
|
24
|
+
/** Currently cached auth token (null when signed out). */
|
|
25
|
+
getToken(): Token | null;
|
|
26
|
+
/** Swap the cached token — slash commands call this after login/logout. */
|
|
27
|
+
setToken(token: Token | null): void;
|
|
28
|
+
/** API base URL (gateway) used by billing + entitlements. */
|
|
29
|
+
apiBase(): string;
|
|
30
|
+
/** URL the `/upgrade` command should send users to. */
|
|
31
|
+
upgradeUrl(): string;
|
|
32
|
+
/** Emit a transient status line above the next prompt. */
|
|
33
|
+
status(message: string): void;
|
|
34
|
+
/** Active execution mode (plan / act / verify). */
|
|
35
|
+
getMode(): Mode;
|
|
36
|
+
/** Swap the mode live — the next turn's system prompt picks it up. */
|
|
37
|
+
setMode(mode: Mode): void;
|
|
38
|
+
/** Current theme name. */
|
|
39
|
+
getTheme(): ThemeName;
|
|
40
|
+
/** Swap the theme — readline REPL applies live; Ink requires restart. */
|
|
41
|
+
setTheme(name: ThemeName): void;
|
|
42
|
+
/** Active session (null in headless contexts). */
|
|
43
|
+
getSession(): Session | null;
|
|
44
|
+
/** Session store for creating branches / loading siblings. */
|
|
45
|
+
getSessionStore(): SessionStore | null;
|
|
46
|
+
/** Provider bound to the current model — used by /session branch. */
|
|
47
|
+
getProvider(): Provider | null;
|
|
48
|
+
/** Model used for background summaries (e.g. branch summarisation). */
|
|
49
|
+
getSummaryModel(): string;
|
|
50
|
+
}
|
|
51
|
+
export type SlashHandler = (args: string[], ctx: SlashContext) => Promise<string | undefined> | string | undefined;
|
|
52
|
+
export declare class SlashRegistry {
|
|
53
|
+
private readonly handlers;
|
|
54
|
+
register(name: string, handler: SlashHandler): void;
|
|
55
|
+
has(name: string): boolean;
|
|
56
|
+
names(): string[];
|
|
57
|
+
dispatch(line: string, ctx: SlashContext): Promise<{
|
|
58
|
+
handled: boolean;
|
|
59
|
+
output?: string;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
export declare function createDefaultSlashRegistry(): SlashRegistry;
|
|
63
|
+
/**
|
|
64
|
+
* Register the 20 built-in slash commands onto an existing registry.
|
|
65
|
+
* Skips names already claimed by core primitives so /help / /exit /
|
|
66
|
+
* /clear etc keep their simple inline handlers.
|
|
67
|
+
*
|
|
68
|
+
* Call site: `interactive.ts` after `createDefaultSlashRegistry()`.
|
|
69
|
+
* Kept separate from `createDefaultSlashRegistry` so the core primitives
|
|
70
|
+
* stay importable without dragging in the full command set.
|
|
71
|
+
*/
|
|
72
|
+
export declare function registerBuiltinSlashCommands(registry: SlashRegistry): Promise<void>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slash command registry used by the interactive REPL. Handlers receive
|
|
3
|
+
* a parsed command plus an ambient session context; they return a
|
|
4
|
+
* string that the REPL prints, or nothing when the handler produced
|
|
5
|
+
* output directly.
|
|
6
|
+
*/
|
|
7
|
+
export class SlashRegistry {
|
|
8
|
+
handlers = new Map();
|
|
9
|
+
register(name, handler) {
|
|
10
|
+
this.handlers.set(name, handler);
|
|
11
|
+
}
|
|
12
|
+
has(name) {
|
|
13
|
+
return this.handlers.has(name);
|
|
14
|
+
}
|
|
15
|
+
names() {
|
|
16
|
+
return [...this.handlers.keys()].sort();
|
|
17
|
+
}
|
|
18
|
+
async dispatch(line, ctx) {
|
|
19
|
+
if (!line.startsWith('/'))
|
|
20
|
+
return { handled: false };
|
|
21
|
+
const stripped = line.slice(1).trim();
|
|
22
|
+
if (stripped.length === 0)
|
|
23
|
+
return { handled: false };
|
|
24
|
+
const [name, ...args] = stripped.split(/\s+/);
|
|
25
|
+
const handler = this.handlers.get(name);
|
|
26
|
+
if (!handler)
|
|
27
|
+
return { handled: true, output: `Unknown slash command: /${name}. Try /help.` };
|
|
28
|
+
const output = await handler(args, ctx);
|
|
29
|
+
return { handled: true, output };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function createDefaultSlashRegistry() {
|
|
33
|
+
const registry = new SlashRegistry();
|
|
34
|
+
// Core readline-REPL primitives
|
|
35
|
+
registry.register('help', (_, ctx) => ctx.showHelp());
|
|
36
|
+
registry.register('exit', (_, ctx) => { ctx.exit(0); return undefined; });
|
|
37
|
+
registry.register('quit', (_, ctx) => { ctx.exit(0); return undefined; });
|
|
38
|
+
registry.register('clear', (_, ctx) => { ctx.clear(); return undefined; });
|
|
39
|
+
registry.register('model', (args, ctx) => {
|
|
40
|
+
if (args.length === 0)
|
|
41
|
+
return `Current model: ${ctx.model}`;
|
|
42
|
+
ctx.setModel(args[0]);
|
|
43
|
+
return `Model set to ${args[0]}`;
|
|
44
|
+
});
|
|
45
|
+
registry.register('compact', (_, ctx) => ctx.compact());
|
|
46
|
+
registry.register('session', async (args, ctx) => {
|
|
47
|
+
if (args[0] === 'list')
|
|
48
|
+
return ctx.listSessions();
|
|
49
|
+
if (args[0] === 'load' && args[1])
|
|
50
|
+
return ctx.loadSession(args[1]);
|
|
51
|
+
return 'Usage: /session list | /session load <id>';
|
|
52
|
+
});
|
|
53
|
+
registry.register('skills', (_, ctx) => ctx.listSkills());
|
|
54
|
+
registry.register('cost', (_, ctx) => ctx.showCost());
|
|
55
|
+
return registry;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Register the 20 built-in slash commands onto an existing registry.
|
|
59
|
+
* Skips names already claimed by core primitives so /help / /exit /
|
|
60
|
+
* /clear etc keep their simple inline handlers.
|
|
61
|
+
*
|
|
62
|
+
* Call site: `interactive.ts` after `createDefaultSlashRegistry()`.
|
|
63
|
+
* Kept separate from `createDefaultSlashRegistry` so the core primitives
|
|
64
|
+
* stay importable without dragging in the full command set.
|
|
65
|
+
*/
|
|
66
|
+
export async function registerBuiltinSlashCommands(registry) {
|
|
67
|
+
const { builtinSlashCommands } = await import('./slash/index.js');
|
|
68
|
+
for (const cmd of builtinSlashCommands) {
|
|
69
|
+
if (!registry.has(cmd.name))
|
|
70
|
+
registry.register(cmd.name, cmd.execute);
|
|
71
|
+
for (const alias of cmd.aliases ?? []) {
|
|
72
|
+
if (!registry.has(alias))
|
|
73
|
+
registry.register(alias, cmd.execute);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=slash.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha ask "prompt"` — headless one-shot with tools.
|
|
3
|
+
*
|
|
4
|
+
* Semantically equivalent to passing a bare positional prompt to
|
|
5
|
+
* `dirgha` on the command line (handled in main.ts), but spelled
|
|
6
|
+
* explicitly so scripts can be self-documenting and unambiguous. We
|
|
7
|
+
* default `--max-turns` to 30 (v1 parity) and forward everything else
|
|
8
|
+
* through the main agent path.
|
|
9
|
+
*
|
|
10
|
+
* Implementation mirrors main.ts's non-interactive branch — we don't
|
|
11
|
+
* delegate to it because that path lives inside a top-level async
|
|
12
|
+
* `main()` with early exits, which makes it awkward to reuse as a
|
|
13
|
+
* function. Keeping the one-shot pipeline here keeps the subcommand
|
|
14
|
+
* composable and testable.
|
|
15
|
+
*/
|
|
16
|
+
import type { Subcommand } from './index.js';
|
|
17
|
+
export declare const askSubcommand: Subcommand;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha ask "prompt"` — headless one-shot with tools.
|
|
3
|
+
*
|
|
4
|
+
* Semantically equivalent to passing a bare positional prompt to
|
|
5
|
+
* `dirgha` on the command line (handled in main.ts), but spelled
|
|
6
|
+
* explicitly so scripts can be self-documenting and unambiguous. We
|
|
7
|
+
* default `--max-turns` to 30 (v1 parity) and forward everything else
|
|
8
|
+
* through the main agent path.
|
|
9
|
+
*
|
|
10
|
+
* Implementation mirrors main.ts's non-interactive branch — we don't
|
|
11
|
+
* delegate to it because that path lives inside a top-level async
|
|
12
|
+
* `main()` with early exits, which makes it awkward to reuse as a
|
|
13
|
+
* function. Keeping the one-shot pipeline here keeps the subcommand
|
|
14
|
+
* composable and testable.
|
|
15
|
+
*/
|
|
16
|
+
import { stdout, stderr } from 'node:process';
|
|
17
|
+
import { randomUUID } from 'node:crypto';
|
|
18
|
+
import { parseFlags } from '../flags.js';
|
|
19
|
+
import { loadConfig } from '../config.js';
|
|
20
|
+
import { ProviderRegistry } from '../../providers/index.js';
|
|
21
|
+
import { builtInTools, createToolExecutor, createToolRegistry } from '../../tools/index.js';
|
|
22
|
+
import { createEventStream } from '../../kernel/event-stream.js';
|
|
23
|
+
import { runAgentLoop } from '../../kernel/agent-loop.js';
|
|
24
|
+
import { renderStreamingEvents } from '../../tui/renderer.js';
|
|
25
|
+
const DEFAULT_ASK_MAX_TURNS = 30;
|
|
26
|
+
export const askSubcommand = {
|
|
27
|
+
name: 'ask',
|
|
28
|
+
description: 'Headless one-shot agent (with tools, --max-turns 30 default)',
|
|
29
|
+
async run(argv, ctx) {
|
|
30
|
+
const { flags, positionals } = parseFlags(argv);
|
|
31
|
+
const prompt = positionals.join(' ').trim();
|
|
32
|
+
if (!prompt) {
|
|
33
|
+
stderr.write('usage: dirgha ask "your prompt" [-m <model>] [-s <system>] [--max-turns N] [--json]\n');
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
const config = await loadConfig(ctx.cwd);
|
|
37
|
+
const model = typeof flags.model === 'string' ? flags.model
|
|
38
|
+
: typeof flags.m === 'string' ? flags.m
|
|
39
|
+
: config.model;
|
|
40
|
+
const system = typeof flags.system === 'string' ? flags.system
|
|
41
|
+
: typeof flags.s === 'string' ? flags.s
|
|
42
|
+
: undefined;
|
|
43
|
+
const maxTurns = typeof flags['max-turns'] === 'string'
|
|
44
|
+
? Number.parseInt(flags['max-turns'], 10)
|
|
45
|
+
: DEFAULT_ASK_MAX_TURNS;
|
|
46
|
+
const json = flags.json === true;
|
|
47
|
+
const providers = new ProviderRegistry();
|
|
48
|
+
const registry = createToolRegistry(builtInTools);
|
|
49
|
+
const sessionId = randomUUID();
|
|
50
|
+
const events = createEventStream();
|
|
51
|
+
if (json)
|
|
52
|
+
events.subscribe(ev => { stdout.write(`${JSON.stringify(ev)}\n`); });
|
|
53
|
+
else
|
|
54
|
+
events.subscribe(renderStreamingEvents({ showThinking: config.showThinking }));
|
|
55
|
+
const executor = createToolExecutor({ registry, cwd: ctx.cwd, sessionId });
|
|
56
|
+
const sanitized = registry.sanitize({ descriptionLimit: 200 });
|
|
57
|
+
const messages = [];
|
|
58
|
+
if (system)
|
|
59
|
+
messages.push({ role: 'system', content: system });
|
|
60
|
+
messages.push({ role: 'user', content: prompt });
|
|
61
|
+
const result = await runAgentLoop({
|
|
62
|
+
sessionId,
|
|
63
|
+
model,
|
|
64
|
+
messages,
|
|
65
|
+
tools: sanitized.definitions,
|
|
66
|
+
maxTurns,
|
|
67
|
+
provider: providers.forModel(model),
|
|
68
|
+
toolExecutor: executor,
|
|
69
|
+
events,
|
|
70
|
+
});
|
|
71
|
+
if (!json)
|
|
72
|
+
stdout.write('\n');
|
|
73
|
+
return result.stopReason === 'error' ? 2 : 0;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=ask.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha audit` — read the local audit log.
|
|
3
|
+
*
|
|
4
|
+
* The audit log lives at `~/.dirgha/audit/events.jsonl` (append-only
|
|
5
|
+
* JSONL). Other parts of the CLI (tool approval, destructive actions,
|
|
6
|
+
* auth) are expected to append records here; this command is read-only.
|
|
7
|
+
*
|
|
8
|
+
* Subcommands:
|
|
9
|
+
* list [N] Show the last N entries (default 20).
|
|
10
|
+
* tail Follow the log (blocks, prints new entries live).
|
|
11
|
+
* search <query> Print entries whose JSON includes `query`.
|
|
12
|
+
* `--json` emits structured output instead of the table renderer.
|
|
13
|
+
*/
|
|
14
|
+
import type { Subcommand } from './index.js';
|
|
15
|
+
export declare const auditSubcommand: Subcommand;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha audit` — read the local audit log.
|
|
3
|
+
*
|
|
4
|
+
* The audit log lives at `~/.dirgha/audit/events.jsonl` (append-only
|
|
5
|
+
* JSONL). Other parts of the CLI (tool approval, destructive actions,
|
|
6
|
+
* auth) are expected to append records here; this command is read-only.
|
|
7
|
+
*
|
|
8
|
+
* Subcommands:
|
|
9
|
+
* list [N] Show the last N entries (default 20).
|
|
10
|
+
* tail Follow the log (blocks, prints new entries live).
|
|
11
|
+
* search <query> Print entries whose JSON includes `query`.
|
|
12
|
+
* `--json` emits structured output instead of the table renderer.
|
|
13
|
+
*/
|
|
14
|
+
import { mkdir, readFile, stat } from 'node:fs/promises';
|
|
15
|
+
import { watch } from 'node:fs';
|
|
16
|
+
import { homedir } from 'node:os';
|
|
17
|
+
import { join } from 'node:path';
|
|
18
|
+
import { stdout, stderr } from 'node:process';
|
|
19
|
+
import { style, defaultTheme } from '../../tui/theme.js';
|
|
20
|
+
function auditDir() { return join(homedir(), '.dirgha', 'audit'); }
|
|
21
|
+
function auditPath() { return join(auditDir(), 'events.jsonl'); }
|
|
22
|
+
async function ensureLog() {
|
|
23
|
+
await mkdir(auditDir(), { recursive: true });
|
|
24
|
+
}
|
|
25
|
+
async function readEntries() {
|
|
26
|
+
await ensureLog();
|
|
27
|
+
const text = await readFile(auditPath(), 'utf8').catch(() => '');
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const line of text.split('\n')) {
|
|
30
|
+
if (!line.trim())
|
|
31
|
+
continue;
|
|
32
|
+
try {
|
|
33
|
+
out.push(JSON.parse(line));
|
|
34
|
+
}
|
|
35
|
+
catch { /* skip malformed */ }
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
function formatEntry(entry) {
|
|
40
|
+
const ts = String(entry.ts ?? '').slice(0, 19);
|
|
41
|
+
const kind = String(entry.kind ?? 'event').padEnd(14);
|
|
42
|
+
const actor = entry.actor ? ` ${style(defaultTheme.muted, `(${String(entry.actor)})`)}` : '';
|
|
43
|
+
const summary = entry.summary ? String(entry.summary) : JSON.stringify({ ...entry, ts: undefined, kind: undefined });
|
|
44
|
+
return `${style(defaultTheme.muted, ts)} ${style(defaultTheme.accent, kind)}${actor} ${summary}`;
|
|
45
|
+
}
|
|
46
|
+
function emit(entries, json) {
|
|
47
|
+
if (json) {
|
|
48
|
+
for (const e of entries)
|
|
49
|
+
stdout.write(`${JSON.stringify(e)}\n`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (entries.length === 0) {
|
|
53
|
+
stdout.write(style(defaultTheme.muted, '(no audit entries yet)\n'));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
for (const e of entries)
|
|
57
|
+
stdout.write(`${formatEntry(e)}\n`);
|
|
58
|
+
}
|
|
59
|
+
function usage() {
|
|
60
|
+
return [
|
|
61
|
+
'usage:',
|
|
62
|
+
' dirgha audit list [N] Last N entries (default 20)',
|
|
63
|
+
' dirgha audit tail Follow the log',
|
|
64
|
+
' dirgha audit search <q> Entries containing q',
|
|
65
|
+
' dirgha audit [--json] JSON output',
|
|
66
|
+
].join('\n');
|
|
67
|
+
}
|
|
68
|
+
async function runTail(json) {
|
|
69
|
+
await ensureLog();
|
|
70
|
+
const path = auditPath();
|
|
71
|
+
const initial = await readEntries();
|
|
72
|
+
emit(initial.slice(-20), json);
|
|
73
|
+
let lastSize = (await stat(path).catch(() => undefined))?.size ?? 0;
|
|
74
|
+
stderr.write(style(defaultTheme.muted, '\n(following — Ctrl-C to stop)\n'));
|
|
75
|
+
return new Promise(resolve => {
|
|
76
|
+
const watcher = watch(path, { persistent: true }, async () => {
|
|
77
|
+
const st = await stat(path).catch(() => undefined);
|
|
78
|
+
if (!st || st.size <= lastSize)
|
|
79
|
+
return;
|
|
80
|
+
const fh = await readFile(path, 'utf8').catch(() => '');
|
|
81
|
+
const newText = fh.slice(lastSize);
|
|
82
|
+
lastSize = st.size;
|
|
83
|
+
for (const line of newText.split('\n')) {
|
|
84
|
+
if (!line.trim())
|
|
85
|
+
continue;
|
|
86
|
+
try {
|
|
87
|
+
emit([JSON.parse(line)], json);
|
|
88
|
+
}
|
|
89
|
+
catch { /* skip */ }
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
process.on('SIGINT', () => {
|
|
93
|
+
watcher.close();
|
|
94
|
+
resolve(0);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
export const auditSubcommand = {
|
|
99
|
+
name: 'audit',
|
|
100
|
+
description: 'Read the local audit log (list / tail / search)',
|
|
101
|
+
async run(argv) {
|
|
102
|
+
const json = argv.includes('--json');
|
|
103
|
+
const args = argv.filter(a => a !== '--json');
|
|
104
|
+
const op = args[0] ?? 'list';
|
|
105
|
+
if (op === 'list') {
|
|
106
|
+
const n = Number.parseInt(args[1] ?? '20', 10);
|
|
107
|
+
const entries = await readEntries();
|
|
108
|
+
emit(entries.slice(-n), json);
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
if (op === 'tail')
|
|
112
|
+
return runTail(json);
|
|
113
|
+
if (op === 'search') {
|
|
114
|
+
const query = args[1];
|
|
115
|
+
if (!query) {
|
|
116
|
+
stderr.write(`${usage()}\n`);
|
|
117
|
+
return 1;
|
|
118
|
+
}
|
|
119
|
+
const entries = await readEntries();
|
|
120
|
+
const needle = query.toLowerCase();
|
|
121
|
+
emit(entries.filter(e => JSON.stringify(e).toLowerCase().includes(needle)), json);
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
stderr.write(`unknown subcommand "${op}"\n${usage()}\n`);
|
|
125
|
+
return 1;
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=audit.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha chat "prompt"` — pure LLM chat, no tool calls.
|
|
3
|
+
*
|
|
4
|
+
* Skips the agent loop entirely: opens a streaming provider connection,
|
|
5
|
+
* prints text deltas as they arrive, and exits. No tool execution, no
|
|
6
|
+
* session persistence (beyond the transient event prints). Useful for
|
|
7
|
+
* quick Q&A where you explicitly do *not* want the agent touching the
|
|
8
|
+
* filesystem or shelling out.
|
|
9
|
+
*
|
|
10
|
+
* Flags mirror the one-shot path on main.ts: `-m`, `-s`, `--json`.
|
|
11
|
+
*/
|
|
12
|
+
import type { Subcommand } from './index.js';
|
|
13
|
+
export declare const chatSubcommand: Subcommand;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha chat "prompt"` — pure LLM chat, no tool calls.
|
|
3
|
+
*
|
|
4
|
+
* Skips the agent loop entirely: opens a streaming provider connection,
|
|
5
|
+
* prints text deltas as they arrive, and exits. No tool execution, no
|
|
6
|
+
* session persistence (beyond the transient event prints). Useful for
|
|
7
|
+
* quick Q&A where you explicitly do *not* want the agent touching the
|
|
8
|
+
* filesystem or shelling out.
|
|
9
|
+
*
|
|
10
|
+
* Flags mirror the one-shot path on main.ts: `-m`, `-s`, `--json`.
|
|
11
|
+
*/
|
|
12
|
+
import { stdout, stderr } from 'node:process';
|
|
13
|
+
import { parseFlags } from '../flags.js';
|
|
14
|
+
import { loadConfig } from '../config.js';
|
|
15
|
+
import { ProviderRegistry } from '../../providers/index.js';
|
|
16
|
+
async function consume(stream, json) {
|
|
17
|
+
for await (const ev of stream) {
|
|
18
|
+
if (json) {
|
|
19
|
+
stdout.write(`${JSON.stringify(ev)}\n`);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (ev.type === 'text_delta')
|
|
23
|
+
stdout.write(ev.delta);
|
|
24
|
+
else if (ev.type === 'text_end')
|
|
25
|
+
stdout.write('');
|
|
26
|
+
else if (ev.type === 'turn_end')
|
|
27
|
+
stdout.write('\n');
|
|
28
|
+
else if (ev.type === 'error')
|
|
29
|
+
stderr.write(`\nerror: ${ev.message}\n`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export const chatSubcommand = {
|
|
33
|
+
name: 'chat',
|
|
34
|
+
description: 'Pure chat turn (no tools) — one-shot LLM call',
|
|
35
|
+
async run(argv, ctx) {
|
|
36
|
+
const { flags, positionals } = parseFlags(argv);
|
|
37
|
+
const prompt = positionals.join(' ').trim();
|
|
38
|
+
if (!prompt) {
|
|
39
|
+
stderr.write('usage: dirgha chat "your prompt" [-m <model>] [-s <system>] [--json]\n');
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
const config = await loadConfig(ctx.cwd);
|
|
43
|
+
const model = typeof flags.model === 'string' ? flags.model
|
|
44
|
+
: typeof flags.m === 'string' ? flags.m
|
|
45
|
+
: config.model;
|
|
46
|
+
const system = typeof flags.system === 'string' ? flags.system
|
|
47
|
+
: typeof flags.s === 'string' ? flags.s
|
|
48
|
+
: undefined;
|
|
49
|
+
const tempRaw = typeof flags.temperature === 'string' ? flags.temperature
|
|
50
|
+
: typeof flags.t === 'string' ? flags.t
|
|
51
|
+
: undefined;
|
|
52
|
+
const tempParsed = tempRaw !== undefined ? Number.parseFloat(tempRaw) : Number.NaN;
|
|
53
|
+
const temperature = Number.isFinite(tempParsed) ? tempParsed : undefined;
|
|
54
|
+
const json = flags.json === true;
|
|
55
|
+
const providers = new ProviderRegistry();
|
|
56
|
+
const provider = providers.forModel(model);
|
|
57
|
+
const messages = [];
|
|
58
|
+
if (system)
|
|
59
|
+
messages.push({ role: 'system', content: system });
|
|
60
|
+
messages.push({ role: 'user', content: prompt });
|
|
61
|
+
try {
|
|
62
|
+
const stream = provider.stream({ model, messages, temperature });
|
|
63
|
+
await consume(stream, json);
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
stderr.write(`\nfatal: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
68
|
+
return 2;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=chat.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha compact [sessionId]` — force-compact a session on disk.
|
|
3
|
+
*
|
|
4
|
+
* Reads the session JSONL, drops intermediate tool-result and thinking
|
|
5
|
+
* parts from older messages, and appends a `compaction` entry that
|
|
6
|
+
* records the rough token savings. The in-repl compaction pass is
|
|
7
|
+
* richer (LLM summarisation), but this is intentionally offline: safe
|
|
8
|
+
* to run without any provider access.
|
|
9
|
+
*
|
|
10
|
+
* When `sessionId` is omitted we pick the most recently modified
|
|
11
|
+
* session in `~/.dirgha/sessions/`.
|
|
12
|
+
*/
|
|
13
|
+
import type { Subcommand } from './index.js';
|
|
14
|
+
export declare const compactSubcommand: Subcommand;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha compact [sessionId]` — force-compact a session on disk.
|
|
3
|
+
*
|
|
4
|
+
* Reads the session JSONL, drops intermediate tool-result and thinking
|
|
5
|
+
* parts from older messages, and appends a `compaction` entry that
|
|
6
|
+
* records the rough token savings. The in-repl compaction pass is
|
|
7
|
+
* richer (LLM summarisation), but this is intentionally offline: safe
|
|
8
|
+
* to run without any provider access.
|
|
9
|
+
*
|
|
10
|
+
* When `sessionId` is omitted we pick the most recently modified
|
|
11
|
+
* session in `~/.dirgha/sessions/`.
|
|
12
|
+
*/
|
|
13
|
+
import { readdir, stat } from 'node:fs/promises';
|
|
14
|
+
import { homedir } from 'node:os';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
import { stdout, stderr } from 'node:process';
|
|
17
|
+
import { createSessionStore } from '../../context/session.js';
|
|
18
|
+
import { style, defaultTheme } from '../../tui/theme.js';
|
|
19
|
+
function estimateTokens(entry) {
|
|
20
|
+
if (entry.type !== 'message')
|
|
21
|
+
return 0;
|
|
22
|
+
const text = typeof entry.message.content === 'string'
|
|
23
|
+
? entry.message.content
|
|
24
|
+
: entry.message.content.map(partText).join('');
|
|
25
|
+
return Math.ceil(text.length / 4);
|
|
26
|
+
}
|
|
27
|
+
function partText(part) {
|
|
28
|
+
if (part.type === 'text' || part.type === 'thinking')
|
|
29
|
+
return part.text;
|
|
30
|
+
if (part.type === 'tool_result')
|
|
31
|
+
return part.content;
|
|
32
|
+
return JSON.stringify(part);
|
|
33
|
+
}
|
|
34
|
+
function compactMessage(message, olderThanIdx, myIdx) {
|
|
35
|
+
// Strip verbose tool_result/thinking content from older messages.
|
|
36
|
+
if (myIdx >= olderThanIdx)
|
|
37
|
+
return message;
|
|
38
|
+
if (typeof message.content === 'string')
|
|
39
|
+
return message;
|
|
40
|
+
const pruned = message.content.map(part => {
|
|
41
|
+
if (part.type === 'thinking')
|
|
42
|
+
return { type: 'text', text: '[thinking elided]' };
|
|
43
|
+
if (part.type === 'tool_result') {
|
|
44
|
+
const trimmed = part.content.length > 200 ? `${part.content.slice(0, 200)}… [elided]` : part.content;
|
|
45
|
+
return { type: 'tool_result', toolUseId: part.toolUseId, content: trimmed, isError: part.isError };
|
|
46
|
+
}
|
|
47
|
+
return part;
|
|
48
|
+
});
|
|
49
|
+
return { ...message, content: pruned };
|
|
50
|
+
}
|
|
51
|
+
async function mostRecentSession() {
|
|
52
|
+
const dir = join(homedir(), '.dirgha', 'sessions');
|
|
53
|
+
const files = await readdir(dir).catch(() => []);
|
|
54
|
+
let best;
|
|
55
|
+
for (const file of files) {
|
|
56
|
+
if (!file.endsWith('.jsonl'))
|
|
57
|
+
continue;
|
|
58
|
+
const info = await stat(join(dir, file)).catch(() => undefined);
|
|
59
|
+
if (!info)
|
|
60
|
+
continue;
|
|
61
|
+
if (!best || info.mtimeMs > best.mtime)
|
|
62
|
+
best = { id: file.replace(/\.jsonl$/, ''), mtime: info.mtimeMs };
|
|
63
|
+
}
|
|
64
|
+
return best?.id;
|
|
65
|
+
}
|
|
66
|
+
export const compactSubcommand = {
|
|
67
|
+
name: 'compact',
|
|
68
|
+
description: 'Force-compact a session on disk (token savings summary)',
|
|
69
|
+
async run(argv) {
|
|
70
|
+
const sessionId = argv[0] ?? await mostRecentSession();
|
|
71
|
+
if (!sessionId) {
|
|
72
|
+
stderr.write('no sessions found\n');
|
|
73
|
+
return 1;
|
|
74
|
+
}
|
|
75
|
+
const store = createSessionStore();
|
|
76
|
+
const session = await store.open(sessionId);
|
|
77
|
+
if (!session) {
|
|
78
|
+
stderr.write(`session "${sessionId}" not found\n`);
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
const entries = [];
|
|
82
|
+
for await (const entry of session.replay())
|
|
83
|
+
entries.push(entry);
|
|
84
|
+
const beforeTokens = entries.reduce((sum, e) => sum + estimateTokens(e), 0);
|
|
85
|
+
const messageIndices = [];
|
|
86
|
+
entries.forEach((e, i) => { if (e.type === 'message')
|
|
87
|
+
messageIndices.push(i); });
|
|
88
|
+
// Keep the last 6 messages intact; elide older ones.
|
|
89
|
+
const keepFrom = messageIndices.length > 6 ? messageIndices[messageIndices.length - 6] : 0;
|
|
90
|
+
let afterTokens = 0;
|
|
91
|
+
for (let i = 0; i < entries.length; i++) {
|
|
92
|
+
const entry = entries[i];
|
|
93
|
+
if (entry.type === 'message') {
|
|
94
|
+
const pruned = compactMessage(entry.message, keepFrom, i);
|
|
95
|
+
entries[i] = { ...entry, message: pruned };
|
|
96
|
+
}
|
|
97
|
+
afterTokens += estimateTokens(entries[i]);
|
|
98
|
+
}
|
|
99
|
+
const saved = Math.max(0, beforeTokens - afterTokens);
|
|
100
|
+
await session.append({
|
|
101
|
+
type: 'compaction',
|
|
102
|
+
ts: new Date().toISOString(),
|
|
103
|
+
keptFrom: String(keepFrom),
|
|
104
|
+
summary: `offline compact: ${saved} tokens elided`,
|
|
105
|
+
});
|
|
106
|
+
stdout.write(`${style(defaultTheme.success, '✓')} compacted ${sessionId}\n`);
|
|
107
|
+
stdout.write(` before ~${beforeTokens} tokens\n`);
|
|
108
|
+
stdout.write(` after ~${afterTokens} tokens\n`);
|
|
109
|
+
const pct = beforeTokens > 0 ? Math.round((saved / beforeTokens) * 100) : 0;
|
|
110
|
+
stdout.write(` saved ~${saved} (${pct}%)\n`);
|
|
111
|
+
return 0;
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=compact.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha doctor` — environment diagnostics.
|
|
3
|
+
*
|
|
4
|
+
* Checks Node version (≥ 20), that cwd is a git repo, that `~/.dirgha/`
|
|
5
|
+
* exists and is writable, which provider env vars are set, and whether
|
|
6
|
+
* each configured provider's base endpoint is reachable (HEAD/GET with a
|
|
7
|
+
* 3 s timeout). Prints a table by default; emits NDJSON when `--json`
|
|
8
|
+
* is passed. Exit code 0 when every check passes, 1 if any fails.
|
|
9
|
+
*/
|
|
10
|
+
import type { Subcommand } from './index.js';
|
|
11
|
+
export declare const doctorSubcommand: Subcommand;
|