mixdog 0.9.170 → 0.9.172
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/package.json +2 -1
- package/scripts/build-ffmpeg-runtime.sh +57 -58
- package/scripts/build-runtime-linux.sh +211 -191
- package/scripts/build-runtime-macos.sh +94 -76
- package/scripts/daemon-stub.mjs +1 -2
- package/scripts/fixtures/patch-replay-corpus.json +85 -28
- package/scripts/generate-runtime-manifest.mjs +1 -1
- package/scripts/graph-parity.mjs +204 -151
- package/scripts/lib/embedding-model-bench-core.mjs +5 -9
- package/scripts/lib/embedding-model-bench-core.test.mjs +47 -0
- package/scripts/lib/parse-since.mjs +22 -0
- package/scripts/lib/recall-bench-eval.mjs +4 -12
- package/scripts/lib/run-node-tests.mjs +28 -0
- package/scripts/lib/test-summary-reporter.mjs +26 -0
- package/scripts/llm-trace-summary.mjs +2 -23
- package/scripts/local-provider-live-check.mjs +1 -1
- package/scripts/media-image-live.mjs +4 -6
- package/scripts/mouse-probe.mjs +1 -11
- package/scripts/native-binary-arch.mjs +1 -1
- package/scripts/office/author-deck.mjs +4 -1
- package/scripts/patch-replay.mjs +4 -1
- package/scripts/perf/transcript-baseline.mjs +10 -8
- package/scripts/pg-memory-diet.mjs +8 -5
- package/scripts/prune-embedding-runtime.mjs +1 -20
- package/scripts/recall-bench-cases.json +64 -9
- package/scripts/recall-event-cases.json +398 -41
- package/scripts/recall-history-cases.json +396 -36
- package/scripts/recall-quality-cases.json +146 -17
- package/scripts/recall-repo-cases.json +188 -24
- package/scripts/recall-usecase-cases.json +96 -16
- package/scripts/release-timing-report.mjs +4 -1
- package/scripts/routing-corpus.mjs +113 -141
- package/scripts/run-office-live-tests.mjs +2 -1
- package/scripts/session-diag.mjs +2 -21
- package/scripts/session-sweep.mjs +4 -4
- package/scripts/smoke-runtime-negative.sh +22 -16
- package/scripts/test-direct.mjs +5 -0
- package/scripts/test.mjs +11 -24
- package/scripts/tool-efficiency-diag.mjs +4 -1
- package/scripts/tool-failures.mjs +1 -20
- package/scripts/tui-frame-harness.mjs +6 -7
- package/src/defaults/skills/browser-use/SKILL.md +33 -9
- package/src/defaults/skills/code-tidy/SKILL.md +158 -73
- package/src/defaults/skills/code-tidy/references/agent-cleanup.md +126 -52
- package/src/defaults/skills/code-tidy/references/dead-code.md +61 -19
- package/src/defaults/skills/computer-use/SKILL.md +19 -6
- package/src/defaults/skills/docx/SKILL.md +2 -0
- package/src/defaults/skills/docx/references/native-authoring.md +7 -2
- package/src/defaults/skills/goal-management/SKILL.md +10 -3
- package/src/defaults/skills/local-provider/SKILL.md +1 -1
- package/src/defaults/skills/memory-management/SKILL.md +1 -1
- package/src/defaults/skills/pdf/SKILL.md +1 -1
- package/src/defaults/skills/pptx/SKILL.md +18 -13
- package/src/defaults/skills/pptx/references/charts.md +10 -5
- package/src/defaults/skills/pptx/references/direction.md +1 -1
- package/src/defaults/skills/pptx/references/kit.md +153 -44
- package/src/defaults/skills/pptx/references/pictures.md +10 -1
- package/src/defaults/skills/pptx/scripts/qc-pages.mjs +161 -116
- package/src/defaults/skills/setup/SKILL.md +1 -1
- package/src/defaults/skills/skill-creator/SKILL.md +3 -3
- package/src/defaults/skills/skill-creator/references/design.md +3 -3
- package/src/defaults/skills/xlsx/SKILL.md +8 -5
- package/src/headless-exec.mjs +328 -696
- package/src/headless-json-lifecycle.mjs +461 -0
- package/src/headless-role.mjs +1 -1
- package/src/lib/keychain-cjs.cjs +7 -8
- package/src/lib/mixdog-debug.cjs +4 -5
- package/src/lib/plugin-paths.cjs +2 -2
- package/src/lib/rules-builder.cjs +22 -38
- package/src/lib/text-utils.cjs +1 -3
- package/src/repl/runtime-handle.mjs +46 -0
- package/src/repl/slash-commands.mjs +134 -0
- package/src/repl/stream-sink.mjs +129 -0
- package/src/repl/turn-output.mjs +51 -0
- package/src/repl.mjs +99 -381
- package/src/rules/agent/40-cycle1-agent.md +4 -3
- package/src/rules/agent/AGENT.md +11 -11
- package/src/rules/lead/LEAD.md +14 -12
- package/src/rules/shared/05-parallel-calls.md +3 -5
- package/src/rules/shared/15-skills.md +4 -0
- package/src/rules/shared/45-destructive.md +4 -4
- package/src/rules/shared/70-delivery.md +10 -3
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/abort-link.mjs +44 -0
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/ask-args.mjs +128 -0
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/preset.mjs +72 -0
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/session-prep.mjs +114 -0
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/turn.mjs +111 -0
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/watchdog.mjs +80 -0
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +112 -606
- package/src/runtime/agent/orchestrator/agent-runtime/agent-progress-watchdog.mjs +1 -2
- package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +61 -49
- package/src/runtime/agent/orchestrator/agent-trace-format.mjs +18 -22
- package/src/runtime/agent/orchestrator/agent-trace-io.mjs +3 -3
- package/src/runtime/agent/orchestrator/agent-trace.mjs +6 -19
- package/src/runtime/agent/orchestrator/cache-break-trace.mjs +3 -2
- package/src/runtime/agent/orchestrator/cache-mtime.mjs +2 -2
- package/src/runtime/agent/orchestrator/config-presets.mjs +1 -1
- package/src/runtime/agent/orchestrator/config-storage.mjs +9 -11
- package/src/runtime/agent/orchestrator/config.mjs +6 -4
- package/src/runtime/agent/orchestrator/context/deferred-tools.mjs +5 -14
- package/src/runtime/agent/orchestrator/context/role-instructions.mjs +8 -16
- package/src/runtime/agent/orchestrator/context/skill-catalog.mjs +11 -17
- package/src/runtime/agent/orchestrator/context/skill-state.mjs +0 -16
- package/src/runtime/agent/orchestrator/dispatch-persist.mjs +2 -2
- package/src/runtime/agent/orchestrator/internal-agents.mjs +4 -7
- package/src/runtime/agent/orchestrator/mcp/child-tree.mjs +1 -2
- package/src/runtime/agent/orchestrator/mcp/client-config.mjs +238 -0
- package/src/runtime/agent/orchestrator/mcp/client-handshake.mjs +70 -0
- package/src/runtime/agent/orchestrator/mcp/client-transport.mjs +110 -0
- package/src/runtime/agent/orchestrator/mcp/client.mjs +89 -438
- package/src/runtime/agent/orchestrator/providers/account-pool.mjs +167 -71
- package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +16 -78
- package/src/runtime/agent/orchestrator/providers/anthropic-betas.mjs +0 -10
- package/src/runtime/agent/orchestrator/providers/anthropic-effort.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/anthropic-fast-mode.mjs +3 -11
- package/src/runtime/agent/orchestrator/providers/anthropic-leaked-toolcall.mjs +8 -4
- package/src/runtime/agent/orchestrator/providers/anthropic-max-tokens.mjs +2 -3
- package/src/runtime/agent/orchestrator/providers/anthropic-messages.mjs +23 -12
- package/src/runtime/agent/orchestrator/providers/anthropic-model-resolve.mjs +11 -4
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-client-version.mjs +2 -3
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-credentials.mjs +6 -6
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-midstream.mjs +223 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-recovery.mjs +183 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request/abort-wiring.mjs +67 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request/gzip-post.mjs +52 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request/initial-status.mjs +75 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request.mjs +136 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +205 -798
- package/src/runtime/agent/orchestrator/providers/anthropic-server-fallback.mjs +2 -1
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/leak-guard.mjs +75 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-blocks.mjs +112 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-delta.mjs +86 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-start.mjs +82 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-stop.mjs +101 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/message-events.mjs +67 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events.mjs +22 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-outcome.mjs +156 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-state.mjs +37 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn.mjs +55 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-watchdogs.mjs +162 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +78 -918
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +16 -18
- package/src/runtime/agent/orchestrator/providers/antigravity-oauth-catalog.mjs +7 -2
- package/src/runtime/agent/orchestrator/providers/antigravity-oauth-login.mjs +4 -5
- package/src/runtime/agent/orchestrator/providers/antigravity-oauth-tokens.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/antigravity-oauth.mjs +14 -15
- package/src/runtime/agent/orchestrator/providers/antigravity-request.mjs +31 -24
- package/src/runtime/agent/orchestrator/providers/api-usage.mjs +2 -7
- package/src/runtime/agent/orchestrator/providers/cursor-auth.mjs +8 -9
- package/src/runtime/agent/orchestrator/providers/cursor-wire-exec.mjs +368 -0
- package/src/runtime/agent/orchestrator/providers/cursor-wire-models.mjs +96 -0
- package/src/runtime/agent/orchestrator/providers/cursor-wire-normalization.mjs +182 -103
- package/src/runtime/agent/orchestrator/providers/cursor-wire-protobuf.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/cursor-wire-request.mjs +197 -0
- package/src/runtime/agent/orchestrator/providers/cursor-wire-stream-bridge.mjs +157 -0
- package/src/runtime/agent/orchestrator/providers/cursor-wire-stream-messages.mjs +106 -0
- package/src/runtime/agent/orchestrator/providers/cursor-wire-stream-sink.mjs +53 -0
- package/src/runtime/agent/orchestrator/providers/cursor-wire-transport.mjs +269 -0
- package/src/runtime/agent/orchestrator/providers/cursor-wire.mjs +117 -1246
- package/src/runtime/agent/orchestrator/providers/cursor.mjs +261 -183
- package/src/runtime/agent/orchestrator/providers/custom-tool-wire.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/gemini-cache.mjs +3 -2
- package/src/runtime/agent/orchestrator/providers/gemini-rest-stream/sse-lines.mjs +21 -0
- package/src/runtime/agent/orchestrator/providers/gemini-rest-stream/watchdogs.mjs +68 -0
- package/src/runtime/agent/orchestrator/providers/gemini-schema.mjs +9 -17
- package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/cancellation.mjs +71 -0
- package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/reader.mjs +108 -0
- package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +71 -283
- package/src/runtime/agent/orchestrator/providers/gemini.mjs +913 -753
- package/src/runtime/agent/orchestrator/providers/grok-oauth-login.mjs +3 -4
- package/src/runtime/agent/orchestrator/providers/grok-oauth-tokens.mjs +16 -24
- package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +2 -8
- package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +7 -8
- package/src/runtime/agent/orchestrator/providers/lib/gemini-model-catalog.mjs +9 -7
- package/src/runtime/agent/orchestrator/providers/lib/grok-tool-schema.mjs +77 -63
- package/src/runtime/agent/orchestrator/providers/lib/oauth-pkce.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/lib/openai-tool-args.mjs +4 -2
- package/src/runtime/agent/orchestrator/providers/lib/responses-terminal-fields.mjs +28 -0
- package/src/runtime/agent/orchestrator/providers/lib/stream-outcome.mjs +3 -1
- package/src/runtime/agent/orchestrator/providers/lib/usage-primitives.mjs +0 -7
- package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +10 -18
- package/src/runtime/agent/orchestrator/providers/model-cache.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/model-catalog-projection.mjs +9 -7
- package/src/runtime/agent/orchestrator/providers/model-catalog.mjs +21 -21
- package/src/runtime/agent/orchestrator/providers/model-list-sanitize.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/model-pricing-rates.mjs +8 -7
- package/src/runtime/agent/orchestrator/providers/oauth-usage.mjs +167 -124
- package/src/runtime/agent/orchestrator/providers/openai-codex-metadata.mjs +5 -5
- package/src/runtime/agent/orchestrator/providers/openai-codex-model.mjs +5 -8
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-send.mjs +243 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/chunk-events.mjs +46 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-result.mjs +82 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-state.mjs +127 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/tool-call-acc.mjs +69 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream.mjs +35 -302
- package/src/runtime/agent/orchestrator/providers/openai-compat-models.mjs +78 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-options.mjs +76 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-response-normalization.mjs +358 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-responses-events.mjs +342 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-responses-state.mjs +172 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-responses.mjs +10 -18
- package/src/runtime/agent/orchestrator/providers/openai-compat-stream-common.mjs +24 -1
- package/src/runtime/agent/orchestrator/providers/openai-compat-stream.mjs +32 -534
- package/src/runtime/agent/orchestrator/providers/openai-compat-trace.mjs +2 -8
- package/src/runtime/agent/orchestrator/providers/openai-compat-wire.mjs +11 -11
- package/src/runtime/agent/orchestrator/providers/openai-compat-xai-send.mjs +262 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-xai.mjs +23 -24
- package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +35 -970
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-request.mjs +228 -0
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events/output-items.mjs +110 -0
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events/terminal-frames.mjs +122 -0
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events.mjs +69 -0
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-items.mjs +142 -0
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-outcome.mjs +195 -0
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-state.mjs +74 -0
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/text-relay.mjs +114 -0
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state.mjs +45 -0
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-watchdogs.mjs +176 -0
- package/src/runtime/agent/orchestrator/providers/openai-oauth-catalog.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +70 -1095
- package/src/runtime/agent/orchestrator/providers/openai-oauth-login.mjs +3 -3
- package/src/runtime/agent/orchestrator/providers/openai-oauth-tokens.mjs +3 -3
- package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +98 -1504
- package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/openai-responses-payload.mjs +160 -141
- package/src/runtime/agent/orchestrator/providers/openai-startup-prewarm.mjs +4 -7
- package/src/runtime/agent/orchestrator/providers/openai-transport-policy.mjs +6 -1
- package/src/runtime/agent/orchestrator/providers/openai-ws-delta.mjs +12 -11
- package/src/runtime/agent/orchestrator/providers/openai-ws-events.mjs +4 -11
- package/src/runtime/agent/orchestrator/providers/openai-ws-headers.mjs +5 -18
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +193 -227
- package/src/runtime/agent/orchestrator/providers/openai-ws-response-state/citations.mjs +53 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-response-state/replay-items.mjs +80 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-response-state/tool-calls.mjs +245 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-response-state/usage.mjs +15 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-response-state.mjs +227 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-send/acquire-attempt.mjs +94 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-send/attempt-request.mjs +145 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-send/reasoning-replay.mjs +36 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-send/send-context.mjs +154 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/attempt-context.mjs +74 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/handshake-failure.mjs +105 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/policy.mjs +142 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/stream-failure-stamps.mjs +81 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/stream-failure.mjs +109 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts.mjs +63 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-send-outcome.mjs +625 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-send-span.mjs +93 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream/event-switch.mjs +125 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream/outcome.mjs +28 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream/socket-handlers.mjs +192 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream/terminal-frames.mjs +118 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream/turn-state-headers.mjs +106 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +139 -1447
- package/src/runtime/agent/orchestrator/providers/openai-ws-terminal.mjs +120 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-text-relay.mjs +84 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-warmup.mjs +171 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-watchdogs.mjs +204 -0
- package/src/runtime/agent/orchestrator/providers/provider-catalog-cache.mjs +3 -3
- package/src/runtime/agent/orchestrator/providers/registry.mjs +13 -0
- package/src/runtime/agent/orchestrator/providers/retry-backoff.mjs +219 -0
- package/src/runtime/agent/orchestrator/providers/retry-classification.mjs +575 -0
- package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +52 -1317
- package/src/runtime/agent/orchestrator/providers/retry-executor.mjs +263 -0
- package/src/runtime/agent/orchestrator/providers/retry-midstream.mjs +345 -0
- package/src/runtime/agent/orchestrator/providers/stream-json-pool/owner-affinity.mjs +121 -0
- package/src/runtime/agent/orchestrator/providers/stream-json-pool/pool-tasks.mjs +74 -0
- package/src/runtime/agent/orchestrator/providers/stream-json-pool/stream-order.mjs +71 -0
- package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/pending-queue.mjs +54 -0
- package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/slot-pick.mjs +28 -0
- package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/slot-spawn.mjs +92 -0
- package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots.mjs +165 -0
- package/src/runtime/agent/orchestrator/providers/stream-json-pool.mjs +66 -492
- package/src/runtime/agent/orchestrator/providers/trace-utils.mjs +10 -4
- package/src/runtime/agent/orchestrator/session/agent-loop.mjs +28 -551
- package/src/runtime/agent/orchestrator/session/cache/read-cache.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/cache/scoped-cache.mjs +111 -117
- package/src/runtime/agent/orchestrator/session/compact/budget.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/compact/constants.mjs +3 -0
- package/src/runtime/agent/orchestrator/session/compact/execution-tail.mjs +9 -8
- package/src/runtime/agent/orchestrator/session/compact/runner.mjs +327 -242
- package/src/runtime/agent/orchestrator/session/compact/summary-schema.mjs +3 -2
- package/src/runtime/agent/orchestrator/session/compact/summary.mjs +47 -341
- package/src/runtime/agent/orchestrator/session/compact/text-utils.mjs +3 -2
- package/src/runtime/agent/orchestrator/session/context-tool-pairs.mjs +295 -0
- package/src/runtime/agent/orchestrator/session/context-utils.mjs +219 -432
- package/src/runtime/agent/orchestrator/session/eager-dispatch/admission.mjs +132 -0
- package/src/runtime/agent/orchestrator/session/eager-dispatch/barriers.mjs +120 -0
- package/src/runtime/agent/orchestrator/session/eager-dispatch/entry.mjs +98 -0
- package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +51 -323
- package/src/runtime/agent/orchestrator/session/evidence-union.mjs +26 -553
- package/src/runtime/agent/orchestrator/session/explicit-skills.mjs +0 -3
- package/src/runtime/agent/orchestrator/session/loop/arg-schema-coerce.mjs +3 -1
- package/src/runtime/agent/orchestrator/session/loop/assistant-commit.mjs +3 -1
- package/src/runtime/agent/orchestrator/session/loop/compact-debug.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +145 -97
- package/src/runtime/agent/orchestrator/session/loop/completion-guards.mjs +3 -3
- package/src/runtime/agent/orchestrator/session/loop/context-overflow.mjs +11 -5
- package/src/runtime/agent/orchestrator/session/loop/fresh-context.mjs +142 -81
- package/src/runtime/agent/orchestrator/session/loop/hidden-agents.mjs +5 -5
- package/src/runtime/agent/orchestrator/session/loop/loop-state.mjs +183 -0
- package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/continuation.mjs +48 -0
- package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/diagnostic.mjs +8 -0
- package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/empty-nudge.mjs +32 -0
- package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/output-limit.mjs +39 -0
- package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/refusal.mjs +25 -0
- package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/segments.mjs +42 -0
- package/src/runtime/agent/orchestrator/session/loop/no-tool-turn.mjs +42 -200
- package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/loop/request-projection.mjs +5 -8
- package/src/runtime/agent/orchestrator/session/loop/send-phase.mjs +297 -0
- package/src/runtime/agent/orchestrator/session/loop/steering.mjs +11 -13
- package/src/runtime/agent/orchestrator/session/loop/stored-tool-args.mjs +7 -7
- package/src/runtime/agent/orchestrator/session/loop/termination.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/loop/test-isolation.mjs +73 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-classify.mjs +3 -4
- package/src/runtime/agent/orchestrator/session/loop/tool-exec/after-hook.mjs +36 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-exec/before-hook.mjs +74 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-exec/call-prep.mjs +110 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-exec/dispatch.mjs +103 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-exec/read-only-deadline.mjs +113 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +59 -422
- package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +9 -12
- package/src/runtime/agent/orchestrator/session/loop/tool-phase.mjs +86 -0
- package/src/runtime/agent/orchestrator/session/loop/transcript-repair.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/loop/usage.mjs +5 -1
- package/src/runtime/agent/orchestrator/session/manager/agent-runtime-singleton.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/manager/ask-call-interrupt.mjs +52 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-queue.mjs +96 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +149 -1447
- package/src/runtime/agent/orchestrator/session/manager/ask-support.mjs +48 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-commit.mjs +184 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-execute.mjs +181 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-failure.mjs +209 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-loop-options.mjs +242 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-open.mjs +132 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-prepare.mjs +247 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-settle.mjs +199 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-state.mjs +126 -0
- package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +300 -255
- package/src/runtime/agent/orchestrator/session/manager/delivered-completions.mjs +3 -2
- package/src/runtime/agent/orchestrator/session/manager/failed-turn-rewind.mjs +47 -0
- package/src/runtime/agent/orchestrator/session/manager/foreign-pending-messages.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/manager/idle-cleanup.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/manager/message-sanitize.mjs +6 -25
- package/src/runtime/agent/orchestrator/session/manager/pending-message-entry.mjs +13 -12
- package/src/runtime/agent/orchestrator/session/manager/pending-messages.mjs +12 -24
- package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge/file-entries.mjs +36 -0
- package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge/file-prefetch.mjs +85 -0
- package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge/symbol-prefetch.mjs +31 -0
- package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge.mjs +36 -203
- package/src/runtime/agent/orchestrator/session/manager/rules-cache.mjs +2 -31
- package/src/runtime/agent/orchestrator/session/manager/rules-source-cache.mjs +3 -2
- package/src/runtime/agent/orchestrator/session/manager/runtime-liveness.mjs +5 -2
- package/src/runtime/agent/orchestrator/session/manager/runtime-loaders.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +5 -3
- package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +155 -163
- package/src/runtime/agent/orchestrator/session/manager/session-id.mjs +3 -3
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +371 -266
- package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +3 -9
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-context.mjs +5 -12
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.mjs +4 -4
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +3 -5
- package/src/runtime/agent/orchestrator/session/manager/turn-interruption-journal.mjs +114 -0
- package/src/runtime/agent/orchestrator/session/manager/turn-interruption.mjs +75 -164
- package/src/runtime/agent/orchestrator/session/manager/usage-metrics.mjs +206 -173
- package/src/runtime/agent/orchestrator/session/manager.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +447 -462
- package/src/runtime/agent/orchestrator/session/provider-prefix-guard.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/runtime-user-context.mjs +2 -5
- package/src/runtime/agent/orchestrator/session/save-session-worker.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +662 -620
- package/src/runtime/agent/orchestrator/session/store/fs-probe.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/store/listing.mjs +9 -586
- package/src/runtime/agent/orchestrator/session/store/load-cache.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/store/paths-heartbeat.mjs +3 -3
- package/src/runtime/agent/orchestrator/session/store/save-fault.mjs +15 -14
- package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +221 -207
- package/src/runtime/agent/orchestrator/session/store/serialize.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/store/summary-cache.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/store/summary-rebuild-worker.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/store/sweep/stale-sweep.mjs +74 -0
- package/src/runtime/agent/orchestrator/session/store/sweep/sweep-finish.mjs +90 -0
- package/src/runtime/agent/orchestrator/session/store/sweep/sweep-plan.mjs +81 -0
- package/src/runtime/agent/orchestrator/session/store/sweep/sweep-record.mjs +92 -0
- package/src/runtime/agent/orchestrator/session/store/sweep/sweep-row.mjs +313 -0
- package/src/runtime/agent/orchestrator/session/store-agent-worker-pool.mjs +37 -0
- package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +3 -3
- package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +259 -228
- package/src/runtime/agent/orchestrator/session/store.mjs +13 -13
- package/src/runtime/agent/orchestrator/session/synthetic-user-envelope.mjs +6 -2
- package/src/runtime/agent/orchestrator/session/tool-batch/execute-call.mjs +265 -0
- package/src/runtime/agent/orchestrator/session/tool-batch/finalize.mjs +259 -0
- package/src/runtime/agent/orchestrator/session/tool-batch/flush.mjs +65 -0
- package/src/runtime/agent/orchestrator/session/tool-batch/plan.mjs +99 -0
- package/src/runtime/agent/orchestrator/session/tool-batch/pre-dispatch.mjs +123 -0
- package/src/runtime/agent/orchestrator/session/tool-batch/record-outcome.mjs +160 -0
- package/src/runtime/agent/orchestrator/session/tool-batch/state.mjs +54 -0
- package/src/runtime/agent/orchestrator/session/tool-batch.mjs +24 -1061
- package/src/runtime/agent/orchestrator/session/tool-envelope.mjs +7 -5
- package/src/runtime/agent/orchestrator/session/tool-result-offload.mjs +6 -6
- package/src/runtime/agent/orchestrator/tool-loop-guard.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/bash-policy-scan.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/advisory-lock.mjs +5 -8
- package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +17 -12
- package/src/runtime/agent/orchestrator/tools/builtin/atomic-write.mjs +155 -159
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/abort-signals.mjs +66 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/backgrounded-result.mjs +82 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/benign-exit.mjs +86 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/command-preflight.mjs +46 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/completed-result.mjs +169 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/deadline-plan.mjs +75 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/inline-hoist.mjs +36 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/invocation-plan.mjs +84 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/result-format.mjs +113 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/spawn-env.mjs +24 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/transport-artifacts.mjs +114 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +109 -905
- package/src/runtime/agent/orchestrator/tools/builtin/binary-file.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +8 -4
- package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +58 -111
- package/src/runtime/agent/orchestrator/tools/builtin/diff-utils.mjs +7 -2
- package/src/runtime/agent/orchestrator/tools/builtin/external-tool-adapters.mjs +251 -208
- package/src/runtime/agent/orchestrator/tools/builtin/find-files-tool.mjs +529 -0
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-policy.mjs +1 -0
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.mjs +145 -666
- package/src/runtime/agent/orchestrator/tools/builtin/git-partial-stage.mjs +43 -21
- package/src/runtime/agent/orchestrator/tools/builtin/glob-walk.mjs +5 -5
- package/src/runtime/agent/orchestrator/tools/builtin/grep-formatting.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/hash-utils.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-context-expander.mjs +121 -107
- package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-output.mjs +100 -56
- package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-path-fanout.mjs +243 -212
- package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-pattern-fanout.mjs +330 -331
- package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-request.mjs +291 -0
- package/src/runtime/agent/orchestrator/tools/builtin/lib/search-grep-chunks.mjs +7 -6
- package/src/runtime/agent/orchestrator/tools/builtin/lib/search-input-helpers.mjs +13 -0
- package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-task-output.mjs +104 -0
- package/src/runtime/agent/orchestrator/tools/builtin/lib/tool-progress.mjs +10 -0
- package/src/runtime/agent/orchestrator/tools/builtin/list-tool-shared.mjs +48 -0
- package/src/runtime/agent/orchestrator/tools/builtin/list-tool.mjs +314 -791
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-client.mjs +8 -4
- package/src/runtime/agent/orchestrator/tools/builtin/path-diagnostics.mjs +8 -8
- package/src/runtime/agent/orchestrator/tools/builtin/path-utils.mjs +19 -10
- package/src/runtime/agent/orchestrator/tools/builtin/read-args.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/read-batch.mjs +16 -21
- package/src/runtime/agent/orchestrator/tools/builtin/read-image-resize.mjs +174 -103
- package/src/runtime/agent/orchestrator/tools/builtin/read-image.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/builtin/read-line-collector.mjs +160 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-mode-tool.mjs +14 -14
- package/src/runtime/agent/orchestrator/tools/builtin/read-office-files.mjs +5 -8
- package/src/runtime/agent/orchestrator/tools/builtin/read-open.mjs +3 -4
- package/src/runtime/agent/orchestrator/tools/builtin/read-range-index.mjs +5 -5
- package/src/runtime/agent/orchestrator/tools/builtin/read-single-fast-paths.mjs +178 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-single-guards.mjs +161 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-single-media.mjs +53 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-single-render.mjs +210 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-single-stream.mjs +79 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-single-tool.mjs +122 -832
- package/src/runtime/agent/orchestrator/tools/builtin/read-snapshot-runtime.mjs +3 -4
- package/src/runtime/agent/orchestrator/tools/builtin/read-special-files.mjs +6 -11
- package/src/runtime/agent/orchestrator/tools/builtin/read-streaming.mjs +23 -139
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-dispatch.mjs +123 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-entries.mjs +137 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-render.mjs +158 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-snapshot.mjs +88 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool/glob-survey.mjs +100 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool/image-fast-path.mjs +32 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool/reach-preflight.mjs +95 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool.mjs +115 -703
- package/src/runtime/agent/orchestrator/tools/builtin/read-window-widen.mjs +42 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-windows.mjs +9 -2
- package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.mjs +47 -30
- package/src/runtime/agent/orchestrator/tools/builtin/search-builders.mjs +4 -4
- package/src/runtime/agent/orchestrator/tools/builtin/search-glob-tool.mjs +494 -427
- package/src/runtime/agent/orchestrator/tools/builtin/search-grep-tool.mjs +550 -785
- package/src/runtime/agent/orchestrator/tools/builtin/search-path-diagnostics.mjs +5 -5
- package/src/runtime/agent/orchestrator/tools/builtin/shell-analysis.mjs +13 -7
- package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +16 -19
- package/src/runtime/agent/orchestrator/tools/builtin/shell-lossless-compact.mjs +1 -2
- package/src/runtime/agent/orchestrator/tools/builtin/shell-runtime.mjs +3 -3
- package/src/runtime/agent/orchestrator/tools/builtin/snapshot-store.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/builtin/snapshot-validation.mjs +5 -5
- package/src/runtime/agent/orchestrator/tools/builtin/task-tool.mjs +25 -17
- package/src/runtime/agent/orchestrator/tools/builtin/text-stats.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin.mjs +22 -20
- package/src/runtime/agent/orchestrator/tools/code-graph/aggregate-roots.mjs +9 -10
- package/src/runtime/agent/orchestrator/tools/code-graph/ast-calls.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +94 -87
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch/abort-race.mjs +33 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch/federation.mjs +144 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch/root-resolution.mjs +142 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch/work.mjs +125 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +180 -1056
- package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/child-kill.mjs +55 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/jsonl-records.mjs +22 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/spawn-jsonl.mjs +135 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary.mjs +43 -232
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/calls.mjs +152 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/dependents.mjs +91 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/shared.mjs +81 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/structure.mjs +75 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/symbols.mjs +150 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/project-root.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +40 -41
- package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +3 -4
- package/src/runtime/agent/orchestrator/tools/code-graph/text-columns.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.golden.json +47 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.mjs +244 -290
- package/src/runtime/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/code-graph-state.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/env-scrub.mjs +7 -11
- package/src/runtime/agent/orchestrator/tools/graph-manifest.json +11 -11
- package/src/runtime/agent/orchestrator/tools/lib/isolated-test-env.mjs +30 -0
- package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/lib/shell-run-background/promote-job.mjs +90 -0
- package/src/runtime/agent/orchestrator/tools/lib/shell-run-background/promotion-results.mjs +158 -0
- package/src/runtime/agent/orchestrator/tools/lib/shell-run-background.mjs +142 -0
- package/src/runtime/agent/orchestrator/tools/lib/shell-run-settle.mjs +165 -0
- package/src/runtime/agent/orchestrator/tools/lib/shell-run-spawn.mjs +208 -0
- package/src/runtime/agent/orchestrator/tools/lib/shell-run-state.mjs +175 -0
- package/src/runtime/agent/orchestrator/tools/lib/shell-spawn-retry.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/lib/shell-warm-standby.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/patch/apply-patch/codex-batch.mjs +245 -0
- package/src/runtime/agent/orchestrator/tools/patch/apply-patch/request.mjs +96 -0
- package/src/runtime/agent/orchestrator/tools/patch/apply-patch/route.mjs +46 -0
- package/src/runtime/agent/orchestrator/tools/patch/constants.mjs +1 -2
- package/src/runtime/agent/orchestrator/tools/patch/dispatch/native-proofs.mjs +65 -0
- package/src/runtime/agent/orchestrator/tools/patch/dispatch/native-report.mjs +65 -0
- package/src/runtime/agent/orchestrator/tools/patch/dispatch/native-snapshots.mjs +72 -0
- package/src/runtime/agent/orchestrator/tools/patch/dispatch.mjs +32 -168
- package/src/runtime/agent/orchestrator/tools/patch/matcher.mjs +116 -358
- package/src/runtime/agent/orchestrator/tools/patch/mutation-output.mjs +30 -0
- package/src/runtime/agent/orchestrator/tools/patch/orchestrator.mjs +69 -1401
- package/src/runtime/agent/orchestrator/tools/patch/parsing.mjs +4 -2
- package/src/runtime/agent/orchestrator/tools/patch/post-patch-excerpts.mjs +99 -0
- package/src/runtime/agent/orchestrator/tools/patch/read-redirects.mjs +81 -0
- package/src/runtime/agent/orchestrator/tools/patch/replay-capture.mjs +184 -0
- package/src/runtime/agent/orchestrator/tools/patch/rollback-state.mjs +51 -0
- package/src/runtime/agent/orchestrator/tools/patch/section-coalesce.mjs +82 -0
- package/src/runtime/agent/orchestrator/tools/patch/sequence/report.mjs +88 -0
- package/src/runtime/agent/orchestrator/tools/patch/sequence/run.mjs +70 -0
- package/src/runtime/agent/orchestrator/tools/patch/sequence/units.mjs +132 -0
- package/src/runtime/agent/orchestrator/tools/patch/sequence.mjs +84 -0
- package/src/runtime/agent/orchestrator/tools/patch/text-lines.mjs +267 -0
- package/src/runtime/agent/orchestrator/tools/patch/ui-diff.mjs +108 -0
- package/src/runtime/agent/orchestrator/tools/patch/v4a-anchors.mjs +4 -5
- package/src/runtime/agent/orchestrator/tools/patch/v4a-convert.mjs +434 -432
- package/src/runtime/agent/orchestrator/tools/patch/wave.mjs +114 -0
- package/src/runtime/agent/orchestrator/tools/patch-binary-fetcher.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/patch-manifest.json +11 -11
- package/src/runtime/agent/orchestrator/tools/progress-message.mjs +6 -5
- package/src/runtime/agent/orchestrator/tools/shell-command.mjs +249 -996
- package/src/runtime/agent/orchestrator/tools/shell-exec-output.mjs +7 -9
- package/src/runtime/agent/orchestrator/tools/shell-exec-policy.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/shell-policy.mjs +6 -6
- package/src/runtime/agent/orchestrator/tools/shell-powershell.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/shell-snapshot.mjs +4 -5
- package/src/runtime/agent/orchestrator/tools/spawn-manifest.json +11 -11
- package/src/runtime/agent/orchestrator/tools/tool-batch-trace.mjs +9 -13
- package/src/runtime/attachments/store.mjs +3 -9
- package/src/runtime/browser-bridge/action-schema.mjs +396 -325
- package/src/runtime/browser-bridge/client.mjs +1 -9
- package/src/runtime/browser-bridge/input-fields.mjs +13 -9
- package/src/runtime/channels/lib/config.mjs +1 -10
- package/src/runtime/channels/lib/crash-log.mjs +4 -4
- package/src/runtime/channels/lib/event-queue.mjs +5 -6
- package/src/runtime/channels/lib/executor.mjs +2 -84
- package/src/runtime/channels/lib/owned-runtime/automation-services.mjs +105 -0
- package/src/runtime/channels/lib/owned-runtime/automation-start.mjs +44 -0
- package/src/runtime/channels/lib/owned-runtime/config-reload.mjs +79 -0
- package/src/runtime/channels/lib/owned-runtime/owned-start.mjs +172 -0
- package/src/runtime/channels/lib/owned-runtime/owned-stop.mjs +59 -0
- package/src/runtime/channels/lib/owned-runtime/ownership-refresh.mjs +36 -0
- package/src/runtime/channels/lib/owned-runtime/state.mjs +22 -0
- package/src/runtime/channels/lib/owned-runtime.mjs +45 -488
- package/src/runtime/channels/lib/parent-bridge.mjs +2 -2
- package/src/runtime/channels/lib/runtime-paths.mjs +5 -8
- package/src/runtime/channels/lib/scheduler.mjs +152 -135
- package/src/runtime/channels/lib/settings.mjs +1 -1
- package/src/runtime/channels/lib/state-file.mjs +1 -6
- package/src/runtime/channels/lib/status-snapshot.mjs +53 -53
- package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +17 -21
- package/src/runtime/channels/lib/voice-transcription.mjs +5 -5
- package/src/runtime/channels/lib/webhook/deliveries.mjs +0 -5
- package/src/runtime/channels/lib/webhook/listener-lifecycle.mjs +119 -0
- package/src/runtime/channels/lib/webhook/log.mjs +3 -3
- package/src/runtime/channels/lib/webhook/relay-tunnel/leg-heartbeat.mjs +35 -0
- package/src/runtime/channels/lib/webhook/relay-tunnel/limits.mjs +6 -0
- package/src/runtime/channels/lib/webhook/relay-tunnel/local-forward.mjs +93 -0
- package/src/runtime/channels/lib/webhook/relay-tunnel.mjs +50 -168
- package/src/runtime/channels/lib/webhook/request-handler.mjs +258 -0
- package/src/runtime/channels/lib/webhook/session-dispatch.mjs +132 -0
- package/src/runtime/channels/lib/webhook/signature.mjs +1 -1
- package/src/runtime/channels/lib/webhook/verification.mjs +90 -0
- package/src/runtime/channels/lib/webhook.mjs +46 -497
- package/src/runtime/channels/lib/whisper-language.mjs +3 -10
- package/src/runtime/channels/lib/worker-bootstrap.mjs +51 -41
- package/src/runtime/channels/lib/worker-ipc.mjs +4 -4
- package/src/runtime/channels/lib/worker-main.mjs +7 -11
- package/src/runtime/computer-bridge/action-schema.mjs +180 -133
- package/src/runtime/computer-bridge/actions.mjs +19 -2
- package/src/runtime/computer-bridge/capture-size.mjs +8 -2
- package/src/runtime/computer-bridge/client.mjs +179 -147
- package/src/runtime/computer-bridge/core-actions.mjs +143 -101
- package/src/runtime/computer-bridge/pending-continuation.mjs +4 -7
- package/src/runtime/github/client.mjs +5 -7
- package/src/runtime/github/contract.mjs +3 -1
- package/src/runtime/local-provider/asset-installer.mjs +5 -7
- package/src/runtime/local-provider/model-state.mjs +8 -6
- package/src/runtime/local-provider/server-process/child-state.mjs +73 -0
- package/src/runtime/local-provider/server-process/readiness.mjs +42 -0
- package/src/runtime/local-provider/server-process.mjs +28 -113
- package/src/runtime/media/adapters/codex-image.mjs +1 -1
- package/src/runtime/media/adapters/xai-media.mjs +7 -2
- package/src/runtime/media/catalog-errors.mjs +3 -5
- package/src/runtime/media/catalog.mjs +4 -6
- package/src/runtime/media/defaults.mjs +2 -2
- package/src/runtime/media/jobs.mjs +1 -2
- package/src/runtime/media/renditions.mjs +11 -10
- package/src/runtime/media/store.mjs +7 -9
- package/src/runtime/media/tool.mjs +1 -5
- package/src/runtime/memory/data/runtime-manifest.json +9 -9
- package/src/runtime/memory/index.mjs +8 -15
- package/src/runtime/memory/lib/agent-ipc.mjs +1 -1
- package/src/runtime/memory/lib/core-memory-file.mjs +7 -5
- package/src/runtime/memory/lib/cycle-llm-adapters.mjs +1 -1
- package/src/runtime/memory/lib/cycle-scheduler/backlog-probe.mjs +65 -0
- package/src/runtime/memory/lib/cycle-scheduler/cycle1-runs.mjs +120 -0
- package/src/runtime/memory/lib/cycle-scheduler/cycle2-runs.mjs +120 -0
- package/src/runtime/memory/lib/cycle-scheduler/health-ledger.mjs +96 -0
- package/src/runtime/memory/lib/cycle-scheduler/scheduled-enqueue.mjs +50 -0
- package/src/runtime/memory/lib/cycle-scheduler/tick-loop.mjs +104 -0
- package/src/runtime/memory/lib/cycle-scheduler.mjs +71 -475
- package/src/runtime/memory/lib/cycle-signatures.mjs +1 -2
- package/src/runtime/memory/lib/cycle1/cycle1-plan.mjs +94 -0
- package/src/runtime/memory/lib/cycle1/cycle1-result.mjs +113 -0
- package/src/runtime/memory/lib/cycle1/cycle1-rows.mjs +194 -0
- package/src/runtime/memory/lib/cycle1/cycle1-window.mjs +193 -0
- package/src/runtime/memory/lib/embedding-provider.mjs +3 -3
- package/src/runtime/memory/lib/embedding-worker.mjs +7 -9
- package/src/runtime/memory/lib/http-router/admin-routes.mjs +213 -0
- package/src/runtime/memory/lib/http-router/ingest-routes.mjs +122 -0
- package/src/runtime/memory/lib/http-router/lifecycle-routes.mjs +96 -0
- package/src/runtime/memory/lib/http-router/mcp-route.mjs +49 -0
- package/src/runtime/memory/lib/http-router/session-routes.mjs +67 -0
- package/src/runtime/memory/lib/http-router/tool-routes.mjs +84 -0
- package/src/runtime/memory/lib/http-router.mjs +43 -659
- package/src/runtime/memory/lib/http-wire.mjs +1 -2
- package/src/runtime/memory/lib/ingest/ingest-embed-flush.mjs +72 -0
- package/src/runtime/memory/lib/ingest/ingest-insert.mjs +66 -0
- package/src/runtime/memory/lib/ingest/ingest-occurrences.mjs +109 -0
- package/src/runtime/memory/lib/ingest/ordinal-state.mjs +181 -0
- package/src/runtime/memory/lib/ingest/transcript-discovery.mjs +52 -0
- package/src/runtime/memory/lib/ingest/transcript-offsets.mjs +54 -0
- package/src/runtime/memory/lib/ingest/transcript-rows.mjs +81 -0
- package/src/runtime/memory/lib/ingest/transcript-tail.mjs +110 -0
- package/src/runtime/memory/lib/ingest/transcript-watcher.mjs +216 -0
- package/src/runtime/memory/lib/light-ko-morph.mjs +1 -1
- package/src/runtime/memory/lib/memory-action-handlers/core-actions.mjs +127 -0
- package/src/runtime/memory/lib/memory-action-handlers/cycle-actions.mjs +278 -0
- package/src/runtime/memory/lib/memory-action-handlers/maintenance-actions.mjs +76 -0
- package/src/runtime/memory/lib/memory-action-handlers/manage-actions.mjs +181 -0
- package/src/runtime/memory/lib/memory-action-handlers.mjs +49 -679
- package/src/runtime/memory/lib/memory-chunk-quality.mjs +59 -20
- package/src/runtime/memory/lib/memory-config-flags.mjs +1 -1
- package/src/runtime/memory/lib/memory-cycle-requests.mjs +9 -21
- package/src/runtime/memory/lib/memory-cycle1.mjs +49 -525
- package/src/runtime/memory/lib/memory-cycle2-mutations.mjs +4 -3
- package/src/runtime/memory/lib/memory-cycle2-review.mjs +5 -3
- package/src/runtime/memory/lib/memory-cycle2-shared.mjs +2 -2
- package/src/runtime/memory/lib/memory-embed.mjs +4 -9
- package/src/runtime/memory/lib/memory-extraction.mjs +1 -1
- package/src/runtime/memory/lib/memory-process-lock.mjs +1 -1
- package/src/runtime/memory/lib/memory-recall-scope-filter.mjs +7 -3
- package/src/runtime/memory/lib/memory-recall-store.mjs +70 -678
- package/src/runtime/memory/lib/memory-schema/core-and-meta.mjs +60 -0
- package/src/runtime/memory/lib/memory-schema/entries.mjs +94 -0
- package/src/runtime/memory/lib/memory-schema/entry-triggers.mjs +54 -0
- package/src/runtime/memory/lib/memory-schema/score-params.mjs +66 -0
- package/src/runtime/memory/lib/memory-text-utils.mjs +10 -10
- package/src/runtime/memory/lib/memory.mjs +14 -260
- package/src/runtime/memory/lib/model-profile.mjs +1 -1
- package/src/runtime/memory/lib/pg/adapter.mjs +4 -2
- package/src/runtime/memory/lib/pg/process.mjs +251 -254
- package/src/runtime/memory/lib/pg/supervisor.mjs +1 -6
- package/src/runtime/memory/lib/query-core-recall.mjs +82 -0
- package/src/runtime/memory/lib/query-fan-out.mjs +66 -0
- package/src/runtime/memory/lib/query-handlers.mjs +61 -1124
- package/src/runtime/memory/lib/query-hybrid-search.mjs +369 -0
- package/src/runtime/memory/lib/query-id-lookup.mjs +60 -0
- package/src/runtime/memory/lib/query-last-browse.mjs +266 -0
- package/src/runtime/memory/lib/query-maintenance-handlers.mjs +18 -17
- package/src/runtime/memory/lib/query-ranking.mjs +5 -3
- package/src/runtime/memory/lib/query-raw-merge.mjs +27 -0
- package/src/runtime/memory/lib/query-raw-window.mjs +64 -0
- package/src/runtime/memory/lib/query-search-plan.mjs +117 -0
- package/src/runtime/memory/lib/query-session-recall.mjs +153 -0
- package/src/runtime/memory/lib/query-window-browse.mjs +63 -0
- package/src/runtime/memory/lib/recall-event-context.mjs +1 -1
- package/src/runtime/memory/lib/recall-format.mjs +318 -279
- package/src/runtime/memory/lib/recall-hybrid/concept-expansion.mjs +211 -0
- package/src/runtime/memory/lib/recall-hybrid/hybrid-sql.mjs +250 -0
- package/src/runtime/memory/lib/recall-hybrid/members.mjs +33 -0
- package/src/runtime/memory/lib/recall-hybrid/plan.mjs +80 -0
- package/src/runtime/memory/lib/recall-hybrid/root-resolution.mjs +131 -0
- package/src/runtime/memory/lib/runtime-fetcher.mjs +4 -6
- package/src/runtime/memory/lib/session-ingest-runtime.mjs +50 -433
- package/src/runtime/memory/lib/session-ingest.mjs +8 -136
- package/src/runtime/memory/lib/tool-call-handler.mjs +2 -3
- package/src/runtime/memory/lib/trace-store/agent-call-inserts.mjs +90 -0
- package/src/runtime/memory/lib/trace-store/agent-call-rows.mjs +81 -0
- package/src/runtime/memory/lib/trace-store/agent-session-summary.mjs +65 -0
- package/src/runtime/memory/lib/trace-store.mjs +12 -242
- package/src/runtime/memory/lib/transcript-ingest.mjs +32 -475
- package/src/runtime/office/README.md +3 -2
- package/src/runtime/office/authoring/pptx-author-action.mjs +138 -70
- package/src/runtime/office/authoring/pptx-brief.mjs +52 -16
- package/src/runtime/office/authoring/pptx-contact-sheet.mjs +3 -1
- package/src/runtime/office/authoring/pptx-receipt.mjs +13 -12
- package/src/runtime/office/authoring/pptx-script-normalize.mjs +1 -1
- package/src/runtime/office/bench/deck-bench.mjs +6 -3
- package/src/runtime/office/bench/quality-live-benchmark.mjs +33 -0
- package/src/runtime/office/capabilities-aliases.mjs +61 -0
- package/src/runtime/office/capabilities-catalog.mjs +591 -0
- package/src/runtime/office/capabilities-signatures.mjs +580 -0
- package/src/runtime/office/capabilities.mjs +266 -1460
- package/src/runtime/office/com/com-adapter.mjs +2 -2
- package/src/runtime/office/com/office-com-host.ps1 +5185 -4979
- package/src/runtime/office/core/office-actions-batch.mjs +353 -312
- package/src/runtime/office/core/office-actions-inspect.mjs +108 -115
- package/src/runtime/office/core/office-actions-lifecycle.mjs +39 -253
- package/src/runtime/office/core/office-actions-open.mjs +28 -34
- package/src/runtime/office/core/office-actions-render.mjs +30 -258
- package/src/runtime/office/core/office-core.mjs +14 -24
- package/src/runtime/office/core/office-documents.mjs +3 -1
- package/src/runtime/office/core/office-finalize/commit-stage.mjs +54 -0
- package/src/runtime/office/core/office-finalize/holds.mjs +57 -0
- package/src/runtime/office/core/office-finalize/review-stage.mjs +90 -0
- package/src/runtime/office/core/office-finalize/session-save.mjs +47 -0
- package/src/runtime/office/core/office-qa/design-review-stage.mjs +80 -0
- package/src/runtime/office/core/office-qa/fix-operations.mjs +47 -0
- package/src/runtime/office/core/office-qa/preview-stage.mjs +90 -0
- package/src/runtime/office/core/office-qa/review-assembly.mjs +87 -0
- package/src/runtime/office/core/office-recalculation.mjs +2 -2
- package/src/runtime/office/core/office-render-preview.mjs +11 -13
- package/src/runtime/office/core/office-sessions.mjs +273 -286
- package/src/runtime/office/core/pagination.mjs +6 -6
- package/src/runtime/office/core/pptx-page-cache.mjs +1 -1
- package/src/runtime/office/core/tabular.mjs +11 -6
- package/src/runtime/office/design/composition-system.mjs +3 -1
- package/src/runtime/office/design/content-model.mjs +3 -1
- package/src/runtime/office/design/design-art-direction.mjs +5 -1
- package/src/runtime/office/design/design-creative-director.mjs +7 -8
- package/src/runtime/office/design/design-discipline.mjs +15 -18
- package/src/runtime/office/design/design-system.mjs +5 -8
- package/src/runtime/office/design/design-tokens.mjs +33 -28
- package/src/runtime/office/design/docx/design-docx/front-matter.mjs +81 -0
- package/src/runtime/office/design/docx/design-docx/section.mjs +114 -0
- package/src/runtime/office/design/docx/design-docx/writer.mjs +57 -0
- package/src/runtime/office/design/docx/design-docx-components.mjs +18 -19
- package/src/runtime/office/design/docx/design-docx.mjs +19 -222
- package/src/runtime/office/design/library/design-library-core.mjs +1 -1
- package/src/runtime/office/design/library/design-library.mjs +8 -6
- package/src/runtime/office/design/library/design-template-fill.mjs +159 -0
- package/src/runtime/office/design/library/design-template-index.mjs +221 -174
- package/src/runtime/office/design/library/design-template-induct.mjs +222 -0
- package/src/runtime/office/design/library/design-template-inspect.mjs +165 -121
- package/src/runtime/office/design/xlsx/design-xlsx-components.mjs +12 -15
- package/src/runtime/office/design/xlsx/design-xlsx.mjs +450 -359
- package/src/runtime/office/index.mjs +3 -1
- package/src/runtime/office/pdf/pdf-adapter.mjs +25 -816
- package/src/runtime/office/pdf/pdf-analysis.mjs +385 -585
- package/src/runtime/office/pdf/pdf-batch-content.mjs +349 -0
- package/src/runtime/office/pdf/pdf-batch-structure.mjs +240 -0
- package/src/runtime/office/pdf/pdf-document.mjs +41 -0
- package/src/runtime/office/pdf/pdf-draw.mjs +1 -1
- package/src/runtime/office/pdf/pdf-edit-document.mjs +142 -0
- package/src/runtime/office/pdf/pdf-fonts.mjs +1 -1
- package/src/runtime/office/pdf/pdf-forms.mjs +3 -1
- package/src/runtime/office/pdf/pdf-marks.mjs +123 -0
- package/src/runtime/office/pdf/pdf-ocr.mjs +347 -0
- package/src/runtime/office/pdf/pdf-search.mjs +4 -1
- package/src/runtime/office/pdf/pdf-security.mjs +37 -9
- package/src/runtime/office/pdf/pdf-writer.mjs +541 -412
- package/src/runtime/office/portable/docx-revisions.mjs +10 -8
- package/src/runtime/office/portable/docx-runs.mjs +3 -5
- package/src/runtime/office/portable/docx-tracked-edits.mjs +1 -2
- package/src/runtime/office/portable/font-provisioner.mjs +1 -1
- package/src/runtime/office/portable/portable-cells.mjs +67 -79
- package/src/runtime/office/portable/portable-chart-faults.mjs +42 -11
- package/src/runtime/office/portable/portable-chart.mjs +21 -17
- package/src/runtime/office/portable/portable-docx-edits.mjs +755 -0
- package/src/runtime/office/portable/portable-docx-operations.mjs +733 -0
- package/src/runtime/office/portable/portable-docx-parts.mjs +35 -4
- package/src/runtime/office/portable/portable-docx-xml.mjs +90 -60
- package/src/runtime/office/portable/portable-docx.mjs +84 -1340
- package/src/runtime/office/portable/portable-ooxml.mjs +5 -6
- package/src/runtime/office/portable/portable-opc.mjs +73 -3
- package/src/runtime/office/portable/portable-package.mjs +16 -7
- package/src/runtime/office/portable/portable-pivot.mjs +35 -30
- package/src/runtime/office/portable/portable-pptx-charts.mjs +48 -45
- package/src/runtime/office/portable/portable-pptx-core.mjs +94 -93
- package/src/runtime/office/portable/portable-pptx-deck.mjs +16 -13
- package/src/runtime/office/portable/portable-pptx-shapes.mjs +356 -276
- package/src/runtime/office/portable/portable-shared-formulas.mjs +92 -0
- package/src/runtime/office/portable/portable-sheet-audits.mjs +416 -0
- package/src/runtime/office/portable/portable-sheet-styles.mjs +8 -7
- package/src/runtime/office/portable/portable-sheet-xml.mjs +28 -29
- package/src/runtime/office/portable/portable-slide-shapes.mjs +44 -28
- package/src/runtime/office/portable/portable-snapshot-docx.mjs +622 -0
- package/src/runtime/office/portable/portable-snapshot-pptx.mjs +254 -0
- package/src/runtime/office/portable/portable-snapshot-shared.mjs +106 -0
- package/src/runtime/office/portable/portable-snapshot-xlsx.mjs +453 -0
- package/src/runtime/office/portable/portable-snapshot.mjs +8 -1134
- package/src/runtime/office/portable/portable-soffice.mjs +230 -232
- package/src/runtime/office/portable/portable-validation-package.mjs +312 -0
- package/src/runtime/office/portable/portable-validation.mjs +615 -1098
- package/src/runtime/office/portable/portable-xlsx-operations.mjs +1002 -0
- package/src/runtime/office/portable/portable-xlsx-sheet-edits.mjs +531 -0
- package/src/runtime/office/portable/portable-xlsx.mjs +103 -1387
- package/src/runtime/office/portable/portable-xml.mjs +4 -8
- package/src/runtime/office/portable/pptx-relations.mjs +1 -1
- package/src/runtime/office/portable/review-editability.mjs +3 -1
- package/src/runtime/office/portable/text-metrics.mjs +121 -84
- package/src/runtime/office/portable/xlsx-assertions.mjs +1 -1
- package/src/runtime/office/portable/xlsx-contract.mjs +132 -106
- package/src/runtime/office/portable/xlsx-formula-audit.mjs +246 -118
- package/src/runtime/office/portable/xlsx-formula-engine.mjs +549 -0
- package/src/runtime/office/portable/xlsx-recalculate.mjs +278 -0
- package/src/runtime/office/portable/xlsx-sheet-hygiene.mjs +98 -26
- package/src/runtime/office/quality/assurance-checklist.mjs +82 -60
- package/src/runtime/office/quality/assurance-issue.mjs +5 -0
- package/src/runtime/office/quality/assurance-structure-docx.mjs +205 -0
- package/src/runtime/office/quality/assurance-structure-pptx.mjs +762 -0
- package/src/runtime/office/quality/assurance-structure-xlsx.mjs +256 -0
- package/src/runtime/office/quality/assurance-structure.mjs +4 -798
- package/src/runtime/office/quality/assurance-trust.mjs +44 -49
- package/src/runtime/office/quality/design-aesthetics.mjs +3 -6
- package/src/runtime/office/quality/design-deck-diversity.mjs +85 -48
- package/src/runtime/office/quality/design-review-critique.mjs +7 -6
- package/src/runtime/office/quality/design-review.mjs +10 -13
- package/src/runtime/office/quality/document-acceptance.mjs +8 -7
- package/src/runtime/office/quality/inline-audit.mjs +2 -1
- package/src/runtime/office/quality/presentation-acceptance.mjs +3 -7
- package/src/runtime/office/quality/quality-pipeline.mjs +49 -11
- package/src/runtime/office/quality/quality-score.mjs +5 -7
- package/src/runtime/office/quality/visual-diff.mjs +0 -2
- package/src/runtime/shared/abort-controller.mjs +1 -1
- package/src/runtime/shared/agent-reap-state.mjs +35 -0
- package/src/runtime/shared/atomic-file.mjs +5 -5
- package/src/runtime/shared/automation-attachments.mjs +5 -4
- package/src/runtime/shared/background-tasks.mjs +44 -9
- package/src/runtime/shared/boot-profile.mjs +6 -2
- package/src/runtime/shared/buffered-appender.mjs +1 -1
- package/src/runtime/shared/child-spawn-gate.mjs +2 -2
- package/src/runtime/shared/code-point-order.mjs +5 -0
- package/src/runtime/shared/config-patch.mjs +9 -12
- package/src/runtime/shared/config.mjs +5 -5
- package/src/runtime/shared/error-presentation.mjs +2 -8
- package/src/runtime/shared/extension-scopes.mjs +3 -1
- package/src/runtime/shared/file-lock.mjs +2 -1
- package/src/runtime/shared/injected-display-text.mjs +38 -0
- package/src/runtime/shared/llm/cost.mjs +6 -9
- package/src/runtime/shared/llm/http-agent.mjs +1 -1
- package/src/runtime/shared/llm/index.mjs +1 -1
- package/src/runtime/shared/llm/reasoning-usage.mjs +42 -0
- package/src/runtime/shared/llm/usage-ledger-import.mjs +3 -1
- package/src/runtime/shared/llm/usage-ledger-repair.mjs +6 -14
- package/src/runtime/shared/llm/usage-ledger.mjs +31 -30
- package/src/runtime/shared/llm/usage-rollup.mjs +8 -2
- package/src/runtime/shared/loopback-listener.mjs +1 -6
- package/src/runtime/shared/open-url.mjs +1 -1
- package/src/runtime/shared/orchestration.mjs +2 -2
- package/src/runtime/shared/plugin-paths.mjs +3 -3
- package/src/runtime/shared/process-shutdown.mjs +4 -4
- package/src/runtime/shared/provider-accounts.mjs +109 -11
- package/src/runtime/shared/resource-admission.mjs +32 -8
- package/src/runtime/shared/review-diff.mjs +34 -0
- package/src/runtime/shared/schedules-db.mjs +1 -1
- package/src/runtime/shared/schema-value-error.mjs +3 -5
- package/src/runtime/shared/skill-selection.mjs +3 -1
- package/src/runtime/shared/staged-child-result.mjs +0 -2
- package/src/runtime/shared/staged-update.mjs +1 -1
- package/src/runtime/shared/task-notification-envelope.mjs +130 -58
- package/src/runtime/shared/time-format.mjs +6 -5
- package/src/runtime/shared/tool-card-model/agent-surface.mjs +170 -0
- package/src/runtime/shared/tool-card-model/aggregate-card.mjs +66 -0
- package/src/runtime/shared/tool-card-model/background-task.mjs +171 -0
- package/src/runtime/shared/tool-card-model/card-detail.mjs +115 -0
- package/src/runtime/shared/tool-card-model/card-header.mjs +48 -0
- package/src/runtime/shared/tool-card-model/card-input.mjs +85 -0
- package/src/runtime/shared/tool-card-model/card-status.mjs +83 -0
- package/src/runtime/shared/tool-card-model/displayed-result.mjs +44 -0
- package/src/runtime/shared/tool-card-model/generic-detail.mjs +79 -0
- package/src/runtime/shared/tool-card-model/git-result.mjs +9 -0
- package/src/runtime/shared/tool-card-model/inline-text.mjs +78 -0
- package/src/runtime/shared/tool-card-model/shell-surface.mjs +45 -0
- package/src/runtime/shared/tool-card-model/terminal-status.mjs +109 -0
- package/src/runtime/shared/tool-card-model.golden-cases.mjs +208 -0
- package/src/runtime/shared/tool-card-model.golden.json +964 -0
- package/src/runtime/shared/tool-card-model.mjs +110 -893
- package/src/runtime/shared/tool-execution-contract.mjs +104 -60
- package/src/runtime/shared/tool-primitives.mjs +2 -1
- package/src/runtime/shared/tool-result-summary.mjs +244 -233
- package/src/runtime/shared/tool-surface.mjs +33 -461
- package/src/runtime/shared/tool-work-units.mjs +504 -0
- package/src/runtime/shared/transcript-writer/rotation.mjs +90 -0
- package/src/runtime/shared/transcript-writer/session-record.mjs +49 -0
- package/src/runtime/shared/transcript-writer/transcript-file.mjs +108 -0
- package/src/runtime/shared/transcript-writer.mjs +35 -239
- package/src/runtime/shared/transport-error-text.mjs +53 -66
- package/src/runtime/shared/turn-snapshot-store.mjs +14 -0
- package/src/runtime/shared/turn-snapshot.mjs +31 -16
- package/src/runtime/shared/turn-worktree-snapshot.mjs +120 -13
- package/src/runtime/shared/update-checker.mjs +1 -1
- package/src/runtime/shared/user-cwd.mjs +4 -4
- package/src/runtime/shared/user-data-guard.mjs +22 -7
- package/src/runtime/shared/webhooks-db.mjs +1 -1
- package/src/runtime/tidy/extract.mjs +1 -1
- package/src/runtime/tidy/history-comment.mjs +23 -2
- package/src/runtime/tidy/languages.mjs +20 -15
- package/src/runtime/tidy/report.mjs +169 -44
- package/src/runtime/tidy/resolve.mjs +3 -6
- package/src/runtime/tidy/rules/kotlin/no-history-comment.yml +1 -1
- package/src/runtime/tidy/rules/kotlin/todo-marker.yml +1 -1
- package/src/runtime/tidy/run-engines.mjs +29 -14
- package/src/runtime/tidy/runners/biome.mjs +11 -13
- package/src/runtime/tidy/runners/mago.mjs +3 -1
- package/src/runtime/tidy/structural.mjs +67 -47
- package/src/runtime/tidy/tool-defs.mjs +26 -6
- package/src/runtime/tidy/tool.mjs +227 -41
- package/src/runtime/web-search/index.mjs +7 -9
- package/src/runtime/web-search/lib/cache.mjs +1 -1
- package/src/runtime/web-search/lib/config.mjs +3 -3
- package/src/runtime/web-search/lib/document-content.mjs +3 -5
- package/src/runtime/web-search/lib/fetch-pipeline.mjs +3 -1
- package/src/runtime/web-search/lib/formatter.mjs +16 -9
- package/src/runtime/web-search/lib/http-fetch.mjs +3 -2
- package/src/runtime/web-search/lib/ssrf-guard.mjs +4 -9
- package/src/runtime/web-search/lib/state.mjs +0 -4
- package/src/runtime/web-search/lib/web-tools.mjs +1 -4
- package/src/session-runtime/agent-tool-routing.mjs +3 -5
- package/src/session-runtime/boot/apis.mjs +487 -0
- package/src/session-runtime/boot/begin.mjs +123 -0
- package/src/session-runtime/boot/config.mjs +108 -0
- package/src/session-runtime/boot/facade.mjs +88 -0
- package/src/session-runtime/boot/infrastructure.mjs +250 -0
- package/src/session-runtime/boot/providers.mjs +240 -0
- package/src/session-runtime/boot/session.mjs +125 -0
- package/src/session-runtime/boot/shared.mjs +33 -0
- package/src/session-runtime/boot/tools.mjs +250 -0
- package/src/session-runtime/builtin-features.mjs +1 -1
- package/src/session-runtime/config-helpers.mjs +26 -44
- package/src/session-runtime/config-lifecycle/config-writers.mjs +152 -0
- package/src/session-runtime/config-lifecycle/output-style-cache.mjs +42 -0
- package/src/session-runtime/config-lifecycle.mjs +26 -184
- package/src/session-runtime/context-inspection.mjs +390 -145
- package/src/session-runtime/context-status-cache.mjs +126 -0
- package/src/session-runtime/context-status-inspection.mjs +61 -0
- package/src/session-runtime/context-status-shape.mjs +271 -0
- package/src/session-runtime/context-status.mjs +40 -370
- package/src/session-runtime/cwd-plugins/core-memory-context.mjs +60 -0
- package/src/session-runtime/cwd-plugins/cwd-apply.mjs +83 -0
- package/src/session-runtime/cwd-plugins/plugin-status.mjs +124 -0
- package/src/session-runtime/cwd-plugins.mjs +16 -252
- package/src/session-runtime/fs-utils.mjs +11 -1
- package/src/session-runtime/goal-control.mjs +154 -0
- package/src/session-runtime/goal-deadlines.mjs +4 -4
- package/src/session-runtime/goal-mutations.mjs +257 -0
- package/src/session-runtime/goal-runtime.mjs +56 -794
- package/src/session-runtime/goal-state.mjs +18 -15
- package/src/session-runtime/goal-store.mjs +118 -0
- package/src/session-runtime/goal-tasks.mjs +3 -1
- package/src/session-runtime/goal-text.mjs +30 -19
- package/src/session-runtime/goal-title.mjs +52 -0
- package/src/session-runtime/goal-tool-exec.mjs +156 -0
- package/src/session-runtime/goal-turns.mjs +166 -0
- package/src/session-runtime/internal-tool-executor/bridge-tools.mjs +63 -0
- package/src/session-runtime/internal-tool-executor/feature-tools.mjs +42 -0
- package/src/session-runtime/internal-tool-executor/knowledge-tools.mjs +59 -0
- package/src/session-runtime/internal-tool-executor/workspace-tools.mjs +63 -0
- package/src/session-runtime/internal-tool-executor.mjs +40 -189
- package/src/session-runtime/lifecycle/inheritance.mjs +192 -0
- package/src/session-runtime/lifecycle/memory-ingest.mjs +42 -0
- package/src/session-runtime/lifecycle/session-catalog.mjs +98 -0
- package/src/session-runtime/lifecycle/session-switch/context-switch.mjs +70 -0
- package/src/session-runtime/lifecycle/session-switch/resume.mjs +158 -0
- package/src/session-runtime/lifecycle/session-switch/session-delete.mjs +93 -0
- package/src/session-runtime/lifecycle/session-switch.mjs +45 -0
- package/src/session-runtime/lifecycle/shared.mjs +32 -0
- package/src/session-runtime/lifecycle/teardown/runtime-stops.mjs +94 -0
- package/src/session-runtime/lifecycle/teardown/session-close.mjs +87 -0
- package/src/session-runtime/lifecycle/teardown.mjs +164 -0
- package/src/session-runtime/lifecycle-api.mjs +36 -850
- package/src/session-runtime/mcp-glue/connect.mjs +159 -0
- package/src/session-runtime/mcp-glue/server-catalog.mjs +102 -0
- package/src/session-runtime/mcp-glue/server-input.mjs +79 -0
- package/src/session-runtime/mcp-glue.mjs +21 -322
- package/src/session-runtime/model-route/route-persist.mjs +49 -0
- package/src/session-runtime/model-route/route-tuning.mjs +60 -0
- package/src/session-runtime/model-route/set-route.mjs +156 -0
- package/src/session-runtime/model-route/web-search-route.mjs +103 -0
- package/src/session-runtime/model-route-api.mjs +21 -304
- package/src/session-runtime/native-web-search/routes.mjs +74 -0
- package/src/session-runtime/native-web-search/tool-shape.mjs +115 -0
- package/src/session-runtime/native-web-search.mjs +83 -237
- package/src/session-runtime/orchestration.mjs +10 -5
- package/src/session-runtime/plugin-mcp.mjs +7 -58
- package/src/session-runtime/prewarm/channel-start.mjs +95 -0
- package/src/session-runtime/prewarm/code-graph-prewarm.mjs +94 -0
- package/src/session-runtime/prewarm/tool-runtime-warmup.mjs +79 -0
- package/src/session-runtime/prewarm.mjs +13 -243
- package/src/session-runtime/provider-auth/accounts.mjs +79 -0
- package/src/session-runtime/provider-auth/login.mjs +85 -0
- package/src/session-runtime/provider-auth/refresh.mjs +57 -0
- package/src/session-runtime/provider-auth/setup.mjs +51 -0
- package/src/session-runtime/provider-auth-api.mjs +18 -251
- package/src/session-runtime/provider-models/catalog-load.mjs +90 -0
- package/src/session-runtime/provider-models/model-meta.mjs +77 -0
- package/src/session-runtime/provider-models/row-hydration.mjs +46 -0
- package/src/session-runtime/provider-models/web-search-catalog.mjs +111 -0
- package/src/session-runtime/provider-models.mjs +71 -286
- package/src/session-runtime/provider-request-snapshot.mjs +1 -1
- package/src/session-runtime/provider-usage.mjs +3 -3
- package/src/session-runtime/quick-model-rows/model-meta.mjs +32 -0
- package/src/session-runtime/quick-model-rows/provider-rows.mjs +77 -0
- package/src/session-runtime/quick-model-rows/web-search-rows.mjs +144 -0
- package/src/session-runtime/quick-model-rows.mjs +27 -221
- package/src/session-runtime/resource-api.mjs +28 -522
- package/src/session-runtime/resource-extension-sync.mjs +89 -0
- package/src/session-runtime/resource-mcp-api.mjs +199 -0
- package/src/session-runtime/resource-plugins-api.mjs +85 -0
- package/src/session-runtime/resource-recall-api.mjs +92 -0
- package/src/session-runtime/resource-scope-decorate.mjs +58 -0
- package/src/session-runtime/resource-skills-api.mjs +50 -0
- package/src/session-runtime/route-resolution.mjs +71 -0
- package/src/session-runtime/route-state.mjs +86 -0
- package/src/session-runtime/runtime-bootstrap.mjs +3 -3
- package/src/session-runtime/runtime-core.mjs +37 -1375
- package/src/session-runtime/self-update.mjs +2 -3
- package/src/session-runtime/session-create/materialize.mjs +77 -0
- package/src/session-runtime/session-create/route-prep.mjs +49 -0
- package/src/session-runtime/session-create/session-options.mjs +73 -0
- package/src/session-runtime/session-create/session-start-hook.mjs +39 -0
- package/src/session-runtime/session-create.mjs +69 -0
- package/src/session-runtime/session-hooks.mjs +3 -4
- package/src/session-runtime/session-lifecycle.mjs +43 -417
- package/src/session-runtime/session-text.mjs +7 -37
- package/src/session-runtime/session-transcript.mjs +2 -4
- package/src/session-runtime/session-turn-api.mjs +37 -757
- package/src/session-runtime/settings-api.mjs +29 -528
- package/src/session-runtime/settings-builtin-tools-api.mjs +191 -0
- package/src/session-runtime/settings-compaction-api.mjs +161 -0
- package/src/session-runtime/settings-profile-api.mjs +100 -0
- package/src/session-runtime/settings-system-api.mjs +82 -0
- package/src/session-runtime/setup-tool/executor.mjs +354 -315
- package/src/session-runtime/setup-tool/extended-actions.mjs +42 -16
- package/src/session-runtime/setup-tool/settings-contract.mjs +99 -39
- package/src/session-runtime/setup-tool/tool-defs.mjs +22 -4
- package/src/session-runtime/setup-tool/ui-requests.mjs +25 -7
- package/src/session-runtime/skill-tool-loading.mjs +15 -8
- package/src/session-runtime/skills-api.mjs +7 -8
- package/src/session-runtime/tool-catalog-data.mjs +1 -2
- package/src/session-runtime/tool-catalog-schema.mjs +1 -1
- package/src/session-runtime/tool-catalog.mjs +21 -19
- package/src/session-runtime/tool-defs.mjs +2 -2
- package/src/session-runtime/tool-policy-refresh.mjs +33 -21
- package/src/session-runtime/tool-profile.mjs +0 -1
- package/src/session-runtime/tool-surface.mjs +6 -4
- package/src/session-runtime/turn/agent-ops.mjs +98 -0
- package/src/session-runtime/turn/session-ops.mjs +132 -0
- package/src/session-runtime/turn/share-ops.mjs +73 -0
- package/src/session-runtime/turn/turn-run/ask-callbacks.mjs +90 -0
- package/src/session-runtime/turn/turn-run/snapshot-tracker.mjs +51 -0
- package/src/session-runtime/turn/turn-run/transcript.mjs +47 -0
- package/src/session-runtime/turn/turn-run/turn-open.mjs +60 -0
- package/src/session-runtime/turn/turn-run/turn-prepare.mjs +142 -0
- package/src/session-runtime/turn/turn-run/turn-settle.mjs +105 -0
- package/src/session-runtime/turn/turn-run/turn-timing.mjs +52 -0
- package/src/session-runtime/turn/turn-run.mjs +121 -0
- package/src/session-runtime/usage-stats-api.mjs +48 -33
- package/src/session-runtime/warmup/catalog-warmup.mjs +34 -0
- package/src/session-runtime/warmup/provider-warmups.mjs +105 -0
- package/src/session-runtime/warmup/statusline-usage-warmup.mjs +82 -0
- package/src/session-runtime/warmup/timer-arm.mjs +22 -0
- package/src/session-runtime/warmup-schedulers.mjs +11 -232
- package/src/session-runtime/workflow/agents.mjs +91 -0
- package/src/session-runtime/workflow/context.mjs +89 -0
- package/src/session-runtime/workflow/packs.mjs +68 -0
- package/src/session-runtime/workflow-agents-api/agent-editor.mjs +152 -0
- package/src/session-runtime/workflow-agents-api/agent-route.mjs +98 -0
- package/src/session-runtime/workflow-agents-api/onboarding.mjs +113 -0
- package/src/session-runtime/workflow-agents-api/shared.mjs +23 -0
- package/src/session-runtime/workflow-agents-api/style-and-mode.mjs +61 -0
- package/src/session-runtime/workflow-agents-api/workflow-packs.mjs +117 -0
- package/src/session-runtime/workflow-agents-api.mjs +16 -515
- package/src/session-runtime/workflow-ids.mjs +57 -0
- package/src/session-runtime/workflow.mjs +17 -289
- package/src/standalone/agent-task-status.mjs +8 -2
- package/src/standalone/agent-tool/close-flow.mjs +163 -0
- package/src/standalone/agent-tool/execute.mjs +223 -0
- package/src/standalone/agent-tool/helpers.mjs +3 -17
- package/src/standalone/agent-tool/job-views/agent-list.mjs +71 -0
- package/src/standalone/agent-tool/job-views/job-lookup.mjs +84 -0
- package/src/standalone/agent-tool/job-views/job-render.mjs +98 -0
- package/src/standalone/agent-tool/job-views/session-progress.mjs +81 -0
- package/src/standalone/agent-tool/job-views/spawn-meta.mjs +62 -0
- package/src/standalone/agent-tool/job-views.mjs +24 -373
- package/src/standalone/agent-tool/lead-worker-index/index-file.mjs +45 -0
- package/src/standalone/agent-tool/lead-worker-index/lead-rows.mjs +39 -0
- package/src/standalone/agent-tool/lead-worker-index/reap-timers.mjs +31 -0
- package/src/standalone/agent-tool/lead-worker-index/row-settlement.mjs +59 -0
- package/src/standalone/agent-tool/lead-worker-index.mjs +28 -163
- package/src/standalone/agent-tool/notify.mjs +6 -6
- package/src/standalone/agent-tool/provider-init.mjs +3 -4
- package/src/standalone/agent-tool/render.mjs +26 -22
- package/src/standalone/agent-tool/send-flow.mjs +186 -0
- package/src/standalone/agent-tool/spawn-flow/deferred-spawn.mjs +97 -0
- package/src/standalone/agent-tool/spawn-flow/job-start.mjs +83 -0
- package/src/standalone/agent-tool/spawn-flow/spawn-prep.mjs +179 -0
- package/src/standalone/agent-tool/spawn-flow/spawn-run.mjs +222 -0
- package/src/standalone/agent-tool/spawn-flow.mjs +30 -557
- package/src/standalone/agent-tool/tag-maps.mjs +29 -0
- package/src/standalone/agent-tool/tag-registry/tag-lookup.mjs +106 -0
- package/src/standalone/agent-tool/tag-registry/tag-refresh.mjs +34 -0
- package/src/standalone/agent-tool/tag-registry.mjs +63 -524
- package/src/standalone/agent-tool/terminal-reaper/reap-timers.mjs +142 -0
- package/src/standalone/agent-tool/terminal-reaper/row-helpers.mjs +25 -0
- package/src/standalone/agent-tool/terminal-reaper/scan-admission.mjs +89 -0
- package/src/standalone/agent-tool/terminal-reaper/stale-rows.mjs +52 -0
- package/src/standalone/agent-tool/terminal-reaper/tombstones.mjs +113 -0
- package/src/standalone/agent-tool/terminal-reaper.mjs +46 -0
- package/src/standalone/agent-tool/terminal-trace.mjs +40 -0
- package/src/standalone/agent-tool/tool-def.mjs +1 -2
- package/src/standalone/agent-tool/turn-review.mjs +27 -0
- package/src/standalone/agent-tool/worker-index/mutation-batch.mjs +41 -0
- package/src/standalone/agent-tool/worker-index/row-liveness.mjs +65 -0
- package/src/standalone/agent-tool/worker-index/row-shape.mjs +109 -0
- package/src/standalone/agent-tool/worker-index/row-store.mjs +100 -0
- package/src/standalone/agent-tool/worker-index.mjs +66 -345
- package/src/standalone/agent-tool/worker-rows.mjs +34 -9
- package/src/standalone/agent-tool.mjs +61 -650
- package/src/standalone/agent-watchdog-registry.mjs +36 -8
- package/src/standalone/channel-admin.mjs +3 -5
- package/src/standalone/channel-client/daemon-request.mjs +136 -0
- package/src/standalone/channel-client/notify-stream.mjs +130 -0
- package/src/standalone/channel-client/reconnect.mjs +113 -0
- package/src/standalone/channel-client/registration.mjs +87 -0
- package/src/standalone/channel-client.mjs +58 -460
- package/src/standalone/channel-transport/call-dispatch.mjs +209 -0
- package/src/standalone/channel-transport/client-registry/client-grace.mjs +69 -0
- package/src/standalone/channel-transport/client-registry/registration-replays.mjs +96 -0
- package/src/standalone/channel-transport/client-registry/sse-attach.mjs +44 -0
- package/src/standalone/channel-transport/client-registry.mjs +228 -0
- package/src/standalone/channel-transport/http-routes.mjs +171 -0
- package/src/standalone/channel-transport/remote-binding.mjs +168 -0
- package/src/standalone/channel-transport/remote-notify.mjs +138 -0
- package/src/standalone/channel-transport.mjs +111 -982
- package/src/standalone/channel-worker/client-heartbeat.mjs +103 -0
- package/src/standalone/channel-worker/daemon-attach.mjs +157 -0
- package/src/standalone/channel-worker/daemon-spawn.mjs +93 -0
- package/src/standalone/channel-worker.mjs +55 -342
- package/src/standalone/daemon-boot-coordinator.mjs +6 -2
- package/src/standalone/daemon-crash-capture/paths.mjs +16 -0
- package/src/standalone/daemon-crash-capture/retention.mjs +217 -0
- package/src/standalone/daemon-crash-capture/spawn-capture.mjs +370 -0
- package/src/standalone/daemon-crash-capture.mjs +14 -568
- package/src/standalone/daemon.mjs +0 -3
- package/src/standalone/desktop-service-registry.mjs +4 -7
- package/src/standalone/fair-call-scheduler/owner-groups.mjs +90 -0
- package/src/standalone/fair-call-scheduler/queue-item.mjs +21 -0
- package/src/standalone/fair-call-scheduler.mjs +94 -167
- package/src/standalone/hook-bus/command-handler.mjs +1 -1
- package/src/standalone/hook-bus/config-loader.mjs +130 -0
- package/src/standalone/hook-bus/config.mjs +8 -9
- package/src/standalone/hook-bus/event-log.mjs +30 -0
- package/src/standalone/hook-bus/event-runner.mjs +175 -0
- package/src/standalone/hook-bus/rule-store.mjs +149 -0
- package/src/standalone/hook-bus/tool-gate.mjs +72 -0
- package/src/standalone/hook-bus.mjs +65 -511
- package/src/standalone/memory-runtime-proxy/calls.mjs +121 -0
- package/src/standalone/memory-runtime-proxy/client-registry.mjs +93 -0
- package/src/standalone/memory-runtime-proxy/daemon-spawn.mjs +158 -0
- package/src/standalone/memory-runtime-proxy/discovery.mjs +98 -0
- package/src/standalone/memory-runtime-proxy/owner-claim.mjs +67 -0
- package/src/standalone/memory-runtime-proxy/rpc.mjs +122 -0
- package/src/standalone/memory-runtime-proxy/start.mjs +51 -0
- package/src/standalone/memory-runtime-proxy/state.mjs +21 -0
- package/src/standalone/memory-runtime-proxy/tool-wire.mjs +32 -0
- package/src/standalone/memory-runtime-proxy.mjs +52 -712
- package/src/standalone/opencode-go-login.mjs +1 -1
- package/src/standalone/plugin-admin.mjs +4 -9
- package/src/standalone/provider-admin.mjs +186 -161
- package/src/standalone/seeds.mjs +132 -5
- package/src/standalone/session-client/frame-stream.mjs +125 -0
- package/src/standalone/session-client/stream-reconnect.mjs +119 -0
- package/src/standalone/session-client.mjs +83 -259
- package/src/standalone/session-frame-stream.mjs +3 -6
- package/src/standalone/session-protocol.mjs +1 -0
- package/src/standalone/session-proxy/project-routes.mjs +25 -0
- package/src/standalone/session-proxy/projection.mjs +112 -0
- package/src/standalone/session-proxy/proxy-view.mjs +50 -0
- package/src/standalone/session-proxy/remote-actions.mjs +121 -0
- package/src/standalone/session-proxy/resync.mjs +67 -0
- package/src/standalone/session-proxy/transitions.mjs +99 -0
- package/src/standalone/session-proxy/transport-calls.mjs +121 -0
- package/src/standalone/session-proxy.mjs +49 -527
- package/src/standalone/session-runtime-agent-control-client.mjs +2 -4
- package/src/standalone/session-runtime-host.mjs +6 -110
- package/src/standalone/session-runtime-inline-host/agent-dispatch.mjs +66 -0
- package/src/standalone/session-runtime-inline-host/boot-loaders.mjs +96 -0
- package/src/standalone/session-runtime-inline-host/runtime-records.mjs +66 -0
- package/src/standalone/session-runtime-inline-host.mjs +27 -182
- package/src/standalone/session-runtime-worker.mjs +2 -6
- package/src/standalone/session-runtime-workload.mjs +98 -0
- package/src/standalone/session-service/agent-tree/agent-cancel.mjs +79 -0
- package/src/standalone/session-service/agent-tree/agent-registry.mjs +73 -0
- package/src/standalone/session-service/agent-tree/agent-rehydrate.mjs +163 -0
- package/src/standalone/session-service/agent-tree/agent-turns.mjs +122 -0
- package/src/standalone/session-service/agent-tree.mjs +91 -388
- package/src/standalone/session-service/entries/external-binding.mjs +60 -0
- package/src/standalone/session-service/entries/lifecycle.mjs +140 -0
- package/src/standalone/session-service/entries/session-loads.mjs +109 -0
- package/src/standalone/session-service/entries.mjs +95 -0
- package/src/standalone/session-service/projection/address-index.mjs +54 -0
- package/src/standalone/session-service/projection/external-views.mjs +91 -0
- package/src/standalone/session-service/projection/frames.mjs +79 -0
- package/src/standalone/session-service/projection/revisions.mjs +100 -0
- package/src/standalone/session-service/projection.mjs +36 -274
- package/src/standalone/session-service/retention.mjs +158 -0
- package/src/standalone/session-service/session-calls/session-action.mjs +97 -0
- package/src/standalone/session-service/session-calls/session-turns.mjs +165 -0
- package/src/standalone/session-service/session-calls/session-views.mjs +192 -0
- package/src/standalone/session-service/session-calls.mjs +59 -0
- package/src/standalone/session-service/viewers.mjs +111 -0
- package/src/standalone/session-service.mjs +135 -992
- package/src/standalone/session-state-projection.mjs +5 -1
- package/src/standalone/session-transport/call-lanes.mjs +113 -0
- package/src/standalone/session-transport/call-route.mjs +104 -0
- package/src/standalone/session-transport/client-registry/client-grace.mjs +81 -0
- package/src/standalone/session-transport/client-registry/registration-replays.mjs +69 -0
- package/src/standalone/session-transport/client-registry.mjs +129 -0
- package/src/standalone/session-transport/routes.mjs +185 -0
- package/src/standalone/session-transport.mjs +104 -574
- package/src/standalone/sse-frames.mjs +27 -0
- package/src/standalone/usage-dashboard-model.mjs +28 -22
- package/src/standalone/usage-dashboard.mjs +6 -4
- package/src/standalone/usage-stats-hours.mjs +2 -6
- package/src/standalone/usage-stats-model.mjs +22 -29
- package/src/standalone/usage-stats-period.mjs +83 -22
- package/src/tui/App.jsx +0 -6
- package/src/tui/app/app-format.mjs +7 -1
- package/src/tui/app/app-view.jsx +253 -226
- package/src/tui/app/clipboard.mjs +1 -1
- package/src/tui/app/core-memory-picker.mjs +10 -14
- package/src/tui/app/create-app-pickers.mjs +2 -2
- package/src/tui/app/doctor.mjs +158 -135
- package/src/tui/app/extension-pickers/mcp-servers-picker.mjs +115 -0
- package/src/tui/app/extension-pickers/plugins-pickers.mjs +236 -0
- package/src/tui/app/extension-pickers/scope-note.mjs +30 -0
- package/src/tui/app/extension-pickers/skills-pickers.mjs +201 -0
- package/src/tui/app/extension-pickers.mjs +29 -532
- package/src/tui/app/input-parsers.mjs +6 -5
- package/src/tui/app/maintenance-pickers/auto-clear-picker.mjs +167 -0
- package/src/tui/app/maintenance-pickers/profile-picker.mjs +147 -0
- package/src/tui/app/maintenance-pickers/update-picker.mjs +175 -0
- package/src/tui/app/maintenance-pickers.mjs +18 -449
- package/src/tui/app/model-options.mjs +5 -39
- package/src/tui/app/model-picker/catalog-load.mjs +101 -0
- package/src/tui/app/model-picker/model-footer.mjs +79 -0
- package/src/tui/app/model-picker/provider-models-list.mjs +115 -0
- package/src/tui/app/model-picker/route-selection.mjs +227 -0
- package/src/tui/app/model-picker.mjs +57 -460
- package/src/tui/app/onboarding/models-step.mjs +106 -0
- package/src/tui/app/onboarding/persist.mjs +49 -0
- package/src/tui/app/onboarding/role-model-picker.mjs +141 -0
- package/src/tui/app/onboarding/step-data.mjs +65 -0
- package/src/tui/app/onboarding-steps.mjs +45 -346
- package/src/tui/app/panel-surface.mjs +2 -1
- package/src/tui/app/project-picker/create-flow.mjs +76 -0
- package/src/tui/app/project-picker/picker-state.mjs +78 -0
- package/src/tui/app/project-picker/project-service.mjs +61 -0
- package/src/tui/app/project-picker.mjs +29 -221
- package/src/tui/app/prompt-handlers/history-navigation.mjs +32 -0
- package/src/tui/app/prompt-handlers/paste-pipeline.mjs +72 -0
- package/src/tui/app/prompt-handlers/use-prompt-history-nav.mjs +31 -0
- package/src/tui/app/prompt-handlers/use-prompt-interrupt.mjs +102 -0
- package/src/tui/app/prompt-handlers/use-prompt-paste.mjs +48 -0
- package/src/tui/app/prompt-submit/chat-submit.mjs +66 -0
- package/src/tui/app/prompt-submit/panel-write.mjs +54 -0
- package/src/tui/app/prompt-submit/provider-prompts.mjs +103 -0
- package/src/tui/app/prompt-submit/settings-prompts.mjs +337 -0
- package/src/tui/app/prompt-submit.mjs +21 -554
- package/src/tui/app/provider-setup/api-key-actions.mjs +164 -0
- package/src/tui/app/provider-setup/oauth-actions.mjs +230 -0
- package/src/tui/app/provider-setup/provider-items.mjs +80 -0
- package/src/tui/app/provider-setup-picker.mjs +81 -499
- package/src/tui/app/resume-picker.mjs +2 -5
- package/src/tui/app/route-pickers/agents-picker.mjs +155 -0
- package/src/tui/app/route-pickers/output-style-picker.mjs +123 -0
- package/src/tui/app/route-pickers/workflow-picker.mjs +84 -0
- package/src/tui/app/route-pickers.mjs +13 -322
- package/src/tui/app/settings-picker/settings-navigation.mjs +69 -0
- package/src/tui/app/settings-picker/settings-rows.mjs +200 -0
- package/src/tui/app/settings-picker/settings-toggles.mjs +190 -0
- package/src/tui/app/settings-picker.mjs +42 -431
- package/src/tui/app/shell-layout/panel-transition.mjs +140 -0
- package/src/tui/app/shell-layout/row-budgets.mjs +268 -0
- package/src/tui/app/shell-layout/surfaces.mjs +93 -0
- package/src/tui/app/shell-layout/viewport.mjs +151 -0
- package/src/tui/app/shell-layout.mjs +34 -568
- package/src/tui/app/slash-dispatch/panel-commands.mjs +84 -0
- package/src/tui/app/slash-dispatch/route-commands.mjs +191 -0
- package/src/tui/app/slash-dispatch/session-commands.mjs +128 -0
- package/src/tui/app/slash-dispatch/slash-panel.mjs +43 -0
- package/src/tui/app/slash-dispatch.mjs +19 -449
- package/src/tui/app/theme-effort-pickers.mjs +4 -11
- package/src/tui/app/transcript-anchor-lock.mjs +120 -0
- package/src/tui/app/transcript-anchor-sync.mjs +173 -0
- package/src/tui/app/transcript-measure.mjs +245 -0
- package/src/tui/app/transcript-row-estimate.mjs +10 -34
- package/src/tui/app/transcript-scroll-anchor.mjs +42 -0
- package/src/tui/app/transcript-window.mjs +102 -122
- package/src/tui/app/usage-context-panels/context-model.mjs +282 -0
- package/src/tui/app/usage-context-panels/usage-panel.mjs +48 -0
- package/src/tui/app/usage-context-panels.mjs +24 -282
- package/src/tui/app/use-copy-selection.mjs +5 -4
- package/src/tui/app/use-global-key-input.mjs +2 -3
- package/src/tui/app/use-mouse-input.mjs +7 -11
- package/src/tui/app/use-pasted-buffers.mjs +2 -2
- package/src/tui/app/use-prompt-draft-flow.mjs +1 -1
- package/src/tui/app/use-prompt-handlers.mjs +32 -257
- package/src/tui/app/use-prompt-hint.mjs +1 -1
- package/src/tui/app/use-prompt-queue-history.mjs +1 -1
- package/src/tui/app/use-selection-focus.mjs +132 -0
- package/src/tui/app/use-selection-geometry.mjs +108 -0
- package/src/tui/app/use-selection-paint.mjs +192 -0
- package/src/tui/app/use-selection-stitch.mjs +128 -0
- package/src/tui/app/use-terminal-chrome.mjs +1 -1
- package/src/tui/app/use-transcript-activity.mjs +4 -3
- package/src/tui/app/use-transcript-follow.mjs +91 -0
- package/src/tui/app/use-transcript-scroll.mjs +220 -737
- package/src/tui/app/use-transcript-window/geometry.mjs +139 -0
- package/src/tui/app/use-transcript-window/instance-state.mjs +80 -0
- package/src/tui/app/use-transcript-window/selection-shift.mjs +57 -0
- package/src/tui/app/use-transcript-window/visible-items.mjs +46 -0
- package/src/tui/app/use-transcript-window.mjs +101 -827
- package/src/tui/app/use-welcome-prompt-hint.mjs +1 -1
- package/src/tui/components/AnsiText.jsx +2 -4
- package/src/tui/components/ContextInspector.jsx +87 -39
- package/src/tui/components/ContextPanel.jsx +18 -34
- package/src/tui/components/Markdown.jsx +4 -1
- package/src/tui/components/Message.jsx +9 -2
- package/src/tui/components/Picker.jsx +48 -43
- package/src/tui/components/QueuedCommands.jsx +6 -5
- package/src/tui/components/SlashCommandPalette.jsx +1 -18
- package/src/tui/components/Spinner.jsx +25 -21
- package/src/tui/components/StatusLine.jsx +7 -30
- package/src/tui/components/ToolExecution.jsx +22 -29
- package/src/tui/components/TranscriptItem.jsx +5 -13
- package/src/tui/components/TurnDone.jsx +27 -35
- package/src/tui/components/UsagePanel.jsx +55 -66
- package/src/tui/components/panel-cell-text.mjs +19 -0
- package/src/tui/components/prompt-input/edit-helpers.mjs +8 -4
- package/src/tui/components/tool-execution/text-format.mjs +2 -3
- package/src/tui/components/tool-output-format.mjs +3 -3
- package/src/tui/dist/index.mjs +8446 -7222
- package/src/tui/hooks/useSharedTick.mjs +3 -9
- package/src/tui/input-editing.mjs +3 -1
- package/src/tui/markdown/ansi-line-wrap.mjs +37 -0
- package/src/tui/markdown/format-token.mjs +6 -41
- package/src/tui/markdown/measure-rendered-rows.mjs +7 -2
- package/src/tui/markdown/stream-fence.mjs +1 -2
- package/src/tui/markdown/streaming-markdown.mjs +1 -7
- package/src/tui/markdown/table-layout.mjs +3 -40
- package/src/tui/paste-attachments.mjs +1 -2
- package/src/tui/prompt-history-store.mjs +1 -1
- package/src/tui/session/active-tool-summary.mjs +71 -0
- package/src/tui/session/agent-envelope.mjs +42 -13
- package/src/tui/session/agent-job-feed/agent-job-card.mjs +30 -0
- package/src/tui/session/agent-job-feed/agent-status-refresh.mjs +37 -0
- package/src/tui/session/agent-job-feed/execution-dedup.mjs +80 -0
- package/src/tui/session/agent-job-feed/execution-delivery.mjs +103 -0
- package/src/tui/session/agent-job-feed/model-notification.mjs +79 -0
- package/src/tui/session/agent-job-feed/notification-chain.mjs +64 -0
- package/src/tui/session/agent-job-feed/notification-router.mjs +66 -0
- package/src/tui/session/agent-job-feed/pending-resume.mjs +131 -0
- package/src/tui/session/agent-job-feed.mjs +57 -513
- package/src/tui/session/agent-response-tail.mjs +1 -1
- package/src/tui/session/context-state.mjs +5 -2
- package/src/tui/session/cross-surface-share.mjs +411 -0
- package/src/tui/session/draft-store.mjs +85 -0
- package/src/tui/session/goal-continuation/continuation-queue.mjs +90 -0
- package/src/tui/session/goal-continuation/deadline-delivery.mjs +76 -0
- package/src/tui/session/goal-continuation/goal-visibility.mjs +38 -0
- package/src/tui/session/goal-continuation.mjs +34 -178
- package/src/tui/session/initial-state.mjs +50 -0
- package/src/tui/session/live-share/delta.mjs +153 -0
- package/src/tui/session/live-share/mirror.mjs +106 -0
- package/src/tui/session/live-share/owner.mjs +235 -0
- package/src/tui/session/live-share/retry.mjs +39 -0
- package/src/tui/session/live-share/viewer/submit-acks.mjs +65 -0
- package/src/tui/session/live-share/viewer/sync-waiters.mjs +53 -0
- package/src/tui/session/live-share/viewer.mjs +190 -0
- package/src/tui/session/live-share/wire.mjs +41 -0
- package/src/tui/session/live-share.mjs +34 -775
- package/src/tui/session/notice-surface.mjs +77 -0
- package/src/tui/session/notification-plan.mjs +7 -9
- package/src/tui/session/oauth-flows.mjs +4 -4
- package/src/tui/session/prompt-history.mjs +1 -1
- package/src/tui/session/queue-helpers.mjs +3 -1
- package/src/tui/session/render-timing.mjs +0 -1
- package/src/tui/session/session-api/commands.mjs +163 -0
- package/src/tui/session/session-api/controls.mjs +119 -0
- package/src/tui/session/session-api/extensions.mjs +154 -0
- package/src/tui/session/session-api/intake/abort.mjs +150 -0
- package/src/tui/session/session-api/intake/rewind.mjs +47 -0
- package/src/tui/session/session-api/intake/submission.mjs +111 -0
- package/src/tui/session/session-api/intake.mjs +54 -0
- package/src/tui/session/session-api/integrations.mjs +171 -0
- package/src/tui/session/session-api/lifecycle/dispose.mjs +50 -0
- package/src/tui/session/session-api/lifecycle/inheritance.mjs +73 -0
- package/src/tui/session/session-api/lifecycle/resume.mjs +78 -0
- package/src/tui/session/session-api/lifecycle/session-reset.mjs +145 -0
- package/src/tui/session/session-api/lifecycle.mjs +51 -0
- package/src/tui/session/session-api/media.mjs +125 -0
- package/src/tui/session/session-api/routes.mjs +205 -0
- package/src/tui/session/session-api/settings.mjs +163 -0
- package/src/tui/session/session-api/shared.mjs +34 -0
- package/src/tui/session/session-api-ext.mjs +18 -867
- package/src/tui/session/session-api.mjs +14 -1026
- package/src/tui/session/session-flow/auto-clear.mjs +185 -0
- package/src/tui/session/session-flow/drain.mjs +269 -0
- package/src/tui/session/session-flow/failed-turn-rewind.mjs +27 -0
- package/src/tui/session/session-flow/queue.mjs +213 -0
- package/src/tui/session/session-flow/session-reset.mjs +135 -0
- package/src/tui/session/session-flow/steering.mjs +190 -0
- package/src/tui/session/session-flow.mjs +43 -846
- package/src/tui/session/tool-approval.mjs +1 -3
- package/src/tui/session/tool-card-results/aggregate-result.mjs +98 -0
- package/src/tui/session/tool-card-results/grouped-result.mjs +94 -0
- package/src/tui/session/tool-card-results/item-patch.mjs +28 -0
- package/src/tui/session/tool-card-results.mjs +45 -234
- package/src/tui/session/tool-result-status.mjs +14 -22
- package/src/tui/session/tool-result-text.mjs +1 -3
- package/src/tui/session/transcript-intake.mjs +151 -0
- package/src/tui/session/transcript-spill/spill-dir.mjs +102 -0
- package/src/tui/session/transcript-spill/spill-writer.mjs +160 -0
- package/src/tui/session/transcript-spill.mjs +42 -261
- package/src/tui/session/transcript-store.mjs +193 -0
- package/src/tui/session/tui-steering-persist.mjs +2 -2
- package/src/tui/session/turn-aggregate-cards/early-complete.mjs +62 -0
- package/src/tui/session/turn-aggregate-cards/header-sync.mjs +71 -0
- package/src/tui/session/turn-aggregate-cards.mjs +19 -122
- package/src/tui/session/turn-deferred-cards.mjs +2 -21
- package/src/tui/session/turn-stream.mjs +464 -0
- package/src/tui/session/turn-tool-cards.mjs +338 -0
- package/src/tui/session/turn.mjs +531 -1252
- package/src/tui/session-local.mjs +63 -910
- package/src/tui/spinner-meta.mjs +2 -2
- package/src/tui/theme.mjs +3 -3
- package/src/tui/transcript-tool-failures.mjs +4 -7
- package/src/ui/ansi.mjs +6 -28
- package/src/ui/context-inspection.mjs +22 -10
- package/src/ui/context-measurement.mjs +10 -7
- package/src/ui/markdown.mjs +15 -17
- package/src/ui/model-display.mjs +5 -6
- package/src/ui/statusline-format.mjs +5 -3
- package/src/ui/statusline.mjs +214 -223
- package/src/ui/streaming-markdown-heal.mjs +7 -3
- package/src/ui/tool-card.mjs +1 -1
- package/src/workflows/default/WORKFLOW.md +4 -0
- package/src/rules/routes/common.md +0 -4
- package/src/runtime/agent/orchestrator/providers/anthropic-turn-reminder.mjs +0 -96
- package/src/runtime/agent/orchestrator/session/batching-nudge.mjs +0 -461
- package/src/runtime/channels/lib/index-drop-trace.mjs +0 -89
- package/src/runtime/channels/lib/network-retry.mjs +0 -24
|
@@ -1,33 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { basename, dirname, extname, resolve } from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
BlendMode,
|
|
5
|
-
PDFDocument,
|
|
6
|
-
PDFArray,
|
|
7
|
-
PDFDict,
|
|
8
|
-
PDFHexString,
|
|
9
|
-
PDFName,
|
|
10
|
-
PDFNumber,
|
|
11
|
-
PDFRawStream,
|
|
12
|
-
PDFString,
|
|
13
|
-
decodePDFRawStream,
|
|
14
|
-
degrees,
|
|
15
|
-
} from 'pdf-lib';
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
16
2
|
import { inspectPdfBuffer } from '../../attachments/pdf-extract.mjs';
|
|
17
|
-
import { extractPdfOutline
|
|
18
|
-
import { SAVE_OPTIONS,
|
|
19
|
-
import { embedDocumentFont } from './pdf-fonts.mjs';
|
|
3
|
+
import { extractPdfOutline } from './pdf-analysis.mjs';
|
|
4
|
+
import { SAVE_OPTIONS, round2 } from './pdf-draw.mjs';
|
|
20
5
|
import { activeContentIssues } from './pdf-safety.mjs';
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
fieldWidgets,
|
|
27
|
-
fillFormValues,
|
|
28
|
-
lintPdfFormFields,
|
|
29
|
-
rectanglesOverlap,
|
|
30
|
-
} from './pdf-forms.mjs';
|
|
6
|
+
import { describeFormField, rectanglesOverlap } from './pdf-forms.mjs';
|
|
7
|
+
import { PDF_ENCRYPTED_HINT, loadPdf, pdfAttachments } from './pdf-edit-document.mjs';
|
|
8
|
+
import { MARK_OPERATIONS } from './pdf-marks.mjs';
|
|
9
|
+
import { CONTENT_OPERATIONS } from './pdf-batch-content.mjs';
|
|
10
|
+
import { STRUCTURE_OPERATIONS } from './pdf-batch-structure.mjs';
|
|
31
11
|
|
|
32
12
|
// The adapter is the session-facing surface: open, inspect, edit, validate.
|
|
33
13
|
// Writing a new document lives in pdf-writer.mjs and the form vocabulary in
|
|
@@ -35,85 +15,11 @@ import {
|
|
|
35
15
|
export { createPdf } from './pdf-writer.mjs';
|
|
36
16
|
export { lintPdfFormFields } from './pdf-forms.mjs';
|
|
37
17
|
|
|
38
|
-
const PDF_ENCRYPTED_HINT =
|
|
39
|
-
"PDF is encrypted: write an unencrypted copy first with action:'secure' security:'decrypt' path password output:<copy.pdf>, then open that copy";
|
|
40
18
|
const NO_TEXT_MARKER = '(no extractable text on this page)';
|
|
41
19
|
// How much page text one audit call reads: the bound on its work, not on the
|
|
42
20
|
// document. Past it the answer says how many pages it covered.
|
|
43
21
|
const PDF_AUDIT_MAX_CHARS = 4_000_000;
|
|
44
|
-
const
|
|
45
|
-
// pdf.js analysis takes at most this many pages per call.
|
|
46
|
-
const MEASURE_CHUNK = 100;
|
|
47
|
-
|
|
48
|
-
function isEncryptionError(error) {
|
|
49
|
-
return error?.constructor?.name === 'EncryptedPDFError' || /is encrypted/i.test(String(error?.message || ''));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// pdf-lib refuses encrypted input with a message that names its own option;
|
|
53
|
-
// the model needs the Mixdog route (secure → decrypt) instead. Reading page
|
|
54
|
-
// counts and sizes still works on an encrypted file, so inspection may opt in.
|
|
55
|
-
async function loadPdf(buffer, { allowEncrypted = false } = {}) {
|
|
56
|
-
try {
|
|
57
|
-
return await PDFDocument.load(buffer, { ignoreEncryption: false, updateMetadata: false });
|
|
58
|
-
} catch (error) {
|
|
59
|
-
if (!isEncryptionError(error)) throw error;
|
|
60
|
-
if (!allowEncrypted) throw new Error(PDF_ENCRYPTED_HINT);
|
|
61
|
-
return await PDFDocument.load(buffer, { ignoreEncryption: true, updateMetadata: false });
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function selectedPages(document, operation) {
|
|
66
|
-
const count = document.getPageCount();
|
|
67
|
-
const pages =
|
|
68
|
-
Array.isArray(operation.pages) && operation.pages.length
|
|
69
|
-
? operation.pages
|
|
70
|
-
: operation.page
|
|
71
|
-
? [operation.page]
|
|
72
|
-
: Array.from({ length: count }, (_, index) => index + 1);
|
|
73
|
-
return pages.map((page) => {
|
|
74
|
-
const index = Number(page) - 1;
|
|
75
|
-
if (!Number.isInteger(index) || index < 0 || index >= count) throw new Error(`PDF page out of range: ${page}`);
|
|
76
|
-
return { page: document.getPage(index), index };
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function attachmentEntries(document) {
|
|
81
|
-
try {
|
|
82
|
-
const names = document.catalog.lookup(PDFName.of('Names'), PDFDict);
|
|
83
|
-
const embedded = names?.lookup(PDFName.of('EmbeddedFiles'), PDFDict);
|
|
84
|
-
const entries = embedded?.lookup(PDFName.of('Names'), PDFArray);
|
|
85
|
-
if (!entries) return [];
|
|
86
|
-
const output = [];
|
|
87
|
-
for (let index = 0; index + 1 < entries.size(); index += 2) {
|
|
88
|
-
const nameObject = entries.lookup(index, PDFString, PDFHexString);
|
|
89
|
-
const spec = entries.lookup(index + 1, PDFDict);
|
|
90
|
-
const description = spec?.lookupMaybe?.(PDFName.of('Desc'), PDFString, PDFHexString);
|
|
91
|
-
output.push({
|
|
92
|
-
path: `/attachments[${output.length + 1}]`,
|
|
93
|
-
index: output.length + 1,
|
|
94
|
-
name: nameObject?.decodeText?.() || '',
|
|
95
|
-
description: description?.decodeText?.() || '',
|
|
96
|
-
spec,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return output;
|
|
100
|
-
} catch {
|
|
101
|
-
return [];
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function pdfAttachments(document) {
|
|
106
|
-
return attachmentEntries(document).map(({ spec, ...entry }) => entry);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function attachmentBytes(spec) {
|
|
110
|
-
const files = spec?.lookup(PDFName.of('EF'), PDFDict);
|
|
111
|
-
const stream = files?.lookup(PDFName.of('UF')) || files?.lookup(PDFName.of('F'));
|
|
112
|
-
if (!stream) return null;
|
|
113
|
-
if (stream instanceof PDFRawStream) return Buffer.from(decodePDFRawStream(stream).decode());
|
|
114
|
-
if (typeof stream.getContents === 'function') return Buffer.from(stream.getContents());
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
22
|
+
const BATCH_OPERATIONS = { ...CONTENT_OPERATIONS, ...STRUCTURE_OPERATIONS };
|
|
117
23
|
|
|
118
24
|
function pageGeometry(structure, index) {
|
|
119
25
|
const page = structure.getPage(index - 1);
|
|
@@ -179,8 +85,8 @@ export async function snapshotPdf(path, options = {}) {
|
|
|
179
85
|
}
|
|
180
86
|
const texts = new Map();
|
|
181
87
|
const regex = /--- Page (\d+) ---\n([\s\S]*?)(?=\n\n--- Page \d+ ---|$)/g;
|
|
182
|
-
|
|
183
|
-
|
|
88
|
+
const text = result.text || '';
|
|
89
|
+
for (let match = regex.exec(text); match; match = regex.exec(text)) texts.set(Number(match[1]), match[2]);
|
|
184
90
|
const pages = selected
|
|
185
91
|
.filter((index) => passwordRequired || texts.has(index))
|
|
186
92
|
.map((index) => ({
|
|
@@ -227,728 +133,31 @@ export async function snapshotPdf(path, options = {}) {
|
|
|
227
133
|
ocrRequired: likelyScannedPages.length > 0,
|
|
228
134
|
encrypted,
|
|
229
135
|
...(encrypted ? { passwordRequired, hint: PDF_ENCRYPTED_HINT } : {}),
|
|
230
|
-
...(options.paged
|
|
231
|
-
? {
|
|
232
|
-
pagination: {
|
|
233
|
-
unit: 'page',
|
|
234
|
-
offset,
|
|
235
|
-
limit,
|
|
236
|
-
returned: pages.length,
|
|
237
|
-
total: pageCount,
|
|
238
|
-
nextOffset: !options.pages?.length && offset + pages.length < pageCount ? offset + pages.length : null,
|
|
239
|
-
},
|
|
240
|
-
}
|
|
241
|
-
: {}),
|
|
136
|
+
...(options.paged ? { pagination: pagePagination(options, offset, limit, pages.length, pageCount) } : {}),
|
|
242
137
|
};
|
|
243
138
|
}
|
|
244
139
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (!entries.length) return 0;
|
|
249
|
-
const { context, catalog } = document;
|
|
250
|
-
const existing = catalog.lookupMaybe(PDFName.of('Outlines'), PDFDict);
|
|
251
|
-
const rootRef = existing ? catalog.get(PDFName.of('Outlines')) : context.nextRef();
|
|
252
|
-
const refs = entries.map(() => context.nextRef());
|
|
253
|
-
const previousLastRef = existing?.get(PDFName.of('Last'));
|
|
254
|
-
entries.forEach((entry, index) => {
|
|
255
|
-
const page = document.getPage(entry.pageIndex);
|
|
256
|
-
const item = context.obj({
|
|
257
|
-
Title: PDFHexString.fromText(entry.title),
|
|
258
|
-
Parent: rootRef,
|
|
259
|
-
Dest: [page.ref, PDFName.of('Fit')],
|
|
260
|
-
});
|
|
261
|
-
const previous = index > 0 ? refs[index - 1] : previousLastRef;
|
|
262
|
-
if (previous) item.set(PDFName.of('Prev'), previous);
|
|
263
|
-
if (index < entries.length - 1) item.set(PDFName.of('Next'), refs[index + 1]);
|
|
264
|
-
context.assign(refs[index], item);
|
|
265
|
-
});
|
|
266
|
-
if (existing) {
|
|
267
|
-
if (previousLastRef) context.lookup(previousLastRef, PDFDict)?.set(PDFName.of('Next'), refs[0]);
|
|
268
|
-
else existing.set(PDFName.of('First'), refs[0]);
|
|
269
|
-
existing.set(PDFName.of('Last'), refs.at(-1));
|
|
270
|
-
const count = existing.lookupMaybe(PDFName.of('Count'), PDFNumber)?.asNumber() ?? 0;
|
|
271
|
-
existing.set(PDFName.of('Count'), PDFNumber.of(Math.max(0, count) + entries.length));
|
|
272
|
-
} else {
|
|
273
|
-
context.assign(
|
|
274
|
-
rootRef,
|
|
275
|
-
context.obj({ Type: 'Outlines', First: refs[0], Last: refs.at(-1), Count: entries.length })
|
|
276
|
-
);
|
|
277
|
-
catalog.set(PDFName.of('Outlines'), rootRef);
|
|
278
|
-
}
|
|
279
|
-
return entries.length;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
async function writeSibling(path, target, bytes) {
|
|
283
|
-
const output = resolve(dirname(path), String(target));
|
|
284
|
-
if (output.toLowerCase() === resolve(path).toLowerCase())
|
|
285
|
-
throw new Error('output must differ from the document being edited');
|
|
286
|
-
await mkdir(dirname(output), { recursive: true });
|
|
287
|
-
await writeFile(output, bytes);
|
|
288
|
-
return output;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// A page's own /Rotate, normalized: the quarter turns a viewer applies before
|
|
292
|
-
// anyone sees the page.
|
|
293
|
-
function pageSpin(page) {
|
|
294
|
-
const angle = Math.round(Number(page.getRotation?.()?.angle) || 0);
|
|
295
|
-
return ((angle % 360) + 360) % 360;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// A point on the page as displayed (bottom-left origin, after the page's own
|
|
299
|
-
// rotation) back to the user space a drawing operator writes in.
|
|
300
|
-
function displayPointToUser(spin, width, height, x, y) {
|
|
301
|
-
if (spin === 90) return { x: width - y, y: x };
|
|
302
|
-
if (spin === 180) return { x: width - x, y: height - y };
|
|
303
|
-
if (spin === 270) return { x: y, y: height - x };
|
|
304
|
-
return { x, y };
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// Display coordinates (top-left, page as shown) back to PDF user space through
|
|
308
|
-
// the inverse of pdf.js's page transform; the four corners keep a rotated box honest.
|
|
309
|
-
function displayToUser(transform, box) {
|
|
310
|
-
const [a, b, c, d, e, f] = transform;
|
|
311
|
-
const det = a * d - b * c;
|
|
312
|
-
const invert = ([X, Y]) => [(d * (X - e) - c * (Y - f)) / det, (-b * (X - e) + a * (Y - f)) / det];
|
|
313
|
-
const corners = [
|
|
314
|
-
[box.x, box.top],
|
|
315
|
-
[box.x + box.width, box.top],
|
|
316
|
-
[box.x, box.top + box.height],
|
|
317
|
-
[box.x + box.width, box.top + box.height],
|
|
318
|
-
].map(invert);
|
|
319
|
-
const xs = corners.map(([x]) => x);
|
|
320
|
-
const ys = corners.map(([, y]) => y);
|
|
321
|
-
const x = Math.min(...xs);
|
|
322
|
-
const y = Math.min(...ys);
|
|
323
|
-
return { x, y, width: Math.max(...xs) - x, height: Math.max(...ys) - y };
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// highlight and add_link take a box in bottom-left points, or `find`, which
|
|
327
|
-
// measures every match on the selected pages of the document as it stands in
|
|
328
|
-
// this batch (earlier operations included) so the boxes land on the real text.
|
|
329
|
-
// Measuring means serializing, and pdf-lib caches every stream it serializes
|
|
330
|
-
// (later drawing on such a page would be lost), so the batch continues on a
|
|
331
|
-
// fresh load of those bytes: the returned document replaces the caller's.
|
|
332
|
-
// `measure` carries the bytes and the pages already measured; marks do not
|
|
333
|
-
// move text, so consecutive marks share one measurement.
|
|
334
|
-
async function targetBoxes(document, operation, measure = null) {
|
|
335
|
-
const find = String(operation.find ?? '').trim();
|
|
336
|
-
if (!find) {
|
|
337
|
-
const box = ['x', 'y', 'width', 'height'].map((key) => Number(operation[key]));
|
|
338
|
-
if (!operation.page || box.some((value) => !Number.isFinite(value)) || box[2] <= 0 || box[3] <= 0) {
|
|
339
|
-
throw new Error(`${operation.op} needs find, or page with x, y, width, height in points`);
|
|
340
|
-
}
|
|
341
|
-
const [{ index }] = selectedPages(document, { page: operation.page });
|
|
342
|
-
return { document, boxes: [{ index, x: box[0], y: box[1], width: box[2], height: box[3] }], measure };
|
|
343
|
-
}
|
|
344
|
-
const selected = selectedPages(document, operation);
|
|
345
|
-
let current = document;
|
|
346
|
-
let next = measure;
|
|
347
|
-
if (!next) {
|
|
348
|
-
const bytes = await document.save(SAVE_OPTIONS);
|
|
349
|
-
current = await loadPdf(bytes);
|
|
350
|
-
next = { bytes, pages: new Map() };
|
|
351
|
-
}
|
|
352
|
-
const missing = selected.map(({ index }) => index + 1).filter((page) => !next.pages.has(page));
|
|
353
|
-
for (let at = 0; at < missing.length; at += MEASURE_CHUNK) {
|
|
354
|
-
const layout = await extractPdfTextLayout(next.bytes, {
|
|
355
|
-
pages: missing.slice(at, at + MEASURE_CHUNK),
|
|
356
|
-
shapes: false,
|
|
357
|
-
maxItems: 500_000,
|
|
358
|
-
});
|
|
359
|
-
for (const page of layout.pages) next.pages.set(page.page, page);
|
|
360
|
-
}
|
|
361
|
-
const layout = { pages: selected.map(({ index }) => next.pages.get(index + 1)).filter(Boolean) };
|
|
362
|
-
const { matches } = findPdfText(layout, find, {
|
|
363
|
-
limit: 500,
|
|
364
|
-
wholeWord: operation.wholeWord === true,
|
|
365
|
-
regex: operation.regex === true,
|
|
366
|
-
});
|
|
367
|
-
if (!matches.length) {
|
|
368
|
-
const scope =
|
|
369
|
-
selected.length === document.getPageCount()
|
|
370
|
-
? 'the document'
|
|
371
|
-
: `page${selected.length > 1 ? 's' : ''} ${selected.map(({ index }) => index + 1).join(', ')}`;
|
|
372
|
-
throw new Error(
|
|
373
|
-
`${operation.op} found no text matching "${find}" in ${scope}; check the snapshot text or pass page, x, y, width, height`
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
// A phrase that wraps comes back as one rect per line, and each is marked on
|
|
377
|
-
// its own; `first` selects a match, so its lines stay together.
|
|
378
|
-
const all = matches.map((match) => {
|
|
379
|
-
const index = match.page - 1;
|
|
380
|
-
const page = layout.pages.find((entry) => entry.page === match.page);
|
|
381
|
-
const rects = Array.isArray(match.rects) && match.rects.length ? match.rects : [match];
|
|
382
|
-
return rects.map((part) => {
|
|
383
|
-
// The layout is measured on the page as displayed (rotation and crop box
|
|
384
|
-
// applied); inverting the page's transform puts the box back into user space.
|
|
385
|
-
const rect =
|
|
386
|
-
Array.isArray(page?.transform) && page.transform.length === 6
|
|
387
|
-
? displayToUser(page.transform, part)
|
|
388
|
-
: { x: part.x, y: page.height - part.top - part.height, width: part.width, height: part.height };
|
|
389
|
-
return { index, ...rect, text: match.text };
|
|
390
|
-
});
|
|
391
|
-
});
|
|
392
|
-
const boxes = (operation.first === true ? all.slice(0, 1) : all).flat();
|
|
393
|
-
return { document: current, boxes, measure: next };
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// The first few boxes go back in bottom-left points so a caller can check a
|
|
397
|
-
// mark against the snapshot without rendering; a long match list is a count.
|
|
398
|
-
function reportBoxes(boxes) {
|
|
399
|
-
return boxes.slice(0, 20).map((box) => ({
|
|
400
|
-
page: box.index + 1,
|
|
401
|
-
x: round2(box.x),
|
|
402
|
-
y: round2(box.y),
|
|
403
|
-
width: round2(box.width),
|
|
404
|
-
height: round2(box.height),
|
|
405
|
-
...(box.text ? { text: box.text } : {}),
|
|
406
|
-
}));
|
|
140
|
+
function pagePagination(options, offset, limit, returned, total) {
|
|
141
|
+
const nextOffset = !options.pages?.length && offset + returned < total ? offset + returned : null;
|
|
142
|
+
return { unit: 'page', offset, limit, returned, total, nextOffset };
|
|
407
143
|
}
|
|
408
144
|
|
|
409
145
|
export async function applyPdfBatch(path, operations, context = {}) {
|
|
410
146
|
const source = await readFile(path);
|
|
411
|
-
|
|
147
|
+
// Batch state the handlers share: a handler that must continue on a fresh
|
|
148
|
+
// load (marks, previews, page reorders, OCR) replaces state.document.
|
|
149
|
+
const state = { path, source, context, document: await loadPdf(source), measure: null };
|
|
412
150
|
const results = [];
|
|
413
|
-
// Text positions measured for a mark stay valid across further marks; any
|
|
414
|
-
// other operation may move text, so it drops the measurement.
|
|
415
|
-
let measure = null;
|
|
416
151
|
for (const operation of operations) {
|
|
417
|
-
if (!
|
|
418
|
-
|
|
419
|
-
case 'add_text':
|
|
420
|
-
case 'watermark': {
|
|
421
|
-
const watermark = operation.op === 'watermark';
|
|
422
|
-
const template = String(operation.text ?? '');
|
|
423
|
-
if (!template.trim()) throw new Error(`${operation.op} needs text`);
|
|
424
|
-
const { font, fontPath, embedded } = await embedDocumentFont(document, {
|
|
425
|
-
fontPath: operation.fontPath,
|
|
426
|
-
text: template,
|
|
427
|
-
});
|
|
428
|
-
const size = Number(operation.size ?? (watermark ? 48 : 12));
|
|
429
|
-
const opacity = Number(operation.opacity ?? (watermark ? 0.25 : 1));
|
|
430
|
-
const angle = Number(operation.rotation ?? (watermark ? 45 : 0));
|
|
431
|
-
const pageCount = document.getPageCount();
|
|
432
|
-
const pages = [];
|
|
433
|
-
const align = String(operation.align || (watermark ? 'center' : 'left')).toLowerCase();
|
|
434
|
-
if (!['left', 'center', 'right'].includes(align))
|
|
435
|
-
throw new Error(`${operation.op} align must be left, center, or right`);
|
|
436
|
-
for (const { page, index } of selectedPages(document, operation)) {
|
|
437
|
-
// {page} and {pages} number an existing file the way create's pageNumbers does.
|
|
438
|
-
const text = template.replace(/\{page\}/g, String(index + 1)).replace(/\{pages\}/g, String(pageCount));
|
|
439
|
-
const textWidth = font.widthOfTextAtSize(text, size);
|
|
440
|
-
// A rotated page is stamped as the reader sees it: x and y are points
|
|
441
|
-
// on the displayed page, mapped back into user space, and the run is
|
|
442
|
-
// turned by the page's own rotation so the stamp reads with the page
|
|
443
|
-
// instead of lying sideways along an edge.
|
|
444
|
-
const spin = pageSpin(page);
|
|
445
|
-
const upright = spin % 180 === 0;
|
|
446
|
-
const displayWidth = upright ? page.getWidth() : page.getHeight();
|
|
447
|
-
const displayHeight = upright ? page.getHeight() : page.getWidth();
|
|
448
|
-
// A watermark centres its rotated run on the page unless placed
|
|
449
|
-
// explicitly; add_text with align centres or right-aligns the run
|
|
450
|
-
// between the page margins when x is omitted.
|
|
451
|
-
const spanX = textWidth * Math.cos((angle * Math.PI) / 180);
|
|
452
|
-
const spanY = textWidth * Math.sin((angle * Math.PI) / 180);
|
|
453
|
-
const defaultX =
|
|
454
|
-
align === 'center' ? (displayWidth - spanX) / 2 : align === 'right' ? displayWidth - 36 - spanX : 36;
|
|
455
|
-
const defaultY = watermark ? (displayHeight - spanY) / 2 : 36;
|
|
456
|
-
const placed = displayPointToUser(
|
|
457
|
-
spin,
|
|
458
|
-
page.getWidth(),
|
|
459
|
-
page.getHeight(),
|
|
460
|
-
operation.x === undefined || operation.x === null ? defaultX : Number(operation.x),
|
|
461
|
-
operation.y === undefined || operation.y === null ? defaultY : Number(operation.y)
|
|
462
|
-
);
|
|
463
|
-
const { x, y } = placed;
|
|
464
|
-
page.drawText(text, {
|
|
465
|
-
x,
|
|
466
|
-
y,
|
|
467
|
-
size,
|
|
468
|
-
font,
|
|
469
|
-
color: color(operation.color),
|
|
470
|
-
opacity,
|
|
471
|
-
rotate: degrees(angle + spin),
|
|
472
|
-
});
|
|
473
|
-
pages.push(index + 1);
|
|
474
|
-
}
|
|
475
|
-
results.push({
|
|
476
|
-
op: operation.op,
|
|
477
|
-
changed: pages.length > 0,
|
|
478
|
-
pages,
|
|
479
|
-
fontEmbedded: embedded,
|
|
480
|
-
...(fontPath ? { fontPath } : {}),
|
|
481
|
-
});
|
|
482
|
-
break;
|
|
483
|
-
}
|
|
484
|
-
case 'highlight': {
|
|
485
|
-
const target = await targetBoxes(document, operation, measure);
|
|
486
|
-
({ document, measure } = target);
|
|
487
|
-
const { boxes } = target;
|
|
488
|
-
const fill = color(operation.color || 'ffeb3b');
|
|
489
|
-
const opacity = Number(operation.opacity ?? 0.45);
|
|
490
|
-
const pages = new Set();
|
|
491
|
-
for (const box of boxes) {
|
|
492
|
-
// Multiply keeps the glyphs under the mark legible, the way a marker pen does.
|
|
493
|
-
document.getPage(box.index).drawRectangle({
|
|
494
|
-
x: box.x - 1,
|
|
495
|
-
y: box.y - 1,
|
|
496
|
-
width: box.width + 2,
|
|
497
|
-
height: box.height + 2,
|
|
498
|
-
color: fill,
|
|
499
|
-
opacity,
|
|
500
|
-
blendMode: BlendMode.Multiply,
|
|
501
|
-
borderWidth: 0,
|
|
502
|
-
});
|
|
503
|
-
pages.add(box.index + 1);
|
|
504
|
-
}
|
|
505
|
-
results.push({
|
|
506
|
-
op: operation.op,
|
|
507
|
-
changed: true,
|
|
508
|
-
marks: boxes.length,
|
|
509
|
-
pages: [...pages],
|
|
510
|
-
...(operation.find ? { find: String(operation.find) } : {}),
|
|
511
|
-
boxes: reportBoxes(boxes),
|
|
512
|
-
});
|
|
513
|
-
break;
|
|
514
|
-
}
|
|
515
|
-
case 'add_link': {
|
|
516
|
-
const autoUrls = operation.urls === true;
|
|
517
|
-
const url = String(operation.url ?? '').trim();
|
|
518
|
-
const toPage = operation.toPage === undefined || operation.toPage === null ? null : Number(operation.toPage);
|
|
519
|
-
if (!url && toPage === null && !autoUrls) throw new Error('add_link needs url, toPage, or urls:true');
|
|
520
|
-
if (url && !/^(https?:\/\/|mailto:)/i.test(url))
|
|
521
|
-
throw new Error(`add_link url must start with http://, https://, or mailto: (${url})`);
|
|
522
|
-
if (toPage !== null) selectedPages(document, { page: toPage });
|
|
523
|
-
// urls:true finds every http(s) address in the text and points each at itself.
|
|
524
|
-
const request = autoUrls
|
|
525
|
-
? { ...operation, find: 'https?://[^\\s<>()"\']+', regex: true, wholeWord: false }
|
|
526
|
-
: operation;
|
|
527
|
-
let target;
|
|
528
|
-
try {
|
|
529
|
-
target = await targetBoxes(document, request, measure);
|
|
530
|
-
} catch (error) {
|
|
531
|
-
if (!autoUrls || !/found no text matching/.test(String(error?.message || ''))) throw error;
|
|
532
|
-
throw new Error(
|
|
533
|
-
`add_link urls:true found no http(s) address in the selected pages; pass find or a box instead`
|
|
534
|
-
);
|
|
535
|
-
}
|
|
536
|
-
({ document, measure } = target);
|
|
537
|
-
const { boxes } = target;
|
|
538
|
-
// The destination page is looked up after measuring, on the document the links go into.
|
|
539
|
-
const destination = toPage === null ? null : [document.getPage(toPage - 1).ref, 'XYZ', null, null, null];
|
|
540
|
-
const linkUrl = (box) => (autoUrls ? box.text.replace(/[.,;:!?]+$/, '') : url);
|
|
541
|
-
const pages = new Set();
|
|
542
|
-
for (const box of boxes) {
|
|
543
|
-
const page = document.getPage(box.index);
|
|
544
|
-
const href = linkUrl(box);
|
|
545
|
-
const annotation = document.context.obj({
|
|
546
|
-
Type: 'Annot',
|
|
547
|
-
Subtype: 'Link',
|
|
548
|
-
Rect: [box.x, box.y, box.x + box.width, box.y + box.height],
|
|
549
|
-
Border: [0, 0, 0],
|
|
550
|
-
...(href ? { A: { Type: 'Action', S: 'URI', URI: PDFString.of(href) } } : { Dest: destination }),
|
|
551
|
-
});
|
|
552
|
-
page.node.addAnnot(document.context.register(annotation));
|
|
553
|
-
pages.add(box.index + 1);
|
|
554
|
-
}
|
|
555
|
-
results.push({
|
|
556
|
-
op: operation.op,
|
|
557
|
-
changed: true,
|
|
558
|
-
links: boxes.length,
|
|
559
|
-
pages: [...pages],
|
|
560
|
-
...(autoUrls ? { urls: boxes.map(linkUrl) } : url ? { url } : { toPage }),
|
|
561
|
-
boxes: reportBoxes(boxes),
|
|
562
|
-
});
|
|
563
|
-
break;
|
|
564
|
-
}
|
|
565
|
-
case 'stamp_image': {
|
|
566
|
-
const imagePath = resolve(dirname(path), String(operation.path || ''));
|
|
567
|
-
const placed = await embedImage(document, imagePath);
|
|
568
|
-
const pages = [];
|
|
569
|
-
for (const { page, index } of selectedPages(document, operation)) {
|
|
570
|
-
// Pixels become points one-to-one, so a photo would run off the page; keep it inside the margins unless sized.
|
|
571
|
-
const width = Number(operation.width || Math.min(placed.width, page.getWidth() - 72));
|
|
572
|
-
const height = Number(operation.height || (placed.height * width) / placed.width);
|
|
573
|
-
page.drawImage(placed.image, {
|
|
574
|
-
x: Number(operation.x || 0),
|
|
575
|
-
y: Number(operation.y || 0),
|
|
576
|
-
width,
|
|
577
|
-
height,
|
|
578
|
-
opacity: Number(operation.opacity ?? 1),
|
|
579
|
-
});
|
|
580
|
-
pages.push(index + 1);
|
|
581
|
-
}
|
|
582
|
-
results.push({ op: operation.op, changed: pages.length > 0, pages, image: imagePath });
|
|
583
|
-
break;
|
|
584
|
-
}
|
|
585
|
-
case 'ocr_pages': {
|
|
586
|
-
await writeFile(path, await document.save(SAVE_OPTIONS));
|
|
587
|
-
const result = await ocrPdf(path, operation, context);
|
|
588
|
-
document = await loadPdf(await readFile(path));
|
|
589
|
-
results.push(result);
|
|
590
|
-
break;
|
|
591
|
-
}
|
|
592
|
-
case 'rotate_pages': {
|
|
593
|
-
const delta = Number(operation.rotation ?? 90);
|
|
594
|
-
if (!Number.isInteger(delta) || delta % 90 !== 0)
|
|
595
|
-
throw new Error(`PDF rotation must be a multiple of 90 degrees: ${operation.rotation}`);
|
|
596
|
-
const pages = [];
|
|
597
|
-
for (const { page, index } of selectedPages(document, operation)) {
|
|
598
|
-
const current = page.getRotation().angle;
|
|
599
|
-
const next = (((operation.absolute ? delta : current + delta) % 360) + 360) % 360;
|
|
600
|
-
page.setRotation(degrees(next));
|
|
601
|
-
pages.push({ page: index + 1, from: current, rotation: next });
|
|
602
|
-
}
|
|
603
|
-
results.push({ op: operation.op, changed: pages.some((entry) => entry.from !== entry.rotation), pages });
|
|
604
|
-
break;
|
|
605
|
-
}
|
|
606
|
-
case 'delete_pages': {
|
|
607
|
-
const indexes = selectedPages(document, operation)
|
|
608
|
-
.map(({ index }) => index)
|
|
609
|
-
.sort((a, b) => b - a);
|
|
610
|
-
if (indexes.length >= document.getPageCount())
|
|
611
|
-
throw new Error('delete_pages cannot remove every page; use extract_pages or delete fewer pages');
|
|
612
|
-
for (const index of indexes) document.removePage(index);
|
|
613
|
-
results.push({
|
|
614
|
-
op: operation.op,
|
|
615
|
-
changed: indexes.length > 0,
|
|
616
|
-
count: indexes.length,
|
|
617
|
-
pageCount: document.getPageCount(),
|
|
618
|
-
});
|
|
619
|
-
break;
|
|
620
|
-
}
|
|
621
|
-
case 'extract_pages': {
|
|
622
|
-
const next = await PDFDocument.create();
|
|
623
|
-
const indexes = selectedPages(document, operation).map(({ index }) => index);
|
|
624
|
-
const copied = await next.copyPages(document, indexes);
|
|
625
|
-
copied.forEach((page) => next.addPage(page));
|
|
626
|
-
const pages = indexes.map((index) => index + 1);
|
|
627
|
-
if (operation.output) {
|
|
628
|
-
// With an output the session document stays whole; the subset is a new file.
|
|
629
|
-
const output = await writeSibling(path, operation.output, await next.save(SAVE_OPTIONS));
|
|
630
|
-
results.push({
|
|
631
|
-
op: operation.op,
|
|
632
|
-
changed: true,
|
|
633
|
-
documentChanged: false,
|
|
634
|
-
output,
|
|
635
|
-
count: indexes.length,
|
|
636
|
-
pages,
|
|
637
|
-
});
|
|
638
|
-
} else {
|
|
639
|
-
document = next;
|
|
640
|
-
results.push({ op: operation.op, changed: true, count: indexes.length, pages });
|
|
641
|
-
}
|
|
642
|
-
break;
|
|
643
|
-
}
|
|
644
|
-
case 'split_pages': {
|
|
645
|
-
const every = Math.max(1, Math.floor(Number(operation.every) || 1));
|
|
646
|
-
const indexes = selectedPages(document, operation).map(({ index }) => index);
|
|
647
|
-
const stem = basename(path, extname(path));
|
|
648
|
-
const directory = resolve(dirname(path), String(operation.output || '.'));
|
|
649
|
-
const files = [];
|
|
650
|
-
for (let start = 0; start < indexes.length; start += every) {
|
|
651
|
-
const group = indexes.slice(start, start + every);
|
|
652
|
-
const part = await PDFDocument.create();
|
|
653
|
-
const copied = await part.copyPages(document, group);
|
|
654
|
-
copied.forEach((page) => part.addPage(page));
|
|
655
|
-
const first = String(group[0] + 1).padStart(3, '0');
|
|
656
|
-
const label = group.length === 1 ? first : `${first}-${String(group.at(-1) + 1).padStart(3, '0')}`;
|
|
657
|
-
const output = await writeSibling(
|
|
658
|
-
path,
|
|
659
|
-
resolve(directory, `${stem}-${label}.pdf`),
|
|
660
|
-
await part.save(SAVE_OPTIONS)
|
|
661
|
-
);
|
|
662
|
-
files.push({ output, pages: group.map((index) => index + 1) });
|
|
663
|
-
}
|
|
664
|
-
results.push({
|
|
665
|
-
op: operation.op,
|
|
666
|
-
changed: files.length > 0,
|
|
667
|
-
documentChanged: false,
|
|
668
|
-
count: files.length,
|
|
669
|
-
files,
|
|
670
|
-
});
|
|
671
|
-
break;
|
|
672
|
-
}
|
|
673
|
-
case 'fill_form': {
|
|
674
|
-
const form = document.getForm();
|
|
675
|
-
const filled = fillFormValues(form, operation.values);
|
|
676
|
-
const coverage = Object.values(operation.values || {})
|
|
677
|
-
.flat()
|
|
678
|
-
.map((value) => String(value ?? ''))
|
|
679
|
-
.join(' ');
|
|
680
|
-
const { font, fontPath, embedded } = await embedDocumentFont(document, {
|
|
681
|
-
fontPath: operation.fontPath,
|
|
682
|
-
text: coverage,
|
|
683
|
-
});
|
|
684
|
-
form.updateFieldAppearances(font);
|
|
685
|
-
// The appearances exist now, so the values can be measured against the
|
|
686
|
-
// boxes that will show them before the document is handed on.
|
|
687
|
-
const clipped = clippedFormValues(document, form, operation.values, font);
|
|
688
|
-
if (operation.flatten) form.flatten();
|
|
689
|
-
results.push({
|
|
690
|
-
op: operation.op,
|
|
691
|
-
changed: filled.length > 0,
|
|
692
|
-
filled,
|
|
693
|
-
flattened: Boolean(operation.flatten),
|
|
694
|
-
fontEmbedded: embedded,
|
|
695
|
-
...(fontPath ? { fontPath } : {}),
|
|
696
|
-
...(clipped.length
|
|
697
|
-
? {
|
|
698
|
-
clipped,
|
|
699
|
-
warning: `${clipped.length} value(s) do not fit their field box: ${clipped.map((entry) => entry.message).join(' ')}`,
|
|
700
|
-
}
|
|
701
|
-
: {}),
|
|
702
|
-
});
|
|
703
|
-
break;
|
|
704
|
-
}
|
|
705
|
-
case 'add_form_field': {
|
|
706
|
-
const check = lintPdfFormFields(
|
|
707
|
-
[operation],
|
|
708
|
-
document.getPages().map((entry) => [entry.getWidth(), entry.getHeight()])
|
|
709
|
-
);
|
|
710
|
-
if (!check.ok) throw new Error(check.issues.map((issue) => issue.message).join(' '));
|
|
711
|
-
const { font } = await embedDocumentFont(document, {
|
|
712
|
-
fontPath: operation.fontPath,
|
|
713
|
-
text: fieldText(operation),
|
|
714
|
-
});
|
|
715
|
-
await addFormField(document, operation, font);
|
|
716
|
-
document.getForm().updateFieldAppearances(font);
|
|
717
|
-
results.push({
|
|
718
|
-
op: operation.op,
|
|
719
|
-
changed: true,
|
|
720
|
-
name: operation.name,
|
|
721
|
-
type: String(operation.type || 'text').toLowerCase(),
|
|
722
|
-
});
|
|
723
|
-
break;
|
|
724
|
-
}
|
|
725
|
-
case 'flatten_form': {
|
|
726
|
-
const form = document.getForm();
|
|
727
|
-
const count = form.getFields().length;
|
|
728
|
-
if (operation.fontPath) {
|
|
729
|
-
const { font } = await embedDocumentFont(document, { fontPath: operation.fontPath });
|
|
730
|
-
form.updateFieldAppearances(font);
|
|
731
|
-
}
|
|
732
|
-
form.flatten();
|
|
733
|
-
results.push({ op: operation.op, changed: count > 0, fields: count });
|
|
734
|
-
break;
|
|
735
|
-
}
|
|
736
|
-
case 'add_attachment': {
|
|
737
|
-
const attachmentPath = resolve(dirname(path), String(operation.path || ''));
|
|
738
|
-
await document.attach(await readFile(attachmentPath), String(operation.name || basename(attachmentPath)), {
|
|
739
|
-
mimeType: String(operation.mimeType || 'application/octet-stream'),
|
|
740
|
-
description: String(operation.description || ''),
|
|
741
|
-
});
|
|
742
|
-
results.push({ op: operation.op, changed: true, name: String(operation.name || basename(attachmentPath)) });
|
|
743
|
-
break;
|
|
744
|
-
}
|
|
745
|
-
case 'extract_attachment': {
|
|
746
|
-
const entries = attachmentEntries(document);
|
|
747
|
-
const wanted = entries.find(
|
|
748
|
-
(entry) =>
|
|
749
|
-
(operation.name != null && entry.name === String(operation.name)) ||
|
|
750
|
-
(operation.index != null && entry.index === Number(operation.index))
|
|
751
|
-
);
|
|
752
|
-
if (!wanted) {
|
|
753
|
-
throw new Error(
|
|
754
|
-
`PDF has no attachment ${operation.name ?? operation.index ?? ''}; attachments: ${entries.map((entry) => entry.name).join(', ') || '(none)'}`
|
|
755
|
-
);
|
|
756
|
-
}
|
|
757
|
-
const bytes = attachmentBytes(wanted.spec);
|
|
758
|
-
if (!bytes) throw new Error(`Attachment ${wanted.name} has no embedded file stream`);
|
|
759
|
-
const output = await writeSibling(path, operation.output || wanted.name || `attachment-${wanted.index}`, bytes);
|
|
760
|
-
results.push({
|
|
761
|
-
op: operation.op,
|
|
762
|
-
changed: true,
|
|
763
|
-
documentChanged: false,
|
|
764
|
-
name: wanted.name,
|
|
765
|
-
output,
|
|
766
|
-
bytes: bytes.length,
|
|
767
|
-
});
|
|
768
|
-
break;
|
|
769
|
-
}
|
|
770
|
-
case 'compress': {
|
|
771
|
-
results.push({ op: operation.op, changed: true, method: 'object-streams', bytesBefore: source.length });
|
|
772
|
-
break;
|
|
773
|
-
}
|
|
774
|
-
case 'preview_fields': {
|
|
775
|
-
// A copy with every field's box outlined and named — and any box the
|
|
776
|
-
// caller proposes — so a render shows placement before a fill. The
|
|
777
|
-
// session document continues on a reload of the same bytes (see targetBoxes).
|
|
778
|
-
const output = String(operation.output || '').trim();
|
|
779
|
-
if (!output) throw new Error('preview_fields needs output (a file name beside the document)');
|
|
780
|
-
const bytes = await document.save(SAVE_OPTIONS);
|
|
781
|
-
document = await loadPdf(bytes);
|
|
782
|
-
const copy = await loadPdf(bytes);
|
|
783
|
-
const fields = copy.getForm().getFields();
|
|
784
|
-
const proposed = Array.isArray(operation.boxes) ? operation.boxes : [];
|
|
785
|
-
const labels = [
|
|
786
|
-
...fields.map((field) => field.getName()),
|
|
787
|
-
...proposed.map((box) => String(box.label ?? '')),
|
|
788
|
-
].join(' ');
|
|
789
|
-
const { font } = await embedDocumentFont(copy, { text: `${labels} box 0123456789` });
|
|
790
|
-
const ink = color('d32f2f');
|
|
791
|
-
const outline = (page, box, label) => {
|
|
792
|
-
page.drawRectangle({
|
|
793
|
-
x: box.x,
|
|
794
|
-
y: box.y,
|
|
795
|
-
width: box.width,
|
|
796
|
-
height: box.height,
|
|
797
|
-
borderColor: ink,
|
|
798
|
-
borderWidth: 1,
|
|
799
|
-
});
|
|
800
|
-
page.drawText(label, { x: box.x, y: box.y + box.height + 2, size: 7, font, color: ink });
|
|
801
|
-
};
|
|
802
|
-
let widgets = 0;
|
|
803
|
-
fields.forEach((field, index) => {
|
|
804
|
-
for (const widget of fieldWidgets(field, copy)) {
|
|
805
|
-
if (!widget.page) continue;
|
|
806
|
-
outline(copy.getPage(widget.page - 1), widget, `${index + 1} ${field.getName()}`);
|
|
807
|
-
widgets += 1;
|
|
808
|
-
}
|
|
809
|
-
});
|
|
810
|
-
proposed.forEach((box, index) => {
|
|
811
|
-
const rect = ['x', 'y', 'width', 'height'].map((key) => Number(box?.[key]));
|
|
812
|
-
if (!box?.page || rect.some((value) => !Number.isFinite(value)))
|
|
813
|
-
throw new Error(`preview_fields boxes[${index}] needs page, x, y, width, height`);
|
|
814
|
-
const [{ page }] = selectedPages(copy, { page: box.page });
|
|
815
|
-
outline(
|
|
816
|
-
page,
|
|
817
|
-
{ x: rect[0], y: rect[1], width: rect[2], height: rect[3] },
|
|
818
|
-
String(box.label ?? `box ${index + 1}`)
|
|
819
|
-
);
|
|
820
|
-
});
|
|
821
|
-
const written = await writeSibling(path, output, await copy.save(SAVE_OPTIONS));
|
|
822
|
-
results.push({
|
|
823
|
-
op: operation.op,
|
|
824
|
-
changed: true,
|
|
825
|
-
documentChanged: false,
|
|
826
|
-
output: written,
|
|
827
|
-
fields: fields.length,
|
|
828
|
-
widgets,
|
|
829
|
-
boxes: proposed.length,
|
|
830
|
-
});
|
|
831
|
-
break;
|
|
832
|
-
}
|
|
833
|
-
case 'merge_pdf': {
|
|
834
|
-
const sources =
|
|
835
|
-
Array.isArray(operation.sources) && operation.sources.length
|
|
836
|
-
? operation.sources
|
|
837
|
-
: operation.path
|
|
838
|
-
? [operation.path]
|
|
839
|
-
: [];
|
|
840
|
-
if (!sources.length) throw new Error('merge_pdf needs sources:[path | { path, pages }] or path');
|
|
841
|
-
let insertAt = null;
|
|
842
|
-
if (operation.index != null) {
|
|
843
|
-
insertAt = Number(operation.index) - 1;
|
|
844
|
-
if (!Number.isInteger(insertAt) || insertAt < 0 || insertAt > document.getPageCount()) {
|
|
845
|
-
throw new Error(`PDF insertion index out of range: ${operation.index}`);
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
const merged = [];
|
|
849
|
-
for (const entry of sources) {
|
|
850
|
-
const sourcePath = resolve(dirname(path), String(typeof entry === 'string' ? entry : entry?.path || ''));
|
|
851
|
-
const other = await loadPdf(await readFile(sourcePath));
|
|
852
|
-
const selection = typeof entry === 'string' ? {} : { pages: entry?.pages, page: entry?.page };
|
|
853
|
-
const indexes = selectedPages(other, selection).map(({ index }) => index);
|
|
854
|
-
const copied = await document.copyPages(other, indexes);
|
|
855
|
-
const firstPage = insertAt == null ? document.getPageCount() : insertAt;
|
|
856
|
-
for (const page of copied) {
|
|
857
|
-
if (insertAt == null) document.addPage(page);
|
|
858
|
-
else {
|
|
859
|
-
document.insertPage(insertAt, page);
|
|
860
|
-
insertAt += 1;
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
merged.push({
|
|
864
|
-
path: sourcePath,
|
|
865
|
-
pages: indexes.map((index) => index + 1),
|
|
866
|
-
pagesAdded: copied.length,
|
|
867
|
-
at: firstPage + 1,
|
|
868
|
-
title: typeof entry === 'string' ? '' : String(entry?.title || ''),
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
|
-
const pagesAdded = merged.reduce((sum, entry) => sum + entry.pagesAdded, 0);
|
|
872
|
-
const bookmarks =
|
|
873
|
-
operation.bookmarks === true
|
|
874
|
-
? addOutlineEntries(
|
|
875
|
-
document,
|
|
876
|
-
merged
|
|
877
|
-
.filter((entry) => entry.pagesAdded > 0)
|
|
878
|
-
.map((entry) => ({
|
|
879
|
-
title: entry.title || basename(entry.path, extname(entry.path)),
|
|
880
|
-
pageIndex: entry.at - 1,
|
|
881
|
-
}))
|
|
882
|
-
)
|
|
883
|
-
: 0;
|
|
884
|
-
results.push({
|
|
885
|
-
op: operation.op,
|
|
886
|
-
changed: pagesAdded > 0,
|
|
887
|
-
pagesAdded,
|
|
888
|
-
sources: merged,
|
|
889
|
-
pageCount: document.getPageCount(),
|
|
890
|
-
...(operation.bookmarks === true ? { bookmarks } : {}),
|
|
891
|
-
});
|
|
892
|
-
break;
|
|
893
|
-
}
|
|
894
|
-
case 'add_bookmark': {
|
|
895
|
-
const title = String(operation.title ?? '').trim();
|
|
896
|
-
if (!title) throw new Error('add_bookmark needs title');
|
|
897
|
-
if (!operation.page) throw new Error('add_bookmark needs page');
|
|
898
|
-
const [{ index }] = selectedPages(document, { page: operation.page });
|
|
899
|
-
addOutlineEntries(document, [{ title, pageIndex: index }]);
|
|
900
|
-
results.push({ op: operation.op, changed: true, title, page: index + 1 });
|
|
901
|
-
break;
|
|
902
|
-
}
|
|
903
|
-
case 'set_metadata': {
|
|
904
|
-
const props = operation.properties || {};
|
|
905
|
-
const applied = [];
|
|
906
|
-
if (props.title !== undefined) {
|
|
907
|
-
document.setTitle(String(props.title));
|
|
908
|
-
applied.push('title');
|
|
909
|
-
}
|
|
910
|
-
if (props.author !== undefined) {
|
|
911
|
-
document.setAuthor(String(props.author));
|
|
912
|
-
applied.push('author');
|
|
913
|
-
}
|
|
914
|
-
if (props.subject !== undefined) {
|
|
915
|
-
document.setSubject(String(props.subject));
|
|
916
|
-
applied.push('subject');
|
|
917
|
-
}
|
|
918
|
-
if (props.creator !== undefined) {
|
|
919
|
-
document.setCreator(String(props.creator));
|
|
920
|
-
applied.push('creator');
|
|
921
|
-
}
|
|
922
|
-
if (props.keywords !== undefined) {
|
|
923
|
-
document.setKeywords(Array.isArray(props.keywords) ? props.keywords.map(String) : [String(props.keywords)]);
|
|
924
|
-
applied.push('keywords');
|
|
925
|
-
}
|
|
926
|
-
results.push({ op: operation.op, changed: applied.length > 0, applied });
|
|
927
|
-
break;
|
|
928
|
-
}
|
|
929
|
-
case 'move_page': {
|
|
930
|
-
const from = Number(operation.page) - 1;
|
|
931
|
-
const to = Number(operation.index) - 1;
|
|
932
|
-
const count = document.getPageCount();
|
|
933
|
-
if (!Number.isInteger(from) || from < 0 || from >= count)
|
|
934
|
-
throw new Error(`PDF page out of range: ${operation.page}`);
|
|
935
|
-
if (!Number.isInteger(to) || to < 0 || to >= count)
|
|
936
|
-
throw new Error(`PDF destination page out of range: ${operation.index}`);
|
|
937
|
-
const order = document.getPageIndices();
|
|
938
|
-
const [moved] = order.splice(from, 1);
|
|
939
|
-
order.splice(to, 0, moved);
|
|
940
|
-
const next = await PDFDocument.create();
|
|
941
|
-
const copied = await next.copyPages(document, order);
|
|
942
|
-
copied.forEach((page) => next.addPage(page));
|
|
943
|
-
document = next;
|
|
944
|
-
results.push({ op: operation.op, changed: from !== to, from: from + 1, to: to + 1 });
|
|
945
|
-
break;
|
|
946
|
-
}
|
|
947
|
-
default:
|
|
948
|
-
throw new Error(`PDF backend does not support operation: ${operation.op}`);
|
|
152
|
+
if (!Object.hasOwn(BATCH_OPERATIONS, operation.op)) {
|
|
153
|
+
throw new Error(`PDF backend does not support operation: ${operation.op}`);
|
|
949
154
|
}
|
|
155
|
+
// Text positions measured for a mark stay valid across further marks; any
|
|
156
|
+
// other operation may move text, so it drops the measurement.
|
|
157
|
+
if (!MARK_OPERATIONS.has(operation.op)) state.measure = null;
|
|
158
|
+
results.push(await BATCH_OPERATIONS[operation.op](state, operation));
|
|
950
159
|
}
|
|
951
|
-
const bytes = await document.save(SAVE_OPTIONS);
|
|
160
|
+
const bytes = await state.document.save(SAVE_OPTIONS);
|
|
952
161
|
await writeFile(path, bytes);
|
|
953
162
|
for (const entry of results) {
|
|
954
163
|
if (entry.op !== 'compress') continue;
|