Initial import of streamline
This commit is contained in:
@@ -0,0 +1,194 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import "../styles.css";
|
||||
import ImportDialog from "../components/ImportDialog";
|
||||
import Toaster from "../components/Toaster";
|
||||
import { api } from "../lib/api";
|
||||
import { setLang } from "../lib/i18n";
|
||||
import {
|
||||
DEFAULT_VERIFY_RUN_FIRST_TEMPLATE, parseVerifySpec, verifyKnowledgeBlock, verifySpecBlock, type VerifySpec,
|
||||
} from "@bbbug/shared/verify_prompt";
|
||||
import { checksFromPresets, type CustomCheckPreset } from "@bbbug/shared/verify_scope_templates";
|
||||
import SAMPLE from "./verifyChecksDemo.data.json";
|
||||
|
||||
/**
|
||||
* 本地演示:UI 走查的检查项不再有系统缺省。
|
||||
*
|
||||
* 右侧渲染的是**真模板 + 真 verifySpecBlock**(shared/verify_prompt.ts),和派发时 agent 收到的正文同源;
|
||||
* 只有节点侧才知道的块(Frida 接入、设备说明、wait-for)留了占位。「改前」一栏是改动前不勾专项时
|
||||
* 系统补上的那段原文,拿来对照。
|
||||
*
|
||||
* 左边「新建验证任务」打开的是真表单;提交被拦在本页(createVerification 换成假的),不会建单,
|
||||
* 建出的规约直接进右侧渲染。「快捷专项筛查 → 添加更多」的共享专项存在本页内存里(刷新即复原),
|
||||
* 增删改走的是和线上同一套表单与校验。
|
||||
*
|
||||
* 打开方式:control-web 下 `API_TARGET=http://127.0.0.1:9 bun x vite --port 8092`,访问 /demo-verify-checks.html。
|
||||
*/
|
||||
|
||||
// 改动前 verifySpecBlock 在 checks 为空时补上的那段(UI_AUDIT_CHECKS),逐字保留做对照。
|
||||
const OLD_DEFAULT = `**检查项**(逐条对照,不要只报你第一眼看见的那类):
|
||||
1. 老旧组件样式:用的是不是规范的 TUX 组件(Panel / 按钮 / 颜色 / 圆角) —— 截图 + 代码参数
|
||||
2. UI 异常:提示气泡 / 弹窗 / banner 同屏出现两样及以上,插画 / icon / 按钮尺寸异常 —— 截图 + 代码参数
|
||||
3. 热区异常或过小:低于 44×44pt 的可点区域 —— 代码参数
|
||||
4. 文案冗长或不合理截断:被硬截断、从单词中间断开、折行挤压 —— 截图
|
||||
5. 新用户流程体验:连续遭遇弹窗 / banner / 提示 —— 截图 + 代码参数
|
||||
6. 多语言适配:截断、超长、与英文对照表意错误、标点滥用 —— 截图`;
|
||||
|
||||
type Scenario = { key: string; label: string; spec: VerifySpec; note: string };
|
||||
const base: VerifySpec = { format: "ui-audit", scope: SAMPLE.scope, budgetHours: 12 };
|
||||
const GENERAL = ["general-legacy-style", "general-ui-anomaly", "hit-area-spec", "general-copy-truncation", "general-new-user-flow", "general-multilingual"];
|
||||
const SCENARIOS: Scenario[] = [
|
||||
{ key: "none", label: "e1e28a58 原样:不勾专项", spec: base,
|
||||
note: "就是线上那张单。改前系统补了六类(含热区 <44pt),报告里 23 条热区;改后只按范围正文查。" },
|
||||
{ key: "hit", label: "同范围 + 勾「热区问题」", spec: { ...base, checks: checksFromPresets(["hit-area-spec"]) },
|
||||
note: "想查热区就勾上。注入的是按平台组件规范的那一份,不再有 44pt / 36pt 两个阈值。" },
|
||||
{ key: "general", label: "同范围 + 勾「常规走查」", spec: { ...base, checks: checksFromPresets(GENERAL) },
|
||||
note: "以前的缺省六类,现在是一个显式预设:勾了才进 prompt。" },
|
||||
];
|
||||
|
||||
let captured: ((s: VerifySpec, title: string) => void) | null = null;
|
||||
setLang("zh");
|
||||
// 共享专项:本页内存里的假存储,预置一条别人加的。
|
||||
let store: CustomCheckPreset[] = [{
|
||||
id: "custom-demo-1", label: "Toast 文案超过两行", cat: "文案与多语言",
|
||||
text: "Toast 文案超过两行。行数从截图数,或结构树里 label 高度 ÷ 单行高;「细节」抄原文并写行数",
|
||||
createdBy: "teammate@bytedance.com", updatedBy: "teammate@bytedance.com", updatedAt: Date.now(),
|
||||
}];
|
||||
const ME = "demo.user@bytedance.com";
|
||||
api.verifyCheckPresets = async () => ({ presets: store });
|
||||
api.addVerifyCheckPreset = async (input) => {
|
||||
const p: CustomCheckPreset = { id: `custom-${crypto.randomUUID()}`, ...input, createdBy: ME, updatedBy: ME, updatedAt: Date.now() };
|
||||
store = [...store, p];
|
||||
return p;
|
||||
};
|
||||
api.updateVerifyCheckPreset = async (id, input) => {
|
||||
const old = store.find((p) => p.id === id);
|
||||
if (!old) throw new Error("这条专项已被删除");
|
||||
const p = { ...old, ...input, updatedBy: ME, updatedAt: Date.now() };
|
||||
store = store.map((x) => x.id === id ? p : x);
|
||||
return p;
|
||||
};
|
||||
api.deleteVerifyCheckPreset = async (id) => { store = store.filter((p) => p.id !== id); return { ok: true }; };
|
||||
api.clustersList = async () => ({ clusters: ["default"] });
|
||||
api.productProfiles = async () => ({ version: 1, profiles: [{ id: "tiktok", name: "TikTok", platforms: { ios: { repoKey: "tiktok-ios", baseBranch: "develop" }, android: { repoKey: "tiktok-android", baseBranch: "develop" } } }] }) as unknown as Awaited<ReturnType<typeof api.productProfiles>>;
|
||||
api.ttkbPackages = (async () => ({ packages: [] })) as unknown as typeof api.ttkbPackages;
|
||||
api.createVerification = (async (input: { verifySpec: string; title: string | null; description: string }) => {
|
||||
const spec = parseVerifySpec(input.verifySpec);
|
||||
const title = input.title || input.description.slice(0, 24);
|
||||
if (spec) captured?.(spec, title);
|
||||
return { title };
|
||||
}) as unknown as typeof api.createVerification;
|
||||
|
||||
function render(spec: VerifySpec, title: string): string {
|
||||
const fill: Record<string, string> = {
|
||||
workspaceDir: "/…/verify-demo", verifySpecBlock: verifySpecBlock(spec), knowledgeBlock: verifyKnowledgeBlock("ios"),
|
||||
budgetHours: String(spec.budgetHours ?? 6), title, platform: "ios", batchNo: "1", attempts: "0",
|
||||
fridaBlock: "(Frida 接入说明 —— 节点按平台渲染)", iosDeviceBlock: "", waitBlock: "", waitForCmd: "wait-for",
|
||||
auditReportCmd: "audit-report", aiWorkspace: "~/ai_workspace", baseBranch: "develop", langNote: "中文", linkNote: "", reviewFeedback: "",
|
||||
};
|
||||
return DEFAULT_VERIFY_RUN_FIRST_TEMPLATE.replace(/\{\{(\w+)\}\}/g, (_, k: string) => fill[k] ?? "");
|
||||
}
|
||||
|
||||
function checksSection(spec: VerifySpec): string {
|
||||
const block = verifySpecBlock(spec);
|
||||
return block.slice(block.indexOf("**检查项**")).trim();
|
||||
}
|
||||
|
||||
const HIT = /热区|44×44|36×36/g;
|
||||
function hitLines(text: string): string[] {
|
||||
return text.split("\n").filter((l) => HIT.test(l) && ((HIT.lastIndex = 0), true));
|
||||
}
|
||||
|
||||
function Mark({ text }: { text: string }) {
|
||||
const parts = text.split(/(热区|44×44pt|36×36pt)/);
|
||||
return <>{parts.map((p, i) => i % 2 ? <mark key={i}>{p}</mark> : p)}</>;
|
||||
}
|
||||
|
||||
function Demo() {
|
||||
const [key, setKey] = useState("none");
|
||||
const [mine, setMine] = useState<Scenario | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [full, setFull] = useState(false);
|
||||
useEffect(() => {
|
||||
captured = (spec, title) => {
|
||||
setMine({ key: "mine", label: `你刚建的:${title}`, spec, note: "表单提交被拦在本页,没有真的建单。" });
|
||||
setKey("mine");
|
||||
};
|
||||
}, []);
|
||||
// 表单默认停在 Bug 页签,打开后切到「验证」。
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const id = setTimeout(() => {
|
||||
const tab = [...document.querySelectorAll<HTMLButtonElement>(".import-dialog .import-kind-tabs button")]
|
||||
.find((b) => /^(验证|Verify)/.test(b.textContent?.trim() ?? ""));
|
||||
tab?.click();
|
||||
}, 50);
|
||||
return () => clearTimeout(id);
|
||||
}, [open]);
|
||||
|
||||
const all = mine ? [...SCENARIOS, mine] : SCENARIOS;
|
||||
const sc = all.find((s) => s.key === key) ?? SCENARIOS[0];
|
||||
const prompt = render(sc.spec, SAMPLE.title);
|
||||
const noChecks = !sc.spec.checks?.length;
|
||||
const hits = hitLines(prompt);
|
||||
|
||||
return <div className="vc-demo">
|
||||
<h1>走查检查项隔离 · 演示</h1>
|
||||
<p className="vc-sub">验证任务按格式决定报告;具体查什么只来自「筛查内容」和勾选的专项,系统 prompt 里不再有缺省检查项。
|
||||
右侧是派发时 agent 真正收到的 prompt(真模板、真渲染)。</p>
|
||||
|
||||
<div className="vc-bar">
|
||||
{all.map((s) => <button key={s.key} type="button" aria-pressed={s.key === sc.key} onClick={() => setKey(s.key)}>{s.label}</button>)}
|
||||
<button type="button" className="primary" onClick={() => setOpen(true)}>新建验证任务(真表单)…</button>
|
||||
</div>
|
||||
<p className="vc-note">{sc.note}</p>
|
||||
|
||||
<div className="vc-cols">
|
||||
<section>
|
||||
<h2>改前 · 检查项段</h2>
|
||||
<pre className="vc-old"><Mark text={noChecks ? OLD_DEFAULT : checksSection(sc.spec).replace("(建单人勾的专项,逐条对照", "(逐条对照")} /></pre>
|
||||
{noChecks && <p className="vc-foot">不勾专项时系统自动补上这六条 —— 第 3 条就是热区。</p>}
|
||||
</section>
|
||||
<section>
|
||||
<h2>改后 · 检查项段</h2>
|
||||
<pre className="vc-new"><Mark text={checksSection(sc.spec)} /></pre>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section className="vc-hits">
|
||||
<h2>改后整份 prompt 里提到热区的地方:{hits.length} 处</h2>
|
||||
<ul>{hits.map((l, i) => <li key={i}><Mark text={l.trim().slice(0, 220)} /></li>)}</ul>
|
||||
{noChecks && <p className="vc-foot">不勾专项时只剩报告的分类词表那一行 —— 它说明「类别列能填什么」,并注明不是检查清单。</p>}
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<button type="button" className="ghost" onClick={() => setFull(!full)}>{full ? "收起" : "展开"}整份 prompt({prompt.length.toLocaleString()} 字)</button>
|
||||
{full && <pre className="vc-full"><Mark text={prompt} /></pre>}
|
||||
</section>
|
||||
|
||||
<ImportDialog open={open} onClose={() => setOpen(false)} />
|
||||
<Toaster />
|
||||
</div>;
|
||||
}
|
||||
|
||||
const style = document.createElement("style");
|
||||
style.textContent = `
|
||||
.vc-demo { padding: 24px 32px 64px; max-width: 1280px; color: var(--text); }
|
||||
.vc-demo h1 { font-size: 20px; margin: 0 0 6px; }
|
||||
.vc-demo h2 { font-size: 14px; margin: 0 0 8px; }
|
||||
.vc-sub, .vc-note, .vc-foot { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 0 0 12px; }
|
||||
.vc-note { color: var(--text); }
|
||||
.vc-bar { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 8px; }
|
||||
.vc-bar button[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
|
||||
.vc-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
|
||||
.vc-demo section { margin-bottom: 20px; }
|
||||
.vc-demo pre { white-space: pre-wrap; font-size: 12.5px; line-height: 1.65; padding: 12px 14px; border-radius: 12px;
|
||||
border: 1px solid var(--border); background: var(--surface); margin: 0; max-height: 560px; overflow: auto; }
|
||||
.vc-old { border-color: color-mix(in srgb, #d14 40%, var(--border)) !important; }
|
||||
.vc-new { border-color: color-mix(in srgb, #1a7 45%, var(--border)) !important; }
|
||||
.vc-full { max-height: 80vh !important; }
|
||||
.vc-demo mark { background: #ffd54a66; color: inherit; padding: 0 1px; border-radius: 2px; }
|
||||
.vc-hits ul { margin: 0; padding-left: 18px; font-size: 12.5px; line-height: 1.7; }
|
||||
`;
|
||||
document.head.appendChild(style);
|
||||
createRoot(document.getElementById("root")!).render(<Demo />);
|
||||
Reference in New Issue
Block a user