feat(worker): expose RestoreDefaultAgents hub method

This commit is contained in:
mika kuns
2026-04-23 12:18:49 +02:00
parent df57c2bc05
commit 1a10e6fa09
2 changed files with 35 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ public record UpdateListDto(string Id, string Name, string? WorkingDir, string D
public record UpdateListConfigDto(string ListId, string? Model, string? SystemPrompt, string? AgentPath); public record UpdateListConfigDto(string ListId, string? Model, string? SystemPrompt, string? AgentPath);
public record UpdateTaskAgentSettingsDto(string TaskId, string? Model, string? SystemPrompt, string? AgentPath); public record UpdateTaskAgentSettingsDto(string TaskId, string? Model, string? SystemPrompt, string? AgentPath);
public record ListConfigDto(string? Model, string? SystemPrompt, string? AgentPath); public record ListConfigDto(string? Model, string? SystemPrompt, string? AgentPath);
public record SeedResultDto(int Copied, int Skipped);
public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
{ {
@@ -36,6 +37,7 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
private readonly QueueService _queue; private readonly QueueService _queue;
private readonly AgentFileService _agentService; private readonly AgentFileService _agentService;
private readonly DefaultAgentSeeder _seeder;
private readonly HubBroadcaster _broadcaster; private readonly HubBroadcaster _broadcaster;
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory; private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
private readonly WorktreeMaintenanceService _wtMaintenance; private readonly WorktreeMaintenanceService _wtMaintenance;
@@ -45,6 +47,7 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
public WorkerHub( public WorkerHub(
QueueService queue, QueueService queue,
AgentFileService agentService, AgentFileService agentService,
DefaultAgentSeeder seeder,
HubBroadcaster broadcaster, HubBroadcaster broadcaster,
IDbContextFactory<ClaudeDoDbContext> dbFactory, IDbContextFactory<ClaudeDoDbContext> dbFactory,
WorktreeMaintenanceService wtMaintenance, WorktreeMaintenanceService wtMaintenance,
@@ -53,6 +56,7 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
{ {
_queue = queue; _queue = queue;
_agentService = agentService; _agentService = agentService;
_seeder = seeder;
_broadcaster = broadcaster; _broadcaster = broadcaster;
_dbFactory = dbFactory; _dbFactory = dbFactory;
_wtMaintenance = wtMaintenance; _wtMaintenance = wtMaintenance;
@@ -125,6 +129,12 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
public async Task RefreshAgents() => await _agentService.ScanAsync(); public async Task RefreshAgents() => await _agentService.ScanAsync();
public async Task<SeedResultDto> RestoreDefaultAgents()
{
var result = await _seeder.SeedMissingAsync();
return new SeedResultDto(result.Copied, result.Skipped);
}
public async Task<AppSettingsDto> GetAppSettings() public async Task<AppSettingsDto> GetAppSettings()
{ {
using var ctx = _dbFactory.CreateDbContext(); using var ctx = _dbFactory.CreateDbContext();

View File

@@ -44,4 +44,29 @@ public sealed class AgentSettingsHubTests : IDisposable
Assert.Null(await _repo.GetConfigAsync(listId)); Assert.Null(await _repo.GetConfigAsync(listId));
} }
[Fact]
public async Task RestoreDefaultAgents_CopiesMissingBundledFiles()
{
var root = Path.Combine(Path.GetTempPath(), $"claudedo_hub_restore_{Guid.NewGuid():N}");
var bundleDir = Path.Combine(root, "bundle");
var targetDir = Path.Combine(root, "target");
try
{
Directory.CreateDirectory(bundleDir);
Directory.CreateDirectory(targetDir);
await File.WriteAllTextAsync(Path.Combine(bundleDir, "code-reviewer.md"), "body");
var seeder = new ClaudeDo.Worker.Services.DefaultAgentSeeder(bundleDir, targetDir);
var result = await seeder.SeedMissingAsync();
Assert.Equal(1, result.Copied);
Assert.Equal(0, result.Skipped);
Assert.True(File.Exists(Path.Combine(targetDir, "code-reviewer.md")));
}
finally
{
try { Directory.Delete(root, true); } catch { }
}
}
} }