@myrialabs/clopen 0.3.5 → 0.3.6

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, and Chromium 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
 
@@ -2,7 +2,7 @@
2
2
  * System Tool Install Recipes
3
3
  *
4
4
  * Data-driven registry of install commands for system tools that clopen
5
- * depends on (Git, Claude Code, OpenCode, Chrome for puppeteer). Each
5
+ * depends on (Git, Claude Code, OpenCode, Chromium for puppeteer). Each
6
6
  * recipe is platform-aware and privilege-aware: when the runner cannot
7
7
  * reasonably complete the install non-interactively (e.g. `apt` without
8
8
  * root, `choco` without Administrator), the recipe is marked
@@ -14,14 +14,14 @@
14
14
  */
15
15
 
16
16
  import { homedir } from 'node:os';
17
- import { existsSync, readdirSync } from 'node:fs';
17
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
18
18
  import { join } from 'node:path';
19
19
  import { isElevated } from '$backend/utils/privilege';
20
20
  import { getClopenDir } from '$backend/utils/paths';
21
21
  import { resolveBinary, resolveBinaryWithRefresh } from '$backend/utils/cli';
22
22
  import { resolveStaticCurlAsset } from '$backend/utils/static-curl';
23
23
 
24
- export type ToolId = 'git' | 'claude' | 'opencode' | 'chrome';
24
+ export type ToolId = 'git' | 'claude' | 'opencode' | 'chromium';
25
25
 
26
26
  export interface ManualInstruction {
27
27
  label: string;
@@ -99,16 +99,19 @@ function detectMacPkgMgr(): 'brew' | null {
99
99
  }
100
100
 
101
101
  // ─────────────────────────────────────────────────────────────────────────────
102
- // Chrome detection via puppeteer cache layout
102
+ // Chromium detection
103
103
  // ─────────────────────────────────────────────────────────────────────────────
104
104
 
105
105
  /**
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.
106
+ * Resolve the Chromium executable path under ~/.clopen/bin using the
107
+ * @puppeteer/browsers cache layout: <cache>/chromium/<platform>-<buildId>/<archive>/<binary>.
108
+ * Only macOS and Windows install via @puppeteer/browsers — on Linux we
109
+ * delegate to the distro package manager and skip this scan.
109
110
  */
110
- export function resolveClopenChromePath(): string | null {
111
- const cacheDir = join(getClopenDir(), 'bin', 'chrome');
111
+ export function resolveClopenChromiumPath(): string | null {
112
+ if (process.platform !== 'darwin' && process.platform !== 'win32') return null;
113
+
114
+ const cacheDir = join(getClopenDir(), 'bin', 'chromium');
112
115
  if (!existsSync(cacheDir)) return null;
113
116
 
114
117
  try {
@@ -117,17 +120,10 @@ export function resolveClopenChromePath(): string | null {
117
120
  const buildDir = join(cacheDir, entry);
118
121
  let candidate: string;
119
122
  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');
123
+ candidate = join(buildDir, 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium');
128
124
  if (existsSync(candidate)) return candidate;
129
125
  } else {
130
- candidate = join(buildDir, 'chrome-linux64', 'chrome');
126
+ candidate = join(buildDir, 'chrome-win', 'chrome.exe');
131
127
  if (existsSync(candidate)) return candidate;
132
128
  }
133
129
  }
@@ -137,40 +133,29 @@ export function resolveClopenChromePath(): string | null {
137
133
  return null;
138
134
  }
139
135
 
140
- function detectSystemChrome(): string | null {
136
+ function detectSystemChromium(): string | null {
141
137
  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
- ];
138
+ const paths = ['/Applications/Chromium.app/Contents/MacOS/Chromium'];
147
139
  for (const p of paths) if (existsSync(p)) return p;
148
140
  return null;
149
141
  }
150
142
  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
- 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')
158
- ];
159
- for (const p of paths) if (existsSync(p)) return p;
160
- return null;
143
+ // Chromium has no canonical Windows install location; rely on PATH.
144
+ return resolveBinary('chromium');
161
145
  }
162
- return resolveBinary('google-chrome')
163
- ?? resolveBinary('google-chrome-stable')
164
- ?? resolveBinary('chromium')
165
- ?? resolveBinary('chromium-browser');
146
+ // Linux: distro package + snap (Ubuntu).
147
+ const snapPath = '/snap/bin/chromium';
148
+ if (existsSync(snapPath)) return snapPath;
149
+ return resolveBinary('chromium') ?? resolveBinary('chromium-browser');
166
150
  }
167
151
 
168
152
  /**
169
- * Preferred executable path for puppeteer. Clopen-managed install wins
170
- * over system Chrome so users can keep the bundled version consistent.
153
+ * Preferred Chromium executable path for puppeteer. Clopen-managed install
154
+ * (macOS/Windows via @puppeteer/browsers) wins over system Chromium so the
155
+ * bundled version stays consistent; on Linux only the system path is used.
171
156
  */
172
- export function getChromeExecutablePath(): string | null {
173
- return resolveClopenChromePath() ?? detectSystemChrome();
157
+ export function getChromiumExecutablePath(): string | null {
158
+ return resolveClopenChromiumPath() ?? detectSystemChromium();
174
159
  }
175
160
 
176
161
  // ─────────────────────────────────────────────────────────────────────────────
@@ -191,11 +176,11 @@ async function runVersion(binary: string, versionFlag = '--version'): Promise<st
191
176
  }
192
177
 
193
178
  export async function getToolStatus(tool: ToolId): Promise<ToolStatus> {
194
- if (tool === 'chrome') {
195
- const resolved = getChromeExecutablePath();
179
+ if (tool === 'chromium') {
180
+ const resolved = getChromiumExecutablePath();
196
181
  if (!resolved) return { tool, installed: false, version: null, source: null };
197
182
  const version = await runVersion(resolved);
198
- const source = resolveClopenChromePath() ? 'clopen' : 'system';
183
+ const source = resolveClopenChromiumPath() ? 'clopen' : 'system';
199
184
  return { tool, installed: true, version, source };
200
185
  }
201
186
 
@@ -398,23 +383,195 @@ async function resolveOpenCodeRecipe(): Promise<Recipe> {
398
383
  return base;
399
384
  }
400
385
 
401
- async function resolveChromeRecipe(): Promise<Recipe> {
386
+ // ─────────────────────────────────────────────────────────────────────────────
387
+ // Linux distro detection (apt sub-flavour: Debian vs Ubuntu)
388
+ // ─────────────────────────────────────────────────────────────────────────────
389
+
390
+ interface LinuxDistro {
391
+ id: string;
392
+ idLike: string[];
393
+ }
394
+
395
+ function readLinuxDistro(): LinuxDistro | null {
396
+ try {
397
+ const text = readFileSync('/etc/os-release', 'utf8');
398
+ const fields: Record<string, string> = {};
399
+ for (const line of text.split('\n')) {
400
+ const eq = line.indexOf('=');
401
+ if (eq < 0) continue;
402
+ const key = line.slice(0, eq).trim();
403
+ let value = line.slice(eq + 1).trim();
404
+ if (value.startsWith('"') && value.endsWith('"')) value = value.slice(1, -1);
405
+ fields[key] = value;
406
+ }
407
+ return {
408
+ id: (fields['ID'] ?? '').toLowerCase(),
409
+ idLike: (fields['ID_LIKE'] ?? '').toLowerCase().split(/\s+/).filter(Boolean)
410
+ };
411
+ } catch {
412
+ return null;
413
+ }
414
+ }
415
+
416
+ function isUbuntuLike(distro: LinuxDistro | null): boolean {
417
+ if (!distro) return false;
418
+ if (distro.id === 'ubuntu') return true;
419
+ return distro.idLike.includes('ubuntu');
420
+ }
421
+
422
+ // ─────────────────────────────────────────────────────────────────────────────
423
+ // Chromium recipe — Puppeteer download (macOS/Windows) or distro pkg (Linux)
424
+ // ─────────────────────────────────────────────────────────────────────────────
425
+
426
+ const PPTR_CHROMIUM_DOCS = 'https://pptr.dev/browsers-api';
427
+ const PPTR_LINUX_DOCS = 'https://pptr.dev/troubleshooting#chrome-doesnt-launch-on-linux';
428
+
429
+ async function resolveChromiumRecipe(): Promise<Recipe> {
402
430
  const cacheDir = join(getClopenDir(), 'bin');
431
+ const pptrArgs = ['bun', 'x', '@puppeteer/browsers', 'install', 'chromium@latest', '--path', cacheDir];
432
+ const pptrDisplay = `bun x @puppeteer/browsers install chromium@latest --path "${cacheDir}"`;
433
+
434
+ // macOS / Windows: Puppeteer download is self-contained.
435
+ if (process.platform === 'darwin' || process.platform === 'win32') {
436
+ return {
437
+ tool: 'chromium',
438
+ autoInstallable: true,
439
+ missingPrereqs: [],
440
+ manualInstructions: [{
441
+ label: 'Puppeteer browsers CLI',
442
+ command: pptrDisplay,
443
+ docs: PPTR_CHROMIUM_DOCS
444
+ }],
445
+ command: pptrArgs,
446
+ displayCommand: pptrDisplay
447
+ };
448
+ }
449
+
450
+ // Linux: delegate to distro package manager so deps auto-resolve.
451
+ return resolveLinuxChromiumRecipe();
452
+ }
453
+
454
+ interface LinuxChromiumStrategy {
455
+ pkgMgrLabel: string;
456
+ /** Argv-form command to spawn (sh -c <string>). */
457
+ installCommand: string;
458
+ /** User-facing display command (with sudo prefix if interactive). */
459
+ manualCommand: string;
460
+ /** Extra env to inject into the spawn. */
461
+ env?: Record<string, string>;
462
+ }
463
+
464
+ async function resolveLinuxChromiumRecipe(): Promise<Recipe> {
465
+ const distro = readLinuxDistro();
466
+ const ubuntuLike = isUbuntuLike(distro);
467
+ const mgr = detectLinuxPkgMgr();
468
+
469
+ const manual: ManualInstruction[] = [];
470
+
471
+ // Always surface the recommended manual command(s) for this platform.
472
+ const strategy = pickLinuxChromiumStrategy(mgr, ubuntuLike);
473
+
474
+ if (strategy) {
475
+ manual.push({
476
+ label: `${strategy.pkgMgrLabel} (recommended)`,
477
+ command: strategy.manualCommand,
478
+ docs: PPTR_LINUX_DOCS
479
+ });
480
+ }
481
+
482
+ // Ubuntu users may want a non-snap fallback; mention common alternatives.
483
+ if (ubuntuLike) {
484
+ manual.push({
485
+ label: 'Ubuntu — install snapd first if missing',
486
+ command: 'sudo apt-get update && sudo apt-get install -y snapd && sudo snap install chromium',
487
+ docs: 'https://snapcraft.io/chromium'
488
+ });
489
+ }
490
+
403
491
  const base: Recipe = {
404
- tool: 'chrome',
405
- autoInstallable: true,
492
+ tool: 'chromium',
493
+ autoInstallable: false,
406
494
  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}`
495
+ manualInstructions: manual
414
496
  };
497
+
498
+ if (!mgr || !strategy) {
499
+ base.unavailableReason = mgr
500
+ ? `No Chromium install strategy is mapped for ${mgr} on this distro. Install Chromium manually with your package manager.`
501
+ : 'No supported Linux package manager found (apt / dnf / pacman / apk / zypper). Install Chromium manually.';
502
+ return base;
503
+ }
504
+
505
+ if (ubuntuLike && !resolveBinary('snap')) {
506
+ base.unavailableReason = 'Ubuntu Chromium is distributed as a snap, but snapd is not installed on this system. Install snapd first (`sudo apt-get install -y snapd`), then retry — or use the manual instructions below.';
507
+ return base;
508
+ }
509
+
510
+ const elevated = await isElevated();
511
+ if (!elevated) {
512
+ base.unavailableReason = `Installing Chromium via ${strategy.pkgMgrLabel} requires root. Run clopen as root, or install Chromium manually with the command below and retry.`;
513
+ return base;
514
+ }
515
+
516
+ base.autoInstallable = true;
517
+ base.shell = { program: 'sh', args: ['-c'] };
518
+ base.command = [strategy.installCommand];
519
+ base.displayCommand = strategy.manualCommand;
520
+ if (strategy.env) base.env = strategy.env;
415
521
  return base;
416
522
  }
417
523
 
524
+ function pickLinuxChromiumStrategy(
525
+ mgr: LinuxPkgMgr | null,
526
+ ubuntuLike: boolean
527
+ ): LinuxChromiumStrategy | null {
528
+ if (mgr === 'apt' && ubuntuLike) {
529
+ // Ubuntu's `chromium` / `chromium-browser` deb is a snap shim. Use snap directly.
530
+ return {
531
+ pkgMgrLabel: 'snap',
532
+ installCommand: 'snap install chromium',
533
+ manualCommand: 'sudo snap install chromium'
534
+ };
535
+ }
536
+ if (mgr === 'apt') {
537
+ return {
538
+ pkgMgrLabel: 'apt',
539
+ installCommand: 'apt-get update && apt-get install -y chromium',
540
+ manualCommand: 'sudo apt-get update && sudo apt-get install -y chromium',
541
+ env: { DEBIAN_FRONTEND: 'noninteractive' }
542
+ };
543
+ }
544
+ if (mgr === 'dnf') {
545
+ return {
546
+ pkgMgrLabel: 'dnf',
547
+ installCommand: 'dnf install -y chromium',
548
+ manualCommand: 'sudo dnf install -y chromium'
549
+ };
550
+ }
551
+ if (mgr === 'pacman') {
552
+ return {
553
+ pkgMgrLabel: 'pacman',
554
+ installCommand: 'pacman -S --noconfirm chromium',
555
+ manualCommand: 'sudo pacman -S --noconfirm chromium'
556
+ };
557
+ }
558
+ if (mgr === 'apk') {
559
+ return {
560
+ pkgMgrLabel: 'apk',
561
+ installCommand: 'apk add --no-cache chromium',
562
+ manualCommand: 'sudo apk add --no-cache chromium'
563
+ };
564
+ }
565
+ if (mgr === 'zypper') {
566
+ return {
567
+ pkgMgrLabel: 'zypper',
568
+ installCommand: 'zypper --non-interactive install chromium',
569
+ manualCommand: 'sudo zypper install chromium'
570
+ };
571
+ }
572
+ return null;
573
+ }
574
+
418
575
  /**
419
576
  * Resolve the install recipe for a tool on the current platform.
420
577
  * Result is platform- and privilege-aware: recipes that would fail
@@ -425,6 +582,6 @@ export async function resolveRecipe(tool: ToolId): Promise<Recipe> {
425
582
  case 'git': return resolveGitRecipe();
426
583
  case 'claude': return resolveClaudeRecipe();
427
584
  case 'opencode': return resolveOpenCodeRecipe();
428
- case 'chrome': return resolveChromeRecipe();
585
+ case 'chromium': return resolveChromiumRecipe();
429
586
  }
430
587
  }
@@ -19,7 +19,7 @@ import type { Browser, BrowserContext, Page } from 'puppeteer';
19
19
  import { debug } from '$shared/utils/logger';
20
20
  import puppeteer from 'puppeteer-extra';
21
21
  import StealthPlugin from 'puppeteer-extra-plugin-stealth';
22
- import { getChromeExecutablePath } from '$backend/engine/install-recipes';
22
+ import { getChromiumExecutablePath } from '$backend/engine/install-recipes';
23
23
 
24
24
  puppeteer.use(StealthPlugin());
25
25
 
@@ -99,18 +99,19 @@ 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.
104
- 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}`);
102
+ // Use the clopen-managed Chromium under ~/.clopen/bin (macOS/Windows)
103
+ // or the system Chromium installed via the distro package manager (Linux).
104
+ const executablePath = getChromiumExecutablePath();
105
+ if (!executablePath) {
106
+ throw new Error('Chromium not installed. Go to Settings → System Tools and click Install.');
111
107
  }
108
+ debug.log('preview', ` using Chromium at: ${executablePath}`);
112
109
 
113
- const browser = await puppeteer.launch(launchOptions) as unknown as Browser;
110
+ const browser = await puppeteer.launch({
111
+ headless: true,
112
+ executablePath,
113
+ args: CHROMIUM_ARGS
114
+ }) as unknown as Browser;
114
115
 
115
116
  debug.log('preview', '✅ Browser launched successfully');
116
117
 
@@ -16,9 +16,9 @@
16
16
  * the stunnel team. Release: https://github.com/stunnel/static-curl
17
17
  */
18
18
 
19
- import { existsSync, readdirSync, mkdirSync, mkdtempSync, chmodSync, renameSync, rmSync } from 'node:fs';
19
+ import { existsSync, readdirSync, mkdirSync, chmodSync, renameSync } from 'node:fs';
20
20
  import { join, dirname } from 'node:path';
21
- import { tmpdir } from 'node:os';
21
+ import { XzReadableStream } from 'xz-decompress';
22
22
  import { debug } from '$shared/utils/logger';
23
23
  import { getClopenDir } from '$backend/utils/paths';
24
24
  import { resolveBinary } from '$backend/utils/cli';
@@ -98,19 +98,65 @@ export function hasCachedStaticCurl(): boolean {
98
98
  return existsSync(getStaticCurlPath());
99
99
  }
100
100
 
101
- async function sha256OfFile(path: string): Promise<string> {
101
+ function sha256(bytes: Uint8Array): string {
102
102
  const hasher = new Bun.CryptoHasher('sha256');
103
- const reader = Bun.file(path).stream().getReader();
104
- try {
105
- while (true) {
106
- const { done, value } = await reader.read();
107
- if (done) break;
108
- hasher.update(value);
103
+ hasher.update(bytes);
104
+ return hasher.digest('hex');
105
+ }
106
+
107
+ function parseTarOctal(bytes: Uint8Array): number {
108
+ let end = bytes.length;
109
+ for (let i = 0; i < bytes.length; i++) {
110
+ if (bytes[i] === 0 || bytes[i] === 0x20) {
111
+ end = i;
112
+ break;
109
113
  }
110
- } finally {
111
- reader.releaseLock();
112
114
  }
113
- return hasher.digest('hex');
115
+ const str = new TextDecoder().decode(bytes.subarray(0, end)).trim();
116
+ return str === '' ? 0 : parseInt(str, 8);
117
+ }
118
+
119
+ /**
120
+ * Minimal POSIX tar reader: walks header blocks and returns the first
121
+ * regular file whose name matches. Sufficient for static-curl archives
122
+ * which contain `curl` at the root with a short name.
123
+ */
124
+ function findFileInTar(tarBytes: Uint8Array, filename: string): Uint8Array | null {
125
+ const decoder = new TextDecoder();
126
+ let offset = 0;
127
+ while (offset + 512 <= tarBytes.length) {
128
+ const header = tarBytes.subarray(offset, offset + 512);
129
+ let allZero = true;
130
+ for (let i = 0; i < 512; i++) {
131
+ if (header[i] !== 0) { allZero = false; break; }
132
+ }
133
+ if (allZero) return null;
134
+
135
+ const nameBytes = header.subarray(0, 100);
136
+ const nameEnd = nameBytes.indexOf(0);
137
+ const name = decoder.decode(nameEnd >= 0 ? nameBytes.subarray(0, nameEnd) : nameBytes);
138
+ const size = parseTarOctal(header.subarray(124, 136));
139
+ const typeflag = header[156];
140
+ const isRegularFile = typeflag === 0 || typeflag === 0x30; // '\0' or '0'
141
+
142
+ offset += 512;
143
+ if (isRegularFile && name === filename) {
144
+ return tarBytes.subarray(offset, offset + size);
145
+ }
146
+ offset += Math.ceil(size / 512) * 512;
147
+ }
148
+ return null;
149
+ }
150
+
151
+ async function decompressXz(xzBytes: Uint8Array): Promise<Uint8Array> {
152
+ const input = new ReadableStream<Uint8Array>({
153
+ start(controller) {
154
+ controller.enqueue(xzBytes);
155
+ controller.close();
156
+ }
157
+ });
158
+ const decompressed = new Response(new XzReadableStream(input));
159
+ return new Uint8Array(await decompressed.arrayBuffer());
114
160
  }
115
161
 
116
162
  export type CurlProgressPhase = 'cached' | 'fetching' | 'verifying' | 'extracting' | 'done';
@@ -148,51 +194,35 @@ export async function ensureCurlAvailable(
148
194
  }
149
195
 
150
196
  mkdirSync(binDir, { recursive: true });
151
- const workDir = mkdtempSync(join(tmpdir(), 'clopen-curl-'));
152
- const archivePath = join(workDir, 'curl.tar.xz');
153
-
154
- try {
155
- onProgress({ phase: 'fetching', message: `downloading ${asset.url}` });
156
- const response = await fetch(asset.url, { redirect: 'follow' });
157
- if (!response.ok) {
158
- throw new Error(`HTTP ${response.status} ${response.statusText}`);
159
- }
160
- await Bun.write(archivePath, response);
161
197
 
162
- onProgress({ phase: 'verifying', message: `verifying SHA256 ${asset.sha256}` });
163
- const actualSha = await sha256OfFile(archivePath);
164
- if (actualSha !== asset.sha256) {
165
- throw new Error(`SHA256 mismatch: expected ${asset.sha256}, got ${actualSha}`);
166
- }
198
+ onProgress({ phase: 'fetching', message: `downloading ${asset.url}` });
199
+ const response = await fetch(asset.url, { redirect: 'follow' });
200
+ if (!response.ok) {
201
+ throw new Error(`HTTP ${response.status} ${response.statusText}`);
202
+ }
203
+ const archiveBytes = new Uint8Array(await response.arrayBuffer());
167
204
 
168
- onProgress({ phase: 'extracting', message: `extracting curl to ${binDir}` });
169
- const proc = Bun.spawn(['tar', '-xJf', archivePath, '-C', workDir, 'curl'], {
170
- stdout: 'pipe',
171
- stderr: 'pipe'
172
- });
173
- const exit = await proc.exited;
174
- if (exit !== 0) {
175
- const stderr = (await new Response(proc.stderr).text()).trim();
176
- throw new Error(`tar extract failed (exit ${exit}): ${stderr || 'unknown error'}`);
177
- }
205
+ onProgress({ phase: 'verifying', message: `verifying SHA256 ${asset.sha256}` });
206
+ const actualSha = sha256(archiveBytes);
207
+ if (actualSha !== asset.sha256) {
208
+ throw new Error(`SHA256 mismatch: expected ${asset.sha256}, got ${actualSha}`);
209
+ }
178
210
 
179
- const extractedBinary = join(workDir, 'curl');
180
- if (!existsSync(extractedBinary)) {
181
- throw new Error('tar succeeded but curl binary not found in archive');
182
- }
211
+ onProgress({ phase: 'extracting', message: `extracting curl to ${binDir}` });
212
+ const tarBytes = await decompressXz(archiveBytes);
213
+ const curlBytes = findFileInTar(tarBytes, 'curl');
214
+ if (!curlBytes) {
215
+ throw new Error('curl binary not found in archive');
216
+ }
183
217
 
184
- // Atomic move — finalPath either exists and is valid, or doesn't exist.
185
- renameSync(extractedBinary, finalPath);
186
- chmodSync(finalPath, 0o755);
218
+ // Write via a sibling tmp path then rename, so finalPath is always
219
+ // either absent or a complete, valid binary.
220
+ const tmpPath = `${finalPath}.tmp-${process.pid}`;
221
+ await Bun.write(tmpPath, curlBytes);
222
+ chmodSync(tmpPath, 0o755);
223
+ renameSync(tmpPath, finalPath);
187
224
 
188
- onProgress({ phase: 'done', message: `curl installed at ${finalPath}` });
189
- debug.log('path', `static-curl: installed ${asset.archKey} v${asset.version} at ${finalPath}`);
190
- return binDir;
191
- } finally {
192
- try {
193
- rmSync(workDir, { recursive: true, force: true });
194
- } catch {
195
- // best-effort cleanup
196
- }
197
- }
225
+ onProgress({ phase: 'done', message: `curl installed at ${finalPath}` });
226
+ debug.log('path', `static-curl: installed ${asset.archKey} v${asset.version} at ${finalPath}`);
227
+ return binDir;
198
228
  }
@@ -66,7 +66,7 @@ export const wsRouter = createRouter()
66
66
  // AI Engine Management
67
67
  .merge(engineRouter)
68
68
 
69
- // System Tools (install Git, Claude Code, OpenCode, Chrome binaries)
69
+ // System Tools (install Git, Claude Code, OpenCode, Chromium binaries)
70
70
  .merge(systemToolsRouter);
71
71
 
72
72
  // Export API type for frontend type-safe access
@@ -23,7 +23,7 @@ const TOOL_UNION = t.Union([
23
23
  t.Literal('git'),
24
24
  t.Literal('claude'),
25
25
  t.Literal('opencode'),
26
- t.Literal('chrome')
26
+ t.Literal('chromium')
27
27
  ]);
28
28
 
29
29
  const STATUS_UNION = t.Union([
@@ -2,7 +2,7 @@
2
2
  * System Tool Status Handlers
3
3
  *
4
4
  * Reports installation status for each managed tool (git, claude,
5
- * opencode, chrome). The corresponding recipe is bundled so the
5
+ * opencode, chromium). The corresponding recipe is bundled so the
6
6
  * frontend can render the install button state and manual fallback
7
7
  * without a second round-trip.
8
8
  */
@@ -17,7 +17,7 @@ const TOOL_UNION = t.Union([
17
17
  t.Literal('git'),
18
18
  t.Literal('claude'),
19
19
  t.Literal('opencode'),
20
- t.Literal('chrome')
20
+ t.Literal('chromium')
21
21
  ]);
22
22
 
23
23
  const RECIPE_SCHEMA = t.Object({
@@ -66,7 +66,7 @@ const ACTIVE_SESSION_SCHEMA = t.Union([
66
66
  })
67
67
  ]);
68
68
 
69
- function toRecipeDTO(tool: 'git' | 'claude' | 'opencode' | 'chrome', recipe: Awaited<ReturnType<typeof resolveRecipe>>) {
69
+ function toRecipeDTO(tool: 'git' | 'claude' | 'opencode' | 'chromium', recipe: Awaited<ReturnType<typeof resolveRecipe>>) {
70
70
  return {
71
71
  tool,
72
72
  autoInstallable: recipe.autoInstallable,
@@ -109,7 +109,7 @@ export const systemToolsStatusHandler = createRouter()
109
109
  })
110
110
  }, async () => {
111
111
  debug.log('path', 'system-tools:status-all');
112
- const ids = ['git', 'claude', 'opencode', 'chrome'] as const;
112
+ const ids = ['git', 'claude', 'opencode', 'chromium'] as const;
113
113
  const tools = await Promise.all(ids.map(async (id) => {
114
114
  const [status, recipe] = await Promise.all([
115
115
  getToolStatus(id),