Skip to main content

ag_protocol/
subtask.rs

1//! Orchestrator subtask model shared across protocol, coordinator, and UI
2//! code.
3
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6
7/// Execution behavior requested for one orchestration subtask.
8#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
9#[serde(rename_all = "lowercase")]
10pub enum SubtaskKind {
11    /// Produces repository changes for later verification and integration.
12    #[default]
13    Implementation,
14    /// Inspects the repository without retaining any worktree changes and
15    /// returns a report to the controller.
16    Research,
17}
18
19/// One proposed child session in an orchestrator decomposition plan.
20///
21/// Each subtask is executed unattended by its own child session in its own
22/// worktree, branched from the same base branch as its siblings. Children never
23/// coordinate with each other while running, so each prompt must be
24/// self-contained. `touched_areas` provides best-effort planning context rather
25/// than an exclusive ownership boundary.
26#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
27#[schemars(
28    title = "SubtaskItem",
29    description = "One proposed child session in an orchestrator decomposition plan. Each subtask \
30                   runs unattended in its own worktree branched from the same base branch, so it \
31                   must be completable without coordinating with its siblings."
32)]
33pub struct SubtaskItem {
34    /// Observable conditions the worker must satisfy before the controller
35    /// may verify this task as complete.
36    #[serde(default)]
37    #[schemars(
38        title = "acceptance_criteria",
39        description = "Concrete, testable acceptance criteria for this subtask. The approval UI \
40                       shows these criteria and the controller verifies the finished child \
41                       against the same list."
42    )]
43    pub acceptance_criteria: Vec<String>,
44    /// Whether this task implements repository changes or only reports
45    /// read-only findings.
46    #[serde(default)]
47    #[schemars(
48        title = "kind",
49        description = "Execution behavior for this subtask. `implementation` (the default) may \
50                       change repository files and proceeds to integration. `research` runs as a \
51                       temporary read-only child, returns a report, and is never integrated."
52    )]
53    pub kind: SubtaskKind,
54    /// Complete standalone prompt handed to the child session.
55    #[schemars(
56        title = "prompt",
57        description = "Complete standalone prompt for the child session. The child sees only this \
58                       prompt and the repository, so restate every constraint it needs instead of \
59                       referring back to the plan or to sibling subtasks."
60    )]
61    pub prompt: String,
62    /// Stable identifier for this subtask within one orchestration.
63    #[schemars(
64        title = "task_key",
65        description = "Short stable `kebab-case` identifier for this subtask, unique within the \
66                       plan. Reuse the exact same key when re-proposing a subtask so a retry \
67                       replaces the previous attempt instead of creating a duplicate."
68    )]
69    pub task_key: String,
70    /// Short human-readable subtask title.
71    #[schemars(
72        title = "title",
73        description = "Short human-readable title describing what this subtask delivers."
74    )]
75    pub title: String,
76    /// Best-effort repository-relative paths or directories this subtask is
77    /// expected to change.
78    #[serde(default)]
79    #[schemars(
80        title = "touched_areas",
81        description = "Best-effort repository-relative file or directory paths this subtask is \
82                       expected to modify. Wildcard patterns are not supported. Paths may overlap \
83                       between subtasks and workers may modify additional files when needed to \
84                       satisfy the task. Defaults to an empty list when omitted."
85    )]
86    pub touched_areas: Vec<String>,
87}