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: stop agy agents pasting into the folder-trust gate they never confirmed

[._.]/ Adam Eivyc4ba421cc3b2
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index bfc3efb415..a9de5062d4 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -71,3 +71,8 @@
- The model list comes from `agy models` — click Refresh Models on the AI Providers page and it pulls whatever your installed binary actually offers, rather than a list baked into PortOS that goes stale. Existing installs get the shipped catalog added automatically on first read; a model list you'd customized yourself is left alone. If the refresh can't reach your `agy` binary it says so and keeps your existing list, instead of reporting success over a built-in list your plan may not match.
- Leaving the model unset keeps the previous behavior exactly: no `--model` flag is passed and `agy` uses its own configured default. Nothing changes for existing tasks and schedules until you pick a model.
- A `--model` you'd hard-coded into the provider's own arguments now survives (it used to be stripped) and takes precedence over the per-task selection. The legacy Gemini-CLI spellings `agy` still rejects (`-m`, `--output-format`, `--yolo`) are stripped as before.
+
+## CoS agents
+
+- **Antigravity (agy) agents no longer die on the first-run folder-trust gate.** An agy agent launched in a fresh worktree could fail immediately with `Do you trust the contents of this project?` and a `paste-not-rendered` error, having done nothing. The spawner waits for a positive "input box is live" signal before pasting the task prompt, and for claude that signal — the terminal's bracketed-paste mode turning back on — arrives exactly when its composer appears. agy turns it on much earlier, when it enters full-screen mode, while it is still signing in and before its trust prompt has even drawn. So on any run where agy's sign-in outlasted the startup delay, the prompt was pasted into a screen that wasn't ready; the trust menu then appeared and swallowed it along with all three retries, and because the trust prompt hadn't been seen yet the auto-confirm never fired. agy now additionally waits for its composer footer, which only draws once the trust gate is resolved, so the trust prompt is confirmed first and the prompt lands in the input box. (`--dangerously-skip-permissions` does not bypass this gate, contrary to what the code previously assumed.)
+- Handshake markers are now matched against a rolling window of recent terminal output rather than a single read, so a prompt or footer that arrives split across two reads is still recognized.
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.js
index 6bbb2ddebd..1257404aa9 100644
--- a/server/lib/tuiHandshake.js
+++ b/server/lib/tuiHandshake.js
@@ -274,19 +274,51 @@ export const BRACKETED_PASTE_MODE_PATTERN = /\x1b\[\?2004([hl])/g;
export const TUI_TRUST_PROMPT_PATTERN =
/trustthisfolder|isthisaprojectyou(?:created|trust)/i;
-export function createInputReadyTracker() {
+// Antigravity (agy) needs a SECOND, positive readiness signal on top of paste
+// mode. agy enables bracketed paste the moment it enters the alt screen — while
+// it is still "Signing in…", before its folder-trust gate has painted and long
+// before its composer exists. So `sawCommandRun && pasteModeOn` goes true within
+// ~200ms of launch and the paste fires into whatever screen happens to be up.
+// When agy's sign-in round trip outran the 2.5s prompt delay, that screen was
+// the trust gate — it swallowed the prompt and all three paste retries, and the
+// agent died `paste-not-rendered` without the trust auto-confirm ever running
+// (`needsTrust` was still false when the paste went out). agy renders
+// `? for shortcuts` under its composer, and ONLY once the composer is live —
+// i.e. strictly after the trust gate is resolved — so gating on it orders the
+// two signals correctly and removes the race.
+//
+// (`--dangerously-skip-permissions` does NOT bypass agy's trust gate, despite
+// what the flag name suggests — real transcripts show the gate appearing under
+// it, same as claude's.)
+export const AGY_INPUT_READY_PATTERN = /\?forshortcuts/i;
+
+// Handshake markers are matched against a rolling window of whitespace-stripped
+// output rather than a single chunk, so a marker split across two PTY reads
+// (`? for short` | `cuts`) still matches. Sized to a few screens of chrome.
+const OBSERVE_TAIL_MAX_LEN = 4000;
+
+// readyTextPattern: optional extra positive gate, tested against the stripped
+// rolling tail. When supplied, `ready` also requires that marker to have been
+// seen (see AGY_INPUT_READY_PATTERN).
+export function createInputReadyTracker({ readyTextPattern = null } = {}) {
let pasteModeOn = false; // LIVE bracketed-paste mode state from the stream
let sawCommandRun = false; // shell turned paste mode OFF to run the command
let needsTrust = false;
+ let sawReadyText = false;
+ let tail = '';
return {
- // Ready once claude has RE-ENABLED bracketed-paste mode after the launch
- // shell turned it off to run the command — its input box is live and a
- // paste will be read as a paste. (The launch shell's own initial ON does
- // not count: sawCommandRun gates on the intervening OFF.)
- get ready() { return sawCommandRun && pasteModeOn; },
+ // Ready once the TUI has RE-ENABLED bracketed-paste mode after the launch
+ // shell turned it off to run the command — for claude that means its input
+ // box is live and a paste will be read as a paste. (The launch shell's own
+ // initial ON does not count: sawCommandRun gates on the intervening OFF.)
+ // Providers that enable paste mode before their composer exists supply a
+ // readyTextPattern to close the gap.
+ get ready() {
+ return sawCommandRun && pasteModeOn && (!readyTextPattern || sawReadyText);
+ },
get needsTrust() { return needsTrust; },
// rawText: un-stripped chunk (paste-mode toggles live here);
- // strippedText: ANSI-stripped chunk (the trust-gate text).
+ // strippedText: ANSI-stripped chunk (the trust-gate / composer text).
observe(rawText, strippedText) {
if (rawText) {
for (const m of rawText.matchAll(BRACKETED_PASTE_MODE_PATTERN)) {
@@ -294,8 +326,10 @@ export function createInputReadyTracker() {
else pasteModeOn = true;
}
}
- if (strippedText && !needsTrust && TUI_TRUST_PROMPT_PATTERN.test(strippedText.replace(/\s+/g, ''))) {
- needsTrust = true;
+ if (strippedText) {
+ tail = (tail + strippedText.replace(/\s+/g, '')).slice(-OBSERVE_TAIL_MAX_LEN);
+ if (!needsTrust && TUI_TRUST_PROMPT_PATTERN.test(tail)) needsTrust = true;
+ if (readyTextPattern && !sawReadyText && readyTextPattern.test(tail)) sawReadyText = true;
}
},
};
diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.js
index b49d4764af..f8337fdeb7 100644
--- a/server/lib/tuiHandshake.test.js
+++ b/server/lib/tuiHandshake.test.js
@@ -46,6 +46,8 @@ import {
verifyPasteRendered,
isPasteConfirmed,
isCollapsedPasteChip,
+ createInputReadyTracker,
+ AGY_INPUT_READY_PATTERN,
} from './tuiHandshake.js';
import { CODEX_CONFIGURED_DEFAULT } from './providerModels.js';
@@ -820,6 +822,61 @@ describe('tuiHandshake.extractVerifiablePromptPrefix', () => {
});
});
+describe('createInputReadyTracker', () => {
+ const PASTE_OFF = '\x1b[?2004l';
+ const PASTE_ON = '\x1b[?2004h';
+
+ it('is ready once paste mode is re-enabled after the launch command ran', () => {
+ const tracker = createInputReadyTracker();
+ tracker.observe(PASTE_ON, ''); // the launch shell's own paste mode — not ready
+ expect(tracker.ready).toBe(false);
+ tracker.observe(PASTE_OFF, ''); // shell turned it off to run the command
+ expect(tracker.ready).toBe(false);
+ tracker.observe(PASTE_ON, '');
+ expect(tracker.ready).toBe(true);
+ });
+
+ it('latches needsTrust on either trust-gate wording', () => {
+ const claude = createInputReadyTracker();
+ claude.observe('', 'Is this a project you trust?');
+ expect(claude.needsTrust).toBe(true);
+
+ const agy = createInputReadyTracker();
+ agy.observe('', 'Do you trust the contents of this project?\n> Yes, I trust this folder\n');
+ expect(agy.needsTrust).toBe(true);
+ });
+
+ it('matches a marker split across two PTY chunks (rolling tail)', () => {
+ const tracker = createInputReadyTracker();
+ tracker.observe('', '> Yes, I trust th');
+ expect(tracker.needsTrust).toBe(false);
+ tracker.observe('', 'is folder');
+ expect(tracker.needsTrust).toBe(true);
+ });
+
+ // agy enables bracketed paste on ALT-SCREEN ENTRY — before its composer, and
+ // before its folder-trust gate paints — so paste mode alone raced the trust
+ // menu and the prompt was pasted into it (`paste-not-rendered`).
+ it('readyTextPattern: paste mode alone is not ready until the composer marker is seen', () => {
+ const tracker = createInputReadyTracker({ readyTextPattern: AGY_INPUT_READY_PATTERN });
+ tracker.observe(`${PASTE_OFF}${PASTE_ON}`, 'Welcome to the Antigravity CLI.\n Signing in...\n');
+ expect(tracker.ready).toBe(false);
+
+ tracker.observe('', 'Do you trust the contents of this project?\n> Yes, I trust this folder\n');
+ expect(tracker.needsTrust).toBe(true);
+ expect(tracker.ready).toBe(false); // still not ready while the trust menu is up
+
+ tracker.observe('', '>\n? for shortcutsGemini 3.6 Flash · medium');
+ expect(tracker.ready).toBe(true);
+ });
+
+ it('readyTextPattern: the composer marker alone is not ready without paste mode', () => {
+ const tracker = createInputReadyTracker({ readyTextPattern: AGY_INPUT_READY_PATTERN });
+ tracker.observe('', '? for shortcuts');
+ expect(tracker.ready).toBe(false);
+ });
+});
+
describe('tuiHandshake.verifyPasteRendered', () => {
it('returns true when prefix is found in buffer', () => {
const prefix = 'implement the truncateMiddle function';
diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.js
index d6b34e1733..8557053bd5 100644
--- a/server/services/agentTuiSpawning.js
+++ b/server/services/agentTuiSpawning.js
@@ -42,6 +42,7 @@ import {
MCP_BOOT_PASTE_DEADLINE_MS,
MCP_BOOT_PASTE_RETRY_DELAY_MS,
createInputReadyTracker,
+ AGY_INPUT_READY_PATTERN,
rendersWorkCounter,
PASTE_TO_ENTER_MIN_DELAY_MS,
PASTE_TO_ENTER_FALLBACK_MS,
@@ -309,7 +310,11 @@ export async function spawnTuiAgent({
// Tracks claude's interactive input-readiness (footer chrome) and its first-run
// folder-trust gate. Gates the prompt paste for the claude TUI so we never
// paste into a startup banner, a trust menu, or a returned shell prompt.
- const inputReady = createInputReadyTracker();
+ // agy enables bracketed paste on alt-screen entry, before its composer (and
+ // before its trust gate) exists, so it needs the extra composer-footer gate.
+ const inputReady = createInputReadyTracker(
+ isAntigravityCommand(tuiConfig.command) ? { readyTextPattern: AGY_INPUT_READY_PATTERN } : {},
+ );
let trustAccepted = false;
// True once shell.js actually injects the `claude` command (after its
// round-trip readiness probe). The probe runs its OWN shell command first,
@@ -917,19 +922,21 @@ export async function spawnTuiAgent({
// trust gate, and NEVER blind-paste: if the prompt never appears we surface a
// failure. Other TUI providers keep the original idle heuristic + deadline.
//
- // Antigravity (agy) gets the SAME positive gate (issue #2705). agy's TUI also
- // enables bracketed-paste mode (`ESC[?2004h`) exactly when its input box is
- // live — the identical signal createInputReadyTracker keys on — but the old
- // blind-paste path fired into agy's still-initializing banner, so the prompt
- // never landed and the agent sat idle at an empty prompt until it was reaped
- // having done nothing. agy DOES have a first-run folder-trust gate ("Do you
- // trust the contents of this project?") like claude's — production spawns agy
- // with `--dangerously-skip-permissions`, which bypasses it; and if it does
- // appear (agy launched without that flag), its "Yes, I trust this folder"
- // option matches TUI_TRUST_PROMPT_PATTERN, so the requireInputReady auto-confirm
- // branch below handles it exactly as it does claude's. If agy ever fails to
- // signal ready, the requireInputReady path fails fast with a surfaced startup
- // error instead of silently idle-reaping.
+ // Antigravity (agy) gets the SAME positive gate (issue #2705), but agy alone
+ // needs a second signal on top of paste mode: unlike claude it enables
+ // bracketed paste on ALT-SCREEN ENTRY, ~200ms after launch, while it is still
+ // signing in and before its trust gate has even painted. Gating on paste mode
+ // alone therefore raced agy's sign-in round trip — when that outran the 2.5s
+ // prompt delay the prompt was pasted into the still-pending trust gate, which
+ // swallowed it and all three retries (`paste-not-rendered`). agy's composer
+ // footer (AGY_INPUT_READY_PATTERN) renders only after the trust gate is
+ // resolved, so requiring it orders the two correctly. agy DOES have a
+ // first-run folder-trust gate ("Do you trust the contents of this project?")
+ // and `--dangerously-skip-permissions` does NOT bypass it — the auto-confirm
+ // branch below is load-bearing, matching its "Yes, I trust this folder" option
+ // via TUI_TRUST_PROMPT_PATTERN. If agy ever fails to signal ready, the
+ // requireInputReady path fails fast with a surfaced startup error instead of
+ // silently idle-reaping.
const requireInputReady = isClaudeCommand(tuiConfig.command) || isAntigravityCommand(tuiConfig.command);
// sendPrompt / finishStartupFailure are async and dispatched fire-and-forget
// from the interval below. A setInterval callback can't await, and an
@@ -949,12 +956,13 @@ export async function spawnTuiAgent({
const elapsed = now - startedAt;
if (requireInputReady) {
- // Auto-confirm claude's first-run "trust this folder?" gate (default is
- // "Yes, I trust") so claims can run in fresh worktrees. Send Enter once.
+ // Auto-confirm the first-run "trust this folder?" gate (claude's and agy's
+ // both default to "Yes, I trust") so claims can run in fresh worktrees.
+ // Send Enter once.
if (inputReady.needsTrust && !trustAccepted) {
trustAccepted = true;
shellService.writeToSession(sessionId, '\r');
- appendLine(`📟 Auto-confirmed claude folder-trust prompt for session ${sessionId.slice(0, 8)}`);
+ appendLine(`📟 Auto-confirmed ${tuiConfig.command} folder-trust prompt for session ${sessionId.slice(0, 8)}`);
return;
}
if (inputReady.ready && elapsed >= tuiConfig.promptDelayMs) {
diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.js
index 6f3bcb2eee..f2a964e74b 100644
--- a/server/services/agentTuiSpawning.test.js
+++ b/server/services/agentTuiSpawning.test.js
@@ -938,7 +938,13 @@ describe('spawnTuiAgent runtime', () => {
// agent sitting at an empty prompt until it was reaped). Without the fix agy
// took the idle-heuristic path and WOULD have pasted after ~2s of banner idle;
// asserting pasteCount()===0 there is what discriminates the fix.
- it('agy input-ready: does NOT paste on the startup banner, only once paste mode is re-enabled', async () => {
+ //
+ // agy needs a SECOND gate on top of paste mode, because — unlike claude — it
+ // enables bracketed paste on alt-screen entry, before its composer exists. Its
+ // composer footer is the marker that says the input box is actually live.
+ const AGY_COMPOSER_FOOTER = '? for shortcuts';
+
+ it('agy input-ready: does NOT paste until the composer footer follows paste-mode-on', async () => {
runSpawn({ tuiConfig: agyTuiConfig });
await flushMicrotasks();
@@ -949,8 +955,51 @@ describe('spawnTuiAgent runtime', () => {
await flushMicrotasks();
expect(pasteCount()).toBe(0); // banner / paste-mode-off is not "input ready"
- // agy re-enables bracketed-paste mode → input box live, safe to paste.
- await capturedOnData(Buffer.from(PASTE_ON));
+ // agy enables bracketed paste when it enters the alt screen — still signing
+ // in, no composer yet. Paste mode ALONE must not be treated as ready.
+ await capturedOnData(Buffer.from(`${PASTE_ON}Welcome to the Antigravity CLI.\n Signing in...\n`));
+ await flushMicrotasks();
+ await vi.advanceTimersByTimeAsync(2000);
+ await flushMicrotasks();
+ expect(pasteCount()).toBe(0);
+
+ // Composer renders → input box live, safe to paste.
+ await capturedOnData(Buffer.from(`>\n${AGY_COMPOSER_FOOTER}Gemini 3.5 Flash · medium`));
+ await flushMicrotasks();
+ await vi.advanceTimersByTimeAsync(400);
+ await flushMicrotasks();
+ expect(pasteCount()).toBe(1);
+ });
+
+ // Regression: the real `paste-not-rendered` failure. agy turned bracketed paste
+ // ON at alt-screen entry (~200ms in) and then spent longer than promptDelayMs
+ // signing in, so the old paste-mode-only gate fired while the folder-trust menu
+ // was still pending — `needsTrust` was still false, the trust auto-confirm never
+ // ran, and the menu swallowed the prompt plus all three paste retries.
+ it('agy trust gate: paste mode turns on BEFORE the trust menu — waits for trust confirm, then the composer', async () => {
+ runSpawn({ tuiConfig: agyTuiConfig });
+ await flushMicrotasks();
+
+ // Alt-screen entry enables paste mode while agy is still signing in.
+ await capturedOnData(Buffer.from(`${PASTE_OFF}${PASTE_ON}Welcome to the Antigravity CLI. You are currently not signed in.\n Signing in...\n`));
+ await flushMicrotasks();
+ await vi.advanceTimersByTimeAsync(2000);
+ await flushMicrotasks();
+ expect(pasteCount()).toBe(0); // would have pasted into the void before the fix
+
+ // Trust gate finally paints (after the sign-in round trip).
+ await capturedOnData(Buffer.from('Do you trust the contents of this project?\nAntigravity CLI requires permission to read, edit, and execute files here.\n> Yes, I trust this folder\n No, exit\n'));
+ await flushMicrotasks();
+ await vi.advanceTimersByTimeAsync(700);
+ await flushMicrotasks();
+
+ // Auto-confirmed with a bare Enter, and still no paste.
+ expect(vi.mocked(shellService.writeToSession).mock.calls.filter(([, d]) => d === '\r').length)
+ .toBeGreaterThanOrEqual(1);
+ expect(pasteCount()).toBe(0);
+
+ // Composer comes up only after trust is accepted → now the paste lands.
+ await capturedOnData(Buffer.from(`>\n${AGY_COMPOSER_FOOTER}Gemini 3.5 Flash · medium`));
await flushMicrotasks();
await vi.advanceTimersByTimeAsync(400);
await flushMicrotasks();