feat(prime): carry the action kind through the hub and validate custom prompts

This commit is contained in:
mika kuns
2026-08-25 08:51:37 +02:00
parent cf6a6b6208
commit 4e8e0334b2
4 changed files with 62 additions and 4 deletions
+9 -3
View File
@@ -1033,11 +1033,14 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
using var ctx = _dbFactory.CreateDbContext();
var rows = await new PrimeScheduleRepository(ctx).ListAsync();
return rows.Select(e => new PrimeScheduleDto(
e.Id, (int)e.Days, e.TimeOfDay, e.Enabled, e.LastRunAt, e.PromptOverride)).ToList();
e.Id, (int)e.Days, e.TimeOfDay, e.Enabled, e.LastRunAt, e.PromptOverride, e.Kind)).ToList();
}
public async Task<PrimeScheduleDto> UpsertPrimeSchedule(PrimeScheduleDto dto)
{
var error = PrimeScheduleValidation.Validate(dto);
if (error is not null) throw new HubException(error);
using var ctx = _dbFactory.CreateDbContext();
var repo = new PrimeScheduleRepository(ctx);
var existing = await repo.GetAsync(dto.Id);
@@ -1048,13 +1051,14 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
TimeOfDay = dto.TimeOfDay,
Enabled = dto.Enabled,
PromptOverride = dto.PromptOverride,
Kind = dto.Kind,
CreatedAt = existing?.CreatedAt ?? DateTimeOffset.UtcNow,
LastRunAt = existing?.LastRunAt,
};
await repo.UpsertAsync(entity);
_primeSignal.Signal();
return new PrimeScheduleDto(entity.Id, (int)entity.Days, entity.TimeOfDay,
entity.Enabled, entity.LastRunAt, entity.PromptOverride);
entity.Enabled, entity.LastRunAt, entity.PromptOverride, entity.Kind);
}
public async Task DeletePrimeSchedule(Guid id)
@@ -1072,7 +1076,9 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
public async Task<bool> RunDailyPrepNow()
{
var schedule = new PrimeScheduleDto(Guid.Empty, 0, TimeSpan.Zero, true, null, null);
var schedule = new PrimeScheduleDto(
Guid.Empty, 0, TimeSpan.Zero, true, null, null,
ClaudeDo.Data.Models.PrimeActionKind.FillMyDay);
var firedAt = DateTimeOffset.Now;
var outcome = await _primeRunner.FireAsync(schedule, Context.ConnectionAborted);
await _broadcaster.PrimeFired(Guid.Empty, outcome.Success, outcome.Message, firedAt);
@@ -0,0 +1,14 @@
using ClaudeDo.Data.Models;
namespace ClaudeDo.Worker.Prime;
public static class PrimeScheduleValidation
{
/// <summary>Returns an error message, or null when the schedule is safe to persist.</summary>
public static string? Validate(PrimeScheduleDto dto)
{
if (dto.Kind == PrimeActionKind.Custom && string.IsNullOrWhiteSpace(dto.PromptOverride))
return "A custom Prime schedule needs a prompt.";
return null;
}
}