# sagaryeole/ai-task-orchestrator architecture

> Architecture diagram of the GitHub repository sagaryeole/ai-task-orchestrator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sagaryeole/ai-task-orchestrator
- Repository: https://github.com/sagaryeole/ai-task-orchestrator

## Overview

#### Purpose and Entry Points
Task Orchestrator is an offline-first Python controller for unattended AI coding backlogs. It reads Markdown checklist tasks, invokes configured coding-agent CLIs, handles rate-limit failover, verifies changes, and marks successful tasks complete.

Primary entry points:
- Legacy/direct executable: `orchestrator.py`
- Installed CLI and subcommands (`init`, `validate`): `src/task_orchestrator/cli.py`
- Core package execution path: `src/task_orchestrator/runner.py`

#### CLI and Initialization Boundary
The CLI parses run modes such as dry-run, one-shot execution, provider/task overrides, task filtering, JSON logs, and concurrency. `init` scaffolds project-local backlog/config/prompt assets; `validate` checks readiness without invoking agents.

Relevant paths:
- `src/task_orchestrator/cli.py`
- `task-orchestrator.config.schema.json`
- `task-orchestrator.config.json`

The runtime is Python 3.9+ and standard-library-only; it is distributed as a package through `pyproject.toml`.

#### Configuration-Driven Provider Layer
Providers are declarative subprocess definitions: executable command, environment overlay, rate-limit output patterns, cooldown, enabled state, and optional priority. Commands receive prompts over stdin unless their command includes `{{TASK}}`, which inserts the generated prompt as one argv element.

Relevant paths:
- `task-orchestrator.config.json`
- `task-orchestrator.config.copilot.json`
- `examples/multi-provider.json`

This boundary isolates external systems: Copilot, Claude, Codex, Kilo, Ollama, or any compatible local/remote agent CLI. The orchestrator itself makes no network calls; configured CLIs own authentication and outbound API traffic.

#### Backlog, Prompt, and State Inputs
The runner selects unchecked GitHub-flavored checkbox items from the configured Todo file, optionally batches them, renders task text into a prompt template, and maintains resumable provider cooldown state.

Relevant paths:
- `Todo.md`
- `prompts/task_prompt.txt`
- `src/task_orchestrator/runner.py`

Project-local runtime outputs include `state.json` for cooldown persistence and `logs/` for append-only text/JSONL records. Task text and provider command configuration are trusted inputs; subprocesses run without a shell.

#### Per-Task Control Flow
For each selected task or batch, the runner:
1. Chooses an available provider by priority or round-robin, respecting persisted cooldowns and optional forced provider selection.
2. Runs the provider synchronously with merged environment and captured combined output.
3. Detects configured rate-limit patterns; on match, persists cooldown and immediately retries the same task on another provider.
4. If all providers are cooling down, waits until the earliest expiry.
5. Uses exit status and repository change detection to reject suspicious/no-op outcomes.
6. Runs configured verification commands, then obtains manual approval or automatically accepts.
7. Marks all batch tasks complete atomically; optionally commits changes; sleeps before the next successful task.

Core implementation paths:
- `src/task_orchestrator/runner.py`
- `orchestrator.py`
- `scripts/sync_todo.py`

#### Quality and Repository Boundaries
Verification commands run in the configured working directory and have per-command timeout protection. Git is both a change-detection boundary (`git status --porcelain`) and an optional commit target. Failed verification, agent failure, rejection, or retry policy determines whether to retry, rotate, continue, or stop.

Relevant paths:
- `src/task_orchestrator/runner.py`
- `task-orchestrator.config.schema.json`
- `README.md`

#### Observability and Interactive Runtime Services
The system writes concise terminal status while retaining full provider, verification, and stats output in logs; optional JSONL supports local downstream processing. An optional stdlib HTTP dashboard exposes current task/provider/history state as HTML and `/api/state` JSON. Interactive terminal commands can pause, resume, skip, or quit cleanly.

Relevant paths:
- `src/task_orchestrator/runner.py`
- `src/task_orchestrator/cli.py`
- `run_forever.sh`

Cross-platform supervisor scripts support crash-restart operation on shell and PowerShell:
- `run_forever.sh`
- `run_forever.ps1`

Main entry points: [`src/task_orchestrator/runner.py`](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py) (Runner), [`src/task_orchestrator/cli.py`](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/cli.py) (Installed CLI), [`task-orchestrator.config.json`](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/task-orchestrator.config.json) (Runtime config), [`Todo.md`](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/Todo.md) (Task backlog)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry &amp; Setup"]
  node_cli["Installed CLI<br/>[cli.py]"]
  node_legacy["Legacy executable<br/>Python entry<br/>[orchestrator.py]"]
  node_supervisor["Restart supervisors<br/>shell scripts<br/>[run_forever.sh]"]
end

subgraph group_core["Task Execution"]
  node_runner["Runner<br/>orchestration core<br/>[runner.py]"]
  node_task_selection["Task selection &amp; batching<br/>runner layer<br/>[runner.py]"]
  node_provider_scheduler["Provider scheduler<br/>runner layer<br/>[runner.py]"]
  node_verification["Verification commands<br/>subprocess checks<br/>[runner.py]"]
  node_approval["Approval &amp; completion<br/>runner layer<br/>[runner.py]"]
end

subgraph group_inputs["Project Inputs"]
  node_config["Runtime config<br/>JSON config"]
  node_schema["Config schema<br/>JSON schema"]
  node_backlog["Task backlog<br/>Markdown checklist<br/>[Todo.md]"]
  node_prompt["Prompt template<br/>text template<br/>[task_prompt.txt]"]
end

subgraph group_runtime["Runtime Boundaries"]
  node_agent_execution{{"Agent subprocesses<br/>external CLIs"}}
  node_cooldown_state["Cooldown state<br/>runtime JSON"]
  node_change_gate{{"Change detection<br/>Git boundary<br/>[runner.py]"}}
  node_git{{"Git repository<br/>VCS boundary"}}
  node_logs["Logs<br/>text / JSONL output"]
  node_dashboard["Dashboard &amp; controls<br/>HTTP and terminal UI<br/>[runner.py]"]
end

node_cli -->|"validates config"| node_schema
node_cli -->|"loads"| node_config
node_cli -->|"starts"| node_runner
node_legacy -->|"starts"| node_runner
node_supervisor -->|"restarts"| node_cli
node_config -->|"runtime policy"| node_runner
node_backlog -->|"unchecked tasks"| node_task_selection
node_prompt -->|"renders prompt"| node_task_selection
node_runner -->|"coordinates"| node_task_selection
node_task_selection -->|"selected task or batch"| node_provider_scheduler
node_provider_scheduler -->|"reads and persists"| node_cooldown_state
node_provider_scheduler -->|"invokes available provider"| node_agent_execution
node_agent_execution -->|"output / rate limit"| node_provider_scheduler
node_agent_execution -->|"workspace changes"| node_change_gate
node_change_gate -->|"changed result"| node_verification
node_verification -->|"verification result"| node_approval
node_approval -->|"atomically marks complete"| node_backlog
node_approval -->|"optional commit"| node_git
node_runner -->|"writes status and output"| node_logs
node_runner -->|"publishes runtime state"| node_dashboard

click node_cli "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/cli.py"
click node_legacy "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/orchestrator.py"
click node_supervisor "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/run_forever.sh"
click node_config "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/task-orchestrator.config.json"
click node_schema "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/task-orchestrator.config.schema.json"
click node_backlog "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/Todo.md"
click node_prompt "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/prompts/task_prompt.txt"
click node_runner "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py"
click node_task_selection "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py"
click node_provider_scheduler "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py"
click node_change_gate "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py"
click node_verification "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py"
click node_approval "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py"
click node_dashboard "https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_legacy,node_supervisor toneBlue
class node_runner,node_task_selection,node_provider_scheduler,node_verification,node_approval toneAmber
class node_config,node_schema,node_backlog,node_prompt toneMint
class node_agent_execution,node_cooldown_state,node_change_gate,node_git,node_logs,node_dashboard toneRose
```

## Components

### Entry & Setup

- [Installed CLI](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/cli.py): CLI · Run, init, and validate subcommands. · `src/task_orchestrator/cli.py`
- [Legacy executable](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/orchestrator.py): Python entry · `orchestrator.py`
- [Restart supervisors](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/run_forever.sh): shell scripts · Crash-restart wrappers for unattended operation. · `run_forever.sh`

### Task Execution

- [Runner](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py): orchestration core · Coordinates selection, execution, retries, verification, and completion. · `src/task_orchestrator/runner.py`
- [Task selection & batching](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py): runner layer · Selects unchecked tasks and renders batch prompts. · `src/task_orchestrator/runner.py`
- [Provider scheduler](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py): runner layer · Priority or round-robin selection with cooldown failover. · `src/task_orchestrator/runner.py`
- [Verification commands](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py): subprocess checks · Configured commands run with per-command timeouts. · `src/task_orchestrator/runner.py`
- [Approval & completion](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py): runner layer · Accepts or rejects results, atomically checks off batches, and may commit. · `src/task_orchestrator/runner.py`

### Project Inputs

- [Runtime config](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/task-orchestrator.config.json): JSON config · Provider, verification, task, and runtime policy. · `task-orchestrator.config.json`
- [Config schema](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/task-orchestrator.config.schema.json): JSON schema · `task-orchestrator.config.schema.json`
- [Task backlog](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/Todo.md): Markdown checklist · `Todo.md`
- [Prompt template](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/prompts/task_prompt.txt): text template · `prompts/task_prompt.txt`

### Runtime Boundaries

- **Agent subprocesses**: external CLIs · Trusted prompts are sent over stdin or as a {{TASK}} argv value.
- **Cooldown state**: runtime JSON · Resumable provider rate-limit state.
- [Change detection](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py): Git boundary · Rejects suspicious or no-op agent outcomes. · `src/task_orchestrator/runner.py`
- **Git repository**: VCS boundary · Optional commit target after accepted work.
- **Logs**: text / JSONL output · Provider, verification, and statistics records.
- [Dashboard & controls](https://github.com/sagaryeole/ai-task-orchestrator/blob/main/src/task_orchestrator/runner.py): HTTP and terminal UI · Exposes state and accepts pause, resume, skip, and quit. · `src/task_orchestrator/runner.py`

## Connections

- Installed CLI → Config schema: validates config
- Installed CLI → Runtime config: loads
- Installed CLI → Runner: starts
- Legacy executable → Runner: starts
- Restart supervisors → Installed CLI: restarts
- Runtime config → Runner: runtime policy
- Task backlog → Task selection & batching: unchecked tasks
- Prompt template → Task selection & batching: renders prompt
- Runner → Task selection & batching: coordinates
- Task selection & batching → Provider scheduler: selected task or batch
- Provider scheduler → Cooldown state: reads and persists
- Provider scheduler → Agent subprocesses: invokes available provider
- Agent subprocesses → Provider scheduler: output / rate limit
- Agent subprocesses → Change detection: workspace changes
- Change detection → Verification commands: changed result
- Verification commands → Approval & completion: verification result
- Approval & completion → Task backlog: atomically marks complete
- Approval & completion → Git repository: optional commit
- Runner → Logs: writes status and output
- Runner → Dashboard & controls: publishes runtime state
