feat(worker): add claude-cli runner, queue service, and hub api
Runner stack (non-worktree path): IClaudeProcess + ClaudeProcess spawning the CLI with --output-format stream-json, prompt via stdin, parses the final type:"result" line into RunResult. LogWriter appends ndjson to ~/.todo-app/logs/<taskId>.ndjson. TaskRunner orchestrates DB transitions (MarkRunning -> MarkDone/Failed) and pushes TaskStarted/Message/Finished/ Updated via HubBroadcaster. Worktree-backed lists short-circuit with a "Slice E" failure message until git support lands. QueueService (BackgroundService) holds two in-memory slots (_queueSlot + _overrideSlot) guarded by a lock. Uses PeriodicTimer + SemaphoreSlim wake signal so WakeQueue() triggers an instant pickup. RunNow throws InvalidOperationException when override busy; CancelTask cancels the linked CTS which kills the child process tree. WorkerHub extended with GetActive, RunNow (translated to HubException variants), CancelTask, WakeQueue. HubBroadcaster exposes typed push methods. Tests: 26 pass (12 new). QueueServiceTests cover override-busy, schedule-filter, FIFO sequentiality, cancellation, plus a FakeClaudeProcess that blocks on a TCS for deterministic slot-state assertions. MessageParserTests cover result extraction + malformed/non-result lines. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
25
src/ClaudeDo.Worker/Hub/HubBroadcaster.cs
Normal file
25
src/ClaudeDo.Worker/Hub/HubBroadcaster.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace ClaudeDo.Worker.Hub;
|
||||
|
||||
public sealed class HubBroadcaster
|
||||
{
|
||||
private readonly IHubContext<WorkerHub> _hub;
|
||||
|
||||
public HubBroadcaster(IHubContext<WorkerHub> hub) => _hub = hub;
|
||||
|
||||
public Task TaskStarted(string slot, string taskId, DateTime startedAt) =>
|
||||
_hub.Clients.All.SendAsync("TaskStarted", slot, taskId, startedAt);
|
||||
|
||||
public Task TaskFinished(string slot, string taskId, string status, DateTime finishedAt) =>
|
||||
_hub.Clients.All.SendAsync("TaskFinished", slot, taskId, status, finishedAt);
|
||||
|
||||
public Task TaskMessage(string taskId, string ndjsonLine) =>
|
||||
_hub.Clients.All.SendAsync("TaskMessage", taskId, ndjsonLine);
|
||||
|
||||
public Task WorktreeUpdated(string taskId) =>
|
||||
_hub.Clients.All.SendAsync("WorktreeUpdated", taskId);
|
||||
|
||||
public Task TaskUpdated(string taskId) =>
|
||||
_hub.Clients.All.SendAsync("TaskUpdated", taskId);
|
||||
}
|
||||
Reference in New Issue
Block a user