@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
@@ -0,0 +1,96 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ import { GRAPH_FIT_MIN_SCALE } from "./tasks-model.js";
3
+ export const TASKS_GLIDE_MS = 220;
4
+ /** Breathing room the fit leaves around the content box, per axis. */
5
+ const FIT_MARGIN = 12;
6
+ function easeOut(value) {
7
+ const t = Math.min(1, Math.max(0, value));
8
+ return 1 - (1 - t) ** 3;
9
+ }
10
+ function reducedMotion() {
11
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
12
+ }
13
+ export function useTasksViewGlide(input) {
14
+ const initialScale = input.surface === "sidebar" ? 0.85 : 1;
15
+ const [transform, setTransform] = useState({ x: 16, y: 16, k: initialScale });
16
+ const drawnRef = useRef(transform);
17
+ const animationRef = useRef(null);
18
+ const animateTo = useCallback((target) => {
19
+ if (animationRef.current !== null && typeof cancelAnimationFrame === "function")
20
+ cancelAnimationFrame(animationRef.current);
21
+ const from = drawnRef.current;
22
+ if (reducedMotion()) {
23
+ drawnRef.current = target;
24
+ setTransform(target);
25
+ return;
26
+ }
27
+ if (typeof requestAnimationFrame !== "function") {
28
+ setTransform(target);
29
+ return;
30
+ }
31
+ const started = performance.now();
32
+ let frame = 0;
33
+ const step = () => {
34
+ const progress = easeOut((performance.now() - started) / TASKS_GLIDE_MS);
35
+ const next = {
36
+ x: from.x + (target.x - from.x) * progress,
37
+ y: from.y + (target.y - from.y) * progress,
38
+ k: from.k + (target.k - from.k) * progress,
39
+ };
40
+ drawnRef.current = next;
41
+ setTransform(next);
42
+ if (progress < 1) {
43
+ frame = requestAnimationFrame(step);
44
+ animationRef.current = frame;
45
+ }
46
+ else {
47
+ animationRef.current = null;
48
+ }
49
+ };
50
+ frame = requestAnimationFrame(step);
51
+ animationRef.current = frame;
52
+ return () => {
53
+ if (animationRef.current === frame)
54
+ animationRef.current = null;
55
+ cancelAnimationFrame(frame);
56
+ };
57
+ }, []);
58
+ const fit = useCallback(() => {
59
+ if (input.enabled === false)
60
+ return;
61
+ const viewport = input.viewportRef.current;
62
+ if (!viewport)
63
+ return;
64
+ const width = Math.max(1, input.layout.width);
65
+ const height = Math.max(1, input.layout.height);
66
+ const availableW = Math.max(1, viewport.clientWidth - FIT_MARGIN * 2);
67
+ const availableH = Math.max(1, viewport.clientHeight - FIT_MARGIN * 2);
68
+ const maxScale = input.surface === "sidebar" ? 1.1 : 1.3;
69
+ const k = Math.max(GRAPH_FIT_MIN_SCALE, Math.min(maxScale, availableW / width, availableH / height));
70
+ // Center on both axes. The clamp only guards the sub-pixel case where the
71
+ // content is wider than the viewport at the readability floor; it must not
72
+ // push content away from the center on the axis that fits.
73
+ const x = Math.max(FIT_MARGIN, (viewport.clientWidth - width * k) / 2);
74
+ const y = Math.max(FIT_MARGIN, (viewport.clientHeight - height * k) / 2);
75
+ animateTo({ x, y, k });
76
+ }, [animateTo, input.enabled, input.layout.height, input.layout.width, input.surface, input.viewportRef]);
77
+ const zoom = useCallback((factor) => {
78
+ const current = drawnRef.current;
79
+ animateTo({ ...current, k: Math.max(0.1, Math.min(1.75, Math.round(current.k * factor * 100) / 100)) });
80
+ }, [animateTo]);
81
+ useEffect(() => {
82
+ if (input.enabled === false)
83
+ return;
84
+ fit();
85
+ const viewport = input.viewportRef.current;
86
+ if (!viewport || typeof ResizeObserver === "undefined")
87
+ return;
88
+ const observer = new ResizeObserver(() => fit());
89
+ observer.observe(viewport);
90
+ return () => observer.disconnect();
91
+ }, [fit, input.enabled, input.viewportRef]);
92
+ const setPan = useCallback((next) => {
93
+ setTransform((current) => ({ ...current, x: next.x, y: next.y }));
94
+ }, []);
95
+ return { scale: transform.k, pan: { x: transform.x, y: transform.y }, zoom, fit, setPan };
96
+ }
@@ -12,6 +12,7 @@ export function sameTurnGroupInputs(previous, next) {
12
12
  previous.turnState === next.turnState &&
13
13
  previous.turnClosed === next.turnClosed &&
14
14
  previous.live === next.live &&
15
+ previous.workspaceChanges === next.workspaceChanges &&
15
16
  sameReferences(previous.assistants, next.assistants) &&
16
17
  sameReferences(previous.tools, next.tools) &&
17
18
  sameReferences(previous.conversationItems ?? [], next.conversationItems ?? []));
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The Tasks page's motion host: `@formkit/auto-animate` (FLIP) attached through
3
+ * ONE guarded hook, so every animated container in the page behaves the same and
4
+ * the test / non-WAAPI environments stay inert.
5
+ *
6
+ * This mirrors DSH's own `use-auto-animate.ts` (same library, same version line)
7
+ * because the parity target is the plugin's behaviour — a row the reader folds
8
+ * away fades out in place while its siblings slide up.
9
+ *
10
+ * Where it is used — and where it deliberately is NOT:
11
+ *
12
+ * - the tree view and the jobs drawer are normal FLOW containers, so a row the
13
+ * reader folds away fades out in place while its siblings slide up: exactly
14
+ * what FLIP is for;
15
+ * - the graph CANVAS is excluded. Its card layer carries the fit's
16
+ * `transform: scale(k)`, and the library pins a leaving card with absolute
17
+ * `left/top` derived from `getBoundingClientRect()` (a box the scaled layer
18
+ * cannot express) and translates movers in unscaled units (k× the true
19
+ * distance). Measured live on DSH, that read as "折叠展开的动效都特别怪"; the
20
+ * canvas uses the CSS entrance on the card instead, and leaving cards are
21
+ * removed instantly — the edges they hang from are not animated, so nothing
22
+ * disagrees with them.
23
+ *
24
+ * The library needs `Element.prototype.animate` (Web Animations API) and a real
25
+ * layout pass, so the hook attaches to nothing when either is missing: jsdom
26
+ * renders the same DOM without motion, and no test has to stub an animation
27
+ * engine. It respects `prefers-reduced-motion` on its own (its
28
+ * `disrespectUserMotionPreference` option defaults to false).
29
+ */
30
+ import autoAnimate from "@formkit/auto-animate";
31
+ import { useEffect } from "react";
32
+ /** Whether this environment can run FLIP animations at all. */
33
+ function canAnimate() {
34
+ return (typeof Element !== "undefined" &&
35
+ typeof Element.prototype.animate === "function" &&
36
+ typeof document !== "undefined");
37
+ }
38
+ /**
39
+ * Animate one container's children.
40
+ *
41
+ * @param ref - the container whose DIRECT children are animated. Layout changes
42
+ * below the direct children are not animated — that is the library's own scope
43
+ * rule, and the page keeps one host per list it wants animated.
44
+ *
45
+ * The consuming component MUST be declared at MODULE scope. Declared inside
46
+ * another component, its function identity changes on every render, React sees a
47
+ * different component type, and the element this hook attached to is unmounted
48
+ * and rebuilt — taking the observer with it. That failure is silent and total:
49
+ * the tree still renders, but no motion ever runs.
50
+ */
51
+ export function useAutoAnimateRef(ref) {
52
+ useEffect(() => {
53
+ const element = ref.current;
54
+ if (element === null || !canAnimate())
55
+ return undefined;
56
+ const controller = autoAnimate(element);
57
+ return () => {
58
+ controller.destroy?.();
59
+ };
60
+ }, [ref]);
61
+ }
@@ -132,6 +132,34 @@ export function stabilizeSessionList(previous, next) {
132
132
  });
133
133
  return changed ? stabilized : previous;
134
134
  }
135
+ /**
136
+ * P2-B: Reconcile server baseline list with local optimistic mutation log,
137
+ * preventing stale list responses from rolling back pending renames/archives
138
+ * or reviving deleted sessions.
139
+ */
140
+ export function reconcileSessionListWithMutationLog(current, baseline, mutationLog, visibleWorkspaceIds, workspacesLoading = false) {
141
+ const belongsToVisibleWorkspace = (item) => workspacesLoading ||
142
+ !item.workspaceId ||
143
+ visibleWorkspaceIds.has(item.workspaceId);
144
+ const durable = baseline
145
+ .filter((item) => belongsToVisibleWorkspace(item) && !mutationLog.deleted.has(item.sessionId))
146
+ .map((item) => {
147
+ const mutation = mutationLog.mutated.get(item.sessionId);
148
+ if (!mutation)
149
+ return item;
150
+ return {
151
+ ...item,
152
+ ...(mutation.title !== undefined ? { title: mutation.title } : {}),
153
+ ...(mutation.displayTitle !== undefined ? { displayTitle: mutation.displayTitle } : {}),
154
+ ...(mutation.state !== undefined ? { state: mutation.state } : {}),
155
+ ...(mutation.updatedAt !== undefined ? { updatedAt: mutation.updatedAt } : {}),
156
+ };
157
+ });
158
+ const optimistic = [...mutationLog.created.values()].filter((item) => belongsToVisibleWorkspace(item) &&
159
+ !mutationLog.deleted.has(item.sessionId) &&
160
+ !durable.some((session) => session.sessionId === item.sessionId));
161
+ return stabilizeSessionList(current, [...optimistic, ...durable]);
162
+ }
135
163
  /** Project a session detail/list record into the active ChatSessionInfo. */
136
164
  export function projectActiveChatSession(session, fallbackWorkspaceId) {
137
165
  const workspaceId = session.workspaceId?.trim() || fallbackWorkspaceId?.trim() || "";
@@ -143,7 +171,7 @@ export function projectActiveChatSession(session, fallbackWorkspaceId) {
143
171
  };
144
172
  }
145
173
  /** Select a server-confirmed blank session owned by the requested workspace. */
146
- export function findReusableBlankSession(list, workspaceId, sessionMode = DEFAULT_CONSOLE_CHAT_SESSION_MODE) {
174
+ export function findReusableBlankSession(list, workspaceId, sessionMode = DEFAULT_CONSOLE_CHAT_SESSION_MODE, activeSession, hasPendingSubmission = false) {
147
175
  const scope = workspaceId.trim();
148
176
  if (!scope)
149
177
  return undefined;
@@ -153,7 +181,8 @@ export function findReusableBlankSession(list, workspaceId, sessionMode = DEFAUL
153
181
  item.turnPhase === "idle" &&
154
182
  !item.activeTurnId &&
155
183
  !item.optimisticState &&
156
- (item.sessionMode ?? DEFAULT_CONSOLE_CHAT_SESSION_MODE) === sessionMode);
184
+ (item.sessionMode ?? DEFAULT_CONSOLE_CHAT_SESSION_MODE) === sessionMode &&
185
+ (!activeSession || activeSession.sessionId !== item.sessionId || !hasPendingSubmission));
157
186
  }
158
187
  export async function createSessionAndPrimeTitleWatcher(input) {
159
188
  if (input.creatingRef?.current) {
@@ -248,9 +277,13 @@ export class SessionDetailCache {
248
277
  if (known?.inFlight)
249
278
  return known.inFlight;
250
279
  const promise = loader().then((body) => {
280
+ const authoritativeBody = {
281
+ ...body,
282
+ cacheKind: "authoritative",
283
+ };
251
284
  const current = this.entries.get(key);
252
- this.touch(key, { ...(current ?? {}), body });
253
- return body;
285
+ this.touch(key, { ...(current ?? {}), body: authoritativeBody });
286
+ return authoritativeBody;
254
287
  }).finally(() => {
255
288
  const current = this.entries.get(key);
256
289
  if (current?.inFlight === promise) {
@@ -260,6 +293,34 @@ export class SessionDetailCache {
260
293
  this.touch(key, { ...(known ?? {}), inFlight: promise });
261
294
  return promise;
262
295
  }
296
+ /**
297
+ * Adopt a durable create response as the first projection of a just-created
298
+ * blank session. Never replaces a snapshot that is already cached or in
299
+ * flight — a revalidate either way is still authoritative.
300
+ */
301
+ seed(key, body) {
302
+ if (this.entries.has(key))
303
+ return;
304
+ this.touch(key, {
305
+ body: {
306
+ ...body,
307
+ cacheKind: body.cacheKind ?? "create-seed",
308
+ asOfSeq: body.asOfSeq ?? 0,
309
+ },
310
+ });
311
+ }
312
+ /**
313
+ * Explicitly invalidate when an entry is a create-seed (for example on first
314
+ * turn/prompt/event), while preserving authoritative or hydrated entries.
315
+ */
316
+ invalidateCreateSeed(key) {
317
+ const entry = this.entries.get(key);
318
+ if (entry?.body?.cacheKind === "create-seed") {
319
+ this.entries.delete(key);
320
+ return true;
321
+ }
322
+ return false;
323
+ }
263
324
  invalidate(key) {
264
325
  this.entries.delete(key);
265
326
  }
@@ -284,6 +345,42 @@ export function sessionDetailCacheKey(origin, sessionId, ownerWorkspaceId) {
284
345
  return `${origin}\u0000${ownerWorkspaceId?.trim() ?? ""}\u0000${sessionId}`;
285
346
  }
286
347
  export const sessionDetailCache = new SessionDetailCache(8);
348
+ /**
349
+ * Adopt the create response as the first detail projection of a blank session.
350
+ * The POST body is the durable truth and `replaceOptimisticSession` already
351
+ * committed the list row; re-activating this session before the first turn can
352
+ * therefore render from cache instead of paying a detail GET.
353
+ */
354
+ export function primeCreatedSessionDetailCache(input) {
355
+ const { session } = input;
356
+ sessionDetailCache.seed(sessionDetailCacheKey(input.origin, session.sessionId, session.workspaceId), {
357
+ cacheKind: "create-seed",
358
+ asOfSeq: 0,
359
+ session: {
360
+ sessionId: session.sessionId,
361
+ ...(session.workspaceId ? { workspaceId: session.workspaceId } : {}),
362
+ ...(session.sessionMode ? { sessionMode: session.sessionMode } : {}),
363
+ ...(session.model
364
+ ? {
365
+ modelProvider: session.model.provider,
366
+ modelId: session.model.modelId,
367
+ }
368
+ : {}),
369
+ ...(session.thinkingLevel
370
+ ? { thinkingLevel: session.thinkingLevel }
371
+ : {}),
372
+ },
373
+ });
374
+ }
375
+ /**
376
+ * Invalidate a create-seed entry when a session starts running turns or
377
+ * receiving user messages / events, preventing stale blank seeds from being
378
+ * reused as historical snapshots.
379
+ */
380
+ export function invalidateSessionDetailCacheSeed(sessionId, ownerWorkspaceId, origin = "") {
381
+ const key = sessionDetailCacheKey(origin, sessionId, ownerWorkspaceId);
382
+ return sessionDetailCache.invalidateCreateSeed(key);
383
+ }
287
384
  class SessionDetailFetchError extends Error {
288
385
  status;
289
386
  code;
@@ -314,7 +411,7 @@ export function startSessionListPolling(refresh) {
314
411
  * compact, plus browser-refresh recovery from the durable session store. */
315
412
  export function useChatSessions(params) {
316
413
  const { origin, refs, setSession, thread, composer, browser, setError, setNotice, onCompactionChange, setProcessOpen, setAutoScroll, } = params;
317
- const { applyActivatedSession, resetForNewSession, setMessages, refreshSessionTelemetry, } = thread;
414
+ const { applyActivatedSession, resetForNewSession, setMessages, } = thread;
318
415
  const { seedSession, releaseSession } = composer;
319
416
  const { setPreviews, setActivePreviewPath } = browser;
320
417
  const { workspaceId, blocked } = params;
@@ -349,6 +446,12 @@ export function useChatSessions(params) {
349
446
  const sessionListGlobalErrorRef = useRef(null);
350
447
  const pendingDeletedIdsRef = useRef(new Set());
351
448
  const pendingCreatedRowsRef = useRef(new Map());
449
+ const mutationLogRef = useRef({
450
+ created: pendingCreatedRowsRef.current,
451
+ deleted: pendingDeletedIdsRef.current,
452
+ mutated: new Map(),
453
+ generation: 0,
454
+ });
352
455
  const sessionMutationVersionRef = useRef(0);
353
456
  const deleteRequestVersionsRef = useRef(new Map());
354
457
  const activateSessionRef = useRef(null);
@@ -448,14 +551,20 @@ export function useChatSessions(params) {
448
551
  if (baseline.workspaceErrors.length > 0) {
449
552
  throw new Error(`部分工作区的会话加载失败(${baseline.workspaceErrors.length} 个)`);
450
553
  }
451
- const belongsToVisibleWorkspace = (item) => params.workspacesLoading ||
452
- !item.workspaceId ||
453
- visibleWorkspaceIds.has(item.workspaceId);
454
- const durable = baseline.sessions.filter((item) => belongsToVisibleWorkspace(item) &&
455
- !pendingDeletedIdsRef.current.has(item.sessionId));
456
- const optimistic = [...pendingCreatedRowsRef.current.values()].filter((item) => belongsToVisibleWorkspace(item) &&
457
- !durable.some((session) => session.sessionId === item.sessionId));
458
- const next = stabilizeSessionList(sessionListRef.current, [...optimistic, ...durable]);
554
+ // P2-B: Reconcile baseline with local mutation log to prevent stale responses
555
+ // from rolling back renames/archives or reviving deleted sessions.
556
+ const next = reconcileSessionListWithMutationLog(sessionListRef.current, baseline.sessions, mutationLogRef.current, visibleWorkspaceIds, params.workspacesLoading);
557
+ // Clear mutations that have already landed on the durable baseline
558
+ for (const item of baseline.sessions) {
559
+ const mutation = mutationLogRef.current.mutated.get(item.sessionId);
560
+ if (mutation) {
561
+ const titleMatches = mutation.title === undefined || mutation.title === item.title;
562
+ const stateMatches = mutation.state === undefined || mutation.state === item.state;
563
+ if (titleMatches && stateMatches) {
564
+ mutationLogRef.current.mutated.delete(item.sessionId);
565
+ }
566
+ }
567
+ }
459
568
  sessionListRef.current = next;
460
569
  setSessionList(next);
461
570
  setSessionListStatus({ phase: "ready", state: "idle", error: null });
@@ -506,6 +615,8 @@ export function useChatSessions(params) {
506
615
  // No pre-mutation snapshot may overwrite this deletion or its rollback.
507
616
  invalidateSessionListBaseline();
508
617
  pendingDeletedIdsRef.current.add(sessionId);
618
+ mutationLogRef.current.mutated.delete(sessionId);
619
+ mutationLogRef.current.generation += 1;
509
620
  deleteRequestVersionsRef.current.set(sessionId, requestId);
510
621
  const activeSession = refs.sessionRef.current?.sessionId === sessionId
511
622
  ? refs.sessionRef.current
@@ -715,6 +826,7 @@ export function useChatSessions(params) {
715
826
  (body.session.deferredTurn ? [body.session.deferredTurn] : []),
716
827
  pendingQuestion: body.session.pendingQuestion ?? null,
717
828
  todos: body.session.todos ?? [],
829
+ workspaceChanges: body.session.workspaceChanges ?? [],
718
830
  goal: body.session.goal ?? null,
719
831
  goalStatus: body.session.goalStatus,
720
832
  subagents: body.subagents?.items,
@@ -724,8 +836,18 @@ export function useChatSessions(params) {
724
836
  setActivePreviewPath(null);
725
837
  return true;
726
838
  };
839
+ const listedItem = sessionListRef.current.find((item) => item.sessionId === sessionId);
727
840
  const cached = sessionDetailCache.get(cacheKey);
728
- const hasUsableCache = cached ? applyDetail(cached) : false;
841
+ // P1-C: A create-seed is strictly a client hint for blank shells. If the
842
+ // session is known to have messages or active turns, invalidate the seed
843
+ // so activation performs an authoritative fetch instead of showing empty state.
844
+ if (cached?.cacheKind === "create-seed" &&
845
+ listedItem &&
846
+ (!listedItem.isBlank || listedItem.activeTurnId)) {
847
+ sessionDetailCache.invalidateCreateSeed(cacheKey);
848
+ }
849
+ const effectiveCached = sessionDetailCache.get(cacheKey);
850
+ const hasUsableCache = effectiveCached ? applyDetail(effectiveCached) : false;
729
851
  try {
730
852
  const body = await sessionDetailCache.load(cacheKey, async () => {
731
853
  const res = await fetch(`${origin}/api/operator/v1/chat/sessions/${encodeURIComponent(sessionId)}${ownerQuery}`, { credentials: "include" });
@@ -751,7 +873,7 @@ export function useChatSessions(params) {
751
873
  forgetLostSession(sessionId, ownerWorkspaceId);
752
874
  return false;
753
875
  }
754
- if (hasUsableCache)
876
+ if (hasUsableCache && effectiveCached?.cacheKind !== "create-seed")
755
877
  return true;
756
878
  setError(error instanceof Error ? error.message : String(error));
757
879
  return false;
@@ -922,6 +1044,7 @@ export function useChatSessions(params) {
922
1044
  deferredTurns: body.session.deferredTurns ?? (body.session.deferredTurn ? [body.session.deferredTurn] : []),
923
1045
  pendingQuestion: body.session.pendingQuestion ?? null,
924
1046
  todos: body.session.todos ?? [],
1047
+ workspaceChanges: body.session.workspaceChanges ?? [],
925
1048
  goal: body.session.goal ?? null,
926
1049
  goalStatus: body.session.goalStatus,
927
1050
  subagents: body.subagents?.items,
@@ -981,20 +1104,16 @@ export function useChatSessions(params) {
981
1104
  sessionListRef,
982
1105
  setSessionList,
983
1106
  titleWatcher: titleWatcherRef.current,
984
- refreshSessionList,
985
1107
  options: { ...options, workspaceId: scope, optimisticSessionId },
986
1108
  setCreatingSession,
987
1109
  creatingRef: creatingSessionRef,
988
1110
  });
989
1111
  pendingCreatedRowsRef.current.delete(optimisticSessionId);
990
- const durableRow = sessionListRef.current.find((item) => item.sessionId === created.sessionId);
991
- if (durableRow) {
992
- pendingCreatedRowsRef.current.set(created.sessionId, durableRow);
993
- invalidateSessionListBaseline();
994
- void refreshSessionList().finally(() => {
995
- pendingCreatedRowsRef.current.delete(created.sessionId);
996
- });
997
- }
1112
+ // The create response is the durable truth for this blank session:
1113
+ // `replaceOptimisticSession` already committed the list row, so a full
1114
+ // catalog rescan would only add latency. Seed the detail cache with
1115
+ // the same durable metadata so re-activating it is cache-first.
1116
+ primeCreatedSessionDetailCache({ origin, session: created });
998
1117
  return created;
999
1118
  }
1000
1119
  catch (error) {
@@ -1004,13 +1123,7 @@ export function useChatSessions(params) {
1004
1123
  setSessionList(cleaned);
1005
1124
  throw error;
1006
1125
  }
1007
- }, [
1008
- origin,
1009
- refreshSessionList,
1010
- workspaceId,
1011
- setError,
1012
- invalidateSessionListBaseline,
1013
- ]);
1126
+ }, [origin, workspaceId, setError, invalidateSessionListBaseline]);
1014
1127
  const createSession = useCallback(async (options) => {
1015
1128
  // Suppress concurrent create from any entry (sidebar / Landing / chip).
1016
1129
  if (creatingSessionRef.current)
@@ -1028,9 +1141,10 @@ export function useChatSessions(params) {
1028
1141
  // A caller-provided snapshot is an explicit new-session boundary; reusing
1029
1142
  // an existing shell would silently drop that context suffix.
1030
1143
  const sessionMode = options?.sessionMode ?? DEFAULT_CONSOLE_CHAT_SESSION_MODE;
1144
+ const hasPending = Boolean(refs.pendingSubmissionRef.current);
1031
1145
  const reusable = options?.snapshot
1032
1146
  ? undefined
1033
- : findReusableBlankSession(sessionListRef.current, scope, sessionMode);
1147
+ : findReusableBlankSession(sessionListRef.current, scope, sessionMode, previousSession, hasPending);
1034
1148
  if (reusable) {
1035
1149
  if (previousSession?.sessionId === reusable.sessionId)
1036
1150
  return previousSession;
@@ -1058,7 +1172,8 @@ export function useChatSessions(params) {
1058
1172
  setSelectedSession(created);
1059
1173
  rememberActiveChatSession(window.localStorage, created.workspaceId ?? options?.workspaceId ?? workspaceId, created.sessionId);
1060
1174
  setSession(created);
1061
- void refreshSessionTelemetry();
1175
+ // A just-created blank session has no messages, requests or usage yet;
1176
+ // a detail GET here would only queue behind the first turn.
1062
1177
  return created;
1063
1178
  }
1064
1179
  catch (e) {
@@ -1082,7 +1197,6 @@ export function useChatSessions(params) {
1082
1197
  activateSession,
1083
1198
  blocked,
1084
1199
  workspaceId,
1085
- refreshSessionTelemetry,
1086
1200
  ]);
1087
1201
  // Phase-1: fork / in-session branch / mainline switch UI deferred; API routes remain.
1088
1202
  /** Single compact helper for toolbar + `/compact <instructions>` (AC-1). */
@@ -1159,22 +1273,55 @@ export function useChatSessions(params) {
1159
1273
  sessionOwnerQuery,
1160
1274
  ]);
1161
1275
  const updateSession = async (sessionId, patch) => {
1162
- // AC-002: rename/archive follows the session's durable owner.
1163
- const res = await fetch(`${origin}/api/operator/v1/chat/sessions/${encodeURIComponent(sessionId)}${sessionOwnerQuery(sessionListRef.current.find((item) => item.sessionId === sessionId)
1164
- ?.workspaceId ?? null)}`, {
1165
- method: "PATCH",
1166
- credentials: "include",
1167
- headers: {
1168
- "content-type": "application/json",
1169
- "x-loop-console-confirmation": confirmationToken(),
1170
- },
1171
- body: JSON.stringify(patch),
1276
+ // P2-B: Optimistically record in local mutation log and update state immediately
1277
+ const now = new Date().toISOString();
1278
+ mutationLogRef.current.mutated.set(sessionId, {
1279
+ ...(patch.title !== undefined ? { title: patch.title } : {}),
1280
+ ...(patch.displayTitle !== undefined ? { displayTitle: patch.displayTitle } : {}),
1281
+ ...(patch.state === "active" || patch.state === "archived" ? { state: patch.state } : {}),
1282
+ updatedAt: now,
1172
1283
  });
1173
- if (!res.ok) {
1174
- setError("会话更新失败");
1284
+ mutationLogRef.current.generation += 1;
1285
+ invalidateSessionListBaseline();
1286
+ setSessionList((current) => current.map((item) => {
1287
+ if (item.sessionId !== sessionId)
1288
+ return item;
1289
+ return {
1290
+ ...item,
1291
+ ...(patch.title !== undefined ? { title: patch.title } : {}),
1292
+ ...(patch.displayTitle !== undefined ? { displayTitle: patch.displayTitle } : {}),
1293
+ ...(patch.state === "active" || patch.state === "archived" ? { state: patch.state } : {}),
1294
+ updatedAt: now,
1295
+ };
1296
+ }));
1297
+ // AC-002: rename/archive follows the session's durable owner.
1298
+ try {
1299
+ const res = await fetch(`${origin}/api/operator/v1/chat/sessions/${encodeURIComponent(sessionId)}${sessionOwnerQuery(sessionListRef.current.find((item) => item.sessionId === sessionId)
1300
+ ?.workspaceId ?? null)}`, {
1301
+ method: "PATCH",
1302
+ credentials: "include",
1303
+ headers: {
1304
+ "content-type": "application/json",
1305
+ "x-loop-console-confirmation": confirmationToken(),
1306
+ },
1307
+ body: JSON.stringify(patch),
1308
+ });
1309
+ if (!res.ok) {
1310
+ mutationLogRef.current.mutated.delete(sessionId);
1311
+ invalidateSessionListBaseline();
1312
+ void refreshSessionList();
1313
+ setError("会话更新失败");
1314
+ return;
1315
+ }
1316
+ await refreshSessionList();
1317
+ }
1318
+ catch (error) {
1319
+ mutationLogRef.current.mutated.delete(sessionId);
1320
+ invalidateSessionListBaseline();
1321
+ void refreshSessionList();
1322
+ setError(error instanceof Error ? error.message : String(error));
1175
1323
  return;
1176
1324
  }
1177
- await refreshSessionList();
1178
1325
  if (patch.state === "archived") {
1179
1326
  titleWatcherRef.current?.cancel(sessionId);
1180
1327
  }
@@ -5,6 +5,7 @@ import { confirmationToken, requestId, sleep } from "./format.js";
5
5
  import { classifyCreateTurnNetworkFailure, classifyCreateTurnResponse, createPendingSubmission, decideSubmissionRoute, isRuntimeBusyUnion, isSubmissionCurrent, isTerminalTurnState, keepAmbiguousAfterRetry, reconcileDeferredSubmissionFromState, reconcilePendingSubmissionFromState, resolveAmbiguousFromState, } from "./turn-submission.js";
6
6
  import { applyAbortDecision, applyPendingReconcileDecision, classifyAbortResponse, createBoundedOwnerSignal, markStopRequested, operatorChatAbortUrl, operatorChatEventsUrl, operatorChatStateUrl, operatorChatTurnsUrl, releaseOwnershipOnTerminalEvidence, releaseSubmitOwnership as releaseOwnershipBag, requestStopOnOwnership, requestAbortWithRetry, settleCreateTurnOutcome, turnPhaseFromOwnership, visualTurnPhaseFromOwnership, } from "./turn-stream-controller.js";
7
7
  import { appendPendingSubmission, removePendingSubmission } from "./pending-user-message.js";
8
+ import { invalidateSessionDetailCacheSeed } from "./useChatSessions.js";
8
9
  import { createTurnStateReconcileQueue, turnStateReconcileTrigger, } from "./turn-state-projection.js";
9
10
  const STATE_REQUEST_TIMEOUT_MS = 2_000;
10
11
  async function fetchReconciledSessionState(origin, sessionId, options) {
@@ -891,6 +892,9 @@ export function useChatStream(params) {
891
892
  userMessageId,
892
893
  });
893
894
  refs.pendingSubmissionRef.current = pending;
895
+ // P1-C: Starting a prompt transition makes the initial blank create-seed
896
+ // obsolete so re-activation fetches authoritative messages/turns.
897
+ invalidateSessionDetailCacheSeed(activeSession.sessionId, activeSession.workspaceId, origin);
894
898
  const userMsg = {
895
899
  id: userMessageId,
896
900
  role: "user",
@@ -7,10 +7,14 @@ import { createChatSseEventApplier, } from "./chat-sse-events.js";
7
7
  import { mergePendingSubmissionOnHydration } from "./pending-user-message.js";
8
8
  import { taskContextUnchanged } from "./format.js";
9
9
  import { upsertCompactionMessage } from "./compaction-message.js";
10
+ import { invalidateSessionDetailCacheSeed } from "./useChatSessions.js";
10
11
  import { mergeSubagentCatalogItems, projectSubagentCatalogFromToolCalls, subagentSummary, } from "./subagent-catalog.js";
11
12
  import { sameTurnGroupInputs } from "./turn-group-equality.js";
12
13
  import { conversationNodesFromEvents, } from "../../chat/conversation-nodes.js";
13
14
  import { mergeTurnStateSummaries, setProjectedTurnState, } from "./turn-state-projection.js";
15
+ function latestWorkspaceChanges(items) {
16
+ return [...new Map(items.map(item => [item.turnId, item])).values()];
17
+ }
14
18
  const EMPTY_USAGE = {
15
19
  inputTokens: 0,
16
20
  outputTokens: 0,
@@ -149,6 +153,7 @@ export function useChatThread(params) {
149
153
  const [operatorActions, setOperatorActions] = useState([]);
150
154
  const [conversationNodes, setConversationNodes] = useState([]);
151
155
  const [turnStatesById, setTurnStatesById] = useState({});
156
+ const [workspaceChanges, setWorkspaceChanges] = useState([]);
152
157
  const reconcileTurnStates = useCallback((summaries) => {
153
158
  setTurnStatesById((current) => mergeTurnStateSummaries(current, summaries));
154
159
  }, []);
@@ -193,6 +198,9 @@ export function useChatThread(params) {
193
198
  setTurnTelemetry(body.turnTelemetry ?? []);
194
199
  setRequestDetails(body.requestDetails ?? []);
195
200
  setSddSessionIdentity(body.sddDataAlignment ?? null);
201
+ if (body.session?.workspaceChanges) {
202
+ setWorkspaceChanges(latestWorkspaceChanges(body.session.workspaceChanges));
203
+ }
196
204
  reconcileTurnStates(body.session?.turnStates);
197
205
  }
198
206
  catch {
@@ -214,6 +222,7 @@ export function useChatThread(params) {
214
222
  setDeferredTurns,
215
223
  setPendingQuestion,
216
224
  setTodos,
225
+ setWorkspaceChanges,
217
226
  setWorkflowRuns,
218
227
  setGoal,
219
228
  setGoalStatus,
@@ -266,6 +275,10 @@ export function useChatThread(params) {
266
275
  refs.seenEventIdsRef.current.add(dedupeId);
267
276
  }
268
277
  applyChatSseEvent(eventName, data, assistantId, options);
278
+ const targetId = options?.targetSessionId ?? refs.sessionRef.current?.sessionId;
279
+ if (targetId) {
280
+ invalidateSessionDetailCacheSeed(targetId, refs.sessionRef.current?.workspaceId, origin);
281
+ }
269
282
  return eventId ?? dedupeId;
270
283
  }, [applyChatSseEvent, refs]);
271
284
  const loadTaskContext = useCallback(async (targetSessionId, options) => {
@@ -382,6 +395,7 @@ export function useChatThread(params) {
382
395
  activeAssistantId: streamingAssistantId,
383
396
  conversationNodes,
384
397
  turnStatesById,
398
+ workspaceChanges,
385
399
  });
386
400
  // Preserve completed group objects across streaming tokens. Stable
387
401
  // historical groups keep their references so
@@ -532,6 +546,7 @@ export function useChatThread(params) {
532
546
  setDeferredTurns([]);
533
547
  setPendingQuestion(null);
534
548
  setTodos([]);
549
+ setWorkspaceChanges([]);
535
550
  setWorkflowRuns(new Map());
536
551
  setGoal(null);
537
552
  setGoalStatus("loading");
@@ -600,6 +615,7 @@ export function useChatThread(params) {
600
615
  setDeferredTurns(next.deferredTurns ?? (next.deferredTurn ? [next.deferredTurn] : []));
601
616
  setPendingQuestion(next.pendingQuestion ?? null);
602
617
  setTodos(next.todos ?? []);
618
+ setWorkspaceChanges(latestWorkspaceChanges(next.workspaceChanges ?? []));
603
619
  setGoal(next.goal ?? null);
604
620
  setGoalStatus(next.goalStatus ?? (next.goal ? "present" : "absent"));
605
621
  setServerSubagents(next.subagents ?? []);
@@ -638,6 +654,7 @@ export function useChatThread(params) {
638
654
  setDeferredTurns(body.session.deferredTurns ?? (body.session.deferredTurn ? [body.session.deferredTurn] : []));
639
655
  setPendingQuestion(body.session.pendingQuestion ?? null);
640
656
  setTodos(body.session.todos ?? []);
657
+ setWorkspaceChanges(body.session.workspaceChanges ?? []);
641
658
  setGoal(body.session.goal ?? null);
642
659
  setGoalStatus(body.session.goalStatus ?? (body.session.goal ? "present" : "absent"));
643
660
  if (body.sessionStats)
@@ -749,6 +766,7 @@ export function useChatThread(params) {
749
766
  pendingQuestion,
750
767
  setPendingQuestion,
751
768
  todos,
769
+ workspaceChanges,
752
770
  workflowRuns,
753
771
  goal,
754
772
  setGoal,