OverwriteWithNote 使用单个 Note 覆盖整个记忆文件 与 AppendNote 不同,该方法会丢弃原有内容,仅保留新的标题与正文
(ctx context.Context, file, title, content string)
| 143 | // OverwriteWithNote 使用单个 Note 覆盖整个记忆文件 |
| 144 | // 与 AppendNote 不同,该方法会丢弃原有内容,仅保留新的标题与正文 |
| 145 | func (m *Manager) OverwriteWithNote(ctx context.Context, file, title, content string) (string, error) { |
| 146 | if file == "" { |
| 147 | return "", errors.New("memory.OverwriteWithNote: file cannot be empty") |
| 148 | } |
| 149 | if strings.TrimSpace(content) == "" { |
| 150 | return "", errors.New("memory.OverwriteWithNote: content cannot be empty") |
| 151 | } |
| 152 | |
| 153 | path := m.resolvePath(file) |
| 154 | |
| 155 | noteTitle := strings.TrimSpace(title) |
| 156 | if noteTitle == "" { |
| 157 | noteTitle = time.Now().Format("2006-01-02 15:04:05") |
| 158 | } |
| 159 | |
| 160 | section := fmt.Sprintf("## %s\n\n%s\n", noteTitle, strings.TrimSpace(content)) |
| 161 | |
| 162 | if _, err := m.backend.Write(ctx, path, section); err != nil { |
| 163 | return "", fmt.Errorf("memory.OverwriteWithNote: write content failed: %w", err) |
| 164 | } |
| 165 | |
| 166 | return path, nil |
| 167 | } |
| 168 | |
| 169 | // Search 在 memoryPath 下执行全文搜索 |
| 170 | // 默认使用大小写不敏感的字面量匹配,可选正则模式 |
no test coverage detected