loop # loop Keep an agent working toward a goal until commands you trust say it is done. ## Use in Pi Run `/loop guide` and let the agent interview you. It proposes a goal and gates from the project's instructions and task runner, then starts the run with its `loop_begin` tool once you agree. `loop_begin` works only after `/loop guide`; the agent cannot start a loop on its own. To set everything yourself, run `/loop start` while the agent is idle. Pi asks for the goal, then for the gates as a JSON array: ```json [ { "name": "types", "command": "npx", "args": ["tsc", "--noEmit"] }, { "name": "tests", "command": "npm", "args": ["test"] } ] ``` A gate is a raw executable with optional `args`, `env`, and `cwd`; no shell is involved. On Windows, wrap `.cmd` shims explicitly, for example `{ "command": "cmd", "args": ["/c", "npm", "test"] }`. One attempt runs the gates in order and stops at the first failure. The run succeeds only when every gate exits 0 in one attempt; what the agent says never counts. After each failed attempt Pi prompts the agent again with the goal, the failing gate, and the tail of its output. Older loop prompts shrink to one line, so gate output does not pile up in context. Optional budgets follow `start` or `guide` as `minutes turns attempts`, with `none` for uncapped, for example `/loop start 60 30 10`. | Command | Effect | | --- | --- | | `/loop guide [minutes turns attempts]` | Brainstorm goal and gates with the agent, which then starts the run. | | `/loop start [minutes turns attempts]` | Ask for goal and gates, run the baseline attempt, then loop. | | `/loop pause` / `/loop stop [id\|latest]` | Pause or stop; typing `stop` or `pause` also pauses. | | `/loop resume ` | Re-arm a paused run; used turns and attempts still count, the time budget restarts. | | `/loop status` / `/loop list` | Show the current run or the run history. | | `/loop view` | Open the live run page in the browser. | Escape, an aborted turn, an exhausted budget, or leaving the session pauses the run. Nothing resumes on its own. The agent is told to work things out on its own first. When it is truly blocked on you, for example on access or a decision outside the goal, it pauses the run with its `loop_control` tool and says what it needs. While paused you talk with the agent as usual; those turns do not count against the budget. Once you have unblocked it, the agent resumes the run with the same tool, or you run `/loop resume` or `/loop stop`. ## Companion In the terminal UI, a red-haired pin-up in a pastel orange bikini poses below the editor while a run is active. She holds slow, calm poses while the camera glides between close-ups of her face, bust and hips. She reacts to the loop: she waits with a hand at her collarbone while gates run, looks unimpressed after a failed attempt, lounges while paused, and stretches slowly with her arms over her head, then blows kisses, when every gate passes. One quiet line beside her shows attempts, turns, and the failing gate. She leaves when the run stops, and about 40 seconds after it succeeds. ## Run page `/loop view` serves a page on `127.0.0.1` behind a random token and opens it in the browser. It shows the run with its budgets, each gate with the failing gate's output, a timeline of turns and attempts, the event feed, and the run history. It updates live and follows the system light or dark theme. The page only observes; its resume button copies the `/loop resume` command for you to run in Pi. ## State Runs, gate attempts, and events live in `.pi/loop/state.db` inside the project, or wherever `loop.statePath` points. Gate output is stored there, so add the file to `.gitignore` unless your team wants the history in version control. `/loop guide` mentions this when Git does not ignore the file. [Installation](../../README.md#install) ## Reference ### Commands | Command | Purpose | | --- | --- | | `/loop` | Goal-gated agent loop: start\|guide\|resume\|pause\|stop\|status\|view\|list | ### Setting names | Setting | Environment | | --- | --- | | `loop.statePath` | `PI_LOOP_STATE_PATH` | #### Setting values | Setting | Default | Valid values | Purpose | | --- | --- | --- | --- | | `loop.statePath` | `".pi/loop/state.db"` | Parser-validated | State database: SQLite file holding runs, gate attempts, and events; relative paths resolve against the project directory. |