Skip to content

feat(history): add historical log context for Ralph iterations - #10

Merged
AskTinNguyen merged 1 commit into
mainfrom
feature/historical-log-context
Jan 19, 2026
Merged

AskTinNguyen merged 1 commit into
mainfrom
feature/historical-log-context

Conversation

@AskTinNguyen

Copy link
Copy Markdown
Owner

Summary

  • Enable fresh Ralph iterations to optionally access historical logs from earlier runs to avoid repeating failed approaches
  • Three modes: off (default), smart (recommended), full
  • Parses existing run-*.md summary files for context

Changes

New files:

  • lib/history/indexer.js - Parses run-*.md summary files into structured data
  • lib/history/context-cli.js - CLI to generate {{HISTORICAL_CONTEXT}} markdown
  • lib/history/index.js - Module exports

Modified files:

  • .agents/ralph/config.sh - Added RALPH_HISTORY_* configuration variables
  • .agents/ralph/PROMPT_build.md - Added {{HISTORICAL_CONTEXT}} section
  • .agents/ralph/loop.sh - Added history generation before render_prompt()
  • bin/ralph - Added --with-history, --no-history, --history-mode flags

Usage

# Enable with smart mode (recommended)
ralph build 5 --with-history

# Use full historical context
ralph build 5 --history-mode=full

# Disable historical context (default)
ralph build 5 --no-history

Configuration

# In .agents/ralph/config.sh
RALPH_HISTORY_MODE=off          # off|smart|full
RALPH_HISTORY_TOKEN_BUDGET=4000 # Max tokens for context
RALPH_HISTORY_MAX_RUNS=10       # Max runs to index

Test plan

  • Indexer parses run-*.md files correctly
  • Context CLI generates valid markdown output
  • Smart mode prioritizes failures for current story
  • Full mode includes all runs by relevance
  • CLI flags work correctly
  • Bash syntax validation passes
  • Integration test with actual build

🤖 Generated with Claude Code

Enable fresh Ralph iterations to optionally access historical logs from
earlier runs to avoid repeating failed approaches.

Features:
- Three modes: off (default), smart (recommended), full
- Configurable token budget (default 4000)
- Parses existing run-*.md summary files
- CLI flags: --with-history, --no-history, --history-mode

Configuration in .agents/ralph/config.sh:
- RALPH_HISTORY_MODE: off|smart|full
- RALPH_HISTORY_TOKEN_BUDGET: max tokens for context
- RALPH_HISTORY_MAX_RUNS: max historical runs to index

Smart mode prioritizes:
1. Failures for current story
2. Successful approaches for current story
3. Recent failures from other stories

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@AskTinNguyen

Copy link
Copy Markdown
Owner Author

@greptileai

@greptile-apps

greptile-apps Bot commented Jan 19, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is well-structured with proper error handling, backward compatibility (default mode off), and clear separation of concerns. Bash syntax validates correctly, Node.js code follows good practices with try-catch blocks, and the integration is cleanly isolated with environment variables. The feature is opt-in and includes comprehensive configuration options.
  • No files require special attention

Important Files Changed

Filename Overview
lib/history/indexer.js New file implementing run summary parsing with structured data extraction for historical context
lib/history/context-cli.js New CLI tool for generating markdown historical context with smart/full modes and token budget management
.agents/ralph/loop.sh Integrated historical context generation before prompt rendering with proper environment variable passing
bin/ralph Added CLI flags for history mode with validation and environment variable propagation

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI as bin/ralph
    participant LoopScript as loop.sh
    participant Indexer as indexer.js
    participant ContextCLI as context-cli.js
    participant Prompt as PROMPT_build.md

    User->>CLI: ralph build 5 --with-history
    CLI->>CLI: Parse flags and set env
    CLI->>LoopScript: Execute with RALPH_HISTORY_MODE
    
    LoopScript->>LoopScript: Start iteration
    LoopScript->>LoopScript: Select next story and set STORY_ID
    
    alt History enabled and STORY_ID exists
        LoopScript->>ContextCLI: Invoke node context-cli.js
        ContextCLI->>Indexer: buildIndex prdFolder
        Indexer->>Indexer: Parse run-*.md files
        Indexer-->>ContextCLI: Return structured index
        
        alt Smart mode
            ContextCLI->>Indexer: Get story runs and failures
            ContextCLI->>ContextCLI: Generate focused context
        else Full mode
            ContextCLI->>ContextCLI: Score and rank all runs
            ContextCLI->>ContextCLI: Generate complete context
        end
        
        ContextCLI-->>LoopScript: Return markdown context
        LoopScript->>LoopScript: Export HISTORICAL_CONTEXT
        LoopScript->>LoopScript: Log context generation
    end
    
    LoopScript->>Prompt: Call render_prompt
    Prompt->>Prompt: Replace HISTORICAL_CONTEXT placeholder
    Prompt-->>LoopScript: Rendered prompt with history
    LoopScript->>LoopScript: Execute agent iteration
    LoopScript-->>User: Complete with learning
Loading

@greptile-apps

greptile-apps Bot commented Jan 19, 2026

Copy link
Copy Markdown

Greptile's behavior is changing!

From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section.

This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".

AskTinNguyen added a commit that referenced this pull request Jan 19, 2026
Address GreptileAI review comments:
- Prefix unused 'success' function with underscore (line 42)
- Prefix unused 'parallelModule' variable with underscore (line 749)
- Add missing 'warn()' function definition (line 876 - CRITICAL)

This resolves all critical logic issues flagged in PR #10.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@AskTinNguyen
AskTinNguyen merged commit eacf090 into main Jan 19, 2026
4 of 11 checks passed
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.

1 participant