feat(auto-review): 增加当前模型轻量审查基础设施 - #1226
Conversation
|
| Filename | Overview |
|---|---|
| packages/maker-core/src/agents/shared/auto-review-decision.ts | 新增 Auto-review 请求与决策协议、本地裁决分层、输入证据检查、委托超时及保守降级。 |
| apps/desktop/src/main/maker-host/auto-permission-reviewer.ts | 新增有界提示构造、载荷结构转义、严格响应解析和 host 侧轻量审查委托器;先前标签闭合问题已修复。 |
| apps/desktop/src/main/utility-model/oneShotCandidates.ts | 为 provider one-shot 请求传递推理强度和输出上限,并为不兼容可选字段的自定义路由提供最小请求重试。 |
| packages/maker-core/src/agents/base-agent.ts | 扩展 host 与 session 接口,为后续 Auto-review fallback 路由提供委托和切换能力。 |
| apps/desktop/src/main/maker-host/tests/autoPermissionReviewer.test.ts | 覆盖提示载荷最小化、标签转义、输入上限、输出解析、超时和异常降级行为。 |
| apps/desktop/src/main/utility-model/tests/oneShotCandidates.test.ts | 覆盖各 provider 的推理参数、输出上限、能力例外和无可选字段重试请求形状。 |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[AutoReviewRequest] --> B[本地确定性规则]
B -->|明显安全| C[allow]
B -->|高影响边界| D[ask]
B -->|灰区| E{证据完整且大小合规?}
E -->|否| F[block]
E -->|是| G[当前会话模型轻量审查]
G -->|有效三态 JSON| H[返回模型决策]
G -->|超时、异常或畸形输出| F
Reviews (9): Last reviewed commit: "fix(auto-review): minimize incompatible ..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 46d272f50c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: zqchris <chrisz83@gmail.com>
46d272f to
77ccc4e
Compare
There was a problem hiding this comment.
Pull request overview
本 PR 为 Auto-review 增加“当前会话模型轻量审查”的基础设施:在 maker-core 侧统一 allow / block / ask 的决策协议与最小审查上下文,并在 Desktop host 侧提供可复用的 one-shot 审查 prompt/解析器与调用封装;同时补齐 utility one-shot 的推理强度提示与对部分 Responses 兼容端点的参数形状适配,并配套单元测试。
Changes:
- 在
@cindy/maker-core新增 Auto-review 决策 schema、最小请求结构、delegate 协议与本地/委托融合裁决入口,并导出相关类型。 - 在 Desktop main 新增轻量 auto permission reviewer(prompt 构建、输出解析、日志与失败降级),用于 vendor reviewer 不可用时的兜底路径。
- 在 utility one-shot 请求链路中透传
reasoningEffort,并为特定 Responses 端点增加max_output_tokens兼容开关,补齐对应测试。
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/maker-core/src/agents/shared/auto-review-decision.ts | 新增 Auto-review 决策类型、最小请求、delegate 协议与裁决入口(本地规则 + 可选委托)。 |
| packages/maker-core/src/agents/shared/auto-review-decision.test.ts | 覆盖本地 deterministic 分支不调用 delegate、灰区 delegate 结果透传、异常/非法输出 fail-closed。 |
| packages/maker-core/src/agents/index.ts | 对外导出 Auto-review 决策相关类型与 ReviewableAction 类型。 |
| packages/maker-core/src/agents/base-agent.ts | 在 AgentDeps / SessionHandle 上扩展轻量 reviewer 依赖与 fallback hook(含 deprecations)。 |
| apps/desktop/src/main/utility-model/oneShotCandidates.ts | one-shot 请求链路透传 reasoningEffort;为部分 Responses 端点禁用 max_output_tokens。 |
| apps/desktop/src/main/utility-model/tests/oneShotCandidates.test.ts | 断言 ChatGPT Codex 路由 body 形状:包含 reasoning.effort 且不发送 max_output_tokens。 |
| apps/desktop/src/main/maker-host/auto-permission-reviewer.ts | 新增 Desktop host 侧轻量 reviewer:最小 payload prompt、紧凑 JSON 解析、输出/原因截断与日志。 |
| apps/desktop/src/main/maker-host/tests/autoPermissionReviewer.test.ts | 覆盖 prompt 最小化、越界截断、解析容错与异常降级路径。 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 77ccc4e430
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@zqchris 👋 这个 PR 还有 5 条 review conversation 没 resolve(packages/maker-core/src/agents/shared/auto-review-decision.ts / apps/desktop/src/main/maker-host/auto-permission-reviewer.ts / apps/desktop/src/main/utility-model/oneShotCandidates.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。 如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
Suppressed comments (1)
packages/maker-core/src/agents/shared/auto-review-decision.ts:43
reviewAction()的返回值包含prompt(见 packages/maker-core/src/agents/shared/auto-review.ts:45-109),语义是需要升级用户确认;但这里仅把prompt-each-time映射成ask,会把prompt当成“灰区”继续走 delegate(甚至在 delegate 缺失时直接block)。这会导致本应走本地确定性“需要确认”的动作在 fallback 路径下被误判(可能被模型放行、或无 delegate 时被静默拦截),与注释“明显红线仍由本地规则确定”不一致。建议把prompt也映射到ask。
if (localVerdict === 'auto-approve') return { verdict: 'allow' };
if (localVerdict === 'prompt-each-time') return { verdict: 'ask' };
if (!delegate) {
Signed-off-by: zqchris <chrisz83@gmail.com>
Signed-off-by: zqchris <chrisz83@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (1)
packages/maker-core/src/agents/shared/auto-review.ts:62
ReviewVerdict里的prompt在auto-review.ts的模块注释中仍被描述为“升级用户确认(可本会话记住)”(packages/maker-core/src/agents/shared/auto-review.ts:20-21),但本 PR 新增的auto-review-decision.ts已将prompt显式映射为内部灰区needs-review,并可能走 host 侧轻量 reviewer 后返回block(不一定触发用户确认)。这会让后续维护者误解prompt的语义,尤其是新增/调整 adapter 时更容易把prompt当成 UI 行为。建议同步更新auto-review.ts的判定档说明,把prompt解释为“需要进一步审查/升级到外层裁决层”,避免与 UI 的ask混用。
| { kind: 'session-state' }
| { kind: 'file-write'; path: string | undefined }
| { kind: 'exec'; command: string }
| { kind: 'network'; target?: string; operation?: string }
| { kind: 'other' };
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
apps/desktop/src/main/maker-host/auto-permission-reviewer.ts:140
- 这里用 Promise.race 做超时兜底时,未对 deps.requestText() 的“落败 promise”附加 catch;如果 requestText 在超时返回后才 reject,Node 可能触发 unhandledRejection(同时请求也会继续跑到结束)。建议在 race 前把 requestText 包一层 .catch(() => null) 来吞掉后续 reject,避免进程级告警/崩溃风险。
const text = await Promise.race([
deps.requestText(request, buildAutoPermissionReviewPrompt(request)),
new Promise<typeof REVIEW_TIMEOUT>((resolve) => {
timeout = setTimeout(() => resolve(REVIEW_TIMEOUT), REVIEW_TIMEOUT_MS);
}),
]);
Signed-off-by: zqchris <chrisz83@gmail.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a07f1c2ea8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@zqchris 👋 这个 PR 还有 1 条 review conversation 没 resolve(packages/maker-core/src/agents/shared/auto-review-decision.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。 如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (1)
packages/maker-core/src/agents/shared/auto-review-decision.ts:107
- 这里直接 await delegate(request) 没有任何超时兜底;如果 host 侧 delegate 永不 settle(例如请求挂死或漏了超时),resolveAutoReviewDecision 会一直卡住,和上方注释“超时/不可用时灰区一律 block、且不应 hold tool callback open”的承诺不一致。建议在 core 侧也用 Promise.race 加一个硬超时(与 host 的 8s 对齐即可),超时按 null/非法结果处理并走 block 降级。
try {
const decision = await delegate(request);
if (
decision?.verdict === 'allow'
|| decision?.verdict === 'block'
Signed-off-by: zqchris <chrisz83@gmail.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 746f27cdc4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (3)
apps/desktop/src/main/maker-host/auto-permission-reviewer.ts:139
- 这里用
Promise.race实现 8s deadline,但超时分支不会 abort 正在进行的请求。结合上面的AbortSignal扩展后,建议在超时时调用controller.abort(),以便及时释放 HTTP 连接并避免后台持续跑请求。
const text = await Promise.race([
deps.requestText(request, buildAutoPermissionReviewPrompt(request)),
new Promise<typeof REVIEW_TIMEOUT>((resolve) => {
timeout = setTimeout(() => resolve(REVIEW_TIMEOUT), REVIEW_TIMEOUT_MS);
}),
apps/desktop/src/main/maker-host/auto-permission-reviewer.ts:14
- 目前超时只让
Promise.race先返回,但不会取消底层的requestText(网络请求仍会继续占用连接/算力),在高频审批场景里可能造成并发堆积。建议在 deps 层暴露可选AbortSignal,让 reviewer 在超时时主动 abort。
This issue also appears on line 135 of the same file.
export interface AutoPermissionReviewerDeps {
requestText(request: AutoReviewRequest, prompt: string): Promise<string | null>;
logger: AutoPermissionReviewerLogger;
packages/maker-core/src/agents/shared/auto-review-decision.ts:61
missingReviewEvidence对network只检查了target,但ReviewableAction已支持operation字段;如果 adapter 只填了operation(例如用它承载搜索词/操作描述),这里会被误判为“缺少证据”并直接block,导致不必要的 fail-closed。建议把operation也纳入“证据充分”的判断。
case 'network':
return action.target?.trim()
? null
: 'Network review needs a concrete destination or query.';
|
@zqchris 👋 这个 PR 还有 1 条 review conversation 没 resolve(apps/desktop/src/main/maker-host/auto-permission-reviewer.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。 如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。 |
Signed-off-by: zqchris <chrisz83@gmail.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4b9c1c44c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
apps/desktop/src/main/maker-host/auto-permission-reviewer.ts:138
- 这里用
Promise.race实现 8s 超时只会让 reviewer 提前返回null,但不会取消正在进行的deps.requestText(...)。在 fallback reviewer 这种“失败必须尽快 fail-closed”的链路里,这会在超时后继续占用网络/上游并产生额外成本。建议用AbortController在超时触发时中止底层请求(并把signal透传给实现侧)。
const text = await Promise.race([
deps.requestText(request, buildAutoPermissionReviewPrompt(request)),
new Promise<typeof REVIEW_TIMEOUT>((resolve) => {
timeout = setTimeout(() => resolve(REVIEW_TIMEOUT), REVIEW_TIMEOUT_MS);
}),
Signed-off-by: zqchris <chrisz83@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (1)
packages/maker-core/src/agents/shared/auto-review-decision.ts:79
ReviewableAction的network新增了operation?字段,但missingReviewEvidence目前只检查target。这会导致仅填了operation(例如“search”/“GET”)但没有target的网络动作被当作“证据缺失”直接block,与类型设计不一致。建议把判定改为:target或operation任一非空即可视为有足够证据进入灰区审查。
case 'network':
return action.target?.trim()
? null
: 'Network review needs a concrete destination or query.';
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e2c9fa9613
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: zqchris <chrisz83@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (1)
packages/maker-core/src/agents/shared/auto-review-decision.ts:79
ReviewableAction的network动作现在包含operation?: string,但missingReviewEvidence()只检查target。这会导致即便提供了operation(符合错误文案里“destination or query”的表述)也会被当作证据不足直接 block,行为与类型/文案不一致。建议改为target或operation任一存在即可视为证据齐全(或相反:如果必须有 target,就把operation去掉/把文案改成只要求 target)。
case 'network':
return action.target?.trim()
? null
: 'Network review needs a concrete destination or query.';
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d6924fa942
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: zqchris <chrisz83@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (1)
packages/maker-core/src/agents/shared/auto-review-decision.ts:149
- resolveAutoReviewDecision 目前只校验 delegate 返回的 verdict 三态就直接透传 decision,但没有对 reason 做任何长度/类型约束;如果 delegate 直接回传模型原文(或被上游注入超长 reason),这里会把未受限的字符串继续向后传播,破坏“输出硬上限”的安全边界。建议在 core 层也做一次最小清洗:仅保留 verdict,并对 reason 做 trim + 截断(与 host 侧 240 上限对齐)。
|| decision?.verdict === 'ask'
)
) {
return decision;
}
MagicLizi
left a comment
There was a problem hiding this comment.
审查通过,零 P0/P1。fail-closed 设计与 anti-injection 措施到位。
|
fail-closed + Unicode 编码隔离不可信输入的设计,给后面想接入更多自动审查场景打了个好底子。timeout 全在 finally 里清也是该有的细节。 |
这次改了什么
摘要
增加 Auto-review 的轻量审查基础设施:统一
allow/block/ask决策协议,并提供可复用的“当前会话模型单次审查”委托器。输入仅包含当前意图、待执行动作与有限工作区信息,输出、耗时和上下文均有硬上限。本 PR 是两片改造中的第一片,只增加能力,不接入 Claude Code 或 Codex 的现有审批路径,因此单独合入不会改变用户行为。第二片负责原生优先、当前模型兜底和最少打扰策略,并在本 PR 合入前保持依赖分支 / draft,避免乱序合入。
变更类型
feat新功能fix缺陷修复refactor/perf重构或性能优化docs/test/chore文档、测试或工程维护范围
UI 变化
不涉及。
怎么验证的
自动验证
手工验证
使用两种当前会话模型做了最小上下文实机探针:普通 typecheck 动作为
allow,清理构建产物在意图对齐时为allow,向主分支强推为ask。同时验证了 OpenAI ChatGPT Codex 路由不发送其不支持的max_output_tokens参数,生产形状请求返回有效紧凑 JSON。未执行的验证
未在本机运行无界全仓
pnpm test:unit:该机器曾被全仓高并发测试卡死,本地按定向单 worker 验证,完整门禁交由 CI。风险
风险分类
影响与回滚
提交前检查
git commit -s,见 DCO)