Skip to content

Commit 36e5723

Browse files
committed
fix: render settled-diff refs paste-ready in CLI output
A settled diff activates a PARTIAL ref frame (ADR 0014), which admits only the pinned `@eN~s<gen>` form of the refs it issued. The unchanged-interactive tail already rendered that way, but the diff's own added lines rendered the bare `@eN` embedded in the snapshot line — so a CLI caller who copied the ref the diff just handed them got `plain_ref_requires_complete_frame` and had to append the generation by hand. Added lines now render pinned when the response carries `refsGeneration`, exactly like the tail. Removed lines render verbatim: they name elements that just left the screen, and `SettleDiffLine` never gives them a ref. This is not new to scroll/back — press/click/fill/longpress had the same gap since #1101. MCP was never affected: its ref-pin store rewrites plain refs on the way in, which is why the model never sees a suffix. Live: `scroll down --settle` now emits `+ @E14~s218078 [cell] "Game Center"`, and `press @E14~s218078` copied straight out of that line taps successfully.
1 parent 275e965 commit 36e5723

3 files changed

Lines changed: 70 additions & 4 deletions

File tree

‎src/commands/interaction/output.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,40 @@ describe('press CLI output', () => {
109109
);
110110
});
111111

112+
// ADR 0014: a settled diff activates a PARTIAL frame, so only the pinned form
113+
// of the refs it issued is admitted. The diff has to hand the CLI caller that
114+
// form directly or a copied `@e9` bounces with plain_ref_requires_complete_frame.
115+
test('renders added-line refs pinned at the settle generation', () => {
116+
const output = formatPress({
117+
message: 'Tapped (278, 817)',
118+
x: 278,
119+
y: 817,
120+
settle: {
121+
settled: true,
122+
waitedMs: 1200,
123+
refsGeneration: 41,
124+
diff: {
125+
summary: { additions: 1, removals: 1, unchanged: 8 },
126+
lines: [
127+
{ kind: 'removed', text: '@e4 [button] "Search"' },
128+
{ kind: 'added', text: '@e9 [text] "Notifications"', ref: 'e9' },
129+
],
130+
},
131+
},
132+
});
133+
134+
expect(output.text).toBe(
135+
[
136+
'Tapped (278, 817)',
137+
'settled after 1200ms: +1 -1 (~8 unchanged)',
138+
// A removed line names an element that just left: rendered verbatim,
139+
// never as a paste-ready target.
140+
'- @e4 [button] "Search"',
141+
'+ @e9~s41 [text] "Notifications"',
142+
].join('\n'),
143+
);
144+
});
145+
112146
test('prints the response warning after the tap line', () => {
113147
const output = formatPress({
114148
message: 'Tapped (278, 817)',

‎src/commands/settle-output.ts‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type SettleTextView = {
2222
hint?: string;
2323
diff?: {
2424
summary?: { additions?: number; removals?: number; unchanged?: number };
25-
lines?: Array<{ kind?: string; text?: string }>;
25+
lines?: Array<{ kind?: string; text?: string; ref?: string }>;
2626
truncated?: boolean;
2727
};
2828
tail?: Array<{ ref?: string; role?: string; label?: string }>;
@@ -51,21 +51,42 @@ function formatSettleText(settle: unknown): string {
5151
const view = settle as SettleTextView;
5252
const parts = [
5353
formatSettleVerdict(view),
54-
...formatSettleDiffLines(view.diff),
54+
...formatSettleDiffLines(view),
5555
...formatSettleTailLines(view),
5656
];
5757
if (view.hint) parts.push(`hint: ${view.hint}`);
5858
return `\n${parts.join('\n')}`;
5959
}
6060

61-
function formatSettleDiffLines(diff: SettleTextView['diff']): string[] {
61+
function formatSettleDiffLines(view: SettleTextView): string[] {
62+
const diff = view.diff;
6263
const lines = (diff?.lines ?? []).map(
63-
(line) => `${line.kind === 'removed' ? '-' : '+'} ${line.text ?? ''}`,
64+
(line) =>
65+
`${line.kind === 'removed' ? '-' : '+'} ${pinnedDiffLineText(line, view.refsGeneration)}`,
6466
);
6567
if (diff?.truncated) lines.push('… changed lines truncated');
6668
return lines;
6769
}
6870

71+
/**
72+
* ADR 0014: a settled diff publishes a PARTIAL frame, which admits only the
73+
* pinned form of the refs it issued — so a CLI caller who copies a bare `@eN`
74+
* out of the diff gets `plain_ref_requires_complete_frame`. Render the added
75+
* line's ref in the same paste-ready `@eN~s<gen>` form the tail already uses.
76+
* Only added lines carry a ref (`SettleDiffLine`); removed lines render
77+
* verbatim, since nothing there is a target.
78+
*/
79+
function pinnedDiffLineText(
80+
line: { text?: string; ref?: string },
81+
refsGeneration: number | undefined,
82+
): string {
83+
const text = line.text ?? '';
84+
const pinned = pinnedRefText(line.ref, refsGeneration);
85+
if (!pinned || !line.ref) return text;
86+
const plain = `@${line.ref}`;
87+
return text.startsWith(`${plain} `) ? `${pinned}${text.slice(plain.length)}` : text;
88+
}
89+
6990
// Unchanged interactive tail: only present when the diff's added lines
7091
// carried zero refs (modal-dismiss/toast-only diff), so the settled tree's
7192
// remaining actionable elements would otherwise be invisible.

‎src/daemon/__tests__/generic-settle.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ test('scroll --settle answers with the settled diff against the stored pre-actio
201201
text: expect.stringContaining('Load more'),
202202
ref: 'e2',
203203
});
204+
// `SettleDiffLine`: removed lines never carry a ref — their refs would name
205+
// nodes of the REPLACED tree, and ref bodies are index-derived, so `@e2` on a
206+
// removed line is a different element in the settled tree that took its slot.
207+
// Enforced in snapshot-diff (removed lines are built without one); asserted
208+
// here because this route is the one that diffs against the STORED session
209+
// snapshot, whose nodes all carry refs, so it is where a regression would
210+
// first publish one.
211+
const removed = settle.diff?.lines.find((line) => line.kind === 'removed');
212+
expect(removed?.text).toContain('Continue');
213+
expect(removed?.ref).toBeUndefined();
214+
204215
// The settled tree became the stored snapshot, and its refs were published:
205216
// a partial frame is active at the generation the payload reports.
206217
const stored = sessionStore.get(sessionName) as SessionState;

0 commit comments

Comments
 (0)