mixdog 0.9.152 → 0.9.154
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/LICENSES/browser-import-NOTICE.txt +11 -0
- package/NOTICE.md +11 -0
- package/README.md +8 -10
- package/package.json +19 -3
- package/scripts/computer-task-cost-report.mjs +144 -0
- package/scripts/run-office-live-tests.mjs +32 -0
- package/src/agents/front-worker/AGENT.md +13 -0
- package/src/agents/front-worker/agent.json +6 -0
- package/src/agents/heavy-worker/AGENT.md +10 -11
- package/src/agents/heavy-worker/agent.json +1 -1
- package/src/agents/maintainer/AGENT.md +0 -2
- package/src/agents/reviewer/AGENT.md +9 -13
- package/src/agents/reviewer/agent.json +1 -1
- package/src/agents/security/AGENT.md +14 -0
- package/src/agents/security/agent.json +6 -0
- package/src/agents/worker/AGENT.md +8 -8
- package/src/agents/worker/agent.json +1 -1
- package/src/agents/writer/AGENT.md +14 -0
- package/src/agents/writer/agent.json +6 -0
- package/src/rules/agent/00-common.md +4 -7
- package/src/rules/lead/01-general.md +0 -3
- package/src/rules/shared/10-tool-workflow.md +10 -2
- package/src/rules/shared/60-verification.md +2 -0
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +183 -26
- package/src/runtime/agent/orchestrator/agent-runtime/session-builder.mjs +4 -0
- package/src/runtime/agent/orchestrator/cache-break-trace.mjs +109 -0
- package/src/runtime/agent/orchestrator/config.mjs +7 -2
- package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +16 -3
- package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +9 -1
- package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +30 -9
- package/src/runtime/agent/orchestrator/providers/openai-codex-metadata.mjs +18 -26
- package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +25 -2
- package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +103 -10
- package/src/runtime/agent/orchestrator/providers/openai-turn-state.mjs +68 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-delta.mjs +36 -11
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +140 -86
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +9 -13
- package/src/runtime/agent/orchestrator/session/agent-loop.mjs +72 -4
- package/src/runtime/agent/orchestrator/session/browser-snapshot-supersession.mjs +61 -0
- package/src/runtime/agent/orchestrator/session/compact/handoff.mjs +0 -22
- package/src/runtime/agent/orchestrator/session/compact/messages.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/compact/runner.mjs +11 -23
- package/src/runtime/agent/orchestrator/session/compact/summary.mjs +28 -269
- package/src/runtime/agent/orchestrator/session/compact.mjs +0 -6
- package/src/runtime/agent/orchestrator/session/context-utils.mjs +86 -11
- package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +17 -1
- package/src/runtime/agent/orchestrator/session/image-strip-recovery.mjs +12 -8
- package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +110 -2
- package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +3 -16
- package/src/runtime/agent/orchestrator/session/loop/recall-fasttrack.mjs +80 -18
- package/src/runtime/agent/orchestrator/session/loop/steering.mjs +6 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +3 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +6 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +80 -21
- package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +33 -72
- package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +21 -2
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +25 -51
- package/src/runtime/agent/orchestrator/session/manager/status-telemetry.mjs +3 -0
- package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +4 -110
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.mjs +39 -15
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +14 -4
- package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +41 -8
- package/src/runtime/agent/orchestrator/session/provider-prefix-guard.mjs +129 -12
- package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/store/listing.mjs +8 -1
- package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +15 -1
- package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +36 -2
- package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +157 -30
- package/src/runtime/agent/orchestrator/session/store-summary-visibility.mjs +57 -0
- package/src/runtime/agent/orchestrator/session/store.mjs +3 -1
- package/src/runtime/agent/orchestrator/session/tool-batch.mjs +22 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-special-files.mjs +6 -6
- package/src/runtime/agent/orchestrator/tools/progress-message.mjs +4 -0
- package/src/runtime/attachments/pdf-extract.mjs +3 -0
- package/src/runtime/attachments/pdfjs-runtime.mjs +13 -0
- package/src/runtime/browser-bridge/action-schema.mjs +251 -0
- package/src/runtime/browser-bridge/client.mjs +75 -26
- package/src/runtime/browser-bridge/tool-defs.mjs +132 -15
- package/src/runtime/computer-bridge/action-schema.mjs +653 -0
- package/src/runtime/computer-bridge/client.mjs +211 -28
- package/src/runtime/computer-bridge/tool-defs.mjs +25 -45
- package/src/runtime/office/assurance-benchmark.mjs +358 -0
- package/src/runtime/office/assurance.mjs +833 -0
- package/src/runtime/office/benchmark.mjs +496 -0
- package/src/runtime/office/capabilities.mjs +551 -0
- package/src/runtime/office/com-adapter.mjs +283 -0
- package/src/runtime/office/content-model.mjs +183 -0
- package/src/runtime/office/contract-benchmark.mjs +105 -0
- package/src/runtime/office/design-library.mjs +1562 -0
- package/src/runtime/office/design-system.mjs +1966 -0
- package/src/runtime/office/index.mjs +2413 -0
- package/src/runtime/office/journal.mjs +82 -0
- package/src/runtime/office/office-com-host.ps1 +3781 -0
- package/src/runtime/office/office-com-session-host.ps1 +855 -0
- package/src/runtime/office/ooxml-validator.mjs +271 -0
- package/src/runtime/office/pagination.mjs +132 -0
- package/src/runtime/office/pdf-adapter.mjs +591 -0
- package/src/runtime/office/pdf-analysis.mjs +372 -0
- package/src/runtime/office/pdf-render.mjs +167 -0
- package/src/runtime/office/pdf-security.mjs +63 -0
- package/src/runtime/office/polish-benchmark.mjs +190 -0
- package/src/runtime/office/portable-ooxml.mjs +1867 -0
- package/src/runtime/office/quality-live-benchmark.mjs +486 -0
- package/src/runtime/office/quality-pipeline.mjs +136 -0
- package/src/runtime/office/tabular.mjs +302 -0
- package/src/runtime/office/templates/mixdog-executive.pptx +0 -0
- package/src/runtime/office/templates/mixdog-executive.pptx.mixdog.json +190 -0
- package/src/runtime/office/tool-defs.mjs +113 -0
- package/src/runtime/office/visual-diff.mjs +89 -0
- package/src/runtime/office/xlsx-assertions.mjs +172 -0
- package/src/runtime/office/xlsx-contract.mjs +147 -0
- package/src/runtime/shared/agent-route-config.mjs +9 -0
- package/src/runtime/shared/tool-execution-contract.mjs +16 -0
- package/src/runtime/shared/tool-surface.mjs +9 -0
- package/src/session-runtime/context-status.mjs +9 -3
- package/src/session-runtime/deferred-tool-delta.mjs +104 -0
- package/src/session-runtime/goal-runtime.mjs +617 -197
- package/src/session-runtime/lifecycle-api.mjs +50 -8
- package/src/session-runtime/provider-request-snapshot.mjs +33 -9
- package/src/session-runtime/resource-api.mjs +31 -94
- package/src/session-runtime/runtime-core.mjs +78 -26
- package/src/session-runtime/session-lifecycle.mjs +34 -12
- package/src/session-runtime/session-title.mjs +2 -2
- package/src/session-runtime/session-turn-api.mjs +15 -14
- package/src/session-runtime/tool-catalog-data.mjs +1 -1
- package/src/session-runtime/tool-catalog.mjs +38 -99
- package/src/session-runtime/tool-defs.mjs +6 -1
- package/src/session-runtime/tool-surface.mjs +18 -8
- package/src/session-runtime/workflow-agents-api.mjs +8 -25
- package/src/session-runtime/workflow.mjs +8 -6
- package/src/standalone/agent-tool/helpers.mjs +2 -2
- package/src/standalone/agent-tool/job-views.mjs +3 -1
- package/src/standalone/agent-tool/notify.mjs +5 -1
- package/src/standalone/agent-tool/render.mjs +3 -0
- package/src/standalone/agent-tool/spawn-flow.mjs +61 -16
- package/src/standalone/agent-tool/tool-def.mjs +1 -1
- package/src/standalone/agent-tool/worker-index.mjs +123 -0
- package/src/standalone/agent-tool/worker-rows.mjs +2 -1
- package/src/standalone/agent-tool.mjs +57 -10
- package/src/standalone/daemon.mjs +105 -6
- package/src/standalone/session-runtime-host.mjs +61 -48
- package/src/standalone/session-runtime-inline-host.mjs +34 -127
- package/src/standalone/session-runtime-worker.mjs +20 -198
- package/src/standalone/session-service.mjs +632 -7
- package/src/tui/dist/index.mjs +24 -1
- package/src/tui/lib/voice-setup.mjs +4 -1
- package/src/tui/session/context-state.mjs +2 -13
- package/src/tui/session/goal-continuation.mjs +38 -7
- package/src/tui/session/session-api-ext.mjs +9 -0
- package/src/tui/session/session-api.mjs +15 -1
- package/src/tui/session/session-flow.mjs +25 -1
- package/src/tui/session/turn.mjs +88 -16
- package/src/tui/session-local.mjs +25 -3
- package/src/vendor/statusline/src/gateway/route-meta.mjs +31 -0
- package/scripts/generate-voice-runtime-manifest.test.mjs +0 -135
- package/scripts/native-binary-arch.test.mjs +0 -111
- package/scripts/patch-replay.test.mjs +0 -94
- package/src/headless-exec.test.mjs +0 -539
- package/src/runtime/agent/orchestrator/agent-trace-timing.test.mjs +0 -57
- package/src/runtime/agent/orchestrator/context/collect-skills.test.mjs +0 -153
- package/src/runtime/agent/orchestrator/mcp/cancellation.test.mjs +0 -139
- package/src/runtime/agent/orchestrator/mcp/features.test.mjs +0 -66
- package/src/runtime/agent/orchestrator/mcp/security.test.mjs +0 -80
- package/src/runtime/agent/orchestrator/providers/anthropic-fast-mode.test.mjs +0 -90
- package/src/runtime/agent/orchestrator/providers/anthropic-server-fallback.test.mjs +0 -215
- package/src/runtime/agent/orchestrator/providers/antigravity-oauth.test.mjs +0 -165
- package/src/runtime/agent/orchestrator/providers/media-parity.test.mjs +0 -142
- package/src/runtime/agent/orchestrator/providers/openai-codex-identity.test.mjs +0 -153
- package/src/runtime/agent/orchestrator/providers/openai-codex-model.test.mjs +0 -24
- package/src/runtime/agent/orchestrator/providers/openai-ws-delta-parity.test.mjs +0 -190
- package/src/runtime/agent/orchestrator/providers/provider-replay.test.mjs +0 -235
- package/src/runtime/agent/orchestrator/providers/sse-framing.test.mjs +0 -719
- package/src/runtime/agent/orchestrator/session/cache/prefetch-cache.test.mjs +0 -40
- package/src/runtime/agent/orchestrator/session/compact-policy.test.mjs +0 -176
- package/src/runtime/agent/orchestrator/session/compaction-read-reset.test.mjs +0 -161
- package/src/runtime/agent/orchestrator/session/eager-dispatch.test.mjs +0 -115
- package/src/runtime/agent/orchestrator/session/evidence-union.test.mjs +0 -228
- package/src/runtime/agent/orchestrator/session/image-strip-recovery.test.mjs +0 -245
- package/src/runtime/agent/orchestrator/session/lossless-tool-output.test.mjs +0 -125
- package/src/runtime/agent/orchestrator/session/manager/pending-messages-persistence.test.mjs +0 -325
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.test.mjs +0 -70
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.test.mjs +0 -457
- package/src/runtime/agent/orchestrator/session/provider-prefix-guard.test.mjs +0 -117
- package/src/runtime/agent/orchestrator/session/reduction-metrics.test.mjs +0 -87
- package/src/runtime/agent/orchestrator/session/store/serialize.test.mjs +0 -60
- package/src/runtime/agent/orchestrator/session/store-summary-reader.test.mjs +0 -583
- package/src/runtime/agent/orchestrator/session/task-wait-control.test.mjs +0 -78
- package/src/runtime/agent/orchestrator/tools/builtin/absence-absorption.test.mjs +0 -43
- package/src/runtime/agent/orchestrator/tools/builtin/absolute-glob-expand.test.mjs +0 -63
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool-cwd-env.test.mjs +0 -14
- package/src/runtime/agent/orchestrator/tools/builtin/edit-encoding-eol.test.mjs +0 -224
- package/src/runtime/agent/orchestrator/tools/builtin/edit-sequential-occupation.test.mjs +0 -224
- package/src/runtime/agent/orchestrator/tools/builtin/enoent-outside-project.test.mjs +0 -56
- package/src/runtime/agent/orchestrator/tools/builtin/find-search-budget.test.mjs +0 -103
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-policy.test.mjs +0 -30
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.test.mjs +0 -390
- package/src/runtime/agent/orchestrator/tools/builtin/git-repo-rw-lock.test.mjs +0 -83
- package/src/runtime/agent/orchestrator/tools/builtin/grep-output-budget.test.mjs +0 -31
- package/src/runtime/agent/orchestrator/tools/builtin/grep-single-file-rescue.test.mjs +0 -106
- package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-job-records.test.mjs +0 -102
- package/src/runtime/agent/orchestrator/tools/builtin/list-tool-integrity.test.mjs +0 -152
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-health.test.mjs +0 -24
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-transport.test.mjs +0 -24
- package/src/runtime/agent/orchestrator/tools/builtin/noise-dir-visibility.test.mjs +0 -69
- package/src/runtime/agent/orchestrator/tools/builtin/read-glob-survey.test.mjs +0 -71
- package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.test.mjs +0 -56
- package/src/runtime/agent/orchestrator/tools/builtin/search-builders.test.mjs +0 -16
- package/src/runtime/agent/orchestrator/tools/builtin/search-glob-top-k.test.mjs +0 -39
- package/src/runtime/agent/orchestrator/tools/builtin/write-symlink.test.mjs +0 -153
- package/src/runtime/agent/orchestrator/tools/code-graph/aggregate-anchor-relocation.test.mjs +0 -55
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.test.mjs +0 -88
- package/src/runtime/agent/orchestrator/tools/code-graph/loose-file-target.test.mjs +0 -72
- package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.test.mjs +0 -54
- package/src/runtime/agent/orchestrator/tools/code-graph/search-references.test.mjs +0 -20
- package/src/runtime/agent/orchestrator/tools/code-graph/symbol-search-scope.test.mjs +0 -55
- package/src/runtime/agent/orchestrator/tools/code-graph/text-span-mask.test.mjs +0 -268
- package/src/runtime/agent/orchestrator/tools/env-scrub.test.mjs +0 -57
- package/src/runtime/agent/orchestrator/tools/graph-binary-fetcher.test.mjs +0 -19
- package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.test.mjs +0 -104
- package/src/runtime/agent/orchestrator/tools/patch/engine-contract-gate.test.mjs +0 -661
- package/src/runtime/agent/orchestrator/tools/patch/patch-codec-eol.test.mjs +0 -552
- package/src/runtime/agent/orchestrator/tools/patch/patch-symlink.test.mjs +0 -141
- package/src/runtime/agent/orchestrator/tools/patch/v4a-pure-move.test.mjs +0 -57
- package/src/runtime/agent/orchestrator/tools/patch/v4a-section-coalesce.test.mjs +0 -81
- package/src/runtime/agent/orchestrator/tools/spawn-binary-fetcher.test.mjs +0 -52
- package/src/runtime/attachments/store.test.mjs +0 -209
- package/src/runtime/channels/lib/voice-runtime-fetcher.test.mjs +0 -17
- package/src/runtime/channels/lib/webhook/deliveries.test.mjs +0 -18
- package/src/runtime/channels/lib/webhook/relay-tunnel.test.mjs +0 -68
- package/src/runtime/media/adapters/codex-image.test.mjs +0 -22
- package/src/runtime/media/download.test.mjs +0 -52
- package/src/runtime/media/renditions.test.mjs +0 -99
- package/src/runtime/media/store.test.mjs +0 -159
- package/src/runtime/memory/lib/archive-security.test.mjs +0 -128
- package/src/runtime/memory/lib/embedding-model-config.test.mjs +0 -33
- package/src/runtime/memory/lib/http-wire.test.mjs +0 -15
- package/src/runtime/memory/lib/memory-cycle-packets.test.mjs +0 -49
- package/src/runtime/memory/lib/memory-cycle2-shared.test.mjs +0 -78
- package/src/runtime/memory/lib/memory-embedding-migration.test.mjs +0 -50
- package/src/runtime/memory/lib/pg/process.test.mjs +0 -36
- package/src/runtime/memory/lib/trace-store.test.mjs +0 -57
- package/src/runtime/memory/lib/transcript-ingest.test.mjs +0 -52
- package/src/runtime/shared/background-tasks.test.mjs +0 -78
- package/src/runtime/shared/bounded-download.test.mjs +0 -41
- package/src/runtime/shared/channel-notification-routing.test.mjs +0 -25
- package/src/runtime/shared/child-spawn-remote.test.mjs +0 -124
- package/src/runtime/shared/remote-intent.test.mjs +0 -40
- package/src/runtime/shared/resource-admission.test.mjs +0 -43
- package/src/runtime/shared/runtime-root.test.mjs +0 -34
- package/src/runtime/shared/schedule-time.test.mjs +0 -29
- package/src/runtime/shared/session-runtime-health.test.mjs +0 -83
- package/src/runtime/shared/skill-document.test.mjs +0 -81
- package/src/runtime/shared/tool-surface.test.mjs +0 -87
- package/src/runtime/shared/update-checker.test.mjs +0 -33
- package/src/runtime/shared/user-cwd.test.mjs +0 -43
- package/src/runtime/shared/webhook-session-run.test.mjs +0 -14
- package/src/session-runtime/agent-disable.test.mjs +0 -123
- package/src/session-runtime/cwd-plugins.test.mjs +0 -75
- package/src/session-runtime/cwd-tool-routing.test.mjs +0 -61
- package/src/session-runtime/global-extensions.test.mjs +0 -28
- package/src/session-runtime/goal-runtime.test.mjs +0 -108
- package/src/session-runtime/lifecycle-api.test.mjs +0 -21
- package/src/session-runtime/model-settings-persist.test.mjs +0 -105
- package/src/session-runtime/notification-bus.test.mjs +0 -148
- package/src/session-runtime/plugin-mcp-standard.test.mjs +0 -177
- package/src/session-runtime/prewarm.test.mjs +0 -52
- package/src/session-runtime/provider-request-snapshot.test.mjs +0 -37
- package/src/session-runtime/resource-api-global.test.mjs +0 -69
- package/src/session-runtime/session-lifecycle.test.mjs +0 -125
- package/src/session-runtime/session-title.test.mjs +0 -36
- package/src/session-runtime/skills-api.test.mjs +0 -99
- package/src/session-runtime/tool-policy-surface.test.mjs +0 -331
- package/src/standalone/agent-tool/helpers.test.mjs +0 -62
- package/src/standalone/agent-tool/notify.test.mjs +0 -37
- package/src/standalone/agent-tool/spawn-flow.test.mjs +0 -63
- package/src/standalone/channel-restart.test.mjs +0 -145
- package/src/standalone/channel-session-router.test.mjs +0 -37
- package/src/standalone/channel-worker-heartbeat.test.mjs +0 -30
- package/src/standalone/hook-bus/handlers.test.mjs +0 -88
- package/src/standalone/plugin-admin.test.mjs +0 -173
- package/src/standalone/session-runtime-agent-control-client.test.mjs +0 -71
- package/src/standalone/session-runtime-dispatch-cancel.test.mjs +0 -139
- package/src/standalone/session-runtime-host-factory.test.mjs +0 -31
- package/src/standalone/session-runtime-host-health.test.mjs +0 -160
- package/src/standalone/session-runtime-inline-host.test.mjs +0 -83
- package/src/standalone/session-runtime-provider-cooldown.test.mjs +0 -80
- package/src/standalone/session-runtime-shard-host.test.mjs +0 -569
- package/src/standalone/session-runtime-shard-router.test.mjs +0 -101
- package/src/tui/app/live-spinner-visibility.test.mjs +0 -44
- package/src/tui/app/panel-epoch.test.mjs +0 -1009
- package/src/tui/app/panel-handoff.test.mjs +0 -311
- package/src/tui/app/prompt-submit.test.mjs +0 -206
- package/src/tui/session/completion-card-restore.test.mjs +0 -111
- package/src/tui/session/goal-continuation.test.mjs +0 -84
- package/src/tui/session/oauth-flows.test.mjs +0 -134
- package/src/tui/session/queue-helpers.test.mjs +0 -46
- package/src/tui/session/session-action-surface.test.mjs +0 -108
- package/src/tui/session/task-wait-submit.test.mjs +0 -80
- package/src/tui/session/tool-result-status.test.mjs +0 -131
- package/src/tui/session/tui-steering-persist.test.mjs +0 -104
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import test from 'node:test';
|
|
3
|
-
import { projectProviderEvidence } from './evidence-union.mjs';
|
|
4
|
-
|
|
5
|
-
function call(id, name, args = {}) {
|
|
6
|
-
return { role: 'assistant', content: '', toolCalls: [{ id, name, arguments: args }] };
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function result(id, content) {
|
|
10
|
-
return { role: 'tool', toolCallId: id, toolKind: 'normal', content };
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
test('keeps the first read and puts only new lines plus prior locations in later envelopes', () => {
|
|
14
|
-
const beta = `beta ${'b'.repeat(96)}`;
|
|
15
|
-
const gamma = `gamma ${'g'.repeat(96)}`;
|
|
16
|
-
const first = result('read_1', `1→alpha\n2→${beta}\n3→${gamma}\n[lines 1-3]`);
|
|
17
|
-
const second = result('read_2', `2→${beta}\n3→${gamma}\n4→delta\n[lines 2-4]`);
|
|
18
|
-
const messages = [
|
|
19
|
-
call('read_1', 'read', { file_path: 'src/a.mjs' }),
|
|
20
|
-
first,
|
|
21
|
-
call('read_2', 'read', { file_path: 'src/a.mjs' }),
|
|
22
|
-
second,
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
const projected = projectProviderEvidence(messages);
|
|
26
|
-
assert.equal(projected.messages[1], first);
|
|
27
|
-
assert.equal(projected.messages[3].toolCallId, 'read_2');
|
|
28
|
-
assert.match(projected.messages[3].content, /\[evidence-ref tool_call_id="read_1" location=src\/a\.mjs:2-3\]/);
|
|
29
|
-
assert.doesNotMatch(projected.messages[3].content, /(?:^|\n)2→beta/);
|
|
30
|
-
assert.doesNotMatch(projected.messages[3].content, /(?:^|\n)3→gamma/);
|
|
31
|
-
assert.match(projected.messages[3].content, /(?:^|\n)4→delta/);
|
|
32
|
-
assert.equal(messages[3], second);
|
|
33
|
-
assert.equal(messages[3].content, `2→${beta}\n3→${gamma}\n4→delta\n[lines 2-4]`);
|
|
34
|
-
assert.equal(projected.stats.reusedRows, 2);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('requires exact content at the same path and line', () => {
|
|
38
|
-
const messages = [
|
|
39
|
-
call('read_1', 'read', { file_path: 'src/a.mjs' }),
|
|
40
|
-
result('read_1', '2→old'),
|
|
41
|
-
call('read_2', 'read', { file_path: 'src/a.mjs' }),
|
|
42
|
-
result('read_2', '2→new'),
|
|
43
|
-
];
|
|
44
|
-
const projected = projectProviderEvidence(messages);
|
|
45
|
-
assert.equal(projected.messages, messages);
|
|
46
|
-
assert.equal(projected.stats.reusedRows, 0);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('references exact repeated list, glob, and find results without changing envelopes', () => {
|
|
50
|
-
const content = Array.from({ length: 24 }, (_, index) => `src/feature-${index}.mjs`).join('\n');
|
|
51
|
-
for (const name of ['list', 'glob', 'find', 'find_files']) {
|
|
52
|
-
const first = result(`${name}_1`, content);
|
|
53
|
-
const second = result(`${name}_2`, content);
|
|
54
|
-
const messages = [
|
|
55
|
-
call(`${name}_1`, name),
|
|
56
|
-
first,
|
|
57
|
-
call(`${name}_2`, name),
|
|
58
|
-
second,
|
|
59
|
-
];
|
|
60
|
-
const projected = projectProviderEvidence(messages);
|
|
61
|
-
assert.equal(projected.messages[1], first, name);
|
|
62
|
-
assert.equal(projected.messages[3].toolCallId, `${name}_2`, name);
|
|
63
|
-
assert.match(projected.messages[3].content, new RegExp(`tool_call_id="${name}_1"`), name);
|
|
64
|
-
assert.match(projected.messages[3].content, /exact_bytes=\d+/, name);
|
|
65
|
-
assert.doesNotMatch(projected.messages[3].content, /src\/feature-0\.mjs/, name);
|
|
66
|
-
assert.equal(projected.stats.exactResultRefs, 1, name);
|
|
67
|
-
assert.ok(projected.stats.exactResultBytesSaved > 0, name);
|
|
68
|
-
assert.equal(messages[3], second, name);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('keeps tiny exact results when a reference would be larger', () => {
|
|
73
|
-
const messages = [
|
|
74
|
-
call('list_1', 'list'),
|
|
75
|
-
result('list_1', 'src'),
|
|
76
|
-
call('list_2', 'list'),
|
|
77
|
-
result('list_2', 'src'),
|
|
78
|
-
];
|
|
79
|
-
const projected = projectProviderEvidence(messages);
|
|
80
|
-
assert.equal(projected.messages, messages);
|
|
81
|
-
assert.equal(projected.stats.exactResultRefs, 0);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('aliases repeated typed paths across same-turn glob and batch read results', () => {
|
|
85
|
-
const repeated = `src/${'deep/'.repeat(10)}feature.mjs`;
|
|
86
|
-
const first = result('glob_1', `${repeated}\nsrc/unique.mjs`);
|
|
87
|
-
const second = result('read_1', `read 1\n\n${repeated} [ok]\n1→export const value = 1;`);
|
|
88
|
-
const messages = [
|
|
89
|
-
{
|
|
90
|
-
role: 'assistant',
|
|
91
|
-
content: '',
|
|
92
|
-
toolCalls: [
|
|
93
|
-
{ id: 'glob_1', name: 'glob', arguments: { pattern: '**/*.mjs' } },
|
|
94
|
-
{ id: 'read_1', name: 'read', arguments: { file_path: '**/*.mjs' } },
|
|
95
|
-
],
|
|
96
|
-
},
|
|
97
|
-
first,
|
|
98
|
-
second,
|
|
99
|
-
];
|
|
100
|
-
const projected = projectProviderEvidence(messages);
|
|
101
|
-
const combined = `${projected.messages[1].content}\n${projected.messages[2].content}`;
|
|
102
|
-
assert.equal(projected.messages[1].toolCallId, 'glob_1');
|
|
103
|
-
assert.equal(projected.messages[2].toolCallId, 'read_1');
|
|
104
|
-
assert.equal(combined.split(repeated).length - 1, 1);
|
|
105
|
-
assert.match(projected.messages[1].content, /\[path-alias p1="/);
|
|
106
|
-
assert.match(projected.messages[1].content, /(?:^|\n)p1(?:\n|$)/);
|
|
107
|
-
assert.match(projected.messages[2].content, /(?:^|\n)p1 \[ok\](?:\n|$)/);
|
|
108
|
-
assert.equal(projected.stats.pathAliases, 1);
|
|
109
|
-
assert.equal(projected.stats.reusedPathFacts, 1);
|
|
110
|
-
assert.ok(projected.stats.pathAliasBytesSaved > 0);
|
|
111
|
-
assert.equal(messages[1], first);
|
|
112
|
-
assert.equal(messages[2], second);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test('keeps short repeated paths and resets path aliases across mutations', () => {
|
|
116
|
-
const shortMessages = [
|
|
117
|
-
call('glob_1', 'glob'),
|
|
118
|
-
result('glob_1', 'src/a.mjs'),
|
|
119
|
-
call('read_1', 'read'),
|
|
120
|
-
result('read_1', 'src/a.mjs [ok]\n1→a'),
|
|
121
|
-
];
|
|
122
|
-
assert.equal(projectProviderEvidence(shortMessages).stats.pathAliases, 0);
|
|
123
|
-
|
|
124
|
-
const repeated = `src/${'nested/'.repeat(10)}a.mjs`;
|
|
125
|
-
const mutationMessages = [
|
|
126
|
-
call('glob_1', 'glob'),
|
|
127
|
-
result('glob_1', repeated),
|
|
128
|
-
call('patch_1', 'apply_patch'),
|
|
129
|
-
result('patch_1', 'ok'),
|
|
130
|
-
call('read_1', 'read'),
|
|
131
|
-
result('read_1', `${repeated} [ok]\n1→a`),
|
|
132
|
-
];
|
|
133
|
-
const projected = projectProviderEvidence(mutationMessages);
|
|
134
|
-
assert.equal(projected.messages, mutationMessages);
|
|
135
|
-
assert.equal(projected.stats.pathAliases, 0);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
test('apply_patch, shell, and mutating git batches invalidate all earlier evidence', () => {
|
|
139
|
-
const same = `same ${'s'.repeat(160)}`;
|
|
140
|
-
const listing = Array.from({ length: 24 }, (_, index) => `src/item-${index}.mjs`).join('\n');
|
|
141
|
-
for (const [mutationName, mutationArgs] of [
|
|
142
|
-
['apply_patch', {}],
|
|
143
|
-
['shell', {}],
|
|
144
|
-
['git_stage', { diff_id: 'diff_test', change_ids: ['chg_test'] }],
|
|
145
|
-
['git', { command: 'git commit -m test' }],
|
|
146
|
-
['git', { command: "git reflog delete 'HEAD@{1}'" }],
|
|
147
|
-
]) {
|
|
148
|
-
const messages = [
|
|
149
|
-
call('read_1', 'read', { file_path: 'src/a.mjs' }),
|
|
150
|
-
result('read_1', `2→${same}`),
|
|
151
|
-
call('list_1', 'list'),
|
|
152
|
-
result('list_1', listing),
|
|
153
|
-
call('mut_1', mutationName, mutationArgs),
|
|
154
|
-
result('mut_1', 'ok'),
|
|
155
|
-
call('read_2', 'read', { file_path: 'src/a.mjs' }),
|
|
156
|
-
result('read_2', `2→${same}`),
|
|
157
|
-
call('list_2', 'list'),
|
|
158
|
-
result('list_2', listing),
|
|
159
|
-
];
|
|
160
|
-
const projected = projectProviderEvidence(messages);
|
|
161
|
-
assert.equal(projected.messages, messages, mutationName);
|
|
162
|
-
assert.equal(projected.stats.reusedRows, 0, mutationName);
|
|
163
|
-
assert.equal(projected.stats.exactResultRefs, 0, mutationName);
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test('read-only git operations preserve earlier evidence', () => {
|
|
168
|
-
const beta = `beta ${'b'.repeat(96)}`;
|
|
169
|
-
const gamma = `gamma ${'g'.repeat(96)}`;
|
|
170
|
-
const messages = [
|
|
171
|
-
call('read_1', 'read', { file_path: 'src/a.mjs' }),
|
|
172
|
-
result('read_1', `1→alpha\n2→${beta}\n3→${gamma}\n[lines 1-3]`),
|
|
173
|
-
call('git_1', 'git', { command: 'git status' }),
|
|
174
|
-
result('git_1', '{"ok":true}'),
|
|
175
|
-
call('read_2', 'read', { file_path: 'src/a.mjs' }),
|
|
176
|
-
result('read_2', `2→${beta}\n3→${gamma}\n4→delta\n[lines 2-4]`),
|
|
177
|
-
];
|
|
178
|
-
const projected = projectProviderEvidence(messages);
|
|
179
|
-
assert.equal(projected.stats.reusedRows, 2);
|
|
180
|
-
assert.match(projected.messages[5].content, /tool_call_id="read_1"/);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
test('deduplicates deterministic grep context rows while preserving the tool envelope', () => {
|
|
184
|
-
const eleven = `eleven ${'e'.repeat(96)}`;
|
|
185
|
-
const twelve = `twelve ${'t'.repeat(96)}`;
|
|
186
|
-
const messages = [
|
|
187
|
-
call('grep_1', 'grep'),
|
|
188
|
-
result('grep_1', `# src/a.mjs:11 [lines 10-12]\nten\n${eleven}\n${twelve}`),
|
|
189
|
-
call('grep_2', 'grep'),
|
|
190
|
-
result('grep_2', `# src/a.mjs:12 [lines 11-13]\n${eleven}\n${twelve}\nthirteen`),
|
|
191
|
-
];
|
|
192
|
-
const projected = projectProviderEvidence(messages);
|
|
193
|
-
assert.equal(projected.messages[3].toolCallId, 'grep_2');
|
|
194
|
-
assert.match(projected.messages[3].content, /location=src\/a\.mjs:11-12/);
|
|
195
|
-
assert.doesNotMatch(projected.messages[3].content, /(?:^|\n)eleven/);
|
|
196
|
-
assert.doesNotMatch(projected.messages[3].content, /(?:^|\n)twelve/);
|
|
197
|
-
assert.match(projected.messages[3].content, /(?:^|\n)thirteen(?:\n|$)/);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
test('shadow mode reports savings without changing provider messages', () => {
|
|
201
|
-
const same = `same ${'s'.repeat(160)}`;
|
|
202
|
-
const messages = [
|
|
203
|
-
call('read_1', 'read', { path: 'src/a.mjs' }),
|
|
204
|
-
result('read_1', `1→${same}`),
|
|
205
|
-
call('read_2', 'read', { path: 'src/a.mjs' }),
|
|
206
|
-
result('read_2', `1→${same}`),
|
|
207
|
-
];
|
|
208
|
-
const projected = projectProviderEvidence(messages, { apply: false });
|
|
209
|
-
assert.equal(projected.messages, messages);
|
|
210
|
-
assert.equal(projected.stats.reusedRows, 1);
|
|
211
|
-
assert.ok(projected.stats.afterBytes < projected.stats.beforeBytes);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
test('provider projection stays append-only when path aliases are disabled', () => {
|
|
215
|
-
const repeated = `src/${'nested/'.repeat(10)}feature.mjs`;
|
|
216
|
-
const firstMessages = [
|
|
217
|
-
call('glob_1', 'glob'),
|
|
218
|
-
result('glob_1', `${repeated}\nsrc/unique.mjs`),
|
|
219
|
-
];
|
|
220
|
-
const first = projectProviderEvidence(firstMessages, { pathAliases: false });
|
|
221
|
-
const later = projectProviderEvidence([
|
|
222
|
-
...firstMessages,
|
|
223
|
-
call('read_1', 'read', { file_path: repeated }),
|
|
224
|
-
result('read_1', `${repeated} [ok]\n1→export const value = 1;`),
|
|
225
|
-
], { pathAliases: false });
|
|
226
|
-
assert.deepEqual(later.messages.slice(0, first.messages.length), first.messages);
|
|
227
|
-
assert.equal(later.stats.pathAliases, 0);
|
|
228
|
-
});
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import test from 'node:test';
|
|
3
|
-
import { agentLoop } from './agent-loop.mjs';
|
|
4
|
-
import {
|
|
5
|
-
IMAGE_STRIP_PLACEHOLDER,
|
|
6
|
-
confirmedImageRejection,
|
|
7
|
-
isImageProcessingError,
|
|
8
|
-
isLikelyImageBodyRejected,
|
|
9
|
-
persistenceMessagesForConfirmedImageRejection,
|
|
10
|
-
promptHasInlineImages,
|
|
11
|
-
shouldStripImagesForRetry,
|
|
12
|
-
stripInlineImages,
|
|
13
|
-
} from './image-strip-recovery.mjs';
|
|
14
|
-
import { isRetryableStreamErrorEvent } from '../providers/retry-classifier.mjs';
|
|
15
|
-
|
|
16
|
-
test('strips user image parts to the Grok Build placeholder', () => {
|
|
17
|
-
const messages = [
|
|
18
|
-
{ role: 'system', content: 'sys' },
|
|
19
|
-
{ role: 'user', content: [
|
|
20
|
-
{ type: 'text', text: 'what is this' },
|
|
21
|
-
{ type: 'image', mimeType: 'image/png', attachmentRef: 'abc' },
|
|
22
|
-
] },
|
|
23
|
-
];
|
|
24
|
-
assert.equal(promptHasInlineImages(messages), true);
|
|
25
|
-
const { messages: next, stripped } = stripInlineImages(messages);
|
|
26
|
-
assert.equal(stripped, 1);
|
|
27
|
-
assert.equal(next[1].content[1].text, IMAGE_STRIP_PLACEHOLDER);
|
|
28
|
-
assert.equal(messages[1].content[1].type, 'image');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('strips wrapped tool-result images and counts unique payloads', () => {
|
|
32
|
-
const messages = [{
|
|
33
|
-
role: 'tool',
|
|
34
|
-
content: {
|
|
35
|
-
content: [
|
|
36
|
-
{ type: 'text', text: 'preview' },
|
|
37
|
-
{ type: 'image', data: 'broken', mimeType: 'image/png' },
|
|
38
|
-
],
|
|
39
|
-
},
|
|
40
|
-
}];
|
|
41
|
-
assert.equal(promptHasInlineImages(messages), true);
|
|
42
|
-
const { messages: next, stripped, uniqueImages } = stripInlineImages(messages);
|
|
43
|
-
assert.equal(stripped, 1);
|
|
44
|
-
assert.equal(uniqueImages, 1);
|
|
45
|
-
assert.equal(next[0].content.content[1].text, IMAGE_STRIP_PLACEHOLDER);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('image processing 413/400 phrase/invalid_image trigger strip', () => {
|
|
49
|
-
assert.equal(isImageProcessingError({ status: 413 }), true);
|
|
50
|
-
assert.equal(isImageProcessingError({
|
|
51
|
-
httpStatus: 400,
|
|
52
|
-
message: 'Could not process image: bad format',
|
|
53
|
-
}), true);
|
|
54
|
-
assert.equal(isImageProcessingError({
|
|
55
|
-
httpStatus: 500,
|
|
56
|
-
providerErrorCode: 'invalid_image',
|
|
57
|
-
}), true);
|
|
58
|
-
const openAIInvalid = {
|
|
59
|
-
httpStatus: 400,
|
|
60
|
-
message: 'The image data you provided does not represent a valid image. Please check your input and try again.',
|
|
61
|
-
};
|
|
62
|
-
assert.equal(isImageProcessingError(openAIInvalid), true);
|
|
63
|
-
assert.equal(confirmedImageRejection(openAIInvalid), true);
|
|
64
|
-
assert.equal(isImageProcessingError({ httpStatus: 400, message: 'bad json' }), false);
|
|
65
|
-
assert.equal(isLikelyImageBodyRejected({ code: 'ECONNRESET' }), true);
|
|
66
|
-
assert.equal(shouldStripImagesForRetry({ status: 413 }, { hasImages: true }), true);
|
|
67
|
-
assert.equal(shouldStripImagesForRetry({ status: 413 }, { hasImages: false }), false);
|
|
68
|
-
assert.equal(shouldStripImagesForRetry({ status: 413 }, { hasImages: true, alreadyStripped: true }), false);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('confirmed rejection persistently removes only one newly introduced image', () => {
|
|
72
|
-
const err = {
|
|
73
|
-
httpStatus: 400,
|
|
74
|
-
message: 'The image data you provided does not represent a valid image.',
|
|
75
|
-
};
|
|
76
|
-
const oldImage = { type: 'image', data: 'old', mimeType: 'image/png' };
|
|
77
|
-
const badImage = { type: 'image', data: 'bad', mimeType: 'image/png' };
|
|
78
|
-
const messages = [
|
|
79
|
-
{ role: 'user', content: [oldImage] },
|
|
80
|
-
{ role: 'assistant', content: 'seen' },
|
|
81
|
-
{ role: 'user', content: [{ type: 'text', text: 'next' }, badImage] },
|
|
82
|
-
];
|
|
83
|
-
const persisted = persistenceMessagesForConfirmedImageRejection(err, messages);
|
|
84
|
-
assert.ok(persisted);
|
|
85
|
-
assert.equal(persisted[0].content[0].type, 'image');
|
|
86
|
-
assert.equal(persisted[2].content[1].text, IMAGE_STRIP_PLACEHOLDER);
|
|
87
|
-
|
|
88
|
-
const ambiguous = [...messages.slice(0, 2), {
|
|
89
|
-
role: 'user',
|
|
90
|
-
content: [badImage, { type: 'image', data: 'other', mimeType: 'image/png' }],
|
|
91
|
-
}];
|
|
92
|
-
assert.equal(persistenceMessagesForConfirmedImageRejection(err, ambiguous), null);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('agent loop heals one rejected tail image and the next turn stays usable', async () => {
|
|
96
|
-
const imageParts = (messages) => messages.flatMap((message) => {
|
|
97
|
-
const content = Array.isArray(message?.content)
|
|
98
|
-
? message.content
|
|
99
|
-
: (Array.isArray(message?.content?.content) ? message.content.content : []);
|
|
100
|
-
return content.filter((part) => part?.type === 'image');
|
|
101
|
-
});
|
|
102
|
-
const messages = [
|
|
103
|
-
{ role: 'system', content: 'system' },
|
|
104
|
-
{ role: 'user', content: [{ type: 'image', data: 'old-valid', mimeType: 'image/png' }] },
|
|
105
|
-
{ role: 'assistant', content: 'seen' },
|
|
106
|
-
{ role: 'user', content: [
|
|
107
|
-
{ type: 'text', text: 'inspect' },
|
|
108
|
-
{ type: 'image', data: 'new-bad', mimeType: 'image/png' },
|
|
109
|
-
] },
|
|
110
|
-
];
|
|
111
|
-
let calls = 0;
|
|
112
|
-
const provider = {
|
|
113
|
-
async send(sentMessages) {
|
|
114
|
-
calls += 1;
|
|
115
|
-
if (calls === 1) {
|
|
116
|
-
assert.equal(imageParts(sentMessages).length, 2);
|
|
117
|
-
throw Object.assign(
|
|
118
|
-
new Error('The image data you provided does not represent a valid image. Please check your input and try again.'),
|
|
119
|
-
{ httpStatus: 400 },
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
assert.equal(imageParts(sentMessages).length, 0, 'retry must omit request images');
|
|
123
|
-
return { content: 'recovered', toolCalls: [], stopReason: 'end_turn' };
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
const session = {
|
|
127
|
-
id: 'image-strip-loop-test',
|
|
128
|
-
owner: 'cli',
|
|
129
|
-
contextWindow: 200_000,
|
|
130
|
-
rawContextWindow: 200_000,
|
|
131
|
-
compaction: { auto: false },
|
|
132
|
-
};
|
|
133
|
-
const first = await agentLoop(
|
|
134
|
-
provider,
|
|
135
|
-
messages,
|
|
136
|
-
'fake-model',
|
|
137
|
-
[],
|
|
138
|
-
null,
|
|
139
|
-
process.cwd(),
|
|
140
|
-
{ session, sessionId: session.id },
|
|
141
|
-
);
|
|
142
|
-
assert.equal(first.content, 'recovered');
|
|
143
|
-
assert.equal(calls, 2);
|
|
144
|
-
assert.deepEqual(imageParts(messages).map((part) => part.data), ['old-valid']);
|
|
145
|
-
|
|
146
|
-
messages.push({ role: 'user', content: 'next turn' });
|
|
147
|
-
let nextCalls = 0;
|
|
148
|
-
const next = await agentLoop(
|
|
149
|
-
{
|
|
150
|
-
async send(sentMessages) {
|
|
151
|
-
nextCalls += 1;
|
|
152
|
-
assert.deepEqual(imageParts(sentMessages).map((part) => part.data), ['old-valid']);
|
|
153
|
-
return { content: 'still usable', toolCalls: [], stopReason: 'end_turn' };
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
messages,
|
|
157
|
-
'fake-model',
|
|
158
|
-
[],
|
|
159
|
-
null,
|
|
160
|
-
process.cwd(),
|
|
161
|
-
{ session, sessionId: session.id },
|
|
162
|
-
);
|
|
163
|
-
assert.equal(next.content, 'still usable');
|
|
164
|
-
assert.equal(nextCalls, 1);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test('agent loop keeps provider tool snapshots turn-local', async () => {
|
|
168
|
-
const oldTool = {
|
|
169
|
-
name: 'shell',
|
|
170
|
-
description: 'old schema',
|
|
171
|
-
inputSchema: { type: 'object', properties: { retired: { type: 'boolean' } } },
|
|
172
|
-
};
|
|
173
|
-
const currentTool = {
|
|
174
|
-
name: 'shell',
|
|
175
|
-
description: 'current schema',
|
|
176
|
-
inputSchema: { type: 'object', properties: { command: { type: 'string' } } },
|
|
177
|
-
};
|
|
178
|
-
const nextTool = {
|
|
179
|
-
name: 'shell',
|
|
180
|
-
description: 'next schema',
|
|
181
|
-
inputSchema: { type: 'object', properties: { command: { type: 'string' }, timeout_ms: { type: 'number' } } },
|
|
182
|
-
};
|
|
183
|
-
const sentToolDescriptions = [];
|
|
184
|
-
const provider = {
|
|
185
|
-
async send(_messages, _model, tools) {
|
|
186
|
-
sentToolDescriptions.push(tools?.[0]?.description);
|
|
187
|
-
return { content: 'done', toolCalls: [], stopReason: 'end_turn' };
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
const session = {
|
|
191
|
-
id: 'provider-tool-snapshot-lifetime-test',
|
|
192
|
-
owner: 'cli',
|
|
193
|
-
contextWindow: 200_000,
|
|
194
|
-
rawContextWindow: 200_000,
|
|
195
|
-
compaction: { auto: false },
|
|
196
|
-
_providerToolSurfaceSnapshot: [oldTool],
|
|
197
|
-
};
|
|
198
|
-
const messages = [
|
|
199
|
-
{ role: 'system', content: 'system' },
|
|
200
|
-
{ role: 'user', content: 'first turn' },
|
|
201
|
-
];
|
|
202
|
-
|
|
203
|
-
await agentLoop(
|
|
204
|
-
provider,
|
|
205
|
-
messages,
|
|
206
|
-
'fake-model',
|
|
207
|
-
[currentTool],
|
|
208
|
-
null,
|
|
209
|
-
process.cwd(),
|
|
210
|
-
{ session, sessionId: session.id },
|
|
211
|
-
);
|
|
212
|
-
assert.equal(Object.hasOwn(session, '_providerToolSurfaceSnapshot'), false);
|
|
213
|
-
|
|
214
|
-
messages.push({ role: 'user', content: 'next turn' });
|
|
215
|
-
await agentLoop(
|
|
216
|
-
provider,
|
|
217
|
-
messages,
|
|
218
|
-
'fake-model',
|
|
219
|
-
[nextTool],
|
|
220
|
-
null,
|
|
221
|
-
process.cwd(),
|
|
222
|
-
{ session, sessionId: session.id },
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
assert.deepEqual(sentToolDescriptions, ['current schema', 'next schema']);
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
test('mid-stream xAI generation crash is retryable even as invalid_request_error', () => {
|
|
229
|
-
const err = new Error('xAI Responses stream error: Internal error during token generation');
|
|
230
|
-
err.providerWireError = true;
|
|
231
|
-
err.providerErrorCode = 'invalid_request_error';
|
|
232
|
-
err.providerError = { type: 'invalid_request_error', message: 'Internal error during token generation' };
|
|
233
|
-
assert.equal(isRetryableStreamErrorEvent(err), true);
|
|
234
|
-
|
|
235
|
-
const typed400 = new Error('bad request');
|
|
236
|
-
typed400.providerWireError = true;
|
|
237
|
-
typed400.httpStatus = 400;
|
|
238
|
-
typed400.providerErrorCode = 'invalid_request_error';
|
|
239
|
-
assert.equal(isRetryableStreamErrorEvent(typed400), false);
|
|
240
|
-
|
|
241
|
-
const quota = new Error('quota');
|
|
242
|
-
quota.providerWireError = true;
|
|
243
|
-
quota.providerErrorCode = 'insufficient_quota';
|
|
244
|
-
assert.equal(isRetryableStreamErrorEvent(quota), false);
|
|
245
|
-
});
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
3
|
-
import { mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import test from 'node:test';
|
|
7
|
-
import {
|
|
8
|
-
compactOffloadedToolResultText,
|
|
9
|
-
maybeOffloadToolResult,
|
|
10
|
-
} from './tool-result-offload.mjs';
|
|
11
|
-
import { normalizeToolEnvelope } from './tool-envelope.mjs';
|
|
12
|
-
import { pruneToolOutputsUnanchored } from './compact/budget.mjs';
|
|
13
|
-
import { executeBuiltinTool } from '../tools/builtin.mjs';
|
|
14
|
-
|
|
15
|
-
test('offload commits exact bytes before replacing provider-visible output', async () => {
|
|
16
|
-
const originalDataDir = process.env.MIXDOG_DATA_DIR;
|
|
17
|
-
const dataDir = mkdtempSync(join(tmpdir(), 'mixdog-lossless-output-'));
|
|
18
|
-
process.env.MIXDOG_DATA_DIR = dataDir;
|
|
19
|
-
try {
|
|
20
|
-
const raw = `head\n${'payload\n'.repeat(8_000)}tail\n`;
|
|
21
|
-
const result = await maybeOffloadToolResult(
|
|
22
|
-
'session-lossless-output',
|
|
23
|
-
'call-lossless-output',
|
|
24
|
-
'shell',
|
|
25
|
-
raw,
|
|
26
|
-
);
|
|
27
|
-
const path = result.match(/→ (.+?) \(/)?.[1];
|
|
28
|
-
const sha256 = createHash('sha256').update(raw).digest('hex');
|
|
29
|
-
assert.ok(path);
|
|
30
|
-
assert.equal(readFileSync(path, 'utf8'), raw);
|
|
31
|
-
assert.match(result, new RegExp(`sha256 ${sha256}`));
|
|
32
|
-
assert.match(result, /preview middle omitted/);
|
|
33
|
-
assert.match(result, /(?:^|\n)head\n/);
|
|
34
|
-
assert.match(result, /tail\n/);
|
|
35
|
-
assert.doesNotMatch(result, /use read/i);
|
|
36
|
-
assert.ok(result.length < 1_024);
|
|
37
|
-
} finally {
|
|
38
|
-
if (originalDataDir === undefined) delete process.env.MIXDOG_DATA_DIR;
|
|
39
|
-
else process.env.MIXDOG_DATA_DIR = originalDataDir;
|
|
40
|
-
rmSync(dataDir, { recursive: true, force: true });
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('identical bytes share one session content-addressed artifact', async () => {
|
|
45
|
-
const originalDataDir = process.env.MIXDOG_DATA_DIR;
|
|
46
|
-
const dataDir = mkdtempSync(join(tmpdir(), 'mixdog-content-addressed-output-'));
|
|
47
|
-
process.env.MIXDOG_DATA_DIR = dataDir;
|
|
48
|
-
try {
|
|
49
|
-
const raw = `same\n${'content\n'.repeat(5_000)}`;
|
|
50
|
-
const first = await maybeOffloadToolResult(
|
|
51
|
-
'session-content-addressed',
|
|
52
|
-
'call-content-addressed-1',
|
|
53
|
-
'shell',
|
|
54
|
-
raw,
|
|
55
|
-
);
|
|
56
|
-
const second = await maybeOffloadToolResult(
|
|
57
|
-
'session-content-addressed',
|
|
58
|
-
'call-content-addressed-2',
|
|
59
|
-
'shell',
|
|
60
|
-
raw,
|
|
61
|
-
);
|
|
62
|
-
const firstPath = first.match(/→ (.+?) \(/)?.[1];
|
|
63
|
-
const secondPath = second.match(/→ (.+?) \(/)?.[1];
|
|
64
|
-
const sha256 = createHash('sha256').update(raw).digest('hex');
|
|
65
|
-
assert.equal(firstPath, secondPath);
|
|
66
|
-
assert.match(firstPath, new RegExp(`${sha256}\\.txt$`));
|
|
67
|
-
assert.deepEqual(
|
|
68
|
-
readdirSync(join(dataDir, 'tool-results', 'session-content-addressed')),
|
|
69
|
-
[`${sha256}.txt`],
|
|
70
|
-
);
|
|
71
|
-
assert.equal(readFileSync(firstPath, 'utf8'), raw);
|
|
72
|
-
} finally {
|
|
73
|
-
if (originalDataDir === undefined) delete process.env.MIXDOG_DATA_DIR;
|
|
74
|
-
else process.env.MIXDOG_DATA_DIR = originalDataDir;
|
|
75
|
-
rmSync(dataDir, { recursive: true, force: true });
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('compaction shortens only artifact-backed previews', () => {
|
|
80
|
-
const raw = 'raw evidence '.repeat(1_000);
|
|
81
|
-
const messages = [
|
|
82
|
-
{ role: 'user', content: 'task' },
|
|
83
|
-
{ role: 'assistant', content: '', toolCalls: [{ id: 'call_raw', name: 'read', arguments: {} }] },
|
|
84
|
-
{ role: 'tool', toolCallId: 'call_raw', toolKind: 'normal', content: raw },
|
|
85
|
-
];
|
|
86
|
-
const pruned = pruneToolOutputsUnanchored(messages, 1, { maxToolOutputChars: 256 });
|
|
87
|
-
assert.equal(pruned[2].content, raw);
|
|
88
|
-
|
|
89
|
-
const offloaded = `[tool output offloaded: shell → C:/safe/result.txt (50 KB, 500 lines, sha256 ${'a'.repeat(64)})]\n\n${raw}`;
|
|
90
|
-
assert.equal(
|
|
91
|
-
compactOffloadedToolResultText(offloaded),
|
|
92
|
-
`${offloaded.split('\n')[0]}\n[preview omitted; full output preserved at the artifact path above]`,
|
|
93
|
-
);
|
|
94
|
-
assert.doesNotMatch(compactOffloadedToolResultText(offloaded), /use read/i);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test('artifact failure preserves the complete inline result', async () => {
|
|
98
|
-
const originalDataDir = process.env.MIXDOG_DATA_DIR;
|
|
99
|
-
const dataDir = mkdtempSync(join(tmpdir(), 'mixdog-lossless-fail-open-'));
|
|
100
|
-
process.env.MIXDOG_DATA_DIR = dataDir;
|
|
101
|
-
try {
|
|
102
|
-
writeFileSync(join(dataDir, 'tool-results'), 'not a directory');
|
|
103
|
-
const raw = 'x'.repeat(40_000);
|
|
104
|
-
assert.equal(
|
|
105
|
-
await maybeOffloadToolResult('session-fail-open', 'call-fail-open', 'shell', raw),
|
|
106
|
-
raw,
|
|
107
|
-
);
|
|
108
|
-
} finally {
|
|
109
|
-
if (originalDataDir === undefined) delete process.env.MIXDOG_DATA_DIR;
|
|
110
|
-
else process.env.MIXDOG_DATA_DIR = originalDataDir;
|
|
111
|
-
rmSync(dataDir, { recursive: true, force: true });
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test('completed shell output is not middle-truncated at 400 lines', async () => {
|
|
116
|
-
const result = normalizeToolEnvelope(await executeBuiltinTool(
|
|
117
|
-
'shell',
|
|
118
|
-
{ command: `node -e "for (let i=0;i<450;i++) console.log('line-'+i)"`, timeout_ms: 10_000 },
|
|
119
|
-
process.cwd(),
|
|
120
|
-
{ sessionId: 'session-shell-lines', toolCallId: 'call-shell-lines' },
|
|
121
|
-
));
|
|
122
|
-
assert.doesNotMatch(result.result, /lines omitted|tool-output truncated/);
|
|
123
|
-
assert.match(result.result, /(?:^|\n)line-0\n/);
|
|
124
|
-
assert.match(result.result, /(?:^|\n)line-449(?:\n|$)/);
|
|
125
|
-
});
|