Commit Graph

31 Commits

Author SHA1 Message Date
rob 05959e6884 feat: add provider feedback logs 2025-11-02 00:40:02 -03:00
rob 44cc12c0ab feat: share ai fallback with agents and add provider status 2025-11-02 00:21:10 -03:00
rob 25c04859e6 fix: synthesize diff header when provider omits it 2025-11-01 23:39:06 -03:00
rob 01ead5754f fix: ensure codex fallback uses stdin 2025-11-01 23:19:09 -03:00
rob d6a88e483b fix: allow yaml header edits in append-only check 2025-11-01 23:05:27 -03:00
rob e84b0757f8 fix: remove unstaging logic from patch application
Fix critical bug in patcher.py where patches failed to apply to staged
files during pre-commit hooks.

**Root Cause:**
The apply_patch() function was unstaging files before applying patches:
1. File gets unstaged (git reset HEAD)
2. Patch tries to apply with --index flag
3. But patch was generated from STAGED content
4. Base state mismatch causes patch application to fail
5. Original changes get re-staged, AI changes are lost

**The Fix:**
Remove the unstaging logic entirely (lines 599-610, 639-641).
- Patches are generated from staged content (git diff --cached)
- The --index flag correctly applies to both working tree and index
- No need to unstage first - that changes the base state

**Changes:**
- Deleted 19 lines of problematic unstaging code
- Added clear comment explaining why unstaging is harmful
- Simplified apply_patch() function

**Impact:**
- Patches now apply correctly during pre-commit hooks
- Status changes (OPEN → READY_FOR_DESIGN) work properly
- Gate creation (design_gate_writer) will trigger correctly
- No behavior change for non-staged files

**Testing:**
- All 18 existing tests still pass
- Bundle rebuilt and verified

Discovered during end-to-end testing when AI-generated status promotion
patches failed with "Failed to apply patch (strict and 3-way both failed)".

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-01 22:53:34 -03:00
rob f6ce763a49 fix: default missing status field to OPEN in question formatting
Fix question extraction bug where AI-generated questions were being
filtered out due to missing 'status' field.

**Root Cause:**
The AI agents module returns questions without a 'status' field:
  {'participant': 'Bob', 'question': 'text', 'line': 'original'}

But format_questions_section() filtered for status == "OPEN":
  open_questions = [q for q in questions if q.get("status") == "OPEN"]

Since AI questions had no status, q.get("status") returned None,
which didn't match "OPEN", so questions were filtered out.

**Fix:**
Default missing status to "OPEN" in the filter:
  open_questions = [q for q in questions if q.get("status", "OPEN") == "OPEN"]

This makes the function defensive - questions without explicit status
are treated as OPEN, which matches the basic extraction behavior.

**Impact:**
- Questions extracted by AI agents now appear in summaries
- Maintains backward compatibility with basic extraction (has status)
- All 18 tests now pass (was 17/18)

**Testing:**
- Verified with test_run_status_updates_summary_sections
- Question "What is the rollout plan?" now correctly appears in summary
- No regressions in other tests

Resolves test failure identified in comprehensive project review.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-01 21:58:32 -03:00
rob 372d24b30d feat: add multi-provider AI system with model hint optimization
Major automation enhancements for flexible AI provider configuration:

1. Add config/ai.yml - Centralized AI configuration
   - Three command chains: default, fast, quality
   - Multi-provider fallback (Claude → Codex → Gemini)
   - Configurable per optimization level
   - Sentinel token configuration

2. Extend automation/ai_config.py
   - Add RunnerSettings with three chain support
   - Add get_chain_for_hint() method
   - Load and validate all three command chains
   - Proper fallback to defaults

3. Update automation/runner.py
   - Read model_hint from .ai-rules.yml
   - Pass model_hint to generate_output()
   - Support output_type hint overrides

4. Update automation/patcher.py
   - Add model_hint parameter throughout pipeline
   - Inject TASK COMPLEXITY hint into prompts
   - ModelConfig.get_commands_for_hint() selects chain
   - Fallback mechanism tries all commands in chain

5. Add design discussion stage to features.ai-rules.yml
   - New design_gate_writer rule (model_hint: fast)
   - New design_discussion_writer rule (model_hint: quality)
   - Update feature_request to create design gate
   - Update feature_discussion to create design gate
   - Add design.discussion.md file associations
   - Proper status transitions: READY_FOR_DESIGN → READY_FOR_IMPLEMENTATION

6. Add assets/templates/design.discussion.md
   - Template for Stage 3 design discussions
   - META header with tokens support
   - Design goals and participation instructions

7. Update tools/setup_claude_agents.sh
   - Agent descriptions reference TASK COMPLEXITY hint
   - cdev-patch: "MUST BE USED when TASK COMPLEXITY is FAST"
   - cdev-patch-quality: "MUST BE USED when TASK COMPLEXITY is QUALITY"

8. Fix assets/hooks/pre-commit
   - Correct template path comment (process/templates not assets/templates)

9. Update tools/mock_ai.sh
   - Log prompts to /tmp/mock_ai_prompts.log for debugging

Impact:
- Users can configure AI providers via config/ai.yml
- Automatic fallback between Claude, Codex, Gemini
- Fast models for simple tasks (vote counting, gate checks)
- Quality models for complex tasks (design, implementation planning)
- Reduced costs through intelligent model selection
- Design stage now properly integrated into workflow

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-01 21:43:13 -03:00
rob 0e83b6cf88 feat: parse codex exec json output for fallbacks 2025-11-01 17:28:57 -03:00
rob e9cc23685d docs: align claude setup references 2025-11-01 16:18:06 -03:00
rob ca73528068 feat: extend ai config with codex and gemini fallbacks 2025-11-01 14:59:45 -03:00
rob 4680f4b629 build: bundle shared ai config into installer 2025-11-01 14:44:25 -03:00
rob 57255a7e09 feat: load ai command chain from shared config 2025-11-01 14:37:57 -03:00
rob feb8580b3a feat: add ai fallback chain with no-change sentinel 2025-11-01 14:25:22 -03:00
rob eed12ce749 fix: ignore comment blocks in discussion parsing 2025-11-01 14:22:36 -03:00
rob 82aee9ef63 fix: recognize plain speaker lines in discussions 2025-11-01 14:22:14 -03:00
rob 73bcccdecd chore: clarify summary marker log 2025-11-01 14:21:54 -03:00
rob 2862b2ad50 updated uml diagrams 2025-11-01 11:34:06 -03:00
rob 77248847a8 fix: Use local .git/ai-agents-temp/ for Claude CLI file permissions
Changed temp file location from /tmp to .git/ai-agents-temp/ to resolve
Claude CLI permission errors when reading discussion content.

Problem:
- agents.py created temp files in /tmp/tmp*.md
- Asked Claude CLI to read these files
- Claude CLI couldn't access /tmp without explicit permission grant
- Error: "I don't have permission to read that file"
- Fell back to basic pattern matching (degraded functionality)

Solution:
- Create temp files in .git/ai-agents-temp/ directory
- Claude CLI has permission to read files in the project directory
- Use PID for unique filenames to avoid conflicts
- Cleanup still handled by finally block

Benefits:
- No user configuration needed
- Claude CLI can now read discussion files
- AI agents work properly for structured extraction
- Temp files automatically gitignored (.git/ directory)
- Easy debugging (files visible in project)

The finally block at line 154-158 still cleans up temp files after use.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-01 03:41:14 -03:00
rob 188f6b3b16 fix: Handle empty AI diffs gracefully instead of raising errors
Changed approach from disabling outputs to properly handling AI's decision
not to generate changes (e.g., gated outputs, conditional rules).

Changes:

1. patcher.py - Allow empty diffs
   - sanitize_unified_patch() returns empty string instead of raising error
   - generate_output() returns early for empty patches (silent skip)
   - Common case: implementation_gate_writer when status != READY_FOR_IMPLEMENTATION
   - AI can now return explanatory text without a diff (no error)

2. features.ai-rules.yml - Override README rule
   - Add README.md → "readme_skip" association
   - Creates empty rule to disable README updates in Docs/features/
   - Prevents unnecessary AI calls during feature discussions
   - README automation still works in root directory

3. root.ai-rules.yml - Restore default README rule
   - Removed "enabled: false" flag (back to default enabled)
   - Features directory overrides this with empty rule

Benefits:
- implementation_gate now calls AI but AI returns empty diff (as designed)
- No more "[runner] error generating ...implementation.discussion.md"
- No more "[runner] error generating README.md"
- Clean separation: AI decides vs. config disables
- Instructions to AI are still executed, AI just chooses no changes

Testing:
Setup completes cleanly with no [runner] errors. The automation
runs and AI correctly returns no diff for implementation file
when status is OPEN.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-01 02:33:31 -03:00
rob 70c3f6f80d refactor: Clean up pre-commit hook and add comprehensive comments
Removed dead code and added detailed documentation:

1. Removed unused functions (61 lines deleted)
   - resolve_template() - Template resolution now handled by config.py
   - apply_patch_with_3way() - Patch application now handled by patcher.py

2. Added comprehensive function documentation
   - check_append_only_discussion: Detailed docstring explaining validation logic
   - ensure_summary: Explains companion file creation and auto-staging

3. Added execution flow documentation
   - STEP 1: Collect staged files
   - STEP 2: Process discussion files (validation + summary creation)
   - STEP 3: Run AI automation (runner.py) with examples and debug info
   - STEP 4: Run workflow automation (workflow.py) with vote tracking details

4. Improved inline comments
   - Explained what each automation phase does
   - Documented exit codes and behavior
   - Added examples of file transformations
   - Noted debug artifact locations

Result:
- Hook reduced from 141 lines to 109 lines (cleaner)
- Every section now clearly documented
- Easier for users to understand automation flow
- Better debugging guidance

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-01 01:08:00 -03:00
rob c231edcd82 fix: Handle API overload errors gracefully
- Detect Claude API 500 Overloaded errors
- Continue processing other files on error instead of aborting
- Log errors to stderr for visibility

This allows commits to succeed even if some AI requests fail due to rate limiting.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-31 10:15:48 -03:00
rob 429174f6e4 fix: Save debug artifacts even when patch extraction fails
Helps debugging by preserving raw AI output when markers are missing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-31 10:05:07 -03:00
rob 4aa5d01588 fix: Handle claude CLI exit code 1 for successful responses
Claude CLI returns exit code 1 even when successfully generating output.
Check for stdout content before failing on non-zero exit codes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-31 09:57:26 -03:00
rob 4176f51e7d fix: Add YAML syntax fix and mock AI script for testing
- Fix missing space after colon in features.ai-rules.yml
- Add tools/mock_ai.sh for testing automation without real AI
- Ensures installer has valid YAML templates

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-31 09:18:59 -03:00
rob bee5315aea docs: Add automation quick reference guide
Add automation/README.md with:
- Quick start instructions for Phase 1 and Phase 2
- Configuration examples for all supported providers
- How it works explanation
- Vote format and optional markers
- Testing and troubleshooting sections

Provides a concise reference for users without needing to read full AUTOMATION.md.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 18:32:08 -03:00
rob 5944269ed8 refactor: Support CLI-based AI providers (Claude Code, Gemini, Codex)
Major refactoring to support flexible AI provider configuration instead of
requiring direct API access. Users can now use whatever AI CLI tool they have
installed (claude, gemini, codex, etc.) without API keys.

## Changes to automation/agents.py

**New Functions:**
- `get_ai_config()` - Reads config from env vars or git config
  - Environment: CDEV_AI_PROVIDER, CDEV_AI_COMMAND (highest priority)
  - Git config: cascadingdev.aiprovider, cascadingdev.aicommand
  - Default: claude-cli with "claude -p '{prompt}'"

- `call_ai_cli()` - Execute AI via CLI command
  - Passes content via temp file to avoid shell escaping
  - Supports {prompt} placeholder in command template
  - 60s timeout with error handling
  - Parses JSON from response (with/without code blocks)

- `call_ai_api()` - Direct API access (renamed from call_claude)
  - Unchanged functionality
  - Now used as fallback option

- `call_ai()` - Unified AI caller
  - Try CLI first (if configured)
  - Fall back to API (if ANTHROPIC_API_KEY set)
  - Graceful failure with warnings

**Updated Functions:**
- `normalize_discussion()` - calls call_ai() instead of call_claude()
- `track_questions()` - calls call_ai() instead of call_claude()
- `track_action_items()` - calls call_ai() instead of call_claude()
- `track_decisions()` - calls call_ai() instead of call_claude()

**Configuration Precedence:**
1. Environment variables (session-scoped)
2. Git config (repo-scoped)
3. Defaults (claude-cli)

## Changes to docs/AUTOMATION.md

**Updated Sections:**
- "Requirements" - Now lists CLI as Option 1 (recommended), API as Option 2
- "Configuration" - Complete rewrite with 5 provider examples:
  1. Claude CLI (default)
  2. Gemini CLI
  3. OpenAI Codex CLI
  4. Direct API (Anthropic)
  5. Custom AI command
- "Troubleshooting" - Added "AI command failed" section, updated error messages

**New Configuration Examples:**
```bash
# Claude Code (default)
git config cascadingdev.aicommand "claude -p '{prompt}'"

# Gemini
git config cascadingdev.aiprovider "gemini-cli"
git config cascadingdev.aicommand "gemini '{prompt}'"

# Custom
git config cascadingdev.aicommand "my-ai-tool --prompt '{prompt}' --format json"
```

## Benefits

1. **No API Key Required**: Use existing CLI tools (claude, gemini, etc.)
2. **Flexible Configuration**: Git config (persistent) or env vars (session)
3. **Provider Agnostic**: Works with any CLI that returns JSON
4. **Backward Compatible**: Still supports direct API if ANTHROPIC_API_KEY set
5. **User-Friendly**: Defaults to "claude -p" if available

## Testing

-  get_ai_config() tests:
  - Default: claude-cli with "claude -p '{prompt}'"
  - Git config override: gemini-cli with "gemini '{prompt}'"
  - Env var override: codex-cli with "codex '{prompt}'"
-  extract_mentions() still works (no AI required)
-  All 6 workflow tests pass

## Impact

Users with Claude Code installed can now use the automation without any
configuration - it just works! Same for users with gemini or codex CLIs.
Only requires git config setup if using non-default command.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 18:31:27 -03:00
rob 72577bd30d feat: Implement Phase 2 - AI-powered discussion automation
Complete implementation of the AI-enhanced automation system with 5 specialized agents:

## New Files

1. **automation/agents.py** (270 lines)
   - Agent 1: normalize_discussion() - Extracts structured info from natural language
   - Agent 2: track_questions() - Identifies questions and tracks answers (OPEN/PARTIAL/ANSWERED)
   - Agent 3: track_action_items() - Manages TODO → ASSIGNED → DONE lifecycle
   - Agent 4: track_decisions() - Logs ADR-style decisions with rationale
   - extract_mentions() - Parses @Name and @all mentions (no API required)
   - call_claude() - Anthropic API integration with JSON response parsing

2. **automation/summary.py** (289 lines)
   - update_marker_block() - Non-destructive marker block updates
   - format_votes_section() - Formats vote counts and participants
   - format_questions_section() - Formats open/partial/answered questions
   - format_action_items_section() - Formats TODO/ASSIGNED/DONE tasks
   - format_decisions_section() - Formats ADR-style decisions
   - format_awaiting_section() - Groups @mentions by target
   - update_summary_file() - Orchestrates all section updates

3. **docs/AUTOMATION.md** (361 lines)
   - Complete system documentation
   - Phase 1 (basic) and Phase 2 (AI) explanations
   - Conversation guidelines and markers
   - Configuration and troubleshooting

## Enhanced Files

**automation/workflow.py** (enhanced to 349 lines, +132 lines)
- get_discussion_changes() - Git diff extraction for incremental processing
- update_summary_votes() - Marker block update for votes (Phase 1 fallback)
- process_discussion_with_ai() - Orchestrates all AI agents
- Enhanced _run_status() - Processes with AI when available, graceful fallback
- Dual import style for different execution contexts (pre-commit hook vs direct)

## Features

### Phase 1 (Always Enabled):
-  Vote parsing and tracking (READY/CHANGES/REJECT)
-  Latest vote per participant logic
-  Summary file auto-update and staging
-  Non-blocking git hook integration

### Phase 2 (Optional, requires ANTHROPIC_API_KEY):
-  @Mention extraction and tracking
-  Question identification and status tracking
-  Action item lifecycle management
-  Decision logging with rationale (ADR-style)
-  Incremental processing via git diff
-  Graceful degradation when API unavailable

## Architecture

- Modular design with separate concerns (agents, summary, workflow)
- Non-blocking operation (always exits 0)
- Dual-phase capability (basic + AI-enhanced)
- Graceful fallbacks at every level
- Comprehensive error handling

## Testing

- All 11 existing tests passing
- End-to-end testing in /tmp/cdev-test-phase2a confirmed:
  - Vote tracking works correctly
  - @Mentions extracted and grouped by target
  - Summary files updated non-destructively
  - Auto-staging of updated summaries
  - Pre-commit hook integration functional

## Documentation

- AUTOMATION.md covers architecture, usage, and troubleshooting
- Code comments explain complex logic
- Example formats provided for all features
- Configuration and setup instructions included

This completes the Phase 2 automation milestone, providing a sophisticated
AI-powered discussion summarization system while maintaining full backward
compatibility with basic vote-only mode.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 18:12:48 -03:00
rob 05002b766b test: Add comprehensive workflow tests and improve template tests
Testing improvements completing Week 1 consolidation:

1. Add tests/test_workflow.py (6 comprehensive tests)
   - test_extract_vote_value: Vote value extraction
   - test_parse_votes_single_participant_single_vote: Basic parsing
   - test_parse_votes_single_participant_multiple_votes: Latest vote wins
   - test_parse_votes_multiple_participants: Multi-participant tracking
   - test_parse_votes_malformed_lines: Error handling
   - test_parse_votes_mixed_content: Real-world scenarios

2. Improve tests/test_template_meta.py
   - Replace stub tests with real implementations
   - test_find_template_fields: Field extraction from templates
   - test_render_request_from_template: Template rendering
   - test_render_request_from_template_with_existing_meta: Preserve existing data

3. Add __init__.py files for test imports
   - assets/__init__.py: Make assets importable
   - automation/__init__.py: Make automation importable
   - Enables tests to import workflow.py and create_feature.py

4. Update pyproject.toml pytest configuration
   - Add ".", "assets" to pythonpath
   - Allows tests to import from automation/ and assets/

Test Results:
- All 11 tests passing
- Coverage: workflow vote parsing, template rendering, utils
- Foundation ready for Stage 2 development

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 16:20:42 -03:00
rob 858dcae72e fix: Make workflow.py executable and add missing argparse import
Critical bug fixes discovered during end-to-end testing:

1. Add missing argparse import to workflow.py
   - workflow.py was missing `import argparse`
   - Caused NameError when pre-commit hook tried to run it
   - Added import at line 13

2. Make workflow.py executable during installation
   - Installer now sets executable permissions (0o755)
   - Pre-commit hook checks `if [ -x "automation/workflow.py" ]`
   - Without executable bit, hook silently skipped workflow
   - Fix in setup_project.py lines 381-384

Testing:
- Created fresh project with installer
- Added votes to discussion file
- Verified workflow.py runs during commit
- Output: "CHANGES: 2 votes, READY: 3 votes" ✓

Impact:
- Users now see vote counts during commits
- Phase 1 orchestration fully functional
- Foundation ready for Stage 2 (summary updates)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 16:14:44 -03:00
rob 4e7ad11b4c feat: Implement vote parsing orchestrator and testing infrastructure
Major implementation milestone - core automation is now functional:

1. Add automation/workflow.py (Phase 1 - Vote Parsing)
   - Parse VOTE: lines from discussion files
   - Track latest vote per participant
   - Print human-readable vote summaries
   - Non-blocking (always exits 0)
   - Proper error handling for missing files/git failures
   - 158 lines of production-quality code

2. Add testing infrastructure
   - Create tests/ directory with pytest configuration
   - Add test_utils.py with actual version reading test
   - Add test_template_meta.py (stubs for META system tests)
   - Add test_build.py (stub for build verification)
   - Configure pytest in pyproject.toml (pythonpath)
   - All 4 tests passing

3. Add AGENTS.md - Developer guidelines
   - Project structure and module organization
   - Build, test, and development commands
   - Coding style and naming conventions
   - Testing guidelines
   - Commit and PR guidelines

4. Update docs/DESIGN.md
   - Document workflow.py implementation
   - Update automation status from "planned" to "implemented"
   - Clarify Phase 1 vs future phases

5. Code cleanup - Remove empty stub modules
   - Delete src/cascadingdev/feature_seed.py
   - Delete src/cascadingdev/fs_scaffold.py
   - Delete src/cascadingdev/ramble_integration.py
   - Delete src/cascadingdev/rules_seed.py

Impact:
- Users can now see vote counts in their commits
- Testing foundation enables safe refactoring
- Code is cleaner with only working modules
- Week 1 implementation goals complete

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 14:25:53 -03:00