createBackup 创建文件备份
(ctx context.Context, filePath, content string, tc *tools.ToolContext)
| 224 | |
| 225 | // createBackup 创建文件备份 |
| 226 | func (t *WriteTool) createBackup(ctx context.Context, filePath, content string, tc *tools.ToolContext) string { |
| 227 | timestamp := time.Now().Format("20060102_150405") |
| 228 | ext := filepath.Ext(filePath) |
| 229 | base := strings.TrimSuffix(filePath, ext) |
| 230 | backupPath := fmt.Sprintf("%s.backup_%s%s", base, timestamp, ext) |
| 231 | |
| 232 | err := tc.Sandbox.FS().Write(ctx, backupPath, content) |
| 233 | if err != nil { |
| 234 | return "" |
| 235 | } |
| 236 | |
| 237 | return backupPath |
| 238 | } |
| 239 | |
| 240 | func (t *WriteTool) Prompt() string { |
| 241 | return `向本地文件系统写入文件内容。 |