新增 internal/repository,并在 runtime -> context 主链中条件化接入仓库上下文#430
新增 internal/repository,并在 runtime -> context 主链中条件化接入仓库上下文#430phantom5099 merged 18 commits into1024XEngineer:mainfrom
internal/repository,并在 runtime -> context 主链中条件化接入仓库上下文#430Conversation
|
@xgopilot 修复报错--- FAIL: TestRetrieveRejectsPathEscapeAndSymlinkEscape (0.00s) |
修复结果已修复 变更:
测试结果已执行并通过:
提交与推送
未完成项:
|
…olution Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
fix(security): reject backslash traversal in workspace path resolution
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
/code 提高测试覆盖率至100% |
结果已完成一轮覆盖率提升并推送到当前工作分支。
已完成改动
验证结果
关键包最新覆盖率:
未完成项
|
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
test: improve coverage for repository context branches
|
/simplify |
完成情况已按触发评论执行:先检查并评估未解决 review 评论,修复值得修复项,再调用 已修复问题
简化结果(code-simplifier)
测试已通过:
提交与推送
未完成项:无。 |
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
fix(repository): cancel-aware walk and safer retrieval filters
|
@xgopilot 批判性review整个PR,分析所有潜在风险点,找出所有漏洞,确保每个地方的修改不是退步的,方案上的设计也不能碎片化,更不能妥协式兼容或兜底旧代码,不许输出正向表扬 |
|
/review 做一轮审查性review |
|
@xgopilot 批判性review整个PR,分析所有潜在风险点,找出所有漏洞,确保每个地方的修改不是退步的,方案上的设计也不能碎片化,更不能妥协式兼容或兜底旧代码,不许输出正向表扬 |
|
@xgopilot 批判性review整个PR,分析所有潜在风险点,找出所有漏洞,确保每个地方的修改不是退步的,方案上的设计也不能碎片化,更不能妥协式兼容或兜底旧代码,不许输出正向表扬 |
|
@xgopilot --- FAIL: TestResolveWorkspaceWalkPathFromRootUnknownTypeStillChecksSymlinkEscape (0.00s) |
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
fix(security): keep symlink escape checks for unknown walk entries
|
@xgopilot 批判性review整个PR,分析所有潜在风险点,找出所有漏洞,确保每个地方的修改不是退步的,方案上的设计也不能碎片化,更不能妥协式兼容或兜底旧代码,不许输出正向表扬 |
|
@xgopilot 批判性review整个PR,分析所有潜在风险点,找出所有漏洞,确保每个地方的修改不是退步的,方案上的设计 |
|
/code 修复错误:--- FAIL: TestRetrieveRejectsPathEscapeAndSymlinkEscape (0.00s) |
|
已修复触发评论中的两个失败用例,根因是 traversal 检测仅识别 变更
验证
提交与推送
未做项:未执行全量 |
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
|
/review |
| @@ -0,0 +1,66 @@ | |||
| # Repository 模块设计 | |||
Summary
本次改动新增了专门的
internal/repository模块,作为仓库级事实的统一落点,并在runtime -> context主链中接入一条受控、按需的 repository context 注入路径。当前实现统一提供:
Summary()ChangedFiles()Retrieve()这次落地的是一个轻量事实层,不是代码智能平台。本次不会引入 LSP、向量检索、预索引,也不会把 repository 暴露成模型直接调用的工具。
背景问题
此前项目中的仓库感知能力比较分散:
internal/context/source_system.go只内置了一小段 git 状态解析这带来了几个具体问题:
git/ 文件检索逻辑,缺少统一抽象。context很容易继续膨胀成“发现事实 + 决定注入 + 渲染 prompt”的混合层。主要改动
1. 新增
internal/repository新增统一的仓库事实服务:
Summary(ctx, workdir)ChangedFiles(ctx, workdir, opts)Retrieve(ctx, workdir, query)核心特性:
Truncatedsymbol检索采用 Go-first 的轻量实现2. 将 git summary 责任从
context中迁出internal/context/source_system.go不再直接执行和解析git status。现在改为:
context消费repository.SummarySystem State仍由context负责渲染3. 为
context增加 repository prompt sectioncontext.BuildInput新增了 repository 投影字段,context在 runtime 显式传入数据时,会渲染独立的Repository Contextsection。这个 section 目前可承载:
但
context本身不决定是否拉取这些事实。4. 在 runtime 中新增条件化 repository context 决策
runtime现在会在构建当前轮上下文之前,判断是否值得注入 repository context。当前策略:
ChangedFilesRetrievepath > symbol > text这样可以保证 repository context 只在高相关场景下注入,避免默认膨胀 prompt。
5. 复用现有 workspace 安全语义
新增
internal/security/workspace_paths.go,让 repository 的路径解析直接复用现有 workspace containment 和 symlink escape 语义,而不是自己维护第二套边界规则。6. 更新文档
README.md增加internal/repository说明docs/repository-design.md补充模块职责、边界、上限与非目标收益
开发侧收益
git和检索逻辑散落在多个模块中。repository负责发现事实runtime负责决定何时使用事实context负责渲染事实context或别的层。用户侧收益
设计约束
本次实现明确避免了几个问题:
internal/repository后继续保留零散 repo 解析旁路security之外再维护第二套 workspace 路径边界语义测试验证
已通过:
go test ./internal/runtime/... ./internal/context/... ./internal/repository/... ./internal/security/...同时也检查了:
go test ./...当前全量测试状态:
internal/config/atomic_write_test.gofsync时的Access is denied风险
主要风险:
本次的控制方式:
internal/security的共享语义后续建议
后续值得继续推进的方向:
repositorycontext的被动消费角色,不把 repository 取数逻辑再塞回去