mixdog 0.8.1 → 0.9.1
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/README.md +47 -23
- package/package.json +34 -28
- package/scripts/_test-folder-dialog.mjs +30 -0
- package/scripts/agent-parallel-smoke.mjs +388 -0
- package/scripts/agent-tag-reuse-smoke.mjs +183 -0
- package/scripts/background-task-meta-smoke.mjs +38 -0
- package/scripts/boot-smoke.mjs +52 -9
- package/scripts/build-runtime-linux.sh +348 -0
- package/scripts/build-runtime-macos.sh +217 -0
- package/scripts/build-runtime-windows.ps1 +242 -0
- package/scripts/compact-active-turn-test.mjs +68 -0
- package/scripts/compact-smoke.mjs +859 -129
- package/scripts/compact-trigger-migration-smoke.mjs +187 -0
- package/scripts/fix-brief-fn.mjs +35 -0
- package/scripts/fix-format-tool-surface.mjs +24 -0
- package/scripts/fix-tool-exec-visible.mjs +42 -0
- package/scripts/generate-runtime-manifest.mjs +166 -0
- package/scripts/hook-bus-test.mjs +330 -0
- package/scripts/lead-workflow-smoke.mjs +33 -39
- package/scripts/live-worker-smoke.mjs +43 -37
- package/scripts/llm-trace-summary.mjs +315 -0
- package/scripts/memory-meta-concurrency-test.mjs +20 -0
- package/scripts/output-style-smoke.mjs +56 -15
- package/scripts/parent-abort-link-test.mjs +44 -0
- package/scripts/patch-agent-brief.mjs +48 -0
- package/scripts/patch-app.mjs +21 -0
- package/scripts/patch-app2.mjs +18 -0
- package/scripts/patch-dist-brief.mjs +96 -0
- package/scripts/patch-tool-exec.mjs +70 -0
- package/scripts/pretool-ask-runtime-test.mjs +54 -0
- package/scripts/provider-toolcall-test.mjs +376 -0
- package/scripts/reactive-compact-persist-smoke.mjs +124 -0
- package/scripts/sanitize-tool-pairs-test.mjs +260 -0
- package/scripts/session-context-bench.mjs +205 -33
- package/scripts/session-ingest-smoke.mjs +177 -0
- package/scripts/set-effort-config-test.mjs +41 -0
- package/scripts/smoke-runtime-negative.ps1 +106 -0
- package/scripts/smoke-runtime-negative.sh +97 -0
- package/scripts/smoke.mjs +25 -0
- package/scripts/tool-result-hook-test.mjs +48 -0
- package/scripts/tool-smoke.mjs +1222 -90
- package/scripts/toolcall-args-test.mjs +150 -0
- package/scripts/tui-background-failure-smoke.mjs +73 -0
- package/scripts/usage-metrics-epoch-smoke.mjs +114 -0
- package/src/agents/debugger/AGENT.md +8 -0
- package/src/agents/explore/AGENT.md +4 -0
- package/src/agents/heavy-worker/AGENT.md +9 -3
- package/src/agents/maintainer/AGENT.md +4 -0
- package/src/agents/reviewer/AGENT.md +8 -0
- package/src/agents/scheduler-task/AGENT.md +12 -0
- package/src/agents/scheduler-task/agent.json +6 -0
- package/src/agents/webhook-handler/AGENT.md +12 -0
- package/src/agents/webhook-handler/agent.json +6 -0
- package/src/agents/worker/AGENT.md +9 -3
- package/src/app.mjs +77 -3
- package/src/defaults/hidden-roles.json +17 -12
- package/src/headless-role.mjs +117 -0
- package/src/help.mjs +30 -0
- package/src/hooks/lib/permission-evaluator.cjs +11 -475
- package/src/lib/keychain-cjs.cjs +9 -1
- package/src/lib/mixdog-debug.cjs +0 -29
- package/src/lib/plugin-paths.cjs +1 -7
- package/src/lib/rules-builder.cjs +242 -98
- package/src/lib/text-utils.cjs +1 -1
- package/src/mixdog-session-runtime.mjs +2211 -446
- package/src/output-styles/default.md +12 -28
- package/src/output-styles/extreme-simple.md +9 -6
- package/src/output-styles/simple.md +22 -9
- package/src/repl.mjs +108 -59
- package/src/rules/agent/00-common.md +15 -0
- package/src/rules/{bridge → agent}/20-skip-protocol.md +1 -2
- package/src/rules/agent/30-explorer.md +22 -0
- package/src/rules/{bridge → agent}/40-cycle1-agent.md +7 -0
- package/src/rules/{bridge → agent}/41-cycle2-agent.md +7 -0
- package/src/rules/{bridge → agent}/42-cycle3-agent.md +7 -0
- package/src/rules/lead/01-general.md +9 -5
- package/src/rules/lead/04-workflow.md +51 -12
- package/src/rules/lead/lead-tool.md +6 -0
- package/src/rules/shared/01-tool.md +12 -1
- package/src/runtime/agent/orchestrator/activity-bus.mjs +7 -18
- package/src/runtime/agent/orchestrator/agent-owner.mjs +11 -0
- package/src/runtime/agent/orchestrator/{smart-bridge/bridge-llm.mjs → agent-runtime/agent-dispatch.mjs} +138 -111
- package/src/runtime/agent/orchestrator/agent-runtime/agent-progress-watchdog.mjs +94 -0
- package/src/runtime/agent/orchestrator/{smart-bridge → agent-runtime}/cache-strategy.mjs +32 -23
- package/src/runtime/agent/orchestrator/{smart-bridge → agent-runtime}/session-builder.mjs +33 -27
- package/src/runtime/agent/orchestrator/{bridge-trace.mjs → agent-trace.mjs} +132 -81
- package/src/runtime/agent/orchestrator/cache-mtime.mjs +0 -21
- package/src/runtime/agent/orchestrator/config.mjs +174 -55
- package/src/runtime/agent/orchestrator/context/collect.mjs +195 -487
- package/src/runtime/agent/orchestrator/dispatch-persist.mjs +1 -1
- package/src/runtime/agent/orchestrator/internal-roles.mjs +77 -29
- package/src/runtime/agent/orchestrator/internal-tools.mjs +5 -6
- package/src/runtime/agent/orchestrator/mcp/client.mjs +15 -9
- package/src/runtime/agent/orchestrator/providers/anthropic-betas.mjs +7 -1
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +380 -268
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +131 -93
- package/src/runtime/agent/orchestrator/providers/api-usage.mjs +236 -4
- package/src/runtime/agent/orchestrator/providers/custom-tool-wire.mjs +49 -0
- package/src/runtime/agent/orchestrator/providers/gemini.mjs +58 -13
- package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +67 -149
- package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +132 -2
- package/src/runtime/agent/orchestrator/providers/model-catalog.mjs +4 -1
- package/src/runtime/agent/orchestrator/providers/oauth-credential-probes.mjs +45 -0
- package/src/runtime/agent/orchestrator/providers/oauth-usage.mjs +61 -116
- package/src/runtime/agent/orchestrator/providers/openai-compat-presets.mjs +25 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-stream.mjs +79 -255
- package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +203 -71
- package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +512 -312
- package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +343 -518
- package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +6 -6
- package/src/runtime/agent/orchestrator/providers/registry.mjs +88 -51
- package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +289 -11
- package/src/runtime/agent/orchestrator/providers/statusline-route-meta.mjs +41 -8
- package/src/runtime/agent/orchestrator/session/compact.mjs +1173 -267
- package/src/runtime/agent/orchestrator/session/context-utils.mjs +199 -36
- package/src/runtime/agent/orchestrator/session/loop.mjs +840 -612
- package/src/runtime/agent/orchestrator/session/manager.mjs +1574 -459
- package/src/runtime/agent/orchestrator/session/manager.reactive-persist.test.mjs +107 -0
- package/src/runtime/agent/orchestrator/session/store.mjs +67 -29
- package/src/runtime/agent/orchestrator/session/tool-result-offload.mjs +2 -2
- package/src/runtime/agent/orchestrator/stall-policy.mjs +31 -16
- package/src/runtime/agent/orchestrator/tool-loop-guard.mjs +3 -219
- package/src/runtime/agent/orchestrator/tools/bash-session.mjs +35 -8
- package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +19 -8
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +10 -53
- package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +60 -37
- package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +21 -2
- package/src/runtime/agent/orchestrator/tools/builtin/device-paths.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/diagnostics-tool.mjs +0 -7
- package/src/runtime/agent/orchestrator/tools/builtin/glob-walk.mjs +1 -3
- package/src/runtime/agent/orchestrator/tools/builtin/list-tool.mjs +36 -12
- package/src/runtime/agent/orchestrator/tools/builtin/read-args.mjs +2 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-constants.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/builtin/read-formatting.mjs +5 -12
- package/src/runtime/agent/orchestrator/tools/builtin/read-image-resize.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/read-single-tool.mjs +4 -36
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool.mjs +2 -40
- package/src/runtime/agent/orchestrator/tools/builtin/rg-runner.mjs +148 -27
- package/src/runtime/agent/orchestrator/tools/builtin/search-builders.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/builtin/search-tool.mjs +43 -75
- package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +90 -20
- package/src/runtime/agent/orchestrator/tools/builtin.mjs +59 -5
- package/src/runtime/agent/orchestrator/tools/code-graph-state.mjs +86 -0
- package/src/runtime/agent/orchestrator/tools/code-graph-tool-defs.mjs +11 -11
- package/src/runtime/agent/orchestrator/tools/code-graph.mjs +4106 -4019
- package/src/runtime/agent/orchestrator/tools/patch-tool-defs.mjs +33 -4
- package/src/runtime/agent/orchestrator/tools/patch.mjs +90 -6
- package/src/runtime/agent/orchestrator/tools/progress-message.mjs +6 -4
- package/src/runtime/agent/orchestrator/tools/result-compression.mjs +4 -4
- package/src/runtime/agent/orchestrator/tools/shell-command.mjs +8 -1
- package/src/runtime/agent/orchestrator/tools/shell-snapshot.mjs +4 -4
- package/src/runtime/channels/index.mjs +149 -51
- package/src/runtime/channels/lib/cli-worker-host.mjs +1 -8
- package/src/runtime/channels/lib/config.mjs +0 -1
- package/src/runtime/channels/lib/drop-trace.mjs +1 -1
- package/src/runtime/channels/lib/executor.mjs +0 -3
- package/src/runtime/channels/lib/memory-client.mjs +0 -38
- package/src/runtime/channels/lib/output-forwarder.mjs +1 -8
- package/src/runtime/channels/lib/runtime-paths.mjs +0 -6
- package/src/runtime/channels/lib/scheduler.mjs +18 -14
- package/src/runtime/channels/lib/session-discovery.mjs +3 -6
- package/src/runtime/channels/lib/tool-format.mjs +0 -1
- package/src/runtime/channels/lib/transcript-discovery.mjs +4 -12
- package/src/runtime/channels/lib/webhook.mjs +1 -1
- package/src/runtime/channels/tool-defs.mjs +29 -29
- package/src/runtime/lib/keychain-cjs.cjs +0 -1
- package/src/runtime/memory/data/runtime-manifest.json +6 -7
- package/src/runtime/memory/index.mjs +519 -118
- package/src/runtime/memory/lib/agent-ipc.mjs +29 -12
- package/src/runtime/memory/lib/core-memory-store.mjs +2 -2
- package/src/runtime/memory/lib/embedding-model-config.mjs +55 -0
- package/src/runtime/memory/lib/embedding-provider.mjs +31 -4
- package/src/runtime/memory/lib/embedding-worker.mjs +19 -10
- package/src/runtime/memory/lib/llm-worker-host.mjs +0 -4
- package/src/runtime/memory/lib/memory-cycle1.mjs +28 -7
- package/src/runtime/memory/lib/memory-cycle2.mjs +4 -5
- package/src/runtime/memory/lib/memory-cycle3.mjs +2 -2
- package/src/runtime/memory/lib/memory-ops-policy.mjs +2 -2
- package/src/runtime/memory/lib/memory-session-merge.mjs +38 -0
- package/src/runtime/memory/lib/memory.mjs +88 -9
- package/src/runtime/memory/lib/model-profile.mjs +1 -1
- package/src/runtime/memory/lib/pg/adapter.mjs +1 -1
- package/src/runtime/memory/lib/pg/supervisor.mjs +12 -0
- package/src/runtime/memory/lib/runtime-fetcher.mjs +80 -21
- package/src/runtime/memory/lib/session-ingest.mjs +196 -0
- package/src/runtime/memory/lib/trace-store.mjs +96 -51
- package/src/runtime/memory/tool-defs.mjs +46 -37
- package/src/runtime/search/index.mjs +104 -473
- package/src/runtime/search/lib/config.mjs +0 -4
- package/src/runtime/search/lib/state.mjs +1 -15
- package/src/runtime/search/lib/web-tools.mjs +44 -25
- package/src/runtime/search/tool-defs.mjs +16 -23
- package/src/runtime/shared/abort-controller.mjs +1 -1
- package/src/runtime/shared/atomic-file.mjs +4 -3
- package/src/runtime/shared/background-tasks.mjs +122 -11
- package/src/runtime/shared/child-spawn-gate.mjs +139 -0
- package/src/runtime/shared/config.mjs +7 -4
- package/src/runtime/shared/err-text.mjs +131 -4
- package/src/runtime/shared/llm/cost.mjs +2 -2
- package/src/runtime/shared/llm/http-agent.mjs +23 -7
- package/src/runtime/shared/llm/index.mjs +34 -11
- package/src/runtime/shared/llm/usage-log.mjs +4 -4
- package/src/runtime/shared/markdown-frontmatter.mjs +56 -0
- package/src/runtime/shared/singleton-owner.mjs +104 -0
- package/src/runtime/shared/tool-execution-contract.mjs +199 -20
- package/src/runtime/shared/tool-execution-contract.test.mjs +183 -0
- package/src/runtime/shared/tool-surface.mjs +624 -95
- package/src/runtime/shared/user-data-guard.mjs +0 -2
- package/src/standalone/agent-task-status.mjs +203 -0
- package/src/standalone/agent-task-status.test.mjs +76 -0
- package/src/standalone/agent-tool.mjs +1913 -0
- package/src/standalone/channel-worker.mjs +370 -14
- package/src/standalone/explore-tool.mjs +165 -70
- package/src/standalone/folder-dialog.mjs +314 -0
- package/src/standalone/hook-bus.mjs +898 -22
- package/src/standalone/memory-runtime-proxy.mjs +320 -0
- package/src/standalone/projects.mjs +226 -0
- package/src/standalone/provider-admin.mjs +41 -24
- package/src/standalone/seeds.mjs +1 -78
- package/src/standalone/usage-dashboard.mjs +96 -8
- package/src/tui/App.jsx +4800 -2140
- package/src/tui/components/AnsiText.jsx +39 -28
- package/src/tui/components/ContextPanel.jsx +14 -4
- package/src/tui/components/Markdown.jsx +43 -77
- package/src/tui/components/MarkdownTable.jsx +9 -184
- package/src/tui/components/Message.jsx +28 -11
- package/src/tui/components/Picker.jsx +95 -56
- package/src/tui/components/PromptInput.jsx +428 -239
- package/src/tui/components/QueuedCommands.jsx +1 -1
- package/src/tui/components/SlashCommandPalette.jsx +27 -21
- package/src/tui/components/Spinner.jsx +67 -38
- package/src/tui/components/StatusLine.jsx +606 -38
- package/src/tui/components/TextEntryPanel.jsx +128 -9
- package/src/tui/components/ToolExecution.jsx +597 -362
- package/src/tui/components/TurnDone.jsx +3 -3
- package/src/tui/components/UsagePanel.jsx +3 -5
- package/src/tui/components/tool-output-format.mjs +499 -0
- package/src/tui/components/tool-output-format.test.mjs +312 -0
- package/src/tui/dist/index.mjs +9192 -2399
- package/src/tui/engine-runtime-notification.test.mjs +115 -0
- package/src/tui/engine-tool-result-text.test.mjs +75 -0
- package/src/tui/engine.mjs +1455 -279
- package/src/tui/figures.mjs +21 -40
- package/src/tui/index.jsx +75 -31
- package/src/tui/input-editing.mjs +25 -0
- package/src/tui/markdown/format-token.mjs +671 -69
- package/src/tui/markdown/format-token.test.mjs +312 -0
- package/src/tui/markdown/render-ansi.mjs +94 -0
- package/src/tui/markdown/render-ansi.test.mjs +108 -0
- package/src/tui/markdown/stream-fence.mjs +34 -0
- package/src/tui/markdown/stream-fence.test.mjs +26 -0
- package/src/tui/markdown/table-layout.mjs +250 -0
- package/src/tui/paste-attachments.mjs +0 -7
- package/src/tui/spinner-verbs.mjs +1 -2
- package/src/tui/statusline-ansi-bridge.mjs +172 -0
- package/src/tui/statusline-ansi-bridge.test.mjs +159 -0
- package/src/tui/theme.mjs +756 -24
- package/src/tui/time-format.mjs +1 -1
- package/src/tui/transcript-tool-failures.mjs +67 -0
- package/src/tui/transcript-tool-failures.test.mjs +111 -0
- package/src/ui/ansi.mjs +1 -2
- package/src/ui/markdown.mjs +85 -26
- package/src/ui/markdown.test.mjs +70 -0
- package/src/ui/model-display.mjs +121 -0
- package/src/ui/session-stats.mjs +44 -0
- package/src/ui/statusline-context-label.test.mjs +15 -0
- package/src/ui/statusline.mjs +386 -178
- package/src/ui/tool-card.mjs +2 -13
- package/src/vendor/statusline/bin/statusline-lib.mjs +1 -620
- package/src/vendor/statusline/bin/statusline-route.mjs +169 -37
- package/src/vendor/statusline/bin/statusline-route.test.mjs +80 -0
- package/src/vendor/statusline/scripts/lib/gateway-settings.mjs +3 -3
- package/src/vendor/statusline/src/gateway/claude-current.mjs +1 -1
- package/src/vendor/statusline/src/gateway/route-meta.mjs +44 -6
- package/src/vendor/statusline/src/gateway/session-routes.mjs +1 -1
- package/src/workflows/default/WORKFLOW.md +12 -5
- package/src/workflows/default/workflow.json +0 -1
- package/src/workflows/solo/WORKFLOW.md +15 -0
- package/src/workflows/solo/workflow.json +7 -0
- package/vendor/ink/build/ink.js +54 -8
- package/vendor/ink/build/output.js +6 -1
- package/src/agents/scheduler-task.md +0 -3
- package/src/agents/web-researcher/AGENT.md +0 -3
- package/src/agents/web-researcher/agent.json +0 -6
- package/src/agents/webhook-handler.md +0 -3
- package/src/hooks/lib/permission-rules.cjs +0 -170
- package/src/hooks/lib/settings-loader.cjs +0 -112
- package/src/lib/hook-pipe-path.cjs +0 -10
- package/src/rules/bridge/00-common.md +0 -5
- package/src/rules/bridge/30-explorer.md +0 -4
- package/src/rules/lead/00-tool-lead.md +0 -5
- package/src/rules/shared/00-language.md +0 -3
- package/src/runtime/agent/orchestrator/tools/builtin/native-edit-runner.mjs +0 -110
- package/src/runtime/agent/orchestrator/tools/mutation-content-cache.mjs +0 -67
- package/src/runtime/channels/lib/hook-pipe-server.mjs +0 -671
- package/src/runtime/memory/lib/bridge-trace-queries.mjs +0 -120
- package/src/runtime/shared/llm/pid-cleanup.mjs +0 -27
- package/src/standalone/bridge-tool.mjs +0 -1414
- package/src/tui/runtime/shared/process-shutdown.mjs +0 -1
package/src/standalone/seeds.mjs
CHANGED
|
@@ -1,60 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname, join, resolve } from 'node:path';
|
|
3
|
-
|
|
4
|
-
const DEFAULT_DATA_FILES = [];
|
|
5
|
-
const DEFAULT_MIXDOG_MD = `# Mixdog Instructions
|
|
6
|
-
|
|
7
|
-
Use this file for Mixdog-specific user and project context.
|
|
8
|
-
|
|
9
|
-
- Keep stable preferences, workflow notes, and project conventions here.
|
|
10
|
-
- Mixdog loads this file as context for new sessions.
|
|
11
|
-
- Edit or replace this content at any time.
|
|
12
|
-
`;
|
|
13
|
-
|
|
14
|
-
const DEFAULT_PROJECT_MIXDOG_MD = `# Mixdog Instructions
|
|
15
|
-
|
|
16
|
-
Use this file for project-specific Mixdog context.
|
|
17
|
-
|
|
18
|
-
- Add stable project conventions, commands, and workflow notes here.
|
|
19
|
-
- Mixdog loads this file from the project root for new sessions.
|
|
20
|
-
- Edit or replace this content at any time.
|
|
21
|
-
`;
|
|
22
|
-
|
|
23
|
-
function isDirectory(path) {
|
|
24
|
-
try {
|
|
25
|
-
return statSync(path).isDirectory();
|
|
26
|
-
} catch {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function hasProjectSentinel(dir) {
|
|
32
|
-
return existsSync(join(dir, '.git'))
|
|
33
|
-
|| existsSync(join(dir, 'package.json'))
|
|
34
|
-
|| existsSync(join(dir, 'pyproject.toml'))
|
|
35
|
-
|| existsSync(join(dir, 'Cargo.toml'))
|
|
36
|
-
|| existsSync(join(dir, 'go.mod'))
|
|
37
|
-
|| existsSync(join(dir, 'mixdog.md'))
|
|
38
|
-
|| existsSync(join(dir, 'Mixdog.md'))
|
|
39
|
-
|| existsSync(join(dir, 'AGENTS.md'));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function resolveProjectRoot(cwd) {
|
|
43
|
-
if (!cwd || typeof cwd !== 'string') return null;
|
|
44
|
-
let cur;
|
|
45
|
-
try {
|
|
46
|
-
cur = resolve(cwd);
|
|
47
|
-
} catch {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
if (!isDirectory(cur)) return null;
|
|
51
|
-
while (true) {
|
|
52
|
-
if (hasProjectSentinel(cur)) return cur;
|
|
53
|
-
const parent = dirname(cur);
|
|
54
|
-
if (parent === cur) return null;
|
|
55
|
-
cur = parent;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
1
|
+
import { mkdirSync } from 'node:fs';
|
|
58
2
|
|
|
59
3
|
export function ensureStandaloneEnvironment({ rootDir, dataDir }) {
|
|
60
4
|
if (!rootDir) throw new Error('standalone rootDir is required');
|
|
@@ -70,25 +14,4 @@ export function ensureStandaloneEnvironment({ rootDir, dataDir }) {
|
|
|
70
14
|
process.env.MIXDOG_PATCH_NATIVE_PREWARM ??= '0';
|
|
71
15
|
|
|
72
16
|
mkdirSync(dataDir, { recursive: true });
|
|
73
|
-
const mixdogMdPath = join(dataDir, 'mixdog.md');
|
|
74
|
-
if (!existsSync(mixdogMdPath)) {
|
|
75
|
-
writeFileSync(mixdogMdPath, DEFAULT_MIXDOG_MD, { encoding: 'utf8', mode: 0o600 });
|
|
76
|
-
}
|
|
77
|
-
for (const file of DEFAULT_DATA_FILES) {
|
|
78
|
-
const from = join(rootDir, 'defaults', file);
|
|
79
|
-
const to = join(dataDir, file);
|
|
80
|
-
if (!existsSync(from) || existsSync(to)) continue;
|
|
81
|
-
mkdirSync(dirname(to), { recursive: true });
|
|
82
|
-
copyFileSync(from, to);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function ensureProjectMixdogMd({ cwd } = {}) {
|
|
87
|
-
const projectRoot = resolveProjectRoot(cwd);
|
|
88
|
-
if (!projectRoot) return null;
|
|
89
|
-
const target = join(projectRoot, 'Mixdog.md');
|
|
90
|
-
if (!existsSync(target)) {
|
|
91
|
-
writeFileSync(target, DEFAULT_PROJECT_MIXDOG_MD, { encoding: 'utf8', mode: 0o600 });
|
|
92
|
-
}
|
|
93
|
-
return target;
|
|
94
17
|
}
|
|
@@ -122,6 +122,23 @@ function snapshotUsage(snapshot) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
function snapshotTokenUsage(snapshot) {
|
|
126
|
+
const value = snapshot?.tokenUsage;
|
|
127
|
+
if (!value || typeof value !== 'object') return null;
|
|
128
|
+
const inputTokens = num(value.inputTokens ?? value.input_tokens, 0);
|
|
129
|
+
const outputTokens = num(value.outputTokens ?? value.output_tokens, 0);
|
|
130
|
+
const cachedInputTokens = num(value.cachedInputTokens ?? value.cached_input_tokens, 0);
|
|
131
|
+
const requests = num(value.requests ?? value.numModelRequests ?? value.num_model_requests, 0);
|
|
132
|
+
if (!inputTokens && !outputTokens && !cachedInputTokens && !requests) return null;
|
|
133
|
+
return {
|
|
134
|
+
inputTokens,
|
|
135
|
+
outputTokens,
|
|
136
|
+
cachedInputTokens,
|
|
137
|
+
requests,
|
|
138
|
+
source: clean(value.source) || clean(snapshot?.source) || 'provider-api',
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
125
142
|
function displayWindow(w) {
|
|
126
143
|
const label = String(w?.label || 'USE').toUpperCase();
|
|
127
144
|
if (num(w?.remainingUsd, null) !== null) return `${label} ${money(w.remainingUsd)}`;
|
|
@@ -135,8 +152,8 @@ function displayWindow(w) {
|
|
|
135
152
|
|
|
136
153
|
function providerDescription(id, group) {
|
|
137
154
|
switch (String(id || '').toLowerCase()) {
|
|
138
|
-
case 'openai-oauth': return '
|
|
139
|
-
case 'anthropic-oauth': return '
|
|
155
|
+
case 'openai-oauth': return 'OpenAI OAuth subscription quota';
|
|
156
|
+
case 'anthropic-oauth': return 'Anthropic OAuth subscription quota';
|
|
140
157
|
case 'grok-oauth': return 'Grok Build subscription quota';
|
|
141
158
|
case 'opencode-go': return 'OpenCode Go subscription quota';
|
|
142
159
|
case 'openai': return 'OpenAI API billing';
|
|
@@ -150,6 +167,42 @@ function providerDescription(id, group) {
|
|
|
150
167
|
}
|
|
151
168
|
}
|
|
152
169
|
|
|
170
|
+
function snapshotUnavailable(snapshot) {
|
|
171
|
+
const value = snapshot?.unavailable;
|
|
172
|
+
return value && typeof value === 'object' ? value : null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function apiUnavailableDetail(id, snapshot) {
|
|
176
|
+
const providerId = String(id || '').toLowerCase();
|
|
177
|
+
const unavailable = snapshotUnavailable(snapshot);
|
|
178
|
+
const message = clean(unavailable?.message);
|
|
179
|
+
if (providerId === 'openai') {
|
|
180
|
+
if (/invalid|incorrect api key|unauthorized/i.test(message)) return `OpenAI usage probe failed: ${message}`;
|
|
181
|
+
if (/api\.usage\.read|insufficient permissions/i.test(message)) {
|
|
182
|
+
return 'OpenAI spend needs api.usage.read; remaining credit is web UI only';
|
|
183
|
+
}
|
|
184
|
+
if (message) return `OpenAI usage probe failed: ${message}; remaining credit is web UI only`;
|
|
185
|
+
return 'OpenAI API does not expose remaining credit; org spend needs api.usage.read';
|
|
186
|
+
}
|
|
187
|
+
if (providerId === 'anthropic') {
|
|
188
|
+
if (message) return `Anthropic cost probe: ${message}`;
|
|
189
|
+
return 'Anthropic balance is Console-only; usage needs ANTHROPIC_ADMIN_API_KEY';
|
|
190
|
+
}
|
|
191
|
+
if (providerId === 'gemini') return 'Gemini balance is AI Studio/Cloud Billing only; no key-scope probe';
|
|
192
|
+
if (providerId === 'xai') return message || 'xAI balance needs XAI_MANAGEMENT_API_KEY and XAI_TEAM_ID';
|
|
193
|
+
if (providerId === 'deepseek') return message ? `DeepSeek balance unavailable: ${message}` : 'DeepSeek balance unavailable';
|
|
194
|
+
return message || 'Usage not exposed';
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function applyApiUnavailable(row, id, snapshot) {
|
|
198
|
+
row.status = 'hidden';
|
|
199
|
+
row.source = snapshotUnavailable(snapshot) ? 'provider-api-unavailable' : 'provider-hidden';
|
|
200
|
+
row.sourceLabel = 'unavailable';
|
|
201
|
+
row.primary = '';
|
|
202
|
+
row.detail = apiUnavailableDetail(id, snapshot);
|
|
203
|
+
return row;
|
|
204
|
+
}
|
|
205
|
+
|
|
153
206
|
function rowTone(row) {
|
|
154
207
|
if (row.status === 'error') return 'error';
|
|
155
208
|
if (row.status === 'missing') return 'missing';
|
|
@@ -263,6 +316,19 @@ function applyKnownUsage(row, known) {
|
|
|
263
316
|
return row;
|
|
264
317
|
}
|
|
265
318
|
|
|
319
|
+
function applyTokenUsage(row, usage) {
|
|
320
|
+
if (!usage) return row;
|
|
321
|
+
const totalTokens = num(usage.inputTokens, 0) + num(usage.outputTokens, 0);
|
|
322
|
+
row.status = 'partial';
|
|
323
|
+
row.source = usage.source || 'provider-api';
|
|
324
|
+
row.sourceLabel = 'usage';
|
|
325
|
+
row.primary = `${compactNumber(totalTokens)} tokens`;
|
|
326
|
+
row.detail = `${compactNumber(usage.inputTokens)} in · ${compactNumber(usage.outputTokens)} out${usage.requests ? ` · ${compactNumber(usage.requests)} req` : ''}`;
|
|
327
|
+
row.includeInTotal = false;
|
|
328
|
+
row.totalBucket = null;
|
|
329
|
+
return row;
|
|
330
|
+
}
|
|
331
|
+
|
|
266
332
|
function applyWindowQuota(row, windows, { source = 'quota', detail = 'quota windows' } = {}) {
|
|
267
333
|
const normalized = normaliseWindows(windows, source);
|
|
268
334
|
if (!normalized.length) return false;
|
|
@@ -341,6 +407,7 @@ export async function createUsageDashboard(config = {}, options = {}) {
|
|
|
341
407
|
const rows = [];
|
|
342
408
|
const checkedAt = Date.now();
|
|
343
409
|
const refresh = options.refresh === true;
|
|
410
|
+
const preview = options.preview === true;
|
|
344
411
|
const emit = (checking = true) => emitUsageDashboard(
|
|
345
412
|
options,
|
|
346
413
|
usageDashboardSnapshot(rows, { checkedAt, refresh, checking }),
|
|
@@ -358,6 +425,10 @@ export async function createUsageDashboard(config = {}, options = {}) {
|
|
|
358
425
|
rows.push(row);
|
|
359
426
|
emit(true);
|
|
360
427
|
|
|
428
|
+
if (preview) {
|
|
429
|
+
return row;
|
|
430
|
+
}
|
|
431
|
+
|
|
361
432
|
if (!row.authenticated) {
|
|
362
433
|
row.status = 'missing';
|
|
363
434
|
row.source = 'not-configured';
|
|
@@ -366,6 +437,7 @@ export async function createUsageDashboard(config = {}, options = {}) {
|
|
|
366
437
|
row.detail = 'Configure auth';
|
|
367
438
|
} else {
|
|
368
439
|
let hasQuota = false;
|
|
440
|
+
let apiUsageSnapshot = null;
|
|
369
441
|
if (item.id === 'opencode-go') {
|
|
370
442
|
const usageStatus = openCodeGoUsageConfigStatus(config);
|
|
371
443
|
try {
|
|
@@ -400,9 +472,12 @@ export async function createUsageDashboard(config = {}, options = {}) {
|
|
|
400
472
|
}
|
|
401
473
|
} else {
|
|
402
474
|
const snapshot = await apiSnapshot(item.id, options);
|
|
475
|
+
apiUsageSnapshot = snapshot;
|
|
403
476
|
const known = snapshotRemaining(snapshot);
|
|
404
477
|
const usage = snapshotUsage(snapshot);
|
|
478
|
+
const tokenUsage = snapshotTokenUsage(snapshot);
|
|
405
479
|
const windows = normaliseWindows(snapshot?.quotaWindows, clean(snapshot?.source) || 'provider-api');
|
|
480
|
+
const estimated = localBudget(providerCfg);
|
|
406
481
|
row.updatedAt = num(snapshot?.cachedAt, null);
|
|
407
482
|
if (known) {
|
|
408
483
|
applyKnownRemaining(row, known, { estimated: false });
|
|
@@ -413,17 +488,26 @@ export async function createUsageDashboard(config = {}, options = {}) {
|
|
|
413
488
|
source: clean(snapshot?.source) || 'provider-api',
|
|
414
489
|
detail: 'provider quota',
|
|
415
490
|
});
|
|
491
|
+
} else if (estimated) {
|
|
492
|
+
applyKnownRemaining(row, estimated, { estimated: true });
|
|
493
|
+
hasQuota = true;
|
|
416
494
|
} else if (usage) {
|
|
417
495
|
applyKnownUsage(row, usage);
|
|
418
496
|
hasQuota = true;
|
|
497
|
+
} else if (tokenUsage) {
|
|
498
|
+
applyTokenUsage(row, tokenUsage);
|
|
499
|
+
hasQuota = true;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (!row.includeInTotal && !hasQuota) {
|
|
503
|
+
const estimated = localBudget(providerCfg);
|
|
504
|
+
if (estimated) {
|
|
505
|
+
applyKnownRemaining(row, estimated, { estimated: true });
|
|
506
|
+
hasQuota = true;
|
|
419
507
|
}
|
|
420
508
|
}
|
|
421
509
|
if (item.id !== 'opencode-go' && !row.includeInTotal && !hasQuota) {
|
|
422
|
-
row.
|
|
423
|
-
row.source = 'provider-hidden';
|
|
424
|
-
row.sourceLabel = 'hidden';
|
|
425
|
-
row.primary = '';
|
|
426
|
-
row.detail = 'Usage not exposed';
|
|
510
|
+
applyApiUnavailable(row, item.id, apiUsageSnapshot);
|
|
427
511
|
}
|
|
428
512
|
}
|
|
429
513
|
row.tone = rowTone(row);
|
|
@@ -443,6 +527,10 @@ export async function createUsageDashboard(config = {}, options = {}) {
|
|
|
443
527
|
rows.push(row);
|
|
444
528
|
emit(true);
|
|
445
529
|
|
|
530
|
+
if (preview) {
|
|
531
|
+
return row;
|
|
532
|
+
}
|
|
533
|
+
|
|
446
534
|
if (!row.authenticated) {
|
|
447
535
|
row.status = 'missing';
|
|
448
536
|
row.source = 'not-configured';
|
|
@@ -504,7 +592,7 @@ export async function createUsageDashboard(config = {}, options = {}) {
|
|
|
504
592
|
|
|
505
593
|
await Promise.all([...apiTasks, ...oauthTasks]);
|
|
506
594
|
|
|
507
|
-
const dashboard = usageDashboardSnapshot(rows, { checkedAt, refresh, checking:
|
|
595
|
+
const dashboard = usageDashboardSnapshot(rows, { checkedAt, refresh, checking: preview });
|
|
508
596
|
emitUsageDashboard(options, dashboard);
|
|
509
597
|
return dashboard;
|
|
510
598
|
}
|