Neue Tabelle mission_control_sessions (Migration AddMissionControlSessions), befuellt vom InteractiveLaunchSpecService bei Task-, Ad-hoc- und Handoff-Kacheln. Flyout im Mission-Control-Header listet die letzten 14 Tage / 50 Sessions, Handoffs eingerueckt unter ihrer Ursprungs-Session, mit Fortsetzen (--resume im gespeicherten cwd) und Brief anzeigen.
35 lines
1.6 KiB
C#
35 lines
1.6 KiB
C#
using ClaudeDo.Data.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace ClaudeDo.Data.Repositories;
|
|
|
|
/// <summary>Reads and writes <c>mission_control_sessions</c>.</summary>
|
|
public sealed class MissionControlSessionRepository
|
|
{
|
|
private readonly ClaudeDoDbContext _context;
|
|
|
|
public MissionControlSessionRepository(ClaudeDoDbContext context) => _context = context;
|
|
|
|
/// <summary>Inserts the session unless it is already recorded — a resumed task session keeps
|
|
/// its original row and start time.</summary>
|
|
public async Task RecordAsync(MissionControlSessionEntity session, CancellationToken ct = default)
|
|
{
|
|
if (await _context.MissionControlSessions.AnyAsync(s => s.SessionId == session.SessionId, ct)) return;
|
|
_context.MissionControlSessions.Add(session);
|
|
await _context.SaveChangesAsync(ct);
|
|
}
|
|
|
|
/// <summary>The recorded session, or null.</summary>
|
|
public async Task<MissionControlSessionEntity?> GetAsync(string sessionId, CancellationToken ct = default) =>
|
|
await _context.MissionControlSessions.AsNoTracking().FirstOrDefaultAsync(s => s.SessionId == sessionId, ct);
|
|
|
|
/// <summary>Sessions started since <paramref name="sinceUtc"/>, newest first, at most <paramref name="max"/>.</summary>
|
|
public async Task<IReadOnlyList<MissionControlSessionEntity>> ListRecentAsync(
|
|
DateTime sinceUtc, int max, CancellationToken ct = default) =>
|
|
await _context.MissionControlSessions.AsNoTracking()
|
|
.Where(s => s.StartedAt >= sinceUtc)
|
|
.OrderByDescending(s => s.StartedAt)
|
|
.Take(max)
|
|
.ToListAsync(ct);
|
|
}
|