@tea-agent/loop-agent 0.11.0 → 0.13.0-alpha.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.
- package/CHANGELOG.md +74 -1
- package/README.md +33 -4
- package/dist/application/dag/generate-task-dag.js +45 -0
- package/dist/application/dag/run-dag.js +10 -0
- package/dist/application/dag/validate-dag.js +11 -0
- package/dist/cli/command-definitions.js +10 -3
- package/dist/commands/init.js +74 -7
- package/dist/commands/knowledge.js +129 -31
- package/dist/governance/manifest-types.js +3 -0
- package/dist/shared/package-metadata.js +135 -0
- package/dist/task/config-types.js +6 -1
- package/dist/worker/cli.js +99 -2
- package/dist/worker/delivery/package.js +3 -3
- package/dist/worker/feature/decision-loader.js +37 -6
- package/dist/worker/feature/next-action.js +10 -2
- package/dist/worker/feature/ready-plan-projection.js +81 -0
- package/dist/worker/feature/reducer.js +2 -1
- package/dist/worker/feature/review.js +19 -2
- package/dist/worker/feature/run.js +27 -2
- package/dist/worker/follow-up/approve.js +5 -2
- package/dist/worker/follow-up/factory.js +1 -1
- package/dist/worker/observability/event-history.js +216 -0
- package/dist/worker/observability/read-model.js +552 -118
- package/dist/worker/observe/paths.js +17 -0
- package/dist/worker/observe/routes.js +310 -23
- package/dist/worker/observe/server.js +59 -1
- package/dist/worker/observe/spec-evidence.js +281 -0
- package/dist/worker/observe/static/api.js +46 -0
- package/dist/worker/observe/static/app.js +120 -2598
- package/dist/worker/observe/static/constants.js +148 -0
- package/dist/worker/observe/static/copy.js +67 -0
- package/dist/worker/observe/static/dag-helpers.js +172 -0
- package/dist/worker/observe/static/dag-model.js +72 -0
- package/dist/worker/observe/static/dom.js +61 -0
- package/dist/worker/observe/static/format-pool.js +67 -0
- package/dist/worker/observe/static/format.js +292 -0
- package/dist/worker/observe/static/index.html +300 -82
- package/dist/worker/observe/static/kpi.js +94 -0
- package/dist/worker/observe/static/relations.js +133 -0
- package/dist/worker/observe/static/router.js +93 -0
- package/dist/worker/observe/static/run-processing.js +148 -0
- package/dist/worker/observe/static/shell-chrome.js +68 -0
- package/dist/worker/observe/static/state.js +253 -0
- package/dist/worker/observe/static/styles.css +1731 -495
- package/dist/worker/observe/static/views/batch.js +227 -0
- package/dist/worker/observe/static/views/dag-graph.js +172 -0
- package/dist/worker/observe/static/views/dag-inspector.js +596 -0
- package/dist/worker/observe/static/views/dag.js +362 -0
- package/dist/worker/observe/static/views/dashboard.js +445 -0
- package/dist/worker/observe/static/views/failures.js +143 -0
- package/dist/worker/observe/static/views/feature.js +492 -0
- package/dist/worker/observe/static/views/pool.js +350 -0
- package/dist/worker/observe/static/views/run.js +453 -0
- package/dist/worker/observe/static/views/session-timeline.js +205 -0
- package/dist/worker/observe/static/views/shell.js +7 -0
- package/dist/worker/observe/static/views/task.js +314 -0
- package/dist/worker/observe/static/views/timeline.js +163 -0
- package/dist/worker/pool/doctor.js +165 -0
- package/dist/worker/pool/migrate-state.js +303 -0
- package/dist/worker/pool/run-store.js +205 -17
- package/dist/worker/pool/types.js +17 -1
- package/dist/worker/pool/validation.js +100 -15
- package/dist/worker/report/morning-report.js +12 -2
- package/dist/worker/runner/run-ready.js +41 -26
- package/dist/worker/task-graph/ready-planner.js +136 -0
- package/dist/workflows/dag/controller-identity.js +104 -0
- package/dist/workflows/dag/convergence/controller.js +16 -8
- package/dist/workflows/dag/failure-routing.js +12 -1
- package/dist/workflows/dag/init-hybrid.js +1233 -11
- package/dist/workflows/dag/node-execution.js +123 -29
- package/dist/workflows/dag/repair-artifact.js +91 -0
- package/dist/workflows/dag/report.js +50 -0
- package/dist/workflows/dag/retry-policy.js +138 -0
- package/dist/workflows/dag/runner.js +32 -0
- package/dist/workflows/dag/runtime-contract.js +87 -0
- package/dist/workflows/dag/skill-snapshot.js +2 -0
- package/dist/workflows/dag/types.js +45 -1
- package/dist/workflows/dag/validate.js +68 -4
- package/docs/README.md +1 -1
- package/docs/agent-dag-recovery-playbook.md +9 -0
- package/docs/agent-dag-runner.md +26 -1
- package/docs/architecture/dag-execution.md +6 -0
- package/docs/architecture/evolution.md +7 -5
- package/docs/architecture/facts-and-state.md +15 -2
- package/docs/architecture/worker-and-feature.md +6 -2
- package/docs/decisions/README.md +3 -0
- package/docs/design/README.md +12 -3
- package/docs/exec-plans/active/README.md +2 -2
- package/docs/exec-plans/completed/README.md +12 -0
- package/docs/feature-workflow.md +108 -2
- package/docs/loop-agent-harness.md +15 -4
- package/docs/progress/README.md +22 -0
- package/docs/reports/README.md +14 -2
- package/docs/templates/agent-dag-report.schema.json +17 -0
- package/docs/templates/agent-dag.schema.json +69 -1
- package/docs/templates/agent-dag.supervised-implementation.json +8 -2
- package/docs/templates/backend-test-dag.generate-pytest.prompt.md +139 -0
- package/docs/templates/backend-test-dag.json +288 -0
- package/docs/templates/backend-test-dag.retrospect.prompt.md +125 -0
- package/docs/templates/backend-test-dag.review-cases.prompt.md +81 -0
- package/docs/templates/knowledge-graph-bootstrap-dag.json +118 -0
- package/docs/templates/knowledge-sync-dag.json +177 -0
- package/docs/templates/knowledge-sync-draft.schema.json +71 -0
- package/docs/verification-matrix.md +2 -1
- package/package.json +8 -2
- package/scripts/kb-bootstrap-init-skeleton.sh +239 -0
- package/scripts/kb-graph-incremental-prepare.mjs +372 -0
- package/scripts/kb-graph-incremental-prepare.sh +5 -0
- package/scripts/kb-graph-materialize.mjs +105 -0
- package/scripts/kb-graph-materialize.sh +4 -0
- package/scripts/kb-graph-promote.mjs +153 -0
- package/scripts/kb-graph-promote.sh +4 -0
- package/scripts/kb-query.mjs +554 -0
- package/scripts/kb-query.sh +5 -0
- package/skills/agent-worker/SKILL.md +3 -1
- package/skills/agent-worker/references/agent-worker-operator.md +18 -1
- package/skills/frontend-design-review/SKILL.md +26 -24
- package/skills/frontend-implementation/SKILL.md +29 -26
- package/skills/frontend-implementation/references/node-contracts.md +50 -19
- package/skills/frontend-review/SKILL.md +1 -1
- package/skills/loop-agent/references/command-reference.md +2 -0
- package/skills/loop-agent/references/hybrid-dag.md +22 -3
- package/skills/loop-agent/references/verification-and-failure-handling.md +6 -0
|
@@ -0,0 +1,596 @@
|
|
|
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
|
+
updateDagTimelineViewportState,
|
|
17
|
+
updateDagOutputViewportState,
|
|
18
|
+
computeFollowLatest,
|
|
19
|
+
isInteractiveGestureActive,
|
|
20
|
+
} from "../state.js";
|
|
21
|
+
import {
|
|
22
|
+
formatSessionEventTime,
|
|
23
|
+
renderSessionTimeline,
|
|
24
|
+
} from "./session-timeline.js";
|
|
25
|
+
|
|
26
|
+
export function selectDagNode(dagRunId, nodeId) {
|
|
27
|
+
const nodeChanged = uiState.selectedDagNodeId !== nodeId;
|
|
28
|
+
uiState.selectedDagNodeId = nodeId;
|
|
29
|
+
uiState.dagInspectorOpen = true;
|
|
30
|
+
if (nodeChanged) {
|
|
31
|
+
uiState.sessionEventOffset = 0;
|
|
32
|
+
uiState.sessionEvents = [];
|
|
33
|
+
}
|
|
34
|
+
void import("./dag.js").then((m) => m.renderDagDetail(dagRunId, false));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function closeDagInspector() {
|
|
38
|
+
uiState.dagInspectorOpen = false;
|
|
39
|
+
const panel = document.getElementById("dag-inspector");
|
|
40
|
+
if (panel) {
|
|
41
|
+
panel.classList.remove("is-open");
|
|
42
|
+
panel.setAttribute("aria-hidden", "true");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function closeDagInspectorOnOutsideClick(event) {
|
|
47
|
+
if (!uiState.dagInspectorOpen || !(event.target instanceof Element)) return;
|
|
48
|
+
if (
|
|
49
|
+
event.target.closest(
|
|
50
|
+
"#dag-inspector, .dag-node-table tbody tr, button, a, input, select, textarea, [role='button'], [role='tab']",
|
|
51
|
+
)
|
|
52
|
+
) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
closeDagInspector();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function dagInspectorMaximumWidth() {
|
|
59
|
+
return Math.max(
|
|
60
|
+
DAG_INSPECTOR_MIN_WIDTH,
|
|
61
|
+
Math.min(
|
|
62
|
+
DAG_INSPECTOR_MAX_WIDTH,
|
|
63
|
+
window.innerWidth - DAG_INSPECTOR_VIEWPORT_MARGIN,
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function setDagInspectorWidth(panel, requestedWidth) {
|
|
69
|
+
const maximum = dagInspectorMaximumWidth();
|
|
70
|
+
uiState.dagInspectorWidth = Math.min(
|
|
71
|
+
maximum,
|
|
72
|
+
Math.max(DAG_INSPECTOR_MIN_WIDTH, Math.round(requestedWidth)),
|
|
73
|
+
);
|
|
74
|
+
panel.style.setProperty(
|
|
75
|
+
"--dag-inspector-width",
|
|
76
|
+
`${uiState.dagInspectorWidth}px`,
|
|
77
|
+
);
|
|
78
|
+
return {
|
|
79
|
+
minimum: DAG_INSPECTOR_MIN_WIDTH,
|
|
80
|
+
maximum,
|
|
81
|
+
value: uiState.dagInspectorWidth,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function createDagInspectorResizeHandle(panel) {
|
|
86
|
+
const handle = el("div", "dag-inspector-resize-handle");
|
|
87
|
+
handle.tabIndex = 0;
|
|
88
|
+
handle.setAttribute("role", "separator");
|
|
89
|
+
handle.setAttribute("aria-orientation", "vertical");
|
|
90
|
+
handle.setAttribute("aria-label", "调整节点检查器宽度");
|
|
91
|
+
handle.title = "拖动调整节点检查器宽度";
|
|
92
|
+
|
|
93
|
+
const updateRange = (requestedWidth) => {
|
|
94
|
+
const range = setDagInspectorWidth(
|
|
95
|
+
panel,
|
|
96
|
+
requestedWidth ??
|
|
97
|
+
uiState.dagInspectorWidth ??
|
|
98
|
+
DAG_INSPECTOR_DEFAULT_WIDTH,
|
|
99
|
+
);
|
|
100
|
+
handle.setAttribute("aria-valuemin", String(range.minimum));
|
|
101
|
+
handle.setAttribute("aria-valuemax", String(range.maximum));
|
|
102
|
+
handle.setAttribute("aria-valuenow", String(range.value));
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
updateRange();
|
|
106
|
+
handle.addEventListener("pointerdown", (event) => {
|
|
107
|
+
if (event.button !== 0) return;
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
handle.setPointerCapture(event.pointerId);
|
|
110
|
+
document.body.classList.add("is-resizing-dag-inspector");
|
|
111
|
+
});
|
|
112
|
+
handle.addEventListener("pointermove", (event) => {
|
|
113
|
+
if (!handle.hasPointerCapture(event.pointerId)) return;
|
|
114
|
+
updateRange(window.innerWidth - event.clientX - DAG_INSPECTOR_RIGHT_OFFSET);
|
|
115
|
+
});
|
|
116
|
+
const stopResizing = (event) => {
|
|
117
|
+
if (handle.hasPointerCapture(event.pointerId)) {
|
|
118
|
+
handle.releasePointerCapture(event.pointerId);
|
|
119
|
+
}
|
|
120
|
+
document.body.classList.remove("is-resizing-dag-inspector");
|
|
121
|
+
};
|
|
122
|
+
handle.addEventListener("pointerup", stopResizing);
|
|
123
|
+
handle.addEventListener("pointercancel", stopResizing);
|
|
124
|
+
handle.addEventListener("keydown", (event) => {
|
|
125
|
+
const currentWidth =
|
|
126
|
+
uiState.dagInspectorWidth ?? DAG_INSPECTOR_DEFAULT_WIDTH;
|
|
127
|
+
if (event.key === "ArrowLeft") {
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
updateRange(currentWidth + DAG_INSPECTOR_KEYBOARD_STEP);
|
|
130
|
+
} else if (event.key === "ArrowRight") {
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
updateRange(currentWidth - DAG_INSPECTOR_KEYBOARD_STEP);
|
|
133
|
+
} else if (event.key === "Home") {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
updateRange(DAG_INSPECTOR_MIN_WIDTH);
|
|
136
|
+
} else if (event.key === "End") {
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
updateRange(dagInspectorMaximumWidth());
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
return handle;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function captureDagTimelineViewportState(panel) {
|
|
145
|
+
const scrollEl = panel.querySelector(".process-timeline-scroll");
|
|
146
|
+
if (scrollEl?.dataset.dagRunId && scrollEl.dataset.nodeId) {
|
|
147
|
+
const followLatest = computeFollowLatest(
|
|
148
|
+
scrollEl.scrollTop,
|
|
149
|
+
scrollEl.scrollHeight,
|
|
150
|
+
scrollEl.clientHeight,
|
|
151
|
+
);
|
|
152
|
+
uiState.dagTimelineViewportState = updateDagTimelineViewportState(
|
|
153
|
+
uiState.dagTimelineViewportState,
|
|
154
|
+
scrollEl.dataset.dagRunId,
|
|
155
|
+
scrollEl.dataset.nodeId,
|
|
156
|
+
scrollEl.scrollLeft,
|
|
157
|
+
scrollEl.scrollTop,
|
|
158
|
+
followLatest,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function appendInlineMarkdown(target, text) {
|
|
164
|
+
const tokenPattern = /(`[^`]*`|\*\*[^*]+\*\*|\*[^*]+\*|\[[^\]]+\]\([^)]+\))/g;
|
|
165
|
+
let cursor = 0;
|
|
166
|
+
for (const match of text.matchAll(tokenPattern)) {
|
|
167
|
+
const index = match.index ?? 0;
|
|
168
|
+
if (index > cursor)
|
|
169
|
+
target.appendChild(document.createTextNode(text.slice(cursor, index)));
|
|
170
|
+
const token = match[0];
|
|
171
|
+
if (token.startsWith("`")) {
|
|
172
|
+
target.appendChild(el("code", null, token.slice(1, -1)));
|
|
173
|
+
} else if (token.startsWith("**")) {
|
|
174
|
+
const strong = document.createElement("strong");
|
|
175
|
+
strong.textContent = token.slice(2, -2);
|
|
176
|
+
target.appendChild(strong);
|
|
177
|
+
} else if (token.startsWith("*")) {
|
|
178
|
+
const emphasis = document.createElement("em");
|
|
179
|
+
emphasis.textContent = token.slice(1, -1);
|
|
180
|
+
target.appendChild(emphasis);
|
|
181
|
+
} else {
|
|
182
|
+
const link = token.match(/^\[([^\]]+)\]\((.+)\)$/);
|
|
183
|
+
const href = markdownLinkHref(link?.[2]);
|
|
184
|
+
if (link && href) {
|
|
185
|
+
const anchor = document.createElement("a");
|
|
186
|
+
anchor.href = href;
|
|
187
|
+
anchor.target = "_blank";
|
|
188
|
+
anchor.rel = "noopener noreferrer";
|
|
189
|
+
anchor.textContent = link[1];
|
|
190
|
+
target.appendChild(anchor);
|
|
191
|
+
} else {
|
|
192
|
+
target.appendChild(document.createTextNode(token));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
cursor = index + token.length;
|
|
196
|
+
}
|
|
197
|
+
if (cursor < text.length)
|
|
198
|
+
target.appendChild(document.createTextNode(text.slice(cursor)));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function renderMarkdown(content) {
|
|
202
|
+
const article = el("article", "markdown-output");
|
|
203
|
+
for (const block of parseMarkdownBlocks(content)) {
|
|
204
|
+
switch (block.type) {
|
|
205
|
+
case "heading": {
|
|
206
|
+
const heading = document.createElement(`h${block.level}`);
|
|
207
|
+
appendInlineMarkdown(heading, block.text);
|
|
208
|
+
article.appendChild(heading);
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
case "paragraph": {
|
|
212
|
+
const paragraph = document.createElement("p");
|
|
213
|
+
appendInlineMarkdown(paragraph, block.text);
|
|
214
|
+
article.appendChild(paragraph);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case "quote": {
|
|
218
|
+
const quote = document.createElement("blockquote");
|
|
219
|
+
appendInlineMarkdown(quote, block.text);
|
|
220
|
+
article.appendChild(quote);
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
case "list": {
|
|
224
|
+
const list = document.createElement(block.ordered ? "ol" : "ul");
|
|
225
|
+
for (const item of block.items) {
|
|
226
|
+
const listItem = document.createElement("li");
|
|
227
|
+
appendInlineMarkdown(listItem, item);
|
|
228
|
+
list.appendChild(listItem);
|
|
229
|
+
}
|
|
230
|
+
article.appendChild(list);
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
case "code": {
|
|
234
|
+
const pre = document.createElement("pre");
|
|
235
|
+
const code = document.createElement("code");
|
|
236
|
+
if (block.language) code.dataset.language = block.language;
|
|
237
|
+
code.textContent = block.text;
|
|
238
|
+
pre.appendChild(code);
|
|
239
|
+
article.appendChild(pre);
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
case "table": {
|
|
243
|
+
const table = document.createElement("table");
|
|
244
|
+
const head = document.createElement("thead");
|
|
245
|
+
const headRow = document.createElement("tr");
|
|
246
|
+
for (const value of block.headers) {
|
|
247
|
+
const cell = document.createElement("th");
|
|
248
|
+
appendInlineMarkdown(cell, value);
|
|
249
|
+
headRow.appendChild(cell);
|
|
250
|
+
}
|
|
251
|
+
head.appendChild(headRow);
|
|
252
|
+
table.appendChild(head);
|
|
253
|
+
const body = document.createElement("tbody");
|
|
254
|
+
for (const row of block.rows) {
|
|
255
|
+
const tableRow = document.createElement("tr");
|
|
256
|
+
for (const value of row) {
|
|
257
|
+
const cell = document.createElement("td");
|
|
258
|
+
appendInlineMarkdown(cell, value);
|
|
259
|
+
tableRow.appendChild(cell);
|
|
260
|
+
}
|
|
261
|
+
body.appendChild(tableRow);
|
|
262
|
+
}
|
|
263
|
+
table.appendChild(body);
|
|
264
|
+
article.appendChild(table);
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
case "rule":
|
|
268
|
+
article.appendChild(document.createElement("hr"));
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return article;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async function renderSpecEvidence(content, dagRunId, nodeId) {
|
|
276
|
+
const evidence = await fetchJson(
|
|
277
|
+
`/api/dag-runs/${encodeURIComponent(dagRunId)}/nodes/${encodeURIComponent(nodeId)}/spec-evidence`,
|
|
278
|
+
);
|
|
279
|
+
if (!content.isConnected || content.dataset.dagNodeId !== String(nodeId)) return;
|
|
280
|
+
if (!evidence) {
|
|
281
|
+
content.appendChild(el("p", "empty", "无法加载规范证据。"));
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const statusLabels = {
|
|
286
|
+
"spec-read": "已读取规范",
|
|
287
|
+
"spec-injected": "仅注入 skill",
|
|
288
|
+
"search-only": "仅执行检索",
|
|
289
|
+
"kb-queried": "已观察知识库查询",
|
|
290
|
+
"no-evidence": "未观察到读取",
|
|
291
|
+
};
|
|
292
|
+
const statusSection = el("div", "spec-evidence-section");
|
|
293
|
+
statusSection.appendChild(el("h4", null, "证据状态"));
|
|
294
|
+
statusSection.appendChild(
|
|
295
|
+
el(
|
|
296
|
+
"span",
|
|
297
|
+
`badge badge-${evidence.status === "spec-read" ? "succeeded" : evidence.status === "no-evidence" ? "failed" : "pending"}`,
|
|
298
|
+
statusLabels[evidence.status] ?? evidence.status,
|
|
299
|
+
),
|
|
300
|
+
);
|
|
301
|
+
if (evidence.summary) {
|
|
302
|
+
statusSection.appendChild(
|
|
303
|
+
el("p", "spec-evidence-summary", evidence.summary),
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
content.appendChild(statusSection);
|
|
307
|
+
|
|
308
|
+
const appendListSection = (title, entries, renderEntry) => {
|
|
309
|
+
if (!entries?.length) return;
|
|
310
|
+
const section = el("div", "spec-evidence-section");
|
|
311
|
+
section.appendChild(el("h4", null, title));
|
|
312
|
+
const list = el("ul", "spec-evidence-list");
|
|
313
|
+
for (const entry of entries) list.appendChild(renderEntry(entry));
|
|
314
|
+
section.appendChild(list);
|
|
315
|
+
content.appendChild(section);
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
appendListSection("注入的 Skill", evidence.skillInjection?.skills, (skill) => {
|
|
319
|
+
const item = el("li", null);
|
|
320
|
+
const icon = el("i", "ri-bookmark-line");
|
|
321
|
+
icon.setAttribute("aria-hidden", "true");
|
|
322
|
+
item.append(icon, document.createTextNode(` ${skill}`));
|
|
323
|
+
return item;
|
|
324
|
+
});
|
|
325
|
+
appendListSection(
|
|
326
|
+
`已读取规范文件(${evidence.specReads?.length ?? 0})`,
|
|
327
|
+
evidence.specReads,
|
|
328
|
+
(read) => {
|
|
329
|
+
const item = el("li", null);
|
|
330
|
+
const icon = el("i", "ri-file-text-line");
|
|
331
|
+
icon.setAttribute("aria-hidden", "true");
|
|
332
|
+
item.append(icon, el("code", null, read.path));
|
|
333
|
+
if (read.timestamp) {
|
|
334
|
+
item.appendChild(
|
|
335
|
+
el(
|
|
336
|
+
"span",
|
|
337
|
+
"spec-evidence-time",
|
|
338
|
+
formatSessionEventTime({ timestamp: read.timestamp }),
|
|
339
|
+
),
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
return item;
|
|
343
|
+
},
|
|
344
|
+
);
|
|
345
|
+
appendListSection(
|
|
346
|
+
`检索操作(${evidence.specSearches?.length ?? 0})`,
|
|
347
|
+
evidence.specSearches,
|
|
348
|
+
(search) => {
|
|
349
|
+
const item = el("li", null);
|
|
350
|
+
const icon = el("i", "ri-search-line");
|
|
351
|
+
icon.setAttribute("aria-hidden", "true");
|
|
352
|
+
item.append(icon, document.createTextNode(` ${search.tool}: ${search.query}`));
|
|
353
|
+
return item;
|
|
354
|
+
},
|
|
355
|
+
);
|
|
356
|
+
appendListSection(
|
|
357
|
+
`知识库查询(${evidence.knowledgeBaseQueries?.length ?? 0})`,
|
|
358
|
+
evidence.knowledgeBaseQueries,
|
|
359
|
+
(query) => {
|
|
360
|
+
const item = el("li", null);
|
|
361
|
+
const icon = el("i", "ri-database-2-line");
|
|
362
|
+
icon.setAttribute("aria-hidden", "true");
|
|
363
|
+
item.append(icon, document.createTextNode(` ${query.connector}`));
|
|
364
|
+
return item;
|
|
365
|
+
},
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
if (evidence.status === "spec-injected" || evidence.status === "no-evidence") {
|
|
369
|
+
const warning = el("div", "spec-evidence-warning");
|
|
370
|
+
const icon = el("i", "ri-alert-line");
|
|
371
|
+
icon.setAttribute("aria-hidden", "true");
|
|
372
|
+
warning.append(
|
|
373
|
+
icon,
|
|
374
|
+
document.createTextNode(
|
|
375
|
+
evidence.status === "no-evidence"
|
|
376
|
+
? "未观察到规范读取。只有 session event 中成功配对的 read 工具调用才算已读取,模型总结或文件名命中不能作为证明。"
|
|
377
|
+
: "规范 skill 已注入,但未观察到规范读取或知识库查询;grep/find/ls 只能证明检索,不能替代 read。",
|
|
378
|
+
),
|
|
379
|
+
);
|
|
380
|
+
content.appendChild(warning);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function fillDagInspectorContent(content, dagRunId, node) {
|
|
385
|
+
const activeTab = ["timeline", "spec-evidence"].includes(
|
|
386
|
+
uiState.dagInspectorTab,
|
|
387
|
+
)
|
|
388
|
+
? uiState.dagInspectorTab
|
|
389
|
+
: "output";
|
|
390
|
+
content.id = `dag-inspector-panel-${activeTab}`;
|
|
391
|
+
content.setAttribute("role", "tabpanel");
|
|
392
|
+
content.setAttribute("aria-labelledby", `dag-inspector-tab-${activeTab}`);
|
|
393
|
+
content.dataset.dagNodeId = String(node.nodeId ?? "");
|
|
394
|
+
if (activeTab === "spec-evidence") {
|
|
395
|
+
void renderSpecEvidence(content, dagRunId, node.nodeId);
|
|
396
|
+
} else if (activeTab === "timeline") {
|
|
397
|
+
renderSessionTimeline(content, node.nodeId);
|
|
398
|
+
} else if (!node.outputPreview && !node.errorPreview) {
|
|
399
|
+
content.appendChild(el("p", "empty", UI_TEXT.noOutput));
|
|
400
|
+
} else {
|
|
401
|
+
if (node.outputPreview)
|
|
402
|
+
content.appendChild(renderMarkdown(node.outputPreview));
|
|
403
|
+
if (node.errorPreview) {
|
|
404
|
+
const error = el("section", "markdown-error");
|
|
405
|
+
error.appendChild(el("p", "markdown-error-title", "错误输出"));
|
|
406
|
+
error.appendChild(renderMarkdown(node.errorPreview));
|
|
407
|
+
content.appendChild(error);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function buildDagInspectorHeader(dagRunId, node) {
|
|
413
|
+
const header = el("div", "dag-inspector-header");
|
|
414
|
+
header.dataset.dagRunId = String(dagRunId ?? "");
|
|
415
|
+
header.dataset.dagNodeId = String(node.nodeId ?? "");
|
|
416
|
+
const title = el("div", "dag-inspector-title");
|
|
417
|
+
title.appendChild(el("h3", null, "节点检查器"));
|
|
418
|
+
title.appendChild(el("div", "dag-inspector-node", node.nodeId));
|
|
419
|
+
header.appendChild(title);
|
|
420
|
+
const controls = el("div", "dag-inspector-controls");
|
|
421
|
+
const status = badge(node.status ?? "unknown");
|
|
422
|
+
status.classList.add("dag-inspector-status");
|
|
423
|
+
controls.appendChild(status);
|
|
424
|
+
const close = document.createElement("button");
|
|
425
|
+
close.type = "button";
|
|
426
|
+
close.className = "dag-inspector-close";
|
|
427
|
+
close.setAttribute("aria-label", "关闭节点检查器");
|
|
428
|
+
const closeIcon = el("i", "ri-close-line");
|
|
429
|
+
closeIcon.setAttribute("aria-hidden", "true");
|
|
430
|
+
close.appendChild(closeIcon);
|
|
431
|
+
close.addEventListener("click", closeDagInspector);
|
|
432
|
+
controls.appendChild(close);
|
|
433
|
+
header.appendChild(controls);
|
|
434
|
+
|
|
435
|
+
const tabDefs = [
|
|
436
|
+
["output", "节点输出", "ri-file-text-line"],
|
|
437
|
+
["timeline", "执行过程", "ri-route-line"],
|
|
438
|
+
["spec-evidence", "规范证据", "ri-book-open-line"],
|
|
439
|
+
];
|
|
440
|
+
const tabs = el("div", "dag-inspector-tabs");
|
|
441
|
+
tabs.setAttribute("role", "tablist");
|
|
442
|
+
tabs.setAttribute("aria-label", "节点检查器面板");
|
|
443
|
+
for (const [tab, label, icon] of tabDefs) {
|
|
444
|
+
const selected = uiState.dagInspectorTab === tab;
|
|
445
|
+
const button = document.createElement("button");
|
|
446
|
+
button.type = "button";
|
|
447
|
+
button.id = `dag-inspector-tab-${tab}`;
|
|
448
|
+
button.className = "dag-inspector-tab";
|
|
449
|
+
button.setAttribute("role", "tab");
|
|
450
|
+
button.setAttribute("aria-controls", `dag-inspector-panel-${tab}`);
|
|
451
|
+
button.setAttribute("aria-selected", String(selected));
|
|
452
|
+
button.tabIndex = selected ? 0 : -1;
|
|
453
|
+
button.dataset.tab = tab;
|
|
454
|
+
const tabIcon = el("i", icon);
|
|
455
|
+
tabIcon.setAttribute("aria-hidden", "true");
|
|
456
|
+
button.appendChild(tabIcon);
|
|
457
|
+
button.appendChild(document.createTextNode(` ${label}`));
|
|
458
|
+
button.addEventListener("click", () => {
|
|
459
|
+
uiState.dagInspectorTab = tab;
|
|
460
|
+
renderDagInspector(dagRunId, node, false);
|
|
461
|
+
const next = document.getElementById(`dag-inspector-tab-${tab}`);
|
|
462
|
+
next?.focus();
|
|
463
|
+
});
|
|
464
|
+
button.addEventListener("keydown", (event) => {
|
|
465
|
+
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
|
|
466
|
+
event.preventDefault();
|
|
467
|
+
event.stopPropagation();
|
|
468
|
+
const order = tabDefs.map(([id]) => id);
|
|
469
|
+
const idx = order.indexOf(tab);
|
|
470
|
+
if (idx < 0) return;
|
|
471
|
+
const delta = event.key === "ArrowRight" ? 1 : -1;
|
|
472
|
+
const nextTab = order[(idx + delta + order.length) % order.length];
|
|
473
|
+
uiState.dagInspectorTab = nextTab;
|
|
474
|
+
renderDagInspector(dagRunId, node, false);
|
|
475
|
+
document.getElementById(`dag-inspector-tab-${nextTab}`)?.focus();
|
|
476
|
+
});
|
|
477
|
+
tabs.appendChild(button);
|
|
478
|
+
}
|
|
479
|
+
header.appendChild(tabs);
|
|
480
|
+
return header;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function syncDagInspectorHeader(panel, dagRunId, node) {
|
|
484
|
+
const header = panel.querySelector(".dag-inspector-header");
|
|
485
|
+
if (!header) return;
|
|
486
|
+
header.dataset.dagRunId = String(dagRunId ?? "");
|
|
487
|
+
header.dataset.dagNodeId = String(node.nodeId ?? "");
|
|
488
|
+
const nodeLabel = header.querySelector(".dag-inspector-node");
|
|
489
|
+
if (nodeLabel) nodeLabel.textContent = node.nodeId;
|
|
490
|
+
const status = header.querySelector(".dag-inspector-status");
|
|
491
|
+
if (status) {
|
|
492
|
+
const next = badge(node.status ?? "unknown");
|
|
493
|
+
next.classList.add("dag-inspector-status");
|
|
494
|
+
status.replaceWith(next);
|
|
495
|
+
}
|
|
496
|
+
for (const button of header.querySelectorAll(".dag-inspector-tab")) {
|
|
497
|
+
const selected = button.dataset.tab === uiState.dagInspectorTab;
|
|
498
|
+
button.setAttribute("aria-selected", String(selected));
|
|
499
|
+
button.tabIndex = selected ? 0 : -1;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function dagInspectorSignature(dagRunId, node) {
|
|
504
|
+
return JSON.stringify([
|
|
505
|
+
dagRunId,
|
|
506
|
+
node.nodeId,
|
|
507
|
+
uiState.dagInspectorTab,
|
|
508
|
+
node.outputPreview ?? "",
|
|
509
|
+
node.errorPreview ?? "",
|
|
510
|
+
uiState.dagInspectorTab === "timeline" ? uiState.sessionEventOffset : null,
|
|
511
|
+
]);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
export function renderDagInspector(dagRunId, node, initial = true) {
|
|
515
|
+
const panel = document.getElementById("dag-inspector");
|
|
516
|
+
if (!panel) return;
|
|
517
|
+
captureDagTimelineViewportState(panel);
|
|
518
|
+
if (!uiState.dagInspectorOpen || !node) {
|
|
519
|
+
panel.classList.remove("is-open");
|
|
520
|
+
panel.setAttribute("aria-hidden", "true");
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Defer tearing down the inspector shell while the user is actively
|
|
525
|
+
// dragging the resize handle (or the graph) so the pointer-capture target
|
|
526
|
+
// is not destroyed mid-gesture; the next poll refreshes the content.
|
|
527
|
+
if (isInteractiveGestureActive(document.body.classList)) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
const existingContent = panel.querySelector(".dag-inspector-content") ?? null;
|
|
532
|
+
const reuseShell = !initial && Boolean(existingContent);
|
|
533
|
+
const nextContentSignature = dagInspectorSignature(dagRunId, node);
|
|
534
|
+
|
|
535
|
+
if (reuseShell && existingContent) {
|
|
536
|
+
panel.classList.add("is-open");
|
|
537
|
+
panel.setAttribute("aria-hidden", "false");
|
|
538
|
+
syncDagInspectorHeader(panel, dagRunId, node);
|
|
539
|
+
if (panel.dataset.contentSignature === nextContentSignature) return;
|
|
540
|
+
const previousNode = existingContent.dataset.dagNodeId ?? "";
|
|
541
|
+
const nodeChanged = previousNode !== String(node.nodeId ?? "");
|
|
542
|
+
const followLatest =
|
|
543
|
+
nodeChanged ||
|
|
544
|
+
computeFollowLatest(
|
|
545
|
+
existingContent.scrollTop,
|
|
546
|
+
existingContent.scrollHeight,
|
|
547
|
+
existingContent.clientHeight,
|
|
548
|
+
);
|
|
549
|
+
const regionKey = `dag:${dagRunId}:${node.nodeId}:output`;
|
|
550
|
+
uiState.dagNodeOutputViewportState = updateDagOutputViewportState(
|
|
551
|
+
uiState.dagNodeOutputViewportState,
|
|
552
|
+
regionKey,
|
|
553
|
+
existingContent.scrollLeft,
|
|
554
|
+
existingContent.scrollTop,
|
|
555
|
+
followLatest,
|
|
556
|
+
);
|
|
557
|
+
const nestedViewportState = [
|
|
558
|
+
...existingContent.querySelectorAll("pre"),
|
|
559
|
+
].map((pre) => ({
|
|
560
|
+
scrollLeft: pre.scrollLeft,
|
|
561
|
+
scrollTop: pre.scrollTop,
|
|
562
|
+
}));
|
|
563
|
+
clearNode(existingContent);
|
|
564
|
+
fillDagInspectorContent(existingContent, dagRunId, node);
|
|
565
|
+
if (followLatest) {
|
|
566
|
+
existingContent.scrollTop = existingContent.scrollHeight;
|
|
567
|
+
} else {
|
|
568
|
+
existingContent.scrollTop = uiState.dagNodeOutputViewportState.scrollTop;
|
|
569
|
+
}
|
|
570
|
+
for (const [index, pre] of [
|
|
571
|
+
...existingContent.querySelectorAll("pre"),
|
|
572
|
+
].entries()) {
|
|
573
|
+
const previous = nestedViewportState[index];
|
|
574
|
+
if (!previous) continue;
|
|
575
|
+
pre.scrollLeft = previous.scrollLeft;
|
|
576
|
+
pre.scrollTop = previous.scrollTop;
|
|
577
|
+
}
|
|
578
|
+
panel.dataset.contentSignature = nextContentSignature;
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
clearNode(panel);
|
|
583
|
+
panel.classList.add("is-open");
|
|
584
|
+
panel.setAttribute("aria-hidden", "false");
|
|
585
|
+
panel.appendChild(createDagInspectorResizeHandle(panel));
|
|
586
|
+
panel.appendChild(buildDagInspectorHeader(dagRunId, node));
|
|
587
|
+
|
|
588
|
+
const content = el("div", "dag-inspector-content");
|
|
589
|
+
fillDagInspectorContent(content, dagRunId, node);
|
|
590
|
+
panel.appendChild(content);
|
|
591
|
+
panel.dataset.contentSignature = nextContentSignature;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Bounded event history UI. Uses opaque `cursor`/`nextCursor` (not SSE/run `after` offsets).
|
|
596
|
+
*/
|