@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,292 @@
|
|
|
1
|
+
/** Format helpers for Observe UI (R5). */
|
|
2
|
+
import {
|
|
3
|
+
STATUS_LABELS,
|
|
4
|
+
DAG_EFFECTIVE_STATUS_LABELS,
|
|
5
|
+
LIVENESS_LABELS,
|
|
6
|
+
} from "./constants.js";
|
|
7
|
+
import { el } from "./dom.js";
|
|
8
|
+
|
|
9
|
+
export function parseMarkdownBlocks(markdown) {
|
|
10
|
+
const lines = String(markdown ?? "")
|
|
11
|
+
.replace(/\r\n?/g, "\n")
|
|
12
|
+
.split("\n");
|
|
13
|
+
const blocks = [];
|
|
14
|
+
let paragraph = [];
|
|
15
|
+
let list = null;
|
|
16
|
+
let code = null;
|
|
17
|
+
|
|
18
|
+
const flushParagraph = () => {
|
|
19
|
+
const text = paragraph.join(" ").trim();
|
|
20
|
+
if (text) blocks.push({ type: "paragraph", text });
|
|
21
|
+
paragraph = [];
|
|
22
|
+
};
|
|
23
|
+
const flushList = () => {
|
|
24
|
+
if (list?.items.length) blocks.push(list);
|
|
25
|
+
list = null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
29
|
+
const line = lines[index] ?? "";
|
|
30
|
+
if (code) {
|
|
31
|
+
if (/^```\s*$/.test(line)) {
|
|
32
|
+
blocks.push({
|
|
33
|
+
type: "code",
|
|
34
|
+
language: code.language,
|
|
35
|
+
text: code.lines.join("\n"),
|
|
36
|
+
});
|
|
37
|
+
code = null;
|
|
38
|
+
} else {
|
|
39
|
+
code.lines.push(line);
|
|
40
|
+
}
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const fence = line.match(/^```([^\s]*)\s*$/);
|
|
45
|
+
if (fence) {
|
|
46
|
+
flushParagraph();
|
|
47
|
+
flushList();
|
|
48
|
+
code = { language: fence[1] ?? "", lines: [] };
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (!line.trim()) {
|
|
52
|
+
flushParagraph();
|
|
53
|
+
flushList();
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const heading = line.match(/^(#{1,4})\s+(.+)$/);
|
|
57
|
+
if (heading) {
|
|
58
|
+
flushParagraph();
|
|
59
|
+
flushList();
|
|
60
|
+
blocks.push({
|
|
61
|
+
type: "heading",
|
|
62
|
+
level: heading[1].length,
|
|
63
|
+
text: heading[2].trim(),
|
|
64
|
+
});
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (/^\s{0,3}([-*_])(?:\s*\1){2,}\s*$/.test(line)) {
|
|
68
|
+
flushParagraph();
|
|
69
|
+
flushList();
|
|
70
|
+
blocks.push({ type: "rule" });
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (line.startsWith(">")) {
|
|
74
|
+
flushParagraph();
|
|
75
|
+
flushList();
|
|
76
|
+
blocks.push({ type: "quote", text: line.replace(/^>\s?/, "") });
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const unordered = line.match(/^[-*+]\s+(.+)$/);
|
|
80
|
+
const ordered = line.match(/^\d+[.)]\s+(.+)$/);
|
|
81
|
+
if (unordered || ordered) {
|
|
82
|
+
flushParagraph();
|
|
83
|
+
const orderedList = Boolean(ordered);
|
|
84
|
+
if (!list || list.ordered !== orderedList) {
|
|
85
|
+
flushList();
|
|
86
|
+
list = { type: "list", ordered: orderedList, items: [] };
|
|
87
|
+
}
|
|
88
|
+
list.items.push((ordered?.[1] ?? unordered?.[1] ?? "").trim());
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (
|
|
92
|
+
line.includes("|") &&
|
|
93
|
+
/^\s*\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(
|
|
94
|
+
lines[index + 1] ?? "",
|
|
95
|
+
)
|
|
96
|
+
) {
|
|
97
|
+
flushParagraph();
|
|
98
|
+
flushList();
|
|
99
|
+
const parseCells = (row) =>
|
|
100
|
+
row
|
|
101
|
+
.trim()
|
|
102
|
+
.replace(/^\||\|$/g, "")
|
|
103
|
+
.split("|")
|
|
104
|
+
.map((cell) => cell.trim());
|
|
105
|
+
const headers = parseCells(line);
|
|
106
|
+
const rows = [];
|
|
107
|
+
index += 2;
|
|
108
|
+
while (index < lines.length && lines[index].includes("|")) {
|
|
109
|
+
rows.push(parseCells(lines[index]));
|
|
110
|
+
index += 1;
|
|
111
|
+
}
|
|
112
|
+
index -= 1;
|
|
113
|
+
blocks.push({ type: "table", headers, rows });
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
flushList();
|
|
117
|
+
paragraph.push(line.trim());
|
|
118
|
+
}
|
|
119
|
+
if (code)
|
|
120
|
+
blocks.push({
|
|
121
|
+
type: "code",
|
|
122
|
+
language: code.language,
|
|
123
|
+
text: code.lines.join("\n"),
|
|
124
|
+
});
|
|
125
|
+
flushParagraph();
|
|
126
|
+
flushList();
|
|
127
|
+
return blocks;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function markdownLinkHref(value) {
|
|
131
|
+
const href = typeof value === "string" ? value.trim() : "";
|
|
132
|
+
if (!href) return null;
|
|
133
|
+
if (href.startsWith("#") || href.startsWith("/")) return href;
|
|
134
|
+
try {
|
|
135
|
+
const parsed = new URL(
|
|
136
|
+
href,
|
|
137
|
+
typeof location === "undefined" ? "http://localhost" : location.href,
|
|
138
|
+
);
|
|
139
|
+
return ["http:", "https:", "mailto:"].includes(parsed.protocol)
|
|
140
|
+
? href
|
|
141
|
+
: null;
|
|
142
|
+
} catch {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function statusLabel(status) {
|
|
148
|
+
if (!status) return STATUS_LABELS.unknown;
|
|
149
|
+
const key = status.toLowerCase().replace(/-/g, "_");
|
|
150
|
+
if (STATUS_LABELS[key]) return STATUS_LABELS[key];
|
|
151
|
+
if (status === "FINISHED") return STATUS_LABELS.finished_upper;
|
|
152
|
+
if (status === "ERROR") return STATUS_LABELS.error_upper;
|
|
153
|
+
if (status === "SKIPPED") return STATUS_LABELS.skipped_upper;
|
|
154
|
+
return status;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function statusSymbol(status) {
|
|
158
|
+
const key = (status ?? "unknown").toLowerCase();
|
|
159
|
+
if (["finished", "completed", "succeeded", "done"].includes(key)) return "✓";
|
|
160
|
+
if (["failed", "error"].includes(key)) return "✕";
|
|
161
|
+
if (key === "skipped") return "↷";
|
|
162
|
+
if (["running", "started"].includes(key)) return "●";
|
|
163
|
+
if (["pending", "queued", "blocked"].includes(key)) return "○";
|
|
164
|
+
return "◇";
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function badgeClass(status) {
|
|
168
|
+
if (!status) return "unknown";
|
|
169
|
+
const key = status.toLowerCase().replace(/_/g, "-");
|
|
170
|
+
if (
|
|
171
|
+
["finished", "completed", "succeeded", "done", "superseded"].includes(key)
|
|
172
|
+
) {
|
|
173
|
+
return "succeeded";
|
|
174
|
+
}
|
|
175
|
+
if (["error", "failed", "interrupted"].includes(key)) return "failed";
|
|
176
|
+
if (key === "partial-failed") return "partial-failed";
|
|
177
|
+
if (key === "skipped" || key === "abandoned") return "skipped";
|
|
178
|
+
if (key === "running" || key === "started" || key === "running-quiet")
|
|
179
|
+
return "running";
|
|
180
|
+
if (key === "paused") return "blocked";
|
|
181
|
+
if (key === "remote-unknown") return "unknown";
|
|
182
|
+
return key;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function badge(status) {
|
|
186
|
+
const label = statusLabel(status);
|
|
187
|
+
const cls = badgeClass(status);
|
|
188
|
+
return el("span", `badge badge-${cls}`, label);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function formatTs(value) {
|
|
192
|
+
if (!value) return "—";
|
|
193
|
+
const d = new Date(value);
|
|
194
|
+
if (Number.isNaN(d.getTime())) return value;
|
|
195
|
+
return d.toLocaleString("zh-CN", { hour12: false });
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function formatMs(ms) {
|
|
199
|
+
if (ms === undefined || ms === null) return "—";
|
|
200
|
+
if (ms < 1000) return `${ms}ms`;
|
|
201
|
+
if (ms >= 60_000) {
|
|
202
|
+
const totalSeconds = Math.floor(ms / 1000);
|
|
203
|
+
return `${Math.floor(totalSeconds / 60)}min ${totalSeconds % 60}s`;
|
|
204
|
+
}
|
|
205
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function dagStatusBadge(status) {
|
|
209
|
+
const value = status ?? "unknown";
|
|
210
|
+
return el(
|
|
211
|
+
"span",
|
|
212
|
+
`badge badge-${badgeClass(value)}`,
|
|
213
|
+
DAG_EFFECTIVE_STATUS_LABELS[value] ?? statusLabel(value),
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function formatDuration(ms) {
|
|
218
|
+
if (ms === undefined || ms === null || Number.isNaN(ms)) return "—";
|
|
219
|
+
if (ms < 0) ms = 0;
|
|
220
|
+
const totalSec = Math.floor(ms / 1000);
|
|
221
|
+
const hours = Math.floor(totalSec / 3600);
|
|
222
|
+
const minutes = Math.floor((totalSec % 3600) / 60);
|
|
223
|
+
const seconds = totalSec % 60;
|
|
224
|
+
if (hours > 0) return `${hours}小时 ${minutes}分 ${seconds}秒`;
|
|
225
|
+
if (minutes > 0) return `${minutes}分 ${seconds}秒`;
|
|
226
|
+
return `${seconds}秒`;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function formatAgo(iso, nowMs) {
|
|
230
|
+
if (!iso) return "—";
|
|
231
|
+
const ts = Date.parse(iso);
|
|
232
|
+
if (Number.isNaN(ts)) return "—";
|
|
233
|
+
const base = nowMs ?? Date.now();
|
|
234
|
+
const deltaSec = Math.max(0, Math.floor((base - ts) / 1000));
|
|
235
|
+
if (deltaSec < 10) return "刚刚";
|
|
236
|
+
if (deltaSec < 60) return `${deltaSec} 秒前`;
|
|
237
|
+
if (deltaSec < 3600) return `${Math.floor(deltaSec / 60)} 分钟前`;
|
|
238
|
+
if (deltaSec < 86400) return `${Math.floor(deltaSec / 3600)} 小时前`;
|
|
239
|
+
return `${Math.floor(deltaSec / 86400)} 天前`;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function livenessBadge(liveness) {
|
|
243
|
+
if (!liveness) return null;
|
|
244
|
+
return el(
|
|
245
|
+
"span",
|
|
246
|
+
`badge liveness-${liveness}`,
|
|
247
|
+
LIVENESS_LABELS[liveness] ?? liveness,
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function summaryText(summary) {
|
|
252
|
+
if (!summary) return "—";
|
|
253
|
+
let text = `总计 ${summary.total} · 成功 ${summary.succeeded} · 失败 ${summary.failed} · 复用历史结果 ${summary.reused}`;
|
|
254
|
+
if (summary.recordErrors !== undefined) {
|
|
255
|
+
text += ` · 记录错误 ${summary.recordErrors}`;
|
|
256
|
+
}
|
|
257
|
+
if (summary.runErrors !== undefined) {
|
|
258
|
+
text += ` · 运行错误 ${summary.runErrors}`;
|
|
259
|
+
}
|
|
260
|
+
return text;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Derived duration from wall-clock facts only (not persisted). */
|
|
264
|
+
export function derivedDurationMs(startedAt, finishedAt) {
|
|
265
|
+
if (!startedAt || !finishedAt) return undefined;
|
|
266
|
+
const start = Date.parse(startedAt);
|
|
267
|
+
const end = Date.parse(finishedAt);
|
|
268
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || end < start)
|
|
269
|
+
return undefined;
|
|
270
|
+
return end - start;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export function displayDurationMs(fact) {
|
|
274
|
+
return (
|
|
275
|
+
derivedDurationMs(fact?.startedAt, fact?.finishedAt) ?? fact?.durationMs
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function truncateText(text, maxLen) {
|
|
280
|
+
if (!text) return "—";
|
|
281
|
+
const normalized = String(text).replace(/\s+/g, " ").trim();
|
|
282
|
+
if (normalized.length <= maxLen) return normalized;
|
|
283
|
+
return `${normalized.slice(0, maxLen)}…`;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function repoBaseName(repoRoot) {
|
|
287
|
+
if (!repoRoot) return "未绑定仓库";
|
|
288
|
+
const trimmed = String(repoRoot).replace(/[\\/]+$/, "");
|
|
289
|
+
const parts = trimmed.split(/[\\/]/);
|
|
290
|
+
return parts[parts.length - 1] || trimmed || "未绑定仓库";
|
|
291
|
+
}
|
|
292
|
+
|