返回 DeepSeek-Reasonix
schema.go
根目录 / internal / autoresearch / schema.go
1 package autoresearch
2
3 import "strings"
4
5 func (r *ValidationReport) add(file, field, msg string) {
6 r.Errors = append(r.Errors, ValidationError{File: file, Field: field, Error: msg})
7 }
8
9 func validateTaskSpec(report *ValidationReport, taskID string, spec TaskSpec) {
10 if strings.TrimSpace(spec.TaskID) == "" {
11 report.add("task_spec.json", "task_id", "task id is required")
12 } else if spec.TaskID != taskID {
13 report.add("task_spec.json", "task_id", "task id must match directory")
14 }
15 if strings.TrimSpace(spec.Goal) == "" {
16 report.add("task_spec.json", "goal", "goal is required")
17 }
18 seenCriteria := map[string]bool{}
19 for i, c := range spec.SuccessCriteria {
20 fieldPrefix := "success_criteria"
21 if strings.TrimSpace(c.ID) == "" {
22 report.add("task_spec.json", fieldPrefix, "criterion id is required")
23 } else if seenCriteria[c.ID] {
24 report.add("task_spec.json", fieldPrefix, "criterion id must be unique")
25 }
26 seenCriteria[c.ID] = true
27 if strings.TrimSpace(c.Description) == "" {
28 report.add("task_spec.json", fieldPrefix, "criterion description is required")
29 }
30 _ = i
31 }
32 }
33
34 func validateProgress(report *ValidationReport, progress Progress) {
35 switch progress.Status {
36 case StatusRunning, StatusBlocked, StatusComplete, StatusStopped, StatusInvalid:
37 default:
38 report.add("progress.json", "status", "status is invalid")
39 }
40 if progress.Iteration < 0 {
41 report.add("progress.json", "iteration", "iteration must not be negative")
42 }
43 if progress.StaleCount < 0 {
44 report.add("progress.json", "stale_count", "stale count must not be negative")
45 }
46 if progress.PivotCount < 0 {
47 report.add("progress.json", "pivot_count", "pivot count must not be negative")
48 }
49 if progress.UpdatedAt.IsZero() {
50 report.add("progress.json", "updated_at", "updated_at is required")
51 }
52 }
53
53 lines GO