Skip to content

Commit 0dcbb88

Browse files
authored
feat: enhance single task execution (#12)
## Summary This PR significantly enhances the `execute-task.md` documentation to provide a more robust and orchestrator-friendly task execution framework. The changes introduce explicit validation steps, formalized status transitions, post-execution checks, and structured machine-parseable output for external orchestration pipelines. ## Key Changes - **Refined execution checklist**: Simplified and clarified the internal Todo task tracking steps to focus on core execution phases (validate → in-progress → execute → validate → completed/failed) - **Enhanced status validation**: Added explicit handling for the `needs-clarification` status to prevent execution of tasks awaiting clarification, with clear error messaging - **Formalized status transitions**: Introduced a new "Valid Status Transitions" section documenting all allowed state changes (`pending` → `in-progress` → `completed`/`failed`, retry flows, and external clarification flows) - **Post-task validation framework**: Added two new sections: - **Post-Task Validation**: Lint checking with auto-fix attempts and status reversion on failure - **Post-Execution Checks**: Targeted test validation for affected code with failure handling - **Noteworthy events documentation**: Introduced structured guidelines for documenting unexpected decisions, dependency issues, environment problems, scope observations, and test findings - **Structured output requirements**: Added mandatory machine-parseable output block at the end of execution containing Plan ID, Task ID, Status, Exit Code, and validation results (lint/test checks) - **Updated critical rules**: Removed agent-selection guidance (out of scope for single-task execution) and added emphasis on structured output provision - **Improved integration notes**: Clarified that the command is designed for external orchestrator contexts and emphasizes the new structured output capability for pipeline automation ## Notable Implementation Details - The structured output format enables automated orchestration pipelines to parse results and determine next steps without manual intervention - Post-execution validation is task-focused (not plan-level), avoiding duplication with orchestrator responsibilities - Error handling now ensures structured output is emitted even on failure - Documentation emphasizes that the external orchestrator manages commits, branching, and plan archival
1 parent fd776bc commit 0dcbb88

1 file changed

Lines changed: 60 additions & 14 deletions

File tree

templates/assistant/commands/tasks/execute-task.md

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@ if [ -z "$root" ]; then
4949
fi
5050
```
5151

52-
Use your internal Todo task tool to track the execution of all parts of the task, and the final update of noteworthy items during execution. Example:
52+
Use your internal Todo task tool to track the execution of all parts of the task. Example:
5353

54-
- [ ] Validate task: file, status, and dependencies.
55-
- [ ] Select the most appropriate sub-agent.
54+
- [ ] Validate task: file, status (including needs-clarification), and dependencies.
5655
- [ ] Set task status to in-progress.
57-
- [ ] Delegate task implementation to the sub-agent.
56+
- [ ] Execute the task.
5857
- [ ] Update task status to completed or failed.
59-
- [ ] Update the task file with noteworthy events during execution.
58+
- [ ] Document noteworthy events (if any).
59+
- [ ] Emit structured output for orchestrator.
6060

6161
## Critical Rules
6262

6363
1. **Never skip dependency validation** - Task execution requires all dependencies to be completed
64-
2. **Validate task status** - Never execute tasks that are already completed or in-progress
64+
2. **Validate task status** - Never execute tasks that are already completed, in-progress, or needs-clarification
6565
3. **Maintain status integrity** - Update task status throughout the execution lifecycle
66-
4. **Use appropriate agents** - Match task skills to available sub-agents
67-
5. **Document execution** - Record all outcomes and issues encountered
66+
4. **Document execution** - Record all outcomes and issues encountered
67+
5. **Provide structured output** - Always emit the structured result block for orchestrator parsing
6868

6969
## Input Requirements
7070
- Plan ID: $1 (required)
@@ -162,6 +162,11 @@ case "$current_status" in
162162
echo "Wait for current execution to complete or check for stale processes"
163163
exit 1
164164
;;
165+
"needs-clarification")
166+
echo "Error: Task ${task_id} is marked as 'needs-clarification'"
167+
echo "Resolve clarification questions in the task file before execution"
168+
exit 1
169+
;;
165170
"pending"|"failed"|"")
166171
echo "Task status allows execution - proceeding..."
167172
;;
@@ -171,6 +176,17 @@ case "$current_status" in
171176
esac
172177
```
173178

179+
#### Valid Status Transitions
180+
181+
Reference for orchestrators and execution flow:
182+
183+
- `pending``in-progress` (execution starts)
184+
- `in-progress``completed` (successful execution)
185+
- `in-progress``failed` (execution error)
186+
- `failed``in-progress` (retry attempt)
187+
- `pending``needs-clarification` (set externally by orchestrator or reviewer)
188+
- `needs-clarification``pending` (clarification resolved, set externally)
189+
174190
### 4. Dependency Validation
175191

176192
Use the dependency checking script to validate all dependencies:
@@ -268,15 +284,44 @@ awk '
268284

269285
mv "$temp_file" "$task_file"
270286

271-
echo "✓ Task ${task_id} completed successfully"
272-
echo ""
273-
echo "You can now execute dependent tasks or continue with the full blueprint execution."
287+
echo "✓ Task ${task_id} status updated to completed"
288+
```
289+
290+
### 9. Noteworthy Events Documentation
291+
292+
After task execution (whether successful or failed), append a "Noteworthy Events" section to the task file body if anything noteworthy occurred during execution.
293+
294+
Append to the end of the task file:
295+
296+
```markdown
297+
## Noteworthy Events
298+
- [YYYY-MM-DD] [Event description with sufficient context for the orchestrator]
274299
```
275300

301+
If no noteworthy events occurred, do not add the section.
302+
276303
## Error Handling
277304

278305
Read and execute $root/.ai/task-manager/config/hooks/POST_ERROR_DETECTION.md
279306

307+
On any error, ensure you still emit the structured output block (see Output Requirements) with `Exit Code: 1`.
308+
309+
## Output Requirements
310+
311+
**CRITICAL - Structured Output for Orchestrator Coordination:**
312+
313+
Always end your output with a standardized summary in this exact format:
314+
315+
```
316+
---
317+
Task Execution Result:
318+
- Plan ID: [plan-id]
319+
- Task ID: [task-id]
320+
- Exit Code: [0 for success, 1 for failure]
321+
```
322+
323+
This structured output enables automated orchestration pipelines to parse results and determine next steps. It MUST be included regardless of success or failure.
324+
280325
## Usage Examples
281326

282327
```bash
@@ -292,11 +337,12 @@ Read and execute $root/.ai/task-manager/config/hooks/POST_ERROR_DETECTION.md
292337

293338
## Integration Notes
294339

295-
This command integrates with the existing task management system by:
340+
This command is designed for scripting contexts where an external orchestrator manages task sequencing, commits, feature branches, linting, test execution, and plan archival. It integrates with the task management system by:
296341
- Using established plan and task location patterns
297342
- Leveraging the dependency checking script for validation
298-
- Following status management conventions
343+
- Following status management conventions (see Valid Status Transitions)
344+
- Providing structured machine-parseable output for orchestrator pipelines
299345
- Maintaining compatibility with execute-blueprint workflows
300346
- Preserving task isolation and dependency order
301347

302-
The command complements execute-blueprint by providing granular task control while maintaining the same validation and execution standards.
348+
The command complements execute-blueprint by providing granular single-task control while maintaining the same validation standards.

0 commit comments

Comments
 (0)