Skip to content

refactor: unify runtime/security/todo/subagent paths#414

Merged
phantom5099 merged 18 commits into1024XEngineer:mainfrom
Cai-Tang-www:feat/git
Apr 23, 2026
Merged

refactor: unify runtime/security/todo/subagent paths#414
phantom5099 merged 18 commits into1024XEngineer:mainfrom
Cai-Tang-www:feat/git

Conversation

@Cai-Tang-www
Copy link
Copy Markdown
Collaborator

@Cai-Tang-www Cai-Tang-www commented Apr 22, 2026

变更摘要

本 PR 聚焦于 Runtime / Security / Todo / SubAgent 的重构收敛,保持主链路行为不变。

1) Security 策略收敛

  • bash_git_read_only 调整为默认 allow(只读 Git 语义放行)
  • 其他 Git 语义类别(remote/mutation/destructive/unknown)继续受控治理
  • 同步更新策略测试与工具集成文档

2) Todo / Session Legacy 清理

  • 移除 todo_write 的 legacy title -> content 兼容路径
  • legacy 入参改为显式迁移错误(要求使用 content
  • 移除 Session 中基于历史字段的 executor 推断逻辑,缺失 executor 统一落到 agent

3) Runtime / Config 强化

  • 新增 runtime.max_turns(默认 20),防止异常场景无限循环
  • max_no_progress_streak 默认值由 3 提升到 5
  • 移除 memo.max_index_lines 兼容映射,改为显式迁移提示到 memo.max_entries

4) SubAgent 调度器重构

  • 收敛 Todo patch 写回路径到统一入口
  • 统一 revision 冲突处理和错误包装语义
  • 降低状态写回分支重复,提高可维护性

提交拆分

  • dda052b refactor(security): allow git read-only semantic class by default
  • c034aec refactor(todo): remove legacy title/executor compatibility paths
  • fb38790 refactor(runtime): enforce max turns and tighten config defaults
  • 93d01bf refactor(subagent): centralize todo patch writeback handling

验证

  • go test ./...
  • go vet ./...

兼容性说明

  • 移除了部分 legacy 输入兼容路径,不再静默降级
  • 对旧输入返回结构化错误并提供迁移方向

fennoai[bot]

This comment was marked as outdated.

@Cai-Tang-www Cai-Tang-www changed the title refactor: runtime/security/todo cleanup and scheduler writeback unification refactor: unify runtime/security/todo/subagent paths Apr 22, 2026
@Cai-Tang-www
Copy link
Copy Markdown
Collaborator Author

/simplify 顺便解决CI冲突

该分支存在冲突,必须解决
可以干净地合并更改。

docs/tools-and-tui-integration.md
internal/runtime/session_mutation.go
internal/security/policy.go
internal/security/policy_test.go
internal/tools/permission_mapper.go
internal/tools/session_memory.go

@fennoai
Copy link
Copy Markdown

fennoai Bot commented Apr 22, 2026

处理结果

已处理该 PR 的冲突问题并推送到同一分支 feat/git

  • 同步 origin/main 到当前 PR 分支,生成合并提交:a75bcac
  • GitHub 冲突状态已从 CONFLICTING 变为 MERGEABLE
  • 你列出的冲突文件已随合并收敛:
    • docs/tools-and-tui-integration.md
    • internal/runtime/session_mutation.go
    • internal/security/policy.go
    • internal/security/policy_test.go
    • internal/tools/permission_mapper.go
    • internal/tools/session_memory.go

验证

已执行:go test ./...(通过)

未执行

  • 未额外改动业务逻辑(本次仅解决分支与 main 的合并冲突并验证)

View job run

@Cai-Tang-www
Copy link
Copy Markdown
Collaborator Author

@xgopilot 提高覆盖率到95%

@fennoai
Copy link
Copy Markdown

fennoai Bot commented Apr 23, 2026

已完成覆盖率补齐并推送到当前 PR 分支 feat/git(commit: 3877630)。

本次完成

  • 补充 internal/tools/result_status_test.go:覆盖 parseToolResultOK / parseToolResultExitCode / parseFloatExitCode 的完整分支与边界类型。
  • 补充 internal/subagent/scheduler_test.go:覆盖 updateTodoWithPatchapplyOutcomerecoverInterruptedTodosensureBlockedensureDependencyFailedensureReadyStatushandleTaskFailure 的错误与 changed=false 分支。
  • 补充 internal/tools/todo/common_test.go:覆盖 ensureNoLegacyTodoTitleField(nil)items 含非对象元素的分支。
  • 补充 internal/runtime/runtime_progress_test.go:新增 runtime.max_turns 触发停止分支验证。

验证结果

  • go test ./...
  • go test ./... -coverprofile=/tmp/cover.out
  • 本地按 patch 可执行语句行估算:98.29% (230/234),已超过 95% 目标。

说明

  • go vet ./... 仍有现存告警(internal/tui/services/gateway_rpc_client_additional_test.go 的 goroutine 中 t.Fatalf),与本次覆盖率补测改动无关,未在本次处理。

View job run

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: Cai-Tang-www <106404101+Cai-Tang-www@users.noreply.github.com>
@Cai-Tang-www
Copy link
Copy Markdown
Collaborator Author

Cai-Tang-www commented Apr 23, 2026

/simplify

@fennoai
Copy link
Copy Markdown

fennoai Bot commented Apr 23, 2026

完成情况

已按要求读取历史评论并处理仍未解决的 review comments,随后执行了 code-simplifier 子代理复查并完成提交推送。

本次修复

  • 修复 internal/subagent/scheduler.goupdateTodoWithPatch 在写回成功但无法读取最新快照时,返回 changed=false,避免基于过期对象触发后续状态迁移。
  • 修复 internal/security/policy.go:对 bash_git_read_only 增加敏感目标保护。
    • 敏感路径读取命中 ask-bash-git-read-only-sensitive(需审批)
    • 私钥材料读取命中 deny-bash-git-read-only-private-keys(拒绝)
    • 新增 git 只读命令中的敏感路径识别函数,覆盖 git show HEAD:.env / git show HEAD:.ssh/id_rsa 等场景。

测试与简化

  • 新增/调整测试:internal/security/policy_test.gointernal/subagent/scheduler_test.go
  • code-simplifier 结果:对 NewPolicyEngine 的规则排序实现做了等价简化(去掉中间结构,改为稳定排序函数),其余目标文件无需简化。
  • 已验证:go test ./internal/security ./internal/subagentgo test ./... 全部通过。

提交与推送

  • Commit: 5a9c20c
  • 已推送到当前 PR 分支:Cai-Tang-www:feat/git

View job run

- return changed=false when todo snapshot reload fails after patch write
- guard git read-only sensitive/private-key targets with ask/deny policy
- add regression tests for both paths

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: Cai-Tang-www <106404101+Cai-Tang-www@users.noreply.github.com>
@Cai-Tang-www
Copy link
Copy Markdown
Collaborator Author

@xgopilot 对这个Pr进行严格的审查,包括安全风险和其他不合理的地方等等,直接给出我结果

@phantom5099
Copy link
Copy Markdown
Collaborator

@xgopilot 采取合适的方案解决冲突,不要应急式补丁

@phantom5099
Copy link
Copy Markdown
Collaborator

@xgopilot 先解决冲突,同时上调DefaultMaxTurns至40

@fennoai
Copy link
Copy Markdown

fennoai Bot commented Apr 23, 2026

完成情况

已按你的要求完成两部分工作,并已推送到当前 PR 分支 Cai-Tang-www:feat/git

本次处理

  1. 解决冲突(非应急补丁,按根因收敛)
  • 修复 bash_semantic 的复合命令识别缺口:现在会识别 $() 命令替换并降级为 unknown,避免被误判为 git read_only 自动放行。
  • 修复高风险 Git 参数等价写法漏检:新增参数名归一化,覆盖 --config-env=...-ccore... 等形式,统一按高风险参数处理。
  • 同步补充/更新测试覆盖上述场景。
  1. 上调 DefaultMaxTurns
  • internal/config/runtime.goDefaultMaxTurns 已从 20 调整为 40
  • 同步更新配置文档 docs/guides/configuration.md 的示例与默认值描述。

验证

  • go test ./... 通过。

提交与推送

  • Commit: 5e5e83d
  • Push: HEAD -> feat/git

未执行项:未做与本次请求无关的额外重构。

View job run

xgopilot and others added 3 commits April 23, 2026 06:02
…default

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
# Conflicts:
#	docs/guides/configuration.md
#	internal/config/loader_test.go
#	internal/runtime/run.go
#	internal/session/sqlite_store_additional_test.go
#	internal/session/todo.go
#	internal/session/todo_test.go
@phantom5099
Copy link
Copy Markdown
Collaborator

@xgopilot 批判性review整个PR,分析所有潜在风险点,找出所有漏洞,确保每个地方的修改不是退步的,方案上的设计也不能碎片化,更不能妥协式兼容或兜底旧代码,不许输出正向表扬

@Cai-Tang-www
Copy link
Copy Markdown
Collaborator Author

@xgopilot 批判性review整个PR,分析所有潜在风险点,找出所有漏洞,确保每个地方的修改不是退步的,方案上的设计也不能碎片化,更不能妥协式兼容或兜底旧代码,不许输出正向表扬

@phantom5099
Copy link
Copy Markdown
Collaborator

/review

fennoai[bot]

This comment was marked as outdated.

@Cai-Tang-www
Copy link
Copy Markdown
Collaborator Author

/simplify

@fennoai
Copy link
Copy Markdown

fennoai Bot commented Apr 23, 2026

完成情况

已按触发评论执行:读取历史评论并处理未解决 review 点,然后调用 code-simplifier 做等价简化,最后完成提交与推送。

处理结果

  1. 已评估未解决 review comment(internal/security/policy.go:206)并修复。
  • 修复点:deny-bash-git-read-only-private-keys 去除 RequireSensitivePath 约束,避免 id_dsa / *.p12 / *.pfx 等私钥材料在 bash_git_read_only 被误放行。
  1. 已补充测试并验证。
  • 新增用例:git show HEAD:keys/id_dsagit show HEAD:certs/client.p12 均应命中 deny。
  • 运行:go test ./internal/securitygo test ./...,均通过。
  1. 已执行 code-simplifier 简化并保留行为不变。
  • internal/security/policy.go:合并重复归一化/匹配逻辑(泛型 helper + 共享包含判断 + git 只读路径分类收敛)。
  • internal/security/policy_test.go:提取统一断言 helper,消除重复校验代码。
  1. 已提交并推送。
  • Commit: d0d68c3
  • 已推送到当前 PR 分支:Cai-Tang-www:feat/git
  • 说明:同步产生了一个附加远端分支 fork-pr-414-1776909437(同一提交),PR 更新已在 feat/git 上生效。

未执行

  • 未处理触发评论之外的历史诉求(如额外审查范围扩展或非本次指令的重构)。

View job run

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: Cai-Tang-www <106404101+Cai-Tang-www@users.noreply.github.com>
@Cai-Tang-www
Copy link
Copy Markdown
Collaborator Author

/review

Copy link
Copy Markdown

@fennoai fennoai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed 4 review passes (code quality, performance, security, documentation) and deduplicated findings.

I found 1 noteworthy security issue in the changed code.

Comment thread internal/tools/bash/executor.go
@phantom5099 phantom5099 merged commit ea71014 into 1024XEngineer:main Apr 23, 2026
2 checks passed
@Cai-Tang-www Cai-Tang-www deleted the feat/git branch April 28, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants