@tea-agent/loop-agent 0.10.0 → 0.12.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/AGENTS.md +10 -2
- package/CHANGELOG.md +91 -24
- package/README.md +84 -12
- package/dist/application/dag/args.js +1 -12
- package/dist/application/dag/generate-task-dag.js +38 -2
- package/dist/application/dag/run-dag.js +11 -27
- package/dist/application/dag/validate-dag.js +13 -2
- package/dist/application/loop/run-action.js +0 -4
- package/dist/cli/command-definitions.js +44 -16
- package/dist/cli/program.js +40 -23
- package/dist/cli/update/notifier.js +117 -0
- package/dist/cli/update/npm-client.js +151 -0
- package/dist/cli/update/policy.js +58 -0
- package/dist/cli/update/state.js +68 -0
- package/dist/cli.js +33 -0
- package/dist/commands/cursor-prompt.js +42 -82
- package/dist/commands/dag-approve.js +36 -0
- package/dist/commands/delegate.js +75 -77
- package/dist/commands/doctor.js +0 -18
- package/dist/commands/init.js +547 -95
- package/dist/commands/instructions.js +7 -10
- package/dist/commands/loop.js +4 -20
- package/dist/commands/plan.js +50 -0
- package/dist/executors/config-core.js +0 -51
- package/dist/executors/dag-pi-executor.js +1 -1
- package/dist/executors/dag.js +0 -1
- package/dist/executors/index.js +0 -2
- package/dist/executors/model-routing.js +9 -9
- package/dist/executors/shell-executor.js +1 -1
- package/dist/governance/checks.js +6 -3
- package/dist/governance/exec-plans.js +545 -0
- package/dist/governance/manifest-types.js +24 -2
- package/dist/infrastructure/harness/loop-action-store.js +0 -3
- package/dist/records/harvest.js +2 -23
- package/dist/records/one-shot-runs.js +1 -1
- package/dist/shared/artifacts-core.js +24 -5
- package/dist/shared/output-truncation.js +37 -0
- package/dist/shared/package-metadata.js +488 -0
- package/dist/{executors/cursor-executor.js → sidecars/cursor-prompt/executor.js} +2 -42
- package/dist/sidecars/cursor-prompt/index.js +3 -0
- package/dist/sidecars/cursor-prompt/stream.js +121 -0
- package/dist/task/config-types.js +29 -12
- package/dist/task/delegate.js +9 -21
- package/dist/task/runtime.js +1 -2
- package/dist/worker/cli.js +32 -3
- package/dist/worker/delivery/final-verification.js +47 -11
- package/dist/worker/delivery/package.js +63 -10
- package/dist/worker/feature/run.js +60 -8
- package/dist/worker/loop-agent/loop-agent-client.js +329 -126
- package/dist/worker/observability/event-history.js +216 -0
- package/dist/worker/observability/read-model.js +338 -83
- package/dist/worker/observe/paths.js +17 -0
- package/dist/worker/observe/routes.js +165 -21
- package/dist/worker/observe/server.js +59 -1
- package/dist/worker/observe/static/api.js +27 -0
- package/dist/worker/observe/static/app.js +120 -2317
- 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 +128 -0
- package/dist/worker/observe/static/router.js +85 -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 +1720 -495
- package/dist/worker/observe/static/views/batch.js +226 -0
- package/dist/worker/observe/static/views/dag-graph.js +172 -0
- package/dist/worker/observe/static/views/dag-inspector.js +477 -0
- package/dist/worker/observe/static/views/dag.js +362 -0
- package/dist/worker/observe/static/views/dashboard.js +442 -0
- package/dist/worker/observe/static/views/failures.js +143 -0
- package/dist/worker/observe/static/views/feature.js +453 -0
- package/dist/worker/observe/static/views/pool.js +347 -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 +260 -0
- package/dist/worker/observe/static/views/timeline.js +163 -0
- package/dist/worker/preflight.js +49 -1
- package/dist/worker/run-task/run-task.js +22 -12
- package/dist/worker/runner/run-ready.js +76 -12
- package/dist/worker/task-spec/schema.js +0 -1
- package/dist/workflows/dag/controller-identity.js +104 -0
- package/dist/workflows/dag/convergence/controller.js +1 -1
- package/dist/workflows/dag/executor-registry.js +0 -2
- package/dist/workflows/dag/init-hybrid.js +797 -27
- package/dist/workflows/dag/node-execution.js +183 -35
- 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 +77 -17
- package/dist/workflows/dag/runtime-contract.js +87 -0
- package/dist/workflows/dag/scheduler.js +7 -2
- package/dist/workflows/dag/sdd-embedded.js +128 -0
- package/dist/workflows/dag/skill-instructions.js +5 -4
- package/dist/workflows/dag/skill-snapshot.js +529 -0
- package/dist/workflows/dag/types.js +86 -10
- package/dist/workflows/dag/validate.js +73 -12
- package/dist/workflows/loop/actions/dag-action.js +0 -2
- package/dist/workflows/loop/actions/shared.js +1 -1
- package/dist/workflows/loop/actions.js +14 -31
- package/dist/workflows/loop/benchmark.js +1 -1
- package/dist/workflows/loop/index.js +1 -1
- package/dist/workflows/loop/policy/auto-policy.js +22 -14
- package/dist/workflows/loop/policy/path-patterns.js +13 -0
- package/docs/README.md +36 -33
- package/docs/agent-dag-recovery-playbook.md +1 -1
- package/docs/agent-dag-runner.md +28 -3
- package/docs/architecture/README.md +26 -0
- package/docs/architecture/dag-execution.md +140 -0
- package/docs/architecture/evolution.md +53 -0
- package/docs/architecture/facts-and-state.md +58 -0
- package/docs/architecture/runtime-boundaries.md +45 -17
- package/docs/architecture/system-overview.md +93 -0
- package/docs/architecture/worker-and-feature.md +81 -0
- package/docs/cursor-prompt-sidecar.md +36 -0
- package/docs/decisions/README.md +13 -1
- package/docs/design/README.md +43 -21
- package/docs/development-principles.md +2 -2
- package/docs/exec-plans/active/README.md +1 -3
- package/docs/exec-plans/completed/README.md +23 -0
- package/docs/feature-workflow.md +78 -4
- package/docs/harness-methodology-debugging.md +1 -1
- package/docs/harness-methodology-tdd.md +3 -3
- package/docs/init-surface.manifest.json +60 -25
- package/docs/loop-agent-harness.md +28 -4
- package/docs/progress/README.md +50 -1
- package/docs/reports/README.md +90 -18
- package/docs/skills/README.md +2 -1
- package/docs/skills/vetted-skill-registry.md +2 -1
- package/docs/templates/agent-dag-report.schema.json +23 -6
- package/docs/templates/agent-dag.base.json +0 -5
- package/docs/templates/agent-dag.final-verification.json +0 -5
- package/docs/templates/agent-dag.schema.json +70 -3
- package/docs/templates/agent-dag.supervised-implementation.json +9 -8
- package/docs/templates/backend-test-dag.generate-pytest.prompt.md +139 -0
- package/docs/templates/backend-test-dag.json +276 -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/frontend-design-contract.md +33 -0
- package/docs/templates/frontend-task-constraints.md +25 -0
- package/docs/templates/frontend-task-requirement.md +61 -0
- package/docs/templates/harness.schema.json +10 -12
- package/docs/templates/hybrid-dag.json +1 -6
- package/docs/templates/interactive-ui-round2-experiment.md +1 -1
- package/docs/templates/product-line/task.yaml +0 -1
- package/docs/templates/project-start-checklist.md +2 -2
- package/docs/templates/worker-dogfood-evidence.md +28 -0
- package/docs/templates/worker-dogfood-setup.md +20 -0
- package/docs/verification-matrix.md +10 -0
- package/examples/decision-gate-agent-dag.json +87 -33
- package/examples/example-dag.json +0 -5
- package/examples/hybrid-loop-agent-dag.json +0 -5
- package/harness.json +7 -15
- package/package.json +22 -46
- package/scripts/check-product-line-docs.sh +10 -7
- package/skills/agent-worker/SKILL.md +37 -0
- package/skills/agent-worker/references/agent-worker-operator.md +43 -0
- package/skills/frontend-design-review/SKILL.md +59 -0
- package/skills/frontend-design-review/references/review-checklist.md +37 -0
- package/skills/frontend-implementation/SKILL.md +51 -0
- package/skills/frontend-implementation/references/code-standards.md +34 -0
- package/skills/frontend-implementation/references/design-spec.md +46 -0
- package/skills/frontend-implementation/references/node-contracts.md +32 -0
- package/skills/frontend-review/SKILL.md +53 -0
- package/skills/frontend-review/references/review-findings.md +42 -0
- package/skills/frontend-verification/SKILL.md +40 -0
- package/skills/frontend-verification/references/verification-checklist.md +56 -0
- package/skills/grill-me/SKILL.md +10 -0
- package/skills/grill-with-docs/SKILL.md +88 -0
- package/skills/grill-with-docs/adr-format.md +47 -0
- package/skills/grill-with-docs/context-format.md +60 -0
- package/skills/loop-agent/SKILL.md +11 -9
- package/skills/loop-agent/references/command-reference.md +14 -15
- package/skills/loop-agent/references/docs-converge.md +126 -0
- package/skills/loop-agent/references/harness-policy.md +7 -7
- package/skills/loop-agent/references/hybrid-dag.md +36 -20
- package/skills/loop-agent/references/long-running-loop.md +4 -6
- package/skills/loop-agent/references/multi-worktree.md +6 -6
- package/skills/loop-agent/references/orchestrator-and-interventions.md +3 -3
- package/skills/loop-agent/references/pi-subagent-assisted-mode.md +14 -11
- package/skills/loop-agent/references/task-workflow.md +1 -1
- package/skills/loop-agent/references/verification-and-failure-handling.md +6 -0
- package/skills/using-git-worktrees/SKILL.md +215 -0
- package/dist/commands/cursor-worker.js +0 -43
- package/dist/cursor-worker-entry.js +0 -8
- package/dist/executors/cursor-artifacts.js +0 -33
- package/dist/executors/cursor-execution-log.js +0 -81
- package/dist/executors/cursor-executor-artifacts.js +0 -134
- package/dist/executors/cursor-run.js +0 -115
- package/dist/executors/cursor-tool.js +0 -94
- package/dist/executors/cursor-worker-client.js +0 -223
- package/dist/executors/cursor-worker-protocol.js +0 -18
- package/dist/executors/cursor-worker-server.js +0 -54
- package/dist/executors/cursor-worker.js +0 -3
- package/dist/executors/cursor.js +0 -6
- package/dist/executors/dag-cursor-executor.js +0 -87
- package/dist/workflows/loop/actions/cursor-fix.js +0 -191
- package/dist/workflows/loop/policy/cursor-fix-policy.js +0 -31
- package/docs/cursor-executor-usage.md +0 -25
- package/docs/dynamic-workflow-dag-engine-roadmap.md +0 -1749
|
@@ -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
|
+
|