feat(pi): print and JSON mode skip the wake-up and mailbox poll (MEMPALACE_WAKEUP_PRINT=1 to keep them)
In print and JSON mode, `pi -p` and `--mode json` no longer get the before_agent_start wake-up injection (status, diary and the tier-1 mailbox), and the mid-session mailbox poll is off as well. The poll has its own guard, not just `wokeUp`, because `pi -p -c` resumes and a resume sets wokeUp. The client still connects, and the mempalace_* tools stay registered. MEMPALACE_WAKEUP_PRINT=1 restores both. TUI and RPC sessions are unchanged. Why: a one-shot run is a script asking one question. The wake-up cost it 12 palace calls and a large orientation message, and it is meant for the operator of an interactive session. It can also do harm: on tor-ms22 a flash model given "Reply with exactly: PONG" read the injected diary's open items as its task, ran about 12 tool calls, and filed a wrong drawer in the shared palace. Measured on tor-ms22 (workspace copy, -ne -nt --no-session -e) with a fetch probe that re-wraps pi's own fetch. The earlier preload-only fetch wrapper had logged 0 lines in every run, because pi replaces globalThis.fetch. - pi -p: 3 palace requests (initialize, initialized, tools/list), 1.6 s. - --mode json: the same requests, 1.0 s, and no mempalace-wakeup in stdout. - --mode json with MEMPALACE_WAKEUP_PRINT=1: 15 requests, 12 of them tools/call (status 1, diary 1, event_list 10), 3.6 s, and the wake-up is in stdout. New scripts/test-wakeup-mode.sh has these cases: tui, print, json, print resumed, tui resumed (a control that shows the poll does run), print with MEMPALACE_WAKEUP_PRINT=1, and rpc. f590a3a's source fails the print, json and print-resumed cases, with 12, 12 and 5 calls. All seven scripts/test-*.sh pass.
This commit is contained in:
@@ -38,6 +38,9 @@ dependencies (~300 MB).
|
||||
injects the result as a `mempalace-wakeup` system message so the
|
||||
agent orients itself the way `~/.agents/skills/mempalace/SKILL.md`
|
||||
describes. Skipped on resume/fork (context is already in the thread).
|
||||
Also skipped in print and JSON mode (`pi -p`, `--mode json`), together
|
||||
with the mid-session mailbox poll, unless `MEMPALACE_WAKEUP_PRINT=1`.
|
||||
See [Debugging](#pi--p-prints-its-answer-then-takes-minutes-to-exit).
|
||||
4. **Automatic transcript feeding** (`session_shutdown`, and a debounced
|
||||
`agent_settled`): stages + mines this pi installation's own session
|
||||
transcripts into the palace with no user action needed — **as of
|
||||
@@ -116,6 +119,7 @@ side of the wiring.
|
||||
|---|---|---|
|
||||
| `MEMPALACE_FEED` | `1` | Set `0` to disable automatic feeding entirely. |
|
||||
| `MEMPALACE_FEED_PRINT` | unset | Set `1` to feed in print and JSON mode too (`pi -p`, `--mode json`). They skip the feed by default, because the next interactive session's feed files the same sessions without duplicates. See [Debugging](#pi--p-prints-its-answer-then-takes-minutes-to-exit). |
|
||||
| `MEMPALACE_WAKEUP_PRINT` | unset | Set `1` to keep the wake-up injection and the mid-session mailbox poll in print and JSON mode. They are skipped there by default. The `mempalace_*` tools stay registered either way. |
|
||||
| `MEMPALACE_FEED_BIN` | `mempalace-pi-session` | Helper to run. |
|
||||
| `MEMPALACE_FEED_WING` | `wing_conversations` | Target wing — passed to both the exporter and the `mempalace_mine` call. |
|
||||
| `MEMPALACE_FEED_DEBOUNCE_MS` | `600000` (10 min) | Minimum gap between mid-session (`agent_settled`) feeds. Bounds crash loss to one window instead of a whole session. |
|
||||
@@ -608,6 +612,25 @@ skips an unchanged file, and for a grown file it purges that file's drawers
|
||||
before refiling. A device that only ever runs `pi -p` sets
|
||||
`MEMPALACE_FEED_PRINT=1`, or its transcripts are never fed.
|
||||
|
||||
**Print and JSON mode skip the wake-up too (also 2026-10-13).** The wake-up
|
||||
injection costs 12 palace calls: `mempalace_status`, `mempalace_diary_read`,
|
||||
and 10 `mempalace_event_list` for the tier-1 mailbox. It also adds a large
|
||||
orientation message to a script's one question. It is meant for the operator
|
||||
of an interactive session, who sees the same thing in their next one. It can
|
||||
also do harm. In one tor-ms22 probe, a flash model was given
|
||||
`Reply with exactly: PONG`. It read the injected diary's open items as its
|
||||
task, ran about 12 tool calls, and filed a wrong drawer in the shared palace.
|
||||
So in print and JSON mode the bridge now skips the injection. It also skips
|
||||
the mid-session mailbox poll, through its own guard: `pi -p -c` resumes, and a
|
||||
resume sets the flag the poll would otherwise use. The client still connects
|
||||
and the `mempalace_*` tools stay registered, so a prompt that asks for the
|
||||
palace gets it. Measured on tor-ms22 with a fetch probe that re-wraps pi's
|
||||
own `fetch`: `pi -p` made 3 palace requests (`initialize`, `initialized`,
|
||||
`tools/list`) and exited in 1.6 s. With `MEMPALACE_WAKEUP_PRINT=1` it made 15,
|
||||
including 12 `tools/call`, and the wake-up appeared in the JSON stream.
|
||||
`scripts/test-wakeup-mode.sh` pins it; `f590a3a`'s source fails its print,
|
||||
json and print-resumed cases.
|
||||
|
||||
## The `Type.Unsafe` gotcha
|
||||
|
||||
Earlier versions of this extension registered every MCP tool with
|
||||
|
||||
Reference in New Issue
Block a user