@myrialabs/clopen 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -57,7 +57,7 @@ A complete development environment designed around AI-assisted workflows, built
57
57
  - **Cloudflare Tunnel** — One-click public HTTPS URL for your local dev server. Built-in QR code for instant mobile access. Share your work without deploying
58
58
  - **MCP Support** — Full Model Context Protocol integration. Connect AI tools, external APIs, and custom capabilities to your AI agents with zero friction
59
59
  - **Flexible Authentication** — No Login or With Login mode with admin/member roles, invite links, rate-limited login, and CLI token recovery
60
- - **System Tools Installer** — Install Git, Claude Code, OpenCode, and Chrome straight from the admin Settings UI, with live install output streamed to the browser via xterm.js
60
+ - **System Tools Installer** — Install Git, Claude Code, OpenCode, Chrome, and Cloudflared (for Public Tunnel) straight from the admin Settings UI, with live install output streamed to the browser via xterm.js
61
61
  - **Background Processing** — Chat, terminal, and other processes continue running even when you close the browser — come back later and pick up where you left off
62
62
  - **Database Management** — Browse tables, run queries, and inspect your database directly from the workspace *(coming soon)*
63
63
 
@@ -88,7 +88,7 @@ Or manually via Bun:
88
88
  bun add -g @myrialabs/clopen
89
89
  ```
90
90
 
91
- You can also update from the **Settings > Maintenance > Updates** section in the web UI.
91
+ You can also update from the **Settings → Maintenance > Updates** section in the web UI.
92
92
 
93
93
  ### Usage
94
94
 
@@ -107,9 +107,9 @@ On first launch, a setup wizard guides you through:
107
107
  3. **AI Engines** — Check Claude Code and OpenCode installation status
108
108
  4. **Preferences** — Set theme, font size, and notification preferences
109
109
 
110
- You can change the authentication mode anytime in **Settings > Security > Authentication**.
110
+ You can change the authentication mode anytime in **Settings → Security > Authentication**.
111
111
 
112
- To invite team members (With Login mode), go to **Settings > Team > Invite** and generate an invite link (valid for 15 minutes).
112
+ To invite team members (With Login mode), go to **Settings → Team > Invite** and generate an invite link (valid for 15 minutes).
113
113
 
114
114
  If you lose your admin token:
115
115
 
@@ -13,7 +13,6 @@
13
13
  * surface a copy-able command and a docs link, regardless of platform.
14
14
  */
15
15
 
16
- import { homedir } from 'node:os';
17
16
  import { existsSync, readdirSync } from 'node:fs';
18
17
  import { join } from 'node:path';
19
18
  import { isElevated } from '$backend/utils/privilege';
@@ -21,7 +20,7 @@ import { getClopenDir } from '$backend/utils/paths';
21
20
  import { resolveBinary, resolveBinaryWithRefresh } from '$backend/utils/cli';
22
21
  import { resolveStaticCurlAsset } from '$backend/utils/static-curl';
23
22
 
24
- export type ToolId = 'git' | 'claude' | 'opencode' | 'chrome';
23
+ export type ToolId = 'git' | 'claude' | 'opencode' | 'chrome' | 'cloudflared';
25
24
 
26
25
  export interface ManualInstruction {
27
26
  label: string;
@@ -99,15 +98,18 @@ function detectMacPkgMgr(): 'brew' | null {
99
98
  }
100
99
 
101
100
  // ─────────────────────────────────────────────────────────────────────────────
102
- // Chrome detection via puppeteer cache layout
101
+ // Chrome detection
103
102
  // ─────────────────────────────────────────────────────────────────────────────
104
103
 
105
104
  /**
106
- * Resolve the Chrome executable path under ~/.clopen/bin using the
107
- * @puppeteer/browsers cache layout. Checks common Chrome build IDs by
108
- * scanning the cache directory.
105
+ * Resolve the Chrome for Testing executable path under ~/.clopen/bin using
106
+ * the @puppeteer/browsers cache layout: <cache>/chrome/<platform>-<buildId>/<archive>/<binary>.
107
+ * Only macOS and Windows install Chrome this way — on Linux we install
108
+ * Google Chrome via the distro package manager and skip this scan.
109
109
  */
110
110
  export function resolveClopenChromePath(): string | null {
111
+ if (process.platform !== 'darwin' && process.platform !== 'win32') return null;
112
+
111
113
  const cacheDir = join(getClopenDir(), 'bin', 'chrome');
112
114
  if (!existsSync(cacheDir)) return null;
113
115
 
@@ -115,20 +117,22 @@ export function resolveClopenChromePath(): string | null {
115
117
  const entries = readdirSync(cacheDir);
116
118
  for (const entry of entries) {
117
119
  const buildDir = join(cacheDir, entry);
118
- let candidate: string;
119
120
  if (process.platform === 'darwin') {
120
- candidate = join(buildDir, 'chrome-mac-arm64', 'Google Chrome for Testing.app', 'Contents', 'MacOS', 'Google Chrome for Testing');
121
- if (existsSync(candidate)) return candidate;
122
- candidate = join(buildDir, 'chrome-mac-x64', 'Google Chrome for Testing.app', 'Contents', 'MacOS', 'Google Chrome for Testing');
123
- if (existsSync(candidate)) return candidate;
124
- } else if (process.platform === 'win32') {
125
- candidate = join(buildDir, 'chrome-win64', 'chrome.exe');
126
- if (existsSync(candidate)) return candidate;
127
- candidate = join(buildDir, 'chrome-win32', 'chrome.exe');
128
- if (existsSync(candidate)) return candidate;
121
+ const macDirs = ['chrome-mac-arm64', 'chrome-mac-x64', 'chrome-mac'];
122
+ for (const dir of macDirs) {
123
+ const candidate = join(
124
+ buildDir, dir,
125
+ 'Google Chrome for Testing.app',
126
+ 'Contents', 'MacOS', 'Google Chrome for Testing'
127
+ );
128
+ if (existsSync(candidate)) return candidate;
129
+ }
129
130
  } else {
130
- candidate = join(buildDir, 'chrome-linux64', 'chrome');
131
- if (existsSync(candidate)) return candidate;
131
+ const winDirs = ['chrome-win64', 'chrome-win'];
132
+ for (const dir of winDirs) {
133
+ const candidate = join(buildDir, dir, 'chrome.exe');
134
+ if (existsSync(candidate)) return candidate;
135
+ }
132
136
  }
133
137
  }
134
138
  } catch {
@@ -139,35 +143,32 @@ export function resolveClopenChromePath(): string | null {
139
143
 
140
144
  function detectSystemChrome(): string | null {
141
145
  if (process.platform === 'darwin') {
142
- const paths = [
143
- '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
144
- '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
145
- '/Applications/Chromium.app/Contents/MacOS/Chromium'
146
- ];
147
- for (const p of paths) if (existsSync(p)) return p;
148
- return null;
146
+ const p = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
147
+ return existsSync(p) ? p : null;
149
148
  }
150
149
  if (process.platform === 'win32') {
151
- const programFiles = process.env['PROGRAMFILES'] ?? 'C:\\Program Files';
152
- const programFilesX86 = process.env['PROGRAMFILES(X86)'] ?? 'C:\\Program Files (x86)';
153
- const localAppData = process.env['LOCALAPPDATA'] ?? join(homedir(), 'AppData', 'Local');
154
150
  const paths = [
155
- join(programFiles, 'Google', 'Chrome', 'Application', 'chrome.exe'),
156
- join(programFilesX86, 'Google', 'Chrome', 'Application', 'chrome.exe'),
157
- join(localAppData, 'Google', 'Chrome', 'Application', 'chrome.exe')
151
+ 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
152
+ 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
158
153
  ];
159
154
  for (const p of paths) if (existsSync(p)) return p;
160
- return null;
155
+ return resolveBinary('chrome');
161
156
  }
162
- return resolveBinary('google-chrome')
163
- ?? resolveBinary('google-chrome-stable')
164
- ?? resolveBinary('chromium')
165
- ?? resolveBinary('chromium-browser');
157
+ // Linux: Google Chrome only (installed via apt/dnf/zypper from dl.google.com).
158
+ const chromePaths = [
159
+ '/opt/google/chrome/chrome',
160
+ '/usr/bin/google-chrome-stable',
161
+ '/usr/bin/google-chrome'
162
+ ];
163
+ for (const p of chromePaths) if (existsSync(p)) return p;
164
+ return resolveBinary('google-chrome-stable') ?? resolveBinary('google-chrome');
166
165
  }
167
166
 
168
167
  /**
169
- * Preferred executable path for puppeteer. Clopen-managed install wins
170
- * over system Chrome so users can keep the bundled version consistent.
168
+ * Preferred Chrome executable path for puppeteer. Clopen-managed install
169
+ * (macOS/Windows via @puppeteer/browsers → Chrome for Testing) wins over
170
+ * system Google Chrome so the bundled version stays consistent; on Linux
171
+ * only the system Google Chrome path is used.
171
172
  */
172
173
  export function getChromeExecutablePath(): string | null {
173
174
  return resolveClopenChromePath() ?? detectSystemChrome();
@@ -195,7 +196,7 @@ export async function getToolStatus(tool: ToolId): Promise<ToolStatus> {
195
196
  const resolved = getChromeExecutablePath();
196
197
  if (!resolved) return { tool, installed: false, version: null, source: null };
197
198
  const version = await runVersion(resolved);
198
- const source = resolveClopenChromePath() ? 'clopen' : 'system';
199
+ const source = resolveClopenChromePath() ? 'clopen' : resolved;
199
200
  return { tool, installed: true, version, source };
200
201
  }
201
202
 
@@ -203,6 +204,16 @@ export async function getToolStatus(tool: ToolId): Promise<ToolStatus> {
203
204
  if (!resolved) return { tool, installed: false, version: null, source: null };
204
205
  const version = await runVersion(resolved);
205
206
  if (!version) return { tool, installed: false, version: null, source: null };
207
+
208
+ // Cloudflared: tag binaries under ~/.clopen/bin as "clopen"-managed so the
209
+ // UI distinguishes System Tools installs from system-wide ones.
210
+ if (tool === 'cloudflared') {
211
+ const clopenBinDir = join(getClopenDir(), 'bin');
212
+ if (resolved.startsWith(clopenBinDir)) {
213
+ return { tool, installed: true, version, source: 'clopen' };
214
+ }
215
+ }
216
+
206
217
  return { tool, installed: true, version, source: resolved };
207
218
  }
208
219
 
@@ -398,20 +409,244 @@ async function resolveOpenCodeRecipe(): Promise<Recipe> {
398
409
  return base;
399
410
  }
400
411
 
412
+ // ─────────────────────────────────────────────────────────────────────────────
413
+ // Chrome recipe — Puppeteer download (macOS/Windows) or Google Chrome (Linux)
414
+ // ─────────────────────────────────────────────────────────────────────────────
415
+
416
+ const PPTR_CHROME_DOCS = 'https://pptr.dev/browsers-api';
417
+ const CHROME_LINUX_DOCS = 'https://www.google.com/chrome/';
418
+
419
+ // Google Chrome Linux package URLs. Google only publishes Linux x86_64
420
+ // .deb (apt) and .rpm (dnf/zypper) — other distros / arm64 surface manual
421
+ // instructions.
422
+ const GOOGLE_CHROME_DEB_URL = 'https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb';
423
+ const GOOGLE_CHROME_RPM_URL = 'https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm';
424
+
401
425
  async function resolveChromeRecipe(): Promise<Recipe> {
402
426
  const cacheDir = join(getClopenDir(), 'bin');
427
+ const pptrArgs = ['bun', 'x', '@puppeteer/browsers', 'install', 'chrome@stable', '--path', cacheDir];
428
+ const pptrDisplay = `bun x @puppeteer/browsers install chrome@stable --path "${cacheDir}"`;
429
+
430
+ // macOS / Windows: Puppeteer downloads Chrome for Testing, self-contained.
431
+ if (process.platform === 'darwin' || process.platform === 'win32') {
432
+ return {
433
+ tool: 'chrome',
434
+ autoInstallable: true,
435
+ missingPrereqs: [],
436
+ manualInstructions: [{
437
+ label: 'Puppeteer browsers CLI',
438
+ command: pptrDisplay,
439
+ docs: PPTR_CHROME_DOCS
440
+ }],
441
+ command: pptrArgs,
442
+ displayCommand: pptrDisplay
443
+ };
444
+ }
445
+
446
+ // Linux: Google Chrome deb/rpm for x86_64 (apt/dnf/zypper). Other
447
+ // distros / arm64 are marked non-auto-installable with manual steps.
448
+ return resolveLinuxChromeRecipe();
449
+ }
450
+
451
+ interface LinuxChromeStrategy {
452
+ pkgMgrLabel: string;
453
+ /** Argv-form command to spawn (sh -c <string>). */
454
+ installCommand: string;
455
+ /** User-facing display command (with sudo prefix if interactive). */
456
+ manualCommand: string;
457
+ /** Whether this strategy shells out to curl (for static-curl fallback). */
458
+ requiresCurl?: boolean;
459
+ /** Extra env to inject into the spawn. */
460
+ env?: Record<string, string>;
461
+ }
462
+
463
+ async function resolveLinuxChromeRecipe(): Promise<Recipe> {
464
+ const mgr = detectLinuxPkgMgr();
465
+ const arch = process.arch;
466
+
467
+ const manual: ManualInstruction[] = [];
468
+ const strategy = pickLinuxChromeStrategy(mgr, arch);
469
+
470
+ if (strategy) {
471
+ manual.push({
472
+ label: `${strategy.pkgMgrLabel} (recommended)`,
473
+ command: strategy.manualCommand,
474
+ docs: CHROME_LINUX_DOCS
475
+ });
476
+ }
477
+
403
478
  const base: Recipe = {
404
479
  tool: 'chrome',
405
- autoInstallable: true,
480
+ autoInstallable: false,
406
481
  missingPrereqs: [],
407
- manualInstructions: [{
408
- label: 'Puppeteer browsers CLI',
409
- command: `bun x @puppeteer/browsers install chrome@stable --path "${cacheDir}"`,
410
- docs: 'https://pptr.dev/browsers-api'
411
- }],
412
- command: ['bun', 'x', '@puppeteer/browsers', 'install', 'chrome@stable', '--path', cacheDir],
413
- displayCommand: `bun x @puppeteer/browsers install chrome@stable --path ${cacheDir}`
482
+ manualInstructions: manual
483
+ };
484
+
485
+ if (!strategy) {
486
+ base.unavailableReason = arch !== 'x64'
487
+ ? `Google Chrome is only published for Linux x86_64. No Chrome build exists for ${arch}. Download Chrome manually from google.com/chrome.`
488
+ : `Google Chrome is only available via apt, dnf, or zypper on Linux${mgr ? ` (this system uses ${mgr})` : ' — no supported package manager was detected'}. Download Chrome manually from google.com/chrome.`;
489
+ return base;
490
+ }
491
+
492
+ if (strategy.requiresCurl && !attachCurlRequirement(base, 'Google Chrome')) {
493
+ return base;
494
+ }
495
+
496
+ const elevated = await isElevated();
497
+ if (!elevated) {
498
+ base.unavailableReason = `Installing Google Chrome via ${strategy.pkgMgrLabel} requires root. Run clopen as root, or install Chrome manually with the command below and retry.`;
499
+ return base;
500
+ }
501
+
502
+ base.autoInstallable = true;
503
+ base.shell = { program: 'sh', args: ['-c'] };
504
+ base.command = [strategy.installCommand];
505
+ base.displayCommand = strategy.manualCommand;
506
+ if (strategy.env) base.env = strategy.env;
507
+ return base;
508
+ }
509
+
510
+ function pickLinuxChromeStrategy(
511
+ mgr: LinuxPkgMgr | null,
512
+ arch: string
513
+ ): LinuxChromeStrategy | null {
514
+ // Google only publishes Linux Chrome for x86_64.
515
+ if (arch !== 'x64') return null;
516
+
517
+ if (mgr === 'apt') {
518
+ // Download + install the .deb from dl.google.com. apt-get install with
519
+ // a local deb path auto-resolves dependencies (libatk, libnss3, etc.)
520
+ // from the distro repos. The postinst adds Google's apt source for
521
+ // future updates.
522
+ const cmd =
523
+ 'apt-get update && apt-get install -y curl ca-certificates && ' +
524
+ `curl -fsSL -o /tmp/google-chrome-stable.deb ${GOOGLE_CHROME_DEB_URL} && ` +
525
+ 'apt-get install -y /tmp/google-chrome-stable.deb && ' +
526
+ 'rm -f /tmp/google-chrome-stable.deb';
527
+ return {
528
+ pkgMgrLabel: 'apt',
529
+ installCommand: cmd,
530
+ manualCommand:
531
+ `sudo apt-get update && sudo apt-get install -y curl ca-certificates && ` +
532
+ `curl -fsSL -o /tmp/google-chrome-stable.deb ${GOOGLE_CHROME_DEB_URL} && ` +
533
+ `sudo apt-get install -y /tmp/google-chrome-stable.deb`,
534
+ requiresCurl: true,
535
+ env: { DEBIAN_FRONTEND: 'noninteractive' }
536
+ };
537
+ }
538
+ if (mgr === 'dnf') {
539
+ return {
540
+ pkgMgrLabel: 'dnf',
541
+ installCommand: `dnf install -y ${GOOGLE_CHROME_RPM_URL}`,
542
+ manualCommand: `sudo dnf install -y ${GOOGLE_CHROME_RPM_URL}`
543
+ };
544
+ }
545
+ if (mgr === 'zypper') {
546
+ return {
547
+ pkgMgrLabel: 'zypper',
548
+ installCommand: `zypper --non-interactive --gpg-auto-import-keys install ${GOOGLE_CHROME_RPM_URL}`,
549
+ manualCommand: `sudo zypper install ${GOOGLE_CHROME_RPM_URL}`
550
+ };
551
+ }
552
+ return null;
553
+ }
554
+
555
+ // ─────────────────────────────────────────────────────────────────────────────
556
+ // Cloudflared recipe — downloads the Cloudflare-signed binary into ~/.clopen/bin
557
+ // ─────────────────────────────────────────────────────────────────────────────
558
+
559
+ const CLOUDFLARED_RELEASE_BASE = 'https://github.com/cloudflare/cloudflared/releases/latest/download';
560
+ const CLOUDFLARED_DOCS = 'https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/';
561
+
562
+ const CLOUDFLARED_LINUX_ARCH: Record<string, string> = {
563
+ x64: 'amd64',
564
+ arm64: 'arm64',
565
+ arm: 'arm',
566
+ ia32: '386'
567
+ };
568
+
569
+ async function resolveCloudflaredRecipe(): Promise<Recipe> {
570
+ const base: Recipe = {
571
+ tool: 'cloudflared',
572
+ autoInstallable: false,
573
+ missingPrereqs: [],
574
+ manualInstructions: []
414
575
  };
576
+
577
+ const binDir = join(getClopenDir(), 'bin');
578
+
579
+ if (process.platform === 'darwin') {
580
+ const archKey = process.arch === 'arm64' ? 'arm64' : 'amd64';
581
+ const file = `cloudflared-darwin-${archKey}.tgz`;
582
+ const url = `${CLOUDFLARED_RELEASE_BASE}/${file}`;
583
+ const cmd =
584
+ `mkdir -p "${binDir}" && ` +
585
+ `curl -fsSL -o "${binDir}/${file}" "${url}" && ` +
586
+ `tar -xzf "${binDir}/${file}" -C "${binDir}" && ` +
587
+ `rm -f "${binDir}/${file}" && ` +
588
+ `chmod +x "${binDir}/cloudflared"`;
589
+
590
+ base.manualInstructions.push({
591
+ label: 'curl + tar',
592
+ command: cmd,
593
+ docs: CLOUDFLARED_DOCS
594
+ });
595
+ if (!attachCurlRequirement(base, 'Cloudflared')) return base;
596
+ base.autoInstallable = true;
597
+ base.shell = { program: 'bash', args: ['-c'] };
598
+ base.command = [cmd];
599
+ base.displayCommand = cmd;
600
+ return base;
601
+ }
602
+
603
+ if (process.platform === 'linux') {
604
+ const archKey = CLOUDFLARED_LINUX_ARCH[process.arch];
605
+ if (!archKey) {
606
+ base.unavailableReason = `Cloudflared has no published Linux build for ${process.arch}.`;
607
+ return base;
608
+ }
609
+ const file = `cloudflared-linux-${archKey}`;
610
+ const url = `${CLOUDFLARED_RELEASE_BASE}/${file}`;
611
+ const cmd =
612
+ `mkdir -p "${binDir}" && ` +
613
+ `curl -fsSL -o "${binDir}/cloudflared" "${url}" && ` +
614
+ `chmod +x "${binDir}/cloudflared"`;
615
+
616
+ base.manualInstructions.push({
617
+ label: 'curl',
618
+ command: cmd,
619
+ docs: CLOUDFLARED_DOCS
620
+ });
621
+ if (!attachCurlRequirement(base, 'Cloudflared')) return base;
622
+ base.autoInstallable = true;
623
+ base.shell = { program: 'bash', args: ['-c'] };
624
+ base.command = [cmd];
625
+ base.displayCommand = cmd;
626
+ return base;
627
+ }
628
+
629
+ if (process.platform === 'win32') {
630
+ const archKey = process.arch === 'ia32' ? '386' : 'amd64';
631
+ const file = `cloudflared-windows-${archKey}.exe`;
632
+ const url = `${CLOUDFLARED_RELEASE_BASE}/${file}`;
633
+ const psCmd =
634
+ `New-Item -ItemType Directory -Path "${binDir}" -Force | Out-Null; ` +
635
+ `Invoke-WebRequest -Uri "${url}" -OutFile "${binDir}\\cloudflared.exe"`;
636
+
637
+ base.manualInstructions.push({
638
+ label: 'PowerShell',
639
+ command: psCmd,
640
+ docs: CLOUDFLARED_DOCS
641
+ });
642
+ base.autoInstallable = true;
643
+ base.shell = { program: 'powershell.exe', args: ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command'] };
644
+ base.command = [psCmd];
645
+ base.displayCommand = psCmd;
646
+ return base;
647
+ }
648
+
649
+ base.unavailableReason = `Unsupported platform: ${process.platform}`;
415
650
  return base;
416
651
  }
417
652
 
@@ -426,5 +661,6 @@ export async function resolveRecipe(tool: ToolId): Promise<Recipe> {
426
661
  case 'claude': return resolveClaudeRecipe();
427
662
  case 'opencode': return resolveOpenCodeRecipe();
428
663
  case 'chrome': return resolveChromeRecipe();
664
+ case 'cloudflared': return resolveCloudflaredRecipe();
429
665
  }
430
666
  }
@@ -17,6 +17,7 @@
17
17
  * may only pick a tool id; it cannot supply arbitrary command strings.
18
18
  */
19
19
 
20
+ import { freemem, totalmem } from 'node:os';
20
21
  import { debug } from '$shared/utils/logger';
21
22
  import { ws } from '$backend/utils/ws';
22
23
  import { getCleanSpawnEnv } from '$backend/utils/env';
@@ -191,6 +192,40 @@ async function runStreamedProcess(session: Session, proc: ReturnType<typeof Bun.
191
192
  return exitCode;
192
193
  }
193
194
 
195
+ function formatBytes(bytes: number): string {
196
+ const mb = bytes / (1024 * 1024);
197
+ if (mb < 1024) return `${mb.toFixed(0)} MB`;
198
+ return `${(mb / 1024).toFixed(1)} GB`;
199
+ }
200
+
201
+ /**
202
+ * Build a human-readable hint for non-zero exit codes that likely indicate
203
+ * an environmental problem (OOM kill, external termination) rather than a
204
+ * recipe bug. Returns null when no specific guidance applies.
205
+ *
206
+ * Shells propagate signals as `128 + signum`: 137 = SIGKILL (OOM killer on
207
+ * Linux), 143 = SIGTERM. On a cancelled session we skip the hint — the UI
208
+ * already labels the run as "Cancelled".
209
+ */
210
+ function explainFailure(exitCode: number, cancelled: boolean): string | null {
211
+ if (cancelled) return null;
212
+ if (exitCode === 137) {
213
+ const total = formatBytes(totalmem());
214
+ const free = formatBytes(freemem());
215
+ return [
216
+ '',
217
+ '⚠ Exit 137 — the process was killed (SIGKILL), almost always by the kernel out-of-memory killer.',
218
+ ` System memory: total=${total}, free=${free}.`,
219
+ ' Common causes: low-RAM VPS / container / WSL without enough swap. Installer subprocesses can briefly peak at several hundred MB of memory.',
220
+ ' Remedies: add swap, raise the container memory limit, or run the install command in a shell with more memory, then retry.'
221
+ ].join('\n');
222
+ }
223
+ if (exitCode === 143) {
224
+ return '\n⚠ Exit 143 — the process received SIGTERM (external termination). Possible causes: systemd/container shutdown, manual kill, or an orchestrator timeout.';
225
+ }
226
+ return null;
227
+ }
228
+
194
229
  async function runInstall(session: Session, env: Record<string, string>): Promise<void> {
195
230
  const { recipe } = session;
196
231
  let proc: ReturnType<typeof Bun.spawn>;
@@ -240,6 +275,10 @@ async function runInstall(session: Session, env: Record<string, string>): Promis
240
275
  session.proc = proc;
241
276
 
242
277
  const exitCode = await runStreamedProcess(session, proc);
278
+ if (exitCode !== 0) {
279
+ const hint = explainFailure(exitCode, session.status === 'cancelled');
280
+ if (hint) emitStream(session, 'stderr', hint + '\n');
281
+ }
243
282
  finalizeSession(session, exitCode === 0 ? 'success' : 'failed', exitCode);
244
283
  }
245
284
 
@@ -68,9 +68,9 @@ Automatically creates session. New tab is immediately active - no need to switch
68
68
 
69
69
  VIEWPORT MODES:
70
70
  - desktop: 1920x1080 (default rotation: landscape) - For testing full desktop layouts
71
- - laptop: 1280x800 (default, default rotation: landscape) - Most common desktop viewport
72
- - tablet: 820x1050 (default rotation: portrait) - iPad-like tablet viewport
73
- - mobile: 393x740 (default rotation: portrait) - Modern smartphone viewport
71
+ - laptop: 1440x900 (default, default rotation: landscape) - Modern 14" laptop viewport
72
+ - tablet: 834x1194 (default rotation: portrait) - iPad Pro 11" class viewport
73
+ - mobile: 402x874 (default rotation: portrait) - iPhone 16 / modern flagship viewport
74
74
 
75
75
  ROTATION:
76
76
  - portrait: Standard vertical orientation (default for tablet/mobile)
@@ -114,9 +114,9 @@ OUTPUT: Confirmation with tab ID and new viewport settings.
114
114
 
115
115
  VIEWPORT MODES:
116
116
  - desktop: 1920x1080 - For testing full desktop layouts
117
- - laptop: 1280x800 - Most common desktop viewport
118
- - tablet: 820x1050 - iPad-like tablet viewport
119
- - mobile: 393x740 - Modern smartphone viewport
117
+ - laptop: 1440x900 - Modern 14" laptop viewport
118
+ - tablet: 834x1194 - iPad Pro 11" class viewport
119
+ - mobile: 402x874 - iPhone 16 / modern flagship viewport
120
120
 
121
121
  ROTATION:
122
122
  - portrait: Standard vertical orientation
@@ -45,9 +45,9 @@ const DEFAULT_CONFIG: PoolConfig = {
45
45
  };
46
46
 
47
47
  /**
48
- * Chromium launch arguments for stealth (matches test-cf.ts exactly)
48
+ * Chrome launch arguments for stealth (matches test-cf.ts exactly)
49
49
  */
50
- const CHROMIUM_ARGS = [
50
+ const CHROME_ARGS = [
51
51
  '--no-sandbox',
52
52
  '--disable-blink-features=AutomationControlled',
53
53
  '--window-size=1366,768',
@@ -99,18 +99,20 @@ class BrowserPool {
99
99
  private async launchBrowser(): Promise<Browser> {
100
100
  debug.log('preview', '🚀 Launching browser with puppeteer-extra + StealthPlugin...');
101
101
 
102
- // Prefer the clopen-managed Chrome under ~/.clopen/bin, then system Chrome.
103
- // Fall back to puppeteer's `channel: 'chrome'` discovery only if neither exists.
102
+ // Use the clopen-managed Chrome for Testing under ~/.clopen/bin
103
+ // (macOS/Windows) or the system Google Chrome / chromium installed
104
+ // via the distro package manager (Linux).
104
105
  const executablePath = getChromeExecutablePath();
105
- const launchOptions: Parameters<typeof puppeteer.launch>[0] = executablePath
106
- ? { headless: true, executablePath, args: CHROMIUM_ARGS }
107
- : { headless: true, channel: 'chrome', args: CHROMIUM_ARGS };
108
-
109
- if (executablePath) {
110
- debug.log('preview', ` using Chrome at: ${executablePath}`);
106
+ if (!executablePath) {
107
+ throw new Error('Chrome not installed. Go to Settings → System Tools and click Install.');
111
108
  }
109
+ debug.log('preview', ` using Chrome at: ${executablePath}`);
112
110
 
113
- const browser = await puppeteer.launch(launchOptions) as unknown as Browser;
111
+ const browser = await puppeteer.launch({
112
+ headless: true,
113
+ executablePath,
114
+ args: CHROME_ARGS
115
+ }) as unknown as Browser;
114
116
 
115
117
  debug.log('preview', '✅ Browser launched successfully');
116
118
 
@@ -1,11 +1,16 @@
1
1
  /**
2
2
  * Cloudflared Binary Manager
3
3
  *
4
- * Handles downloading and managing the cloudflared binary.
5
- * Replaces the `cloudflared` npm package for binary management.
4
+ * Handles resolving and managing the cloudflared binary.
6
5
  *
7
- * Binary is stored in ~/.clopen/bin/cloudflared (or .clopen-dev for dev)
8
- * Downloads from GitHub releases: https://github.com/cloudflare/cloudflared/releases
6
+ * Primary install path is ~/.clopen/bin/cloudflared (.clopen-dev in dev), which
7
+ * the System Tools installer downloads from GitHub releases. A system-wide
8
+ * cloudflared (e.g. brew, apt) is also honored via PATH so users who already
9
+ * have it on their machine don't have to install through clopen.
10
+ *
11
+ * installBinary() is kept for programmatic use (CLI, one-off scripts) but
12
+ * the server never auto-downloads — tunnel flows fail with a pointer to
13
+ * Settings → System Tools when the binary is missing.
9
14
  */
10
15
 
11
16
  import { existsSync, mkdirSync, createWriteStream, chmodSync, unlinkSync, renameSync } from 'fs';
@@ -13,6 +18,7 @@ import { join, dirname } from 'path';
13
18
  import { platform, arch } from 'os';
14
19
  import { execSync } from 'child_process';
15
20
  import { getClopenDir } from '../../utils/paths';
21
+ import { resolveBinary } from '../../utils/cli';
16
22
  import { debug } from '$shared/utils/logger';
17
23
 
18
24
  const RELEASE_BASE = 'https://github.com/cloudflare/cloudflared/releases/';
@@ -47,6 +53,18 @@ export function isBinaryInstalled(): boolean {
47
53
  return existsSync(getBinaryPath());
48
54
  }
49
55
 
56
+ /**
57
+ * Resolve an executable cloudflared binary. Prefers the System Tools install
58
+ * under ~/.clopen/bin; falls back to any cloudflared on PATH so users who
59
+ * installed it via brew/apt/winget don't have to reinstall via clopen.
60
+ * Returns null when nothing is found.
61
+ */
62
+ export function resolveCloudflaredBinary(): string | null {
63
+ const managed = getBinaryPath();
64
+ if (existsSync(managed)) return managed;
65
+ return resolveBinary('cloudflared');
66
+ }
67
+
50
68
  /** Download a file via HTTPS, following redirects */
51
69
  function download(url: string, to: string, redirect = 0): Promise<string> {
52
70
  if (redirect > 10) {
@@ -5,9 +5,10 @@
5
5
  * Provides binary management and tunnel process control.
6
6
  */
7
7
 
8
- export { getBinaryPath, isBinaryInstalled, installBinary } from './binary';
8
+ export { getBinaryPath, isBinaryInstalled, installBinary, resolveCloudflaredBinary } from './binary';
9
9
  export {
10
10
  CloudflaredTunnel,
11
+ CloudflaredMissingError,
11
12
  type ConnectionInfo,
12
13
  type LoginHandle,
13
14
  type LoginCallbacks,