Tool handlers
(_ context.Context, params CreateTaskArgs)
| 276 | // Tool handlers |
| 277 | |
| 278 | func (t *ToolSet) createTask(_ context.Context, params CreateTaskArgs) (*tools.ToolCallResult, error) { |
| 279 | desc, err := t.resolveDescription(params.Description, params.Path) |
| 280 | if err != nil { |
| 281 | return tools.ResultError(err.Error()), nil |
| 282 | } |
| 283 | |
| 284 | priority := TaskPriority(params.Priority) |
| 285 | if params.Priority == "" { |
| 286 | priority = PriorityMedium |
| 287 | } else if !validPriority(params.Priority) { |
| 288 | return tools.ResultError("invalid priority: " + params.Priority), nil |
| 289 | } |
| 290 | |
| 291 | t.mu.Lock() |
| 292 | defer t.mu.Unlock() |
| 293 | |
| 294 | store := t.load() |
| 295 | id := uuid.New().String() |
| 296 | |
| 297 | deps := params.Dependencies |
| 298 | if deps == nil { |
| 299 | deps = []string{} |
| 300 | } |
| 301 | for _, depID := range deps { |
| 302 | if _, ok := store.Tasks[depID]; !ok { |
| 303 | return tools.ResultError("dependency task not found: " + depID), nil |
| 304 | } |
| 305 | } |
| 306 | if hasCycle(store.Tasks, id, deps) { |
| 307 | return tools.ResultError("adding these dependencies would create a cycle"), nil |
| 308 | } |
| 309 | |
| 310 | task := Task{ |
| 311 | ID: id, |
| 312 | Title: params.Title, |
| 313 | Description: desc, |
| 314 | Priority: priority, |
| 315 | Status: StatusPending, |
| 316 | Dependencies: deps, |
| 317 | CreatedAt: now(), |
| 318 | UpdatedAt: now(), |
| 319 | } |
| 320 | |
| 321 | store.Tasks[id] = task |
| 322 | if err := t.save(store); err != nil { |
| 323 | return tools.ResultError(err.Error()), nil |
| 324 | } |
| 325 | |
| 326 | return taskResult(task), nil |
| 327 | } |
| 328 | |
| 329 | func (t *ToolSet) getTask(_ context.Context, params GetTaskArgs) (*tools.ToolCallResult, error) { |
| 330 | t.mu.Lock() |