mixdog 0.9.167 → 0.9.169

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.
Files changed (1284) hide show
  1. package/LICENSES/air-MIT.txt +21 -0
  2. package/LICENSES/ast-grep-MIT.txt +21 -0
  3. package/LICENSES/biome-MIT.txt +22 -0
  4. package/LICENSES/clang-format-Apache-2.0-WITH-LLVM-exception.txt +279 -0
  5. package/LICENSES/dprint-MIT.txt +21 -0
  6. package/LICENSES/gofumpt-BSD-3-Clause.txt +27 -0
  7. package/LICENSES/mago-MIT.txt +21 -0
  8. package/LICENSES/ruff-MIT.txt +430 -0
  9. package/LICENSES/shfmt-BSD-3-Clause.txt +27 -0
  10. package/LICENSES/stylua-MPL-2.0.txt +373 -0
  11. package/NOTICE.md +82 -0
  12. package/README.md +84 -11
  13. package/package.json +4 -2
  14. package/scripts/agent-lead-e2e-probe.mjs +66 -39
  15. package/scripts/agent-turn-trace-probe.mjs +68 -36
  16. package/scripts/audit-usage-ledger.mjs +102 -47
  17. package/scripts/build-tui.mjs +1 -4
  18. package/scripts/code-graph-description-contract.mjs +41 -30
  19. package/scripts/computer-task-cost-report.mjs +5 -19
  20. package/scripts/context-renewal-live-check.mjs +64 -24
  21. package/scripts/daemon-stub.mjs +66 -24
  22. package/scripts/dependency-lock-cache-key.mjs +15 -17
  23. package/scripts/embedding-quality-probe.mjs +42 -34
  24. package/scripts/fixtures/spawn-lease-fixture-worker.mjs +5 -1
  25. package/scripts/generate-runtime-manifest.mjs +37 -22
  26. package/scripts/graph-parity.mjs +1096 -0
  27. package/scripts/import-usage-ledger.mjs +5 -3
  28. package/scripts/lib/embedding-model-bench-core.mjs +126 -124
  29. package/scripts/lib/isolated-root-cleanup.mjs +11 -5
  30. package/scripts/lib/local-provider-live-scenarios.mjs +14 -5
  31. package/scripts/lib/recall-bench-eval.mjs +32 -18
  32. package/scripts/lib/stage-postgres-runtime-windows.ps1 +2 -2
  33. package/scripts/lib/test-timing-reporter.mjs +8 -2
  34. package/scripts/llm-trace-summary.mjs +48 -23
  35. package/scripts/local-provider-live-check.mjs +180 -79
  36. package/scripts/manifest-cache-key.mjs +16 -16
  37. package/scripts/media-image-live.mjs +123 -56
  38. package/scripts/memory-chunk-quality.mjs +120 -87
  39. package/scripts/memory-layer2-check.mjs +157 -104
  40. package/scripts/model-catalog-audit.mjs +22 -14
  41. package/scripts/mouse-probe.mjs +17 -3
  42. package/scripts/native-binary-arch.mjs +62 -50
  43. package/scripts/native-spawn-test-runtime.mjs +1 -1
  44. package/scripts/native-tool-download.mjs +61 -60
  45. package/scripts/office/aesthetics-probe.mjs +28 -7
  46. package/scripts/office/author-deck.mjs +48 -13
  47. package/scripts/office/build-pptx-icons.mjs +278 -12
  48. package/scripts/office-design-audit.mjs +16 -16
  49. package/scripts/office-live-test-plan.mjs +10 -1
  50. package/scripts/patch-replay.mjs +46 -16
  51. package/scripts/pdf-rotation-stress.mjs +8 -4
  52. package/scripts/perf/cold-reconnect-probe.mjs +78 -41
  53. package/scripts/perf/transcript-baseline.mjs +76 -47
  54. package/scripts/perf/transcript-runtime-probe.mjs +50 -24
  55. package/scripts/pg-memory-diet-apply.mjs +86 -56
  56. package/scripts/pg-memory-diet-verify.mjs +101 -60
  57. package/scripts/pg-memory-diet.mjs +208 -113
  58. package/scripts/prepare-native-assets.mjs +8 -19
  59. package/scripts/prune-desktop-runtime.mjs +136 -163
  60. package/scripts/prune-embedding-runtime.mjs +78 -90
  61. package/scripts/reduction-trace-report.mjs +18 -14
  62. package/scripts/release-paths.mjs +2 -12
  63. package/scripts/release-timing-report.mjs +38 -26
  64. package/scripts/routing-corpus.mjs +311 -102
  65. package/scripts/run-office-live-tests.mjs +4 -1
  66. package/scripts/runtime-dependency-cache-key.mjs +39 -39
  67. package/scripts/search-rg-parity.mjs +149 -97
  68. package/scripts/session-diag.mjs +30 -18
  69. package/scripts/session-sweep.mjs +235 -191
  70. package/scripts/smoke.mjs +9 -2
  71. package/scripts/suite-health.mjs +1 -2
  72. package/scripts/test.mjs +13 -5
  73. package/scripts/tidy/sync-engines-manifest.mjs +686 -0
  74. package/scripts/tool-efficiency-diag.mjs +36 -11
  75. package/scripts/tool-failures.mjs +68 -50
  76. package/scripts/tool-overhead-microbench.mjs +17 -11
  77. package/scripts/tool-stress.mjs +166 -57
  78. package/scripts/tui-frame-harness-shim.mjs +16 -6
  79. package/scripts/tui-frame-harness.mjs +171 -68
  80. package/scripts/tui-transcript-jitter-harness.mjs +0 -2
  81. package/scripts/verify-release-assets.mjs +25 -38
  82. package/src/app.mjs +24 -18
  83. package/src/cli.mjs +24 -19
  84. package/src/defaults/agents.json +1 -13
  85. package/src/defaults/skills/browser-use/SKILL.md +5 -3
  86. package/src/defaults/skills/code-tidy/SKILL.md +91 -0
  87. package/src/defaults/skills/computer-use/SKILL.md +21 -7
  88. package/src/defaults/skills/memory-management/SKILL.md +4 -5
  89. package/src/defaults/skills/pptx/scripts/qc-pages.mjs +107 -54
  90. package/src/defaults/skills/pptx/scripts/review-deck.mjs +102 -34
  91. package/src/defaults/skills/pptx/scripts/source-extract.mjs +6 -3
  92. package/src/defaults/skills/skill-creator/scripts/validate-skill.mjs +25 -27
  93. package/src/headless-command.mjs +22 -13
  94. package/src/headless-exec.mjs +272 -268
  95. package/src/headless-role.mjs +17 -31
  96. package/src/lib/keychain-cjs.cjs +410 -358
  97. package/src/lib/mixdog-debug.cjs +20 -14
  98. package/src/lib/output-style-meta.cjs +22 -13
  99. package/src/lib/rules-builder.cjs +46 -23
  100. package/src/lib/text-utils.cjs +44 -42
  101. package/src/repl.mjs +72 -57
  102. package/src/rules/agent/00-common.md +3 -0
  103. package/src/rules/agent/41-cycle2-agent.md +12 -32
  104. package/src/rules/lead/lead-brief.md +9 -13
  105. package/src/rules/shared/10-tool-workflow.md +11 -8
  106. package/src/rules/shared/30-exploration.md +4 -0
  107. package/src/rules/shared/80-memory.md +3 -3
  108. package/src/runtime/agent/orchestrator/activity-bus.mjs +5 -1
  109. package/src/runtime/agent/orchestrator/agent-owner.mjs +9 -4
  110. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +419 -382
  111. package/src/runtime/agent/orchestrator/agent-runtime/agent-progress-watchdog.mjs +215 -221
  112. package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +256 -255
  113. package/src/runtime/agent/orchestrator/agent-runtime/completion-text.mjs +9 -9
  114. package/src/runtime/agent/orchestrator/agent-runtime/maintenance-route.mjs +36 -36
  115. package/src/runtime/agent/orchestrator/agent-runtime/session-builder.mjs +108 -93
  116. package/src/runtime/agent/orchestrator/agent-runtime/title-completion.mjs +54 -48
  117. package/src/runtime/agent/orchestrator/agent-trace-format.mjs +702 -609
  118. package/src/runtime/agent/orchestrator/agent-trace-io.mjs +353 -330
  119. package/src/runtime/agent/orchestrator/agent-trace.mjs +295 -298
  120. package/src/runtime/agent/orchestrator/cache-break-trace.mjs +87 -86
  121. package/src/runtime/agent/orchestrator/cache-mtime.mjs +32 -21
  122. package/src/runtime/agent/orchestrator/config-presets.mjs +99 -63
  123. package/src/runtime/agent/orchestrator/config-storage.mjs +226 -194
  124. package/src/runtime/agent/orchestrator/config.mjs +343 -338
  125. package/src/runtime/agent/orchestrator/context/collect.mjs +19 -19
  126. package/src/runtime/agent/orchestrator/context/deferred-tools.mjs +180 -176
  127. package/src/runtime/agent/orchestrator/context/role-instructions.mjs +199 -194
  128. package/src/runtime/agent/orchestrator/context/skill-catalog.mjs +288 -288
  129. package/src/runtime/agent/orchestrator/context/skill-state.mjs +38 -30
  130. package/src/runtime/agent/orchestrator/dispatch-persist.mjs +52 -240
  131. package/src/runtime/agent/orchestrator/internal-agents.mjs +59 -58
  132. package/src/runtime/agent/orchestrator/internal-tools.mjs +57 -52
  133. package/src/runtime/agent/orchestrator/mcp/child-tree.mjs +222 -161
  134. package/src/runtime/agent/orchestrator/mcp/client.mjs +984 -904
  135. package/src/runtime/agent/orchestrator/mcp/reconnect-singleflight.mjs +21 -21
  136. package/src/runtime/agent/orchestrator/providers/account-pool.mjs +33 -17
  137. package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +532 -513
  138. package/src/runtime/agent/orchestrator/providers/anthropic-betas.mjs +34 -32
  139. package/src/runtime/agent/orchestrator/providers/anthropic-effort.mjs +249 -237
  140. package/src/runtime/agent/orchestrator/providers/anthropic-fable-history.mjs +64 -55
  141. package/src/runtime/agent/orchestrator/providers/anthropic-fast-mode.mjs +32 -32
  142. package/src/runtime/agent/orchestrator/providers/anthropic-leaked-toolcall.mjs +297 -280
  143. package/src/runtime/agent/orchestrator/providers/anthropic-max-tokens.mjs +33 -33
  144. package/src/runtime/agent/orchestrator/providers/anthropic-messages.mjs +107 -96
  145. package/src/runtime/agent/orchestrator/providers/anthropic-model-resolve.mjs +117 -118
  146. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-client-version.mjs +72 -67
  147. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-credentials.mjs +564 -496
  148. package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +1262 -1138
  149. package/src/runtime/agent/orchestrator/providers/anthropic-server-fallback.mjs +24 -34
  150. package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +1017 -915
  151. package/src/runtime/agent/orchestrator/providers/anthropic-thinking-contract.mjs +11 -7
  152. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +745 -674
  153. package/src/runtime/agent/orchestrator/providers/antigravity-oauth-catalog.mjs +152 -153
  154. package/src/runtime/agent/orchestrator/providers/antigravity-oauth-login.mjs +361 -308
  155. package/src/runtime/agent/orchestrator/providers/antigravity-oauth-tokens.mjs +215 -204
  156. package/src/runtime/agent/orchestrator/providers/antigravity-oauth.mjs +443 -453
  157. package/src/runtime/agent/orchestrator/providers/antigravity-request.mjs +77 -65
  158. package/src/runtime/agent/orchestrator/providers/api-usage.mjs +99 -55
  159. package/src/runtime/agent/orchestrator/providers/codex-client-meta.mjs +59 -53
  160. package/src/runtime/agent/orchestrator/providers/compat-request-policy.mjs +9 -9
  161. package/src/runtime/agent/orchestrator/providers/cursor-auth.mjs +242 -215
  162. package/src/runtime/agent/orchestrator/providers/cursor-wire-guards.mjs +227 -221
  163. package/src/runtime/agent/orchestrator/providers/cursor-wire-interactions.mjs +68 -68
  164. package/src/runtime/agent/orchestrator/providers/cursor-wire-normalization.mjs +174 -156
  165. package/src/runtime/agent/orchestrator/providers/cursor-wire-protobuf.mjs +823 -827
  166. package/src/runtime/agent/orchestrator/providers/cursor-wire.mjs +1413 -1286
  167. package/src/runtime/agent/orchestrator/providers/cursor.mjs +614 -589
  168. package/src/runtime/agent/orchestrator/providers/custom-tool-wire.mjs +27 -19
  169. package/src/runtime/agent/orchestrator/providers/effort-configuration.mjs +120 -97
  170. package/src/runtime/agent/orchestrator/providers/gemini-cache.mjs +223 -231
  171. package/src/runtime/agent/orchestrator/providers/gemini-history-signatures.mjs +27 -21
  172. package/src/runtime/agent/orchestrator/providers/gemini-schema.mjs +752 -733
  173. package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +700 -628
  174. package/src/runtime/agent/orchestrator/providers/gemini-thinking.mjs +39 -39
  175. package/src/runtime/agent/orchestrator/providers/gemini.mjs +1055 -1002
  176. package/src/runtime/agent/orchestrator/providers/grok-oauth-login.mjs +149 -127
  177. package/src/runtime/agent/orchestrator/providers/grok-oauth-tokens.mjs +325 -268
  178. package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +444 -397
  179. package/src/runtime/agent/orchestrator/providers/lib/action-input-contract.mjs +29 -25
  180. package/src/runtime/agent/orchestrator/providers/lib/anthropic-image-input.mjs +101 -89
  181. package/src/runtime/agent/orchestrator/providers/lib/anthropic-native-blocks.mjs +7 -8
  182. package/src/runtime/agent/orchestrator/providers/lib/anthropic-replay-blocks.mjs +37 -36
  183. package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +387 -394
  184. package/src/runtime/agent/orchestrator/providers/lib/gemini-model-catalog.mjs +96 -92
  185. package/src/runtime/agent/orchestrator/providers/lib/grok-tool-schema.mjs +200 -176
  186. package/src/runtime/agent/orchestrator/providers/lib/oauth-pkce.mjs +20 -20
  187. package/src/runtime/agent/orchestrator/providers/lib/oauth-token-utils.mjs +22 -20
  188. package/src/runtime/agent/orchestrator/providers/lib/openai-tool-args.mjs +41 -42
  189. package/src/runtime/agent/orchestrator/providers/lib/provider-replay.mjs +40 -34
  190. package/src/runtime/agent/orchestrator/providers/lib/sse-framing.mjs +39 -39
  191. package/src/runtime/agent/orchestrator/providers/lib/stream-outcome.mjs +119 -90
  192. package/src/runtime/agent/orchestrator/providers/lib/wire-pairing.mjs +87 -81
  193. package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +489 -421
  194. package/src/runtime/agent/orchestrator/providers/mixdog-local-wire.mjs +1 -3
  195. package/src/runtime/agent/orchestrator/providers/mixdog-local.mjs +24 -17
  196. package/src/runtime/agent/orchestrator/providers/model-cache.mjs +31 -23
  197. package/src/runtime/agent/orchestrator/providers/model-catalog-projection.mjs +106 -100
  198. package/src/runtime/agent/orchestrator/providers/model-catalog.mjs +562 -494
  199. package/src/runtime/agent/orchestrator/providers/model-list-sanitize.mjs +93 -39
  200. package/src/runtime/agent/orchestrator/providers/model-pricing-rates.mjs +50 -34
  201. package/src/runtime/agent/orchestrator/providers/model-service-tiers.mjs +8 -6
  202. package/src/runtime/agent/orchestrator/providers/oauth-credential-probes.mjs +117 -95
  203. package/src/runtime/agent/orchestrator/providers/oauth-usage.mjs +177 -147
  204. package/src/runtime/agent/orchestrator/providers/openai-codex-endpoints.mjs +1 -1
  205. package/src/runtime/agent/orchestrator/providers/openai-codex-metadata.mjs +186 -186
  206. package/src/runtime/agent/orchestrator/providers/openai-codex-model.mjs +80 -83
  207. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream.mjs +317 -295
  208. package/src/runtime/agent/orchestrator/providers/openai-compat-presets.mjs +20 -20
  209. package/src/runtime/agent/orchestrator/providers/openai-compat-responses.mjs +183 -167
  210. package/src/runtime/agent/orchestrator/providers/openai-compat-stream-common.mjs +113 -111
  211. package/src/runtime/agent/orchestrator/providers/openai-compat-stream.mjs +579 -498
  212. package/src/runtime/agent/orchestrator/providers/openai-compat-trace.mjs +41 -43
  213. package/src/runtime/agent/orchestrator/providers/openai-compat-wire.mjs +367 -352
  214. package/src/runtime/agent/orchestrator/providers/openai-compat-xai.mjs +549 -476
  215. package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +1132 -1106
  216. package/src/runtime/agent/orchestrator/providers/openai-direct-request.mjs +12 -12
  217. package/src/runtime/agent/orchestrator/providers/openai-oauth-catalog.mjs +81 -82
  218. package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +1122 -1049
  219. package/src/runtime/agent/orchestrator/providers/openai-oauth-login.mjs +137 -124
  220. package/src/runtime/agent/orchestrator/providers/openai-oauth-tokens.mjs +257 -200
  221. package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +1509 -1419
  222. package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +567 -564
  223. package/src/runtime/agent/orchestrator/providers/openai-responses-input.mjs +157 -158
  224. package/src/runtime/agent/orchestrator/providers/openai-responses-payload.mjs +197 -201
  225. package/src/runtime/agent/orchestrator/providers/openai-startup-prewarm.mjs +104 -100
  226. package/src/runtime/agent/orchestrator/providers/openai-transport-policy.mjs +76 -62
  227. package/src/runtime/agent/orchestrator/providers/openai-turn-state.mjs +37 -37
  228. package/src/runtime/agent/orchestrator/providers/openai-ws-delta.mjs +345 -336
  229. package/src/runtime/agent/orchestrator/providers/openai-ws-events.mjs +72 -66
  230. package/src/runtime/agent/orchestrator/providers/openai-ws-headers.mjs +92 -91
  231. package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +805 -665
  232. package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +1425 -1331
  233. package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +229 -239
  234. package/src/runtime/agent/orchestrator/providers/opencode-go-usage.mjs +46 -34
  235. package/src/runtime/agent/orchestrator/providers/opencode-go.mjs +132 -140
  236. package/src/runtime/agent/orchestrator/providers/provider-catalog-cache.mjs +19 -11
  237. package/src/runtime/agent/orchestrator/providers/provider-model-identities.mjs +30 -27
  238. package/src/runtime/agent/orchestrator/providers/registry.mjs +383 -354
  239. package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +644 -537
  240. package/src/runtime/agent/orchestrator/providers/stream-json-pool.mjs +592 -567
  241. package/src/runtime/agent/orchestrator/providers/stream-json-worker.mjs +37 -37
  242. package/src/runtime/agent/orchestrator/providers/tool-stream-state.mjs +43 -46
  243. package/src/runtime/agent/orchestrator/providers/trace-utils.mjs +30 -30
  244. package/src/runtime/agent/orchestrator/session/abort-lookup.mjs +6 -6
  245. package/src/runtime/agent/orchestrator/session/agent-loop.mjs +508 -469
  246. package/src/runtime/agent/orchestrator/session/browser-snapshot-supersession.mjs +2 -2
  247. package/src/runtime/agent/orchestrator/session/cache/prefetch-cache.mjs +112 -94
  248. package/src/runtime/agent/orchestrator/session/cache/read-cache.mjs +260 -243
  249. package/src/runtime/agent/orchestrator/session/cache/scoped-cache-outcome.mjs +3 -3
  250. package/src/runtime/agent/orchestrator/session/cache/scoped-cache.mjs +400 -316
  251. package/src/runtime/agent/orchestrator/session/cache/util.mjs +45 -34
  252. package/src/runtime/agent/orchestrator/session/compact/budget.mjs +96 -83
  253. package/src/runtime/agent/orchestrator/session/compact/constants.mjs +20 -17
  254. package/src/runtime/agent/orchestrator/session/compact/continuation.mjs +33 -40
  255. package/src/runtime/agent/orchestrator/session/compact/execution-tail.mjs +117 -110
  256. package/src/runtime/agent/orchestrator/session/compact/messages.mjs +119 -123
  257. package/src/runtime/agent/orchestrator/session/compact/runner.mjs +427 -448
  258. package/src/runtime/agent/orchestrator/session/compact/summary-schema.mjs +223 -222
  259. package/src/runtime/agent/orchestrator/session/compact/summary.mjs +433 -441
  260. package/src/runtime/agent/orchestrator/session/compact/text-utils.mjs +217 -195
  261. package/src/runtime/agent/orchestrator/session/compact.mjs +19 -19
  262. package/src/runtime/agent/orchestrator/session/context-compaction-policy.mjs +136 -132
  263. package/src/runtime/agent/orchestrator/session/context-fingerprint.mjs +65 -45
  264. package/src/runtime/agent/orchestrator/session/context-utils.mjs +700 -682
  265. package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +326 -292
  266. package/src/runtime/agent/orchestrator/session/evidence-union.mjs +454 -452
  267. package/src/runtime/agent/orchestrator/session/explicit-skills.mjs +48 -39
  268. package/src/runtime/agent/orchestrator/session/image-strip-recovery.mjs +96 -93
  269. package/src/runtime/agent/orchestrator/session/lifecycle-scan.mjs +105 -88
  270. package/src/runtime/agent/orchestrator/session/loop/arg-schema-coerce.mjs +61 -61
  271. package/src/runtime/agent/orchestrator/session/loop/assistant-commit.mjs +70 -66
  272. package/src/runtime/agent/orchestrator/session/loop/compact-debug.mjs +17 -11
  273. package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +585 -567
  274. package/src/runtime/agent/orchestrator/session/loop/completion-guards.mjs +26 -16
  275. package/src/runtime/agent/orchestrator/session/loop/context-overflow.mjs +60 -48
  276. package/src/runtime/agent/orchestrator/session/loop/deferred-call-through.mjs +60 -49
  277. package/src/runtime/agent/orchestrator/session/loop/diagnostics.mjs +54 -40
  278. package/src/runtime/agent/orchestrator/session/loop/fresh-context.mjs +157 -141
  279. package/src/runtime/agent/orchestrator/session/loop/hidden-agents.mjs +8 -6
  280. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn.mjs +242 -218
  281. package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +71 -73
  282. package/src/runtime/agent/orchestrator/session/loop/request-boundary.mjs +112 -94
  283. package/src/runtime/agent/orchestrator/session/loop/request-projection.mjs +93 -77
  284. package/src/runtime/agent/orchestrator/session/loop/steering.mjs +194 -181
  285. package/src/runtime/agent/orchestrator/session/loop/stored-tool-args.mjs +96 -91
  286. package/src/runtime/agent/orchestrator/session/loop/termination.mjs +37 -44
  287. package/src/runtime/agent/orchestrator/session/loop/tool-classify.mjs +102 -83
  288. package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +353 -309
  289. package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +175 -168
  290. package/src/runtime/agent/orchestrator/session/loop/transcript-repair.mjs +75 -72
  291. package/src/runtime/agent/orchestrator/session/loop/usage.mjs +59 -53
  292. package/src/runtime/agent/orchestrator/session/loop.mjs +9 -9
  293. package/src/runtime/agent/orchestrator/session/manager/agent-runtime-singleton.mjs +5 -5
  294. package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +1382 -1303
  295. package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +426 -388
  296. package/src/runtime/agent/orchestrator/session/manager/context-meta.mjs +180 -179
  297. package/src/runtime/agent/orchestrator/session/manager/delivered-completions.mjs +60 -55
  298. package/src/runtime/agent/orchestrator/session/manager/foreign-pending-messages.mjs +324 -316
  299. package/src/runtime/agent/orchestrator/session/manager/idle-cleanup.mjs +136 -125
  300. package/src/runtime/agent/orchestrator/session/manager/message-sanitize.mjs +112 -112
  301. package/src/runtime/agent/orchestrator/session/manager/pending-message-entry.mjs +242 -233
  302. package/src/runtime/agent/orchestrator/session/manager/pending-messages.mjs +1048 -951
  303. package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge.mjs +214 -198
  304. package/src/runtime/agent/orchestrator/session/manager/prompt-utils.mjs +152 -148
  305. package/src/runtime/agent/orchestrator/session/manager/provider-cache-key.mjs +17 -17
  306. package/src/runtime/agent/orchestrator/session/manager/rules-cache.mjs +80 -58
  307. package/src/runtime/agent/orchestrator/session/manager/rules-source-cache.mjs +48 -48
  308. package/src/runtime/agent/orchestrator/session/manager/runtime-liveness.mjs +392 -389
  309. package/src/runtime/agent/orchestrator/session/manager/runtime-loaders.mjs +10 -10
  310. package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +212 -169
  311. package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +323 -300
  312. package/src/runtime/agent/orchestrator/session/manager/session-errors.mjs +12 -12
  313. package/src/runtime/agent/orchestrator/session/manager/session-id.mjs +49 -52
  314. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +786 -795
  315. package/src/runtime/agent/orchestrator/session/manager/session-lock.mjs +54 -51
  316. package/src/runtime/agent/orchestrator/session/manager/status-telemetry.mjs +77 -71
  317. package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +173 -182
  318. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-context.mjs +171 -171
  319. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.mjs +392 -385
  320. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +175 -172
  321. package/src/runtime/agent/orchestrator/session/manager/turn-interruption.mjs +388 -399
  322. package/src/runtime/agent/orchestrator/session/manager/usage-metrics.mjs +371 -352
  323. package/src/runtime/agent/orchestrator/session/manager.mjs +60 -60
  324. package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +485 -430
  325. package/src/runtime/agent/orchestrator/session/provider-prefix-guard.mjs +144 -145
  326. package/src/runtime/agent/orchestrator/session/reduction-metrics.mjs +102 -104
  327. package/src/runtime/agent/orchestrator/session/result-classification.mjs +37 -38
  328. package/src/runtime/agent/orchestrator/session/save-session-worker.mjs +76 -70
  329. package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +680 -643
  330. package/src/runtime/agent/orchestrator/session/store/canonical-reader.mjs +49 -48
  331. package/src/runtime/agent/orchestrator/session/store/fs-probe.mjs +24 -24
  332. package/src/runtime/agent/orchestrator/session/store/listing.mjs +722 -655
  333. package/src/runtime/agent/orchestrator/session/store/live-state.mjs +104 -104
  334. package/src/runtime/agent/orchestrator/session/store/load-cache.mjs +124 -124
  335. package/src/runtime/agent/orchestrator/session/store/paths-heartbeat.mjs +119 -100
  336. package/src/runtime/agent/orchestrator/session/store/save-fault.mjs +147 -141
  337. package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +711 -615
  338. package/src/runtime/agent/orchestrator/session/store/serialize.mjs +96 -91
  339. package/src/runtime/agent/orchestrator/session/store/summary-cache.mjs +159 -154
  340. package/src/runtime/agent/orchestrator/session/store/summary-rebuild-worker.mjs +12 -12
  341. package/src/runtime/agent/orchestrator/session/store/write-guards.mjs +86 -86
  342. package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +291 -272
  343. package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +904 -897
  344. package/src/runtime/agent/orchestrator/session/store-summary-visibility.mjs +26 -28
  345. package/src/runtime/agent/orchestrator/session/store-transcript-cache.mjs +93 -93
  346. package/src/runtime/agent/orchestrator/session/store.mjs +897 -842
  347. package/src/runtime/agent/orchestrator/session/synthetic-user-envelope.mjs +71 -76
  348. package/src/runtime/agent/orchestrator/session/task-wait-control.mjs +9 -3
  349. package/src/runtime/agent/orchestrator/session/thinking-replay-recovery.mjs +55 -58
  350. package/src/runtime/agent/orchestrator/session/token-estimate-floors.mjs +25 -24
  351. package/src/runtime/agent/orchestrator/session/token-estimate.mjs +42 -42
  352. package/src/runtime/agent/orchestrator/session/tool-batch.mjs +989 -918
  353. package/src/runtime/agent/orchestrator/session/tool-envelope.mjs +25 -32
  354. package/src/runtime/agent/orchestrator/session/tool-result-offload.mjs +390 -369
  355. package/src/runtime/agent/orchestrator/stall-policy.mjs +184 -180
  356. package/src/runtime/agent/orchestrator/tool-loop-guard.mjs +4 -3
  357. package/src/runtime/agent/orchestrator/tools/bash-policy-scan.mjs +7 -6
  358. package/src/runtime/agent/orchestrator/tools/builtin/advisory-lock.mjs +166 -153
  359. package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +859 -795
  360. package/src/runtime/agent/orchestrator/tools/builtin/atomic-write.mjs +234 -184
  361. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +772 -722
  362. package/src/runtime/agent/orchestrator/tools/builtin/binary-file.mjs +83 -80
  363. package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +336 -231
  364. package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +444 -408
  365. package/src/runtime/agent/orchestrator/tools/builtin/device-paths.mjs +152 -103
  366. package/src/runtime/agent/orchestrator/tools/builtin/diff-utils.mjs +104 -90
  367. package/src/runtime/agent/orchestrator/tools/builtin/external-tool-adapters.mjs +559 -498
  368. package/src/runtime/agent/orchestrator/tools/builtin/fs-reachability.mjs +49 -42
  369. package/src/runtime/agent/orchestrator/tools/builtin/git-command-policy.mjs +169 -100
  370. package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.mjs +1072 -793
  371. package/src/runtime/agent/orchestrator/tools/builtin/git-partial-stage.mjs +215 -209
  372. package/src/runtime/agent/orchestrator/tools/builtin/git-repo-rw-lock.mjs +66 -66
  373. package/src/runtime/agent/orchestrator/tools/builtin/glob-walk.mjs +212 -173
  374. package/src/runtime/agent/orchestrator/tools/builtin/grep-formatting.mjs +114 -111
  375. package/src/runtime/agent/orchestrator/tools/builtin/hash-utils.mjs +4 -2
  376. package/src/runtime/agent/orchestrator/tools/builtin/lib/absolute-glob-expand.mjs +98 -86
  377. package/src/runtime/agent/orchestrator/tools/builtin/lib/glob-static-prefix.mjs +91 -91
  378. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-chunk-merge.mjs +100 -101
  379. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-context-expander.mjs +456 -461
  380. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-output.mjs +229 -182
  381. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-path-fanout.mjs +240 -238
  382. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-pattern-fanout.mjs +350 -323
  383. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-single-file-rescue.mjs +201 -162
  384. package/src/runtime/agent/orchestrator/tools/builtin/lib/list-helpers.mjs +22 -25
  385. package/src/runtime/agent/orchestrator/tools/builtin/lib/search-grep-chunks.mjs +124 -125
  386. package/src/runtime/agent/orchestrator/tools/builtin/lib/search-input-helpers.mjs +39 -43
  387. package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-job-insights.mjs +75 -69
  388. package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-job-records.mjs +221 -194
  389. package/src/runtime/agent/orchestrator/tools/builtin/list-formatting.mjs +6 -6
  390. package/src/runtime/agent/orchestrator/tools/builtin/list-tool.mjs +894 -868
  391. package/src/runtime/agent/orchestrator/tools/builtin/local-search-telemetry.mjs +52 -50
  392. package/src/runtime/agent/orchestrator/tools/builtin/native-search-client.mjs +128 -114
  393. package/src/runtime/agent/orchestrator/tools/builtin/native-search-runner.mjs +36 -34
  394. package/src/runtime/agent/orchestrator/tools/builtin/native-search-transport.mjs +35 -7
  395. package/src/runtime/agent/orchestrator/tools/builtin/path-diagnostics.mjs +217 -179
  396. package/src/runtime/agent/orchestrator/tools/builtin/path-locks.mjs +28 -23
  397. package/src/runtime/agent/orchestrator/tools/builtin/path-utils.mjs +239 -216
  398. package/src/runtime/agent/orchestrator/tools/builtin/read-args.mjs +52 -52
  399. package/src/runtime/agent/orchestrator/tools/builtin/read-batch.mjs +228 -217
  400. package/src/runtime/agent/orchestrator/tools/builtin/read-formatting.mjs +60 -61
  401. package/src/runtime/agent/orchestrator/tools/builtin/read-image-resize.mjs +217 -202
  402. package/src/runtime/agent/orchestrator/tools/builtin/read-image.mjs +29 -19
  403. package/src/runtime/agent/orchestrator/tools/builtin/read-lines.mjs +7 -7
  404. package/src/runtime/agent/orchestrator/tools/builtin/read-mode-tool.mjs +406 -368
  405. package/src/runtime/agent/orchestrator/tools/builtin/read-office-files.mjs +479 -417
  406. package/src/runtime/agent/orchestrator/tools/builtin/read-open.mjs +157 -148
  407. package/src/runtime/agent/orchestrator/tools/builtin/read-range-index.mjs +237 -214
  408. package/src/runtime/agent/orchestrator/tools/builtin/read-ranges.mjs +24 -23
  409. package/src/runtime/agent/orchestrator/tools/builtin/read-single-tool.mjs +807 -739
  410. package/src/runtime/agent/orchestrator/tools/builtin/read-snapshot-runtime.mjs +181 -185
  411. package/src/runtime/agent/orchestrator/tools/builtin/read-source-windows.mjs +76 -71
  412. package/src/runtime/agent/orchestrator/tools/builtin/read-special-files.mjs +231 -191
  413. package/src/runtime/agent/orchestrator/tools/builtin/read-streaming.mjs +553 -538
  414. package/src/runtime/agent/orchestrator/tools/builtin/read-tool.mjs +670 -607
  415. package/src/runtime/agent/orchestrator/tools/builtin/read-windows.mjs +111 -111
  416. package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.mjs +183 -180
  417. package/src/runtime/agent/orchestrator/tools/builtin/search-admission.mjs +7 -16
  418. package/src/runtime/agent/orchestrator/tools/builtin/search-builders.mjs +222 -203
  419. package/src/runtime/agent/orchestrator/tools/builtin/search-glob-tool.mjs +466 -438
  420. package/src/runtime/agent/orchestrator/tools/builtin/search-grep-tool.mjs +730 -718
  421. package/src/runtime/agent/orchestrator/tools/builtin/search-path-diagnostics.mjs +194 -163
  422. package/src/runtime/agent/orchestrator/tools/builtin/search-tool.mjs +8 -8
  423. package/src/runtime/agent/orchestrator/tools/builtin/shell-analysis.mjs +834 -770
  424. package/src/runtime/agent/orchestrator/tools/builtin/shell-direct-exe.mjs +209 -136
  425. package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +417 -384
  426. package/src/runtime/agent/orchestrator/tools/builtin/shell-lossless-compact.mjs +315 -318
  427. package/src/runtime/agent/orchestrator/tools/builtin/shell-output.mjs +67 -68
  428. package/src/runtime/agent/orchestrator/tools/builtin/shell-runtime.mjs +171 -156
  429. package/src/runtime/agent/orchestrator/tools/builtin/snapshot-helpers.mjs +103 -100
  430. package/src/runtime/agent/orchestrator/tools/builtin/snapshot-store.mjs +277 -253
  431. package/src/runtime/agent/orchestrator/tools/builtin/snapshot-validation.mjs +86 -85
  432. package/src/runtime/agent/orchestrator/tools/builtin/task-tool.mjs +226 -230
  433. package/src/runtime/agent/orchestrator/tools/builtin/text-stats.mjs +59 -57
  434. package/src/runtime/agent/orchestrator/tools/builtin/tool-output-limit.mjs +31 -34
  435. package/src/runtime/agent/orchestrator/tools/builtin/windows-roots.mjs +3 -3
  436. package/src/runtime/agent/orchestrator/tools/builtin.mjs +384 -411
  437. package/src/runtime/agent/orchestrator/tools/code-graph/aggregate-roots.mjs +68 -30
  438. package/src/runtime/agent/orchestrator/tools/code-graph/ast-calls.mjs +304 -0
  439. package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +259 -153
  440. package/src/runtime/agent/orchestrator/tools/code-graph/calls-cache.mjs +109 -0
  441. package/src/runtime/agent/orchestrator/tools/code-graph/constants.mjs +98 -6
  442. package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +206 -69
  443. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +536 -269
  444. package/src/runtime/agent/orchestrator/tools/code-graph/exact-file-graph.mjs +6 -4
  445. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary.mjs +450 -182
  446. package/src/runtime/agent/orchestrator/tools/code-graph/graph-model.mjs +25 -8
  447. package/src/runtime/agent/orchestrator/tools/code-graph/keyword-match.mjs +10 -3
  448. package/src/runtime/agent/orchestrator/tools/code-graph/lang-predicates.mjs +60 -26
  449. package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.mjs +6 -14
  450. package/src/runtime/agent/orchestrator/tools/code-graph/project-root.mjs +31 -10
  451. package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +290 -100
  452. package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +422 -511
  453. package/src/runtime/agent/orchestrator/tools/code-graph/source-access.mjs +11 -3
  454. package/src/runtime/agent/orchestrator/tools/code-graph/span.mjs +1 -1
  455. package/src/runtime/agent/orchestrator/tools/code-graph/symbol-index.mjs +148 -259
  456. package/src/runtime/agent/orchestrator/tools/code-graph/text-columns.mjs +79 -34
  457. package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.mjs +20 -9
  458. package/src/runtime/agent/orchestrator/tools/code-graph/trusted-roots.mjs +23 -18
  459. package/src/runtime/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +4 -9
  460. package/src/runtime/agent/orchestrator/tools/code-graph-state.mjs +1 -3
  461. package/src/runtime/agent/orchestrator/tools/code-graph-tool-defs.mjs +49 -7
  462. package/src/runtime/agent/orchestrator/tools/destructive-warning.mjs +247 -52
  463. package/src/runtime/agent/orchestrator/tools/env-scrub.mjs +93 -91
  464. package/src/runtime/agent/orchestrator/tools/graph-binary-fetcher.mjs +6 -5
  465. package/src/runtime/agent/orchestrator/tools/graph-manifest.json +11 -11
  466. package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.mjs +125 -81
  467. package/src/runtime/agent/orchestrator/tools/lib/shell-descendants.mjs +10 -3
  468. package/src/runtime/agent/orchestrator/tools/lib/shell-spawn-retry.mjs +18 -13
  469. package/src/runtime/agent/orchestrator/tools/lib/shell-warm-standby.mjs +123 -105
  470. package/src/runtime/agent/orchestrator/tools/next-call-utils.mjs +5 -2
  471. package/src/runtime/agent/orchestrator/tools/patch/dispatch.mjs +85 -53
  472. package/src/runtime/agent/orchestrator/tools/patch/matcher.mjs +109 -86
  473. package/src/runtime/agent/orchestrator/tools/patch/native-server.mjs +158 -70
  474. package/src/runtime/agent/orchestrator/tools/patch/orchestrator.mjs +287 -213
  475. package/src/runtime/agent/orchestrator/tools/patch/parsing.mjs +30 -17
  476. package/src/runtime/agent/orchestrator/tools/patch/paths.mjs +31 -23
  477. package/src/runtime/agent/orchestrator/tools/patch/v4a-anchors.mjs +17 -16
  478. package/src/runtime/agent/orchestrator/tools/patch/v4a-convert.mjs +71 -71
  479. package/src/runtime/agent/orchestrator/tools/patch/v4a-windows.mjs +23 -19
  480. package/src/runtime/agent/orchestrator/tools/patch-binary-fetcher.mjs +7 -7
  481. package/src/runtime/agent/orchestrator/tools/patch-tool-defs.mjs +11 -5
  482. package/src/runtime/agent/orchestrator/tools/patch.mjs +7 -1
  483. package/src/runtime/agent/orchestrator/tools/progress-message.mjs +83 -85
  484. package/src/runtime/agent/orchestrator/tools/shell-command.mjs +258 -148
  485. package/src/runtime/agent/orchestrator/tools/shell-exec-output.mjs +39 -29
  486. package/src/runtime/agent/orchestrator/tools/shell-exec-policy.mjs +23 -12
  487. package/src/runtime/agent/orchestrator/tools/shell-policy-danger-target.mjs +29 -8
  488. package/src/runtime/agent/orchestrator/tools/shell-policy.mjs +77 -33
  489. package/src/runtime/agent/orchestrator/tools/shell-powershell.mjs +12 -13
  490. package/src/runtime/agent/orchestrator/tools/shell-snapshot.mjs +112 -101
  491. package/src/runtime/agent/orchestrator/tools/spawn-binary-fetcher.mjs +2 -2
  492. package/src/runtime/agent/orchestrator/tools/tool-batch-trace.mjs +32 -27
  493. package/src/runtime/attachments/pdf-extract.mjs +28 -14
  494. package/src/runtime/attachments/pdfjs-runtime.mjs +3 -1
  495. package/src/runtime/attachments/store.mjs +66 -62
  496. package/src/runtime/bridge-discovery.mjs +7 -7
  497. package/src/runtime/browser-bridge/action-schema.d.mts +5 -4
  498. package/src/runtime/browser-bridge/action-schema.mjs +168 -134
  499. package/src/runtime/browser-bridge/browser-action-contract.mjs +75 -15
  500. package/src/runtime/browser-bridge/client.mjs +40 -39
  501. package/src/runtime/browser-bridge/input-fields.mjs +269 -50
  502. package/src/runtime/browser-bridge/timing.mjs +9 -5
  503. package/src/runtime/browser-bridge/tool-defs.mjs +20 -20
  504. package/src/runtime/channels/index.mjs +2 -2
  505. package/src/runtime/channels/lib/boot-profile.mjs +3 -3
  506. package/src/runtime/channels/lib/cli-worker-host.mjs +2 -5
  507. package/src/runtime/channels/lib/config.mjs +36 -54
  508. package/src/runtime/channels/lib/crash-log.mjs +48 -29
  509. package/src/runtime/channels/lib/event-pipeline.mjs +19 -19
  510. package/src/runtime/channels/lib/event-queue.mjs +63 -52
  511. package/src/runtime/channels/lib/executor.mjs +58 -61
  512. package/src/runtime/channels/lib/index-drop-trace.mjs +44 -24
  513. package/src/runtime/channels/lib/network-retry.mjs +8 -7
  514. package/src/runtime/channels/lib/owned-runtime.mjs +410 -376
  515. package/src/runtime/channels/lib/owner-heartbeat.mjs +1 -1
  516. package/src/runtime/channels/lib/parent-bridge.mjs +39 -17
  517. package/src/runtime/channels/lib/runtime-paths.mjs +202 -169
  518. package/src/runtime/channels/lib/scheduler.mjs +166 -128
  519. package/src/runtime/channels/lib/settings.mjs +3 -5
  520. package/src/runtime/channels/lib/state-file.mjs +7 -14
  521. package/src/runtime/channels/lib/status-snapshot.mjs +17 -17
  522. package/src/runtime/channels/lib/tool-dispatch.mjs +71 -65
  523. package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +444 -374
  524. package/src/runtime/channels/lib/voice-transcription.mjs +101 -40
  525. package/src/runtime/channels/lib/webhook/deliveries.mjs +10 -11
  526. package/src/runtime/channels/lib/webhook/log.mjs +13 -12
  527. package/src/runtime/channels/lib/webhook/relay-tunnel.mjs +199 -110
  528. package/src/runtime/channels/lib/webhook/signature.mjs +14 -14
  529. package/src/runtime/channels/lib/webhook.mjs +173 -132
  530. package/src/runtime/channels/lib/whisper-language.mjs +19 -18
  531. package/src/runtime/channels/lib/whisper-port.mjs +20 -12
  532. package/src/runtime/channels/lib/whisper-server.mjs +135 -75
  533. package/src/runtime/channels/lib/worker-bootstrap.mjs +94 -78
  534. package/src/runtime/channels/lib/worker-ipc.mjs +92 -73
  535. package/src/runtime/channels/lib/worker-main.mjs +106 -79
  536. package/src/runtime/computer-bridge/action-schema.mjs +206 -142
  537. package/src/runtime/computer-bridge/actions.d.mts +3 -1
  538. package/src/runtime/computer-bridge/actions.mjs +49 -6
  539. package/src/runtime/computer-bridge/capture-size.d.mts +5 -0
  540. package/src/runtime/computer-bridge/capture-size.mjs +20 -0
  541. package/src/runtime/computer-bridge/client.mjs +171 -77
  542. package/src/runtime/computer-bridge/core-actions.mjs +33 -21
  543. package/src/runtime/computer-bridge/error-code.d.mts +1 -0
  544. package/src/runtime/computer-bridge/error-code.mjs +5 -0
  545. package/src/runtime/computer-bridge/error-recovery.mjs +82 -29
  546. package/src/runtime/computer-bridge/limits.mjs +17 -6
  547. package/src/runtime/computer-bridge/pending-continuation.mjs +79 -32
  548. package/src/runtime/computer-bridge/tool-defs.mjs +2 -5
  549. package/src/runtime/github/client.d.mts +5 -1
  550. package/src/runtime/github/client.mjs +80 -43
  551. package/src/runtime/github/commands.mjs +72 -31
  552. package/src/runtime/github/contract.d.mts +45 -11
  553. package/src/runtime/github/contract.mjs +62 -27
  554. package/src/runtime/github/tool.mjs +29 -7
  555. package/src/runtime/local-provider/asset-installer.mjs +66 -46
  556. package/src/runtime/local-provider/asset-storage.mjs +3 -1
  557. package/src/runtime/local-provider/catalog.mjs +20 -23
  558. package/src/runtime/local-provider/context-settings.mjs +2 -2
  559. package/src/runtime/local-provider/gguf-header.mjs +69 -18
  560. package/src/runtime/local-provider/hardware.mjs +84 -31
  561. package/src/runtime/local-provider/hugging-face.mjs +108 -33
  562. package/src/runtime/local-provider/input-capabilities.mjs +16 -5
  563. package/src/runtime/local-provider/install-progress.mjs +42 -17
  564. package/src/runtime/local-provider/model-maintenance.mjs +79 -35
  565. package/src/runtime/local-provider/model-state.mjs +21 -8
  566. package/src/runtime/local-provider/registered-models.mjs +23 -13
  567. package/src/runtime/local-provider/request-queue.mjs +31 -10
  568. package/src/runtime/local-provider/resumable-installations.mjs +25 -7
  569. package/src/runtime/local-provider/server-process.mjs +42 -16
  570. package/src/runtime/local-provider/server.mjs +63 -47
  571. package/src/runtime/media/adapters/antigravity-image.mjs +5 -4
  572. package/src/runtime/media/adapters/codex-image.mjs +24 -9
  573. package/src/runtime/media/adapters/gemini-image.mjs +17 -16
  574. package/src/runtime/media/adapters/gemini-video.mjs +4 -5
  575. package/src/runtime/media/adapters/xai-media.mjs +5 -1
  576. package/src/runtime/media/catalog-errors.mjs +5 -2
  577. package/src/runtime/media/catalog.mjs +77 -55
  578. package/src/runtime/media/download.mjs +12 -31
  579. package/src/runtime/media/jobs.mjs +17 -19
  580. package/src/runtime/media/lanes.mjs +24 -12
  581. package/src/runtime/media/renditions.mjs +94 -63
  582. package/src/runtime/media/store.mjs +8 -21
  583. package/src/runtime/media/tool-defs.mjs +38 -12
  584. package/src/runtime/media/tool.mjs +118 -31
  585. package/src/runtime/media/upstream-error.mjs +5 -1
  586. package/src/runtime/memory/data/runtime-manifest.json +3 -3
  587. package/src/runtime/memory/index.mjs +336 -316
  588. package/src/runtime/memory/lib/agent-ipc.mjs +122 -100
  589. package/src/runtime/memory/lib/compact-handoff.mjs +76 -74
  590. package/src/runtime/memory/lib/compact-vector-cache.mjs +34 -37
  591. package/src/runtime/memory/lib/core-memory-file.mjs +87 -111
  592. package/src/runtime/memory/lib/core-memory-index.mjs +57 -47
  593. package/src/runtime/memory/lib/core-memory-management.mjs +62 -0
  594. package/src/runtime/memory/lib/core-memory-store.mjs +223 -481
  595. package/src/runtime/memory/lib/core-memory-uniqueness.mjs +44 -0
  596. package/src/runtime/memory/lib/cycle-llm-adapters.mjs +12 -11
  597. package/src/runtime/memory/lib/cycle-scheduler.mjs +294 -332
  598. package/src/runtime/memory/lib/cycle-signatures.mjs +3 -17
  599. package/src/runtime/memory/lib/embedding-cache-retention.mjs +21 -31
  600. package/src/runtime/memory/lib/embedding-model-cache-compression.mjs +21 -33
  601. package/src/runtime/memory/lib/embedding-model-config.mjs +25 -26
  602. package/src/runtime/memory/lib/embedding-provider.mjs +230 -200
  603. package/src/runtime/memory/lib/embedding-reindex.mjs +30 -30
  604. package/src/runtime/memory/lib/embedding-worker.mjs +324 -248
  605. package/src/runtime/memory/lib/history-duplicates.mjs +11 -0
  606. package/src/runtime/memory/lib/http-router.mjs +359 -327
  607. package/src/runtime/memory/lib/http-wire.mjs +22 -22
  608. package/src/runtime/memory/lib/light-ko-morph.mjs +100 -41
  609. package/src/runtime/memory/lib/llm-worker-host.mjs +2 -4
  610. package/src/runtime/memory/lib/memory-action-handlers.mjs +364 -585
  611. package/src/runtime/memory/lib/memory-chunk-audit.mjs +26 -20
  612. package/src/runtime/memory/lib/memory-chunk-quality.mjs +314 -225
  613. package/src/runtime/memory/lib/memory-config-flags.mjs +27 -29
  614. package/src/runtime/memory/lib/memory-cycle-requests.mjs +125 -108
  615. package/src/runtime/memory/lib/memory-cycle.mjs +9 -10
  616. package/src/runtime/memory/lib/memory-cycle1.mjs +445 -355
  617. package/src/runtime/memory/lib/memory-cycle2-mutations.mjs +103 -624
  618. package/src/runtime/memory/lib/memory-cycle2-review.mjs +232 -0
  619. package/src/runtime/memory/lib/memory-cycle2-shared.mjs +36 -43
  620. package/src/runtime/memory/lib/memory-cycle2.mjs +132 -838
  621. package/src/runtime/memory/lib/memory-daemon-lifecycle.mjs +65 -57
  622. package/src/runtime/memory/lib/memory-embed.mjs +329 -292
  623. package/src/runtime/memory/lib/memory-extraction.mjs +4 -4
  624. package/src/runtime/memory/lib/memory-fingerprint.mjs +54 -0
  625. package/src/runtime/memory/lib/memory-maintenance-store.mjs +13 -11
  626. package/src/runtime/memory/lib/memory-ops-policy.mjs +114 -89
  627. package/src/runtime/memory/lib/memory-port-advertiser.mjs +55 -44
  628. package/src/runtime/memory/lib/memory-process-lock.mjs +61 -46
  629. package/src/runtime/memory/lib/memory-recall-id-patch.mjs +7 -7
  630. package/src/runtime/memory/lib/memory-recall-read-query.mjs +4 -4
  631. package/src/runtime/memory/lib/memory-recall-scope-filter.mjs +61 -68
  632. package/src/runtime/memory/lib/memory-recall-store.mjs +322 -406
  633. package/src/runtime/memory/lib/memory-retrievers.mjs +94 -68
  634. package/src/runtime/memory/lib/memory-score.mjs +21 -18
  635. package/src/runtime/memory/lib/memory-service-lifecycle.mjs +70 -62
  636. package/src/runtime/memory/lib/memory-session-merge.mjs +21 -15
  637. package/src/runtime/memory/lib/memory-text-utils.mjs +146 -83
  638. package/src/runtime/memory/lib/memory.mjs +275 -332
  639. package/src/runtime/memory/lib/pg/adapter.mjs +214 -199
  640. package/src/runtime/memory/lib/pg/compact-indexes.mjs +78 -59
  641. package/src/runtime/memory/lib/pg/process.mjs +434 -300
  642. package/src/runtime/memory/lib/pg/supervisor.mjs +217 -131
  643. package/src/runtime/memory/lib/project-id-resolver.mjs +1 -1
  644. package/src/runtime/memory/lib/query-handlers.mjs +568 -498
  645. package/src/runtime/memory/lib/query-maintenance-handlers.mjs +98 -67
  646. package/src/runtime/memory/lib/query-ranking.mjs +218 -170
  647. package/src/runtime/memory/lib/recall-embedding-readiness.mjs +35 -45
  648. package/src/runtime/memory/lib/recall-event-context.mjs +81 -72
  649. package/src/runtime/memory/lib/recall-format.mjs +293 -259
  650. package/src/runtime/memory/lib/recall-fusion.mjs +20 -28
  651. package/src/runtime/memory/lib/recall-limits.mjs +4 -0
  652. package/src/runtime/memory/lib/recall-order.mjs +12 -12
  653. package/src/runtime/memory/lib/recall-page-cursor.mjs +17 -17
  654. package/src/runtime/memory/lib/recall-scoring.mjs +25 -40
  655. package/src/runtime/memory/lib/recall-substring-predicate.mjs +2 -2
  656. package/src/runtime/memory/lib/runtime-fetcher.mjs +253 -215
  657. package/src/runtime/memory/lib/session-ingest-runtime.mjs +177 -155
  658. package/src/runtime/memory/lib/session-ingest.mjs +163 -141
  659. package/src/runtime/memory/lib/tool-call-handler.mjs +27 -18
  660. package/src/runtime/memory/lib/trace-mode.mjs +30 -34
  661. package/src/runtime/memory/lib/trace-store.mjs +506 -381
  662. package/src/runtime/memory/lib/transcript-ingest.mjs +253 -203
  663. package/src/runtime/memory/tool-defs.mjs +105 -23
  664. package/src/runtime/office/authoring/pptx-author-action.mjs +20 -11
  665. package/src/runtime/office/authoring/pptx-author-session.mjs +20 -18
  666. package/src/runtime/office/authoring/pptx-brief.mjs +80 -22
  667. package/src/runtime/office/authoring/pptx-contact-sheet.mjs +9 -2
  668. package/src/runtime/office/authoring/pptx-icons.json +265 -1
  669. package/src/runtime/office/authoring/pptx-icons.mjs +19 -9
  670. package/src/runtime/office/authoring/pptx-receipt.mjs +262 -82
  671. package/src/runtime/office/authoring/pptx-script-contract.mjs +5 -3
  672. package/src/runtime/office/authoring/pptx-script-normalize.mjs +85 -34
  673. package/src/runtime/office/authoring/pptx-script-runner.mjs +53 -14
  674. package/src/runtime/office/bench/assurance-benchmark.mjs +204 -144
  675. package/src/runtime/office/bench/benchmark.mjs +162 -101
  676. package/src/runtime/office/bench/contract-benchmark.mjs +2 -1
  677. package/src/runtime/office/bench/deck-bench.mjs +11 -3
  678. package/src/runtime/office/bench/polish-benchmark.mjs +240 -120
  679. package/src/runtime/office/bench/quality-live-benchmark.mjs +234 -133
  680. package/src/runtime/office/capabilities.mjs +1031 -243
  681. package/src/runtime/office/com/com-adapter.mjs +108 -70
  682. package/src/runtime/office/com/office-com-cleanup.ps1 +125 -116
  683. package/src/runtime/office/com/office-com-session-host.ps1 +820 -783
  684. package/src/runtime/office/com/office-session-client.mjs +36 -16
  685. package/src/runtime/office/com/office-word-formatting.ps1 +23 -23
  686. package/src/runtime/office/core/journal.mjs +2 -13
  687. package/src/runtime/office/core/office-actions-batch.mjs +156 -107
  688. package/src/runtime/office/core/office-actions-inspect.mjs +110 -85
  689. package/src/runtime/office/core/office-actions-lifecycle.mjs +54 -43
  690. package/src/runtime/office/core/office-actions-open.mjs +61 -46
  691. package/src/runtime/office/core/office-actions-read.mjs +18 -17
  692. package/src/runtime/office/core/office-actions-render.mjs +75 -72
  693. package/src/runtime/office/core/office-core.mjs +88 -98
  694. package/src/runtime/office/core/office-documents.mjs +18 -12
  695. package/src/runtime/office/core/office-recalculation.mjs +9 -5
  696. package/src/runtime/office/core/office-render-preview.mjs +90 -44
  697. package/src/runtime/office/core/office-sessions.mjs +183 -111
  698. package/src/runtime/office/core/office-transactions.mjs +73 -60
  699. package/src/runtime/office/core/pagination.mjs +36 -32
  700. package/src/runtime/office/core/pptx-page-cache.mjs +37 -17
  701. package/src/runtime/office/core/snapshot-contract.mjs +18 -11
  702. package/src/runtime/office/core/tabular.mjs +71 -42
  703. package/src/runtime/office/design/composition-system.mjs +155 -77
  704. package/src/runtime/office/design/content-model.mjs +11 -7
  705. package/src/runtime/office/design/design-art-direction.mjs +43 -38
  706. package/src/runtime/office/design/design-creative-director.mjs +12 -17
  707. package/src/runtime/office/design/design-discipline.mjs +50 -30
  708. package/src/runtime/office/design/design-system.mjs +10 -4
  709. package/src/runtime/office/design/design-tokens.mjs +81 -76
  710. package/src/runtime/office/design/docx/design-docx-components.mjs +21 -31
  711. package/src/runtime/office/design/docx/design-docx.mjs +25 -21
  712. package/src/runtime/office/design/docx/document-typography.mjs +2 -1
  713. package/src/runtime/office/design/library/design-library-core.mjs +15 -29
  714. package/src/runtime/office/design/library/design-library-pack.mjs +86 -63
  715. package/src/runtime/office/design/library/design-library.mjs +49 -68
  716. package/src/runtime/office/design/library/design-template-index.mjs +45 -47
  717. package/src/runtime/office/design/library/design-template-inspect.mjs +73 -85
  718. package/src/runtime/office/design/library/templates/mixdog-executive.pptx.mixdog.json +89 -10
  719. package/src/runtime/office/design/xlsx/design-xlsx-components.mjs +31 -43
  720. package/src/runtime/office/design/xlsx/design-xlsx.mjs +85 -91
  721. package/src/runtime/office/index.mjs +81 -47
  722. package/src/runtime/office/office-test-support.mjs +4 -4
  723. package/src/runtime/office/pdf/document-preview.mjs +30 -20
  724. package/src/runtime/office/pdf/pdf-adapter.mjs +258 -93
  725. package/src/runtime/office/pdf/pdf-analysis.mjs +130 -72
  726. package/src/runtime/office/pdf/pdf-draw.mjs +12 -6
  727. package/src/runtime/office/pdf/pdf-fonts.mjs +30 -23
  728. package/src/runtime/office/pdf/pdf-forms.mjs +47 -15
  729. package/src/runtime/office/pdf/pdf-render.mjs +57 -65
  730. package/src/runtime/office/pdf/pdf-safety.mjs +10 -13
  731. package/src/runtime/office/pdf/pdf-search.mjs +33 -24
  732. package/src/runtime/office/pdf/pdf-security.mjs +16 -17
  733. package/src/runtime/office/pdf/pdf-writer.mjs +184 -70
  734. package/src/runtime/office/portable/docx-formatting.mjs +27 -10
  735. package/src/runtime/office/portable/docx-revisions.mjs +75 -35
  736. package/src/runtime/office/portable/docx-runs.mjs +53 -21
  737. package/src/runtime/office/portable/docx-tracked-edits.mjs +12 -5
  738. package/src/runtime/office/portable/font-provisioner.mjs +11 -9
  739. package/src/runtime/office/portable/image-layout.mjs +7 -5
  740. package/src/runtime/office/portable/ooxml-validator.mjs +61 -44
  741. package/src/runtime/office/portable/portable-cells.mjs +33 -35
  742. package/src/runtime/office/portable/portable-chart-faults.mjs +30 -16
  743. package/src/runtime/office/portable/portable-chart.mjs +162 -131
  744. package/src/runtime/office/portable/portable-docx-parts.mjs +161 -138
  745. package/src/runtime/office/portable/portable-docx-xml.mjs +136 -95
  746. package/src/runtime/office/portable/portable-docx.mjs +375 -189
  747. package/src/runtime/office/portable/portable-ooxml.mjs +6 -5
  748. package/src/runtime/office/portable/portable-opc.mjs +56 -55
  749. package/src/runtime/office/portable/portable-package.mjs +335 -236
  750. package/src/runtime/office/portable/portable-pivot.mjs +159 -127
  751. package/src/runtime/office/portable/portable-pptx-chart.mjs +63 -44
  752. package/src/runtime/office/portable/portable-pptx-charts.mjs +110 -81
  753. package/src/runtime/office/portable/portable-pptx-core.mjs +56 -83
  754. package/src/runtime/office/portable/portable-pptx-deck.mjs +101 -78
  755. package/src/runtime/office/portable/portable-pptx-package.mjs +129 -111
  756. package/src/runtime/office/portable/portable-pptx-shapes.mjs +183 -120
  757. package/src/runtime/office/portable/portable-pptx.mjs +53 -7
  758. package/src/runtime/office/portable/portable-sheet-page.mjs +72 -27
  759. package/src/runtime/office/portable/portable-sheet-parts.mjs +55 -41
  760. package/src/runtime/office/portable/portable-sheet-styles.mjs +83 -34
  761. package/src/runtime/office/portable/portable-sheet-xml.mjs +94 -100
  762. package/src/runtime/office/portable/portable-slide-shapes.mjs +107 -80
  763. package/src/runtime/office/portable/portable-snapshot.mjs +216 -137
  764. package/src/runtime/office/portable/portable-soffice.mjs +85 -55
  765. package/src/runtime/office/portable/portable-validation.mjs +344 -167
  766. package/src/runtime/office/portable/portable-xlsx.mjs +416 -211
  767. package/src/runtime/office/portable/portable-xml.mjs +10 -26
  768. package/src/runtime/office/portable/pptx-relations.mjs +38 -14
  769. package/src/runtime/office/portable/pptx-targets.mjs +9 -4
  770. package/src/runtime/office/portable/review-editability.mjs +28 -6
  771. package/src/runtime/office/portable/text-metrics.mjs +95 -70
  772. package/src/runtime/office/portable/xlsx-assertions.mjs +111 -43
  773. package/src/runtime/office/portable/xlsx-audit-support.mjs +12 -12
  774. package/src/runtime/office/portable/xlsx-contract.mjs +93 -51
  775. package/src/runtime/office/portable/xlsx-formula-audit.mjs +98 -30
  776. package/src/runtime/office/portable/xlsx-sheet-hygiene.mjs +59 -14
  777. package/src/runtime/office/quality/assurance-checklist.mjs +23 -17
  778. package/src/runtime/office/quality/assurance-rendered.mjs +49 -56
  779. package/src/runtime/office/quality/assurance-structure.mjs +342 -265
  780. package/src/runtime/office/quality/assurance-trust.mjs +38 -31
  781. package/src/runtime/office/quality/design-aesthetics-metrics.mjs +23 -17
  782. package/src/runtime/office/quality/design-aesthetics.mjs +100 -101
  783. package/src/runtime/office/quality/design-deck-diversity.mjs +53 -37
  784. package/src/runtime/office/quality/design-review-authored.mjs +36 -24
  785. package/src/runtime/office/quality/design-review-critique.mjs +55 -22
  786. package/src/runtime/office/quality/design-review.mjs +148 -162
  787. package/src/runtime/office/quality/document-acceptance.mjs +37 -18
  788. package/src/runtime/office/quality/inline-audit.mjs +13 -11
  789. package/src/runtime/office/quality/pptx-deck-rubric.mjs +30 -12
  790. package/src/runtime/office/quality/pptx-slide-roles.mjs +28 -15
  791. package/src/runtime/office/quality/presentation-acceptance.mjs +11 -10
  792. package/src/runtime/office/quality/quality-pipeline.mjs +151 -88
  793. package/src/runtime/office/quality/quality-score.mjs +13 -20
  794. package/src/runtime/office/quality/render-air.mjs +59 -24
  795. package/src/runtime/office/quality/visual-diff.mjs +5 -2
  796. package/src/runtime/office/shared/values.mjs +9 -2
  797. package/src/runtime/office/tool-defs.mjs +108 -27
  798. package/src/runtime/shared/abort-controller.mjs +5 -1
  799. package/src/runtime/shared/abort-race.mjs +4 -2
  800. package/src/runtime/shared/agent-route-config.mjs +18 -21
  801. package/src/runtime/shared/atomic-file.d.mts +3 -3
  802. package/src/runtime/shared/atomic-file.mjs +81 -47
  803. package/src/runtime/shared/automation-attachments.mjs +10 -5
  804. package/src/runtime/shared/automation-workflow.mjs +4 -2
  805. package/src/runtime/shared/background-tasks.mjs +59 -46
  806. package/src/runtime/shared/boot-profile.mjs +5 -3
  807. package/src/runtime/shared/bounded-download.mjs +9 -13
  808. package/src/runtime/shared/bridge-tool-args.mjs +1 -3
  809. package/src/runtime/shared/buffered-appender.mjs +151 -142
  810. package/src/runtime/shared/child-guardian.mjs +7 -9
  811. package/src/runtime/shared/child-spawn-gate.mjs +40 -47
  812. package/src/runtime/shared/child-spawn-remote.mjs +44 -32
  813. package/src/runtime/shared/config.mjs +246 -210
  814. package/src/runtime/shared/debounced-writer.mjs +33 -31
  815. package/src/runtime/shared/edit-tool-dialect.mjs +6 -5
  816. package/src/runtime/shared/err-text.mjs +57 -32
  817. package/src/runtime/shared/error-presentation.mjs +67 -19
  818. package/src/runtime/shared/file-lock.mjs +44 -18
  819. package/src/runtime/shared/file-permissions.d.mts +2 -8
  820. package/src/runtime/shared/file-permissions.mjs +5 -1
  821. package/src/runtime/shared/http-request-body.mjs +26 -15
  822. package/src/runtime/shared/idle-gc.mjs +19 -7
  823. package/src/runtime/shared/json-file.mjs +5 -1
  824. package/src/runtime/shared/json-metrics.mjs +19 -8
  825. package/src/runtime/shared/keyed-serial-queue.d.mts +1 -4
  826. package/src/runtime/shared/keyed-serial-queue.mjs +4 -1
  827. package/src/runtime/shared/llm/cost.mjs +81 -63
  828. package/src/runtime/shared/llm/http-agent.mjs +78 -60
  829. package/src/runtime/shared/llm/index.mjs +13 -14
  830. package/src/runtime/shared/llm/usage-accounting.mjs +64 -56
  831. package/src/runtime/shared/llm/usage-ledger-import.mjs +169 -125
  832. package/src/runtime/shared/llm/usage-ledger-repair.mjs +125 -88
  833. package/src/runtime/shared/llm/usage-ledger.mjs +481 -325
  834. package/src/runtime/shared/llm/usage-log.mjs +19 -17
  835. package/src/runtime/shared/llm/usage-measurement.mjs +45 -28
  836. package/src/runtime/shared/llm/usage-pricing-refresh.mjs +15 -11
  837. package/src/runtime/shared/llm/usage-rollup.mjs +39 -30
  838. package/src/runtime/shared/llm/usage-session-history.mjs +23 -18
  839. package/src/runtime/shared/loopback-listener.mjs +56 -44
  840. package/src/runtime/shared/markdown-frontmatter.mjs +6 -2
  841. package/src/runtime/shared/memory-snapshot.mjs +68 -54
  842. package/src/runtime/shared/native-asset.mjs +54 -24
  843. package/src/runtime/shared/notify-trace.mjs +8 -2
  844. package/src/runtime/shared/open-url.mjs +3 -1
  845. package/src/runtime/shared/orchestration.mjs +35 -0
  846. package/src/runtime/shared/owner-fair-gate.mjs +47 -31
  847. package/src/runtime/shared/plugin-manifest.mjs +1 -3
  848. package/src/runtime/shared/plugin-metadata.mjs +1 -5
  849. package/src/runtime/shared/pristine-execution.mjs +52 -59
  850. package/src/runtime/shared/process-lifecycle.mjs +130 -91
  851. package/src/runtime/shared/process-listener-headroom.mjs +3 -2
  852. package/src/runtime/shared/process-shutdown.mjs +36 -24
  853. package/src/runtime/shared/profile-config.cjs +15 -9
  854. package/src/runtime/shared/provider-accounts.mjs +50 -24
  855. package/src/runtime/shared/provider-api-key.mjs +8 -3
  856. package/src/runtime/shared/provider-auth-binding.mjs +8 -7
  857. package/src/runtime/shared/resource-admission.mjs +47 -59
  858. package/src/runtime/shared/runtime-root.mjs +3 -14
  859. package/src/runtime/shared/safe-ipc-send.mjs +6 -2
  860. package/src/runtime/shared/schedule-time.mjs +1 -3
  861. package/src/runtime/shared/schedules-db.mjs +33 -53
  862. package/src/runtime/shared/schema-value-error.mjs +5 -2
  863. package/src/runtime/shared/service-discovery.mjs +44 -46
  864. package/src/runtime/shared/session-runtime-health.mjs +18 -11
  865. package/src/runtime/shared/shell-display.mjs +5 -5
  866. package/src/runtime/shared/singleton-owner.mjs +1 -5
  867. package/src/runtime/shared/skill-document.mjs +6 -9
  868. package/src/runtime/shared/skill-selection.mjs +12 -12
  869. package/src/runtime/shared/skill-tool-dependencies.mjs +46 -29
  870. package/src/runtime/shared/sleep.mjs +3 -3
  871. package/src/runtime/shared/staged-update.mjs +186 -46
  872. package/src/runtime/shared/task-notification-envelope.mjs +15 -14
  873. package/src/runtime/shared/time-format.mjs +1 -2
  874. package/src/runtime/shared/tool-card-model.mjs +283 -145
  875. package/src/runtime/shared/tool-execution-contract.mjs +66 -61
  876. package/src/runtime/shared/tool-execution-owner.mjs +4 -1
  877. package/src/runtime/shared/tool-primitives.mjs +43 -23
  878. package/src/runtime/shared/tool-result-summary.mjs +98 -42
  879. package/src/runtime/shared/tool-status.mjs +12 -5
  880. package/src/runtime/shared/tool-surface.mjs +228 -95
  881. package/src/runtime/shared/transcript-writer.mjs +35 -20
  882. package/src/runtime/shared/transport-error-text.mjs +80 -21
  883. package/src/runtime/shared/turn-snapshot-store.mjs +20 -11
  884. package/src/runtime/shared/turn-snapshot.mjs +59 -69
  885. package/src/runtime/shared/turn-worktree-snapshot.mjs +103 -123
  886. package/src/runtime/shared/update-checker.mjs +24 -64
  887. package/src/runtime/shared/user-cwd.mjs +68 -75
  888. package/src/runtime/shared/user-data-guard.mjs +33 -40
  889. package/src/runtime/shared/webhook-session-run.mjs +11 -2
  890. package/src/runtime/shared/webhooks-db.mjs +30 -28
  891. package/src/runtime/tidy/apply.mjs +164 -0
  892. package/src/runtime/tidy/core-install.mjs +444 -0
  893. package/src/runtime/tidy/engines-manifest.json +417 -0
  894. package/src/runtime/tidy/engines.mjs +306 -0
  895. package/src/runtime/tidy/extract.mjs +147 -0
  896. package/src/runtime/tidy/history-comment.mjs +277 -0
  897. package/src/runtime/tidy/install.mjs +258 -0
  898. package/src/runtime/tidy/languages.mjs +227 -0
  899. package/src/runtime/tidy/process.mjs +231 -0
  900. package/src/runtime/tidy/report.mjs +167 -0
  901. package/src/runtime/tidy/resolve.mjs +343 -0
  902. package/src/runtime/tidy/rules/__tests__/no-debugger.yml +9 -0
  903. package/src/runtime/tidy/rules/__tests__/no-empty-catch.yml +7 -0
  904. package/src/runtime/tidy/rules/__tests__/no-history-comment.yml +81 -0
  905. package/src/runtime/tidy/rules/__tests__/todo-marker.yml +27 -0
  906. package/src/runtime/tidy/rules/bash/no-history-comment.yml +9 -0
  907. package/src/runtime/tidy/rules/bash/todo-marker.yml +8 -0
  908. package/src/runtime/tidy/rules/c/no-history-comment.yml +9 -0
  909. package/src/runtime/tidy/rules/c/todo-marker.yml +8 -0
  910. package/src/runtime/tidy/rules/cpp/no-history-comment.yml +9 -0
  911. package/src/runtime/tidy/rules/cpp/todo-marker.yml +8 -0
  912. package/src/runtime/tidy/rules/csharp/no-empty-catch.yml +12 -0
  913. package/src/runtime/tidy/rules/csharp/no-history-comment.yml +9 -0
  914. package/src/runtime/tidy/rules/csharp/todo-marker.yml +8 -0
  915. package/src/runtime/tidy/rules/go/no-history-comment.yml +9 -0
  916. package/src/runtime/tidy/rules/go/todo-marker.yml +8 -0
  917. package/src/runtime/tidy/rules/java/no-empty-catch.yml +12 -0
  918. package/src/runtime/tidy/rules/java/no-history-comment.yml +12 -0
  919. package/src/runtime/tidy/rules/java/todo-marker.yml +11 -0
  920. package/src/runtime/tidy/rules/javascript/no-debugger.yml +8 -0
  921. package/src/runtime/tidy/rules/javascript/no-empty-catch.yml +12 -0
  922. package/src/runtime/tidy/rules/javascript/no-history-comment.yml +9 -0
  923. package/src/runtime/tidy/rules/javascript/todo-marker.yml +8 -0
  924. package/src/runtime/tidy/rules/kotlin/no-history-comment.yml +12 -0
  925. package/src/runtime/tidy/rules/kotlin/todo-marker.yml +11 -0
  926. package/src/runtime/tidy/rules/lua/no-history-comment.yml +9 -0
  927. package/src/runtime/tidy/rules/lua/todo-marker.yml +8 -0
  928. package/src/runtime/tidy/rules/php/no-empty-catch.yml +12 -0
  929. package/src/runtime/tidy/rules/php/no-history-comment.yml +9 -0
  930. package/src/runtime/tidy/rules/php/todo-marker.yml +8 -0
  931. package/src/runtime/tidy/rules/python/no-history-comment.yml +9 -0
  932. package/src/runtime/tidy/rules/python/todo-marker.yml +8 -0
  933. package/src/runtime/tidy/rules/ruby/no-history-comment.yml +9 -0
  934. package/src/runtime/tidy/rules/ruby/todo-marker.yml +8 -0
  935. package/src/runtime/tidy/rules/rust/no-history-comment.yml +12 -0
  936. package/src/runtime/tidy/rules/rust/todo-marker.yml +11 -0
  937. package/src/runtime/tidy/rules/swift/no-history-comment.yml +12 -0
  938. package/src/runtime/tidy/rules/swift/todo-marker.yml +11 -0
  939. package/src/runtime/tidy/rules/tsx/no-debugger.yml +8 -0
  940. package/src/runtime/tidy/rules/tsx/no-empty-catch.yml +12 -0
  941. package/src/runtime/tidy/rules/tsx/no-history-comment.yml +9 -0
  942. package/src/runtime/tidy/rules/tsx/todo-marker.yml +8 -0
  943. package/src/runtime/tidy/rules/typescript/no-debugger.yml +8 -0
  944. package/src/runtime/tidy/rules/typescript/no-empty-catch.yml +12 -0
  945. package/src/runtime/tidy/rules/typescript/no-history-comment.yml +9 -0
  946. package/src/runtime/tidy/rules/typescript/todo-marker.yml +8 -0
  947. package/src/runtime/tidy/run-engines.mjs +132 -0
  948. package/src/runtime/tidy/runners/air.mjs +50 -0
  949. package/src/runtime/tidy/runners/biome.mjs +425 -0
  950. package/src/runtime/tidy/runners/clang-format.mjs +53 -0
  951. package/src/runtime/tidy/runners/dotnet-format.mjs +238 -0
  952. package/src/runtime/tidy/runners/dprint.mjs +48 -0
  953. package/src/runtime/tidy/runners/eslint.mjs +51 -0
  954. package/src/runtime/tidy/runners/gofmt.mjs +10 -0
  955. package/src/runtime/tidy/runners/gofumpt.mjs +10 -0
  956. package/src/runtime/tidy/runners/index.mjs +43 -0
  957. package/src/runtime/tidy/runners/mago.mjs +110 -0
  958. package/src/runtime/tidy/runners/prettier.mjs +11 -0
  959. package/src/runtime/tidy/runners/psscriptanalyzer.mjs +138 -0
  960. package/src/runtime/tidy/runners/ruff.mjs +68 -0
  961. package/src/runtime/tidy/runners/rustfmt.mjs +72 -0
  962. package/src/runtime/tidy/runners/shared.mjs +177 -0
  963. package/src/runtime/tidy/runners/shellcheck.mjs +52 -0
  964. package/src/runtime/tidy/runners/shfmt.mjs +10 -0
  965. package/src/runtime/tidy/runners/stylua.mjs +45 -0
  966. package/src/runtime/tidy/structural.mjs +368 -0
  967. package/src/runtime/tidy/tool-defs.mjs +56 -0
  968. package/src/runtime/tidy/tool.mjs +380 -0
  969. package/src/runtime/web-search/index.mjs +296 -254
  970. package/src/runtime/web-search/lib/cache.mjs +92 -86
  971. package/src/runtime/web-search/lib/config.mjs +27 -24
  972. package/src/runtime/web-search/lib/document-content.mjs +139 -86
  973. package/src/runtime/web-search/lib/fetch-pipeline.mjs +128 -108
  974. package/src/runtime/web-search/lib/formatter.mjs +103 -89
  975. package/src/runtime/web-search/lib/http-fetch.mjs +284 -228
  976. package/src/runtime/web-search/lib/ssrf-guard.mjs +140 -122
  977. package/src/runtime/web-search/lib/state.mjs +65 -71
  978. package/src/runtime/web-search/lib/web-tools.mjs +213 -197
  979. package/src/runtime/web-search/tool-defs.mjs +47 -13
  980. package/src/session-runtime/agent-tool-routing.mjs +21 -19
  981. package/src/session-runtime/bridge-first-use-gate.mjs +18 -11
  982. package/src/session-runtime/builtin-features.d.mts +13 -4
  983. package/src/session-runtime/builtin-features.mjs +40 -30
  984. package/src/session-runtime/channel-config-api.mjs +4 -9
  985. package/src/session-runtime/config-helpers.mjs +53 -28
  986. package/src/session-runtime/config-lifecycle.mjs +53 -26
  987. package/src/session-runtime/context-status.mjs +58 -64
  988. package/src/session-runtime/cwd-plugins.mjs +19 -14
  989. package/src/session-runtime/deferred-tool-availability.mjs +9 -0
  990. package/src/session-runtime/deferred-tool-delta.mjs +2 -5
  991. package/src/session-runtime/effort.mjs +10 -8
  992. package/src/session-runtime/extension-scopes.mjs +10 -4
  993. package/src/session-runtime/fs-utils.mjs +5 -1
  994. package/src/session-runtime/goal-deadlines.mjs +29 -14
  995. package/src/session-runtime/goal-facade-api.mjs +9 -9
  996. package/src/session-runtime/goal-reminder.mjs +7 -11
  997. package/src/session-runtime/goal-runtime.mjs +211 -120
  998. package/src/session-runtime/goal-state.mjs +29 -26
  999. package/src/session-runtime/goal-storage.mjs +16 -5
  1000. package/src/session-runtime/goal-tasks.mjs +45 -23
  1001. package/src/session-runtime/goal-text.mjs +30 -24
  1002. package/src/session-runtime/goal-tool-defs.mjs +91 -47
  1003. package/src/session-runtime/hitch-profile.mjs +1 -1
  1004. package/src/session-runtime/hook-payload.mjs +0 -1
  1005. package/src/session-runtime/inheritance-fit.mjs +13 -15
  1006. package/src/session-runtime/internal-tool-executor.mjs +42 -20
  1007. package/src/session-runtime/lifecycle-api.mjs +289 -216
  1008. package/src/session-runtime/local-model-api.mjs +9 -3
  1009. package/src/session-runtime/local-provider-settings.mjs +19 -8
  1010. package/src/session-runtime/mcp-glue.mjs +28 -21
  1011. package/src/session-runtime/memory-runtime-prewarm.mjs +5 -5
  1012. package/src/session-runtime/model-capabilities.mjs +19 -13
  1013. package/src/session-runtime/model-recency.mjs +27 -11
  1014. package/src/session-runtime/model-route-api.mjs +72 -55
  1015. package/src/session-runtime/native-web-search.mjs +55 -45
  1016. package/src/session-runtime/new-session-config.mjs +44 -0
  1017. package/src/session-runtime/notification-bus.mjs +32 -17
  1018. package/src/session-runtime/orchestration.mjs +27 -0
  1019. package/src/session-runtime/output-styles.mjs +23 -8
  1020. package/src/session-runtime/plugin-mcp.mjs +31 -27
  1021. package/src/session-runtime/prewarm.mjs +96 -68
  1022. package/src/session-runtime/provider-auth-api.mjs +40 -24
  1023. package/src/session-runtime/provider-catalog-cache.mjs +25 -21
  1024. package/src/session-runtime/provider-models.mjs +53 -42
  1025. package/src/session-runtime/provider-readiness.mjs +1 -6
  1026. package/src/session-runtime/provider-request-snapshot.mjs +55 -92
  1027. package/src/session-runtime/provider-request-tools.mjs +13 -13
  1028. package/src/session-runtime/provider-usage.mjs +13 -11
  1029. package/src/session-runtime/quick-model-rows.mjs +19 -17
  1030. package/src/session-runtime/quick-web-search-models.mjs +2 -6
  1031. package/src/session-runtime/resource-api.mjs +78 -60
  1032. package/src/session-runtime/runtime-bootstrap.mjs +5 -1
  1033. package/src/session-runtime/runtime-core.mjs +205 -152
  1034. package/src/session-runtime/runtime-facade.mjs +4 -0
  1035. package/src/session-runtime/runtime-feature-gates.mjs +8 -10
  1036. package/src/session-runtime/runtime-paths.mjs +1 -1
  1037. package/src/session-runtime/runtime-review-api.mjs +4 -8
  1038. package/src/session-runtime/runtime-tool-routing.mjs +11 -13
  1039. package/src/session-runtime/runtime-tunables.mjs +18 -17
  1040. package/src/session-runtime/self-update.mjs +11 -11
  1041. package/src/session-runtime/session-hooks.mjs +62 -38
  1042. package/src/session-runtime/session-lifecycle.mjs +107 -94
  1043. package/src/session-runtime/session-route-policy.mjs +8 -7
  1044. package/src/session-runtime/session-text.mjs +44 -26
  1045. package/src/session-runtime/session-title.mjs +59 -49
  1046. package/src/session-runtime/session-transcript.mjs +15 -8
  1047. package/src/session-runtime/session-turn-api.mjs +503 -392
  1048. package/src/session-runtime/settings-api.mjs +75 -30
  1049. package/src/session-runtime/setup-tool/executor.mjs +152 -69
  1050. package/src/session-runtime/setup-tool/tool-defs.mjs +96 -22
  1051. package/src/session-runtime/skill-tool-loading.mjs +22 -17
  1052. package/src/session-runtime/skills-api.mjs +37 -24
  1053. package/src/session-runtime/statusline-route.mjs +1 -1
  1054. package/src/session-runtime/tool-catalog-data.mjs +56 -11
  1055. package/src/session-runtime/tool-catalog-schema.mjs +21 -24
  1056. package/src/session-runtime/tool-catalog.mjs +155 -137
  1057. package/src/session-runtime/tool-defs.mjs +19 -14
  1058. package/src/session-runtime/tool-policy-refresh.mjs +42 -36
  1059. package/src/session-runtime/tool-profile.mjs +19 -14
  1060. package/src/session-runtime/tool-surface.mjs +34 -52
  1061. package/src/session-runtime/usage-stats-api.mjs +22 -9
  1062. package/src/session-runtime/warmup-schedulers.mjs +10 -8
  1063. package/src/session-runtime/workflow-agents-api.mjs +102 -54
  1064. package/src/session-runtime/workflow.mjs +86 -90
  1065. package/src/standalone/agent-dispatch-broker.mjs +31 -23
  1066. package/src/standalone/agent-task-status.mjs +10 -24
  1067. package/src/standalone/agent-tool/helpers.mjs +44 -9
  1068. package/src/standalone/agent-tool/job-task-reconcile.mjs +16 -15
  1069. package/src/standalone/agent-tool/job-views.mjs +69 -42
  1070. package/src/standalone/agent-tool/lead-worker-index.mjs +28 -18
  1071. package/src/standalone/agent-tool/notify.mjs +23 -11
  1072. package/src/standalone/agent-tool/provider-init.mjs +35 -10
  1073. package/src/standalone/agent-tool/render.mjs +16 -9
  1074. package/src/standalone/agent-tool/spawn-flow.mjs +132 -107
  1075. package/src/standalone/agent-tool/spawn-preset.mjs +3 -5
  1076. package/src/standalone/agent-tool/tag-registry.mjs +145 -3
  1077. package/src/standalone/agent-tool/tool-def.mjs +26 -7
  1078. package/src/standalone/agent-tool/worker-index.mjs +73 -51
  1079. package/src/standalone/agent-tool/worker-rows.mjs +22 -7
  1080. package/src/standalone/agent-tool.mjs +189 -184
  1081. package/src/standalone/agent-watchdog-registry.mjs +32 -11
  1082. package/src/standalone/boot-phase-profiler.mjs +1 -5
  1083. package/src/standalone/channel-admin.mjs +44 -45
  1084. package/src/standalone/channel-binding.mjs +6 -2
  1085. package/src/standalone/channel-client.mjs +238 -151
  1086. package/src/standalone/channel-session-router.mjs +8 -10
  1087. package/src/standalone/channel-transport.mjs +233 -115
  1088. package/src/standalone/channel-worker.mjs +74 -40
  1089. package/src/standalone/daemon-boot-coordinator.mjs +2 -2
  1090. package/src/standalone/daemon-crash-capture.mjs +81 -37
  1091. package/src/standalone/daemon-log.mjs +34 -15
  1092. package/src/standalone/daemon-telemetry.mjs +14 -9
  1093. package/src/standalone/daemon.mjs +199 -117
  1094. package/src/standalone/desktop-service-registry.mjs +28 -19
  1095. package/src/standalone/fair-call-scheduler.mjs +18 -20
  1096. package/src/standalone/folder-dialog.mjs +19 -10
  1097. package/src/standalone/hook-bus/command-handler.mjs +31 -18
  1098. package/src/standalone/hook-bus/config.mjs +22 -14
  1099. package/src/standalone/hook-bus/constants.mjs +1 -5
  1100. package/src/standalone/hook-bus/handlers.mjs +68 -29
  1101. package/src/standalone/hook-bus/rules.mjs +6 -4
  1102. package/src/standalone/hook-bus.mjs +76 -49
  1103. package/src/standalone/memory-runtime-proxy.mjs +187 -132
  1104. package/src/standalone/opencode-go-login.mjs +22 -7
  1105. package/src/standalone/plugin-admin.mjs +52 -41
  1106. package/src/standalone/projects.mjs +1 -3
  1107. package/src/standalone/provider-admin.mjs +173 -67
  1108. package/src/standalone/rpc-call-identity.mjs +3 -4
  1109. package/src/standalone/seeds.mjs +18 -4
  1110. package/src/standalone/session-attachment-pool.mjs +1 -6
  1111. package/src/standalone/session-call-cache.mjs +62 -33
  1112. package/src/standalone/session-client.mjs +245 -187
  1113. package/src/standalone/session-frame-stream.mjs +44 -24
  1114. package/src/standalone/session-protocol.mjs +4 -0
  1115. package/src/standalone/session-proxy.mjs +152 -110
  1116. package/src/standalone/session-runtime-agent-control-client.mjs +41 -39
  1117. package/src/standalone/session-runtime-host-factory.mjs +11 -6
  1118. package/src/standalone/session-runtime-host.mjs +291 -203
  1119. package/src/standalone/session-runtime-inline-host.mjs +29 -35
  1120. package/src/standalone/session-runtime-provider-cooldown.mjs +15 -15
  1121. package/src/standalone/session-runtime-record.mjs +3 -1
  1122. package/src/standalone/session-runtime-shard-router.mjs +12 -6
  1123. package/src/standalone/session-runtime-worker.mjs +105 -74
  1124. package/src/standalone/session-service/agent-tree.mjs +63 -70
  1125. package/src/standalone/session-service/projection.mjs +37 -31
  1126. package/src/standalone/session-service/stored-reader.mjs +2 -3
  1127. package/src/standalone/session-service.mjs +130 -134
  1128. package/src/standalone/session-state-patch.mjs +2 -7
  1129. package/src/standalone/session-state-projection.mjs +1 -1
  1130. package/src/standalone/session-transport.mjs +110 -89
  1131. package/src/standalone/session-wire.mjs +8 -9
  1132. package/src/standalone/usage-dashboard-model.mjs +170 -93
  1133. package/src/standalone/usage-dashboard.mjs +14 -15
  1134. package/src/standalone/usage-stats-hours.mjs +49 -13
  1135. package/src/standalone/usage-stats-model.mjs +38 -43
  1136. package/src/standalone/usage-stats-period.mjs +46 -11
  1137. package/src/tui/App.jsx +167 -272
  1138. package/src/tui/app/app-format.mjs +26 -28
  1139. package/src/tui/app/app-view.jsx +363 -177
  1140. package/src/tui/app/clipboard.mjs +4 -2
  1141. package/src/tui/app/core-memory-picker.mjs +18 -22
  1142. package/src/tui/app/create-app-pickers.mjs +10 -12
  1143. package/src/tui/app/doctor.mjs +14 -3
  1144. package/src/tui/app/extension-pickers.mjs +43 -20
  1145. package/src/tui/app/input-parsers.mjs +19 -45
  1146. package/src/tui/app/live-spinner-visibility.mjs +15 -12
  1147. package/src/tui/app/maintenance-pickers.mjs +63 -37
  1148. package/src/tui/app/message-selector.mjs +27 -19
  1149. package/src/tui/app/model-options.mjs +40 -45
  1150. package/src/tui/app/model-picker.mjs +98 -76
  1151. package/src/tui/app/onboarding-steps.mjs +50 -33
  1152. package/src/tui/app/panel-surface.mjs +1 -3
  1153. package/src/tui/app/project-picker.mjs +25 -24
  1154. package/src/tui/app/prompt-submit.mjs +143 -86
  1155. package/src/tui/app/provider-setup-picker.mjs +66 -49
  1156. package/src/tui/app/resume-picker.mjs +13 -11
  1157. package/src/tui/app/route-pickers.mjs +71 -51
  1158. package/src/tui/app/settings-picker.mjs +93 -57
  1159. package/src/tui/app/shell-layout.mjs +78 -66
  1160. package/src/tui/app/slash-commands.mjs +57 -11
  1161. package/src/tui/app/slash-dispatch.mjs +80 -52
  1162. package/src/tui/app/text-entry-policy.mjs +1 -5
  1163. package/src/tui/app/text-layout.mjs +2 -2
  1164. package/src/tui/app/theme-effort-pickers.mjs +36 -25
  1165. package/src/tui/app/transcript-row-estimate.mjs +51 -23
  1166. package/src/tui/app/transcript-window.mjs +142 -147
  1167. package/src/tui/app/usage-context-panels.mjs +39 -28
  1168. package/src/tui/app/use-copy-selection.mjs +44 -45
  1169. package/src/tui/app/use-global-key-input.mjs +131 -116
  1170. package/src/tui/app/use-mouse-input.mjs +78 -52
  1171. package/src/tui/app/use-prompt-draft-flow.mjs +96 -75
  1172. package/src/tui/app/use-prompt-handlers.mjs +259 -208
  1173. package/src/tui/app/use-prompt-hint.mjs +7 -7
  1174. package/src/tui/app/use-prompt-queue-history.mjs +109 -95
  1175. package/src/tui/app/use-terminal-chrome.mjs +3 -1
  1176. package/src/tui/app/use-transcript-activity.mjs +16 -7
  1177. package/src/tui/app/use-transcript-scroll.mjs +484 -442
  1178. package/src/tui/app/use-transcript-window.mjs +101 -84
  1179. package/src/tui/app/use-welcome-prompt-hint.mjs +8 -3
  1180. package/src/tui/components/AnsiText.jsx +1 -4
  1181. package/src/tui/components/ConfirmBar.jsx +1 -5
  1182. package/src/tui/components/ContextPanel.jsx +38 -13
  1183. package/src/tui/components/ItemRightHintOverprint.jsx +8 -17
  1184. package/src/tui/components/Markdown.jsx +32 -31
  1185. package/src/tui/components/MarkdownTable.jsx +0 -1
  1186. package/src/tui/components/Message.jsx +20 -18
  1187. package/src/tui/components/Picker.jsx +136 -51
  1188. package/src/tui/components/PromptInput.jsx +523 -471
  1189. package/src/tui/components/QueuedCommands.jsx +13 -5
  1190. package/src/tui/components/SlashCommandPalette.jsx +27 -22
  1191. package/src/tui/components/Spinner.jsx +106 -39
  1192. package/src/tui/components/StatusLine.jsx +143 -59
  1193. package/src/tui/components/TextEntryPanel.jsx +219 -189
  1194. package/src/tui/components/ToolExecution.jsx +120 -72
  1195. package/src/tui/components/TranscriptItem.jsx +88 -16
  1196. package/src/tui/components/TurnDone.jsx +48 -10
  1197. package/src/tui/components/UsagePanel.jsx +38 -17
  1198. package/src/tui/components/prompt-input/edit-helpers.mjs +4 -8
  1199. package/src/tui/components/prompt-input/escape-policy.mjs +7 -8
  1200. package/src/tui/components/prompt-input/restore-policy.d.mts +3 -6
  1201. package/src/tui/components/prompt-input/restore-policy.mjs +30 -38
  1202. package/src/tui/components/tool-execution/ResultBody.jsx +16 -16
  1203. package/src/tui/components/tool-output-format.mjs +20 -20
  1204. package/src/tui/dist/index.mjs +18057 -16856
  1205. package/src/tui/index.jsx +139 -42
  1206. package/src/tui/input-editing.mjs +6 -7
  1207. package/src/tui/lib/voice-setup.mjs +2 -4
  1208. package/src/tui/markdown/format-token.mjs +111 -55
  1209. package/src/tui/markdown/measure-rendered-rows.mjs +34 -24
  1210. package/src/tui/markdown/render-ansi.mjs +15 -15
  1211. package/src/tui/markdown/stream-fence.mjs +6 -6
  1212. package/src/tui/markdown/streaming-markdown.mjs +3 -8
  1213. package/src/tui/markdown/table-layout.mjs +3 -4
  1214. package/src/tui/paste-attachments.mjs +43 -22
  1215. package/src/tui/paste-text-policy.mjs +4 -3
  1216. package/src/tui/prompt-history-store.mjs +15 -18
  1217. package/src/tui/session/agent-envelope.mjs +106 -58
  1218. package/src/tui/session/agent-job-feed.mjs +105 -71
  1219. package/src/tui/session/agent-response-tail.mjs +10 -8
  1220. package/src/tui/session/boot-profile.mjs +1 -1
  1221. package/src/tui/session/context-state.mjs +25 -19
  1222. package/src/tui/session/goal-continuation.mjs +20 -25
  1223. package/src/tui/session/goal-turn-state.mjs +4 -2
  1224. package/src/tui/session/labels.mjs +3 -12
  1225. package/src/tui/session/live-share.mjs +250 -132
  1226. package/src/tui/session/notice-text.mjs +4 -5
  1227. package/src/tui/session/notification-plan.mjs +10 -4
  1228. package/src/tui/session/oauth-flows.mjs +26 -21
  1229. package/src/tui/session/prompt-history.mjs +4 -1
  1230. package/src/tui/session/queue-helpers.mjs +33 -31
  1231. package/src/tui/session/render-frame-source.mjs +9 -9
  1232. package/src/tui/session/render-timing.mjs +69 -79
  1233. package/src/tui/session/session-api-ext.mjs +234 -148
  1234. package/src/tui/session/session-api.mjs +142 -63
  1235. package/src/tui/session/session-flow.mjs +216 -155
  1236. package/src/tui/session/tool-approval.mjs +12 -4
  1237. package/src/tui/session/tool-call-fields.mjs +2 -6
  1238. package/src/tui/session/tool-card-results.mjs +41 -10
  1239. package/src/tui/session/tool-result-status.mjs +34 -41
  1240. package/src/tui/session/tool-result-text.mjs +48 -13
  1241. package/src/tui/session/transcript-spill.mjs +73 -46
  1242. package/src/tui/session/tui-steering-persist.mjs +105 -83
  1243. package/src/tui/session/turn-aggregate-cards.mjs +19 -14
  1244. package/src/tui/session/turn-deferred-cards.mjs +23 -6
  1245. package/src/tui/session/turn.mjs +278 -120
  1246. package/src/tui/session-local.mjs +277 -151
  1247. package/src/tui/spinner-meta.mjs +6 -2
  1248. package/src/tui/spinner-verbs.mjs +188 -35
  1249. package/src/tui/statusline-ansi-bridge.mjs +10 -8
  1250. package/src/tui/theme.mjs +9 -16
  1251. package/src/tui/themes/catppuccin.mjs +0 -1
  1252. package/src/tui/themes/index.mjs +85 -15
  1253. package/src/tui/themes/nord.mjs +0 -1
  1254. package/src/tui/themes/utils.mjs +8 -12
  1255. package/src/tui/transcript-tool-failures.mjs +3 -1
  1256. package/src/ui/ansi.mjs +13 -13
  1257. package/src/ui/context-measurement.mjs +24 -15
  1258. package/src/ui/markdown.mjs +28 -23
  1259. package/src/ui/model-display.mjs +6 -8
  1260. package/src/ui/statusline-agents.mjs +33 -18
  1261. package/src/ui/statusline-format.mjs +2 -2
  1262. package/src/ui/statusline-segments.mjs +27 -9
  1263. package/src/ui/statusline.mjs +149 -66
  1264. package/src/ui/streaming-markdown-heal.mjs +57 -6
  1265. package/src/ui/tool-card.mjs +5 -1
  1266. package/src/workflows/default/WORKFLOW.md +3 -10
  1267. package/src/workflows/headless/WORKFLOW.md +0 -1
  1268. package/src/defaults/cycle3-review-prompt.md +0 -144
  1269. package/src/defaults/memory-promote-prompt.md +0 -176
  1270. package/src/rules/agent/42-cycle3-agent.md +0 -33
  1271. package/src/runtime/agent/orchestrator/session/manager/prompt-surface-publish.mjs +0 -35
  1272. package/src/runtime/memory/lib/core-memory-candidates.mjs +0 -359
  1273. package/src/runtime/memory/lib/generated-memory-management.mjs +0 -98
  1274. package/src/runtime/memory/lib/memory-authority-review.mjs +0 -89
  1275. package/src/runtime/memory/lib/memory-cycle2-gate.mjs +0 -792
  1276. package/src/runtime/memory/lib/memory-cycle3-evidence.mjs +0 -117
  1277. package/src/runtime/memory/lib/memory-cycle3-generated.mjs +0 -76
  1278. package/src/runtime/memory/lib/memory-cycle3-guards.mjs +0 -272
  1279. package/src/runtime/memory/lib/memory-cycle3.mjs +0 -811
  1280. package/src/runtime/memory/lib/memory-source-evidence.mjs +0 -34
  1281. package/src/runtime/memory/lib/phase-merge-verdicts.mjs +0 -54
  1282. package/src/runtime/memory/lib/promotion-fingerprint.mjs +0 -50
  1283. package/src/runtime/memory/lib/prompt-surface-file.mjs +0 -99
  1284. package/src/workflows/solo/WORKFLOW.md +0 -16
@@ -1,9 +1,71 @@
1
- import { join } from 'node:path';
2
- import { PIXELS_TO_POINTS, addPackageRelationship, ensureContentTypeOverride, fillTemplateParts, partRelationshipPath, provenanceCitation, zipText } from './portable-opc.mjs';
1
+ import {
2
+ PIXELS_TO_POINTS,
3
+ addPackageRelationship,
4
+ ensureContentTypeOverride,
5
+ fillTemplateParts,
6
+ partRelationshipPath,
7
+ provenanceCitation,
8
+ zipText,
9
+ } from './portable-opc.mjs';
3
10
  import { appendDocxBlock, docxBodyModel } from './portable-snapshot.mjs';
4
- import { OFFICE_RELATIONSHIP_BASE, XML_HEADER, paragraphTexts, rebuildTextNodes, replaceAcrossRuns, textNodes, upsertOrderedChild, xmlDecode, xmlEncode } from './portable-xml.mjs';
5
- import { SETTINGS_CONTENT_TYPE, SETTINGS_ORDER, WORD_2010_NS, WORD_MAIN_NS, addDocumentImage, anchorDocxComment, commentParagraphId, documentTracksChanges, ensureCommentsPart, ensureNotePart, ensureNumbering, forgetCommentIdentity, markRunsDeleted, nextRevisionId, registerCommentIdentity, registerCommentThread, revisionAttributes, documentSectionSpans, trailingSectionProperties, upsertSectionChild, upsertSectionReference, wordDrawingXml, writeHeaderFooterPart, writeSectionProperties, writeSectionPropertiesAt } from './portable-docx-parts.mjs';
6
- import { alignWordTableColumns, applyWordRunFormat, blankTableCells, docxStyleId, docxTable, insertDocxBlockAt, justifyWordParagraphs, mergeWordCellProperties, paragraphFormatXml, replaceDocxTable, replaceWordProperties, rewriteTableColumns, rowCellMatches, tableRowMatches, wordJustification, wordParagraph, wordRunProperties, wordTableProperties, wordTableXml } from './portable-docx-xml.mjs';
11
+ import {
12
+ OFFICE_RELATIONSHIP_BASE,
13
+ XML_HEADER,
14
+ paragraphTexts,
15
+ rebuildTextNodes,
16
+ replaceAcrossRuns,
17
+ textNodes,
18
+ upsertOrderedChild,
19
+ xmlDecode,
20
+ xmlEncode,
21
+ } from './portable-xml.mjs';
22
+ import {
23
+ SETTINGS_CONTENT_TYPE,
24
+ SETTINGS_ORDER,
25
+ WORD_2010_NS,
26
+ WORD_MAIN_NS,
27
+ addDocumentImage,
28
+ anchorDocxComment,
29
+ commentParagraphId,
30
+ documentTracksChanges,
31
+ ensureCommentsPart,
32
+ ensureNotePart,
33
+ ensureNumbering,
34
+ forgetCommentIdentity,
35
+ markRunsDeleted,
36
+ nextRevisionId,
37
+ registerCommentIdentity,
38
+ registerCommentThread,
39
+ revisionAttributes,
40
+ documentSectionSpans,
41
+ trailingSectionProperties,
42
+ upsertSectionChild,
43
+ upsertSectionReference,
44
+ wordDrawingXml,
45
+ writeHeaderFooterPart,
46
+ writeSectionPropertiesAt,
47
+ } from './portable-docx-parts.mjs';
48
+ import {
49
+ alignWordTableColumns,
50
+ applyWordRunFormat,
51
+ blankTableCells,
52
+ docxStyleId,
53
+ docxTable,
54
+ insertDocxBlockAt,
55
+ justifyWordParagraphs,
56
+ mergeWordCellProperties,
57
+ paragraphFormatXml,
58
+ replaceDocxTable,
59
+ replaceWordProperties,
60
+ rewriteTableColumns,
61
+ rowCellMatches,
62
+ tableRowMatches,
63
+ wordJustification,
64
+ wordParagraph,
65
+ wordRunProperties,
66
+ wordTableProperties,
67
+ wordTableXml,
68
+ } from './portable-docx-xml.mjs';
7
69
  import { docxRevisionTree, flattenDocxRevisions } from './docx-revisions.mjs';
8
70
  import { normalizeDocxRuns, settleDocxStory } from './docx-runs.mjs';
9
71
  import { anchorPhraseInParagraph, trackedParagraphReplace, trackedParagraphRewrite } from './docx-tracked-edits.mjs';
@@ -24,9 +86,8 @@ async function docxHeadingLevels(zip) {
24
86
  const name = /<w:name\b[^>]*\bw:val="([^"]*)"/.exec(match[0])?.[1] || '';
25
87
  const outline = Number(/<w:outlineLvl\b[^>]*\bw:val="(\d+)"/.exec(match[0])?.[1]);
26
88
  const named = /^(?:heading|제목|표제)\s*([1-9])/i.exec(name.trim());
27
- const level = Number.isInteger(outline) && outline >= 0 && outline <= 8
28
- ? outline + 1
29
- : (named ? Number(named[1]) : 0);
89
+ const level =
90
+ Number.isInteger(outline) && outline >= 0 && outline <= 8 ? outline + 1 : named ? Number(named[1]) : 0;
30
91
  if (level) levels.set(match[1], level);
31
92
  }
32
93
  return levels;
@@ -47,8 +108,11 @@ function docxTocEntries(documentXml, lower, upper, headingLevels = new Map()) {
47
108
  function docxTocCacheRuns(entries, lower) {
48
109
  return entries.length
49
110
  ? entries
50
- .map((entry) => `<w:r><w:t xml:space="preserve">${xmlEncode(`${' '.repeat(entry.level - lower)}${entry.text}`)}</w:t></w:r>`)
51
- .join('<w:r><w:br/></w:r>')
111
+ .map(
112
+ (entry) =>
113
+ `<w:r><w:t xml:space="preserve">${xmlEncode(`${' '.repeat(entry.level - lower)}${entry.text}`)}</w:t></w:r>`
114
+ )
115
+ .join('<w:r><w:br/></w:r>')
52
116
  : '<w:r><w:t>Update this field in Word to build the table of contents.</w:t></w:r>';
53
117
  }
54
118
 
@@ -66,7 +130,7 @@ export async function refreshDocxTableOfContents(zip) {
66
130
  const lower = Math.max(1, Number(range?.[1]) || 1);
67
131
  const upper = Math.max(lower, Number(range?.[2]) || 3);
68
132
  return `<w:fldSimple${attributes}>${docxTocCacheRuns(docxTocEntries(current, lower, upper, headingLevels), lower)}</w:fldSimple>`;
69
- },
133
+ }
70
134
  );
71
135
  if (next === current) return false;
72
136
  zip.file('word/document.xml', next);
@@ -84,7 +148,9 @@ function replaceTrackedParagraphs(xml, find, replacement, author) {
84
148
  let count = 0;
85
149
  let paragraphRewrites = 0;
86
150
  const next = xml.replace(/<w:p(?:\s[^>]*)?>[\s\S]*?<\/w:p>/g, (paragraph) => {
87
- const joined = textNodes(paragraph, 'w:t').map((node) => node.text).join('');
151
+ const joined = textNodes(paragraph, 'w:t')
152
+ .map((node) => node.text)
153
+ .join('');
88
154
  if (!joined.includes(find)) return paragraph;
89
155
  const cut = trackedParagraphReplace(paragraph, find, replacement, id, author);
90
156
  if (cut.count) {
@@ -127,17 +193,26 @@ async function pruneOrphanComments(zip, parts) {
127
193
  // without their comment they would read as a marker mismatch.
128
194
  for (const part of parts.filter((name) => !/\/comments\.xml$/i.test(name))) {
129
195
  const xml = await zipText(zip, part);
130
- const stripped = removedIds.reduce((value, id) => value.replace(
131
- new RegExp(`<w:commentRange(?:Start|End)\\b[^>]*\\bw:id="${id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"[^>]*\\/>`, 'g'),
132
- '',
133
- ), xml);
196
+ const stripped = removedIds.reduce(
197
+ (value, id) =>
198
+ value.replace(
199
+ new RegExp(
200
+ `<w:commentRange(?:Start|End)\\b[^>]*\\bw:id="${id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"[^>]*\\/>`,
201
+ 'g'
202
+ ),
203
+ ''
204
+ ),
205
+ xml
206
+ );
134
207
  if (stripped !== xml) zip.file(part, stripped);
135
208
  }
136
209
  return removedIds.length;
137
210
  }
138
211
 
139
212
  export async function applyDocx(zip, operations) {
140
- const parts = Object.keys(zip.files).filter((name) => /^word\/(document|header\d+|footer\d+|footnotes|endnotes|comments)\.xml$/i.test(name));
213
+ const parts = Object.keys(zip.files).filter((name) =>
214
+ /^word\/(document|header\d+|footer\d+|footnotes|endnotes|comments)\.xml$/i.test(name)
215
+ );
141
216
  const results = [];
142
217
  let tracking = await documentTracksChanges(zip);
143
218
  for (const op of operations) {
@@ -152,15 +227,13 @@ export async function applyDocx(zip, operations) {
152
227
  zip,
153
228
  partRelationshipPath('word/document.xml'),
154
229
  `${OFFICE_RELATIONSHIP_BASE}/settings`,
155
- 'settings.xml',
230
+ 'settings.xml'
156
231
  );
157
232
  }
158
- zip.file(part, upsertOrderedChild(
159
- settings,
160
- SETTINGS_ORDER,
161
- 'w:trackRevisions',
162
- enabled ? '<w:trackRevisions/>' : '',
163
- ));
233
+ zip.file(
234
+ part,
235
+ upsertOrderedChild(settings, SETTINGS_ORDER, 'w:trackRevisions', enabled ? '<w:trackRevisions/>' : '')
236
+ );
164
237
  tracking = enabled;
165
238
  results.push({ op: op.op, changed: true, enabled });
166
239
  continue;
@@ -168,9 +241,15 @@ export async function applyDocx(zip, operations) {
168
241
  if (op.op === 'fill_template') {
169
242
  // Under track changes each token becomes a tracked deletion plus the
170
243
  // inserted value, so a filled template still passes the redlining audit.
171
- const filled = await fillTemplateParts(zip, parts, 'w:t', op, tracking
172
- ? { replace: (xml, _tag, find, replacement) => replaceTrackedParagraphs(xml, find, replacement, op.author) }
173
- : {});
244
+ const filled = await fillTemplateParts(
245
+ zip,
246
+ parts,
247
+ 'w:t',
248
+ op,
249
+ tracking
250
+ ? { replace: (xml, _tag, find, replacement) => replaceTrackedParagraphs(xml, find, replacement, op.author) }
251
+ : {}
252
+ );
174
253
  results.push(tracking ? { ...filled, tracked: true } : filled);
175
254
  continue;
176
255
  }
@@ -190,14 +269,18 @@ export async function applyDocx(zip, operations) {
190
269
  op: op.op,
191
270
  changed: count > 0,
192
271
  count,
193
- ...(tracking ? {
194
- tracked: true,
195
- granularity: paragraphRewrites ? 'paragraph' : 'run',
196
- ...(paragraphRewrites ? {
197
- paragraphRewrites,
198
- note: `${paragraphRewrites} paragraph(s) held the match across a tab, break, field, or drawing and were rewritten whole: their runs are marked deleted and one inserted run carries the new text.`,
199
- } : {}),
200
- } : {}),
272
+ ...(tracking
273
+ ? {
274
+ tracked: true,
275
+ granularity: paragraphRewrites ? 'paragraph' : 'run',
276
+ ...(paragraphRewrites
277
+ ? {
278
+ paragraphRewrites,
279
+ note: `${paragraphRewrites} paragraph(s) held the match across a tab, break, field, or drawing and were rewritten whole: their runs are marked deleted and one inserted run carries the new text.`,
280
+ }
281
+ : {}),
282
+ }
283
+ : {}),
201
284
  });
202
285
  continue;
203
286
  }
@@ -205,20 +288,18 @@ export async function applyDocx(zip, operations) {
205
288
  const current = await zipText(zip, 'word/document.xml');
206
289
  const properties = op.properties || {};
207
290
  const listKind = String(properties.listKind || '').toLowerCase();
208
- const numbering = listKind
209
- ? await ensureNumbering(zip, listKind === 'number' ? 'number' : 'bullet')
210
- : null;
291
+ const numbering = listKind ? await ensureNumbering(zip, listKind === 'number' ? 'number' : 'bullet') : null;
211
292
  const style = docxStyleId(op.style || properties.style || (numbering ? 'List Paragraph' : ''));
212
293
  const format = paragraphFormatXml(
213
294
  properties,
214
- numbering ? { numId: numbering.numId, level: properties.listLevel } : null,
295
+ numbering ? { numId: numbering.numId, level: properties.listLevel } : null
215
296
  );
216
- const paragraphProperties = style || format
217
- ? `<w:pPr>${style ? `<w:pStyle w:val="${xmlEncode(style)}"/>` : ''}${format}</w:pPr>`
218
- : '';
297
+ const paragraphProperties =
298
+ style || format ? `<w:pPr>${style ? `<w:pStyle w:val="${xmlEncode(style)}"/>` : ''}${format}</w:pPr>` : '';
219
299
  const runProperties = wordRunProperties(properties);
220
- const run = `<w:r>${runProperties ? `<w:rPr>${runProperties}</w:rPr>` : ''}`
221
- + `<w:t${/^\s|\s$/.test(String(op.text || '')) ? ' xml:space="preserve"' : ''}>${xmlEncode(op.text || '')}</w:t></w:r>`;
300
+ const run =
301
+ `<w:r>${runProperties ? `<w:rPr>${runProperties}</w:rPr>` : ''}` +
302
+ `<w:t${/^\s|\s$/.test(String(op.text || '')) ? ' xml:space="preserve"' : ''}>${xmlEncode(op.text || '')}</w:t></w:r>`;
222
303
  const content = tracking
223
304
  ? `<w:ins ${revisionAttributes(nextRevisionId(current), properties.author)}>${run}</w:ins>`
224
305
  : run;
@@ -241,10 +322,19 @@ export async function applyDocx(zip, operations) {
241
322
  current = appendDocxBlock(current, table);
242
323
  }
243
324
  zip.file('word/document.xml', current);
244
- results.push({ op: op.op, changed: true, table: docxBodyModel(current).blocks.filter((block) => block.name === 'w:tbl').length });
325
+ results.push({
326
+ op: op.op,
327
+ changed: true,
328
+ table: docxBodyModel(current).blocks.filter((block) => block.name === 'w:tbl').length,
329
+ });
245
330
  continue;
246
331
  }
247
- if (op.op === 'set_paragraph_text' || op.op === 'set_run_text' || op.op === 'remove_paragraph' || op.op === 'move_paragraph') {
332
+ if (
333
+ op.op === 'set_paragraph_text' ||
334
+ op.op === 'set_run_text' ||
335
+ op.op === 'remove_paragraph' ||
336
+ op.op === 'move_paragraph'
337
+ ) {
248
338
  let current = await zipText(zip, 'word/document.xml');
249
339
  const model = docxBodyModel(current);
250
340
  const paragraph = model.blocks.filter((block) => block.name === 'w:p')[Number(op.paragraph) - 1];
@@ -255,9 +345,9 @@ export async function applyDocx(zip, operations) {
255
345
  const marked = markRunsDeleted(paragraph.xml, id, op.author);
256
346
  const mark = `<w:del ${revisionAttributes(id + 900, op.author)}/>`;
257
347
  const withMark = /<w:pPr(?:\s[^>]*)?>/.test(marked)
258
- ? (/<w:rPr(?:\s[^>]*)?>[\s\S]*?<\/w:rPr>\s*<\/w:pPr>/.test(marked)
348
+ ? /<w:rPr(?:\s[^>]*)?>[\s\S]*?<\/w:rPr>\s*<\/w:pPr>/.test(marked)
259
349
  ? marked.replace(/(<w:rPr(?:\s[^>]*)?>)/, `$1${mark}`)
260
- : marked.replace(/<\/w:pPr>/, `<w:rPr>${mark}</w:rPr></w:pPr>`))
350
+ : marked.replace(/<\/w:pPr>/, `<w:rPr>${mark}</w:rPr></w:pPr>`)
261
351
  : marked.replace(/^(<w:p(?:\s[^>]*)?>)/, `$1<w:pPr><w:rPr>${mark}</w:rPr></w:pPr>`);
262
352
  nextInner = `${nextInner.slice(0, paragraph.start)}${withMark}${nextInner.slice(paragraph.end)}`;
263
353
  } else if (op.op === 'remove_paragraph') {
@@ -275,7 +365,12 @@ export async function applyDocx(zip, operations) {
275
365
  nextInner = `${without.slice(0, adjustedStart)}${paragraph.xml}${without.slice(adjustedStart)}`;
276
366
  }
277
367
  } else if (tracking && op.op === 'set_paragraph_text') {
278
- const nextParagraph = trackedParagraphRewrite(paragraph.xml, String(op.text ?? ''), nextRevisionId(current), op.author);
368
+ const nextParagraph = trackedParagraphRewrite(
369
+ paragraph.xml,
370
+ String(op.text ?? ''),
371
+ nextRevisionId(current),
372
+ op.author
373
+ );
279
374
  nextInner = `${nextInner.slice(0, paragraph.start)}${nextParagraph}${nextInner.slice(paragraph.end)}`;
280
375
  } else {
281
376
  const nodes = textNodes(paragraph.xml, 'w:t');
@@ -325,7 +420,10 @@ export async function applyDocx(zip, operations) {
325
420
  nextParagraph = nextParagraph.replace(/<w:pPr(?:\s[^>]*)?>/, (open) => `${open}<w:pStyle w:val="${style}"/>`);
326
421
  }
327
422
  } else {
328
- nextParagraph = nextParagraph.replace(/<w:p(?:\s[^>]*)?>/, (open) => `${open}<w:pPr><w:pStyle w:val="${style}"/></w:pPr>`);
423
+ nextParagraph = nextParagraph.replace(
424
+ /<w:p(?:\s[^>]*)?>/,
425
+ (open) => `${open}<w:pPr><w:pStyle w:val="${style}"/></w:pPr>`
426
+ );
329
427
  }
330
428
  const nextInner = `${model.body.inner.slice(0, paragraph.start)}${nextParagraph}${model.body.inner.slice(paragraph.end)}`;
331
429
  current = `${current.slice(0, model.body.start)}${nextInner}${current.slice(model.body.end)}`;
@@ -362,8 +460,11 @@ export async function applyDocx(zip, operations) {
362
460
  return deleted;
363
461
  });
364
462
  if (first) {
365
- nextCell = cell[0].replace('</w:tc>', `<w:p><w:ins ${revisionAttributes(id, op.author)}><w:r>`
366
- + `<w:t xml:space="preserve">${xmlEncode(op.text ?? '')}</w:t></w:r></w:ins></w:p></w:tc>`);
463
+ nextCell = cell[0].replace(
464
+ '</w:tc>',
465
+ `<w:p><w:ins ${revisionAttributes(id, op.author)}><w:r>` +
466
+ `<w:t xml:space="preserve">${xmlEncode(op.text ?? '')}</w:t></w:r></w:ins></w:p></w:tc>`
467
+ );
367
468
  }
368
469
  } else if (nodes.length) {
369
470
  nodes[0].text = String(op.text ?? '');
@@ -385,12 +486,15 @@ export async function applyDocx(zip, operations) {
385
486
  // Restyling a table must not undo its width: the declared width is part
386
487
  // of the layout, not of the style being replaced.
387
488
  const declaredWidth = /<w:tblW\b[^>]*\bw:w="(\d+)"[^>]*\bw:type="dxa"/.exec(table[0])?.[1];
388
- const nextTable = alignWordTableColumns(replaceWordProperties(
389
- table[0],
390
- 'tbl',
391
- 'tblPr',
392
- wordTableProperties(op.properties, { totalWidth: Number(declaredWidth) || 0 }),
393
- ), Array.isArray(op.properties?.columnAlignments) ? op.properties.columnAlignments : []);
489
+ const nextTable = alignWordTableColumns(
490
+ replaceWordProperties(
491
+ table[0],
492
+ 'tbl',
493
+ 'tblPr',
494
+ wordTableProperties(op.properties, { totalWidth: Number(declaredWidth) || 0 })
495
+ ),
496
+ Array.isArray(op.properties?.columnAlignments) ? op.properties.columnAlignments : []
497
+ );
394
498
  current = replaceDocxTable(current, table, nextTable);
395
499
  zip.file('word/document.xml', current);
396
500
  results.push({ op: op.op, changed: nextTable !== table[0], table: Number(op.table) });
@@ -421,28 +525,43 @@ export async function applyDocx(zip, operations) {
421
525
  op.properties?.bold ? '<w:b/>' : '',
422
526
  op.properties?.italic ? '<w:i/>' : '',
423
527
  op.properties?.color ? `<w:color w:val="${xmlEncode(String(op.properties.color).replace(/^#/, ''))}"/>` : '',
424
- Number.isFinite(cellSize) && cellSize > 0 ? `<w:sz w:val="${Math.round(cellSize * 2)}"/><w:szCs w:val="${Math.round(cellSize * 2)}"/>` : '',
528
+ Number.isFinite(cellSize) && cellSize > 0
529
+ ? `<w:sz w:val="${Math.round(cellSize * 2)}"/><w:szCs w:val="${Math.round(cellSize * 2)}"/>`
530
+ : '',
425
531
  ].join('');
426
532
  nextCell = applyWordRunFormat(nextCell, runFormat);
427
533
  // The cell's line pitch follows its new size (the table convention, 1.3× the size, at least): a 9 pt
428
534
  // label row under a 22 pt value row otherwise keeps the value row's 29 pt lines and floats the labels.
429
535
  if (Number.isFinite(cellSize) && cellSize > 0) {
430
- nextCell = nextCell.replace(/(<w:spacing\b[^>]*\bw:line=")(\d+)("[^>]*\bw:lineRule="atLeast")/g, (_, open, __, close) => `${open}${Math.round(cellSize * 1.3 * 20)}${close}`);
536
+ nextCell = nextCell.replace(
537
+ /(<w:spacing\b[^>]*\bw:line=")(\d+)("[^>]*\bw:lineRule="atLeast")/g,
538
+ (_, open, __, close) => `${open}${Math.round(cellSize * 1.3 * 20)}${close}`
539
+ );
431
540
  }
432
541
  // A cell's horizontal alignment is its paragraphs' justification: a
433
542
  // centred metric that stays left-aligned reads as a different number
434
543
  // column from the header above it.
435
- const alignment = String(op.properties?.horizontalAlignment || '').trim().toLowerCase();
544
+ const alignment = String(op.properties?.horizontalAlignment || '')
545
+ .trim()
546
+ .toLowerCase();
436
547
  if (alignment) {
437
548
  const justification = wordJustification(alignment);
438
- if (!justification) throw new Error(`set_table_cell_style horizontalAlignment must be left, center, right, or justify, not ${alignment}`);
549
+ if (!justification)
550
+ throw new Error(
551
+ `set_table_cell_style horizontalAlignment must be left, center, right, or justify, not ${alignment}`
552
+ );
439
553
  nextCell = justifyWordParagraphs(nextCell, justification);
440
554
  }
441
555
  nextTable = table[0].replace(cell[0], nextCell);
442
556
  } else {
443
557
  const colSpan = Math.max(1, Number(op.colSpan) || 1);
444
558
  const rowSpan = Math.max(1, Number(op.rowSpan) || 1);
445
- let merged = replaceWordProperties(cell[0], 'tc', 'tcPr', `${colSpan > 1 ? `<w:gridSpan w:val="${colSpan}"/>` : ''}${rowSpan > 1 ? '<w:vMerge w:val="restart"/>' : ''}`);
559
+ const merged = replaceWordProperties(
560
+ cell[0],
561
+ 'tc',
562
+ 'tcPr',
563
+ `${colSpan > 1 ? `<w:gridSpan w:val="${colSpan}"/>` : ''}${rowSpan > 1 ? '<w:vMerge w:val="restart"/>' : ''}`
564
+ );
446
565
  let nextRow = row[0].replace(cell[0], merged);
447
566
  for (let index = Number(op.col); index < Number(op.col) + colSpan - 1; index += 1) {
448
567
  const remove = cells[index];
@@ -456,22 +575,31 @@ export async function applyDocx(zip, operations) {
456
575
  const continuationCells = rowCellMatches(continuationRow[0]);
457
576
  const continuation = continuationCells[Number(op.col) - 1];
458
577
  if (!continuation) continue;
459
- const nextCell = replaceWordProperties(continuation[0], 'tc', 'tcPr', `${colSpan > 1 ? `<w:gridSpan w:val="${colSpan}"/>` : ''}<w:vMerge/>`);
578
+ const nextCell = replaceWordProperties(
579
+ continuation[0],
580
+ 'tc',
581
+ 'tcPr',
582
+ `${colSpan > 1 ? `<w:gridSpan w:val="${colSpan}"/>` : ''}<w:vMerge/>`
583
+ );
460
584
  nextTable = nextTable.replace(continuation[0], nextCell);
461
585
  }
462
586
  }
463
587
  }
464
588
  current = replaceDocxTable(current, table, nextTable);
465
589
  zip.file('word/document.xml', current);
466
- results.push({ op: op.op, changed: nextTable !== table[0], table: Number(op.table), row: Number(op.row), col: Number(op.col) });
590
+ results.push({
591
+ op: op.op,
592
+ changed: nextTable !== table[0],
593
+ table: Number(op.table),
594
+ row: Number(op.row),
595
+ col: Number(op.col),
596
+ });
467
597
  continue;
468
598
  }
469
599
  if (op.op === 'set_paragraph_format') {
470
600
  const properties = op.properties || {};
471
601
  const listKind = String(properties.listKind || '').toLowerCase();
472
- const numbering = listKind
473
- ? await ensureNumbering(zip, listKind === 'number' ? 'number' : 'bullet')
474
- : null;
602
+ const numbering = listKind ? await ensureNumbering(zip, listKind === 'number' ? 'number' : 'bullet') : null;
475
603
  let current = await zipText(zip, 'word/document.xml');
476
604
  const model = docxBodyModel(current);
477
605
  const paragraph = model.blocks.filter((block) => block.name === 'w:p')[Number(op.paragraph) - 1];
@@ -479,7 +607,7 @@ export async function applyDocx(zip, operations) {
479
607
  const nextParagraph = patchParagraphFormat(
480
608
  paragraph.xml,
481
609
  properties,
482
- numbering ? { numId: numbering.numId, level: properties.listLevel } : null,
610
+ numbering ? { numId: numbering.numId, level: properties.listLevel } : null
483
611
  );
484
612
  const nextInner = `${model.body.inner.slice(0, paragraph.start)}${nextParagraph}${model.body.inner.slice(paragraph.end)}`;
485
613
  current = `${current.slice(0, model.body.start)}${nextInner}${current.slice(model.body.end)}`;
@@ -491,14 +619,20 @@ export async function applyDocx(zip, operations) {
491
619
  const current = await zipText(zip, 'word/document.xml');
492
620
  const media = await addDocumentImage(zip, op.path);
493
621
  const pixels = media.pixels;
494
- const width = Number(op.width) > 0
495
- ? Number(op.width)
496
- : (pixels ? pixels.width * PIXELS_TO_POINTS : 240);
497
- const height = Number(op.height) > 0
498
- ? Number(op.height)
499
- : (pixels ? pixels.height * PIXELS_TO_POINTS * (Number(op.width) > 0 ? Number(op.width) / (pixels.width * PIXELS_TO_POINTS) : 1) : 180);
500
- const id = [...current.matchAll(/<wp:docPr\b[^>]*\bid="(\d+)"/g)]
501
- .reduce((max, match) => Math.max(max, Number(match[1])), 0) + 1;
622
+ const width = Number(op.width) > 0 ? Number(op.width) : pixels ? pixels.width * PIXELS_TO_POINTS : 240;
623
+ const height =
624
+ Number(op.height) > 0
625
+ ? Number(op.height)
626
+ : pixels
627
+ ? pixels.height *
628
+ PIXELS_TO_POINTS *
629
+ (Number(op.width) > 0 ? Number(op.width) / (pixels.width * PIXELS_TO_POINTS) : 1)
630
+ : 180;
631
+ const id =
632
+ [...current.matchAll(/<wp:docPr\b[^>]*\bid="(\d+)"/g)].reduce(
633
+ (max, match) => Math.max(max, Number(match[1])),
634
+ 0
635
+ ) + 1;
502
636
  const block = `<w:p><w:r>${wordDrawingXml({
503
637
  id,
504
638
  embedId: media.relationshipId,
@@ -546,15 +680,15 @@ export async function applyDocx(zip, operations) {
546
680
  section,
547
681
  'pgSz',
548
682
  `<w:pgSz w:w="${pageWidth}" w:h="${pageHeight}"${orientation === 'landscape' ? ' w:orient="landscape"' : ''}/>`,
549
- ['type'],
683
+ ['type']
550
684
  );
551
685
  return upsertSectionChild(
552
686
  withSize,
553
687
  'pgMar',
554
- `<w:pgMar w:top="${margin('top', 'topMargin', 1418)}" w:right="${margin('right', 'rightMargin', 1418)}"`
555
- + ` w:bottom="${margin('bottom', 'bottomMargin', 1418)}" w:left="${margin('left', 'leftMargin', 1418)}"`
556
- + ` w:header="${margin('header', 'headerMargin', 709)}" w:footer="${margin('footer', 'footerMargin', 709)}" w:gutter="0"/>`,
557
- ['pgSz'],
688
+ `<w:pgMar w:top="${margin('top', 'topMargin', 1418)}" w:right="${margin('right', 'rightMargin', 1418)}"` +
689
+ ` w:bottom="${margin('bottom', 'bottomMargin', 1418)}" w:left="${margin('left', 'leftMargin', 1418)}"` +
690
+ ` w:header="${margin('header', 'headerMargin', 709)}" w:footer="${margin('footer', 'footerMargin', 709)}" w:gutter="0"/>`,
691
+ ['pgSz']
558
692
  );
559
693
  });
560
694
  zip.file('word/document.xml', next);
@@ -577,17 +711,14 @@ export async function applyDocx(zip, operations) {
577
711
  const position = Math.max(1, Math.min(Number(op.row) || rows.length + 1, rows.length + 1));
578
712
  const template = rows[Math.min(position, rows.length) - 1];
579
713
  const blank = blankTableCells(template[0]);
580
- nextTable = position > rows.length
581
- ? table[0].replace(/<\/w:tbl>$/, `${blank}</w:tbl>`)
582
- : `${table[0].slice(0, template.index)}${blank}${table[0].slice(template.index)}`;
714
+ nextTable =
715
+ position > rows.length
716
+ ? table[0].replace(/<\/w:tbl>$/, `${blank}</w:tbl>`)
717
+ : `${table[0].slice(0, template.index)}${blank}${table[0].slice(template.index)}`;
583
718
  }
584
719
  } else {
585
720
  const columnIndex = Math.max(1, Number(op.column) || 1);
586
- nextTable = rewriteTableColumns(
587
- table[0],
588
- columnIndex,
589
- op.op === 'delete_table_column' ? 'delete' : 'insert',
590
- );
721
+ nextTable = rewriteTableColumns(table[0], columnIndex, op.op === 'delete_table_column' ? 'delete' : 'insert');
591
722
  }
592
723
  current = replaceDocxTable(current, table, nextTable);
593
724
  zip.file('word/document.xml', current);
@@ -606,9 +737,10 @@ export async function applyDocx(zip, operations) {
606
737
  const cleaned = existing
607
738
  .replace(/<w:numPr\b[^>]*?(?:\/>|>[\s\S]*?<\/w:numPr>)/, '')
608
739
  .replace(/<w:pStyle\b[^>]*\/>/, '');
609
- const properties = '<w:pStyle w:val="ListParagraph"/>'
610
- + `<w:numPr><w:ilvl w:val="${level}"/><w:numId w:val="${numbering.numId}"/></w:numPr>`
611
- + cleaned;
740
+ const properties =
741
+ '<w:pStyle w:val="ListParagraph"/>' +
742
+ `<w:numPr><w:ilvl w:val="${level}"/><w:numId w:val="${numbering.numId}"/></w:numPr>` +
743
+ cleaned;
612
744
  const nextParagraph = replaceWordProperties(paragraph.xml, 'p', 'pPr', properties);
613
745
  const nextInner = `${model.body.inner.slice(0, paragraph.start)}${nextParagraph}${model.body.inner.slice(paragraph.end)}`;
614
746
  current = `${current.slice(0, model.body.start)}${nextInner}${current.slice(model.body.end)}`;
@@ -627,17 +759,19 @@ export async function applyDocx(zip, operations) {
627
759
  let current = await zipText(zip, 'word/document.xml');
628
760
  const relationshipId = address
629
761
  ? await addPackageRelationship(
630
- zip,
631
- partRelationshipPath('word/document.xml'),
632
- `${OFFICE_RELATIONSHIP_BASE}/hyperlink`,
633
- address,
634
- 'External',
635
- )
762
+ zip,
763
+ partRelationshipPath('word/document.xml'),
764
+ `${OFFICE_RELATIONSHIP_BASE}/hyperlink`,
765
+ address,
766
+ 'External'
767
+ )
636
768
  : '';
637
- const run = '<w:r><w:rPr><w:color w:val="0563C1"/><w:u w:val="single"/></w:rPr>'
638
- + `<w:t${/^\s|\s$/.test(display) ? ' xml:space="preserve"' : ''}>${xmlEncode(display)}</w:t></w:r>`;
639
- const link = `<w:hyperlink${relationshipId ? ` r:id="${relationshipId}"` : ''}`
640
- + `${op.subAddress ? ` w:anchor="${xmlEncode(op.subAddress)}"` : ''}>${run}</w:hyperlink>`;
769
+ const run =
770
+ '<w:r><w:rPr><w:color w:val="0563C1"/><w:u w:val="single"/></w:rPr>' +
771
+ `<w:t${/^\s|\s$/.test(display) ? ' xml:space="preserve"' : ''}>${xmlEncode(display)}</w:t></w:r>`;
772
+ const link =
773
+ `<w:hyperlink${relationshipId ? ` r:id="${relationshipId}"` : ''}` +
774
+ `${op.subAddress ? ` w:anchor="${xmlEncode(op.subAddress)}"` : ''}>${run}</w:hyperlink>`;
641
775
  // A link asked for by phrase replaces that phrase, the way Word does it.
642
776
  // Appending it to the end of the document instead put the link somewhere
643
777
  // the caller never named and still reported success.
@@ -682,30 +816,36 @@ export async function applyDocx(zip, operations) {
682
816
  let current = await zipText(zip, 'word/document.xml');
683
817
  const model = docxBodyModel(current);
684
818
  const paragraphs = model.blocks.filter((block) => block.name === 'w:p');
685
- const paragraph = op.op === 'add_provenance'
686
- ? paragraphs[Number(op.paragraph) - 1]
687
- : paragraphs.find((entry) => paragraphTexts(entry.xml, 'w:t').join('').includes(String(op.find || '')));
819
+ const paragraph =
820
+ op.op === 'add_provenance'
821
+ ? paragraphs[Number(op.paragraph) - 1]
822
+ : paragraphs.find((entry) =>
823
+ paragraphTexts(entry.xml, 'w:t')
824
+ .join('')
825
+ .includes(String(op.find || ''))
826
+ );
688
827
  if (!paragraph) {
689
- throw new Error(op.op === 'add_provenance'
690
- ? `DOCX paragraph ${op.paragraph} not found`
691
- : `DOCX text not found for comment anchor: ${op.find}`);
828
+ throw new Error(
829
+ op.op === 'add_provenance'
830
+ ? `DOCX paragraph ${op.paragraph} not found`
831
+ : `DOCX text not found for comment anchor: ${op.find}`
832
+ );
692
833
  }
693
834
  const comments = await ensureCommentsPart(zip);
694
835
  const ids = [...comments.xml.matchAll(/<w:comment\b[^>]*\bw:id="(\d+)"/g)].map((match) => Number(match[1]));
695
836
  const id = Math.max(0, ...ids) + 1;
696
837
  const stamp = new Date().toISOString().replace(/\.\d+Z$/, 'Z');
697
- const entry = `<w:comment w:id="${id}" w:author="${xmlEncode(op.author || 'Mixdog')}"`
698
- + ` w:date="${stamp}" w:initials="${xmlEncode(op.initials || 'MD')}">`
699
- + `<w:p xmlns:w14="${WORD_2010_NS}" w14:paraId="${commentParagraphId(id)}">`
700
- + `<w:r><w:t${/^\s|\s$/.test(text) ? ' xml:space="preserve"' : ''}>${xmlEncode(text)}</w:t></w:r></w:p></w:comment>`;
838
+ const entry =
839
+ `<w:comment w:id="${id}" w:author="${xmlEncode(op.author || 'Mixdog')}"` +
840
+ ` w:date="${stamp}" w:initials="${xmlEncode(op.initials || 'MD')}">` +
841
+ `<w:p xmlns:w14="${WORD_2010_NS}" w14:paraId="${commentParagraphId(id)}">` +
842
+ `<w:r><w:t${/^\s|\s$/.test(text) ? ' xml:space="preserve"' : ''}>${xmlEncode(text)}</w:t></w:r></w:p></w:comment>`;
701
843
  zip.file(comments.part, comments.xml.replace('</w:comments>', `${entry}</w:comments>`));
702
844
  await registerCommentThread(zip, { commentId: id });
703
845
  await registerCommentIdentity(zip, { commentId: id, date: stamp });
704
846
  // A comment marks the phrase it was asked about; the paragraph only when
705
847
  // the phrase cannot be cut out of its runs.
706
- const phrase = op.op === 'add_comment'
707
- ? anchorPhraseInParagraph(paragraph.xml, String(op.find || ''), id)
708
- : null;
848
+ const phrase = op.op === 'add_comment' ? anchorPhraseInParagraph(paragraph.xml, String(op.find || ''), id) : null;
709
849
  const anchored = phrase || anchorDocxComment(paragraph.xml, id);
710
850
  const nextInner = `${model.body.inner.slice(0, paragraph.start)}${anchored}${model.body.inner.slice(paragraph.end)}`;
711
851
  current = `${current.slice(0, model.body.start)}${nextInner}${current.slice(model.body.end)}`;
@@ -736,10 +876,11 @@ export async function applyDocx(zip, operations) {
736
876
  const ids = [...comments.xml.matchAll(/<w:comment\b[^>]*\bw:id="(\d+)"/g)].map((match) => Number(match[1]));
737
877
  const id = Math.max(0, ...ids) + 1;
738
878
  const stamp = new Date().toISOString().replace(/\.\d+Z$/, 'Z');
739
- const reply = `<w:comment w:id="${id}" w:author="${xmlEncode(op.author || 'Mixdog')}"`
740
- + ` w:date="${stamp}" w:initials="${xmlEncode(op.initials || 'MD')}">`
741
- + `<w:p xmlns:w14="${WORD_2010_NS}" w14:paraId="${commentParagraphId(id)}">`
742
- + `<w:r><w:t${/^\s|\s$/.test(text) ? ' xml:space="preserve"' : ''}>${xmlEncode(text)}</w:t></w:r></w:p></w:comment>`;
879
+ const reply =
880
+ `<w:comment w:id="${id}" w:author="${xmlEncode(op.author || 'Mixdog')}"` +
881
+ ` w:date="${stamp}" w:initials="${xmlEncode(op.initials || 'MD')}">` +
882
+ `<w:p xmlns:w14="${WORD_2010_NS}" w14:paraId="${commentParagraphId(id)}">` +
883
+ `<w:r><w:t${/^\s|\s$/.test(text) ? ' xml:space="preserve"' : ''}>${xmlEncode(text)}</w:t></w:r></w:p></w:comment>`;
743
884
  zip.file(comments.part, comments.xml.replace('</w:comments>', `${reply}</w:comments>`));
744
885
  await registerCommentThread(zip, { commentId: id, parentId: parent });
745
886
  await registerCommentIdentity(zip, { commentId: id, date: stamp });
@@ -747,8 +888,9 @@ export async function applyDocx(zip, operations) {
747
888
  const anchor = new RegExp(`<w:commentRangeEnd\\b[^>]*\\bw:id="${parent}"[^>]*\\/>`).exec(current);
748
889
  if (anchor) {
749
890
  const position = anchor.index;
750
- const marks = `<w:commentRangeStart w:id="${id}"/><w:commentRangeEnd w:id="${id}"/>`
751
- + `<w:r><w:commentReference w:id="${id}"/></w:r>`;
891
+ const marks =
892
+ `<w:commentRangeStart w:id="${id}"/><w:commentRangeEnd w:id="${id}"/>` +
893
+ `<w:r><w:commentReference w:id="${id}"/></w:r>`;
752
894
  zip.file('word/document.xml', `${current.slice(0, position)}${marks}${current.slice(position)}`);
753
895
  }
754
896
  results.push({ op: op.op, changed: true, comment: id, parent });
@@ -767,7 +909,13 @@ export async function applyDocx(zip, operations) {
767
909
  const next = current
768
910
  .replace(new RegExp(`<w:commentRangeStart\\b[^>]*\\bw:id="${id}"[^>]*\\/>`, 'g'), '')
769
911
  .replace(new RegExp(`<w:commentRangeEnd\\b[^>]*\\bw:id="${id}"[^>]*\\/>`, 'g'), '')
770
- .replace(new RegExp(`<w:r>(?:(?!<\\/w:r>)[\\s\\S])*?<w:commentReference\\b[^>]*\\bw:id="${id}"[^>]*\\/>[\\s\\S]*?<\\/w:r>`, 'g'), '');
912
+ .replace(
913
+ new RegExp(
914
+ `<w:r>(?:(?!<\\/w:r>)[\\s\\S])*?<w:commentReference\\b[^>]*\\bw:id="${id}"[^>]*\\/>[\\s\\S]*?<\\/w:r>`,
915
+ 'g'
916
+ ),
917
+ ''
918
+ );
771
919
  zip.file('word/document.xml', next);
772
920
  results.push({ op: op.op, changed: true, comment: id });
773
921
  continue;
@@ -790,7 +938,15 @@ export async function applyDocx(zip, operations) {
790
938
  // Word's accept-all settles them too. Snapshot ordinals run through the
791
939
  // story parts in name order, which is the order walked here.
792
940
  const stories = parts.filter((name) => !/\/comments\.xml$/i.test(name)).sort();
793
- const totals = { resolved: 0, merged: 0, cleared: 0, unmerged: 0, rowsRemoved: 0, rowsCleared: 0, propertyChanges: 0 };
941
+ const totals = {
942
+ resolved: 0,
943
+ merged: 0,
944
+ cleared: 0,
945
+ unmerged: 0,
946
+ rowsRemoved: 0,
947
+ rowsCleared: 0,
948
+ propertyChanges: 0,
949
+ };
794
950
  const reviewers = new Set();
795
951
  let ordinalOffset = 0;
796
952
  let settled = false;
@@ -820,7 +976,8 @@ export async function applyDocx(zip, operations) {
820
976
  const commentsRemoved = single ? 0 : await pruneOrphanComments(zip, parts);
821
977
  const paragraphMarks = totals.merged + totals.cleared + totals.unmerged;
822
978
  const tableRows = totals.rowsRemoved + totals.rowsCleared;
823
- const changed = totals.resolved > 0 || paragraphMarks > 0 || tableRows > 0 || totals.propertyChanges > 0 || commentsRemoved > 0;
979
+ const changed =
980
+ totals.resolved > 0 || paragraphMarks > 0 || tableRows > 0 || totals.propertyChanges > 0 || commentsRemoved > 0;
824
981
  results.push({
825
982
  op: op.op,
826
983
  changed,
@@ -830,18 +987,22 @@ export async function applyDocx(zip, operations) {
830
987
  ...(author ? { author } : {}),
831
988
  // A label that matches nobody is most often a misspelt reviewer; the
832
989
  // names actually present let the caller correct it.
833
- ...(author && !changed ? {
834
- note: reviewers.size
835
- ? `No revision by "${author}"; the tracked changes are by ${[...reviewers].map((name) => `"${name}"`).join(', ')}.`
836
- : `No revision by "${author}"; the document carries no tracked change.`,
837
- } : {}),
990
+ ...(author && !changed
991
+ ? {
992
+ note: reviewers.size
993
+ ? `No revision by "${author}"; the tracked changes are by ${[...reviewers].map((name) => `"${name}"`).join(', ')}.`
994
+ : `No revision by "${author}"; the document carries no tracked change.`,
995
+ }
996
+ : {}),
838
997
  ...(paragraphMarks ? { paragraphMarks, mergedParagraphs: totals.merged } : {}),
839
998
  ...(tableRows ? { tableRows: { removed: totals.rowsRemoved, cleared: totals.rowsCleared } } : {}),
840
999
  ...(totals.propertyChanges ? { propertyChanges: totals.propertyChanges } : {}),
841
1000
  ...(commentsRemoved ? { commentsRemoved } : {}),
842
- ...(totals.unmerged ? {
843
- note: `${totals.unmerged} paragraph mark(s) could not join the next block (a table or the end of the body); the mark was cleared instead.`,
844
- } : {}),
1001
+ ...(totals.unmerged
1002
+ ? {
1003
+ note: `${totals.unmerged} paragraph mark(s) could not join the next block (a table or the end of the body); the mark was cleared instead.`,
1004
+ }
1005
+ : {}),
845
1006
  });
846
1007
  continue;
847
1008
  }
@@ -860,11 +1021,15 @@ export async function applyDocx(zip, operations) {
860
1021
  const count = Math.max(1, columns.length);
861
1022
  const current_widths = columns.map((column) => Number(/\bw:w="(\d+)"/.exec(column[1])?.[1]) || 0);
862
1023
  const total = current_widths.reduce((sum, width) => sum + width, 0);
863
- const widths = total > 0
864
- ? current_widths.map((width) => Math.max(240, Math.round((width / total) * usable)))
865
- : Array.from({ length: count }, () => Math.round(usable / count));
1024
+ const widths =
1025
+ total > 0
1026
+ ? current_widths.map((width) => Math.max(240, Math.round((width / total) * usable)))
1027
+ : Array.from({ length: count }, () => Math.round(usable / count));
866
1028
  let nextTable = grid
867
- ? table[0].replace(grid[0], `<w:tblGrid>${widths.map((width) => `<w:gridCol w:w="${width}"/>`).join('')}</w:tblGrid>`)
1029
+ ? table[0].replace(
1030
+ grid[0],
1031
+ `<w:tblGrid>${widths.map((width) => `<w:gridCol w:w="${width}"/>`).join('')}</w:tblGrid>`
1032
+ )
868
1033
  : table[0];
869
1034
  const declared = `<w:tblW w:w="${usable}" w:type="dxa"/>`;
870
1035
  let tableProperties = op.properties
@@ -877,32 +1042,27 @@ export async function applyDocx(zip, operations) {
877
1042
  } else {
878
1043
  tableProperties = `${declared}${tableProperties}`;
879
1044
  }
880
- nextTable = replaceWordProperties(
881
- nextTable,
882
- 'tbl',
883
- 'tblPr',
884
- tableProperties,
885
- );
1045
+ nextTable = replaceWordProperties(nextTable, 'tbl', 'tblPr', tableProperties);
886
1046
  nextTable = nextTable.replace(/<w:tr(?:\s[^>]*)?>[\s\S]*?<\/w:tr>/g, (row) => {
887
1047
  let index = 0;
888
1048
  return row.replace(/<w:tc(?:\s[^>]*)?>[\s\S]*?<\/w:tc>/g, (cell) => {
889
1049
  const existing = /<w:tcPr>([\s\S]*?)<\/w:tcPr>/.exec(cell)?.[1] || '';
890
1050
  const keep = (pattern) => pattern.exec(existing)?.[0] || '';
891
1051
  const span = Math.max(1, Number(/<w:gridSpan\b[^>]*\bw:val="(\d+)"/.exec(existing)?.[1]) || 1);
892
- const width = widths.slice(index, index + span).reduce((sum, column) => sum + (column || 0), 0)
893
- || widths.at(-1);
1052
+ const width =
1053
+ widths.slice(index, index + span).reduce((sum, column) => sum + (column || 0), 0) || widths.at(-1);
894
1054
  index += span;
895
1055
  return replaceWordProperties(
896
1056
  cell,
897
1057
  'tc',
898
1058
  'tcPr',
899
- `<w:tcW w:w="${width}" w:type="dxa"/>`
900
- + keep(/<w:gridSpan\b[^>]*\/>/)
901
- + keep(/<w:hMerge\b[^>]*\/>/)
902
- + keep(/<w:vMerge\b[^>]*\/>/)
903
- + keep(/<w:tcBorders>[\s\S]*?<\/w:tcBorders>/)
904
- + keep(/<w:shd\b[^>]*\/>/)
905
- + keep(/<w:vAlign\b[^>]*\/>/),
1059
+ `<w:tcW w:w="${width}" w:type="dxa"/>` +
1060
+ keep(/<w:gridSpan\b[^>]*\/>/) +
1061
+ keep(/<w:hMerge\b[^>]*\/>/) +
1062
+ keep(/<w:vMerge\b[^>]*\/>/) +
1063
+ keep(/<w:tcBorders>[\s\S]*?<\/w:tcBorders>/) +
1064
+ keep(/<w:shd\b[^>]*\/>/) +
1065
+ keep(/<w:vAlign\b[^>]*\/>/)
906
1066
  );
907
1067
  });
908
1068
  });
@@ -929,7 +1089,9 @@ export async function applyDocx(zip, operations) {
929
1089
  if (!tag && !Number.isInteger(wanted)) throw new Error('set_content_control requires tag or control');
930
1090
  const parts = Object.keys(zip.files)
931
1091
  .filter((name) => /^word\/(document|header\d+|footer\d+)\.xml$/i.test(name))
932
- .sort((left, right) => (left === 'word/document.xml' ? -1 : right === 'word/document.xml' ? 1 : left.localeCompare(right)));
1092
+ .sort((left, right) =>
1093
+ left === 'word/document.xml' ? -1 : right === 'word/document.xml' ? 1 : left.localeCompare(right)
1094
+ );
933
1095
  let ordinal = 0;
934
1096
  let filled = null;
935
1097
  for (const part of parts) {
@@ -961,7 +1123,10 @@ export async function applyDocx(zip, operations) {
961
1123
  filled = { part, ordinal, tag: controlTag };
962
1124
  // A placeholder control shows grey prompt text until the flag goes.
963
1125
  const cleaned = control.replace(/<w:showingPlcHdr\b[^>]*\/>/g, '');
964
- return cleaned.replace(/<w:sdtContent\b[^>]*>[\s\S]*?<\/w:sdtContent>/, `<w:sdtContent>${paragraph}</w:sdtContent>`);
1126
+ return cleaned.replace(
1127
+ /<w:sdtContent\b[^>]*>[\s\S]*?<\/w:sdtContent>/,
1128
+ `<w:sdtContent>${paragraph}</w:sdtContent>`
1129
+ );
965
1130
  });
966
1131
  if (changed) {
967
1132
  zip.file(part, next);
@@ -969,9 +1134,9 @@ export async function applyDocx(zip, operations) {
969
1134
  }
970
1135
  }
971
1136
  if (!filled) {
972
- throw new Error(tag
973
- ? `DOCX content control not found for tag: ${tag}`
974
- : `DOCX content control ${wanted} not found`);
1137
+ throw new Error(
1138
+ tag ? `DOCX content control not found for tag: ${tag}` : `DOCX content control ${wanted} not found`
1139
+ );
975
1140
  }
976
1141
  results.push({
977
1142
  op: op.op,
@@ -994,23 +1159,26 @@ export async function applyDocx(zip, operations) {
994
1159
  ? paragraphs[Number(op.paragraph) - 1]
995
1160
  : paragraphs.find((entry) => paragraphTexts(entry.xml, 'w:t').join('').includes(find));
996
1161
  if (!paragraph) {
997
- throw new Error(op.paragraph
998
- ? `DOCX paragraph ${op.paragraph} not found`
999
- : `DOCX text not found for note anchor: ${find}`);
1162
+ throw new Error(
1163
+ op.paragraph ? `DOCX paragraph ${op.paragraph} not found` : `DOCX text not found for note anchor: ${find}`
1164
+ );
1000
1165
  }
1001
- const ids = [...definition.xml.matchAll(new RegExp(`<${definition.tag}\\b[^>]*\\bw:id="(-?\\d+)"`, 'g'))]
1002
- .map((match) => Number(match[1]));
1166
+ const ids = [...definition.xml.matchAll(new RegExp(`<${definition.tag}\\b[^>]*\\bw:id="(-?\\d+)"`, 'g'))].map(
1167
+ (match) => Number(match[1])
1168
+ );
1003
1169
  const id = Math.max(0, ...ids) + 1;
1004
- const entry = `<${definition.tag} w:id="${id}">`
1005
- + `<w:p><w:pPr><w:pStyle w:val="${definition.textStyle}"/></w:pPr>`
1006
- + `<w:r><w:rPr><w:rStyle w:val="${definition.style}"/><w:vertAlign w:val="superscript"/></w:rPr>`
1007
- + `<w:${definition.reference === 'w:footnoteReference' ? 'footnoteRef' : 'endnoteRef'}/></w:r>`
1008
- + `<w:r><w:t xml:space="preserve"> ${xmlEncode(text)}</w:t></w:r></w:p></${definition.tag}>`;
1170
+ const entry =
1171
+ `<${definition.tag} w:id="${id}">` +
1172
+ `<w:p><w:pPr><w:pStyle w:val="${definition.textStyle}"/></w:pPr>` +
1173
+ `<w:r><w:rPr><w:rStyle w:val="${definition.style}"/><w:vertAlign w:val="superscript"/></w:rPr>` +
1174
+ `<w:${definition.reference === 'w:footnoteReference' ? 'footnoteRef' : 'endnoteRef'}/></w:r>` +
1175
+ `<w:r><w:t xml:space="preserve"> ${xmlEncode(text)}</w:t></w:r></w:p></${definition.tag}>`;
1009
1176
  zip.file(definition.part, definition.xml.replace(`</${definition.root}>`, `${entry}</${definition.root}>`));
1010
1177
  // The mark belongs right after the phrase it cites; a phrase split across
1011
1178
  // a tab, field, or drawing falls back to the end of its paragraph.
1012
- const mark = `<w:r><w:rPr><w:rStyle w:val="${definition.style}"/><w:vertAlign w:val="superscript"/></w:rPr>`
1013
- + `<${definition.reference} w:id="${id}"/></w:r>`;
1179
+ const mark =
1180
+ `<w:r><w:rPr><w:rStyle w:val="${definition.style}"/><w:vertAlign w:val="superscript"/></w:rPr>` +
1181
+ `<${definition.reference} w:id="${id}"/></w:r>`;
1014
1182
  const phrase = find ? anchorPhraseInParagraph(paragraph.xml, find, id, { start: '', end: mark }) : null;
1015
1183
  const anchored = phrase || paragraph.xml.replace(/<\/w:p>$/, `${mark}</w:p>`);
1016
1184
  const nextInner = `${model.body.inner.slice(0, paragraph.start)}${anchored}${model.body.inner.slice(paragraph.end)}`;
@@ -1035,11 +1203,16 @@ export async function applyDocx(zip, operations) {
1035
1203
  const paragraphs = model.blocks.filter((block) => block.name === 'w:p');
1036
1204
  const paragraph = op.paragraph
1037
1205
  ? paragraphs[Number(op.paragraph) - 1]
1038
- : paragraphs.find((entry) => paragraphTexts(entry.xml, 'w:t').join('').includes(String(op.find || '')));
1206
+ : paragraphs.find((entry) =>
1207
+ paragraphTexts(entry.xml, 'w:t')
1208
+ .join('')
1209
+ .includes(String(op.find || ''))
1210
+ );
1039
1211
  if (!paragraph) throw new Error('add_bookmark could not resolve a target paragraph');
1040
1212
  const opening = /^<w:p(?:\s[^>]*)?>(?:<w:pPr(?:\s[^>]*)?>[\s\S]*?<\/w:pPr>)?/.exec(paragraph.xml)?.[0] || '<w:p>';
1041
- const marked = `${opening}<w:bookmarkStart w:id="${id}" w:name="${xmlEncode(name)}"/>`
1042
- + `${paragraph.xml.slice(opening.length)}`.replace(/<\/w:p>$/, `<w:bookmarkEnd w:id="${id}"/></w:p>`);
1213
+ const marked =
1214
+ `${opening}<w:bookmarkStart w:id="${id}" w:name="${xmlEncode(name)}"/>` +
1215
+ `${paragraph.xml.slice(opening.length)}`.replace(/<\/w:p>$/, `<w:bookmarkEnd w:id="${id}"/></w:p>`);
1043
1216
  const nextInner = `${model.body.inner.slice(0, paragraph.start)}${marked}${model.body.inner.slice(paragraph.end)}`;
1044
1217
  current = `${current.slice(0, model.body.start)}${nextInner}${current.slice(model.body.end)}`;
1045
1218
  zip.file('word/document.xml', current);
@@ -1074,7 +1247,7 @@ export async function applyDocx(zip, operations) {
1074
1247
  section,
1075
1248
  header ? 'headerReference' : 'footerReference',
1076
1249
  kind,
1077
- written.relationshipId,
1250
+ written.relationshipId
1078
1251
  );
1079
1252
  return kind === 'first' && !/<w:titlePg\b/.test(referenced)
1080
1253
  ? upsertSectionChild(referenced, 'titlePg', '<w:titlePg/>', ['pgMar', 'pgSz'])
@@ -1083,7 +1256,14 @@ export async function applyDocx(zip, operations) {
1083
1256
  zip.file('word/document.xml', next);
1084
1257
  // replaced says the section already had this story: whatever stood there
1085
1258
  // — a page number, an earlier line — is gone, not beside the new text.
1086
- results.push({ op: op.op, changed: true, part: written.part, header, kind, ...(written.replaced ? { replaced: true } : {}) });
1259
+ results.push({
1260
+ op: op.op,
1261
+ changed: true,
1262
+ part: written.part,
1263
+ header,
1264
+ kind,
1265
+ ...(written.replaced ? { replaced: true } : {}),
1266
+ });
1087
1267
  continue;
1088
1268
  }
1089
1269
  if (op.op === 'add_page_numbers') {
@@ -1105,22 +1285,28 @@ export async function applyDocx(zip, operations) {
1105
1285
  ? String(op.alignment).toLowerCase()
1106
1286
  : 'center';
1107
1287
  const prefix = op.prefix ? `<w:r><w:t xml:space="preserve">${xmlEncode(op.prefix)} </w:t></w:r>` : '';
1108
- const separator = op.includeTotal === true
1109
- ? `<w:r><w:t xml:space="preserve"> ${xmlEncode(op.separator || '/')} </w:t></w:r>`
1110
- + '<w:fldSimple w:instr=" NUMPAGES "><w:r><w:t>1</w:t></w:r></w:fldSimple>'
1111
- : '';
1112
- const body = `<w:p><w:pPr><w:jc w:val="${alignment}"/></w:pPr>${prefix}`
1113
- + '<w:fldSimple w:instr=" PAGE "><w:r><w:t>1</w:t></w:r></w:fldSimple>'
1114
- + `${separator}</w:p>`;
1288
+ const separator =
1289
+ op.includeTotal === true
1290
+ ? `<w:r><w:t xml:space="preserve"> ${xmlEncode(op.separator || '/')} </w:t></w:r>` +
1291
+ '<w:fldSimple w:instr=" NUMPAGES "><w:r><w:t>1</w:t></w:r></w:fldSimple>'
1292
+ : '';
1293
+ const body =
1294
+ `<w:p><w:pPr><w:jc w:val="${alignment}"/></w:pPr>${prefix}` +
1295
+ '<w:fldSimple w:instr=" PAGE "><w:r><w:t>1</w:t></w:r></w:fldSimple>' +
1296
+ `${separator}</w:p>`;
1115
1297
  const written = await writeHeaderFooterPart(zip, { header, body, documentXml: current, kind });
1116
- const next = writeSectionPropertiesAt(current, op.section, (section) => upsertSectionReference(
1117
- section,
1118
- header ? 'headerReference' : 'footerReference',
1119
- kind,
1120
- written.relationshipId,
1121
- ));
1298
+ const next = writeSectionPropertiesAt(current, op.section, (section) =>
1299
+ upsertSectionReference(section, header ? 'headerReference' : 'footerReference', kind, written.relationshipId)
1300
+ );
1122
1301
  zip.file('word/document.xml', next);
1123
- results.push({ op: op.op, changed: true, part: written.part, header, includeTotal: op.includeTotal === true, ...(written.replaced ? { replaced: true } : {}) });
1302
+ results.push({
1303
+ op: op.op,
1304
+ changed: true,
1305
+ part: written.part,
1306
+ header,
1307
+ includeTotal: op.includeTotal === true,
1308
+ ...(written.replaced ? { replaced: true } : {}),
1309
+ });
1124
1310
  continue;
1125
1311
  }
1126
1312
  if (op.op === 'insert_break') {
@@ -1137,7 +1323,7 @@ export async function applyDocx(zip, operations) {
1137
1323
  const closing = upsertSectionChild(
1138
1324
  match ? match[0] : '<w:sectPr></w:sectPr>',
1139
1325
  'type',
1140
- `<w:type w:val="${kind === 'section_continuous' ? 'continuous' : 'nextPage'}"/>`,
1326
+ `<w:type w:val="${kind === 'section_continuous' ? 'continuous' : 'nextPage'}"/>`
1141
1327
  );
1142
1328
  const block = `<w:p><w:pPr>${closing}</w:pPr></w:p>`;
1143
1329
  const next = insertDocxBlockAt(current, block, op.paragraph);