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: submit OpenCode TUI pastes with Enter

Adam Eivy481da72408cd
diff --git a/.changelog/next/fixed-agent-d1618386.md b/.changelog/next/fixed-agent-d1618386.md
new file mode 100644
index 0000000000..baef987496
--- /dev/null
+++ b/.changelog/next/fixed-agent-d1618386.md
@@ -0,0 +1 @@
+- OpenCode TUI pastes now submit with Enter instead of being repeated.
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.js
index 33d4574e1f..f31c0721e4 100644
--- a/server/lib/tuiHandshake.js
+++ b/server/lib/tuiHandshake.js
@@ -33,10 +33,11 @@ export const PASTE_DEADLINE_MS = 10000;
// path; the non-claude providers use PASTE_DEADLINE_MS.
export const TUI_INPUT_READY_DEADLINE_MS = 45000;
-// Claude Code emits `[Pasted text #N +M lines]`, while Codex emits
-// `[Pasted Content N chars]`, after committing a paste. Watch for either
-// marker (or fall back after PASTE_TO_ENTER_FALLBACK_MS) before sending `\r`
-// so Enter doesn't get swallowed mid-paste-commit.
+// Claude Code emits `[Pasted text #N +M lines]`, Codex emits
+// `[Pasted Content N chars]`, and OpenCode emits `[Pasted ~N lines]` 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.
//
// CRITICAL: the marker must be matched against ANSI-STRIPPED output, never the
// raw PTY stream. Claude Code renders the marker by positioning each token with
@@ -62,7 +63,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)\]/i;
+export const PASTE_MARKER_PATTERN = /\[Pasted\s*(?:text\s*#\d+[^\]]*|content\s*\d+\s*chars|~\s*\d+\s*lines?)\]/i;
export const PASTE_TO_ENTER_MIN_DELAY_MS = 200;
export const PASTE_TO_ENTER_FALLBACK_MS = 3500;
@@ -124,7 +125,8 @@ export function verifyPasteRendered(strippedBuffer, prefix) {
}
/**
- * Count the `[Pasted text #N …]` paste-commit markers in `strippedText`.
+ * Count paste-commit markers from Claude Code, Codex, or OpenCode in
+ * `strippedText`.
* Callers MUST pass ANSI-STRIPPED output (see PASTE_MARKER_PATTERN above for why
* the raw stream never matches). Shared by both TUI consumers so the
* strip-then-match contract can't drift between them.
@@ -200,12 +202,12 @@ export function isCollapsedPasteChip(strippedText) {
* paste — the gate before sending the submit Enter(s). Two independent signals,
* checked in priority order:
*
- * 1. The TUI's own paste-commit MARKER (`[Pasted text #N]`) count exceeds the
- * count the prompt itself carried (promptMarkerCount). This is AUTHORITATIVE
- * and is checked FIRST because Claude Code collapses a multi-line bracketed
- * paste INTO that chip and HIDES the pasted body text from the buffer — so on
- * every multi-line prompt the literal text is genuinely absent even though
- * the paste landed perfectly. Real incident (2026-07-05): every
+ * 1. The TUI's own paste-commit marker count exceeds the count the prompt
+ * itself carried (promptMarkerCount). This is AUTHORITATIVE and is checked
+ * FIRST because Claude Code collapses a multi-line bracketed paste into a
+ * chip and HIDES the pasted body text from the buffer — so on every
+ * multi-line prompt the literal text is genuinely absent even though the
+ * paste landed perfectly. Real incident (2026-07-05): every
* claude-code-tui CoS agent failed `paste-not-rendered` after 3 retries
* because #2192's text-only check never saw the collapsed body — while the
* marker was sitting right there. (agent-656efa6e et al.)
diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.js
index 24b75094e4..895428d50f 100644
--- a/server/lib/tuiHandshake.test.js
+++ b/server/lib/tuiHandshake.test.js
@@ -101,6 +101,13 @@ describe('tuiHandshake — paste timing constants', () => {
expect(PASTE_MARKER_PATTERN.test('[PastedContent2431chars]')).toBe(true);
});
+ it('PASTE_MARKER_PATTERN matches OpenCode paste-commit chips', () => {
+ expect(PASTE_MARKER_PATTERN.test('[Pasted ~46 lines]')).toBe(true);
+ expect(PASTE_MARKER_PATTERN.test('[Pasted~46lines]')).toBe(true);
+ expect(PASTE_MARKER_PATTERN.test('[Pasted ~1 line]')).toBe(true);
+ expect(PASTE_MARKER_PATTERN.test('[Pasted ~46 chars]')).toBe(false);
+ });
+
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
@@ -1496,6 +1503,12 @@ describe('tuiHandshake.isPasteConfirmed', () => {
expect(isPasteConfirmed(inlineBuffer, { verifiablePrefix: prefix, promptMarkerCount: 0 })).toBe(true);
});
+ it('confirms an OpenCode line-count chip even when the prompt body is hidden', () => {
+ const opencodeBuffer = 'Build · hf.co/example/model Ollama [Pasted ~46 lines]';
+ expect(verifyPasteRendered(opencodeBuffer, prefix)).toBe(false);
+ expect(isPasteConfirmed(opencodeBuffer, { verifiablePrefix: prefix, promptMarkerCount: 0 })).toBe(true);
+ });
+
it('does NOT confirm when neither the marker nor the text appears (paste swallowed by a not-ready TUI)', () => {
const swallowedBuffer = '❯ Try "how does PipelineEditorialChecks.jsx work?" ⏵⏵ bypass permissions on (shift+tab to cycle)';
expect(isPasteConfirmed(swallowedBuffer, { verifiablePrefix: prefix, promptMarkerCount: 0 })).toBe(false);