Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ uv tool install claude-task-master --force --reinstall
├── state.json # Machine state
├── progress.md # Progress summary
├── context.md # Accumulated learnings
├── coding-style.md # Coding style guide (generated from CLAUDE.md)
├── mailbox.json # Pending messages for plan updates
├── logs/
│ └── run-*.txt # Last 10 logs kept
Expand All @@ -119,7 +120,7 @@ uv tool install claude-task-master --force --reinstall

## Exit Codes

- **0 (Success)**: Tasks done, cleanup all except logs/, keep last 10 logs
- **0 (Success)**: Tasks done, cleanup all except logs/ and coding-style.md, keep last 10 logs
- **1 (Blocked)**: Need intervention, keep everything for resume
- **2 (Interrupted)**: Ctrl+C, keep everything for resume

Expand Down Expand Up @@ -177,11 +178,22 @@ All commands check `state_manager.exists()` first:
- Uses `PlanUpdater` to integrate change request into existing plan
- Preserves completed tasks, modifies pending tasks as needed

### Coding Style Generation
- Before planning, generates `coding-style.md` if it doesn't exist
- Analyzes `CLAUDE.md` and convention files to extract:
- Development workflow (TDD, test-first patterns)
- Code style conventions (naming, formatting)
- Project-specific requirements
- Concise guide (~600 words) injected into planning and work prompts
- Preserved across runs (not deleted on success) to save tokens
- Uses Opus for high-quality extraction

### Planning Prompt
- Instructs Claude to add `.claude-task-master/` to .gitignore
- Use Read, Glob, Grep to explore codebase
- Create task list with checkboxes
- Define success criteria
- Includes coding style guide for task planning

## Testing

Expand Down
27 changes: 25 additions & 2 deletions src/claude_task_master/core/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,35 @@ def _import_sdk(self) -> None:
ValueError("query must be callable"),
)

def run_planning_phase(self, goal: str, context: str = "") -> dict[str, Any]:
def run_planning_phase(
self, goal: str, context: str = "", coding_style: str | None = None
) -> dict[str, Any]:
"""Run planning phase with read-only tools.

Always uses Opus (smartest model) for planning to ensure
high-quality task breakdown and complexity classification.

Args:
goal: The goal to plan for.
context: Additional context for planning.
coding_style: Optional coding style guide to inject into prompt.

Delegates to AgentPhaseExecutor for implementation.
"""
return self._phase_executor.run_planning_phase(goal, context, coding_style)

def generate_coding_style(self) -> dict[str, Any]:
"""Generate a coding style guide by analyzing the codebase.

Analyzes CLAUDE.md, convention files, and codebase to create a
concise coding style guide with workflow and conventions.

Returns:
Dict with 'coding_style' and 'raw_output' keys.

Delegates to AgentPhaseExecutor for implementation.
"""
return self._phase_executor.run_planning_phase(goal, context)
return self._phase_executor.generate_coding_style()

def run_work_session(
self,
Expand All @@ -190,6 +210,7 @@ def run_work_session(
create_pr: bool = True,
pr_group_info: dict | None = None,
target_branch: str = "main",
coding_style: str | None = None,
) -> dict[str, Any]:
"""Run a work session with full tools.

Expand All @@ -203,6 +224,7 @@ def run_work_session(
create_pr: If True, instruct agent to create PR. If False, commit only.
pr_group_info: Optional dict with PR group context (name, completed_tasks, etc).
target_branch: The target branch for rebasing (default: "main").
coding_style: Optional coding style guide to inject into prompt.

Returns:
Dict with 'output', 'success', and 'model_used' keys.
Expand All @@ -218,6 +240,7 @@ def run_work_session(
create_pr=create_pr,
pr_group_info=pr_group_info,
target_branch=target_branch,
coding_style=coding_style,
)

def verify_success_criteria(self, criteria: str, context: str = "") -> dict[str, Any]:
Expand Down
56 changes: 53 additions & 3 deletions src/claude_task_master/core/agent_phases.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@

from . import console
from .agent_models import ModelType, get_tools_for_phase
from .prompts import build_planning_prompt, build_verification_prompt, build_work_prompt
from .prompts import (
build_coding_style_prompt,
build_planning_prompt,
build_verification_prompt,
build_work_prompt,
extract_coding_style,
)

if TYPE_CHECKING:
from .agent_query import AgentQueryExecutor
Expand Down Expand Up @@ -104,7 +110,9 @@ def __init__(
self.get_agents_func = get_agents_func
self.process_message_func = process_message_func

def run_planning_phase(self, goal: str, context: str = "") -> dict[str, Any]:
def run_planning_phase(
self, goal: str, context: str = "", coding_style: str | None = None
) -> dict[str, Any]:
"""Run planning phase with read-only tools.

Always uses Opus (smartest model) for planning to ensure
Expand All @@ -113,12 +121,17 @@ def run_planning_phase(self, goal: str, context: str = "") -> dict[str, Any]:
Args:
goal: The goal to plan for.
context: Additional context for planning.
coding_style: Optional coding style guide to inject into prompt.

Returns:
Dict with 'plan', 'criteria', and 'raw_output' keys.
"""
# Build prompt for planning
prompt = build_planning_prompt(goal=goal, context=context if context else None)
prompt = build_planning_prompt(
goal=goal,
context=context if context else None,
coding_style=coding_style,
)

# Always use Opus for planning (smartest model)
console.info("Planning with Opus (smartest model)...")
Expand Down Expand Up @@ -152,6 +165,7 @@ def run_work_session(
create_pr: bool = True,
pr_group_info: dict | None = None,
target_branch: str = "main",
coding_style: str | None = None,
) -> dict[str, Any]:
"""Run a work session with full tools.

Expand All @@ -165,6 +179,7 @@ def run_work_session(
create_pr: If True, instruct agent to create PR. If False, commit only.
pr_group_info: Optional dict with PR group context (name, completed_tasks, etc).
target_branch: The target branch for rebasing (default: "main").
coding_style: Optional coding style guide to inject into prompt.

Returns:
Dict with 'output', 'success', and 'model_used' keys.
Expand All @@ -178,6 +193,7 @@ def run_work_session(
create_pr=create_pr,
pr_group_info=pr_group_info,
target_branch=target_branch,
coding_style=coding_style,
)

# Run async query with optional model override
Expand Down Expand Up @@ -328,3 +344,37 @@ def _extract_criteria(self, result: str) -> str:

# Default criteria if none specified
return "All tasks in the task list are completed successfully."

def generate_coding_style(self) -> dict[str, Any]:
"""Generate a coding style guide by analyzing the codebase.

Analyzes CLAUDE.md, convention files, and sample source files
to create a concise coding style guide.

Returns:
Dict with 'coding_style' and 'raw_output' keys.
"""
# Build prompt for coding style generation
prompt = build_coding_style_prompt()

console.info("Generating coding style guide with Opus...")

# Run with planning tools (read-only) and Opus for quality
result = run_async_with_cleanup(
self.query_executor.run_query(
prompt=prompt,
tools=self.get_tools_for_phase("planning"),
model_override=ModelType.OPUS, # Use Opus for quality
get_model_name_func=self.get_model_name_func,
get_agents_func=self.get_agents_func,
process_message_func=self.process_message_func,
)
)

# Extract the coding style content
coding_style = extract_coding_style(result)

return {
"coding_style": coding_style,
"raw_output": result,
}
4 changes: 4 additions & 0 deletions src/claude_task_master/core/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,11 +1337,15 @@ def _run_verification_fix(self, verification_details: str, state: TaskState) ->
After completing your fixes, end with: TASK COMPLETE"""

try:
# Load coding style for consistent style in fix session
coding_style = self.state_manager.load_coding_style()

self.agent.run_work_session(
task_description=task_description,
context=context,
model_override=ModelType.OPUS,
create_pr=True,
coding_style=coding_style,
)
state.session_count += 1
self.state_manager.save_state(state)
Expand Down
44 changes: 41 additions & 3 deletions src/claude_task_master/core/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import Any

from . import console
from .agent import AgentWrapper
from .state import StateManager

Expand All @@ -14,13 +15,50 @@ def __init__(self, agent: AgentWrapper, state_manager: StateManager):
self.agent = agent
self.state_manager = state_manager

def ensure_coding_style(self) -> str | None:
"""Ensure coding style guide exists, generating it if needed.

Checks if coding-style.md exists. If not, generates it by analyzing
CLAUDE.md and convention files in the codebase.

Returns:
The coding style guide content, or None if generation failed.
"""
# Check if coding style already exists
coding_style = self.state_manager.load_coding_style()
if coding_style:
console.info("Using existing coding style guide")
return coding_style

# Generate coding style by analyzing codebase
console.info("Generating coding style guide from codebase...")
result = self.agent.generate_coding_style()

coding_style_content: str = result.get("coding_style", "")
if coding_style_content:
self.state_manager.save_coding_style(coding_style_content)
console.success("Coding style guide generated and saved")
return coding_style_content

console.warning("Could not generate coding style guide")
return None

def create_plan(self, goal: str) -> dict[str, Any]:
"""Create initial task plan using read-only tools."""
"""Create initial task plan using read-only tools.

First generates coding style guide if it doesn't exist, then
runs planning phase with the coding style injected.
"""
# Ensure coding style exists (generate if needed)
coding_style = self.ensure_coding_style()

# Load any existing context
context = self.state_manager.load_context()

# Run planning phase with Claude
result = self.agent.run_planning_phase(goal=goal, context=context)
# Run planning phase with Claude (with coding style)
result = self.agent.run_planning_phase(
goal=goal, context=context, coding_style=coding_style
)

# Extract plan and criteria from result
plan = result.get("plan", "")
Expand Down
8 changes: 8 additions & 0 deletions src/claude_task_master/core/prompts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Prompt Templates - Centralized, maintainable prompt generation.

This module provides structured prompt templates for different agent phases:
- Coding Style: Generate concise coding style guide from codebase analysis
- Planning: Initial codebase analysis and task creation
- Plan Update: Modifying existing plans based on change requests
- Working: Task execution with verification
Expand All @@ -12,6 +13,7 @@
This module re-exports all prompt functions for backward compatibility.
The actual implementations are in:
- prompts_base.py: PromptSection, PromptBuilder
- prompts_coding_style.py: build_coding_style_prompt, extract_coding_style
- prompts_planning.py: build_planning_prompt
- prompts_plan_update.py: build_plan_update_prompt
- prompts_working.py: build_work_prompt
Expand All @@ -24,6 +26,9 @@
# Re-export base classes
from .prompts_base import PromptBuilder, PromptSection

# Re-export coding style prompts
from .prompts_coding_style import build_coding_style_prompt, extract_coding_style

# Re-export planning prompts
from .prompts_plan_update import build_plan_update_prompt
from .prompts_planning import build_planning_prompt
Expand All @@ -43,6 +48,9 @@
# Base classes
"PromptSection",
"PromptBuilder",
# Coding Style
"build_coding_style_prompt",
"extract_coding_style",
# Planning
"build_planning_prompt",
"build_plan_update_prompt",
Expand Down
Loading