fix(mcp): keep visible selections when hidden rows are selected
Why
In a long list, three collapsed selected rows can make MCP omit the only visible selected row. The app still reports that row as selected in the full tree.
What
Hidden rows no longer count toward the three-mark limit that protects a visible selection from folding. The final output cap and full screen.tree() output are unchanged. No API change.
How it works
Skip hidden subtrees when counting marks in packages/core/src/agent/screen-fold.ts:126.
Issue
Fixes #2704
Verified
Ran it locally: yes
The Electron reproduction left the control unchanged. The affected view still reported six hidden nodes.
| main | this PR |
|---|---|
| 68 nodes, 18 shown. Message 15 missing. | 68 nodes, 20 shown. Message 15 [selected] in both MCP responses. |
Not run: rendered docs screenshots. The docs checks ran.
Commands and output
At 3535139, pnpm check and all 21 folding unit tests passed again. This follow-up only clarifies the existing output cap. Output below was captured at 03d52ca:
$ cd /tmp/e2e-selection-folding-repro && node probe.mjs
control
MCP observe: Current screen (..., 62 nodes, 20 shown):
#2.1.39 row "Message 15" [selected]
hidden
MCP observe: Current screen (..., 68 nodes, 20 shown):
#2.1.39 row "Message 15" [selected]
… 6 hidden nodes (scrolled out or collapsed)
The probe exited 0 on both checkouts. See #2704 for setup commands. The main probe used c19837e; 1abeb95 adds only Japanese and Simplified Chinese translation updates.
$ npm exec --yes --package=pnpm@12.3.4 -- pnpm check
Found 0 warnings and 0 errors.
e2e plugin: checked 23 generated files
[exit 0]
$ npm exec --yes --package=pnpm@12.3.4 -- pnpm --filter e2e run test:unit
Test Files 268 passed (268)
Tests 5596 passed | 2 skipped (5598)
[exit 0]
$ npm exec --yes --package=pnpm@12.3.4 -- pnpm --filter @e2e-dev/testbed test
Test Files 53 passed (53)
Tests 654 passed | 3 skipped (657)
[exit 0]
An earlier workspace-wide pnpm test did not pass. It ran alongside a rebuild and reported missing build files, an offline MCP install failure, and a CLI cancellation assertion. The isolated package unit run above passed, including that cancellation test.
Checklist
- Changeset added (
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only. - Breaking change: title carries
!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.
Summary by CodeRabbit
- Bug Fixes
- Folded observations now apply the three-node limit to visible focused or selected nodes. Hidden nodes and their descendants no longer affect whether visible marked rows are retained.
- Documentation
- Updated the observation guides to clarify that the final output limits may still omit focused or selected rows from folded results.