(ctx context.Context, commitNo, limit int)
| 510 | return err |
| 511 | } |
| 512 | for _, id := range ids { |
| 513 | if _, err := tx.ExecContext(ctx, `INSERT OR IGNORE INTO commit_messages(commit_id, message_id) VALUES(?, ?)`, commitID, id); err != nil { |
| 514 | return err |
| 515 | } |
| 516 | } |
| 517 | if ftsAvailable { |
| 518 | _, _ = tx.ExecContext(ctx, `INSERT INTO commit_fts(commit_id, title, summary, tags) VALUES(?, ?, ?, ?)`, commitID, title, summary, strings.Join(tags, " ")) |
| 519 | } |
| 520 | if _, err := tx.ExecContext(ctx, `INSERT OR REPLACE INTO schema_meta(key, value) VALUES('last_committed_user_turn', ?)`, fmt.Sprint(endTurn)); err != nil { |
| 521 | return err |
| 522 | } |
| 523 | if _, err := tx.ExecContext(ctx, `INSERT OR REPLACE INTO schema_meta(key, value) VALUES('next_commit_no', ?)`, fmt.Sprint(commitNo+1)); err != nil { |
| 524 | return err |
| 525 | } |
| 526 | return tx.Commit() |
| 527 | } |
| 528 | |
| 529 | func (s *Store) summarize(ctx context.Context, startTurn, endTurn int, previews []string) (string, string, []string, error) { |
| 530 | joined := strings.Join(previews, "\n") |
| 531 | system := "You summarize a coding-agent conversation segment. Return concise JSON only with keys: title, summary, tags. The summary must preserve user goals, decisions, files, tool findings, errors, and next steps. Do not invent facts." |
| 532 | user := fmt.Sprintf("Summarize session turns %d-%d. This is one commit covering the whole interval, not separate summaries per turn.\n\n%s", startTurn, endTurn, joined) |
| 533 | complete := s.complete |
| 534 | if complete == nil { |
| 535 | client, err := llmclient.Create(s.cfg, s.summaryModel(), s.cfg.SessionMemorySummaryMaxTokens, nil, api.DefaultRetryConfigPtr()) |
| 536 | if err != nil { |
| 537 | return "", "", nil, err |
| 538 | } |
| 539 | complete = func(ctx context.Context, systemPrompt string, messages []map[string]any, maxTokens int) (string, error) { |
| 540 | streamCtx := api.ContextWithStreamIdleTimeout(ctx, |
| 541 | time.Duration(s.cfg.APIStreamIdleTimeoutSeconds*float64(time.Second))) |
| 542 | return client.Complete(streamCtx, systemPrompt, messages, api.CompleteOptions{MaxTokens: maxTokens}) |
| 543 | } |
no test coverage detected