omp packages

pi-review-chain0.1.0

Route a reviewer's findings straight into the next subagent instead of the parent session: one named workflow resource (xq.review-chain) built on pi-subagents' official extension seam.

xuqianhui Published 3 hours ago MIT ~0 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-review-chain

让复核结论直接进下一个子代理,而不是进父会话。给 pi-subagents 补上「复核结果由运行时消费、父只调度」这一段:只用一个官方扩展接口,不改上游一行代码。

上游 issue:nicobailon/pi-subagents#3433

问题

pi-subagents 0.90.0 的 acceptance.review 只接受调用方已经拿到的 reviewer 结果(docs/tool-reference.md:481 原文 orchestrate the reviewer separately),review-required 状态(:492)等的就是父会话自己把 findings 读进来。于是「复核」这个本该发生在子代理之间的一步,永远要穿过父模型的上下文。

用法

{ "workflow": "xq.review-chain", "async": false,
  "args": { "task": "复核当前 diff:正确性、测试、契约", "fix": true, "rounds": 1 } }
字段 类型 默认 说明
task string ≤4 KB 必填 复核目标/范围
fix boolean true verdict 为 blocked 时是否派 worker 修(findings 直接拼进它的 task)
rounds 1 | 2 1 2 = 修完再复核一次,父只收最终 verdict
reviewer reviewer | oracle reviewer 只允许这两个内置只读角色
output string ≤240 无 给了路径 → review 子代理 outputMode:"file-only",父只看到指针

父侧拿到(没有 findings 正文):

{ "verdict": "fixed", "round": 1, "fixed": 2, "review": null, "next": "rounds=1: 未再复核" }

verdict:ok(无需修)/ fixed / blocked(fix:false,或 rounds=2 仍有 blocker → 交回父决定)。

怎么做到「父不读」

  1. reviewer 用 outputSchema 提交结构化 verdict(p0/p1/p2/summary);缺字段或越界由运行时判子代理失败,不会被静默当成 ok。
  2. 判定在 workflow 脚本里:blockers = p0 ++ p1,非空才派 fix;findings 只作为下一个子代理的 task。
  3. 脚本 return 只有计数与路径 ⇒ 终局通知也不带 review 正文。
  4. 给了 output 时 review 子代理是 file-only,正文落在受管产物目录(~/.cache/pi-tmp/…/artifacts/outputs/<call-id>/review.md),不写仓库。

复现

npm test        # 11 项:参数校验 + 用假 runs 执行生成的脚本(ok/blocked/fix:false/rounds=2/失败/file-only/注入转义)
npm run check   # 扩展能 import、default 是注册函数
npm run e2e     # 真跑:造带 bug 的临时 git 仓 → review→fix → 断言 verdict、null-safe 修复、测试补充
ROUNDS=2 npm run e2e

npm run e2e 自带前置断言(夹具不抛错就 FAIL,防止「修无可修」的假绿),单轮约 60–90 s,两次子代理调用。

2026-12-04 实测(pi-subagents 0.90.0):

场景 子代理 父侧返回值
fix:false,README 错字仓库 1(18.6 s) {verdict:"blocked", blockers:2, review:null}
fix:true, output:"review.md" 2(25.6 s + 8.0 s) {verdict:"fixed", fixed:1, review:"…/review.md"},hello wrold → hello world
本会话 fix:true,total(null) 抛错仓库 2(28.6 s + 35.1 s) {verdict:"fixed", fixed:2},worker 改成 null-safe + 补 20 行测试

为什么另开一个仓,而不是提进 pi-subagents 本体

  1. 缺的只是薄薄一层,官方接口已经够用:registerWorkflowResource(docs/extension-api.md:5)本来就允许第三方注册命名 workflow,路由和结构化 verdict 都在接口能力内。能靠扩展解决的部分不值得动内核。
  2. 真正需要改内核的是另外两件,已单独立 issue:acceptance.review 由运行时自动派 reviewer(要动 acceptance 语义)、以及终局通知的 per-child preview 瘦身(#3394 合并时明确留作单独改动)。这两条要等上游设计定案,直接提 PR 会先把 API 形状钉死。
  3. 可随时删掉:扩展只在 session_start 注册一个资源名,没有持久副作用、不改上游产物格式。上游落地 #3433 后,本仓退化成薄封装或者直接 pi remove。

安装

pi install ~/pi-plugins/pi-review-chain     # 或 npm:pi-review-chain(见下)

本目录带 node_modules/pi-subagents → ~/.pi/agent/npm/node_modules/pi-subagents 软链,用于解析 pi-subagents/workflow-resources。软链断了 npm run check 会直接报错;重建:ln -sfn ~/.pi/agent/npm/node_modules/pi-subagents node_modules/pi-subagents。

回滚

pi remove ~/pi-plugins/pi-review-chain      # 或手改 settings.json 删掉 packages 里那一行
# 可选:删包(发版 72 h 内)
npm-pub unpublish pi-review-chain@0.1.0

影响面:只影响 subagent({ workflow: "xq.review-chain" }) 这类调用,之后就报 unknown workflow resource;已跑完的 workflow 产物、会话记录都不受影响。装之前的 settings 备份:/tmp/settings.json.bak-20261204。

边界

  • 不跑 host 命令、不拼 shell:JSON.stringify 只用于把参数嵌进 JS 源码。
  • 脚本里没有模型判断,只有「p0/p1 非空 → 派修」。要语义取舍就用 reviewer:"oracle" 或 rounds:2。
  • subagent({action:"validate"}) 不接受命名 workflow 资源(上游行为:Named workflow resource execution must omit action),验证只能真跑 —— 这就是 npm run e2e 存在的原因。