@tea-agent/loop-agent 0.26.0 → 0.26.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1056 -1020
- package/README.md +8 -3
- package/bin/loop-agent.js +21 -21
- package/dist/application/dag/generate-task-dag.js +33 -0
- package/dist/cli/command-definitions.js +25 -10
- package/dist/cli/help.js +4 -3
- package/dist/cli/program.js +43 -17
- package/dist/commands/cursor-prompt.js +6 -6
- package/dist/commands/import-prd.js +7 -2
- package/dist/commands/init.js +7 -5
- package/dist/commands/loop-benchmark.js +11 -11
- package/dist/commands/pi-reuse-benchmark.js +16 -16
- package/dist/commands/task-source-prepare.js +474 -0
- package/dist/executors/dag-pi-executor.js +40 -5
- package/dist/executors/shell-executor.js +111 -0
- package/dist/executors/shell-presets.js +12 -4
- package/dist/executors/shell-write-guard.js +161 -25
- package/dist/sidecars/cursor-prompt/executor.js +1 -1
- package/dist/task/config-types.js +6 -0
- package/dist/task/contract/constants.js +1 -0
- package/dist/task/contract/project.js +8 -0
- package/dist/task/contract/schema.js +1 -0
- package/dist/task/frontend-preflight.js +131 -0
- package/dist/task/runtime.js +2 -4
- package/dist/task/source-prepare/build-draft.js +224 -0
- package/dist/task/source-prepare/completeness.js +195 -0
- package/dist/task/source-prepare/index.js +7 -0
- package/dist/task/source-prepare/parse-intent.js +373 -0
- package/dist/task/source-prepare/path-policy.js +197 -0
- package/dist/task/source-prepare/prepare.js +506 -0
- package/dist/task/source-prepare/reference-integrity.js +274 -0
- package/dist/task/source-prepare/types.js +7 -0
- package/dist/worker/observability/read-model.js +134 -0
- package/dist/worker/observe/static/copy.js +67 -67
- package/dist/worker/observe/static/dag-layout.d.ts +31 -31
- package/dist/worker/observe/static/dag-layout.js +83 -83
- package/dist/worker/observe/static/dom.js +220 -220
- package/dist/worker/observe/static/relations.js +133 -133
- package/dist/worker/observe/static/router.js +93 -93
- package/dist/worker/observe/static/run-processing.js +148 -148
- package/dist/worker/observe/static/state.js +61 -0
- package/dist/worker/observe/static/styles.css +8 -0
- package/dist/worker/observe/static/views/batch.js +227 -227
- package/dist/worker/observe/static/views/dag-graph.js +248 -172
- package/dist/worker/observe/static/views/dag-inspector.js +374 -157
- package/dist/worker/observe/static/views/dag.js +4 -11
- package/dist/worker/observe/static/views/failures.js +143 -143
- package/dist/worker/observe/static/views/feature.js +492 -492
- package/dist/worker/observe/static/views/run.js +453 -453
- package/dist/worker/observe/static/views/shell.js +7 -7
- package/dist/worker/observe/static/views/timeline.js +163 -163
- package/dist/workflows/dag/backend-test-pytest-collection.js +277 -0
- package/dist/workflows/dag/canvas-observer.js +275 -275
- package/dist/workflows/dag/convergence/controller.js +110 -21
- package/dist/workflows/dag/frontend-implementation-contract.js +218 -17
- package/dist/workflows/dag/frontend-review-context.js +7 -1
- package/dist/workflows/dag/frontend-verification-trace.js +14 -3
- package/dist/workflows/dag/frontend-worktree-diff.js +14 -3
- package/dist/workflows/dag/init-hybrid.js +96 -34
- package/dist/workflows/dag/output-protocol.js +180 -7
- package/dist/workflows/dag/runner.js +141 -52
- package/dist/workflows/dag/types.js +4 -0
- package/dist/workflows/dag/validate.js +3 -2
- package/docs/skills/README.md +7 -7
- package/docs/templates/adr.md +60 -60
- package/docs/templates/agent-dag-authority-surface-audit.prompt.md +94 -94
- package/docs/templates/agent-dag-decision-envelope.schema.json +213 -213
- package/docs/templates/agent-dag-decision-gate.prompt.md +246 -246
- package/docs/templates/agent-dag-process-supervisor.prompt.md +98 -98
- package/docs/templates/agent-dag-report.schema.json +473 -473
- package/docs/templates/agent-dag-review-verdict.prompt.md +68 -68
- package/docs/templates/backend-test-dag.json +100 -8
- package/docs/templates/backend-test-result.schema.json +99 -99
- package/docs/templates/feature-spec.md +53 -53
- package/docs/templates/frontend-design-contract.md +42 -42
- package/docs/templates/frontend-eval/fixtures/failures/01-type-build-error.md +17 -17
- package/docs/templates/frontend-eval/fixtures/failures/02-unit-component-test-fail.md +16 -16
- package/docs/templates/frontend-eval/fixtures/failures/03-fixture-schema-drift.md +16 -16
- package/docs/templates/frontend-eval/fixtures/failures/04-missing-loading-empty-error-state.md +16 -16
- package/docs/templates/frontend-eval/fixtures/failures/05-forbidden-write-writeset-expansion.md +16 -16
- package/docs/templates/frontend-eval/fixtures/failures/06-unapproved-dependency-add.md +16 -16
- package/docs/templates/frontend-eval/fixtures/failures/07-mock-production-on.md +21 -21
- package/docs/templates/frontend-eval/fixtures/functional/01-simple-component-style.md +29 -29
- package/docs/templates/frontend-eval/fixtures/functional/02-form-validation.md +28 -28
- package/docs/templates/frontend-eval/fixtures/functional/03-list-detail-page.md +28 -28
- package/docs/templates/frontend-eval/fixtures/functional/04-api-mock.md +29 -29
- package/docs/templates/frontend-eval/fixtures/functional/05-permission-auth-gated-ui.md +27 -27
- package/docs/templates/frontend-eval/fixtures/functional/06-ssr-server-client-boundary.md +28 -28
- package/docs/templates/frontend-eval/fixtures/functional/07-shared-public-component-api.md +28 -28
- package/docs/templates/frontend-eval/fixtures/functional/08-pure-local-no-remote.md +27 -27
- package/docs/templates/frontend-eval/metrics.md +138 -138
- package/docs/templates/frontend-eval/smoke-targets.md +53 -53
- package/docs/templates/frontend-task-constraints.md +35 -35
- package/docs/templates/frontend-task-requirement.md +70 -70
- package/docs/templates/init-evolution-review.md +35 -35
- package/docs/templates/init-managed-agents.md +10 -5
- package/docs/templates/interactive-ui-round2-experiment.md +66 -66
- package/docs/templates/knowledge-graph-bootstrap-dag.json +118 -118
- package/docs/templates/knowledge-sync-dag.json +178 -178
- package/docs/templates/knowledge-sync-draft.schema.json +71 -71
- package/docs/templates/product-line/closeout.yaml +9 -9
- package/docs/templates/product-line/design.md +13 -13
- package/docs/templates/product-line/links.md +10 -10
- package/docs/templates/product-line/requirement.md +17 -17
- package/docs/templates/product-line/test-plan.md +7 -7
- package/docs/templates/production-readiness-checklist.md +57 -57
- package/docs/templates/project-start-checklist.md +9 -9
- package/docs/templates/qa-report.md +48 -48
- package/docs/templates/sprint-contract.md +29 -29
- package/docs/templates/worker-dogfood-evidence.md +80 -80
- package/docs/templates/worker-dogfood-setup.md +68 -68
- package/package.json +1 -1
- package/scripts/kb-bootstrap-init-skeleton.sh +0 -0
- package/scripts/kb-graph-incremental-prepare.mjs +386 -386
- package/scripts/kb-graph-materialize.mjs +105 -105
- package/scripts/kb-graph-promote.mjs +164 -164
- package/scripts/kb-query.mjs +554 -554
- package/skills/ai-engineering-context/SKILL.md +48 -48
- package/skills/analyze-product-dependencies/SKILL.md +67 -67
- package/skills/analyze-product-dependencies/agents/openai.yaml +4 -4
- package/skills/analyze-product-dependencies/references/api-documentation-schema.md +30 -30
- package/skills/analyze-product-dependencies/references/dependency-analysis-schema.md +28 -28
- package/skills/analyze-product-dependencies/references/example.md +76 -76
- package/skills/analyze-product-dependencies/references/forward-test-cases.md +35 -35
- package/skills/analyze-product-dependencies/references/input-contract.md +11 -11
- package/skills/analyze-product-dependencies/references/scouting-rules.md +61 -61
- package/skills/analyze-product-dependencies/scripts/test-validators.mjs +267 -267
- package/skills/analyze-product-dependencies/scripts/validate-api-documentation.mjs +101 -101
- package/skills/analyze-product-dependencies/scripts/validate-dependency-analysis.mjs +142 -142
- package/skills/analyze-product-dependencies/scripts/validate-product-requirement-input.mjs +76 -76
- package/skills/analyze-product-dependencies/scripts/validation-helpers.mjs +146 -146
- package/skills/analyze-product-requirements/SKILL.md +90 -90
- package/skills/analyze-product-requirements/agents/openai.yaml +4 -4
- package/skills/analyze-product-requirements/references/acceptance-criteria.md +91 -91
- package/skills/analyze-product-requirements/references/clarification-and-knowledge.md +56 -56
- package/skills/analyze-product-requirements/references/example.md +86 -86
- package/skills/analyze-product-requirements/references/forward-test-cases.md +66 -66
- package/skills/analyze-product-requirements/references/product-analysis-schema.md +32 -32
- package/skills/analyze-product-requirements/references/product-requirement-schema.md +33 -33
- package/skills/analyze-product-requirements/references/requirement-clarification-schema.md +35 -35
- package/skills/analyze-product-requirements/scripts/test-validators.mjs +193 -193
- package/skills/analyze-product-requirements/scripts/validate-product-analysis.mjs +69 -69
- package/skills/analyze-product-requirements/scripts/validate-product-requirement.mjs +97 -97
- package/skills/analyze-product-requirements/scripts/validate-requirement-clarification.mjs +98 -98
- package/skills/analyze-product-requirements/scripts/validation-helpers.mjs +156 -156
- package/skills/browser-tools/browser-content.js +103 -103
- package/skills/browser-tools/browser-cookies.js +35 -35
- package/skills/browser-tools/browser-eval.js +53 -53
- package/skills/browser-tools/browser-hn-scraper.js +108 -108
- package/skills/browser-tools/browser-nav.js +44 -44
- package/skills/browser-tools/browser-pick.js +162 -162
- package/skills/browser-tools/browser-screenshot.js +34 -34
- package/skills/browser-tools/browser-start.js +86 -86
- package/skills/browser-tools/package-lock.json +2556 -2556
- package/skills/browser-tools/package.json +19 -19
- package/skills/code-review-core/SKILL.md +20 -20
- package/skills/codebase-scout/SKILL.md +19 -19
- package/skills/grill-me/SKILL.md +10 -10
- package/skills/loop-agent/SKILL.md +5 -2
- package/skills/loop-agent/references/README.md +67 -67
- package/skills/loop-agent/references/command-reference.md +17 -15
- package/skills/loop-agent/references/docs-converge.md +126 -126
- package/skills/loop-agent/references/harness-policy.md +3 -4
- package/skills/loop-agent/references/hybrid-dag.md +1 -1
- package/skills/loop-agent/references/learned/README.md +21 -21
- package/skills/loop-agent/references/long-running-loop.md +57 -57
- package/skills/loop-agent/references/one-shot-runs.md +85 -85
- package/skills/loop-agent/references/pi-prompt.md +23 -23
- package/skills/loop-agent/references/pi-subagent-assisted-mode.md +84 -84
- package/skills/loop-agent/references/post-implementation-and-patterns.md +1 -1
- package/skills/loop-agent/references/source-and-plan-practice.md +3 -2
- package/skills/loop-agent/references/task-workflow.md +7 -5
- package/skills/playwright-cli/SKILL.md +420 -420
- package/skills/playwright-cli/references/element-attributes.md +23 -23
- package/skills/playwright-cli/references/playwright-tests.md +39 -39
- package/skills/playwright-cli/references/request-mocking.md +87 -87
- package/skills/playwright-cli/references/running-code.md +241 -241
- package/skills/playwright-cli/references/session-management.md +225 -225
- package/skills/playwright-cli/references/storage-state.md +275 -275
- package/skills/playwright-cli/references/test-generation.md +433 -433
- package/skills/playwright-cli/references/tracing.md +139 -139
- package/skills/playwright-cli/references/video-recording.md +143 -143
- package/skills/requesting-code-review/SKILL.md +101 -101
- package/skills/requesting-code-review/code-reviewer.md +168 -168
- package/skills/systematic-debugging/CREATION-LOG.md +119 -119
- package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -158
- package/skills/systematic-debugging/condition-based-waiting.md +115 -115
- package/skills/systematic-debugging/defense-in-depth.md +122 -122
- package/skills/systematic-debugging/find-polluter.sh +63 -63
- package/skills/systematic-debugging/root-cause-tracing.md +169 -169
- package/skills/systematic-debugging/test-academic.md +14 -14
- package/skills/systematic-debugging/test-pressure-1.md +58 -58
- package/skills/systematic-debugging/test-pressure-2.md +68 -68
- package/skills/systematic-debugging/test-pressure-3.md +69 -69
- package/skills/using-git-worktrees/SKILL.md +215 -215
- package/skills/verification-before-completion/SKILL.md +154 -154
- package/skills/webapp-testing/SKILL.md +19 -19
|
@@ -1,172 +1,248 @@
|
|
|
1
|
-
/** DAG dependency graph rendering (Observe UI R5). */
|
|
2
|
-
import { layoutDag } from "../dag-layout.js";
|
|
3
|
-
import { el } from "../dom.js";
|
|
4
|
-
import {
|
|
5
|
-
statusLabel,
|
|
6
|
-
statusSymbol,
|
|
7
|
-
formatMs,
|
|
8
|
-
truncateText,
|
|
9
|
-
} from "../format.js";
|
|
10
|
-
import {
|
|
11
|
-
uiState,
|
|
12
|
-
dagGraphViewportStates,
|
|
13
|
-
updateDagGraphViewportState,
|
|
14
|
-
} from "../state.js";
|
|
15
|
-
import { selectDagNode } from "./dag-inspector.js";
|
|
16
|
-
|
|
17
|
-
export function svgEl(tag, attrs = {}) {
|
|
18
|
-
const node = document.createElementNS("http://www.w3.org/2000/svg", tag);
|
|
19
|
-
for (const [key, value] of Object.entries(attrs))
|
|
20
|
-
node.setAttribute(key, String(value));
|
|
21
|
-
return node;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function renderDagGraph(dag, dagRunId, existingWrap = null) {
|
|
25
|
-
const nodes = dag.nodes ?? [];
|
|
26
|
-
const edges = dag.edges ?? [];
|
|
27
|
-
const layout = layoutDag(nodes, edges, dag.ranks ?? []);
|
|
28
|
-
const wrap = existingWrap ?? el("div", "dag-graph-wrap");
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
()
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
1
|
+
/** DAG dependency graph rendering (Observe UI R5). */
|
|
2
|
+
import { layoutDag } from "../dag-layout.js";
|
|
3
|
+
import { el } from "../dom.js";
|
|
4
|
+
import {
|
|
5
|
+
statusLabel,
|
|
6
|
+
statusSymbol,
|
|
7
|
+
formatMs,
|
|
8
|
+
truncateText,
|
|
9
|
+
} from "../format.js";
|
|
10
|
+
import {
|
|
11
|
+
uiState,
|
|
12
|
+
dagGraphViewportStates,
|
|
13
|
+
updateDagGraphViewportState,
|
|
14
|
+
} from "../state.js";
|
|
15
|
+
import { selectDagNode } from "./dag-inspector.js";
|
|
16
|
+
|
|
17
|
+
export function svgEl(tag, attrs = {}) {
|
|
18
|
+
const node = document.createElementNS("http://www.w3.org/2000/svg", tag);
|
|
19
|
+
for (const [key, value] of Object.entries(attrs))
|
|
20
|
+
node.setAttribute(key, String(value));
|
|
21
|
+
return node;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function renderDagGraph(dag, dagRunId, existingWrap = null) {
|
|
25
|
+
const nodes = dag.nodes ?? [];
|
|
26
|
+
const edges = dag.edges ?? [];
|
|
27
|
+
const layout = layoutDag(nodes, edges, dag.ranks ?? []);
|
|
28
|
+
const wrap = existingWrap ?? el("div", "dag-graph-wrap");
|
|
29
|
+
// Preserve .dag-graph-viewport DOM identity across poll refreshes so the
|
|
30
|
+
// user's active scroll/pointer target is not destroyed mid-gesture.
|
|
31
|
+
let viewport =
|
|
32
|
+
existingWrap?.querySelector?.(":scope > .dag-graph-viewport") ??
|
|
33
|
+
existingWrap?.querySelector?.(".dag-graph-viewport") ??
|
|
34
|
+
null;
|
|
35
|
+
if (existingWrap) {
|
|
36
|
+
// Remove only non-interactive siblings. Keeping the viewport connected is
|
|
37
|
+
// important: detaching and re-inserting the same node still cancels a native
|
|
38
|
+
// scrollbar drag/pointer target even though object identity is unchanged.
|
|
39
|
+
for (const child of [...wrap.children]) {
|
|
40
|
+
if (child !== viewport) wrap.removeChild(child);
|
|
41
|
+
}
|
|
42
|
+
if (viewport) {
|
|
43
|
+
while (viewport.firstChild) viewport.removeChild(viewport.firstChild);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const toolbar = el("div", "dag-graph-toolbar");
|
|
47
|
+
let summaryText = `${nodes.length} 节点 · ${layout.edges.length} 条依赖`;
|
|
48
|
+
const convergence = dag.convergence;
|
|
49
|
+
if (convergence?.enabled) {
|
|
50
|
+
summaryText += ` · pass ${convergence.currentPass}/${convergence.maxPasses}`;
|
|
51
|
+
if (convergence.terminalReason) {
|
|
52
|
+
summaryText += ` · ${convergence.terminalReason}`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
toolbar.appendChild(el("span", "dag-graph-summary", summaryText));
|
|
56
|
+
const reset = el("button", "dag-graph-reset", "重置视图");
|
|
57
|
+
toolbar.appendChild(reset);
|
|
58
|
+
const appendBeforeViewport = (child) => {
|
|
59
|
+
if (viewport?.parentNode === wrap) wrap.insertBefore(child, viewport);
|
|
60
|
+
else wrap.appendChild(child);
|
|
61
|
+
};
|
|
62
|
+
appendBeforeViewport(toolbar);
|
|
63
|
+
if (edges.length === 0) {
|
|
64
|
+
appendBeforeViewport(
|
|
65
|
+
el(
|
|
66
|
+
"p",
|
|
67
|
+
"dag-graph-fallback",
|
|
68
|
+
"该运行没有可用依赖数据;图按并行层级展示,节点表格仍保留完整数据。",
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
if (!viewport) {
|
|
73
|
+
viewport = el("div", "dag-graph-viewport");
|
|
74
|
+
}
|
|
75
|
+
viewport.dataset.dagRunId = dagRunId;
|
|
76
|
+
const svg = svgEl("svg", {
|
|
77
|
+
class: "dag-graph",
|
|
78
|
+
viewBox: `0 0 ${layout.width} ${layout.height}`,
|
|
79
|
+
width: layout.width,
|
|
80
|
+
height: layout.height,
|
|
81
|
+
role: "img",
|
|
82
|
+
"aria-label": `DAG 依赖图,共 ${nodes.length} 个节点`,
|
|
83
|
+
});
|
|
84
|
+
const defs = svgEl("defs");
|
|
85
|
+
const marker = svgEl("marker", {
|
|
86
|
+
id: "dag-arrow",
|
|
87
|
+
viewBox: "0 0 10 10",
|
|
88
|
+
refX: 9,
|
|
89
|
+
refY: 5,
|
|
90
|
+
markerWidth: 7,
|
|
91
|
+
markerHeight: 7,
|
|
92
|
+
orient: "auto-start-reverse",
|
|
93
|
+
});
|
|
94
|
+
marker.appendChild(svgEl("path", { d: "M 0 0 L 10 5 L 0 10 z" }));
|
|
95
|
+
defs.appendChild(marker);
|
|
96
|
+
const controlMarker = svgEl("marker", {
|
|
97
|
+
id: "dag-arrow-control",
|
|
98
|
+
viewBox: "0 0 10 10",
|
|
99
|
+
refX: 9,
|
|
100
|
+
refY: 5,
|
|
101
|
+
markerWidth: 7,
|
|
102
|
+
markerHeight: 7,
|
|
103
|
+
orient: "auto-start-reverse",
|
|
104
|
+
});
|
|
105
|
+
controlMarker.appendChild(svgEl("path", { d: "M 0 0 L 10 5 L 0 10 z" }));
|
|
106
|
+
defs.appendChild(controlMarker);
|
|
107
|
+
svg.appendChild(defs);
|
|
108
|
+
const related = new Set([uiState.selectedDagNodeId]);
|
|
109
|
+
for (const edge of layout.edges)
|
|
110
|
+
if (
|
|
111
|
+
edge.from === uiState.selectedDagNodeId ||
|
|
112
|
+
edge.to === uiState.selectedDagNodeId
|
|
113
|
+
) {
|
|
114
|
+
related.add(edge.from);
|
|
115
|
+
related.add(edge.to);
|
|
116
|
+
}
|
|
117
|
+
for (const edge of layout.edges) {
|
|
118
|
+
const path = svgEl("path", {
|
|
119
|
+
d: edge.path,
|
|
120
|
+
class: `dag-edge${uiState.selectedDagNodeId && (!related.has(edge.from) || !related.has(edge.to)) ? " dag-dimmed" : ""}`,
|
|
121
|
+
"marker-end": "url(#dag-arrow)",
|
|
122
|
+
});
|
|
123
|
+
path.appendChild(svgEl("title"));
|
|
124
|
+
path.firstChild.textContent = `${edge.from} → ${edge.to}`;
|
|
125
|
+
svg.appendChild(path);
|
|
126
|
+
}
|
|
127
|
+
// 控制回环:仅由 read model 派生(dag.controlEdges),不进 layout、不参与拓扑。
|
|
128
|
+
// 路径从 review-gate-shell 左侧绕回 repair-pi 右侧,避开节点矩形。
|
|
129
|
+
const layoutByNode = new Map(layout.nodes.map((n) => [n.nodeId, n]));
|
|
130
|
+
for (const ctrl of dag.controlEdges ?? []) {
|
|
131
|
+
const from = layoutByNode.get(ctrl.from);
|
|
132
|
+
const to = layoutByNode.get(ctrl.to);
|
|
133
|
+
if (!from || !to) continue;
|
|
134
|
+
const x1 = from.x;
|
|
135
|
+
const y1 = from.y + from.height / 2;
|
|
136
|
+
const x2 = to.x + to.width;
|
|
137
|
+
const y2 = to.y + to.height / 2;
|
|
138
|
+
const lift = Math.max(48, (from.x - to.x) / 2);
|
|
139
|
+
const rise = Math.max(40, Math.abs(from.y - to.y) / 2 + 16);
|
|
140
|
+
const path = svgEl("path", {
|
|
141
|
+
d: `M ${x1} ${y1} C ${x1 - lift} ${y1 - rise}, ${x2 + lift} ${y2 - rise}, ${x2} ${y2}`,
|
|
142
|
+
class: "dag-edge dag-edge-control",
|
|
143
|
+
"marker-end": "url(#dag-arrow-control)",
|
|
144
|
+
});
|
|
145
|
+
path.appendChild(svgEl("title"));
|
|
146
|
+
path.firstChild.textContent = `${ctrl.from} → ${ctrl.to} (control loop)`;
|
|
147
|
+
svg.appendChild(path);
|
|
148
|
+
}
|
|
149
|
+
const byId = Object.fromEntries(nodes.map((node) => [node.nodeId, node]));
|
|
150
|
+
for (const position of layout.nodes) {
|
|
151
|
+
const node = byId[position.nodeId] ?? { nodeId: position.nodeId };
|
|
152
|
+
const status = (node.status ?? "unknown").toLowerCase();
|
|
153
|
+
const group = svgEl("g", {
|
|
154
|
+
transform: `translate(${position.x} ${position.y})`,
|
|
155
|
+
class: `dag-graph-node status-${status}${node.nodeId === uiState.selectedDagNodeId ? " selected" : ""}${uiState.selectedDagNodeId && !related.has(node.nodeId) ? " dag-dimmed" : ""}`,
|
|
156
|
+
tabindex: 0,
|
|
157
|
+
role: "button",
|
|
158
|
+
"aria-label": `${node.nodeId},状态 ${status}`,
|
|
159
|
+
});
|
|
160
|
+
group.appendChild(
|
|
161
|
+
svgEl("rect", { width: position.width, height: position.height, rx: 10 }),
|
|
162
|
+
);
|
|
163
|
+
const title = svgEl("title");
|
|
164
|
+
title.textContent = `${node.nodeId}\n${node.executor ?? "未知执行器"}\n${status}`;
|
|
165
|
+
group.appendChild(title);
|
|
166
|
+
const label = svgEl("text", { x: 14, y: 26, class: "dag-node-label" });
|
|
167
|
+
label.textContent = truncateText(node.label ?? node.nodeId, 26);
|
|
168
|
+
group.appendChild(label);
|
|
169
|
+
const executor = svgEl("text", { x: 14, y: 50, class: "dag-node-meta" });
|
|
170
|
+
executor.textContent = `◈ ${node.executor ?? "unknown"}`;
|
|
171
|
+
group.appendChild(executor);
|
|
172
|
+
const state = svgEl("text", { x: 14, y: 74, class: "dag-node-status" });
|
|
173
|
+
let stateText = `${statusSymbol(status)} ${statusLabel(node.status)} · ${formatMs(node.durationMs)}`;
|
|
174
|
+
if (node.passes?.length) {
|
|
175
|
+
stateText += ` · P${node.passes.join(",")}`;
|
|
176
|
+
}
|
|
177
|
+
if (node.attemptCount > 0) {
|
|
178
|
+
stateText += ` · attempt ${node.attemptCount}`;
|
|
179
|
+
}
|
|
180
|
+
state.textContent = stateText;
|
|
181
|
+
group.appendChild(state);
|
|
182
|
+
const activate = () => selectDagNode(dagRunId, node.nodeId);
|
|
183
|
+
group.addEventListener("click", activate);
|
|
184
|
+
group.addEventListener("keydown", (event) => {
|
|
185
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
activate();
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
svg.appendChild(group);
|
|
191
|
+
}
|
|
192
|
+
viewport.appendChild(svg);
|
|
193
|
+
if (viewport.parentNode !== wrap) wrap.appendChild(viewport);
|
|
194
|
+
const graphViewportState =
|
|
195
|
+
dagGraphViewportStates.get(dagRunId) ??
|
|
196
|
+
(uiState.dagGraphViewportState?.dagRunId === dagRunId
|
|
197
|
+
? uiState.dagGraphViewportState
|
|
198
|
+
: null);
|
|
199
|
+
// Bind scroll capture once per viewport instance so reuse does not stack listeners.
|
|
200
|
+
if (viewport.dataset.scrollBound !== "1") {
|
|
201
|
+
viewport.dataset.scrollBound = "1";
|
|
202
|
+
viewport.addEventListener(
|
|
203
|
+
"scroll",
|
|
204
|
+
() => {
|
|
205
|
+
const id = viewport.dataset.dagRunId;
|
|
206
|
+
if (!id) return;
|
|
207
|
+
uiState.dagGraphViewportState = updateDagGraphViewportState(
|
|
208
|
+
uiState.dagGraphViewportState,
|
|
209
|
+
id,
|
|
210
|
+
viewport.scrollLeft,
|
|
211
|
+
viewport.scrollTop,
|
|
212
|
+
);
|
|
213
|
+
dagGraphViewportStates.set(id, uiState.dagGraphViewportState);
|
|
214
|
+
},
|
|
215
|
+
{ passive: true },
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
if (graphViewportState) {
|
|
219
|
+
const restoreViewport = () => {
|
|
220
|
+
if (viewport.dataset.dagRunId !== dagRunId) return;
|
|
221
|
+
viewport.scrollLeft = graphViewportState.scrollLeft;
|
|
222
|
+
viewport.scrollTop = graphViewportState.scrollTop;
|
|
223
|
+
};
|
|
224
|
+
// Apply immediately so identity reuse keeps position even before paint,
|
|
225
|
+
// then again on rAF after SVG layout settles.
|
|
226
|
+
restoreViewport();
|
|
227
|
+
if (typeof requestAnimationFrame === "function") {
|
|
228
|
+
requestAnimationFrame(restoreViewport);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// Toolbar is rebuilt each paint; bind reset to the current viewport/dagRunId.
|
|
232
|
+
reset.addEventListener("click", () => {
|
|
233
|
+
uiState.dagGraphViewportState = updateDagGraphViewportState(
|
|
234
|
+
uiState.dagGraphViewportState,
|
|
235
|
+
dagRunId,
|
|
236
|
+
0,
|
|
237
|
+
0,
|
|
238
|
+
);
|
|
239
|
+
dagGraphViewportStates.set(dagRunId, uiState.dagGraphViewportState);
|
|
240
|
+
if (typeof viewport.scrollTo === "function") {
|
|
241
|
+
viewport.scrollTo({ left: 0, top: 0, behavior: "smooth" });
|
|
242
|
+
} else {
|
|
243
|
+
viewport.scrollLeft = 0;
|
|
244
|
+
viewport.scrollTop = 0;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
return wrap;
|
|
248
|
+
}
|