mixdog 0.9.151 → 0.9.153
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 +108 -68
- package/package.json +17 -4
- package/scripts/computer-task-cost-report.mjs +144 -0
- package/scripts/run-office-live-tests.mjs +32 -0
- package/scripts/tool-stress.mjs +0 -2
- 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/defaults/skills/setup/SKILL.md +18 -27
- package/src/headless-exec.mjs +3 -10
- package/src/headless-exec.test.mjs +2 -7
- 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/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +183 -26
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.test.mjs +378 -0
- 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/cache-break-trace.test.mjs +115 -0
- package/src/runtime/agent/orchestrator/config.mjs +13 -68
- package/src/runtime/agent/orchestrator/context/collect-skills.test.mjs +153 -0
- package/src/runtime/agent/orchestrator/context/collect.mjs +49 -45
- package/src/runtime/agent/orchestrator/mcp/client.mjs +242 -15
- package/src/runtime/agent/orchestrator/mcp/features.test.mjs +66 -0
- package/src/runtime/agent/orchestrator/mcp/security.test.mjs +36 -20
- package/src/runtime/agent/orchestrator/providers/admission-scheduler-metrics.test.mjs +47 -0
- package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +16 -3
- package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +54 -33
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +1 -0
- package/src/runtime/agent/orchestrator/providers/antigravity-oauth.mjs +7 -0
- package/src/runtime/agent/orchestrator/providers/gemini-schema.mjs +7 -0
- package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +3 -8
- package/src/runtime/agent/orchestrator/providers/gemini.mjs +7 -0
- package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +19 -3
- package/src/runtime/agent/orchestrator/providers/lib/provider-replay.mjs +50 -0
- package/src/runtime/agent/orchestrator/providers/lib/sse-framing.mjs +93 -0
- package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +30 -9
- package/src/runtime/agent/orchestrator/providers/media-parity.test.mjs +59 -0
- package/src/runtime/agent/orchestrator/providers/model-list-sanitize.mjs +3 -3
- package/src/runtime/agent/orchestrator/providers/openai-codex-identity.test.mjs +71 -0
- package/src/runtime/agent/orchestrator/providers/openai-codex-metadata.mjs +18 -26
- package/src/runtime/agent/orchestrator/providers/openai-compat-presets.mjs +8 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-stream.mjs +7 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-wire.mjs +25 -2
- package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +35 -4
- package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +47 -2
- package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +103 -12
- package/src/runtime/agent/orchestrator/providers/openai-responses-payload.mjs +13 -0
- package/src/runtime/agent/orchestrator/providers/openai-turn-state.mjs +68 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-delta-parity.test.mjs +122 -6
- package/src/runtime/agent/orchestrator/providers/openai-ws-delta.mjs +36 -11
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +144 -93
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +18 -13
- package/src/runtime/agent/orchestrator/providers/provider-replay.test.mjs +288 -0
- package/src/runtime/agent/orchestrator/providers/sse-framing.test.mjs +719 -0
- package/src/runtime/agent/orchestrator/providers/stream-json-pool.mjs +399 -39
- package/src/runtime/agent/orchestrator/providers/stream-json-worker.mjs +26 -0
- package/src/runtime/agent/orchestrator/session/agent-loop.mjs +86 -7
- package/src/runtime/agent/orchestrator/session/agent-loop.test.mjs +222 -0
- package/src/runtime/agent/orchestrator/session/browser-snapshot-supersession.mjs +61 -0
- package/src/runtime/agent/orchestrator/session/browser-snapshot-supersession.test.mjs +83 -0
- package/src/runtime/agent/orchestrator/session/cache/read-cache.mjs +13 -0
- package/src/runtime/agent/orchestrator/session/compact/runner.mjs +26 -2
- package/src/runtime/agent/orchestrator/session/compact-policy.test.mjs +112 -0
- package/src/runtime/agent/orchestrator/session/compaction-read-reset.test.mjs +192 -0
- package/src/runtime/agent/orchestrator/session/context-usage-restart.test.mjs +72 -0
- package/src/runtime/agent/orchestrator/session/context-utils.mjs +100 -15
- package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +17 -1
- package/src/runtime/agent/orchestrator/session/eager-dispatch.test.mjs +74 -0
- package/src/runtime/agent/orchestrator/session/image-strip-recovery.mjs +12 -8
- package/src/runtime/agent/orchestrator/session/image-strip-recovery.test.mjs +20 -1
- 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/pre-dispatch-deny.test.mjs +28 -0
- package/src/runtime/agent/orchestrator/session/loop/recall-fasttrack.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/loop/steering.mjs +6 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +15 -1
- package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +6 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +111 -39
- package/src/runtime/agent/orchestrator/session/manager/ask-session.test.mjs +46 -0
- package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +30 -6
- package/src/runtime/agent/orchestrator/session/manager/message-sanitize.mjs +3 -0
- package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +27 -3
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +26 -54
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.test.mjs +63 -1
- 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 +580 -0
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.test.mjs +593 -0
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +119 -190
- package/src/runtime/agent/orchestrator/session/manager/turn-interruption.mjs +115 -0
- package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +43 -8
- package/src/runtime/agent/orchestrator/session/provider-prefix-guard.mjs +129 -12
- package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +9 -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-live-publication.test.mjs +83 -0
- 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-reader.test.mjs +64 -0
- package/src/runtime/agent/orchestrator/session/store-summary-visibility.mjs +57 -0
- package/src/runtime/agent/orchestrator/session/store-summary-visibility.test.mjs +219 -0
- package/src/runtime/agent/orchestrator/session/store.mjs +26 -2
- package/src/runtime/agent/orchestrator/session/tool-batch.mjs +22 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool-cwd-env.test.mjs +14 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +19 -10
- package/src/runtime/agent/orchestrator/tools/builtin/find-search-budget.test.mjs +30 -14
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-policy.mjs +15 -4
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.mjs +73 -15
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.test.mjs +76 -2
- package/src/runtime/agent/orchestrator/tools/builtin/list-tool.mjs +24 -683
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-client.mjs +64 -72
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-runner.mjs +2 -5
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-transport.mjs +75 -0
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-transport.test.mjs +24 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-special-files.mjs +6 -6
- package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +12 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/constants.mjs +4 -1
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +24 -5
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.test.mjs +44 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary.mjs +12 -2
- package/src/runtime/agent/orchestrator/tools/code-graph/graph-model.mjs +35 -21
- package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.mjs +28 -13
- package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.test.mjs +54 -0
- package/src/runtime/agent/orchestrator/tools/graph-manifest.json +11 -11
- package/src/runtime/agent/orchestrator/tools/patch-manifest.json +11 -11
- package/src/runtime/agent/orchestrator/tools/progress-message.mjs +12 -0
- package/src/runtime/agent/orchestrator/tools/spawn-manifest.json +11 -11
- package/src/runtime/attachments/pdf-extract.mjs +3 -0
- package/src/runtime/attachments/pdfjs-runtime.mjs +13 -0
- package/src/runtime/bridge-clients.test.mjs +827 -0
- package/src/runtime/browser-bridge/action-schema.mjs +251 -0
- package/src/runtime/browser-bridge/client.mjs +152 -0
- package/src/runtime/browser-bridge/tool-defs.mjs +159 -0
- package/src/runtime/computer-bridge/action-schema.mjs +653 -0
- package/src/runtime/computer-bridge/client.mjs +231 -0
- package/src/runtime/computer-bridge/tool-defs.mjs +33 -0
- package/src/runtime/media/store.mjs +18 -8
- package/src/runtime/media/store.test.mjs +14 -0
- package/src/runtime/memory/index.mjs +1 -1
- package/src/runtime/memory/lib/transcript-ingest.mjs +8 -6
- package/src/runtime/memory/lib/transcript-ingest.test.mjs +52 -0
- 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-assurance.test.mjs +371 -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/office-live-runtime.test.mjs +819 -0
- package/src/runtime/office/office-runtime.test.mjs +2070 -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/child-spawn-gate.mjs +17 -0
- package/src/runtime/shared/child-spawn-remote.mjs +69 -7
- package/src/runtime/shared/child-spawn-remote.test.mjs +124 -0
- package/src/runtime/shared/pristine-execution-contract.json +2 -1
- package/src/runtime/shared/provider-api-key.mjs +1 -0
- package/src/runtime/shared/session-runtime-health.mjs +91 -0
- package/src/runtime/shared/session-runtime-health.test.mjs +53 -0
- package/src/runtime/shared/skill-document.mjs +86 -0
- package/src/runtime/shared/skill-document.test.mjs +81 -0
- package/src/runtime/shared/tool-execution-contract.mjs +16 -0
- package/src/runtime/shared/tool-surface.mjs +27 -0
- package/src/runtime/shared/turn-snapshot-store.mjs +1 -0
- package/src/runtime/shared/turn-snapshot.mjs +32 -9
- package/src/runtime/shared/user-cwd.mjs +33 -14
- package/src/runtime/shared/user-cwd.test.mjs +43 -0
- package/src/session-runtime/agent-disable.test.mjs +20 -1
- package/src/session-runtime/context-status.mjs +9 -3
- package/src/session-runtime/cwd-plugins.mjs +26 -26
- package/src/session-runtime/cwd-plugins.test.mjs +75 -0
- package/src/session-runtime/cwd-tool-routing.test.mjs +5 -0
- package/src/session-runtime/deferred-tool-delta.mjs +104 -0
- package/src/session-runtime/deferred-tool-delta.test.mjs +40 -0
- package/src/session-runtime/global-extensions.mjs +26 -0
- package/src/session-runtime/global-extensions.test.mjs +28 -0
- package/src/session-runtime/global-settings-session-identity.test.mjs +76 -0
- package/src/session-runtime/goal-runtime.mjs +1141 -0
- package/src/session-runtime/goal-runtime.test.mjs +645 -0
- package/src/session-runtime/lifecycle-api.mjs +58 -11
- package/src/session-runtime/lifecycle-api.test.mjs +183 -0
- package/src/session-runtime/mcp-glue.mjs +49 -47
- package/src/session-runtime/plugin-mcp-standard.test.mjs +177 -0
- package/src/session-runtime/plugin-mcp.mjs +96 -22
- package/src/session-runtime/prewarm.mjs +1 -10
- package/src/session-runtime/provider-request-snapshot.mjs +33 -9
- package/src/session-runtime/provider-request-snapshot.test.mjs +27 -5
- package/src/session-runtime/resource-api-global.test.mjs +109 -0
- package/src/session-runtime/resource-api.mjs +168 -116
- package/src/session-runtime/runtime-core.mjs +208 -29
- package/src/session-runtime/runtime-tunables.mjs +6 -8
- 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 +37 -25
- package/src/session-runtime/skills-api.mjs +79 -25
- package/src/session-runtime/skills-api.test.mjs +99 -0
- package/src/session-runtime/tool-catalog-data.mjs +1 -1
- package/src/session-runtime/tool-catalog-schema.mjs +0 -5
- package/src/session-runtime/tool-catalog.mjs +42 -112
- package/src/session-runtime/tool-defs.mjs +6 -1
- package/src/session-runtime/tool-policy-surface.test.mjs +93 -17
- package/src/session-runtime/tool-surface.mjs +30 -8
- package/src/session-runtime/workflow-agents-api.mjs +8 -25
- package/src/session-runtime/workflow.mjs +8 -6
- package/src/standalone/agent-dispatch-broker.mjs +5 -9
- 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 +11 -9
- package/src/standalone/agent-tool/notify.test.mjs +37 -0
- package/src/standalone/agent-tool/render.mjs +3 -0
- package/src/standalone/agent-tool/spawn-flow.mjs +61 -16
- package/src/standalone/agent-tool/spawn-flow.test.mjs +41 -0
- 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-index.test.mjs +132 -0
- package/src/standalone/agent-tool/worker-rows.mjs +2 -1
- package/src/standalone/agent-tool.mjs +57 -10
- package/src/standalone/daemon.mjs +113 -15
- package/src/standalone/hook-bus/config.mjs +1 -0
- package/src/standalone/plugin-admin.mjs +17 -0
- package/src/standalone/plugin-admin.test.mjs +7 -0
- package/src/standalone/provider-admin.mjs +1 -0
- package/src/standalone/session-protocol.mjs +5 -0
- package/src/standalone/session-runtime-agent-control-client.mjs +133 -0
- package/src/standalone/session-runtime-agent-control-client.test.mjs +71 -0
- package/src/standalone/session-runtime-dispatch-cancel.test.mjs +139 -0
- package/src/standalone/session-runtime-host-factory.mjs +17 -0
- package/src/standalone/session-runtime-host-factory.test.mjs +31 -0
- package/src/standalone/session-runtime-host-health.test.mjs +5 -0
- package/src/standalone/session-runtime-host.mjs +709 -58
- package/src/standalone/session-runtime-inline-host.mjs +258 -0
- package/src/standalone/session-runtime-inline-host.test.mjs +385 -0
- package/src/standalone/session-runtime-provider-cooldown.mjs +78 -0
- package/src/standalone/session-runtime-provider-cooldown.test.mjs +80 -0
- package/src/standalone/session-runtime-shard-host.test.mjs +642 -0
- package/src/standalone/session-runtime-shard-router.mjs +149 -0
- package/src/standalone/session-runtime-shard-router.test.mjs +101 -0
- package/src/standalone/session-runtime-worker.mjs +302 -26
- package/src/standalone/session-service-agent-tree.test.mjs +984 -0
- package/src/standalone/session-service-goal-recovery.test.mjs +177 -0
- package/src/standalone/session-service.mjs +711 -11
- package/src/tui/app/app-view.jsx +1 -0
- package/src/tui/app/core-memory-picker.mjs +2 -0
- package/src/tui/app/extension-pickers.mjs +1 -1
- package/src/tui/app/maintenance-pickers.mjs +3 -3
- package/src/tui/app/model-options.mjs +2 -0
- package/src/tui/app/model-picker.mjs +14 -4
- package/src/tui/app/panel-handoff.test.mjs +311 -0
- package/src/tui/app/project-picker.mjs +1 -0
- package/src/tui/app/route-pickers.mjs +21 -6
- package/src/tui/app/settings-picker.mjs +26 -3
- package/src/tui/app/slash-commands.mjs +1 -0
- package/src/tui/app/slash-dispatch.mjs +73 -22
- package/src/tui/app/theme-effort-pickers.mjs +7 -2
- package/src/tui/components/Picker.jsx +10 -1
- package/src/tui/dist/index.mjs +187 -45
- package/src/tui/lib/voice-setup.mjs +4 -1
- package/src/tui/session/agent-message-source.test.mjs +37 -0
- package/src/tui/session/completion-card-restore.test.mjs +50 -0
- package/src/tui/session/context-state.mjs +3 -13
- package/src/tui/session/goal-continuation.mjs +141 -0
- package/src/tui/session/goal-continuation.test.mjs +203 -0
- package/src/tui/session/queue-helpers.mjs +5 -2
- package/src/tui/session/session-action-surface.test.mjs +190 -0
- package/src/tui/session/session-api-ext.mjs +48 -8
- package/src/tui/session/session-api.mjs +73 -1
- package/src/tui/session/session-flow.mjs +31 -1
- package/src/tui/session/turn.mjs +88 -15
- package/src/tui/session-local.mjs +39 -3
- package/src/vendor/statusline/src/gateway/route-meta.mjs +31 -0
- package/src/runtime/agent/orchestrator/tools/builtin/fuzzy-match.mjs +0 -301
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
+
import {
|
|
4
|
+
access,
|
|
5
|
+
chmod,
|
|
6
|
+
mkdir,
|
|
7
|
+
readFile,
|
|
8
|
+
rename,
|
|
9
|
+
rm,
|
|
10
|
+
stat,
|
|
11
|
+
writeFile,
|
|
12
|
+
} from 'node:fs/promises';
|
|
13
|
+
import { gunzipSync } from 'node:zlib';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
|
|
16
|
+
const VERSION = '0.3.0';
|
|
17
|
+
const MAX_ARCHIVE_BYTES = 160 * 1024 * 1024;
|
|
18
|
+
const MAX_OUTPUT_BYTES = 5 * 1024 * 1024;
|
|
19
|
+
const PLATFORM_PACKAGES = Object.freeze({
|
|
20
|
+
'win32-x64': {
|
|
21
|
+
name: '@xarsh/ooxml-validator-win32-x64',
|
|
22
|
+
integrity: 'sha512-VflQjYjMfq6Up3sclSiVL5p2dVz17RrubZF+QqXhoWCiOPlMlaMN07hx99J6Ngh6TPboAK6TjcuG8DlGIhcp0w==',
|
|
23
|
+
binary: 'ooxml-validator.exe',
|
|
24
|
+
},
|
|
25
|
+
'win32-arm64': {
|
|
26
|
+
name: '@xarsh/ooxml-validator-win32-arm64',
|
|
27
|
+
integrity: 'sha512-mx7RqjopCZ3mNVlNyPar935FbMA61hOCyIA854L/3trLt4vmj62/spSfjkpgyKx6TKq5/HXTjMf+rNM/WKayaw==',
|
|
28
|
+
binary: 'ooxml-validator.exe',
|
|
29
|
+
},
|
|
30
|
+
'linux-x64': {
|
|
31
|
+
name: '@xarsh/ooxml-validator-linux-x64',
|
|
32
|
+
integrity: 'sha512-GltV9YzcOwLdxhTvw9MIw1kgMbsjnpUvYYaKovDUwMcvwIOlb72Lealp4mZRugLDS1XRDqHbjoChL6Ko+awLpw==',
|
|
33
|
+
binary: 'ooxml-validator',
|
|
34
|
+
},
|
|
35
|
+
'linux-arm64': {
|
|
36
|
+
name: '@xarsh/ooxml-validator-linux-arm64',
|
|
37
|
+
integrity: 'sha512-5D8M0PF8J3eIrnUYNiHfOKyjiwnTkWRfcmUMrwMsqzSTBX0LmTRa1QjbIpAwTjKalkGq8nzutSO6eu/UmNothg==',
|
|
38
|
+
binary: 'ooxml-validator',
|
|
39
|
+
},
|
|
40
|
+
'darwin-x64': {
|
|
41
|
+
name: '@xarsh/ooxml-validator-darwin-x64',
|
|
42
|
+
integrity: 'sha512-Mj0IEDx4lnDbz+cWqhbyQ3zrJTrtcOUhgU13qXgM4m1yS+SNhsojwfIw6NfPjeI6QTvh5rq9oocgewBe7W9LYw==',
|
|
43
|
+
binary: 'ooxml-validator',
|
|
44
|
+
},
|
|
45
|
+
'darwin-arm64': {
|
|
46
|
+
name: '@xarsh/ooxml-validator-darwin-arm64',
|
|
47
|
+
integrity: 'sha512-hgxBf6YzMJCvgEKJN3wVmd4KhIkAx0eCl3ODMoi8a9m8o6N7xE0UKHJFjAku0WhAdbVrZN4w3K5oUVLCC6GnTA==',
|
|
48
|
+
binary: 'ooxml-validator',
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function packageUrl(name) {
|
|
53
|
+
const slug = name.slice(name.indexOf('/') + 1);
|
|
54
|
+
return `https://registry.npmjs.org/${name}/-/${slug}-${VERSION}.tgz`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function archiveEntry(buffer, wanted) {
|
|
58
|
+
for (let offset = 0; offset + 512 <= buffer.length;) {
|
|
59
|
+
const header = buffer.subarray(offset, offset + 512);
|
|
60
|
+
if (header.every((byte) => byte === 0)) break;
|
|
61
|
+
const text = (start, length) => header.subarray(start, start + length)
|
|
62
|
+
.toString('utf8').replace(/\0.*$/s, '').trim();
|
|
63
|
+
const prefix = text(345, 155);
|
|
64
|
+
const name = [prefix, text(0, 100)].filter(Boolean).join('/');
|
|
65
|
+
const size = Number.parseInt(text(124, 12) || '0', 8);
|
|
66
|
+
if (!Number.isFinite(size) || size < 0) throw new Error('OOXML validator archive has an invalid TAR entry size');
|
|
67
|
+
const body = offset + 512;
|
|
68
|
+
if (name === wanted) return buffer.subarray(body, body + size);
|
|
69
|
+
offset = body + Math.ceil(size / 512) * 512;
|
|
70
|
+
}
|
|
71
|
+
throw new Error(`OOXML validator archive is missing ${wanted}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function fetchArchive(url, { signal = null } = {}) {
|
|
75
|
+
const response = await fetch(url, { signal });
|
|
76
|
+
if (!response.ok) throw new Error(`OOXML validator download failed with HTTP ${response.status}`);
|
|
77
|
+
const declared = Number(response.headers.get('content-length') || 0);
|
|
78
|
+
if (declared > MAX_ARCHIVE_BYTES) throw new Error('OOXML validator archive exceeds the download size limit');
|
|
79
|
+
const chunks = [];
|
|
80
|
+
let bytes = 0;
|
|
81
|
+
for await (const chunk of response.body) {
|
|
82
|
+
bytes += chunk.length;
|
|
83
|
+
if (bytes > MAX_ARCHIVE_BYTES) throw new Error('OOXML validator archive exceeds the download size limit');
|
|
84
|
+
chunks.push(Buffer.from(chunk));
|
|
85
|
+
}
|
|
86
|
+
return Buffer.concat(chunks);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function verifyIntegrity(buffer, integrity) {
|
|
90
|
+
const [algorithm, expected] = String(integrity).split('-', 2);
|
|
91
|
+
const actual = createHash(algorithm).update(buffer).digest('base64');
|
|
92
|
+
if (actual !== expected) throw new Error('OOXML validator archive integrity check failed');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function isOfficeExtensionCompatibilityError(error) {
|
|
96
|
+
const path = String(error?.path || '');
|
|
97
|
+
const xPath = String(error?.xPath || '');
|
|
98
|
+
const description = String(error?.description || '');
|
|
99
|
+
if (!/^\/(?:ppt|xl)\/charts\//i.test(path)) return false;
|
|
100
|
+
return /\/c:extLst\[\d+](?:\/c:ext\[\d+])?/i.test(xPath)
|
|
101
|
+
|| /schemas\.microsoft\.com\/office\/drawing\/20\d{2}\//i.test(description);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function classifyOoxmlValidationErrors(errors = []) {
|
|
105
|
+
const reported = Array.isArray(errors) ? errors : [];
|
|
106
|
+
return {
|
|
107
|
+
errors: reported.filter((error) => !isOfficeExtensionCompatibilityError(error)),
|
|
108
|
+
compatibilityWarnings: reported.filter(isOfficeExtensionCompatibilityError),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function cachePaths(dataDir, entry) {
|
|
113
|
+
const root = join(dataDir, 'office', 'tools', 'ooxml-validator', VERSION, `${process.platform}-${process.arch}`);
|
|
114
|
+
return {
|
|
115
|
+
root,
|
|
116
|
+
binary: join(root, entry.binary),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function usableBinary(path) {
|
|
121
|
+
try {
|
|
122
|
+
const details = await stat(path);
|
|
123
|
+
return details.isFile() && details.size > 1024 * 1024;
|
|
124
|
+
} catch {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function ensureOoxmlValidator({
|
|
130
|
+
dataDir,
|
|
131
|
+
download = true,
|
|
132
|
+
signal = null,
|
|
133
|
+
} = {}) {
|
|
134
|
+
const override = String(process.env.MIXDOG_OOXML_VALIDATOR_CLI || '').trim();
|
|
135
|
+
if (override) {
|
|
136
|
+
await access(override);
|
|
137
|
+
return { available: true, cached: true, downloaded: false, path: override, version: 'override' };
|
|
138
|
+
}
|
|
139
|
+
if (process.env.MIXDOG_OOXML_VALIDATOR_DISABLED === '1') {
|
|
140
|
+
return { available: false, disabled: true, downloaded: false, reason: 'OOXML schema validation is disabled.' };
|
|
141
|
+
}
|
|
142
|
+
const entry = PLATFORM_PACKAGES[`${process.platform}-${process.arch}`];
|
|
143
|
+
if (!entry) {
|
|
144
|
+
return {
|
|
145
|
+
available: false,
|
|
146
|
+
downloaded: false,
|
|
147
|
+
reason: `OOXML schema validation is unavailable on ${process.platform}-${process.arch}.`,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const paths = cachePaths(dataDir, entry);
|
|
151
|
+
if (await usableBinary(paths.binary)) {
|
|
152
|
+
return { available: true, cached: true, downloaded: false, path: paths.binary, version: VERSION };
|
|
153
|
+
}
|
|
154
|
+
if (!download) {
|
|
155
|
+
return {
|
|
156
|
+
available: false,
|
|
157
|
+
cached: false,
|
|
158
|
+
downloaded: false,
|
|
159
|
+
downloadRequired: true,
|
|
160
|
+
reason: 'OOXML schema validator is not cached.',
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
await mkdir(paths.root, { recursive: true });
|
|
164
|
+
const temporary = join(paths.root, `.${entry.binary}.${randomUUID()}.tmp`);
|
|
165
|
+
try {
|
|
166
|
+
const archive = await fetchArchive(packageUrl(entry.name), { signal });
|
|
167
|
+
verifyIntegrity(archive, entry.integrity);
|
|
168
|
+
const tar = gunzipSync(archive);
|
|
169
|
+
const binary = archiveEntry(tar, `package/${entry.binary}`);
|
|
170
|
+
await writeFile(temporary, binary, { mode: 0o755 });
|
|
171
|
+
await chmod(temporary, 0o755);
|
|
172
|
+
await rm(paths.binary, { force: true });
|
|
173
|
+
await rename(temporary, paths.binary);
|
|
174
|
+
return {
|
|
175
|
+
available: true,
|
|
176
|
+
cached: false,
|
|
177
|
+
downloaded: true,
|
|
178
|
+
path: paths.binary,
|
|
179
|
+
version: VERSION,
|
|
180
|
+
bytes: binary.length,
|
|
181
|
+
};
|
|
182
|
+
} finally {
|
|
183
|
+
await rm(temporary, { force: true }).catch(() => {});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export async function validateOoxmlSchema(path, {
|
|
188
|
+
dataDir,
|
|
189
|
+
download = true,
|
|
190
|
+
officeVersion = 'Microsoft365',
|
|
191
|
+
signal = null,
|
|
192
|
+
} = {}) {
|
|
193
|
+
const runtime = await ensureOoxmlValidator({ dataDir, download, signal });
|
|
194
|
+
if (!runtime.available) return { ...runtime, ok: false, errors: [] };
|
|
195
|
+
return await new Promise((resolve) => {
|
|
196
|
+
const child = spawn(runtime.path, [path, officeVersion], {
|
|
197
|
+
windowsHide: true,
|
|
198
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
199
|
+
});
|
|
200
|
+
let stdout = '';
|
|
201
|
+
let stderr = '';
|
|
202
|
+
let settled = false;
|
|
203
|
+
const finish = (value) => {
|
|
204
|
+
if (settled) return;
|
|
205
|
+
settled = true;
|
|
206
|
+
clearTimeout(timeout);
|
|
207
|
+
signal?.removeEventListener?.('abort', abort);
|
|
208
|
+
resolve(value);
|
|
209
|
+
};
|
|
210
|
+
const append = (current, chunk) => {
|
|
211
|
+
const next = `${current}${chunk}`;
|
|
212
|
+
return next.length > MAX_OUTPUT_BYTES ? next.slice(0, MAX_OUTPUT_BYTES) : next;
|
|
213
|
+
};
|
|
214
|
+
const abort = () => {
|
|
215
|
+
try { child.kill(); } catch {}
|
|
216
|
+
finish({ ...runtime, ok: false, errors: [], reason: 'OOXML schema validation was cancelled.' });
|
|
217
|
+
};
|
|
218
|
+
child.stdout.setEncoding('utf8');
|
|
219
|
+
child.stderr.setEncoding('utf8');
|
|
220
|
+
child.stdout.on('data', (chunk) => { stdout = append(stdout, chunk); });
|
|
221
|
+
child.stderr.on('data', (chunk) => { stderr = append(stderr, chunk); });
|
|
222
|
+
child.once('error', (error) => finish({
|
|
223
|
+
...runtime,
|
|
224
|
+
ok: false,
|
|
225
|
+
errors: [],
|
|
226
|
+
reason: `Failed to start OOXML schema validator: ${error.message}`,
|
|
227
|
+
}));
|
|
228
|
+
child.once('close', (code) => {
|
|
229
|
+
if (settled) return;
|
|
230
|
+
if (code !== 0) {
|
|
231
|
+
finish({ ...runtime, ok: false, errors: [], reason: stderr.trim() || `OOXML schema validator exited with code ${code}.` });
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
const result = JSON.parse(stdout.trim() || '{}');
|
|
236
|
+
const valid = result.isValid ?? result.valid ?? result.ok;
|
|
237
|
+
const reportedErrors = Array.isArray(result.errors) ? result.errors : [];
|
|
238
|
+
const classified = classifyOoxmlValidationErrors(reportedErrors);
|
|
239
|
+
finish({
|
|
240
|
+
...runtime,
|
|
241
|
+
ok: valid === true || (reportedErrors.length > 0 && classified.errors.length === 0),
|
|
242
|
+
errors: classified.errors.slice(0, 500),
|
|
243
|
+
compatibilityWarnings: classified.compatibilityWarnings.slice(0, 500),
|
|
244
|
+
omittedErrors: Math.max(0, classified.errors.length - 500),
|
|
245
|
+
rawValid: valid === true,
|
|
246
|
+
officeVersion,
|
|
247
|
+
validation: 'open-xml-sdk',
|
|
248
|
+
});
|
|
249
|
+
} catch (error) {
|
|
250
|
+
finish({ ...runtime, ok: false, errors: [], reason: `Invalid OOXML schema validator output: ${error.message}` });
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
const timeout = setTimeout(() => {
|
|
254
|
+
try { child.kill(); } catch {}
|
|
255
|
+
finish({ ...runtime, ok: false, errors: [], reason: 'OOXML schema validation timed out after 120 seconds.' });
|
|
256
|
+
}, 120_000);
|
|
257
|
+
if (signal?.aborted) abort();
|
|
258
|
+
else signal?.addEventListener?.('abort', abort, { once: true });
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function ooxmlValidatorManifest() {
|
|
263
|
+
return {
|
|
264
|
+
version: VERSION,
|
|
265
|
+
platforms: Object.keys(PLATFORM_PACKAGES),
|
|
266
|
+
packages: Object.fromEntries(Object.entries(PLATFORM_PACKAGES).map(([key, value]) => [key, {
|
|
267
|
+
name: value.name,
|
|
268
|
+
integrity: value.integrity,
|
|
269
|
+
}])),
|
|
270
|
+
};
|
|
271
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const DEFAULT_LIMITS = Object.freeze({
|
|
2
|
+
docx: 200,
|
|
3
|
+
xlsx: 2_000,
|
|
4
|
+
pptx: 20,
|
|
5
|
+
csv: 2_000,
|
|
6
|
+
tsv: 2_000,
|
|
7
|
+
pdf: 20,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const MAX_LIMITS = Object.freeze({
|
|
11
|
+
docx: 2_000,
|
|
12
|
+
xlsx: 10_000,
|
|
13
|
+
pptx: 100,
|
|
14
|
+
csv: 10_000,
|
|
15
|
+
tsv: 10_000,
|
|
16
|
+
pdf: 100,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
function normalizedPages(value) {
|
|
20
|
+
if (!Array.isArray(value)) return [];
|
|
21
|
+
return [...new Set(value.map(Number).filter((page) => Number.isInteger(page) && page > 0))];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function encodeCursor(value) {
|
|
25
|
+
return Buffer.from(JSON.stringify(value), 'utf8').toString('base64url');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function decodeCursor(value) {
|
|
29
|
+
try {
|
|
30
|
+
const decoded = JSON.parse(Buffer.from(String(value || ''), 'base64url').toString('utf8'));
|
|
31
|
+
if (!decoded || decoded.version !== 1) throw new Error('unsupported cursor version');
|
|
32
|
+
return decoded;
|
|
33
|
+
} catch {
|
|
34
|
+
throw new Error('Invalid Office snapshot cursor');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function selectorFromArgs(args = {}) {
|
|
39
|
+
return {
|
|
40
|
+
sheet: String(args.sheet || ''),
|
|
41
|
+
range: String(args.range || ''),
|
|
42
|
+
target: String(args.target || ''),
|
|
43
|
+
pages: normalizedPages(args.pages),
|
|
44
|
+
includeStyles: args.includeStyles === true,
|
|
45
|
+
includeSelection: args.includeSelection === true,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function sameSelector(left, right) {
|
|
50
|
+
return left.sheet === right.sheet
|
|
51
|
+
&& left.range === right.range
|
|
52
|
+
&& left.target === right.target
|
|
53
|
+
&& left.includeStyles === right.includeStyles
|
|
54
|
+
&& left.includeSelection === right.includeSelection
|
|
55
|
+
&& JSON.stringify(left.pages) === JSON.stringify(right.pages);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function createOfficeSnapshotRequest(session, args = {}, { full = false } = {}) {
|
|
59
|
+
if (full) return { full: true };
|
|
60
|
+
const format = String(session?.format || '');
|
|
61
|
+
const defaultLimit = DEFAULT_LIMITS[format] || 200;
|
|
62
|
+
const formatMaximum = MAX_LIMITS[format] || 2_000;
|
|
63
|
+
let selector = selectorFromArgs(args);
|
|
64
|
+
let offset = 0;
|
|
65
|
+
let limit = Math.max(1, Number(args.limit) || defaultLimit);
|
|
66
|
+
if (args.cursor) {
|
|
67
|
+
const cursor = decodeCursor(args.cursor);
|
|
68
|
+
if (cursor.session !== session.id || cursor.format !== format) {
|
|
69
|
+
throw new Error('Office snapshot cursor belongs to a different document session');
|
|
70
|
+
}
|
|
71
|
+
if (Number(cursor.revision) !== Number(session.snapshotVersion || 0)) {
|
|
72
|
+
throw new Error('Office snapshot cursor is stale because the document changed');
|
|
73
|
+
}
|
|
74
|
+
const suppliedSelector = selectorFromArgs(args);
|
|
75
|
+
const cursorSelector = cursor.selector || selectorFromArgs();
|
|
76
|
+
const hasSuppliedSelector = suppliedSelector.sheet
|
|
77
|
+
|| suppliedSelector.range
|
|
78
|
+
|| suppliedSelector.target
|
|
79
|
+
|| suppliedSelector.pages.length
|
|
80
|
+
|| suppliedSelector.includeStyles
|
|
81
|
+
|| suppliedSelector.includeSelection;
|
|
82
|
+
if (hasSuppliedSelector && !sameSelector(suppliedSelector, cursorSelector)) {
|
|
83
|
+
throw new Error('Office snapshot cursor selector does not match this request');
|
|
84
|
+
}
|
|
85
|
+
selector = cursorSelector;
|
|
86
|
+
offset = Number(cursor.offset) || 0;
|
|
87
|
+
limit = Math.max(1, Number(args.limit) || Number(cursor.limit) || defaultLimit);
|
|
88
|
+
}
|
|
89
|
+
const maximum = format === 'xlsx' && selector.includeStyles ? 500 : formatMaximum;
|
|
90
|
+
limit = Math.min(maximum, limit);
|
|
91
|
+
return {
|
|
92
|
+
paged: true,
|
|
93
|
+
offset,
|
|
94
|
+
limit,
|
|
95
|
+
...selector,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function finalizeOfficeSnapshotPage(document, session, request) {
|
|
100
|
+
const pagination = document?.pagination;
|
|
101
|
+
if (!pagination || request.full) return document;
|
|
102
|
+
const nextOffset = Number(pagination.nextOffset);
|
|
103
|
+
const hasMore = pagination.nextOffset !== null
|
|
104
|
+
&& pagination.nextOffset !== undefined
|
|
105
|
+
&& Number.isInteger(nextOffset)
|
|
106
|
+
&& nextOffset >= 0;
|
|
107
|
+
pagination.cursor = request.offset > 0
|
|
108
|
+
? encodeCursor({
|
|
109
|
+
version: 1,
|
|
110
|
+
session: session.id,
|
|
111
|
+
format: session.format,
|
|
112
|
+
revision: Number(session.snapshotVersion || 0),
|
|
113
|
+
offset: request.offset,
|
|
114
|
+
limit: request.limit,
|
|
115
|
+
selector: selectorFromArgs(request),
|
|
116
|
+
})
|
|
117
|
+
: null;
|
|
118
|
+
pagination.nextCursor = hasMore
|
|
119
|
+
? encodeCursor({
|
|
120
|
+
version: 1,
|
|
121
|
+
session: session.id,
|
|
122
|
+
format: session.format,
|
|
123
|
+
revision: Number(session.snapshotVersion || 0),
|
|
124
|
+
offset: nextOffset,
|
|
125
|
+
limit: request.limit,
|
|
126
|
+
selector: selectorFromArgs(request),
|
|
127
|
+
})
|
|
128
|
+
: null;
|
|
129
|
+
pagination.hasMore = hasMore;
|
|
130
|
+
delete pagination.nextOffset;
|
|
131
|
+
return document;
|
|
132
|
+
}
|