ralphflow-dsh 0.1.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +220 -167
  2. package/cordis.patch.yml +11 -0
  3. package/lib/create.d.ts +7 -11
  4. package/lib/create.js +132 -83
  5. package/lib/engine.d.ts +667 -262
  6. package/lib/engine.js +3583 -2579
  7. package/lib/index.d.ts +3 -4
  8. package/lib/index.js +222 -163
  9. package/lib/message-source.d.ts +25 -0
  10. package/lib/message-source.js +2 -0
  11. package/lib/reset.d.ts +40 -0
  12. package/lib/reset.js +147 -0
  13. package/lib/tools.d.ts +31 -14
  14. package/lib/tools.js +407 -684
  15. package/lib/verify.d.ts +57 -0
  16. package/lib/verify.js +326 -0
  17. package/lib/voting.d.ts +63 -0
  18. package/lib/voting.js +131 -0
  19. package/package.json +25 -44
  20. package/workflows/loop.yaml +21 -6
  21. package/workflows/spec.yaml +51 -46
  22. package/lib/actions.d.ts +0 -37
  23. package/lib/actions.js +0 -55
  24. package/lib/check-voting.d.ts +0 -54
  25. package/lib/check-voting.js +0 -289
  26. package/lib/check.d.ts +0 -64
  27. package/lib/check.js +0 -329
  28. package/lib/client/CommandCard.d.ts +0 -24
  29. package/lib/client/CommandCard.js +0 -69
  30. package/lib/client/HeaderAction.d.ts +0 -39
  31. package/lib/client/HeaderAction.js +0 -509
  32. package/lib/client/RunCard.d.ts +0 -27
  33. package/lib/client/RunCard.js +0 -375
  34. package/lib/client/client.d.ts +0 -3
  35. package/lib/client/client.js +0 -275
  36. package/lib/client/definition.d.ts +0 -126
  37. package/lib/client/definition.js +0 -259
  38. package/lib/client/hidden-runs.d.ts +0 -6
  39. package/lib/client/hidden-runs.js +0 -52
  40. package/lib/client/http-state.d.ts +0 -67
  41. package/lib/client/http-state.js +0 -81
  42. package/lib/client/markdown.d.ts +0 -26
  43. package/lib/client/markdown.js +0 -174
  44. package/lib/client/notify-watch.d.ts +0 -38
  45. package/lib/client/notify-watch.js +0 -98
  46. package/lib/client/notify.d.ts +0 -21
  47. package/lib/client/notify.js +0 -168
  48. package/lib/client/snapshots.d.ts +0 -8
  49. package/lib/client/snapshots.js +0 -101
  50. package/lib/client.js +0 -2361
  51. package/lib/commands.d.ts +0 -41
  52. package/lib/commands.js +0 -223
  53. package/lib/deps.d.ts +0 -17
  54. package/lib/deps.js +0 -19
  55. package/lib/done-detect.d.ts +0 -2
  56. package/lib/done-detect.js +0 -28
  57. package/lib/driver.d.ts +0 -32
  58. package/lib/driver.js +0 -248
  59. package/lib/events.d.ts +0 -35
  60. package/lib/events.js +0 -52
  61. package/lib/jobs.d.ts +0 -56
  62. package/lib/jobs.js +0 -355
  63. package/lib/mutex.d.ts +0 -9
  64. package/lib/mutex.js +0 -21
  65. package/lib/session-hygiene.d.ts +0 -25
  66. package/lib/session-hygiene.js +0 -205
  67. package/lib/voting-progress.d.ts +0 -37
  68. package/lib/voting-progress.js +0 -89
@@ -1,375 +0,0 @@
1
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- /**
3
- * Ralph Flow for dsh — 对话内嵌 run 卡片(进度/验证/审批/报告)
4
- *
5
- * 注册进 conversation.chat.node(keyed kind 'ralphflow-run')。按数据分支渲染:
6
- * 步骤条 / 验证者活体面板 / 审查门(含审批材料与内联打回意见)/ 报告(Markdown
7
- * 渲染)/ 回退历史。全部消费 dsh 官方主题 token。
8
- *
9
- * 设计要点:
10
- * - 可观测等待:验证者逐个「排队→运行中(计时)→已判定」点亮,超时进度条给
11
- * 等待一个终点——「在跑」和「死了」从此长得不一样。
12
- * - 判断支持:审查门内嵌该步任务要求摘要;打回意见在卡内写好后随命令提交
13
- * (非空意见才代提交,空意见仍只填不代发)。
14
- * - 诚实状态语言:failed = ⏸ 已暂停(可恢复),不是死亡。
15
- */
16
- import * as React from "react";
17
- import { Markdown } from "./markdown.js";
18
- import { hideRun } from "./hidden-runs.js";
19
- const NUM = { fontVariantNumeric: "tabular-nums" };
20
- const STYLE = {
21
- root: {
22
- border: "1px solid var(--dsw-alias-border-l2)",
23
- borderRadius: "10px",
24
- background: "var(--dsw-alias-bg-layer-1)",
25
- padding: "12px 14px",
26
- margin: "6px 0",
27
- fontSize: "13.5px",
28
- lineHeight: 1.6,
29
- },
30
- head: {
31
- display: "flex",
32
- alignItems: "center",
33
- gap: "8px",
34
- marginBottom: "8px",
35
- },
36
- shrinkName: {
37
- minWidth: 0,
38
- overflow: "hidden",
39
- textOverflow: "ellipsis",
40
- whiteSpace: "nowrap",
41
- },
42
- badge: (bg, fg) => ({
43
- fontSize: "11px",
44
- padding: "2px 8px",
45
- borderRadius: "999px",
46
- background: bg,
47
- color: fg || "var(--dsw-alias-label-primary-inverted)",
48
- flexShrink: 0,
49
- whiteSpace: "nowrap",
50
- transition: "background-color .25s ease, color .25s ease",
51
- }),
52
- steps: { display: "flex", flexWrap: "wrap", gap: "6px" },
53
- step: (state) => ({
54
- fontSize: "12px",
55
- padding: "3px 8px",
56
- borderRadius: "6px",
57
- border: "1px solid var(--dsw-alias-border-l2)",
58
- maxWidth: "220px",
59
- overflow: "hidden",
60
- textOverflow: "ellipsis",
61
- whiteSpace: "nowrap",
62
- background: state === "done"
63
- ? "var(--dsw-alias-state-success-tertiary)"
64
- : state === "active"
65
- ? "var(--dsw-alias-state-business-tertiary)"
66
- : state === "fail"
67
- ? "var(--dsw-alias-state-error-secondary)"
68
- : "transparent",
69
- color: state === "done"
70
- ? "var(--dsw-alias-state-success-primary)"
71
- : state === "active"
72
- ? "var(--dsw-alias-state-business-primary)"
73
- : state === "fail"
74
- ? "var(--dsw-alias-state-error-primary)"
75
- : "var(--dsw-alias-label-secondary)",
76
- transition: "background-color .25s ease, color .25s ease",
77
- }),
78
- verdictRow: {
79
- display: "flex",
80
- alignItems: "center",
81
- gap: "8px",
82
- padding: "4px 0",
83
- borderBottom: "1px solid var(--dsw-alias-border-l1)",
84
- flexWrap: "wrap",
85
- animation: "ralphflow-row-in .3s ease",
86
- },
87
- mono: { fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace", fontSize: "12px", color: "var(--dsw-alias-label-secondary)", ...NUM },
88
- reason: {
89
- whiteSpace: "pre-wrap",
90
- wordBreak: "break-word",
91
- maxHeight: "180px",
92
- overflowY: "auto",
93
- fontSize: "12.5px",
94
- color: "var(--dsw-alias-label-secondary)",
95
- },
96
- task: {
97
- marginBottom: "6px",
98
- color: "var(--dsw-alias-label-secondary)",
99
- wordBreak: "break-word",
100
- overflowWrap: "anywhere",
101
- display: "-webkit-box",
102
- WebkitLineClamp: 3,
103
- WebkitBoxOrient: "vertical",
104
- overflow: "hidden",
105
- },
106
- excerpt: {
107
- margin: "6px 0",
108
- padding: "6px 8px",
109
- borderRadius: "6px",
110
- background: "var(--dsw-alias-bg-layer-2)",
111
- fontSize: "12.5px",
112
- color: "var(--dsw-alias-label-secondary)",
113
- maxHeight: "120px",
114
- overflowY: "auto",
115
- whiteSpace: "pre-wrap",
116
- wordBreak: "break-word",
117
- },
118
- rewindRow: {
119
- marginTop: "6px",
120
- fontSize: "12px",
121
- padding: "4px 8px",
122
- borderRadius: "6px",
123
- background: "var(--dsw-alias-bg-layer-2)",
124
- color: "var(--dsw-alias-label-secondary)",
125
- },
126
- actions: {
127
- display: "flex",
128
- gap: "8px",
129
- marginTop: "10px",
130
- flexWrap: "wrap",
131
- alignItems: "center",
132
- },
133
- btn: (kind) => ({
134
- fontSize: "12.5px",
135
- padding: "5px 12px",
136
- borderRadius: "6px",
137
- cursor: "pointer",
138
- border: "1px solid var(--dsw-alias-border-l2)",
139
- background: kind === "primary" ? "var(--dsw-alias-button-primary-fill)" : "transparent",
140
- color: kind === "primary" ? "var(--dsw-alias-label-primary-foreground)" : "var(--dsw-alias-label-primary)",
141
- }),
142
- textarea: {
143
- width: "100%",
144
- boxSizing: "border-box",
145
- minHeight: "56px",
146
- resize: "vertical",
147
- fontSize: "12.5px",
148
- lineHeight: 1.5,
149
- padding: "6px 8px",
150
- borderRadius: "6px",
151
- border: "1px solid var(--dsw-alias-border-l2)",
152
- background: "var(--dsw-alias-bg-layer-2)",
153
- color: "var(--dsw-alias-label-primary)",
154
- marginTop: "6px",
155
- },
156
- chip: {
157
- fontSize: "11.5px",
158
- padding: "2px 8px",
159
- borderRadius: "999px",
160
- border: "1px solid var(--dsw-alias-border-l2)",
161
- background: "transparent",
162
- color: "var(--dsw-alias-label-secondary)",
163
- cursor: "pointer",
164
- },
165
- progressTrack: {
166
- height: "3px",
167
- borderRadius: "999px",
168
- background: "var(--dsw-alias-bg-layer-2)",
169
- marginTop: "6px",
170
- overflow: "hidden",
171
- },
172
- };
173
- // 卡片局部动画:注入一次全局 keyframes(幂等)
174
- const KEYFRAMES_ID = "ralphflow-keyframes";
175
- function ensureKeyframes() {
176
- try {
177
- if (document.getElementById(KEYFRAMES_ID))
178
- return;
179
- const el = document.createElement("style");
180
- el.id = KEYFRAMES_ID;
181
- el.textContent = `
182
- @keyframes ralphflow-row-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
183
- @keyframes ralphflow-breath { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
184
- `;
185
- document.head.appendChild(el);
186
- }
187
- catch { }
188
- }
189
- /** locale 兜底:t 缺省或键缺失时回落中文 */
190
- function tr(t, key, fallback) {
191
- try {
192
- const v = t?.(key);
193
- return typeof v === "string" && v ? v : fallback;
194
- }
195
- catch {
196
- return fallback;
197
- }
198
- }
199
- /** 带 {param} 插值的翻译兜底 */
200
- function trf(t, key, fallback, params) {
201
- const raw = tr(t, key, fallback);
202
- return raw.replace(/\{(\w+)\}/g, (_, k) => (params[k] != null ? String(params[k]) : `{${k}}`));
203
- }
204
- /** 相对时长:90s 内显示秒,之后分钟,1h 后小时 */
205
- function formatElapsed(ms) {
206
- const s = Math.max(0, Math.floor(ms / 1000));
207
- if (s < 90)
208
- return `${s}s`;
209
- const m = Math.floor(s / 60);
210
- if (m < 60)
211
- return `${m}m`;
212
- return `${Math.floor(m / 60)}h${m % 60}m`;
213
- }
214
- /** 实例短身份:runId 尾部 4 位——同名多实例并行时唯一可区分的视觉锚点 */
215
- function shortRunId(runId) {
216
- if (typeof runId !== "string" || !runId)
217
- return null;
218
- return runId.slice(-4);
219
- }
220
- function StepBar({ steps, current }) {
221
- return (_jsx("div", { style: STYLE.steps, children: steps.map((s, i) => {
222
- const active = !!(current && s.id === current.step);
223
- const curIdx = steps.findIndex((x) => current && x.id === current.step);
224
- const done = !active && curIdx >= 0 && i < curIdx;
225
- const fail = active && (current?.failCount ?? 0) > 0;
226
- // 人话步骤条:desc 截断为主(hover 看 id+全文),id 才是给机器对齐的
227
- const label = String(s.desc ?? "").trim() || s.id || `#${i + 1}`;
228
- return (_jsxs("span", { style: STYLE.step(fail ? "fail" : active ? "active" : done ? "done" : "todo"), title: `${s.id ?? ""}${s.desc ? ` — ${s.desc}` : ""}`, children: [done ? "✓ " : "", label.length > 24 ? `${label.slice(0, 24)}…` : label] }, s.id ?? i));
229
- }) }));
230
- }
231
- /**
232
- * 验证者活体面板:每个验证者一行,「排队 → 运行中(实时计时) → ✓/✗/⚠」。
233
- * 数据源:voter-start 帧(开跑时刻)+ verdict 帧(判定)。超时进度条给出
234
- * 等待的终点感。相邻同文的失败意见合并为一条 ×N——读一份就懂为什么被打回。
235
- */
236
- function VoterPanel({ voterStarts, verdicts, votersTotal, timeoutMs, checkStartedAt, now, t, }) {
237
- const total = votersTotal && votersTotal > 0
238
- ? votersTotal
239
- : Math.max(1, ...verdicts.map((v) => v.count || 1), ...voterStarts.map((s) => s.count || 1));
240
- const allDone = verdicts.length >= total;
241
- const rows = [];
242
- for (let i = 1; i <= total; i++) {
243
- const verdict = verdicts.find((v) => v.voter === i);
244
- const start = voterStarts.find((s) => s.voter === i);
245
- let icon = "·";
246
- let iconColor = "var(--dsw-alias-label-tertiary)";
247
- let stateLabel = tr(t, "run.voter.queued", "排队中");
248
- let elapsedText = "";
249
- if (verdict) {
250
- const ok = verdict.status === "pass";
251
- const infra = verdict.status === "infra";
252
- icon = ok ? "✓" : infra ? "⚠" : "✗";
253
- iconColor = ok ? "var(--dsw-alias-state-success-primary)" : infra ? "var(--dsw-alias-state-warn-primary)" : "var(--dsw-alias-state-error-primary)";
254
- stateLabel = ok ? tr(t, "run.pass", "通过") : infra ? tr(t, "run.infra", "环境故障") : tr(t, "run.fail", "未通过");
255
- if (start?.startedAt && verdict.arrivedAt)
256
- elapsedText = formatElapsed(verdict.arrivedAt - start.startedAt);
257
- }
258
- else if (start) {
259
- icon = "⟳";
260
- iconColor = "var(--dsw-alias-state-business-primary)";
261
- stateLabel = start.retry ? tr(t, "run.voter.retrying", "重试中") : tr(t, "run.voter.running", "运行中");
262
- elapsedText = formatElapsed(now - (start.startedAt || now));
263
- }
264
- rows.push(_jsxs("div", { style: STYLE.verdictRow, children: [_jsx("span", { "aria-hidden": "true", style: { color: iconColor, ...(icon === "⟳" ? { animation: "ralphflow-breath 1.6s ease-in-out infinite", display: "inline-block" } : {}) }, children: icon }), _jsx("span", { style: { color: "var(--dsw-alias-label-secondary)", ...NUM }, children: trf(t, "run.verifier", "验证者 {v}/{count}", { v: i, count: total }) }), start?.model ? _jsx("span", { style: STYLE.mono, children: start.model }) : verdict?.model ? _jsx("span", { style: STYLE.mono, children: verdict.model }) : null, _jsxs("span", { style: { marginLeft: "auto", fontSize: "11px", color: "var(--dsw-alias-label-secondary)", flexShrink: 0, ...NUM }, children: [stateLabel, elapsedText ? ` · ${elapsedText}` : ""] }), verdict?.reason ? _jsx("div", { style: { ...STYLE.reason, width: "100%" }, children: verdict.reason }) : null] }, `v${i}`));
265
- }
266
- // 超时进度条:仅验证进行中且已知上限时显示——等待有了终点
267
- const showProgress = !!timeoutMs && !!checkStartedAt && !allDone;
268
- const ratio = showProgress ? Math.min(1, Math.max(0.02, (now - (checkStartedAt || now)) / timeoutMs)) : 0;
269
- const nearTimeout = showProgress && ratio > 0.8;
270
- return (_jsxs("div", { style: { marginTop: "8px" }, children: [total > 1 ? (_jsxs("div", { style: { fontSize: "12px", color: "var(--dsw-alias-label-secondary)", marginBottom: "2px", ...NUM }, children: ["\uD83E\uDD16 ", trf(t, "run.votes", "独立验证 · 已收 {done}/{total} 票", { done: verdicts.length, total })] })) : null, rows, showProgress ? (_jsxs("div", { children: [_jsx("div", { style: STYLE.progressTrack, role: "progressbar", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": Math.round(ratio * 100), children: _jsx("div", { style: {
271
- width: `${ratio * 100}%`,
272
- height: "100%",
273
- borderRadius: "999px",
274
- background: nearTimeout ? "var(--dsw-alias-state-warn-primary)" : "var(--dsw-alias-state-business-tertiary)",
275
- transition: "width 1s linear, background-color .3s ease",
276
- } }) }), _jsx("div", { style: { fontSize: "11px", marginTop: "2px", color: nearTimeout ? "var(--dsw-alias-state-warn-primary)" : "var(--dsw-alias-label-tertiary)", ...NUM }, children: nearTimeout
277
- ? tr(t, "run.timeout.near", "接近超时上限——超时后自动暂停,已投出的票保留")
278
- : trf(t, "run.timeout.left", "超时上限 {min} 分钟", { min: Math.round((timeoutMs || 0) / 60000) }) })] })) : null] }));
279
- }
280
- /**
281
- * 审查门卡:审批材料(该步任务要求)+ 通过/打回。打回意见直接在卡内写——
282
- * 非空意见随命令代提交(用户意图明确);空意见仍只填不代发,防止盲目返工。
283
- */
284
- function GateCard({ gate, t }) {
285
- const [hint, setHint] = React.useState("");
286
- const [returning, setReturning] = React.useState(false);
287
- const [opinion, setOpinion] = React.useState("");
288
- const sendReturn = () => {
289
- const text = opinion.trim();
290
- if (!text) {
291
- // 空意见:只填入命令,绝不代提交——用户必须先说清为什么返工
292
- window.dispatchEvent(new CustomEvent("ralphflow:command", { detail: { command: "/ralphflow-reset ", autoSubmit: false } }));
293
- setHint(tr(t, "run.hint.return", "已在输入框填入 /ralphflow-reset——在后面补上你的修改意见再回车,模型会据此返工(不会自动发送)。"));
294
- return;
295
- }
296
- window.dispatchEvent(new CustomEvent("ralphflow:command", { detail: { command: `/ralphflow-reset ${text}`, autoSubmit: true } }));
297
- setHint(tr(t, "run.hint.returned", "打回意见已发送,模型会按你的意见返工本步骤。"));
298
- };
299
- return (_jsxs("div", { children: [_jsxs("div", { style: { fontWeight: 600, color: "var(--dsw-alias-label-primary)", marginTop: "8px" }, children: ["\uD83D\uDCCB ", tr(t, "run.gate", "待审查"), " \u00B7 ", gate.title] }), _jsx("div", { style: { ...STYLE.reason, margin: "6px 0" }, children: gate.reason }), gate.taskExcerpt ? (_jsxs("div", { children: [_jsx("div", { style: { fontSize: "11.5px", color: "var(--dsw-alias-label-tertiary)", marginBottom: "2px" }, children: tr(t, "run.gate.requirement", "本步要求(审批材料)") }), _jsx("div", { style: STYLE.excerpt, children: gate.taskExcerpt })] })) : null, !returning ? (_jsxs("div", { style: STYLE.actions, children: [_jsxs("button", { style: STYLE.btn("primary"), onClick: () => {
300
- window.dispatchEvent(new CustomEvent("ralphflow:command", { detail: { command: "/ralphflow-continue", autoSubmit: true } }));
301
- setHint(tr(t, "run.hint.approve", "已把 /ralphflow-continue 填入输入框并尝试发送——若未发出,按回车即批准进入验证。"));
302
- }, children: ["\u2713 ", tr(t, "run.approve", "通过")] }), _jsxs("button", { style: STYLE.btn("ghost"), onClick: () => setReturning(true), children: ["\u2717 ", tr(t, "run.return", "打回")] })] })) : (_jsxs("div", { children: [_jsx("div", { style: { fontSize: "12px", color: "var(--dsw-alias-label-secondary)", marginTop: "8px" }, children: tr(t, "run.return.opinion", "打回意见(会随命令发给模型)") }), _jsx("textarea", { style: STYLE.textarea, value: opinion, onChange: (e) => setOpinion(e.target.value), placeholder: tr(t, "run.return.placeholder", "例如:边界情况没覆盖,测试全挂了,请先修 CI 再交付…") }), _jsx("div", { style: STYLE.actions, children: [tr(t, "run.chip.tests", "测试没过,请先修复"), tr(t, "run.chip.scope", "偏离需求范围,请对照原始任务"), tr(t, "run.chip.quality", "质量不达标,请自查后重新提交")].map((c) => (_jsx("button", { type: "button", style: STYLE.chip, onClick: () => setOpinion((v) => (v ? `${v};${c}` : c)), children: c }, c))) }), _jsxs("div", { style: STYLE.actions, children: [_jsx("button", { style: STYLE.btn("primary"), onClick: sendReturn, children: tr(t, "run.return.send", "发送打回") }), _jsx("button", { style: STYLE.btn("ghost"), onClick: () => { setReturning(false); setOpinion(""); }, children: tr(t, "run.cancel.action", "取消") })] })] })), hint ? _jsxs("div", { style: { marginTop: "6px", fontSize: "12px", color: "var(--dsw-alias-state-warn-primary)" }, children: ["\u21A9 ", hint] }) : null] }));
303
- }
304
- function ReportCard({ report, t }) {
305
- if (!report.text && !report.reportPath)
306
- return null;
307
- return (_jsxs("div", { children: [_jsxs("div", { style: { fontWeight: 600, marginBottom: "6px", color: "var(--dsw-alias-label-primary)" }, children: ["\uD83D\uDCC4 ", tr(t, "run.report", "最终报告")] }), report.text ? (_jsx("div", { style: { maxHeight: "340px", overflowY: "auto", fontSize: "13px", border: "1px solid var(--dsw-alias-border-l1)", borderRadius: "8px", padding: "10px 12px" }, children: _jsx(Markdown, { text: report.text }) })) : null, report.reportPath ? (_jsxs("div", { style: { ...STYLE.mono, marginTop: report.text ? "6px" : 0, wordBreak: "break-all" }, children: ["\uD83D\uDCC1 ", report.reportPath] })) : null] }));
308
- }
309
- export function RalphRunCard({ node, t }) {
310
- const data = node?.data;
311
- // ⏱ 时长刷新时钟:事件静默期也要让计时走表;hooks 必须在 early return 之前
312
- const [, tick] = React.useReducer((n) => n + 1, 0);
313
- const live = !!data && !data.stopReason && typeof data.stepStartedAt === "number" && data.stepStartedAt > 0;
314
- const checking = !!data && !data.stopReason && !data.gate && data.current?.phase === "check";
315
- React.useEffect(() => {
316
- if (!live && !checking)
317
- return;
318
- const h = setInterval(tick, 5_000);
319
- return () => clearInterval(h);
320
- }, [live, checking]);
321
- // 注:本卡只负责渲染遗留 run 节点(历史折叠产物)。实时通知/快照/审批早已
322
- // 迁到页头任务列表(HeaderAction,数据源为 HTTP 状态通道)——新会话不再
323
- // 折叠 run 卡(宿主持久化不接受插件自定义事件帧,见 events.ts 架构说明)。
324
- try {
325
- ensureKeyframes();
326
- }
327
- catch { }
328
- if (!data)
329
- return null;
330
- // 状态语言诚实性:stopReason "failed" 是可恢复暂停(continue 即可续),不是
331
- // 死亡——用 warn 黄而非 error 红,文案用「已暂停」,并在卡上给恢复入口。
332
- const isPaused = data.stopReason === "failed";
333
- const statusBg = data.stopReason === "done"
334
- ? "var(--dsw-alias-state-success-primary)"
335
- : isPaused
336
- ? "var(--dsw-alias-state-warn-tertiary)"
337
- : data.stopReason === "cancelled"
338
- ? "transparent"
339
- : data.gate
340
- ? "var(--dsw-alias-state-warn-primary)"
341
- : data.current?.phase === "check"
342
- ? "var(--dsw-alias-state-business-primary)"
343
- : "var(--dsw-alias-state-business-tertiary)";
344
- const statusFg = isPaused
345
- ? "var(--dsw-alias-state-warn-primary)"
346
- : data.stopReason === "cancelled" || (!data.stopReason && !data.gate && data.current?.phase !== "check")
347
- ? "var(--dsw-alias-state-business-primary)"
348
- : undefined;
349
- const statusLabel = data.stopReason === "done" ? tr(t, "run.done", "已完成")
350
- : data.stopReason === "cancelled" ? tr(t, "run.cancelled", "已取消")
351
- : isPaused ? tr(t, "run.paused", "⏸ 已暂停")
352
- : data.gate ? tr(t, "run.gate", "待审查")
353
- : data.current?.phase === "check" ? tr(t, "run.check", "验证中")
354
- : tr(t, "run.running", "进行中");
355
- // 当前步骤已运行时长:host 帧带 ts(准确历史);定时器驱动持续刷新
356
- const elapsed = live ? formatElapsed(Date.now() - data.stepStartedAt) : null;
357
- const shortId = shortRunId(data.runId);
358
- return (_jsxs("section", { "data-ralphflow-run": true, "data-runid": String(data.runId ?? ""), style: { ...STYLE.root, ...(data.detached ? { opacity: 0.75 } : {}) }, children: [data.detached ? (_jsxs("div", { style: { marginBottom: "8px", padding: "5px 8px", borderRadius: "6px", background: "var(--dsw-alias-bg-layer-2)", fontSize: "12px", color: "var(--dsw-alias-label-secondary)" }, children: ["\u21AA ", tr(t, "run.detached", "此工作流已在另一个会话继续——本卡仅保留历史,不再更新。")] })) : null, _jsxs("div", { style: STYLE.head, children: [_jsx("span", { "aria-hidden": "true", style: { fontWeight: 600, color: "var(--dsw-alias-label-primary)", flexShrink: 0 }, children: "\uD83C\uDF00 Ralph Flow" }), _jsxs("span", { "aria-hidden": "true", style: { ...STYLE.mono, ...STYLE.shrinkName }, children: [data.workflow, shortId ? `·${shortId}` : ""] }), (data.current?.failCount ?? 0) > 0 && !data.stopReason ? (_jsxs("span", { style: { ...STYLE.mono, color: "var(--dsw-alias-state-error-primary)", flexShrink: 0 }, children: ["\u00D7", data.current.failCount] })) : null, elapsed ? _jsxs("span", { style: { ...STYLE.mono, fontSize: "11px", flexShrink: 0 }, title: tr(t, "run.elapsed.title", "当前步骤已运行时长"), children: ["\u23F1 ", elapsed] }) : null, _jsx("span", { style: { marginLeft: "auto", ...STYLE.badge(statusBg, statusFg) }, role: "status", children: statusLabel }), (data.stopReason === "done" || data.stopReason === "cancelled" || data.detached) && data.runId ? (_jsx("button", { type: "button", "aria-label": tr(t, "run.hide", "关闭这张卡片"), title: tr(t, "run.hide", "关闭这张卡片"), style: { border: "none", background: "transparent", color: "var(--dsw-alias-label-tertiary)", cursor: "pointer", fontSize: "13px", flexShrink: 0, padding: "0 2px" }, onClick: () => {
359
- try {
360
- hideRun(String(data.runId));
361
- }
362
- catch { }
363
- try {
364
- // 从 DOM 移除本节点(折叠器已不再匹配该 run 的任何后续帧)
365
- const section = document.querySelector(`[data-ralphflow-run][data-runid="${String(data.runId).replace(/"/g, '\\"')}"]`);
366
- section?.parentElement?.removeChild(section);
367
- }
368
- catch { }
369
- }, children: "\u00D7" })) : null] }), data.task ? _jsx("div", { style: STYLE.task, children: data.task }) : null, !Array.isArray(data.steps) || data.steps.length === 0 ? (_jsx("div", { style: { fontSize: "12.5px", color: "var(--dsw-alias-label-tertiary)", animation: live ? "ralphflow-breath 2.4s ease-in-out infinite" : undefined }, children: trf(t, "run.waiting.start", "正在等待模型开始执行…{step}", { step: data.current?.step ? `(${data.current.step})` : "" }) })) : null, Array.isArray(data.steps) && data.steps.length > 0 ? _jsx(StepBar, { steps: data.steps, current: data.current }) : null, !isPaused && !data.stopReason ? (_jsx(VoterPanel, { voterStarts: Array.isArray(data.voterStarts) ? data.voterStarts : [], verdicts: Array.isArray(data.verdicts) ? data.verdicts : [], votersTotal: data.voters, timeoutMs: data.timeoutMs, checkStartedAt: data.current?.phase === "check" ? data.stepStartedAt : undefined, now: Date.now(), t: t })) : null, Array.isArray(data.rewinds) && data.rewinds.length > 0 ? (_jsx("div", { children: data.rewinds.slice(-3).map((r, i) => (_jsxs("div", { style: STYLE.rewindRow, children: [trf(t, "run.rewind", "↩ 回退 {from} → {to}", { from: r.fromStep, to: r.toStep }), r.reason ? `:${String(r.reason).slice(0, 80)}` : ""] }, `${r.fromStep}>${r.toStep}-${i}`))) })) : null, data.lastCheck ? (_jsxs("div", { style: { marginTop: "6px" }, children: [_jsx("div", { style: { color: data.lastCheck.passed ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-state-error-primary)", fontWeight: 600 }, children: data.lastCheck.passed ? `✅ ${tr(t, "run.check.passed", "验证通过")}` : `❌ ${tr(t, "run.check.failed", "验证未通过")}` }), data.lastCheck.reason ? _jsx("div", { style: { ...STYLE.reason, marginTop: "2px" }, children: data.lastCheck.reason }) : null] })) : null, isPaused ? (_jsxs("div", { style: { marginTop: "8px", padding: "6px 8px", borderRadius: "6px", background: "var(--dsw-alias-state-warn-tertiary)", fontSize: "12.5px", color: "var(--dsw-alias-label-primary)" }, children: ["\u23F8 ", data.lastCheck && data.lastCheck.passed === false
370
- ? tr(t, "run.paused.hint.checkfailed", "这一步的验证没有通过,工作流停在这里等你。已完成的工作全部保留:点「继续」让模型带着失败原因重做,或用 /ralphflow-rewind 回退到更早的步骤。")
371
- : tr(t, "run.paused.hint", "工作流已暂停(验证未通过或达到失败上限)——这不是终点:修复问题后即可继续,已完成的工作全部保留。"), _jsx("div", { style: STYLE.actions, children: _jsxs("button", { style: STYLE.btn("primary"), onClick: () => {
372
- window.dispatchEvent(new CustomEvent("ralphflow:command", { detail: { command: "/ralphflow-continue", autoSubmit: true } }));
373
- }, children: ["\u25B6 ", tr(t, "run.resume", "继续")] }) })] })) : null, data.gate ? _jsx(GateCard, { gate: data.gate, t: t }) : null, data.report ? _jsx(ReportCard, { report: data.report, t: t }) : null] }));
374
- }
375
- export default RalphRunCard;
@@ -1,3 +0,0 @@
1
- export declare const name = "ralphflow-client";
2
- export declare const inject: string[];
3
- export declare function apply(ctx: any): void;