返回 CodeWhale
AUTOMATIC_WORKFLOWS.md
根目录 / docs / AUTOMATIC_WORKFLOWS.md
1 # Automatic Workflows
2
3 > 阅读简体中文版:[zh_hans/AUTOMATIC_WORKFLOWS.md](zh_hans/AUTOMATIC_WORKFLOWS.md)。
4
5 You do **not** need to write a `.workflow.js` file to coordinate agents. Operate
6 handles small or tightly coupled work directly. Multi-step delegation starts
7 with a compact Workflow plan: named steps, dependencies, bounded scopes, and
8 completion checks. Workflow runs the same sub-agents that Fleet configures and
9 manages, passing results and evidence between dependent steps. One bounded,
10 independent task can use a direct background agent; follow-up work should reuse
11 that agent with `followup`. Act/Agent can still use the optional soft-auto
12 policy described below.
13
14 Related docs:
15
16 - [Workflow Authoring](WORKFLOW_AUTHORING.md) — checked-in scripts and IR
17 - [Fleet + Workflow Tutorial](FLEET_WORKFLOW_TUTORIAL.md) — manual fleet paths
18 - [Configuration](CONFIGURATION.md) — `[workflow]` knobs
19 - [Sandbox](SANDBOX.md) — what the Workflow VM cannot do
20
21 ## Soft-auto in Act/Agent
22
23 1. **You ask naturally** — “audit every crate for unsafe,” “scout then implement,”
24 “compare these two providers in parallel.”
25 2. **Codewhale decides in Act/Agent** — broad, independent, or staged work can
26 trigger Workflow; one-file edits, simple commands, and pure Q&A do not.
27 3. **It tells you first** — e.g. “This looks set up for a Workflow — three scouts
28 then one verifier.”
29 4. **Optional setup** — if one or two facts would change the plan (read-only vs
30 writes, scope, child count), it opens the **`request_user_input`** modal
31 (structured multiple choice, not a long free-form interview).
32 5. **Launch** — structured `plan` JSON (goal / phases / children) or a short
33 inline script. Parallel branches use `parallel()` partial-success semantics.
34
35 In Operate, those same asks use a compact Workflow plan when they need multiple
36 delegated steps. The plan makes parallel work, dependency handoffs, and the
37 evidence needed to finish visible together. Small or tightly coupled work can
38 stay in the parent under the active tool and approval policy; one bounded,
39 independent task can use a direct agent. Continue an existing agent with
40 `followup` when the task remains the same. You can always type `/workflow` to
41 request orchestration explicitly.
42
43 ## Read-only auto-start vs write approval
44
45 `[workflow]` config (see `config.example.toml`):
46
47 | Knob | Default | Meaning |
48 |------|---------|---------|
49 | `automatic` | `true` | Legacy compatibility field; currently not a launch switch. The model chooses orchestration under the active tool and approval policy. |
50 | `auto_start_read_only` | `true` | Read-only plans may start without a write-approval card |
51 | `require_approval_for_writes` | `true` | Gates the plan-approval card for writes / elevated starts |
52 | `max_children` / `max_concurrent` / `max_depth` | `0` / `64` / `0` | Total children and structural plan depth are uncapped at zero; positive values are owner limits. Concurrency queues excess work. Runtime delegation defaults to a maximum depth of 3 (`[subagents] max_depth`) and remains a separate authority setting. |
53
54 Elevated work (writes, shell beyond read-only, network, secrets, worktrees)
55 surfaces an approval card with goal, child summary, capability flags,
56 and budget before launch (#4126) when `require_approval_for_writes` is on.
57 That flag only gates the card. Session-level auto-approve (YOLO / Full Access /
58 `bypass`) still skips it, the same as other ordinary `Required` tools.
59 Writes inside a running VM `task()` step are the VM runtime contract
60 (sandbox, `writeAuthority`, parent tool policy) — this flag does not re-ask
61 for each child write.
62
63 Worktree isolation and write ownership are separate. A write-capable `task()`
64 (`type: "implementer"`, or `writeAuthority: "workspace_write"` /
65 `"worktree_write"`) may declare repo-relative `writeRoots`, `exactFiles`, or
66 `coordinationContracts`; with none, the spawn boundary claims its
67 `deliverables`, or else the workspace root (`.`), exactly as a plain Agent
68 spawn does. The coordination ledger refuses a second live writer whose claim
69 overlaps, so when a script fans out parallel writers in one checkout it should
70 give each one disjoint `writeRoots` or `exactFiles`. Read-only roles cannot
71 declare write authority. `worktree: true` selects isolation but does not
72 silently grant mutation authority. A prompt-only general task is read-only.
73 `dependencies` and `acceptance` carry bounded child-specific prerequisites and
74 observable completion checks; they are not a parent-transcript copy.
75
76 When a workflow runs from a workspace containing multiple repositories, a
77 child that needs shell or file access must set `cwd` to the repository-relative
78 directory it should use. The host validates that the directory exists inside
79 the parent workspace before dispatch. Use `worktree: true` for isolated writes;
80 `cwd` selects an existing checkout and does not grant write authority or
81 isolation by itself.
82
83 ## Controlling a run
84
85 `/workflow status [run_id]`, `/workflow cancel [run_id]`, and `/workflow
86 settings` are answered by Codewhale itself from the run journal and the live
87 run state — they never spend a model turn, so a status check is free and a
88 cancel lands even while the model is busy. `/workflow cancel` with no id stops
89 the only running workflow.
90
91 Starting work is review-first. `/workflow <objective>` and bare `/workflow`
92 ask the model for a bounded, tool-less proposal; `/workflow run
93 <path/to/x.workflow.js>` prepares a review of that exact checked-in source.
94 Neither form executes anything. After reviewing the proposal, run `/workflow
95 confirm` to launch the latest reviewed draft. The `[workflow]` table above is
96 read from your `config.toml` for every launch decision (auto-start,
97 write-approval card, child limits); `/workflow settings` prints the effective
98 values with what each one does. Reloading `config.toml` refreshes that table
99 for both settings and the workflow tool.
100
101 `/workflows` opens the run dashboard: every run this workspace's journal
102 keeps for the session — running and finished — newest first. Each row shows
103 the status token, the run's label, elapsed time, child count, and latest
104 progress; `Enter` opens the detail pane (run id, phases, the child roster
105 with per-child state, recent progress, and the error/result summary). `x`
106 cancels the selected running run through the same host path as `/workflow
107 cancel`, `r` re-reads the journal, and `Esc` closes. The dashboard never
108 launches anything — orchestration authority stays with `/workflow`.
109
110 ## What you see while it runs
111
112 - **Workflow panel** — phases, children, status
113 - **Compact history card** — one calm row that expands for detail
114 - **One artifact per delegated unit** — no duplicate “delegate + tool card”
115 - **Typed child identity** — labels/roles; no “unknown child” in the default UI
116
117 Cancel stops the run and child agents. Completed activity can persist across the
118 session (and across restarts when configured).
119
120 ## Sandbox guarantees
121
122 The Workflow JS VM has **no** filesystem, shell, network, env, imports, clock, or
123 randomness. Allowed host calls: `task`, `parallel`, `pipeline`, `phase`, `log`,
124 `budget`, `args`. Real work happens in sub-agents / fleet under normal tool and
125 approval policy. See [Sandbox](SANDBOX.md).
126
127 ## Synthesis and compatibility
128
129 - Prefer `responseSchema` on read-only children that must return structured fields.
130 Write-capable children retain their change and verification evidence contract.
131 - Ordinary failed parallel slots become `null` (partial success); filter them
132 before synthesizing one operator-facing summary. A `responseSchema` mismatch
133 is a contract failure and intentionally fails the run instead of being
134 silently converted to `null`.
135 - A `null` slot is no longer anonymous. `parallel()` and `pipeline()` attach a
136 non-enumerable `errors` array to the result — `[{ index, kind, message }]`,
137 ordered by index — so a synthesizer can say *why* a slot is missing. The
138 array's own contents and JSON encoding are unchanged.
139 - `kind` is one of `admission`, `budget`, `cancelled`, `agent`, `schema`,
140 `driver` (assigned by the host where the failure happened) or `script` (the
141 script threw it). Read it from the thrown `Error`'s `.kind`; it is never
142 inferred from message text, so a child's own prose cannot forge a kind.
143 - `opts.mode` selects the contract: `settled` (default — today's behavior),
144 `fail-fast` (reject the whole fan-out with the first non-fatal slot error),
145 or `partial` (resolve every non-cancellation failure to
146 `{ __taskError: { index, kind, message } }`). An unrecognized mode throws
147 rather than quietly reading as `settled`.
148 - A run whose every task failed is recorded as **failed**, not as a partial
149 success, even when the script itself returned a value.
150 - Native plans settle ordinary failures in singleton, sequential, and parallel
151 steps. Independent work continues; a failed or missing required result skips
152 its dependents without launching them. The receipt retains surviving results
153 and the skip reason. Partial loss is `degraded`; no surviving work is `failed`.
154 Cancellation and explicit schema-contract failures still stop the run.
155 - Legacy Workflow token budgets survive only for parse/receipt compatibility and
156 are absent from the advertised tool/plan schema. They are not caps. Aggregate token
157 accounting is unavailable: `budget.metered` is `false`, `budget.total` is
158 `null`, and `budget.spent()` and `budget.remaining()` return `null`. Actual
159 reported provider usage remains in child/run receipts.
160 - Model-authored child step, time, output and delegation-depth limits are not
161 runtime authority. Legacy fields remain parse-compatible but are ignored;
162 direct launch receipts identify ignored fields. Generated Workflow tasks omit
163 legacy token/step/time hints entirely. Configure actual owner limits through
164 the runtime's operator, role/Fleet, parent or saved-run controls. Stop remains
165 authoritative. Continue until the outcome is complete or a real blocker needs a handback.
166 - Compatibility paths remain: `script`, `source_path` (checked-in
167 `.workflow.js` / `.workflow.ts`), and structured `plan`.
168
169 ## Choosing orchestration
170
171 The model can use direct tools instead of a Workflow for:
172
173 - One-file edits and tiny one-step asks
174 - Simple commands / factual questions
175 - Highly interactive design conversations
176 - Risky writes without a clear decomposition
177 - Plans that would exceed `max_children` / `max_depth` (refused before launch)
178
179 These are planning choices, not task-size cutoffs. Use the decomposition the
180 work needs; only the configured structural and authority checks refuse launch.
181
182 ## Example scenarios (#4131)
183
184 Checked-in example workflows cover four automatic-Workflow scenarios:
185
186 1. Read-only repo audit
187 2. Staged bug fix with worktree implementer + verifier
188 3. Partial failure and synthesis
189 4. Cancellation mid-run
190
191 Fixtures: [`docs/examples/dogfood-automatic/`](examples/dogfood-automatic/).
192 Panel regression tests use the `dogfood_` prefix in
193 `crates/tui/src/tui/widgets/workflow_panel.rs`.
194
194 lines MARKDOWN