# Tool reference

The package registers one extension entry and three tools. There are no loader
tools, profile names, generated workflow schemas, or agent-management commands.
The installed tool schemas are authoritative for optional fields.

## `delegate`

```js
delegate({
  prompt: "The complete assignment, including constraints and expected output.",
  name: "optional-readable-name",
  cwd: "/optional/working/directory",
  model: "provider/model",
  thinking: "low",
  context: "fresh",
});
```

`prompt` is required. It is the assignment, not a fragment interpolated into a
canned profile. `name` is an optional display name, not a unique identity or role.
Omitted cwd/model inherit the invoking session's effective selection. A supplied
model must be available; there is no hidden alternate-model retry catalog.

`thinking` accepts `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, or `max`.
It overrides parent effort for this child without changing the parent. It works
with an omitted model or a literal model ID on every supported host, including
official Pi 1.8.0. Omission preserves inherited effort (or the configured overseer
model's thinking when `model` is omitted and `/overseer-model` configures one). Pi applies its native
model-capability clamping; the launch receipt records the requested value, not
proof of the child's effective effort.

On hosts exporting Pi's native `resolveModelReference`, `model` also accepts
`provider/model:thinking` (for example `provider/model:low` or `provider/model:off`).
The explicit suffix overrides inherited thinking for that child only. If both
`thinking` and a suffix specify effort, they must match or the launch fails. Literal
model IDs take precedence, including IDs containing colons or additional slashes;
unknown IDs and invalid suffixes fail without fuzzy matching or another provider.
Native resolution follows Pi's case-insensitive ID matching. Pi still applies the
selected model's native thinking capabilities.

Official Pi, including 1.8.0, does not export that resolver. Older fork runtimes also
lack the export. Those hosts retain case-sensitive literal-ID overrides and
support the `thinking` field. Suffix requests fail with an upgrade message rather
than being parsed by an extension-side replacement. Suffix support requires a
host with the public resolver export, not merely a matching version number.

Fresh context is the default. Fork uses the native conversation, including
historical tool calls and results; restricting a child's authority does not erase
the parent's evidence. Native Pi system/tool instructions and applicable project
resources still apply. Forking does not authorize nested delegation.
Antigravity (`agy`) MCP sessions have no native Pi `.jsonl` journal to fork, so
they accept `context: "fresh"` (or an omitted/`null` `context`) and reject
`context: "fork"` explicitly; see [Antigravity (`agy`) peer adapter](intercom.md#antigravity-agy-peer-adapter).

A fork child has its own session id. Its session header also records, as
`cacheSessionId`, the session id under which the copied conversation was sent to
the provider. A fitchmultz/pi fork that reads the field sends that id to providers
in place of the child's own, so the child's first request reads the copied
conversation from the provider's prompt cache: OpenAI routes a request to a cache
by session id. Other hosts ignore the field, and the child sends its own id; on
OpenAI routes its first request then reads almost nothing from the cache. The
main and its fork children send their requests under one id. OpenAI's guidance
is about 15 requests per minute per key; above it some requests may be routed
elsewhere and read less from the cache.

The response acknowledges launch only. It does not claim a model response or
completion, and no tool waits for child completion: the parent continues other
work or ends its turn, and the completion notice resumes it. Aborting a parent reply
with Escape does not stop already-launched children; use `stop` for one run. Switching
or forking sessions in place (`/new`, `/resume`, `/fork`) detaches the previous
session while keeping its active background children running; exiting the parent
process stops its children, including active work, and preserves their saved conversations.

`readOnly: true` disables repository file-editing tools (`edit`, `write`, `replace_text`,
`write_files`, `apply_patch`) and limits `notes` to `list`, `read`, and `search`.
Shell commands are not OS-sandboxed.

Completion notifications need a running main session. Ending a turn in a persistent
TUI, RPC or SDK session is not parent exit. A one-shot print invocation exits after
its final turn and stops any remaining children; it does not wait for their results.

Only a main may delegate. Children cannot bypass the restriction through a hidden
tool or programmatic invocation of `delegate` or `agent_runs`.
Main Antigravity (`agy`) sessions receive `delegate` and `agent_runs` alongside
`intercom` over the bundled MCP server, with runs owned by `agy-<conversationId>`
and completions/checkpoints delivered through the same `agentapi` wake and hook
queue path as inbound Intercom messages.

## `agent_runs`

Saved runs belong to the main session that launched them (`sessionId` on Pi or
`agy-<conversationId>` on Antigravity), not its cwd,
project, display name, or a different session forked from its history.
Live guidance and saved-run successors keep the child's saved effort even if the
parent's effort has changed.

| Action     | Purpose                                                                                                                                     |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `list`     | Page through the current native owner's saved-run metadata, without output previews.                                                        |
| `inspect`  | Read one run's result and process/publication facts without waiting or interrupting.                                                        |
| `continue` | Steer a live/paused child, approve a paused overseer checkpoint (omit `prompt`), or resume a settled child conversation as a new successor. |
| `stop`     | Request termination (and release any active checkpoint pause); inspect the actual process outcome afterward.                                |

All actions except `list` require `id`. Use IDs returned by the tools rather than
infer them from display names. `list` returns at most 50 runs per page: running
runs first, then newest first. The model reads one line per run (ID, status, end
time, model, name) and the `offset` of the next page. A run with a recorded wake
failure is marked on its line. A run stays `running` while its child waits on its
own background work, and its line states what it waits on; see
[Background work of a child](#background-work-of-a-child). The order can change between pages when a run
starts or settles. The tool details keep the complete metadata summaries with
`nextOffset`, and a codemode script receives those same summaries as a JSON
string. `inspect` states every field of one run, including its cwd, lineage,
native session, guidance and output file. Output is retrieved only by explicit
inspection, not embedded in every inventory row. Inspection of large output returns a continuation
offset; follow that offset until complete. The saved native session and full
output remain available independently of the preview.

Continuation of active work queues guidance. Continuation of completed work
creates an immutable successor in the same conversation. Original handles can
find the latest successor for controls, while inspection preserves predecessor
results. A retained ambiguous launch claim prevents accidental duplicate launch;
missing session state is an error, not permission to start a different chat.
When resuming a settled run whose original directory no longer exists (for example,
after deleting a temporary worktree), pass `cwd` on `agent_runs({ action: "continue", id, prompt, cwd })`
to resume it in an existing directory (`cwd` is valid only with `action: "continue"` on settled runs).
If a handoff saved a run but failed before admission, retry `continue` with the
exact same prompt after its actor and owned shells have exited. This resumes the
saved run and queued command, not another successor. A different prompt is refused
until admission or a canonical result; end the turn or do other work until the
completion notice rather than polling. A missing queued command or ambiguous
process claim requires inspection rather than automatic replay. If the prompt
was lost from context, read its exact value from `launch.json` beside the run's
reported `outputFile`; do not reconstruct or paraphrase it. For adopted legacy
runs, retry using the canonical run ID returned by the existing-successor receipt,
not the retired legacy handle.
Cancellation before delegation preparation starts refuses the delegation.
Cancellation during preparation is checked after the launch and Run command are
saved: the actor is not started, and the same exact-prompt retry can start that
queued run. Once actor startup begins, parent-turn cancellation does not retract
the launch or stop the actor. Use Stop to cancel work handed to an actor.
Guidance that arrives after its run settles is reported as stale rather than
starting untracked work. Inspection text exposes the guidance command IDs and
admission states, native receipt publication and separately known process exit.
Continuing active work returns a guidance receipt with the command ID; queue
acceptance is not admission, and admission is not model consumption. Inspect the result and send a new continuation
if guidance became stale; do not infer acceptance from the old completed output.

A completed child can remain alive and messageable while its main remains
attached. On a Pi fork with native working-session capture, a child that stays
idle for five minutes (no run, turn, journal change, live viewer or owned shell)
parks: it saves its exact working state and its process exits, while its intercom
identity stays listed with no departure. `last` reads do not wake it; the main
answers `last` from the saved history, and
without its main the read reports that history unavailable. Receipt reads also do
not wake it and report `publication_unavailable`. A
sent message or continuation restores the exact saved state into a new
process, which then receives retained messages in order. If the final save
fails, the child records `park-failed.json` and nothing restarts implicitly;
retained messages stay queued and continuing reports the failure. A failed wake
is recorded as the run's `lastWakeFailure`: `agent_runs list` marks the run and
`inspect` states the failure.
This is a historical failure, not a claim about the child's current state. A
later active message requests another wake. The saved working directory must be
available; no other directory is substituted. A pre-existing ambiguous actor
claim still requires inspection and is not removed automatically. Official Pi
keeps idle children resident. Parent process exit stops its actors and verified owned
native shells, allowing native abort a short grace period before escalation. Switching
or forking sessions in place (`/new`, `/resume`, `/fork`) detaches the previous session's
live-main lock while keeping its active children running until they settle, another main
resumes that session, or the parent process exits.
SDK runtime disposal also stops children retained across session switches. When
using multiple in-memory SDK runtimes in one process, bind each replacement
before starting another switch: Pi does not identify the source or destination
of simultaneous fileless switches, so disposal cannot safely reclaim those
retained children.
Actors also watch for parent death, including a hard kill. When the spawner
owns the child, the operating system closes a control pipe as soon as the
spawner exits. The child rereads the current attachment before stopping.
An ordinary extension reload leaves the pipe open and keeps children alive.

Under a fitchmultz/pi fork launcher that provides `ctx.managedHost`, the launcher
that survives `pi restart` and `/restart` owns child lifetime instead of the worker
process. A restart keeps children running; the replacement attaches and delivers
their completions only after it becomes ready, and startup rollback keeps them too.
Quitting, including quitting a replacement before it is ready, still stops them.
Children of a managed launcher, or children adopted by a different owner,
check the recorded owner's process identity instead of relying on a worker's pipe.
After upgrading, relaunch the full CLI once: a worker started by an already-running
older launcher has no `managedHost`, so restart still stops children with the old
worker. Official Pi, SDK, print and RPC sessions keep worker-lifetime ownership.

Resume the same parent and use `continue` with a new prompt to resume a saved
child conversation. This does not replay interrupted tool calls or reconstruct
an execution checkpoint: the child inspects the current work state. Saved
journals and results are retained whether the child was active, stopped or done.

### Background work of a child

On a fitchmultz/pi fork whose sessions list their background work
(`AgentSession.getBackgroundWork()`), a child has the `background_command` tool,
and its run stays `running` while the child's own background work is pending:
`background_command` jobs and codemode background scripts, which message the
child when they end. A child can start such work, end its turn and be woken by
the result, all inside one run. The run ends when the child is idle and lists no
such work. The completion notice and the saved result then carry the text the
child wrote after its last wake, and the run's usage covers every turn up to it.
The actor checks once a second, so the result can follow the child's last turn by
up to a second.

While a run waits, `list` appends `[waiting on "<description>"]` to its line,
with the first item and `+N more`, and `inspect` states since when it waits and
every item with its ID. A job's description is its command preview. `continue`
on a waiting run starts the child's next turn inside that run; it creates no
successor, and the run then waits again. A waiting run is a run, so its child
does not park.

A job that never ends, such as a server or a watcher, keeps its run `running`
until the child cancels the job or the parent stops the run. `stop` requests
cancellation of every listed item and then aborts the child; the result is
`stopped`. A run admitted in the same durable batch as its `stop` is fenced
before its prompt is submitted, so it publishes `stopped` without starting new
work. Parent exit stops children the same way. A job's cancellation is a
request to its detached worker, which stops the shell's process tree whether or
not the actor is still alive. An actor that is killed before it handles the stop
leaves its jobs to end or to reach their own `timeout`; their logs stay under
the child's session directory. A new actor for that child within about ten
seconds of the kill does not list those jobs yet, so its run can end before they
do.

Official Pi has neither API. Its children have no `background_command`, and a
run ends at the child's first idle: a child that ends its turn with a codemode
background script pending completes with the text it wrote before the result.

### Tools a child declares

`subagents.toolExposure` in Pi's `settings.json` is a `toolExposure` map for
children only. It keeps tools that children rarely need out of their requests
while the children can still reach them:

```json
{
  "defaultTools": ["+tool_search"],
  "subagents": {
    "toolExposure": {
      "macuse": "deferred",
      "macuse_reset": "deferred",
      "new_context": "deferred"
    }
  }
}
```

With this example a child's requests do not declare the three tools. The child
loads one with `tool_search`, which declares it from the next request on, and a
codemode script calls one without loading it. Main sessions keep their own
exposure. The package names no tools itself; unset, children are unchanged.

The key needs a fitchmultz/pi fork with the `toolExposure` setting. Keys are
tool names or `*` patterns and values are `direct`, `model-only`, `codemode`,
`deferred` or `hidden`, with the meaning that setting gives them. Official Pi has
no such setting: there the package does not read the key, and children declare
the same tools with or without it.

A child reads the key from its own settings files, when its process starts: the
user file and, for a trusted project, the project file of its working directory.
The map goes on top of the child's own `toolExposure`, as one more settings
layer: an entry replaces a `toolExposure` entry with the same key, and its
patterns match first. Between the two files the project's entries win the same
way. Pi does not validate settings files. A value that is not a JSON object is
skipped, and an entry whose value is not an exposure sets none.

- `deferred` and `codemode` tools are reachable only while `tool_search` or
  `codemode` is active in the child. Children have both tools, inactive until
  `defaultTools` (`"+tool_search"`, `"+codemode"`) or an extension activates
  them. With neither active the child cannot call the tool, and nothing reports
  it: a child has no display for the warning Pi shows an interactive session.
- A child keeps the tools its conversation already declared. A
  `context: "fork"` child keeps the tools its main's conversation declared, and
  a child that `continue` starts again keeps the tools it declared or loaded
  before. The map decides the tools that conversation never declared. If a
  tool is registered differently in the child's project, Pi sends the child's
  declaration so the model can call it with the correct arguments.
- On Fitch Pi hosts whose `getMidConvoToolSupport` reports `"changes"`,
  `context: "fork"` children using Gemini 4 or later on `google-interactions`
  (except `google-ai-plan`) remove `delegate`, `agent_runs`, and `ask_question` through
  `removed_tools` in `system_input` while keeping the cached parent prefix
  intact. Hosts without `getMidConvoToolSupport` (such as official Pi) have no
  `google-interactions` `system_input` adapter and preserve the parent's
  declared tools instead.
- A `context: "fork"` child keeps the parent's declared `delegate`, `agent_runs`,
  and `ask_question`
  declarations when the target model cannot remove tools without rewriting the
  cached prefix. This includes `google-generative-ai`, `google-vertex`,
  `google-ai-plan`, `bedrock-converse-stream`, and models that only support
  tool additions. The child still blocks calls to those guarded tools.
  `subagents.toolExposure` still applies: explicit `hidden` entries deny and
  remove tools. `deferred`, `codemode`, and `direct` entries leave the parent's
  declared tools intact.
- A parked child wakes with the settings it was saved with, the map included.
- If a child reloads its settings, Pi drops the map for that child and declares
  the tools the map deferred. No tool becomes unreachable.

### Evidence levels

Keep these facts distinct:

1. A launch or command was saved/accepted.
2. The child admitted it to its native queue.
3. The relevant native journal entry was fully published.
4. A completed result was produced.
5. The actor process exited with an observed outcome.

Neither a queue receipt nor a stop acknowledgement proves the later levels.
Uncertain process death is reported honestly; it does not synthesize missing tool
results or an exit code. Commands created by tools may have independent process
lifetimes; actor exit alone is not proof that every descendant exited.

Native local bash records process identity before executing the command, allowing
same-owner Stop to clean up its shell group even after an actor crash. This also
supports the recognized `pi-change-working-dir` local bash wrapper without
replacing its cwd/environment behavior. Arbitrary custom or remote bash tools
remain owned by their extensions; the package does not claim cold-crash cleanup
of those external processes.

Stop and shutdown skip a saved PID only when it has exited or replacement is
proven; uncertain ownership still reports a diagnostic without signaling it.
A PID now owned by another user (permission denied) needs the same proof; it is
never treated as exited. Linux cannot read another user's namespace identity,
so such a PID stays uncertain there.
On macOS, a UTC-observed process birth strictly after its record's write time
disproves ownership even when the reused PID is no longer a group leader. This
assumes native record timestamps have not been backdated and the clock did not
move backward between process birth and publication. Missing timestamps,
same-second uncertainty and timezone differences alone do not prove replacement.
Linux uses its native process-clock and namespace identity instead.
New Android actor and shell records also save a native monotonic-clock bound
after process birth, qualified by the real boot ID and reader's time namespace.
Only a conservative birth lower bound from native process elapsed age, in that
same clock context, can disprove ownership. This survives controller clock and
timezone changes without comparing `ps` boot-epoch dates with record timestamps.
Unreadable ages, missing legacy clock bounds, different clock contexts and
whole-second/tick uncertainty do not prove replacement; identity checks still
fail closed rather than signal an unverified PID. An existing record without a
clock bound remains usable when its original process identity is verifiable.

### Prune shell witnesses

After an actor is reaped or its generation is replaced, dead shell witnesses
can be removed. A live orphan keeps its witness so cold Stop can still find it.
To reclaim witnesses from older generations, run the packaged command on the
machine and in the PID namespace that produced the records. Pass the
`sessions/agent-runs` directory, not a journal or an individual run:

```sh
node dist/agent/prune-dead-witnesses.js --dry-run --root ~/.pi/agent/sessions/agent-runs
node dist/agent/prune-dead-witnesses.js --apply --root ~/.pi/agent/sessions/agent-runs
```

Both modes check the current ownership and birth evidence. Apply deletes only
confirmed dead shell publications and their private backing files, then removes
empty closed generation directories. Active generations, ambiguous claims,
malformed records and unfinished publications stay in place.

## `intercom`

Use `list`, `claim`, `send`, `last`, and `status` for normal coordination and
diagnosis. `list` rows
include Git repo/branch context when in a repository, optional `working_on`
claims (set or cleared via `claim` without waking peers), and `worker_started` /
`last_turn_error` health tags locally and across devices. Unpinned `last` reads
warn when a newer assistant turn failed after or
without a completed response. See [local messaging](intercom.md)
for topology, target resolution, native replay, and delivery distinctions.

`send` uses local visibility rules for `name@this-device`, without SSH.
Device discovery includes bridge mailboxes. For an automated forward, use the
[verified `returnAddress` field](intercom.md#forward-a-notice-with-a-return-address)
to give the recipient a mailbox for a new `send`.

### Usage accounting

New calls do not attribute child usage to the parent's token/cost totals. Each
child result records its own native contributions exactly once, and continuations
add only newly published entries. Completion notices, inspection, reload and
metadata inventory do not charge the parent. Explicit inspection can reconcile
pending child accounting. Per-entry `result.contributions` remain in canonical
results and native tool details. JSON receipt text (including `stop`) selects
execution and accounting-status metadata; it does not automatically serialize
per-entry contributions or additional saved diagnostics. Process/stop evidence
and output/paging fields remain available in the text. Inventory, receipts,
inspection and completion notices each have an explicit model-facing renderer.

Historical foreground and `wait` charges already recorded in a parent's journal
remain in its native totals. For workflow totals, count shared continuation
journals once and do not count child contributions again when an older parent
tool result already includes them.

## Completion delivery

Attachment publishes durable ownership before ordinary session startup returns.
Retained completion recovery runs about 200 ms later or on an explicit
reconciliation, not on the awaited startup path. That delay is not a delivery
deadline. A short-lived main may exit before recovery, and a prompt started
immediately after startup may receive the recovered backlog as steering input.
Managed launchers still gate attachment on accepted host readiness.
One session has one live main: a startup that finds another live main's attachment
record refuses to attach instead of overwriting it, so the owning main keeps its
record and the refusing main's runs and stops act as unattached.
Attachment read/check/publication is serialized by a native SQLite OS lock.
Each conversation uses the same lock primitive for actor reinspection, dead-claim
reclamation, spawn, and PID publication. The private `ownership.lock` files stay
outside `actor.lock` and are never unlinked. Contention refuses the operation
without waiting or reclaiming a live lock; retry after the other operation finishes.
Closing the connection or process exit releases the OS lock.

Completion delivery and the interactive inventory share non-recursive directory
watches. The main watches its owner directory and the directories that hold
unfinished run metadata and pending-accounting journals.
Child exits, settlement, and `agent_runs` controls can also trigger reconciliation.
Change hints trigger fresh reads; canonical results, admissions, and journal
receipts decide delivery. A required watch or reconciliation that fails falls
back to 200 ms polling.

To recover dropped hints, the main checks input timestamps once a second while
it is tracking active runs, awaiting results, or waiting for accounting. With
none of those, it checks every 15 seconds and reconciles only if an input changed.
A watched change still wakes an idle main immediately.

Actors admit durable commands the same way: a change to their `commands`
directory, a stop or a deferred run starts a scan. A one-second recovery check
rechecks the directory for changes even when a control pipe handles parent death.
Without a watch, actors poll every 100 ms as before.

Completion notices use steering, not follow-up delivery. A busy parent receives
results at the next native tool boundary; it need not finish its task first.
An idle backlog is published before one wakeup.
This avoids separately deferred settlement wakeups replaying the same result.
New-runtime backlogs are sorted by completion time, then launch time and ID—not
directory order. A later scan cannot reorder messages already admitted to Pi.

Admission is still not publication or model consumption. Native physical receipts
suppress redelivery across reload/resume, and dropped queues can recover. A
`--no-session` parent has no session file, so Pi's in-memory transcript holds its
receipts for the life of that process. Receipt polling reuses unchanged verified
journal metadata.
When a current-format journal grows on the same device and inode, polling retains
the cached prefix and parses only appended records; it does not reread that prefix.
Other file changes rebuild the index. Native current-format writers append;
external prefix edits followed by same-inode growth are outside that contract.
Malformed records and missing final newlines do not fabricate receipts.
Completion delivery appends context; it does not replace prior prompts, tools,
model settings, or the active conversation.

## Read-only human observation

Interactive main sessions expose an above-editor widget and `/agents` list/watch.
The widget shows up to four active runs with circle indicators, status and short ID;
unreadable (unavailable) runs also stay listed. The default picker hides completed
runs; failed, stopped, interrupted, and unavailable runs remain visible there.
The header total counts all saved runs; the widget rows and overflow count include
only active work and unreadable runs.
`/agents <run-id>` still opens
saved completed runs, and an already-open watch stays open through completion.
An empty partial inventory says it is checking saved runs, not that no runs exist.
In fullscreen mode, click a named row to watch that child; click the header or
overflow count to open `/agents`. Picker rows and selection/Back/Close hints are
clickable too. Regular mode retains the keyboard path because Pi leaves mouse
input to the terminal there. Enter or Ctrl+O expands the selected tool card in `/agents`, and Ctrl+P (`app.session.togglePath`) toggles assignment/journal details. The widget
clears once a complete error-free scan finds no active or unreadable runs, or when
the native parent is replaced; it stays while saved runs are still being checked. It is not
a footer-only count.
Use Up/Down to select, Enter to watch, and Escape to return/close (the displayed
hints follow Pi's configured selection keys). `/agents <exact-run-id>` opens that
run directly. Children and print/RPC modes do not install the interactive observer.

If native opening migrates an older-format journal, an existing reader rejects its
changed generation. Reopen the conversation to index the migrated journal.

These views read this native owner's metadata and bounded published journal entries;
they never dispatch, continue, stop, send messages or trigger a model turn.
Published assistant text/tool calls may precede a running tool's result. Partial
journal records and unpublished provider token deltas are not presented as completed
entries. Agent tools remain the orchestration surface; this does not restore the
retired workflow UI or remote transcript APIs.

Long `delegate`, `agent_runs`, and `intercom` result cards start with a four-visual-line
preview, including output that wraps from one long logical line. Pi's native card
click and configured expand-tools key (`app.tools.expand`, Ctrl+O by default) reveal
the full output. Child completion, escalation, notification, and Intercom message
cards use the same four-visual-line preview; cards with at most four visual lines
show no expand hint. Clicking a message card toggles only that card—through the
per-card header action on official Pi, or through native card click on the
maintained Pi fork, where the header itself is plain text so left clicks bubble
to the native card (including under `compactView`). Pressing `app.tools.expand`
(Ctrl+O by default) toggles the global tools-expanded view across all cards. Full
saved and model-visible content is unchanged.

## Installation and upgrade

```bash
pi install npm:@fitchmultz/pi-subagents
# Or register a built, runtime-only local checkout:
npm ci --omit=dev
pi install /absolute/path/to/pi-subagents
```

Development dependencies are for verification, not a second host runtime. Use the
committed npm lockfile. The build publishes a complete staged `dist/`; failed
compilation does not destroy the previous working tree. Do not rebuild a checkout
while active sessions load its files.

On native Android, source installation and verification require an Android build
of `tsgo` on PATH. The prebuilt npm installation needs no compiler. See
[Android development](development.md#native-androidtermux).

Where the filesystem denies hard links, exclusive saved-run records are atomic
relative symlinks to complete, private `.data` files beside them. Keep the entire
run directory, including those backing files and relative links, when backing up
or moving saved state; they are not disposable staging files. Existing regular
records remain readable and are never replaced by a competing exclusive writer.

Finish in-flight work before migrating from the old workflow engine. Preserve the
prior package, native sessions, and durable state for rollback. Old profile files
are left untouched but no longer configure delegation. Chain/fanout orchestration,
acceptance loops, profile administration, canned output paths, custom workflow
UI, and durable supervisor-question revival are retired, not silently translated
into ordinary messaging.

No package update implicitly grants deployment, publication, a global model/auth
change, or permission to restart a live bridge. Remote messaging requires the
separate authenticated bridge setup and coordinated companion migration.
[Rejected bridge wakes](intercom-bridge.md#rejected-wake-requests) remain available as unread mail. A successful bridge policy reload re-arms held receivers and parked notifications.

## Overseer mode

Overseer mode is off by default. Toggle it per session branch with `/overseer` (`/overseer on`, `/overseer off`, or `--overseer`)
or configure defaults under `subagents.overseer` (`{ enabled, model, judge }`) in Pi settings.
`/overseer-model` sets an optional default child model (`inherit` by default, keeping normal `delegate` model/thinking inheritance unless a `provider/model[:thinking]` target is configured);
`/overseer-judge` sets the grounded skeptic model (`auto`, `off`, or `provider/model[:thinking]`). Main-session
tools remain unrestricted so the overseer can run scripts or apply small surgical edits directly.
Changes from `/overseer`, `/overseer-judge`, or `/tree` sync immediately to `<run-base>/overseer.json`
so running subagents and `agent_runs continue` successors pick up the live state:
`/overseer off` stops new checkpoints and releases open pauses,
and `/overseer-judge off` aborts/skips skeptic evaluations and releases open skeptic pauses while
keeping structural checkpoints active.

### Read-only children and free editing

No delegation contract or file-glob allowlist is required.

- Pass `readOnly: true` on `delegate` for research, audits, or review children. File-editing tools
  (`edit`, `write`, `replace_text`, `write_files`, `apply_patch`) are disabled for read-only
  children, and editing checkpoints (`shape_check`, `final_diff`, skeptic) are skipped. Shell
  commands are not OS-sandboxed.
- Editing children work freely from the plain-English task prompt and standing rules (prefer
  isolated worktrees). When overseer mode is enabled, `prepareLaunch` also snapshots the parent
  session branch's chronological owner conversation (`ownerContext`, pairing short chat replies
  with the preceding assistant prompt and including completed `ask_question` answers) so the
  skeptic sees the owner's actual intent even on `context: "fresh"` launches or after context
  rollover.

### Worktree checkpoints

Overseer follows the child's selected working directory, including `change_dir` within a tool
batch. Each Git worktree has its own entry snapshot and last acknowledged checkpoint. Clean
snapshots use the `HEAD` tree; dirty snapshots include untracked files through a private Git
index. Pauses name the reviewed worktree and show only the changes since entry, a reset comparison
base, or the last checkpoint there.

For the full intended change, Overseer compares the current working tree to the merge base of
`HEAD` and `branch.<currentBranch>.gh-merge-base`. If it cannot resolve a base, it labels the
comparison “since entry; PR base unknown.” A restack resets the incremental comparison. During
a merge or rebase, Overseer reports the intermediate state without judging it as a finished change.

Three predictable triggers pause the child and notify the parent with `[agent-escalation]`:

1. **Early shape check (`shape_check`):** fires once per editing run on the first mutating turn
   that modifies the working tree.
2. **Grounded skeptic (`skeptic`) & tool errors (`tool_errors`):** mid-flight, every `4` mutating
   turns or `120` changed diff lines since the last skeptic check (and before settlement if
   unjudged edits remain), the skeptic receives the full intended patch, the incremental focus
   when different, earlier checkpoint decisions, and delivered parent guidance. It focuses on
   new hunks mid-run and the full change at settlement. Three consecutive turns with finalized tool
   errors trigger a `tool_errors` pause listing the exact Pi turn entry IDs and call outcomes.
3. **Pre-ship final diff (`final_diff`):** right before the child settles (`agent_before_settle`),
   if unreviewed file changes exist since the last acknowledged checkpoint, the child pauses so the parent sees the final
   diff before completion. If no edits occurred since the previous checkpoint, the child settles
   without double-pausing.

### Grounded skeptic model and evidence rule

With `/overseer-judge auto`, the skeptic tries available chat models via Pi's native
`modelRegistry.streamSimple` in this order:

1. `cloudflare-ai-gateway/claude-haiku-5-5:low` → `anthropic/claude-haiku-5-5:low`
2. `cloudflare-ai-gateway/gpt-6-luna:medium` → `openai/gpt-6-luna:medium`
3. `google/gemini-3.8-flash:medium`
4. `google/gemini-4-hydrogen:medium`

With an explicit `provider/model[:thinking]` spec, it asks only that model. The request passes the
full diff (never silently sliced client-side; provider context-limit errors fall back across `auto`
candidates or record `judge-unavailable.json`) and exposes a `report_findings` tool validated with
`@earendil-works/pi-schema` (falling back to structured JSON text if the model answers in text).
`validateGroundedFindings` verifies in code that each finding's `file` is in the changed diff and
its literal `excerpt` (>= 6 chars) appears verbatim inside that file's diff hunks; any ungrounded
finding is dropped automatically so content-free pauses cannot happen.

- Grounded `blocking: true` findings pause the child and quote each file, hunk line, and reason.
- Grounded `blocking: false` findings (when no blocking findings exist) are written to
  `overseer-notes.json` and delivered as non-blocking `[overseer-note]` heads-up messages without
  pausing the child or waking an idle parent.
- Every evaluated skeptic checkpoint (`ok`, `flagged`, `notes`, or `unavailable`, with counts and
  any failed candidates) is appended to `judge-checkpoints.json` and surfaced in `agent_runs inspect`.
  If all candidates fail, `judge-unavailable.json` is recorded and the child continues normally so
  structural checkpoints still run.

### Parent-side skeptic

When `/overseer` is enabled and `/overseer-judge` is not `off`, the main session also runs a
grounded skeptic `tool_call` check before:

- `delegate` calls,
- `agent_runs` `action="continue"` calls that carry a `prompt`, and
- high-impact `bash` commands (`gh pr merge`, `gh release create|delete`, `git push`,
  `git commit --no-verify`, `git reset --hard`, `git clean -f`, `git branch -D`,
  `npm|pnpm|yarn publish`, `wrangler deploy`, `chezmoi apply`).

Ordinary local commands (reads, tests, searches, local commits) skip the check. Grounding rules
in `validateParentFindings` depend on the finding kind:

- `contradicts_owner` and `dropped_constraint` require verbatim quotes of both an `ownerExcerpt`
  (>= 6 chars) from the owner's own chat messages or completed (non-cancelled, non-timed-out)
  `ask_question` answers — never from assistant text or peer messages — and an `actionExcerpt`
  (>= 6 chars) from the proposed tool input.
- `bypass_protection` (unauthorized `gh pr merge --admin`, `git commit --no-verify` / `-n`, or
  `git push --no-verify`) requires the command and `actionExcerpt` to carry a real bypass flag
  (verified via `hasProtectionBypassFlag`, ignoring quoted messages/bodies and operands after
  `--` on valid Bash commands and failing closed on unparseable Bash syntax). Include
  `ownerExcerpt`; it may be an empty string (`""`).

Ungrounded findings are dropped automatically. The prompt pairs each owner turn with the
immediately preceding assistant prompt to give short replies such as `a`, `yes`, and `both`
context. It includes bounded verification evidence from the active branch, ahead of recent
assistant updates. The judge uses the newest check, review, and thread results for the exact PR
or run and head commit. On Fitch Pi, a watcher completion can recover the verdict from that
session's watcher log if no terminal result is already visible. This works when the completion
is kept but its matching start was compacted; the check recovers only the start's job details
from the active branch. A process exit alone does not establish that checks passed or identify
the commit that was checked. A verdict from disk uses the verified log's last-write time so
a delayed completion notice does not make an earlier result look newer than a direct check.
Identical verdicts from the same watcher are shown once; conflicting verdicts remain separate.

Peer Intercom messages appear separately with their native sender. Peer messages, tool results,
and child reports cannot lift an owner hold or waive review rules. Grounded `blocking: true`
findings block the tool call with the quoted reason;
non-blocking findings append an `[overseer-note]` without blocking; model unavailability fails
open with a warning notification so the main session is never deadlocked.

### Answering a checkpoint pause

Answer any pause with `agent_runs`:

- **Approve and resume:** `agent_runs({ action: "continue", id })` (omit `prompt`). Advances the
  watermark and releases the child without injecting extra steering text. On a `final_diff` pause,
  the child immediately settles and completes.
- **Steer with corrections:** `agent_runs({ action: "continue", id, prompt: "..." })`. Releases
  the pause and delivers the steering prompt before the child's next model turn (including on
  `final_diff`, where the child takes a corrective turn before settling).
- **Stop:** `agent_runs({ action: "stop", id })`. Releases the pause and terminates the run.
