Repository navigation
feat(pi): collapse foreign and custom tool rows in Calm - #2
Merged
Merged
Conversation
added 6 commits
August 10, 2026 20:15
added 5 commits
August 24, 2026 22:45
…ls-c1 # Conflicts: # .pi/extensions/fm-calm.ts # docs/calm-mode-feasibility.md # docs/calm.md
…lm-custom-tools-c1
…across export window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Finish and land the existing open PR #2, feat(pi): collapse foreign and custom tool rows in Calm, by updating its existing fm/fm-calm-custom-tools-c1 branch in place. Build on the latest post-sync origin/main while preserving both the PR's Calm change and upstream changes, especially the shared Calm test and Pi watch extension. Calm must collapse custom, MCP, extension, provider-side, contested built-in, and unregistered tool-call and text-result rows like Pi built-ins while Calm is on, restore ordinary rendering when off, preserve Ctrl+O semantics and image visibility parity, and remain presentation-only without changing tool execution, model context, session storage, export, or share content. Diagnose and fix the real cause of the prior Behavior portable serial 4 failure without weakening, narrowing, or skipping its regression. Keep executable behavioral coverage that fails when the custom-tool collapse fix is reverted. Reuse PR #2; do not open a separate PR and do not merge it.
What Changed
.pi/extensions/lib/fm-calm-tool-row-layout.ts, a new idempotent adapter onToolExecutionComponent.renderthat renders the text shell of every tool-call and text-result row at zero height while Calm is on — built-in,fm_watch_arm_pi, foreign extension, contested built-in, and unregistered provider-side rows alike — while still emitting the row's image children and spacers so image parity is preserved. It probes both therendermethod and a real instance'simageComponents/imageSpacersstate at install and, like the existing adapters, skips only itself with a diagnostic if either seam is gone.fm-calm.tsinstalls it and its contested-built-in warning/diagnostic now says the row still collapses while/exportand/shareuse the other extension's renderer.calmScreenPresentationHides()infm-calm-visibility.ts— the same policy without the stock-export escape hatch — and moved the tool-row, assistant, and operational-user adapters onto it, since Pi builds export/share output from tool definitions and session entries rather than on-screen rows. Calm's terminal input handler now returnsundefinedon every path so Pi'sTerminalInputHandlercannot read a barereturnas an input override, and the assistant and operational-user adapters forward Pi 0.84.x's widened arguments (extraupdateContentargs,UserMessageComponentmarkdown transformers).tests/fm-calm-pi-extension.test.shwith real-component coverage for foreign self-shell and default-shell custom tools, a foreign-ownedbash, an unregisteredgetMcpToolsrow, foreign-tool image parity, byte-identical Calm-off restoration of each, pre-activation row collapse plus restore, an install-time image-seam probe case, and/export//sharewindow assertions (rows stay collapsed, images survive, repaint is requested viasetStatusrather than tool expansion); the tmux E2E now asserts pre-activation built-in rows collapse instead of staying visible, anddocs/calm.mdanddocs/calm-mode-feasibility.mdrecord the widened tool-row scope and Pi 0.84.1/0.84.2 evidence.Risk Assessment
✅ Low: The change is presentation-only and provably cannot reach export/share content (Pi's exporter renders from tool definitions and session entries, never from ToolExecutionComponent), it fails closed at install if either patched seam is renamed, and every intent criterion is covered by executable tests that exercise real Pi components and a real Pi TUI at the installed 0.84.2, with the serial-4 regression inherited byte-identically from base; the only residual is a superseded factual claim in three source header comments.
Testing
Ran the focused Calm suite (13/13 pass, covering real Pi 0.84.2 render components, a tmux Pi TUI E2E, and a real /export rendered through headless Chrome), plus the Pi watch extension test and the orphan-reap test that was the actual portable-serial-4 failure — all green; the Pi typecheck test self-skips locally for lack of tsc. Beyond the automated tests I drove a real Pi TUI carrying a genuinely foreign extension and captured screenshots showing MCP-style, extension, unregistered provider-side and built-in tool rows all rendering with Calm off, all collapsing with Calm on, staying collapsed under Ctrl+O, and fully restoring on the second /calm, plus an export taken while Calm is on whose HTML still contains every tool call and result. I diagnosed the prior "Behavior portable serial 4" failure from the CI log to tests/fm-remote-job-orphan-reap.test.sh TERMing a worker whose graceful handler intentionally refuses to exit once its state root is gone, confirmed the corrected fixture keeps the same 7 pass points and 19 fail guards, and verified the collapse coverage genuinely fails when the fix is reverted — at the adapter probe, both real-Pi-component tests, and the TUI E2E. Working tree restored byte-identical to the target commit with all lab scratch removed.
/var/folders/j0/w34lmlf93rdgx6qhg4t5m2mh0000gn/T/no-mistakes-evidence/01M0TRDVG7AKVP3MQT85VYEBS0/01-calm-off.png)/var/folders/j0/w34lmlf93rdgx6qhg4t5m2mh0000gn/T/no-mistakes-evidence/01M0TRDVG7AKVP3MQT85VYEBS0/02-calm-on.png)/var/folders/j0/w34lmlf93rdgx6qhg4t5m2mh0000gn/T/no-mistakes-evidence/01M0TRDVG7AKVP3MQT85VYEBS0/03-calm-on-ctrl-o.png)/var/folders/j0/w34lmlf93rdgx6qhg4t5m2mh0000gn/T/no-mistakes-evidence/01M0TRDVG7AKVP3MQT85VYEBS0/04-calm-off-restored.png)/var/folders/j0/w34lmlf93rdgx6qhg4t5m2mh0000gn/T/no-mistakes-evidence/01M0TRDVG7AKVP3MQT85VYEBS0/05-revert-check-calm-on-still-visible.png)/var/folders/j0/w34lmlf93rdgx6qhg4t5m2mh0000gn/T/no-mistakes-evidence/01M0TRDVG7AKVP3MQT85VYEBS0/06-calm-on-export-html-still-complete.png)Evidence: Behavior portable serial 4 — root-cause diagnosis, no-weakening proof, and local pass transcript
Evidence: Revert check transcript — the four behavioral failures produced by disabling the collapse fix
Evidence: Focused Calm suite on the target commit
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
.pi/extensions/lib/fm-calm-assistant-layout.ts:51- The collapsed-thinking adapter is screen-only like the two adapters this change moved to calmScreenPresentationHides (Pi builds /export and /share HTML from session entries in dist/core/export-html/template.js, never from AssistantMessageComponent), but it still reads calmPresentationHides, which honors the stock-export escape hatch. Failing sequence: Calm on, agent streaming; captain submits/export out.html(Pi's editor accepts input during a run) -> fm-calm.ts:437 opens the window and the reset is only a setTimeout(0) macrotask -> a message_update already queued in the same poll phase calls updateContent, hidesThinking()/hidesWorkingNote() return false, and the component keeps the thinking block and mid-turn narration. When the window closes, repaintCalmToolRows() + setStatus() request a render but never re-run updateContent, so the un-hidden thinking/working-note text stays on screen until the next streaming update or a /calm toggle. Same invariant and same one-line fix the sibling adapters got: use calmScreenPresentationHides for lines 51-52. Note this was pre-existing, not introduced here - flagged because the change explicitly established the screen-only rule and updated only two of the three render-time adapters..pi/extensions/fm-calm.ts:434- Root-cause confirmation for the intent's 'Behavior portable serial 4' requirement. The failure in CI run 31427933014 was tests/fm-remote-job-orphan-reap.test.sh -> 'not ok - the serving child ignored TERM' (family=secondmate), unrelated to Calm: the fixture TERMed the recorded serving child after removing the state root, which the worker's graceful handler refuses. The real fix (fixture now useskill -KILLand adds a wait_worker poll for the supervisor's exec-chain race) is already present in the post-sync base 08b9e81 and is inherited verbatim -git diff 08b9e81 9efca48 -- tests/fm-remote-job-orphan-reap.test.sh bin/fm-remote-job-lib.sh bin/fm-remote-job-worker.shis empty - so the regression is neither weakened, narrowed, nor skipped. Separately, the branch's own b3e1f0a change (return;->return undefined;here and at lines 442/464) is a semantic no-op: pi-tui's handleTerminalInput doesconst result = listener(current); if (result?.consume) return;, so an implicit and an explicit undefined are indistinguishable. It is harmless and slightly clearer given TerminalInputHandler's declared return type, but it is not the fix for that CI failure.docs/calm-mode-feasibility.md:246- The '2026-08-10 SuperCalm Pi 0.84.1 verification' block presents$ tests/fm-calm-pi-extension.test.shoutput verbatim, but it was recorded against the pre-merge tree (12 tests). The origin/main merge added test_calm_mid_turn_working_notes, so the merged suite now emits 13 ok lines and the pasted block silently omits 'ok - Pi calm on collapses mid-turn assistant working notes to zero height...'. The pre-existing verification record at line 512 in this same doc does include that line, so the convention is a complete transcript. Re-record the block against the merged tree (or date-scope it explicitly) so the evidence record matches what the suite actually prints.tests/fm-calm-pi-extension.test.sh:950- Merge artifact: the operationalMode fixture object declares getMarkdownTransformers twice (line 948 from upstream, line 950 added by this branch), with the second silently shadowing the first. Both currently return [] so behavior is unchanged, but if either is ever adjusted the earlier one is dead and the divergence is invisible. Remove the duplicate at line 950.tests/fm-calm-pi-extension.test.sh:41- wait_for_text gained a thirdlimit=${3:-120}parameter in b235322 for a singlewait_for_text ... 600call site, but 39321c6 reverted that call back to the two-argument form. No caller now passes a third argument, so the parameter and the$limitloop bound are dead configurability. Either drop it back to the fixed 120 bound or give the long /export wait its explicit limit again.🔧 Fix: fix(pi): make Calm assistant layout screen-only across export window
3 infos still open:
docs/calm-mode-feasibility.md:240- The newly written rationale is factually wrong about entry renderers, and the corresponding code is the one remaining screen-only renderer that still reads the export hatch. Line 238 lists "entry renderers" as an input Pi builds /export and /share output from, and line 240 states "The tool-definition wrappers and the synthetic entry renderer still honor it, so exported and shared artifacts keep their complete content." Pi never calls a registered entry renderer during export: getEntryRenderer has exactly one call site, dist/modes/interactive/components/../interactive-mode.js:2839 (the on-screen transcript), and AgentSession.exportToHtml (dist/core/agent-session.js:2593) hands exportSessionToHtml only a createToolHtmlRenderer plus the session entries; custom entries reach the HTML through template.js:1311's generic customType block. So registerFirstmateSyntheticPresentation's calmPresentationHides("synthetic-user") at .pi/extensions/lib/fm-calm-visibility.ts:102 contributes nothing to exported or shared content - it is the same screen-only-adapter-honoring-an-export-hatch shape the fix round just corrected in the assistant layout. I could not construct a practical failing sequence: CustomEntryComponent only re-runs the renderer from its constructor, setExpanded (Ctrl+O), or invalidate(), and the only whole-transcript invalidate paths (theme-file change, consumeCellSizeResponse, TUI mode switch) are not reachable inside the sub-tick setTimeout(0) export window, so this is a dead hatch plus an incorrect evidence claim rather than a live stale-row bug. Recommend either correcting lines 238/240 to say entry renderers are screen-only and the hatch there is inert, or moving line 102 to calmScreenPresentationHides so all four Calm renderers state the same rule.docs/calm-mode-feasibility.md:16- The fix round re-recorded the verification block against Pi 0.84.2 (heading at line 232,$ pi --versionoutput 0.84.2, matching the installed package) but left every evidence list capped at 0.84.1: line 16 ("Pi 0.84.1 was the SuperCalm tool-row target"), the cross-harness table row at line 291 ("Pi (verified 0.81.1 through 0.84.1)"), the test-file banner at tests/fm-calm-pi-extension.test.sh:21, and the header comments in .pi/extensions/fm-calm.ts:4, fm-calm-assistant-layout.ts:1, fm-calm-operational-user-layout.ts:1, and fm-calm-tool-row-layout.ts:1. Since this doc explicitly treats those lists as accumulated verification evidence rather than support ceilings, a reader consulting the compatibility table will not learn 0.84.2 was verified even though the record immediately below says the whole focused suite passed there. Either add 0.84.2 to the evidence lists or scope the new block's title to say it re-records the 0.84.1 revision on a newer CLI.tests/fm-calm-pi-extension.test.sh:1559- ThesettledAssistantRendercheck added by the fix round cannot fail independently of the in-window check at line 1502. Between the two renders nothing re-runs updateContent on exportWindowAssistantRow: repaintCalmToolRows() invalidates only ToolExecutionComponent instances registered in calmToolRowRepaints, and the fixture's setStatus only records the call. AssistantMessageComponent.render is a pure re-render of an unchanged child container, so line 1559 is guaranteed to equal line 1502's result. It reads as a second, independent guard on the reset repaint but adds no coverage; the real regression evidence is line 1502 alone (which does fail when the adapter is reverted to calmPresentationHides). Harmless as executable documentation of the invariant - noting it so the fix round's coverage claim is not read as stronger than it is.🔧 Fix: docs(pi): correct entry-renderer export claim, record Pi 0.84.2
1 info still open:
.pi/extensions/lib/fm-calm-visibility.ts:90- The round-2 fix corrected docs/calm-mode-feasibility.md to state that registered entry renderers are screen-only and that the synthetic-entry-renderer export hatch is inert, but three source header comments still carry the superseded claim. fm-calm-visibility.ts:90-91 says the stock-export hatch exists because "Pi builds that output from tool definitions and entry renderers", and fm-calm-assistant-layout.ts:13 and fm-calm-operational-user-layout.ts:10 both say the hatch is what "the tool-definition wrappers and the synthetic entry renderer need". Verified against the installed Pi 0.84.2: getEntryRenderer has one call site (the on-screen transcript in interactive-mode.js) and AgentSession.exportToHtml hands the exporter only createToolHtmlRenderer plus session entries, so the entry renderer contributes nothing to /export or /share and does not "need" the hatch. No behavior is affected - calmPresentationHides at line 102 is inert either way, which is exactly why the doc-only option was chosen. Flagged only because this repo treats these headers as version-scoped evidence records, so a reader consulting the source now gets the claim the doc just retired. The user explicitly scoped the round-2 fix to docs/calm-mode-feasibility.md and directed that fm-calm-visibility.ts be left unchanged, so no action is required here.tests/fm-pi-primary-types.test.sh:8- tests/fm-pi-primary-types.test.sh self-skips locally with "skip: tsc not found for Pi extension typecheck", so the one changed line in that file (copying lib/fm-calm-tool-row-layout.ts into the typecheck fixture) is not exercised here. Installing TypeScript is outside this worktree's allowed writes; the Repo invariants / typecheck job in CI owns this.bash tests/fm-calm-pi-extension.test.sh— all 13 tests pass against real Pi 0.84.2 components, a real Pi TUI in tmux, and a real /export rendered through headless Chromebash tests/fm-remote-job-orphan-reap.test.sh— the actual script that failed in "Behavior portable serial 4"; 7/7 assertions pass on the target commitbash tests/fm-pi-watch-extension.test.sh— upstream Pi watch extension preserved through the origin/main merge; passesbash tests/fm-pi-primary-types.test.sh— self-skipped locally (no tsc on PATH)gh-axi run view 31427933014 --job 93583994670 --log-failed— retrieved the original portable-serial-4 CI failure and isolated it tonot ok - the serving child ignored TERMgit diff 48358db^..HEAD -- tests/fm-remote-job-orphan-reap.test.shplus pass/fail-guard counts — confirmed the regression was corrected in fixture shape (TERM -> KILL) without weakening, narrowing, or skippingManual TUI lab: realpi --sessionin tmux with a third-party extension registering an MCP-style self-shell tool (linear_list_issues) and a default-shell tool (acme_deploy_status), plus an unregistered provider tool (mcp__github__search_issues) and built-inbash— captured Calm off, /calm on, Calm on + Ctrl+O, and /calm off restoredManual/exportfrom that lab with Calm ON, then rendered the exported HTML in headless Chrome and parsed the base64 session payload — every tool call, result and definition still presentRevert-check A: removedinstallCalmPresentationAdapter("custom-tool-row", ...)from .pi/extensions/fm-calm.ts and re-ran the focused suite — EXIT=1Revert-check B: forcedhidesToolRowto return false in .pi/extensions/lib/fm-calm-tool-row-layout.ts and re-ran the suite four times with earlier tests skipped —test_tool_row_image_state_probe,test_calm_activation_collision_and_regression_bound,test_rendering_and_session_lifecycleandtest_interactive_terminal_e2eeach fail; both reverts restored andgit statusverified cleandocs/calm-mode-feasibility.md:265- The newest verification record (2026-08-24 SuperCalm Pi 0.84.2) recordstests/fm-pi-primary-types.test.shasskip: tsc not found for Pi extension typecheck, so no recorded strict-typecheck evidence covers the newfm-calm-tool-row-layout.tsadapter or the widened adapter signatures; the only passing typecheck output in the document is the 2026-08-15 record against Pi 0.80.10, from before this adapter existed. The prose claim that the test performs strict no-emit checking is accurate, so this is an evidence gap rather than stale prose, and closing it needs a run with tsc available, which belongs to a validation phase rather than this one.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.