repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

extensions/tune/README.md

Raw

tune

Tune code through autonomous experiment loops for Pi.

Install / load

Loaded through the root pi-ext package. Slug: tune. Package: @bugabinga/pi-ext-tune. See root README.

Commands / tools / settings

Commands:

Tools:

Settings live under tune in Pi settings (~/.pi/agent/settings.json or project .pi/settings.json).

Keys:

Hooks

Pi hooks:

Tune iteration hooks:

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

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.

Benchmark commands are guarded. node .pi/tune/benchmark.mjs, node benchmark.mjs, simple environment prefixes, and nice node benchmark.mjs are accepted. Chained commands are rejected.

If .pi/tune/checks.mjs exists, it runs after every passing benchmark. Check failures block keep.

VCS behavior is native per repo:

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:

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.

Markdown source
File outline
# tune

Tune code through autonomous experiment loops for Pi.

## Install / load

Loaded through the root `pi-ext` package.
Slug: `tune`. Package: `@bugabinga/pi-ext-tune`.
See [root README](../../README.md).

## Commands / tools / settings

Commands:

- `/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 a timed benchmark command, 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+shift+f`; `null` disables
- `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                  |

## Behavior

Tunes through an autonomous loop: edit → benchmark → log → keep or discard →
repeat.

Benchmark output may include metric lines:

```text
METRIC name=value
```

`run_experiment` parses finite numeric metrics and rejects unsafe metric names
such as `__proto__` and `constructor`.

Benchmark commands are guarded. `node .pi/tune/benchmark.mjs`, `node
benchmark.mjs`, simple environment prefixes, and `nice node benchmark.mjs` are
accepted. Chained commands are rejected.

If `.pi/tune/checks.mjs` exists, it runs after every passing benchmark. Check
failures block `keep`.

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.