Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3336377
fix(agent): fold large unchanged subtrees in the full-screen fallback…
Varshith-Kali Nov 14, 2026
6b2865e
fix(changeset): restore missing opening frontmatter delimiter
Varshith-Kali Nov 14, 2026
a6990a9
fix(agent): name the last full listing in fold lines and keep it thro…
Varshith-Kali Nov 14, 2026
4fb2a17
fix(plugins): sync generated skill reference with fold-line wording
Varshith-Kali Nov 14, 2026
7c5e70c
fix(agent): clear fold records on truncated renders and drop the redu…
Varshith-Kali Nov 14, 2026
79be775
test(agent): make the kept-screens budget test discriminate
Varshith-Kali Nov 14, 2026
a6fbf18
fix(agent): clear fold records on overflow shrink and cover the text-…
Varshith-Kali Nov 15, 2026
20a860c
fix(agent): share one screen presenter per step and forget its folds …
Varshith-Kali Nov 15, 2026
6d48f0e
docs(agent): correct the screen option doc to name the shared presenter
Varshith-Kali Nov 15, 2026
156776b
fix(agent): bind a fresh screen presenter per loop run
Varshith-Kali Nov 15, 2026
329fd66
fix(agent): restore the previous screen presenter when a loop run ends
Varshith-Kali Nov 15, 2026
73b5e12
fix(agent): stack screen presenters per loop run so concurrent runs l…
Varshith-Kali Nov 16, 2026
eff1cbc
fix(agent): clear every presenter fold record on overflow shrink
Varshith-Kali Nov 16, 2026
b1db895
docs(executors): correct the overflow-shrink presenter note
Varshith-Kali Nov 16, 2026
7fde9d2
docs(executors): drop the presenter and fold detail from the overflow…
Varshith-Kali Nov 16, 2026
47eddde
docs(executors): point the grammar-tools line at the example below
Varshith-Kali Nov 17, 2026
22f6d4a
fix(agent): fold unchanged subtrees only in MCP sessions
Varshith-Kali Nov 18, 2026
fcc2c2e
fix(agent): scope folded-subtree text to MCP sessions
Varshith-Kali Nov 18, 2026
29f195c
fix(agent): drop the loop-only folding support, keep MCP-only folding
Varshith-Kali Nov 18, 2026
e79c102
test(mcp): fold check runs through a session the host opened
Varshith-Kali Nov 18, 2026
9d9996f
fix(agent): address review on MCP subtree folding
Varshith-Kali Nov 20, 2026
7a7e54a
fix(agent): fold unchanged subtrees in attached MCP sessions
Varshith-Kali Nov 21, 2026
89b47b5
docs(agent): restore complete_step same-turn rule in agent skill
Varshith-Kali Nov 21, 2026
7ccb069
test(mcp): list the first screen with observe in the session fold check
Varshith-Kali Nov 27, 2026
8f0b0bb
fix(agent): address review on folding docs and unlisted coverage
Varshith-Kali Nov 27, 2026
89fb1d3
test(mcp): share the orders session setup between the fold tests
Varshith-Kali Nov 27, 2026
cf64cb0
docs(agent): address review nits on fold wording and wrapping
Varshith-Kali Nov 27, 2026
725af6f
Merge remote-tracking branch 'origin/main' into fix-1788-mcp-fold-unc…
Varshith-Kali Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/mcp-fold-unchanged-subtrees.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
"e2e": patch
Comment thread
Varshith-Kali marked this conversation as resolved.
Resolved
"@e2e-dev/core": patch
---

In MCP sessions (`e2e mcp`), when an action changes most of the screen, large subtrees that did not change are shown as one line instead of being repeated.
13 changes: 9 additions & 4 deletions docs/reference/agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,15 @@ For `vision` and `screenshot` there, see the Note under
The built-in agent offers one tool per verb the target's engine declares, and
none for a verb it does not. A tool that targets a node takes its id from the
newest observation. Every tool returns what changed on screen and is
recorded for the [replay cache](/cache), with its node when it has one. On an engine that declares
`tapModifiers`, `tap`, `double_tap`, and `right_click` take `modifiers`
(`Shift`, `Control`, `Alt`, `Meta`, `ControlOrMeta`) to hold keys for the
click, as a Shift-click extends a selection.
recorded for the [replay cache](/cache), with its node when it has one. When
most of the screen changed, the result sends the whole new screen instead. By
default it lists every node in full; in MCP sessions, large subtrees that
match an earlier listing are folded to one line each, naming how many nodes
each holds and the revision it matches (`same as revision b1`). On an
engine that declares `tapModifiers`, `tap`, `double_tap`, and
`right_click` take `modifiers` (`Shift`, `Control`, `Alt`, `Meta`,
`ControlOrMeta`) to hold keys for the click, as a Shift-click extends a
selection.

| Tool | Engine action | What it does |
| --- | --- | --- |
Expand Down
6 changes: 5 additions & 1 deletion docs/reference/mcp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ current path and revision. Takes no arguments.
`select`, `check`, `scroll`, `scroll_to`, `drag`, `upload`, `navigate`,
`back`, `resize_viewport`, `switch_tab`, `close_tab`, `type_secret`. Each returns the action's summary, the
[test line](#test_lines) that repeats it or why there is none, and what
changed on screen.
changed on screen. When most of the screen changed, the result sends the
whole new screen instead; complete listings fold large subtrees that match
an earlier listing to one line each, naming how many nodes each holds and
the revision it matches (`same as revision b1`); the ids inside a folded
subtree stay valid, and `observe` returns the whole tree again.

| Input | Does |
| --- | --- |
Expand Down
330 changes: 315 additions & 15 deletions packages/core/src/agent/screen-update.ts

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions packages/e2e/src/mcp/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { z } from 'zod';
import { loadAiSdkIfInstalled } from '@e2e-dev/core/lib/agent/ai-sdk';
import { openInteractiveStep, type InteractiveStep } from '../agent/interactive-step.ts';
import { ScreenPresenter } from '@e2e-dev/core/lib/agent/screen-update';
import type { ScreenPresenter } from '@e2e-dev/core/lib/agent/screen-update';
import type { ResolvedConfig, ResolvedTarget } from '@e2e-dev/core/lib/config/resolve';
import { launchesPinnedApp } from '@e2e-dev/core/lib/config/targets';
import { classifyError, ConfigurationError, errorMessage, InfrastructureError, serializeError, type SerializedError } from '@e2e-dev/core/lib/internal/errors';
Expand All @@ -33,6 +33,7 @@ import type { ResolvedRunConfig } from '../config/resolve-run.ts';
import type { StandaloneAttempt } from '@e2e-dev/core/lib/run/standalone-attempt';
import { selectStandaloneTest, testLocation } from '../run/standalone-test.ts';
import { createSessionCatalog, isGrammarVerb, type SessionCatalog } from '../session-tools/catalog.ts';
import { createSessionScreenPresenter } from '../session-tools/screen.ts';
import { sessionFills, sessionSecretLines, sessionSecretParams } from '../session-tools/secrets.ts';
import { appLines } from './app-lines.ts';
import { SESSION_BOUNDS } from '../session-tools/bounds.ts';
Expand Down Expand Up @@ -516,7 +517,7 @@ export class SessionHost {
...(params === undefined ? {} : { params }),
timeout: ttlMs,
});
const screen = new ScreenPresenter();
const screen = createSessionScreenPresenter();
const recorder = this.recorder(id, config, attempt);
const catalog = createSessionCatalog({
context: step.context,
Expand Down Expand Up @@ -702,7 +703,7 @@ export class SessionHost {
lines.push(`- ${toolSignature('run_code', runCode)}: JavaScript with loops, variables, and return values. Use it for most of the work: one call that reads, computes, acts, and asserts, in place of many single actions. A read's value shows in the result unless the code returns or logs. Its API:`, ...runCodeApi({ attempt: () => live.attempt, engineFixtures: Object.keys(live.target.engine?.fixtures ?? {}) }).map((line) => ` ${line}`));
}
lines.push(
'Node ids ("n42") come from the newest observation; an older id works only when exactly one node on the newest screen reads like its node. Every action prints the test line that repeats it. Call close_session when you are done.',
'Node ids ("n42") come from the newest observation; an older id works only when exactly one node on the newest screen reads like its node. Every action prints the test line that repeats it. When most of the screen changed, an action result sends the whole screen instead, with large subtrees that match an earlier listing folded to one line each, naming how many nodes each holds and the revision it matches; the ids inside a folded subtree stay valid, and observe shows the whole tree again. Call close_session when you are done.',
READ_WRITING_GUIDE,
);
return `${lines.join('\n')}\n\n${screen}`;
Expand Down
5 changes: 3 additions & 2 deletions packages/e2e/src/run/worker/held-test-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { StepExecutorContext } from '@e2e-dev/core/lib/agent/executor';
import type { AgentContext } from '@e2e-dev/core/lib/agent/invocation';
import { OperationQueue } from '@e2e-dev/core/lib/agent/operation-queue';
import { executorRedactors } from '@e2e-dev/core/lib/agent/redaction';
import { ScreenPresenter } from '@e2e-dev/core/lib/agent/screen-update';
import type { ScreenPresenter } from '@e2e-dev/core/lib/agent/screen-update';
import { createStepExecution } from '@e2e-dev/core/lib/agent/step-execution';
import type { ResolvedTarget } from '@e2e-dev/core/lib/config/resolve';
import { classifyError, ConfigurationError, errorMessage, InfrastructureError } from '@e2e-dev/core/lib/internal/errors';
Expand All @@ -21,6 +21,7 @@ import { sessionRecordings } from '@e2e-dev/core/lib/run/recordings';
import { StepRecorder } from '@e2e-dev/core/lib/run/steps';
import type { SessionCatalog } from '../../session-tools/catalog.ts';
import type { SessionRecorder } from '../../session-tools/recording.ts';
import { createSessionScreenPresenter } from '../../session-tools/screen.ts';
import { actionResult, catalogLine, describeToolDetail, errorResult, firstScreenLine, invokeTool, redactResult, unavailableSessionTool } from '../../session-tools/tools.ts';
import { sessionFills, sessionSecretLines, sessionSecretParams } from '../../session-tools/secrets.ts';
import { heldTestToolCallScope } from './held-test-tool-scope.ts';
Expand Down Expand Up @@ -152,7 +153,7 @@ export class HeldTestTools {
const { attempt, redact, target } = this.options.runtime;
const controller = new AbortController();
const signal = AbortSignal.any([controller.signal, attempt.signal]);
const screen = new ScreenPresenter();
const screen = createSessionScreenPresenter();

const attachment: Attachment = {
id: requestId,
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/src/session-tools/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ async function saveScreenshot(
function fullObserveTool(context: Pick<StepExecutorContext, 'observe'>, screen: Pick<ScreenPresenter, 'initial'>): ToolSet[string] {
return {
description:
'Look at the whole current screen: every node with its id, role, name, and state. Action results report only what changed since the last screen; call this to list everything, or after waiting for something in progress.',
'Look at the whole current screen: every node with its id, role, name, and state. Action results report only what changed since the last screen; call this to list everything, including any subtree an action result folded to one line, or after waiting for something in progress.',
inputSchema: z.object({}).strict(),
execute: async () => screen.initial(await context.observe()),
};
Expand Down
11 changes: 11 additions & 0 deletions packages/e2e/src/session-tools/screen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ScreenPresenter } from '@e2e-dev/core/lib/agent/screen-update';

/**
* A session screen presenter, with folding on. Both session kinds share it:
* the standalone session and the session attached to a held test. Each has
* a whole-tree `observe` to read a folded subtree back, so a persistent
* sidebar is not repeated on every page transition.
*/
export function createSessionScreenPresenter(): ScreenPresenter {
return new ScreenPresenter({ foldUnchangedSubtrees: true });
}
75 changes: 75 additions & 0 deletions packages/e2e/tests/integration/mcp-step-attachment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,54 @@ const projects: FixtureProject[] = [];
const runs: ReturnType<typeof spawn>[] = [];
const clients: Client[] = [];

/** A project whose screen is a 12-link sidebar beside a main that swaps on tap, for the fold check. */
const FOLD_CONFIG = `import { createFakeEngine, FAKE_APP } from '../../helpers/fake-engine.ts';

const { engine } = createFakeEngine({
scene: () => {
const main = {
id: 'main', role: 'main', name: 'Order list',
children: [
{
id: 'order1', role: 'button', name: 'Order 1',
on(action) {
if (action.kind !== 'tap') return;
main.name = 'Order details';
main.children = [
{ id: 'order42', role: 'heading', name: 'Order 42' },
{ id: 'total', role: 'text', name: 'Total $12' },
{ id: 'placed', role: 'text', name: 'Placed yesterday' },
{ id: 'address', role: 'text', name: 'Ship to 12 Main Street' },
{ id: 'method', role: 'text', name: 'Standard delivery' },
{ id: 'refund', role: 'button', name: 'Refund' },
{ id: 'ship', role: 'button', name: 'Ship' },
{ id: 'invoice', role: 'button', name: 'Invoice' },
{ id: 'receipt', role: 'text', name: 'Email receipt sent' },
{ id: 'phone', role: 'text', name: 'Phone 555 0100' },
{ id: 'gift', role: 'text', name: 'Gift message included' },
{ id: 'tracking', role: 'text', name: 'Tracking 1Z999' },
];
},
},
{ id: 'order2', role: 'button', name: 'Order 2' },
],
};
return [
{
id: 'sidebar', role: 'navigation', name: 'Sidebar',
children: Array.from({ length: 12 }, (_, i) => ({ id: 'item' + (i + 1), role: 'link', name: 'Item ' + (i + 1) })),
},
main,
];
},
});

export default {
targets: [{ name: 'fake', platform: 'fake', engine, app: FAKE_APP }],
workers: 1,
};
`;

/** Writes a test that opens its app before the given statements run. */
function project(body: string, config = CONFIG): string {
const created = createProject({
Expand Down Expand Up @@ -241,6 +289,33 @@ describe('MCP attachments to held tests', { timeout: 60_000 }, () => {
expect(await held.exited).toBe(0);
});

it('folds the unchanged sidebar in an attached session tap result', async () => {
const dir = project('await screen.pause();', FOLD_CONFIG);
const held = await pause(dir);
const { client } = await mcp(dir);
const opened = await openSession(client, { attach: held.id });
// The opening names the first screen without listing it; observe lists it.
expect(opened.text).toMatch(/Screen: revision \S+, .*not listed\./);
expect(opened.text).not.toContain('Item 1');

const observed = await invoke(client, 'call', { tool: 'observe' });
expect(observed.isError, observed.text).toBe(false);
expect(observed.text).toContain('Item 12');
const target = /^[ \t]*#(\S+) button "Order 1"/m.exec(observed.text)?.[1];

if (target === undefined) {
throw new Error(observed.text);
}

const tapped = await invoke(client, 'call', { tool: 'tap', args: { target } });
expect(tapped.isError, tapped.text).toBe(false);
expect(tapped.text).toContain('Order 42');
expect(tapped.text).toContain('nodes inside, same as revision');
expect(tapped.text).not.toContain('Item 1');
expect(e2e(dir, 'run', '--step', 'next').status).toBe(0);
expect(await held.exited).toBe(0);
});

it('redacts a displayed secret from the screen, tool results, and errors', async () => {
const dir = project(`await app.open('/reset/${PASSWORD}'); await screen.pause();`);
const held = await pause(dir);
Expand Down
Loading
Loading