• 简体中文
  • v6.5.0
  • 验证

    运行时将"完成"视为必须被证明的事实,而不仅仅是被声明的结果。当模型说某个任务已完成时,这句话本身毫无价值。验证把声明转化为证据:你声明一组必须成功的命令,运行时执行它们,结果会携带一份你可以检视、据以拦截或呈现给用户的报告。

    验证是会话级的。Rust 核心运行每条命令,记录其退出状态和输出,并将每份报告汇总为一份随回合结果一同返回的摘要。

    产品界面可以先展示交付摘要,再列出支持结论的命令输出和文件级改动。

    运行验证命令

    一条验证命令就是一个小而具名的检查:一个 id、一个 kind、一段可读的 description,以及要运行的 command。当某个失败应被视为硬失败而非警告时,将该检查标记为 required

    Node.js
    Python
    TypeScript
    const report = await session.verifyCommands('release-readiness', [
    {
    id: 'build',
    kind: 'build',
    description: 'Project compiles',
    command: 'cargo build --all-features',
    required: true,
    timeoutMs: 120000,
    },
    {
    id: 'tests',
    kind: 'test',
    description: 'Unit tests pass',
    command: 'cargo test',
    required: true,
    },
    ]);
    console.log(report);

    subject(此处为 release-readiness)为这一批检查命名,使同一会话内的多次验证在报告中保持彼此独立。

    读取回合结束后的摘要

    每个回合的 send() 结果同样携带只读的验证字段,因此你无需单独发起一次验证调用即可据结果拦截。用这些字段判断该回合是否真正完成了它所声称的工作。

    Node.js
    Python
    TypeScript
    const result = await session.send('Apply the fix and run the checks');
    console.log(result.verificationStatus);
    console.log(result.pendingVerificationCount);
    console.log(result.failedVerificationCount);
    console.log(result.verificationReportCount);
    console.log(result.verificationSummaryText);
    if (result.failedVerificationCount > 0) {
    throw new Error('Turn reported done but verification failed');
    }

    检视报告与摘要

    除了逐回合的字段之外,会话还暴露完整的报告集合、一份结构化摘要、可用的预设,以及一份可读的概要。该概要是向人展示某回合为何通过或失败的最快方式。

    Node.js
    Python
    TypeScript
    import { formatVerificationSummary } from '@a3s-lab/code';
    const reports = session.verificationReports();
    const summary = session.verificationSummary();
    const presets = session.verificationPresets();
    // Either the session helper or the standalone formatter yields readable text.
    console.log(session.verificationSummaryText());
    console.log(formatVerificationSummary(summary));

    verificationPresets() 返回根据 workspace 文件推断出的检查模板,例如 Cargo.tomlpackage.jsonpyproject.tomlgo.mod。请把它们当作起点: 在用来拦截发布或用户可见自动化之前,应审查命令、超时和 required 标记是否适合该项目。

    为何重要

    没有验证,一次智能体运行止于模型的一面之词。有了验证,运行止于可观测的证据:编译通过的构建、跑通的测试套件、保持沉默的代码检查器。摘要文本提供审计轨迹;结果上的计数让你能在自动化中以失败为默认(fail closed)。

    相关

    • 遥测 —— 将追踪事件和验证报告作为运行时证据进行检视。
    • 限制 —— 在验证运行之前限定一个回合能完成多少工作量。