Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: recognize Pi's `[paste #N +M lines]` chip so pi-TUI agents submit their prompt

Adam Eivy415eca04d3c2
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.js
index d3fb4c80af..85d5ecb26d 100644
--- a/server/lib/tuiHandshake.js
+++ b/server/lib/tuiHandshake.js
@@ -35,8 +35,9 @@ export const PASTE_DEADLINE_MS = 10000;
export const TUI_INPUT_READY_DEADLINE_MS = 45000;
// Claude Code emits `[Pasted text #N +M lines]`, Codex emits
-// `[Pasted Content N chars]`, OpenCode emits `[Pasted ~N lines]`, and
-// Grok Build emits `[Pasted: 31 KB]` after
+// `[Pasted Content N chars]`, OpenCode emits `[Pasted ~N lines]`, Pi emits
+// `[paste #N +M lines]` (note: "paste", not "Pasted" — hence the optional `d`),
+// and Grok Build emits `[Pasted: 31 KB]` after
// committing a paste. Watch for any of these markers (or fall back after
// PASTE_TO_ENTER_FALLBACK_MS) before sending `\r` so Enter doesn't get
// swallowed mid-paste-commit.
@@ -53,6 +54,14 @@ export const TUI_INPUT_READY_DEADLINE_MS = 45000;
// was the root cause of issue #1229: across a month of real transcripts the
// marker "never appeared" only because the matcher ran against the raw stream;
// the fast path was effectively dead and every run fell back to the blind timer.
+//
+// Pi's marker is ALSO the only evidence a pi paste landed: like Claude Code, pi
+// COLLAPSES a multi-line bracketed paste into the chip and hides the body, so
+// the verifyPasteRendered text fallback can never see the prompt. Before pi's
+// `[paste #N +M lines]` form was in the alternation above, every pi-TUI CoS
+// agent burned all 3 paste attempts and died `paste-not-rendered` with three
+// chips (`[paste #1][paste #2][paste #3]`) sitting unsent in the composer and
+// Enter never sent — the prompt was delivered perfectly all three times.
export const PASTE_MARKER_POLL_MS = 150;
// Paste verification: after paste-commit (marker or fallback), verify the prompt
@@ -65,7 +74,7 @@ export const PASTE_RETRY_MAX_ATTEMPTS = 3;
export const PASTE_RETRY_BASE_DELAY_MS = 800;
// Minimum prefix length for verification (shorter prompts verify whole-text)
const MIN_VERIFIABLE_PREFIX_LEN = 15;
-export const PASTE_MARKER_PATTERN = /\[Pasted\s*(?:text\s*#\d+[^\]]*|content\s*\d+\s*chars|~\s*\d+\s*lines?|:\s*\d+(?:\.\d+)?\s*(?:B|KB|MB))\]/i;
+export const PASTE_MARKER_PATTERN = /\[Pasted?\s*(?:text\s*#\d+[^\]]*|content\s*\d+\s*chars|~\s*\d+\s*lines?|#\d+\s*\+\d+\s*lines?|:\s*\d+(?:\.\d+)?\s*(?:B|KB|MB))\]/i;
export const PASTE_TO_ENTER_MIN_DELAY_MS = 200;
export const PASTE_TO_ENTER_FALLBACK_MS = 3500;
diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.js
index 3e3a7a37ad..f82f55d40c 100644
--- a/server/lib/tuiHandshake.test.js
+++ b/server/lib/tuiHandshake.test.js
@@ -108,6 +108,35 @@ describe('tuiHandshake — paste timing constants', () => {
expect(PASTE_MARKER_PATTERN.test('[Pasted ~46 chars]')).toBe(false);
});
+ it('PASTE_MARKER_PATTERN matches Pi paste-commit chips', () => {
+ // Pi spells the chip `[paste #N +M lines]` — lowercase and WITHOUT the
+ // trailing `d` every other TUI uses, and with no `text` token. Real
+ // incident (2026-09-17): a pi-TUI CoS agent pasted its prompt 3 times and
+ // died `paste-not-rendered` with `[paste #1 +371 lines][paste #2 +371
+ // lines][paste #3 +371 lines]` visible in the composer and Enter never
+ // sent. Pi collapses the paste and HIDES the body, so the marker is the
+ // ONLY confirmation signal available — without it the text fallback in
+ // verifyPasteRendered can never succeed either.
+ expect(PASTE_MARKER_PATTERN.test('[paste #1 +371 lines]')).toBe(true);
+ expect(PASTE_MARKER_PATTERN.test('[paste #3 +1 line]')).toBe(true);
+ // Space-collapsed form left behind by the ANSI stripper.
+ expect(PASTE_MARKER_PATTERN.test('[paste#1+371lines]')).toBe(true);
+ // Each re-paste adds its own chip, so the count is what distinguishes the
+ // TUI's own commit from a marker echoed out of the prompt.
+ expect(countPasteMarkers('[paste #1 +371 lines][paste #2 +371 lines]')).toBe(2);
+ });
+
+ it('a pi paste confirms on the marker alone, with the body hidden', () => {
+ // The whole point of the marker path: pi's chip REPLACES the prompt text in
+ // the buffer, so a prefix that is genuinely absent must still confirm.
+ const prompt = 'x'.repeat(40) + ' ship up to 6 independent issues in parallel';
+ const verifiablePrefix = extractVerifiablePromptPrefix(prompt);
+ expect(verifiablePrefix).toBeTruthy();
+ const buffer = '[Skills] find-skills, hyperframes\n[paste #1 +371 lines]';
+ expect(verifyPasteRendered(buffer, verifiablePrefix)).toBe(false);
+ expect(isPasteConfirmed(buffer, { verifiablePrefix, promptMarkerCount: 0 })).toBe(true);
+ });
+
it('PASTE_MARKER_PATTERN matches the SPACE-COLLAPSED form left after ANSI strip', () => {
// The raw PTY stream renders the marker with absolute-column cursor moves
// between tokens (`[Pasted\x1b[11Gtext\x1b[16G#1…`), so once ANSI is stripped
@@ -134,6 +163,9 @@ describe('tuiHandshake — paste timing constants', () => {
it('PASTE_MARKER_PATTERN does NOT match similar-looking but distinct text', () => {
expect(PASTE_MARKER_PATTERN.test('[Pasted text]')).toBe(false);
expect(PASTE_MARKER_PATTERN.test('[Pasted #1]')).toBe(false);
+ // Pi's `#N` branch requires the `+M lines` tail, so a bare chip stays out.
+ expect(PASTE_MARKER_PATTERN.test('[paste #1]')).toBe(false);
+ expect(PASTE_MARKER_PATTERN.test('[paste #1 +371 chars]')).toBe(false);
expect(PASTE_MARKER_PATTERN.test('Pasted text #1')).toBe(false);
expect(PASTE_MARKER_PATTERN.test('')).toBe(false);
});