@devries-cameron20 / composio-1 / commits / 5555dee25
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

feat(cli): refresh approval fallback page (#3431)

## Summary - Refresh the browser fallback tool-approval page with the Composio CLI landing page visual language: light dithered background, mono terminal card, and brand-blue actions. - Serve the approval HTML directly from the temporary `127.0.0.1` callback server instead of writing/opening a `file://` page, so approval buttons call back to the active CLI process with relative local routes. - Keep the native macOS sidecar as the preferred prompt when available; the browser prompt remains the fallback when the sidecar is missing or fails before returning a decision. - Add a CLI patch changeset. ## Tests - `pnpm exec eslint ts/packages/cli/src/services/tool-permissions.ts` - `pnpm --filter @composio/cli typecheck:src` - `git diff --check` ## Notes - Initially `typecheck:src` failed before workspace package build artifacts existed in the fresh worktree; after building required workspace dependencies it passed. --------- Co-authored-by: Malay Vasa <malayvasa@gmail.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Rahul Tarak committed May 15, 2026 at 17:41 UTC 5555dee25c750bb61cbe168358a4da393ca2ceb2
2 files changed +373 -36
.changeset/cli-permission-fallback-design.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +"@composio/cli": patch
3 +---
4 +
5 +Refresh the browser fallback approval prompt with the Composio CLI landing page visual style and serve it from the local loopback callback server while continuing to prefer the native macOS sidecar when available.
ts/packages/cli/src/services/tool-permissions.ts
+368 -36
@@ -1,12 +1,15 @@
1 import http from 'node:http';
2 import fs from 'node:fs/promises';
3 -import os from 'node:os';
3 import path from 'node:path';
4 import open from 'open';
5 import { detectCliPlatform } from '@composio/cli-local-tools';
6 import { Effect, Option } from 'effect';
7 import { resolveCliConfigDirectorySync } from 'src/services/cli-user-config';
9 -import { requestNativeUiPermissionDecision } from 'src/services/native-ui-sidecar';
8 +import {
9 + detectNativeUiCallerAgent,
10 + requestNativeUiPermissionDecision,
11 + type NativeUiCallerAgent,
12 +} from 'src/services/native-ui-sidecar';
13 import { ComposioUserContext } from 'src/services/user-context';
14
15 const ENHANCED_CONTROLS_UNSUPPORTED_PLATFORMS: ReadonlySet<string> = new Set(['darwin-x64']);
@@ -285,51 +288,371 @@ const escapeHtml = (value: string): string =>
288 }
289 });
290
288 -const html = (params: { toolSlug: string; accountLabel?: string; port: number; token: string }) => {
291 +// Agent glyphs — same SVGs the macOS sidecar embeds (see
292 +// `ts/packages/cli-local-tools/native/composio-native-ui/Sources/ComposioNativeUI/main.swift`).
293 +// Kept verbatim so the browser fallback shows the same brand mark.
294 +const AGENT_SVGS: Readonly<Record<NativeUiCallerAgent, string>> = {
295 + composio: `<svg width="100" height="100" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_2367_5)"><path d="M91.7032 28.1801L35.3611 16.6572C31.6669 15.8988 28.1929 18.7367 28.1929 22.5043V49.1954V50.6144V77.3052C28.1929 81.0729 31.6669 83.9112 35.3611 83.1526L91.7032 71.6296" stroke="black" stroke-width="2.8556" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/><path d="M48.1992 7.38531C48.1993 2.09223 53.6097 -1.44765 58.4546 0.57874L58.6851 0.679333L58.6902 0.68227L88.8308 14.6023C91.4759 15.7947 93.1338 18.4366 93.1346 21.3053V33.0975C93.1346 37.3994 89.4707 40.797 85.1902 40.4658L51.0547 37.918V61.8914L85.185 59.3435L85.585 59.323C89.6842 59.2231 93.1331 62.5334 93.109 66.6876V78.4797C93.109 81.3707 91.4075 83.9737 88.8105 85.1812L88.806 85.1827L58.691 99.0774L58.6917 99.0782C53.7808 101.351 48.1992 97.7714 48.1992 92.3759V81.1383C47.9779 81.2256 47.741 81.2834 47.4921 81.3015L30.8347 82.5007C29.4429 82.6007 28.2584 81.4977 28.2582 80.1023V67.7354C28.2583 67.256 28.4014 66.8063 28.6474 66.4277L14.9439 67.4513H14.9388C10.6701 67.7539 7.00001 64.3671 7 60.0823V39.7271C7.00031 35.4239 10.6671 32.0248 14.9491 32.3589H14.9483L28.3486 33.3589C28.2905 33.152 28.2583 32.9345 28.2582 32.7099V19.6826C28.2582 17.7807 29.9597 16.3299 31.8377 16.6304L47.6992 19.168C47.8735 19.1959 48.0404 19.2435 48.1992 19.3059V7.38531ZM85.4075 62.191H85.4023L51.0547 64.755V79.6601L90.2541 71.4669V66.6774L90.2496 66.435C90.1323 63.9438 87.9489 61.9928 85.4075 62.191ZM27.7075 36.1748C27.9471 36.5495 28.0863 36.9936 28.0864 37.4678V62.7813C28.0864 63.0748 28.0314 63.3559 27.9344 63.6169L48.1992 62.1044V37.7043L27.7075 36.1748ZM51.0547 35.0544L85.4023 37.6183L85.4075 37.6191L85.6511 37.6316C88.1632 37.6928 90.279 35.6595 90.279 33.0975V28.1405L51.0547 19.9411V35.0544Z" fill="black"/></g><defs><clipPath id="clip0_2367_5"><rect width="86.4662" height="100" fill="white" transform="translate(7)"/></clipPath></defs></svg>`,
296 + claude: `<svg preserveAspectRatio="xMidYMid" viewBox="0 0 256 257" xmlns="http://www.w3.org/2000/svg"><path fill="#D97757" d="m50.228 170.321 50.357-28.257.843-2.463-.843-1.361h-2.462l-8.426-.518-28.775-.778-24.952-1.037-24.175-1.296-6.092-1.297L0 125.796l.583-3.759 5.12-3.434 7.324.648 16.202 1.101 24.304 1.685 17.629 1.037 26.118 2.722h4.148l.583-1.685-1.426-1.037-1.101-1.037-25.147-17.045-27.22-18.017-14.258-10.37-7.713-5.25-3.888-4.925-1.685-10.758 7-7.713 9.397.649 2.398.648 9.527 7.323 20.35 15.75L94.817 91.9l3.889 3.24 1.555-1.102.195-.777-1.75-2.917-14.453-26.118-15.425-26.572-6.87-11.018-1.814-6.61c-.648-2.723-1.102-4.991-1.102-7.778l7.972-10.823L71.42 0 82.05 1.426l4.472 3.888 6.61 15.101 10.694 23.786 16.591 32.34 4.861 9.592 2.592 8.879.973 2.722h1.685v-1.556l1.36-18.211 2.528-22.36 2.463-28.776.843-8.1 4.018-9.722 7.971-5.25 6.222 2.981 5.12 7.324-.713 4.73-3.046 19.768-5.962 30.98-3.889 20.739h2.268l2.593-2.593 10.499-13.934 17.628-22.036 7.778-8.749 9.073-9.657 5.833-4.601h11.018l8.1 12.055-3.628 12.443-11.342 14.388-9.398 12.184-13.48 18.147-8.426 14.518.778 1.166 2.01-.194 30.46-6.481 16.462-2.982 19.637-3.37 8.88 4.148.971 4.213-3.5 8.62-20.998 5.184-24.628 4.926-36.682 8.685-.454.324.519.648 16.526 1.555 7.065.389h17.304l32.21 2.398 8.426 5.574 5.055 6.805-.843 5.184-12.962 6.611-17.498-4.148-40.83-9.721-14-3.5h-1.944v1.167l11.666 11.406 21.387 19.314 26.767 24.887 1.36 6.157-3.434 4.86-3.63-.518-23.526-17.693-9.073-7.972-20.545-17.304h-1.36v1.814l4.73 6.935 25.017 37.59 1.296 11.536-1.814 3.76-6.481 2.268-7.13-1.297-14.647-20.544-15.1-23.138-12.185-20.739-1.49.843-7.194 77.448-3.37 3.953-7.778 2.981-6.48-4.925-3.436-7.972 3.435-15.749 4.148-20.544 3.37-16.333 3.046-20.285 1.815-6.74-.13-.454-1.49.194-15.295 20.999-23.267 31.433-18.406 19.702-4.407 1.75-7.648-3.954.713-7.064 4.277-6.286 25.47-32.405 15.36-20.092 9.917-11.6-.065-1.686h-.583L44.07 198.125l-12.055 1.555-5.185-4.86.648-7.972 2.463-2.593 20.35-13.999-.064.065Z"/></svg>`,
297 + codex: `<svg fill="#0A0A0A" fill-rule="evenodd" style="flex:none;line-height:1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path clip-rule="evenodd" d="M8.086.457a6.105 6.105 0 013.046-.415c1.333.153 2.521.72 3.564 1.7a.117.117 0 00.107.029c1.408-.346 2.762-.224 4.061.366l.063.03.154.076c1.357.703 2.33 1.77 2.918 3.198.278.679.418 1.388.421 2.126a5.655 5.655 0 01-.18 1.631.167.167 0 00.04.155 5.982 5.982 0 011.578 2.891c.385 1.901-.01 3.615-1.183 5.14l-.182.22a6.063 6.063 0 01-2.934 1.851.162.162 0 00-.108.102c-.255.736-.511 1.364-.987 1.992-1.199 1.582-2.962 2.462-4.948 2.451-1.583-.008-2.986-.587-4.21-1.736a.145.145 0 00-.14-.032c-.518.167-1.04.191-1.604.185a5.924 5.924 0 01-2.595-.622 6.058 6.058 0 01-2.146-1.781c-.203-.269-.404-.522-.551-.821a7.74 7.74 0 01-.495-1.283 6.11 6.11 0 01-.017-3.064.166.166 0 00.008-.074.115.115 0 00-.037-.064 5.958 5.958 0 01-1.38-2.202 5.196 5.196 0 01-.333-1.589 6.915 6.915 0 01.188-2.132c.45-1.484 1.309-2.648 2.577-3.493.282-.188.55-.334.802-.438.286-.12.573-.22.861-.304a.129.129 0 00.087-.087A6.016 6.016 0 015.635 2.31C6.315 1.464 7.132.846 8.086.457zm-.804 7.85a.848.848 0 00-1.473.842l1.694 2.965-1.688 2.848a.849.849 0 001.46.864l1.94-3.272a.849.849 0 00.007-.854l-1.94-3.393zm5.446 6.24a.849.849 0 000 1.695h4.848a.849.849 0 000-1.696h-4.848z"/></svg>`,
298 + openclaw: `<svg viewBox="0 0 120 120" fill="none" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="openclaw__lobster-gradient" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" stop-color="#ff4d4d"/><stop offset="100%" stop-color="#991b1b"/></linearGradient></defs><path d="M60 10 C30 10 15 35 15 55 C15 75 30 95 45 100 L45 110 L55 110 L55 100 C55 100 60 102 65 100 L65 110 L75 110 L75 100 C90 95 105 75 105 55 C105 35 90 10 60 10Z" fill="url(#openclaw__lobster-gradient)"/><path d="M20 45 C5 40 0 50 5 60 C10 70 20 65 25 55 C28 48 25 45 20 45Z" fill="url(#openclaw__lobster-gradient)"/><path d="M100 45 C115 40 120 50 115 60 C110 70 100 65 95 55 C92 48 95 45 100 45Z" fill="url(#openclaw__lobster-gradient)"/><path d="M45 15 Q35 5 30 8" stroke="#ff4d4d" stroke-width="3" stroke-linecap="round"/><path d="M75 15 Q85 5 90 8" stroke="#ff4d4d" stroke-width="3" stroke-linecap="round"/><circle cx="45" cy="35" r="6" fill="#050810"/><circle cx="75" cy="35" r="6" fill="#050810"/><circle cx="46" cy="34" r="2.5" fill="#00e5cc"/><circle cx="76" cy="34" r="2.5" fill="#00e5cc"/></svg>`,
299 +};
300 +
301 +const AGENT_DISPLAY_NAMES: Readonly<Record<NativeUiCallerAgent, string>> = {
302 + composio: 'Composio',
303 + claude: 'Claude',
304 + codex: 'Codex',
305 + openclaw: 'OpenClaw',
306 +};
307 +
308 +// 8x8 Bayer matrix encoded as a tiny SVG, matching the sidecar's ordered-dither
309 +// shader. Tiled across the card as a multiply-blended background.
310 +const DITHER_SVG = `<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8'><g fill='%23000' fill-opacity='0.10'>${[
311 + [0, 0],
312 + [4, 0],
313 + [1, 0],
314 + [5, 0],
315 + [6, 1],
316 + [2, 1],
317 + [7, 1],
318 + [3, 1],
319 + [1, 2],
320 + [5, 2],
321 + [0, 2],
322 + [4, 2],
323 + [7, 3],
324 + [3, 3],
325 + [6, 3],
326 + [2, 3],
327 + [0, 4],
328 + [4, 4],
329 + [1, 4],
330 + [5, 5],
331 + [6, 5],
332 + [2, 5],
333 + [7, 5],
334 + [3, 5],
335 + [1, 6],
336 + [5, 6],
337 + [0, 6],
338 + [4, 6],
339 + [7, 7],
340 + [3, 7],
341 + [6, 7],
342 + [2, 7],
343 +]
344 + .map(([x, y]) => `<rect x='${x}' y='${y}' width='1' height='1'/>`)
345 + .join('')}</g></svg>`;
346 +const DITHER_DATA_URI = `url("data:image/svg+xml;utf8,${DITHER_SVG}")`;
347 +
348 +const approvalHtml = (params: {
349 + toolSlug: string;
350 + accountLabel?: string;
351 + token: string;
352 + agent: NativeUiCallerAgent;
353 +}) => {
354 const toolSlug = escapeHtml(params.toolSlug);
290 - const accountLabel = params.accountLabel ? escapeHtml(params.accountLabel) : undefined;
355 + const account = escapeHtml(params.accountLabel ?? 'default connection');
356 + const token = encodeURIComponent(params.token);
357 + const agent = params.agent;
358 + const agentName = AGENT_DISPLAY_NAMES[agent];
359 + const agentSvg = AGENT_SVGS[agent];
360 + // The sidecar uses "wants to use TOOL" when an agent is detected and falls
361 + // back to "The composio cli wants to execute TOOL" in CLI mode. Mirror it.
362 + const titleBody =
363 + agent === 'composio'
364 + ? `The composio cli wants to execute <code>${toolSlug}</code>`
365 + : `<span class="agent-mark" aria-label="${agentName}">${agentSvg}</span><span class="agent-name">${agentName}</span> wants to use <code>${toolSlug}</code>`;
366 +
367 return `<!doctype html>
292 -<html>
368 +<html lang="en">
369 <head>
370 <meta charset="utf-8" />
371 <meta name="viewport" content="width=device-width, initial-scale=1" />
296 - <title>Allow ${toolSlug}?</title>
372 + <title>Allow ${toolSlug}? · Composio CLI</title>
373 <style>
298 - body { margin: 0; min-height: 100vh; display: grid; place-items: center; font-family: -apple-system, BlinkMacSystemFont, sans-serif; background: radial-gradient(circle at 20% 20%, #7c3aed33, transparent 35%), #080812; color: white; }
299 - main { width: min(520px, calc(100vw - 32px)); padding: 28px; border: 1px solid #ffffff22; border-radius: 24px; background: #ffffff12; box-shadow: 0 24px 80px #0008; backdrop-filter: blur(24px); }
300 - h1 { margin: 0 0 10px; font-size: 24px; }
301 - p { color: #d6d6e7; line-height: 1.5; }
302 - .actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 22px; }
303 - a { color: white; text-decoration: none; padding: 11px 14px; border-radius: 999px; background: #ffffff1c; }
304 - a.primary { background: #7c3aed; }
374 + :root {
375 + color-scheme: light;
376 + --ink: #121212;
377 + --muted: #666666;
378 + --border: rgba(0, 0, 0, 0.10);
379 + --card: rgba(255, 255, 255, 0.86);
380 + --wash: rgba(255, 255, 255, 0.55);
381 + --primary: #171717;
382 + --primary-hover: #2e2e2e;
383 + }
384 + * { box-sizing: border-box; }
385 + html, body { height: 100%; }
386 + body {
387 + margin: 0;
388 + display: grid;
389 + place-items: center;
390 + padding: 24px;
391 + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
392 + color: var(--ink);
393 + background: #d8d8d8;
394 + }
395 + .card {
396 + position: relative;
397 + width: min(520px, calc(100vw - 32px));
398 + border: 1px solid var(--border);
399 + border-radius: 16px;
400 + overflow: hidden;
401 + background: var(--card);
402 + backdrop-filter: blur(12px);
403 + box-shadow:
404 + 0 1px 0 rgba(255, 255, 255, 0.6) inset,
405 + 0 18px 50px rgba(0, 0, 0, 0.16),
406 + 0 2px 6px rgba(0, 0, 0, 0.06);
407 + }
408 + /* Dithered Bayer pattern, multiplied beneath the wash — same recipe the
409 + Metal shader uses in the macOS sidecar. */
410 + .card::before {
411 + content: "";
412 + position: absolute;
413 + inset: 0;
414 + background-image: ${DITHER_DATA_URI};
415 + background-size: 8px 8px;
416 + mix-blend-mode: multiply;
417 + opacity: 0.55;
418 + pointer-events: none;
419 + }
420 + /* Diagonal sine-wave hint (162°), pale and soft. */
421 + .card::after {
422 + content: "";
423 + position: absolute;
424 + inset: -20%;
425 + background: linear-gradient(
426 + 108deg,
427 + transparent 30%,
428 + rgba(0, 0, 0, 0.07) 50%,
429 + transparent 70%
430 + );
431 + filter: blur(28px);
432 + pointer-events: none;
433 + }
434 + .card > * { position: relative; z-index: 1; }
435 + /* Translucent white wash that softens the dither beneath text. */
436 + .wash {
437 + position: absolute;
438 + inset: 0;
439 + background: var(--wash);
440 + pointer-events: none;
441 + z-index: 0;
442 + }
443 + .body {
444 + padding: 22px 22px 18px;
445 + display: grid;
446 + gap: 16px;
447 + }
448 + .title {
449 + display: flex;
450 + flex-wrap: wrap;
451 + align-items: center;
452 + gap: 6px 8px;
453 + margin: 0;
454 + font-size: 16px;
455 + font-weight: 600;
456 + letter-spacing: -0.2px;
457 + line-height: 1.35;
458 + color: var(--ink);
459 + }
460 + .agent-mark {
461 + display: inline-flex;
462 + width: 28px;
463 + height: 28px;
464 + align-items: center;
465 + justify-content: center;
466 + }
467 + .agent-mark svg { width: 100%; height: 100%; }
468 + .agent-name { font-weight: 600; }
469 + .title code, .account code {
470 + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
471 + font-weight: 600;
472 + font-size: 0.92em;
473 + }
474 + .account {
475 + margin: 0;
476 + font-size: 12.5px;
477 + color: var(--muted);
478 + letter-spacing: -0.1px;
479 + }
480 + .account code {
481 + color: var(--ink);
482 + font-weight: 600;
483 + }
484 + .row {
485 + display: flex;
486 + align-items: center;
487 + justify-content: space-between;
488 + gap: 12px;
489 + margin-top: 20px;
490 + }
491 + .logo {
492 + width: 32px;
493 + height: 32px;
494 + flex: none;
495 + opacity: 0.85;
496 + }
497 + .logo svg { width: 100%; height: 100%; }
498 + .actions {
499 + display: flex;
500 + gap: 8px;
501 + flex-wrap: wrap;
502 + justify-content: flex-end;
503 + }
504 + .btn {
505 + appearance: none;
506 + display: inline-flex;
507 + align-items: center;
508 + justify-content: center;
509 + height: 30px;
510 + padding: 0 14px;
511 + border-radius: 8px;
512 + border: 1px solid var(--border);
513 + background: rgba(255, 255, 255, 0.55);
514 + color: var(--ink);
515 + font: 500 12.5px -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
516 + letter-spacing: 0.1px;
517 + text-decoration: none;
518 + cursor: pointer;
519 + transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
520 + }
521 + .btn:hover { background: rgba(255, 255, 255, 0.85); }
522 + .btn:active { transform: scale(0.97); }
523 + .btn.primary {
524 + background: var(--primary);
525 + color: #fff;
526 + border-color: transparent;
527 + box-shadow: 0 6px 18px rgba(0, 0, 0, 0);
528 + }
529 + .btn.primary:hover {
530 + background: var(--primary-hover);
531 + box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
532 + }
533 + @media (max-width: 480px) {
534 + .row { flex-direction: column; align-items: stretch; }
535 + .actions { justify-content: stretch; }
536 + .btn { flex: 1; }
537 + }
538 </style>
539 </head>
540 <body>
308 - <main>
309 - <h1>Allow ${toolSlug}?</h1>
310 - <p>Composio CLI is requesting permission to execute this tool${accountLabel ? ` for ${accountLabel}` : ''}.</p>
311 - <div class="actions">
312 - <a class="primary" href="http://127.0.0.1:${params.port}/allow-session?token=${params.token}">Allow for this session</a>
313 - <a href="http://127.0.0.1:${params.port}/allow-once?token=${params.token}">Allow once</a>
314 - <a href="http://127.0.0.1:${params.port}/deny?token=${params.token}">Deny</a>
541 + <main class="card" aria-labelledby="approval-title">
542 + <div class="wash" aria-hidden="true"></div>
543 + <div class="body">
544 + <h1 id="approval-title" class="title">${titleBody}</h1>
545 + <p class="account">Account: <code>${account}</code></p>
546 + <div class="row">
547 + <span class="logo" aria-hidden="true">${AGENT_SVGS.composio}</span>
548 + <div class="actions">
549 + <a class="btn" href="/deny?token=${token}">Deny</a>
550 + <a class="btn" href="/allow-session?token=${token}">Allow for session</a>
551 + <a class="btn primary" href="/allow-once?token=${token}">Allow once</a>
552 + </div>
553 + </div>
554 </div>
555 </main>
556 </body>
557 </html>`;
558 };
559
560 +const COMPLETION_COPY: Readonly<
561 + Record<PermissionDecision, { readonly title: string; readonly body: string }>
562 +> = {
563 + allow_once: {
564 + title: 'Allowed once',
565 + body: 'This tool call is going through now. We’ll ask again next time it’s used.',
566 + },
567 + allow_session: {
568 + title: 'Allowed for this session',
569 + body: 'This tool can run again for the rest of this CLI session without asking.',
570 + },
571 + deny: {
572 + title: 'Denied',
573 + body: 'The tool call was blocked. The agent will be told it was denied and can try something else.',
574 + },
575 +};
576 +
577 +const completionHtml = (decision: PermissionDecision) => {
578 + const { title, body } = COMPLETION_COPY[decision];
579 + return `<!doctype html>
580 +<html lang="en">
581 +<head>
582 + <meta charset="utf-8" />
583 + <meta name="viewport" content="width=device-width, initial-scale=1" />
584 + <title>${title} · Composio CLI</title>
585 + <style>
586 + body {
587 + margin: 0;
588 + min-height: 100vh;
589 + display: grid;
590 + place-items: center;
591 + padding: 24px;
592 + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
593 + background: #d8d8d8;
594 + color: #121212;
595 + }
596 + main {
597 + width: min(420px, calc(100vw - 32px));
598 + border: 1px solid rgba(0, 0, 0, 0.10);
599 + border-radius: 16px;
600 + background: rgba(255, 255, 255, 0.86);
601 + backdrop-filter: blur(12px);
602 + padding: 22px;
603 + box-shadow: 0 18px 50px rgba(0, 0, 0, 0.12);
604 + }
605 + .logo { display: block; width: 26px; height: 26px; margin-bottom: 14px; opacity: 0.85; }
606 + .logo svg { width: 100%; height: 100%; display: block; }
607 + h1 { margin: 0 0 6px; font-size: 16px; font-weight: 600; letter-spacing: -0.2px; }
608 + p { margin: 0; font-size: 13px; line-height: 1.5; color: #555; }
609 + .hint { margin-top: 14px; font-size: 12px; color: #888; }
610 + </style>
611 +</head>
612 +<body>
613 + <main>
614 + <span class="logo" aria-hidden="true">${AGENT_SVGS.composio}</span>
615 + <h1>${title}</h1>
616 + <p>${body}</p>
617 + <p class="hint">You can close this tab.</p>
618 + </main>
619 +</body>
620 +</html>`;
621 +};
622 +
623 const requestPermissionInBrowser = (params: {
624 readonly toolSlug: string;
625 readonly accountLabel?: string;
626 + readonly agent: NativeUiCallerAgent;
627 }): Promise<PermissionDecision> =>
628 new Promise((resolve, reject) => {
629 const token = crypto.randomUUID();
630 + let settled = false;
631 +
632 + const settle = (decision: PermissionDecision) => {
633 + if (settled) return;
634 + settled = true;
635 + server.close();
636 + resolve(decision);
637 + };
638 +
639 const server = http.createServer((req, res) => {
640 const url = new URL(req.url ?? '/', 'http://127.0.0.1');
641 if (url.searchParams.get('token') !== token) {
330 - res.writeHead(403).end('Forbidden');
642 + res.writeHead(403, { 'Content-Type': 'text/plain; charset=utf-8' }).end('Forbidden');
643 + return;
644 + }
645 +
646 + if (url.pathname === '/') {
647 + res
648 + .writeHead(200, {
649 + 'Content-Type': 'text/html; charset=utf-8',
650 + 'Cache-Control': 'no-store',
651 + })
652 + .end(approvalHtml({ ...params, token }));
653 return;
654 }
655 +
656 const decision =
657 url.pathname === '/allow-session'
658 ? 'allow_session'
@@ -339,30 +662,36 @@ const requestPermissionInBrowser = (params: {
662 ? 'deny'
663 : undefined;
664 if (!decision) {
342 - res.writeHead(404).end('Not found');
665 + res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' }).end('Not found');
666 return;
667 }
345 - res.writeHead(200, { 'Content-Type': 'text/html' }).end('<p>You can close this tab.</p>');
346 - server.close();
347 - resolve(decision);
668 +
669 + res
670 + .writeHead(200, {
671 + 'Content-Type': 'text/html; charset=utf-8',
672 + 'Cache-Control': 'no-store',
673 + })
674 + .end(completionHtml(decision));
675 + settle(decision);
676 });
677
350 - const timeout = setTimeout(() => {
351 - server.close();
352 - resolve('deny');
353 - }, 30_000);
678 + const timeout = setTimeout(() => settle('deny'), 30_000);
679
680 server.on('close', () => clearTimeout(timeout));
356 - server.on('error', reject);
681 + server.on('error', error => {
682 + if (settled) return;
683 + settled = true;
684 + clearTimeout(timeout);
685 + reject(error);
686 + });
687 server.listen(0, '127.0.0.1', async () => {
688 try {
689 const address = server.address();
690 const port = typeof address === 'object' && address ? address.port : undefined;
691 if (!port) throw new Error('Unable to allocate permission callback port.');
362 - const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'composio-permission-'));
363 - const filePath = path.join(dir, 'index.html');
364 - await fs.writeFile(filePath, html({ ...params, port, token }), 'utf8');
365 - await open(filePath);
692 + await open(`http://127.0.0.1:${port}/?token=${encodeURIComponent(token)}`, {
693 + wait: false,
694 + });
695 } catch (error) {
696 server.close();
697 reject(error);
@@ -374,10 +703,13 @@ const requestPermissionDecision = async (params: {
703 readonly toolSlug: string;
704 readonly accountLabel?: string;
705 }): Promise<PermissionDecision> => {
377 - const nativeDecision = await requestNativeUiPermissionDecision(params);
706 + // Prefer the bundled macOS native sidecar when it is available. The browser
707 + // prompt remains the cross-platform fallback and is only opened when the
708 + // native sidecar is missing or fails before returning a decision.
709 + const nativeDecision = await requestNativeUiPermissionDecision(params).catch(() => undefined);
710 if (nativeDecision === 'allow_once' || nativeDecision === 'allow_session') return nativeDecision;
711 if (nativeDecision === 'deny' || nativeDecision === 'dismissed') return 'deny';
380 - return requestPermissionInBrowser(params);
712 + return requestPermissionInBrowser({ ...params, agent: detectNativeUiCallerAgent() });
713 };
714
715 export const gateToolExecution = (params: GateParams) =>