Skip to content

Ralph 2.0 Go CLI#2

Merged
iyaki merged 130 commits into
mainfrom
go-migration
Mar 29, 2026
Merged

Ralph 2.0 Go CLI#2
iyaki merged 130 commits into
mainfrom
go-migration

Conversation

@iyaki

@iyaki iyaki commented Mar 29, 2026

Copy link
Copy Markdown
Owner

Why

Ralph has outgrown the original shell-based implementation. This PR introduces a Go-based CLI architecture that is easier to maintain, test, and evolve, while preserving the core workflow and adding stronger configuration, multi-agent support, and quality gates.

What’s included

  • Replaces ralph.sh with a compiled Go CLI (cmd/ralph) and structured internal packages.
  • Adds a pluggable agent layer with support for:
    • opencode
    • claude
    • cursor
  • Adds --model and agent mode support, with clear precedence across flags, env vars, config, and prompt front matter.
  • Implements first-class commands:
    • run for explicit execution
    • init for interactive setup and config generation
  • Introduces robust config loading and merging:
    • global config + local overlay support
    • TOML-based config files
    • improved precedence handling and override behavior
  • Improves prompt handling:
    • file, stdin, and inline prompt sources
    • front matter parsing for per-prompt overrides
  • Upgrades execution + logging:
    • real-time streaming output
    • improved completion signal handling
    • safer logging behavior (including permissions hardening and explicit flag precedence)
  • Adds comprehensive test coverage:
    • unit tests across core packages
    • black-box e2e harness and scenario coverage (prompt resolution, config precedence, logging, flags, max iterations, etc.)
  • Establishes spec-driven development artifacts and documentation under specs/.
  • Adds repo quality and release infrastructure:
    • Make targets for lint/test/e2e/security/coverage/mutation
    • lefthook integration
    • CI workflows for quality, security, release, and dependabot automation
    • devcontainer/tooling updates for reproducible local development

Breaking changes / migration notes

  • ralph.sh is removed in favor of the Go binary.
  • Configuration is now TOML-based and supports overlay merging.
  • Users should run through ralph init (or update existing config files) to align with the new format and defaults.

Validation

  • Added/updated extensive unit and e2e tests for new behavior.
  • CI workflows now enforce quality/security checks and release readiness.

Outcome

This PR establishes the Ralph 2.0 foundation: a production-ready Go CLI with multi-agent support, deterministic configuration behavior, strong test coverage, and maintainable delivery pipelines.

iyaki added 30 commits March 29, 2026 01:22
- Introduced `Agent` interface and implementations for `claude` and `opencode`.
- Updated command handling to select and execute the configured agent.
- Enhanced documentation to reflect new agent support and usage instructions.
- Introduced `--model` flag and `RALPH_MODEL` environment variable for specifying AI models.
- Updated `GetAgent` function to accept model parameter.
- Modified `ClaudeAgent` and `OpencodeAgent` to utilize the specified model during execution.
- Enhanced documentation in GO.md to reflect new model selection capabilities.
- Added test scripts to verify model precedence from flags, environment variables, and config files.
- Updated the executor package to improve command execution and output handling.
- Refactored the logger package for better file management and logging configuration.
- Enhanced the prompt package to streamline prompt retrieval from various sources.
- Improved test coverage for executor, logger, and prompt functionalities.
- Added utility functions for better code organization and readability.
iyaki added 26 commits March 29, 2026 01:25
Copilot AI review requested due to automatic review settings March 29, 2026 01:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces the “Ralph 2.0” Go-based CLI along with specs-first documentation and an expanded automated test suite (unit + E2E) covering routing, config precedence, prompt front matter, logging, and agent integration.

Changes:

  • Added a Go CLI implementation (cobra-based) with init/run command routing, config overlays, agent env overrides, front matter parsing, and logging.
  • Added extensive unit + end-to-end tests plus a test agent to validate CLI behavior deterministically.
  • Added/updated project specs, dev tooling, and CI workflows to support the new Go implementation and release process.

Reviewed changes

Copilot reviewed 122 out of 124 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/e2e/types_test.go Defines shared E2E test types.
test/e2e/specs_flags_test.go E2E coverage for specs flags.
test/e2e/scenarios_test.go E2E scenarios for loop behavior.
test/e2e/run_command_test.go E2E coverage for run routing.
test/e2e/prompt_test.go E2E prompt source tests.
test/e2e/plan_flags_test.go E2E plan naming tests.
test/e2e/model_flags_test.go E2E model/agent-mode flags.
test/e2e/logging_flags_test.go E2E logging behavior validation.
test/e2e/init_command_test.go E2E init command behavior.
test/e2e/config_precedence_test.go E2E precedence (flags/env/config).
test/e2e/config_local_test.go E2E local overlay behavior.
test/e2e/config_by_prompt_test.go E2E front matter overrides.
test/e2e/agents/ralph-test-agent/main_test.go Unit tests for test agent.
test/e2e/agents/ralph-test-agent/main.go Test-only agent binary.
test/e2e/agent_selection_test.go E2E agent selection tests.
test/e2e/agent_env_overrides_test.go E2E child env overrides.
specs/vision-goals.md Defines project vision/goals.
specs/run-command.md Documents run command routing.
specs/release-workflow.md Documents release workflow.
specs/prompts.md Documents prompt resolution.
specs/logging.md Documents logging behavior.
specs/init-command.md Documents init command design.
specs/development-testing.md Documents dev/testing workflow.
specs/core-architecture.md Documents core CLI architecture.
specs/config-local-overlay.md Documents overlay merge rules.
specs/config-by-prompt.md Documents prompt front matter overrides.
specs/agents/opencode.md Opencode integration spec.
specs/agents/cursor.md Cursor integration spec.
specs/agents/claude.md Claude integration spec.
specs/agents.md Agent interface/selection spec.
specs/agent-env-overrides.md Documents --env child env support.
specs/README.md Index for specs set.
skills-lock.json Locks external skills metadata.
ralph.toml Adds default config example.
package.json Adds JS tooling dependency.
opencode.jsonc OpenCode configuration updates.
logs/.gitignore Ignores generated logs.
lefthook.yml Adds local hook automation.
internal/prompt/frontmatter_test.go Adds front matter parsing tests.
internal/prompt/frontmatter.go Implements front matter parsing.
internal/logger/logger_test.go Adds logger unit tests.
internal/logger/logger.go Implements file logger behavior.
internal/executor/executor_test.go Adds executor unit tests.
internal/executor/executor.go Implements command execution helper.
internal/config/writer_test.go Adds config writer tests.
internal/config/writer.go Implements atomic config writing.
internal/config/config_local_test.go Adds overlay config tests.
internal/cli/run_test.go Adds run command tests.
internal/cli/run_internal_test.go Adds internal run helpers tests.
internal/cli/init_test.go Adds init command structure tests.
internal/cli/init_internal_test.go Adds init internal behavior tests.
internal/cli/init.go Implements init command skeleton.
internal/cli/cmd_config_test.go Adds precedence tests for CLI.
internal/cli/cmd.go Creates root command + subcommands.
internal/agent/runner.go Adds child env builder + exec helper.
internal/agent/opencode.go Implements opencode agent.
internal/agent/cursor.go Implements cursor agent.
internal/agent/claude.go Implements claude agent.
internal/agent/agent.go Agent interface + factory.
go.sum Adds Go dependency checksums.
go.mod Defines module + dependencies.
examples/ralph.toml Provides full config example.
cmd/ralph/main_test.go Adds CLI entrypoint tests.
cmd/ralph/main.go Adds CLI entrypoint.
Makefile Adds build/test/quality targets.
LICENSE Adds MIT license file.
CONTRIBUTING.md Adds contributor workflow docs.
AGENTS.md Adds agent contribution guidelines.
.opencode/skills Links OpenCode skills directory.
.opencode/plans/.gitignore Ignores OpenCode plans output.
.opencode/commands/spec-status.md Adds OpenCode command doc.
.gremlins.yaml Adds mutation testing config.
.golangci.yml Adds golangci-lint config.
.go-arch-lint.yml Adds architecture lint config.
.gitignore Updates repo ignore rules.
.github/workflows/tests.yml Removes legacy shell test workflow.
.github/workflows/security.yml Adds Go security workflow.
.github/workflows/release.yml Adds release workflow for binaries.
.github/workflows/quality.yml Adds CI quality gates.
.github/workflows/dependabot-automerge.yml Adds dependabot automerge.
.github/dependabot.yml Adds npm/go updates to dependabot.
.devcontainer/setup.sh Devcontainer bootstrap script.
.devcontainer/pull-git-lfs-artifacts-override.sh Overrides LFS pull behavior.
.devcontainer/install-go-tools.sh Installs Go tools in container.
.devcontainer/devcontainer.json Updates devcontainer definition.
.devcontainer/devcontainer-lock.json Locks devcontainer features.
.agents/skills/skill-creator/scripts/utils.py Adds skill parsing utility.
.agents/skills/skill-creator/scripts/quick_validate.py Adds skill quick validation script.
.agents/skills/skill-creator/scripts/package_skill.py Adds skill packager script.
.agents/skills/skill-creator/assets/eval_review.html Adds eval review static asset.
.agents/skills/skill-creator/agents/comparator.md Adds comparator agent spec.
.agents/skills/code-search/SKILL.md Adds code-search skill doc.
.agents/skills/agent-spec-creation/SKILL.md Adds agent spec workflow skill.
.agents/skills/agent-implementation/SKILL.md Adds agent implementation skill.
.agents/.skill-lock.json Adds agents skill lock.
Comments suppressed due to low confidence (5)

internal/logger/logger.go:1

  • getGitBranch (and getGitCommit) return \"N/A\" on failure, but NewLogger prints these lines whenever the value is non-empty—so logs will include Git branch: N/A even when git metadata is unavailable. To match the intent of 'when available' (and the function comment), return an empty string on error (or update the caller to explicitly test for \"N/A\" and omit the line).
    internal/cli/init.go:1
  • TTY detection checks os.Stdout only, but ralph init reads from stdin (interactive questionnaire). This can incorrectly allow non-interactive runs (e.g., stdin is piped) or block waiting for input. Consider checking both stdin and stdout (or use golang.org/x/term.IsTerminal(int(fd)) on stdin) so the command reliably fails fast when not interactive.
    internal/cli/init.go:1
  • The error from getWorkingDir() is ignored. If os.Getwd fails, cwd will be empty and the command may write to an unintended relative location. Handle the error and return a clear failure so init doesn’t proceed with an invalid output path.
    internal/prompt/frontmatter.go:1
  • strings.TrimSpace(body) removes all leading/trailing whitespace, which can unintentionally change prompt content (e.g., intentional indentation, trailing newlines, or leading spaces). If the goal is only to drop the single newline after the closing ---, prefer trimming only leading \\r\\n after the delimiter, or return the body unchanged and let callers decide.
    AGENTS.md:1
  • Correct typo: 'Writting' should be 'Writing'.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +73 to +83
"features": {
"ghcr.io/devcontainers/features/common-utils:": {
"installZsh": false,
"installOhMyZsh": false,
"installOhMyZshConfig": false,
"username": "automatic"
},
"ghcr.io/devcontainers/features/go:": {
"version": "1.25",
"golangciLintVersion": "latest"
},

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devcontainer feature identifiers look malformed (e.g., common-utils: and go: have a trailing colon but no feature version). Devcontainer features generally require an explicit version suffix (e.g., common-utils:2, go:1). As written, feature resolution may fail.

Copilot uses AI. Check for mistakes.
"""

import sys
import os

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os is imported but not used in this script. Removing unused imports keeps the script cleaner and avoids linter failures if Python linting is introduced.

Suggested change
import os

Copilot uses AI. Check for mistakes.
@iyaki iyaki merged commit 756d50f into main Mar 29, 2026
13 of 14 checks passed
@iyaki iyaki deleted the go-migration branch March 29, 2026 01:33
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