Plan Parser¶
Plan file parsing for task generation.
Parse implementation plan files into structured task definitions.
When an agent completes a task that results in an implementation plan
(written to .claude/plan.md or a similar file in the workspace), this
module reads the plan file, parses its markdown content, and extracts
individual steps that can be turned into follow-up tasks.
Classes¶
PlanQualityReport
dataclass
¶
PlanQualityReport(is_design_doc: bool, is_implementation_plan: bool, quality_score: float, total_sections: int, actionable_sections: int, filtered_sections: int, actionable_ratio: float, warnings: list[str] = list(), recommendation: str = '')
Quality assessment of a parsed plan document.
PlanStep
dataclass
¶
A single actionable step extracted from an implementation plan.
ParsedPlan
dataclass
¶
The result of parsing a plan file.
Functions¶
find_plan_file ¶
Search for a plan file in the workspace directory.
Checks each candidate pattern in order. Patterns that contain glob
characters (* or ?) are expanded; the most-recently-modified
match is returned so that freshly written plans take priority.
For plain (non-glob) patterns the file is checked directly.
If no pattern matches, falls back to a deep scan that looks for recently-modified markdown files with plan-like structure indicators (e.g. headings containing "Phase 1:", "Step 2:", etc.).
Returns the first match, or None if no plan file is found.
Source code in src/plan_parser.py
read_plan_file ¶
parse_plan ¶
Parse plan markdown content into structured steps.
Supports several common plan formats:
-
Implementation-section plans — Large design documents with a dedicated
## Implementation Planor similar section containing###sub-headings for each phase. Only the sub-headings within the implementation section become steps. -
Heading-based plans — Each
## Sectionor### Sectionbecomes a step, with the text underneath as the description. -
Numbered-list plans — Top-level numbered items (
1. ...,2. ...) become individual steps with the item text and any indented sub-items as the description. -
Mixed — If both heading sections and numbered lists are present, heading sections take priority.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
Raw markdown content of the plan file. |
required |
source_file
|
str
|
Path to the plan file (for traceability). |
''
|
max_steps
|
int
|
Maximum number of steps to return (truncated if exceeded). |
5
|
Returns a ParsedPlan containing the ordered list of steps.
Source code in src/plan_parser.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | |
build_task_description ¶
build_task_description(step: PlanStep, parent_task: object | None = None, plan_context: str = '') -> str
Build a self-contained task description from a plan step.
The description is enriched with context from the parent task and the overall plan so that the executing agent has all the information it needs without access to external context.
When the step description contains multiple sub-steps (e.g. from consolidation or a well-structured phase), a high-level outline is extracted and presented prominently so the agent can see all the work in the phase at a glance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
PlanStep
|
The parsed plan step. |
required |
parent_task
|
object | None
|
The parent task object (must have .title and .description). |
None
|
plan_context
|
str
|
Additional context from the plan preamble. |
''
|
Returns:
| Type | Description |
|---|---|
str
|
A self-contained description string. |
Source code in src/plan_parser.py
validate_plan_quality ¶
Assess the quality of a plan document for task splitting.
Analyzes the markdown content to determine whether it is an actionable implementation plan or a design/reference document, and scores it accordingly.
Source code in src/plan_parser.py
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 | |
parse_and_generate_steps ¶
parse_and_generate_steps(content: str, *, max_steps: int = 5, enforce_quality: bool = False, min_quality_score: float = 0.3) -> tuple[list[dict], PlanQualityReport]
Parse a plan document and return steps as dicts with a quality report.
This is the main orchestrator integration point. It combines
parse_plan() with validate_plan_quality() and applies an
additional post-filter to remove any remaining non-actionable steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
Raw markdown content. |
required |
max_steps
|
int
|
Maximum number of steps to return. |
5
|
enforce_quality
|
bool
|
If True, return no steps when quality is below threshold. |
False
|
min_quality_score
|
float
|
Minimum quality score (used when enforce_quality=True). |
0.3
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
A tuple of (steps, quality_report) where each step is a dict with |
PlanQualityReport
|
|