feat(worker): MCP tools for child-task CRUD
This commit is contained in:
85
src/ClaudeDo.Worker/Planning/PlanningMcpService.cs
Normal file
85
src/ClaudeDo.Worker/Planning/PlanningMcpService.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Data.Repositories;
|
||||
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||
|
||||
namespace ClaudeDo.Worker.Planning;
|
||||
|
||||
public sealed record ChildTaskDto(string TaskId, string Title, string? Description, string Status, IReadOnlyList<string> Tags);
|
||||
public sealed record CreatedChildDto(string TaskId, string Status);
|
||||
|
||||
public sealed class PlanningMcpService
|
||||
{
|
||||
private readonly TaskRepository _tasks;
|
||||
|
||||
public PlanningMcpService(TaskRepository tasks) => _tasks = tasks;
|
||||
|
||||
public async Task<CreatedChildDto> CreateChildTask(
|
||||
PlanningMcpContext ctx,
|
||||
string title,
|
||||
string? description,
|
||||
IReadOnlyList<string>? tags,
|
||||
string? commitType,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var child = await _tasks.CreateChildAsync(ctx.ParentTaskId, title, description, tags, commitType, cancellationToken);
|
||||
return new CreatedChildDto(child.Id, "Draft");
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<ChildTaskDto>> ListChildTasks(
|
||||
PlanningMcpContext ctx,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var children = await _tasks.GetChildrenAsync(ctx.ParentTaskId, cancellationToken);
|
||||
var list = new List<ChildTaskDto>(children.Count);
|
||||
foreach (var c in children)
|
||||
{
|
||||
var tagList = await _tasks.GetTagsAsync(c.Id, cancellationToken);
|
||||
list.Add(new ChildTaskDto(c.Id, c.Title, c.Description, c.Status.ToString(), tagList.Select(t => t.Name).ToList()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public async Task<ChildTaskDto> UpdateChildTask(
|
||||
PlanningMcpContext ctx,
|
||||
string taskId,
|
||||
string? title,
|
||||
string? description,
|
||||
IReadOnlyList<string>? tags,
|
||||
string? commitType,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var child = await _tasks.GetByIdAsync(taskId, cancellationToken)
|
||||
?? throw new InvalidOperationException($"Task {taskId} not found.");
|
||||
if (child.ParentTaskId != ctx.ParentTaskId)
|
||||
throw new InvalidOperationException("Task is not a child of this planning session.");
|
||||
if (child.Status != TaskStatus.Draft)
|
||||
throw new InvalidOperationException("Cannot modify a finalized task.");
|
||||
|
||||
if (title is not null) child.Title = title;
|
||||
if (description is not null) child.Description = description;
|
||||
if (commitType is not null) child.CommitType = commitType;
|
||||
await _tasks.UpdateAsync(child, cancellationToken);
|
||||
|
||||
// Tag handling omitted for v1 simplicity — tags set at create time.
|
||||
// If Claude asks to update tags, it can delete and re-create.
|
||||
|
||||
var reload = (await _tasks.GetByIdAsync(taskId, cancellationToken))!;
|
||||
var tagList = await _tasks.GetTagsAsync(reload.Id, cancellationToken);
|
||||
return new ChildTaskDto(reload.Id, reload.Title, reload.Description, reload.Status.ToString(), tagList.Select(t => t.Name).ToList());
|
||||
}
|
||||
|
||||
public async Task DeleteChildTask(
|
||||
PlanningMcpContext ctx,
|
||||
string taskId,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var child = await _tasks.GetByIdAsync(taskId, cancellationToken)
|
||||
?? throw new InvalidOperationException($"Task {taskId} not found.");
|
||||
if (child.ParentTaskId != ctx.ParentTaskId)
|
||||
throw new InvalidOperationException("Task is not a child of this planning session.");
|
||||
if (child.Status != TaskStatus.Draft)
|
||||
throw new InvalidOperationException("Cannot delete a finalized task.");
|
||||
|
||||
await _tasks.DeleteAsync(taskId, cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user