Initial import of streamline

This commit is contained in:
2026-11-16 17:26:44 -08:00
commit 8e4aec1855
1221 changed files with 274256 additions and 0 deletions
+314
View File
@@ -0,0 +1,314 @@
import { useState } from "react";
import { createRoot } from "react-dom/client";
import "../styles.css";
import "../styles/dashboard.css";
import {
api, type LoopOverview, type LoopExperiment, type LoopExperimentDetail, type LoopShipView, type LoopShipOption,
type LoopShipScope, type LoopStatus, type LoopEvent,
} from "../lib/api";
import RsiLoop from "../components/RsiLoop";
import Toaster from "../components/Toaster";
import DialogHost from "../components/DialogHost";
/**
* 本地演示:自我改进 → 实验里的「上线决策」(批准上线 / 驳回 / 重跑一端 / 补另一端)。
* 面板是真组件(RsiLoop),回路的几个接口在这里打桩,状态存在内存里,刷新页面重置。
*
* 打开方式:control-web 下 `API_TARGET=http://127.0.0.1:9 bun x vite --port 8092`,访问
* /demo-rsi-ship.html(API_TARGET 指向死端口,保证不会代理到任何真实服务)。
*
* 打桩只模拟「控制面算好的东西」—— 真正的规则与补丁校验在 control-server/src/rsi_ship_service.ts
* 与 shared/src/rsi_ship.ts,单测在 control-server/test/rsi_ship.test.ts。
*/
const now = Date.now();
const H = 3_600_000;
const wait = (ms: number) => new Promise((r) => setTimeout(r, ms));
type Plat = "ios" | "android";
interface Member { id: string; platform: Plat; status: LoopStatus; reason: string; labReason?: string; inconclusive?: boolean; createdAt: number; shipScope?: string | null; promotedAt?: number | null }
interface Case {
title: string; note: string; kind: "prompt" | "runtime"; scope: "both" | Plat; target: string;
members: Member[];
added?: string[]; profile?: Record<string, string>;
/** 补丁冲突时的错误(演示「补丁不可用」)。 */
conflict?: string;
drift?: { platform: string; lines: number }[];
}
const PASS = (t: string) => `复跑通过:${t}`;
const CASES: Case[] = [
{
title: "进入目标页前先等首页 feed 加载完", kind: "prompt", scope: "both", target: "reach_s",
note: "① 双端策略,两端都通过 → 只有「两端一起上线」",
members: [
{ id: "c1-ios", platform: "ios", status: "lab_passed", reason: PASS("到达复现现场 44.1 → 36.8 分(5 对);自报修好 4 → 4;到达 4 → 5"), createdAt: now - 70 * H },
{ id: "c1-and", platform: "android", status: "lab_passed", reason: PASS("到达复现现场 31.2 → 27.9 分(5 对);自报修好 3 → 4;到达 4 → 4"), createdAt: now - 70 * H + 1 },
],
added: ["- 冷启动后先确认首页 feed 已出现第一条内容,再去点目标入口;feed 没出来就等,不要先点入口再回头等。"],
},
{
title: "deeplink 打不开时换成首页入口走", kind: "prompt", scope: "both", target: "reach_miss",
note: "② 双端策略,iOS 通过、Android 变差 → 只能「只上 iOS」(新增行包进 iOS 段,Android 逐字节不变)",
members: [
{ id: "c2-ios", platform: "ios", status: "lab_passed", reason: PASS("未到达复现现场 2 → 0(5 对);自报修好 3 → 4"), createdAt: now - 90 * H },
{ id: "c2-and", platform: "android", status: "lab_failed", reason: "复跑未通过:到达复现现场的个数比现行少(4 → 3),底线没守住", createdAt: now - 90 * H + 1 },
],
added: ["- deeplink 跳转后 10 秒内目标页没出现,不要重试同一条 deeplink;回到首页按 TestSpec 的入口路径手动进入。"],
},
{
title: "Frida 报错后先看后续调用有没有自愈", kind: "prompt", scope: "both", target: "dead_end_s",
note: "③ 双端策略,iOS 通过、Android「判不了」(可比的对数不够)→ 可以只上 iOS,也可以先重跑 Android",
members: [
{ id: "c3-ios", platform: "ios", status: "lab_passed", reason: PASS("走不通时耗掉的时长 96 → 71 分(4 对);自报修好 3 → 3"), createdAt: now - 120 * H },
{ id: "c3-and", platform: "android", status: "lab_failed", inconclusive: true, reason: "复跑 3 天到期,只有 2 对可比的跑完(至少要 3 对),判不了;另有 1 对不可比已剔除(两组跑在不同版本的卫星包上)", createdAt: now - 120 * H + 1 },
],
added: ["- Frida attach / 调用报错后,先看接下来两次调用是否已恢复;连续三次同样报错再判定为环境问题。"],
},
{
title: "安装包之后先确认进程起来再操作", kind: "prompt", scope: "both", target: "reach_s",
note: "④ 双端策略,iOS 已通过、Android 还在复跑 → 等两端都跑完才能决定",
members: [
{ id: "c4-ios", platform: "ios", status: "lab_passed", reason: PASS("到达复现现场 41.0 → 37.2 分(5 对)"), createdAt: now - 30 * H },
{ id: "c4-and", platform: "android", status: "lab", reason: "复跑中:3/5 对已跑完", createdAt: now - 30 * H + 1 },
],
added: ["- 装完包先用 wait-for --pid 等 App 进程起来,再做第一次 UI 操作。"],
},
{
title: "catuse 树里找不到控件时先滚动再找", kind: "prompt", scope: "ios", target: "reach_s",
note: "⑤ 单端策略(iOS 专有),通过 → 只能「只上 iOS」;也可以「补 Android 端复跑」变成双端组",
members: [
{ id: "c5-ios", platform: "ios", status: "lab_passed", reason: PASS("到达复现现场 47.5 → 40.3 分(5 对);自报修好 4 → 4"), createdAt: now - 50 * H },
],
added: ["- catuse ui 的结构树里找不到目标控件时,先在当前列表上滑一屏再找,别直接判定入口不存在。"],
drift: [{ platform: "ios", lines: 2 }],
},
{
title: "Android:思考强度调到 medium", kind: "runtime", scope: "android", target: "reach_s",
note: "⑥ 运行时旋钮(单端):生产配置包按端分开,只改 Android 的",
members: [
{ id: "c6-and", platform: "android", status: "lab_passed", reason: PASS("到达复现现场 53.3 → 50.2 分(5 对);单次用时 86 → 77 分"), createdAt: now - 200 * H },
],
profile: { android: "思考强度=medium" },
},
{
title: "复现前先清 App 数据", kind: "prompt", scope: "ios", target: "reach_miss",
note: "⑦ 补丁冲突:实验之后模板改过,锚点那一行没了 → 「补丁不可用」,不能批准",
members: [
{ id: "c7-ios", platform: "ios", status: "lab_passed", reason: PASS("未到达复现现场 1 → 0(5 对)"), createdAt: now - 240 * H },
],
added: ["- 复现前先清掉 App 数据(设置 → 通用 → iPhone 储存空间),避免旧缓存把问题盖住。"],
conflict: "新增的「- 复现前先清掉 App 数据…」在现在的模板里找不到唯一的位置(锚点「## 步骤 3 — 复现、修复、验证」已改动或重复)",
},
{
title: "长列表滚动到底再判定没有数据", kind: "prompt", scope: "both", target: "reach_s",
note: "⑧ 已批准两端、等改动进代码:显示落代码命令;可撤销批准",
members: [
{ id: "c8-ios", platform: "ios", status: "approved", shipScope: "both", reason: "admin.wang 批准上线(两端):两端到达都快了", createdAt: now - 300 * H },
{ id: "c8-and", platform: "android", status: "approved", shipScope: "both", reason: "admin.wang 批准上线(两端):两端到达都快了", createdAt: now - 300 * H + 1 },
],
added: ["- 判定「列表没有数据」之前,先滚动到底并等加载更多结束。"],
},
{
title: "评论区输入框弹起后等键盘动画结束", kind: "prompt", scope: "both", target: "reach_s",
note: "⑨ 已上线(iOS)+ Android 当时判不了被单独留下",
members: [
{ id: "c9-ios", platform: "ios", status: "shipped", shipScope: "ios", promotedAt: now - 20 * H, reason: "admin.wang 批准上线(iOS)", createdAt: now - 400 * H },
{ id: "c9-and", platform: "android", status: "declined", reason: "admin.wang 批准时只上 iOS,这一端不上", createdAt: now - 400 * H + 1 },
],
added: ["- 点评论输入框后,等键盘动画结束(wait-for --settle)再输入。"],
},
];
// ── 内存里的状态机:只演示交互,规则以控制面为准 ───────────────────────────────
const byMember = new Map<string, Case>();
for (const c of CASES) for (const m of c.members) { byMember.set(m.id, c); m.labReason = m.reason; }
const events = new Map<string, LoopEvent[]>();
const ev = (id: string, actor: string, type: string, title: string, body: string | null = null) =>
events.set(id, [{ id: `${id}-${Math.random()}`, experimentId: id, at: Date.now(), actor, type, title, body }, ...(events.get(id) ?? [])]);
for (const c of CASES) for (const m of c.members) {
ev(m.id, "loop-runner", "proposal", `提案${c.scope === "both" ? `(双端 · ${m.platform === "ios" ? "iOS" : "Android"} 端)` : ""}:${c.title}`);
if (m.status !== "lab") ev(m.id, "loop-judge", m.status === "lab_failed" ? "lab_fail" : "lab_pass", m.reason);
}
const latest = (c: Case) => {
const map = new Map<string, Member>();
for (const m of [...c.members].sort((a, b) => a.createdAt - b.createdAt)) map.set(m.platform, m);
return [...map.values()];
};
function shipView(c: Case, self: Member): LoopShipView {
const ms = latest(c);
const running = ms.filter((m) => m.status === "lab" || m.status === "queued");
const passed = ms.filter((m) => m.status === "lab_passed");
const options: LoopShipOption[] = [];
if (!running.length && passed.length) {
const scope: LoopShipScope = passed.length === 2 ? "both" : passed[0].platform;
if (c.conflict) options.push({ scope, ok: false, error: c.conflict });
else if (c.kind === "runtime") {
options.push({ scope, ok: true, profile: c.profile, checks: (["ios", "android"] as const).map((p) => p === scope || scope === "both"
? { platform: p, kind: "shipped" as const, ok: true, note: `生产配置包改为 ${c.profile?.[p] ?? ""}` }
: { platform: p, kind: "unchanged" as const, ok: true, note: "生产配置包不变" }) });
} else {
options.push({ scope, ok: true, added: c.added, drift: c.drift, checks: (["ios", "android"] as const).map((p) => scope === "both" || p === scope
? { platform: p, kind: "shipped" as const, ok: true, note: `新增 ${c.added?.length ?? 0} 行,与复跑的候选一致` }
: { platform: p, kind: "unchanged" as const, ok: true, note: "展开后的正文逐字节不变" }) });
}
}
const lead = c.members[0];
const canExtend = c.scope !== "both" && ["lab_passed", "approved", "shipped"].includes(lead.status);
return {
scope: c.scope,
members: c.members.map((m) => ({ id: m.id, platform: m.platform, status: m.status, reason: m.reason, inconclusive: !!m.inconclusive,
createdAt: m.createdAt, shipScope: m.shipScope ?? null, promotedAt: m.promotedAt ?? null })),
options,
waiting: running.length ? `等 ${running.map((m) => (m.platform === "ios" ? "iOS" : "Android")).join(" / ")} 复跑结束:双端策略两端都跑完才决定` : null,
rerunnable: ms.filter((m) => m.status === "lab_failed").map((m) => ({ id: m.id, platform: m.platform })),
extendTo: canExtend && self.id === lead.id ? (lead.platform === "ios" ? "android" : "ios") : null,
};
}
function toExp(c: Case, m: Member): LoopExperiment {
return {
id: m.id, stage: "bug.run", platform: m.platform, kind: c.kind, status: m.status, title: c.title,
problemClass: null, cluster: null,
summary: "(演示数据)回路从近 7 天的执行会话里切出这类浪费,聚合后排在第一。",
hypothesis: "(演示数据)把这条纪律写进执行 prompt,能让 agent 更早走到复现现场。",
method: c.kind === "runtime" ? "运行时实验:两组同一版 prompt,候选组多带执行配置包。" : "在步骤 3 前插入一行纪律;实验机上配对复跑评估集历史任务。",
conclusion: null, targetMetric: c.target, basePromptId: null, candidatePromptId: null,
candidateProfile: c.kind === "runtime" ? JSON.stringify({ effort: "medium" }) : null,
scope: c.scope, groupId: c.scope === "both" || c.members.length > 1 ? c.members[0].id : null, shipScope: (m.shipScope as LoopShipScope) ?? null,
offlineResult: null,
onlineResult: m.status === "lab" ? { phase: "lab", at: now, decision: "continue", reason: m.labReason ?? m.reason }
: { phase: "lab", at: m.createdAt + 60 * H, decision: m.status === "lab_failed" ? "fail" : "pass", reason: m.labReason ?? m.reason },
decisionReason: ["approved", "declined", "shipped"].includes(m.status) ? m.reason : null, share: 0,
createdBy: "loop-runner", createdAt: m.createdAt, updatedAt: now, canaryStartedAt: null, promotedAt: m.promotedAt ?? null, decidedAt: null,
};
}
const BASE = "## 步骤 3 — 复现、修复、验证\n- 先按 TestSpec 的入口走到目标页。\n- 到达后录屏取证。";
const metrics = [
{ key: "reach_s", label: "到达复现现场用时", unit: "seconds" as const, better: "down" as const, role: "target" as const, group: "business" as const, doc: "从这批开始到第一张校验通过的修复前证据。" },
{ key: "reach_miss", label: "未到达复现现场", unit: "rate" as const, better: "down" as const, role: "target" as const, group: "business" as const, doc: "一批结束仍没有合格的修复前证据。" },
{ key: "dead_end_s", label: "走不通时耗掉的时长", unit: "seconds" as const, better: "down" as const, role: "target" as const, group: "business" as const, doc: "没以 FIXED 收尾的批次的整批时长。" },
];
function overview(): LoopOverview {
return {
enabled: true, labNodes: { android: "evaluator-android-01", ios: "temp-ios-01" },
pause: { paused: false, by: null, at: null, reason: null },
params: { LAB_WALL_TOLERANCE: 0.2, LAB_MIN_PAIRS: 3, LAB_MAX_DAYS: 3 },
stages: ["bug.run"], metrics,
experiments: CASES.flatMap((c) => c.members.map((m) => toExp(c, m))).sort((a, b) => b.createdAt - a.createdAt),
events: [],
baseline: {
days: Array.from({ length: 14 }, (_, i) => ({ day: new Date(now - (13 - i) * 24 * H).toISOString().slice(0, 10), rounds: 10,
metrics: { reach_s: { mean: 2400 + Math.sin(i / 2) * 300, n: 10 } } })),
markers: [],
},
};
}
function find(id: string): { c: Case; m: Member } {
const c = byMember.get(id)!;
return { c, m: c.members.find((x) => x.id === id)! };
}
const WHO = "admin.wang";
Object.assign(api.rsi.loop, {
overview: async () => { await wait(150); return overview(); },
experiment: async (id: string): Promise<LoopExperimentDetail> => {
await wait(200);
const { c, m } = find(id);
const cand = c.added ? BASE.replace("## 步骤 3 — 复现、修复、验证\n", `## 步骤 3 — 复现、修复、验证\n${c.added.join("\n")}\n`) : null;
return { experiment: toExp(c, m), events: events.get(id) ?? [], baseTemplate: BASE, candidateTemplate: cand, lab: [], ship: shipView(c, m) };
},
approve: async (id: string, scope: LoopShipScope, reason?: string) => {
await wait(500);
const { c } = find(id);
for (const m of latest(c)) {
if (m.status !== "lab_passed") continue;
if (scope === "both" || m.platform === scope) {
m.status = "approved"; m.shipScope = scope; m.reason = `${WHO} 批准上线(${scope === "both" ? "两端" : scope === "ios" ? "iOS" : "Android"})${reason ? `:${reason}` : ""}`;
ev(m.id, WHO, "approve", `人工决定:批准上线(${scope})`, reason ?? null);
} else {
m.status = "declined"; m.reason = `${WHO} 批准时只上 ${scope === "ios" ? "iOS" : "Android"},这一端不上`;
ev(m.id, WHO, "decision", "人工决定:这一端不上");
}
}
return { ok: true };
},
decline: async (id: string, reason: string) => {
await wait(400);
const { c } = find(id);
for (const m of latest(c)) if (m.status === "lab_passed" || m.status === "approved") {
m.status = "declined"; m.shipScope = null; m.reason = `${WHO} 驳回:${reason}`; ev(m.id, WHO, "decision", "人工决定:驳回", reason);
}
return { ok: true };
},
unapprove: async (id: string) => {
await wait(400);
const { c } = find(id);
for (const m of latest(c)) {
if (m.status === "approved" || (m.status === "declined" && /批准时只上/.test(m.reason))) {
m.status = "lab_passed"; m.shipScope = null; m.reason = m.labReason ?? PASS(""); ev(m.id, WHO, "decision", "人工决定:撤销批准,回到待决定");
}
}
return { ok: true };
},
rerun: async (id: string) => {
await wait(500);
const { c, m } = find(id);
const nm: Member = { id: `${id}-r${Date.now()}`, platform: m.platform, status: "lab", reason: "复跑中:0/5 对已跑完", labReason: "复跑中:0/5 对已跑完", createdAt: Date.now() };
c.members.push(nm); byMember.set(nm.id, c);
ev(nm.id, WHO, "proposal", `重跑 ${m.platform === "ios" ? "iOS" : "Android"} 端:同一对现行 / 候选,换一批复跑`);
return { ok: true };
},
extend: async (id: string) => {
await wait(500);
const { c, m } = find(id);
const to: Plat = m.platform === "ios" ? "android" : "ios";
c.scope = "both";
const nm: Member = { id: `${id}-x${Date.now()}`, platform: to, status: "queued", reason: "实验机被别的实验占着,排队", labReason: "排队中", createdAt: Date.now() };
c.members.push(nm); byMember.set(nm.id, c);
ev(nm.id, WHO, "proposal", `补 ${to === "ios" ? "iOS" : "Android"} 端复跑`);
return { ok: true };
},
revert: async () => { await wait(300); return { ok: true }; },
pause: async () => ({ pause: overview().pause }),
});
function Demo() {
const [admin, setAdmin] = useState(true);
const [k, setK] = useState(0);
return (
<div className="rs-demo">
<h1>自我改进 · 实验「上线决策」演示</h1>
<p className="rs-sub">面板是真组件、数据是假的,刷新页面重置。点开任意实验,详情里的「上线决策」块就是这次新增的部分。规则:<b>哪端复跑通过就只上哪端</b>;双端策略两端都跑完才决定。</p>
<div className="rs-bar">
<label style={{ display: "inline-flex", alignItems: "center", gap: 6, cursor: "pointer" }}><input type="checkbox" style={{ width: "auto", margin: 0 }} checked={admin} onChange={(e) => { setAdmin(e.target.checked); setK((n) => n + 1); }} /> 以管理员身份查看(取消勾选 = 非管理员,只能看不能点)</label>
</div>
<ol className="rs-cases">{CASES.map((c) => <li key={c.title}><b>{c.title}</b> —— {c.note}</li>)}</ol>
<div className="lab rsi"><div className="rsi-body">
<RsiLoop key={k} canDecide canShip={admin} />
</div></div>
<Toaster />
<DialogHost />
</div>
);
}
const style = document.createElement("style");
style.textContent = `
html, body, #root { height: auto !important; overflow: auto !important; }
body { margin: 0; background: var(--bg, #f6f7f9); }
.rs-demo { padding: 24px 32px 64px; max-width: 1120px; margin: 0 auto; color: var(--text); }
.rs-demo h1 { font-size: 20px; margin: 0 0 6px; }
.rs-sub { font-size: 13px; color: var(--muted); margin: 0 0 12px; line-height: 1.7; }
.rs-bar { font-size: 13px; margin-bottom: 10px; }
.rs-cases { font-size: 12.5px; color: var(--text-2); line-height: 1.8; margin: 0 0 16px; padding-left: 20px; }
@media (max-width: 640px) { .rs-demo { padding: 16px; } }
`;
document.head.appendChild(style);
createRoot(document.getElementById("root")!).render(<Demo />);