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(shell): attached viewer's terminal replies no longer cancel a pasted TUI prompt's Enter retries

Adam Eivya0eb4fe99423
diff --git a/server/services/shell.js b/server/services/shell.js
index 0f0b5f222f..1e1560862f 100644
--- a/server/services/shell.js
+++ b/server/services/shell.js
@@ -690,6 +690,12 @@ export function getSessionProcess(sessionId) {
return shellSessions.get(sessionId)?.pty || null;
}
+// Automatic xterm replies to the TUI's own queries/focus tracking: focus
+// in/out, CPR, DA1/DA2, DSR, and OSC color answers. An attached viewer emits
+// these unprompted, so they are not a person typing over a pasted prompt.
+// eslint-disable-next-line no-control-regex
+const TERMINAL_REPLY_RE = /^(?:\x1b\[[IO]|\x1b\[\??[\d;]*[Rcn]|\x1b\][\s\S]*?(?:\x07|\x1b\\))+$/;
+
/**
* Write input to a shell session
*/
@@ -697,7 +703,10 @@ export function writeToSession(sessionId, data, options) {
const session = shellSessions.get(sessionId);
if (session) {
session.lastInputAt = Date.now();
- session.inputRevision = (session.inputRevision || 0) + 1;
+ // pasteToSession cancels its Enter retries when this moves; a terminal
+ // protocol reply must not, or an attached viewer silently strands the
+ // pasted prompt unsubmitted.
+ if (!TERMINAL_REPLY_RE.test(data)) session.inputRevision = (session.inputRevision || 0) + 1;
// Runner proxies carry submission evidence alongside the Enter. Native
// node-pty sessions retain their ordinary one-argument write contract.
if (session.external && options?.promptSubmission) session.pty.write(data, options);
diff --git a/server/services/shell.test.js b/server/services/shell.test.js
index 29d1d3ebd0..277a314f45 100644
--- a/server/services/shell.test.js
+++ b/server/services/shell.test.js
@@ -753,6 +753,16 @@ describe('pasteToSession', () => {
expect(pty.write).toHaveBeenCalledWith('new input');
});
+ it('keeps retrying Enter when an attached viewer sends terminal replies', () => {
+ shell.pasteToSession(id, 'hi');
+ shell.writeToSession(id, '\x1b[I');
+ shell.writeToSession(id, '\x1b[12;40R');
+ shell.writeToSession(id, '\x1b[?62;4c');
+ vi.advanceTimersByTime(1400);
+
+ expect(pty.write.mock.calls.filter(([data]) => data === '\r')).toHaveLength(3);
+ });
+
it('returns false and writes nothing for a missing session', () => {
expect(shell.pasteToSession('missing', 'hi')).toBe(false);
expect(pty.write).not.toHaveBeenCalled();