Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Strict——运行完整 CLI 工作流:

```bash
./infermatrix-copilot -p "review pr 5172"
./infermatrix-copilot --playbook pr-review --task-param pr=5172 --task-param include_score=true
./infermatrix-copilot -p "review pr 5172" --plan-only # 只看计划不执行
./infermatrix-copilot -p "review pr 5172" --performance # 用高能力模型档
```
Expand All @@ -159,6 +160,15 @@ Strict 在固定到 PR head 的 checkout 上运行,并按改动规模和风险
“Use InferMatrixCopilot in Strict mode to review …”;拿到 `run_id` 后,用
`get_review_status` 和 `get_review_result` 轮询。

Strict 根据改动承诺检查证据。性能比较需要同一工作负载下可比的原始记录,生成结果需要检查实际输出。
报告会列出无法核实的主张。评审结论考虑所有独立核实的实质性发现。即使某个严重问题已有当前
head 上的活跃讨论、无需再发一条行内评论,它仍可导致 `REQUEST CHANGES`。

需要百分制评分时,CLI 可使用上面的 `include_score=true`,MCP 可传
`review(..., mode="strict", include_score=true)`,SDK 可传 `StrictReviewRequest(..., include_score=True)`。
评分默认关闭。结构化结果的 `review_claim_evidence` 给出证据检查,`review_score` 仅在请求时出现。
有数值时它只供参考;head 已移动、无法复核或审查不完整时,报告列出原因并保留已支持的分项。

## 快速上手 2 · rebase

把单个 PR rebase 到最新 base。工作流会识别 fork,检出 PR 分支,完成 rebase、
Expand Down Expand Up @@ -366,7 +376,7 @@ Agent 会先读取仓库约定、相关源码和知识,明确完成条件,
zero(`vllm-omni`),可传任何已接入仓库的短名、别名或 owner/name:

- `review(target, repo="vllm-omni", mode="direct", post=false,
review_depth="", title="", body="", changed_files=[], repo_path="")`:
review_depth="", title="", body="", changed_files=[], repo_path="", include_score=false)`:
Direct 返回至多 3 条精确知识路由和审查门禁;Strict 返回 `run_id`。
`repo_path` 可临时指定 Strict 使用的本地 checkout。
- `validate_direct_review(subtraction_signal, subtraction?,
Expand Down
5 changes: 3 additions & 2 deletions doc/architecture/SPEC/app/request_policy.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# app/request_policy.py — request safety policy

<!-- verified-against: 2026-09-26 -->
<!-- verified-against: 2026-11-25 -->

This headless application module validates untrusted read-only requests for
the SDK, MCP transport, and reserved-run worker. It derives a new `TaskSpec`
Expand All @@ -11,7 +11,8 @@ reading `request.json`; persisted input alone is not an authority.
`post=False`, limits repositories to the configured allowlist, checks positive
PR/issue numbers, validates full expected-head SHAs, and strips unknown
params. A bounded `deterministic_signals` list applies only to quality review;
carried findings are validated for PR review. `authorize_repo_path` verifies
carried findings are validated for PR review. PR review accepts boolean
`include_score`. False and omission have the same idempotency fingerprint. `authorize_repo_path` verifies
both checkout origin identity and containment under allowed roots.

`enforce_strict_review_policy` accepts only PR review, forces eco mode, and
Expand Down
7 changes: 4 additions & 3 deletions doc/architecture/SPEC/contract.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# contract.py —— 规范

<!-- verified-against: 2026-09-30 -->
<!-- verified-against: 2026-11-25 -->

`旧版跨仓库契约兼容层 · refactor-status: compatibility-shim`

Expand All @@ -13,7 +13,7 @@

## 公开契约(`__all__`)
`SDK_API_VERSION` / `DIRECT_API_VERSION` / `STRICT_API_VERSION` /
`QUALITY_API_VERSION` / `KNOWLEDGE_API_VERSION`(SDK、Quality 为 `"1.0.0"`,Direct 为 `"1.1.0"`,Strict 为 `"1.4.0"`,Knowledge 为 `"1.1.0"`,且都从 `sdk.v1.models`
`QUALITY_API_VERSION` / `KNOWLEDGE_API_VERSION`(SDK、Quality 为 `"1.0.0"`,Direct 为 `"1.1.0"`,Strict 为 `"1.5.0"`,Knowledge 为 `"1.1.0"`,且都从 `sdk.v1.models`
取唯一值)。`capabilities(max_strict_workers=1,
supports_file_locking=True) -> dict` 委托 SDK typed handshake 再投影为兼容
dict;它包含 distribution/SDK/Direct/Strict/Quality/Knowledge 版本、resource
Expand All @@ -23,7 +23,8 @@ revision、supported repositories,以及 `supports_expected_head`、
`max_strict_workers`(服务真实的并发 worker 数,即 `STRICT_MAX_WORKERS`,
同一 checkout+PR 的 run 仍逐个执行)。其余兼容导出包括 `build_review_result(run_dir) -> dict`(结构化评审
结果:`contract_version`、`run_id`、`state`、`reviewed_head_sha`、`verdict`、
`summary_markdown`、`comments`、`finding_dispositions`、`findings`、
`summary_markdown`、`comments`、`finding_dispositions`、`findings`、本次运行记录的
`review_claim_evidence` 及按请求生成的 `review_score`、
`stale`/`expected_head_sha`/`actual_head_sha`、`diagnostics`);`unknown_run_result(run_id)`(显式
`state: unknown`,绝不抛错 —— 丢响应和还在跑必须可区分);
`sanitize_comments` 与 `COMMENT_FIELDS`,以及 `finding_id` / `build_findings`;另有从 `direct_routing` 再导出的
Expand Down
5 changes: 4 additions & 1 deletion doc/architecture/SPEC/engine/agent_runtime.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# engine/agent_runtime/ —— 规范

<!-- verified-against: 2026-11-04 -->
<!-- verified-against: 2026-11-25 -->

`LOC ~1690(7 个文件) · 引擎(受治理的 agent 运行时) · refactor-status: ok`

Expand Down Expand Up @@ -55,6 +55,9 @@
- briefing 只在 `profile_briefing_enabled` 时进 prompt(消融开关)。
- 输出:base+extension schema、一轮修复、状态→FailureKind;预算耗尽会**强制最终答复**。
全程 trace(`agent_dispatch`/`agent_output`)。
- Strict 的每个调查可以返回 `claim_checks`。请求评分时还会返回 `dimension_ratings`。
重试和深度升级保留已获取的证据。reducer 独立合并调查记录,即使所有评论都被丢弃,
证据仍会进入固定版本的核验和结果输出。
- ensemble reducer:逐编号候选做 keep/drop/dup、确定性组装、**未提及即保留**
(fail-open)、共识门控的快路径。
- **零产出的 lens 单独重问一次**(`ensemble_zero_yield_retry`),
Expand Down
6 changes: 5 additions & 1 deletion doc/architecture/SPEC/engine/steps/_common.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# engine/steps/_common.py —— 规范

<!-- verified-against: 2026-09-26 -->
<!-- verified-against: 2026-11-25 -->

`LOC ~300 · step 库基础设施 · refactor-status: ok`

Expand Down Expand Up @@ -61,3 +61,7 @@ step 样板的收敛就落在这个文件。`require_repo`(K3)、`no_llm_gap
`store_for(adapter)`(K3)。
已落地与待抽取的每一个都必须**保住它所包裹的那条保证**(B1 类型化返回、B2 交接、
E2 `capability_gap` 事件)。**只在 ≥2 个真实现场时才抽取**。

Strict review passes `issue_comments=False` to `gh_read_tools`. Its issue reader
can inspect issue title, body and labels without exposing conversation on a PR
addressed by the same number. Issue workflows retain the default comment access.
8 changes: 7 additions & 1 deletion doc/architecture/SPEC/engine/steps/pr.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# engine/steps/pr/ —— 规范

<!-- verified-against: 2026-10-08 -->
<!-- verified-against: 2026-11-25 -->

`LOC ~1988(6 个文件) · step 库(PR) · refactor-status: ok`

Expand Down Expand Up @@ -129,3 +129,9 @@ K3/K4/K7 的精简(require_repo/published/from_state)已在各子模块落
## 自进化接入(2026-10-04)

影子模式下 `pr.fetch_diff`、gate 和 CI 取数从可信控制器准备的 `pr_snapshot` 读取;快照缺少必要字段即阻塞,不回退到实时网络。基线和候选共用冻结的 base/head 与上下文。

Strict review fetches the PR description, commit subjects and linked issue
acceptance criteria before source investigation. Its initial GitHub query omits
PR discussion and review threads. Full PR quality assessments may still include
discussion. The checkpoint records whether the fetched context is independent of
feedback, so reviews resumed from older combined bundles can exclude discussion.
22 changes: 21 additions & 1 deletion doc/architecture/SPEC/engine/steps/review.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# engine/steps/review/ —— 规范

<!-- verified-against: 2026-10-04 -->
<!-- verified-against: 2026-11-25 -->

`patch gate + PR review + quality(9 个源文件) · step 库(评审) · refactor-status: ok`

Expand Down Expand Up @@ -138,3 +138,23 @@ Direct 1.1 / Strict 1.3 accept typed `CarriedFinding` inputs (unique IDs, source
## 自进化接入(2026-10-04)

影子评审继承严格工具 scope;PR 文件、基础版本与历史工具只能读取冻结仓库,涉及生产写入的步骤由执行器拒绝。

## Independent findings and publication

`publication.py` derives the verdict from selected findings before applying
thread suppression, the unit-test comment cap or the inline comment budget.
Current-head rechecks may contribute a confirmed carried defect. An open recheck
gap is reported and precludes an otherwise empty approval.

`feedback.py` compares at most the latest 50 inline threads after candidate
selection. Suppression requires an active, current RIGHT-side thread at the same
path and line with matching concern text on the reviewed head. The review links
the existing thread and retains its impact in the verdict. Missing feedback and
a moved head preserve the independently selected findings. No-discussion and
isolated snapshot reviews perform no GitHub feedback lookup.

The host verifies claim evidence against the pinned source or raw CI log
records tied to the reviewed revision. A verified acceptance requirement can
affect the verdict. When the caller requests `include_score`, missing required
artifacts zero the claim-evidence dimension. The scoring result explains a
withheld total when the head is stale or material checks remain incomplete.
5 changes: 3 additions & 2 deletions doc/architecture/SPEC/improve.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# improve/ —— 规范(元改进引擎)

<!-- verified-against: 2026-10-09 -->
<!-- verified-against: 2026-11-25 -->

`设计:/data/zhoutaichang/copilot/meta-improvement-engine-design.md v1(GPT-6 sol 批准 2026-09-29) · refactor-status: building (P0–P4 已落地)`

Expand All @@ -16,7 +16,8 @@

Replay envelope 保留完整文件与引用,由 TraceStore 脱敏、压缩和按内容寻址;未压缩 UTF-8 JSON 上限为 64,000,000 bytes。超限只记录 `replay_capture_deferred` 的大小、上限和摘要并抛出专用 `ReplayCaptureLimit`,不保存截断输入,也不进入 replay 数据集。知识起草无活动进化工作流时继续原生固定生成器;活动工作流(含已禁用项)缺少完整 replay 时保持事件 pending。其他捕获错误不能走此延期路径。

`runtime.py` 重新应用补丁核验实际评估树,原子采用本地不可变 release,原生 PR 评审、知识草稿、lint 和归因在活动制品的沙箱中运行。宿主记录运行指纹才更新部署基线。首次八个不同 item 与上一版比较,七日缺证据自动恢复;保留后每周最多八个新 item 持续比较。契约、凭据/隔离/预算、指纹失败或资源显著退化自动恢复上一版;恢复制品不可验证则禁用执行。执行/切换锁及持久化激活、回滚意图支持重启恢复。
`runtime.py` 重新应用补丁核验实际评估树,原子采用本地不可变 release,原生 PR 评审、知识草稿、lint 和归因在活动制品的沙箱中运行。PR 评分和主张证据在宿主的真实评审版本上验证,沙箱重建的 Git SHA 不作为实际 PR 的标识。
宿主记录运行指纹才更新部署基线。首次八个不同 item 与上一版比较,七日缺证据自动恢复;保留后每周最多八个新 item 持续比较。契约、凭据/隔离/预算、指纹失败或资源显著退化自动恢复上一版;恢复制品不可验证则禁用执行。执行/切换锁及持久化激活、回滚意图支持重启恢复。

默认 `IMPROVE_EVALUATION_MODE=objective`、`IMPROVE_PROMOTION_MODE=automatic`,不要求人工标签、判官或 performance 模型。总开关仍关闭,固定模型取 `IMPROVE_EVOLVE_MODEL` 或 eco;每周一个候选、一次修复及共享 20 美元预算不变。`gold/pr` 模式保留原有双家族取证及人工流程。无隔离生产驱动的机械工作流仍可 lint,但不自动采用。当前主机命名空间关闭,代码候选实际执行延期。

Expand Down
4 changes: 3 additions & 1 deletion doc/architecture/SPEC/intent.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# intent.py —— 规范

<!-- verified-against: 2026-10-04 -->
<!-- verified-against: 2026-11-25 -->

`LOC ~379 · 任务层 · refactor-status: ok`

Expand Down Expand Up @@ -30,6 +30,8 @@ LLM 把命令(kind / pr / issue / flags)分类成 `TaskSpec`;低于置信
推理模型会先把预算花在思考上,500 的上限下它**一个 JSON 字符都吐不出来**,于是一条
完全清楚的命令被答成"I couldn't parse that"。`review/planner.py` 踩过同一个坑并定在
8000;**修复轮同样要给足**——那正是被饿死的模型会落到的地方。
- PR 评审可以按明确请求附加数值评分,例如 `review PR 7 with a score`。
省略或否定评分请求时保留默认值。
- 空命令或未配置 LLM → 澄清(绝不猜测)。
- **有歧义就澄清 —— 绝不猜测**:LLM 置信度 < 0.7、显式澄清、畸形回复、未知 kind,
全都 → 澄清。
Expand Down
4 changes: 2 additions & 2 deletions doc/architecture/SPEC/mcp_server.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mcp_server.py —— 规范

<!-- verified-against: 2026-09-26 -->
<!-- verified-against: 2026-11-25 -->

`MCP 协议适配器 · refactor-status: ok`

Expand All @@ -18,7 +18,7 @@
`CopilotMCP` 是 `RunService` 的兼容别名;`build_mcp()` 注册 start/poll 工具,外加
`get_capabilities()`(包 `contract.capabilities`,含
`MAX_STRICT_WORKERS=1` 与文件锁能力上报)。`start_review` 接受
`expected_head_sha`;`start_strict_review` 接受 `idempotency_key` 并把
`expected_head_sha` 及默认关闭的 `include_score`;`start_strict_review` 接受 `idempotency_key` 并把
`(run_id, created)` 语义(见下)落到入队决定上。新增内部
`reserve_strict_review` 原样返回该 tuple,供 typed SDK 准确报告幂等复用;
`start_strict_review` 继续只返 `run_id`,保持 MCP/既有调用兼容;
Expand Down
4 changes: 3 additions & 1 deletion doc/architecture/SPEC/playbooks/PLAYBOOKS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# playbooks/*.yaml —— 规范

<!-- verified-against: 2026-10-05 -->
<!-- verified-against: 2026-11-25 -->

`9 个文件 · 声明式编排数据 · refactor-status: ok`

Expand All @@ -23,6 +23,8 @@ success, steps[]`。
**不要改它的 step 列表**。
- `pr-rebase`/`pr-debug`/`pr-review`/`pr-quality`/`issue-answer`/`issue-triage` —— active,
仓库中立(`repos: []`、`requires: [repo.path]`)。
- `pr-review` 声明可选布尔参数 `include_score`。默认按固定版本输出发现和证据,
显式请求后附加参考分数。
- `pr-debug` 的 report-only 模式跳过 checkout 和 push;修复模式在推送前审查
已提交的变更。
- `repo-profile` —— active,仓库中立(用于接入第二个仓库)。
Expand Down
3 changes: 3 additions & 0 deletions doc/architecture/SPEC/providers/zcode.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ argv 单参数上限 128KiB)。`--mode` 按调用选:一次性调用用 `pla
实时交付原生事件,`supports_native_events=True`。`native_snapshot()` 只返回提供方实际报告的
用量与模型;缺失的 token、缓存和 USD 字段保持未知,不补造零值。

RFC 的错误分类和无工具调用可在缺少 `fcntl` 的平台上导入。写入工作区 MCP
信任记录前必须取得 POSIX 文件锁;缺少锁支持时抛出 `FileLockingUnavailable`。

## 不变量(**C1**、**C2**)
- **会话 cwd 永远是自有临时目录,不是 PR worktree。** zcode 从 cwd 加载 `.env`,并从 cwd
往上到 git 根发现 `zcode.json` / `.zcode/config.json`,项目配置里的 stdio MCP server 会被
Expand Down
7 changes: 4 additions & 3 deletions doc/architecture/SPEC/sdk.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sdk/ —— 规范

<!-- verified-against: 2026-11-04 -->
<!-- verified-against: 2026-11-25 -->


`Python SDK v1 · 跨仓库唯一 typed 边界 · refactor-status: ok`
Expand Down Expand Up @@ -157,9 +157,10 @@
push、开 PR 或 schedule。ReviewBot 必须向 `KnowledgeCurator` 传 dedicated work
checkout,并继续拥有重试、artifact 与本地补丁导出;SDK 也绝不写 packaged
knowledge tree。自适应 DirectClient 仅管理知识上下文的运行账本,不代替知识出版治理。
- SDK、Quality API 版本常量为 `1.0.0`;Direct 为 `1.1.0`,Strict 为 `1.4.0`
- SDK、Quality API 版本常量为 `1.0.0`;Direct 为 `1.1.0`,Strict 为 `1.5.0`
(1.1 新增 `finding_dispositions`;1.2 新增 `findings`;1.3 新增显式 recheck;
1.4 新增 `StrictRuntimeConfig.max_workers`),Knowledge 为 `1.1.0`
1.4 新增 `StrictRuntimeConfig.max_workers`;1.5 新增 `StrictReviewRequest.include_score`,
以及 `StrictReviewResult.review_claim_evidence` 与可选 `review_score`。读取旧结果时分别为空元组与 None),Knowledge 为 `1.1.0`
(1.1 向后兼容地新增 `catalog_entries()` / `KnowledgeCatalogEntry` 与容量预检),
distribution 为 `0.2.0`;`Capabilities.knowledge_api_version` 与
`supports_knowledge_curation` 组成 ReviewBot 的 paired-release 握手,避免只按
Expand Down
3 changes: 2 additions & 1 deletion doc/architecture/SPEC/thin_mcp_server.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# thin_mcp_server.py —— 规范

<!-- verified-against: 2026-11-04 -->
<!-- verified-against: 2026-11-25 -->

`LOC ~490 · 默认 MCP:Direct 门面 + Strict 入口 · refactor-status: ok`

Expand All @@ -19,6 +19,7 @@
`get_workflow` / `get_update_status`。

## 公开契约
Strict 的 `review(..., include_score=true)` 请求参考分数,分页结果保留证据明细和可选评分。
上述工具;`build_mcp(...)`;`main()`。`review(knowledge_profile="adaptive")`
返回单一实际 `model_content` 和不重复正文的引用;默认 `legacy` 保持旧契约。
会话工具累积预算,跨仓库目标只在主机授权与 confirmed 固定依赖同时成立时可读;
Expand Down
3 changes: 2 additions & 1 deletion doc/guide/hosts/codex.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ Strict 会用它配置的模型运行打包好的 `pr-review` playbook,带进

- `review(target, repo?, mode="direct", post=false, title="", body="",
changed_files=[], review_depth="", repo_path="", expected_head_sha="",
idempotency_key="")`:在宿主发出进度更新之后,
idempotency_key="", include_score=false)`:Strict 可按要求在结论之后给出百分制参考分数。
在宿主发出进度更新之后,
Direct 用 title/body 返回**至多三条**精确的 owner/model 路由,各自带内嵌的精简
`quick_map` 摘录。changed files 通常只做范围校验;但当返回的路由**没有一条**命中
它们推导出的 owner 时,改由 changed files 选路,并在响应里明说
Expand Down
1 change: 1 addition & 0 deletions playbooks/pr-review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ requires: [repo.path]
# declared adaptation surface: specs carrying only these params still resolve
# as reuse (L0) — an undeclared param would demote to adapt (L1, review gate)
params:
include_score: "optional boolean — report a revision-bound advisory score"
review_depth: "optional light|standard|full|auto — pins the adaptive review
depth for this run (see review/planner.py)"
steps:
Expand Down
7 changes: 6 additions & 1 deletion src/infermatrix_copilot/app/request_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# strictly value-validated below — a knob may modulate cost/depth, never widen
# permissions.
_ALLOWED_PARAMS: frozenset[str] = frozenset({
"review_depth", "deterministic_signals", "carried_findings",
"review_depth", "deterministic_signals", "carried_findings", "include_score",
})
_REVIEW_DEPTHS = ("auto", "light", "standard", "full")

Expand Down Expand Up @@ -156,6 +156,11 @@ def enforce_mcp_policy(raw: dict[str, Any], *, allowed_repos: list[str],
f"review_depth {params['review_depth']!r} is not one of "
f"{list(_REVIEW_DEPTHS)}")
params["review_depth"] = str(params["review_depth"]).lower()
if "include_score" in params:
if not isinstance(params["include_score"], bool):
raise PolicyError("include_score must be a boolean")
if kind != "pr_review" or not params["include_score"]:
params.pop("include_score")
if "carried_findings" in params:
if kind != "pr_review":
params.pop("carried_findings")
Expand Down
Loading
Loading