返回 CodeWhale
FLEET_WORKFLOW_TUTORIAL.md
根目录 / docs / FLEET_WORKFLOW_TUTORIAL.md
1 # Fleet + Workflow Tutorial
2
3 > 阅读简体中文版:[zh_hans/FLEET_WORKFLOW_TUTORIAL.md](zh_hans/FLEET_WORKFLOW_TUTORIAL.md)。
4
5 Fleet and Workflow are meant to work together, but they solve different parts
6 of the problem:
7
8 - **Fleet** configures and manages the same sub-agents: reusable roles, model
9 routes, permissions, logs, artifacts, and status/restart/stop controls.
10 - **Workflow** describes orchestration: phases, branches, reducers, loops, and
11 agent leaves that can dispatch through the fleet/sub-agent runtime.
12
13 **Default product path:** ask in natural language. Work handles small or
14 tightly coupled work directly under the active posture. Multi-step delegation
15 uses a compact Workflow plan with named steps, dependencies, bounded scopes,
16 and completion checks; results and evidence pass to the steps that need them.
17 One bounded, independent task can use a direct background agent. Reuse that
18 agent with `followup` for continued work. Background work keeps the composer
19 available, and ordinary multi-agent work does not require workflow files. Details:
20 [Automatic Workflows](AUTOMATIC_WORKFLOWS.md).
21
22 This tutorial covers the **manual** fleet task-spec / checked-in Workflow path
23 for operators who want durable host workers and reviewable specs. A
24 one-sentence request should still not silently generate `tasks.json`; worker
25 cards and permission posture make dispatch visible without exposing authoring
26 mechanics.
27
28 The examples use `codewhale fleet` and `/fleet`.
29 On-disk paths, config keys, and the Workflow `--fleet` flag use the Fleet name.
30
31 ## 1. Prepare The Workspace
32
33 Run fleet from the workspace you want workers to inspect or modify:
34
35 ```sh
36 codewhale fleet init
37 ```
38
39 This creates the workspace ledger at `.codewhale/fleet.jsonl`. Worker logs and
40 bounded artifacts live under `.codewhale/fleet/`; host adapter logs live under
41 `.codewhale/fleet-host/`.
42
43 If you want named reusable workers, open the TUI and run:
44
45 ```text
46 /fleet setup
47 ```
48
49 Pick a role, choose whether that profile inherits the operator route or pins a
50 specific provider/model, choose where the profile lives (**This project** →
51 `.codewhale/agents/<role>.toml`, or **Personal** →
52 `$CODEWHALE_HOME/agents/<role>.toml`, available across repositories while a
53 same-id project profile remains the higher-priority override), then review the
54 exact file, permissions/tools/route posture, and save. The save control names
55 its effect ("Save to this project" / "Save as Personal profile"), and
56 replacing an existing file always asks for a second confirmation. fleet task
57 specs can reference either resolved profile with `worker.agent_profile` or the
58 shorter `worker.profile` alias.
59
60 This makes the fleet definition cross-repository, not the authority of one
61 running session. For a multi-repository operation, launch Codewhale from a
62 shared parent workspace. Profile availability does not grant filesystem access;
63 the session's workspace, explicit trusted paths, trust mode, and permission
64 posture remain authoritative.
65
66 ## 2. Write A fleet Task Spec
67
68 `codewhale fleet run` accepts JSON or TOML. The checked-in
69 `docs/examples/fleet-dogfood.toml` file is the realistic manual smoke example;
70 the JSON below shows the same authoring shape with one read-only reviewer and
71 one bounded docs-note worker. The live Runtime policy controls secrets and
72 trust; fleet identity carries neither.
73
74 ```json
75 {
76 "name": "docs readiness check",
77 "labels": {
78 "kind": "tutorial"
79 },
80 "tasks": [
81 {
82 "id": "map-docs",
83 "name": "Map current docs",
84 "objective": "Find the docs that describe fleet and Workflow.",
85 "instructions": "Read docs/FLEET.md and docs/WORKFLOW_AUTHORING.md. Report the command surfaces, current limitations, and any confusing gaps.",
86 "worker": {
87 "role": "reviewer",
88 "tools": [
89 "rg",
90 "sed",
91 "git"
92 ]
93 },
94 "workspace": {
95 "required_files": [
96 "docs/FLEET.md",
97 "docs/WORKFLOW_AUTHORING.md"
98 ],
99 "writable_paths": [],
100 "environment": {
101 "required": [],
102 "allowlist": []
103 }
104 },
105 "input_files": [
106 "docs/FLEET.md",
107 "docs/WORKFLOW_AUTHORING.md"
108 ],
109 "expected_artifacts": [
110 "log",
111 "report"
112 ],
113 "scorer": {
114 "kind": "manual"
115 },
116 "retry_policy": {
117 "max_attempts": 1
118 }
119 },
120 {
121 "id": "draft-gap-note",
122 "name": "Draft gap note",
123 "objective": "Draft a short local note for any missing tutorial steps.",
124 "instructions": "Write a concise Markdown note with the missing fleet + Workflow tutorial steps. Do not edit public docs unless explicitly asked.",
125 "worker": {
126 "role": "builder",
127 "tools": [
128 "rg",
129 "sed"
130 ]
131 },
132 "workspace": {
133 "required_files": [
134 "docs/FLEET.md"
135 ],
136 "writable_paths": [
137 ".codewhale/fleet"
138 ],
139 "environment": {
140 "allowlist": []
141 }
142 },
143 "expected_artifacts": [
144 "log",
145 "report"
146 ],
147 "scorer": {
148 "kind": "manual"
149 }
150 }
151 ]
152 }
153 ```
154
155 Save it as `tasks.json`. These workers inherit the active provider and model;
156 connect a provider before validating their route. `--check` validates the
157 specification and route without creating or launching a run; it does not
158 prove that credentials or a remote model work.
159
160 Common task fields:
161
162 | Field | Purpose |
163 | --- | --- |
164 | `id`, `name` | Stable task identity and display name. |
165 | `objective`, `instructions` | The worker goal and exact operating instructions. |
166 | `worker.role` | Built-in or custom role intent, such as `reviewer`, `builder`, `read-only`, or `smoke-runner`. |
167 | `worker.profile` / `worker.agent_profile` | Saved fleet roster profile resolved from project `.codewhale/agents/`, personal `$CODEWHALE_HOME/agents/`, or `[fleet.profiles]`. |
168 | `worker.tools` | Tool names the task expects the worker to use. |
169 | `worker.model` | Preferred explicit model pin. Route resolution still owns provider/model validation. |
170 | `worker.model_class`, `worker.loadout` | Compatibility routing hints for older task specs; prefer `worker.profile` plus saved profile route pins for new specs. |
171 | `workspace.required_files` | Files that must exist before the task starts. |
172 | `workspace.writable_paths` | Paths the task is allowed to write when the effective runtime posture allows writing. |
173 | `workspace.environment` | Required or allowlisted environment variables, by name only. |
174 | `input_files`, `context` | Extra files and strings to thread into the task prompt. |
175 | `expected_artifacts` | Artifact kinds to expect: `log`, `report`, `patch`, `test_result`, `checkpoint`, or `receipt`. |
176 | `scorer` | Deterministic or manual verification rule. |
177 | `retry_policy`, `timeout_seconds`, `budget` | Retry and budget controls. |
178
179 Do not put `security_policy` or worker `trust_level` in a new fleet task spec.
180 Those legacy fields remain readable only for old ledger replay and new-run
181 validation rejects them. Project trust, filesystem/network reach, secrets,
182 approvals, sandboxing, and tool authority are Runtime policy inputs.
183
184 ## 3. Start And Monitor fleet
185
186 Launch the run:
187
188 ```sh
189 codewhale fleet run tasks.json --max-workers 4
190 ```
191
192 The command prints the run id and worker ids. In another terminal, monitor the
193 ledgered state:
194
195 ```sh
196 codewhale fleet status
197 codewhale fleet inspect <worker-id>
198 codewhale fleet logs <worker-id>
199 codewhale fleet artifacts <worker-id>
200 ```
201
202 Use typed controls when a worker needs intervention:
203
204 ```sh
205 codewhale fleet interrupt <worker-id>
206 codewhale fleet restart <worker-id>
207 codewhale fleet resume <run-id>
208 codewhale fleet stop --all
209 ```
210
211 `resume` is for restart recovery after a manager exit, laptop sleep, or stale
212 lease. It replays the ledger and reconciles stale work without creating a new
213 run.
214
215 ## 4. Author A Workflow
216
217 Workflow source is declarative JavaScript or TypeScript that lowers to typed
218 Rust `WorkflowSpec`. It is not a general JavaScript runtime: imports, process
219 access, filesystem reads/writes, network calls, `eval`, `async`, and `await`
220 are rejected.
221
222 Create a checked-in file such as `workflows/docs_readiness.workflow.js`. The
223 repo also includes `.codewhale/workflows/issue_audit.workflow.js` as a maintained example.
224
225 ```js
226 export default workflow({
227 "id": "docs-readiness",
228 "goal": "Inspect fleet and Workflow docs, then synthesize a readiness note",
229 "nodes": [
230 {
231 "branch": {
232 "id": "parallel-docs-audit",
233 "parallel": true,
234 "children": [
235 {
236 "agent": {
237 "id": "fleet-docs",
238 "prompt": "Inspect docs/FLEET.md for command and task-spec coverage.",
239 "agent_type": "review",
240 "mode": "read_only",
241 "profile": "reviewer",
242 "file_scope": ["docs/FLEET.md"]
243 }
244 },
245 {
246 "agent": {
247 "id": "workflow-docs",
248 "prompt": "Inspect docs/WORKFLOW_AUTHORING.md for Workflow authoring coverage.",
249 "agent_type": "review",
250 "mode": "read_only",
251 "profile": "reviewer",
252 "file_scope": ["docs/WORKFLOW_AUTHORING.md"]
253 }
254 }
255 ]
256 }
257 },
258 {
259 "reduce": {
260 "id": "readiness-summary",
261 "inputs": ["fleet-docs", "workflow-docs"],
262 "prompt": "Summarize the exact docs gaps and the safest next edit."
263 }
264 }
265 ]
266 });
267 ```
268
269 Current Workflow node wrappers are `agent`, `branch`, `sequence`, and `reduce`.
270 `agent.profile` names a fleet roster profile; explicit agent fields override
271 profile defaults.
272
273 The model-facing `workflow` tool can start, run, inspect, or cancel a workflow
274 from inline source or a `source_path`. When Codewhale uses this path, ask it to
275 show the plan first if the workflow will launch multiple workers or touch files.
276
277 ## 5. Natural Language Intake
278
279 A good prompt today is:
280
281 ```text
282 Draft a fleet task spec for this goal, but do not run it yet.
283 Show the proposed tasks, worker profiles, writable paths, expected artifacts,
284 scorers, and security policy. Keep secrets disabled unless I explicitly grant
285 them.
286 ```
287
288 After reviewing the generated spec, save it as `tasks.json` and run the fleet
289 commands above. For workflows, ask Codewhale to draft a `.workflow.js` file,
290 show the plan, and use the workflow tool path only after approval.
291
292 This review step is intentional. It keeps provider routing, DeepSeek or other
293 model support, writable paths, network access, and secret use explicit before
294 durable workers start.
295
295 lines MARKDOWN