|
8 | 8 | "os" |
9 | 9 | "path/filepath" |
10 | 10 | "rapide/internal/model" |
| 11 | + "sort" |
11 | 12 | "time" |
12 | 13 | ) |
13 | 14 |
|
@@ -303,6 +304,56 @@ func (s *Storage) TrimBefore(cutoff time.Time) (int, error) { |
303 | 304 | return count, s.saveAll(toKeep) |
304 | 305 | } |
305 | 306 |
|
| 307 | +func (s *Storage) GetUniqueMarginKeys() ([]string, error) { |
| 308 | + entries, err := s.List() |
| 309 | + if err != nil { |
| 310 | + return nil, err |
| 311 | + } |
| 312 | + |
| 313 | + keysMap := make(map[string]struct{}) |
| 314 | + for _, e := range entries { |
| 315 | + if e.MarginKey != "" { |
| 316 | + keysMap[e.MarginKey] = struct{}{} |
| 317 | + } |
| 318 | + } |
| 319 | + |
| 320 | + keys := make([]string, 0, len(keysMap)) |
| 321 | + for k := range keysMap { |
| 322 | + keys = append(keys, k) |
| 323 | + } |
| 324 | + return keys, nil |
| 325 | +} |
| 326 | + |
| 327 | +func (s *Storage) GetRecentIDs() ([]string, error) { |
| 328 | + entries, err := s.List() |
| 329 | + if err != nil { |
| 330 | + return nil, err |
| 331 | + } |
| 332 | + |
| 333 | + // Only return IDs for relevant items (maybe last 50?) |
| 334 | + // Sort by timestamp desc |
| 335 | + sort.Slice(entries, func(i, j int) bool { |
| 336 | + return entries[i].Timestamp.After(entries[j].Timestamp) |
| 337 | + }) |
| 338 | + |
| 339 | + limit := 50 |
| 340 | + if len(entries) < limit { |
| 341 | + limit = len(entries) |
| 342 | + } |
| 343 | + |
| 344 | + ids := make([]string, 0, limit) |
| 345 | + for i := 0; i < limit; i++ { |
| 346 | + // Include content snippet in completion description if possible |
| 347 | + // Cobra supports "id\tDescription" format |
| 348 | + snippet := entries[i].Content |
| 349 | + if len(snippet) > 30 { |
| 350 | + snippet = snippet[:27] + "..." |
| 351 | + } |
| 352 | + ids = append(ids, fmt.Sprintf("%s\t%s %s", entries[i].ID, entries[i].Bullet, snippet)) |
| 353 | + } |
| 354 | + return ids, nil |
| 355 | +} |
| 356 | + |
306 | 357 | func generateID(e model.Entry) string { |
307 | 358 | h := sha1.New() |
308 | 359 | h.Write([]byte(fmt.Sprintf("%d%s%s", e.Timestamp.UnixNano(), e.Bullet, e.Content))) |
|
0 commit comments