实现 Issue #143: 在PR review comment 里执行Comment,要把所有的历史comments都给到AI #150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
改动摘要
根据Issue要求,在PR review comment场景中,现在会获取所有历史comments(包括PR body、一般评论、代码行评论、Review评论)作为上下文信息提供给AI,以提高代码质量。修改保持了当前Comment作为主要指令的核心地位,历史信息仅作为补充上下文。
具体改动
1. 添加新的数据模型
/workspace/pkg/models/workspace.go
PRAllComments
结构体,用于存储PR的所有评论信息:PRBody
: PR描述IssueComments
: 一般PR评论ReviewComments
: 代码行评论Reviews
: Review评论2. 扩展GitHub客户端功能
/workspace/internal/github/client.go
GetAllPRComments
方法,用于获取PR的所有评论历史:3. 增强AI Agent处理逻辑
/workspace/internal/agent/agent.go
formatHistoricalComments
方法,用于格式化历史评论作为上下文ContinuePRWithArgs
方法,增加历史上下文获取和智能prompt构建FixPRWithArgs
方法,增加历史上下文获取和智能prompt构建4. 智能Prompt构建策略
5. 错误处理和兼容性
这些改动确保了PR review comment场景下AI能够获得完整的背景信息,从而提供更高质量的代码建议和修改,同时保持了当前指令的核心地位。
AI 完整输出
Perfect! The implementation is complete and the code compiles successfully. Let me provide a summary of the changes:
改动摘要
根据Issue要求,在PR review comment场景中,现在会获取所有历史comments(包括PR body、一般评论、代码行评论、Review评论)作为上下文信息提供给AI,以提高代码质量。修改保持了当前Comment作为主要指令的核心地位,历史信息仅作为补充上下文。
具体改动
1. 添加新的数据模型
/workspace/pkg/models/workspace.go
PRAllComments
结构体,用于存储PR的所有评论信息:PRBody
: PR描述IssueComments
: 一般PR评论ReviewComments
: 代码行评论Reviews
: Review评论2. 扩展GitHub客户端功能
/workspace/internal/github/client.go
GetAllPRComments
方法,用于获取PR的所有评论历史:3. 增强AI Agent处理逻辑
/workspace/internal/agent/agent.go
formatHistoricalComments
方法,用于格式化历史评论作为上下文ContinuePRWithArgs
方法,增加历史上下文获取和智能prompt构建FixPRWithArgs
方法,增加历史上下文获取和智能prompt构建4. 智能Prompt构建策略
5. 错误处理和兼容性
这些改动确保了PR review comment场景下AI能够获得完整的背景信息,从而提供更高质量的代码建议和修改,同时保持了当前指令的核心地位。
原始 Prompt
根据Issue修改代码:
标题:在PR review comment 里执行Comment,要把所有的历史comments都给到AI
描述:PR review场景一般有两种交互姿势,一种是基于代码行精准评价,而第二种就是reviewer会直接在PR的Comment里反馈,且这两种场景对应的github event类型也是不同的。
在第二种场景,目前codeagent仅仅从事件的body里拿到内容,实际上给到AI的上下文信息不全,导致代码质量不高。因为一般reviewer在PR 里comments时,默认是知道所有PR内容以及相关讨论的,有相关的背景。
所以在这个场景,我们应该把所有的有效内容都给到AI,包括PR的body,其他comments,以及当前事件的comment。当然,这里要注意,其他的comments仅仅是作为上下文信息补充,核心的要面对的指令,仍然是当前的Comment。所以这里的prompt构建要有一定的针对性。
输出格式:
改动摘要
简要说明改动内容
具体改动