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
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, extname, basename, join } from 'node:path';
|
|
3
|
+
import { createCanvas, loadImage } from '@napi-rs/canvas';
|
|
4
|
+
|
|
5
|
+
function imageByPage(images) {
|
|
6
|
+
return new Map((images || []).map((image) => [Number(image.page), image]));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function compareRenderedPages(beforeImages, afterImages, outputPdf) {
|
|
10
|
+
const before = imageByPage(beforeImages);
|
|
11
|
+
const after = imageByPage(afterImages);
|
|
12
|
+
const pages = [...new Set([...before.keys(), ...after.keys()])].sort((left, right) => left - right);
|
|
13
|
+
const metrics = [];
|
|
14
|
+
const images = [];
|
|
15
|
+
const stem = basename(outputPdf, extname(outputPdf));
|
|
16
|
+
for (const page of pages) {
|
|
17
|
+
const beforeImage = before.get(page);
|
|
18
|
+
const afterImage = after.get(page);
|
|
19
|
+
const left = beforeImage ? await loadImage(Buffer.from(beforeImage.data, 'base64')) : null;
|
|
20
|
+
const right = afterImage ? await loadImage(Buffer.from(afterImage.data, 'base64')) : null;
|
|
21
|
+
const width = Math.max(left?.width || 0, right?.width || 0);
|
|
22
|
+
const height = Math.max(left?.height || 0, right?.height || 0);
|
|
23
|
+
if (!width || !height) continue;
|
|
24
|
+
const beforeCanvas = createCanvas(width, height);
|
|
25
|
+
const afterCanvas = createCanvas(width, height);
|
|
26
|
+
for (const [canvas, image] of [[beforeCanvas, left], [afterCanvas, right]]) {
|
|
27
|
+
const context = canvas.getContext('2d');
|
|
28
|
+
context.fillStyle = '#ffffff';
|
|
29
|
+
context.fillRect(0, 0, width, height);
|
|
30
|
+
if (image) context.drawImage(image, 0, 0);
|
|
31
|
+
}
|
|
32
|
+
const beforePixels = beforeCanvas.getContext('2d').getImageData(0, 0, width, height).data;
|
|
33
|
+
const afterPixels = afterCanvas.getContext('2d').getImageData(0, 0, width, height).data;
|
|
34
|
+
const diffCanvas = createCanvas(width, height);
|
|
35
|
+
const diffContext = diffCanvas.getContext('2d');
|
|
36
|
+
const diff = diffContext.createImageData(width, height);
|
|
37
|
+
let changed = 0;
|
|
38
|
+
for (let index = 0; index < afterPixels.length; index += 4) {
|
|
39
|
+
const delta = Math.max(
|
|
40
|
+
Math.abs(beforePixels[index] - afterPixels[index]),
|
|
41
|
+
Math.abs(beforePixels[index + 1] - afterPixels[index + 1]),
|
|
42
|
+
Math.abs(beforePixels[index + 2] - afterPixels[index + 2]),
|
|
43
|
+
);
|
|
44
|
+
const pixel = index / 4;
|
|
45
|
+
if (delta >= 24) {
|
|
46
|
+
changed += 1;
|
|
47
|
+
diff.data[index] = 239;
|
|
48
|
+
diff.data[index + 1] = 68;
|
|
49
|
+
diff.data[index + 2] = 68;
|
|
50
|
+
diff.data[index + 3] = 230;
|
|
51
|
+
} else {
|
|
52
|
+
const gray = Math.round((afterPixels[index] + afterPixels[index + 1] + afterPixels[index + 2]) / 3);
|
|
53
|
+
diff.data[index] = gray;
|
|
54
|
+
diff.data[index + 1] = gray;
|
|
55
|
+
diff.data[index + 2] = gray;
|
|
56
|
+
diff.data[index + 3] = 55;
|
|
57
|
+
}
|
|
58
|
+
if (pixel >= width * height) break;
|
|
59
|
+
}
|
|
60
|
+
diffContext.putImageData(diff, 0, 0);
|
|
61
|
+
const data = diffCanvas.toBuffer('image/png');
|
|
62
|
+
const path = join(dirname(outputPdf), `${stem}-visual-diff-page-${page}.png`);
|
|
63
|
+
await writeFile(path, data);
|
|
64
|
+
const total = width * height;
|
|
65
|
+
metrics.push({
|
|
66
|
+
page,
|
|
67
|
+
changedPixels: changed,
|
|
68
|
+
totalPixels: total,
|
|
69
|
+
changedPercent: Number(((changed / total) * 100).toFixed(3)),
|
|
70
|
+
});
|
|
71
|
+
images.push({
|
|
72
|
+
page,
|
|
73
|
+
path,
|
|
74
|
+
width,
|
|
75
|
+
height,
|
|
76
|
+
mimeType: 'image/png',
|
|
77
|
+
data: data.toString('base64'),
|
|
78
|
+
kind: 'visual-diff',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
available: metrics.length > 0,
|
|
83
|
+
pages: metrics,
|
|
84
|
+
changedPercent: metrics.length
|
|
85
|
+
? Number((metrics.reduce((sum, item) => sum + item.changedPercent, 0) / metrics.length).toFixed(3))
|
|
86
|
+
: 0,
|
|
87
|
+
images,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
const ERROR_VALUE = /^(?:#REF!|#DIV\/0!|#VALUE!|#NAME\?|#N\/A|#NUM!|#NULL!)$/i;
|
|
2
|
+
|
|
3
|
+
function cellsFromDocument(document) {
|
|
4
|
+
const cells = [];
|
|
5
|
+
for (const sheet of document?.sheets || []) {
|
|
6
|
+
for (const cell of sheet.cells || []) cells.push({ ...cell, sheet: sheet.name });
|
|
7
|
+
for (const block of sheet.rowBlocks || []) {
|
|
8
|
+
for (const row of block.rows || []) {
|
|
9
|
+
for (const cell of row.cells || []) cells.push({ ...cell, sheet: sheet.name });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return cells;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function cellIndex(document) {
|
|
17
|
+
return new Map(cellsFromDocument(document).map((cell) => [
|
|
18
|
+
`${String(cell.sheet).toLowerCase()}!${String(cell.ref).toUpperCase()}`,
|
|
19
|
+
cell,
|
|
20
|
+
]));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function reference(value, fallbackSheet = '') {
|
|
24
|
+
if (typeof value === 'number') return { literal: value };
|
|
25
|
+
if (value && typeof value === 'object' && value.cell) {
|
|
26
|
+
return { sheet: String(value.sheet || fallbackSheet), cell: String(value.cell).toUpperCase() };
|
|
27
|
+
}
|
|
28
|
+
const match = /^(?:(?:'([^']+)'|([^!]+))!)?(\$?[A-Z]{1,3}\$?[1-9]\d*)$/.exec(String(value || '').trim());
|
|
29
|
+
if (!match) return null;
|
|
30
|
+
return {
|
|
31
|
+
sheet: String(match[1] || match[2] || fallbackSheet),
|
|
32
|
+
cell: match[3].replaceAll('$', '').toUpperCase(),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function numeric(value) {
|
|
37
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value;
|
|
38
|
+
const parsed = Number(value);
|
|
39
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function sameValue(actual, expected, tolerance = 0) {
|
|
43
|
+
const left = numeric(actual);
|
|
44
|
+
const right = numeric(expected);
|
|
45
|
+
if (left !== null && right !== null) return Math.abs(left - right) <= Math.max(0, Number(tolerance) || 0);
|
|
46
|
+
return String(actual ?? '') === String(expected ?? '');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function columnNumber(label) {
|
|
50
|
+
let value = 0;
|
|
51
|
+
for (const character of String(label).toUpperCase()) value = value * 26 + character.charCodeAt(0) - 64;
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function parsedCell(value) {
|
|
56
|
+
const match = /^([A-Z]{1,3})([1-9]\d*)$/i.exec(String(value || '').replaceAll('$', ''));
|
|
57
|
+
return match ? { column: columnNumber(match[1]), row: Number(match[2]) } : null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function parsedRange(value) {
|
|
61
|
+
const match = /^(\$?[A-Z]{1,3}\$?[1-9]\d*):(\$?[A-Z]{1,3}\$?[1-9]\d*)$/i.exec(String(value || '').trim());
|
|
62
|
+
if (!match) return null;
|
|
63
|
+
const start = parsedCell(match[1]);
|
|
64
|
+
const end = parsedCell(match[2]);
|
|
65
|
+
return {
|
|
66
|
+
startRow: Math.min(start.row, end.row),
|
|
67
|
+
endRow: Math.max(start.row, end.row),
|
|
68
|
+
startColumn: Math.min(start.column, end.column),
|
|
69
|
+
endColumn: Math.max(start.column, end.column),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function cellsForAssertion(document, assertion) {
|
|
74
|
+
const range = parsedRange(assertion?.range);
|
|
75
|
+
return cellsFromDocument(document).filter((cell) => {
|
|
76
|
+
if (assertion?.sheet && String(cell.sheet).toLowerCase() !== String(assertion.sheet).toLowerCase()) return false;
|
|
77
|
+
if (!range) return true;
|
|
78
|
+
const parsed = parsedCell(cell.ref);
|
|
79
|
+
return Boolean(parsed)
|
|
80
|
+
&& parsed.row >= range.startRow
|
|
81
|
+
&& parsed.row <= range.endRow
|
|
82
|
+
&& parsed.column >= range.startColumn
|
|
83
|
+
&& parsed.column <= range.endColumn;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function normalizeFormula(formula, origin) {
|
|
88
|
+
const base = parsedCell(origin);
|
|
89
|
+
return String(formula || '')
|
|
90
|
+
.replace(/\s+/g, '')
|
|
91
|
+
.replace(/(\$?)([A-Z]{1,3})(\$?)([1-9]\d*)/gi, (_all, absoluteColumn, label, absoluteRow, row) => {
|
|
92
|
+
if (!base) return '#REF';
|
|
93
|
+
const column = columnNumber(label);
|
|
94
|
+
const rowNumber = Number(row);
|
|
95
|
+
return `${absoluteRow ? `R${rowNumber}` : `R[${rowNumber - base.row}]`}${absoluteColumn ? `C${column}` : `C[${column - base.column}]`}`;
|
|
96
|
+
})
|
|
97
|
+
.toUpperCase();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function issue(assertion, index, code, message, path = '/') {
|
|
101
|
+
return {
|
|
102
|
+
severity: 'error',
|
|
103
|
+
code,
|
|
104
|
+
path,
|
|
105
|
+
assertion: index + 1,
|
|
106
|
+
message,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function evaluateXlsxAssertions(document, assertions = []) {
|
|
111
|
+
const index = cellIndex(document);
|
|
112
|
+
const issues = [];
|
|
113
|
+
const results = [];
|
|
114
|
+
const get = (value, fallbackSheet = '') => {
|
|
115
|
+
const parsed = reference(value, fallbackSheet);
|
|
116
|
+
if (!parsed) return null;
|
|
117
|
+
if (parsed.literal !== undefined) return { value: parsed.literal, path: '' };
|
|
118
|
+
return index.get(`${parsed.sheet.toLowerCase()}!${parsed.cell}`) || null;
|
|
119
|
+
};
|
|
120
|
+
assertions.forEach((assertion, assertionIndex) => {
|
|
121
|
+
const kind = String(assertion?.kind || '').toLowerCase();
|
|
122
|
+
const sheet = String(assertion?.sheet || document?.sheets?.[0]?.name || '');
|
|
123
|
+
const target = assertion?.cell ? get({ sheet, cell: assertion.cell }) : null;
|
|
124
|
+
let passed = true;
|
|
125
|
+
if (kind === 'cell-value') {
|
|
126
|
+
passed = Boolean(target) && sameValue(target.value, assertion.equals, assertion.tolerance);
|
|
127
|
+
if (!passed) issues.push(issue(assertion, assertionIndex, 'assertion_value_mismatch', `Expected ${sheet}!${assertion.cell} to equal ${JSON.stringify(assertion.equals)}; actual value is ${JSON.stringify(target?.value ?? null)}.`, target?.path || `/sheet[${sheet}]/cell[${assertion.cell}]`));
|
|
128
|
+
} else if (kind === 'cell-formula') {
|
|
129
|
+
const actual = String(target?.formula || '');
|
|
130
|
+
const comparableActual = actual.replace(/^=/, '');
|
|
131
|
+
const comparableExpected = String(assertion.equals ?? '').replace(/^=/, '');
|
|
132
|
+
passed = Boolean(target) && (assertion.equals !== undefined
|
|
133
|
+
? comparableActual === comparableExpected
|
|
134
|
+
: new RegExp(String(assertion.matches || '')).test(actual));
|
|
135
|
+
if (!passed) issues.push(issue(assertion, assertionIndex, 'assertion_formula_mismatch', `Formula assertion failed for ${sheet}!${assertion.cell}; actual formula is ${JSON.stringify(actual)}.`, target?.path || `/sheet[${sheet}]/cell[${assertion.cell}]`));
|
|
136
|
+
} else if (kind === 'tie-out') {
|
|
137
|
+
const left = get(assertion.left, sheet);
|
|
138
|
+
const right = get(assertion.right, sheet);
|
|
139
|
+
passed = Boolean(left && right) && sameValue(left.value, right.value, assertion.tolerance);
|
|
140
|
+
if (!passed) issues.push(issue(assertion, assertionIndex, 'assertion_tie_out_failed', `Tie-out failed: ${JSON.stringify(assertion.left)}=${JSON.stringify(left?.value ?? null)} and ${JSON.stringify(assertion.right)}=${JSON.stringify(right?.value ?? null)}.`, left?.path || right?.path || '/'));
|
|
141
|
+
} else if (kind === 'no-errors') {
|
|
142
|
+
const failures = cellsForAssertion(document, assertion).filter((cell) => (
|
|
143
|
+
ERROR_VALUE.test(String(cell.value || ''))
|
|
144
|
+
));
|
|
145
|
+
passed = failures.length === 0;
|
|
146
|
+
for (const cell of failures.slice(0, 100)) issues.push(issue(assertion, assertionIndex, 'assertion_formula_error', `Formula error ${cell.value} violates no-errors assertion.`, cell.path));
|
|
147
|
+
} else if (kind === 'formula-consistency') {
|
|
148
|
+
const formulas = cellsForAssertion(document, assertion).filter((cell) => cell.formula);
|
|
149
|
+
const patterns = new Map();
|
|
150
|
+
for (const cell of formulas) {
|
|
151
|
+
const pattern = normalizeFormula(cell.formula, cell.ref);
|
|
152
|
+
patterns.set(pattern, (patterns.get(pattern) || 0) + 1);
|
|
153
|
+
}
|
|
154
|
+
const expected = [...patterns.entries()].sort((left, right) => right[1] - left[1])[0]?.[0] || '';
|
|
155
|
+
const inconsistent = formulas.filter((cell) => normalizeFormula(cell.formula, cell.ref) !== expected);
|
|
156
|
+
passed = formulas.length > 0 && inconsistent.length === 0;
|
|
157
|
+
if (!formulas.length) issues.push(issue(assertion, assertionIndex, 'assertion_formula_missing', 'Formula-consistency assertion found no formulas.', `/sheet[${assertion.sheet || sheet}]`));
|
|
158
|
+
for (const cell of inconsistent.slice(0, 100)) issues.push(issue(assertion, assertionIndex, 'assertion_formula_inconsistent', 'Formula differs from the dominant pattern in the asserted region.', cell.path));
|
|
159
|
+
} else {
|
|
160
|
+
passed = false;
|
|
161
|
+
issues.push(issue(assertion, assertionIndex, 'assertion_kind_unknown', `Unknown XLSX assertion kind: ${kind || '(missing)'}`));
|
|
162
|
+
}
|
|
163
|
+
results.push({ index: assertionIndex + 1, kind, passed });
|
|
164
|
+
});
|
|
165
|
+
return {
|
|
166
|
+
ok: issues.length === 0,
|
|
167
|
+
checked: assertions.length,
|
|
168
|
+
passed: results.filter((entry) => entry.passed).length,
|
|
169
|
+
results,
|
|
170
|
+
issues,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
export const XLSX_MAX_ROWS = 1_048_576;
|
|
2
|
+
export const XLSX_MAX_COLUMNS = 16_384;
|
|
3
|
+
export const XLSX_MAX_RANGE_CELLS = 100_000;
|
|
4
|
+
|
|
5
|
+
function columnNumber(label) {
|
|
6
|
+
let value = 0;
|
|
7
|
+
for (const character of String(label || '').toUpperCase()) {
|
|
8
|
+
value = (value * 26) + character.charCodeAt(0) - 64;
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function parseXlsxCell(reference) {
|
|
14
|
+
const match = /^([A-Z]+)([1-9]\d*)$/i.exec(String(reference || '').trim());
|
|
15
|
+
if (!match) throw new Error(`Invalid XLSX cell reference: ${reference}`);
|
|
16
|
+
const column = columnNumber(match[1]);
|
|
17
|
+
const row = Number(match[2]);
|
|
18
|
+
if (column < 1 || column > XLSX_MAX_COLUMNS) {
|
|
19
|
+
throw new Error(`XLSX column must be between A and XFD: ${reference}`);
|
|
20
|
+
}
|
|
21
|
+
if (row < 1 || row > XLSX_MAX_ROWS) {
|
|
22
|
+
throw new Error(`XLSX row must be between 1 and ${XLSX_MAX_ROWS}: ${reference}`);
|
|
23
|
+
}
|
|
24
|
+
return { ref: `${match[1].toUpperCase()}${row}`, row, column };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function parseXlsxRange(reference, { maxCells = XLSX_MAX_RANGE_CELLS } = {}) {
|
|
28
|
+
const match = /^([^:]+):([^:]+)$/.exec(String(reference || '').trim());
|
|
29
|
+
if (!match) throw new Error(`Invalid XLSX range: ${reference}`);
|
|
30
|
+
const start = parseXlsxCell(match[1]);
|
|
31
|
+
const end = parseXlsxCell(match[2]);
|
|
32
|
+
if (start.row > end.row || start.column > end.column) {
|
|
33
|
+
throw new Error(`XLSX range start must not follow range end: ${reference}`);
|
|
34
|
+
}
|
|
35
|
+
const rows = end.row - start.row + 1;
|
|
36
|
+
const columns = end.column - start.column + 1;
|
|
37
|
+
const cells = rows * columns;
|
|
38
|
+
if (cells > maxCells) {
|
|
39
|
+
throw new Error(`XLSX range contains ${cells} cells; maximum is ${maxCells}`);
|
|
40
|
+
}
|
|
41
|
+
return { start, end, rows, columns, cells };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function parseXlsxAutofitRange(reference) {
|
|
45
|
+
const text = String(reference || '').trim();
|
|
46
|
+
const columns = /^([A-Z]+):([A-Z]+)$/i.exec(text);
|
|
47
|
+
if (columns) {
|
|
48
|
+
const start = columnNumber(columns[1]);
|
|
49
|
+
const end = columnNumber(columns[2]);
|
|
50
|
+
if (start < 1 || end > XLSX_MAX_COLUMNS || start > end) {
|
|
51
|
+
throw new Error(`Invalid XLSX column range: ${reference}`);
|
|
52
|
+
}
|
|
53
|
+
return { type: 'columns', start, end };
|
|
54
|
+
}
|
|
55
|
+
const rows = /^([1-9]\d*):([1-9]\d*)$/.exec(text);
|
|
56
|
+
if (rows) {
|
|
57
|
+
const start = Number(rows[1]);
|
|
58
|
+
const end = Number(rows[2]);
|
|
59
|
+
if (end > XLSX_MAX_ROWS || start > end) throw new Error(`Invalid XLSX row range: ${reference}`);
|
|
60
|
+
return { type: 'rows', start, end };
|
|
61
|
+
}
|
|
62
|
+
return { type: 'cells', ...parseXlsxRange(text) };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function validateRangeMatrix(operation, area) {
|
|
66
|
+
if (!Array.isArray(operation.values)) {
|
|
67
|
+
throw new Error('XLSX set_range requires values as a row matrix');
|
|
68
|
+
}
|
|
69
|
+
if (operation.values.length !== area.rows) {
|
|
70
|
+
throw new Error(`XLSX set_range expected ${area.rows} value row(s), received ${operation.values.length}`);
|
|
71
|
+
}
|
|
72
|
+
for (let index = 0; index < operation.values.length; index += 1) {
|
|
73
|
+
const row = operation.values[index];
|
|
74
|
+
if (!Array.isArray(row) || row.length !== area.columns) {
|
|
75
|
+
throw new Error(`XLSX set_range row ${index + 1} expected ${area.columns} value(s), received ${Array.isArray(row) ? row.length : 'a non-array'}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function validateXlsxOperations(operations) {
|
|
81
|
+
for (const operation of operations || []) {
|
|
82
|
+
if (!operation || typeof operation !== 'object') throw new Error('XLSX operation must be an object');
|
|
83
|
+
const op = String(operation.op || '');
|
|
84
|
+
if (['set_cell', 'set_formula', 'clear_cell', 'add_note', 'delete_note'].includes(op)) {
|
|
85
|
+
parseXlsxCell(operation.cell);
|
|
86
|
+
}
|
|
87
|
+
if (op === 'freeze_panes') {
|
|
88
|
+
const row = operation.row ?? 1;
|
|
89
|
+
const column = operation.column ?? 0;
|
|
90
|
+
if (!Number.isInteger(row) || row < 0 || row > XLSX_MAX_ROWS) {
|
|
91
|
+
throw new Error(`XLSX freeze_panes row must be between 0 and ${XLSX_MAX_ROWS}`);
|
|
92
|
+
}
|
|
93
|
+
if (!Number.isInteger(column) || column < 0 || column > XLSX_MAX_COLUMNS) {
|
|
94
|
+
throw new Error(`XLSX freeze_panes column must be between 0 and ${XLSX_MAX_COLUMNS}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (op === 'set_style' && operation.cell) parseXlsxCell(operation.cell);
|
|
98
|
+
if (operation.range && [
|
|
99
|
+
'set_range',
|
|
100
|
+
'set_style',
|
|
101
|
+
'add_table',
|
|
102
|
+
'add_chart',
|
|
103
|
+
'add_conditional_format',
|
|
104
|
+
'add_validation',
|
|
105
|
+
].includes(op)) {
|
|
106
|
+
const area = parseXlsxRange(operation.range);
|
|
107
|
+
if (op === 'set_range') validateRangeMatrix(operation, area);
|
|
108
|
+
} else if (op === 'set_range') {
|
|
109
|
+
throw new Error('XLSX set_range requires range');
|
|
110
|
+
}
|
|
111
|
+
if (op === 'autofit_range') {
|
|
112
|
+
if (!operation.range) throw new Error('XLSX autofit_range requires range');
|
|
113
|
+
parseXlsxAutofitRange(operation.range);
|
|
114
|
+
}
|
|
115
|
+
if (op === 'append_row') {
|
|
116
|
+
if (!Array.isArray(operation.values)) throw new Error('XLSX append_row requires values');
|
|
117
|
+
if (operation.values.length > XLSX_MAX_COLUMNS) {
|
|
118
|
+
throw new Error(`XLSX append_row contains ${operation.values.length} values; maximum is ${XLSX_MAX_COLUMNS}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (['insert_rows', 'delete_rows'].includes(op)) {
|
|
122
|
+
const row = operation.row;
|
|
123
|
+
const count = operation.count ?? 1;
|
|
124
|
+
if (!Number.isInteger(row) || row < 1 || row > XLSX_MAX_ROWS) {
|
|
125
|
+
throw new Error(`XLSX ${op} row must be between 1 and ${XLSX_MAX_ROWS}`);
|
|
126
|
+
}
|
|
127
|
+
if (!Number.isInteger(count) || count < 1 || row + count - 1 > XLSX_MAX_ROWS) {
|
|
128
|
+
throw new Error(`XLSX ${op} count exceeds the worksheet row limit`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (['insert_columns', 'delete_columns'].includes(op)) {
|
|
132
|
+
const column = operation.column;
|
|
133
|
+
const count = operation.count ?? 1;
|
|
134
|
+
if (!Number.isInteger(column) || column < 1 || column > XLSX_MAX_COLUMNS) {
|
|
135
|
+
throw new Error(`XLSX ${op} column must be between 1 and ${XLSX_MAX_COLUMNS}`);
|
|
136
|
+
}
|
|
137
|
+
if (!Number.isInteger(count) || count < 1 || column + count - 1 > XLSX_MAX_COLUMNS) {
|
|
138
|
+
throw new Error(`XLSX ${op} count exceeds the worksheet column limit`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (['merge_cells', 'unmerge_cells', 'set_autofilter'].includes(op)) {
|
|
142
|
+
if (!operation.range) throw new Error(`XLSX ${op} requires range`);
|
|
143
|
+
parseXlsxRange(operation.range);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return operations;
|
|
147
|
+
}
|
|
@@ -3,6 +3,15 @@ const REDUNDANT_WORKFLOW_PRESET_IDS = new Set([
|
|
|
3
3
|
'workflow-memory',
|
|
4
4
|
]);
|
|
5
5
|
|
|
6
|
+
export const DEFAULT_DISABLED_AGENT_IDS = Object.freeze([
|
|
7
|
+
'worker',
|
|
8
|
+
'heavy-worker',
|
|
9
|
+
'reviewer',
|
|
10
|
+
'security',
|
|
11
|
+
'front-worker',
|
|
12
|
+
'writer',
|
|
13
|
+
]);
|
|
14
|
+
|
|
6
15
|
function record(value) {
|
|
7
16
|
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
8
17
|
}
|
|
@@ -185,6 +185,22 @@ const INTERNAL_TRANSCRIPT_CONTEXT_RE =
|
|
|
185
185
|
const INTERNAL_TRANSCRIPT_SYNTHETIC_RE =
|
|
186
186
|
/^(?:\[mixdog-runtime\]|A previous model worked on this task and produced the compacted handoff summary below\b|Re-attached after compaction\b|Reference files:\s)/i;
|
|
187
187
|
const INTERNAL_TRANSCRIPT_ASYNC_HEAD_RE = /^Async .+ finished\./i;
|
|
188
|
+
const TRANSCRIPT_HIDDEN_CONTROL_TOOL_NAMES = new Set([
|
|
189
|
+
'goal',
|
|
190
|
+
'create_goal',
|
|
191
|
+
'get_goal',
|
|
192
|
+
'set_goal_tasks',
|
|
193
|
+
'update_goal',
|
|
194
|
+
'load_tool',
|
|
195
|
+
'tool_search',
|
|
196
|
+
'skill',
|
|
197
|
+
]);
|
|
198
|
+
|
|
199
|
+
export function isTranscriptHiddenControlToolName(name) {
|
|
200
|
+
const normalized = clean(name).toLowerCase().replace(/^functions\./, '');
|
|
201
|
+
return TRANSCRIPT_HIDDEN_CONTROL_TOOL_NAMES.has(normalized);
|
|
202
|
+
}
|
|
203
|
+
|
|
188
204
|
// Persisted USER cancellation control rows ("[Request interrupted by user]"
|
|
189
205
|
// and its tool-use variant) exist for the next model step, not for humans:
|
|
190
206
|
// the human already saw the cancel they typed. The live engine path already
|
|
@@ -157,6 +157,8 @@ export function displayToolName(name, args = {}) {
|
|
|
157
157
|
return 'Browser';
|
|
158
158
|
case 'computer':
|
|
159
159
|
return 'Computer';
|
|
160
|
+
case 'office':
|
|
161
|
+
return 'Office';
|
|
160
162
|
case 'list_mcp_resources':
|
|
161
163
|
case 'list_mcp_resource_templates':
|
|
162
164
|
case 'cwd':
|
|
@@ -289,6 +291,11 @@ export function summarizeToolArgs(name, args, { max = DEFAULT_SUMMARY_MAX } = {}
|
|
|
289
291
|
String(a.action || ''),
|
|
290
292
|
a.window ? truncateToolText(a.window, max) : a.ref ? String(a.ref) : a.app ? truncateToolText(a.app, max) : '',
|
|
291
293
|
]);
|
|
294
|
+
case 'office':
|
|
295
|
+
return compactParts([
|
|
296
|
+
String(a.action || ''),
|
|
297
|
+
a.path ? truncateToolText(a.path, max) : a.session ? String(a.session) : '',
|
|
298
|
+
]);
|
|
292
299
|
case 'read_mcp_resource':
|
|
293
300
|
return truncateToolText(a.uri || '', max);
|
|
294
301
|
case 'list_mcp_resources':
|
|
@@ -577,6 +584,8 @@ export function toolWorkUnit(name, args = {}, category = '') {
|
|
|
577
584
|
return unitDescriptor('Browser', { count: 1, active: 'Browsing', done: 'Browsed', noun: 'action' });
|
|
578
585
|
case 'computer':
|
|
579
586
|
return unitDescriptor('Computer', { count: 1, active: 'Operating', done: 'Operated', noun: 'action' });
|
|
587
|
+
case 'office':
|
|
588
|
+
return unitDescriptor('Office', { count: 1, active: 'Editing', done: 'Edited', noun: 'document action' });
|
|
580
589
|
case 'fetch': {
|
|
581
590
|
const fetchLimit = Number(a.limit ?? a.messages);
|
|
582
591
|
const fetchCount = Number.isFinite(fetchLimit) && fetchLimit > 0
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { SUMMARY_PREFIX } from '../runtime/agent/orchestrator/session/compact.mjs';
|
|
12
12
|
import { hasUserConversationMessage } from '../runtime/agent/orchestrator/session/manager/prompt-utils.mjs';
|
|
13
13
|
import {
|
|
14
|
+
resolveContextUsageSnapshot,
|
|
14
15
|
resolveGaugeContextTokens,
|
|
15
16
|
resolveWorkerCompactPolicy,
|
|
16
17
|
} from '../runtime/agent/orchestrator/session/loop/compact-policy.mjs';
|
|
@@ -115,6 +116,7 @@ export function createContextStatus({
|
|
|
115
116
|
compactionTriggerTokens: Number(compaction.triggerTokens || 0),
|
|
116
117
|
compactionLastChangedAt: Number(compaction.lastChangedAt || 0),
|
|
117
118
|
compactionLastCompactAt: Number(compaction.lastCompactAt || 0),
|
|
119
|
+
contextUsageSnapshot: session?.contextUsageSnapshot || null,
|
|
118
120
|
};
|
|
119
121
|
}
|
|
120
122
|
|
|
@@ -268,9 +270,13 @@ export function createContextStatus({
|
|
|
268
270
|
...resolveSessionCompactPolicy(session || {}, compactBoundaryTokens),
|
|
269
271
|
tokenCalibration: providerTokenCalibration(session?.provider || route.provider),
|
|
270
272
|
};
|
|
271
|
-
//
|
|
272
|
-
//
|
|
273
|
-
|
|
273
|
+
// A successful compaction publishes one durable post-mutation reading.
|
|
274
|
+
// Polling and cold resume keep that exact value until a fresh provider
|
|
275
|
+
// baseline or a changed transcript/route/tool surface invalidates it.
|
|
276
|
+
const usageSnapshot = (!lastContextTokens || lastUsageStale)
|
|
277
|
+
? resolveContextUsageSnapshot(session, compactPolicy, { messages })
|
|
278
|
+
: null;
|
|
279
|
+
const usedTokens = usageSnapshot?.usedTokens ?? resolveGaugeContextTokens(
|
|
274
280
|
messageSummary.estimatedTokens,
|
|
275
281
|
compactPolicy,
|
|
276
282
|
{ messages, sessionRef: session },
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { clean } from './session-text.mjs';
|
|
2
|
+
|
|
3
|
+
function compactDescription(value) {
|
|
4
|
+
return String(value || '')
|
|
5
|
+
.replace(/\s+/g, ' ')
|
|
6
|
+
.replace(/[<>]/g, '')
|
|
7
|
+
.trim()
|
|
8
|
+
.slice(0, 240);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function normalizedDelta(value) {
|
|
12
|
+
const source = value && typeof value === 'object' ? value : {};
|
|
13
|
+
const addedByName = new Map();
|
|
14
|
+
for (const entry of Array.isArray(source.added) ? source.added : []) {
|
|
15
|
+
const name = clean(entry?.name);
|
|
16
|
+
if (name) addedByName.set(name, { name, description: compactDescription(entry?.description) });
|
|
17
|
+
}
|
|
18
|
+
const removed = new Set(
|
|
19
|
+
(Array.isArray(source.removed) ? source.removed : [])
|
|
20
|
+
.map((entry) => clean(typeof entry === 'string' ? entry : entry?.name))
|
|
21
|
+
.filter(Boolean),
|
|
22
|
+
);
|
|
23
|
+
for (const name of addedByName.keys()) removed.delete(name);
|
|
24
|
+
return {
|
|
25
|
+
revision: Math.max(0, Number(source.revision) || 0),
|
|
26
|
+
addedByName,
|
|
27
|
+
removed,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function mergePendingDeferredToolDelta(session, change = {}) {
|
|
32
|
+
if (!session || typeof session !== 'object') return null;
|
|
33
|
+
const current = normalizedDelta(session.pendingDeferredToolDelta);
|
|
34
|
+
const nextRevision = Math.max(
|
|
35
|
+
current.revision,
|
|
36
|
+
Math.max(0, Number(session.deferredToolDeltaRevision) || 0),
|
|
37
|
+
) + 1;
|
|
38
|
+
for (const entry of Array.isArray(change.added) ? change.added : []) {
|
|
39
|
+
const name = clean(entry?.name);
|
|
40
|
+
if (!name) continue;
|
|
41
|
+
if (current.removed.delete(name)) continue;
|
|
42
|
+
current.addedByName.set(name, {
|
|
43
|
+
name,
|
|
44
|
+
description: compactDescription(entry?.description),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
for (const entry of Array.isArray(change.removed) ? change.removed : []) {
|
|
48
|
+
const name = clean(typeof entry === 'string' ? entry : entry?.name);
|
|
49
|
+
if (!name) continue;
|
|
50
|
+
if (current.addedByName.delete(name)) continue;
|
|
51
|
+
current.removed.add(name);
|
|
52
|
+
}
|
|
53
|
+
const added = [...current.addedByName.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
54
|
+
const removed = [...current.removed].sort();
|
|
55
|
+
if (!added.length && !removed.length) {
|
|
56
|
+
session.deferredToolDeltaRevision = nextRevision;
|
|
57
|
+
delete session.pendingDeferredToolDelta;
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
session.deferredToolDeltaRevision = nextRevision;
|
|
61
|
+
session.pendingDeferredToolDelta = {
|
|
62
|
+
version: 1,
|
|
63
|
+
type: 'deferred_tools_delta',
|
|
64
|
+
revision: nextRevision,
|
|
65
|
+
added,
|
|
66
|
+
removed,
|
|
67
|
+
};
|
|
68
|
+
session.updatedAt = Date.now();
|
|
69
|
+
return session.pendingDeferredToolDelta;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function snapshotPendingDeferredToolDelta(session) {
|
|
73
|
+
const current = normalizedDelta(session?.pendingDeferredToolDelta);
|
|
74
|
+
const added = [...current.addedByName.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
75
|
+
const removed = [...current.removed].sort();
|
|
76
|
+
if (!added.length && !removed.length) return null;
|
|
77
|
+
const lines = ['<system-reminder>', '<deferred_tools_delta>'];
|
|
78
|
+
if (added.length) {
|
|
79
|
+
lines.push('Added deferred tools:');
|
|
80
|
+
for (const entry of added) {
|
|
81
|
+
lines.push(entry.description ? `- ${entry.name}: ${entry.description}` : `- ${entry.name}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (removed.length) {
|
|
85
|
+
lines.push('Removed deferred tools:');
|
|
86
|
+
for (const name of removed) lines.push(`- ${name}`);
|
|
87
|
+
}
|
|
88
|
+
lines.push('</deferred_tools_delta>', '</system-reminder>');
|
|
89
|
+
return {
|
|
90
|
+
revision: current.revision,
|
|
91
|
+
added,
|
|
92
|
+
removed,
|
|
93
|
+
content: lines.join('\n'),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function acknowledgePendingDeferredToolDelta(session, revision) {
|
|
98
|
+
if (!session || typeof session !== 'object') return false;
|
|
99
|
+
const current = normalizedDelta(session.pendingDeferredToolDelta);
|
|
100
|
+
if (!current.revision || current.revision !== Number(revision)) return false;
|
|
101
|
+
delete session.pendingDeferredToolDelta;
|
|
102
|
+
session.updatedAt = Date.now();
|
|
103
|
+
return true;
|
|
104
|
+
}
|