@tea-agent/loop-agent 0.13.0 → 0.14.0

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 (270) hide show
  1. package/AGENTS.md +157 -157
  2. package/CHANGELOG.md +73 -301
  3. package/README.md +338 -334
  4. package/bin/agent-worker.js +22 -22
  5. package/bin/loop-agent.js +21 -21
  6. package/dist/commands/cursor-prompt.js +6 -6
  7. package/dist/commands/init.js +505 -505
  8. package/dist/commands/loop-benchmark.js +11 -11
  9. package/dist/commands/pi-reuse-benchmark.js +16 -16
  10. package/dist/executors/pi-event-serializer.js +33 -11
  11. package/dist/sidecars/cursor-prompt/executor.js +1 -1
  12. package/dist/task/runtime.js +27 -27
  13. package/dist/worker/observe/spec-evidence.js +19 -10
  14. package/dist/worker/observe/static/api.js +46 -46
  15. package/dist/worker/observe/static/app.js +151 -150
  16. package/dist/worker/observe/static/constants.js +156 -148
  17. package/dist/worker/observe/static/copy.js +67 -67
  18. package/dist/worker/observe/static/dag-helpers.js +201 -172
  19. package/dist/worker/observe/static/dag-layout.d.ts +31 -31
  20. package/dist/worker/observe/static/dag-layout.js +83 -83
  21. package/dist/worker/observe/static/dag-model.js +72 -72
  22. package/dist/worker/observe/static/dom.js +122 -122
  23. package/dist/worker/observe/static/format-pool.d.ts +71 -0
  24. package/dist/worker/observe/static/format-pool.js +134 -67
  25. package/dist/worker/observe/static/format.js +317 -292
  26. package/dist/worker/observe/static/index.html +350 -308
  27. package/dist/worker/observe/static/kpi.js +100 -94
  28. package/dist/worker/observe/static/markdown-render.js +124 -0
  29. package/dist/worker/observe/static/relations.js +133 -133
  30. package/dist/worker/observe/static/router.js +93 -93
  31. package/dist/worker/observe/static/run-processing.js +148 -148
  32. package/dist/worker/observe/static/shell-chrome.js +74 -68
  33. package/dist/worker/observe/static/state.js +273 -267
  34. package/dist/worker/observe/static/styles.css +2504 -1902
  35. package/dist/worker/observe/static/views/batch.js +227 -227
  36. package/dist/worker/observe/static/views/dag-graph.js +172 -172
  37. package/dist/worker/observe/static/views/dag-inspector.js +530 -627
  38. package/dist/worker/observe/static/views/dag.js +371 -371
  39. package/dist/worker/observe/static/views/dashboard.js +86 -100
  40. package/dist/worker/observe/static/views/failures.js +143 -143
  41. package/dist/worker/observe/static/views/feature.js +492 -492
  42. package/dist/worker/observe/static/views/pool.js +708 -350
  43. package/dist/worker/observe/static/views/run.js +453 -453
  44. package/dist/worker/observe/static/views/session-timeline.js +771 -219
  45. package/dist/worker/observe/static/views/shell.js +7 -7
  46. package/dist/worker/observe/static/views/task.js +314 -314
  47. package/dist/worker/observe/static/views/timeline.js +163 -163
  48. package/dist/workflows/dag/canvas-observer.js +275 -275
  49. package/docs/README.md +105 -104
  50. package/docs/agent-dag-recovery-playbook.md +195 -195
  51. package/docs/agent-dag-runner.md +67 -67
  52. package/docs/architecture/README.md +26 -26
  53. package/docs/architecture/dag-execution.md +140 -140
  54. package/docs/architecture/evolution.md +54 -54
  55. package/docs/architecture/facts-and-state.md +71 -71
  56. package/docs/architecture/runtime-boundaries.md +191 -191
  57. package/docs/architecture/system-overview.md +93 -93
  58. package/docs/architecture/worker-and-feature.md +85 -85
  59. package/docs/cursor-prompt-sidecar.md +36 -36
  60. package/docs/decisions/README.md +18 -18
  61. package/docs/design/README.md +167 -167
  62. package/docs/development-principles.md +73 -73
  63. package/docs/exec-plans/README.md +6 -6
  64. package/docs/exec-plans/active/README.md +2 -1
  65. package/docs/exec-plans/completed/README.md +105 -104
  66. package/docs/feature-workflow.md +414 -414
  67. package/docs/harness-methodology-debugging.md +153 -153
  68. package/docs/harness-methodology-tdd.md +130 -130
  69. package/docs/harness-methodology-verification.md +27 -27
  70. package/docs/init-surface.manifest.json +307 -307
  71. package/docs/loop-agent-harness.md +142 -142
  72. package/docs/production-readiness.md +96 -96
  73. package/docs/progress/README.md +59 -58
  74. package/docs/reports/README.md +123 -119
  75. package/docs/skills/README.md +7 -7
  76. package/docs/skills/vetted-skill-registry.md +29 -29
  77. package/docs/templates/adr.md +60 -60
  78. package/docs/templates/agent-dag-authority-surface-audit.prompt.md +94 -94
  79. package/docs/templates/agent-dag-decision-envelope.schema.json +213 -213
  80. package/docs/templates/agent-dag-decision-gate-dogfood-report.md +117 -117
  81. package/docs/templates/agent-dag-decision-gate.prompt.md +246 -246
  82. package/docs/templates/agent-dag-process-supervisor.prompt.md +98 -98
  83. package/docs/templates/agent-dag-report.schema.json +473 -473
  84. package/docs/templates/agent-dag-review-verdict.prompt.md +68 -68
  85. package/docs/templates/agent-dag.base.json +190 -190
  86. package/docs/templates/agent-dag.final-verification.json +185 -185
  87. package/docs/templates/agent-dag.schema.json +411 -411
  88. package/docs/templates/agent-dag.supervised-implementation.json +620 -620
  89. package/docs/templates/backend-test-analysis.schema.json +44 -44
  90. package/docs/templates/backend-test-case-manifest.schema.json +190 -190
  91. package/docs/templates/backend-test-dag.classify.prompt.md +75 -75
  92. package/docs/templates/backend-test-dag.generate-pytest.prompt.md +204 -204
  93. package/docs/templates/backend-test-dag.json +559 -559
  94. package/docs/templates/backend-test-dag.retrospect.prompt.md +139 -139
  95. package/docs/templates/backend-test-dag.review-cases.prompt.md +83 -83
  96. package/docs/templates/backend-test-execution.schema.json +133 -133
  97. package/docs/templates/backend-test-result.schema.json +99 -99
  98. package/docs/templates/exec-plan.md +64 -64
  99. package/docs/templates/feature-spec.md +53 -53
  100. package/docs/templates/frontend-design-contract.md +42 -42
  101. package/docs/templates/frontend-eval/fixtures/failures/01-type-build-error.md +17 -17
  102. package/docs/templates/frontend-eval/fixtures/failures/02-unit-component-test-fail.md +16 -16
  103. package/docs/templates/frontend-eval/fixtures/failures/03-fixture-schema-drift.md +16 -16
  104. package/docs/templates/frontend-eval/fixtures/failures/04-missing-loading-empty-error-state.md +16 -16
  105. package/docs/templates/frontend-eval/fixtures/failures/05-forbidden-write-writeset-expansion.md +16 -16
  106. package/docs/templates/frontend-eval/fixtures/failures/06-unapproved-dependency-add.md +16 -16
  107. package/docs/templates/frontend-eval/fixtures/failures/07-mock-production-on.md +21 -21
  108. package/docs/templates/frontend-eval/fixtures/functional/01-simple-component-style.md +29 -29
  109. package/docs/templates/frontend-eval/fixtures/functional/02-form-validation.md +28 -28
  110. package/docs/templates/frontend-eval/fixtures/functional/03-list-detail-page.md +28 -28
  111. package/docs/templates/frontend-eval/fixtures/functional/04-api-mock.md +29 -29
  112. package/docs/templates/frontend-eval/fixtures/functional/05-permission-auth-gated-ui.md +27 -27
  113. package/docs/templates/frontend-eval/fixtures/functional/06-ssr-server-client-boundary.md +28 -28
  114. package/docs/templates/frontend-eval/fixtures/functional/07-shared-public-component-api.md +28 -28
  115. package/docs/templates/frontend-eval/fixtures/functional/08-pure-local-no-remote.md +27 -27
  116. package/docs/templates/frontend-eval/metrics.md +138 -138
  117. package/docs/templates/frontend-eval/smoke-targets.md +53 -53
  118. package/docs/templates/frontend-implementation-contract.schema.json +27 -27
  119. package/docs/templates/frontend-task-constraints.md +35 -35
  120. package/docs/templates/frontend-task-requirement.md +70 -70
  121. package/docs/templates/frontend-test-dag.generate-cases.prompt.md +5 -5
  122. package/docs/templates/frontend-test-dag.json +23 -23
  123. package/docs/templates/frontend-test-dag.retrieve-context.prompt.md +3 -3
  124. package/docs/templates/frontend-test-dag.retrospect.prompt.md +3 -3
  125. package/docs/templates/frontend-test-dag.review-cases.prompt.md +3 -3
  126. package/docs/templates/frontend-test-dag.review-execution.prompt.md +3 -3
  127. package/docs/templates/harness.schema.json +221 -221
  128. package/docs/templates/hybrid-dag.json +188 -188
  129. package/docs/templates/init-evolution-review.md +35 -35
  130. package/docs/templates/interactive-ui-round2-experiment.md +66 -66
  131. package/docs/templates/knowledge-graph-bootstrap-dag.json +118 -118
  132. package/docs/templates/knowledge-sync-dag.json +178 -178
  133. package/docs/templates/knowledge-sync-draft.schema.json +71 -71
  134. package/docs/templates/product-line/AGENTS.md +8 -8
  135. package/docs/templates/product-line/README.md +9 -9
  136. package/docs/templates/product-line/acceptance.yaml +14 -14
  137. package/docs/templates/product-line/closeout.yaml +9 -9
  138. package/docs/templates/product-line/design.md +13 -13
  139. package/docs/templates/product-line/links.md +10 -10
  140. package/docs/templates/product-line/requirement.md +17 -17
  141. package/docs/templates/product-line/task-graph.yaml +15 -15
  142. package/docs/templates/product-line/task.yaml +64 -64
  143. package/docs/templates/product-line/test-plan.md +7 -7
  144. package/docs/templates/production-readiness-checklist.md +57 -57
  145. package/docs/templates/progress-log.md +17 -17
  146. package/docs/templates/project-start-checklist.md +9 -9
  147. package/docs/templates/qa-report.md +48 -48
  148. package/docs/templates/sprint-contract.md +29 -29
  149. package/docs/templates/worker-dogfood-evidence.md +80 -80
  150. package/docs/templates/worker-dogfood-setup.md +68 -68
  151. package/docs/verification-matrix.md +70 -70
  152. package/examples/decision-gate-agent-dag.json +173 -173
  153. package/examples/example-dag.json +46 -46
  154. package/examples/hybrid-loop-agent-dag.json +188 -188
  155. package/harness.json +66 -66
  156. package/package.json +88 -52
  157. package/scripts/check-product-line-docs.sh +29 -29
  158. package/scripts/check-task-pool-root.sh +32 -32
  159. package/scripts/kb-bootstrap-init-skeleton.sh +240 -240
  160. package/scripts/kb-graph-incremental-prepare.mjs +386 -386
  161. package/scripts/kb-graph-incremental-prepare.sh +5 -5
  162. package/scripts/kb-graph-materialize.mjs +105 -105
  163. package/scripts/kb-graph-materialize.sh +4 -4
  164. package/scripts/kb-graph-promote.mjs +164 -164
  165. package/scripts/kb-graph-promote.sh +4 -4
  166. package/scripts/kb-query.mjs +554 -554
  167. package/scripts/kb-query.sh +5 -5
  168. package/skills/agent-worker/SKILL.md +39 -39
  169. package/skills/agent-worker/references/agent-worker-operator.md +60 -60
  170. package/skills/ai-engineering-context/SKILL.md +48 -48
  171. package/skills/analyze-product-dependencies/SKILL.md +67 -67
  172. package/skills/analyze-product-dependencies/agents/openai.yaml +4 -4
  173. package/skills/analyze-product-dependencies/references/api-documentation-schema.md +30 -30
  174. package/skills/analyze-product-dependencies/references/dependency-analysis-schema.md +28 -28
  175. package/skills/analyze-product-dependencies/references/example.md +76 -76
  176. package/skills/analyze-product-dependencies/references/forward-test-cases.md +35 -35
  177. package/skills/analyze-product-dependencies/references/input-contract.md +11 -11
  178. package/skills/analyze-product-dependencies/references/scouting-rules.md +61 -61
  179. package/skills/analyze-product-dependencies/scripts/test-validators.mjs +267 -267
  180. package/skills/analyze-product-dependencies/scripts/validate-api-documentation.mjs +101 -101
  181. package/skills/analyze-product-dependencies/scripts/validate-dependency-analysis.mjs +142 -142
  182. package/skills/analyze-product-dependencies/scripts/validate-product-requirement-input.mjs +76 -76
  183. package/skills/analyze-product-dependencies/scripts/validation-helpers.mjs +146 -146
  184. package/skills/analyze-product-requirements/SKILL.md +90 -90
  185. package/skills/analyze-product-requirements/agents/openai.yaml +4 -4
  186. package/skills/analyze-product-requirements/references/acceptance-criteria.md +91 -91
  187. package/skills/analyze-product-requirements/references/clarification-and-knowledge.md +56 -56
  188. package/skills/analyze-product-requirements/references/example.md +86 -86
  189. package/skills/analyze-product-requirements/references/forward-test-cases.md +66 -66
  190. package/skills/analyze-product-requirements/references/product-analysis-schema.md +32 -32
  191. package/skills/analyze-product-requirements/references/product-requirement-schema.md +33 -33
  192. package/skills/analyze-product-requirements/references/requirement-clarification-schema.md +35 -35
  193. package/skills/analyze-product-requirements/scripts/test-validators.mjs +193 -193
  194. package/skills/analyze-product-requirements/scripts/validate-product-analysis.mjs +69 -69
  195. package/skills/analyze-product-requirements/scripts/validate-product-requirement.mjs +97 -97
  196. package/skills/analyze-product-requirements/scripts/validate-requirement-clarification.mjs +98 -98
  197. package/skills/analyze-product-requirements/scripts/validation-helpers.mjs +156 -156
  198. package/skills/browser-tools/SKILL.md +196 -196
  199. package/skills/browser-tools/browser-content.js +103 -103
  200. package/skills/browser-tools/browser-cookies.js +35 -35
  201. package/skills/browser-tools/browser-eval.js +53 -53
  202. package/skills/browser-tools/browser-hn-scraper.js +108 -108
  203. package/skills/browser-tools/browser-nav.js +44 -44
  204. package/skills/browser-tools/browser-pick.js +162 -162
  205. package/skills/browser-tools/browser-screenshot.js +34 -34
  206. package/skills/browser-tools/browser-start.js +86 -86
  207. package/skills/browser-tools/package-lock.json +2556 -2556
  208. package/skills/browser-tools/package.json +19 -19
  209. package/skills/code-review-core/SKILL.md +20 -20
  210. package/skills/codebase-scout/SKILL.md +19 -19
  211. package/skills/frontend-design-review/SKILL.md +66 -66
  212. package/skills/frontend-design-review/references/review-checklist.md +58 -58
  213. package/skills/frontend-implementation/SKILL.md +49 -49
  214. package/skills/frontend-implementation/references/code-standards.md +32 -32
  215. package/skills/frontend-implementation/references/design-spec.md +46 -46
  216. package/skills/frontend-implementation/references/node-contracts.md +27 -27
  217. package/skills/frontend-review/SKILL.md +59 -59
  218. package/skills/frontend-review/references/review-findings.md +47 -47
  219. package/skills/frontend-verification/SKILL.md +53 -53
  220. package/skills/frontend-verification/references/verification-checklist.md +68 -68
  221. package/skills/grill-me/SKILL.md +10 -10
  222. package/skills/grill-with-docs/SKILL.md +88 -88
  223. package/skills/grill-with-docs/adr-format.md +47 -47
  224. package/skills/grill-with-docs/context-format.md +60 -60
  225. package/skills/init-capability-evolution/SKILL.md +70 -70
  226. package/skills/loop-agent/SKILL.md +151 -151
  227. package/skills/loop-agent/references/README.md +67 -67
  228. package/skills/loop-agent/references/command-reference.md +527 -527
  229. package/skills/loop-agent/references/docs-converge.md +126 -126
  230. package/skills/loop-agent/references/harness-policy.md +263 -263
  231. package/skills/loop-agent/references/hybrid-dag.md +243 -243
  232. package/skills/loop-agent/references/learned/README.md +21 -21
  233. package/skills/loop-agent/references/long-running-loop.md +57 -57
  234. package/skills/loop-agent/references/model-routing.md +36 -36
  235. package/skills/loop-agent/references/multi-worktree.md +54 -54
  236. package/skills/loop-agent/references/one-shot-runs.md +85 -85
  237. package/skills/loop-agent/references/orchestrator-and-interventions.md +169 -169
  238. package/skills/loop-agent/references/pi-prompt.md +23 -23
  239. package/skills/loop-agent/references/pi-subagent-assisted-mode.md +84 -84
  240. package/skills/loop-agent/references/post-implementation-and-patterns.md +44 -44
  241. package/skills/loop-agent/references/task-workflow.md +89 -89
  242. package/skills/loop-agent/references/verification-and-failure-handling.md +141 -141
  243. package/skills/playwright-cli/SKILL.md +420 -420
  244. package/skills/playwright-cli/references/element-attributes.md +23 -23
  245. package/skills/playwright-cli/references/playwright-tests.md +39 -39
  246. package/skills/playwright-cli/references/request-mocking.md +87 -87
  247. package/skills/playwright-cli/references/running-code.md +241 -241
  248. package/skills/playwright-cli/references/session-management.md +225 -225
  249. package/skills/playwright-cli/references/storage-state.md +275 -275
  250. package/skills/playwright-cli/references/test-generation.md +433 -433
  251. package/skills/playwright-cli/references/tracing.md +139 -139
  252. package/skills/playwright-cli/references/video-recording.md +143 -143
  253. package/skills/playwright-cli-case-generator/SKILL.md +74 -74
  254. package/skills/requesting-code-review/SKILL.md +101 -101
  255. package/skills/requesting-code-review/code-reviewer.md +168 -168
  256. package/skills/systematic-debugging/CREATION-LOG.md +119 -119
  257. package/skills/systematic-debugging/SKILL.md +296 -296
  258. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -158
  259. package/skills/systematic-debugging/condition-based-waiting.md +115 -115
  260. package/skills/systematic-debugging/defense-in-depth.md +122 -122
  261. package/skills/systematic-debugging/find-polluter.sh +63 -63
  262. package/skills/systematic-debugging/root-cause-tracing.md +169 -169
  263. package/skills/systematic-debugging/test-academic.md +14 -14
  264. package/skills/systematic-debugging/test-pressure-1.md +58 -58
  265. package/skills/systematic-debugging/test-pressure-2.md +68 -68
  266. package/skills/systematic-debugging/test-pressure-3.md +69 -69
  267. package/skills/test-driven-development/SKILL.md +20 -20
  268. package/skills/using-git-worktrees/SKILL.md +215 -215
  269. package/skills/verification-before-completion/SKILL.md +154 -154
  270. package/skills/webapp-testing/SKILL.md +19 -19
@@ -1,627 +1,530 @@
1
- /** DAG node inspector panel (Observe UI R5). */
2
- import {
3
- DAG_INSPECTOR_DEFAULT_WIDTH,
4
- DAG_INSPECTOR_MIN_WIDTH,
5
- DAG_INSPECTOR_MAX_WIDTH,
6
- DAG_INSPECTOR_RIGHT_OFFSET,
7
- DAG_INSPECTOR_VIEWPORT_MARGIN,
8
- DAG_INSPECTOR_KEYBOARD_STEP,
9
- UI_TEXT,
10
- } from "../constants.js";
11
- import { clearNode, el } from "../dom.js";
12
- import { fetchJson } from "../api.js";
13
- import { badge, parseMarkdownBlocks, markdownLinkHref } from "../format.js";
14
- import {
15
- uiState,
16
- makeSessionEventIdentity,
17
- updateDagTimelineViewportState,
18
- updateDagOutputViewportState,
19
- computeFollowLatest,
20
- isInteractiveGestureActive,
21
- } from "../state.js";
22
- import {
23
- formatSessionEventTime,
24
- renderSessionTimeline,
25
- } from "./session-timeline.js";
26
-
27
- // Current inspector selection. Tab handlers reference this mutable slot so a
28
- // reused inspector shell never keeps stale node closures: every render writes
29
- // the latest {dagRunId, node} here and tab clicks re-render from the same
30
- // reference, always resolving the currently selected node identity.
31
- const inspectorSelection = { dagRunId: null, node: null };
32
-
33
- function renderDagInspectorForCurrent() {
34
- if (!inspectorSelection.dagRunId || !inspectorSelection.node) return;
35
- renderDagInspector(inspectorSelection.dagRunId, inspectorSelection.node, false);
36
- }
37
-
38
- export function selectDagNode(dagRunId, nodeId) {
39
- const nodeChanged = uiState.selectedDagNodeId !== nodeId;
40
- uiState.selectedDagNodeId = nodeId;
41
- uiState.dagInspectorOpen = true;
42
- if (nodeChanged) {
43
- uiState.sessionEventOffset = 0;
44
- uiState.sessionEvents = [];
45
- // Bump the session-event identity token so any in-flight response for the
46
- // previous node is rejected before it can mutate the current node cache.
47
- uiState.sessionEventIdentity = makeSessionEventIdentity(dagRunId, nodeId);
48
- }
49
- void import("./dag.js").then((m) => m.renderDagDetail(dagRunId, false));
50
- }
51
-
52
- export function closeDagInspector() {
53
- uiState.dagInspectorOpen = false;
54
- const panel = document.getElementById("dag-inspector");
55
- if (panel) {
56
- panel.classList.remove("is-open");
57
- panel.setAttribute("aria-hidden", "true");
58
- }
59
- }
60
-
61
- export function closeDagInspectorOnOutsideClick(event) {
62
- if (!uiState.dagInspectorOpen || !(event.target instanceof Element)) return;
63
- if (
64
- event.target.closest(
65
- "#dag-inspector, .dag-node-table tbody tr, button, a, input, select, textarea, [role='button'], [role='tab']",
66
- )
67
- ) {
68
- return;
69
- }
70
- closeDagInspector();
71
- }
72
-
73
- export function dagInspectorMaximumWidth() {
74
- return Math.max(
75
- DAG_INSPECTOR_MIN_WIDTH,
76
- Math.min(
77
- DAG_INSPECTOR_MAX_WIDTH,
78
- window.innerWidth - DAG_INSPECTOR_VIEWPORT_MARGIN,
79
- ),
80
- );
81
- }
82
-
83
- export function setDagInspectorWidth(panel, requestedWidth) {
84
- const maximum = dagInspectorMaximumWidth();
85
- uiState.dagInspectorWidth = Math.min(
86
- maximum,
87
- Math.max(DAG_INSPECTOR_MIN_WIDTH, Math.round(requestedWidth)),
88
- );
89
- panel.style.setProperty(
90
- "--dag-inspector-width",
91
- `${uiState.dagInspectorWidth}px`,
92
- );
93
- return {
94
- minimum: DAG_INSPECTOR_MIN_WIDTH,
95
- maximum,
96
- value: uiState.dagInspectorWidth,
97
- };
98
- }
99
-
100
- export function createDagInspectorResizeHandle(panel) {
101
- const handle = el("div", "dag-inspector-resize-handle");
102
- handle.tabIndex = 0;
103
- handle.setAttribute("role", "separator");
104
- handle.setAttribute("aria-orientation", "vertical");
105
- handle.setAttribute("aria-label", "调整节点检查器宽度");
106
- handle.title = "拖动调整节点检查器宽度";
107
-
108
- const updateRange = (requestedWidth) => {
109
- const range = setDagInspectorWidth(
110
- panel,
111
- requestedWidth ??
112
- uiState.dagInspectorWidth ??
113
- DAG_INSPECTOR_DEFAULT_WIDTH,
114
- );
115
- handle.setAttribute("aria-valuemin", String(range.minimum));
116
- handle.setAttribute("aria-valuemax", String(range.maximum));
117
- handle.setAttribute("aria-valuenow", String(range.value));
118
- };
119
-
120
- updateRange();
121
- handle.addEventListener("pointerdown", (event) => {
122
- if (event.button !== 0) return;
123
- event.preventDefault();
124
- handle.setPointerCapture(event.pointerId);
125
- document.body.classList.add("is-resizing-dag-inspector");
126
- });
127
- handle.addEventListener("pointermove", (event) => {
128
- if (!handle.hasPointerCapture(event.pointerId)) return;
129
- updateRange(window.innerWidth - event.clientX - DAG_INSPECTOR_RIGHT_OFFSET);
130
- });
131
- const stopResizing = (event) => {
132
- if (handle.hasPointerCapture(event.pointerId)) {
133
- handle.releasePointerCapture(event.pointerId);
134
- }
135
- document.body.classList.remove("is-resizing-dag-inspector");
136
- };
137
- handle.addEventListener("pointerup", stopResizing);
138
- handle.addEventListener("pointercancel", stopResizing);
139
- handle.addEventListener("keydown", (event) => {
140
- const currentWidth =
141
- uiState.dagInspectorWidth ?? DAG_INSPECTOR_DEFAULT_WIDTH;
142
- if (event.key === "ArrowLeft") {
143
- event.preventDefault();
144
- updateRange(currentWidth + DAG_INSPECTOR_KEYBOARD_STEP);
145
- } else if (event.key === "ArrowRight") {
146
- event.preventDefault();
147
- updateRange(currentWidth - DAG_INSPECTOR_KEYBOARD_STEP);
148
- } else if (event.key === "Home") {
149
- event.preventDefault();
150
- updateRange(DAG_INSPECTOR_MIN_WIDTH);
151
- } else if (event.key === "End") {
152
- event.preventDefault();
153
- updateRange(dagInspectorMaximumWidth());
154
- }
155
- });
156
- return handle;
157
- }
158
-
159
- export function captureDagTimelineViewportState(panel) {
160
- const scrollEl = panel.querySelector(".process-timeline-scroll");
161
- if (scrollEl?.dataset.dagRunId && scrollEl.dataset.nodeId) {
162
- const followLatest = computeFollowLatest(
163
- scrollEl.scrollTop,
164
- scrollEl.scrollHeight,
165
- scrollEl.clientHeight,
166
- );
167
- uiState.dagTimelineViewportState = updateDagTimelineViewportState(
168
- uiState.dagTimelineViewportState,
169
- scrollEl.dataset.dagRunId,
170
- scrollEl.dataset.nodeId,
171
- scrollEl.scrollLeft,
172
- scrollEl.scrollTop,
173
- followLatest,
174
- );
175
- }
176
- }
177
-
178
- export function appendInlineMarkdown(target, text) {
179
- const tokenPattern = /(`[^`]*`|\*\*[^*]+\*\*|\*[^*]+\*|\[[^\]]+\]\([^)]+\))/g;
180
- let cursor = 0;
181
- for (const match of text.matchAll(tokenPattern)) {
182
- const index = match.index ?? 0;
183
- if (index > cursor)
184
- target.appendChild(document.createTextNode(text.slice(cursor, index)));
185
- const token = match[0];
186
- if (token.startsWith("`")) {
187
- target.appendChild(el("code", null, token.slice(1, -1)));
188
- } else if (token.startsWith("**")) {
189
- const strong = document.createElement("strong");
190
- strong.textContent = token.slice(2, -2);
191
- target.appendChild(strong);
192
- } else if (token.startsWith("*")) {
193
- const emphasis = document.createElement("em");
194
- emphasis.textContent = token.slice(1, -1);
195
- target.appendChild(emphasis);
196
- } else {
197
- const link = token.match(/^\[([^\]]+)\]\((.+)\)$/);
198
- const href = markdownLinkHref(link?.[2]);
199
- if (link && href) {
200
- const anchor = document.createElement("a");
201
- anchor.href = href;
202
- anchor.target = "_blank";
203
- anchor.rel = "noopener noreferrer";
204
- anchor.textContent = link[1];
205
- target.appendChild(anchor);
206
- } else {
207
- target.appendChild(document.createTextNode(token));
208
- }
209
- }
210
- cursor = index + token.length;
211
- }
212
- if (cursor < text.length)
213
- target.appendChild(document.createTextNode(text.slice(cursor)));
214
- }
215
-
216
- export function renderMarkdown(content) {
217
- const article = el("article", "markdown-output");
218
- for (const block of parseMarkdownBlocks(content)) {
219
- switch (block.type) {
220
- case "heading": {
221
- const heading = document.createElement(`h${block.level}`);
222
- appendInlineMarkdown(heading, block.text);
223
- article.appendChild(heading);
224
- break;
225
- }
226
- case "paragraph": {
227
- const paragraph = document.createElement("p");
228
- appendInlineMarkdown(paragraph, block.text);
229
- article.appendChild(paragraph);
230
- break;
231
- }
232
- case "quote": {
233
- const quote = document.createElement("blockquote");
234
- appendInlineMarkdown(quote, block.text);
235
- article.appendChild(quote);
236
- break;
237
- }
238
- case "list": {
239
- const list = document.createElement(block.ordered ? "ol" : "ul");
240
- for (const item of block.items) {
241
- const listItem = document.createElement("li");
242
- appendInlineMarkdown(listItem, item);
243
- list.appendChild(listItem);
244
- }
245
- article.appendChild(list);
246
- break;
247
- }
248
- case "code": {
249
- const pre = document.createElement("pre");
250
- const code = document.createElement("code");
251
- if (block.language) code.dataset.language = block.language;
252
- code.textContent = block.text;
253
- pre.appendChild(code);
254
- article.appendChild(pre);
255
- break;
256
- }
257
- case "table": {
258
- const table = document.createElement("table");
259
- const head = document.createElement("thead");
260
- const headRow = document.createElement("tr");
261
- for (const value of block.headers) {
262
- const cell = document.createElement("th");
263
- appendInlineMarkdown(cell, value);
264
- headRow.appendChild(cell);
265
- }
266
- head.appendChild(headRow);
267
- table.appendChild(head);
268
- const body = document.createElement("tbody");
269
- for (const row of block.rows) {
270
- const tableRow = document.createElement("tr");
271
- for (const value of row) {
272
- const cell = document.createElement("td");
273
- appendInlineMarkdown(cell, value);
274
- tableRow.appendChild(cell);
275
- }
276
- body.appendChild(tableRow);
277
- }
278
- table.appendChild(body);
279
- article.appendChild(table);
280
- break;
281
- }
282
- case "rule":
283
- article.appendChild(document.createElement("hr"));
284
- break;
285
- }
286
- }
287
- return article;
288
- }
289
-
290
- async function renderSpecEvidence(content, dagRunId, nodeId) {
291
- const evidence = await fetchJson(
292
- `/api/dag-runs/${encodeURIComponent(dagRunId)}/nodes/${encodeURIComponent(nodeId)}/spec-evidence`,
293
- );
294
- if (!content.isConnected || content.dataset.dagNodeId !== String(nodeId)) return;
295
- if (!evidence) {
296
- content.appendChild(el("p", "empty", "无法加载规范证据。"));
297
- return;
298
- }
299
-
300
- const statusLabels = {
301
- "spec-read": "已读取规范",
302
- "source-bound": "已绑定任务源",
303
- "spec-injected": "仅注入 skill",
304
- "search-only": "仅执行检索",
305
- "kb-queried": "已观察知识库查询",
306
- "no-evidence": "未观察到读取",
307
- };
308
- const statusSection = el("div", "spec-evidence-section");
309
- statusSection.appendChild(el("h4", null, "证据状态"));
310
- statusSection.appendChild(
311
- el(
312
- "span",
313
- `badge badge-${evidence.status === "spec-read" ? "succeeded" : evidence.status === "no-evidence" ? "failed" : "pending"}`,
314
- statusLabels[evidence.status] ?? evidence.status,
315
- ),
316
- );
317
- if (evidence.summary) {
318
- statusSection.appendChild(
319
- el("p", "spec-evidence-summary", evidence.summary),
320
- );
321
- }
322
- content.appendChild(statusSection);
323
-
324
- const appendListSection = (title, entries, renderEntry) => {
325
- if (!entries?.length) return;
326
- const section = el("div", "spec-evidence-section");
327
- section.appendChild(el("h4", null, title));
328
- const list = el("ul", "spec-evidence-list");
329
- for (const entry of entries) list.appendChild(renderEntry(entry));
330
- section.appendChild(list);
331
- content.appendChild(section);
332
- };
333
-
334
- appendListSection("注入的 Skill", evidence.skillInjection?.skills, (skill) => {
335
- const item = el("li", null);
336
- const icon = el("i", "ri-bookmark-line");
337
- icon.setAttribute("aria-hidden", "true");
338
- item.append(icon, document.createTextNode(` ${skill}`));
339
- return item;
340
- });
341
- appendListSection("已绑定任务源", evidence.sourceBinding?.sources, (source) => {
342
- const item = el("li", null);
343
- const icon = el("i", "ri-links-line");
344
- icon.setAttribute("aria-hidden", "true");
345
- item.append(icon, document.createTextNode(` ${source.kind}: `), el("code", null, source.path), document.createTextNode(` · sha256 ${source.sha256.slice(0, 12)}…`));
346
- return item;
347
- });
348
- appendListSection("显式需求编号", evidence.sourceBinding?.requirementIds, (id) => el("li", null, id));
349
- appendListSection(
350
- `已读取规范文件(${evidence.specReads?.length ?? 0})`,
351
- evidence.specReads,
352
- (read) => {
353
- const item = el("li", null);
354
- const icon = el("i", "ri-file-text-line");
355
- icon.setAttribute("aria-hidden", "true");
356
- item.append(icon, el("code", null, read.path));
357
- if (read.timestamp) {
358
- item.appendChild(
359
- el(
360
- "span",
361
- "spec-evidence-time",
362
- formatSessionEventTime({ timestamp: read.timestamp }),
363
- ),
364
- );
365
- }
366
- return item;
367
- },
368
- );
369
- appendListSection(
370
- `检索操作(${evidence.specSearches?.length ?? 0})`,
371
- evidence.specSearches,
372
- (search) => {
373
- const item = el("li", null);
374
- const icon = el("i", "ri-search-line");
375
- icon.setAttribute("aria-hidden", "true");
376
- item.append(icon, document.createTextNode(` ${search.tool}: ${search.query}`));
377
- return item;
378
- },
379
- );
380
- appendListSection(
381
- `知识库查询(${evidence.knowledgeBaseQueries?.length ?? 0})`,
382
- evidence.knowledgeBaseQueries,
383
- (query) => {
384
- const item = el("li", null);
385
- const icon = el("i", "ri-database-2-line");
386
- icon.setAttribute("aria-hidden", "true");
387
- item.append(icon, document.createTextNode(` ${query.connector}`));
388
- return item;
389
- },
390
- );
391
-
392
- if (evidence.status === "source-bound" || evidence.status === "spec-injected" || evidence.status === "no-evidence") {
393
- const warning = el("div", "spec-evidence-warning");
394
- const icon = el("i", "ri-alert-line");
395
- icon.setAttribute("aria-hidden", "true");
396
- warning.append(
397
- icon,
398
- document.createTextNode(
399
- evidence.status === "source-bound"
400
- ? "DAG 已绑定权威任务源及内容哈希,但尚未观察到成功的 read 工具调用;绑定证明上下文来源,read 事件才证明节点读取了完整文件。"
401
- : evidence.status === "no-evidence"
402
- ? "未观察到规范读取。只有 session event 中成功配对的 read 工具调用才算已读取,模型总结或文件名命中不能作为证明。"
403
- : "规范 skill 已注入,但未观察到规范读取或知识库查询;grep/find/ls 只能证明检索,不能替代 read。",
404
- ),
405
- );
406
- content.appendChild(warning);
407
- }
408
- }
409
-
410
- function fillDagInspectorContent(content, dagRunId, node) {
411
- const activeTab = ["timeline", "spec-evidence"].includes(
412
- uiState.dagInspectorTab,
413
- )
414
- ? uiState.dagInspectorTab
415
- : "output";
416
- content.id = `dag-inspector-panel-${activeTab}`;
417
- content.setAttribute("role", "tabpanel");
418
- content.setAttribute("aria-labelledby", `dag-inspector-tab-${activeTab}`);
419
- content.dataset.dagNodeId = String(node.nodeId ?? "");
420
- if (activeTab === "spec-evidence") {
421
- void renderSpecEvidence(content, dagRunId, node.nodeId);
422
- } else if (activeTab === "timeline") {
423
- renderSessionTimeline(content, node.nodeId);
424
- } else if (!node.outputPreview && !node.errorPreview) {
425
- content.appendChild(el("p", "empty", UI_TEXT.noOutput));
426
- } else {
427
- if (node.outputPreview)
428
- content.appendChild(renderMarkdown(node.outputPreview));
429
- if (node.errorPreview) {
430
- const error = el("section", "markdown-error");
431
- error.appendChild(el("p", "markdown-error-title", "错误输出"));
432
- error.appendChild(renderMarkdown(node.errorPreview));
433
- content.appendChild(error);
434
- }
435
- }
436
- }
437
-
438
- function buildDagInspectorHeader(dagRunId, node) {
439
- const header = el("div", "dag-inspector-header");
440
- header.dataset.dagRunId = String(dagRunId ?? "");
441
- header.dataset.dagNodeId = String(node.nodeId ?? "");
442
- const title = el("div", "dag-inspector-title");
443
- title.appendChild(el("h3", null, "节点检查器"));
444
- title.appendChild(el("div", "dag-inspector-node", node.nodeId));
445
- header.appendChild(title);
446
- const controls = el("div", "dag-inspector-controls");
447
- const status = badge(node.status ?? "unknown");
448
- status.classList.add("dag-inspector-status");
449
- controls.appendChild(status);
450
- const close = document.createElement("button");
451
- close.type = "button";
452
- close.className = "dag-inspector-close";
453
- close.setAttribute("aria-label", "关闭节点检查器");
454
- const closeIcon = el("i", "ri-close-line");
455
- closeIcon.setAttribute("aria-hidden", "true");
456
- close.appendChild(closeIcon);
457
- close.addEventListener("click", closeDagInspector);
458
- controls.appendChild(close);
459
- header.appendChild(controls);
460
-
461
- const tabDefs = [
462
- ["output", "节点输出", "ri-file-text-line"],
463
- ["timeline", "执行过程", "ri-route-line"],
464
- ["spec-evidence", "规范证据", "ri-book-open-line"],
465
- ];
466
- const tabs = el("div", "dag-inspector-tabs");
467
- tabs.setAttribute("role", "tablist");
468
- tabs.setAttribute("aria-label", "节点检查器面板");
469
- for (const [tab, label, icon] of tabDefs) {
470
- const selected = uiState.dagInspectorTab === tab;
471
- const button = document.createElement("button");
472
- button.type = "button";
473
- button.id = `dag-inspector-tab-${tab}`;
474
- button.className = "dag-inspector-tab";
475
- button.setAttribute("role", "tab");
476
- button.setAttribute("aria-controls", `dag-inspector-panel-${tab}`);
477
- button.setAttribute("aria-selected", String(selected));
478
- button.tabIndex = selected ? 0 : -1;
479
- button.dataset.tab = tab;
480
- const tabIcon = el("i", icon);
481
- tabIcon.setAttribute("aria-hidden", "true");
482
- button.appendChild(tabIcon);
483
- button.appendChild(document.createTextNode(` ${label}`));
484
- button.addEventListener("click", () => {
485
- uiState.dagInspectorTab = tab;
486
- renderDagInspectorForCurrent();
487
- const next = document.getElementById(`dag-inspector-tab-${tab}`);
488
- next?.focus();
489
- });
490
- button.addEventListener("keydown", (event) => {
491
- if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
492
- event.preventDefault();
493
- event.stopPropagation();
494
- const order = tabDefs.map(([id]) => id);
495
- const idx = order.indexOf(tab);
496
- if (idx < 0) return;
497
- const delta = event.key === "ArrowRight" ? 1 : -1;
498
- const nextTab = order[(idx + delta + order.length) % order.length];
499
- uiState.dagInspectorTab = nextTab;
500
- renderDagInspectorForCurrent();
501
- document.getElementById(`dag-inspector-tab-${nextTab}`)?.focus();
502
- });
503
- tabs.appendChild(button);
504
- }
505
- header.appendChild(tabs);
506
- return header;
507
- }
508
-
509
- function syncDagInspectorHeader(panel, dagRunId, node) {
510
- const header = panel.querySelector(".dag-inspector-header");
511
- if (!header) return;
512
- header.dataset.dagRunId = String(dagRunId ?? "");
513
- header.dataset.dagNodeId = String(node.nodeId ?? "");
514
- const nodeLabel = header.querySelector(".dag-inspector-node");
515
- if (nodeLabel) nodeLabel.textContent = node.nodeId;
516
- const status = header.querySelector(".dag-inspector-status");
517
- if (status) {
518
- const next = badge(node.status ?? "unknown");
519
- next.classList.add("dag-inspector-status");
520
- status.replaceWith(next);
521
- }
522
- for (const button of header.querySelectorAll(".dag-inspector-tab")) {
523
- const selected = button.dataset.tab === uiState.dagInspectorTab;
524
- button.setAttribute("aria-selected", String(selected));
525
- button.tabIndex = selected ? 0 : -1;
526
- }
527
- }
528
-
529
- function dagInspectorSignature(dagRunId, node) {
530
- return JSON.stringify([
531
- dagRunId,
532
- node.nodeId,
533
- uiState.dagInspectorTab,
534
- node.outputPreview ?? "",
535
- node.errorPreview ?? "",
536
- uiState.dagInspectorTab === "timeline" ? uiState.sessionEventOffset : null,
537
- ]);
538
- }
539
-
540
- export function renderDagInspector(dagRunId, node, initial = true) {
541
- // Record the current selection before any early-return so tab handlers
542
- // (which reference the mutable inspectorSelection slot) always re-render
543
- // the currently selected node, never a stale build-time closure.
544
- inspectorSelection.dagRunId = dagRunId;
545
- inspectorSelection.node = node;
546
- const panel = document.getElementById("dag-inspector");
547
- if (!panel) return;
548
- captureDagTimelineViewportState(panel);
549
- if (!uiState.dagInspectorOpen || !node) {
550
- panel.classList.remove("is-open");
551
- panel.setAttribute("aria-hidden", "true");
552
- return;
553
- }
554
-
555
- // Defer tearing down the inspector shell while the user is actively
556
- // dragging the resize handle (or the graph) so the pointer-capture target
557
- // is not destroyed mid-gesture; the next poll refreshes the content.
558
- if (isInteractiveGestureActive(document.body.classList)) {
559
- return;
560
- }
561
-
562
- const existingContent = panel.querySelector(".dag-inspector-content") ?? null;
563
- const reuseShell = !initial && Boolean(existingContent);
564
- const nextContentSignature = dagInspectorSignature(dagRunId, node);
565
-
566
- if (reuseShell && existingContent) {
567
- panel.classList.add("is-open");
568
- panel.setAttribute("aria-hidden", "false");
569
- syncDagInspectorHeader(panel, dagRunId, node);
570
- if (panel.dataset.contentSignature === nextContentSignature) return;
571
- const previousNode = existingContent.dataset.dagNodeId ?? "";
572
- const nodeChanged = previousNode !== String(node.nodeId ?? "");
573
- const followLatest =
574
- nodeChanged ||
575
- computeFollowLatest(
576
- existingContent.scrollTop,
577
- existingContent.scrollHeight,
578
- existingContent.clientHeight,
579
- );
580
- const regionKey = `dag:${dagRunId}:${node.nodeId}:output`;
581
- uiState.dagNodeOutputViewportState = updateDagOutputViewportState(
582
- uiState.dagNodeOutputViewportState,
583
- regionKey,
584
- existingContent.scrollLeft,
585
- existingContent.scrollTop,
586
- followLatest,
587
- );
588
- const nestedViewportState = [
589
- ...existingContent.querySelectorAll("pre"),
590
- ].map((pre) => ({
591
- scrollLeft: pre.scrollLeft,
592
- scrollTop: pre.scrollTop,
593
- }));
594
- clearNode(existingContent);
595
- fillDagInspectorContent(existingContent, dagRunId, node);
596
- if (followLatest) {
597
- existingContent.scrollTop = existingContent.scrollHeight;
598
- } else {
599
- existingContent.scrollTop = uiState.dagNodeOutputViewportState.scrollTop;
600
- }
601
- for (const [index, pre] of [
602
- ...existingContent.querySelectorAll("pre"),
603
- ].entries()) {
604
- const previous = nestedViewportState[index];
605
- if (!previous) continue;
606
- pre.scrollLeft = previous.scrollLeft;
607
- pre.scrollTop = previous.scrollTop;
608
- }
609
- panel.dataset.contentSignature = nextContentSignature;
610
- return;
611
- }
612
-
613
- clearNode(panel);
614
- panel.classList.add("is-open");
615
- panel.setAttribute("aria-hidden", "false");
616
- panel.appendChild(createDagInspectorResizeHandle(panel));
617
- panel.appendChild(buildDagInspectorHeader(dagRunId, node));
618
-
619
- const content = el("div", "dag-inspector-content");
620
- fillDagInspectorContent(content, dagRunId, node);
621
- panel.appendChild(content);
622
- panel.dataset.contentSignature = nextContentSignature;
623
- }
624
-
625
- /**
626
- * Bounded event history UI. Uses opaque `cursor`/`nextCursor` (not SSE/run `after` offsets).
627
- */
1
+ /** DAG node inspector panel (Observe UI R5). */
2
+ import {
3
+ DAG_INSPECTOR_DEFAULT_WIDTH,
4
+ DAG_INSPECTOR_DEFAULT_WIDTH_RATIO,
5
+ DAG_INSPECTOR_MIN_WIDTH,
6
+ DAG_INSPECTOR_MAX_WIDTH,
7
+ DAG_INSPECTOR_RIGHT_OFFSET,
8
+ DAG_INSPECTOR_VIEWPORT_MARGIN,
9
+ DAG_INSPECTOR_KEYBOARD_STEP,
10
+ UI_TEXT,
11
+ } from "../constants.js";
12
+ import { clearNode, el } from "../dom.js";
13
+ import { fetchJson } from "../api.js";
14
+ import { badge } from "../format.js";
15
+ import { renderMarkdown } from "../markdown-render.js";
16
+ import {
17
+ uiState,
18
+ makeSessionEventIdentity,
19
+ updateDagTimelineViewportState,
20
+ updateDagOutputViewportState,
21
+ computeFollowLatest,
22
+ isInteractiveGestureActive,
23
+ } from "../state.js";
24
+ import {
25
+ formatSessionEventTime,
26
+ renderSessionTimeline,
27
+ } from "./session-timeline.js";
28
+
29
+ // Current inspector selection. Tab handlers reference this mutable slot so a
30
+ // reused inspector shell never keeps stale node closures: every render writes
31
+ // the latest {dagRunId, node} here and tab clicks re-render from the same
32
+ // reference, always resolving the currently selected node identity.
33
+ const inspectorSelection = { dagRunId: null, node: null };
34
+
35
+ function renderDagInspectorForCurrent() {
36
+ if (!inspectorSelection.dagRunId || !inspectorSelection.node) return;
37
+ renderDagInspector(inspectorSelection.dagRunId, inspectorSelection.node, false);
38
+ }
39
+
40
+ export function selectDagNode(dagRunId, nodeId) {
41
+ const nodeChanged = uiState.selectedDagNodeId !== nodeId;
42
+ uiState.selectedDagNodeId = nodeId;
43
+ uiState.dagInspectorOpen = true;
44
+ if (nodeChanged) {
45
+ uiState.sessionEventOffset = 0;
46
+ uiState.sessionEvents = [];
47
+ // Bump the session-event identity token so any in-flight response for the
48
+ // previous node is rejected before it can mutate the current node cache.
49
+ uiState.sessionEventIdentity = makeSessionEventIdentity(dagRunId, nodeId);
50
+ }
51
+ void import("./dag.js").then((m) => m.renderDagDetail(dagRunId, false));
52
+ }
53
+
54
+ export function closeDagInspector() {
55
+ uiState.dagInspectorOpen = false;
56
+ const panel = document.getElementById("dag-inspector");
57
+ if (panel) {
58
+ panel.classList.remove("is-open");
59
+ panel.setAttribute("aria-hidden", "true");
60
+ }
61
+ }
62
+
63
+ export function closeDagInspectorOnOutsideClick(event) {
64
+ if (!uiState.dagInspectorOpen || !(event.target instanceof Element)) return;
65
+ if (
66
+ event.target.closest(
67
+ "#dag-inspector, .dag-node-table tbody tr, button, a, input, select, textarea, [role='button'], [role='tab']",
68
+ )
69
+ ) {
70
+ return;
71
+ }
72
+ closeDagInspector();
73
+ }
74
+
75
+ export function dagInspectorMaximumWidth() {
76
+ return Math.max(
77
+ DAG_INSPECTOR_MIN_WIDTH,
78
+ Math.min(
79
+ DAG_INSPECTOR_MAX_WIDTH,
80
+ window.innerWidth - DAG_INSPECTOR_VIEWPORT_MARGIN,
81
+ ),
82
+ );
83
+ }
84
+
85
+ /** Default open width: half the viewport, clamped to min/max. */
86
+ export function dagInspectorDefaultWidth() {
87
+ const half = Math.round(
88
+ window.innerWidth * DAG_INSPECTOR_DEFAULT_WIDTH_RATIO,
89
+ );
90
+ return Math.min(
91
+ dagInspectorMaximumWidth(),
92
+ Math.max(DAG_INSPECTOR_MIN_WIDTH, half || DAG_INSPECTOR_DEFAULT_WIDTH),
93
+ );
94
+ }
95
+
96
+ export function setDagInspectorWidth(panel, requestedWidth) {
97
+ const maximum = dagInspectorMaximumWidth();
98
+ uiState.dagInspectorWidth = Math.min(
99
+ maximum,
100
+ Math.max(DAG_INSPECTOR_MIN_WIDTH, Math.round(requestedWidth)),
101
+ );
102
+ panel.style.setProperty(
103
+ "--dag-inspector-width",
104
+ `${uiState.dagInspectorWidth}px`,
105
+ );
106
+ return {
107
+ minimum: DAG_INSPECTOR_MIN_WIDTH,
108
+ maximum,
109
+ value: uiState.dagInspectorWidth,
110
+ };
111
+ }
112
+
113
+ export function createDagInspectorResizeHandle(panel) {
114
+ const handle = el("div", "dag-inspector-resize-handle");
115
+ handle.tabIndex = 0;
116
+ handle.setAttribute("role", "separator");
117
+ handle.setAttribute("aria-orientation", "vertical");
118
+ handle.setAttribute("aria-label", "调整节点检查器宽度");
119
+ handle.title = "拖动调整节点检查器宽度";
120
+
121
+ const updateRange = (requestedWidth) => {
122
+ const range = setDagInspectorWidth(
123
+ panel,
124
+ requestedWidth ??
125
+ uiState.dagInspectorWidth ??
126
+ dagInspectorDefaultWidth(),
127
+ );
128
+ handle.setAttribute("aria-valuemin", String(range.minimum));
129
+ handle.setAttribute("aria-valuemax", String(range.maximum));
130
+ handle.setAttribute("aria-valuenow", String(range.value));
131
+ };
132
+
133
+ updateRange();
134
+ handle.addEventListener("pointerdown", (event) => {
135
+ if (event.button !== 0) return;
136
+ event.preventDefault();
137
+ handle.setPointerCapture(event.pointerId);
138
+ document.body.classList.add("is-resizing-dag-inspector");
139
+ });
140
+ handle.addEventListener("pointermove", (event) => {
141
+ if (!handle.hasPointerCapture(event.pointerId)) return;
142
+ updateRange(window.innerWidth - event.clientX - DAG_INSPECTOR_RIGHT_OFFSET);
143
+ });
144
+ const stopResizing = (event) => {
145
+ if (handle.hasPointerCapture(event.pointerId)) {
146
+ handle.releasePointerCapture(event.pointerId);
147
+ }
148
+ document.body.classList.remove("is-resizing-dag-inspector");
149
+ };
150
+ handle.addEventListener("pointerup", stopResizing);
151
+ handle.addEventListener("pointercancel", stopResizing);
152
+ handle.addEventListener("keydown", (event) => {
153
+ const currentWidth =
154
+ uiState.dagInspectorWidth ?? dagInspectorDefaultWidth();
155
+ if (event.key === "ArrowLeft") {
156
+ event.preventDefault();
157
+ updateRange(currentWidth + DAG_INSPECTOR_KEYBOARD_STEP);
158
+ } else if (event.key === "ArrowRight") {
159
+ event.preventDefault();
160
+ updateRange(currentWidth - DAG_INSPECTOR_KEYBOARD_STEP);
161
+ } else if (event.key === "Home") {
162
+ event.preventDefault();
163
+ updateRange(DAG_INSPECTOR_MIN_WIDTH);
164
+ } else if (event.key === "End") {
165
+ event.preventDefault();
166
+ updateRange(dagInspectorMaximumWidth());
167
+ }
168
+ });
169
+ return handle;
170
+ }
171
+
172
+ export function captureDagTimelineViewportState(panel) {
173
+ const scrollEl = panel.querySelector(".process-timeline-scroll");
174
+ if (scrollEl?.dataset.dagRunId && scrollEl.dataset.nodeId) {
175
+ const followLatest = computeFollowLatest(
176
+ scrollEl.scrollTop,
177
+ scrollEl.scrollHeight,
178
+ scrollEl.clientHeight,
179
+ );
180
+ uiState.dagTimelineViewportState = updateDagTimelineViewportState(
181
+ uiState.dagTimelineViewportState,
182
+ scrollEl.dataset.dagRunId,
183
+ scrollEl.dataset.nodeId,
184
+ scrollEl.scrollLeft,
185
+ scrollEl.scrollTop,
186
+ followLatest,
187
+ );
188
+ }
189
+ }
190
+
191
+ async function renderSpecEvidence(content, dagRunId, nodeId) {
192
+ const evidence = await fetchJson(
193
+ `/api/dag-runs/${encodeURIComponent(dagRunId)}/nodes/${encodeURIComponent(nodeId)}/spec-evidence`,
194
+ );
195
+ if (!content.isConnected || content.dataset.dagNodeId !== String(nodeId)) return;
196
+ if (!evidence) {
197
+ content.appendChild(el("p", "empty", "无法加载规范证据。"));
198
+ return;
199
+ }
200
+
201
+ const statusLabels = {
202
+ "spec-read": "已读取规范",
203
+ "source-bound": "已绑定任务源",
204
+ "spec-injected": "仅注入 skill",
205
+ "search-only": "仅执行检索",
206
+ "kb-queried": "已观察知识库查询",
207
+ "no-evidence": "未观察到读取",
208
+ };
209
+ const statusSection = el("div", "spec-evidence-section");
210
+ statusSection.appendChild(el("h4", null, "证据状态"));
211
+ statusSection.appendChild(
212
+ el(
213
+ "span",
214
+ `badge badge-${evidence.status === "spec-read" ? "succeeded" : evidence.status === "no-evidence" ? "failed" : "pending"}`,
215
+ statusLabels[evidence.status] ?? evidence.status,
216
+ ),
217
+ );
218
+ if (evidence.summary) {
219
+ statusSection.appendChild(
220
+ el("p", "spec-evidence-summary", evidence.summary),
221
+ );
222
+ }
223
+ content.appendChild(statusSection);
224
+
225
+ const appendListSection = (title, entries, renderEntry) => {
226
+ if (!entries?.length) return;
227
+ const section = el("div", "spec-evidence-section");
228
+ section.appendChild(el("h4", null, title));
229
+ const list = el("ul", "spec-evidence-list");
230
+ for (const entry of entries) list.appendChild(renderEntry(entry));
231
+ section.appendChild(list);
232
+ content.appendChild(section);
233
+ };
234
+
235
+ appendListSection("注入的 Skill", evidence.skillInjection?.skills, (skill) => {
236
+ const item = el("li", null);
237
+ const icon = el("i", "ri-bookmark-line");
238
+ icon.setAttribute("aria-hidden", "true");
239
+ item.append(icon, document.createTextNode(` ${skill}`));
240
+ return item;
241
+ });
242
+ appendListSection("已绑定任务源", evidence.sourceBinding?.sources, (source) => {
243
+ const item = el("li", null);
244
+ const icon = el("i", "ri-links-line");
245
+ icon.setAttribute("aria-hidden", "true");
246
+ item.append(icon, document.createTextNode(` ${source.kind}: `), el("code", null, source.path), document.createTextNode(` · sha256 ${source.sha256.slice(0, 12)}…`));
247
+ return item;
248
+ });
249
+ appendListSection("显式需求编号", evidence.sourceBinding?.requirementIds, (id) => el("li", null, id));
250
+ appendListSection(
251
+ `已读取规范文件(${evidence.specReads?.length ?? 0})`,
252
+ evidence.specReads,
253
+ (read) => {
254
+ const item = el("li", null);
255
+ const icon = el("i", "ri-file-text-line");
256
+ icon.setAttribute("aria-hidden", "true");
257
+ item.append(icon, el("code", null, read.path));
258
+ if (read.timestamp) {
259
+ item.appendChild(
260
+ el(
261
+ "span",
262
+ "spec-evidence-time",
263
+ formatSessionEventTime({ timestamp: read.timestamp }),
264
+ ),
265
+ );
266
+ }
267
+ return item;
268
+ },
269
+ );
270
+ appendListSection(
271
+ `检索操作(${evidence.specSearches?.length ?? 0})`,
272
+ evidence.specSearches,
273
+ (search) => {
274
+ const item = el("li", null);
275
+ const icon = el("i", "ri-search-line");
276
+ icon.setAttribute("aria-hidden", "true");
277
+ item.append(icon, document.createTextNode(` ${search.tool}: ${search.query}`));
278
+ return item;
279
+ },
280
+ );
281
+ appendListSection(
282
+ `知识库查询(${evidence.knowledgeBaseQueries?.length ?? 0})`,
283
+ evidence.knowledgeBaseQueries,
284
+ (query) => {
285
+ const item = el("li", null);
286
+ const icon = el("i", "ri-database-2-line");
287
+ icon.setAttribute("aria-hidden", "true");
288
+ item.append(icon, document.createTextNode(` ${query.connector}`));
289
+ return item;
290
+ },
291
+ );
292
+
293
+ if (evidence.status === "source-bound" || evidence.status === "spec-injected" || evidence.status === "no-evidence") {
294
+ const warning = el("div", "spec-evidence-warning");
295
+ const icon = el("i", "ri-alert-line");
296
+ icon.setAttribute("aria-hidden", "true");
297
+ warning.append(
298
+ icon,
299
+ document.createTextNode(
300
+ evidence.status === "source-bound"
301
+ ? "DAG 已绑定权威任务源及内容哈希,但尚未观察到成功的 read 工具调用;绑定证明上下文来源,read 事件才证明节点读取了完整文件。"
302
+ : evidence.status === "no-evidence"
303
+ ? "未观察到规范读取。只有 session event 中成功配对的 read 工具调用才算已读取,模型总结或文件名命中不能作为证明。"
304
+ : "规范 skill 已注入,但未观察到规范读取或知识库查询;grep/find/ls 只能证明检索,不能替代 read。",
305
+ ),
306
+ );
307
+ content.appendChild(warning);
308
+ }
309
+ }
310
+
311
+ function fillDagInspectorContent(content, dagRunId, node) {
312
+ const activeTab = ["timeline", "spec-evidence"].includes(
313
+ uiState.dagInspectorTab,
314
+ )
315
+ ? uiState.dagInspectorTab
316
+ : "output";
317
+ content.id = `dag-inspector-panel-${activeTab}`;
318
+ content.setAttribute("role", "tabpanel");
319
+ content.setAttribute("aria-labelledby", `dag-inspector-tab-${activeTab}`);
320
+ content.dataset.dagNodeId = String(node.nodeId ?? "");
321
+ // Drop timeline-only classes when switching tabs so output layout stays clean.
322
+ content.className = "dag-inspector-content";
323
+ if (activeTab === "spec-evidence") {
324
+ void renderSpecEvidence(content, dagRunId, node.nodeId);
325
+ } else if (activeTab === "timeline") {
326
+ renderSessionTimeline(content, node.nodeId);
327
+ } else if (!node.outputPreview && !node.errorPreview) {
328
+ content.appendChild(el("p", "empty", UI_TEXT.noOutput));
329
+ } else {
330
+ if (node.outputPreview)
331
+ content.appendChild(renderMarkdown(node.outputPreview));
332
+ if (node.errorPreview) {
333
+ const error = el("section", "markdown-error");
334
+ error.appendChild(el("p", "markdown-error-title", "错误输出"));
335
+ error.appendChild(renderMarkdown(node.errorPreview));
336
+ content.appendChild(error);
337
+ }
338
+ }
339
+ }
340
+
341
+ function buildDagInspectorHeader(dagRunId, node) {
342
+ const header = el("div", "dag-inspector-header");
343
+ header.dataset.dagRunId = String(dagRunId ?? "");
344
+ header.dataset.dagNodeId = String(node.nodeId ?? "");
345
+ const title = el("div", "dag-inspector-title");
346
+ title.appendChild(el("h3", null, "节点检查器"));
347
+ title.appendChild(el("div", "dag-inspector-node", node.nodeId));
348
+ header.appendChild(title);
349
+ const controls = el("div", "dag-inspector-controls");
350
+ const status = badge(node.status ?? "unknown");
351
+ status.classList.add("dag-inspector-status");
352
+ controls.appendChild(status);
353
+ const close = document.createElement("button");
354
+ close.type = "button";
355
+ close.className = "dag-inspector-close";
356
+ close.setAttribute("aria-label", "关闭节点检查器");
357
+ const closeIcon = el("i", "ri-close-line");
358
+ closeIcon.setAttribute("aria-hidden", "true");
359
+ close.appendChild(closeIcon);
360
+ close.addEventListener("click", closeDagInspector);
361
+ controls.appendChild(close);
362
+ header.appendChild(controls);
363
+
364
+ const tabDefs = [
365
+ ["output", "节点输出", "ri-file-text-line"],
366
+ ["timeline", "执行过程", "ri-route-line"],
367
+ ["spec-evidence", "规范证据", "ri-book-open-line"],
368
+ ];
369
+ const tabs = el("div", "dag-inspector-tabs");
370
+ tabs.setAttribute("role", "tablist");
371
+ tabs.setAttribute("aria-label", "节点检查器面板");
372
+ for (const [tab, label, icon] of tabDefs) {
373
+ const selected = uiState.dagInspectorTab === tab;
374
+ const button = document.createElement("button");
375
+ button.type = "button";
376
+ button.id = `dag-inspector-tab-${tab}`;
377
+ button.className = "dag-inspector-tab";
378
+ button.setAttribute("role", "tab");
379
+ button.setAttribute("aria-controls", `dag-inspector-panel-${tab}`);
380
+ button.setAttribute("aria-selected", String(selected));
381
+ button.tabIndex = selected ? 0 : -1;
382
+ button.dataset.tab = tab;
383
+ const tabIcon = el("i", icon);
384
+ tabIcon.setAttribute("aria-hidden", "true");
385
+ button.appendChild(tabIcon);
386
+ button.appendChild(document.createTextNode(` ${label}`));
387
+ button.addEventListener("click", () => {
388
+ uiState.dagInspectorTab = tab;
389
+ renderDagInspectorForCurrent();
390
+ const next = document.getElementById(`dag-inspector-tab-${tab}`);
391
+ next?.focus();
392
+ });
393
+ button.addEventListener("keydown", (event) => {
394
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
395
+ event.preventDefault();
396
+ event.stopPropagation();
397
+ const order = tabDefs.map(([id]) => id);
398
+ const idx = order.indexOf(tab);
399
+ if (idx < 0) return;
400
+ const delta = event.key === "ArrowRight" ? 1 : -1;
401
+ const nextTab = order[(idx + delta + order.length) % order.length];
402
+ uiState.dagInspectorTab = nextTab;
403
+ renderDagInspectorForCurrent();
404
+ document.getElementById(`dag-inspector-tab-${nextTab}`)?.focus();
405
+ });
406
+ tabs.appendChild(button);
407
+ }
408
+ header.appendChild(tabs);
409
+ return header;
410
+ }
411
+
412
+ function syncDagInspectorHeader(panel, dagRunId, node) {
413
+ const header = panel.querySelector(".dag-inspector-header");
414
+ if (!header) return;
415
+ header.dataset.dagRunId = String(dagRunId ?? "");
416
+ header.dataset.dagNodeId = String(node.nodeId ?? "");
417
+ const nodeLabel = header.querySelector(".dag-inspector-node");
418
+ if (nodeLabel) nodeLabel.textContent = node.nodeId;
419
+ const status = header.querySelector(".dag-inspector-status");
420
+ if (status) {
421
+ const next = badge(node.status ?? "unknown");
422
+ next.classList.add("dag-inspector-status");
423
+ status.replaceWith(next);
424
+ }
425
+ for (const button of header.querySelectorAll(".dag-inspector-tab")) {
426
+ const selected = button.dataset.tab === uiState.dagInspectorTab;
427
+ button.setAttribute("aria-selected", String(selected));
428
+ button.tabIndex = selected ? 0 : -1;
429
+ }
430
+ }
431
+
432
+ function dagInspectorSignature(dagRunId, node) {
433
+ return JSON.stringify([
434
+ dagRunId,
435
+ node.nodeId,
436
+ uiState.dagInspectorTab,
437
+ node.outputPreview ?? "",
438
+ node.errorPreview ?? "",
439
+ uiState.dagInspectorTab === "timeline" ? uiState.sessionEventOffset : null,
440
+ ]);
441
+ }
442
+
443
+ export function renderDagInspector(dagRunId, node, initial = true) {
444
+ // Record the current selection before any early-return so tab handlers
445
+ // (which reference the mutable inspectorSelection slot) always re-render
446
+ // the currently selected node, never a stale build-time closure.
447
+ inspectorSelection.dagRunId = dagRunId;
448
+ inspectorSelection.node = node;
449
+ const panel = document.getElementById("dag-inspector");
450
+ if (!panel) return;
451
+ captureDagTimelineViewportState(panel);
452
+ if (!uiState.dagInspectorOpen || !node) {
453
+ panel.classList.remove("is-open");
454
+ panel.setAttribute("aria-hidden", "true");
455
+ return;
456
+ }
457
+
458
+ // Defer tearing down the inspector shell while the user is actively
459
+ // dragging the resize handle (or the graph) so the pointer-capture target
460
+ // is not destroyed mid-gesture; the next poll refreshes the content.
461
+ if (isInteractiveGestureActive(document.body.classList)) {
462
+ return;
463
+ }
464
+
465
+ const existingContent = panel.querySelector(".dag-inspector-content") ?? null;
466
+ const reuseShell = !initial && Boolean(existingContent);
467
+ const nextContentSignature = dagInspectorSignature(dagRunId, node);
468
+
469
+ if (reuseShell && existingContent) {
470
+ panel.classList.add("is-open");
471
+ panel.setAttribute("aria-hidden", "false");
472
+ syncDagInspectorHeader(panel, dagRunId, node);
473
+ if (panel.dataset.contentSignature === nextContentSignature) return;
474
+ const previousNode = existingContent.dataset.dagNodeId ?? "";
475
+ const nodeChanged = previousNode !== String(node.nodeId ?? "");
476
+ const followLatest =
477
+ nodeChanged ||
478
+ computeFollowLatest(
479
+ existingContent.scrollTop,
480
+ existingContent.scrollHeight,
481
+ existingContent.clientHeight,
482
+ );
483
+ const regionKey = `dag:${dagRunId}:${node.nodeId}:output`;
484
+ uiState.dagNodeOutputViewportState = updateDagOutputViewportState(
485
+ uiState.dagNodeOutputViewportState,
486
+ regionKey,
487
+ existingContent.scrollLeft,
488
+ existingContent.scrollTop,
489
+ followLatest,
490
+ );
491
+ const nestedViewportState = [
492
+ ...existingContent.querySelectorAll("pre"),
493
+ ].map((pre) => ({
494
+ scrollLeft: pre.scrollLeft,
495
+ scrollTop: pre.scrollTop,
496
+ }));
497
+ clearNode(existingContent);
498
+ fillDagInspectorContent(existingContent, dagRunId, node);
499
+ if (followLatest) {
500
+ existingContent.scrollTop = existingContent.scrollHeight;
501
+ } else {
502
+ existingContent.scrollTop = uiState.dagNodeOutputViewportState.scrollTop;
503
+ }
504
+ for (const [index, pre] of [
505
+ ...existingContent.querySelectorAll("pre"),
506
+ ].entries()) {
507
+ const previous = nestedViewportState[index];
508
+ if (!previous) continue;
509
+ pre.scrollLeft = previous.scrollLeft;
510
+ pre.scrollTop = previous.scrollTop;
511
+ }
512
+ panel.dataset.contentSignature = nextContentSignature;
513
+ return;
514
+ }
515
+
516
+ clearNode(panel);
517
+ panel.classList.add("is-open");
518
+ panel.setAttribute("aria-hidden", "false");
519
+ panel.appendChild(createDagInspectorResizeHandle(panel));
520
+ panel.appendChild(buildDagInspectorHeader(dagRunId, node));
521
+
522
+ const content = el("div", "dag-inspector-content");
523
+ fillDagInspectorContent(content, dagRunId, node);
524
+ panel.appendChild(content);
525
+ panel.dataset.contentSignature = nextContentSignature;
526
+ }
527
+
528
+ /**
529
+ * Bounded event history UI. Uses opaque `cursor`/`nextCursor` (not SSE/run `after` offsets).
530
+ */