@tea-agent/loop-agent 0.52.0-next.1 → 0.52.0-next.11

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 (234) hide show
  1. package/CHANGELOG.md +99 -21
  2. package/dist/build-stamp.json +3 -3
  3. package/dist/cli/command-definitions.js +1 -75
  4. package/dist/cli/help.js +1 -1
  5. package/dist/cli/program.js +1 -28
  6. package/dist/commands/init-accepted-merge.js +46 -0
  7. package/dist/commands/init-upgrade.js +115 -2
  8. package/dist/commands/init.js +79 -12
  9. package/dist/executors/pi-sdk-executor.js +3 -3
  10. package/dist/governance/path-guard.js +2 -0
  11. package/dist/records/harvest.js +1 -1
  12. package/dist/shared/git-progress.js +3 -0
  13. package/dist/shared/operator/capabilities.js +0 -122
  14. package/dist/shared/pi-context-pressure/checkpoint.js +94 -24
  15. package/dist/shared/pi-context-pressure/compaction-policy.js +152 -66
  16. package/dist/shared/pi-context-pressure/extension.js +32 -8
  17. package/dist/shared/pi-context-pressure/index.js +1 -1
  18. package/dist/shared/pi-context-pressure/telemetry.js +15 -0
  19. package/dist/shared/update/npm-client.js +14 -3
  20. package/dist/task/config-types.js +5 -10
  21. package/dist/task/delegate.js +1 -1
  22. package/dist/task/read-model.js +0 -4
  23. package/dist/task/runtime.js +0 -1
  24. package/dist/task/worktree.js +1 -1
  25. package/dist/worker/console/chat/api-workbench-core.js +17 -6
  26. package/dist/worker/console/chat/api-workbench.js +2 -0
  27. package/dist/worker/console/chat/assistant-content.js +21 -3
  28. package/dist/worker/console/chat/chat-event-projection.js +6 -0
  29. package/dist/worker/console/chat/chat-event-store.js +32 -2
  30. package/dist/worker/console/chat/chat-references.js +4 -0
  31. package/dist/worker/console/chat/compaction-errors.js +14 -2
  32. package/dist/worker/console/chat/context-insights.js +41 -4
  33. package/dist/worker/console/chat/context-usage.js +4 -1
  34. package/dist/worker/console/chat/pi-runtime/custom-tools/apiworkbench-tools.js +65 -3
  35. package/dist/worker/console/chat/pi-runtime/custom-tools/browser-tools.js +2 -2
  36. package/dist/worker/console/chat/pi-runtime/extension-bindings.js +39 -0
  37. package/dist/worker/console/chat/pi-runtime/sdk-bindings.js +4 -0
  38. package/dist/worker/console/chat/pi-runtime.js +389 -191
  39. package/dist/worker/console/chat/repo-browser.js +5 -2
  40. package/dist/worker/console/chat/repo-preview-kind.js +16 -6
  41. package/dist/worker/console/chat/routes.js +299 -25
  42. package/dist/worker/console/chat/scheduled-goal-request.js +1 -1
  43. package/dist/worker/console/chat/subagents/jobs.js +115 -4
  44. package/dist/worker/console/chat/terminal-sessions.js +52 -6
  45. package/dist/worker/console/chat/tool-exposure-catalog.js +1 -1
  46. package/dist/worker/console/chat/tool-presentation.js +17 -10
  47. package/dist/worker/console/chat/tool-preview.js +22 -0
  48. package/dist/worker/console/chat/turn-process.js +49 -0
  49. package/dist/worker/console/chat/vcp-prompt.js +14 -9
  50. package/dist/worker/console/chat/workspace-changes.js +17 -0
  51. package/dist/worker/console/console-update-runtime.js +5 -1
  52. package/dist/worker/console/operator-actions.js +7 -6
  53. package/dist/worker/console/operator-user-error.js +5 -1
  54. package/dist/worker/console/pi-compaction-settings.js +220 -0
  55. package/dist/worker/console/routes.js +1 -1
  56. package/dist/worker/console/server.js +148 -6
  57. package/dist/worker/console/static/assets/FilePreviewDocx-ybM3ZqSl.js +9 -0
  58. package/dist/worker/console/static/assets/abnfDiagram-N423BO3Z-CT26sIgH.js +1 -0
  59. package/dist/worker/console/static/assets/{arc-Bkf_oc0_.js → arc-CPwLqDB0.js} +1 -1
  60. package/dist/worker/console/static/assets/architectureDiagram-T3A2C74G-CzTSMPU_.js +36 -0
  61. package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-D62uVvbI.js → blockDiagram-VBNYF7ZC-BfgbtJLH.js} +1 -1
  62. package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-Iq0Y8Afx.js → c4Diagram-5PPSVZJV-B9pTjB8U.js} +1 -1
  63. package/dist/worker/console/static/assets/channel-DtYRMDck.js +1 -0
  64. package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-D1TxRE3k.js → chunk-2GRJ4B5K-xORV8QsC.js} +1 -1
  65. package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-BE-DHkAO.js → chunk-2Q5K7J3B-BzpYWAHK.js} +1 -1
  66. package/dist/worker/console/static/assets/{chunk-5RXB4S5H-t0iYO8Cc.js → chunk-5RXB4S5H-D8zcRP6c.js} +1 -1
  67. package/dist/worker/console/static/assets/{chunk-5VM5RSS4-Clo2nExi.js → chunk-5VM5RSS4-DVEXxzQJ.js} +1 -1
  68. package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-C7bSpo-3.js → chunk-6Q2QTUOP-CKZOJU2z.js} +1 -1
  69. package/dist/worker/console/static/assets/{chunk-GF5L2VYU-DorZaymh.js → chunk-GF5L2VYU-Cgx34Dj8.js} +1 -1
  70. package/dist/worker/console/static/assets/{chunk-JWPE2WC7-Ch_4HvyJ.js → chunk-JWPE2WC7-ehcSKOcx.js} +1 -1
  71. package/dist/worker/console/static/assets/{chunk-KBJHAD2P-yaSoFe-3.js → chunk-KBJHAD2P-CiY9emCG.js} +1 -1
  72. package/dist/worker/console/static/assets/{chunk-RYQCIY6F-QpjaXecS.js → chunk-RYQCIY6F-Bk9X-ksQ.js} +1 -1
  73. package/dist/worker/console/static/assets/{chunk-XXDRQBXY-B3t6cycg.js → chunk-XXDRQBXY-DC0xXfHy.js} +1 -1
  74. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DyesHbs5.js +1 -0
  75. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DyesHbs5.js +1 -0
  76. package/dist/worker/console/static/assets/cose-bilkent-JH36ORCC-C_EVg5l9.js +1 -0
  77. package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-CP8LtrOl.js → cynefin-VYW2F7L2-BIFL8KrA.js} +1 -1
  78. package/dist/worker/console/static/assets/cynefinDiagram-MW4NZA55-DjtUYOlE.js +62 -0
  79. package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-BK0ua9V8.js → dagre-VZM6K2ZE-D2aN2V9t.js} +1 -1
  80. package/dist/worker/console/static/assets/{diagram-7IWD3JNH-t9-HP13j.js → diagram-7IWD3JNH-D_twhmFi.js} +1 -1
  81. package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-L5Sg9jMD.js → diagram-B4RE2ZJO-ChzncqLV.js} +1 -1
  82. package/dist/worker/console/static/assets/diagram-LBJQPF4R-B6LO-bF2.js +24 -0
  83. package/dist/worker/console/static/assets/diagram-Q27KOJAE-GrzM7AFc.js +24 -0
  84. package/dist/worker/console/static/assets/diagram-UB23O5K3-Bv-lntaq.js +41 -0
  85. package/dist/worker/console/static/assets/docx-preview-CAbT0VNs.js +23 -0
  86. package/dist/worker/console/static/assets/docxPreview-D_T4B7qe.js +1 -0
  87. package/dist/worker/console/static/assets/ebnfDiagram-BXEA7PRR-BvD2jkO_.js +1 -0
  88. package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-CNOuj3BO.js → erDiagram-JOGREHBK-BirPCcmA.js} +1 -1
  89. package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-h_Cyayai.js → flowDiagram-UKHOOZJN-Chu1YnGQ.js} +1 -1
  90. package/dist/worker/console/static/assets/ganttDiagram-PKOTCBZU-Djn17xhB.js +292 -0
  91. package/dist/worker/console/static/assets/gitGraphDiagram-DS77QQ5N-Bx1qbGHx.js +106 -0
  92. package/dist/worker/console/static/assets/infoDiagram-6WML65LV-D-TLMqmb.js +2 -0
  93. package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-DAdf5lHp.js → ishikawaDiagram-WSZJBQD7-DbJoh-6T.js} +1 -1
  94. package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-BQbGtg66.js → journeyDiagram-NVQOT4AX-DsyokZ6e.js} +1 -1
  95. package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-CetLubYc.js → kanban-definition-27J2QSJJ-DlzXTxic.js} +1 -1
  96. package/dist/worker/console/static/assets/{linear-DLZOjaVz.js → linear-ClnZn3vw.js} +1 -1
  97. package/dist/worker/console/static/assets/main-D-ZQ4gLb.css +1 -0
  98. package/dist/worker/console/static/assets/main-fc3P1HID.js +645 -0
  99. package/dist/worker/console/static/assets/{mermaid.core-B_xZl_gM.js → mermaid.core-DqSlcvbf.js} +5 -5
  100. package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-Dzo3dzp0.js → mindmap-definition-FAOFIHXS-CSFbzpiX.js} +1 -1
  101. package/dist/worker/console/static/assets/pegDiagram-VL7TDLO6-DK80yQqe.js +1 -0
  102. package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-Cp3YrVzQ.js → pieDiagram-7S7Q4E2Y-DWX7SFGb.js} +1 -1
  103. package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-4tI5mUgW.js → quadrantDiagram-CIZ2JOQS-BEPPhtXs.js} +1 -1
  104. package/dist/worker/console/static/assets/railroadDiagram-AXF67PYL-Ck_s6fQn.js +1 -0
  105. package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-DY-0JqdT.js → requirementDiagram-LRYGKXZP-CYig27Rj.js} +1 -1
  106. package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-DuJIzRKC.js → sankeyDiagram-W5VNT64P-u-0aSx5s.js} +1 -1
  107. package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-BTbVJ85l.js → sequenceDiagram-SI44F4Z6-NsEJI9sM.js} +1 -1
  108. package/dist/worker/console/static/assets/{sheet-workbook-BPPh1uLw.js → sheet-workbook-kZ_HK4Sg.js} +2 -2
  109. package/dist/worker/console/static/assets/sizeCapture-X5ZJPWSS-8vneVM5U.js +1 -0
  110. package/dist/worker/console/static/assets/stateDiagram-OKZ733FA-CMIobUBh.js +1 -0
  111. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Bd0pHHKP.js +1 -0
  112. package/dist/worker/console/static/assets/swimlanes-SLNWSIFB-D4Qzt6ug.js +2 -0
  113. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-BzmSZnl_.js +8 -0
  114. package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-GR6lxokn.js → timeline-definition-Z64GVDOM-DMb1LpED.js} +1 -1
  115. package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-DEkwyzsF.js → vennDiagram-T6HMQDX7-C_9eFOs3.js} +1 -1
  116. package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-W5jnvEJ3.js → wardleyDiagram-T6FBY63Y-DJYMe3uT.js} +1 -1
  117. package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-cqsloioo.js → xychartDiagram-ELKLHX3M-Cv_1Mi3u.js} +1 -1
  118. package/dist/worker/console/static/docx-preview.html +25 -0
  119. package/dist/worker/console/static/index.html +3 -2
  120. package/dist/worker/console/static/vcp/fonts/README.md +28 -0
  121. package/dist/worker/console/static/vcp/vendor/vcp-engine-v1.js +4 -4
  122. package/dist/worker/console/static-src/operator-chat/StateDot.js +17 -0
  123. package/dist/worker/console/static-src/operator-chat/changed-file-diff.js +15 -0
  124. package/dist/worker/console/static-src/operator-chat/chat-font-size.js +90 -0
  125. package/dist/worker/console/static-src/operator-chat/chat-session-order.js +96 -0
  126. package/dist/worker/console/static-src/operator-chat/chat-sse-events.js +8 -1
  127. package/dist/worker/console/static-src/operator-chat/compaction-message.js +4 -0
  128. package/dist/worker/console/static-src/operator-chat/details-rail-surfaces.js +2 -0
  129. package/dist/worker/console/static-src/operator-chat/file-touch.js +107 -0
  130. package/dist/worker/console/static-src/operator-chat/format-file-size.js +26 -0
  131. package/dist/worker/console/static-src/operator-chat/open-preview-in-browser.js +44 -0
  132. package/dist/worker/console/static-src/operator-chat/reference-display.js +7 -1
  133. package/dist/worker/console/static-src/operator-chat/tasks-auto-open.js +100 -0
  134. package/dist/worker/console/static-src/operator-chat/tasks-layout-tween.js +103 -0
  135. package/dist/worker/console/static-src/operator-chat/tasks-model.js +657 -0
  136. package/dist/worker/console/static-src/operator-chat/tasks-view-glide.js +96 -0
  137. package/dist/worker/console/static-src/operator-chat/turn-group-equality.js +1 -0
  138. package/dist/worker/console/static-src/operator-chat/use-auto-animate.js +61 -0
  139. package/dist/worker/console/static-src/operator-chat/useChatSessions.js +194 -47
  140. package/dist/worker/console/static-src/operator-chat/useChatStream.js +4 -0
  141. package/dist/worker/console/static-src/operator-chat/useChatThread.js +18 -0
  142. package/dist/worker/console/static-src/operator-chat/useRepoBrowser.js +111 -21
  143. package/dist/worker/console/static-src/operator-chat/useRuntimeControls.js +91 -47
  144. package/dist/worker/console/static-src/operator-chat/useVcpPreferences.js +1 -1
  145. package/dist/worker/console/static-src/operator-chat/user-turn-anchors-merge.js +50 -0
  146. package/dist/worker/console/static-src/operator-chat/vcp-fonts.js +180 -22
  147. package/dist/worker/console/static-src/operator-chat/vcp-frame.js +3 -3
  148. package/dist/worker/console/static-src/shell/console-update-progress.js +16 -0
  149. package/dist/worker/console/static-src/shell/console-update-reload.js +4 -1
  150. package/dist/worker/console/static-src/shell/workspace-route.js +0 -2
  151. package/dist/worker/console/vite.config.js +5 -1
  152. package/dist/worker/console/workspace-registry.js +62 -19
  153. package/dist/worker/observe/static/operator-chrome.js +0 -1
  154. package/dist/worker/scheduler/git-base.js +3 -0
  155. package/dist/worker/scheduler/night-git-finalizer.js +1 -1
  156. package/dist/worker/scheduler/night-harvest.js +1 -1
  157. package/dist/worker/scheduler/prepared-attempt-recovery.js +1 -1
  158. package/dist/worker/scheduler/scheduled-goal-evidence.js +1 -1
  159. package/dist/workflows/dag/backend-test-scenario-param.js +60 -4
  160. package/dist/workflows/dag/dynamic-runtime/reduction.js +7 -2
  161. package/dist/workflows/dag/frontend-test-framework-adapters.js +11 -2
  162. package/dist/workflows/script/windows/guest.js +13 -2
  163. package/dist/workflows/script/windows/native.js +21 -3
  164. package/docs/architecture/dag-execution.md +2 -13
  165. package/docs/architecture/facts-and-state.md +2 -3
  166. package/docs/architecture/runtime-boundaries.md +2 -2
  167. package/package.json +9 -7
  168. package/resource-catalog.v1.json +6 -6
  169. package/scripts/patch-pi-sdk-windows-hide.mjs +3 -3
  170. package/skills/loop-agent/references/command-reference.md +2 -41
  171. package/skills/loop-agent/references/harness-policy.md +3 -30
  172. package/skills/loop-agent/references/long-running-loop.md +6 -54
  173. package/dist/application/loop/run-action.js +0 -19
  174. package/dist/commands/dag-workflow-compile.js +0 -93
  175. package/dist/commands/dag-workflow-plan.js +0 -132
  176. package/dist/commands/dag-workflow-validate.js +0 -68
  177. package/dist/commands/loop-benchmark.js +0 -74
  178. package/dist/commands/loop.js +0 -251
  179. package/dist/commands/workflow.js +0 -259
  180. package/dist/infrastructure/harness/loop-store.js +0 -41
  181. package/dist/worker/console/static/assets/abnfDiagram-N423BO3Z-FQePHM07.js +0 -1
  182. package/dist/worker/console/static/assets/architectureDiagram-T3A2C74G-p_mwm8cd.js +0 -36
  183. package/dist/worker/console/static/assets/channel-CIBAg8WF.js +0 -1
  184. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-B4xQrSmv.js +0 -1
  185. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-B4xQrSmv.js +0 -1
  186. package/dist/worker/console/static/assets/cose-bilkent-JH36ORCC-BPXf8ZYr.js +0 -1
  187. package/dist/worker/console/static/assets/cynefinDiagram-MW4NZA55-CNsL9N2-.js +0 -62
  188. package/dist/worker/console/static/assets/diagram-LBJQPF4R-BipWFRgs.js +0 -24
  189. package/dist/worker/console/static/assets/diagram-Q27KOJAE-T2p4xa38.js +0 -24
  190. package/dist/worker/console/static/assets/diagram-UB23O5K3-CVwz6LVu.js +0 -41
  191. package/dist/worker/console/static/assets/ebnfDiagram-BXEA7PRR-CybQrGSA.js +0 -1
  192. package/dist/worker/console/static/assets/ganttDiagram-PKOTCBZU-D411_55h.js +0 -292
  193. package/dist/worker/console/static/assets/gitGraphDiagram-DS77QQ5N-DpVtzs9z.js +0 -106
  194. package/dist/worker/console/static/assets/index-B7cwOTL9.js +0 -649
  195. package/dist/worker/console/static/assets/index-CATbSkPc.css +0 -1
  196. package/dist/worker/console/static/assets/infoDiagram-6WML65LV-D74Uvx6K.js +0 -2
  197. package/dist/worker/console/static/assets/pegDiagram-VL7TDLO6-CSwoBOpM.js +0 -1
  198. package/dist/worker/console/static/assets/railroadDiagram-AXF67PYL-n0Mt3Yia.js +0 -1
  199. package/dist/worker/console/static/assets/sizeCapture-X5ZJPWSS-Dmf1pC7B.js +0 -1
  200. package/dist/worker/console/static/assets/stateDiagram-OKZ733FA-4-jdPUHD.js +0 -1
  201. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-DojWfYnC.js +0 -1
  202. package/dist/worker/console/static/assets/swimlanes-SLNWSIFB-DNhjjaAU.js +0 -2
  203. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-CJo4AKWH.js +0 -8
  204. package/dist/worker/console/static/vcp/fonts/Lanxi-/345/217/257/345/256/213.woff2 +0 -0
  205. package/dist/worker/console/static/vcp/fonts/Lanxi-/346/234/227/345/256/213.woff2 +0 -0
  206. package/dist/worker/console/static/vcp/fonts/Lanxi-/350/266/205/347/262/227/351/273/221.woff2 +0 -0
  207. package/dist/workflows/dynamic/compile.js +0 -371
  208. package/dist/workflows/dynamic/compileTypes.js +0 -1
  209. package/dist/workflows/dynamic/errors.js +0 -5
  210. package/dist/workflows/dynamic/profiles.js +0 -156
  211. package/dist/workflows/dynamic/spec.js +0 -115
  212. package/dist/workflows/dynamic/validate.js +0 -275
  213. package/dist/workflows/loop/actions/dag-action.js +0 -129
  214. package/dist/workflows/loop/actions/pi-review.js +0 -267
  215. package/dist/workflows/loop/actions/shared.js +0 -157
  216. package/dist/workflows/loop/actions/shell-verify.js +0 -82
  217. package/dist/workflows/loop/actions/types.js +0 -1
  218. package/dist/workflows/loop/actions/workflow-action.js +0 -255
  219. package/dist/workflows/loop/actions.js +0 -160
  220. package/dist/workflows/loop/benchmark.js +0 -513
  221. package/dist/workflows/loop/closeout.js +0 -135
  222. package/dist/workflows/loop/context.js +0 -47
  223. package/dist/workflows/loop/events.js +0 -26
  224. package/dist/workflows/loop/hash.js +0 -32
  225. package/dist/workflows/loop/index.js +0 -8
  226. package/dist/workflows/loop/paths.js +0 -17
  227. package/dist/workflows/loop/policy/auto-policy.js +0 -112
  228. package/dist/workflows/loop/policy/path-patterns.js +0 -13
  229. package/dist/workflows/loop/rounds.js +0 -81
  230. package/dist/workflows/loop/signals.js +0 -52
  231. package/dist/workflows/loop/state.js +0 -116
  232. package/dist/workflows/loop/templates.js +0 -54
  233. package/dist/workflows/loop/types.js +0 -28
  234. /package/dist/workflows/{dynamic/artifacts.js → dag/dynamic-runtime/reduction-artifacts.js} +0 -0
@@ -17,9 +17,10 @@ export function repoHtmlPreviewUrl(origin, workspaceId, file) {
17
17
  function withHtmlPreviewUrl(preview, origin, workspaceId) {
18
18
  if (preview.kind === "image" ||
19
19
  preview.kind === "pdf" ||
20
- preview.kind === "sheet") {
21
- // Images, PDFs, and spreadsheets load their bytes from the same
22
- // workspace-scoped route that serves HTML relative assets.
20
+ preview.kind === "sheet" ||
21
+ preview.kind === "docx") {
22
+ // Images, PDFs, spreadsheets, and Word documents load their bytes from
23
+ // the same workspace-scoped route that serves HTML relative assets.
23
24
  const previewUrl = repoHtmlPreviewUrl(origin, workspaceId, preview.path);
24
25
  return previewUrl ? { ...preview, previewUrl } : preview;
25
26
  }
@@ -34,6 +35,8 @@ function withHtmlPreviewUrl(preview, origin, workspaceId) {
34
35
  htmlPreviewUrl,
35
36
  };
36
37
  }
38
+ const repoTreeCache = new Map();
39
+ const repoTreeInFlight = new Map();
37
40
  /** Details-rail repo tree + file preview tabs state. */
38
41
  export function useRepoBrowser(params) {
39
42
  const { origin, refs, sessionId, workspaceId, blocked } = params;
@@ -52,40 +55,67 @@ export function useRepoBrowser(params) {
52
55
  const previewController = useRef(null);
53
56
  const treeScopeRef = useRef(null);
54
57
  const [previewGeneration, setPreviewGeneration] = useState(0);
58
+ const [reloading, setReloading] = useState(false);
55
59
  const expandedDirsRef = useRef(new Set());
56
60
  expandedDirsRef.current = expandedDirs;
57
61
  const workspaceQuery = workspaceId
58
62
  ? `&workspaceId=${encodeURIComponent(workspaceId)}`
59
63
  : "";
60
- const loadTree = useCallback(async (directory = "") => {
64
+ const loadTree = useCallback(async (directory = "", forceNetwork = false) => {
61
65
  if (blocked)
62
66
  return; // AC-R5-002: fail-closed, zero repo requests
63
67
  if (!workspaceScopeReady(workspaceId))
64
68
  return;
65
69
  const requestWorkspaceId = workspaceId ?? null;
66
- try {
67
- setTreeError(null);
68
- const res = await fetch(`${origin}/api/operator/v1/chat/repo/tree?path=${encodeURIComponent(directory)}${workspaceQuery}`, { credentials: "include" });
69
- const body = (await res.json());
70
- if (workspaceScopeRef.current !== requestWorkspaceId)
70
+ const cacheKey = `${origin}\0${requestWorkspaceId ?? ""}\0${directory}`;
71
+ if (!forceNetwork) {
72
+ const cached = repoTreeCache.get(cacheKey);
73
+ if (cached && Date.now() - cached.fetchedAt < 15_000) {
74
+ treeScopeRef.current = requestWorkspaceId;
75
+ setTree((current) => ({
76
+ ...current,
77
+ [directory]: cached.entries,
78
+ }));
71
79
  return;
72
- if (!res.ok)
73
- throw new Error(body.error?.message ?? "无法读取仓库目录");
80
+ }
81
+ }
82
+ let promise = repoTreeInFlight.get(cacheKey);
83
+ if (!promise) {
84
+ promise = (async () => {
85
+ try {
86
+ const res = await fetch(`${origin}/api/operator/v1/chat/repo/tree?path=${encodeURIComponent(directory)}${workspaceQuery}`, { credentials: "include" });
87
+ const body = (await res.json());
88
+ if (!res.ok) {
89
+ return { error: body.error?.message ?? "无法读取仓库目录" };
90
+ }
91
+ const entries = body.data?.entries ?? [];
92
+ repoTreeCache.set(cacheKey, { entries, fetchedAt: Date.now() });
93
+ return { entries };
94
+ }
95
+ catch (error) {
96
+ return { error: error instanceof Error ? error.message : String(error) };
97
+ }
98
+ })().finally(() => {
99
+ repoTreeInFlight.delete(cacheKey);
100
+ });
101
+ repoTreeInFlight.set(cacheKey, promise);
102
+ }
103
+ const outcome = await promise;
104
+ if (workspaceScopeRef.current !== requestWorkspaceId)
105
+ return;
106
+ if (outcome.error) {
107
+ setTreeError(outcome.error);
108
+ }
109
+ else if (outcome.entries) {
110
+ const entries = outcome.entries;
111
+ setTreeError(null);
74
112
  treeScopeRef.current = requestWorkspaceId;
75
113
  setTree((current) => ({
76
114
  ...current,
77
- [directory]: body.data?.entries ?? [],
115
+ [directory]: entries,
78
116
  }));
79
117
  }
80
- catch (error) {
81
- if (workspaceScopeRef.current !== requestWorkspaceId)
82
- return;
83
- setTreeError(error instanceof Error ? error.message : String(error));
84
- }
85
118
  }, [origin, workspaceQuery, workspaceId, blocked]);
86
- useEffect(() => {
87
- void loadTree();
88
- }, [loadTree]);
89
119
  /** pi-web parity: re-fetch the root + every expanded directory. Bump
90
120
  * `refreshTick` to trigger; cached entries are NOT reused, so newly
91
121
  * created/deleted files appear without a manual refresh. */
@@ -97,8 +127,9 @@ export function useRepoBrowser(params) {
97
127
  const dirs = treeScopeRef.current === (workspaceId ?? null)
98
128
  ? ["", ...expandedDirsRef.current]
99
129
  : [""];
130
+ const force = refreshTick > 0;
100
131
  for (const dir of dirs)
101
- void loadTree(dir);
132
+ void loadTree(dir, force);
102
133
  }, [loadTree, refreshTick]);
103
134
  // Also refresh when the tab regains focus: external tools (editor, git,
104
135
  // CLI) may have changed the tree while the console was hidden.
@@ -255,6 +286,56 @@ export function useRepoBrowser(params) {
255
286
  setPreviewError(null);
256
287
  setActivePreviewPath(file);
257
288
  }, []);
289
+ /**
290
+ * Re-fetch the content of open previews in place, keeping their tab order and
291
+ * the active tab.
292
+ *
293
+ * This is what the model's own file edits trigger (see `file-touch.ts`): the
294
+ * preview is a snapshot and DSH does not watch the filesystem either, so the
295
+ * session's settled `write`/`edit` calls are the only honest signal that the
296
+ * bytes on screen are stale.
297
+ *
298
+ * Deliberately quiet: no loading spinner and no error banner replaces the
299
+ * content, because the reader is usually mid-sentence in the chat when this
300
+ * fires. A file that fails to re-read keeps its previous content rather than
301
+ * blanking the tab.
302
+ */
303
+ const reloadPreviews = useCallback(async (paths) => {
304
+ if (blocked || !workspaceScopeReady(workspaceId))
305
+ return;
306
+ const wanted = paths && paths.length > 0 ? new Set(paths.map(normalizePreviewPath)) : null;
307
+ const targets = previews.filter((item) => !wanted || wanted.has(normalizePreviewPath(item.path)));
308
+ if (targets.length === 0)
309
+ return;
310
+ const requestScope = previewScopeRef.current;
311
+ setReloading(true);
312
+ try {
313
+ await Promise.all(targets.map(async (target) => {
314
+ try {
315
+ const res = await fetch(`${origin}/api/operator/v1/chat/repo/file?path=${encodeURIComponent(target.path)}${workspaceQuery}`, { credentials: "include" });
316
+ if (!res.ok)
317
+ return;
318
+ const body = (await res.json());
319
+ const fresh = body.data;
320
+ if (!fresh || previewScopeRef.current !== requestScope)
321
+ return;
322
+ // Keep the reader's own scroll/focus state on the tab.
323
+ const merged = {
324
+ ...withHtmlPreviewUrl(fresh, origin, workspaceId),
325
+ ...(target.focusLine ? { focusLine: target.focusLine } : {}),
326
+ };
327
+ setPreviews((current) => current.map((item) => (item.path === target.path ? merged : item)));
328
+ }
329
+ catch {
330
+ // A failed re-read leaves the previous content in place.
331
+ }
332
+ }));
333
+ }
334
+ finally {
335
+ if (previewScopeRef.current === requestScope)
336
+ setReloading(false);
337
+ }
338
+ }, [blocked, workspaceId, previews, origin, workspaceQuery]);
258
339
  return {
259
340
  tree,
260
341
  expandedDirs,
@@ -266,11 +347,20 @@ export function useRepoBrowser(params) {
266
347
  previewLoading,
267
348
  previewError,
268
349
  previewGeneration,
350
+ reloading,
269
351
  setPreviews,
270
352
  loadTree,
271
353
  refreshTree,
272
354
  openPreview,
355
+ reloadPreviews,
273
356
  closePreview,
274
357
  toggleDir,
275
358
  };
276
359
  }
360
+ /**
361
+ * Compare two spellings of a file path that may differ only in separators or a
362
+ * leading `./` — the tool's argument and the tree's entry do not always agree.
363
+ */
364
+ function normalizePreviewPath(path) {
365
+ return path.replace(/\\/g, "/").replace(/^\.\//, "").trim();
366
+ }
@@ -5,6 +5,9 @@ import { isLostChatSessionError, mergeRuntimeContextWithSnapshot, runtimeSelecti
5
5
  import { buildToolCatalog } from "./tools-catalog.js";
6
6
  import { adoptMutationSnapshot, dispatchRuntimeSnapshot, getRuntimeSnapshotState, refreshRuntimeSnapshot, releaseDeferredRuntimeSnapshotFetch, settleMutationLifecycle, useRuntimeSnapshot, } from "./useRuntimeSnapshot.js";
7
7
  import { workspaceScopeReady } from "./useWorkspaceBrowserGate.js";
8
+ const capabilitiesCache = new Map();
9
+ const capabilitiesInFlight = new Map();
10
+ const modelsInFlight = new Map();
8
11
  /**
9
12
  * Monotonic mutation sequence shared across switchRuntime calls (RF-04). Each
10
13
  * mutation captures its own token; only the LATEST started token may settle
@@ -43,24 +46,46 @@ export function useRuntimeControls(params) {
43
46
  }, [session?.sessionId, setSwitching]);
44
47
  const snapshotState = useRuntimeSnapshot();
45
48
  const snapshot = snapshotState.snapshot;
49
+ const scopeGenerationRef = useRef(0);
50
+ const modelsGenerationRef = useRef(0);
46
51
  const loadCapabilities = useCallback(async () => {
47
- try {
48
- // Workspace-scoped: the server rejects a bare capabilities call with
49
- // WORKSPACE_REQUIRED. Wait for a selected workspace instead of firing
50
- // an unscoped request that shows up as a 400 in the browser Network panel.
51
- const scope = (session?.workspaceId ??
52
- params.workspaceId ??
53
- "").trim();
54
- if (!workspaceScopeReady(scope))
55
- return;
56
- const res = await fetch(`${origin}/api/operator/v1/chat/capabilities?workspaceId=${encodeURIComponent(scope)}`);
57
- if (!res.ok)
52
+ const scope = (session?.workspaceId ??
53
+ params.workspaceId ??
54
+ "").trim();
55
+ if (!workspaceScopeReady(scope))
56
+ return;
57
+ const generation = ++scopeGenerationRef.current;
58
+ const cacheKey = `${origin}\0${scope}`;
59
+ const cached = capabilitiesCache.get(cacheKey);
60
+ // P1-B: Low-latency cached hint so the tool menu / capabilities are available immediately
61
+ if (cached) {
62
+ setCapabilities(cached.body);
63
+ if (Date.now() - cached.fetchedAt < 60_000)
58
64
  return;
59
- const body = (await res.json());
60
- setCapabilities(body);
61
65
  }
62
- catch {
63
- // capabilities optional; Chat still works without them
66
+ let promise = capabilitiesInFlight.get(cacheKey);
67
+ if (!promise) {
68
+ promise = (async () => {
69
+ try {
70
+ const res = await fetch(`${origin}/api/operator/v1/chat/capabilities?workspaceId=${encodeURIComponent(scope)}`);
71
+ if (!res.ok)
72
+ return null;
73
+ const body = (await res.json());
74
+ capabilitiesCache.set(cacheKey, { body, fetchedAt: Date.now() });
75
+ return body;
76
+ }
77
+ catch {
78
+ return null;
79
+ }
80
+ })().finally(() => {
81
+ capabilitiesInFlight.delete(cacheKey);
82
+ });
83
+ capabilitiesInFlight.set(cacheKey, promise);
84
+ }
85
+ const body = await promise;
86
+ // Generation fence: discard late response if user switched workspace
87
+ if (body && scopeGenerationRef.current === generation) {
88
+ setCapabilities(body);
64
89
  }
65
90
  }, [origin, session?.workspaceId, params.workspaceId]);
66
91
  useEffect(() => {
@@ -69,6 +94,7 @@ export function useRuntimeControls(params) {
69
94
  // Models + thinking levels: GET lists the workspace catalog and does not
70
95
  // wait for historical Pi session reopen. Failure is a STRUCTURED error
71
96
  // (with retry), never silently folded into an empty list.
97
+ // P1-B: in-flight request deduplication and generation fence.
72
98
  const sessionId = session?.sessionId ?? null;
73
99
  const loadModels = useCallback(async () => {
74
100
  if (!sessionId) {
@@ -77,47 +103,65 @@ export function useRuntimeControls(params) {
77
103
  setModelsForSessionId(null);
78
104
  return;
79
105
  }
106
+ const generation = ++modelsGenerationRef.current;
80
107
  setModelsStatus("loading");
81
108
  setModelsError(null);
82
- try {
83
- const res = await fetch(`${origin}/api/operator/v1/chat/sessions/${encodeURIComponent(sessionId)}/models`, { credentials: "include" });
84
- const body = (await res.json().catch(() => null));
85
- // Guard against a stale response landing after the user switched/
86
- // created/forked a session: only adopt models for the session we
87
- // actually requested them for.
88
- if (refs.sessionRef.current?.sessionId !== sessionId)
89
- return;
90
- if (!res.ok || !body) {
91
- const error = body
92
- ?.error;
93
- if (isLostChatSessionError({
94
- status: res.status,
95
- code: error?.code,
96
- message: error?.message,
97
- })) {
98
- setModelsStatus("idle");
99
- setModelsError(null);
100
- setModelsForSessionId(sessionId);
101
- onUnrecoverableSession?.(sessionId);
102
- return;
109
+ const inFlightKey = `${origin}\0${sessionId}`;
110
+ let promise = modelsInFlight.get(inFlightKey);
111
+ if (!promise) {
112
+ promise = (async () => {
113
+ try {
114
+ const res = await fetch(`${origin}/api/operator/v1/chat/sessions/${encodeURIComponent(sessionId)}/models`, { credentials: "include" });
115
+ const body = (await res.json().catch(() => null));
116
+ if (!res.ok || !body) {
117
+ return {
118
+ error: body?.error ?? {
119
+ message: `模型列表读取失败(HTTP ${res.status})`,
120
+ },
121
+ };
122
+ }
123
+ return body;
124
+ }
125
+ catch (reason) {
126
+ return {
127
+ error: {
128
+ message: reason instanceof Error ? reason.message : String(reason),
129
+ },
130
+ };
103
131
  }
104
- setModelsStatus("error");
105
- setModelsError(error?.message ?? `模型列表读取失败(HTTP ${res.status})`);
132
+ })().finally(() => {
133
+ modelsInFlight.delete(inFlightKey);
134
+ });
135
+ modelsInFlight.set(inFlightKey, promise);
136
+ }
137
+ const result = await promise;
138
+ // Generation & session fence: ignore if session switched or newer load triggered
139
+ if (modelsGenerationRef.current !== generation ||
140
+ refs.sessionRef.current?.sessionId !== sessionId) {
141
+ return;
142
+ }
143
+ if (!result || result.error) {
144
+ const error = result?.error;
145
+ if (isLostChatSessionError({
146
+ status: 404,
147
+ code: error?.code,
148
+ message: error?.message,
149
+ })) {
150
+ setModelsStatus("idle");
151
+ setModelsError(null);
106
152
  setModelsForSessionId(sessionId);
153
+ onUnrecoverableSession?.(sessionId);
107
154
  return;
108
155
  }
109
- setModels(body.models ?? []);
110
- setThinkingLevels(body.thinkingLevels ?? []);
111
- setModelsStatus("ready");
112
- setModelsForSessionId(sessionId);
113
- }
114
- catch (reason) {
115
- if (refs.sessionRef.current?.sessionId !== sessionId)
116
- return;
117
156
  setModelsStatus("error");
118
- setModelsError(reason instanceof Error ? reason.message : String(reason));
157
+ setModelsError(error?.message ?? "模型列表读取失败");
119
158
  setModelsForSessionId(sessionId);
159
+ return;
120
160
  }
161
+ setModels(result.models ?? []);
162
+ setThinkingLevels(result.thinkingLevels ?? []);
163
+ setModelsStatus("ready");
164
+ setModelsForSessionId(sessionId);
121
165
  }, [origin, sessionId, refs, onUnrecoverableSession]);
122
166
  useEffect(() => {
123
167
  void loadModels();
@@ -30,7 +30,7 @@ export const VCP_STYLES = [
30
30
  id: "warm-minimal",
31
31
  label: "暖调极简",
32
32
  subtitle: "轻奢无彩色/纸感",
33
- scene: "暖米白宣纸基底,朗宋可宋质感,适合产品落地页与品牌物料",
33
+ scene: "暖米白宣纸基底,衬线标题搭配黑体正文,适合产品落地页与品牌物料",
34
34
  color: "#b45309",
35
35
  bgTint: "rgba(180, 83, 9, 0.12)",
36
36
  },
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Merge the server's turn outline with the turns the client already renders.
3
+ *
4
+ * The outline is the authority on numbering, but it is produced only when a
5
+ * session is loaded or reloaded. A message sent in this tab arrives through the
6
+ * event stream and never reaches it, so using the outline alone froze the rail
7
+ * at whatever it held when the session opened: the new input appeared in the
8
+ * transcript with no anchor on the rail.
9
+ *
10
+ * DSH reaches the same conclusion for its own rail — `mergeTurnRailItems`
11
+ * unions the loaded turns with the outline rather than choosing one, keyed by
12
+ * turn number and re-sorted. This port keys by message id because the Console
13
+ * outline identifies messages, and appends unknown turns after the known ones
14
+ * so the server's numbering stays authoritative.
15
+ */
16
+ /**
17
+ * @param outline - server-authoritative entries, may be empty or stale.
18
+ * @param turns - user messages currently in the transcript, in display order.
19
+ * @returns anchors ordered by index; outline entries keep their own index, and
20
+ * turns the outline does not know are numbered after the highest known one.
21
+ */
22
+ export function mergeTurnAnchors(outline, turns) {
23
+ if (!outline || outline.length === 0) {
24
+ return turns.map((turn, index) => ({
25
+ id: turn.id,
26
+ index: index + 1,
27
+ text: turn.text,
28
+ createdAt: turn.createdAt,
29
+ }));
30
+ }
31
+ const known = new Set(outline.map((item) => item.messageId));
32
+ let nextIndex = outline.reduce((max, item) => Math.max(max, item.index), 0) + 1;
33
+ const appended = turns
34
+ .filter((turn) => !known.has(turn.id))
35
+ .map((turn) => ({
36
+ id: turn.id,
37
+ index: nextIndex++,
38
+ text: turn.text,
39
+ createdAt: turn.createdAt,
40
+ }));
41
+ return [
42
+ ...outline.map((item) => ({
43
+ id: item.messageId,
44
+ index: item.index,
45
+ text: item.textPreview,
46
+ createdAt: item.createdAt,
47
+ })),
48
+ ...appended,
49
+ ];
50
+ }
@@ -1,19 +1,182 @@
1
1
  /**
2
- * VCP built-in font registry: the shipped core Lanxi-* woff2 subsets under
3
- * /vcp/fonts/**. Cards reference them by bare font-family name; the host
4
- * injects global @font-face declarations once (upstream ensureGlobalFonts
5
- * parity — without this every Lanxi-* reference silently falls back to the
6
- * system face). Paths must be URL-encoded when declared.
2
+ * VCP font strategy: a small, legible palette instead of a display-face
3
+ * catalogue.
4
+ *
5
+ * Two sources of families are published to cards:
6
+ *
7
+ * 1. Built-in `Lanxi-*` woff2 subsets under /vcp/fonts/**. Deliberately small
8
+ * (see `VCP_BUILTIN_FONTS`): only faces that are (a) SIL OFL 1.1 licensed
9
+ * so they can ship inside the npm package, and (b) not already covered by a
10
+ * reliable system font. Removed earlier: `Lanxi-超粗黑` (strokes merge into
11
+ * a solid block at heading sizes), `Lanxi-可宋` and `Lanxi-朗宋` (both
12
+ * "Noncommercial" licensed, 5 MB together, and redundant with the
13
+ * `Vcp-Serif` system serif chain).
14
+ * 2. Platform aliases (`Vcp-Sans` / `Vcp-Serif` / `Vcp-Kai` / `Vcp-Mono`).
15
+ * Each alias is declared as an `@font-face` whose `src` is a `local()`
16
+ * fallback chain of faces shipped with macOS / Windows, so a card can name
17
+ * one token and still get PingFang SC, Songti SC, Kaiti SC, Microsoft
18
+ * YaHei, SimSun, KaiTi, Segoe UI, Menlo, Consolas … without the model
19
+ * hand-rolling a font stack (and getting it wrong on the other OS).
20
+ *
21
+ * Cards reference built-ins by bare family name; the host injects global
22
+ * @font-face declarations once (upstream ensureGlobalFonts parity — without
23
+ * this every Lanxi-* reference silently falls back to the system face).
24
+ * Paths must be URL-encoded when declared.
7
25
  */
8
- export const VCP_BUILTIN_FONT_FAMILIES = [
9
- "Lanxi-超粗黑",
10
- "Lanxi-可宋",
11
- "Lanxi-朗宋",
12
- "Lanxi-HeiTi",
13
- "Lanxi-HeiTiBold",
14
- "Lanxi-WenKai",
26
+ export const VCP_BUILTIN_FONTS = [
27
+ { family: "Lanxi-HeiTi", weight: 400, source: "Noto Sans CJK SC", license: "OFL-1.1" },
28
+ { family: "Lanxi-HeiTiBold", weight: 700, source: "Noto Sans CJK SC Bold", license: "OFL-1.1" },
29
+ { family: "Lanxi-WenKai", weight: 400, source: "LXGW WenKai GB Lite", license: "OFL-1.1" },
30
+ ];
31
+ export const VCP_BUILTIN_FONT_FAMILIES = VCP_BUILTIN_FONTS.map((font) => font.family);
32
+ /** Weight per built-in family, derived from the registry above. */
33
+ const BUILTIN_FONT_WEIGHTS = Object.fromEntries(VCP_BUILTIN_FONTS.map((font) => [font.family, font.weight]));
34
+ export const VCP_FONT_ALIASES = [
35
+ {
36
+ name: "Vcp-Sans",
37
+ label: "系统黑体(默认正文与标题)",
38
+ locals: [
39
+ "PingFang SC",
40
+ "PingFangSC-Regular",
41
+ "Hiragino Sans GB",
42
+ "HiraKakuProN-W3",
43
+ "Microsoft YaHei UI",
44
+ "MicrosoftYaHeiUI",
45
+ "Microsoft YaHei",
46
+ "MicrosoftYaHei",
47
+ "Segoe UI",
48
+ "Helvetica Neue",
49
+ // Near-universal last resort: a missing alias face would otherwise
50
+ // fall back to the browser default (Times) instead of a sans face.
51
+ "Arial",
52
+ "Helvetica",
53
+ ],
54
+ stack: '-apple-system,BlinkMacSystemFont,"PingFang SC","Hiragino Sans GB","Microsoft YaHei UI","Microsoft YaHei","Segoe UI",system-ui,sans-serif',
55
+ },
56
+ {
57
+ name: "Vcp-Serif",
58
+ label: "系统宋体/衬线(杂志标题、精装正文)",
59
+ locals: [
60
+ "Songti SC",
61
+ "SongtiSC-Regular",
62
+ "STSong",
63
+ "STSongti-SC-Regular",
64
+ "SimSun",
65
+ "NSimSun",
66
+ "Source Han Serif SC",
67
+ "Noto Serif CJK SC",
68
+ "Georgia",
69
+ "Times New Roman",
70
+ ],
71
+ stack: '"Songti SC","STSong","SimSun","Source Han Serif SC","Noto Serif CJK SC",Georgia,"Times New Roman",serif',
72
+ },
73
+ {
74
+ name: "Vcp-Kai",
75
+ label: "系统楷体(随笔、引言,不用于数据)",
76
+ locals: [
77
+ "Kaiti SC",
78
+ "KaitiSC-Regular",
79
+ "STKaiti",
80
+ "KaiTi",
81
+ "楷体",
82
+ "KaiTi_GB2312",
83
+ "Songti SC",
84
+ "SimSun",
85
+ "Times New Roman",
86
+ ],
87
+ stack: '"Kaiti SC","STKaiti","KaiTi","KaiTi_GB2312",serif',
88
+ },
89
+ {
90
+ name: "Vcp-Mono",
91
+ label: "系统等宽(代码、指标数字、时间戳)",
92
+ locals: [
93
+ "SF Mono",
94
+ "SFMono-Regular",
95
+ "Menlo",
96
+ "Menlo-Regular",
97
+ "Consolas",
98
+ "Cascadia Mono",
99
+ "CascadiaMono",
100
+ "Liberation Mono",
101
+ "Courier New",
102
+ "Courier",
103
+ ],
104
+ stack: 'ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,"Cascadia Mono","Liberation Mono",monospace',
105
+ },
15
106
  ];
16
107
  const FONT_FACE_HOST_ID = "loop-console-vcp-fontfaces";
108
+ function cssQuote(value) {
109
+ return `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
110
+ }
111
+ /**
112
+ * `@font-face` for the built-in subsets plus the platform alias faces.
113
+ * `builtins` narrows the subset list (standalone export only needs the faces
114
+ * the card actually names).
115
+ */
116
+ export function vcpFontFaceCss(origin = "", builtins = VCP_BUILTIN_FONT_FAMILIES) {
117
+ const faces = [];
118
+ for (const family of builtins) {
119
+ const url = `${origin}/vcp/fonts/${encodeURIComponent(family)}.woff2`;
120
+ const weight = BUILTIN_FONT_WEIGHTS[family];
121
+ if (weight === undefined)
122
+ continue;
123
+ faces.push(`@font-face{font-family:${cssQuote(family)};src:url('${url}') format('woff2');font-weight:${weight};font-display:swap;}`);
124
+ }
125
+ for (const alias of VCP_FONT_ALIASES) {
126
+ const sources = alias.locals.map((local) => `local(${cssQuote(local)})`).join(",");
127
+ faces.push(`@font-face{font-family:${cssQuote(alias.name)};src:${sources};font-display:swap;}`);
128
+ }
129
+ return faces.join("");
130
+ }
131
+ /** `--vcp-font-sans|serif|kai|mono` tokens for cards that prefer variables. */
132
+ export function vcpFontVariableCss() {
133
+ const vars = VCP_FONT_ALIASES.map((alias) => `--vcp-font-${alias.name.replace(/^Vcp-/, "").toLowerCase()}:${alias.stack};`).join("");
134
+ return `:root{${vars}}`;
135
+ }
136
+ /**
137
+ * Baseline typography every card inherits when it declares nothing: family,
138
+ * size, line height, text colour, and a restrained heading scale.
139
+ *
140
+ * The selectors are deliberately low-specificity element rules, matching how
141
+ * a browser stylesheet behaves, so any card rule (class or inline) still wins.
142
+ * Heading weight stops at 600 and is not inherited through the CJK faces —
143
+ * "thick as a blob" is the exact failure this baseline exists to prevent.
144
+ *
145
+ * `:root` carries the family so the old root-lock rule (`font-family:
146
+ * inherit` per element) resolves to the same chain instead of the initial
147
+ * value.
148
+ */
149
+ export const VCP_FRAME_BASE_TEXT_CSS = ":root{font-family:var(--vcp-font-sans);}" +
150
+ "body{margin:0;font-family:var(--vcp-font-sans);font-size:15px;line-height:1.65;font-weight:400;color:#27303f;-webkit-font-smoothing:antialiased;}" +
151
+ "h1,h2,h3,h4,h5,h6{font-family:inherit;font-weight:600;line-height:1.3;letter-spacing:0;}" +
152
+ "h1{font-size:1.85em;}h2{font-size:1.4em;}h3{font-size:1.15em;}" +
153
+ "p{margin:0 0 0.85em;}" +
154
+ "strong,b{font-weight:600;}" +
155
+ "small{font-size:0.85em;}" +
156
+ "code,pre,kbd,samp{font-family:var(--vcp-font-mono);}" +
157
+ "table{border-collapse:collapse;}" +
158
+ "img,svg,video{max-width:100%;height:auto;}";
159
+ /**
160
+ * Main-window baseline. Script-free cards render into the Console document
161
+ * (not the sandboxed frame), so they need the same typography contract — and
162
+ * they must outrank the Console's own panel rules (`.panel h2` is (0,1,1)),
163
+ * otherwise host styling leaks into the card.
164
+ *
165
+ * The doubled class gives (0,2,1). That is still safe for card intent: the
166
+ * engine lifts card-authored declarations (class rules and inline styles) to
167
+ * `!important`, so a card that really wants weight 700 keeps it.
168
+ */
169
+ const VCP_HOST_SCOPE = ".oc-vcp-card-host.oc-vcp-card-host";
170
+ export const VCP_HOST_BASE_CSS = `${VCP_HOST_SCOPE}{-webkit-font-smoothing:antialiased;}` +
171
+ `${VCP_HOST_SCOPE} h1,${VCP_HOST_SCOPE} h2,${VCP_HOST_SCOPE} h3,${VCP_HOST_SCOPE} h4,${VCP_HOST_SCOPE} h5,${VCP_HOST_SCOPE} h6{font-weight:600;line-height:1.3;letter-spacing:0;}` +
172
+ `${VCP_HOST_SCOPE} h1{font-size:1.85em;}${VCP_HOST_SCOPE} h2{font-size:1.4em;}${VCP_HOST_SCOPE} h3{font-size:1.15em;}` +
173
+ `${VCP_HOST_SCOPE} strong,${VCP_HOST_SCOPE} b{font-weight:600;}` +
174
+ `${VCP_HOST_SCOPE} table{border-collapse:collapse;}` +
175
+ `${VCP_HOST_SCOPE} img,${VCP_HOST_SCOPE} svg,${VCP_HOST_SCOPE} video{max-width:100%;height:auto;}`;
176
+ /** Full global stylesheet text for main-window cards. */
177
+ export function vcpGlobalFontCss(origin = "") {
178
+ return `${vcpFontFaceCss(origin)}${vcpFontVariableCss()}${VCP_HOST_BASE_CSS}`;
179
+ }
17
180
  /** Idempotently declare every built-in font as a global @font-face. */
18
181
  export function ensureVcpGlobalFonts() {
19
182
  if (typeof document === "undefined")
@@ -24,14 +187,9 @@ export function ensureVcpGlobalFonts() {
24
187
  host.id = FONT_FACE_HOST_ID;
25
188
  document.head.appendChild(host);
26
189
  }
27
- let added = 0;
28
- for (const family of VCP_BUILTIN_FONT_FAMILIES) {
29
- const url = `/vcp/fonts/${encodeURIComponent(family)}.woff2`;
30
- const rule = `@font-face{font-family:'${family}';src:url('${url}') format('woff2');font-display:swap;}`;
31
- if (!host.textContent?.includes(rule)) {
32
- host.textContent = (host.textContent ?? "") + rule;
33
- added += 1;
34
- }
35
- }
36
- return added;
190
+ const css = vcpGlobalFontCss("");
191
+ if (host.textContent === css)
192
+ return 0;
193
+ host.textContent = css;
194
+ return 1;
37
195
  }