@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,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha logout` — clear the cached credentials.
|
|
3
|
+
*
|
|
4
|
+
* Calls `clearToken()` (unlinks `~/.dirgha/credentials.json`) and
|
|
5
|
+
* prints a single confirmation line. Always exits 0, even when no
|
|
6
|
+
* token exists — idempotent sign-out matches curl/gh conventions.
|
|
7
|
+
*/
|
|
8
|
+
import { stdout } from 'node:process';
|
|
9
|
+
import { clearToken } from '../../integrations/device-auth.js';
|
|
10
|
+
import { defaultTheme, style } from '../../tui/theme.js';
|
|
11
|
+
export async function runLogout(_argv) {
|
|
12
|
+
await clearToken();
|
|
13
|
+
stdout.write(`${style(defaultTheme.success, 'Signed out.')}\n`);
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
export const logoutSubcommand = {
|
|
17
|
+
name: 'logout',
|
|
18
|
+
description: 'Clear cached credentials',
|
|
19
|
+
async run(argv) { return runLogout(argv); },
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=logout.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha models <list|default|info>` — richer model management.
|
|
3
|
+
*
|
|
4
|
+
* list Table of every model in the catalogue.
|
|
5
|
+
* default [modelId] Print the current default, or persist
|
|
6
|
+
* `modelId` into ~/.dirgha/config.json.
|
|
7
|
+
* info <modelId> Pricing + provider + rough context
|
|
8
|
+
* window for a single model.
|
|
9
|
+
*
|
|
10
|
+
* Complements the simpler `dirgha models` already implemented in
|
|
11
|
+
* `models-cmd.ts`; this subcommand supersedes it via the dispatcher.
|
|
12
|
+
*/
|
|
13
|
+
import type { Subcommand } from './index.js';
|
|
14
|
+
export declare const modelsSubcommand: Subcommand;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha models <list|default|info>` — richer model management.
|
|
3
|
+
*
|
|
4
|
+
* list Table of every model in the catalogue.
|
|
5
|
+
* default [modelId] Print the current default, or persist
|
|
6
|
+
* `modelId` into ~/.dirgha/config.json.
|
|
7
|
+
* info <modelId> Pricing + provider + rough context
|
|
8
|
+
* window for a single model.
|
|
9
|
+
*
|
|
10
|
+
* Complements the simpler `dirgha models` already implemented in
|
|
11
|
+
* `models-cmd.ts`; this subcommand supersedes it via the dispatcher.
|
|
12
|
+
*/
|
|
13
|
+
import { mkdir, readFile, writeFile } 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 { PRICES } from '../../intelligence/prices.js';
|
|
18
|
+
import { style, defaultTheme } from '../../tui/theme.js';
|
|
19
|
+
const PROVIDER_ENV = {
|
|
20
|
+
anthropic: 'ANTHROPIC_API_KEY',
|
|
21
|
+
openai: 'OPENAI_API_KEY',
|
|
22
|
+
gemini: 'GEMINI_API_KEY',
|
|
23
|
+
nvidia: 'NVIDIA_API_KEY',
|
|
24
|
+
openrouter: 'OPENROUTER_API_KEY',
|
|
25
|
+
ollama: '',
|
|
26
|
+
};
|
|
27
|
+
function configPath() {
|
|
28
|
+
return join(homedir(), '.dirgha', 'config.json');
|
|
29
|
+
}
|
|
30
|
+
async function readConfig() {
|
|
31
|
+
const text = await readFile(configPath(), 'utf8').catch(() => '');
|
|
32
|
+
if (!text)
|
|
33
|
+
return {};
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(text);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function writeConfig(cfg) {
|
|
42
|
+
await mkdir(join(homedir(), '.dirgha'), { recursive: true });
|
|
43
|
+
await writeFile(configPath(), JSON.stringify(cfg, null, 2) + '\n', 'utf8');
|
|
44
|
+
}
|
|
45
|
+
function configured(provider) {
|
|
46
|
+
const env = PROVIDER_ENV[provider];
|
|
47
|
+
if (!env)
|
|
48
|
+
return true;
|
|
49
|
+
const raw = process.env[env];
|
|
50
|
+
return Boolean(raw && raw.length > 0);
|
|
51
|
+
}
|
|
52
|
+
function priceText(value) {
|
|
53
|
+
return value === 0 ? 'free' : `$${value.toFixed(2)}/M`;
|
|
54
|
+
}
|
|
55
|
+
function runList() {
|
|
56
|
+
stdout.write(`\n${style(defaultTheme.accent, 'Model catalogue')}\n`);
|
|
57
|
+
const byProvider = new Map();
|
|
58
|
+
for (const row of PRICES) {
|
|
59
|
+
const bucket = byProvider.get(row.provider) ?? [];
|
|
60
|
+
bucket.push(row);
|
|
61
|
+
byProvider.set(row.provider, bucket);
|
|
62
|
+
}
|
|
63
|
+
for (const [provider, rows] of byProvider) {
|
|
64
|
+
const env = PROVIDER_ENV[provider] ?? '';
|
|
65
|
+
const marker = configured(provider)
|
|
66
|
+
? style(defaultTheme.success, 'configured')
|
|
67
|
+
: style(defaultTheme.muted, env ? `set ${env} to enable` : 'no key required');
|
|
68
|
+
stdout.write(`\n${style(defaultTheme.userPrompt, provider)} (${marker})\n`);
|
|
69
|
+
for (const row of rows) {
|
|
70
|
+
stdout.write(` ${row.model.padEnd(44)} in ${priceText(row.inputPerM).padEnd(10)} out ${priceText(row.outputPerM)}\n`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
stdout.write(`\nUse \`dirgha models default <id>\` to persist a new default.\n`);
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
async function runDefault(id) {
|
|
77
|
+
if (!id) {
|
|
78
|
+
const cfg = await readConfig();
|
|
79
|
+
const current = typeof cfg.model === 'string' ? cfg.model : process.env.DIRGHA_MODEL ?? '(using DEFAULT_CONFIG)';
|
|
80
|
+
stdout.write(`${current}\n`);
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
const match = PRICES.find(p => p.model === id);
|
|
84
|
+
if (!match) {
|
|
85
|
+
stderr.write(`${id} is not in the catalogue. Models with no route will still work if the provider accepts it.\n`);
|
|
86
|
+
}
|
|
87
|
+
const cfg = await readConfig();
|
|
88
|
+
cfg.model = id;
|
|
89
|
+
await writeConfig(cfg);
|
|
90
|
+
stdout.write(`${style(defaultTheme.success, '✓')} default model set to ${id}${match ? ` (${match.provider})` : ''}\n`);
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
function runInfo(id) {
|
|
94
|
+
const all = PRICES.filter(p => p.model === id);
|
|
95
|
+
if (all.length === 0) {
|
|
96
|
+
stderr.write(`model "${id}" is not in the catalogue\n`);
|
|
97
|
+
return 1;
|
|
98
|
+
}
|
|
99
|
+
for (const row of all) {
|
|
100
|
+
stdout.write(`\n${style(defaultTheme.accent, row.model)}\n`);
|
|
101
|
+
stdout.write(` provider ${row.provider}\n`);
|
|
102
|
+
stdout.write(` input / M ${priceText(row.inputPerM)}\n`);
|
|
103
|
+
stdout.write(` output / M ${priceText(row.outputPerM)}\n`);
|
|
104
|
+
if (row.cachedInputPerM !== undefined)
|
|
105
|
+
stdout.write(` cached in / M $${row.cachedInputPerM.toFixed(2)}\n`);
|
|
106
|
+
const env = PROVIDER_ENV[row.provider] ?? '';
|
|
107
|
+
const marker = configured(row.provider) ? 'configured' : env ? `set ${env} to enable` : 'no key required';
|
|
108
|
+
stdout.write(` configured? ${marker}\n`);
|
|
109
|
+
}
|
|
110
|
+
stdout.write('\n');
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
function usage() {
|
|
114
|
+
return [
|
|
115
|
+
'usage:',
|
|
116
|
+
' dirgha models list',
|
|
117
|
+
' dirgha models default [modelId]',
|
|
118
|
+
' dirgha models info <modelId>',
|
|
119
|
+
].join('\n');
|
|
120
|
+
}
|
|
121
|
+
export const modelsSubcommand = {
|
|
122
|
+
name: 'models',
|
|
123
|
+
description: 'List, inspect, and set the default model',
|
|
124
|
+
async run(argv) {
|
|
125
|
+
const [op, arg] = argv;
|
|
126
|
+
if (!op || op === 'list')
|
|
127
|
+
return runList();
|
|
128
|
+
if (op === 'default')
|
|
129
|
+
return runDefault(arg);
|
|
130
|
+
if (op === 'info') {
|
|
131
|
+
if (!arg) {
|
|
132
|
+
stderr.write(`${usage()}\n`);
|
|
133
|
+
return 1;
|
|
134
|
+
}
|
|
135
|
+
return runInfo(arg);
|
|
136
|
+
}
|
|
137
|
+
// Single bare model id? treat it as a shorthand for `info <id>`.
|
|
138
|
+
if (!arg && PRICES.some(p => p.model === op))
|
|
139
|
+
return runInfo(op);
|
|
140
|
+
stderr.write(`unknown subcommand "${op}"\n${usage()}\n`);
|
|
141
|
+
return 1;
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha setup` — quick BYOK onboarding.
|
|
3
|
+
*
|
|
4
|
+
* Non-interactive sibling of `cli/setup.ts`. Asks for a preferred
|
|
5
|
+
* provider and optional API keys, then persists them to
|
|
6
|
+
* `~/.dirgha/keys.json` (mode 0600). Falls back to a how-to doc when
|
|
7
|
+
* stdin is not a TTY or `--interactive=false` is passed.
|
|
8
|
+
*/
|
|
9
|
+
import type { Subcommand } from './index.js';
|
|
10
|
+
export declare function runSetup(argv: string[]): Promise<number>;
|
|
11
|
+
export declare const setupSubcommand: Subcommand;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha setup` — quick BYOK onboarding.
|
|
3
|
+
*
|
|
4
|
+
* Non-interactive sibling of `cli/setup.ts`. Asks for a preferred
|
|
5
|
+
* provider and optional API keys, then persists them to
|
|
6
|
+
* `~/.dirgha/keys.json` (mode 0600). Falls back to a how-to doc when
|
|
7
|
+
* stdin is not a TTY or `--interactive=false` is passed.
|
|
8
|
+
*/
|
|
9
|
+
import { stdin, stdout } from 'node:process';
|
|
10
|
+
import { chmod, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
11
|
+
import { createInterface } from 'node:readline';
|
|
12
|
+
import { homedir } from 'node:os';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { defaultTheme, style } from '../../tui/theme.js';
|
|
15
|
+
const PROVIDERS = [
|
|
16
|
+
{ label: 'NVIDIA NIM', env: 'NVIDIA_API_KEY', helpUrl: 'https://build.nvidia.com/settings/api-keys' },
|
|
17
|
+
{ label: 'OpenRouter', env: 'OPENROUTER_API_KEY', helpUrl: 'https://openrouter.ai/keys' },
|
|
18
|
+
{ label: 'Anthropic', env: 'ANTHROPIC_API_KEY', helpUrl: 'https://console.anthropic.com/settings/keys' },
|
|
19
|
+
{ label: 'OpenAI', env: 'OPENAI_API_KEY', helpUrl: 'https://platform.openai.com/api-keys' },
|
|
20
|
+
{ label: 'Gemini', env: 'GEMINI_API_KEY', helpUrl: 'https://aistudio.google.com/apikey' },
|
|
21
|
+
];
|
|
22
|
+
function keysPath() {
|
|
23
|
+
return join(homedir(), '.dirgha', 'keys.json');
|
|
24
|
+
}
|
|
25
|
+
async function readKeys() {
|
|
26
|
+
const text = await readFile(keysPath(), 'utf8').catch(() => '');
|
|
27
|
+
if (!text)
|
|
28
|
+
return {};
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(text);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function writeKeys(store) {
|
|
37
|
+
const path = keysPath();
|
|
38
|
+
await mkdir(join(homedir(), '.dirgha'), { recursive: true });
|
|
39
|
+
await writeFile(path, `${JSON.stringify(store, null, 2)}\n`, 'utf8');
|
|
40
|
+
try {
|
|
41
|
+
await chmod(path, 0o600);
|
|
42
|
+
}
|
|
43
|
+
catch { /* non-POSIX */ }
|
|
44
|
+
}
|
|
45
|
+
function parseInteractiveFlag(argv) {
|
|
46
|
+
for (const a of argv) {
|
|
47
|
+
if (a === '--interactive=false' || a === '--non-interactive')
|
|
48
|
+
return false;
|
|
49
|
+
if (a === '--interactive=true' || a === '--interactive')
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return stdin.isTTY === true;
|
|
53
|
+
}
|
|
54
|
+
function printHowTo() {
|
|
55
|
+
stdout.write(`${style(defaultTheme.accent, '\ndirgha setup')}\n\n`);
|
|
56
|
+
stdout.write(`Non-interactive context detected. Configure BYOK manually:\n\n`);
|
|
57
|
+
for (const p of PROVIDERS) {
|
|
58
|
+
stdout.write(` ${p.label.padEnd(12)} export ${p.env}=<key> (${p.helpUrl})\n`);
|
|
59
|
+
}
|
|
60
|
+
stdout.write(`\nOr edit ${keysPath()} directly:\n`);
|
|
61
|
+
stdout.write(` { "NVIDIA_API_KEY": "nvapi-…", "OPENAI_API_KEY": "sk-…" }\n`);
|
|
62
|
+
stdout.write(`\nTo sign in with a hosted account instead: dirgha login\n`);
|
|
63
|
+
}
|
|
64
|
+
export async function runSetup(argv) {
|
|
65
|
+
const interactive = parseInteractiveFlag(argv);
|
|
66
|
+
if (!interactive) {
|
|
67
|
+
printHowTo();
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
const rl = createInterface({ input: stdin, output: stdout });
|
|
71
|
+
const ask = (q, dflt) => new Promise(resolve => {
|
|
72
|
+
rl.question(`${q}${dflt ? ` [${dflt}]` : ''}: `, ans => resolve(ans.trim() || dflt || ''));
|
|
73
|
+
});
|
|
74
|
+
stdout.write(`${style(defaultTheme.accent, '\ndirgha setup')} — BYOK keys saved to ~/.dirgha/keys.json\n\n`);
|
|
75
|
+
PROVIDERS.forEach((p, i) => { stdout.write(` ${i + 1}. ${p.label}\n`); });
|
|
76
|
+
const pick = await ask('\nPreferred provider (number or name, blank to skip)', '1');
|
|
77
|
+
const store = await readKeys();
|
|
78
|
+
const chosen = PROVIDERS.find((p, i) => `${i + 1}` === pick || p.label.toLowerCase() === pick.toLowerCase() || p.env === pick);
|
|
79
|
+
if (chosen) {
|
|
80
|
+
stdout.write(`\n${chosen.label} — ${chosen.helpUrl}\n`);
|
|
81
|
+
const key = await ask(` ${chosen.env}`);
|
|
82
|
+
if (key)
|
|
83
|
+
store[chosen.env] = key;
|
|
84
|
+
}
|
|
85
|
+
const addMore = (await ask('\nAdd keys for other providers? (y/N)', 'n')).toLowerCase();
|
|
86
|
+
if (addMore === 'y' || addMore === 'yes') {
|
|
87
|
+
for (const p of PROVIDERS) {
|
|
88
|
+
if (chosen && p.env === chosen.env)
|
|
89
|
+
continue;
|
|
90
|
+
const existing = store[p.env];
|
|
91
|
+
const key = await ask(` ${p.env}`, existing ? '<keep>' : '<skip>');
|
|
92
|
+
if (key && key !== '<skip>' && key !== '<keep>')
|
|
93
|
+
store[p.env] = key;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
rl.close();
|
|
97
|
+
await writeKeys(store);
|
|
98
|
+
stdout.write(`${style(defaultTheme.success, '\n✓ Saved.')} Keys stored at ${keysPath()} (0600).\n`);
|
|
99
|
+
stdout.write(`\nTip: sign in with a hosted account for quota + billing → ${style(defaultTheme.accent, 'dirgha login')}\n`);
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
export const setupSubcommand = {
|
|
103
|
+
name: 'setup',
|
|
104
|
+
description: 'Configure BYOK provider keys',
|
|
105
|
+
async run(argv) { return runSetup(argv); },
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha stats` — session + token + cost aggregates.
|
|
3
|
+
*
|
|
4
|
+
* Reads the JSONL session files under `~/.dirgha/sessions/`, walking
|
|
5
|
+
* every `usage` entry to compute totals. Subcommands narrow the time
|
|
6
|
+
* window (today / week / month / all; defaults to `all`). Output is a
|
|
7
|
+
* table by default, `--json` for structured output.
|
|
8
|
+
*
|
|
9
|
+
* By-model and by-day rollups are also emitted so the user can see
|
|
10
|
+
* which model ate the budget and how usage trends over time.
|
|
11
|
+
*/
|
|
12
|
+
import type { Subcommand } from './index.js';
|
|
13
|
+
export declare const statsSubcommand: Subcommand;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha stats` — session + token + cost aggregates.
|
|
3
|
+
*
|
|
4
|
+
* Reads the JSONL session files under `~/.dirgha/sessions/`, walking
|
|
5
|
+
* every `usage` entry to compute totals. Subcommands narrow the time
|
|
6
|
+
* window (today / week / month / all; defaults to `all`). Output is a
|
|
7
|
+
* table by default, `--json` for structured output.
|
|
8
|
+
*
|
|
9
|
+
* By-model and by-day rollups are also emitted so the user can see
|
|
10
|
+
* which model ate the budget and how usage trends over time.
|
|
11
|
+
*/
|
|
12
|
+
import { readdir } from 'node:fs/promises';
|
|
13
|
+
import { homedir } from 'node:os';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { stdout, stderr } from 'node:process';
|
|
16
|
+
import { streamJsonl } from '../../context/session.js';
|
|
17
|
+
import { findPrice } from '../../intelligence/prices.js';
|
|
18
|
+
import { style, defaultTheme } from '../../tui/theme.js';
|
|
19
|
+
function empty() {
|
|
20
|
+
return { sessions: 0, messages: 0, inputTokens: 0, outputTokens: 0, cachedTokens: 0, costUsd: 0, byModel: {}, byDay: {} };
|
|
21
|
+
}
|
|
22
|
+
function windowStart(win) {
|
|
23
|
+
const now = new Date();
|
|
24
|
+
if (win === 'today') {
|
|
25
|
+
const d = new Date(now);
|
|
26
|
+
d.setHours(0, 0, 0, 0);
|
|
27
|
+
return d;
|
|
28
|
+
}
|
|
29
|
+
if (win === 'week') {
|
|
30
|
+
const d = new Date(now);
|
|
31
|
+
d.setDate(d.getDate() - 7);
|
|
32
|
+
return d;
|
|
33
|
+
}
|
|
34
|
+
if (win === 'month') {
|
|
35
|
+
const d = new Date(now);
|
|
36
|
+
d.setDate(d.getDate() - 30);
|
|
37
|
+
return d;
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
function costFor(model, input, output, cached) {
|
|
42
|
+
for (const provider of ['anthropic', 'openai', 'gemini', 'nvidia', 'openrouter']) {
|
|
43
|
+
const price = findPrice(provider, model);
|
|
44
|
+
if (!price)
|
|
45
|
+
continue;
|
|
46
|
+
const cachedCost = price.cachedInputPerM !== undefined ? (cached / 1_000_000) * price.cachedInputPerM : 0;
|
|
47
|
+
return ((input - cached) / 1_000_000) * price.inputPerM + cachedCost + (output / 1_000_000) * price.outputPerM;
|
|
48
|
+
}
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
async function aggregate(win) {
|
|
52
|
+
const dir = join(homedir(), '.dirgha', 'sessions');
|
|
53
|
+
const files = await readdir(dir).catch(() => []);
|
|
54
|
+
const since = windowStart(win);
|
|
55
|
+
const agg = empty();
|
|
56
|
+
for (const file of files) {
|
|
57
|
+
if (!file.endsWith('.jsonl'))
|
|
58
|
+
continue;
|
|
59
|
+
agg.sessions += 1;
|
|
60
|
+
let currentModel = 'unknown';
|
|
61
|
+
const pushEntry = (entry) => {
|
|
62
|
+
const ts = new Date(entry.ts);
|
|
63
|
+
if (since && ts < since)
|
|
64
|
+
return;
|
|
65
|
+
const dayKey = entry.ts.slice(0, 10);
|
|
66
|
+
if (entry.type === 'message') {
|
|
67
|
+
agg.messages += 1;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (entry.type === 'model_change') {
|
|
71
|
+
currentModel = entry.to;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (entry.type !== 'usage')
|
|
75
|
+
return;
|
|
76
|
+
agg.inputTokens += entry.usage.inputTokens;
|
|
77
|
+
agg.outputTokens += entry.usage.outputTokens;
|
|
78
|
+
agg.cachedTokens += entry.usage.cachedTokens;
|
|
79
|
+
const cost = entry.usage.costUsd > 0
|
|
80
|
+
? entry.usage.costUsd
|
|
81
|
+
: costFor(currentModel, entry.usage.inputTokens, entry.usage.outputTokens, entry.usage.cachedTokens);
|
|
82
|
+
agg.costUsd += cost;
|
|
83
|
+
const m = agg.byModel[currentModel] ?? { tokens: 0, costUsd: 0 };
|
|
84
|
+
m.tokens += entry.usage.inputTokens + entry.usage.outputTokens;
|
|
85
|
+
m.costUsd += cost;
|
|
86
|
+
agg.byModel[currentModel] = m;
|
|
87
|
+
const d = agg.byDay[dayKey] ?? { tokens: 0, costUsd: 0 };
|
|
88
|
+
d.tokens += entry.usage.inputTokens + entry.usage.outputTokens;
|
|
89
|
+
d.costUsd += cost;
|
|
90
|
+
agg.byDay[dayKey] = d;
|
|
91
|
+
};
|
|
92
|
+
await streamJsonl(join(dir, file), pushEntry).catch(() => undefined);
|
|
93
|
+
}
|
|
94
|
+
return agg;
|
|
95
|
+
}
|
|
96
|
+
function formatTok(n) {
|
|
97
|
+
if (n >= 1_000_000)
|
|
98
|
+
return `${(n / 1_000_000).toFixed(2)}M`;
|
|
99
|
+
if (n >= 1_000)
|
|
100
|
+
return `${(n / 1_000).toFixed(1)}k`;
|
|
101
|
+
return String(n);
|
|
102
|
+
}
|
|
103
|
+
function printTable(win, a) {
|
|
104
|
+
const title = `Dirgha stats — ${win}`;
|
|
105
|
+
stdout.write(`\n${style(defaultTheme.accent, title)}\n\n`);
|
|
106
|
+
stdout.write(` sessions ${a.sessions}\n`);
|
|
107
|
+
stdout.write(` messages ${a.messages}\n`);
|
|
108
|
+
stdout.write(` input tokens ${formatTok(a.inputTokens)}\n`);
|
|
109
|
+
stdout.write(` output tokens ${formatTok(a.outputTokens)}\n`);
|
|
110
|
+
stdout.write(` cached tokens ${formatTok(a.cachedTokens)}\n`);
|
|
111
|
+
stdout.write(` cost usd $${a.costUsd.toFixed(4)}\n`);
|
|
112
|
+
const models = Object.entries(a.byModel).sort((x, y) => y[1].tokens - x[1].tokens).slice(0, 8);
|
|
113
|
+
if (models.length > 0) {
|
|
114
|
+
stdout.write(`\n${style(defaultTheme.userPrompt, 'by model')}\n`);
|
|
115
|
+
for (const [model, s] of models) {
|
|
116
|
+
stdout.write(` ${model.padEnd(44)} ${formatTok(s.tokens).padStart(8)} $${s.costUsd.toFixed(4)}\n`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const days = Object.entries(a.byDay).sort().slice(-14);
|
|
120
|
+
if (days.length > 0) {
|
|
121
|
+
stdout.write(`\n${style(defaultTheme.userPrompt, 'by day')}\n`);
|
|
122
|
+
for (const [day, s] of days) {
|
|
123
|
+
stdout.write(` ${day} ${formatTok(s.tokens).padStart(8)} $${s.costUsd.toFixed(4)}\n`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
stdout.write('\n');
|
|
127
|
+
}
|
|
128
|
+
export const statsSubcommand = {
|
|
129
|
+
name: 'stats',
|
|
130
|
+
description: 'Usage stats (sessions, tokens, cost) — today / week / month / all',
|
|
131
|
+
async run(argv) {
|
|
132
|
+
const json = argv.includes('--json');
|
|
133
|
+
const rest = argv.filter(a => a !== '--json');
|
|
134
|
+
const op = (rest[0] ?? 'all');
|
|
135
|
+
const valid = ['today', 'week', 'month', 'all'];
|
|
136
|
+
if (!valid.includes(op)) {
|
|
137
|
+
stderr.write(`usage: dirgha stats [${valid.join('|')}] [--json]\n`);
|
|
138
|
+
return 1;
|
|
139
|
+
}
|
|
140
|
+
const a = await aggregate(op);
|
|
141
|
+
if (json)
|
|
142
|
+
stdout.write(`${JSON.stringify({ window: op, ...a })}\n`);
|
|
143
|
+
else
|
|
144
|
+
printTable(op, a);
|
|
145
|
+
return 0;
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=stats.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha status` — snapshot of the CLI state.
|
|
3
|
+
*
|
|
4
|
+
* Reports:
|
|
5
|
+
* - whether the user is logged in (via device-auth credentials)
|
|
6
|
+
* - current default model + configured providers
|
|
7
|
+
* - session store location + count
|
|
8
|
+
* - quota summary when logged in (best-effort; silent on error)
|
|
9
|
+
*
|
|
10
|
+
* Mirrors the REPL `/status` slash but is scoped to globals rather
|
|
11
|
+
* than a live session.
|
|
12
|
+
*/
|
|
13
|
+
import type { Subcommand } from './index.js';
|
|
14
|
+
export declare const statusSubcommand: Subcommand;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha status` — snapshot of the CLI state.
|
|
3
|
+
*
|
|
4
|
+
* Reports:
|
|
5
|
+
* - whether the user is logged in (via device-auth credentials)
|
|
6
|
+
* - current default model + configured providers
|
|
7
|
+
* - session store location + count
|
|
8
|
+
* - quota summary when logged in (best-effort; silent on error)
|
|
9
|
+
*
|
|
10
|
+
* Mirrors the REPL `/status` slash but is scoped to globals rather
|
|
11
|
+
* than a live session.
|
|
12
|
+
*/
|
|
13
|
+
import { readdir } from 'node:fs/promises';
|
|
14
|
+
import { homedir } from 'node:os';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
import { stdout } from 'node:process';
|
|
17
|
+
import { loadConfig } from '../config.js';
|
|
18
|
+
import { loadToken } from '../../integrations/device-auth.js';
|
|
19
|
+
import { createEntitlementsClient } from '../../integrations/entitlements.js';
|
|
20
|
+
import { style, defaultTheme } from '../../tui/theme.js';
|
|
21
|
+
const PROVIDER_ENV = {
|
|
22
|
+
anthropic: 'ANTHROPIC_API_KEY',
|
|
23
|
+
openai: 'OPENAI_API_KEY',
|
|
24
|
+
gemini: 'GEMINI_API_KEY',
|
|
25
|
+
nvidia: 'NVIDIA_API_KEY',
|
|
26
|
+
openrouter: 'OPENROUTER_API_KEY',
|
|
27
|
+
fireworks: 'FIREWORKS_API_KEY',
|
|
28
|
+
};
|
|
29
|
+
async function sessionCount() {
|
|
30
|
+
const dir = join(homedir(), '.dirgha', 'sessions');
|
|
31
|
+
const files = await readdir(dir).catch(() => []);
|
|
32
|
+
return files.filter(f => f.endsWith('.jsonl')).length;
|
|
33
|
+
}
|
|
34
|
+
async function entitlementsFor(token) {
|
|
35
|
+
try {
|
|
36
|
+
const client = createEntitlementsClient();
|
|
37
|
+
return await client.get(token);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export const statusSubcommand = {
|
|
44
|
+
name: 'status',
|
|
45
|
+
description: 'Show current config, model, providers, and login state',
|
|
46
|
+
async run(argv, ctx) {
|
|
47
|
+
const json = argv.includes('--json');
|
|
48
|
+
const config = await loadConfig(ctx.cwd);
|
|
49
|
+
const token = await loadToken();
|
|
50
|
+
const sessions = await sessionCount();
|
|
51
|
+
const providers = {};
|
|
52
|
+
for (const [name, env] of Object.entries(PROVIDER_ENV)) {
|
|
53
|
+
providers[name] = Boolean(process.env[env]);
|
|
54
|
+
}
|
|
55
|
+
const entitlements = token ? await entitlementsFor(token.token) : undefined;
|
|
56
|
+
if (json) {
|
|
57
|
+
const payload = {
|
|
58
|
+
loggedIn: Boolean(token),
|
|
59
|
+
user: token ? { userId: token.userId, email: token.email, expiresAt: token.expiresAt } : undefined,
|
|
60
|
+
model: config.model,
|
|
61
|
+
maxTurns: config.maxTurns,
|
|
62
|
+
sessions,
|
|
63
|
+
providers,
|
|
64
|
+
entitlements,
|
|
65
|
+
};
|
|
66
|
+
stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
stdout.write(`\n${style(defaultTheme.accent, 'Dirgha status')}\n\n`);
|
|
70
|
+
stdout.write(` ${'account'.padEnd(14)} ${token ? style(defaultTheme.success, `${token.email ?? token.userId}`) : style(defaultTheme.muted, 'not logged in')}\n`);
|
|
71
|
+
if (token)
|
|
72
|
+
stdout.write(` ${'expires'.padEnd(14)} ${style(defaultTheme.muted, token.expiresAt)}\n`);
|
|
73
|
+
stdout.write(` ${'model'.padEnd(14)} ${config.model}\n`);
|
|
74
|
+
stdout.write(` ${'max turns'.padEnd(14)} ${config.maxTurns}\n`);
|
|
75
|
+
stdout.write(` ${'sessions'.padEnd(14)} ${sessions} saved\n`);
|
|
76
|
+
stdout.write(`\n${style(defaultTheme.userPrompt, 'providers')}\n`);
|
|
77
|
+
for (const [name, hasKey] of Object.entries(providers)) {
|
|
78
|
+
const marker = hasKey ? style(defaultTheme.success, 'configured') : style(defaultTheme.muted, 'unset');
|
|
79
|
+
stdout.write(` ${name.padEnd(14)} ${marker}\n`);
|
|
80
|
+
}
|
|
81
|
+
if (entitlements) {
|
|
82
|
+
stdout.write(`\n${style(defaultTheme.userPrompt, 'plan')}\n`);
|
|
83
|
+
stdout.write(` ${'tier'.padEnd(14)} ${entitlements.tier}\n`);
|
|
84
|
+
stdout.write(` ${'daily deploys'.padEnd(14)} ${entitlements.limits.dailyDeploys}\n`);
|
|
85
|
+
stdout.write(` ${'subagents'.padEnd(14)} ${entitlements.limits.maxSubagents}\n`);
|
|
86
|
+
}
|
|
87
|
+
stdout.write('\n');
|
|
88
|
+
return 0;
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha submit-paper <doi>` — fetch Crossref metadata for a DOI, produce a
|
|
3
|
+
* JSON file suitable for the dirgha-org-site `content/papers/` directory, and
|
|
4
|
+
* (optionally) open a pull request against the public repo.
|
|
5
|
+
*
|
|
6
|
+
* Without GITHUB_TOKEN the command prints the JSON + manual PR instructions.
|
|
7
|
+
* With a token it runs `gh api` to fork + branch + PR.
|
|
8
|
+
*/
|
|
9
|
+
export interface SubmitPaperArgs {
|
|
10
|
+
doi: string;
|
|
11
|
+
targetDir?: string;
|
|
12
|
+
openPr?: boolean;
|
|
13
|
+
repo?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function runSubmitPaper(args: SubmitPaperArgs): Promise<number>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dirgha submit-paper <doi>` — fetch Crossref metadata for a DOI, produce a
|
|
3
|
+
* JSON file suitable for the dirgha-org-site `content/papers/` directory, and
|
|
4
|
+
* (optionally) open a pull request against the public repo.
|
|
5
|
+
*
|
|
6
|
+
* Without GITHUB_TOKEN the command prints the JSON + manual PR instructions.
|
|
7
|
+
* With a token it runs `gh api` to fork + branch + PR.
|
|
8
|
+
*/
|
|
9
|
+
import { stdout, stderr, env } from 'node:process';
|
|
10
|
+
import { writeFile, mkdir } from 'node:fs/promises';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
13
|
+
export async function runSubmitPaper(args) {
|
|
14
|
+
const { doi, targetDir = path.join(tmpdir(), 'dirgha-papers'), openPr = false, repo = 'dirghaai/dirgha-org-site' } = args;
|
|
15
|
+
stdout.write(`→ fetching Crossref metadata for ${doi}\n`);
|
|
16
|
+
const res = await fetch(`https://api.crossref.org/works/${encodeURIComponent(doi)}`);
|
|
17
|
+
if (!res.ok) {
|
|
18
|
+
stderr.write(`× Crossref returned ${res.status}\n`);
|
|
19
|
+
return 2;
|
|
20
|
+
}
|
|
21
|
+
const body = (await res.json());
|
|
22
|
+
const m = body.message;
|
|
23
|
+
if (!m) {
|
|
24
|
+
stderr.write('× unexpected Crossref shape\n');
|
|
25
|
+
return 2;
|
|
26
|
+
}
|
|
27
|
+
const title = (m.title ?? [])[0] ?? '(no title)';
|
|
28
|
+
const authors = (m.author ?? []).map(a => [a.given, a.family].filter(Boolean).join(' ')).filter(Boolean);
|
|
29
|
+
const year = (m.published?.['date-parts'] ?? [[undefined]])[0]?.[0];
|
|
30
|
+
const venue = (m['container-title'] ?? [])[0];
|
|
31
|
+
const abstract = (m.abstract ?? '').replace(/<[^>]+>/g, '').trim();
|
|
32
|
+
const tags = (m.subject ?? []).map(s => s.toLowerCase().replace(/\s+/g, '-'));
|
|
33
|
+
const record = {
|
|
34
|
+
doi: m.DOI,
|
|
35
|
+
title,
|
|
36
|
+
authors,
|
|
37
|
+
...(year !== undefined ? { year } : {}),
|
|
38
|
+
...(venue ? { venue } : {}),
|
|
39
|
+
...(abstract ? { abstract } : {}),
|
|
40
|
+
...(tags.length ? { tags } : {}),
|
|
41
|
+
};
|
|
42
|
+
const slug = m.DOI.replace(/[^a-z0-9]+/gi, '-').toLowerCase().slice(0, 60);
|
|
43
|
+
const fileName = `${Date.now()}-${slug}.json`;
|
|
44
|
+
await mkdir(targetDir, { recursive: true });
|
|
45
|
+
const outPath = path.join(targetDir, fileName);
|
|
46
|
+
await writeFile(outPath, JSON.stringify(record, null, 2) + '\n', 'utf8');
|
|
47
|
+
stdout.write(`✓ wrote ${outPath}\n\n`);
|
|
48
|
+
stdout.write(`${JSON.stringify(record, null, 2)}\n\n`);
|
|
49
|
+
if (!openPr) {
|
|
50
|
+
stdout.write(`Next steps — manual PR:\n`);
|
|
51
|
+
stdout.write(` 1. git clone https://github.com/${repo}.git\n`);
|
|
52
|
+
stdout.write(` 2. cp ${outPath} dirgha-org-site/content/papers/\n`);
|
|
53
|
+
stdout.write(` 3. git checkout -b submit-${slug} && git add . && git commit -m "papers: ${title.slice(0, 60)}"\n`);
|
|
54
|
+
stdout.write(` 4. gh pr create --title "papers: ${title}" --body "DOI: ${m.DOI}"\n`);
|
|
55
|
+
stdout.write(`\nOr re-run with --open-pr to have the CLI open the PR for you (requires GITHUB_TOKEN).\n`);
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
const token = env.GITHUB_TOKEN;
|
|
59
|
+
if (!token) {
|
|
60
|
+
stderr.write('× GITHUB_TOKEN not set — cannot open PR automatically.\n');
|
|
61
|
+
return 2;
|
|
62
|
+
}
|
|
63
|
+
stdout.write(`→ opening PR against ${repo} (placeholder — wire via gh CLI or REST when needed)\n`);
|
|
64
|
+
// Placeholder: real implementation invokes `gh repo fork`, `gh pr create`, etc.
|
|
65
|
+
// Keeping this minimal so the function stays testable without a live repo.
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=submit-paper.js.map
|