(_ context.Context, _ *gomcp.CallToolRequest, input GraphInput)
| 29 | } |
| 30 | |
| 31 | func handleGraph(_ context.Context, _ *gomcp.CallToolRequest, input GraphInput) (*gomcp.CallToolResult, any, error) { |
| 32 | taskDir := input.TaskDir |
| 33 | if taskDir == "" { |
| 34 | taskDir = "." |
| 35 | } |
| 36 | |
| 37 | taskScanner := scanner.NewScanner(taskDir, false, nil) |
| 38 | result, err := taskScanner.Scan() |
| 39 | if err != nil { |
| 40 | return nil, nil, fmt.Errorf("scan failed: %w", err) |
| 41 | } |
| 42 | |
| 43 | tasks := result.Tasks |
| 44 | |
| 45 | if len(input.Filters) > 0 { |
| 46 | tasks, err = filter.Apply(tasks, input.Filters) |
| 47 | if err != nil { |
| 48 | return nil, nil, fmt.Errorf("filter error: %w", err) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | if len(input.ExcludeStatus) > 0 { |
| 53 | tasks = excludeByStatus(tasks, input.ExcludeStatus) |
| 54 | } |
| 55 | |
| 56 | g := graph.NewGraph(tasks) |
| 57 | |
| 58 | if input.RootTaskID != "" { |
| 59 | if _, ok := g.TaskMap[input.RootTaskID]; !ok { |
| 60 | return nil, nil, fmt.Errorf("root task not found: %s", input.RootTaskID) |
| 61 | } |
| 62 | upstream := g.GetUpstream(input.RootTaskID) |
| 63 | downstream := g.GetDownstream(input.RootTaskID) |
| 64 | combined := make(map[string]bool, len(upstream)+len(downstream)+1) |
| 65 | for id := range upstream { |
| 66 | combined[id] = true |
| 67 | } |
| 68 | for id := range downstream { |
| 69 | combined[id] = true |
| 70 | } |
| 71 | combined[input.RootTaskID] = true |
| 72 | g = g.FilterTasks(combined) |
| 73 | } |
| 74 | |
| 75 | graphJSON := g.ToJSON() |
| 76 | |
| 77 | data, err := json.Marshal(graphJSON) |
| 78 | if err != nil { |
| 79 | return nil, nil, fmt.Errorf("json marshal failed: %w", err) |
| 80 | } |
| 81 | |
| 82 | return &gomcp.CallToolResult{ |
| 83 | Content: []gomcp.Content{&gomcp.TextContent{Text: string(data)}}, |
| 84 | }, nil, nil |
| 85 | } |
| 86 | |
| 87 | func excludeByStatus(tasks []*model.Task, statuses []string) []*model.Task { |
| 88 | excludeMap := make(map[string]bool, len(statuses)) |
nothing calls this directly
no test coverage detected