MCPcopy Create free account
hub / github.com/cursor/cookbook / validateTask

Function validateTask

sdk/dag-task-runner/src/dag.ts:71–98  ·  view source on GitHub ↗
(raw: unknown, index: number)

Source from the content-addressed store, hash-verified

69}
70
71function validateTask(raw: unknown, index: number): RawTask {
72 if (!raw || typeof raw !== "object") {
73 throw new Error(`tasks[${index}] must be an object.`);
74 }
75 const t = raw as Record<string, unknown>;
76 const id = t.id;
77 if (typeof id !== "string" || id.trim() === "") {
78 throw new Error(`tasks[${index}].id must be a non-empty string.`);
79 }
80 const depends_on = t.depends_on ?? [];
81 if (!Array.isArray(depends_on) || depends_on.some((d) => typeof d !== "string")) {
82 throw new Error(`tasks[${index}].depends_on must be an array of strings.`);
83 }
84 const complexity = t.complexity;
85 if (typeof complexity !== "string" || !COMPLEXITY_VALUES.has(complexity as Complexity)) {
86 throw new Error(`tasks[${index}].complexity must be one of HIGH | MED | LOW.`);
87 }
88 const subtask_prompt = t.subtask_prompt;
89 if (typeof subtask_prompt !== "string" || subtask_prompt.trim() === "") {
90 throw new Error(`tasks[${index}].subtask_prompt must be a non-empty string.`);
91 }
92 return {
93 id,
94 depends_on: [...new Set(depends_on as string[])],
95 complexity: complexity as Complexity,
96 subtask_prompt,
97 };
98}
99
100/** Throws on the first cycle found. Uses iterative DFS with a recursion stack. */
101function detectCycle(tasks: RawTask[]): void {

Callers 1

parseDAGFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected