feat: 添加文件差异对比工具及测试文件

- 新增 test_diff_tool.go 实现文件差异对比功能
- 添加测试文件 test_file_a.txt、test_file_b.txt 和 test_file_whitespace.txt
- 删除旧的 .picoclaw.pid 文件
- 更新 logs/gateway.log 日志文件
This commit is contained in:
keep 2026-04-18 02:02:23 +08:00
parent ec700f4a50
commit f3fd95da86
6 changed files with 131 additions and 7 deletions

View file

@ -1,7 +0,0 @@
{
"pid": 7160,
"token": "ca0cf39c3f6188acfa724839d8382f1a",
"version": "dev",
"port": 18790,
"host": "localhost"
}

View file

@ -115,3 +115,12 @@
{"level":"debug","component":"heartbeat","time":"2026-04-18T01:43:43+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/heartbeat/service.go:163","message":"Executing heartbeat"} {"level":"debug","component":"heartbeat","time":"2026-04-18T01:43:43+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/heartbeat/service.go:163","message":"Executing heartbeat"}
{"level":"info","component":"heartbeat","time":"2026-04-18T01:43:43+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/heartbeat/service.go:167","message":"No heartbeat prompt (HEARTBEAT.md empty or missing)"} {"level":"info","component":"heartbeat","time":"2026-04-18T01:43:43+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/heartbeat/service.go:167","message":"No heartbeat prompt (HEARTBEAT.md empty or missing)"}
{"level":"error","component":"gateway","config_path":"d:\\Desktop\\一面千石\\picoclaw\\config.json","error":"error opening gateway listeners: failed to open adaptive localhost listener on port 18790","home_path":"d:\\Desktop\\一面千石\\picoclaw","allow_empty":false,"debug":true,"time":"2026-04-18T01:44:16+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/gateway/gateway.go:137","message":"Gateway startup failed"} {"level":"error","component":"gateway","config_path":"d:\\Desktop\\一面千石\\picoclaw\\config.json","error":"error opening gateway listeners: failed to open adaptive localhost listener on port 18790","home_path":"d:\\Desktop\\一面千石\\picoclaw","allow_empty":false,"debug":true,"time":"2026-04-18T01:44:16+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/gateway/gateway.go:137","message":"Gateway startup failed"}
{"level":"info","component":"gateway","time":"2026-04-18T01:49:32+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/gateway/gateway.go:265","message":"Shutting down..."}
{"level":"info","component":"channels","time":"2026-04-18T01:49:32+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/channels/manager.go:672","message":"Stopping all channels"}
{"level":"info","component":"channels","time":"2026-04-18T01:49:32+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/channels/manager.go:729","message":"All channels stopped"}
{"level":"info","component":"channels","time":"2026-04-18T01:49:32+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/channels/manager.go:889","message":"Outbound media dispatcher stopped"}
{"level":"info","component":"channels","time":"2026-04-18T01:49:32+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/channels/manager.go:889","message":"Outbound dispatcher stopped"}
{"level":"info","component":"devices","time":"2026-04-18T01:49:32+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/devices/service.go:96","message":"Device event service stopped"}
{"level":"info","component":"heartbeat","time":"2026-04-18T01:49:32+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/heartbeat/service.go:116","message":"Stopping heartbeat service"}
{"level":"info","component":"gateway","time":"2026-04-18T01:49:32+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/gateway/gateway.go:509","message":"✓ Gateway stopped"}
{"level":"info","component":"pid","time":"2026-04-18T01:49:32+08:00","caller":"D:/Desktop/一面千石/picoclaw/pkg/pid/pidfile.go:150","message":"remove pid file: d:\\Desktop\\一面千石\\picoclaw\\.picoclaw.pid"}

84
test_diff_tool.go Normal file
View file

@ -0,0 +1,84 @@
package main
import (
"context"
"fmt"
"os"
"github.com/sipeed/picoclaw/pkg/tools"
)
func main() {
workspace, _ := os.Getwd()
maxReadFileSize := 64 * 1024
fmt.Println("=== 测试 diff_files 工具 ===\n")
tool := tools.NewDiffTool(workspace, false, maxReadFileSize)
fmt.Printf("工具名称: %s\n", tool.Name())
fmt.Printf("工具描述: %s\n", tool.Description())
fmt.Println()
testUnifiedDiff(tool)
testSideBySideDiff(tool)
testIgnoreWhitespace(tool)
fmt.Println("\n=== 测试完成 ===")
}
func testUnifiedDiff(tool *tools.DiffTool) {
fmt.Println("--- 测试 1: 统一差异格式 (unified diff) ---")
fmt.Println()
args := map[string]any{
"file_a": "test_file_a.txt",
"file_b": "test_file_b.txt",
"format": "unified",
"context_lines": 3,
}
result := tool.Execute(context.Background(), args)
fmt.Println("结果:")
fmt.Println(result.ForLLM)
fmt.Println()
}
func testSideBySideDiff(tool *tools.DiffTool) {
fmt.Println("--- 测试 2: 并排对比格式 (side_by_side) ---")
fmt.Println()
args := map[string]any{
"file_a": "test_file_a.txt",
"file_b": "test_file_b.txt",
"format": "side_by_side",
}
result := tool.Execute(context.Background(), args)
fmt.Println("结果:")
fmt.Println(result.ForLLM)
fmt.Println()
}
func testIgnoreWhitespace(tool *tools.DiffTool) {
fmt.Println("--- 测试 3: 忽略空白字符差异 (ignore_whitespace) ---")
fmt.Println()
args := map[string]any{
"file_a": "test_file_a.txt",
"file_b": "test_file_whitespace.txt",
"format": "unified",
"ignore_whitespace": false,
}
fmt.Println("不忽略空白差异:")
result1 := tool.Execute(context.Background(), args)
fmt.Println(result1.ForLLM)
fmt.Println()
args["ignore_whitespace"] = true
fmt.Println("忽略空白差异:")
result2 := tool.Execute(context.Background(), args)
fmt.Println(result2.ForLLM)
fmt.Println()
}

11
test_file_a.txt Normal file
View file

@ -0,0 +1,11 @@
# 示例文件 A - 原始版本
这是一个用于测试文件差异对比功能的示例文件。
## 功能列表
- 支持统一差异格式
- 支持并排对比格式
- 支持忽略空白字符差异
## 注意事项
请确保文件编码为 UTF-8。
大文件可能需要较长时间处理。

16
test_file_b.txt Normal file
View file

@ -0,0 +1,16 @@
# 示例文件 B - 修改版本
这是一个用于测试文件差异对比功能的示例文件。
新增的一行内容。
## 功能列表
- 支持统一差异格式
- 支持并排对比格式
- 支持忽略空白字符差异
- 新增:支持彩色输出(新增功能)
## 注意事项
请确保文件编码为 UTF-8。
大文件可能需要较长时间处理。
## 更新日志
- 2026-04-18: 新增功能说明

11
test_file_whitespace.txt Normal file
View file

@ -0,0 +1,11 @@
# 示例文件 A - 原始版本
这是一个用于测试文件差异对比功能的示例文件。
## 功能列表
- 支持统一差异格式
- 支持并排对比格式
- 支持忽略空白字符差异
## 注意事项
请确保文件编码为 UTF-8。
大文件可能需要较长时间处理。