Skip to content

Conversation

@mattzcarey
Copy link
Owner

@mattzcarey mattzcarey commented Jan 9, 2026

Summary

This PR adds the zagi agent command suite for AI-assisted task planning and execution using the RALPH pattern (Recursive Agent Loop Pattern for Humans).

New Commands

  • zagi agent plan - Interactive planning sessions with AI
  • zagi agent run - Automated task execution loop
  • zagi tasks import - Import tasks from markdown plan files

Usage

Planning with agent plan

Start an interactive planning session where an AI agent helps you design and create tasks:

# Start interactive session (agent asks what you want to build)
zagi agent plan

# Start with initial context
zagi agent plan "Add user authentication with JWT"

# Preview the prompt without executing
zagi agent plan --dry-run

The planning agent follows a collaborative protocol:

  1. Explores codebase - Reads AGENTS.md and relevant code
  2. Asks clarifying questions - Scope, constraints, preferences
  3. Proposes plan - Presents numbered implementation steps
  4. Creates tasks - Only after you explicitly approve

Running tasks with agent run

Execute the RALPH loop to automatically complete pending tasks:

# Run until all tasks complete (or fail 3x)
zagi agent run

# Run only one task then exit
zagi agent run --once

# Safety limit - stop after N tasks
zagi agent run --max-tasks 10

# Preview what would run
zagi agent run --dry-run

Importing tasks from plans

Convert a markdown plan file into tasks:

# Import tasks from a plan file
zagi tasks import plan.md

Executor Configuration

Control which AI executes tasks:

# Use Claude Code (default)
ZAGI_AGENT=claude zagi agent run

# Use opencode
ZAGI_AGENT=opencode zagi agent run

# Use a custom command
ZAGI_AGENT_CMD="aider --yes" zagi agent run

Agent Safety Features

When ZAGI_AGENT is set:

  • Append-only editing: tasks edit appends instead of replacing (prevents accidental overwrites)
  • Blocked destructive commands: reset --hard, push --force, clean -f, etc.
  • Required commit prompts: git commit requires --prompt flag

Test Plan

  • Unit tests for agent.zig
  • Integration tests for agent plan --dry-run
  • Integration tests for agent run with mocked executor
  • Tests for append-only task editing
  • Tests for error conditions and edge cases
  • Tests for ZAGI_AGENT_CMD override

Generated with Claude Code

Implements the RALPH (Run Agent Loop with Prompts Headlessly) workflow:
- --claude (default), --opencode, --runner flags for different runners
- --model flag to specify model
- --once flag to run single task
- --dry-run flag to preview without executing
- --delay and --max-tasks safety controls
- Failure tracking: skips tasks after 3 consecutive failures
- Added --json support to ready command for programmatic access

Also updates start.sh to be a generic RALPH runner script with:
- Auto-detection of zagi binary
- --import flag to import tasks from plan.md
- Same flags as git tasks run

🤖 Generated with [Claude Code](https://claude.com/claude-code)
- Add new `zagi agent` command for RALPH loop execution
- Remove `tasks run` subcommand (replaced by `zagi agent`)
- Remove `--after` dependency syntax from tasks (simplify model)
- Remove `ready` command (no longer needed without dependencies)
- Support --executor flag for claudecode/opencode/custom commands
- Support ZAGI_AGENT env var as default executor
- Add logging to agent.log file
- Add --once, --dry-run, --delay, --max-tasks safety options

🤖 Generated with [Claude Code](https://claude.com/claude-code)
- Rename 'claudecode' to 'claude' for consistency
- Remove --executor flag, use ZAGI_AGENT env var only
- Add ZAGI_AGENT_CMD for custom command override
- Fix segfault: dupe task.id key before storing in hashmap
- Remove default model - use executor defaults (claude -p, opencode run)
- Implement `zagi agent plan` for starting planning sessions
- Add planning prompt with detailed instructions for task creation
- Support ZAGI_AGENT_CMD for custom executor commands
- Update tests to remove obsolete --after and ready references
- Create friction.md documenting known issues:
  - ZAGI_AGENT validation missing
  - Relative path issues in agent
  - Memory leaks in tasks.zig
- Add tasks 011-014 for friction fixes

🤖 Generated with [Claude Code](https://claude.com/claude-code)
- Move deinit() call after print in runDelete to avoid printing freed memory
- Update non-git directory test to accept both "error" and "fatal" messages

🤖 Generated with [Claude Code](https://claude.com/claude-code)
- Add escapeJsonString() helper for proper JSON output
- Escape quotes, backslashes, newlines in task content for --json
- Update start.sh to use tasks list --json (removed 'ready' command)
- Use python3 for reliable JSON parsing of first pending task

🤖 Generated with [Claude Code](https://claude.com/claude-code)
- Use --output-format stream-json for real-time observability
- Add --dangerously-skip-permissions by default for headless runs
- Support CC_CMD env var to override claude command
- Log per-task JSON to logs/<task-id>.json

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

Shell aliases like 'cc' aren't available in scripts, so use the full
'claude --dangerously-skip-permissions' command directly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Validates ZAGI_AGENT against known executors ('claude', 'opencode').
Invalid values like '1' now show clear error with valid options.
ZAGI_AGENT_CMD bypasses validation for custom executors.
Agents now read CONTEXT.md first to understand the overall mission,
current focus, and work streams before tackling their specific task.
Includes link to RALPH methodology.
CONTEXT.md is ephemeral - lives for PR lifetime, deleted before merge.
Document the key concepts in the agent module:
- planning_prompt_template: explains its purpose for creating
  self-contained, verifiable tasks during interactive planning
- RALPH loop algorithm: ASCII diagram showing the execution flow
  with failure handling, safety limits, and exit conditions
- consecutive_failures tracking: explains why we track consecutive
  (not total) failures and the memory management for duplicated keys
Test suite covers:
- RALPH loop behavior (task execution, --once, --max-tasks)
- Consecutive failure counting (increment on failure, reset on success)
- Max failures exit condition (skip after 3 failures, exit when all fail)
- Dry-run mode output verification
- Task completion integration (marks tasks done)
- Error handling (invalid ZAGI_AGENT, ZAGI_AGENT_CMD bypass)
- Reduce createFixtureRepo commit count from 100 to 20
- Switch 6 test files to use lightweight createTestRepo (1 commit)
- Tests now create their own specific fixtures as needed
- Result: ~74-93% faster test execution (411s -> 30s wall-clock)
Add --parallel flag to agent run command for concurrent task execution.
When parallel > 1, tasks run simultaneously with streaming JSON output
to individual log files (logs/<task-id>.json).

Features:
- --parallel <n> flag to run n tasks concurrently
- Streaming JSON output via --output-format stream-json for Claude
- Per-task log files for real-time visibility
- Proper tracking of running tasks and completion handling
- Maintains sequential mode (parallel=1) as default

The parallel execution uses shell redirection to stream output
directly to log files, enabling real-time monitoring of agent progress.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Add two new unit tests to verify appendToTask correctly handles
content containing newlines:
- Test appending multi-line content to single-line original
- Test when both original and addition have embedded newlines

The function preserves newlines in the output; escaping for storage
happens at the serialization layer via escapeContentForStorage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
- Change 'Goal:' to 'Initial context:' (matches actual output)
- Change 'PROJECT GOAL:' to 'INITIAL CONTEXT:' (matches prompt template)
- Update prompt section checks (PHASE 1/4, RULES)
- Fix executor expectations (claude not claude -p for interactive)
- Update edit test for append-only agent behavior
- Clear ZAGI_AGENT_CMD in test helper to isolate tests
- Use 'claude' instead of deprecated 'claude-code'
@mattzcarey mattzcarey changed the title Git agent plan Add agent commands for AI-assisted task planning and execution Jan 9, 2026
mattzcarey and others added 8 commits January 9, 2026 15:02
The planning session runs interactively with the default executor model.
Model selection is only available for agent run.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Model selection is handled by the executor itself. This simplifies
the agent interface - users configure their preferred model in the
executor's own config (e.g., claude settings).

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Log files now go to /tmp/zagi/<repo>/<hash>.log instead of agent.log
- Simplified completion promise to just "TASK_DONE"
- Task only completes if agent outputs TASK_DONE marker
- Capture and display agent output after completion

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Require both start and end markers of completion promise
- Add knowledge persistence section for AGENTS.md updates
- Simplified completion promise bullet points

Co-Authored-By: Claude Opus 4.5 <[email protected]>
…ands

- When ZAGI_AGENT_CMD is set with ZAGI_AGENT, mode flags are auto-added
  (-p for claude, run for opencode)
- Add docs/setup.md with full executor configuration documentation
- Add Zig tests for buildExecutorArgs covering all scenarios
- Update AGENTS.md to reference new setup docs
- Split --prompts to only show prompts (200 char truncation)
- Add --agent flag to show agent name only
- Add --session flag to show session transcript
- Add --session-offset=N and --session-limit=N for pagination
- Shows byte range and suggests next offset when truncated
- Document new log flags: --prompts, --agent, --session
- Document session pagination: --session-offset, --session-limit
- Document git notes namespaces for AI metadata
- Update agent mode docs to reflect auto-detection from environment
- Clarify ZAGI_AGENT is for executor selection, agent mode is auto-detected
@mattzcarey mattzcarey merged commit 6dd4162 into main Jan 9, 2026
1 check 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.

2 participants