Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/browser/daemon-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as fs from 'node:fs';
import * as path from 'node:path';
import { DEFAULT_DAEMON_PORT } from '../constants.js';
import { BrowserConnectError } from '../errors.js';
import { findPackageRoot, hasLocalExtensionSource } from '../package-paths.js';
import { PKG_VERSION } from '../version.js';
import { waitForBridgeReady } from './bridge-readiness.js';
import { fetchDaemonStatus, getDaemonHealth, requestDaemonShutdown, type DaemonHealth, type DaemonStatus } from './daemon-transport.js';
Expand Down Expand Up @@ -181,12 +182,17 @@ function browserConnectErrorFromHealth(health: DaemonHealth, contextId?: string)
);
}
if (health.state === 'no-extension') {
const packageRoot = findPackageRoot(fileURLToPath(import.meta.url));
const installSteps = hasLocalExtensionSource(packageRoot)
? ' 1. Open chrome://extensions → Developer Mode → Load unpacked\n' +
` 2. Select this checkout's extension/ folder (${path.join(packageRoot, 'extension')})`
: ' 1. Download: https://github.com/jackwener/opencli/releases\n' +
' 2. Open chrome://extensions → Developer Mode → Load unpacked';
return new BrowserConnectError(
'Browser Bridge extension not connected',
'Make sure Chrome/Chromium is open and the OpenCLI extension is enabled.\n' +
'If not installed:\n' +
' 1. Download: https://github.com/jackwener/opencli/releases\n' +
' 2. Open chrome://extensions → Developer Mode → Load unpacked',
installSteps,
'extension-not-connected',
);
}
Expand Down
14 changes: 11 additions & 3 deletions src/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Simplified for the daemon-based architecture.
*/

import { fileURLToPath } from 'node:url';
import * as path from 'node:path';
import { DEFAULT_DAEMON_PORT } from './constants.js';
import { BrowserBridge } from './browser/index.js';
import { setDaemonCommandTimeoutSeconds } from './browser/daemon-client.js';
Expand All @@ -15,6 +17,7 @@ import type { BrowserProfileStatus } from './browser/daemon-transport.js';
import { aliasForContextId, loadProfileConfig } from './browser/profile.js';
import { formatDaemonVersion, isDaemonStale, staleDaemonIssue } from './browser/daemon-version.js';
import { findShadowedUserAdapters, formatAdapterShadowIssue, type AdapterShadow } from './adapter-shadow.js';
import { findPackageRoot, hasLocalExtensionSource } from './package-paths.js';

const DOCTOR_LIVE_TIMEOUT_SECONDS = 8;
const DOCTOR_SESSION = '__doctor__';
Expand Down Expand Up @@ -151,13 +154,18 @@ export async function runBrowserDoctor(opts: DoctorOptions = {}): Promise<Doctor
' Open that Chrome profile and make sure the OpenCLI extension is enabled.',
);
} else {
const packageRoot = findPackageRoot(fileURLToPath(import.meta.url));
const installSteps = hasLocalExtensionSource(packageRoot)
? ' 1. Open chrome://extensions/ → Enable Developer Mode\n' +
` 2. Click "Load unpacked" → select this checkout's extension/ folder (${path.join(packageRoot, 'extension')})`
: ' 1. Download from https://github.com/jackwener/opencli/releases\n' +
' 2. Open chrome://extensions/ → Enable Developer Mode\n' +
' 3. Click "Load unpacked" → select the unzipped folder';
issues.push(
'Daemon is running but the Chrome/Chromium extension is not connected.\n' +
'If the extension is already installed, try: opencli daemon restart\n' +
'If the extension is not installed:\n' +
' 1. Download from https://github.com/jackwener/opencli/releases\n' +
' 2. Open chrome://extensions/ → Enable Developer Mode\n' +
' 3. Click "Load unpacked" → select the extension folder',
installSteps,
);
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/package-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,16 @@ export function getCliManifestPath(clisDir: string): string {
export function getFetchAdaptersScriptPath(packageRoot: string): string {
return path.join(packageRoot, 'scripts', 'fetch-adapters.js');
}

/**
* True when a Browser Bridge extension source tree is sitting next to this
* checkout (dev/source checkout of the OpenCLI repo itself). The published
* npm package's `files` list excludes `extension/`, so this is false for a
* real global install — those users need the release zip instead.
*/
export function hasLocalExtensionSource(
packageRoot: string,
fileExists: (candidate: string) => boolean = fs.existsSync,
): boolean {
return fileExists(path.join(packageRoot, 'extension', 'manifest.json'));
}