@tea-agent/loop-agent 0.51.0 → 0.52.0-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +123 -5
- package/dist/build-stamp.json +3 -3
- package/dist/cli/command-definitions.js +1 -75
- package/dist/cli/help.js +1 -1
- package/dist/cli/program.js +1 -28
- package/dist/commands/init-accepted-merge.js +46 -0
- package/dist/commands/init-upgrade.js +115 -2
- package/dist/commands/init.js +79 -12
- package/dist/executors/pi-sdk-executor.js +3 -3
- package/dist/governance/path-guard.js +2 -0
- package/dist/records/harvest.js +1 -1
- package/dist/shared/git-progress.js +3 -0
- package/dist/shared/operator/capabilities.js +0 -122
- package/dist/shared/pi-context-pressure/checkpoint.js +94 -24
- package/dist/shared/pi-context-pressure/compaction-policy.js +152 -66
- package/dist/shared/pi-context-pressure/extension.js +25 -8
- package/dist/shared/pi-context-pressure/index.js +1 -1
- package/dist/shared/pi-context-pressure/telemetry.js +10 -0
- package/dist/shared/update/npm-client.js +14 -3
- package/dist/task/config-types.js +5 -10
- package/dist/task/delegate.js +1 -1
- package/dist/task/read-model.js +0 -4
- package/dist/task/runtime.js +0 -1
- package/dist/task/worktree.js +1 -1
- package/dist/worker/console/chat/api-workbench-core.js +17 -6
- package/dist/worker/console/chat/api-workbench.js +2 -0
- package/dist/worker/console/chat/assistant-content.js +21 -3
- package/dist/worker/console/chat/chat-event-projection.js +6 -0
- package/dist/worker/console/chat/chat-event-store.js +32 -2
- package/dist/worker/console/chat/chat-references.js +4 -0
- package/dist/worker/console/chat/compaction-errors.js +14 -2
- package/dist/worker/console/chat/context-insights.js +41 -4
- package/dist/worker/console/chat/context-usage.js +4 -1
- package/dist/worker/console/chat/pi-runtime/custom-tools/apiworkbench-tools.js +65 -3
- package/dist/worker/console/chat/pi-runtime/custom-tools/browser-tools.js +2 -2
- package/dist/worker/console/chat/pi-runtime/extension-bindings.js +39 -0
- package/dist/worker/console/chat/pi-runtime/sdk-bindings.js +4 -0
- package/dist/worker/console/chat/pi-runtime.js +389 -191
- package/dist/worker/console/chat/repo-browser.js +5 -2
- package/dist/worker/console/chat/repo-preview-kind.js +16 -6
- package/dist/worker/console/chat/routes.js +299 -25
- package/dist/worker/console/chat/scheduled-goal-request.js +1 -1
- package/dist/worker/console/chat/subagents/jobs.js +115 -4
- package/dist/worker/console/chat/terminal-sessions.js +52 -6
- package/dist/worker/console/chat/tool-exposure-catalog.js +1 -1
- package/dist/worker/console/chat/tool-presentation.js +17 -10
- package/dist/worker/console/chat/tool-preview.js +22 -0
- package/dist/worker/console/chat/turn-process.js +49 -0
- package/dist/worker/console/chat/vcp-prompt.js +14 -9
- package/dist/worker/console/chat/workspace-changes.js +17 -0
- package/dist/worker/console/console-update-runtime.js +5 -1
- package/dist/worker/console/operator-actions.js +7 -6
- package/dist/worker/console/operator-user-error.js +5 -1
- package/dist/worker/console/pi-compaction-settings.js +220 -0
- package/dist/worker/console/routes.js +1 -1
- package/dist/worker/console/server.js +148 -6
- package/dist/worker/console/static/assets/FilePreviewDocx-ybM3ZqSl.js +9 -0
- package/dist/worker/console/static/assets/abnfDiagram-N423BO3Z-CT26sIgH.js +1 -0
- package/dist/worker/console/static/assets/{arc-Bkf_oc0_.js → arc-CPwLqDB0.js} +1 -1
- package/dist/worker/console/static/assets/architectureDiagram-T3A2C74G-CzTSMPU_.js +36 -0
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-D62uVvbI.js → blockDiagram-VBNYF7ZC-BfgbtJLH.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-Iq0Y8Afx.js → c4Diagram-5PPSVZJV-B9pTjB8U.js} +1 -1
- package/dist/worker/console/static/assets/channel-DtYRMDck.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-D1TxRE3k.js → chunk-2GRJ4B5K-xORV8QsC.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-BE-DHkAO.js → chunk-2Q5K7J3B-BzpYWAHK.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-t0iYO8Cc.js → chunk-5RXB4S5H-D8zcRP6c.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-Clo2nExi.js → chunk-5VM5RSS4-DVEXxzQJ.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-C7bSpo-3.js → chunk-6Q2QTUOP-CKZOJU2z.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-DorZaymh.js → chunk-GF5L2VYU-Cgx34Dj8.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-Ch_4HvyJ.js → chunk-JWPE2WC7-ehcSKOcx.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-yaSoFe-3.js → chunk-KBJHAD2P-CiY9emCG.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-QpjaXecS.js → chunk-RYQCIY6F-Bk9X-ksQ.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-B3t6cycg.js → chunk-XXDRQBXY-DC0xXfHy.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DyesHbs5.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DyesHbs5.js +1 -0
- package/dist/worker/console/static/assets/cose-bilkent-JH36ORCC-C_EVg5l9.js +1 -0
- package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-CP8LtrOl.js → cynefin-VYW2F7L2-BIFL8KrA.js} +1 -1
- package/dist/worker/console/static/assets/cynefinDiagram-MW4NZA55-DjtUYOlE.js +62 -0
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-BK0ua9V8.js → dagre-VZM6K2ZE-D2aN2V9t.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-t9-HP13j.js → diagram-7IWD3JNH-D_twhmFi.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-L5Sg9jMD.js → diagram-B4RE2ZJO-ChzncqLV.js} +1 -1
- package/dist/worker/console/static/assets/diagram-LBJQPF4R-B6LO-bF2.js +24 -0
- package/dist/worker/console/static/assets/diagram-Q27KOJAE-GrzM7AFc.js +24 -0
- package/dist/worker/console/static/assets/diagram-UB23O5K3-Bv-lntaq.js +41 -0
- package/dist/worker/console/static/assets/docx-preview-CAbT0VNs.js +23 -0
- package/dist/worker/console/static/assets/docxPreview-D_T4B7qe.js +1 -0
- package/dist/worker/console/static/assets/ebnfDiagram-BXEA7PRR-BvD2jkO_.js +1 -0
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-CNOuj3BO.js → erDiagram-JOGREHBK-BirPCcmA.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-h_Cyayai.js → flowDiagram-UKHOOZJN-Chu1YnGQ.js} +1 -1
- package/dist/worker/console/static/assets/ganttDiagram-PKOTCBZU-Djn17xhB.js +292 -0
- package/dist/worker/console/static/assets/gitGraphDiagram-DS77QQ5N-Bx1qbGHx.js +106 -0
- package/dist/worker/console/static/assets/infoDiagram-6WML65LV-D-TLMqmb.js +2 -0
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-DAdf5lHp.js → ishikawaDiagram-WSZJBQD7-DbJoh-6T.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-BQbGtg66.js → journeyDiagram-NVQOT4AX-DsyokZ6e.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-CetLubYc.js → kanban-definition-27J2QSJJ-DlzXTxic.js} +1 -1
- package/dist/worker/console/static/assets/{linear-DLZOjaVz.js → linear-ClnZn3vw.js} +1 -1
- package/dist/worker/console/static/assets/main-D-ZQ4gLb.css +1 -0
- package/dist/worker/console/static/assets/main-fc3P1HID.js +645 -0
- package/dist/worker/console/static/assets/{mermaid.core-B_xZl_gM.js → mermaid.core-DqSlcvbf.js} +5 -5
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-Dzo3dzp0.js → mindmap-definition-FAOFIHXS-CSFbzpiX.js} +1 -1
- package/dist/worker/console/static/assets/pegDiagram-VL7TDLO6-DK80yQqe.js +1 -0
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-Cp3YrVzQ.js → pieDiagram-7S7Q4E2Y-DWX7SFGb.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-4tI5mUgW.js → quadrantDiagram-CIZ2JOQS-BEPPhtXs.js} +1 -1
- package/dist/worker/console/static/assets/railroadDiagram-AXF67PYL-Ck_s6fQn.js +1 -0
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-DY-0JqdT.js → requirementDiagram-LRYGKXZP-CYig27Rj.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-DuJIzRKC.js → sankeyDiagram-W5VNT64P-u-0aSx5s.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-BTbVJ85l.js → sequenceDiagram-SI44F4Z6-NsEJI9sM.js} +1 -1
- package/dist/worker/console/static/assets/{sheet-workbook-BPPh1uLw.js → sheet-workbook-kZ_HK4Sg.js} +2 -2
- package/dist/worker/console/static/assets/sizeCapture-X5ZJPWSS-8vneVM5U.js +1 -0
- package/dist/worker/console/static/assets/stateDiagram-OKZ733FA-CMIobUBh.js +1 -0
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Bd0pHHKP.js +1 -0
- package/dist/worker/console/static/assets/swimlanes-SLNWSIFB-D4Qzt6ug.js +2 -0
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-BzmSZnl_.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-GR6lxokn.js → timeline-definition-Z64GVDOM-DMb1LpED.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-DEkwyzsF.js → vennDiagram-T6HMQDX7-C_9eFOs3.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-W5jnvEJ3.js → wardleyDiagram-T6FBY63Y-DJYMe3uT.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-cqsloioo.js → xychartDiagram-ELKLHX3M-Cv_1Mi3u.js} +1 -1
- package/dist/worker/console/static/docx-preview.html +25 -0
- package/dist/worker/console/static/index.html +3 -2
- package/dist/worker/console/static/vcp/fonts/README.md +28 -0
- package/dist/worker/console/static/vcp/vendor/vcp-engine-v1.js +4 -4
- package/dist/worker/console/static-src/operator-chat/StateDot.js +17 -0
- package/dist/worker/console/static-src/operator-chat/changed-file-diff.js +15 -0
- package/dist/worker/console/static-src/operator-chat/chat-font-size.js +90 -0
- package/dist/worker/console/static-src/operator-chat/chat-session-order.js +96 -0
- package/dist/worker/console/static-src/operator-chat/chat-sse-events.js +8 -1
- package/dist/worker/console/static-src/operator-chat/compaction-message.js +4 -0
- package/dist/worker/console/static-src/operator-chat/details-rail-surfaces.js +2 -0
- package/dist/worker/console/static-src/operator-chat/file-touch.js +107 -0
- package/dist/worker/console/static-src/operator-chat/format-file-size.js +26 -0
- package/dist/worker/console/static-src/operator-chat/open-preview-in-browser.js +44 -0
- package/dist/worker/console/static-src/operator-chat/reference-display.js +7 -1
- package/dist/worker/console/static-src/operator-chat/tasks-auto-open.js +100 -0
- package/dist/worker/console/static-src/operator-chat/tasks-layout-tween.js +103 -0
- package/dist/worker/console/static-src/operator-chat/tasks-model.js +657 -0
- package/dist/worker/console/static-src/operator-chat/tasks-view-glide.js +96 -0
- package/dist/worker/console/static-src/operator-chat/turn-group-equality.js +1 -0
- package/dist/worker/console/static-src/operator-chat/use-auto-animate.js +61 -0
- package/dist/worker/console/static-src/operator-chat/useChatSessions.js +194 -47
- package/dist/worker/console/static-src/operator-chat/useChatStream.js +4 -0
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +18 -0
- package/dist/worker/console/static-src/operator-chat/useRepoBrowser.js +111 -21
- package/dist/worker/console/static-src/operator-chat/useRuntimeControls.js +91 -47
- package/dist/worker/console/static-src/operator-chat/useVcpPreferences.js +1 -1
- package/dist/worker/console/static-src/operator-chat/user-turn-anchors-merge.js +50 -0
- package/dist/worker/console/static-src/operator-chat/vcp-fonts.js +180 -22
- package/dist/worker/console/static-src/operator-chat/vcp-frame.js +3 -3
- package/dist/worker/console/static-src/shell/console-update-progress.js +16 -0
- package/dist/worker/console/static-src/shell/console-update-reload.js +4 -1
- package/dist/worker/console/static-src/shell/workspace-route.js +0 -2
- package/dist/worker/console/vite.config.js +5 -1
- package/dist/worker/console/workspace-registry.js +62 -19
- package/dist/worker/observe/static/operator-chrome.js +0 -1
- package/dist/worker/scheduler/git-base.js +3 -0
- package/dist/worker/scheduler/night-git-finalizer.js +1 -1
- package/dist/worker/scheduler/night-harvest.js +1 -1
- package/dist/worker/scheduler/prepared-attempt-recovery.js +1 -1
- package/dist/worker/scheduler/scheduled-goal-evidence.js +1 -1
- package/dist/workflows/dag/backend-test-scenario-param.js +60 -4
- package/dist/workflows/dag/dynamic-runtime/reduction.js +7 -2
- package/dist/workflows/dag/frontend-test-framework-adapters.js +11 -2
- package/dist/workflows/script/windows/guest.js +13 -2
- package/dist/workflows/script/windows/native.js +21 -3
- package/docs/architecture/dag-execution.md +2 -13
- package/docs/architecture/facts-and-state.md +2 -3
- package/docs/architecture/runtime-boundaries.md +2 -2
- package/package.json +9 -7
- package/resource-catalog.v1.json +6 -6
- package/scripts/patch-pi-sdk-windows-hide.mjs +3 -3
- package/skills/loop-agent/references/command-reference.md +2 -41
- package/skills/loop-agent/references/harness-policy.md +3 -30
- package/skills/loop-agent/references/long-running-loop.md +6 -54
- package/dist/application/loop/run-action.js +0 -19
- package/dist/commands/dag-workflow-compile.js +0 -93
- package/dist/commands/dag-workflow-plan.js +0 -132
- package/dist/commands/dag-workflow-validate.js +0 -68
- package/dist/commands/loop-benchmark.js +0 -74
- package/dist/commands/loop.js +0 -251
- package/dist/commands/workflow.js +0 -259
- package/dist/infrastructure/harness/loop-store.js +0 -41
- package/dist/worker/console/static/assets/abnfDiagram-N423BO3Z-FQePHM07.js +0 -1
- package/dist/worker/console/static/assets/architectureDiagram-T3A2C74G-p_mwm8cd.js +0 -36
- package/dist/worker/console/static/assets/channel-CIBAg8WF.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-B4xQrSmv.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-B4xQrSmv.js +0 -1
- package/dist/worker/console/static/assets/cose-bilkent-JH36ORCC-BPXf8ZYr.js +0 -1
- package/dist/worker/console/static/assets/cynefinDiagram-MW4NZA55-CNsL9N2-.js +0 -62
- package/dist/worker/console/static/assets/diagram-LBJQPF4R-BipWFRgs.js +0 -24
- package/dist/worker/console/static/assets/diagram-Q27KOJAE-T2p4xa38.js +0 -24
- package/dist/worker/console/static/assets/diagram-UB23O5K3-CVwz6LVu.js +0 -41
- package/dist/worker/console/static/assets/ebnfDiagram-BXEA7PRR-CybQrGSA.js +0 -1
- package/dist/worker/console/static/assets/ganttDiagram-PKOTCBZU-D411_55h.js +0 -292
- package/dist/worker/console/static/assets/gitGraphDiagram-DS77QQ5N-DpVtzs9z.js +0 -106
- package/dist/worker/console/static/assets/index-B7cwOTL9.js +0 -649
- package/dist/worker/console/static/assets/index-CATbSkPc.css +0 -1
- package/dist/worker/console/static/assets/infoDiagram-6WML65LV-D74Uvx6K.js +0 -2
- package/dist/worker/console/static/assets/pegDiagram-VL7TDLO6-CSwoBOpM.js +0 -1
- package/dist/worker/console/static/assets/railroadDiagram-AXF67PYL-n0Mt3Yia.js +0 -1
- package/dist/worker/console/static/assets/sizeCapture-X5ZJPWSS-Dmf1pC7B.js +0 -1
- package/dist/worker/console/static/assets/stateDiagram-OKZ733FA-4-jdPUHD.js +0 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-DojWfYnC.js +0 -1
- package/dist/worker/console/static/assets/swimlanes-SLNWSIFB-DNhjjaAU.js +0 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-CJo4AKWH.js +0 -8
- package/dist/worker/console/static/vcp/fonts/Lanxi-/345/217/257/345/256/213.woff2 +0 -0
- package/dist/worker/console/static/vcp/fonts/Lanxi-/346/234/227/345/256/213.woff2 +0 -0
- package/dist/worker/console/static/vcp/fonts/Lanxi-/350/266/205/347/262/227/351/273/221.woff2 +0 -0
- package/dist/workflows/dynamic/compile.js +0 -371
- package/dist/workflows/dynamic/compileTypes.js +0 -1
- package/dist/workflows/dynamic/errors.js +0 -5
- package/dist/workflows/dynamic/profiles.js +0 -156
- package/dist/workflows/dynamic/spec.js +0 -115
- package/dist/workflows/dynamic/validate.js +0 -275
- package/dist/workflows/loop/actions/dag-action.js +0 -129
- package/dist/workflows/loop/actions/pi-review.js +0 -267
- package/dist/workflows/loop/actions/shared.js +0 -157
- package/dist/workflows/loop/actions/shell-verify.js +0 -82
- package/dist/workflows/loop/actions/types.js +0 -1
- package/dist/workflows/loop/actions/workflow-action.js +0 -255
- package/dist/workflows/loop/actions.js +0 -160
- package/dist/workflows/loop/benchmark.js +0 -513
- package/dist/workflows/loop/closeout.js +0 -135
- package/dist/workflows/loop/context.js +0 -47
- package/dist/workflows/loop/events.js +0 -26
- package/dist/workflows/loop/hash.js +0 -32
- package/dist/workflows/loop/index.js +0 -8
- package/dist/workflows/loop/paths.js +0 -17
- package/dist/workflows/loop/policy/auto-policy.js +0 -112
- package/dist/workflows/loop/policy/path-patterns.js +0 -13
- package/dist/workflows/loop/rounds.js +0 -81
- package/dist/workflows/loop/signals.js +0 -52
- package/dist/workflows/loop/state.js +0 -116
- package/dist/workflows/loop/templates.js +0 -54
- package/dist/workflows/loop/types.js +0 -28
- /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
|
-
|
|
22
|
-
//
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
73
|
-
|
|
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]:
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
63
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
105
|
-
|
|
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(
|
|
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();
|
|
@@ -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
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
|
9
|
-
"Lanxi
|
|
10
|
-
"Lanxi
|
|
11
|
-
"Lanxi
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
}
|