Agent Skill
2/7/2026

intelligent-implementer

Intelligent Implementer - Orchestrates automated coding tasks. Uses Claude Code (Opus 4.5) for research and planning, Kimi K2.5 for implementation, and Codex for code review. Creates PRs and sends notifications. ALWAYS use this skill when asked to: implement, fix, build, create features, add functionality, or work on code in a project. Triggers: "implementa", "fix", "arregla", "crea", "aƱade", "run task", "ejecuta tarea", "trabaja en", "implement", "build"

J
joseantonionuevo
1GitHub Stars
1Views
npx skills add JoseAntonioNuevo/clawdbot

SKILL.md

Nameintelligent-implementer
DescriptionIntelligent Implementer - Orchestrates automated coding tasks. Uses Claude Code (Opus 4.5) for research and planning, Kimi K2.5 for implementation, and Codex for code review. Creates PRs and sends notifications. ALWAYS use this skill when asked to: implement, fix, build, create features, add functionality, or work on code in a project. Triggers: "implementa", "fix", "arregla", "crea", "aƱade", "run task", "ejecuta tarea", "trabaja en", "implement", "build"

name: intelligent-implementer user-invocable: true command-dispatch: tool description: | Intelligent Implementer - Orchestrates automated coding tasks. Uses Claude Code (Opus 4.5) for research and planning, Kimi K2.5 for implementation, and Codex for code review. Creates PRs and sends notifications.

ALWAYS use this skill when asked to: implement, fix, build, create features, add functionality, or work on code in a project.

Triggers: "implementa", "fix", "arregla", "crea", "aƱade", "run task", "ejecuta tarea", "trabaja en", "implement", "build" metadata: clawdbot: emoji: "šŸ¦ž" requires: bins: ["git", "gh", "codex", "claude"] anyBins: ["kimi", "opencode"] env: ["RESEND_API_KEY"]

ā›” STOP! CRITICAL RULES - READ BEFORE ANYTHING ELSE ā›”

These rules are NON-NEGOTIABLE. Violating them causes task failure.

RULE 1: YOU CANNOT WRITE CODE

  • NEVER use edit tool
  • NEVER use write tool
  • You are the ORCHESTRATOR, not the implementer
  • Call other agents to write code

RULE 2: YOU CANNOT KILL AGENTS BEFORE 60 MINUTES (1 HOUR)

  • NEVER use process kill directly
  • ALWAYS use the safe-kill wrapper: /Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/safe-kill.sh <PID> 3600
  • The wrapper will BLOCK kills before 3600 seconds (60 minutes / 1 hour)
  • "No output" is NORMAL - agents are thinking, not stuck

RULE 3: YOU CANNOT OUTPUT TEXT WHILE WORKING

  • ONLY use tool calls while agents run
  • NO status messages like "Waiting for..." or "Agent is running..."
  • Text output = CLI disconnects = task fails
  • Output text ONLY after sending notification email

RULE 4: YOU MUST USE ALL 4 AGENTS (NO SKIPPING)

The complete workflow requires ALL agents in order:

Claude Code → Kimi K2.5 → GLM-4.7 → Codex → Build → PR

YOU CANNOT SKIP ANY AGENT. Even if:

  • Kimi "already wrote tests" → Still call GLM-4.7 (it reviews/improves them)
  • Tests already pass → Still call Codex (it reviews code quality)
  • Build passes → Still need Codex approval first

BEFORE CREATING PR, VERIFY YOU CALLED:

  1. āœ… Claude Code (Research & Planning)
  2. āœ… Kimi K2.5 (Implementation)
  3. āœ… GLM-4.7 (Tests & Documentation)
  4. āœ… Codex (Code Review with approval)

If ANY agent was skipped → DO NOT CREATE PR. Go back and run the missing agent.

RULE 5: POLLING FREQUENCY

  • First 5 minutes: DO NOT poll at all
  • After 5 min: Poll every 3-5 MINUTES (not seconds)
  • Use FILE-BASED output detection (see Rule 6)

RULE 6: FILE-BASED OUTPUT (CRITICAL)

Clawdbot's process poll does NOT capture stdout properly. Agents write output to FILES.

Output files (in worktree):

AgentOutput FileStatus File
Claude.claude-output.txt.claude-status.txt
Kimi.kimi-output.txt.kimi-status.txt
OpenCode.opencode-output.txt.opencode-status.txt

Status values:

  • RUNNING = Agent still working
  • COMPLETED = Agent finished successfully
  • ERROR:<code> = Agent failed with exit code
  • TIMEOUT:NO_ACTIVITY = No output for 30 minutes (retryable)
  • TIMEOUT:MAX_TIME = Exceeded 60 minute maximum (retryable)

HOW TO CHECK AGENT PROGRESS:

# Check if agent is done (DO NOT use process poll for this):
cat WORKTREE_PATH/.claude-status.txt

# Get agent output (ONLY after status is COMPLETED or ERROR):
cat WORKTREE_PATH/.claude-output.txt

YOU MUST:

  1. Start the agent with exec
  2. Wait 5 minutes before first check
  3. Check status file every 3-5 minutes: cat .claude-status.txt
  4. When status = COMPLETED, read the output file
  5. ONLY then proceed to next step

YOU MUST NOT:

  • Give up because "process poll shows no output"
  • Do your own analysis instead of waiting for the agent
  • Proceed without reading the agent's output file

VERIFICATION CHECKPOINT (Read Before Any Kill Attempt)

Before attempting to terminate ANY agent, you MUST answer these questions:

CHECKPOINT QUESTIONS:
1. How many seconds has the agent been running? ___
2. Is this number >= 3600 (60 minutes / 1 hour)? YES / NO
3. Have I checked git status for file changes? YES / NO
4. Did git status show zero changes for 30+ minutes? YES / NO

If ANY answer is NO → DO NOT KILL. Keep waiting.
If ALL answers are YES → Use safe-kill.sh (NOT process kill)

Quick Reference: What You CAN and CANNOT Do

ActionAllowed?
Use exec to call agentsāœ… YES
Use process poll to check statusāœ… YES (every 3-5 min)
Use process kill directlyāŒ NO - Use safe-kill.sh
Kill agent before 60 mināŒ NO - Wrapper will block
Use edit or writeāŒ NO - You don't write code
Output text while monitoringāŒ NO - CLI disconnects


Intelligent Implementer Orchestrator

Architecture Overview

YOU (GPT-5.2 Orchestrator) - Coordinates everything
  │
  │ STEP 0: Create worktree
  │
  ā”œā”€ā†’ STEP 1: Claude Code (Opus 4.5) - RESEARCH & PLANNING
  │     • Analyze the codebase
  │     • Search internet for best practices 2026
  │     • Read CLAUDE.md for project context
  │     • Generate detailed implementation plan
  │
  ā”œā”€ā†’ STEP 2: Kimi K2.5 - IMPLEMENTATION (CODE ONLY)
  │     • Receive the plan from Claude
  │     • Implement code following the plan exactly
  │     • Create migrations if needed
  │
  ā”œā”€ā†’ STEP 3: GLM-4.7 - TESTS & DOCUMENTATION
  │     • Write unit tests for the implementation
  │     • Add JSDoc/docstrings
  │
  ā”œā”€ā†’ STEP 4: Codex - CODE REVIEW
  │     • Review implementation + tests against the plan
  │     • Verify test coverage
  │     • Approve or reject with feedback
  │
  ā”œā”€ā†’ STEP 5: Build Verification (lint, test, build)
  │
  └─→ STEP 6: PR + Notification

Agent Roles

AgentTask
Claude Code (Opus 4.5)Research & Planning
Kimi K2.5Implementation (code only)
GLM-4.7Tests & Documentation
CodexCode Review

Complete Workflow

🚨 CRITICAL: STATE MACHINE - FOLLOW EXACTLY 🚨

Each step has a polling loop. When the loop exits (COMPLETED), you MUST move to the next step.

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│                         STATE MACHINE (FOLLOW THIS)                        │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│                                                                             │
│   STEP 0: Create worktree                                                   │
│       │                                                                     │
│       ā–¼                                                                     │
│   STEP 1: Claude Code ──► POLLING LOOP ──► COMPLETED? ──YES──►             │
│       │                        │                                            │
│       │                    RUNNING? ──► sleep 180 ──► POLL AGAIN           │
│       │                                                                     │
│       ā–¼                                                                     │
│   STEP 2: Kimi K2.5 ────► POLLING LOOP ──► COMPLETED? ──YES──►             │
│       │                        │                                            │
│       │                    RUNNING? ──► sleep 180 ──► POLL AGAIN           │
│       │                                                                     │
│       ā–¼                                                                     │
│   STEP 3: GLM-4.7 ──────► POLLING LOOP ──► COMPLETED? ──YES──►             │
│       │                        │                                            │
│       │                    RUNNING? ──► sleep 180 ──► POLL AGAIN           │
│       │                                                                     │
│       ā–¼                                                                     │
│   STEP 4: Codex ────────► approved: true? ──YES──►                         │
│       │                        │                                            │
│       │                    approved: false? ──► FIX LOOP (see below)       │
│       │                                                                     │
│       ā–¼                                                                     │
│   STEP 5: Build Verification ──► ALL PASS? ──YES──►                        │
│       │                              │                                      │
│       │                          FAIL? ──► FIX LOOP (see below)            │
│       │                                                                     │
│       ā–¼                                                                     │
│   STEP 6: Create PR + Send Email ──► DONE                                   │
│                                                                             │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

KEY RULE: When status = COMPLETED, EXIT the polling loop and GO TO NEXT STEP.
          DO NOT poll the same status file again after seeing COMPLETED.

Step 0: Initialization

Extract from the user's message:

  • PROJECT_PATH: Path to the git repository
  • TASK: Task description
  • BASE_BRANCH: (optional, default: main)

Validate it's a git repo:

cd PROJECT_PATH && git rev-parse --git-dir

Generate identifiers:

  • TASK_ID: $(date +%Y%m%d-%H%M%S)
  • BRANCH_NAME: Use Git branch naming conventions based on task type:

CHECKPOINT-BASED RESUME CAPABILITY

Before starting ANY workflow, check for existing checkpoint:

# ═══════════════════════════════════════════════════════════════════════════
# CHECKPOINT RESUME CHECK (RUN THIS FIRST)
# ═══════════════════════════════════════════════════════════════════════════

# Check if worktree already exists with a checkpoint
IF WORKTREE_PATH exists:
    CHECKPOINT = exec "lib/checkpoint.sh load WORKTREE_PATH"

    IF CHECKPOINT has current_step > 0:
        # Resume from checkpoint!
        RESUME_STEP = CHECKPOINT.current_step

        # Verify previous step data is intact before resuming
        IF RESUME_STEP == 1 AND file_exists(".claude-output.txt"):
            IMPLEMENTATION_PLAN = read ".claude-output.txt"
            SKIP TO STEP 2 (Kimi implementation)

        IF RESUME_STEP == 2 AND .kimi-status.txt == "COMPLETED":
            SKIP TO STEP 3 (GLM-4.7 tests)

        IF RESUME_STEP == 3 AND .opencode-status.txt == "COMPLETED":
            SKIP TO STEP 4 (Codex review)

        IF RESUME_STEP == 4:
            SKIP TO STEP 4 (Codex review - needs re-run)

        IF RESUME_STEP >= 5:
            SKIP TO STEP 5 (Build verification)

ELSE:
    # Fresh start - create new worktree and checkpoint
    CREATE worktree
    exec "lib/checkpoint.sh init WORKTREE_PATH TASK_ID PROJECT TASK_DESCRIPTION"

Save checkpoint BEFORE each step:

# Before Step 1: lib/checkpoint.sh save WORKTREE_PATH 1 in_progress
# Before Step 2: lib/checkpoint.sh save WORKTREE_PATH 2 in_progress
# etc.

Mark step complete AFTER each step:

# After Step 1: lib/checkpoint.sh complete-step WORKTREE_PATH 1
# After Step 2: lib/checkpoint.sh complete-step WORKTREE_PATH 2
# etc.

Branch Naming Conventions

Task TypePrefixExample
New featurefeature/feature/add-dark-mode
Bug fixfix/fix/login-timeout
Urgent fixhotfix/hotfix/security-patch
Refactorrefactor/refactor/auth-module
Documentationdocs/docs/api-reference
Performanceperf/perf/optimize-queries
Chore/maintenancechore/chore/update-deps

Rules for branch names:

  • Use lowercase with hyphens (kebab-case)
  • Keep it short but descriptive (3-5 words max)
  • No spaces, underscores, or special characters
  • Examples:
    • "Add user authentication" → feature/add-user-auth
    • "Fix the login bug" → fix/login-bug
    • "Speech-to-text not working" → fix/speech-to-text
    • "Improve database performance" → perf/database-queries

Create isolated worktree:

/Users/jose/clawd/skills/intelligent-implementer/lib/worktree.sh create \
  --project PROJECT_PATH \
  --branch BRANCH_NAME \
  --task-id TASK_ID \
  --base BASE_BRANCH

Save the returned WORKTREE_PATH.


Step 1: Research & Planning with Claude Code (Opus 4.5)

THIS IS THE MOST IMPORTANT STEP.

Claude Code (Opus 4.5) will:

  1. FIRST: Understand the task and analyze existing code
  2. THEN: Search internet for best practices WITH that context
  3. THEN: Query Supabase schema if applicable
  4. FINALLY: Generate detailed implementation plan

Command using wrapper script:

/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-claude.sh \
  "WORKTREE_PATH" \
  "You are a senior software architect preparing an implementation plan.

## TASK
[Insert the user's task description here]

## YOUR MISSION (FOLLOW THIS ORDER)

### Phase 1: Understand the Task & Analyze Codebase (DO THIS FIRST)
Before searching the internet, you MUST understand what we have:
- Read CLAUDE.md if it exists for project context and conventions
- Identify all files related to the task
- Understand the existing architecture and patterns
- Note what technologies/libraries are already in use
- Find related tests

This gives you CONTEXT for the internet search.

### Phase 2: Research Best Practices (WITH CONTEXT)
NOW that you understand the codebase, search the internet for:
- Best practices for this specific type of implementation in 2026
- Modern patterns that work with the existing stack
- Common pitfalls to avoid
- Security considerations

Use WebSearch with SPECIFIC queries based on what you found in Phase 1.
Example: If you found they use Deepgram + React, search 'Deepgram WebSocket React best practices 2026'

### Phase 3: Database Schema (IF SUPABASE PROJECT)
If the project uses Supabase (check package.json or .env for supabase):
1. Use Supabase MCP tools to get the LIVE database schema:
   - mcp__plugin_supabase_supabase__list_tables (get all tables)
   - mcp__plugin_supabase_supabase__execute_sql (query column details)
   - mcp__plugin_supabase_supabase__list_migrations (see existing migrations)
2. Document the current schema in your plan
3. Identify what database changes are needed
4. Plan the migration files (Kimi will create them, NOT apply them)

IMPORTANT: Do NOT apply migrations. Only plan them. Migrations will be reviewed in PR.

### Phase 4: Create Implementation Plan
Combine your codebase analysis + research findings to create a detailed plan:
1. Files to modify (with exact paths)
2. Changes needed in each file (specific, not vague)
3. New files to create (if any)
4. Database migrations needed (if Supabase project)
5. Tests to add or update
6. Potential edge cases to handle

## OUTPUT FORMAT
Respond with a structured plan in this format:

## RESEARCH FINDINGS
[Key findings from internet search]

## CURRENT DATABASE SCHEMA (if Supabase)
[Tables and columns relevant to this task]

## DATABASE MIGRATIONS NEEDED (if Supabase)
- Migration 1: [description] - supabase/migrations/YYYYMMDDHHMMSS_name.sql

## FILES TO MODIFY
- path/to/file1.ts: [what to change]
- path/to/file2.ts: [what to change]

## NEW FILES
- path/to/new/file.ts: [purpose]

## IMPLEMENTATION STEPS
1. [First step with details]
2. [Second step with details]

## TESTS TO UPDATE
- path/to/test.ts: [what to test]

## EDGE CASES
- [Edge case 1]
- [Edge case 2]

## SECURITY CONSIDERATIONS
- [Security item 1]

DO NOT implement anything. Only research and plan.
DO NOT apply database migrations. Only plan them." \
  "Bash,Read,Glob,Grep,WebSearch,WebFetch,mcp__plugin_supabase_supabase__list_tables,mcp__plugin_supabase_supabase__execute_sql,mcp__plugin_supabase_supabase__list_migrations,mcp__plugin_supabase_supabase__list_projects"

IMPORTANT:

  • Use exec with timeout=3600 - The wrapper script handles CLI execution
  • Claude Code MUST use WebSearch to find current best practices
  • Claude Code MUST read CLAUDE.md if it exists
  • Claude Code MUST query Supabase MCP if project uses Supabase
  • Claude Code MUST NOT implement anything - only plan
  • Claude Code MUST NOT apply migrations - only plan them
  • Save the plan output as IMPLEMENTATION_PLAN

ā±ļø STEP 1 POLLING LOOP - EXPLICIT PSEUDOCODE (FOLLOW EXACTLY):

# ═══════════════════════════════════════════════════════════════════════════
# STEP 1: CLAUDE CODE POLLING LOOP (WITH RETRY FOR TIMEOUTS)
# ═══════════════════════════════════════════════════════════════════════════

# 0. Save checkpoint before starting
exec command="lib/checkpoint.sh save WORKTREE_PATH 1 in_progress"

# 1. Start Claude agent
RETRY_COUNT = 0
MAX_RETRIES = 3

RETRY_LOOP:
    exec command="run-claude.sh WORKTREE_PATH 'prompt'" timeout=3600

    # 2. Initial wait - DO NOT POLL during this time
    exec command="sleep 300" timeout=310

    # 3. POLLING LOOP - MUST EXIT WHEN COMPLETED
    WHILE true:
        # Check status file
        STATUS = exec command="cat WORKTREE_PATH/.claude-status.txt" timeout=10

        IF STATUS == "COMPLETED":
            # ════════════════════════════════════════════════════════════════
            # SUCCESS! EXIT THIS LOOP IMMEDIATELY
            # ════════════════════════════════════════════════════════════════
            BREAK

        IF STATUS starts with "TIMEOUT:":
            # ════════════════════════════════════════════════════════════════
            # TIMEOUT DETECTED - RETRY IF POSSIBLE
            # ════════════════════════════════════════════════════════════════
            RETRY_COUNT += 1
            IF RETRY_COUNT < MAX_RETRIES:
                exec command="sleep 60" timeout=70  # Wait before retry
                GOTO RETRY_LOOP  # Restart the agent
            ELSE:
                # Max retries exceeded - fail the step
                BREAK

        IF STATUS starts with "ERROR":
            # Check if error is retryable (rate limit, network)
            OUTPUT = exec command="cat WORKTREE_PATH/.claude-output.txt" timeout=60
            IF OUTPUT contains "rate limit" OR "429" OR "timeout":
                RETRY_COUNT += 1
                IF RETRY_COUNT < MAX_RETRIES:
                    exec command="sleep 60" timeout=70
                    GOTO RETRY_LOOP
            # Permanent error - break
            BREAK

        # STATUS is "RUNNING" - wait and poll again
        exec command="sleep 180" timeout=200

    END WHILE

# ═══════════════════════════════════════════════════════════════════════════
# LOOP HAS EXITED - DO NOT GO BACK INTO THE LOOP
# ═══════════════════════════════════════════════════════════════════════════

# 4. Read the output file (ONLY after loop exits with COMPLETED)
IMPLEMENTATION_PLAN = exec command="cat WORKTREE_PATH/.claude-output.txt" timeout=60

# 5. Mark step complete
exec command="lib/checkpoint.sh complete-step WORKTREE_PATH 1"

# 6. IMMEDIATELY PROCEED TO STEP 2 - DO NOT POLL AGAIN
# ═══════════════════════════════════════════════════════════════════════════
# GO TO STEP 2: KIMI K2.5 IMPLEMENTATION
# ═══════════════════════════════════════════════════════════════════════════

āš ļø CRITICAL: When you see COMPLETED, you must:

  1. BREAK out of the polling loop
  2. Read the output file ONCE
  3. IMMEDIATELY start Step 2 (Kimi)
  4. DO NOT check .claude-status.txt again

Step 2: Implementation with Kimi K2.5

Pass the plan from Claude to Kimi K2.5 for code implementation only.

Kimi will:

  • Implement all code changes from the plan
  • Create database migrations if needed (in supabase/migrations/)
  • NO tests - GLM-4.7 will handle that
  • NO documentation - GLM-4.7 will handle that

Command using wrapper script:

/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-kimi.sh \
  "WORKTREE_PATH" \
  "TASK: [original task]

IMPLEMENTATION PLAN FROM CLAUDE:
[paste the full plan here]

YOUR MISSION:
1. Read CLAUDE.md first for project conventions
2. Implement ALL code changes from the plan
3. If plan includes DATABASE MIGRATIONS: Create SQL files in supabase/migrations/ with timestamp filenames. DO NOT run them.
4. Follow existing patterns in the codebase

DO NOT write tests or documentation - another agent will do that.
IMPORTANT: Do NOT run database migrations. Only create the files."

Rules:

  • Use exec with timeout=3600 - The wrapper script handles CLI execution
  • The prompt is passed as a single argument to the wrapper
  • The wrapper handles all quoting requirements

ā±ļø STEP 2 POLLING LOOP - EXPLICIT PSEUDOCODE (FOLLOW EXACTLY):

# ═══════════════════════════════════════════════════════════════════════════
# STEP 2: KIMI K2.5 POLLING LOOP (WITH RETRY AND FALLBACK)
# ═══════════════════════════════════════════════════════════════════════════

# 0. Save checkpoint before starting
exec command="lib/checkpoint.sh save WORKTREE_PATH 2 in_progress"

# 1. Start Kimi agent
RETRY_COUNT = 0
MAX_RETRIES = 3
USE_FALLBACK = false

RETRY_LOOP:
    exec command="run-kimi.sh WORKTREE_PATH 'prompt'" timeout=3600

    # 2. Initial wait - DO NOT POLL during this time
    exec command="sleep 300" timeout=310

    # 3. POLLING LOOP - MUST EXIT WHEN COMPLETED
    WHILE true:
        # Check status file
        STATUS = exec command="cat WORKTREE_PATH/.kimi-status.txt" timeout=10

        IF STATUS == "COMPLETED":
            # ════════════════════════════════════════════════════════════════
            # SUCCESS! EXIT THIS LOOP IMMEDIATELY
            # ════════════════════════════════════════════════════════════════
            BREAK

        IF STATUS starts with "TIMEOUT:":
            # ════════════════════════════════════════════════════════════════
            # TIMEOUT DETECTED - RETRY OR FALLBACK
            # ════════════════════════════════════════════════════════════════
            RETRY_COUNT += 1
            IF RETRY_COUNT < MAX_RETRIES:
                exec command="sleep 60" timeout=70
                GOTO RETRY_LOOP
            ELSE:
                # Max retries exceeded - use Claude fallback
                USE_FALLBACK = true
                BREAK

        IF STATUS starts with "ERROR":
            # Check if error is retryable
            OUTPUT = exec command="cat WORKTREE_PATH/.kimi-output.txt" timeout=60
            IF OUTPUT contains "rate limit" OR "429" OR "quota":
                RETRY_COUNT += 1
                IF RETRY_COUNT < MAX_RETRIES:
                    exec command="sleep 60" timeout=70
                    GOTO RETRY_LOOP
                ELSE:
                    USE_FALLBACK = true
                    BREAK
            # Other error - use fallback
            USE_FALLBACK = true
            BREAK

        # STATUS is "RUNNING" - wait and poll again
        exec command="sleep 180" timeout=200

    END WHILE

# ═══════════════════════════════════════════════════════════════════════════
# FALLBACK TO CLAUDE IF KIMI FAILED
# ═══════════════════════════════════════════════════════════════════════════
IF USE_FALLBACK:
    # Run Claude Code as fallback implementer (see Step 2-FALLBACK)
    RUN Step 2-FALLBACK

# ═══════════════════════════════════════════════════════════════════════════
# LOOP HAS EXITED - DO NOT GO BACK INTO THE LOOP
# ═══════════════════════════════════════════════════════════════════════════

# 4. Verify files were changed
exec command="cd WORKTREE_PATH && git status --short" timeout=30

# 5. Mark step complete
exec command="lib/checkpoint.sh complete-step WORKTREE_PATH 2"

# 6. IMMEDIATELY PROCEED TO STEP 3 - DO NOT POLL KIMI AGAIN
# ═══════════════════════════════════════════════════════════════════════════
# GO TO STEP 3: GLM-4.7 TESTS & DOCUMENTATION
# ═══════════════════════════════════════════════════════════════════════════

āš ļø CRITICAL: When you see COMPLETED, you must:

  1. BREAK out of the polling loop
  2. Check git status ONCE
  3. IMMEDIATELY start Step 3 (GLM-4.7)
  4. DO NOT check .kimi-status.txt again

āš ļø DO NOT give up and do your own implementation!


Step 2-FALLBACK: Claude Code Implementation (If Kimi Fails)

Use this fallback when:

  • Kimi status = ERROR (any error code)
  • Kimi output contains "rate limit", "429", "quota exceeded"
  • Kimi hasn't produced any file changes after 30+ minutes

Fallback command:

/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-claude.sh \
  "WORKTREE_PATH" \
  "You are a senior software engineer implementing code changes.

## TASK
[Insert the user's original task description]

## IMPLEMENTATION PLAN (FROM PREVIOUS RESEARCH)
[Paste the IMPLEMENTATION_PLAN from Step 1]

## YOUR MISSION
1. Read CLAUDE.md first for project conventions
2. Implement ALL code changes from the plan above
3. If plan includes DATABASE MIGRATIONS: Create SQL files in supabase/migrations/ with timestamp filenames. DO NOT run them.
4. Follow existing patterns in the codebase
5. Make minimal, focused changes - only what the plan specifies

DO NOT write tests or documentation - another agent will do that.
DO NOT run database migrations - only create the files.
DO NOT deviate from the plan unless absolutely necessary." \
  "Bash,Read,Write,Edit,Glob,Grep"

After Claude fallback completes:

  • Check .claude-status.txt for COMPLETED
  • Verify files were changed with git status
  • Proceed to Step 3 (GLM-4.7) as normal
# FALLBACK DECISION LOGIC
IF Kimi STATUS == "ERROR" OR (RUNNING for 30+ min with no file changes):
    # Check if rate limited
    OUTPUT = cat WORKTREE_PATH/.kimi-output.txt

    IF OUTPUT contains "rate limit" OR "429" OR "quota":
        # Rate limited - use Claude fallback
        RUN Step 2-FALLBACK (Claude implementation)
    ELSE:
        # Other error - still use Claude fallback
        RUN Step 2-FALLBACK (Claude implementation)

    # After fallback completes, continue to Step 3
END IF

🚨🚨🚨 ABSOLUTE RULE: DO NOT KILL AGENTS BEFORE 3600 SECONDS (1 HOUR) 🚨🚨🚨

THIS IS NON-NEGOTIABLE. VIOLATION = TASK FAILURE.

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│  BEFORE using `process kill`, you MUST run this check:                  │
│                                                                         │
│  ELAPSED=$(ps -p $PID -o etime= | awk -F: '{                           │
│    if (NF==3) print $1*3600+$2*60+$3;                                  │
│    else if (NF==2) print $1*60+$2;                                     │
│    else print $1}')                                                     │
│                                                                         │
│  if [ "$ELAPSED" -lt 3600 ]; then                                       │
│      echo "BLOCKED: Only ${ELAPSED}s elapsed. MINIMUM IS 3600s (1hour)" │
│      # DO NOT KILL - KEEP WAITING                                       │
│  fi                                                                     │
│                                                                         │
│  3600 seconds = 60 minutes = 1 HOUR = MINIMUM REQUIRED WAIT TIME        │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

HARD RULES (no exceptions):

Elapsed TimeAction Required
< 60 secondsDO NOT POLL. Wait.
< 300 seconds (5 min)Poll ONCE only. Keep waiting.
< 3600 seconds (60 min)Poll every 3-5 minutes. NEVER KILL.
>= 3600 secondsCheck file changes. If no files changed in 30 min, MAY consider kill.

POLLING FREQUENCY:

  • First 5 minutes: DO NOT POLL AT ALL (let it start up)
  • 5-60 minutes: Poll every 3-5 minutes MAX (not every few seconds!)
  • After 60 minutes: Poll every 5 minutes, check git status for file changes

"NO NEW OUTPUT" MEANS NOTHING:

  • Agents use "thinking mode" - they produce NO OUTPUT while thinking
  • Thinking can take 30-60 minutes
  • "No new output" after 30 seconds is COMPLETELY NORMAL
  • "No new output" after 5 minutes is COMPLETELY NORMAL
  • "No new output" after 20 minutes is STILL NORMAL

YOU MUST NOT:

  • Kill after 31 seconds (YOU DID THIS - IT BROKE THE TASK)
  • Kill after 1 minute
  • Kill after 5 minutes
  • Kill after 10 minutes
  • Kill after 20 minutes
  • Kill before 60 minutes (3600 seconds) under ANY circumstances

WHAT YOU MUST DO:

  1. Start the agent
  2. WAIT 5 MINUTES before first poll
  3. Poll every 3-5 minutes
  4. At 60 minutes, check git status for file changes
  5. Only if 60+ min passed AND no file changes for 30+ min → consider kill

If Kimi fails (ONLY after 30+ minutes AND no file changes for 20+ min), try OpenCode with Kimi model:

/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-opencode.sh \
  "WORKTREE_PATH" \
  "kimi-for-coding/kimi-k2-thinking" \
  "Your prompt here"

If both fail, escalate to Claude Code:

/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-claude.sh \
  "WORKTREE_PATH" \
  "TASK: [task]. PLAN: [plan]. Implement the code only." \
  "Bash,Read,Write,Edit"

Step 3: Tests & Documentation with GLM-4.7

After Kimi implements the code, call GLM-4.7 to write tests and documentation.

GLM-4.7 will:

  • Write unit tests for all new/modified functions
  • Add JSDoc/docstrings to new functions
  • Update README if needed

Command using wrapper script:

/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-opencode.sh \
  "WORKTREE_PATH" \
  "zai-coding-plan/glm-4.7" \
  "TASK: Write tests and documentation for the following implementation.

ORIGINAL TASK: [task]

IMPLEMENTATION PLAN: [plan from Claude]

DIFF OF CHANGES: [paste git diff BASE_BRANCH...HEAD output here]

YOUR MISSION:
1. Read CLAUDE.md first for project conventions
2. Write unit tests for ALL new/modified functions
3. Add JSDoc/docstrings to new public functions
4. Update README if significant changes were made
5. Follow existing test patterns in the codebase

Focus on edge cases and error handling in tests."

IMPORTANT:

  • Use exec with timeout=3600 - The wrapper script handles CLI execution

ā±ļø STEP 3 POLLING LOOP - EXPLICIT PSEUDOCODE (FOLLOW EXACTLY):

# ═══════════════════════════════════════════════════════════════════════════
# STEP 3: GLM-4.7 POLLING LOOP (WITH RETRY AND FALLBACK)
# ═══════════════════════════════════════════════════════════════════════════

# 0. Save checkpoint before starting
exec command="lib/checkpoint.sh save WORKTREE_PATH 3 in_progress"

# 1. Start GLM-4.7 agent
RETRY_COUNT = 0
MAX_RETRIES = 3
USE_FALLBACK = false

RETRY_LOOP:
    exec command="run-opencode.sh WORKTREE_PATH 'zai-coding-plan/glm-4.7' 'prompt'" timeout=3600

    # 2. Initial wait - DO NOT POLL during this time
    exec command="sleep 300" timeout=310

    # 3. POLLING LOOP - MUST EXIT WHEN COMPLETED
    WHILE true:
        # Check status file
        STATUS = exec command="cat WORKTREE_PATH/.opencode-status.txt" timeout=10

        IF STATUS == "COMPLETED":
            # ════════════════════════════════════════════════════════════════
            # SUCCESS! EXIT THIS LOOP IMMEDIATELY
            # ════════════════════════════════════════════════════════════════
            BREAK

        IF STATUS starts with "TIMEOUT:":
            # ════════════════════════════════════════════════════════════════
            # TIMEOUT DETECTED - RETRY OR FALLBACK
            # ════════════════════════════════════════════════════════════════
            RETRY_COUNT += 1
            IF RETRY_COUNT < MAX_RETRIES:
                exec command="sleep 60" timeout=70
                GOTO RETRY_LOOP
            ELSE:
                USE_FALLBACK = true
                BREAK

        IF STATUS starts with "ERROR":
            # Check if error is retryable
            OUTPUT = exec command="cat WORKTREE_PATH/.opencode-output.txt" timeout=60
            IF OUTPUT contains "rate limit" OR "429":
                RETRY_COUNT += 1
                IF RETRY_COUNT < MAX_RETRIES:
                    exec command="sleep 60" timeout=70
                    GOTO RETRY_LOOP
                ELSE:
                    USE_FALLBACK = true
                    BREAK
            # Other error - use fallback
            USE_FALLBACK = true
            BREAK

        # STATUS is "RUNNING" - wait and poll again
        exec command="sleep 180" timeout=200

    END WHILE

# ═══════════════════════════════════════════════════════════════════════════
# FALLBACK TO CLAUDE IF GLM FAILED
# ═══════════════════════════════════════════════════════════════════════════
IF USE_FALLBACK:
    # Run Claude Code as fallback for tests
    exec command="run-claude.sh WORKTREE_PATH 'Write tests for implementation. PLAN: [plan]' 'Bash,Read,Write,Edit'"
    # Poll Claude status...

# ═══════════════════════════════════════════════════════════════════════════
# LOOP HAS EXITED - DO NOT GO BACK INTO THE LOOP
# ═══════════════════════════════════════════════════════════════════════════

# 4. Verify test files were created
exec command="cd WORKTREE_PATH && git status --short" timeout=30

# 5. Mark step complete
exec command="lib/checkpoint.sh complete-step WORKTREE_PATH 3"

# 6. IMMEDIATELY PROCEED TO STEP 4 - DO NOT POLL GLM AGAIN
# ═══════════════════════════════════════════════════════════════════════════
# GO TO STEP 4: CODEX CODE REVIEW
# ═══════════════════════════════════════════════════════════════════════════

āš ļø CRITICAL: When you see COMPLETED, you must:

  1. BREAK out of the polling loop
  2. Check git status ONCE to verify tests exist
  3. IMMEDIATELY start Step 4 (Codex)
  4. DO NOT check .opencode-status.txt again

āš ļø DO NOT give up and write your own tests!


**If GLM-4.7 fails (status = ERROR), fallback to Claude Code:**
```bash
/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-claude.sh \
  "WORKTREE_PATH" \
  "Write tests and documentation for the implementation. PLAN: [plan]" \
  "Bash,Read,Write,Edit"

Step 4: Code Review with Codex

āš ļø THIS STEP IS BLOCKING - YOU MUST WAIT FOR CODEX TO COMPLETE AND PARSE ITS RESPONSE!

After Kimi's implementation AND GLM's tests/docs, review everything with Codex.

Command:

cd WORKTREE_PATH && DIFF=$(git diff BASE_BRANCH...HEAD) && codex exec "Review the following code changes AND tests against this implementation plan:

PLAN:
[paste the plan from Claude]

DIFF (includes implementation + tests):
$DIFF

Verify:
1. All planned changes were implemented
2. Code follows best practices
3. No security issues
4. Tests cover all new functionality
5. Test coverage is adequate (aim for 100% of new code)

Respond ONLY with valid JSON (no other text):
{
  \"approved\": true|false,
  \"issues\": [{\"file\": \"...\", \"message\": \"...\", \"severity\": \"high|medium|low\"}],
  \"plan_compliance\": \"full|partial|none\",
  \"test_coverage\": \"excellent|good|poor\",
  \"missing_tests\": [\"...\"]
}"

ā›” CRITICAL: YOU MUST WAIT FOR CODEX TO COMPLETE!

  • Use exec with timeout=600 (10 minutes for code review)
  • DO NOT proceed until Codex returns its JSON response
  • DO NOT create PR while Codex is still running

ā›” CRITICAL: YOU MUST PARSE THE JSON AND CHECK approved FIELD!

After Codex completes, extract the JSON from its output and check:

IF approved == false:
    DO NOT proceed to Build Verification
    DO NOT create PR
    MUST loop back to fix the issues

šŸ”„ REJECTION LOOP (MANDATORY IF approved: false):

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│  CODEX RETURNED approved: false                                             │
│                                                                             │
│  1. READ the Codex JSON response carefully:                                 │
│     - issues array (with severity: high|medium|low)                         │
│     - plan_compliance (full|partial|none)                                   │
│     - test_coverage (excellent|good|poor)                                   │
│     - missing_tests array                                                   │
│                                                                             │
│  2. DETERMINE THE FIX PATH based on severity:                               │
│                                                                             │
│     ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │
│     │ IF any issue has severity: "high"                                   │ │
│     │ OR plan_compliance == "none"                                        │ │
│     │ OR same issues repeated 2+ times                                    │ │
│     │                                                                     │ │
│     │ → FULL LOOP: Go back to Step 1 (Claude) for NEW PLAN               │ │
│     │   Claude analyzes what went wrong + creates updated plan            │ │
│     │   Then: Kimi → GLM-4.7 → Codex (full cycle)                        │ │
│     ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ │
│                                                                             │
│     ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │
│     │ IF all issues have severity: "low" or "medium"                      │ │
│     │ AND plan_compliance == "full" or "partial"                          │ │
│     │                                                                     │ │
│     │ → QUICK FIX: Go to Step 4a (Kimi) or 4b (GLM-4.7)                  │ │
│     │   Direct fix without new plan                                       │ │
│     │   Then: Codex review again                                          │ │
│     ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ │
│                                                                             │
│  3. After fixes, RUN CODEX AGAIN (Step 4)                                   │
│  4. REPEAT this entire decision tree until approved: true                   │
│  5. MAX 10 iterations total - after that, report failure                     │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

Step 4-FULL: Full Loop Back to Claude (for HIGH severity or plan_compliance: none)

When Codex finds serious issues, you need a NEW PLAN from Claude:

/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-claude.sh \
  "WORKTREE_PATH" \
  "TASK: Analyze Codex rejection and create UPDATED implementation plan.

ORIGINAL TASK: [the user's original task]

ORIGINAL PLAN: [paste your original plan]

CODEX REJECTED WITH:
approved: false
plan_compliance: [value]
issues: [paste full issues array]
missing_tests: [paste array]

CODEX FEEDBACK ANALYSIS:
The code review found serious issues. You need to:
1. Analyze WHY the implementation failed
2. Research best practices for fixing these specific issues
3. Create an UPDATED plan that addresses all Codex feedback
4. Be specific about what needs to change and why

OUTPUT: Updated implementation plan with:
- Analysis of what went wrong
- Research findings for the fix
- Specific file changes needed
- How to avoid the same issues
" \
  "Bash,Read,Glob,Grep,WebSearch,WebFetch"

Wait for Claude to complete (check .claude-status.txt).

Then run the FULL cycle again:

  1. Kimi K2.5 implements the UPDATED plan
  2. GLM-4.7 writes/updates tests
  3. Codex reviews again

Step 4a: Quick Fix - Code Issues (for LOW/MEDIUM severity)

For minor issues, Kimi can fix directly without a new plan:

/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-kimi.sh \
  "WORKTREE_PATH" \
  "TASK: Fix code issues identified by Codex code review.

CODEX REVIEW RESULT:
approved: false
severity: [low/medium - NOT high]

ISSUES TO FIX:
[paste the issues array from Codex]

ORIGINAL PLAN:
[paste the plan from Claude]

YOUR MISSION:
1. Fix EACH issue listed above
2. Do NOT change anything else
3. Keep changes minimal and focused

DO NOT write tests - another agent handles that."

Wait for Kimi to complete (check .kimi-status.txt). Then go directly to Codex review (Step 4).


Step 4b: Quick Fix - Test Issues (for missing tests)

For test coverage issues, GLM-4.7 can fix directly:

/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-opencode.sh \
  "WORKTREE_PATH" \
  "zai-coding-plan/glm-4.7" \
  "TASK: Add missing tests identified by Codex code review.

CODEX REVIEW RESULT:
test_coverage: [paste value]

MISSING TESTS:
[paste the missing_tests array from Codex]

ORIGINAL PLAN:
[paste the plan from Claude]

YOUR MISSION:
1. Write tests for EACH item in missing_tests
2. Follow existing test patterns in the codebase
3. Focus on edge cases and error handling"

Wait for GLM-4.7 to complete (check .opencode-status.txt). Then go directly to Codex review (Step 4).


šŸ”„ THE COMPLETE LOOP LOGIC (WITH CHECKPOINTS):

# Save checkpoint before Step 4
exec command="lib/checkpoint.sh save WORKTREE_PATH 4 in_progress"

ITERATION = 0
PREVIOUS_ISSUES = []

WHILE approved != true AND ITERATION < 10:

    # Track iteration count in checkpoint
    exec command="lib/checkpoint.sh increment WORKTREE_PATH codex_review"

    RUN Codex review (Step 4)
    WAIT for completion
    PARSE JSON response

    IF approved == true:
        BREAK → Go to Step 5 (Build Verification)

    ITERATION += 1

    # Check if same issues repeating (stuck)
    IF current_issues == PREVIOUS_ISSUES:
        STUCK_COUNT += 1
    ELSE:
        STUCK_COUNT = 0

    PREVIOUS_ISSUES = current_issues

    # Determine fix path
    IF any_issue_severity == "high" OR plan_compliance == "none" OR STUCK_COUNT >= 2:
        # FULL LOOP - Need new plan
        RUN Claude (Step 4-FULL) → new plan
        RUN Kimi (Step 2) → implement new plan
        RUN GLM-4.7 (Step 3) → write tests
        # Loop continues to Codex review

    ELSE:
        # QUICK FIX
        IF has_code_issues:
            RUN Kimi (Step 4a) → fix code
        IF has_test_issues:
            RUN GLM-4.7 (Step 4b) → fix tests
        # Loop continues to Codex review

IF ITERATION >= 10 AND approved != true:
    SEND failure notification
    EXIT with error

# Mark Step 4 complete
exec command="lib/checkpoint.sh complete-step WORKTREE_PATH 4"

Iteration tracking:

  • Track iteration count (max 10)
  • Track if same issues repeat (triggers full loop after 2 repeats)
  • Each iteration should show progress (fewer issues or different issues)

ā›” YOU CANNOT PROCEED TO BUILD VERIFICATION WITHOUT approved: true!

Codex ResultAction
approved: trueāœ… Proceed to Step 5 (Build Verification)
approved: falseāŒ DO NOT proceed. Loop back to fix issues.
Codex still runningāŒ DO NOT proceed. WAIT for completion.
No JSON responseāŒ DO NOT proceed. Re-run Codex.

Step 5: Build Verification (MANDATORY)

Before creating a PR, the build MUST pass. This is NOT optional.

āš ļø IMPORTANT: If build fails, treat it like Codex rejection with HIGH severity! Build failures mean the code is broken - you MUST go back to Claude for analysis.


1. Detect package manager and check what's available:

cd WORKTREE_PATH

# Detect package manager (pnpm > yarn > npm)
if [[ -f "pnpm-lock.yaml" ]]; then
  PKG_MGR="pnpm"
elif [[ -f "yarn.lock" ]]; then
  PKG_MGR="yarn"
else
  PKG_MGR="npm"
fi

# Check if scripts exist in package.json
HAS_LINT=$(grep -q '"lint"' package.json && echo "yes" || echo "no")
HAS_TEST=$(grep -q '"test"' package.json && echo "yes" || echo "no")

2. Run verification (in order):

# 1. Run lint (ONLY if configured)
if [[ "$HAS_LINT" == "yes" ]]; then
  $PKG_MGR lint
  # If fails → Go to Step 5-FIX
fi

# 2. Run tests (ONLY if configured)
if [[ "$HAS_TEST" == "yes" ]]; then
  $PKG_MGR test
  # If fails → Go to Step 5-FIX
fi

# 3. Run build (MANDATORY - must always run)
$PKG_MGR run build
# If fails → Go to Step 5-FIX

Script not configured? That's OK:

  • No lint script in package.json → Skip lint, continue
  • No test script in package.json → Skip tests, continue
  • No build script → ERROR - every project must have build

3. Priority of checks:

CheckRequired?If fails
lintOptional (if configured)→ Step 5-FIX
testOptional (if configured)→ Step 5-FIX
buildMANDATORY→ Step 5-FIX

Step 5-FIX: Build Failure Loop (FULL LOOP BACK TO CLAUDE)

ā›” If ANY verification fails, you MUST go back to Claude for analysis!

This is treated like a HIGH severity Codex rejection - you need a new plan.

/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-claude.sh \
  "WORKTREE_PATH" \
  "TASK: Analyze build/test/lint failure and create fix plan.

ORIGINAL TASK: [the user's original task]

BUILD VERIFICATION FAILED:
[Which check failed: lint / test / build]

ERROR OUTPUT:
[Paste the FULL error message here]

CURRENT CODE CHANGES:
$(cd WORKTREE_PATH && git diff BASE_BRANCH...HEAD)

YOUR MISSION:
1. Analyze the error message carefully
2. Understand WHY the build/test/lint failed
3. Research best practices for fixing this specific error
4. Create a detailed FIX PLAN that addresses the root cause
5. Be specific about which files need changes and what changes

The previous implementation broke the build. Your new plan must fix it.
" \
  "Bash,Read,Glob,Grep,WebSearch,WebFetch"

Wait for Claude to complete (check .claude-status.txt).

Then run the FULL cycle again:

  1. Kimi K2.5 implements Claude's fix plan
  2. GLM-4.7 updates tests if needed
  3. Codex reviews the fix
  4. Build Verification runs again (Step 5)

šŸ”„ BUILD FAILURE LOOP (WITH CHECKPOINTS):

# Save checkpoint before Step 5
exec command="lib/checkpoint.sh save WORKTREE_PATH 5 in_progress"

BUILD/TEST/LINT FAILS
    ↓
# Track build fix iteration
exec command="lib/checkpoint.sh increment WORKTREE_PATH build_fix"
    ↓
Claude analyzes failure → creates fix plan
    ↓
Kimi implements fix
    ↓
GLM-4.7 updates tests (if needed)
    ↓
Codex reviews (must approve)
    ↓
Build Verification again (Step 5)
    ↓
REPEAT until ALL pass

# Check iteration count before each attempt
BUILD_FIX_COUNT = exec command="lib/checkpoint.sh get-counter WORKTREE_PATH build_fix"
IF BUILD_FIX_COUNT >= 10:
    SEND failure notification
    EXIT with error

Iteration tracking for build failures:

  • Track build failure iterations in checkpoint: lib/checkpoint.sh get-counter WORKTREE_PATH build_fix
  • Max 10 build fix iterations
  • If 10 iterations and still failing → Send failure notification

4. Only proceed to Step 6 when:

  • Lint passes (or not configured)
  • Tests pass (or not configured)
  • Build MUST pass (no exceptions)
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ BUILD VERIFICATION CHECKLIST:                               │
│                                                             │
│ ā–” Lint: PASS or NOT_CONFIGURED                              │
│ ā–” Tests: PASS or NOT_CONFIGURED                             │
│ ā–” Build: PASS (MANDATORY)                                   │
│                                                             │
│ ALL checked? → Mark Step 5 complete, Proceed to Step 6      │
│ ANY failed? → Go to Step 5-FIX (full loop)                  │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

# When build passes:
exec command="lib/checkpoint.sh complete-step WORKTREE_PATH 5"

Step 6: Create PR

ā›” MANDATORY CHECKPOINT - BEFORE CREATING PR:

YOU CANNOT CREATE A PR UNLESS ALL OF THESE ARE TRUE:

AGENTS CHECKLIST (ALL must be TRUE):
ā–” Claude Code completed? → .claude-status.txt = COMPLETED
ā–” Kimi K2.5 completed? → .kimi-status.txt = COMPLETED
ā–” GLM-4.7 completed? → .opencode-status.txt = COMPLETED
ā–” Codex APPROVED? → Codex JSON had "approved": true  ← CRITICAL!

āš ļø CODEX APPROVAL IS MANDATORY!
- If Codex returned "approved": false → YOU CANNOT CREATE PR
- You must loop back and fix issues until Codex says "approved": true
- There is NO exception to this rule

āš ļø VERIFICATION COMMAND (RUN THIS BEFORE COMMIT):

cd WORKTREE_PATH && echo "=== Agent Status Check ===" && \
  echo -n "Claude: "; cat .claude-status.txt 2>/dev/null || echo "NOT RUN"; \
  echo -n "Kimi: "; cat .kimi-status.txt 2>/dev/null || echo "NOT RUN"; \
  echo -n "GLM-4.7: "; cat .opencode-status.txt 2>/dev/null || echo "NOT RUN"; \
  echo "" && echo "=== CODEX APPROVAL STATUS ===" && \
  echo "Did Codex return approved: true? (YOU MUST VERIFY THIS)"

Expected output (ALL must be satisfied):

=== Agent Status Check ===
Claude: COMPLETED
Kimi: COMPLETED
GLM-4.7: COMPLETED

=== CODEX APPROVAL STATUS ===
Did Codex return approved: true? (YOU MUST VERIFY THIS)

BLOCKING CONDITIONS - DO NOT CREATE PR IF:

  • ANY agent shows "NOT RUN" → Run the missing agent
  • ANY agent shows "ERROR" → Fix the error
  • Codex returned approved: false → Loop back to fix issues (Step 4)
  • Codex is still running → WAIT for it to complete
  • You didn't check Codex JSON response → Go check it now

1. Commit changes:

cd WORKTREE_PATH && git add -A && git commit -m "$(cat <<'EOF'
[YOU generate a clean, professional commit message based on changes]

[Write it as if a human developer wrote it - NO mentions of AI, LLMs, agents, or Clawdbot]
EOF
)"

2. Push and create PR:

git push -u origin BRANCH_NAME

gh pr create \
  --title "[YOU generate concise title]" \
  --body "$(cat <<'EOF'
## Summary
[YOU write 1-3 bullets of changes - write as a human developer would]

## Changes
[Brief technical description of what was changed and why]

## Testing
[How the changes were tested]
EOF
)"

3. Mark Step 6 complete:

lib/checkpoint.sh complete-step WORKTREE_PATH 6

Step 7: Notification (MANDATORY - DO NOT SKIP)

YOU MUST send a notification email after creating the PR. This is NOT optional.

āš ļø CRITICAL: Build the "Agents Used" list ONLY from agents that actually ran!

Before sending the email, check which status files exist in the worktree:

# Check which agents actually ran (status file exists AND contains COMPLETED)
AGENTS_USED=""
if [[ -f "WORKTREE_PATH/.claude-status.txt" ]] && grep -q "COMPLETED" "WORKTREE_PATH/.claude-status.txt"; then
  AGENTS_USED="$AGENTS_USED\n- Claude Code (Opus 4.5): Research & Planning"
fi
if [[ -f "WORKTREE_PATH/.kimi-status.txt" ]] && grep -q "COMPLETED" "WORKTREE_PATH/.kimi-status.txt"; then
  AGENTS_USED="$AGENTS_USED\n- Kimi K2.5: Implementation (code only)"
fi
if [[ -f "WORKTREE_PATH/.opencode-status.txt" ]] && grep -q "COMPLETED" "WORKTREE_PATH/.opencode-status.txt"; then
  AGENTS_USED="$AGENTS_USED\n- GLM-4.7: Tests & Documentation"
fi
# Codex doesn't use status file - check if codex command was run and returned approved:true

DO NOT copy-paste all 4 agents. Only list agents that ACTUALLY RAN.

If you skipped GLM-4.7, the email MUST show:

## Agents Used
- Claude Code (Opus 4.5): Research & Planning
- Kimi K2.5: Implementation (code only)
āš ļø GLM-4.7 was SKIPPED (tests not written)
- Codex: Code Review

Full email template:

/Users/jose/clawd/skills/intelligent-implementer/lib/send-resend-email.sh \
  --to "$NOTIFY_EMAIL_TO" \
  --subject "āœ… Clawdbot: [descriptive title]" \
  --body "$(cat <<'EOF'
šŸ¦ž CLAWDBOT TASK COMPLETE

Task: [task]
Project: [project]
PR: [url]
Branch: [branch]
Worktree: [worktree path]

## What was done
[Summary of implementation]

## Research Highlights
[Key findings from Claude's research]

## Testing
[Build verification results: lint, test, build]

## Agents Used
[ONLY list agents that actually ran - check status files!]
[If an agent was skipped, mark it with āš ļø SKIPPED]

Iterations: [N]
EOF
)"

Step 8: FAILURE NOTIFICATION (MANDATORY IF TASK FAILS)

If the task fails at ANY point, you MUST send a failure notification email. This is NOT optional.

Failure can happen due to:

  • Agent timeouts (after waiting 30-60 min with no file changes)
  • Build/lint/test failures that cannot be fixed after multiple attempts
  • Errors that prevent completion
  • Any reason the PR cannot be created

Send failure email:

/Users/jose/clawd/skills/intelligent-implementer/lib/send-resend-email.sh \
  --to "$NOTIFY_EMAIL_TO" \
  --subject "āŒ Clawdbot FAILED: [descriptive title]" \
  --body "$(cat <<'EOF'
šŸ¦ž CLAWDBOT TASK FAILED

Task: [task]
Project: [project]
Worktree: [worktree path]
Branch: [branch name]

## What Failed
[Describe exactly what failed and at which step]

## Error Details
[Include the actual error message or reason for failure]

## What Was Completed
[List any partial progress made before failure]

## Possible Causes
[Your analysis of why it failed]

## Suggested Next Steps
[What the user could try to fix it or continue manually]

## Agents Used Before Failure
- [List which agents were called and their outcomes]

Note: The worktree still exists at [path] with partial changes.
EOF
)"

IMPORTANT:

  • ALWAYS send this email if you cannot complete the task
  • NEVER exit silently without notification
  • Include enough detail for the user to understand what happened
  • The worktree path is critical so user can continue manually if needed

Critical Rules

  1. YOU ARE THE ORCHESTRATOR - You coordinate, you don't implement
  2. BUILD MUST PASS - ALWAYS run lint, test, build before PR. If any fail, loop back to Kimi.
  3. ALWAYS send notification email - On SUCCESS (PR created) OR FAILURE (task cannot complete). NEVER exit silently.
  4. NEVER use edit or write - Always call external agents
  5. NEVER use web_search directly - Only Claude Code has WebSearch. Call Claude via exec.
  6. Claude Code FIRST - Always research and plan before implementing
  7. Internet research is MANDATORY - Claude must use WebSearch (not you)
  8. Follow the plan - Kimi must implement exactly what Claude planned
  9. ā±ļø PATIENCE PROTOCOL - NEVER KILL AGENTS PREMATURELY:
    • Kimi K2.5: Wait 60 MINUTES minimum (1 hour)
    • GLM-4.7: Wait 60 MINUTES minimum (1 hour)
    • Claude Code: Wait 60 MINUTES minimum (1 hour)
    • "No new output" means THINKING, not failure - THIS IS NORMAL
    • Use FILE-BASED progress detection: git status and find -mmin
    • ONLY kill if: 30+ min passed AND no file changes for 20+ min AND no errors
    • Anthropic recommends 60+ minute timeouts for thinking models
  10. Use wrapper scripts for all agent calls - claude, kimi, opencode require the lib/run-*.sh wrappers. Call them via exec command="/path/to/lib/run-claude.sh ..." timeout=3600.
  11. 🚨 NEVER EMIT TEXT UNTIL AFTER SENDING EMAIL 🚨 - The CLI disconnects when you output text!
    • ONLY use tool calls while working (exec, process poll, etc.)
    • DO NOT print status updates like "Agent is running..." or "Waiting for Kimi..."
    • DO NOT explain what you're doing while working
    • COMPLETION ORDER IS MANDATORY:
      1. Create PR (Step 6)
      2. Send notification email (Step 7) ← MUST happen before ANY text
      3. ONLY THEN output final summary text
    • Text output BEFORE sending email = CLI disconnects = email never sent!
    • Work in SILENCE. Email FIRST. Text LAST.

Agent Chain

ALWAYS follow this order:

1. Claude Code (Opus 4.5)
   └─→ Analyze codebase first
   └─→ Research best practices 2026 (WebSearch)
   └─→ Generate implementation plan

2. Kimi K2.5
   └─→ Implement CODE ONLY following Claude's plan
   └─→ Create migrations if needed
   └─→ If fails → Claude Code CLI as fallback

3. GLM-4.7
   └─→ Write tests for implementation
   └─→ Add JSDoc/docstrings
   └─→ If fails → Claude Code CLI as fallback

4. Codex
   └─→ Review code + tests against plan
   └─→ Approve or reject

5. Build Verification (MANDATORY)
   └─→ Run lint (must pass)
   └─→ Run tests (must pass)
   └─→ Run build (must compile)
   └─→ If lint/build fail → Loop back to Kimi
   └─→ If tests fail → Loop back to GLM-4.7

6. PR + Notification

Example

User: "Fix the speech-to-text streaming in /Users/jose/Documents/growth/megrowth"

YOU (Orchestrator):

  1. Create worktree: fix/speech-to-text-streaming

  2. Call Claude Code for research & planning:

    • Claude analyzes: /api/realtime/token/route.ts, useRealtimeTranscription.ts
    • Claude reads: CLAUDE.md
    • Claude searches: "Deepgram Nova-3 WebSocket streaming best practices 2026"
    • Claude outputs: Detailed plan with files, changes, tests
  3. Call Kimi K2.5 with the plan:

    • Kimi implements all code changes (code only)
    • Kimi creates migrations if needed
  4. Call GLM-4.7 for tests & docs:

    • GLM writes unit tests for the implementation
    • GLM adds JSDoc/docstrings
  5. Call Codex for review:

    • Codex verifies plan compliance
    • Codex verifies test coverage
    • IF Codex returns approved: false:
      • Read the issues array
      • Code issues → Loop back to Kimi (step 3)
      • Test issues → Loop back to GLM (step 4)
      • After fixes, run Codex AGAIN
    • ONLY proceed when approved: true
  6. Run build verification (only after Codex approves):

    • pnpm lint → passes
    • pnpm test → passes
    • pnpm run build → compiles successfully
    • (If lint/build fail → Kimi, if tests fail → GLM)
  7. Create PR: "Fix speech-to-text streaming with WebSocket token generation"

  8. Send notification with summary and research highlights


Forbidden Actions

ActionWhy Forbidden
Using edit toolYou are orchestrator, not implementer
Using write toolYou are orchestrator, not implementer
Using web_search toolOnly Claude Code has WebSearch. Call claude via exec instead.
Using agents_spawnUse exec to call CLI tools (claude, kimi, opencode, codex)
Calling coding agents without wrapper scriptsClaude/Kimi/OpenCode REQUIRE the wrapper scripts in lib/.
Skipping Claude researchMissing best practices leads to poor implementation
Implementing without planUnplanned code is buggy code
🚨 Skipping GLM-4.7 (tests/docs)FORBIDDEN. Even if tests pass, GLM reviews/improves them. ALL 4 agents mandatory.
🚨 Skipping Codex (code review)FORBIDDEN. Even if build passes, Codex verifies quality. ALL 4 agents mandatory.
Ignoring Codex feedbackQuality matters
🚨🚨 Creating PR when Codex said approved: falseABSOLUTELY FORBIDDEN. You MUST loop back and fix issues. This is the whole point of code review!
🚨🚨 Creating PR before Codex finishesABSOLUTELY FORBIDDEN. You MUST wait for Codex to complete and return its JSON response.
🚨🚨 Not checking Codex JSON responseABSOLUTELY FORBIDDEN. You MUST parse the JSON and check approved field before proceeding.
🚨🚨 Creating PR when build failsABSOLUTELY FORBIDDEN. Build failures = broken code. Must loop back to Claude for analysis.
🚨🚨 Skipping build verificationABSOLUTELY FORBIDDEN. Build MUST pass before PR. Lint/test optional if not configured.
🚨🚨 Ignoring build/test/lint failuresABSOLUTELY FORBIDDEN. Any failure = full loop back to Claude → Kimi → GLM → Codex → Build.
🚨 Using process kill directlyFORBIDDEN. Use /lib/safe-kill.sh <PID> 3600 instead. It blocks premature kills.
🚨 Polling every few secondsFORBIDDEN. Wait 5 min before first poll. Then poll every 3-5 MINUTES, not seconds.
Killing based on "no output"NEVER. "No output" = agent is THINKING. This is normal. Check git status instead.
Killing after seeing "Process still running"FORBIDDEN. This message is NORMAL. Use safe-kill.sh which will block premature kills.
Marking session as "failed" without 60 min waitAlways wait 3600 seconds (1 hour) minimum. Always check git status before declaring failure.
🚨 EMITTING TEXT DURING MONITORING 🚨CLI DISCONNECTS ON TEXT OUTPUT! Only use tool calls while agents run. Text only on full completion or permanent failure.

How to Call Agents (IMPORTANT)

You call agents via the exec tool, NOT via internal tools or raw bash.

āš ļø CRITICAL: USE WRAPPER SCRIPTS FOR ALL CODING AGENTS

The wrapper scripts in lib/ ensure consistent CLI execution and argument handling.

Why wrappers are needed:

  • Consistent argument passing and quoting
  • Proper working directory handling
  • CLIs work fine in their non-interactive modes (-p, --print)

CORRECT way to call coding agents (using wrappers):

exec command="/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-claude.sh '/path/to/worktree' 'Your prompt' 'Bash,Read,Glob,Grep,WebSearch,WebFetch'" timeout=3600

Wrapper scripts:

# Claude Code for research/planning:
/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-claude.sh \
  "/path/to/worktree" \
  "Your prompt as single string" \
  "Bash,Read,Glob,Grep,WebSearch,WebFetch"

# Kimi for implementation:
/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-kimi.sh \
  "/path/to/worktree" \
  "Your prompt as single string"

# OpenCode (GLM-4.7 for tests & docs, or Kimi fallback):
/Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/run-opencode.sh \
  "/path/to/worktree" \
  "zai-coding-plan/glm-4.7" \
  "Your prompt"

# Codex for review (does NOT need wrapper, must be in git repo):
cd /path/to/worktree && codex exec "Your prompt as single string"

CRITICAL:

  • ALWAYS use wrapper scripts for claude, kimi, and opencode commands
  • ALWAYS use timeout=3600 (60 minutes) for coding agents
  • DO NOT use yieldMs with agent commands - Let them run to completion or timeout
  • All paths must be ABSOLUTE (e.g., /Users/jose/ai-worktrees/...)
  • Wrappers handle argument passing and working directory
  • Codex does NOT need a wrapper (works directly via bash)

āš ļø EXEC PARAMETERS FOR AGENTS:

exec command="..." timeout=3600

DO NOT ADD: yieldMs, waitFor, or any parameter that returns control early. Let the agent run. Check on it every 3-5 MINUTES (not seconds) using process poll.

ā±ļø PATIENCE PROTOCOL WHEN POLLING AGENTS:

  1. Poll every 2-3 minutes with process poll

  2. "No new output" is NORMAL - agents are in thinking mode

  3. Check FILE CHANGES instead of stdout:

    cd WORKTREE_PATH && git status --short
    

    If ANY files modified → Agent is WORKING → Keep waiting

  4. MINIMUM WAIT TIMES (Anthropic recommends 60 min):

    • Kimi/OpenCode: 60 MINUTES minimum (1 hour)
    • GLM-4.7: 60 MINUTES minimum (1 hour)
    • Claude Code: 60 MINUTES minimum (1 hour)
  5. TO KILL AN AGENT, USE THE SAFE-KILL WRAPPER:

    # Get the PID from the exec response, then:
    /Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/safe-kill.sh <PID> 3600
    
    • The wrapper will BLOCK the kill if < 3600 seconds (1 hour) elapsed
    • The wrapper will APPROVE the kill if >= 3600 seconds (1 hour) elapsed
    • NEVER use process kill directly - it bypasses the time check
  6. Track elapsed time:

    # Note start time when launching agent
    # Before ANY kill decision, verify 60+ minutes elapsed (3600 seconds)
    # Or just use safe-kill.sh which does this automatically
    

DO NOT use agents_spawn, agents_list, web_search, or similar internal tools.


ā›” FINAL REMINDER - CRITICAL RULES (READ AGAIN) ā›”

Before you finish reading this document, remember:

  1. YOU CANNOT WRITE CODE - No edit, no write. Call agents instead.

  2. YOU CANNOT SKIP ANY AGENT - ALL 4 agents are MANDATORY:

    Claude Code → Kimi K2.5 → GLM-4.7 → Codex → Build → PR
    

    Even if tests pass or build succeeds, you MUST still call GLM-4.7 and Codex.

  3. YOU CANNOT CREATE PR WITHOUT CODEX APPROVAL - This is the most critical rule:

    IF Codex returns approved: false → YOU CANNOT CREATE PR
    
    HYBRID FIX LOOP:
    - severity: HIGH or plan_compliance: none → FULL LOOP back to Claude
      Claude creates new plan → Kimi → GLM → Codex
    
    - severity: LOW/MEDIUM → QUICK FIX
      Kimi/GLM fixes directly → Codex reviews again
    
    REPEAT until approved: true (max 10 iterations)
    

    YOU MUST WAIT for Codex to complete and check its response! The loop ONLY exits when approved: true!

  4. YOU CANNOT KILL AGENTS BEFORE 60 MINUTES (1 HOUR) - Use safe-kill.sh, not process kill:

    /Users/jose/Documents/clawdbot/skills/intelligent-implementer/lib/safe-kill.sh <PID> 3600
    
  5. YOU CANNOT CREATE PR IF BUILD FAILS - Build failures = full loop back:

    Build/Test/Lint fails → Claude analyzes → Kimi fixes → GLM tests → Codex → Build again
    REPEAT until build passes
    

    Lint and tests are optional (if not configured). Build is MANDATORY.

  6. YOU CANNOT OUTPUT TEXT WHILE WORKING - Only tool calls. Text = CLI disconnect.

  7. POLL EVERY 3-5 MINUTES, NOT SECONDS - First poll after 5 minutes.

These rules exist because you (GPT-5.2) have:

  • Killed agents after 31 seconds (safe-kill.sh now prevents this)
  • Skipped GLM-4.7 and Codex steps (new checkpoints now prevent this)
  • Created PR before Codex finished reviewing (new blocking rules prevent this)
  • Created PR even when Codex said approved: false (new loop enforcement prevents this)
  • Would create PR with failing build (new build loop prevents this)
Skills Info
Original Name:intelligent-implementerAuthor:joseantonionuevo