Skip to content

feat(pi): adapt Calm mid-turn visibility and built-in tool ownership - #32

Merged
withally merged 1 commit into
mainfrom
fm/fm-pi-calm-adapt-c1
Aug 15, 2026
Merged

feat(pi): adapt Calm mid-turn visibility and built-in tool ownership#32
withally merged 1 commit into
mainfrom
fm/fm-pi-calm-adapt-c1

Conversation

@withally

Copy link
Copy Markdown
Owner

Intent

Selectively adapt Pi Calm from upstream snapshot 6789876 to add newer mid-turn assistant visibility and built-in tool-ownership behavior. Preserve the fork's locally verified Pi 0.84.1 transcript-redraw and replay-window behavior, every PR 24 redraw regression, 0.84.1 version coverage, current config/calm on-off semantics, existing Calm presentation levels, the busy-state extension contract, exact operational acknowledgement/tool-reply behavior, and persisted transcript/export/model data. Mid-turn text must be presentation-only: hide completed toolUse text and length-limited text accompanied by a tool call, while leaving pending streams and final replies visible. On Pi 0.84.1, register no built-in wrappers during extension load; when Calm is already on at session_start or first activates, claim only uncontested built-in tool names from the real live registry, preserve and warn about foreign owners, and keep already-mounted or replayed built-in rows Calm-controllable through the exported ToolExecutionComponent presentation seam plus the existing forced-redraw seam. Require both portable regressions and genuine live Pi 0.84.1 proof for rendered visibility and ownership. Selectively reshape upstream behavior onto the diverged files; do not wholesale-copy the snapshot. Deliberately do not take upstream lines that remove 0.84.1 verification, transcript replay/origin/acknowledgement adaptations, pre-activation redraw guarantees, or replace local level semantics. Do not import Cursor, Muse, stow-tiering, startup-network, remote-worker changes, a Calm level redesign, AGENTS supervision edits, or unrelated cleanup. Keep AGENTS.md unchanged unless its single Calm config line genuinely needs a behavior correction. Ensure bin/fm-lint.sh is clean. In the PR body, state the imported visibility and ownership behavior, how it composes with the redraw seam, and which upstream lines were not taken because they would revert Pi 0.84.1 coverage or local guarantees. Do not merge.

What Changed

  • Imported the upstream mid-turn visibility behavior as a new presentation-only assistant-working-note transcript class: Calm now hides text in completed toolUse assistant messages and in length-stopped messages that carry a tool call, while pending streams, final replies, and the exact "Captain, shipshape." operational tool-reply acknowledgement stay visible; the hidden text remains intact in session/transcript data.
  • Imported the upstream built-in tool-ownership behavior reshaped for Pi 0.84.1: extension load registers no built-in wrappers; when Calm is already on at session_start or first activates, it claims only uncontested built-in names from the live registry via pi.getAllTools(), warns about (and never displaces) foreign owners, and reports later-observed ownership losses. Already-mounted or replayed built-in rows stay Calm-controllable through a new ToolExecutionComponent.prototype.render presentation adapter that composes with the existing forced-redraw seam, so pre-activation rows follow Calm on the next redraw without touching their execution owner.
  • Deliberately did not take upstream lines that would revert local guarantees: 0.84.1 version verification, transcript replay/origin/acknowledgement adaptations, pre-activation redraw guarantees, and the local Calm presentation-level semantics all remain as-is; docs (docs/calm.md, docs/calm-mode-feasibility.md, docs/verification/runtime-backends.md) record the adaptation, and both the portable Calm regression suite and the genuine live Pi 0.84.1 tmux guard grew coverage for rendered mid-turn visibility and foreign-owner execution.

Risk Assessment

✅ Low: Presentation-only change that verifiably preserves execution ownership, export/session data, and every intent-required local guarantee, backed by new portable regressions plus recorded genuine live Pi 0.84.1 proof; the only findings are a duplicated string literal and two informational notes.

Testing

Ran the portable Calm regression suite (11/11 ok) and the live Pi 0.84.1 Calm guard (ok), then manually reproduced the live scenario in tmux to capture rendered-TUI evidence: Calm activation warns about the foreign "read" owner, the finalized mid-turn note disappears from the rendered transcript while the final reply stays visible, the note remains in persisted session data, and the foreign tool owner still executes. The change is a terminal TUI, so pane text captures are the reviewer-visible rendering surface; the transient pending-stream-visible state was too brief to capture live but is asserted by the portable suite. All results passed with no product, setup, or flakiness issues.

Evidence: Live Pi 0.84.1 pane: Calm on, foreign built-in owner warning rendered

 Warning: tmux extended-keys-format is xterm. Pi works best with csi-u. Add `set -g extended-keys-format csi-u` to ~/.tmux.conf and restart
 tmux.

 Warning: Firstmate Calm: the "read" built-in tool is already provided by another extension, so Calm may not fully function for it this
 session.

 Tool output: collapsed

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
/private/tmp/fm-calm-evd.HwVXoh/project (master)
0.0%/4.1k (auto)                                                                                                   (calm-live) deterministic
Evidence: Live Pi 0.84.1 pane: final reply visible, mid-turn note hidden from rendered transcript

RUN_CALM_LIVE_GUARD CALM_LIVE_FINAL_REPLY (pane also shows the foreign-owner warning; MIDTURN_LIVE_NOTE and the read tool row are absent from the rendered TUI)


 Warning: tmux extended-keys-format is xterm. Pi works best with csi-u. Add `set -g extended-keys-format csi-u` to ~/.tmux.conf and restart
 tmux.

 Warning: Firstmate Calm: the "read" built-in tool is already provided by another extension, so Calm may not fully function for it this
 session.

 Tool output: collapsed


 RUN_CALM_LIVE_GUARD


 CALM_LIVE_FINAL_REPLY

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
/private/tmp/fm-calm-evd.HwVXoh/project (master)
0.7%/4.1k (auto)                                                                                                   (calm-live) deterministic
Evidence: Persisted session JSONL still contains the hidden mid-turn note
{"type":"message","id":"ab6adf82","parentId":"449ea039","timestamp":"2026-08-15T00:56:39.274Z","message":{"role":"assistant","content":[{"type":"text","text":"MIDTURN_LIVE_NOTE"},{"type":"toolCall","id":"calm-live-read","name":"read","arguments":{"path":"unused.txt"}}],"api":"calm-live-api","provider":"calm-live","model":"deterministic","usage":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0,"totalTokens":0,"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0,"total":0}},"stopReason":"toolUse","timestamp":1786755399272}}
Evidence: Foreign built-in owner executed under Calm

foreign-read-executed

foreign-read-executed
Evidence: Portable Calm regression suite output (11 ok)
ok - Pi calm resolves its persistent home independently of Pi's launch directory
ok - Pi calm compatibility evidence never rejects a Pi version for being newer than 0.82.0, and still fails closed on a missing or malformed version
ok - a missing collapsed-thinking presentation API degrades only that Calm adapter with a clear skip reason, while the rest of Calm still registers
ok - a Pi TUI that stops supplying a forcible-render TUI fails loudly with the harness and version instead of silently losing Calm's transcript redraw, while non-TUI modes stay quiet
ok - missing Pi presentation class exports and both transcript replay seam paths reach the independent adapter degradation path
ok - Calm registers no built-in wrappers during load, claims all 7 from a Calm-on session start, and preserves plus warns about foreign same-name tool owners on first activation
ok - Pi calm centralizes transcript visibility, preserves execution/export data, keeps Pi's stock working row visible while no run is active, and persists its choice across session starts
ok - Pi operational follow-up E2E processes exact user-role notifications once while Calm hides current and adjacent rows, Calm off and absent render them, and restart preserves semantics
ok - Pi Calm native /skill:ahoy geometry keeps every collapsed thinking and tool block at zero height while preserving expansion, history, restart, and Calm-off rendering
ok - Pi Calm working ship moves on a slow independent cadence over faster fixed-cell blue water, paints the complete boat standard yellow with balanced resets, keeps ANSI-stripped width exact, flips the directional sail on the exact bounce at both edges and every width, clamps visible and hidden resizes, falls back deterministically when narrow, freezes and resumes column/direction across settle/start without hidden-time jumps or duplicate timers, resets only on a fresh session, and installs and removes one scheduler-owning widget across starts, settle, abort, failure, shutdown, reload, replacement, and Calm toggles while leaving Calm-off visibility untouched
ok - Pi calm native E2E replaces the stock working row with a moving, resize-clamped working ship that freezes and resumes across two working periods in one Pi session, clears on abort, keeps captain turns visible, hides exact operational user rows without changing persistence, restores stock rendering Calm-off, survives restart, and preserves export plus Ctrl+O behavior
Evidence: Live Pi 0.84.1 Calm guard result

ok - Pi 0.84.1 live Calm guard hid persisted mid-turn text after forced redraw and preserved a foreign built-in owner

ok - Pi 0.84.1 live Calm guard hid persisted mid-turn text after forced redraw and preserved a foreign built-in owner

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 3 infos
  • ℹ️ .pi/extensions/lib/fm-calm-assistant-layout.ts:63 - isProtectedOperationalToolReply hardcodes the literal "Captain, shipshape." at line 63, duplicating the FIRSTMATE_NO_ACTION_ACKNOWLEDGEMENT constant declared at line 72. These must stay in sync for the working-note carve-out to keep matching the exact operational acknowledgement rule; move the constant above the helper and reference it to remove the drift hazard.
  • ℹ️ .pi/extensions/fm-calm.ts:170 - The built-in-tool-row adapter probes only ToolExecutionComponent.prototype.render existence; the private instance fields it reads (toolName, imageComponents, imageSpacers) are unprobed, so a future Pi renaming them degrades silently to fully visible rows instead of emitting the per-adapter diagnostic docs/calm.md promises. The failure direction is safe (nothing over-hidden, no crash — the typeof toolName guard falls back to the original render), and instance fields cannot be probed at install time, so this is an accepted tradeoff worth noting, not a defect.
  • ℹ️ docs/verification/runtime-backends.md:102 - docs/verification/runtime-backends.md honestly records that the broader credentialed live run failed its pre-existing exact-HANDLED model-response assertion (the model replied "Watcher wake handled and acknowledged."). This nondeterministic-model assertion pre-dates this change and is not caused by it, but it is a live-test flakiness source worth a follow-up hardening (e.g. tolerant matching or a deterministic provider for that leg).
✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-calm-pi-extension.test.sh — full portable Calm regression suite (11 ok, exit 0), including the new built-in ownership regression and mid-turn working-note render/hide/restore assertions
  • FM_PI_LIVE_E2E=1 FM_PI_CALM_LIVE_ONLY=1 bash tests/fm-pi-primary-live-e2e.test.sh — genuine live Pi 0.84.1 tmux guard for rendered mid-turn visibility, forced redraw, session-data preservation, and foreign built-in owner execution (exit 0)
  • Manual tmux reproduction of the live Calm guard on installed Pi 0.84.1 with pane captures saved as evidence: /calm activation warning, final-reply pane without the mid-turn note, session JSONL retaining MIDTURN_LIVE_NOTE, and the foreign read tool's execution marker file
  • Verified pi --version = 0.84.1 and the installed @earendil-works/pi-coding-agent package = 0.84.1, so live proof ran against the exact version the intent requires
  • Verified git status clean after testing and no transient lab directories left in the worktree
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@withally
withally merged commit 114a206 into main Aug 15, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant