Files
ClaudeDo/src/ClaudeDo.Worker/Runner/TaskRunMcpService.cs
mika kuns c27a179d2b feat(worker): let Claude set the cheapest model per generated task via MCP
AddTask, planning CreateChildTask, and SuggestImprovement now accept an
optional alias-validated model (haiku/sonnet/opus; blank = inherit) so the
model is chosen at creation time instead of a follow-up set_task_config call.
The planning, system, and improvement prompts instruct Claude to pick the
cheapest capable model (haiku < sonnet < opus).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 22:22:17 +02:00

51 lines
2.2 KiB
C#

using System.ComponentModel;
using ClaudeDo.Data.Repositories;
using ClaudeDo.Worker.Hub;
using ModelContextProtocol.Server;
namespace ClaudeDo.Worker.Runner;
public sealed record SuggestedImprovementDto(string ChildTaskId);
[McpServerToolType]
public sealed class TaskRunMcpService
{
private readonly TaskRepository _tasks;
private readonly TaskRunMcpContextAccessor _ctx;
private readonly HubBroadcaster _broadcaster;
public TaskRunMcpService(TaskRepository tasks, TaskRunMcpContextAccessor ctx, HubBroadcaster broadcaster)
{
_tasks = tasks;
_ctx = ctx;
_broadcaster = broadcaster;
}
[McpServerTool, Description(
"File an out-of-scope improvement as a child task of the current task. The child runs " +
"automatically after this task finishes and is surfaced for review alongside it. Use ONLY " +
"for work that is genuinely outside this task's scope (a refactor, follow-up, or tech debt) " +
"— never for work that belongs to the current task. Set model to the cheapest model that can " +
"do the follow-up well — 'haiku' for trivial/mechanical work, 'sonnet' for normal coding, " +
"'opus' only for complex work. Leave model null to inherit the list/global default.")]
public async Task<SuggestedImprovementDto> SuggestImprovement(
string title,
string description,
string? model,
CancellationToken cancellationToken)
{
var callerId = _ctx.Current.CallerTaskId;
var caller = await _tasks.GetByIdAsync(callerId, cancellationToken)
?? throw new InvalidOperationException("Calling task not found.");
if (caller.ParentTaskId is not null)
throw new InvalidOperationException(
"A child task cannot suggest further improvements (improvements are one layer deep).");
var child = await _tasks.CreateChildAsync(
callerId, title, description, commitType: null, createdBy: callerId, model: model, ct: cancellationToken);
await _broadcaster.TaskUpdated(child.Id);
await _broadcaster.TaskUpdated(callerId);
return new SuggestedImprovementDto(child.Id);
}
}