Task titles, project links

This commit is contained in:
Ian Gulliver
2025-07-10 22:07:51 -07:00
parent 3cde954b6f
commit 0606b2bc7d
2 changed files with 44 additions and 41 deletions

View File

@@ -33,6 +33,7 @@ const (
type Task struct { type Task struct {
ID string `json:"id"` ID string `json:"id"`
State TaskState `json:"-"` State TaskState `json:"-"`
Title string `json:"title"`
Instructions string `json:"instructions"` Instructions string `json:"instructions"`
Data map[string]any `json:"data,omitempty"` Data map[string]any `json:"data,omitempty"`
Result string `json:"-"` Result string `json:"-"`
@@ -41,9 +42,8 @@ type Task struct {
NextTaskID string `json:"-"` NextTaskID string `json:"-"`
projectID string project *Project
mcpService string completionCallback func(project *Project, task *Task) error
completionCallback func(task *Task) error
} }
func New(mcpService string) *Service { func New(mcpService string) *Service {
@@ -73,8 +73,8 @@ func (s *Service) GetProject(id string) (*Project, error) {
return project, nil return project, nil
} }
func (p *Project) InsertTaskBefore(beforeID string, instructions string, completionCallback func(task *Task) error) *Task { func (p *Project) InsertTaskBefore(beforeID string, title string, instructions string, completionCallback func(project *Project, task *Task) error) *Task {
task := p.newTask(instructions, completionCallback, beforeID) task := p.newTask(title, instructions, completionCallback, beforeID)
if p.nextTaskID == "" && beforeID == "" { if p.nextTaskID == "" && beforeID == "" {
p.nextTaskID = task.ID p.nextTaskID = task.ID
@@ -106,10 +106,12 @@ func (p *Project) SetTaskSuccess(id string, result string, notes string) (*Task,
task.Result = result task.Result = result
task.Notes = notes task.Notes = notes
err := task.completionCallback(task) if task.completionCallback != nil {
err := task.completionCallback(task.project, task)
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
p.nextTaskID = task.NextTaskID p.nextTaskID = task.NextTaskID
@@ -122,26 +124,28 @@ func (p *Project) SetTaskFailure(id string, error string, notes string) (*Task,
task.Error = error task.Error = error
task.Notes = notes task.Notes = notes
err := task.completionCallback(task) if task.completionCallback != nil {
err := task.completionCallback(task.project, task)
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
p.nextTaskID = task.NextTaskID p.nextTaskID = task.NextTaskID
return p.GetNextTask(), nil return p.GetNextTask(), nil
} }
func (p *Project) newTask(instructions string, completionCallback func(task *Task) error, nextTaskID string) *Task { func (p *Project) newTask(title string, instructions string, completionCallback func(project *Project, task *Task) error, nextTaskID string) *Task {
task := &Task{ task := &Task{
ID: uuid.New().String(), ID: uuid.New().String(),
State: TaskStatePending, State: TaskStatePending,
NextTaskID: nextTaskID, NextTaskID: nextTaskID,
Title: title,
Instructions: instructions, Instructions: instructions,
Data: map[string]any{}, Data: map[string]any{},
completionCallback: completionCallback, completionCallback: completionCallback,
projectID: p.ID, project: p,
mcpService: p.mcpService,
} }
task.Instructions = strings.ReplaceAll(task.Instructions, "{SUCCESS_PROMPT}", task.SuccessPrompt()) task.Instructions = strings.ReplaceAll(task.Instructions, "{SUCCESS_PROMPT}", task.SuccessPrompt())
@@ -165,13 +169,13 @@ func (p *Project) tasks() iter.Seq[*Task] {
func (t *Task) SuccessPrompt() string { func (t *Task) SuccessPrompt() string {
return fmt.Sprintf(`To mark this task as successful, use the MCP tool: return fmt.Sprintf(`To mark this task as successful, use the MCP tool:
%s.set_task_success(project_id="%s", task_id="%s", result="<your result>", notes="<optional notes>")`, %s.set_task_success(project_id="%s", task_id="%s", result="<your result>", notes="<optional notes>")`,
t.mcpService, t.projectID, t.ID) t.project.mcpService, t.project.ID, t.ID)
} }
func (t *Task) FailurePrompt() string { func (t *Task) FailurePrompt() string {
return fmt.Sprintf(`To mark this task as failed, use the MCP tool: return fmt.Sprintf(`To mark this task as failed, use the MCP tool:
%s.set_task_failure(project_id="%s", task_id="%s", error="<error message>", notes="<optional notes>")`, %s.set_task_failure(project_id="%s", task_id="%s", error="<error message>", notes="<optional notes>")`,
t.mcpService, t.projectID, t.ID) t.project.mcpService, t.project.ID, t.ID)
} }
func (t *Task) String() string { func (t *Task) String() string {

View File

@@ -8,12 +8,11 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestTaskPrompts(t *testing.T) { func TestTaskPrompts(t *testing.T) {
service := taskcp.New("my_service") service := taskcp.New("my_service")
project := service.AddProject() project := service.AddProject()
task := project.InsertTaskBefore("", "Write unit tests", func(task *taskcp.Task) error { return nil }) task := project.InsertTaskBefore("", "Write unit tests", "", func(project *taskcp.Project, task *taskcp.Task) error { return nil })
successPrompt := task.SuccessPrompt() successPrompt := task.SuccessPrompt()
require.Contains(t, successPrompt, "my_service.set_task_success") require.Contains(t, successPrompt, "my_service.set_task_success")
@@ -30,11 +29,11 @@ func TestPlaceholderExpansion(t *testing.T) {
service := taskcp.New("my_service") service := taskcp.New("my_service")
project := service.AddProject() project := service.AddProject()
task1 := project.InsertTaskBefore("", "Please complete this task. {SUCCESS_PROMPT}", func(task *taskcp.Task) error { return nil }) task1 := project.InsertTaskBefore("", "Please complete this task.", "{SUCCESS_PROMPT}", func(project *taskcp.Project, task *taskcp.Task) error { return nil })
require.Contains(t, task1.Instructions, "my_service.set_task_success") require.Contains(t, task1.Instructions, "my_service.set_task_success")
require.NotContains(t, task1.Instructions, "{SUCCESS_PROMPT}") require.NotContains(t, task1.Instructions, "{SUCCESS_PROMPT}")
task2 := project.InsertTaskBefore("", "Try this risky operation. {FAILURE_PROMPT}", func(task *taskcp.Task) error { return nil }) task2 := project.InsertTaskBefore("", "Try this risky operation.", "{FAILURE_PROMPT}", func(project *taskcp.Project, task *taskcp.Task) error { return nil })
require.Contains(t, task2.Instructions, "my_service.set_task_failure") require.Contains(t, task2.Instructions, "my_service.set_task_failure")
require.NotContains(t, task2.Instructions, "{FAILURE_PROMPT}") require.NotContains(t, task2.Instructions, "{FAILURE_PROMPT}")
} }
@@ -45,12 +44,12 @@ func TestTaskFlow(t *testing.T) {
var completed []string var completed []string
task1 := project.InsertTaskBefore("", "First task", func(task *taskcp.Task) error { task1 := project.InsertTaskBefore("", "First task", "", func(project *taskcp.Project, task *taskcp.Task) error {
completed = append(completed, task.ID) completed = append(completed, task.ID)
return nil return nil
}) })
task2 := project.InsertTaskBefore("", "Second task", func(task *taskcp.Task) error { task2 := project.InsertTaskBefore("", "Second task", "", func(project *taskcp.Project, task *taskcp.Task) error {
completed = append(completed, task.ID) completed = append(completed, task.ID)
return nil return nil
}) })
@@ -80,7 +79,7 @@ func TestCallbackError(t *testing.T) {
expectedErr := fmt.Errorf("callback error") expectedErr := fmt.Errorf("callback error")
task := project.InsertTaskBefore("", "Task with error callback", func(task *taskcp.Task) error { task := project.InsertTaskBefore("", "Task with error callback", "", func(project *taskcp.Project, task *taskcp.Task) error {
return expectedErr return expectedErr
}) })