Skip to content

Instantly share code, notes, and snippets.

@johnlindquist
Last active February 16, 2026 17:00
Show Gist options
  • Select an option

  • Save johnlindquist/f46ab03beccd9a3644d410e6849ee2e9 to your computer and use it in GitHub Desktop.

Select an option

Save johnlindquist/f46ab03beccd9a3644d410e6849ee2e9 to your computer and use it in GitHub Desktop.
How xorloop and xtodoloop work — autonomous AI loop explainers with Mermaid diagrams

xorloop & xtodoloop — How They Work

Two autonomous overnight loops from the AI Swarm DSL that discover, plan, and implement code improvements using Oracle (GPT-5.2) and Codex swarms (GPT-5.3).


High-Level Pipeline

flowchart TD
    Gather["1. Gather Context"]
    Oracle["2. Post to Oracle"]
    Implement["3. Implement with Codex"]
    Commit["4. Commit + Summarize"]

    Gather -->|"bundled codebase + prompt"| Oracle
    Oracle -->|"work orders"| Implement
    Implement -->|"file changes"| Commit
    Commit -.->|"repeat with memory<br/>of what was already done"| Gather

    style Gather fill:#1a1a2e,stroke:#5b8def,color:#fff
    style Oracle fill:#3d1f00,stroke:#f97316,color:#fff
    style Implement fill:#0a2e1a,stroke:#22c55e,color:#fff
    style Commit fill:#0a3d62,stroke:#38ada9,color:#fff
Loading

Step by step

1. Gather Context — Claude picks a category (dead code, consistency, code quality, UX polish) and scans the codebase for a specific module that smells wrong. packx bundles the relevant files, CLAUDE.md conventions, recent git history, and summaries from previous iterations into a single payload. The goal: give the next step everything it needs to reason about the code without reading every file.

2. Post to Oracle — The bundled context is sent to Oracle (xpor — GPT-5.2 Pro). Oracle does a deep code review and outputs 1–4 self-contained swarm work orders, each with a worker ID, file scope, and multi-paragraph implementation brief. Oracle plans, it doesn't edit files.

3. Implement with Codex — The work orders are piped to a Codex swarm (xpsw — GPT-5.3). Each work order becomes a parallel Codex worker that autonomously edits real files. Workers have no context beyond what Oracle wrote in their task description — that's why step 2 has to be exhaustive.

4. Commit + Summarize — If the swarm succeeds, changes are git-committed. A cheap Claude call summarizes what was done. If the swarm fails, the working tree is reset to the pre-swarm commit so nothing is left broken.

Repeat — The summary from step 4 feeds back into step 1 as memory context. The next iteration sees what was already fixed and is told "do NOT re-analyze these areas — find something completely different." This prevents the loop from doing the same work twice across 20+ overnight iterations.

xtodoloop is the simpler variant: it skips steps 1–2 entirely. Instead of discovering work, it reads the next line from a TODO.md file and sends it straight to Codex. No Oracle planning — the TODO line is the plan.


xorloop — Autonomous Discovery Loop

Purpose: Overnight autonomous improvement loop. It discovers what to work on by rotating through categories, asks Oracle (GPT-5.2) to analyze the code, then dispatches a Codex swarm to implement fixes.

flowchart TD
    Start["xorloop [focus] [-n max] [-d delay] [--until HH:MM]"]
    Init["Create session dir<br/>.xorloop-sessions/TIMESTAMP/<br/>Write PID, report header"]

    Start --> Init --> CheckStop

    subgraph Loop ["Main Loop (up to max_iter)"]
        CheckStop{{"Stop?<br/>signal / stop file /<br/>--until reached"}}
        CheckStop -- Yes --> Done
        CheckStop -- No --> Pause

        Pause{"Pause file<br/>exists?"}
        Pause -- Yes --> WaitPause["Sleep 30s, re-check"]
        WaitPause --> Pause
        Pause -- No --> PickCat

        PickCat["Phase 0: Pick Category<br/>Sequential rotation through:<br/>• consistency cleanup<br/>• dead code removal<br/>• code quality<br/>• UX polish<br/>(or custom focus/categories)"]

        PickCat --> Discover

        Discover["Phase 1: Feature Discovery (xp)<br/>Cheap fast call — pick ONE module<br/>using seed rotation for variety<br/>→ FEATURE / FILES / SMELL"]

        Discover -- failed --> FallbackPrompt["Use generic 'explore broadly' prompt"]
        Discover -- ok --> BuildPrompt
        FallbackPrompt --> BuildPrompt

        BuildPrompt["Phase 2: Build Prompt<br/>• CLAUDE.md conventions<br/>• Recent git commits (dedup guard)<br/>• Last 3 iteration summaries (memory)<br/>• Swarm task-list output format<br/>→ Save to prompts/iter-NNNN.md"]

        BuildPrompt --> Oracle

        Oracle["Phase 3: Oracle Analysis (xpor)<br/>Deep analysis via GPT-5.2<br/>→ 1-4 swarm work orders"]

        Oracle -- failed --> Backoff["Backoff: 1m → 5m → 15m<br/>3 consecutive fails → abort"]
        Backoff --> CheckStop
        Oracle -- ok --> Swarm

        Swarm["Phase 4: Codex Swarm (xpsw)<br/>Parallel GPT-5.3 workers<br/>execute the work orders"]

        Swarm -- failed --> Reset["git reset to pre-swarm commit"]
        Reset --> Delay
        Swarm -- ok --> Commit

        Commit["Phase 5: Commit<br/>• If Codex already committed → done<br/>• Else git add -A && commit<br/>'[xorloop] iter N: category'"]

        Commit --> Summarize

        Summarize["Phase 6: Summarize (xp)<br/>Extract task bullets + NEXT_AREA<br/>Append to report.md"]

        Summarize --> Delay
        Delay["Sleep delay seconds<br/>(interruptible every 10s)"]
        Delay --> CheckStop
    end

    Done["Write report footer<br/>Remove PID file<br/>Print session paths"]

    style Start fill:#1a1a2e,stroke:#e94560,color:#fff
    style Oracle fill:#16213e,stroke:#0f3460,color:#fff
    style Swarm fill:#16213e,stroke:#0f3460,color:#fff
    style Discover fill:#1a1a2e,stroke:#533483,color:#fff
    style Done fill:#0a3d62,stroke:#38ada9,color:#fff
Loading

xtodoloop — TODO File Consumer Loop

Purpose: Reads a TODO.md file line by line, dispatches each task to a Codex swarm, commits on success, removes the line from the file, and moves to the next task. Simpler — no discovery phase, no Oracle.

flowchart TD
    Start["xtodoloop [--file TODO.md] [-d delay] [--until HH:MM]"]
    Init["Create session dir<br/>.xtodoloop-sessions/TIMESTAMP/<br/>Write PID"]

    Start --> Init --> CheckStop

    subgraph Loop ["Main Loop (until TODO empty)"]
        CheckStop{{"Stop?<br/>signal / stop file /<br/>--until / file deleted"}}
        CheckStop -- Yes --> Done
        CheckStop -- No --> Pause

        Pause{"Pause file?"}
        Pause -- Yes --> WaitPause["Sleep 30s"]
        WaitPause --> Pause
        Pause -- No --> ReadTodo

        ReadTodo["Read TODO.md<br/>Find first actionable line:<br/>• Skip blanks, headings, [x] items<br/>• Strip '- [ ]' prefix<br/>• Record line number"]

        ReadTodo -- "no tasks left" --> Done
        ReadTodo -- "found task" --> BuildPrompt

        BuildPrompt["Build Prompt:<br/>• CLAUDE.md conventions<br/>• Recent commits for context<br/>• Task text as imperative order<br/>• 'Do NOT touch TODO.md'<br/>→ Save to prompts/iter-NNNN.md"]

        BuildPrompt --> Swarm

        Swarm["Dispatch Codex Swarm (xpsw)<br/>Workers implement the task"]

        Swarm -- failed --> KeepTask["Keep task in TODO.md<br/>Log SWARM_FAILED"]
        KeepTask --> Delay
        Swarm -- ok --> Commit

        Commit["git add -A<br/>git reset -- TODO.md<br/>git commit '[xtodoloop] task...'"]

        Commit -- failed --> KeepTask2["Keep task in TODO.md<br/>Log COMMIT_FAILED"]
        KeepTask2 --> Delay
        Commit -- ok --> RemoveLine

        RemoveLine["Remove completed line<br/>from TODO.md by line number<br/>Print remaining count"]

        RemoveLine --> AppendReport["Append to report.md"]
        AppendReport --> Delay

        Delay["Sleep delay seconds<br/>(interruptible)"]
        Delay --> CheckStop
    end

    Done["Print final summary<br/>Remove PID file"]

    style Start fill:#1a1a2e,stroke:#e94560,color:#fff
    style Swarm fill:#16213e,stroke:#0f3460,color:#fff
    style ReadTodo fill:#1a1a2e,stroke:#533483,color:#fff
    style RemoveLine fill:#0a3d62,stroke:#38ada9,color:#fff
    style Done fill:#0a3d62,stroke:#38ada9,color:#fff
Loading

Key Differences

xorloop xtodoloop
Input Self-discovering — rotates through categories User-provided TODO.md
Planning Oracle (GPT-5.2) generates swarm work orders Prompt is the TODO line itself
Pipeline 6 phases: discover → prompt → oracle → swarm → commit → summarize 3 phases: read → swarm → commit
Memory Last 3 summaries fed back to avoid re-doing work None (linear consumption)
Failure Backoff + git reset on swarm failure Keeps task in file, moves on
Completion Iteration count or --until time TODO.md is empty
Controls touch stop, touch pause, --until, -n, signal Same: stop, pause, --until, signal

Both share the same infrastructure: session directories, PID tracking, event logs, report accumulation, and interruptible sleep loops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment