@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,350 +1,708 @@
1
- /** Observe UI view module (R5). */
2
- import {
3
- UI_TEXT,
4
- LIVENESS_LABELS,
5
- ARTIFACT_LABELS,
6
- ARTIFACT_KEYS,
7
- STEP_LABELS,
8
- STEP_ORDER,
9
- DAG_INSPECTOR_DEFAULT_WIDTH,
10
- DAG_INSPECTOR_MIN_WIDTH,
11
- DAG_INSPECTOR_MAX_WIDTH,
12
- DAG_INSPECTOR_RIGHT_OFFSET,
13
- DAG_INSPECTOR_VIEWPORT_MARGIN,
14
- DAG_INSPECTOR_KEYBOARD_STEP,
15
- TERMINAL_RUN_STATUSES,
16
- DAG_EFFECTIVE_STATUS_LABELS,
17
- STATUS_LABELS,
18
- } from "../constants.js";
19
- import { clearNode, el, metaGrid, buildTable } from "../dom.js";
20
- import {
21
- badge,
22
- badgeClass,
23
- statusLabel,
24
- formatTs,
25
- formatMs,
26
- formatDuration,
27
- formatAgo,
28
- dagStatusBadge,
29
- livenessBadge,
30
- displayDurationMs,
31
- derivedDurationMs,
32
- summaryText,
33
- truncateText,
34
- repoBaseName,
35
- parseMarkdownBlocks,
36
- markdownLinkHref,
37
- } from "../format.js";
38
- import { parseRoute, navigate, buildHashPath } from "../router.js";
39
- import {
40
- fetchJson,
41
- artifactUrl,
42
- parseArtifactPreviewResponse,
43
- } from "../api.js";
44
- import {
45
- objectRouteLink,
46
- findFeatureInSnapshot,
47
- featureLookupState,
48
- buildObjectRelations,
49
- renderObjectRelationBar,
50
- } from "../relations.js";
51
- import { copyText, renderRecommendedCommand } from "../copy.js";
52
- import {
53
- isPageVisible,
54
- detailPollDelay,
55
- dashboardPollDelay,
56
- captureDagGraphViewportState,
57
- updateDagGraphViewportState,
58
- updateDagTimelineViewportState,
59
- renderViewState,
60
- mountViewState,
61
- } from "../state.js";
62
- import { uiState } from "../state.js";
63
- import {
64
- sortPoolTasks,
65
- matchesPoolStatusFilter,
66
- poolStatusCounts,
67
- } from "../format-pool.js";
68
- import {
69
- dagMetaVisibility,
70
- isDagRunActive,
71
- dashboardVisibleFeatures,
72
- findDagForRun,
73
- } from "../dag-model.js";
74
- import { layoutDag } from "../dag-layout.js";
75
- import { showView, setBreadcrumb, updateHeaderRefresh } from "../shell-chrome.js";
76
- import { renderProjectionFault } from "../kpi.js";
77
- import { mountBoundedEventTimeline } from "./timeline.js";
78
-
79
- export async function renderPool() {
80
- showView("pool");
81
- setBreadcrumb([
82
- { label: UI_TEXT.dashboard, href: "#/" },
83
- { label: "资源池" },
84
- ]);
85
-
86
- const faultEl = document.getElementById("pool-fault");
87
- const kpiEl = document.getElementById("pool-kpi");
88
- const emptyEl = document.getElementById("pool-empty");
89
- const listEl = document.getElementById("pool-tasks");
90
- const eventsEl = document.getElementById("pool-events");
91
- if (!faultEl || !kpiEl || !emptyEl || !listEl) return;
92
-
93
- mountViewState(faultEl, "loading", "加载资源池…");
94
- clearNode(kpiEl);
95
- clearNode(listEl);
96
- clearNode(emptyEl);
97
- emptyEl.hidden = true;
98
-
99
- const snapshot = await fetchJson("/api/snapshot");
100
- if (!snapshot) {
101
- clearNode(kpiEl);
102
- clearNode(listEl);
103
- clearNode(emptyEl);
104
- emptyEl.hidden = true;
105
- if (eventsEl) clearNode(eventsEl);
106
- mountViewState(faultEl, "error", "无法加载 snapshot。");
107
- return;
108
- }
109
- uiState.lastSnapshot = snapshot;
110
- updateHeaderRefresh(snapshot.generatedAt);
111
-
112
- clearNode(faultEl);
113
- if (snapshot.projectionError) {
114
- mountViewState(faultEl, "degraded", "投影降级:状态分布可能不完整。", {
115
- detail: snapshot.projectionError.message ?? null,
116
- });
117
- faultEl.appendChild(
118
- renderProjectionFault(snapshot.projectionError),
119
- );
120
- }
121
- if ((snapshot.projectionWarnings ?? []).length > 0) {
122
- const warn = el("div", "projection-fault");
123
- const body = el("div", "projection-fault-body");
124
- body.appendChild(el("p", "projection-fault-title", "投影警告"));
125
- body.appendChild(
126
- el(
127
- "p",
128
- "projection-fault-message",
129
- snapshot.projectionWarnings.join(";"),
130
- ),
131
- );
132
- warn.appendChild(body);
133
- faultEl.appendChild(warn);
134
- }
135
- if (snapshot.generatedAt) {
136
- faultEl.appendChild(
137
- el(
138
- "p",
139
- "muted pool-updated-at",
140
- `投影更新时间:${formatTs(snapshot.generatedAt)}(derived/advisory)`,
141
- ),
142
- );
143
- }
144
-
145
- const allTasks = sortPoolTasks(snapshot.tasks ?? []);
146
- const routeFilters = parseRoute().filters ?? {};
147
- const statusFilter = (routeFilters.status ?? "").toLowerCase();
148
- const qFilter = (routeFilters.q ?? "").trim().toLowerCase();
149
- const tasks = allTasks.filter((task) => {
150
- if (statusFilter && !matchesPoolStatusFilter(task.status, statusFilter)) {
151
- return false;
152
- }
153
- if (qFilter) {
154
- const hay =
155
- `${task.taskId ?? ""} ${task.featureId ?? ""} ${task.workerRunId ?? ""} ${task.failureCategory ?? ""}`.toLowerCase();
156
- if (!hay.includes(qFilter)) return false;
157
- }
158
- return true;
159
- });
160
- const poolPresent = snapshot.taskPool?.present === true;
161
- const projectionFailed = Boolean(snapshot.projectionError);
162
-
163
- // Shareable hash filters (REQ-R5-04)
164
- if (listEl) {
165
- let filtersEl = document.getElementById("pool-filters");
166
- if (!filtersEl) {
167
- filtersEl = el("div", "pool-filters");
168
- filtersEl.id = "pool-filters";
169
- listEl.parentElement?.insertBefore(filtersEl, listEl);
170
- }
171
- clearNode(filtersEl);
172
- const statusLabelEl = el("label", null);
173
- statusLabelEl.appendChild(document.createTextNode("状态"));
174
- const statusSelect = document.createElement("select");
175
- statusSelect.setAttribute("aria-label", "按状态筛选 Task");
176
- for (const [value, label] of [
177
- ["", "全部"],
178
- ["running", "运行中"],
179
- ["pending", "等待/排队"],
180
- ["blocked", "阻塞/失联"],
181
- ["failed", "失败"],
182
- ["succeeded", "成功/复用"],
183
- ]) {
184
- const opt = document.createElement("option");
185
- opt.value = value;
186
- opt.textContent = label;
187
- if (value === statusFilter) opt.selected = true;
188
- statusSelect.appendChild(opt);
189
- }
190
- statusLabelEl.appendChild(statusSelect);
191
- const qLabel = el("label", null);
192
- qLabel.appendChild(document.createTextNode("搜索"));
193
- const qInput = document.createElement("input");
194
- qInput.type = "search";
195
- qInput.placeholder = "Task / Feature / run…";
196
- qInput.setAttribute("aria-label", "搜索 Task");
197
- qInput.value = routeFilters.q ?? "";
198
- qLabel.appendChild(qInput);
199
- statusSelect.addEventListener("change", () => {
200
- const next = buildHashPath("/pool", {
201
- status: statusSelect.value || undefined,
202
- q: qInput.value.trim() || undefined,
203
- });
204
- navigate(next);
205
- });
206
- qInput.addEventListener("change", () => {
207
- const next = buildHashPath("/pool", {
208
- status: statusSelect.value || undefined,
209
- q: qInput.value.trim() || undefined,
210
- });
211
- navigate(next);
212
- });
213
- filtersEl.appendChild(statusLabelEl);
214
- filtersEl.appendChild(qLabel);
215
- filtersEl.appendChild(
216
- el("span", "muted layer-raw", `显示 ${tasks.length}/${allTasks.length}`),
217
- );
218
- }
219
-
220
- clearNode(kpiEl);
221
- clearNode(listEl);
222
- emptyEl.hidden = true;
223
- clearNode(emptyEl);
224
-
225
- if (projectionFailed) {
226
- // Fault-first: do not render healthy-looking zero KPIs when projection is broken.
227
- kpiEl.appendChild(
228
- el(
229
- "p",
230
- "empty",
231
- "投影失败,状态分布与健康 KPI 不可用(避免将未知显示为健康 0)。",
232
- ),
233
- );
234
- if (eventsEl) {
235
- await mountBoundedEventTimeline(
236
- eventsEl,
237
- "/api/events",
238
- "最近事件",
239
- );
240
- }
241
- return;
242
- }
243
-
244
- if (!poolPresent && tasks.length === 0) {
245
- emptyEl.hidden = false;
246
- mountViewState(
247
- emptyEl,
248
- "empty",
249
- "当前仓库未使用 Task Pool(未发现 .harness/task-pool)。",
250
- );
251
- if (eventsEl) {
252
- await mountBoundedEventTimeline(
253
- eventsEl,
254
- "/api/events",
255
- "最近事件",
256
- );
257
- }
258
- return;
259
- }
260
-
261
- if (poolPresent && tasks.length === 0) {
262
- emptyEl.hidden = false;
263
- mountViewState(emptyEl, "empty", "Task Pool 已存在,但当前没有 Task。");
264
- }
265
-
266
- const counts = poolStatusCounts(tasks);
267
- const cards = el("div", "kpi-grid");
268
- for (const [label, value] of [
269
- ["运行中", counts.running],
270
- ["等待/排队", counts.pending],
271
- ["阻塞/失联", counts.blocked],
272
- ["失败", counts.failed],
273
- ["成功/复用", counts.succeeded],
274
- ["其他", counts.other],
275
- ["合计", tasks.length],
276
- ]) {
277
- const card = el("div", "kpi-card");
278
- card.appendChild(el("div", "kpi-value", String(value)));
279
- card.appendChild(el("div", "kpi-label", label));
280
- cards.appendChild(card);
281
- }
282
- kpiEl.appendChild(el("h3", "section-heading", "状态分布"));
283
- kpiEl.appendChild(cards);
284
-
285
- if (tasks.length > 0) {
286
- const rows = tasks.map((task) => {
287
- const taskLink = document.createElement("a");
288
- const taskPath = task.featureId
289
- ? `/feature/${encodeURIComponent(task.featureId)}/task/${encodeURIComponent(task.taskId)}`
290
- : `/task/${encodeURIComponent(task.taskId)}`;
291
- taskLink.href = `#${taskPath}`;
292
- taskLink.textContent = task.taskId;
293
- taskLink.addEventListener("click", (e) => {
294
- e.preventDefault();
295
- navigate(taskPath);
296
- });
297
-
298
- let runCell = "";
299
- if (task.workerRunId) {
300
- const a = document.createElement("a");
301
- a.href = `#/run/${encodeURIComponent(task.workerRunId)}`;
302
- a.textContent = task.workerRunId;
303
- a.addEventListener("click", (e) => {
304
- e.preventDefault();
305
- navigate(`#/run/${encodeURIComponent(task.workerRunId)}`);
306
- });
307
- runCell = a;
308
- }
309
-
310
- return {
311
- cells: [
312
- taskLink,
313
- task.featureId ?? "—",
314
- badge(task.status),
315
- runCell,
316
- formatAgo(task.updatedAt || task.finishedAt || task.startedAt),
317
- task.failureCategory ?? "—",
318
- ],
319
- };
320
- });
321
- listEl.appendChild(
322
- buildTable(
323
- ["Task", "Feature", "状态", "最新 worker run", "更新时间", "失败分类"],
324
- rows,
325
- ),
326
- );
327
- }
328
-
329
- if (eventsEl) {
330
- await mountBoundedEventTimeline(
331
- eventsEl,
332
- "/api/events",
333
- "最近事件",
334
- );
335
- }
336
- }
337
-
338
- export function startPoolPolling() {
339
- if (uiState.poolTimer) clearTimeout(uiState.poolTimer);
340
- const generation = ++uiState.pollingGeneration;
341
- const poll = async () => {
342
- await renderPool();
343
- if (generation !== uiState.pollingGeneration) return;
344
- uiState.poolTimer = setTimeout(() => {
345
- uiState.poolTimer = null;
346
- void poll();
347
- }, dashboardPollDelay());
348
- };
349
- void poll();
350
- }
1
+ /** Observe UI view module — Task Pool ops surface (R5 + ops refresh). */
2
+ import { UI_TEXT, POOL_POLL_MS } from "../constants.js";
3
+ import { clearNode, el, reconcileKeyed } from "../dom.js";
4
+ import {
5
+ badge,
6
+ formatAgo,
7
+ formatTs,
8
+ livenessBadge,
9
+ truncateText,
10
+ } from "../format.js";
11
+ import { parseRoute, navigate, buildHashPath } from "../router.js";
12
+ import { fetchJson } from "../api.js";
13
+ import { objectRouteLink } from "../relations.js";
14
+ import {
15
+ isPageVisible,
16
+ dashboardPollDelay,
17
+ mountViewState,
18
+ renderViewState,
19
+ } from "../state.js";
20
+ import { uiState } from "../state.js";
21
+ import {
22
+ sortPoolTasks,
23
+ matchesPoolStatusFilter,
24
+ poolStatusCounts,
25
+ sortAttentionTasks,
26
+ collectPlannerReadyTasks,
27
+ taskIdentityKey,
28
+ } from "../format-pool.js";
29
+ import { showView, setBreadcrumb, updateHeaderRefresh } from "../shell-chrome.js";
30
+ import { renderProjectionFault } from "../kpi.js";
31
+ import { mountBoundedEventTimeline } from "./timeline.js";
32
+
33
+ let poolToolbarBound = false;
34
+ let poolEventsBound = false;
35
+ let poolHasRendered = false;
36
+
37
+ function poolAutoRefreshEnabled() {
38
+ return uiState.poolAutoRefresh === true;
39
+ }
40
+
41
+ function syncPoolToolbar() {
42
+ const auto = document.getElementById("pool-auto-refresh");
43
+ const status = document.getElementById("pool-refresh-status");
44
+ if (auto) auto.checked = poolAutoRefreshEnabled();
45
+ if (status) {
46
+ status.textContent = poolAutoRefreshEnabled()
47
+ ? `自动刷新约 ${Math.round(POOL_POLL_MS / 1000)}s`
48
+ : "已关闭自动刷新";
49
+ }
50
+ }
51
+
52
+ function bindPoolToolbar() {
53
+ if (poolToolbarBound) return;
54
+ const btn = document.getElementById("pool-refresh-btn");
55
+ const auto = document.getElementById("pool-auto-refresh");
56
+ if (!btn || !auto) return;
57
+ poolToolbarBound = true;
58
+ btn.addEventListener("click", () => {
59
+ void renderPool({ reason: "manual" });
60
+ });
61
+ auto.addEventListener("change", () => {
62
+ uiState.poolAutoRefresh = auto.checked;
63
+ syncPoolToolbar();
64
+ if (auto.checked) startPoolAutoPolling();
65
+ else stopPoolAutoPolling();
66
+ });
67
+ }
68
+
69
+ function bindPoolEventsDetails() {
70
+ if (poolEventsBound) return;
71
+ const details = document.getElementById("pool-events-details");
72
+ if (!details) return;
73
+ poolEventsBound = true;
74
+ details.addEventListener("toggle", () => {
75
+ if (details.open) void refreshPoolEvents();
76
+ });
77
+ }
78
+
79
+ function stopPoolAutoPolling() {
80
+ if (uiState.poolTimer) {
81
+ clearTimeout(uiState.poolTimer);
82
+ uiState.poolTimer = null;
83
+ }
84
+ }
85
+
86
+ function startPoolAutoPolling() {
87
+ stopPoolAutoPolling();
88
+ if (!poolAutoRefreshEnabled()) return;
89
+ const generation = ++uiState.pollingGeneration;
90
+ const poll = async () => {
91
+ if (!poolAutoRefreshEnabled()) return;
92
+ await renderPool({ reason: "auto" });
93
+ if (generation !== uiState.pollingGeneration) return;
94
+ if (!poolAutoRefreshEnabled()) return;
95
+ const delay = isPageVisible() ? POOL_POLL_MS : dashboardPollDelay();
96
+ uiState.poolTimer = setTimeout(() => {
97
+ uiState.poolTimer = null;
98
+ void poll();
99
+ }, delay);
100
+ };
101
+ void poll();
102
+ }
103
+
104
+ async function refreshPoolEvents() {
105
+ const eventsEl = document.getElementById("pool-events");
106
+ const details = document.getElementById("pool-events-details");
107
+ if (!eventsEl || !details?.open) return;
108
+ await mountBoundedEventTimeline(eventsEl, "/api/events", "最近事件");
109
+ }
110
+
111
+ function taskPath(task) {
112
+ if (task.featureId) {
113
+ return `/feature/${encodeURIComponent(task.featureId)}/task/${encodeURIComponent(task.taskId)}`;
114
+ }
115
+ return `/task/${encodeURIComponent(task.taskId)}`;
116
+ }
117
+
118
+ function linkTo(path, label, className) {
119
+ const a = el("a", className || "object-link", label);
120
+ a.href = `#${path}`;
121
+ a.addEventListener("click", (e) => {
122
+ e.preventDefault();
123
+ e.stopPropagation();
124
+ navigate(path);
125
+ });
126
+ return a;
127
+ }
128
+
129
+ function syncCell(row, index, content) {
130
+ let td = row.children[index];
131
+ if (!td) {
132
+ td = document.createElement("td");
133
+ row.appendChild(td);
134
+ }
135
+ while (td.firstChild) td.removeChild(td.firstChild);
136
+ if (content instanceof Node) td.appendChild(content);
137
+ else td.textContent = content ?? "—";
138
+ }
139
+
140
+ function ensureTable(parent, headers, scope) {
141
+ let table = parent.querySelector("table");
142
+ if (!table) {
143
+ table = document.createElement("table");
144
+ const thead = document.createElement("thead");
145
+ const headRow = document.createElement("tr");
146
+ for (const h of headers) {
147
+ const th = document.createElement("th");
148
+ th.textContent = h;
149
+ headRow.appendChild(th);
150
+ }
151
+ thead.appendChild(headRow);
152
+ table.appendChild(thead);
153
+ table.appendChild(document.createElement("tbody"));
154
+ parent.appendChild(table);
155
+ }
156
+ return table.querySelector("tbody");
157
+ }
158
+
159
+ function renderOpsCard(item, kind) {
160
+ const card = el("div", `pool-ops-card pool-ops-card-${kind}`);
161
+ const title = el("div", "pool-ops-card-title");
162
+ title.appendChild(linkTo(taskPath(item), item.taskId));
163
+ card.appendChild(title);
164
+ const meta = el("div", "pool-ops-card-meta");
165
+ meta.appendChild(
166
+ el("span", null, item.featureId ? `Feature ${item.featureId}` : "Feature —"),
167
+ );
168
+ if (item.priority) meta.appendChild(el("span", null, item.priority));
169
+ if (item.status) meta.appendChild(badge(item.status));
170
+ else if (item.liveness) meta.appendChild(livenessBadge(item.liveness));
171
+ card.appendChild(meta);
172
+ const detail = item.recommendedFollowUp || item.title || item.failureCategory;
173
+ if (detail) {
174
+ card.appendChild(
175
+ el("p", "pool-ops-card-detail", truncateText(String(detail), 96)),
176
+ );
177
+ }
178
+ card.classList.add("clickable");
179
+ card.addEventListener("click", () => navigate(taskPath(item)));
180
+ return card;
181
+ }
182
+
183
+ function updateOpsCard(card, item) {
184
+ const title = card.querySelector(".pool-ops-card-title");
185
+ if (title) {
186
+ while (title.firstChild) title.removeChild(title.firstChild);
187
+ title.appendChild(linkTo(taskPath(item), item.taskId));
188
+ }
189
+ const meta = card.querySelector(".pool-ops-card-meta");
190
+ if (meta) {
191
+ while (meta.firstChild) meta.removeChild(meta.firstChild);
192
+ meta.appendChild(
193
+ el("span", null, item.featureId ? `Feature ${item.featureId}` : "Feature —"),
194
+ );
195
+ if (item.priority) meta.appendChild(el("span", null, item.priority));
196
+ if (item.status) meta.appendChild(badge(item.status));
197
+ else if (item.liveness) meta.appendChild(livenessBadge(item.liveness));
198
+ }
199
+ let detail = card.querySelector(".pool-ops-card-detail");
200
+ const text = item.recommendedFollowUp || item.title || item.failureCategory;
201
+ if (text) {
202
+ if (!detail) {
203
+ detail = el("p", "pool-ops-card-detail");
204
+ card.appendChild(detail);
205
+ }
206
+ detail.textContent = truncateText(String(text), 96);
207
+ } else if (detail) {
208
+ detail.remove();
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Mount or refresh the pool view. Default: no auto poll.
214
+ * @param {{ reason?: "route" | "manual" | "auto" }} [options]
215
+ */
216
+ export async function renderPool(options = {}) {
217
+ showView("pool");
218
+ setBreadcrumb([
219
+ { label: UI_TEXT.dashboard, href: "#/" },
220
+ { label: "资源池" },
221
+ ]);
222
+ bindPoolToolbar();
223
+ bindPoolEventsDetails();
224
+ syncPoolToolbar();
225
+
226
+ const faultEl = document.getElementById("pool-fault");
227
+ const updatedAtEl = document.getElementById("pool-updated-at");
228
+ const kpiEl = document.getElementById("pool-kpi");
229
+ const emptyEl = document.getElementById("pool-empty");
230
+ const attentionEl = document.getElementById("pool-attention");
231
+ const readyEl = document.getElementById("pool-ready");
232
+ const listEl = document.getElementById("pool-tasks");
233
+ const filtersEl = document.getElementById("pool-filters");
234
+ if (!faultEl || !kpiEl || !emptyEl || !listEl || !attentionEl || !readyEl) {
235
+ return;
236
+ }
237
+
238
+ const firstPaint = !poolHasRendered;
239
+ if (firstPaint) {
240
+ faultEl.hidden = false;
241
+ faultEl.classList.add("pool-fault-active");
242
+ mountViewState(faultEl, "loading", "加载资源池…");
243
+ }
244
+
245
+ const snapshot = await fetchJson("/api/snapshot");
246
+ if (!snapshot) {
247
+ faultEl.hidden = false;
248
+ faultEl.classList.add("pool-fault-active");
249
+ mountViewState(faultEl, "error", "无法加载 snapshot。");
250
+ if (updatedAtEl) updatedAtEl.textContent = "";
251
+ return;
252
+ }
253
+ uiState.lastSnapshot = snapshot;
254
+ updateHeaderRefresh(snapshot.generatedAt, {
255
+ mode: poolAutoRefreshEnabled() ? "auto" : "manual",
256
+ });
257
+ poolHasRendered = true;
258
+
259
+ if (updatedAtEl) {
260
+ updatedAtEl.textContent = snapshot.generatedAt
261
+ ? `投影更新:${formatTs(snapshot.generatedAt)}(advisory)`
262
+ : "";
263
+ }
264
+
265
+ clearNode(faultEl);
266
+ let hasFaultContent = false;
267
+ if (snapshot.projectionError) {
268
+ hasFaultContent = true;
269
+ const degraded = renderViewState(
270
+ "degraded",
271
+ "投影降级:状态分布可能不完整。",
272
+ { detail: snapshot.projectionError.message ?? null },
273
+ );
274
+ faultEl.appendChild(degraded);
275
+ faultEl.appendChild(renderProjectionFault(snapshot.projectionError));
276
+ }
277
+ if ((snapshot.projectionWarnings ?? []).length > 0) {
278
+ hasFaultContent = true;
279
+ const warn = el("div", "projection-fault");
280
+ const body = el("div", "projection-fault-body");
281
+ body.appendChild(el("p", "projection-fault-title", "投影警告"));
282
+ body.appendChild(
283
+ el(
284
+ "p",
285
+ "projection-fault-message",
286
+ snapshot.projectionWarnings.join(";"),
287
+ ),
288
+ );
289
+ warn.appendChild(body);
290
+ faultEl.appendChild(warn);
291
+ }
292
+ faultEl.hidden = !hasFaultContent;
293
+ faultEl.classList.toggle("pool-fault-active", hasFaultContent);
294
+
295
+ const allTasks = sortPoolTasks(snapshot.tasks ?? []);
296
+ const routeFilters = parseRoute().filters ?? {};
297
+ const statusFilter = (routeFilters.status ?? "").toLowerCase();
298
+ const qFilter = (routeFilters.q ?? "").trim().toLowerCase();
299
+ const filteredTasks = allTasks.filter((task) => {
300
+ if (statusFilter && !matchesPoolStatusFilter(task.status, statusFilter)) {
301
+ return false;
302
+ }
303
+ if (qFilter) {
304
+ const hay =
305
+ `${task.taskId ?? ""} ${task.featureId ?? ""} ${task.workerRunId ?? ""} ${task.failureCategory ?? ""} ${task.recommendedFollowUp ?? ""}`.toLowerCase();
306
+ if (!hay.includes(qFilter)) return false;
307
+ }
308
+ return true;
309
+ });
310
+ const poolPresent = snapshot.taskPool?.present === true;
311
+ const projectionFailed = Boolean(snapshot.projectionError);
312
+ const readyItems = collectPlannerReadyTasks(snapshot.features);
313
+ const attentionTasks = sortAttentionTasks(allTasks);
314
+ const counts = poolStatusCounts(allTasks);
315
+ const health = snapshot.health ?? {};
316
+
317
+ // Filters (stable container in HTML)
318
+ if (filtersEl) {
319
+ reconcileKeyed(
320
+ filtersEl,
321
+ [{ key: "__filters__" }],
322
+ {
323
+ getKey: (item) => item.key,
324
+ create: () => {
325
+ const wrap = el("div", "pool-filters-inner");
326
+ const statusLabelEl = el("label", null);
327
+ statusLabelEl.appendChild(document.createTextNode("状态"));
328
+ const statusSelect = document.createElement("select");
329
+ statusSelect.setAttribute("aria-label", "按状态筛选 Task");
330
+ statusSelect.dataset.role = "status";
331
+ for (const [value, label] of [
332
+ ["", "全部"],
333
+ ["running", "运行中"],
334
+ ["pending", "等待/排队"],
335
+ ["blocked", "阻塞/失联"],
336
+ ["failed", "失败"],
337
+ ["succeeded", "成功/复用"],
338
+ ]) {
339
+ const opt = document.createElement("option");
340
+ opt.value = value;
341
+ opt.textContent = label;
342
+ statusSelect.appendChild(opt);
343
+ }
344
+ statusLabelEl.appendChild(statusSelect);
345
+ const qLabel = el("label", null);
346
+ qLabel.appendChild(document.createTextNode("搜索"));
347
+ const qInput = document.createElement("input");
348
+ qInput.type = "search";
349
+ qInput.placeholder = "Task / Feature / run…";
350
+ qInput.setAttribute("aria-label", "搜索 Task");
351
+ qInput.dataset.role = "q";
352
+ qLabel.appendChild(qInput);
353
+ const count = el("span", "muted layer-raw");
354
+ count.dataset.role = "count";
355
+ statusSelect.addEventListener("change", () => {
356
+ navigate(
357
+ buildHashPath("/pool", {
358
+ status: statusSelect.value || undefined,
359
+ q: qInput.value.trim() || undefined,
360
+ }),
361
+ );
362
+ });
363
+ qInput.addEventListener("change", () => {
364
+ navigate(
365
+ buildHashPath("/pool", {
366
+ status: statusSelect.value || undefined,
367
+ q: qInput.value.trim() || undefined,
368
+ }),
369
+ );
370
+ });
371
+ wrap.appendChild(statusLabelEl);
372
+ wrap.appendChild(qLabel);
373
+ wrap.appendChild(count);
374
+ return wrap;
375
+ },
376
+ update: (wrap) => {
377
+ const statusSelect = wrap.querySelector('[data-role="status"]');
378
+ const qInput = wrap.querySelector('[data-role="q"]');
379
+ const count = wrap.querySelector('[data-role="count"]');
380
+ if (statusSelect && statusSelect.value !== statusFilter) {
381
+ statusSelect.value = statusFilter;
382
+ }
383
+ if (qInput && document.activeElement !== qInput) {
384
+ qInput.value = routeFilters.q ?? "";
385
+ }
386
+ if (count) {
387
+ count.textContent = `显示 ${filteredTasks.length}/${allTasks.length}`;
388
+ }
389
+ },
390
+ },
391
+ );
392
+ }
393
+
394
+ if (projectionFailed) {
395
+ clearNode(kpiEl);
396
+ kpiEl.appendChild(
397
+ el(
398
+ "p",
399
+ "empty",
400
+ "投影失败,状态分布与健康 KPI 不可用(避免将未知显示为健康 0)。",
401
+ ),
402
+ );
403
+ clearNode(attentionEl);
404
+ clearNode(readyEl);
405
+ clearNode(listEl);
406
+ emptyEl.hidden = true;
407
+ await refreshPoolEvents();
408
+ return;
409
+ }
410
+
411
+ if (!poolPresent && allTasks.length === 0) {
412
+ clearNode(kpiEl);
413
+ clearNode(attentionEl);
414
+ clearNode(readyEl);
415
+ clearNode(listEl);
416
+ emptyEl.hidden = false;
417
+ mountViewState(
418
+ emptyEl,
419
+ "empty",
420
+ "当前仓库未使用 Task Pool(未发现 .harness/task-pool)。",
421
+ );
422
+ await refreshPoolEvents();
423
+ return;
424
+ }
425
+
426
+ emptyEl.hidden = !(poolPresent && allTasks.length === 0);
427
+ if (!emptyEl.hidden) {
428
+ mountViewState(emptyEl, "empty", "Task Pool 已存在,但当前没有 Task。");
429
+ }
430
+
431
+ // L1 health — always from full pool, not filtered set
432
+ reconcileKeyed(kpiEl, [{ key: "__heading__" }], {
433
+ getKey: () => "__heading__",
434
+ scope: "heading",
435
+ create: () => el("h3", "section-heading", "池健康"),
436
+ update: () => {},
437
+ });
438
+ reconcileKeyed(kpiEl, [{ key: "__cards__" }], {
439
+ getKey: () => "__cards__",
440
+ scope: "cards",
441
+ create: () => el("div", "kpi-grid pool-health-grid"),
442
+ update: (cards) => {
443
+ const entries = [
444
+ ["运行中", counts.running, counts.running > 0 ? "kpi-highlight" : ""],
445
+ [
446
+ "阻塞/失联",
447
+ counts.blocked,
448
+ counts.blocked > 0 ? "kpi-risk" : "",
449
+ ],
450
+ ["失败", counts.failed, counts.failed > 0 ? "kpi-danger" : ""],
451
+ [
452
+ "Ready",
453
+ readyItems.length,
454
+ readyItems.length > 0 ? "kpi-highlight" : "",
455
+ ],
456
+ [
457
+ "无输出",
458
+ health.quietCount ?? 0,
459
+ (health.quietCount ?? 0) > 0 ? "kpi-muted" : "",
460
+ ],
461
+ [
462
+ "即将超时",
463
+ health.timeoutRiskCount ?? 0,
464
+ (health.timeoutRiskCount ?? 0) > 0 ? "kpi-risk" : "",
465
+ ],
466
+ ["合计", allTasks.length, ""],
467
+ ];
468
+ reconcileKeyed(cards, entries, {
469
+ getKey: ([label]) => label,
470
+ create: ([label, value, extra]) => {
471
+ const card = el("div", `kpi-card${extra ? ` ${extra}` : ""}`);
472
+ card.appendChild(el("div", "kpi-value", String(value)));
473
+ card.appendChild(el("div", "kpi-label", label));
474
+ return card;
475
+ },
476
+ update: (card, [label, value, extra]) => {
477
+ card.className = `kpi-card${extra ? ` ${extra}` : ""}`;
478
+ const valueEl = card.querySelector(".kpi-value");
479
+ const labelEl = card.querySelector(".kpi-label");
480
+ if (valueEl) valueEl.textContent = String(value);
481
+ if (labelEl) labelEl.textContent = label;
482
+ },
483
+ });
484
+ },
485
+ });
486
+
487
+ // L2 attention
488
+ reconcileKeyed(attentionEl, [{ key: "__heading__" }], {
489
+ getKey: () => "__heading__",
490
+ scope: "heading",
491
+ create: () => el("h3", "section-heading", "需处理"),
492
+ update: () => {},
493
+ });
494
+ reconcileKeyed(
495
+ attentionEl,
496
+ attentionTasks.length === 0
497
+ ? [{ key: "__empty__", text: "当前没有需要处理的 Task。" }]
498
+ : [{ key: "__list__" }],
499
+ {
500
+ getKey: (item) => item.key,
501
+ scope: "body",
502
+ create: (item) => {
503
+ if (item.key === "__empty__") return el("p", "empty", item.text);
504
+ return el("div", "pool-ops-list");
505
+ },
506
+ update: (node, item) => {
507
+ if (item.key === "__empty__") {
508
+ node.textContent = item.text;
509
+ return;
510
+ }
511
+ reconcileKeyed(node, attentionTasks, {
512
+ getKey: (task) => taskIdentityKey(task.featureId, task.taskId),
513
+ create: (task) => renderOpsCard(task, "attention"),
514
+ update: (card, task) => updateOpsCard(card, task),
515
+ });
516
+ },
517
+ },
518
+ );
519
+
520
+ // L2 Ready — planner selected only
521
+ reconcileKeyed(readyEl, [{ key: "__heading__" }], {
522
+ getKey: () => "__heading__",
523
+ scope: "heading",
524
+ create: () => el("h3", "section-heading", "Ready(Planner)"),
525
+ update: () => {},
526
+ });
527
+ reconcileKeyed(
528
+ readyEl,
529
+ readyItems.length === 0
530
+ ? [{ key: "__empty__", text: "当前没有 Planner 选中的 Ready Task。" }]
531
+ : [{ key: "__list__" }],
532
+ {
533
+ getKey: (item) => item.key,
534
+ scope: "body",
535
+ create: (item) => {
536
+ if (item.key === "__empty__") return el("p", "empty", item.text);
537
+ return el("div", "pool-ops-list");
538
+ },
539
+ update: (node, item) => {
540
+ if (item.key === "__empty__") {
541
+ node.textContent = item.text;
542
+ return;
543
+ }
544
+ const taskByKey = new Map(
545
+ allTasks.map((t) => [taskIdentityKey(t.featureId, t.taskId), t]),
546
+ );
547
+ reconcileKeyed(node, readyItems, {
548
+ getKey: (ready) => taskIdentityKey(ready.featureId, ready.taskId),
549
+ create: (ready) => {
550
+ const live = taskByKey.get(
551
+ taskIdentityKey(ready.featureId, ready.taskId),
552
+ );
553
+ return renderOpsCard(
554
+ {
555
+ ...ready,
556
+ status: live?.status ?? "pending",
557
+ recommendedFollowUp: live?.recommendedFollowUp,
558
+ },
559
+ "ready",
560
+ );
561
+ },
562
+ update: (card, ready) => {
563
+ const live = taskByKey.get(
564
+ taskIdentityKey(ready.featureId, ready.taskId),
565
+ );
566
+ updateOpsCard(card, {
567
+ ...ready,
568
+ status: live?.status ?? "pending",
569
+ recommendedFollowUp: live?.recommendedFollowUp,
570
+ });
571
+ },
572
+ });
573
+ },
574
+ },
575
+ );
576
+
577
+ // L3 inventory
578
+ reconcileKeyed(listEl, [{ key: "__heading__" }], {
579
+ getKey: () => "__heading__",
580
+ scope: "heading",
581
+ create: () => el("h3", "section-heading", "全部 Task"),
582
+ update: () => {},
583
+ });
584
+ if (filteredTasks.length === 0) {
585
+ reconcileKeyed(
586
+ listEl,
587
+ [{ key: "__empty__", text: "没有匹配筛选条件的 Task。" }],
588
+ {
589
+ getKey: (item) => item.key,
590
+ scope: "table",
591
+ create: (item) => el("p", "empty", item.text),
592
+ update: (node, item) => {
593
+ node.textContent = item.text;
594
+ },
595
+ },
596
+ );
597
+ } else {
598
+ reconcileKeyed(listEl, [{ key: "__table__" }], {
599
+ getKey: () => "__table__",
600
+ scope: "table",
601
+ create: () => el("div", "pool-table-wrap"),
602
+ update: (wrap) => {
603
+ const tbody = ensureTable(wrap, [
604
+ "Task",
605
+ "Feature",
606
+ "状态",
607
+ "存活",
608
+ "最新 run",
609
+ "Batch / DAG",
610
+ "跟进",
611
+ "更新",
612
+ ]);
613
+ reconcileKeyed(tbody, filteredTasks, {
614
+ getKey: (task) => taskIdentityKey(task.featureId, task.taskId),
615
+ create: (task) => {
616
+ const tr = document.createElement("tr");
617
+ tr.classList.add("clickable");
618
+ tr.addEventListener("click", () => navigate(taskPath(task)));
619
+ for (let i = 0; i < 8; i++) tr.appendChild(document.createElement("td"));
620
+ return tr;
621
+ },
622
+ update: (tr, task) => {
623
+ syncCell(tr, 0, linkTo(taskPath(task), task.taskId));
624
+ syncCell(
625
+ tr,
626
+ 1,
627
+ task.featureId
628
+ ? objectRouteLink("feature", task.featureId, snapshot)
629
+ : "—",
630
+ );
631
+ syncCell(tr, 2, badge(task.status));
632
+ syncCell(
633
+ tr,
634
+ 3,
635
+ task.liveness ? livenessBadge(task.liveness) : "—",
636
+ );
637
+ syncCell(
638
+ tr,
639
+ 4,
640
+ task.workerRunId
641
+ ? linkTo(
642
+ `/run/${encodeURIComponent(task.workerRunId)}`,
643
+ task.workerRunId,
644
+ )
645
+ : "—",
646
+ );
647
+ const links = el("span", "pool-ref-links");
648
+ if (task.batchRunId) {
649
+ links.appendChild(
650
+ linkTo(
651
+ `/batch/${encodeURIComponent(task.batchRunId)}`,
652
+ task.batchRunId,
653
+ ),
654
+ );
655
+ }
656
+ if (task.dagRunId) {
657
+ if (links.childNodes.length) {
658
+ links.appendChild(document.createTextNode(" · "));
659
+ }
660
+ links.appendChild(
661
+ linkTo(
662
+ `/dag/${encodeURIComponent(task.dagRunId)}`,
663
+ task.dagRunId,
664
+ ),
665
+ );
666
+ }
667
+ syncCell(
668
+ tr,
669
+ 5,
670
+ links.childNodes.length ? links : "—",
671
+ );
672
+ syncCell(
673
+ tr,
674
+ 6,
675
+ task.recommendedFollowUp || task.failureCategory || "—",
676
+ );
677
+ syncCell(
678
+ tr,
679
+ 7,
680
+ formatAgo(task.updatedAt || task.finishedAt || task.startedAt),
681
+ );
682
+ },
683
+ });
684
+ },
685
+ });
686
+ }
687
+
688
+ if (options.reason === "manual" || options.reason === "auto") {
689
+ await refreshPoolEvents();
690
+ } else {
691
+ // Route entry: only load events if the operator already expanded them.
692
+ await refreshPoolEvents();
693
+ }
694
+ }
695
+
696
+ /** Enter pool view; auto-refresh stays off unless the user already enabled it. */
697
+ export function startPoolView() {
698
+ stopPoolAutoPolling();
699
+ syncPoolToolbar();
700
+ void renderPool({ reason: "route" }).then(() => {
701
+ if (poolAutoRefreshEnabled()) startPoolAutoPolling();
702
+ });
703
+ }
704
+
705
+ /** @deprecated Use startPoolView — kept as alias for older call sites/tests. */
706
+ export function startPoolPolling() {
707
+ startPoolView();
708
+ }