Task Decomposition Specification
Version: 1.1.0 Status: DRAFT Created: 2025-12-19 Updated: 2025-12-30 Target: v0.22.0+ Implementation Report: TASK-DECOMPOSITION-SPEC-IMPLEMENTATION-REPORT.mdv1.1.0 CHANGE: Refactored to be implementation-agnostic. Removed Bash-specific code, retained algorithms as pseudocode. This spec is now AUTHORITATIVE for decomposition principles, applicable to any implementation language (Python, Bash, TypeScript, etc.).
Part 1: Preamble
1.1 Purpose
This specification defines an LLM-agent-first task decomposition system for transforming high-level user requests into atomic, executable tasks. The system produces validated task DAGs (Directed Acyclic Graphs) with dependency relationships suitable for parallel or sequential agent execution.1.2 Authority
This specification is AUTHORITATIVE for:- Task decomposition algorithm phases
- Atomicity criteria and validation
- Dependency graph construction rules
- Challenge protocol for decomposition validation
- CLI integration (
decomposecommand) - JSON output schemas for decomposition results
- SPEC-BIBLE-GUIDELINES.md for document structure
- LLM-TASK-ID-SYSTEM-DESIGN-SPEC.md for task ID format
- HIERARCHY-ENHANCEMENT-SPEC.md for type/parentId/size fields
- LLM-AGENT-FIRST-SPEC.md for JSON output standards
- CONSENSUS-FRAMEWORK-SPEC.md for adversarial validation protocol
Part 2: RFC 2119 Conformance
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in BCP 14 [RFC 2119] [RFC 8174] when, and only when, they appear in all capitals, as shown here.Part 3: Executive Summary
3.1 Problem Statement
LLM agents struggle with:- Scope explosion: Large tasks exceed context windows
- Hallucinated dependencies: Assuming ordering that doesn’t exist
- Non-atomic tasks: Tasks that require hidden sub-decisions
- Parallel blindness: Treating everything as sequential
3.2 Solution Architecture
A 4-phase decomposition pipeline with adversarial validation:3.3 Core Principles
| Principle | Requirement |
|---|---|
| No Time Estimates | Size by scope (small/medium/large), NEVER hours/days |
| Evidence-Based Dependencies | Dependencies MUST be provable, not assumed |
| Atomicity Threshold | Tasks MUST pass 6-point atomicity criteria |
| Adversarial Validation | Each phase MUST survive challenge |
| HITL Gates | Ambiguity triggers human decision points |
| LLM-Agent-First Output | JSON with _meta envelope, structured errors |
Part 4: Atomicity Criteria (AUTHORITATIVE)
4.1 Six-Point Atomicity Test
A task is ATOMIC if and only if ALL of the following are TRUE:| # | Criterion | Test | Failure Indicator |
|---|---|---|---|
| 1 | Single File Scope | Affects ≤3 tightly-coupled files | Changes 4+ unrelated files |
| 2 | Single Cognitive Concern | One “thing” to understand | Requires context switching |
| 3 | Clear Acceptance Criteria | Testable completion condition | ”It works” is not testable |
| 4 | No Context Switching | Can complete in one focus session | Requires waiting for external input |
| 5 | No Hidden Sub-Decisions | All choices made at decomposition time | Agent must ask HITL during execution |
| 6 | Programmatic Validation | Result verifiable by code/test | Requires subjective human judgment |
4.2 Atomicity Score Calculation
4.3 Size-to-Atomicity Mapping
| Size | File Scope | Atomicity Expectation |
|---|---|---|
small | 1-2 files | MUST be atomic (score = 100) |
medium | 3-7 files | SHOULD be atomic, MAY need review |
large | 8+ files | MUST NOT be atomic, MUST decompose |
4.4 Examples
ATOMIC (score = 100):Part 5: Phase 1 - Scope Analyzer
5.1 Purpose
Assess input complexity and determine decomposition strategy before work begins.5.2 Inputs
5.3 Algorithm
5.4 Output Schema
5.5 Exit Codes
| Code | Constant | Meaning |
|---|---|---|
| 0 | EXIT_SUCCESS | Scope analysis complete |
| 2 | EXIT_INVALID_INPUT | Request is empty or malformed |
| 30 | EXIT_HITL_REQUIRED | Ambiguities require human input |
Part 6: Phase 2 - Goal Decomposer
6.1 Purpose
Recursively decompose goals into atomic tasks using HTN-inspired methods.6.2 Decomposition Methods (AUTHORITATIVE)
Each goal type has defined decomposition methods:| Goal Pattern | Method | Subtask Template |
|---|---|---|
implement_feature | Feature Decomposition | [schema, api, logic, ui, tests] |
fix_bug | Bug Fix Decomposition | [reproduce, diagnose, fix, verify] |
refactor_code | Refactor Decomposition | [analyze, plan, execute, verify] |
add_command | CLI Command Decomposition | [script, help, tests, docs] |
update_schema | Schema Migration | [schema, migration, validation, update-code] |
6.3 Algorithm
6.4 Challenge Protocol (Phase 2)
Per CONSENSUS-FRAMEWORK-SPEC Part 5.5, decomposition MUST be challenged: Challenge Questions:- “Can any of these subtasks be merged without losing clarity?”
- “Are there missing tasks required to achieve the goal?”
- “Does each subtask have clear, distinct acceptance criteria?”
- “Is the decomposition method appropriate for this goal pattern?”
- Logical counter-argument with specific subtask reference
- OR counter-example showing merge/split improves outcome
| Verdict | Condition |
|---|---|
| VALID | Challenge Agent finds no substantive issues |
| NEEDS_REVISION | Challenge Agent identifies fixable issues |
| REJECTED | Decomposition fundamentally flawed, restart |
6.5 Output Schema
Part 7: Phase 3 - Dependency Graph Builder
7.1 Purpose
Construct a validated DAG from the goal tree, identifying true dependencies and parallel opportunities.7.2 Dependency Types (AUTHORITATIVE)
| Type | Detection Method | Evidence Required |
|---|---|---|
| Explicit | Keywords: “after”, “requires”, “depends on” | Present in goal description |
| Data Flow | Output of A is input of B | Schema/type analysis |
| File Conflict | Both modify same file | File path intersection |
| API Contract | B calls API defined in A | Code/interface analysis |
| Semantic | Logical ordering (schema before queries) | Domain knowledge |
7.3 Algorithm
7.4 Challenge Protocol (Phase 3)
Challenge Questions:- “Is dependency X→Y proven or merely assumed?”
- “Can task A actually run in parallel with B?”
- “Are there hidden shared-state conflicts?”
- “What happens if task C fails - what are the ripple effects?”
| Claim | Required Evidence |
|---|---|
| ”A must complete before B” | Data flow proof OR explicit requirement |
| ”A and B can run in parallel” | No shared state, no ordering requirement |
| ”A blocks B on failure” | Error propagation path identified |
7.5 Output Schema
Part 8: Phase 4 - Task Specifier
8.1 Purpose
Generate schema-compliant task objects ready for insertion into cleo.8.2 Field Mapping
| DAG Field | todo.schema.json Field | Transformation |
|---|---|---|
node.id | id | Prefix with “T”, pad to 3+ digits |
node.title | title | Validate length ≤120 chars |
goal.type | type | Map: epic/task/subtask |
parent_node.id | parentId | Use parent’s task ID |
node.atomicityScore | size | ≤50→small, ≤80→medium, else→large |
edges[to=node] | depends | Collect all incoming edge sources |
goal.acceptance | acceptance | Array of testable criteria |
8.3 Algorithm
8.4 Challenge Protocol (Phase 4)
Challenge Questions:- “Can an LLM agent complete this task without HITL intervention?”
- “Is the scope truly minimal or can it be decomposed further?”
- “Are the acceptance criteria actually testable by code?”
- “Is the size classification accurate?”
8.5 Final Output Schema
Part 9: CLI Integration
9.1 Command Syntax
9.2 Command Options
| Option | Type | Default | Description |
|---|---|---|---|
<request> | string | required | Natural language request or structured input |
--file, -i | path | - | Read request from file |
--phase | string | current | Target phase for generated tasks |
--parent | task ID | - | Parent task for all generated tasks |
--dry-run | boolean | false | Preview without creating tasks |
--no-challenge | boolean | false | Skip adversarial validation (NOT RECOMMENDED) |
--eager-execution | boolean | false | Begin on stable spec sections (see 9.6) |
--format, -f | string | auto | Output format (json/text/markdown) |
--quiet, -q | boolean | false | Suppress non-essential output |
--verbose, -v | boolean | false | Show detailed phase outputs |
9.3 Exit Codes
| Code | Constant | Meaning |
|---|---|---|
| 0 | EXIT_SUCCESS | Decomposition complete, tasks created |
| 2 | EXIT_INVALID_INPUT | Request empty or malformed |
| 6 | EXIT_VALIDATION_ERROR | Generated tasks fail schema validation |
| 10 | EXIT_PARENT_NOT_FOUND | Specified --parent doesn’t exist |
| 11 | EXIT_DEPTH_EXCEEDED | Would exceed max hierarchy depth |
| 12 | EXIT_SIBLING_LIMIT | Would exceed max sibling count |
| 14 | EXIT_CIRCULAR_REFERENCE | DAG contains cycles |
| 30 | EXIT_HITL_REQUIRED | Decomposition blocked by ambiguity |
| 31 | EXIT_CHALLENGE_REJECTED | Challenge agent rejected decomposition |
| 35 | EXIT_ATOMICITY_FAILED | Tasks fail atomicity criteria (score < 100) |
| 102 | EXIT_NO_CHANGE | Request already decomposed (idempotent) |
9.4 Error Codes
| Code | Exit Code | Description |
|---|---|---|
E_DECOMPOSE_EMPTY_INPUT | 2 | No request provided |
E_DECOMPOSE_AMBIGUOUS | 30 | Request has unresolved ambiguities |
E_DECOMPOSE_CYCLE | 14 | Generated DAG has cycles |
E_DECOMPOSE_REJECTED | 31 | Challenge agent rejected decomposition |
E_DECOMPOSE_ATOMICITY | 35 | Tasks fail atomicity criteria |
E_DECOMPOSE_DEPTH | 11 | Recursive decomposition exceeded depth |
E_DECOMPOSE_SIBLINGS | 12 | Too many sibling tasks generated |
9.5 Implementation Pipeline (Language-Agnostic)
v1.1.0 CHANGE: Implementation-specific code removed. See pseudocode below.The decompose command MUST implement the following pipeline:
- Implementations MUST follow the 4-phase pipeline order
- Challenge validation at each phase is RECOMMENDED (skip with
--no-challenge) - HITL gates MUST block execution until user input received
- All exit codes MUST match those in Part 9.3
9.6 Eager Execution Mode
v1.1.0 ADDITION: From RCSD Pipeline v1.1 ct-decompose specification.When
--eager-execution is enabled, decomposition MAY begin on stable (non-provisional)
spec sections before the full specification is finalized.
Provisional Task Marking:
Tasks generated from incomplete or provisional spec sections MUST be marked:
- Provisional tasks MUST NOT be scheduled for execution
- Provisional tasks MUST be re-validated when source spec finalizes
- Removing
provisional: truerequires atomicity re-check
- Large specifications where some sections are stable
- Parallel spec writing and task planning
- Early dependency graph visualization
Part 10: Core Functions (Language-Agnostic)
v1.1.0 CHANGE: Bash-specific library code removed. Functions defined as abstract specifications.
10.1 Required Function Signatures
Implementations MUST provide the following functions. Return types are JSON objects.10.2 Implementation Notes
- All functions MUST return valid JSON per LLM-AGENT-FIRST-SPEC
analyze_scopeMAY use heuristics for simple cases, SHOULD use LLM for complex casesdecompose_goalsMUST use LLM invocation per Part 18challenge_decompositionMUST spawn separate agent with adversarial prompts- Implementations MAY add language-specific optimizations while maintaining interface compliance
Part 11: Agent Invocation Pattern
11.1 LLM Agent Prompt for Goal Decomposition
11.2 Challenge Agent Prompt
Part 12: HITL Gate Integration
12.1 Gate Triggers
Decomposition MUST trigger HITL when:| Condition | Gate Type | Action |
|---|---|---|
| Request has multiple interpretations | ambiguity | Present options, request choice |
| Scope exceeds single-session viability | scope | Confirm epic creation |
| External system dependencies detected | external | Confirm integration approach |
| >2 valid decomposition approaches | method | Present options with trade-offs |
| Challenge agent raises blocking issue | challenge | Present finding, request decision |
12.2 Gate Output Format
Part 13: Testing Requirements
13.1 Unit Tests
13.2 Integration Tests
13.3 Challenge Tests
Part 14: Performance Requirements
14.1 Latency Targets
| Phase | Target | Max |
|---|---|---|
| Scope Analysis | <500ms | 2s |
| Goal Decomposition | <5s | 30s |
| Dependency Graph | <1s | 5s |
| Task Specification | <500ms | 2s |
| Challenge (per phase) | <10s | 60s |
| Total (with challenge) | <20s | 120s |
14.2 Scaling Limits
| Metric | Limit | Reason |
|---|---|---|
| Tasks per decomposition | 50 | Context window preservation |
| Depth | 3 | Per TASK-HIERARCHY-SPEC |
| Siblings | 7 | Per TASK-HIERARCHY-SPEC |
| Parallel DAG width | 10 | Practical execution limit |
| Request length | 10,000 chars | Prompt size management |
Part 15: Security Considerations
15.1 Input Validation
- Request text MUST be sanitized before LLM prompts
- File paths in
--fileMUST be validated (no path traversal) - Parent IDs MUST be validated against existing tasks
15.2 Output Integrity
- Generated task IDs MUST use sequential allocation (no user input)
- Decomposition results SHOULD be checksummed
- Challenge results MUST NOT be editable by decomposition agent
15.3 Prompt Injection Prevention
- User request MUST be isolated in prompt (not interpolated)
- JSON outputs MUST be validated before use
- LLM outputs MUST NOT be executed as code without sandboxing
Part 16: Conformance
16.1 Conformance Classes
A conforming implementation MUST:- Implement all 4 phases (scope, goals, dag, tasks)
- Apply atomicity criteria per Part 4
- Validate DAG for cycles before output
- Produce JSON matching output schemas
- Support all exit codes defined in Part 9.3
- Source required libraries per LLM-AGENT-FIRST-SPEC
- Implement challenge protocol per Part 6.4, 7.4, 8.4
- Support HITL gates per Part 12
- Meet latency targets per Part 14.1
- Use alternative decomposition methods beyond Part 6.2
- Extend atomicity criteria beyond Part 4.1
- Add additional output fields to schemas
Part 17: Related Specifications
| Document | Relationship |
|---|---|
| SPEC-BIBLE-GUIDELINES.md | AUTHORITATIVE for document structure |
| LLM-AGENT-FIRST-SPEC.md | AUTHORITATIVE for JSON output, exit codes, error handling |
| HIERARCHY-ENHANCEMENT-SPEC.md | AUTHORITATIVE for type/parentId/size, depth/sibling limits |
| LLM-TASK-ID-SYSTEM-DESIGN-SPEC.md | AUTHORITATIVE for task ID format |
| CONSENSUS-FRAMEWORK-SPEC.md | AUTHORITATIVE for challenge protocol, evidence standards |
| PHASE-SYSTEM-SPEC.md | Related for phase assignment |
| RCSD-PIPELINE-SPEC.md | Stage: This spec implements the DECOMPOSE stage of the RCSD Pipeline (Part 4) |
Part 18: LLM Invocation Architecture (AUTHORITATIVE)
This section addresses Finding 5 (BLOCKING): LLM invocation pattern unclear.18.1 Token Budget Allocation
| Phase | Max Input Tokens | Max Output Tokens | Model Tier |
|---|---|---|---|
| Scope Analysis | 2,000 | 1,000 | Fast (Haiku) |
| Goal Decomposition | 8,000 | 4,000 | Standard (Sonnet) |
| Dependency Graph | 4,000 | 2,000 | Fast (Haiku) |
| Task Specification | 4,000 | 3,000 | Fast (Haiku) |
| Challenge (per phase) | 6,000 | 2,000 | Standard (Sonnet) |
18.2 Invocation Decision Matrix
18.3 Prompt Template Architecture
18.4 Model Selection Logic
v1.1.0 CHANGE: Bash-specific code removed. Selection logic as decision table.
| Tier | Claude Models | OpenAI Models | Purpose |
|---|---|---|---|
fast | claude-3-haiku | gpt-4o-mini | Structured extraction, low latency |
standard | claude-sonnet-4 | gpt-4o | Complex reasoning, adversarial |
capable | claude-opus-4 | o3 | Maximum capability (reserved) |
18.5 Fallback Strategy
If LLM invocation fails:| Failure Type | Fallback Action |
|---|---|
| Rate limit | Exponential backoff (1s, 2s, 4s, max 30s) |
| Timeout | Return partial result with incomplete: true |
| Invalid output | Retry once with stricter schema enforcement |
| Model unavailable | Fall back to simpler model tier |
Part 19: Dependency Detection Algorithms (AUTHORITATIVE)
This section addresses Finding 3 (BLOCKING): Dependency detection underspecified.19.1 Detection Functions
19.2 Confidence Thresholds
| Confidence | Action |
|---|---|
| ≥0.9 | Auto-include dependency |
| 0.7-0.89 | Include, flag for challenge review |
| 0.5-0.69 | Require HITL confirmation |
<0.5 | Reject, log as “considered but excluded” |
19.3 Transitive Dependency Resolution
19.4 Anti-Hallucination Validation
Every dependency MUST have:- Type from defined set:
explicit | data_flow | file_conflict | api_contract | semantic - Evidence string explaining the relationship
- Confidence score 0.0-1.0
evidence: null or evidence: "assumed" MUST be rejected.
Part 20: Generic Decomposition Fallback (AUTHORITATIVE)
This section addresses Finding 2: Generic decomposition method undefined.20.1 Fallback Method
When no pattern-specific method matches:20.2 Recursive Application
If3_implement fails atomicity (score < 100), recursively apply:
20.3 Method Priority Order
- Exact pattern match (e.g.,
implement_feature) - Partial pattern match (regex similarity > 0.8)
- LLM-suggested method (if enabled)
- Generic fallback
Part 21: Challenge Quality Metrics (AUTHORITATIVE)
This section addresses Finding 4: Challenge agent quality metrics missing.21.1 Finding Severity Classification
| Severity | Criteria | Required Action |
|---|---|---|
| blocking | Decomposition fundamentally broken | REJECT, require restart |
| major | Missing/incorrect tasks or dependencies | REVISE before proceeding |
| minor | Style, naming, or optimization issues | LOG, optional fix |
| info | Suggestions for improvement | DOCUMENT for future |
21.2 Challenge Quality Scoring
21.3 Rubber-Stamp Detection
Challenge agent outputs are suspect if:verdict: "VALID"withfindings.length == 0- All findings are
severity: "info" - Challenge completed in
<2seconds - No specific task/edge references
21.4 Minimum Challenge Requirements
Every challenge MUST produce at least:- 2 findings (even if
severity: info) - 1 specific reference to task or edge
- 1 actionable suggestion
Part 22: Iteration and Retry Protocol (AUTHORITATIVE)
This section addresses Finding 6: No iteration/retry protocol.22.1 Retry Configuration
22.2 Phase Retry Logic
22.3 Challenge-Revision Loop
22.4 State Preservation
Between retries, preserve:- Original request (immutable)
- Phase outputs completed successfully
- Challenge findings for learning
- Retry count per phase
Part 23: Schema Extensions (AUTHORITATIVE)
This section addresses Finding: Schema considerations for children and computed fields.23.1 Proposed Schema Additions
The following fields SHOULD be added totodo.schema.json v2.4.0:
23.2 Computed Field Calculation
v1.1.0 CHANGE: Bash-specific code removed. Algorithms as pseudocode.Computed fields are NOT stored in todo.json but calculated on read:
23.3 Materialization Strategy
For performance, computed fields MAY be materialized:- On write: Update
children/dependentswhenparentId/dependschanges - On read: Always compute
blockedBy(status-dependent) - Cache: Store in separate
.cleo/computed-cache.jsonwith TTL
23.4 Backward Compatibility
New fields MUST be:- Optional in schema (not
required) - Handled gracefully by older CLI versions
- Migrated via
cleo migrate run
Appendix A: Decomposition Method Library
A.1 Feature Implementation
A.2 Bug Fix
A.3 CLI Command
Appendix B: Changelog
Version 1.0.0 (2025-12-19)
- Initial specification
- 4-phase decomposition pipeline
- Atomicity criteria (6-point test)
- HTN-inspired goal decomposition
- DAG construction with cycle detection
- Challenge protocol integration
- CLI command specification
- Library function definitions
- Test requirements
- Performance targets
End of Specification
