// Standalone faithful simulation of the SECURITY eval phase for task // 4f097de5-8c3b-443e-b49e-2e8d7c4384a5. Reproduces exactly what // satellite/src/security_evaluator.ts:evaluateSecurity() spawns — same pty // wrapper, same cwd, same flags, same prompt — but writes to a temp log and // does NOT touch the DB or task status. import { spawn } from "bun"; import { mkdirSync, openSync, closeSync } from "node:fs"; import path from "node:path"; import { NEEDS_INPUT_OPEN, NEEDS_INPUT_CLOSE, needsInput as NI } from "../shared/src/protocol"; import { CLAUDE_LAUNCH, AGENT_MODE } from "../satellite/src/claude_launch"; const AI_WORKSPACE = process.env.AI_WORKSPACE || path.join(process.env.HOME!, "ai_workspace"); const workspaceDir = "/Users/fei/bug_workspace/security-4f097de5-8c3b-443e-b49e-2e8d7c4384a5"; const security = { title: "[cluster=default] GIP投稿的BC toggle样式优化 // Optimization of BC toggle style for GIP videos", platform: "android", targetRef: "001fcedc74e7109e1daf6aa97035fc6b9d481fd3", remark: null as string | null, lang: undefined as string | undefined, }; // ── copied verbatim from security_evaluator.ts ────────────────────────────── function securityTemplateRules(targetRef: string | null): string { const refLine = targetRef ? `构建基线:**已指定 \`${targetRef}\`(分支或 commit),必须以此为准检出后构建**。` : `构建基线:未指定,默认 \`develop\` 最新;若 repro spec 内指定了分支/commit/MR,则以其为准。`; return `你只负责产出 SecuritySpec,也就是下游搜证 agent 要执行的 TestSpec.md。不要执行复现、不要构建、不要安装 App、不要采集证据。 **事实边界(贯穿全文,违反即视为不合格)**: - 搜证方案的每一条复现路径、入口、接口、配置、文件路径和判定标准,都必须来自 review_spec.md / machine_readable_repro_spec.json 或你对代码仓的实际调研。 - 严禁编造复现路径、接口、模块名、实验开关、日志 tag、网络端点或 UI 文案。 - 对局部步骤不确定时,不要把整单判为 NEEDS_INFO;在对应位置原样写一行 NEEDS_INPUT 哨兵: \`${NEEDS_INPUT_OPEN} <一句话说明缺什么、需要补充什么> ${NEEDS_INPUT_CLOSE}\` - 哨兵会被工具识别为结构性缺失。能从输入或代码确定的内容必须正常写出,不要滥用哨兵。 **输出纪律**: - 最终 SecuritySpec 里只允许出现:你确定的真实内容,或 NEEDS_INPUT 哨兵。 - 严禁把本模板的说明文字、括号提示、示例占位、省略号抄进结果。 - 不要新增模板未列出的章节;章节标题、顺序、\`//\` 英文副标题必须保持原样。 按下面结构产出: ## 证据目标 // Evidence Goal - 一句话:本次要搜集/证明什么(对应 review_spec 里的安全关注点)。 - 判定成功的标志:拿到哪类证据即视为搜证完成。 ## 复现前置 // Repro Preconditions - ${refLine} - 目标平台 / 设备要求;若 review_spec 未给出平台,用哨兵。 - 触达目标场景前需要的账号 / 数据 / 开关 / region / 实验配置等前置条件(基于 repro spec 和代码调研)。 ## 复现路径 // Repro Path (基于 machine_readable_repro_spec.json + 代码调研给出到达目标场景的可执行步骤,一般 3 到 7 步;每一步必须能被下游 agent 在真机上执行。不确定的关键步骤用哨兵。) 1. ... 涉及的关键文件 / 模块 / 入口(基于代码调研列出真实路径,不要编): - ... ## 搜证方法 // Evidence Method (到达场景后如何取证:要抓什么(日志 / 截图 / 抓包 / 调试器或 Frida hook 输出 / 状态快照),落到 evidence/ 的哪些文件;若需要临时改代码或用 Frida 挂钩来观测,写明挂在哪、观测什么。这些手段都是一次性的,不得提交。) - ... ## 判定标准 // Verdict Criteria (可验证的命题:拿到什么证据判 EVIDENCE_READY;什么情况判无法复现;什么情况判证据不足。每条写成"当...时,应..."。) 1. ... ## 风险与前置缺失 // Risks & Gaps (基于真实事实 / 代码调研写风险、环境依赖和不可控点;结构性缺失用哨兵。) - ...`; } function langDirective(s: typeof security): string { return s.lang === "en" ? "Generate the SecuritySpec and the REASON line in English.\n\n" : "请使用中文生成搜证方案(SecuritySpec)以及 REASON 行的内容。\n\n"; } function buildSecurityEvalPrompt(s: typeof security, wd: string): string { return `${langDirective(s)}You are the evaluation agent for a SECURITY evidence-gathering task. Your job is to decide whether the request has enough reproduction information to run, then draft a grounded SecuritySpec for a downstream runner. You may inspect the repository under your cwd, but you must not execute the reproduction, build the app, install anything, or collect evidence. Read both input files before deciding: - ${wd}/review_spec.md <- human-readable security review request - ${wd}/machine_readable_repro_spec.json <- machine-readable reproduction spec Context: - Title: ${s.title} - Platform: ${s.platform} - Target build ref: ${s.targetRef || "(none — default develop, or as specified in the repro spec)"} ${s.remark ? `\nReporter remark / supplemental info:\n${s.remark}\n` : ""} Decision policy: - Return NEEDS_INFO only when the repro spec is empty or contains no usable reproduction information at all. - Missing or fuzzy local details are not a hard blocker. Draft the SecuritySpec and place NEEDS_INPUT sentinels exactly where the downstream runner needs clarification. - The SecuritySpec must be executable by another agent on a real build. Prefer concrete paths, entry points, settings keys, logs, commands, and evidence names over generic advice. Output contract. Use exactly this wrapper format, with no preamble and no trailing prose: ASSESSMENT: REASON: If and only if ASSESSMENT is READY, emit the SecuritySpec between the markers below, following every rule. ${securityTemplateRules(s.targetRef)} The filled SecuritySpec goes between and . Do not write anything after .`; } // ──────────────────────────────────────────────────────────────────────────── const logFile = path.join("/tmp", `sim-eval-4f097de5-${Date.now()}.log`); const prompt = buildSecurityEvalPrompt(security, workspaceDir); mkdirSync(AI_WORKSPACE, { recursive: true }); const fd = openSync(logFile, "w"); console.log(`[sim] AGENT_MODE=${AGENT_MODE}`); console.log(`[sim] CLAUDE_LAUNCH=${JSON.stringify(CLAUDE_LAUNCH)}`); console.log(`[sim] cwd=${AI_WORKSPACE}`); console.log(`[sim] log=${logFile}`); console.log(`[sim] prompt bytes=${prompt.length}`); const t0 = Date.now(); const proc = spawn({ cmd: [...CLAUDE_LAUNCH, "-p", prompt, "--output-format", "stream-json", "--verbose", "--dangerously-skip-permissions"], cwd: AI_WORKSPACE, stdout: fd, stderr: fd, env: { ...process.env, CLAUDE_PTY_DEBUG: "1" }, // surface wrapper decisions into the log }); // Satellite's own watchdog is EVAL_TIMEOUT_MS; give this sim a generous cap. const CAP_MS = Number(process.env.SIM_CAP_MS || 900_000); const timer = setTimeout(() => { console.log(`[sim] cap ${CAP_MS}ms reached — killing`); try { proc.kill(); } catch {} }, CAP_MS); await proc.exited; clearTimeout(timer); try { closeSync(fd); } catch {} console.log(`[sim] exited after ${((Date.now() - t0) / 1000).toFixed(1)}s; exitCode=${proc.exitCode}`); console.log(`[sim] log written to ${logFile}`);