Skip to content

Conversation

@rpothin
Copy link
Owner

@rpothin rpothin commented Jan 28, 2026

This PR fixes a critical bug in ghcralph run and adds model compatibility improvements, preparing for v0.1.2 release to npm.

🐛 Critical Bug Fix: Multi-Task Plan Processing

Problem: ghcralph run --file PLAN.md only processed the first task then exited, instead
of processing all pending tasks in the plan file.

Root Cause: The run command had no outer loop to continue processing remaining tasks after
the first task completed.

Solution (Option A from remediation plan):

  • Added outer while (currentTask) loop that processes ALL pending tasks
  • Creates fresh AI agent instance for each task (Ralph pattern core principle)
  • Added task-level retry with configurable maxRetriesPerTask (default: 2)
  • Prints final summary with total tasks processed/completed/failed

✨ New Features

Feature Description
--pause-between-tasks CLI flag for strict Ralph mode (human review after each task)
maxRetriesPerTask config Configurable retries per task before marking failed (default: 2)
autoPush config Auto-push to remote after each task completion (default: false)
[ACTION:STUCK] New action type for graceful failure signaling
Dynamic model listing ghcralph init now fetches available models from Copilot SDK

🔧 Technical Changes

Core Multi-Task Loop (src/commands/run.ts)

  • Fresh agent per task prevents context pollution
  • Task-level checkpoints with createTaskCheckpoint() and createFailureCheckpoint()
  • Progress tracking with loadPreviousTaskResults() and appendTaskResult()

Prompt Engineering (src/core/context-builder.ts)

  • Added HONESTY_GUIDANCE section encouraging agents to document blockers instead of false
    completion claims

New STUCK Action (src/core/response-parser.ts, src/core/action-executor.ts)

  • Agents can report: attempted actions, blockers, and suggestions
  • STUCK triggers retry with fresh agent (benefits from progress documentation)

Model Compatibility (src/integrations/copilot-agent.ts, src/commands/init.ts)

  • Added listAvailableModels() and static fetchAvailableModels() using SDK's listModels()
    API
  • ghcralph init dynamically fetches models instead of hardcoded list
  • Falls back gracefully if SDK fetch fails

📁 Files Changed (24 files, +1924/-159 lines)

Core Changes:

  • src/commands/run.ts - Core multi-task loop fix
  • src/commands/init.ts - Dynamic model fetching
  • src/core/config-schema.ts - New config options
  • src/core/checkpoint-manager.ts - Task-level checkpoints
  • src/core/git-branch-manager.ts - Push to remote
  • src/core/progress-tracker.ts - Multi-task progress tracking
  • src/core/context-builder.ts - Honesty guidance in prompt
  • src/core/response-parser.ts - STUCK action type
  • src/core/action-executor.ts - STUCK action handling
  • src/integrations/copilot-agent.ts - Model listing methods

Tests:

  • src/core/model-compatibility.test.ts - New parameterized tests (17 test cases)
  • src/integrations/copilot-agent.test.ts - listModels tests

Documentation:

  • README.md - Updated features, config options, run options
  • docs/architecture.md - STUCK action, updated issues table
  • docs/cookbook.md - Multi-task processing, STUCK troubleshooting

✅ Validation

  • npm run typecheck
  • npm test ✅ (305 tests passing, +20 new tests)
  • npm run build

📚 Documentation Updates

  • README.md: Added multi-task processing, --pause-between-tasks, new config options
  • architecture.md: Documented STUCK action, updated issues table showing all issues FIXED
  • cookbook.md: Added multi-task processing section, STUCK troubleshooting
  • JOURNAL.md: Detailed implementation notes

🔗 Related

  • Fixes the critical issue discovered during v0.1.0 testing
  • Addresses model list discrepancy between hardcoded init options and SDK available models

BREAKING FIX: The ghcralph run --file PLAN.md command now correctly
processes all pending tasks in a plan file sequentially instead of
exiting after just the first task.

Changes:
- Add outer while loop for multi-task iteration in run.ts
- Create fresh AI agent instance per task (Ralph pattern)
- Add --pause-between-tasks flag for strict Ralph mode
- Add task-level retry with configurable maxRetriesPerTask
- Add createTaskCheckpoint() and createFailureCheckpoint() methods
- Add pushToRemote() method to GitBranchManager
- Add loadPreviousTaskResults() and appendTaskResult() to ProgressTracker
- Add reload() method to PlanManager interface
- Add HONESTY_GUIDANCE to prompt template
- Add [ACTION:STUCK] action type for graceful failure signaling
- Add waitForKeypress() utility function
- Add maxRetriesPerTask and autoPush config options

This implements Option A from LOOP_MAJOR_BUG_REMEDIATION_PLAN.md
- Add listAvailableModels() to CopilotAgent using SDK's listModels API
- Add static fetchAvailableModels() for use without agent initialization
- Update ghcralph init to dynamically fetch models from Copilot SDK
- Fall back to hardcoded list if SDK fetch fails
- Add parameterized model compatibility tests for response parsing
- Test CREATE, EDIT, EXECUTE, COMPLETE, STUCK action variations
- Export ModelInfo type from integrations module

Addresses model list discrepancy between hardcoded init options
and actual Copilot SDK available models.

Tests: 305 passing
@rpothin rpothin self-assigned this Jan 28, 2026
@rpothin rpothin added the bug Something isn't working label Jan 28, 2026
- Add multi-task processing feature to README
- Add --pause-between-tasks flag to Advanced Run Options
- Add maxRetriesPerTask and autoPush to Configuration Options
- Update Key Features list
- Document STUCK action in architecture.md
- Add multi-task processing section to cookbook.md
- Add STUCK troubleshooting to cookbook.md
- Update Identified Issues table with fixed items
- Prefix unused parameter with underscore (_currentDefault)
- Add explicit return types to async mock functions
@rpothin rpothin merged commit 6f6faca into main Jan 28, 2026
10 checks passed
@rpothin rpothin deleted the v0.1.2-preparation branch January 28, 2026 04:44
rpothin added a commit that referenced this pull request Jan 28, 2026
…gy, failure warning

Issue #4: Enhanced prompt engineering for honesty
- Added HONESTY_GUIDANCE section to context-builder with completion integrity rules
- Added STUCK_EXAMPLE to prompt-examples showing proper stuck action format
- Updated FORMAT_INSTRUCTIONS and MINIMAL_EXAMPLES to include STUCK action
- Added failure warning in ActionExecutor when COMPLETE used despite failed commands

Issue #2: Git push implementation with configurable pushStrategy
- Added pushStrategy config option: 'per-task' | 'per-run' | 'manual'
- per-task (default): Push after each task completes
- per-run: Push once at the end of the run
- manual: No automatic push

Files modified:
- src/core/context-builder.ts - HONESTY_GUIDANCE enhancement
- src/core/prompt-examples.ts - STUCK_EXAMPLE and format updates
- src/core/action-executor.ts - Failed command tracking and warning
- src/core/config-schema.ts - pushStrategy option
- src/commands/run.ts - pushStrategy implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant