ralphflow-dsh 0.1.1 → 2.0.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/README.md +220 -167
- package/lib/create.d.ts +7 -11
- package/lib/create.js +132 -83
- package/lib/engine.d.ts +667 -262
- package/lib/engine.js +3583 -2579
- package/lib/index.d.ts +3 -4
- package/lib/index.js +222 -163
- package/lib/message-source.d.ts +25 -0
- package/lib/message-source.js +2 -0
- package/lib/reset.d.ts +40 -0
- package/lib/reset.js +147 -0
- package/lib/tools.d.ts +31 -14
- package/lib/tools.js +407 -684
- package/lib/verify.d.ts +57 -0
- package/lib/verify.js +326 -0
- package/lib/voting.d.ts +63 -0
- package/lib/voting.js +131 -0
- package/package.json +19 -44
- package/workflows/loop.yaml +21 -6
- package/workflows/spec.yaml +51 -46
- package/lib/actions.d.ts +0 -37
- package/lib/actions.js +0 -55
- package/lib/check-voting.d.ts +0 -54
- package/lib/check-voting.js +0 -289
- package/lib/check.d.ts +0 -64
- package/lib/check.js +0 -329
- package/lib/client/CommandCard.d.ts +0 -24
- package/lib/client/CommandCard.js +0 -69
- package/lib/client/HeaderAction.d.ts +0 -39
- package/lib/client/HeaderAction.js +0 -509
- package/lib/client/RunCard.d.ts +0 -27
- package/lib/client/RunCard.js +0 -375
- package/lib/client/client.d.ts +0 -3
- package/lib/client/client.js +0 -275
- package/lib/client/definition.d.ts +0 -126
- package/lib/client/definition.js +0 -259
- package/lib/client/hidden-runs.d.ts +0 -6
- package/lib/client/hidden-runs.js +0 -52
- package/lib/client/http-state.d.ts +0 -67
- package/lib/client/http-state.js +0 -81
- package/lib/client/markdown.d.ts +0 -26
- package/lib/client/markdown.js +0 -174
- package/lib/client/notify-watch.d.ts +0 -38
- package/lib/client/notify-watch.js +0 -98
- package/lib/client/notify.d.ts +0 -21
- package/lib/client/notify.js +0 -168
- package/lib/client/snapshots.d.ts +0 -8
- package/lib/client/snapshots.js +0 -101
- package/lib/client.js +0 -2361
- package/lib/commands.d.ts +0 -41
- package/lib/commands.js +0 -223
- package/lib/deps.d.ts +0 -17
- package/lib/deps.js +0 -19
- package/lib/done-detect.d.ts +0 -2
- package/lib/done-detect.js +0 -28
- package/lib/driver.d.ts +0 -32
- package/lib/driver.js +0 -248
- package/lib/events.d.ts +0 -35
- package/lib/events.js +0 -52
- package/lib/jobs.d.ts +0 -56
- package/lib/jobs.js +0 -355
- package/lib/mutex.d.ts +0 -9
- package/lib/mutex.js +0 -21
- package/lib/session-hygiene.d.ts +0 -25
- package/lib/session-hygiene.js +0 -205
- package/lib/voting-progress.d.ts +0 -37
- package/lib/voting-progress.js +0 -89
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ralph Flow for dsh — 手动隐藏 run 卡(存量僵尸卡的最终出口)
|
|
3
|
-
*
|
|
4
|
-
* 修复前的历史遗留:某些旧卡片收不到任何终态帧(跨会话接管时代产生的僵尸),
|
|
5
|
-
* 实例本身可能早已销毁——没有任何帧能把它们救活。给终态卡一个 × 关闭按钮,
|
|
6
|
-
* runId 进 localStorage 屏蔽名单,折叠器 match 层直接过滤。内存缓存避免高频
|
|
7
|
-
* localStorage 读;跨标签页通过 storage 事件同步。
|
|
8
|
-
*/
|
|
9
|
-
const KEY = "ralphflow:hidden-runs";
|
|
10
|
-
let cache = null;
|
|
11
|
-
function load() {
|
|
12
|
-
if (cache)
|
|
13
|
-
return cache;
|
|
14
|
-
try {
|
|
15
|
-
const raw = localStorage.getItem(KEY);
|
|
16
|
-
cache = new Set(raw ? JSON.parse(raw) : []);
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
cache = new Set();
|
|
20
|
-
}
|
|
21
|
-
return cache;
|
|
22
|
-
}
|
|
23
|
-
function persist(set) {
|
|
24
|
-
try {
|
|
25
|
-
localStorage.setItem(KEY, JSON.stringify([...set].slice(-300)));
|
|
26
|
-
cache = set;
|
|
27
|
-
}
|
|
28
|
-
catch { }
|
|
29
|
-
}
|
|
30
|
-
export function isRunHidden(runId) {
|
|
31
|
-
if (!runId)
|
|
32
|
-
return false;
|
|
33
|
-
try {
|
|
34
|
-
return load().has(runId);
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export function hideRun(runId) {
|
|
41
|
-
try {
|
|
42
|
-
const s = load();
|
|
43
|
-
s.add(runId);
|
|
44
|
-
persist(s);
|
|
45
|
-
}
|
|
46
|
-
catch { }
|
|
47
|
-
}
|
|
48
|
-
/** 折叠器入口:被屏蔽的 run 直接不匹配(不建卡、不更新) */
|
|
49
|
-
export function isHiddenEvent(data) {
|
|
50
|
-
const id = data?.runId;
|
|
51
|
-
return typeof id === "string" && id.length > 0 && isRunHidden(id);
|
|
52
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
export interface HttpInstanceState {
|
|
2
|
-
runId: string;
|
|
3
|
-
workflow: string;
|
|
4
|
-
task: string;
|
|
5
|
-
current: {
|
|
6
|
-
step: string;
|
|
7
|
-
phase: string;
|
|
8
|
-
failCount: number;
|
|
9
|
-
} | null;
|
|
10
|
-
steps?: {
|
|
11
|
-
id: string;
|
|
12
|
-
desc: string;
|
|
13
|
-
}[];
|
|
14
|
-
owner?: string | null;
|
|
15
|
-
paused?: boolean;
|
|
16
|
-
pauseReason?: string;
|
|
17
|
-
lastFailureReason?: string;
|
|
18
|
-
startedAt?: string;
|
|
19
|
-
gate?: {
|
|
20
|
-
step: string;
|
|
21
|
-
title: string;
|
|
22
|
-
reason: string;
|
|
23
|
-
taskExcerpt?: string;
|
|
24
|
-
} | null;
|
|
25
|
-
voters?: number;
|
|
26
|
-
/** 本轮 CHECK 的超时上限(ms)——「剩余时间」进度条终点感 */
|
|
27
|
-
timeoutMs?: number;
|
|
28
|
-
/** 本轮 CHECK 的开始时刻(ms)——超时进度条起点 */
|
|
29
|
-
checkStartedAt?: number;
|
|
30
|
-
voterProgress?: {
|
|
31
|
-
voter: number;
|
|
32
|
-
status: string;
|
|
33
|
-
model: string | null;
|
|
34
|
-
check: string;
|
|
35
|
-
startedAt?: number;
|
|
36
|
-
reason?: string;
|
|
37
|
-
}[];
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* CHECK 剩余时间(纯函数,可单测):返回剩余 ms、已消耗比例与是否超时。
|
|
41
|
-
* 字段缺失(进程重启后内存态丢失等)返回 null——UI 降级为不画进度条。
|
|
42
|
-
*/
|
|
43
|
-
export declare function checkTimeLeft(checkStartedAt?: number, timeoutMs?: number, now?: number): {
|
|
44
|
-
leftMs: number;
|
|
45
|
-
ratio: number;
|
|
46
|
-
over: boolean;
|
|
47
|
-
} | null;
|
|
48
|
-
export interface HttpStatePayload {
|
|
49
|
-
instances: HttpInstanceState[];
|
|
50
|
-
/** 引擎可启动的工作流名清单(client 端命令卡折叠器据此识别 /loop /spec 等快捷命令) */
|
|
51
|
-
workflows?: string[];
|
|
52
|
-
/** history 尾部条目(completed/cancelled;完成通知与历史面板数据源) */
|
|
53
|
-
recentEnded?: {
|
|
54
|
-
instId: string;
|
|
55
|
-
workflow: string;
|
|
56
|
-
task?: string;
|
|
57
|
-
status?: string;
|
|
58
|
-
endedAt?: number;
|
|
59
|
-
reportPath?: string;
|
|
60
|
-
}[];
|
|
61
|
-
ts: number;
|
|
62
|
-
}
|
|
63
|
-
/** 启动轮询(幂等;由 client.ts apply 调用一次) */
|
|
64
|
-
export declare function startHttpPolling(intervalMs?: number): void;
|
|
65
|
-
/** React 组件侧 hook:全局实例状态(stale-while-poll,首帧后 2.5s 刷新) */
|
|
66
|
-
export declare function useRalphHttpState(): HttpStatePayload;
|
|
67
|
-
export declare function httpStateCache(): HttpStatePayload;
|
package/lib/client/http-state.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ralph Flow for dsh — HTTP 状态轮询 store(UI 主数据源)
|
|
3
|
-
*
|
|
4
|
-
* 背景:宿主持久化不接受插件自定义 session 事件(会砖掉会话),对话内卡片
|
|
5
|
-
* 折叠所依赖的帧通道已废弃。这里改为轮询 host 的 /ralphflow/instances 端点,
|
|
6
|
-
* 用 useSyncExternalStore 把「全局实例富状态」暴露给 React 组件——页头抽屉、
|
|
7
|
-
* mini pipeline、验证者活体面板全部以它为准。
|
|
8
|
-
*
|
|
9
|
-
* 设计:纯状态 + 无副作用订阅;轮询循环由 client.ts apply 启动(单例)。
|
|
10
|
-
*/
|
|
11
|
-
import { useSyncExternalStore } from "react";
|
|
12
|
-
import { registerWorkflowShortcutNames } from "./definition.js";
|
|
13
|
-
/**
|
|
14
|
-
* CHECK 剩余时间(纯函数,可单测):返回剩余 ms、已消耗比例与是否超时。
|
|
15
|
-
* 字段缺失(进程重启后内存态丢失等)返回 null——UI 降级为不画进度条。
|
|
16
|
-
*/
|
|
17
|
-
export function checkTimeLeft(checkStartedAt, timeoutMs, now = Date.now()) {
|
|
18
|
-
if (typeof checkStartedAt !== "number" || checkStartedAt <= 0 || typeof timeoutMs !== "number" || timeoutMs <= 0)
|
|
19
|
-
return null;
|
|
20
|
-
const elapsed = Math.max(0, now - checkStartedAt);
|
|
21
|
-
const leftMs = Math.max(0, timeoutMs - elapsed);
|
|
22
|
-
return { leftMs, ratio: Math.min(1, elapsed / timeoutMs), over: elapsed >= timeoutMs };
|
|
23
|
-
}
|
|
24
|
-
let snapshot = { instances: [], workflows: [], ts: 0 };
|
|
25
|
-
const listeners = new Set();
|
|
26
|
-
let started = false;
|
|
27
|
-
function emit() {
|
|
28
|
-
for (const l of [...listeners]) {
|
|
29
|
-
try {
|
|
30
|
-
l();
|
|
31
|
-
}
|
|
32
|
-
catch { }
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
async function tick() {
|
|
36
|
-
try {
|
|
37
|
-
const res = await fetch("/ralphflow/instances", { cache: "no-store" });
|
|
38
|
-
if (res.ok) {
|
|
39
|
-
const data = (await res.json());
|
|
40
|
-
if (Array.isArray(data?.instances)) {
|
|
41
|
-
const workflows = Array.isArray(data.workflows) ? data.workflows : snapshot.workflows;
|
|
42
|
-
snapshot = { instances: data.instances, workflows, ts: Date.now() };
|
|
43
|
-
// 工作流清单是命令卡折叠器识别 /loop /spec 等快捷命令的依据,随时喂入
|
|
44
|
-
try {
|
|
45
|
-
registerWorkflowShortcutNames(workflows ?? []);
|
|
46
|
-
}
|
|
47
|
-
catch { }
|
|
48
|
-
emit();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
// host 未就绪/离站:保持上次快照,下轮再试
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/** 启动轮询(幂等;由 client.ts apply 调用一次) */
|
|
57
|
-
export function startHttpPolling(intervalMs = 2500) {
|
|
58
|
-
if (started)
|
|
59
|
-
return;
|
|
60
|
-
started = true;
|
|
61
|
-
void tick();
|
|
62
|
-
const h = window.setInterval(() => void tick(), intervalMs);
|
|
63
|
-
try {
|
|
64
|
-
window.addEventListener("unload", () => clearInterval(h), { once: true });
|
|
65
|
-
}
|
|
66
|
-
catch { }
|
|
67
|
-
}
|
|
68
|
-
function subscribe(cb) {
|
|
69
|
-
listeners.add(cb);
|
|
70
|
-
return () => { listeners.delete(cb); };
|
|
71
|
-
}
|
|
72
|
-
function getSnapshot() {
|
|
73
|
-
return snapshot;
|
|
74
|
-
}
|
|
75
|
-
/** React 组件侧 hook:全局实例状态(stale-while-poll,首帧后 2.5s 刷新) */
|
|
76
|
-
export function useRalphHttpState() {
|
|
77
|
-
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
78
|
-
}
|
|
79
|
-
export function httpStateCache() {
|
|
80
|
-
return snapshot;
|
|
81
|
-
}
|
package/lib/client/markdown.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ralph Flow for dsh — 轻量 Markdown 渲染(报告卡专用)
|
|
3
|
-
*
|
|
4
|
-
* 最终报告是 markdown 写的,用等宽 pre 渲染等于看源码。这里实现一个克制的
|
|
5
|
-
* 子集解析:标题/列表/围栏代码/行内代码/粗体/斜体/链接/引用/分割线。
|
|
6
|
-
* 不引外部依赖(bundle external 面只允许官方包,自写最稳),样式全部消费
|
|
7
|
-
* dsh 主题 token。解析失败永远降级为纯文本——绝不因格式怪异白屏。
|
|
8
|
-
*/
|
|
9
|
-
import * as React from "react";
|
|
10
|
-
interface InlineToken {
|
|
11
|
-
type: "text" | "bold" | "italic" | "code" | "link";
|
|
12
|
-
text: string;
|
|
13
|
-
href?: string;
|
|
14
|
-
}
|
|
15
|
-
/** 行内解析:`code` → **bold** → *italic* → [text](href),顺序 tokenize */
|
|
16
|
-
export declare function parseInline(text: string): InlineToken[];
|
|
17
|
-
/** 链接协议白名单:相对路径/锚点/文件/https/http/mailto;其余一律降级为纯文本 */
|
|
18
|
-
export declare function safeLinkHref(href: string | undefined): string | null;
|
|
19
|
-
/**
|
|
20
|
-
* 解析并渲染 markdown 子集。任何异常都降级为纯文本 pre——报告可读性优先于
|
|
21
|
-
* 格式正确性,绝不让渲染器本身成为新的故障点。
|
|
22
|
-
*/
|
|
23
|
-
export declare function Markdown({ text }: {
|
|
24
|
-
text: string;
|
|
25
|
-
}): React.ReactElement;
|
|
26
|
-
export default Markdown;
|
package/lib/client/markdown.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
/** 行内解析:`code` → **bold** → *italic* → [text](href),顺序 tokenize */
|
|
3
|
-
export function parseInline(text) {
|
|
4
|
-
const tokens = [];
|
|
5
|
-
const re = /(`[^`]+`)|(\*\*[^*]+\*\*)|(\*[^*\s][^*]*\*)|(\[[^\]]+\]\([^)\s]+\))/g;
|
|
6
|
-
let last = 0;
|
|
7
|
-
let m;
|
|
8
|
-
while ((m = re.exec(text)) !== null) {
|
|
9
|
-
if (m.index > last)
|
|
10
|
-
tokens.push({ type: "text", text: text.slice(last, m.index) });
|
|
11
|
-
const raw = m[0];
|
|
12
|
-
if (raw.startsWith("`"))
|
|
13
|
-
tokens.push({ type: "code", text: raw.slice(1, -1) });
|
|
14
|
-
else if (raw.startsWith("**"))
|
|
15
|
-
tokens.push({ type: "bold", text: raw.slice(2, -2) });
|
|
16
|
-
else if (raw.startsWith("*"))
|
|
17
|
-
tokens.push({ type: "italic", text: raw.slice(1, -1) });
|
|
18
|
-
else {
|
|
19
|
-
const link = /^\[([^\]]+)\]\(([^)\s]+)\)$/.exec(raw);
|
|
20
|
-
tokens.push(link ? { type: "link", text: link[1], href: link[2] } : { type: "text", text: raw });
|
|
21
|
-
}
|
|
22
|
-
last = m.index + raw.length;
|
|
23
|
-
}
|
|
24
|
-
if (last < text.length)
|
|
25
|
-
tokens.push({ type: "text", text: text.slice(last) });
|
|
26
|
-
return tokens.length > 0 ? tokens : [{ type: "text", text }];
|
|
27
|
-
}
|
|
28
|
-
function renderInline(tokens, keyPrefix) {
|
|
29
|
-
return tokens.map((tk, i) => {
|
|
30
|
-
const key = `${keyPrefix}-${i}`;
|
|
31
|
-
switch (tk.type) {
|
|
32
|
-
case "code": return _jsx("code", { style: { fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace", fontSize: "0.92em", background: "var(--dsw-alias-bg-layer-2)", borderRadius: "4px", padding: "1px 5px" }, children: tk.text }, key);
|
|
33
|
-
case "bold": return _jsx("strong", { style: { fontWeight: 600 }, children: tk.text }, key);
|
|
34
|
-
case "italic": return _jsx("em", { children: tk.text }, key);
|
|
35
|
-
case "link": {
|
|
36
|
-
// 链接目标消毒:只放行相对路径与安全 scheme,挡住 javascript:/data: 等
|
|
37
|
-
// 注入向量(报告/判定文本来自子代理输出,不能信任)。
|
|
38
|
-
const href = safeLinkHref(tk.href);
|
|
39
|
-
return href === null
|
|
40
|
-
? _jsx("span", { children: tk.text }, key)
|
|
41
|
-
: _jsx("a", { href: href, target: "_blank", rel: "noreferrer", style: { color: "var(--dsw-alias-state-business-primary)" }, children: tk.text }, key);
|
|
42
|
-
}
|
|
43
|
-
default: return _jsx("span", { children: tk.text }, key);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
/** 链接协议白名单:相对路径/锚点/文件/https/http/mailto;其余一律降级为纯文本 */
|
|
48
|
-
export function safeLinkHref(href) {
|
|
49
|
-
try {
|
|
50
|
-
if (!href)
|
|
51
|
-
return null;
|
|
52
|
-
const h = href.trim();
|
|
53
|
-
if (h.startsWith("#") || h.startsWith("/") || h.startsWith("./") || h.startsWith("../"))
|
|
54
|
-
return h;
|
|
55
|
-
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(h)) {
|
|
56
|
-
return /^(https?|mailto|file):/i.test(h) ? h : null;
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const block = {
|
|
65
|
-
h1: { fontSize: "16px", fontWeight: 600, margin: "10px 0 4px", color: "var(--dsw-alias-label-primary)" },
|
|
66
|
-
h2: { fontSize: "14.5px", fontWeight: 600, margin: "10px 0 4px", color: "var(--dsw-alias-label-primary)" },
|
|
67
|
-
h3: { fontSize: "13.5px", fontWeight: 600, margin: "8px 0 3px", color: "var(--dsw-alias-label-primary)" },
|
|
68
|
-
p: { margin: "3px 0" },
|
|
69
|
-
li: { margin: "2px 0", marginLeft: "18px" },
|
|
70
|
-
quote: { borderLeft: "3px solid var(--dsw-alias-border-l2)", margin: "6px 0", padding: "2px 10px", color: "var(--dsw-alias-label-secondary)" },
|
|
71
|
-
codeBlock: {
|
|
72
|
-
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
|
|
73
|
-
fontSize: "12px",
|
|
74
|
-
background: "var(--dsw-alias-bg-layer-2)",
|
|
75
|
-
borderRadius: "6px",
|
|
76
|
-
padding: "8px 10px",
|
|
77
|
-
overflowX: "auto",
|
|
78
|
-
whiteSpace: "pre-wrap",
|
|
79
|
-
wordBreak: "break-word",
|
|
80
|
-
margin: "6px 0",
|
|
81
|
-
},
|
|
82
|
-
hr: { border: "none", borderTop: "1px solid var(--dsw-alias-border-l1)", margin: "10px 0" },
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* 解析并渲染 markdown 子集。任何异常都降级为纯文本 pre——报告可读性优先于
|
|
86
|
-
* 格式正确性,绝不让渲染器本身成为新的故障点。
|
|
87
|
-
*/
|
|
88
|
-
export function Markdown({ text }) {
|
|
89
|
-
try {
|
|
90
|
-
const lines = String(text ?? "").split("\n");
|
|
91
|
-
const out = [];
|
|
92
|
-
let i = 0;
|
|
93
|
-
let key = 0;
|
|
94
|
-
while (i < lines.length) {
|
|
95
|
-
const line = lines[i];
|
|
96
|
-
// 围栏代码块
|
|
97
|
-
if (/^\s*```/.test(line)) {
|
|
98
|
-
const buf = [];
|
|
99
|
-
i++;
|
|
100
|
-
while (i < lines.length && !/^\s*```/.test(lines[i])) {
|
|
101
|
-
buf.push(lines[i]);
|
|
102
|
-
i++;
|
|
103
|
-
}
|
|
104
|
-
i++; // 跳过闭合围栏
|
|
105
|
-
out.push(_jsx("pre", { style: block.codeBlock, children: buf.join("\n") }, key++));
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
// 分割线
|
|
109
|
-
if (/^\s*(---+|\*\*\*+)\s*$/.test(line)) {
|
|
110
|
-
out.push(_jsx("hr", { style: block.hr }, key++));
|
|
111
|
-
i++;
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
// 标题
|
|
115
|
-
const head = /^(#{1,4})\s+(.*)$/.exec(line);
|
|
116
|
-
if (head) {
|
|
117
|
-
const level = head[1].length;
|
|
118
|
-
const st = level === 1 ? block.h1 : level === 2 ? block.h2 : block.h3;
|
|
119
|
-
out.push(_jsx("div", { style: st, children: renderInline(parseInline(head[2]), `h${key}`) }, key++));
|
|
120
|
-
i++;
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
// 引用(连续行合并)
|
|
124
|
-
if (/^\s*>\s?/.test(line)) {
|
|
125
|
-
const buf = [];
|
|
126
|
-
while (i < lines.length && /^\s*>\s?/.test(lines[i])) {
|
|
127
|
-
buf.push(lines[i].replace(/^\s*>\s?/, ""));
|
|
128
|
-
i++;
|
|
129
|
-
}
|
|
130
|
-
out.push(_jsx("blockquote", { style: block.quote, children: renderInline(parseInline(buf.join(" ")), `q${key}`) }, key++));
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
// 无序列表(连续行)
|
|
134
|
-
if (/^\s*[-*]\s+/.test(line)) {
|
|
135
|
-
const items = [];
|
|
136
|
-
while (i < lines.length && /^\s*[-*]\s+/.test(lines[i])) {
|
|
137
|
-
items.push(lines[i].replace(/^\s*[-*]\s+/, ""));
|
|
138
|
-
i++;
|
|
139
|
-
}
|
|
140
|
-
out.push(_jsx("ul", { style: { margin: "4px 0", paddingLeft: "4px" }, children: items.map((it, j) => _jsx("li", { style: block.li, children: renderInline(parseInline(it), `u${key}-${j}`) }, j)) }, key++));
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
// 有序列表(连续行)
|
|
144
|
-
if (/^\s*\d+[.)]\s+/.test(line)) {
|
|
145
|
-
const items = [];
|
|
146
|
-
while (i < lines.length && /^\s*\d+[.)]\s+/.test(lines[i])) {
|
|
147
|
-
items.push(lines[i].replace(/^\s*\d+[.)]\s+/, ""));
|
|
148
|
-
i++;
|
|
149
|
-
}
|
|
150
|
-
out.push(_jsx("ol", { style: { margin: "4px 0", paddingLeft: "20px" }, children: items.map((it, j) => _jsx("li", { style: block.li, children: renderInline(parseInline(it), `o${key}-${j}`) }, j)) }, key++));
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
// 空行跳过;其余按段落聚合连续非空行
|
|
154
|
-
if (!line.trim()) {
|
|
155
|
-
i++;
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
const buf = [];
|
|
159
|
-
while (i < lines.length && lines[i].trim() && !/^\s*(#{1,4}\s|[-*]\s|\d+[.)]\s|>|```|---+$)/.test(lines[i])) {
|
|
160
|
-
buf.push(lines[i]);
|
|
161
|
-
i++;
|
|
162
|
-
}
|
|
163
|
-
if (buf.length > 0)
|
|
164
|
-
out.push(_jsx("p", { style: block.p, children: renderInline(parseInline(buf.join("\n")), `p${key}`) }, key++));
|
|
165
|
-
else
|
|
166
|
-
i++; // 防御:单行不匹配任何块且不进段落时前进,避免死循环
|
|
167
|
-
}
|
|
168
|
-
return _jsx("div", { children: out });
|
|
169
|
-
}
|
|
170
|
-
catch {
|
|
171
|
-
return _jsx("div", { style: { whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: String(text ?? "") });
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
export default Markdown;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ralph Flow for dsh — 全局通知/快照监视(模块级,不依赖任何组件挂载)
|
|
3
|
-
*
|
|
4
|
-
* 组件(HeaderAction)只挂在会话页头槽位;用户停在空状态页或别的会话时,
|
|
5
|
-
* 「待审查 / 已暂停 / 已完成」到达不能没人提醒。本模块在 client apply 启动时
|
|
6
|
-
* 挂到 HTTP 状态通道(单例轮询,与 http-state 同频):
|
|
7
|
-
* - gate 出现 → 待你审查;stopReason 翻转为 failed → 已暂停;
|
|
8
|
-
* - host 的 recentEnded(history 尾部 completed 条目)→ 已完成(带 cursor
|
|
9
|
-
* 预填,切换页面/刷新不重复轰炸历史完成记录);
|
|
10
|
-
* - 边沿变化同时写 localStorage 快照(刷新后抽屉「已结束/待处理」补盲)。
|
|
11
|
-
* 通知走 notify.ts 既有去重与疲劳控制;HTTP 不可用(headless 等无 webServer
|
|
12
|
-
* 形态)时平滑降级为零存在感。
|
|
13
|
-
*/
|
|
14
|
-
import { type HttpStatePayload } from "./http-state.js";
|
|
15
|
-
export type WatchEventKind = "gate" | "paused" | "done";
|
|
16
|
-
export interface WatchEvent {
|
|
17
|
-
kind: WatchEventKind;
|
|
18
|
-
runId: string;
|
|
19
|
-
workflow: string;
|
|
20
|
-
}
|
|
21
|
-
export interface WatchState {
|
|
22
|
-
/** runId → 上一次已通知的状态(gate/stopReason 边沿检测源) */
|
|
23
|
-
runs: Map<string, {
|
|
24
|
-
gate: unknown;
|
|
25
|
-
stopReason?: string;
|
|
26
|
-
}>;
|
|
27
|
-
/** recentEnded 消费游标:与 host history 尾部对齐,防首帧误报历史完成 */
|
|
28
|
-
endedCursor: number;
|
|
29
|
-
}
|
|
30
|
-
/** 初始态:cursor=0 表示「尚未预填」,首轮以最新 endedAt 预填、不发事件 */
|
|
31
|
-
export declare function initialWatchState(): WatchState;
|
|
32
|
-
/** 纯差分:对比上一轮快照与当前 payload,产出需要提醒的事件与下一态(可单测) */
|
|
33
|
-
export declare function diffWatchState(prev: WatchState, payload: HttpStatePayload): {
|
|
34
|
-
events: WatchEvent[];
|
|
35
|
-
next: WatchState;
|
|
36
|
-
};
|
|
37
|
-
/** 启动全局监视(幂等;由 client.ts apply 调用一次) */
|
|
38
|
-
export declare function startNotifyWatch(intervalMs?: number): void;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ralph Flow for dsh — 全局通知/快照监视(模块级,不依赖任何组件挂载)
|
|
3
|
-
*
|
|
4
|
-
* 组件(HeaderAction)只挂在会话页头槽位;用户停在空状态页或别的会话时,
|
|
5
|
-
* 「待审查 / 已暂停 / 已完成」到达不能没人提醒。本模块在 client apply 启动时
|
|
6
|
-
* 挂到 HTTP 状态通道(单例轮询,与 http-state 同频):
|
|
7
|
-
* - gate 出现 → 待你审查;stopReason 翻转为 failed → 已暂停;
|
|
8
|
-
* - host 的 recentEnded(history 尾部 completed 条目)→ 已完成(带 cursor
|
|
9
|
-
* 预填,切换页面/刷新不重复轰炸历史完成记录);
|
|
10
|
-
* - 边沿变化同时写 localStorage 快照(刷新后抽屉「已结束/待处理」补盲)。
|
|
11
|
-
* 通知走 notify.ts 既有去重与疲劳控制;HTTP 不可用(headless 等无 webServer
|
|
12
|
-
* 形态)时平滑降级为零存在感。
|
|
13
|
-
*/
|
|
14
|
-
import { httpStateCache } from "./http-state.js";
|
|
15
|
-
import { notifyRunEvent, shouldNotifyRun } from "./notify.js";
|
|
16
|
-
import { saveRunSnapshot } from "./snapshots.js";
|
|
17
|
-
/** 初始态:cursor=0 表示「尚未预填」,首轮以最新 endedAt 预填、不发事件 */
|
|
18
|
-
export function initialWatchState() {
|
|
19
|
-
return { runs: new Map(), endedCursor: 0 };
|
|
20
|
-
}
|
|
21
|
-
/** 纯差分:对比上一轮快照与当前 payload,产出需要提醒的事件与下一态(可单测) */
|
|
22
|
-
export function diffWatchState(prev, payload) {
|
|
23
|
-
const events = [];
|
|
24
|
-
const runs = new Map();
|
|
25
|
-
for (const inst of Array.isArray(payload.instances) ? payload.instances : []) {
|
|
26
|
-
const runId = String(inst?.runId ?? "");
|
|
27
|
-
if (!runId)
|
|
28
|
-
continue;
|
|
29
|
-
const gate = inst.gate ?? null;
|
|
30
|
-
const stopReason = inst.paused ? "failed" : undefined;
|
|
31
|
-
runs.set(runId, { gate, stopReason });
|
|
32
|
-
const before = prev.runs.get(runId);
|
|
33
|
-
if (before) {
|
|
34
|
-
const kind = shouldNotifyRun(before.stopReason, stopReason, before.gate, gate);
|
|
35
|
-
if (kind)
|
|
36
|
-
events.push({ kind, runId, workflow: String(inst.workflow ?? "") });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const endedList = Array.isArray(payload.recentEnded) ? payload.recentEnded : [];
|
|
40
|
-
let maxEnded = prev.endedCursor;
|
|
41
|
-
for (const e of endedList) {
|
|
42
|
-
const endedAt = Number(e?.endedAt ?? 0);
|
|
43
|
-
if (endedAt > maxEnded)
|
|
44
|
-
maxEnded = endedAt;
|
|
45
|
-
}
|
|
46
|
-
const next = { runs, endedCursor: maxEnded };
|
|
47
|
-
if (prev.endedCursor === 0) {
|
|
48
|
-
// 首轮预填:把存量 history 整体当作已读,不历史轰炸
|
|
49
|
-
return { events: [], next };
|
|
50
|
-
}
|
|
51
|
-
for (const e of endedList) {
|
|
52
|
-
const endedAt = Number(e?.endedAt ?? 0);
|
|
53
|
-
if (e?.status !== "completed" || !endedAt || endedAt <= prev.endedCursor)
|
|
54
|
-
continue;
|
|
55
|
-
const runId = String(e?.instId ?? "");
|
|
56
|
-
if (!runId)
|
|
57
|
-
continue;
|
|
58
|
-
events.push({ kind: "done", runId, workflow: String(e?.workflow ?? "") });
|
|
59
|
-
}
|
|
60
|
-
return { events, next };
|
|
61
|
-
}
|
|
62
|
-
let prev = initialWatchState();
|
|
63
|
-
let started = false;
|
|
64
|
-
function tick() {
|
|
65
|
-
try {
|
|
66
|
-
const payload = httpStateCache();
|
|
67
|
-
const { events, next } = diffWatchState(prev, payload);
|
|
68
|
-
prev = next;
|
|
69
|
-
for (const ev of events) {
|
|
70
|
-
try {
|
|
71
|
-
notifyRunEvent(ev.runId, ev.workflow, ev.kind);
|
|
72
|
-
}
|
|
73
|
-
catch { }
|
|
74
|
-
// 边沿落快照:结束/暂停/待审查的 run 在刷新后仍在抽屉可见(HTTP 主源缺席时)
|
|
75
|
-
try {
|
|
76
|
-
saveRunSnapshot({
|
|
77
|
-
runId: ev.runId,
|
|
78
|
-
workflow: ev.workflow,
|
|
79
|
-
stopReason: ev.kind === "done" ? "done" : ev.kind === "paused" ? "failed" : undefined,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
catch { }
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch { }
|
|
86
|
-
}
|
|
87
|
-
/** 启动全局监视(幂等;由 client.ts apply 调用一次) */
|
|
88
|
-
export function startNotifyWatch(intervalMs = 2500) {
|
|
89
|
-
if (started)
|
|
90
|
-
return;
|
|
91
|
-
started = true;
|
|
92
|
-
tick();
|
|
93
|
-
const h = window.setInterval(() => void tick(), intervalMs);
|
|
94
|
-
try {
|
|
95
|
-
window.addEventListener("unload", () => clearInterval(h), { once: true });
|
|
96
|
-
}
|
|
97
|
-
catch { }
|
|
98
|
-
}
|
package/lib/client/notify.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ralph Flow for dsh — 桌面通知 + 标签页标题提醒
|
|
3
|
-
*
|
|
4
|
-
* 等待的本质问题是「你在等它,但不知道要等多久」——于是切去干别的,回来才
|
|
5
|
-
* 发现它早就停在那等你了。终态事件(审查门/暂停/完成)弹系统通知并让标签页
|
|
6
|
-
* 标题闪烁,点通知聚焦窗口。全部容错:权限被拒/环境不支持时静默降级为零
|
|
7
|
-
* 存在感;sessionStorage 去重防止事件重放(接管历史回放)重复轰炸。
|
|
8
|
-
*/
|
|
9
|
-
export declare function notificationsSupported(): boolean;
|
|
10
|
-
/** 首次交互时请求权限(浏览器要求用户手势);静默失败不打扰 */
|
|
11
|
-
export declare function primeNotifications(): void;
|
|
12
|
-
/** 标题闪烁直到窗口获得焦点或超次;原始标题始终可恢复 */
|
|
13
|
-
export declare function flashTitle(text: string): void;
|
|
14
|
-
/**
|
|
15
|
-
* 判定一个 run 状态变化是否值得提醒用户(供 UI 层调用;纯函数便于单测)。
|
|
16
|
-
* kind: gate=待审查 / paused=已暂停 / done=已完成。cancelled 是用户自己点的,
|
|
17
|
-
* 不打扰。
|
|
18
|
-
*/
|
|
19
|
-
export declare function shouldNotifyRun(prevStopReason: string | undefined, nextStopReason: string | undefined, prevGate: unknown, nextGate: unknown): "gate" | "paused" | "done" | null;
|
|
20
|
-
/** UI 副作用入口:去重后发系统通知 + 标题闪烁 */
|
|
21
|
-
export declare function notifyRunEvent(runId: string, workflow: string, kind: "gate" | "paused" | "done"): void;
|