maxIterations — positive number caps experiments per segment; default null
autoResumeLimit — positive number caps auto-resume turns; default null
Hooks
Pi hooks:
session_start / session_tree — reconstruct state from
.pi/tune/session.jsonl
before_agent_start — inject tune system prompt when mode is active
session_before_compact — produce deterministic compaction summary
agent_end — schedule auto-resume when mode is active
session_shutdown — clean up UI and timers
Tune iteration hooks:
.pi/tune/hooks/before.mjs
.pi/tune/hooks/after.mjs
Hook scripts run with node, receive JSON on stdin, and return steer text on
stdout. Hooks time out after 30 seconds. Hook stdout is capped at 8 KiB.
State
All state lives in .pi/tune/.
File
Purpose
session.jsonl
Append-only experiment log
session.md
Living document: objective, what's been tried
ideas.md
Backlog of untried optimizations
benchmark.mjs
Benchmark script
checks.mjs
Optional correctness gate
hooks/before.mjs
Optional pre-iteration hook
hooks/after.mjs
Optional post-iteration hook
E2E
Run root mise run e2e first to install browsers and execute every extension suite.
After that bootstrap, run mise run e2e here, or mise //extensions/tune:e2e from the repository root, to test dashboard loading, theme interaction, and live updates in Chromium and Firefox.
Behavior
Tunes through an autonomous loop: edit → benchmark → log → keep or discard →
repeat.
Benchmark output may include metric lines:
METRIC name=value
run_experiment parses finite numeric metrics and rejects unsafe metric names
such as __proto__ and constructor.
run_experiment takes no command.
Tune requires no Bash, Git Bash, PowerShell, or WSL for experiments or VCS handling.
Put environment setup and subprocess orchestration in benchmark.mjs with Node APIs.
If .pi/tune/checks.mjs exists, it runs after every passing benchmark. Check
failures block keep.
Benchmark, checks, and hook modules use the same Node executable running Pi.
VCS behavior is native per repo:
jj repos use jj describe, jj new, and jj abandon
non-jj repos use Git
Tune takes an exclusive .pi/tune/lock.json repo lock per Pi session. Parallel
tune runs in one checkout are rejected; use a separate checkout or workspace for
parallel tuning.
Confidence scoring is MAD-based after 3+ runs:
≥2.0× — real
1.0–2.0× — marginal
<1.0× — noise
Compaction skips the default LLM summary and rebuilds a deterministic summary
from persisted tune state.
settings.tune.maxIterations caps experiments per segment.
settings.tune.autoResumeLimit caps automatic resume turns.
Both default to null, meaning unlimited.
# tuneTune code through autonomous experiment loops for Pi.
## Install / loadLoaded through the root `pi-ext` package.
Slug: `tune`. Package: `@bugabinga/pi-ext-tune`.
See [root README](../../README.md).
## Commands / tools / settingsCommands:
- `/tune [off|clear|export|<text>]` — start, stop, clear, export, or resume tune mode
- `/tune clear` deletes `.pi/tune/session.jsonl`; it leaves `ideas.md`,
benchmarks, checks, and hooks intact
Tools:
- `init_experiment` — configure session name, metric, unit, and direction
- `run_experiment` — run `.pi/tune/benchmark.mjs` with Pi's Node executable,
capture output, parse `METRIC name=value` lines, and run checks when configured
- `log_experiment` — record result and keep or discard VCS changes
Settings live under `tune` in Pi settings (`~/.pi/agent/settings.json` or
project `.pi/settings.json`).
Keys:
- `shortcuts.toggleDashboard` — default `ctrl+shift+t`; `null` disables
- `shortcuts.fullscreenDashboard` — default `ctrl+alt+t`; `null` disables
- `maxIterations` — positive number caps experiments per segment; default `null`
- `autoResumeLimit` — positive number caps auto-resume turns; default `null`
## HooksPi hooks:
- `session_start` / `session_tree` — reconstruct state from
`.pi/tune/session.jsonl`
- `before_agent_start` — inject tune system prompt when mode is active
- `session_before_compact` — produce deterministic compaction summary
- `agent_end` — schedule auto-resume when mode is active
- `session_shutdown` — clean up UI and timers
Tune iteration hooks:
- `.pi/tune/hooks/before.mjs`
- `.pi/tune/hooks/after.mjs`
Hook scripts run with `node`, receive JSON on stdin, and return steer text on
stdout. Hooks time out after 30 seconds. Hook stdout is capped at 8 KiB.
## StateAll state lives in `.pi/tune/`.
| File | Purpose |
| ------------------ | --------------------------------------------- |
| `session.jsonl` | Append-only experiment log |
| `session.md` | Living document: objective, what's been tried |
| `ideas.md` | Backlog of untried optimizations |
| `benchmark.mjs` | Benchmark script |
| `checks.mjs` | Optional correctness gate |
| `hooks/before.mjs` | Optional pre-iteration hook |
| `hooks/after.mjs` | Optional post-iteration hook |
## E2ERun root `mise run e2e` first to install browsers and execute every extension suite.
After that bootstrap, run `mise run e2e` here, or `mise //extensions/tune:e2e` from the repository root, to test dashboard loading, theme interaction, and live updates in Chromium and Firefox.
## BehaviorTunes through an autonomous loop: edit → benchmark → log → keep or discard →
repeat.
Benchmark output may include metric lines:
```textMETRIC name=value
```
`run_experiment` parses finite numeric metrics and rejects unsafe metric names
such as `__proto__` and `constructor`.
`run_experiment` takes no command.
Tune requires no Bash, Git Bash, PowerShell, or WSL for experiments or VCS handling.
Put environment setup and subprocess orchestration in `benchmark.mjs` with Node APIs.
If `.pi/tune/checks.mjs` exists, it runs after every passing benchmark. Check
failures block `keep`.
Benchmark, checks, and hook modules use the same Node executable running Pi.
VCS behavior is native per repo:
- jj repos use `jj describe`, `jj new`, and `jj abandon`
- non-jj repos use Git
Tune takes an exclusive `.pi/tune/lock.json` repo lock per Pi session. Parallel
tune runs in one checkout are rejected; use a separate checkout or workspace for
parallel tuning.
Confidence scoring is MAD-based after 3+ runs:
- `≥2.0×` — real
- `1.0–2.0×` — marginal
- `<1.0×` — noise
Compaction skips the default LLM summary and rebuilds a deterministic summary
from persisted tune state.
`settings.tune.maxIterations` caps experiments per segment.
`settings.tune.autoResumeLimit` caps automatic resume turns.
Both default to `null`, meaning unlimited.