@tea-agent/loop-agent 0.40.0-next.1 → 0.40.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.
Files changed (208) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +106 -109
  3. package/README.md +2 -2
  4. package/dist/application/task-lifecycle/advance.js +12 -0
  5. package/dist/build-stamp.json +3 -3
  6. package/dist/cli/update/runtime-activity.js +1 -29
  7. package/dist/commands/dag-rerun.js +1 -1
  8. package/dist/executors/dag-pi-executor.js +69 -7
  9. package/dist/executors/pi-executor.js +4 -2
  10. package/dist/executors/pi-sdk-executor.js +46 -1
  11. package/dist/executors/pi-writer-tool-policy.js +57 -1
  12. package/dist/executors/shell-executor.js +43 -3
  13. package/dist/executors/workspace-write-snapshot.js +68 -0
  14. package/dist/infrastructure/harness/atomic-write.js +23 -0
  15. package/dist/shared/dag-prompt-override.js +4 -5
  16. package/dist/shared/update/npm-client.js +33 -11
  17. package/dist/task/config-types.js +10 -0
  18. package/dist/task/contract/apply.js +11 -1
  19. package/dist/task/contract/constants.js +2 -0
  20. package/dist/task/contract/hash.js +3 -0
  21. package/dist/task/contract/observe.js +25 -4
  22. package/dist/task/contract/paths.js +2 -1
  23. package/dist/task/contract/project.js +15 -1
  24. package/dist/task/contract/schema.js +2 -0
  25. package/dist/task/contract/transaction.js +12 -0
  26. package/dist/task/source-prepare/completeness.js +188 -0
  27. package/dist/task/source-prepare/fragment-inventory.js +474 -0
  28. package/dist/task/source-prepare/index.js +3 -0
  29. package/dist/task/source-prepare/ledger-reconciliation.js +127 -0
  30. package/dist/task/source-prepare/ledger-review.js +214 -0
  31. package/dist/task/source-prepare/ledger.js +545 -0
  32. package/dist/task/source-prepare/prepare.js +262 -1
  33. package/dist/task/source-prepare/semantic-intake.js +19 -3
  34. package/dist/task/source-prepare/source-fidelity-pi.js +384 -0
  35. package/dist/task/source-prepare/types.js +22 -0
  36. package/dist/worker/cli.js +12 -26
  37. package/dist/worker/console/chat/chat-event-store.js +75 -5
  38. package/dist/worker/console/chat/context-panel.js +7 -0
  39. package/dist/worker/console/chat/deferred-turn.js +12 -0
  40. package/dist/worker/console/chat/pi-runtime.js +331 -18
  41. package/dist/worker/console/chat/provider-error.js +98 -0
  42. package/dist/worker/console/chat/routes.js +389 -56
  43. package/dist/worker/console/chat/session-stats.js +179 -0
  44. package/dist/worker/console/chat/session-store.js +93 -63
  45. package/dist/worker/console/chat/todos.js +115 -0
  46. package/dist/worker/console/chat/tool-preview.js +42 -0
  47. package/dist/worker/console/chat/turn-process.js +20 -55
  48. package/dist/worker/console/chat/user-questions.js +266 -0
  49. package/dist/worker/console/chat/workspace-landing.js +79 -0
  50. package/dist/worker/console/console-handoff.js +82 -0
  51. package/dist/worker/console/console-update-and-init.js +115 -0
  52. package/dist/worker/console/console-update-runtime.js +84 -0
  53. package/dist/worker/console/draft-store.js +49 -0
  54. package/dist/worker/console/native-directory-picker.js +13 -0
  55. package/dist/worker/console/operation-store.js +1 -1
  56. package/dist/worker/console/operator-actions.js +129 -4
  57. package/dist/worker/console/operator-surface-health.js +1 -0
  58. package/dist/worker/console/prd-intake-bridge.js +13 -0
  59. package/dist/worker/console/routes.js +312 -1
  60. package/dist/worker/console/security.js +4 -4
  61. package/dist/worker/console/server.js +583 -172
  62. package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-Br92EGb7.js → abnfDiagram-N423BO3Z-Bs-CDAXM.js} +1 -1
  63. package/dist/worker/console/static/assets/{arc-oulImtQq.js → arc-CAkA3We3.js} +1 -1
  64. package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-tyHc6aqO.js → architectureDiagram-T3A2C74G-DEmI_zqr.js} +1 -1
  65. package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-CY86BSpT.js → blockDiagram-VBNYF7ZC-uDHANebE.js} +1 -1
  66. package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-BKKsDmNs.js → c4Diagram-5PPSVZJV-Bv97b4_B.js} +1 -1
  67. package/dist/worker/console/static/assets/channel-amxUpk7o.js +1 -0
  68. package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-CXZdjl3B.js → chunk-2GRJ4B5K-shmQKsFz.js} +1 -1
  69. package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-B-aIFDQ5.js → chunk-2Q5K7J3B-BAraNvcN.js} +1 -1
  70. package/dist/worker/console/static/assets/{chunk-5RXB4S5H-BDgAW_B2.js → chunk-5RXB4S5H-BirhxUop.js} +1 -1
  71. package/dist/worker/console/static/assets/{chunk-5VM5RSS4-DABa4UPR.js → chunk-5VM5RSS4-C9LgUJpR.js} +1 -1
  72. package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-aGbysVOx.js → chunk-6Q2QTUOP-DrU-s-t7.js} +1 -1
  73. package/dist/worker/console/static/assets/{chunk-GF5L2VYU-B8MSZDVs.js → chunk-GF5L2VYU-Tx-H_FA2.js} +1 -1
  74. package/dist/worker/console/static/assets/{chunk-JWPE2WC7-CpelV73g.js → chunk-JWPE2WC7-BjLtNFrR.js} +1 -1
  75. package/dist/worker/console/static/assets/{chunk-KBJHAD2P-BE04ty3z.js → chunk-KBJHAD2P-UNLVwSsy.js} +1 -1
  76. package/dist/worker/console/static/assets/{chunk-RYQCIY6F-BUxTkaaR.js → chunk-RYQCIY6F-CBEUX8XD.js} +1 -1
  77. package/dist/worker/console/static/assets/{chunk-XXDRQBXY-CYYBVKfX.js → chunk-XXDRQBXY-WTL7IZOq.js} +1 -1
  78. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-bejwBVIz.js +1 -0
  79. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-bejwBVIz.js +1 -0
  80. package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-CEQF_xmQ.js → cose-bilkent-JH36ORCC-CkHG6W3s.js} +1 -1
  81. package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-CqpxN5IT.js → cynefin-VYW2F7L2-BRzFqTaL.js} +1 -1
  82. package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-B3PzanVi.js → cynefinDiagram-MW4NZA55-2_CFp_i7.js} +1 -1
  83. package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-BSUGCNx1.js → dagre-VZM6K2ZE-BJtsmdkE.js} +1 -1
  84. package/dist/worker/console/static/assets/{diagram-7IWD3JNH-CdLevU5T.js → diagram-7IWD3JNH-DNEFFo6w.js} +1 -1
  85. package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-BjpF_Kok.js → diagram-B4RE2ZJO-B_IWV7eo.js} +1 -1
  86. package/dist/worker/console/static/assets/{diagram-LBJQPF4R-C4I6NJny.js → diagram-LBJQPF4R-DvvRx2dz.js} +1 -1
  87. package/dist/worker/console/static/assets/{diagram-Q27KOJAE-C8hecCr5.js → diagram-Q27KOJAE-CsibsWLg.js} +1 -1
  88. package/dist/worker/console/static/assets/{diagram-UB23O5K3-Daod6tOS.js → diagram-UB23O5K3-les_djBQ.js} +1 -1
  89. package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-BvvmazGv.js → ebnfDiagram-BXEA7PRR-BEm2n7qJ.js} +1 -1
  90. package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-DeN_vfV4.js → erDiagram-JOGREHBK-BI7vHHVm.js} +1 -1
  91. package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-D6dq1t9z.js → flowDiagram-UKHOOZJN-CUFCERrB.js} +1 -1
  92. package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-DziIdNY4.js → ganttDiagram-PKOTCBZU-wxyLiGWt.js} +1 -1
  93. package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-Dy4s5CXr.js → gitGraphDiagram-DS77QQ5N-Bt897K8Z.js} +1 -1
  94. package/dist/worker/console/static/assets/index-BHhUOTri.css +1 -0
  95. package/dist/worker/console/static/assets/index-DqJbO3-p.js +407 -0
  96. package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-Czv5eYx2.js → infoDiagram-6WML65LV-DYNx_IPv.js} +1 -1
  97. package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-Bsk3nFRT.js → ishikawaDiagram-WSZJBQD7-CzpLNEu6.js} +1 -1
  98. package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-DxGmNj5K.js → journeyDiagram-NVQOT4AX-97f9owNU.js} +1 -1
  99. package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-CYCFqkO_.js → kanban-definition-27J2QSJJ-BxM9hyBn.js} +1 -1
  100. package/dist/worker/console/static/assets/{linear-B0YzRwrd.js → linear-ByuxcHvp.js} +1 -1
  101. package/dist/worker/console/static/assets/{mermaid.core-t3EZtIGh.js → mermaid.core-DwPGvpCv.js} +5 -5
  102. package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-BTXpTv0T.js → mindmap-definition-FAOFIHXS-DCoqG9RT.js} +1 -1
  103. package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-DU8UkKqA.js → pegDiagram-VL7TDLO6-BLSBmBMx.js} +1 -1
  104. package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-DP4y8ohp.js → pieDiagram-7S7Q4E2Y-B0t_0oJW.js} +1 -1
  105. package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-B07vNaYR.js → quadrantDiagram-CIZ2JOQS-sTzDk7Nt.js} +1 -1
  106. package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-xDWktb2i.js → railroadDiagram-AXF67PYL-B3jRdATC.js} +1 -1
  107. package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-BLNMKqeS.js → requirementDiagram-LRYGKXZP-D-cTtXEN.js} +1 -1
  108. package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-n0adalxH.js → sankeyDiagram-W5VNT64P-B25igJRE.js} +1 -1
  109. package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-BbnS-2DL.js → sequenceDiagram-SI44F4Z6-jW_lM1_D.js} +1 -1
  110. package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-B4uPpCLu.js → sizeCapture-X5ZJPWSS-CrzTgsHE.js} +1 -1
  111. package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA--MMbB0fX.js → stateDiagram-OKZ733FA-B01MvlqE.js} +1 -1
  112. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-BvFKEtm2.js +1 -0
  113. package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-BXUgp2QY.js → swimlanes-SLNWSIFB-YcF12FiU.js} +2 -2
  114. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-DIB2eVg-.js +8 -0
  115. package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-CsaMxki7.js → timeline-definition-Z64GVDOM-ClnRcg2s.js} +1 -1
  116. package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-C2IuG9iH.js → vennDiagram-T6HMQDX7-B6gr_z-q.js} +1 -1
  117. package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-CmEWOXCW.js → wardleyDiagram-T6FBY63Y-CvSgguGH.js} +1 -1
  118. package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-D_9LE0MG.js → xychartDiagram-ELKLHX3M-23OtSZCb.js} +1 -1
  119. package/dist/worker/console/static/index.html +2 -2
  120. package/dist/worker/console/static-src/app/console-types.js +68 -4
  121. package/dist/worker/console/static-src/app/useConsoleShell.js +30 -12
  122. package/dist/worker/console/static-src/app/useOperatorActions.js +41 -6
  123. package/dist/worker/console/static-src/app/useRecoveryConsole.js +10 -11
  124. package/dist/worker/console/static-src/app/useRunProgress.js +2 -1
  125. package/dist/worker/console/static-src/app/useTaskWizard.js +74 -2
  126. package/dist/worker/console/static-src/night/useNightBoard.js +8 -5
  127. package/dist/worker/console/static-src/operator-chat/chat-sse-events.js +141 -8
  128. package/dist/worker/console/static-src/operator-chat/compaction-message.js +79 -0
  129. package/dist/worker/console/static-src/operator-chat/details-dag-actions.js +122 -0
  130. package/dist/worker/console/static-src/operator-chat/refs.js +3 -0
  131. package/dist/worker/console/static-src/operator-chat/runtime-selection-labels.js +27 -0
  132. package/dist/worker/console/static-src/operator-chat/spatial-overlay.js +1 -2
  133. package/dist/worker/console/static-src/operator-chat/turn-stream-controller.js +25 -0
  134. package/dist/worker/console/static-src/operator-chat/turn-submission.js +3 -2
  135. package/dist/worker/console/static-src/operator-chat/useChatSessions.js +181 -87
  136. package/dist/worker/console/static-src/operator-chat/useChatStream.js +159 -44
  137. package/dist/worker/console/static-src/operator-chat/useChatThread.js +177 -8
  138. package/dist/worker/console/static-src/operator-chat/useRepoBrowser.js +63 -9
  139. package/dist/worker/console/static-src/operator-chat/useWorkspaceBrowserGate.js +4 -0
  140. package/dist/worker/console/static-src/operator-chat/workspace-layout-mode.js +3 -3
  141. package/dist/worker/console/static-src/shell/useWorkspaces.js +299 -0
  142. package/dist/worker/console/static-src/shell/workspace-route.js +339 -0
  143. package/dist/worker/console/workspace-context.js +234 -0
  144. package/dist/worker/console/workspace-registry.js +214 -0
  145. package/dist/worker/observability/init-runtime-activity.js +26 -0
  146. package/dist/worker/observe/node-input.js +88 -2
  147. package/dist/worker/observe/routes.js +188 -0
  148. package/dist/worker/observe/server.js +4 -0
  149. package/dist/worker/observe/static/api.js +29 -9
  150. package/dist/worker/observe/static/app.js +18 -70
  151. package/dist/worker/observe/static/dag-node-purpose.d.ts +6 -0
  152. package/dist/worker/observe/static/dag-node-purpose.js +203 -0
  153. package/dist/worker/observe/static/format.js +37 -0
  154. package/dist/worker/observe/static/index.html +6 -1
  155. package/dist/worker/observe/static/inspect-workspace.js +307 -0
  156. package/dist/worker/observe/static/operator-chrome.css +145 -20
  157. package/dist/worker/observe/static/operator-chrome.d.ts +20 -3
  158. package/dist/worker/observe/static/operator-chrome.js +330 -100
  159. package/dist/worker/observe/static/prompt-restart-candidates.d.ts +18 -0
  160. package/dist/worker/observe/static/prompt-restart-candidates.js +36 -0
  161. package/dist/worker/observe/static/router.d.ts +46 -0
  162. package/dist/worker/observe/static/router.js +25 -1
  163. package/dist/worker/observe/static/state.d.ts +50 -0
  164. package/dist/worker/observe/static/state.js +174 -2
  165. package/dist/worker/observe/static/styles.css +357 -35
  166. package/dist/worker/observe/static/views/dag-graph.js +4 -2
  167. package/dist/worker/observe/static/views/dag-inspector.js +533 -79
  168. package/dist/worker/observe/static/views/dag.d.ts +13 -0
  169. package/dist/worker/observe/static/views/dag.js +6 -4
  170. package/dist/worker/observe/static/views/dashboard.js +6 -4
  171. package/dist/worker/observe/static/views/night.js +2 -2
  172. package/dist/worker/observe/static/views/pool.js +1 -0
  173. package/dist/worker/observe/static/views/run.js +3 -1
  174. package/dist/worker/observe/static/views/task.js +56 -1
  175. package/dist/workflows/dag/backend-test-case-coverage-analysis.js +29 -1
  176. package/dist/workflows/dag/backend-test-markdown-workflow.js +176 -1
  177. package/dist/workflows/dag/backend-test-pytest-collection.js +98 -14
  178. package/dist/workflows/dag/backend-test-writer-completeness.js +17 -17
  179. package/dist/workflows/dag/dynamic-runtime/map.js +1 -0
  180. package/dist/workflows/dag/frontend-implementation-contract.js +88 -2
  181. package/dist/workflows/dag/frontend-plan-render.js +24 -0
  182. package/dist/workflows/dag/frontend-prewrite-gate.js +197 -0
  183. package/dist/workflows/dag/frontend-review-context.js +92 -10
  184. package/dist/workflows/dag/init-hybrid.js +238 -51
  185. package/dist/workflows/dag/interrupt-request.js +3 -3
  186. package/dist/workflows/dag/lifecycle.js +3 -3
  187. package/dist/workflows/dag/node-execution.js +45 -0
  188. package/dist/workflows/dag/types.js +62 -12
  189. package/docs/README.md +2 -0
  190. package/docs/architecture/evolution.md +45 -0
  191. package/docs/init-surface.manifest.json +1 -0
  192. package/docs/operations/local-development-environment.md +21 -0
  193. package/docs/templates/README.md +1 -1
  194. package/docs/templates/agent-dag.schema.json +18 -0
  195. package/docs/templates/backend-test-dag.json +265 -237
  196. package/docs/templates/frontend-implementation-contract.schema.json +681 -24
  197. package/harness.json +3 -3
  198. package/package.json +3 -1
  199. package/skills/loop-agent/references/hybrid-dag.md +7 -0
  200. package/dist/worker/console/static/assets/channel-TY36zt-i.js +0 -1
  201. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-Dk7QCChM.js +0 -1
  202. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-Dk7QCChM.js +0 -1
  203. package/dist/worker/console/static/assets/index-C3GgHg-g.css +0 -1
  204. package/dist/worker/console/static/assets/index-Ci8ksvBm.js +0 -406
  205. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-BqOigMQ4.js +0 -1
  206. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-Caxz9UA2.js +0 -8
  207. package/dist/worker/console/static-src/operator-chat/activity-rail-presentation.js +0 -73
  208. package/dist/worker/console/static-src/operator-chat/useActivityRailTransition.js +0 -59
@@ -0,0 +1,46 @@
1
+ /** 与 router.js 对应的类型声明(供 vitest/TS 侧导入契约测试)。 */
2
+
3
+ export type InspectHashRoute = {
4
+ view: string;
5
+ batchRunId?: string;
6
+ workerRunId?: string;
7
+ dagRunId?: string;
8
+ featureId?: string;
9
+ taskId?: string;
10
+ scheduleId?: string;
11
+ page?: number;
12
+ pageSize?: number;
13
+ filters?: { status?: string; q?: string };
14
+ };
15
+
16
+ export function parseHashRoute(hashValue: string): InspectHashRoute;
17
+ export function parseRoute(): InspectHashRoute;
18
+ export function setNavigateHandler(
19
+ handler: ((href: string) => void) | null,
20
+ ): void;
21
+ export function inspectPathToCanonicalHref(path: string): string;
22
+ export function navigate(path: string): void;
23
+
24
+ export const DAG_HISTORY_DEFAULT_PAGE: number;
25
+ export const DAG_HISTORY_DEFAULT_PAGE_SIZE: number;
26
+ export const DAG_HISTORY_ALLOWED_PAGE_SIZES: readonly number[];
27
+
28
+ export function clampDagHistoryPageSize(value: unknown): number;
29
+ export function clampDagHistoryPage(
30
+ value: unknown,
31
+ totalPages?: number,
32
+ ): number;
33
+ export function parseDagHistoryQuery(hashValue: string): {
34
+ page: number;
35
+ pageSize: number;
36
+ };
37
+ export function buildDagHistoryHash(page: unknown, pageSize: unknown): string;
38
+ export function parseHashFilters(hashValue: string): {
39
+ status?: string;
40
+ q?: string;
41
+ };
42
+ export function parseHashRouteWithFilters(hashValue: string): InspectHashRoute;
43
+ export function buildHashPath(
44
+ path: string,
45
+ filters?: Record<string, unknown>,
46
+ ): string;
@@ -1,7 +1,10 @@
1
1
  /** Hash routing for Observe UI (R5). */
2
2
 
3
3
  export function parseHashRoute(hashValue) {
4
- const hash = (hashValue.replace(/^#/, "") || "/").split("?")[0] || "/";
4
+ let hash = (hashValue.replace(/^#/, "") || "/").split("?")[0] || "/";
5
+ if (!hash.startsWith("/")) hash = `/${hash}`;
6
+ if (hash === "/inspect") hash = "/";
7
+ else if (hash.startsWith("/inspect/")) hash = hash.slice("/inspect".length) || "/";
5
8
  const batchMatch = /^\/batch\/([^/]+)$/.exec(hash);
6
9
  if (batchMatch) {
7
10
  return { view: "batch", batchRunId: decodeURIComponent(batchMatch[1]) };
@@ -61,7 +64,28 @@ export function parseRoute() {
61
64
  return parseHashRouteWithFilters(location.hash);
62
65
  }
63
66
 
67
+ let navigateHandler = null;
68
+
69
+ export function setNavigateHandler(handler) {
70
+ navigateHandler = typeof handler === "function" ? handler : null;
71
+ }
72
+
73
+ export function inspectPathToCanonicalHref(path) {
74
+ const raw = String(path ?? "");
75
+ if (raw.startsWith("/#/inspect")) return raw;
76
+ if (raw.startsWith("#/inspect")) return `/${raw}`;
77
+ const stripped = raw.replace(/^#/, "");
78
+ const withSlash = stripped.startsWith("/") ? stripped : `/${stripped}`;
79
+ if (withSlash === "/inspect" || withSlash === "/") return "/#/inspect";
80
+ if (withSlash.startsWith("/inspect/")) return `/#${withSlash}`;
81
+ return `/#/inspect${withSlash}`;
82
+ }
83
+
64
84
  export function navigate(path) {
85
+ if (navigateHandler) {
86
+ navigateHandler(inspectPathToCanonicalHref(path));
87
+ return;
88
+ }
65
89
  location.hash = path.startsWith("#") ? path.slice(1) : path;
66
90
  }
67
91
 
@@ -0,0 +1,50 @@
1
+ /** 与 state.js 对应的类型声明(供 vitest/TS 侧导入契约测试)。 */
2
+
3
+ export type ViewStateKind = "loading" | "empty" | "degraded" | "error";
4
+
5
+ export type ViewStateDescriptor = {
6
+ kind: ViewStateKind;
7
+ className: string;
8
+ role: string | null;
9
+ ariaLive: string | null;
10
+ message: string;
11
+ detail: string | null;
12
+ messageClass: string | null;
13
+ };
14
+
15
+ export const uiState: {
16
+ lastSnapshot: unknown;
17
+ specEvidenceDetail: {
18
+ source: string;
19
+ path: string;
20
+ loading: boolean;
21
+ error: string | null;
22
+ data: unknown;
23
+ triggerId: string | null;
24
+ } | null;
25
+ dagNodeExecutionOutputCache: Map<string, unknown> | null;
26
+ [key: string]: unknown;
27
+ };
28
+
29
+ export function setWorkspaceScope(workspaceId: string | null): void;
30
+ export function workspaceScope(): string | null;
31
+ export function scopedApiUrl(url: string): string;
32
+ export function workspaceRequestSignal(): AbortSignal | undefined;
33
+ export function fetchWithWorkspaceScope(
34
+ url: string,
35
+ init?: RequestInit,
36
+ ): Promise<Response>;
37
+ export function abortWorkspaceRequests(): void;
38
+ export function setWorkspaceActive(active: boolean): void;
39
+ export function stopTimers(): void;
40
+ export function pauseForegroundTimers(): void;
41
+
42
+ /** Multi-workspace atomic scope switch (2026-08-26, AC-006). */
43
+ export function applyWorkspaceScopeSwitch(
44
+ nextWorkspaceId: string | null,
45
+ routeValue?: (() => void) | string,
46
+ options?: {
47
+ route?: (hashValue: string) => void;
48
+ onTrace?: (trace: string[]) => void;
49
+ },
50
+ ): string[];
@@ -82,8 +82,8 @@ export const uiState = {
82
82
  dagNodeExecutionOutputLoading: false,
83
83
  dagNodeExecutionOutputError: null,
84
84
  dagNodeExecutionOutputKey: null,
85
- /** When true,「执行过程」展开 message_start/end 原始协议事件。默认展开,用户可点选隐藏。 */
86
- sessionTimelineShowProtocol: true,
85
+ /** When true,「执行过程」展开 message_start/end 原始协议事件。默认隐藏,用户可点选展开。 */
86
+ sessionTimelineShowProtocol: false,
87
87
  /** Open <details> keys restored across timeline re-renders. */
88
88
  sessionTimelineOpenDetails: null,
89
89
  lastSnapshot: null,
@@ -116,6 +116,8 @@ export const uiState = {
116
116
  /** Last-rendered spec-evidence list, used to restore the list synchronously. */
117
117
  specEvidenceListEvidence: null,
118
118
  pollingGeneration: 0,
119
+ /** Hosted Inspect workspace is foreground. Standalone defaults to active. */
120
+ workspaceActive: true,
119
121
  };
120
122
 
121
123
  /** Per-dagRunId graph viewport restore map (stable Map instance). */
@@ -279,16 +281,186 @@ export function isPageVisible() {
279
281
  );
280
282
  }
281
283
 
284
+ export function isWorkspaceActive() {
285
+ return uiState.workspaceActive !== false;
286
+ }
287
+
288
+ export function setWorkspaceActive(active) {
289
+ uiState.workspaceActive = Boolean(active);
290
+ }
291
+
292
+ /**
293
+ * Multi-workspace scope (2026-08-23): every Observe GET must carry the
294
+ * current workspaceId (AC-002/AC-003). The scope is synced from the parent
295
+ * Console shell hash (`?workspaceId=`) or via postMessage for hosted mode;
296
+ * standalone pages default to null and all workspace-scoped routes fail closed
297
+ * until the host or hash publishes an explicit workspace id.
298
+ */
299
+ let currentWorkspaceScope = null;
300
+ let currentWorkspaceRequestController =
301
+ typeof AbortController === "undefined" ? null : new AbortController();
302
+
303
+ export function setWorkspaceScope(workspaceId) {
304
+ currentWorkspaceScope =
305
+ typeof workspaceId === "string" && workspaceId.trim()
306
+ ? workspaceId.trim()
307
+ : null;
308
+ }
309
+
310
+ export function workspaceScope() {
311
+ return currentWorkspaceScope;
312
+ }
313
+
314
+ /** Signal shared by every workspace-scoped Observe request in the active scope. */
315
+ export function workspaceRequestSignal() {
316
+ if (
317
+ typeof AbortController !== "undefined" &&
318
+ (!currentWorkspaceRequestController ||
319
+ currentWorkspaceRequestController.signal.aborted)
320
+ ) {
321
+ currentWorkspaceRequestController = new AbortController();
322
+ }
323
+ return currentWorkspaceRequestController?.signal;
324
+ }
325
+
326
+ function combinedRequestSignal(scopeSignal, requestSignal) {
327
+ const signals = [scopeSignal, requestSignal].filter(Boolean);
328
+ if (signals.length <= 1) return { signal: signals[0], cleanup: () => {} };
329
+ const controller = new AbortController();
330
+ const abort = () => controller.abort();
331
+ for (const signal of signals) {
332
+ if (signal.aborted) abort();
333
+ else signal.addEventListener("abort", abort, { once: true });
334
+ }
335
+ return {
336
+ signal: controller.signal,
337
+ cleanup: () => {
338
+ for (const signal of signals) signal.removeEventListener("abort", abort);
339
+ },
340
+ };
341
+ }
342
+
343
+ /** Fetch through the current workspace boundary and abort on any scope swap. */
344
+ export async function fetchWithWorkspaceScope(url, init = {}) {
345
+ const { signal: requestSignal, ...rest } = init;
346
+ const combined = combinedRequestSignal(
347
+ workspaceRequestSignal(),
348
+ requestSignal,
349
+ );
350
+ try {
351
+ return await fetch(scopedApiUrl(url), {
352
+ ...rest,
353
+ ...(combined.signal ? { signal: combined.signal } : {}),
354
+ });
355
+ } finally {
356
+ combined.cleanup();
357
+ }
358
+ }
359
+
360
+ /** Abort every old-scope request and invalidate request identity guards. */
361
+ export function abortWorkspaceRequests() {
362
+ currentWorkspaceRequestController?.abort();
363
+ currentWorkspaceRequestController =
364
+ typeof AbortController === "undefined" ? null : new AbortController();
365
+ uiState.dagHistoryAbortController?.abort?.();
366
+ uiState.dagHistoryAbortController = null;
367
+ uiState.dagHistoryRequestSeq += 1;
368
+ uiState.dagHistoryPrefetchGeneration += 1;
369
+ uiState.dagNodeInputRequestSeq += 1;
370
+ uiState.dagNodeProcessRequestSeq += 1;
371
+ uiState.dagNodeExecutionOutputRequestSeq += 1;
372
+ }
373
+
374
+ /** Multi-workspace atomic scope switch (2026-08-26, AC-006).
375
+ *
376
+ * Contract order — strictly sequential, no interleaving:
377
+ * 1. abort old — stop every poll/SSE so no late request can race the swap;
378
+ * 2. clear old — drop cached run/task/selection state of the old scope;
379
+ * 3. set scope — publish the new workspaceId for scopedApiUrl;
380
+ * 4. reload new — re-route/re-render with the new scope active.
381
+ *
382
+ * Observability: each stage appends to the returned trace so tests (and
383
+ * diagnostics) can assert the exact ordering; there is no window in which a
384
+ * new route is requested with the old scope or vice versa.
385
+ */
386
+ export function applyWorkspaceScopeSwitch(
387
+ nextWorkspaceId,
388
+ routeValue,
389
+ options = {},
390
+ ) {
391
+ const trace = [];
392
+ // 1. abort old
393
+ abortWorkspaceRequests();
394
+ stopTimers();
395
+ pauseForegroundTimers();
396
+ trace.push("abort-old");
397
+ // 2. clear old
398
+ uiState.lastSnapshot = null;
399
+ uiState.specEvidenceDetail = null;
400
+ uiState.specEvidenceListEvidence = null;
401
+ clearDagNodeExecutionOutputCache();
402
+ trace.push("clear-old");
403
+ // 3. set scope
404
+ setWorkspaceScope(nextWorkspaceId);
405
+ trace.push(`set-scope:${workspaceScope() ?? ""}`);
406
+ // 4. route/reload new
407
+ if (typeof routeValue === "function") routeValue();
408
+ else if (typeof routeValue === "string") options.route?.(routeValue);
409
+ trace.push("route-new");
410
+ if (options.onTrace) options.onTrace(trace);
411
+ return trace;
412
+ }
413
+
414
+ /** Append ?workspaceId= to an observe API URL (real request path kept). */
415
+ export function scopedApiUrl(url) {
416
+ const raw = String(url ?? "");
417
+ if (!currentWorkspaceScope || !raw.startsWith("/api/")) return raw;
418
+ const qIndex = raw.indexOf("?");
419
+ if (qIndex >= 0) {
420
+ const params = new URLSearchParams(raw.slice(qIndex + 1));
421
+ if (params.has("workspaceId")) return raw;
422
+ params.set("workspaceId", currentWorkspaceScope);
423
+ return `${raw.slice(0, qIndex)}?${params.toString()}`;
424
+ }
425
+ return `${raw}?workspaceId=${encodeURIComponent(currentWorkspaceScope)}`;
426
+ }
427
+
282
428
  export function detailPollDelay(status, isVisible) {
283
429
  const normalizedStatus = (status ?? "").toLowerCase().replace(/-/g, "_");
284
430
  if (TERMINAL_RUN_STATUSES.has(normalizedStatus)) return null;
431
+ if (!isWorkspaceActive()) return null;
285
432
  return isVisible ? ACTIVE_DETAIL_POLL_MS : HIDDEN_POLL_MS;
286
433
  }
287
434
 
288
435
  export function dashboardPollDelay() {
436
+ if (!isWorkspaceActive()) return null;
289
437
  return isPageVisible() ? DASHBOARD_POLL_MS : HIDDEN_POLL_MS;
290
438
  }
291
439
 
440
+ /** Stop pausable timers without destroying route/selection/scroll. */
441
+ export function pauseForegroundTimers() {
442
+ if (uiState.dashboardTimer) {
443
+ clearTimeout(uiState.dashboardTimer);
444
+ uiState.dashboardTimer = null;
445
+ }
446
+ if (uiState.runPollTimer) {
447
+ clearTimeout(uiState.runPollTimer);
448
+ uiState.runPollTimer = null;
449
+ }
450
+ if (uiState.dagPollTimer) {
451
+ clearTimeout(uiState.dagPollTimer);
452
+ uiState.dagPollTimer = null;
453
+ }
454
+ if (uiState.poolTimer) {
455
+ clearTimeout(uiState.poolTimer);
456
+ uiState.poolTimer = null;
457
+ }
458
+ if (uiState.taskPollTimer) {
459
+ clearTimeout(uiState.taskPollTimer);
460
+ uiState.taskPollTimer = null;
461
+ }
462
+ }
463
+
292
464
  export function updateDagGraphViewportState(
293
465
  _previous,
294
466
  dagRunId,