mixdog 0.8.0 → 0.9.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/README.md +47 -23
- package/package.json +33 -27
- 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 +344 -0
- 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 +1223 -95
- 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 -7
- package/src/lib/rules-builder.cjs +240 -96
- package/src/lib/text-utils.cjs +1 -1
- package/src/mixdog-session-runtime.mjs +2325 -450
- 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 +118 -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 +377 -243
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +146 -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 +221 -70
- package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +477 -147
- package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +343 -496
- 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 +31 -11
- package/src/runtime/agent/orchestrator/providers/statusline-route-meta.mjs +41 -8
- package/src/runtime/agent/orchestrator/session/cache/post-edit-marks.mjs +4 -4
- package/src/runtime/agent/orchestrator/session/cache/read-cache.mjs +1 -1
- 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 +851 -674
- package/src/runtime/agent/orchestrator/session/manager.mjs +1593 -466
- package/src/runtime/agent/orchestrator/session/manager.reactive-persist.test.mjs +107 -0
- package/src/runtime/agent/orchestrator/session/store.mjs +291 -46
- 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 +34 -7
- package/src/runtime/agent/orchestrator/tools/builtin/advisory-lock.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +19 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +9 -9
- 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/snapshot-store.mjs +1 -1
- 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 +152 -24
- package/src/runtime/channels/lib/scheduler.mjs +18 -14
- package/src/runtime/channels/lib/session-discovery.mjs +3 -2
- package/src/runtime/channels/lib/tool-format.mjs +0 -2
- package/src/runtime/channels/lib/transcript-discovery.mjs +3 -2
- package/src/runtime/channels/lib/webhook.mjs +1 -1
- package/src/runtime/channels/tool-defs.mjs +29 -29
- package/src/runtime/memory/index.mjs +635 -107
- 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/memory-cycle1.mjs +38 -17
- package/src/runtime/memory/lib/memory-cycle2.mjs +6 -7
- package/src/runtime/memory/lib/memory-cycle3.mjs +4 -4
- package/src/runtime/memory/lib/memory-ops-policy.mjs +2 -1
- 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 +15 -1
- package/src/runtime/memory/lib/pg/supervisor.mjs +12 -0
- package/src/runtime/memory/lib/runtime-fetcher.mjs +37 -3
- package/src/runtime/memory/lib/session-ingest.mjs +194 -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 +102 -466
- package/src/runtime/search/lib/web-tools.mjs +45 -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 +145 -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 -98
- 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 +2 -69
- package/src/standalone/usage-dashboard.mjs +96 -8
- package/src/tui/App.jsx +4798 -2153
- package/src/tui/components/AnsiText.jsx +39 -28
- package/src/tui/components/ContextPanel.jsx +87 -29
- 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 +367 -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 +617 -368
- package/src/tui/components/TurnDone.jsx +3 -3
- package/src/tui/components/UsagePanel.jsx +3 -5
- package/src/tui/components/tool-output-format.mjs +365 -0
- package/src/tui/components/tool-output-format.test.mjs +220 -0
- package/src/tui/dist/index.mjs +8915 -2418
- 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 +511 -68
- package/src/tui/markdown/format-token.test.mjs +216 -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 +746 -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 +3 -16
- package/src/vendor/statusline/bin/statusline-lib.mjs +8 -4
- 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/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/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/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
|
@@ -32,12 +32,24 @@ const _LOCAL_TRACE_FLUSH_MS = 1000;
|
|
|
32
32
|
const _LOCAL_TRACE_MAX_BYTES = 10 * 1024 * 1024; // 10 MB — rotate to .1 above this.
|
|
33
33
|
const _TOOL_FAILURE_FLUSH_LINES = 50;
|
|
34
34
|
const _TOOL_FAILURE_FLUSH_MS = 1000;
|
|
35
|
+
const MIXDOG_SLOW_TOOL_TRACE_MS = (() => {
|
|
36
|
+
const v = parseInt(process.env.MIXDOG_SLOW_TOOL_TRACE_MS, 10);
|
|
37
|
+
return Number.isFinite(v) && v > 0 ? v : 3000;
|
|
38
|
+
})();
|
|
39
|
+
const MIXDOG_SLOW_TOOL_TRACE_NAMES_RAW = String(process.env.MIXDOG_SLOW_TOOL_TRACE_NAMES || 'recall,grep,code_graph');
|
|
40
|
+
const MIXDOG_SLOW_TOOL_TRACE_ALL = MIXDOG_SLOW_TOOL_TRACE_NAMES_RAW.trim() === '*';
|
|
41
|
+
const MIXDOG_SLOW_TOOL_TRACE_NAMES = new Set(
|
|
42
|
+
MIXDOG_SLOW_TOOL_TRACE_NAMES_RAW
|
|
43
|
+
.split(',')
|
|
44
|
+
.map((name) => name.trim())
|
|
45
|
+
.filter(Boolean)
|
|
46
|
+
);
|
|
35
47
|
// Throttle interval for local rotation stat checks. statSync on every flush
|
|
36
48
|
// is unnecessary — rotation is a best-effort size guard. First flush always
|
|
37
49
|
// checks; subsequent checks wait at least this many ms. Tune via env
|
|
38
|
-
//
|
|
39
|
-
const
|
|
40
|
-
const v = parseInt(process.env.
|
|
50
|
+
// MIXDOG_AGENT_TRACE_ROTATE_CHECK_MS (default 60000 ms, positive integer).
|
|
51
|
+
const MIXDOG_AGENT_TRACE_ROTATE_CHECK_MS = (() => {
|
|
52
|
+
const v = parseInt(process.env.MIXDOG_AGENT_TRACE_ROTATE_CHECK_MS, 10);
|
|
41
53
|
return Number.isFinite(v) && v > 0 ? v : 60000;
|
|
42
54
|
})();
|
|
43
55
|
let _lastRotateCheckMs = 0;
|
|
@@ -49,7 +61,7 @@ function _rotateLocalTraceIfNeeded(path) {
|
|
|
49
61
|
if (stat && stat.size > _LOCAL_TRACE_MAX_BYTES) {
|
|
50
62
|
try { renameSync(path, `${path}.1`); }
|
|
51
63
|
catch (err) {
|
|
52
|
-
|
|
64
|
+
warnAgentOnce('agent-trace:local-rotate', `[agent-trace] local rotate failed (${err?.message})`);
|
|
53
65
|
}
|
|
54
66
|
}
|
|
55
67
|
} catch {
|
|
@@ -58,11 +70,11 @@ function _rotateLocalTraceIfNeeded(path) {
|
|
|
58
70
|
}
|
|
59
71
|
|
|
60
72
|
function _resolveLocalTracePath() {
|
|
61
|
-
if (process.env.
|
|
73
|
+
if (process.env.MIXDOG_AGENT_TRACE_LOCAL_DISABLE === '1') return null;
|
|
62
74
|
if (_localTracePath) return _localTracePath;
|
|
63
75
|
try {
|
|
64
|
-
_localTracePath = process.env.
|
|
65
|
-
|| join(getPluginData(), 'history', '
|
|
76
|
+
_localTracePath = process.env.MIXDOG_AGENT_TRACE_PATH
|
|
77
|
+
|| join(getPluginData(), 'history', 'agent-trace.jsonl');
|
|
66
78
|
// R4 data-at-rest: trace rows may carry tool payloads / prompts;
|
|
67
79
|
// clamp dir to owner-only on POSIX (advisory on Windows).
|
|
68
80
|
mkdirSync(dirname(_localTracePath), { recursive: true, mode: 0o700 });
|
|
@@ -83,7 +95,7 @@ function _appendLocalTrace(row) {
|
|
|
83
95
|
_localTraceTimer.unref?.();
|
|
84
96
|
}
|
|
85
97
|
} catch (err) {
|
|
86
|
-
|
|
98
|
+
warnAgentOnce('agent-trace:local-spool', `[agent-trace] local spool failed (${err?.message})`);
|
|
87
99
|
}
|
|
88
100
|
}
|
|
89
101
|
|
|
@@ -106,12 +118,12 @@ function _flushLocalTrace() {
|
|
|
106
118
|
// Throttle rotation stat checks to avoid unnecessary statSync calls
|
|
107
119
|
// on every flush. First flush (_lastRotateCheckMs === 0) always checks.
|
|
108
120
|
const now = Date.now();
|
|
109
|
-
if (_lastRotateCheckMs === 0 || now - _lastRotateCheckMs >=
|
|
121
|
+
if (_lastRotateCheckMs === 0 || now - _lastRotateCheckMs >= MIXDOG_AGENT_TRACE_ROTATE_CHECK_MS) {
|
|
110
122
|
_rotateLocalTraceIfNeeded(path);
|
|
111
123
|
_lastRotateCheckMs = now;
|
|
112
124
|
}
|
|
113
125
|
} catch (err) {
|
|
114
|
-
|
|
126
|
+
warnAgentOnce('agent-trace:local-spool', `[agent-trace] local spool failed (${err?.message})`);
|
|
115
127
|
return;
|
|
116
128
|
}
|
|
117
129
|
// mode only applies on file creation; existing files keep their mode.
|
|
@@ -119,7 +131,7 @@ function _flushLocalTrace() {
|
|
|
119
131
|
_localTraceFlushInFlight = true;
|
|
120
132
|
appendFile(path, chunk, { encoding: 'utf8', mode: 0o600 })
|
|
121
133
|
.catch((err) => {
|
|
122
|
-
|
|
134
|
+
warnAgentOnce('agent-trace:local-spool', `[agent-trace] local spool failed (${err?.message})`);
|
|
123
135
|
})
|
|
124
136
|
.finally(() => {
|
|
125
137
|
_localTraceFlushInFlight = false;
|
|
@@ -142,13 +154,13 @@ function _flushLocalTraceSync() {
|
|
|
142
154
|
_localTraceBuffer = [];
|
|
143
155
|
try {
|
|
144
156
|
const now = Date.now();
|
|
145
|
-
if (_lastRotateCheckMs === 0 || now - _lastRotateCheckMs >=
|
|
157
|
+
if (_lastRotateCheckMs === 0 || now - _lastRotateCheckMs >= MIXDOG_AGENT_TRACE_ROTATE_CHECK_MS) {
|
|
146
158
|
_rotateLocalTraceIfNeeded(path);
|
|
147
159
|
_lastRotateCheckMs = now;
|
|
148
160
|
}
|
|
149
161
|
appendFileSync(path, chunk, { encoding: 'utf8', mode: 0o600 });
|
|
150
162
|
} catch (err) {
|
|
151
|
-
|
|
163
|
+
warnAgentOnce('agent-trace:local-spool', `[agent-trace] local spool failed (${err?.message})`);
|
|
152
164
|
}
|
|
153
165
|
}
|
|
154
166
|
|
|
@@ -187,7 +199,7 @@ async function _flush() {
|
|
|
187
199
|
_flushTimer = null;
|
|
188
200
|
if (_buffer.length === 0) return;
|
|
189
201
|
if (_flushInFlight) {
|
|
190
|
-
if (!_flushTimer) _flushTimer = setTimeout(_flush, _FLUSH_INTERVAL_MS);
|
|
202
|
+
if (!_flushTimer) { _flushTimer = setTimeout(_flush, _FLUSH_INTERVAL_MS); _flushTimer.unref?.(); }
|
|
191
203
|
return;
|
|
192
204
|
}
|
|
193
205
|
_flushInFlight = true;
|
|
@@ -195,7 +207,7 @@ async function _flush() {
|
|
|
195
207
|
const url = _resolveServiceUrl();
|
|
196
208
|
if (!url) {
|
|
197
209
|
// Service not up yet — keep buffer, retry next timer tick
|
|
198
|
-
if (!_flushTimer) _flushTimer = setTimeout(_flush, _FLUSH_INTERVAL_MS);
|
|
210
|
+
if (!_flushTimer) { _flushTimer = setTimeout(_flush, _FLUSH_INTERVAL_MS); _flushTimer.unref?.(); }
|
|
199
211
|
return;
|
|
200
212
|
}
|
|
201
213
|
const batch = _buffer.splice(0, _FLUSH_BATCH_SIZE);
|
|
@@ -206,12 +218,17 @@ async function _flush() {
|
|
|
206
218
|
body: JSON.stringify({ events: batch }),
|
|
207
219
|
signal: AbortSignal.timeout(5000),
|
|
208
220
|
});
|
|
221
|
+
// Always drain the body. An undrained response body keeps the
|
|
222
|
+
// underlying keep-alive socket referenced, which can hold the event
|
|
223
|
+
// loop open and make a short-lived process (smoke scripts / one-shot
|
|
224
|
+
// agent tasks) appear to hang for seconds after its work is done.
|
|
225
|
+
try { await resp.arrayBuffer(); } catch { /* body already gone */ }
|
|
209
226
|
if (!resp.ok) {
|
|
210
|
-
|
|
227
|
+
warnAgentOnce('agent-trace:flush-error', `[agent-trace] /admin/trace-record returned ${resp.status} — dropping batch`);
|
|
211
228
|
}
|
|
212
229
|
} catch (err) {
|
|
213
230
|
_serviceUrl = null;
|
|
214
|
-
|
|
231
|
+
warnAgentOnce('agent-trace:flush-fetch', `[agent-trace] flush fetch failed (${err?.message}) — dropping batch`);
|
|
215
232
|
}
|
|
216
233
|
if (_buffer.length >= _FLUSH_BATCH_SIZE) {
|
|
217
234
|
// More pending — schedule another flush immediately
|
|
@@ -228,25 +245,31 @@ function _scheduleFlush(immediate = false) {
|
|
|
228
245
|
setImmediate(_flush);
|
|
229
246
|
} else if (!_flushTimer) {
|
|
230
247
|
_flushTimer = setTimeout(_flush, _FLUSH_INTERVAL_MS);
|
|
248
|
+
// Never let the periodic trace flush keep the event loop alive: a
|
|
249
|
+
// ref'd 5s timer prevented short-lived processes (smoke scripts, agent
|
|
250
|
+
// tasks) from exiting naturally after their work was done — they hung
|
|
251
|
+
// until an external timeout/kill. exit/beforeExit drains still flush
|
|
252
|
+
// the buffer, so unref loses no data.
|
|
253
|
+
_flushTimer.unref?.();
|
|
231
254
|
}
|
|
232
255
|
}
|
|
233
256
|
|
|
234
|
-
async function
|
|
257
|
+
async function drainAgentTrace() {
|
|
235
258
|
if (!_resolveServiceUrl()) return;
|
|
236
259
|
if (_flushTimer) { clearTimeout(_flushTimer); _flushTimer = null; }
|
|
237
260
|
for (let i = 0; i < 10 && _buffer.length > 0; i++) {
|
|
238
261
|
await _flush();
|
|
239
262
|
}
|
|
240
263
|
}
|
|
241
|
-
process.on('exit',
|
|
264
|
+
process.on('exit', drainAgentTrace);
|
|
242
265
|
|
|
243
266
|
function normalizeSessionId(sessionId) {
|
|
244
267
|
return sessionId ? String(sessionId) : 'no-session';
|
|
245
268
|
}
|
|
246
269
|
|
|
247
|
-
function
|
|
270
|
+
function appendAgentTrace(record = {}) {
|
|
248
271
|
// Test isolation — when run-all-tests.mjs sets this env, skip entirely.
|
|
249
|
-
if (process.env.
|
|
272
|
+
if (process.env.MIXDOG_AGENT_TRACE_DISABLE === '1') return;
|
|
250
273
|
try {
|
|
251
274
|
// Coerce ts to epoch ms integer at enqueue time
|
|
252
275
|
let ts = record.ts || Date.now();
|
|
@@ -265,14 +288,14 @@ function appendBridgeTrace(record = {}) {
|
|
|
265
288
|
|
|
266
289
|
if (_buffer.length >= _BUFFER_MAX) {
|
|
267
290
|
_buffer.shift(); // drop oldest
|
|
268
|
-
|
|
291
|
+
warnAgentOnce('agent-trace:buffer-full', '[agent-trace] buffer full (2000) — dropping oldest event');
|
|
269
292
|
}
|
|
270
293
|
_appendLocalTrace(row);
|
|
271
294
|
_buffer.push(row);
|
|
272
295
|
_scheduleFlush(_buffer.length >= _FLUSH_BATCH_SIZE);
|
|
273
296
|
}
|
|
274
297
|
catch {
|
|
275
|
-
// Never break
|
|
298
|
+
// Never break agent execution for telemetry
|
|
276
299
|
}
|
|
277
300
|
}
|
|
278
301
|
|
|
@@ -299,7 +322,7 @@ function extractCachedTokens(usage) {
|
|
|
299
322
|
return 0;
|
|
300
323
|
}
|
|
301
324
|
|
|
302
|
-
function
|
|
325
|
+
function warnAgentOnce(key, message) {
|
|
303
326
|
if (!key || WARNED_KEYS.has(key)) return;
|
|
304
327
|
WARNED_KEYS.add(key);
|
|
305
328
|
try {
|
|
@@ -310,9 +333,9 @@ function warnBridgeOnce(key, message) {
|
|
|
310
333
|
}
|
|
311
334
|
}
|
|
312
335
|
|
|
313
|
-
function
|
|
314
|
-
if (process.env.
|
|
315
|
-
|
|
336
|
+
function traceAgentLoop({ sessionId, iteration, sendMs, messageCount, bodyBytesEst }) {
|
|
337
|
+
if (process.env.MIXDOG_AGENT_TRACE_VERBOSE !== '1') return;
|
|
338
|
+
appendAgentTrace({
|
|
316
339
|
sessionId,
|
|
317
340
|
iteration,
|
|
318
341
|
kind: 'loop',
|
|
@@ -336,10 +359,11 @@ function messagePrefixHash(messages) {
|
|
|
336
359
|
}
|
|
337
360
|
}
|
|
338
361
|
|
|
339
|
-
function
|
|
362
|
+
function traceAgentCompact({
|
|
340
363
|
sessionId,
|
|
341
364
|
iteration,
|
|
342
365
|
stage,
|
|
366
|
+
trigger,
|
|
343
367
|
prune_count,
|
|
344
368
|
compact_changed,
|
|
345
369
|
input_prefix_hash,
|
|
@@ -356,12 +380,13 @@ function traceBridgeCompact({
|
|
|
356
380
|
error,
|
|
357
381
|
error_code,
|
|
358
382
|
}) {
|
|
359
|
-
if (process.env.
|
|
360
|
-
|
|
383
|
+
if (process.env.MIXDOG_AGENT_TRACE_VERBOSE !== '1') return;
|
|
384
|
+
appendAgentTrace({
|
|
361
385
|
sessionId,
|
|
362
386
|
iteration,
|
|
363
387
|
kind: 'compact_meta',
|
|
364
388
|
stage: stage || null,
|
|
389
|
+
trigger: trigger || null,
|
|
365
390
|
prune_count: prune_count ?? 0,
|
|
366
391
|
compact_changed: !!compact_changed,
|
|
367
392
|
input_prefix_hash: input_prefix_hash || null,
|
|
@@ -383,8 +408,12 @@ function traceBridgeCompact({
|
|
|
383
408
|
const TOOL_ARG_KEYS = {
|
|
384
409
|
read: ['path', 'offset', 'limit', 'line', 'context', 'symbol'],
|
|
385
410
|
grep: ['pattern', 'path', 'glob', 'output_mode', 'head_limit', 'offset'],
|
|
386
|
-
glob: ['pattern', 'path', 'head_limit', 'offset'],
|
|
387
|
-
|
|
411
|
+
glob: ['pattern', 'path', 'head_limit', 'offset', 'sort'],
|
|
412
|
+
find: ['query', 'path', 'head_limit'],
|
|
413
|
+
list: ['path', 'head_limit', 'offset'],
|
|
414
|
+
recall: ['query', 'limit', 'session_id', 'cwd'],
|
|
415
|
+
search: ['query', 'limit', 'cwd'],
|
|
416
|
+
explore: ['query', 'queries', 'limit', 'cwd'],
|
|
388
417
|
code_graph: ['mode', 'file', 'symbol', 'symbols', 'body', 'language', 'limit', 'depth', 'page', 'cwd'],
|
|
389
418
|
shell: ['command', 'cwd', 'timeout', 'mode', 'run_in_background', 'persistent', 'session_id'],
|
|
390
419
|
task: ['task_id', 'action', 'timeout_ms', 'poll_ms'],
|
|
@@ -480,7 +509,7 @@ function _scheduleToolFailureFlush(delayMs = _TOOL_FAILURE_FLUSH_MS) {
|
|
|
480
509
|
|
|
481
510
|
function _maybeRotateToolFailureLog(path) {
|
|
482
511
|
const now = Date.now();
|
|
483
|
-
if (_lastToolFailureRotateCheckMs !== 0 && now - _lastToolFailureRotateCheckMs <
|
|
512
|
+
if (_lastToolFailureRotateCheckMs !== 0 && now - _lastToolFailureRotateCheckMs < MIXDOG_AGENT_TRACE_ROTATE_CHECK_MS) return;
|
|
484
513
|
_rotateLocalTraceIfNeeded(path);
|
|
485
514
|
_lastToolFailureRotateCheckMs = now;
|
|
486
515
|
}
|
|
@@ -495,7 +524,7 @@ function _appendToolFailureRow(row) {
|
|
|
495
524
|
_scheduleToolFailureFlush();
|
|
496
525
|
}
|
|
497
526
|
} catch (err) {
|
|
498
|
-
|
|
527
|
+
warnAgentOnce('tool-failure-log:append', `[tool-failure-log] append failed (${err?.message})`);
|
|
499
528
|
}
|
|
500
529
|
}
|
|
501
530
|
|
|
@@ -516,12 +545,12 @@ function _flushToolFailures() {
|
|
|
516
545
|
try {
|
|
517
546
|
_maybeRotateToolFailureLog(path);
|
|
518
547
|
} catch (err) {
|
|
519
|
-
|
|
548
|
+
warnAgentOnce('tool-failure-log:rotate', `[tool-failure-log] rotate check failed (${err?.message})`);
|
|
520
549
|
}
|
|
521
550
|
_toolFailureFlushInFlight = true;
|
|
522
551
|
appendFile(path, chunk, { encoding: 'utf8', mode: 0o600 })
|
|
523
552
|
.catch((err) => {
|
|
524
|
-
|
|
553
|
+
warnAgentOnce('tool-failure-log:append', `[tool-failure-log] append failed (${err?.message})`);
|
|
525
554
|
})
|
|
526
555
|
.finally(() => {
|
|
527
556
|
_toolFailureFlushInFlight = false;
|
|
@@ -543,7 +572,7 @@ function _flushToolFailuresSync() {
|
|
|
543
572
|
_maybeRotateToolFailureLog(path);
|
|
544
573
|
appendFileSync(path, chunk, { encoding: 'utf8', mode: 0o600 });
|
|
545
574
|
} catch (err) {
|
|
546
|
-
|
|
575
|
+
warnAgentOnce('tool-failure-log:append', `[tool-failure-log] append failed (${err?.message})`);
|
|
547
576
|
}
|
|
548
577
|
}
|
|
549
578
|
|
|
@@ -572,8 +601,8 @@ function classifyToolFailure(resultText, toolName) {
|
|
|
572
601
|
return 'runtime/failure';
|
|
573
602
|
}
|
|
574
603
|
|
|
575
|
-
function
|
|
576
|
-
if (process.env.
|
|
604
|
+
function traceAgentToolFailure({ sessionId, iteration, toolName, toolKind, toolMs, toolArgs, role, model, cwd, resultText, resultKind = 'error' }) {
|
|
605
|
+
if (process.env.MIXDOG_AGENT_TRACE_DISABLE === '1') return;
|
|
577
606
|
if (!_resolveToolFailurePath()) return;
|
|
578
607
|
try {
|
|
579
608
|
const cleanText = _redactLogText(String(resultText ?? ''));
|
|
@@ -597,17 +626,21 @@ function traceBridgeToolFailure({ sessionId, iteration, toolName, toolKind, tool
|
|
|
597
626
|
};
|
|
598
627
|
_appendToolFailureRow(row);
|
|
599
628
|
} catch (err) {
|
|
600
|
-
|
|
629
|
+
warnAgentOnce('tool-failure-log:append', `[tool-failure-log] append failed (${err?.message})`);
|
|
601
630
|
}
|
|
602
631
|
}
|
|
603
632
|
|
|
604
|
-
function
|
|
633
|
+
function traceAgentTool({ sessionId, iteration, toolName, toolKind, toolMs, toolArgs, role, resultKind, model, resultText, cwd }) {
|
|
605
634
|
const nextCallCount = countJsonNextCalls(resultText);
|
|
606
|
-
|
|
607
|
-
|
|
635
|
+
const resultBytesEst = typeof resultText === 'string' ? Buffer.byteLength(resultText, 'utf8') : 0;
|
|
636
|
+
const resultLinesEst = typeof resultText === 'string' && resultText.length > 0 ? resultText.split('\n').length : 0;
|
|
637
|
+
const numericToolMs = Number(toolMs);
|
|
638
|
+
const summarizedArgs = summarizeToolArgs(toolName, toolArgs);
|
|
639
|
+
// Flat shape — fields named exactly as the agent_calls PG columns so
|
|
640
|
+
// insertAgentCalls can pick them up by direct property access without
|
|
608
641
|
// a payload-unwrap step. result_kind has no column and rides as plain
|
|
609
642
|
// sibling metadata for downstream consumers.
|
|
610
|
-
|
|
643
|
+
appendAgentTrace({
|
|
611
644
|
sessionId,
|
|
612
645
|
iteration,
|
|
613
646
|
kind: 'tool',
|
|
@@ -616,15 +649,41 @@ function traceBridgeTool({ sessionId, iteration, toolName, toolKind, toolMs, too
|
|
|
616
649
|
tool_name: toolName,
|
|
617
650
|
tool_kind: toolKind,
|
|
618
651
|
tool_ms: toolMs,
|
|
619
|
-
tool_args:
|
|
652
|
+
tool_args: summarizedArgs,
|
|
620
653
|
result_kind: resultKind || null,
|
|
621
654
|
result_has_next_call: nextCallCount > 0,
|
|
622
655
|
result_next_call_count: nextCallCount,
|
|
623
|
-
result_bytes_est:
|
|
624
|
-
result_lines_est:
|
|
656
|
+
result_bytes_est: resultBytesEst,
|
|
657
|
+
result_lines_est: resultLinesEst,
|
|
625
658
|
});
|
|
659
|
+
if (
|
|
660
|
+
Number.isFinite(numericToolMs)
|
|
661
|
+
&& numericToolMs >= MIXDOG_SLOW_TOOL_TRACE_MS
|
|
662
|
+
&& (MIXDOG_SLOW_TOOL_TRACE_ALL || MIXDOG_SLOW_TOOL_TRACE_NAMES.size === 0 || MIXDOG_SLOW_TOOL_TRACE_NAMES.has(String(toolName || '')))
|
|
663
|
+
) {
|
|
664
|
+
appendAgentTrace({
|
|
665
|
+
sessionId,
|
|
666
|
+
iteration,
|
|
667
|
+
kind: 'tool_slow',
|
|
668
|
+
role: role || null,
|
|
669
|
+
model: model || null,
|
|
670
|
+
tool_name: toolName,
|
|
671
|
+
tool_kind: toolKind,
|
|
672
|
+
tool_ms: numericToolMs,
|
|
673
|
+
payload: {
|
|
674
|
+
threshold_ms: MIXDOG_SLOW_TOOL_TRACE_MS,
|
|
675
|
+
result_kind: resultKind || null,
|
|
676
|
+
tool_args: summarizedArgs,
|
|
677
|
+
result_has_next_call: nextCallCount > 0,
|
|
678
|
+
result_next_call_count: nextCallCount,
|
|
679
|
+
result_bytes_est: resultBytesEst,
|
|
680
|
+
result_lines_est: resultLinesEst,
|
|
681
|
+
cwd: cwd || null,
|
|
682
|
+
},
|
|
683
|
+
});
|
|
684
|
+
}
|
|
626
685
|
if (resultKind === 'error') {
|
|
627
|
-
|
|
686
|
+
traceAgentToolFailure({ sessionId, iteration, toolName, toolKind, toolMs, toolArgs, role, model, cwd, resultText, resultKind });
|
|
628
687
|
}
|
|
629
688
|
}
|
|
630
689
|
|
|
@@ -632,13 +691,13 @@ function traceBridgeTool({ sessionId, iteration, toolName, toolKind, toolMs, too
|
|
|
632
691
|
// where compression actually changed the byte count, so `gain` analytics
|
|
633
692
|
// can sum savings_pct over a window (mirrors RTK's `rtk gain` model
|
|
634
693
|
// without an external binary). No-op rows are dropped at the call site.
|
|
635
|
-
export function
|
|
694
|
+
export function traceAgentCompress({ sessionId, toolName, before, after }) {
|
|
636
695
|
// bytes_before/after/savings_pct moved into payload because the
|
|
637
696
|
// trace_events table only carries known top-level columns (id, ts,
|
|
638
697
|
// session_id, kind, tool_name, payload, ...) — fields outside that
|
|
639
698
|
// set are silently dropped at insert time. payload is jsonb so any
|
|
640
699
|
// shape survives. Aggregation: SELECT (payload->>'bytes_before')::int.
|
|
641
|
-
|
|
700
|
+
appendAgentTrace({
|
|
642
701
|
sessionId,
|
|
643
702
|
kind: 'compress',
|
|
644
703
|
tool_name: toolName,
|
|
@@ -654,24 +713,16 @@ export function traceBridgeCompress({ sessionId, toolName, before, after }) {
|
|
|
654
713
|
// tool calls observed. Lets a consumer compute Lead-side multi-tool
|
|
655
714
|
// adoption ratio (calls > 1 / total turns) directly from trace rows
|
|
656
715
|
// instead of re-parsing every assistant message body.
|
|
657
|
-
export function
|
|
658
|
-
|
|
716
|
+
export function traceAgentBatch({ sessionId, toolCallCount }) {
|
|
717
|
+
appendAgentTrace({
|
|
659
718
|
sessionId,
|
|
660
719
|
kind: 'batch',
|
|
661
720
|
tool_call_count: toolCallCount,
|
|
662
721
|
});
|
|
663
722
|
}
|
|
664
723
|
|
|
665
|
-
function _sanitizeSample(sample) {
|
|
666
|
-
if (sample == null) return sample;
|
|
667
|
-
if (typeof sample === 'string' || typeof sample === 'object') {
|
|
668
|
-
return compactTraceArgValue(sample, '', 0);
|
|
669
|
-
}
|
|
670
|
-
return sample;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
724
|
function traceStreamStalled({ sessionId, info }) {
|
|
674
|
-
|
|
725
|
+
appendAgentTrace({
|
|
675
726
|
sessionId,
|
|
676
727
|
kind: 'stream_stalled',
|
|
677
728
|
stale_seconds: info.staleSeconds,
|
|
@@ -681,7 +732,7 @@ function traceStreamStalled({ sessionId, info }) {
|
|
|
681
732
|
}
|
|
682
733
|
|
|
683
734
|
function traceStreamAborted({ sessionId, info }) {
|
|
684
|
-
|
|
735
|
+
appendAgentTrace({
|
|
685
736
|
sessionId,
|
|
686
737
|
kind: 'stream_aborted',
|
|
687
738
|
stale_seconds: info.staleSeconds,
|
|
@@ -690,12 +741,12 @@ function traceStreamAborted({ sessionId, info }) {
|
|
|
690
741
|
});
|
|
691
742
|
}
|
|
692
743
|
|
|
693
|
-
function
|
|
744
|
+
function traceAgentPreset({ sessionId, role, presetName, model, provider, parentSessionId }) {
|
|
694
745
|
// Fires once per dispatch right after the preset has been resolved and
|
|
695
746
|
// its runtime spec (provider/model) assembled. Useful for after-the-fact
|
|
696
747
|
// routing analysis: "which role landed on which preset / provider / model
|
|
697
748
|
// on this request?"
|
|
698
|
-
|
|
749
|
+
appendAgentTrace({
|
|
699
750
|
sessionId,
|
|
700
751
|
kind: 'preset_assign',
|
|
701
752
|
role: role || null,
|
|
@@ -706,7 +757,7 @@ function traceBridgePreset({ sessionId, role, presetName, model, provider, paren
|
|
|
706
757
|
});
|
|
707
758
|
}
|
|
708
759
|
|
|
709
|
-
function
|
|
760
|
+
function traceAgentFetch({ sessionId, headersMs, httpStatus, handshakeRetries, handshakeRetryClassifiers, provider, model, transport }) {
|
|
710
761
|
const payload = {
|
|
711
762
|
headers_ms: headersMs,
|
|
712
763
|
http_status: httpStatus,
|
|
@@ -720,7 +771,7 @@ function traceBridgeFetch({ sessionId, headersMs, httpStatus, handshakeRetries,
|
|
|
720
771
|
if (Array.isArray(handshakeRetryClassifiers) && handshakeRetryClassifiers.length > 0) {
|
|
721
772
|
payload.handshake_retry_classifiers = handshakeRetryClassifiers;
|
|
722
773
|
}
|
|
723
|
-
|
|
774
|
+
appendAgentTrace({
|
|
724
775
|
sessionId,
|
|
725
776
|
kind: 'fetch',
|
|
726
777
|
headers_ms: headersMs,
|
|
@@ -734,8 +785,8 @@ function traceBridgeFetch({ sessionId, headersMs, httpStatus, handshakeRetries,
|
|
|
734
785
|
});
|
|
735
786
|
}
|
|
736
787
|
|
|
737
|
-
function
|
|
738
|
-
|
|
788
|
+
function traceAgentSse({ sessionId, sseParseMs, ttftMs, provider, model, transport }) {
|
|
789
|
+
appendAgentTrace({
|
|
739
790
|
sessionId,
|
|
740
791
|
kind: 'sse',
|
|
741
792
|
sse_parse_ms: sseParseMs,
|
|
@@ -753,7 +804,7 @@ function traceBridgeSse({ sessionId, sseParseMs, ttftMs, provider, model, transp
|
|
|
753
804
|
});
|
|
754
805
|
}
|
|
755
806
|
|
|
756
|
-
function
|
|
807
|
+
function traceAgentUsage({ sessionId, iteration, inputTokens, outputTokens, cachedTokens, cacheWriteTokens, promptTokens, model, modelDisplay, responseId, rawUsage, provider, serviceTier, requestKind }) {
|
|
757
808
|
const inclusive = isInclusiveProvider(provider);
|
|
758
809
|
const inTok = inputTokens || 0;
|
|
759
810
|
const cacheRead = cachedTokens || 0;
|
|
@@ -765,7 +816,7 @@ function traceBridgeUsage({ sessionId, iteration, inputTokens, outputTokens, cac
|
|
|
765
816
|
? Math.max(inTok, cacheRead + cacheWrite)
|
|
766
817
|
: inTok + cacheRead + cacheWrite);
|
|
767
818
|
const resolvedServiceTier = serviceTier || rawUsage?.service_tier || rawUsage?.serviceTier || null;
|
|
768
|
-
|
|
819
|
+
appendAgentTrace({
|
|
769
820
|
sessionId,
|
|
770
821
|
iteration,
|
|
771
822
|
kind: 'usage_raw',
|
|
@@ -795,20 +846,20 @@ function traceBridgeUsage({ sessionId, iteration, inputTokens, outputTokens, cac
|
|
|
795
846
|
}
|
|
796
847
|
|
|
797
848
|
export {
|
|
798
|
-
|
|
799
|
-
|
|
849
|
+
appendAgentTrace,
|
|
850
|
+
drainAgentTrace,
|
|
800
851
|
estimateProviderPayloadBytes,
|
|
801
852
|
extractCachedTokens,
|
|
802
853
|
messagePrefixHash,
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
854
|
+
traceAgentFetch,
|
|
855
|
+
traceAgentLoop,
|
|
856
|
+
traceAgentPreset,
|
|
857
|
+
traceAgentSse,
|
|
858
|
+
traceAgentTool,
|
|
859
|
+
traceAgentToolFailure,
|
|
860
|
+
traceAgentCompact,
|
|
861
|
+
traceAgentUsage,
|
|
811
862
|
traceStreamAborted,
|
|
812
863
|
traceStreamStalled,
|
|
813
|
-
|
|
864
|
+
warnAgentOnce,
|
|
814
865
|
};
|
|
@@ -1,26 +1,5 @@
|
|
|
1
1
|
import { statSync, readdirSync } from 'fs';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Return the maximum mtimeMs across all given paths.
|
|
5
|
-
* Missing / unreadable paths are silently skipped (treated as mtime 0).
|
|
6
|
-
* Pass file paths or directory paths; statSync on a directory returns the
|
|
7
|
-
* mtime of the directory entry itself (updated when children are
|
|
8
|
-
* added/removed), while file mtime covers content changes.
|
|
9
|
-
* Use maxMtimeRecursive for cases where file-content edits within a
|
|
10
|
-
* directory must also invalidate the cache (parent dir mtime is unchanged
|
|
11
|
-
* on Linux/macOS when only a file's content changes).
|
|
12
|
-
*
|
|
13
|
-
* @param {string[]} paths
|
|
14
|
-
* @returns {number}
|
|
15
|
-
*/
|
|
16
|
-
export function maxMtime(paths) {
|
|
17
|
-
let max = 0;
|
|
18
|
-
for (const p of paths) {
|
|
19
|
-
try { const m = statSync(p).mtimeMs; if (m > max) max = m; } catch { /* missing — skip */ }
|
|
20
|
-
}
|
|
21
|
-
return max;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
3
|
/**
|
|
25
4
|
* Return the maximum mtimeMs across all given paths, recursing into
|
|
26
5
|
* directories up to `depth` levels. Directory entries contribute their own
|