Skip to main content
L

dsh-ai-review

lmx494/dsh-ai-review

Independent acceptance review for DeepSeek Harness: hand a finished code, doc or plan to a judge model from a different family and get a structured verdict back. The protocol covers rubric scoring, line-numbered evidence, deterministic quote verification and controlled read-only lookup inside a whitelisted directory; supplying a plan makes the review run twice, so declared trade-offs can withdraw findings while unfulfilled self-check promises become new ones. Its HTTP routes have no DSH access check, so a web page open in your browser could call them.

Install

dsh plugin --profile web add github:lmx494/dsh-ai-review

README

dsh-ai-review

中文文档

本项目授权 DSH Plugin 收录本仓库,并在该站展示插件信息。

Install this and every deliverable you ship gets a second opinion from a different model family — the ai_review tool hands your code/docs/plans to an independent judge that finds real bugs you missed, before your users do.

A DSH local plugin: the ai_review tool — hand your deliverables to a different model family for independent acceptance review and a second opinion.

Core insight: different models have different blind spots. After the author finishes code/docs/a plan, an independent reviewer model with a fresh context picks it apart under a unified protocol — powered by a rubric, line-numbered evidence, deterministic quote verification, and a structured output contract.

Install

Option 1: npm (recommended)

Published on npm, so it installs with one command:

dsh plugin --profile web add dsh-ai-review

You can also install straight from GitHub:

dsh plugin --profile web add github:lmx494/dsh-ai-review

Option 2: local development

Place the plugin in ~/.dsh/local-plugins/dsh-ai-review/ and enable it in the DSH plugin config (cordis.patch.yml is included), or link it into the profile's package.json.

Two-minute start

  1. Install it (command above) and restart DSH.
  2. Point it at an OpenAI-compatible endpoint — the built-in gateway (http://127.0.0.1:8326/v1) is the default, any other works too. Put the key in ~/.dsh/ai-review/settings.json:
{
  "baseUrl": "http://127.0.0.1:8326/v1",
  "apiKeyFile": "~/.dsh/openai-gateway/api-key",
  "reviewerModel": "<a model from a different family than the one writing the code>"
}
  1. Write a task in the input box and ask for a review, for example:
/review <judge-model> 给 src/pid.c 写一份 PID 模块,并审查它

The execution model writes the code first, then hands it to the named judge model. You get a structured verdict — and the code you just wrote is never touched by the reviewer.

  1. After fixing what matters, declare what you did:
ai_review_resolve({review_id, items: [{id: "F1", action: "fixed", change: "added the null check"}, {id: "F2", action: "not_fixed", reason: "intentional: the caller guarantees non-null"}]})

Items you did not fix are flagged for human review. ai_review_record shows the whole record at any time.

Nothing else to configure. reviewerModel is the only field you really need.

What it does

  • ai_review({goal, files, plan?, diff?, focus?, must_have?, model?, author_model?, root_dir?, lookup?, panel?}) → {ok, verdict, confidence, pass, summary, findings[], meta} (on failure {ok: false, error, meta})
  • files accepts paths / {path,label} / inline text / {text,label}; all material is line-numbered, long files are chunked into windows with aligned line boundaries (files exceeding the total budget are skipped honestly, not silently)
  • diff accepts unified diff text, a diff file path, or working / staged / HEAD
  • plan (strongly recommended): goals / approach / self-check promises / trade-offs. Trade-offs must be declared (why this way, what was given up, known limits); if there are none write "trade-off: none (reason)" — omitting it is a hard error (requireTradeoff: false disables; when reviewing a plan document itself, put it in files and omit plan). When provided, review runs twice: pass 1 reviews blind without the plan; pass 2 adjudicates pass-1 findings against the plan — declared trade-offs may withdraw or downgrade findings (must quote the plan verbatim, and the quote is checked against real content), unfulfilled self-check promises become new findings. The plan cannot exempt must_have; pass is locked by pass 1. Withdrawn items land in withdrawn_findings — never silently dropped. planBlindReview: false reverts to single-pass, requirePlan: true makes the plan mandatory
  • Model-family isolation: with author_model (or host auto-injection), same-source reviews are blocked at family granularity (e.g. claude-sonnet-4 vs anthropic/claude-opus-4) and the judge auto-switches to a different-family fallback pool
  • Controlled read-only evidence lookup: with root_dir (or config rootDir), or when files live in the same .git repo, the judge may run up to maxLookupRounds rounds of read-only queries (read_lines / grep / list_files) inside the whitelist — no escapes, no writes
  • Deterministic anti-hallucination check: before returning, every finding's file / line / evidence is cross-checked against the actual submitted/lookup content at zero LLM cost, annotated verified: true|false with verify_note
  • Optional dual-model Panel: only when the caller explicitly passes panel: true (i.e. the user asked for it) — two different-family judges run concurrently and results merge with consensus / single_model labels. It never turns on by itself; cost roughly doubles
  • Lightweight history: review metric summaries append to ~/.dsh/ai-review/history.jsonl (no source code); each successful review also saves ~/.dsh/ai-review/reviews/<review_id>.json (finding summaries and quotes, ≤120 chars) for adoption lookups by id
  • Readable process view: tool output leads with a record view assembled from stored fields (pass-1 blind verdict → pass-2 adjudication → kept/withdrawn items with reasons), followed by the full JSON. No model prose is inserted into the view
  • Record panel (DSH web client): a "审查记录" button above the composer and in the sidebar opens a read-only list of past reviews — verdict, finding counts, adoption state and items needing human review — with a detail page rendered from the stored record (same renderRecordCard output). Served by /ai-review/api/records and /ai-review/api/record; loopback + same-origin guarded
  • Record card ai_review_record({review_id?}): read-only. Assembles the stored review and adoption declaration into one compact card — pass-1 findings, pass-2 adjudication, retained/withdrawn items, who fixed what, what still needs human review. Pure code, no model call, no network
  • Adoption declaration ai_review_resolve({review_id, items}): the author declares fixed / partially_fixed / not_fixed / disputed per finding id (F1, F2…; withdrawn items W1…). No model call; not_fixed/disputed items are flagged "needs human review" and recorded as source: 'author_claim', human_reviewed: false
  • Advisory only: never modifies the reviewed object

Configuration

cordis.patch.yml holds generic defaults; per-machine overrides go to ~/.dsh/ai-review/settings.json (higher priority, not committed):

{
  "baseUrl": "http://127.0.0.1:8326/v1",
  "apiKeyFile": "~/.dsh/openai-gateway/api-key",
  "reviewerModel": "qodercn/q37fmodel",
  "reviewerFallbacks": ["other-family-model"],
  "panelModels": ["second-diverse-model"],
  "reviewTotalTimeoutMs": 600000,
  "maxLookupRounds": 2,
  "planBlindReview": true,
  "requirePlan": false,
  "historyEnabled": true
}

baseUrl/apiKey can point to any OpenAI-compatible endpoint — the built-in DSH gateway is only the default; paid APIs and self-hosted gateways work too.

reviewerFallbacks doubles as the failover pool: on the default route (no explicit model), timeout/network/HTTP failures auto-retry the next different-family model, with the chain recorded in meta.note; an explicit model is never switched — the judge is the caller's choice. reviewTotalTimeoutMs caps the whole review (evidence excerpting + lookups + judge rounds); per-call timeouts alone can't bound their sum.

Example

ai_review({
  goal: "Write a PID control module for STM32",
  files: ["src/pid.c", "src/pid.h"],
  diff: "working",
  plan: "Position-form PID; self-checked: anti-windup added, output clamped ±1000; trade-off: no derivative-on-measurement, judged unnecessary here",
  focus: "concurrency, edge cases, fixed-point overflow",
  must_have: "integral term has anti-windup; output clamped to ±1000",
  author_model: "your-model-name",
  panel: true   // 只有用户明确要求双模型审查时才传
})

Usage convention

Type /review <judge-model> <task> in the input box: the execution model finishes the task first, then submits its output to the named judge model for independent review. This slash convention is triggered via the prompt rules in section 7 of ~/.dsh/AGENTS.md — it is not a plugin-level command.

Design doc

DESIGN.md — data flow, output contract, evidence budgets, model-family isolation, read-only lookup guardrails, and anti-hallucination verification.

Review stats

node scripts/review-stats.mjs            # human-readable
node scripts/review-stats.mjs --json     # machine-readable

Reads ~/.dsh/ai-review/history.jsonl and resolutions.jsonl and reports how many reviews ran, how many findings the judge raised, how many survived plan adjudication, and the adoption rate — fixed findings over findings the author actually declared on. partially_fixed does not count toward the numerator; withdrawn-by-plan findings are not in the denominator. Read-only: it never touches your review records.

Tests

npm test   # 64 offline tests with injected mock chat, no network

中文文档

装上它,你交付的每一份代码/文档/方案都会先被另一个模型家族的裁判挑一遍错——真 bug 在用户发现之前先被发现。

DSH 本地插件:ai_review 工具——把交付物交给异源模型做独立验收与第二意见审查。

核心洞察:不同模型盲点不同。执行者写完代码/文档/方案后,召唤一个独立上下文的异源模型按统一协议挑错——靠的是 rubric + 带行号完整证据 + 确定性原文核验 + 结构化输出契约。

安装

方式一:npm(推荐)

已发布到 npm,一条命令装好:

dsh plugin --profile web add dsh-ai-review

也可以直接从 GitHub 装:

dsh plugin --profile web add github:lmx494/dsh-ai-review

方式二:本地开发

放到 ~/.dsh/local-plugins/dsh-ai-review/ 并在 DSH 插件配置中启用(cordis.patch.yml 已备好),或 link 进 profile 的 package.json。

两分钟上手

  1. 装上(上面的命令),重启 DSH。
  2. 指向一个 OpenAI 兼容端点——DSH 内置网关(http://127.0.0.1:8326/v1)是默认值,换成别的也行。密钥写进 ~/.dsh/ai-review/settings.json:
{
  "baseUrl": "http://127.0.0.1:8326/v1",
  "apiKeyFile": "~/.dsh/openai-gateway/api-key",
  "reviewerModel": "<选一个和写代码的模型不同家族的模型>"
}
  1. 在输入框里写任务并要求审查,例如:
/review <裁判模型> 给 src/pid.c 写一份 PID 模块,并审查它

执行模型先把代码写完,再把它交给指定裁判模型。你拿到的是结构化结论——你刚写的代码不会被裁判改动。

  1. 改完之后声明处理结果:
ai_review_resolve({review_id, items: [{id: "F1", action: "fixed", change: "补了空指针检查"}, {id: "F2", action: "not_fixed", reason: "有意为之:调用方保证非空"}]})

没改的条目标为待人工复核。随时用 ai_review_record 看完整记录。

不用再配别的,reviewerModel 是唯一真正需要的字段。

它做什么

  • ai_review({goal, files, plan?, diff?, focus?, must_have?, model?, author_model?, root_dir?, lookup?, panel?}) → {ok, verdict, confidence, pass, summary, findings[], meta}(失败时 {ok: false, error, meta})
  • files 支持文件路径 / {path,label} / 内联文本 / {text,label};所有材料自动附加行号,长文件行对齐分块摘录(超总预算提前跳过摘录请求并诚实标记)
  • diff 支持 unified diff 文本、diff 文件路径或 working / staged / HEAD
  • plan 施工说明(强烈推荐):目标/方案/自查承诺/取舍。必须写明取舍(为什么这么做、放弃了什么、已知限制);确实没有就写"取舍:无(原因)",空着或不写会直接报错(requireTradeoff: false 可关;审计划本身时把计划文档放 files、不传 plan 即可)。提供后走两遍审查:第一遍裁判看不到 plan,只按交付物盲审;第二遍再拿 plan 裁决第一遍结论——已声明的取舍可撤销或降级对应 finding(必须引用 plan 原句,代码核对原句真实存在),未兑现的自查承诺作为新问题提出。plan 不能豁免 must_have,pass 由第一遍锁定。被撤销的项放在 withdrawn_findings,不会消失。配置 planBlindReview: false 可回到一遍审查,requirePlan: true 可强制要求提供 plan
  • 模型家族级隔离:传 author_model(或由宿主自动透传)后,按模型家族去重(拦截如 claude-sonnet-4 vs anthropic/claude-opus-4 同源审查)并自动切换到异源备选池
  • 受控只读补证:当传入 root_dir(或配置 rootDir)或 files 处于同一 .git 仓库内时,裁判可在白名单目录内执行最多 maxLookupRounds 轮只读查询(read_lines / grep / list_files),严禁越界与写入
  • 确定性反幻觉核验:返回前零成本反查每条 finding 的 file / line / evidence 是否命中真实送审或补证内容,标注 verified: true|false 与 verify_note
  • 可选双模型 Panel:只在调用方显式传 panel: true(即用户明确要求)时启用——两个不同家族模型并发审查,按共识度标注 consensus / single_model。不会自动开启,成本约翻倍
  • 轻量留痕:默认将审查指标摘要追加写入 ~/.dsh/ai-review/history.jsonl(不存源码全文);每次成功审查另存 ~/.dsh/ai-review/reviews/<review_id>.json(finding 摘要与引文,≤120 字),供采纳声明按 id 查找
  • 过程视图:工具结果先输出由记录字段拼成的视图(第一遍盲审结论 → 第二遍按 plan 裁决 → 保留/撤销的问题及理由),再附完整 JSON;视图中不插入模型自然语言
  • 记录面板(DSH 网页客户端):输入框上方和侧边栏各有一个"审查记录"按钮,点开是只读列表——结论、问题数、采纳状态、待人工复核项,点进去看由 renderRecordCard 拼好的详情。数据来自 /ai-review/api/records 与 /ai-review/api/record,带回环地址与同源校验
  • 记录卡片 ai_review_record({review_id?}):只读。把存档与采纳声明拼成一张紧凑卡片——第一遍 findings、第二遍裁决、保留/撤销的条目、谁改了什么、哪些仍待人工复核。纯代码拼接,不调模型、不联网
  • 采纳声明 ai_review_resolve({review_id, items}):执行方按 finding id(F1、F2…,被撤销项 W1…)声明 fixed / partially_fixed / not_fixed / disputed。不调模型;不改不写的必须给理由;未修改、有异议的条目标为"需要人工复核",记录标 source: 'author_claim'、human_reviewed: false
  • 只给意见,不执行:永不修改被审对象

配置

cordis.patch.yml 改通用默认;本机差异写 ~/.dsh/ai-review/settings.json(优先级更高,不进 git):

{
  "baseUrl": "http://127.0.0.1:8326/v1",
  "apiKeyFile": "~/.dsh/openai-gateway/api-key",
  "reviewerModel": "qodercn/q37fmodel",
  "reviewerFallbacks": ["其他家族模型名"],
  "panelModels": ["第二异源模型名"],
  "reviewTotalTimeoutMs": 600000,
  "maxLookupRounds": 2,
  "planBlindReview": true,
  "requirePlan": false,
  "historyEnabled": true
}

baseUrl/apiKey 可指向任何 OpenAI 兼容端点——DSH 内置网关只是默认值,付费 API/自建网关同样可用。

reviewerFallbacks 同时是故障转移池:走默认路由(未显式传 model)时,裁判调用遇 timeout/network/HTTP 等失败会自动换下一异源模型重试,meta.note 记录转移链;显式指定 model 时不换——裁判人选是调用方的决定。reviewTotalTimeoutMs 是整个 review(证据摘录+补证+多轮裁判)的总时限,单次调用超时管不住多次调用叠加。

使用示例

ai_review({
  goal: "给 STM32 写一个 PID 控制模块",
  files: ["src/pid.c", "src/pid.h"],
  diff: "working",
  plan: "采用位置式 PID;已自查:积分抗饱和已加、输出限幅 ±1000;取舍:未做微分先行,认为本场景不需要",
  focus: "并发安全、边界条件、定点溢出",
  must_have: "积分项有抗饱和处理;输出限幅在 ±1000",
  author_model: "你的模型名",
  panel: true
})

使用约定

输入框写 /review <裁判模型> <任务>:执行模型完成任务后把产出送指定裁判模型独立审查。该斜杠指令依赖 ~/.dsh/AGENTS.md 第七节的提示词约定触发 agent 调用 ai_review,并非插件代码层注册的独立命令。

设计文档

DESIGN.md——数据流、输出契约、证据预算、模型家族隔离、只读补证护栏与反幻觉核验机制。

审查统计

node scripts/review-stats.mjs            # 人读格式
node scripts/review-stats.mjs --json     # 机读格式

读 ~/.dsh/ai-review/history.jsonl 与 resolutions.jsonl,报审查次数、裁判提出的问题数、plan 裁决后的保留数,以及采纳率——已修 ÷ 执行方实际声明处理的条目。部分修不计入分子,被 plan 撤销的条目不进分母。只读,不动你的审查记录。

测试

npm test   # 64 项离线测试,注入 mock chat,不碰网络

Related plugins