diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-02-08 21:35:45 -1000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-02-08 21:35:45 -1000 |
| commit | 2e2b2187b957e9af78797a67ec5c6874615fae02 (patch) | |
| tree | 1181dbb7e43f5d30cb025fa4d50fd4e7a2c893b3 /internal/task/parser.go | |
Initial project: task model, executor, API server, CLI, storage, reporter
Claudomator automation toolkit for Claude Code with:
- Task model with YAML parsing, validation, state machine (49 tests, 0 races)
- SQLite storage for tasks and executions
- Executor pool with bounded concurrency, timeout, cancellation
- REST API + WebSocket for mobile PWA integration
- Webhook/multi-notifier system
- CLI: init, run, serve, list, status commands
- Console, JSON, HTML reporters with cost tracking
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/task/parser.go')
| -rw-r--r-- | internal/task/parser.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/internal/task/parser.go b/internal/task/parser.go new file mode 100644 index 0000000..7a450b8 --- /dev/null +++ b/internal/task/parser.go @@ -0,0 +1,61 @@ +package task + +import ( + "fmt" + "os" + "time" + + "github.com/google/uuid" + "gopkg.in/yaml.v3" +) + +// ParseFile reads a YAML file and returns tasks. Supports both single-task +// and batch (tasks: [...]) formats. +func ParseFile(path string) ([]Task, error) { + data, err := os.ReadFile(path) + if err != nil { + return nil, fmt.Errorf("reading task file: %w", err) + } + return Parse(data) +} + +// Parse parses YAML bytes into tasks. +func Parse(data []byte) ([]Task, error) { + // Try batch format first. + var batch BatchFile + if err := yaml.Unmarshal(data, &batch); err == nil && len(batch.Tasks) > 0 { + return initTasks(batch.Tasks), nil + } + + // Try single task. + var t Task + if err := yaml.Unmarshal(data, &t); err != nil { + return nil, fmt.Errorf("parsing task YAML: %w", err) + } + if t.Name == "" { + return nil, fmt.Errorf("task must have a name") + } + return initTasks([]Task{t}), nil +} + +func initTasks(tasks []Task) []Task { + now := time.Now() + for i := range tasks { + if tasks[i].ID == "" { + tasks[i].ID = uuid.New().String() + } + if tasks[i].Priority == "" { + tasks[i].Priority = PriorityNormal + } + if tasks[i].Retry.MaxAttempts == 0 { + tasks[i].Retry.MaxAttempts = 1 + } + if tasks[i].Retry.Backoff == "" { + tasks[i].Retry.Backoff = "exponential" + } + tasks[i].State = StatePending + tasks[i].CreatedAt = now + tasks[i].UpdatedAt = now + } + return tasks +} |
