Skip to content
Open
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
8 changes: 1 addition & 7 deletions internal/core/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (a *Agent) runTurn(ctx context.Context, session *Session, userInput string,

response, err := a.client.Complete(ctx, provider.Request{
Model: a.config.Model,
Messages: cloneMessages(session.Messages),
Messages: session.Messages,
Tools: a.registry.Definitions(),
MaxTokens: a.config.MaxTokens,
Temperature: a.config.Temperature,
Expand Down Expand Up @@ -202,12 +202,6 @@ func (a *Agent) runTurn(ctx context.Context, session *Session, userInput string,
return result, fmt.Errorf("agent exceeded max steps (%d)", a.config.MaxSteps)
}

func cloneMessages(messages []provider.Message) []provider.Message {
cloned := make([]provider.Message, len(messages))
copy(cloned, messages)
return cloned
}

func stringifyArguments(arguments json.RawMessage) string {
if len(arguments) == 0 {
return "{}"
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/anthropic.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (c *AnthropicClient) Complete(ctx context.Context, req Request) (Response,
}

var textParts []string
toolCalls := make([]ToolCall, 0)
var toolCalls []ToolCall
for _, block := range response.Content {
switch block.Type {
case "text":
Expand Down Expand Up @@ -124,7 +124,7 @@ type anthropicResponse struct {
}

func toAnthropicMessages(messages []Message) (string, []map[string]any, error) {
systemParts := make([]string, 0)
var systemParts []string
converted := make([]map[string]any, 0, len(messages))

for _, message := range messages {
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/gemini.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (c *GeminiClient) Complete(ctx context.Context, req Request) (Response, err
}

parts := response.Candidates[0].Content.Parts
textParts := make([]string, 0)
toolCalls := make([]ToolCall, 0)
var textParts []string
var toolCalls []ToolCall
for index, part := range parts {
if part.Text != "" {
textParts = append(textParts, part.Text)
Expand Down Expand Up @@ -140,7 +140,7 @@ type geminiResponse struct {
}

func toGeminiMessages(messages []Message) (string, []map[string]any, error) {
systemParts := make([]string, 0)
var systemParts []string
converted := make([]map[string]any, 0, len(messages))

for _, message := range messages {
Expand Down
9 changes: 2 additions & 7 deletions internal/tools/edit_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,11 @@ func (t *EditTool) edit(target, oldContent, newContent string, all bool) (Result
return Result{}, fmt.Errorf("write file %q: %w", target, err)
}

replacedCount := count
if !all {
replacedCount = 1
}

return Result{
Output: fmt.Sprintf("replaced %d occurrence(s) in %s", replacedCount, target),
Output: fmt.Sprintf("replaced %d occurrence(s) in %s", count, target),
Metadata: map[string]any{
"path": target,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

删除 replacedCount 后,replaced_counttotal_found 现在始终相同(均为 count)。

今日行为正确——第 94 行守卫保证 !allcount == 1。但若未来允许「有多个匹配时仅替换第一个」,replaced_count 将报告错误值(实际替换 1 次,却显示全部匹配数)。建议保留 replacedCount 以区分两字段的语义,或明确删除其中一个以消除歧义。

"replaced_count": replacedCount,
"replaced_count": count,
"total_found": count,
"all": all,
},
Expand Down
7 changes: 2 additions & 5 deletions internal/tools/write_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type writeArgs struct {
Path string `json:"path"`
Content string `json:"content"`
Append bool `json:"append,omitempty"`
Create bool `json:"create,omitempty"`

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Create bool 已从 writeArgs 移除,但 Definition() 的 schema 仍声明了 create 参数,而运行时通过 invocation.ParsedArgs["create"] 读取。两条路径目前均指向同一 JSON 原始数据,功能正常。

维护风险:当前结构体与 schema/运行时的不一致意味着,按照「参数应在 writeArgs 中」惯例做重构时,create=false 会被静默忽略,导致 os.O_CREATE flag 逻辑出错。建议将 Create bool 重新加回结构体并从 args.Create 读取,保持单一数据路径。

}

func NewWriteTool(root string) *WriteTool {
Expand Down Expand Up @@ -73,10 +72,8 @@ func (t *WriteTool) Execute(_ context.Context, invocation Invocation) (Result, e
}

create := true
if invocation.ParsedArgs != nil {
if v, ok := invocation.ParsedArgs["create"].(bool); ok {
create = v
}
if v, ok := invocation.ParsedArgs["create"].(bool); ok {
create = v
}

return t.write(target, args.Content, args.Append, create)
Expand Down