Skip to content

Conversation

@TheHiddenLayer
Copy link
Owner

No description provided.

Implement GitNotes struct that stores/reads JSON data as git notes under
refs/notes/zen/ namespace instead of external JSON files. This is the
foundation for git-native state management.

API:
- add<T>() - serialize and attach JSON note to commit
- read<T>() - deserialize JSON note from commit
- remove() - delete note (no-op if missing)
- list() - enumerate all commits with notes

Includes 10 comprehensive tests covering all operations, edge cases,
and namespace isolation from default refs/notes/commits.

🤖 Assisted by the code-assist SOP
…pace

Implement low-level git refs management with CRUD operations:
- create_ref: Create refs with duplicate detection
- read_ref: Read ref target (returns Option for missing refs)
- update_ref: Update existing refs with existence check
- delete_ref: Idempotent deletion
- list_refs: List refs with optional prefix filtering
- ref_exists: Check ref existence

Add RefExists and RefNotFound error variants.
Add tempfile dev-dependency for test isolation.

Assisted by the code-assist SOP
…n/ namespace

Add GitNotes struct with methods to attach JSON-serialized data to commits
as git notes. This provides a foundation for storing workflow metadata
without modifying the commit history.

Methods implemented:
- new(): Constructor with repository validation
- set_note(): Attach JSON note to a commit (overwrites existing)
- get_note(): Read and deserialize JSON note from a commit
- delete_note(): Remove note (idempotent)
- list_notes(): List commit SHAs with notes in a namespace
- note_exists(): Check if note exists

Notes are stored under refs/notes/zen/{namespace} to isolate from
standard git notes.

🤖 Assisted by the code-assist SOP
…orkflowStatus)

Add foundational type definitions for the Zen v2 workflow orchestration system:

- WorkflowId: UUID-based newtype for workflow identification with short form display
- WorkflowPhase: Enum for workflow phases (Planning, TaskGeneration, Implementation,
  Merging, Documentation, Complete) with ordering support
- WorkflowStatus: Enum for workflow lifecycle (Pending, Running, Paused, Completed, Failed)

All types support serialization via serde for git-native state persistence.

🤖 Assisted by the code-assist SOP
Add core workflow data structures for tracking orchestration runs:
- WorkflowConfig with update_docs, max_parallel_agents, staging_branch_prefix
- Workflow struct with id, name, prompt, phase, status, config, timestamps
- TaskId placeholder type for task references (full impl in Step 8)
- Lifecycle methods: new(), start(), complete(), fail()
- Name derivation from prompt (kebab-case, first 4 words)

All 44 workflow tests pass, 199 total tests pass.

🤖 Assisted by the code-assist SOP
Add WorkflowState struct that manages runtime workflow state and enforces
valid phase transitions according to the Skills-driven workflow ordering.

Key features:
- PhaseHistoryEntry struct for tracking phase transitions with timestamps
- WorkflowState wrapping Workflow with phase history tracking
- Strict transition validation: Planning -> TaskGeneration -> Implementation
  -> Merging -> Documentation -> Complete
- Optional Documentation phase (Merging can transition directly to Complete)
- 33 comprehensive tests covering valid/invalid transitions, history tracking

Also adds InvalidPhaseTransition error variant to error.rs for handling
invalid transition attempts.
…ence

Add GitStateManager struct that composes GitRefs, GitNotes, and GitOps
to provide a unified interface for git-based state operations. This is
the foundation for migrating workflow state from JSON files to git refs
and notes.

- Create src/state/mod.rs with module exports
- Create src/state/manager.rs with GitStateManager struct
- Implement constructor with repo validation
- Add accessor methods for refs, notes, ops components
- Add 7 unit tests covering all acceptance criteria
Add save_workflow, load_workflow, list_workflows, and delete_workflow
methods to GitStateManager for persisting Workflow structs using git
notes under refs/notes/zen/workflows/{id} namespace.

- Each workflow stored as JSON note on HEAD commit
- Per-workflow namespace prevents collision when multiple workflows share commits
- Refs at refs/zen/workflows/{id} track workflow existence
- Idempotent delete operation
- 9 new tests, 248 total tests passing
Add StateMigration module with methods to migrate existing Zen
installations from JSON state file to git-native storage. Migration
creates a marker ref (refs/zen/migrated) to track completion.

Key methods:
- needs_migration() - detect if migration is needed
- migrate() - create marker ref at HEAD commit
- migrate_if_needed() - combined check and migrate
- is_migrated() - check if marker exists

Migration is idempotent and backward compatible - sessions continue
using JSON state file while workflows use git-native storage.

🤖 Assisted by the code-assist SOP
Add the AIHumanProxy struct that autonomously answers skill clarification
questions on behalf of the user, enabling fully autonomous workflow
execution. This is a key innovation for the Skills-driven workflow.

Components:
- AIHumanProxy: Stores original prompt, conversation context, and model
- ConversationContext: Tracks Q&A history for consistent responses
- Mock answer generation based on question patterns
- Escalation detection for ambiguous preference questions

The proxy uses pattern matching to generate reasonable default answers
and can detect when questions need human escalation (e.g., "personal
preference", "which style do you prefer").

🤖 Assisted by the code-assist SOP
Enhance ConversationContext to track key decisions extracted from Q&A
pairs, enabling consistent AI-as-Human responses across workflow phases.

- Add decisions HashMap field to store extracted decisions
- Implement decision extraction heuristics in record() method:
  - naming: questions about names, naming conventions
  - database: questions about database choices
  - technology: questions about frameworks, libraries, tools
  - architecture: questions about patterns, approaches, design
- Add decisions() accessor method for retrieving stored decisions
- Add comprehensive test coverage (18 new tests)

All 305 tests passing, plus 6 doc tests.
Add UUID-based AgentId identifier and AgentStatus enum to support
multiple concurrent agents with lifecycle tracking. AgentId follows
the same pattern as SessionId and WorkflowId. AgentStatus tracks
agent state: Idle, Running (with task_id), Stuck (with since/reason),
Failed (with error), and Terminated.

- AgentId: UUID-based with Display, FromStr, Serialize/Deserialize
- AgentStatus: lifecycle enum with Display implementation
- 20 new tests for AgentId and AgentStatus types

🤖 Assisted by the code-assist SOP
Add AgentPool struct that manages multiple concurrent agents with
capacity limits and event emission. Includes:

- AgentEvent enum for lifecycle events (Started, Completed, Failed,
  StuckDetected, Terminated)
- AgentHandle placeholder struct for agent state tracking
- AgentPool with spawn, terminate, get, active_count, has_capacity
- Error variants for pool full and agent not found conditions

This is a stub implementation; full agent spawning will be added
in Task 4.3 when AgentHandle is fully implemented.

🤖 Assisted by the code-assist SOP
Add full AgentHandle implementation with tmux session communication:

- Add AgentOutput enum (Text, Question, Completed, Error) with pattern parsing
- Enhance AgentHandle struct with new fields:
  - tmux_session: tmux session name for the agent
  - worktree_path: isolated git worktree path
  - started_at/last_activity: timing for health monitoring
  - cancel_token: graceful shutdown support
- Implement communication methods:
  - send(): send input to agent's tmux pane
  - read_output(): capture and parse pane content
  - read_raw_output(): capture without parsing
  - read_output_tail(): efficient last N lines capture
  - last_commit(): get latest commit from worktree
- Add activity tracking methods (touch_activity, idle_duration, running_duration)
- Add 36 new tests (70 total pool tests)

🤖 Assisted by the code-assist SOP
Add ClaudeHeadless struct that executes Claude Code in headless mode
(-p flag) with JSON output parsing. This enables programmatic
interaction with the AI agent.

Key features:
- Binary detection via `which` crate
- Async execution with tokio::process::Command
- JSON response parsing (session_id, result, cost, duration)
- Configurable timeout (default 10 minutes)
- ResultType enum (Success/Error) for structured responses
- Builder pattern (with_binary, with_timeout)

Added error variants:
- ClaudeBinaryNotFound
- ClaudeExecutionFailed

Tests: 33 new tests covering types, JSON parsing, and execution

🤖 Assisted by the code-assist SOP
Add multi-turn conversation support via session continuation:
- Add continue_session() and continue_session_with_model() methods
  using --resume flag for Claude session continuation
- Create SessionManager to track active sessions with register/get/remove/clear
- Enhance AIHumanProxy with optional ClaudeBackendConfig for real Claude
  backend support instead of mock patterns
- Add set_session_id() and clear_session() for session lifecycle management

Tests: 59 claude tests, 176 orchestration tests, 454 total tests passing
Add the central orchestration engine that drives the 5-phase workflow:
- WorkflowResult struct for execution outcomes (workflow_id, status, summary)
- SkillsOrchestrator struct composing AIHumanProxy, AgentPool, ClaudeHeadless
- Constructor initializing all components with WorkflowConfig
- Execute skeleton with phase transition logging
- Phase stub methods for Planning, TaskGeneration, Implementation, Merging, Documentation
- 21 tests covering construction, execution, and phase transitions

This completes Step 6, Task 6.1 of the Zen v2 implementation.

🤖 Assisted by the code-assist SOP
…agement

Add PhaseController that manages workflow phase transitions and emits
events for TUI updates. Includes:

- PhaseEvent enum (Started, Changed, Completed) for event-driven updates
- PhaseController struct with current phase, history, and event channel
- Transition validation following workflow rules (Planning -> TaskGen -> Impl -> Merge -> Docs/Complete)
- Duration tracking for each phase with elapsed() method
- Full test coverage (32 new tests, 53 total skills tests passing)

Part of Step 6, Task 6.2 of Zen v2 implementation.
Add monitor_agent_output() method to SkillsOrchestrator that implements
the core interaction pattern for all skill phases. The loop:
- Polls agent output at configurable intervals
- Detects questions and answers via AIHumanProxy
- Handles completion, errors, and timeout conditions

New types:
- MonitorConfig: Configures poll interval and timeout
- SkillResult: Captures skill execution outcome

The monitor loop enables autonomous workflow execution by handling
agent Q&A without human intervention.

🤖 Assisted by the code-assist SOP
Add PDDResult struct with artifact path validation for PDD outputs:
- design_path, plan_path, research_dir with from_directory() validation
- artifacts_exist() method for checking file existence

Add spawn_for_skill() to AgentPool for skill-specific agent spawning:
- Creates synthetic TaskId for skill execution
- Names tmux session after skill (zen_{skill}_{agent_id})
- Returns AgentHandle for communication

Implement run_pdd_phase() in SkillsOrchestrator:
- Spawns agent via spawn_for_skill("pdd")
- Sends /pdd command with rough_idea parameter
- Monitors via AIHumanProxy for question answering
- Validates PDD artifacts on completion

Add PDDArtifactNotFound error variant for missing artifacts.

Update execute() tests to handle planning phase failure in test
environment (no tmux available).
Add robust question detection module with is_question(), extract_question(),
and is_waiting_for_input() functions. This enables the AI-as-Human proxy to
accurately identify when an agent is asking for input.

Detection patterns include:
- Direct questions (ending with ?)
- Numbered/lettered options lists
- Yes/No prompts and (y/n) patterns
- Input prompts (Enter, Please provide, Type your)

Integrated with AgentOutput::contains_question_pattern() for centralized
question detection logic.

🤖 Assisted by the code-assist SOP
Add core module with Task struct and related types that represent
individual work items in the execution DAG.

- TaskId: UUID-based newtype with short(), Display, FromStr, serde
- TaskStatus: 6 variants (Pending, Ready, Running, Completed, Failed, Blocked)
- Task struct: tracks status, worktree, agent, timing, commit hash
- Lifecycle methods: new(), start(), complete(), fail(), mark_ready(), block()
- Helper methods: assign_agent(), set_worktree(), set_commit()
- Query methods: is_finished(), can_start()
- Full serde support for git notes persistence

39 tests covering all functionality.
…ment

Implements task dependency graph using petgraph DiGraph. Adds DependencyType
enum (DataDependency, FileDependency, SemanticDependency) with serde support.
TaskDAG provides add_task/add_dependency with automatic cycle detection,
get_task/get_dependencies/get_dependents for traversal. 39 new tests.
Add scheduling operations to TaskDAG for parallel task execution:

- ready_tasks(): Returns tasks where all dependencies are satisfied
- complete_task(): Marks a task as completed with timestamp
- all_complete(): Checks if all tasks in the DAG are complete
- topological_order(): Returns tasks in dependency-respecting order
- pending_count(): Returns count of incomplete tasks

These operations enable the scheduler to identify which tasks can run
in parallel and track completion progress through the execution DAG.

Acceptance criteria verified:
- Given DAG: A->C, B->C, D; ready_tasks({}) returns [A, B, D]
- Given DAG: A->B->C; ready_tasks({A}) returns [B]
- Given DAG with 5 tasks; all_complete({all 5}) returns true
- Topological order respects dependencies

🤖 Assisted by the code-assist SOP
…enerator

Add run_task_generation_phase() method that executes /code-task-generator
as Phase 2 of the workflow. The method spawns an agent, sends the generator
command with plan.md path, monitors via AIHumanProxy, and parses generated
.code-task.md files into CodeTask objects.

Key additions:
- run_code_task_generator_phase() for core generator logic
- NoCodeTasksGenerated error variant for empty task output
- Multi-path search (repo root, .sop, implementation dir)
- Task deduplication by ID
- execute() now captures generated tasks for Step 11

Includes 11 new tests for task generation phase.
Add Scheduler struct that manages parallel task execution, dispatching
ready tasks to the agent pool while respecting DAG dependencies and
capacity limits. Key components:

- SchedulerEvent enum for task lifecycle events (TaskStarted, TaskCompleted, TaskFailed, AllTasksComplete)
- ImplResult struct for capturing task implementation results
- Scheduler struct with methods:
  - dispatch_ready_tasks(): spawns agents for ready tasks up to capacity
  - handle_completion(): processes task completion, updates DAG, emits events
  - handle_failure(): processes task failures
  - run(): main scheduling loop (takes agent event receiver)

Includes 28 comprehensive tests covering:
- Ready task dispatch respects capacity limits
- Dependencies are respected (task B not started until A completes)
- Completion handling updates completed set and unlocks dependents
- AllTasksComplete event emitted when done
- Full diamond DAG execution integration test

🤖 Assisted by the code-assist SOP
…assist

Implement run_implementation_phase() and build_task_dag() methods in
SkillsOrchestrator to enable Phase 3 parallel execution of /code-assist.

Key additions:
- build_task_dag(): Converts CodeTask list to TaskDAG with dependency
  edges inferred from CodeTask.dependencies field
- run_implementation_phase(): Creates Scheduler, sets up agent event
  channel, and runs scheduler to completion
- AgentPool.set_event_sender(): Allow replacing the event channel for
  scheduler integration
- Updated execute() to pass generated tasks to implementation phase

Test coverage includes: empty tasks, single task, multiple independent
tasks, dependency chains, diamond patterns, missing dependency handling,
and topological order verification.

🤖 Assisted by the code-assist SOP
…hase

Add progress tracking to the Scheduler that updates task status in
GitStateManager and emits events for TUI display.

GitStateManager task persistence:
- save_task(), load_task(), list_tasks(), delete_task() methods
- Per-task namespace in git notes for collision avoidance
- 9 tests covering roundtrip, lifecycle, and worktree persistence

Scheduler progress tracking:
- state_manager field with with_state_manager() builder pattern
- progress_percentage() returns (completed/total)*100
- emit_progress() sends TaskProgress events on completion
- persist_task() saves task state on start/complete/fail
- 11 tests covering progress calculation and event emission

TEA Message variants for TUI integration:
- Message::TaskStarted { task_id, agent_id }
- Message::TaskProgress { completed, total }
- Message::TaskCompleted { task_id, commit }
- Message::TaskFailed { task_id, error }

Acceptance criteria met:
- 3 of 5 tasks complete = 60% progress ✓
- GitStateManager.save_task() called with Running status ✓
- task.commit_hash set and persisted on completion ✓
- Message variants sent on task state changes ✓

🤖 Assisted by the code-assist SOP
Add merge() method to ConflictResolver that attempts to merge task
worktrees into a staging branch, detecting and reporting conflicts.

Key features:
- merge(worktree, staging_branch) performs full merge workflow
- Handles fast-forward merges efficiently
- Creates staging branch automatically if missing
- Detects merge conflicts via git2 index
- Extracts conflict content (ours/theirs/base) from git blobs
- Returns MergeResult::Success, Conflicts, or Failed

Implementation uses git2 crate for all merge operations:
- merge_analysis() to determine merge strategy
- merge() with MergeOptions for normal merges
- index.conflicts() iterator for conflict extraction
- read_blob_content() helper for extracting file versions

Tests: 24 resolver tests passing (8 new merge tests)

Assisted by the code-assist SOP
Add determine_recovery() and execute_recovery() methods to HealthMonitor
that use heuristic-based analysis to decide recovery actions for stuck
or failing agents.

Key additions:
- RetryTracker: Tracks retry counts per task with increment/reset/clear
- determine_recovery(): Analyzes agent output patterns to decide action
  - Escalate when max retries exceeded
  - Restart for transient errors (rate limit, timeout, connection refused)
  - Abort for fatal errors (permission denied, authentication failed)
  - Decompose for complex task indicators
- execute_recovery(): Executes recovery actions (terminate agent, emit events)
- build_recovery_prompt(): Builds AI prompts for future ClaudeHeadless integration
- parse_recovery_action(): Parses AI responses into RecoveryAction enum

Tests: 65 health tests passing (33 new)
- Add WorkflowView struct in render.rs for workflow display state
- Extend RenderState with optional workflow field
- Implement render_workflow_header() showing workflow name and status
- Implement render_phase_progress() with 5-phase indicator and progress bar
- Add helper functions for status colors and labels
- Add 24 tests covering all acceptance criteria

Task 16.1: Create Workflow UI Components

Assisted by the code-assist SOP
- Create comprehensive docs/user-guide.md with:
  - Installation instructions and prerequisites
  - Quick start guide for first workflow
  - Detailed workflow phases explanation
  - Complete CLI command reference
  - Configuration options documentation
  - Troubleshooting guide

- Create README.md with:
  - Project description and key features
  - Installation and quick start instructions
  - Usage examples for all commands
  - How it works diagram
  - Links to detailed documentation
- Update docs/architecture.md with v2 orchestration system overview
  - Add mermaid diagram showing Skills Orchestration Layer
  - Document all orchestration components (Scheduler, Resolver, etc.)
  - Update thread architecture to include orchestration
  - Add git-native state management section
  - Update dependencies and testing sections

- Create docs/skills-integration.md documenting:
  - Skills-driven workflow (PDD → TaskGen → Impl → Merge → Docs)
  - AI-as-Human pattern with code examples
  - Question detection patterns
  - Guide for adding new skills to the workflow

- Create CONTRIBUTING.md with:
  - Development setup instructions
  - Code style guide (naming, errors, docs, imports)
  - Testing requirements and coverage goals
  - PR process with checklist and commit conventions
  - Architecture guidelines (TEA, two-thread, git-native)

🤖 Assisted by the code-assist SOP
Implements full Skills-driven workflow orchestration with:

Core Systems:
- SkillsOrchestrator: 5-phase workflow (PDD → TaskGen → Impl → Merge → Docs)
- AIHumanProxy: Autonomous skill question answering
- AgentPool: Multi-agent management with capacity limits
- Scheduler: DAG-based parallel task execution with petgraph
- ConflictResolver: AI-assisted merge conflict resolution
- HealthMonitor: Stuck detection and AI-driven recovery
- ReactivePlanner: File watching for dynamic replanning
- CleanupManager: Worktree and resource cleanup

TUI Enhancements:
- WorkflowView: Phase progress and status display
- AgentView: Multi-agent grid with live output preview
- TaskDAGView: ASCII DAG visualization

CLI Commands:
- zen run: Start workflow (TUI or headless mode)
- zen review: Show workflow summary and diff
- zen accept: Merge staging to main, cleanup
- zen reject: Discard workflow, preserve task branches
- zen cleanup: Detect and remove orphaned resources

State Management:
- Git-native persistence via refs/zen/ and refs/notes/zen/
- Task status tracking with git notes
- Workflow state migration tool

48 tasks across 20 implementation steps.
800+ tests passing.
- 45 integration tests for E2E workflow validation
- 15 performance tests (60 FPS render, scheduler overhead, memory)
- Test fixtures with TestRepo, mock harnesses
- CI-compatible tests (no real Claude API calls)
- .sop/planning/: PDD design documents and research
- .sop/planning/implementation/: 48 code task files across 20 steps
- PRD.md: Master reference for implementation workflow
- progress.txt: Detailed task completion log with commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants