@dassi_ai/cli 0.3.0 → 0.4.0
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/.claude-plugin/plugin.json +1 -1
- package/README.md +27 -0
- package/_launch-pipe.mjs +102 -0
- package/dassi.mjs +9 -9
- package/help-text.mjs +4 -2
- package/launch.mjs +221 -53
- package/package.json +2 -1
- package/skills/operate/command-reference.md +15 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dassi",
|
|
3
3
|
"description": "Drive the Dassi Chrome extension from Claude Code. Pick tabs/groups, then run AI agent or browser tools against them.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Omnify Labs",
|
|
7
7
|
"email": "team@dassi.ai"
|
package/README.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
Standalone CLI for the [Dassi](../extension/README.md) Chrome extension — run browser automation from the terminal.
|
|
4
4
|
|
|
5
|
+
## Quickstart
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# 1. Install the Dassi extension from the Chrome Web Store and sign in.
|
|
9
|
+
# 2. Open the Dassi side panel once — this wakes the extension so the CLI can reach it.
|
|
10
|
+
# 3. Run a command (no install needed):
|
|
11
|
+
npx @dassi_ai/cli@latest list-tabs # find a TAB ID
|
|
12
|
+
npx @dassi_ai/cli@latest run "summarize this page" --tab <id>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Prefer a permanent `dassi` command? `npm install -g @dassi_ai/cli` (Node ≥ 20.11), then drop the `npx @dassi_ai/cli@latest` prefix.
|
|
16
|
+
|
|
17
|
+
Two things that trip people up:
|
|
18
|
+
- **`run` needs a target** — pass `--tab <id>` (or `--group <id>` / `--group-title <name>`). `--profile` only selects *which* connected Chrome, not the tab.
|
|
19
|
+
- **Multiple Chrome windows/profiles connected?** Commands need `--profile <label>`; run `dassi list-profiles` to see the labels (one profile = no flag needed).
|
|
20
|
+
|
|
5
21
|
## Installation
|
|
6
22
|
|
|
7
23
|
```bash
|
|
@@ -65,6 +81,17 @@ dassi launch --stop # close the "dev" Chrome (or --stop-
|
|
|
65
81
|
# Note: launch reuses the default daemon (port 18790). To launch on an isolated
|
|
66
82
|
# port (DASSI_BRIDGE_PORT=18791 dassi launch), no default daemon may be running —
|
|
67
83
|
# it errors clearly otherwise, since it can't confirm the running daemon's port.
|
|
84
|
+
#
|
|
85
|
+
# How the extension is loaded (auto-detected per Chrome binary):
|
|
86
|
+
# • Branded Google Chrome (137+) disabled the `--load-extension` flag, so launch
|
|
87
|
+
# installs the dist at runtime via the `Extensions.loadUnpacked` CDP command over
|
|
88
|
+
# `--remote-debugging-pipe`. Because such an extension lives only as long as the
|
|
89
|
+
# debugging pipe, launch spawns a detached `__launch-hold` helper that keeps the
|
|
90
|
+
# pipe open; `--stop` kills the helper, which closes the pipe and its Chrome.
|
|
91
|
+
# • Chrome for Testing / Chromium still honour `--load-extension` (persistent), so
|
|
92
|
+
# launch uses that directly there — no helper. Point at one with `--chrome <path>`.
|
|
93
|
+
# • The mode is auto-detected from the binary; override with `--load-mode auto|pipe|flag`
|
|
94
|
+
# (e.g. `dassi launch --chrome <cft> --load-mode pipe` to exercise the pipe path on CfT).
|
|
68
95
|
|
|
69
96
|
# Show version / help
|
|
70
97
|
dassi --version
|
package/_launch-pipe.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CDP-over-pipe transport for `dassi launch`. Chrome 137+ branded builds disabled the
|
|
3
|
+
* `--load-extension` flag, so the dist is installed at runtime via the
|
|
4
|
+
* `Extensions.loadUnpacked` CDP command over `--remote-debugging-pipe`. This module is
|
|
5
|
+
* the minimal, dependency-free client for that exchange.
|
|
6
|
+
*
|
|
7
|
+
* PRIVATE (underscore-prefixed): import these symbols from `launch.mjs`, which re-exports
|
|
8
|
+
* them. `launch.mjs` is the single public gateway for the launch module.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Minimal CDP client over Chrome's `--remote-debugging-pipe` transport. Messages are
|
|
13
|
+
* JSON framed with a trailing NUL (`\0`) byte; replies are matched back by `id`.
|
|
14
|
+
* No external deps — the CLI only needs to issue a couple of commands at launch.
|
|
15
|
+
* @param {{ writable: import('stream').Writable; readable: import('stream').Readable }} pipe
|
|
16
|
+
* `writable` = Chrome's CDP input (fd 3); `readable` = Chrome's CDP output (fd 4).
|
|
17
|
+
* @returns {{ send: (method: string, params?: object) => Promise<object>; dispose: () => void }}
|
|
18
|
+
*/
|
|
19
|
+
export function cdpPipeClient({ writable, readable }) {
|
|
20
|
+
let nextId = 1;
|
|
21
|
+
const pending = new Map();
|
|
22
|
+
let buf = Buffer.alloc(0);
|
|
23
|
+
const onData = (chunk) => {
|
|
24
|
+
buf = Buffer.concat([buf, chunk]);
|
|
25
|
+
let nul;
|
|
26
|
+
// Reason: a single chunk may carry several NUL-delimited frames, or a partial one —
|
|
27
|
+
// drain every complete frame and keep the remainder buffered for the next chunk.
|
|
28
|
+
while ((nul = buf.indexOf(0)) !== -1) {
|
|
29
|
+
const frame = buf.subarray(0, nul).toString('utf8');
|
|
30
|
+
buf = buf.subarray(nul + 1);
|
|
31
|
+
if (!frame) continue;
|
|
32
|
+
let msg;
|
|
33
|
+
try { msg = JSON.parse(frame); } catch { continue; }
|
|
34
|
+
const entry = msg.id != null ? pending.get(msg.id) : undefined;
|
|
35
|
+
if (!entry) continue; // an event, or a reply we're not waiting on
|
|
36
|
+
pending.delete(msg.id);
|
|
37
|
+
if (msg.error) entry.reject(new Error(msg.error.message || `CDP error ${msg.error.code ?? ''}`));
|
|
38
|
+
else entry.resolve(msg.result ?? {});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
readable.on('data', onData);
|
|
42
|
+
return {
|
|
43
|
+
send(method, params = {}) {
|
|
44
|
+
const id = nextId++;
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
pending.set(id, { resolve, reject });
|
|
47
|
+
writable.write(`${JSON.stringify({ id, method, params })}\0`);
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
dispose() {
|
|
51
|
+
readable.off('data', onData);
|
|
52
|
+
for (const { reject } of pending.values()) reject(new Error('CDP pipe disposed'));
|
|
53
|
+
pending.clear();
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Install the unpacked dist into the just-launched Chrome over the CDP pipe, then
|
|
60
|
+
* open the seed options page (so the extension persists label+bridgePort and dials
|
|
61
|
+
* the daemon). This is the runtime replacement for the disabled `--load-extension`.
|
|
62
|
+
*
|
|
63
|
+
* On success the pipe is left OPEN (still draining Chrome's CDP output so its buffer
|
|
64
|
+
* can't fill) and a `dispose()` is returned — the caller MUST call it once the
|
|
65
|
+
* profile has registered. Reason: branded Chrome discards an automation-created tab
|
|
66
|
+
* (the seed page) if the debugging pipe closes before it finishes loading; keeping
|
|
67
|
+
* the pipe alive until the bridge registers lets the seed run.
|
|
68
|
+
* @param {{ child: import('child_process').ChildProcess; distPath: string; label: string; bridgePort: number; timeoutMs?: number }} opts
|
|
69
|
+
* @returns {Promise<{ id: string; dispose: () => void }>} the loaded extension id + a pipe closer.
|
|
70
|
+
* @throws if the pipe fds are missing or a CDP command errors/times out.
|
|
71
|
+
*/
|
|
72
|
+
export async function loadExtensionOverPipe({ child, distPath, label, bridgePort, timeoutMs = 15000 }) {
|
|
73
|
+
const writable = child.stdio?.[3];
|
|
74
|
+
const readable = child.stdio?.[4];
|
|
75
|
+
if (!writable || !readable) {
|
|
76
|
+
throw new Error('Chrome was not spawned with a CDP pipe (fds 3/4 missing).');
|
|
77
|
+
}
|
|
78
|
+
const cdp = cdpPipeClient({ writable, readable });
|
|
79
|
+
// Reason: capture + clear the timer so a fast-resolving CDP command doesn't leave a
|
|
80
|
+
// pending setTimeout keeping the event loop alive for the full timeoutMs.
|
|
81
|
+
const withTimeout = (p, what) => {
|
|
82
|
+
let timer;
|
|
83
|
+
const timeout = new Promise((_, r) => {
|
|
84
|
+
timer = setTimeout(() => r(new Error(`CDP ${what} timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
85
|
+
});
|
|
86
|
+
return Promise.race([p, timeout]).finally(() => clearTimeout(timer));
|
|
87
|
+
};
|
|
88
|
+
try {
|
|
89
|
+
const loaded = await withTimeout(cdp.send('Extensions.loadUnpacked', { path: distPath }), 'Extensions.loadUnpacked');
|
|
90
|
+
const id = loaded.id;
|
|
91
|
+
if (!id) throw new Error('Extensions.loadUnpacked returned no extension id.');
|
|
92
|
+
// Reason: open the seed page AFTER the extension exists (it isn't loaded at
|
|
93
|
+
// startup anymore), so the options page persists label+bridgePort and the
|
|
94
|
+
// extension's bridge connects to the daemon's actual port.
|
|
95
|
+
const seed = `chrome-extension://${id}/options.html?label=${encodeURIComponent(label)}&bridgePort=${bridgePort}`;
|
|
96
|
+
await withTimeout(cdp.send('Target.createTarget', { url: seed }), 'Target.createTarget');
|
|
97
|
+
return { id, dispose: () => cdp.dispose() };
|
|
98
|
+
} catch (err) {
|
|
99
|
+
cdp.dispose();
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
}
|
package/dassi.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
getAppDir,
|
|
20
20
|
getLaunchesFile,
|
|
21
21
|
} from './dassi-shared.mjs';
|
|
22
|
-
import {
|
|
22
|
+
import { dispatchLaunch } from './launch.mjs';
|
|
23
23
|
import { parseToolCommand, requireTarget, parseStrictInt } from './tool-commands.mjs';
|
|
24
24
|
import { runWithGroupExpansion } from './group-expansion.mjs';
|
|
25
25
|
import { formatResponse } from './format-response.mjs';
|
|
@@ -108,15 +108,21 @@ export function parseCliArgs(argv) {
|
|
|
108
108
|
if (!/^[a-zA-Z0-9_-]{1,64}$/.test(launchLabel)) {
|
|
109
109
|
throw new Error('--label must be 1–64 characters of letters, digits, hyphen, or underscore.');
|
|
110
110
|
}
|
|
111
|
+
const loadMode = getFlag(args, '--load-mode') ?? 'auto'; // auto (detect) | pipe | flag
|
|
112
|
+
if (!['auto', 'pipe', 'flag'].includes(loadMode)) throw new Error('--load-mode must be one of: auto, pipe, flag.');
|
|
111
113
|
return finish('launch', {
|
|
112
114
|
label: launchLabel,
|
|
113
115
|
dist: getFlag(args, '--dist') ?? null,
|
|
114
116
|
chrome: getFlag(args, '--chrome') ?? null,
|
|
115
117
|
profileDir: getFlag(args, '--profile-dir') ?? null,
|
|
118
|
+
loadMode,
|
|
116
119
|
timeoutMs: timeoutRaw ? parseStrictInt(timeoutRaw, '--timeout') : 30000,
|
|
117
120
|
});
|
|
118
121
|
}
|
|
119
122
|
|
|
123
|
+
// Hidden helper command (detached child of `dassi launch` pipe mode); config via DASSI_HOLD_* env.
|
|
124
|
+
if (command === '__launch-hold') return finish('launch_hold', {});
|
|
125
|
+
|
|
120
126
|
if (command === 'run') {
|
|
121
127
|
const prompt = args.shift();
|
|
122
128
|
if (!prompt) throw new Error('run requires a prompt argument');
|
|
@@ -431,14 +437,8 @@ export async function run() {
|
|
|
431
437
|
const { action, params, session, json, profile } = parsed;
|
|
432
438
|
handleImmediateAction(action);
|
|
433
439
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
if (action === 'launch_stop') {
|
|
439
|
-
handleStop(params, { launchesFile: getLaunchesFile() });
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
440
|
+
// Launch family (launch / --stop / __launch-hold) → launch.mjs.
|
|
441
|
+
if (await dispatchLaunch(action, params, { spawn: child_process.spawn, ensureDaemonRunning, getSocketPath, sendCommand, appDir: getAppDir(), launchesFile: getLaunchesFile() })) return;
|
|
442
442
|
|
|
443
443
|
const socketPath = await ensureDaemonReady(session);
|
|
444
444
|
|
package/help-text.mjs
CHANGED
|
@@ -27,8 +27,10 @@ export const HELP_TEXT =
|
|
|
27
27
|
' status Check extension status\n' +
|
|
28
28
|
' bug-report [-o file] Export debug logs from all contexts\n' +
|
|
29
29
|
' raw <json> Send raw JSON command\n' +
|
|
30
|
-
' launch [--label <name>] [--dist <path>]\n' +
|
|
31
|
-
' Open Chrome with a dev dist loaded\n' +
|
|
30
|
+
' launch [--label <name>] [--dist <path>] [--chrome <path>] [--load-mode auto|pipe|flag]\n' +
|
|
31
|
+
' Open Chrome with a dev dist loaded. --load-mode\n' +
|
|
32
|
+
' defaults to auto (pipe for branded Chrome 137+,\n' +
|
|
33
|
+
' --load-extension for Chrome for Testing/Chromium).\n' +
|
|
32
34
|
' launch --stop [label] | --stop-all\n' +
|
|
33
35
|
' Stop a launched Chrome\n\n' +
|
|
34
36
|
'Options:\n' +
|
package/launch.mjs
CHANGED
|
@@ -3,8 +3,14 @@
|
|
|
3
3
|
* building Chrome launch args, and tracking launched instances.
|
|
4
4
|
*/
|
|
5
5
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
6
|
+
import { execFileSync, spawn as childSpawn } from 'child_process';
|
|
6
7
|
import * as path from 'path';
|
|
7
8
|
import { DASSI_EXTENSION_ID, getDaemonBridgePort, DEFAULT_BRIDGE_PORT, isDaemonRunning as isDaemonRunningImpl } from './dassi-shared.mjs';
|
|
9
|
+
import { loadExtensionOverPipe } from './_launch-pipe.mjs';
|
|
10
|
+
// `_launch-pipe.mjs` is private (underscore-prefixed): `launch.mjs` is the SINGLE public
|
|
11
|
+
// gateway for the launch module. Re-export the pipe transport here so every consumer
|
|
12
|
+
// (including the unit tests) imports it from this one surface, never from the private file.
|
|
13
|
+
export { cdpPipeClient, loadExtensionOverPipe } from './_launch-pipe.mjs';
|
|
8
14
|
|
|
9
15
|
/**
|
|
10
16
|
* Resolve the path to an installed Chrome binary.
|
|
@@ -42,18 +48,37 @@ export function resolveDistPath({ dist = null, cwd = process.cwd(), exists = exi
|
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
/**
|
|
45
|
-
* Build the Chrome
|
|
46
|
-
*
|
|
51
|
+
* Build the Chrome args for a pipe-driven launch.
|
|
52
|
+
*
|
|
53
|
+
* The extension is NOT loaded via the `--load-extension` flag: Chrome 137+ branded
|
|
54
|
+
* builds reject it (`ERR_BLOCKED_BY_CLIENT`), and the `--disable-features=
|
|
55
|
+
* DisableLoadExtensionCommandLineSwitch` escape hatch is gone in Chrome 149. Instead
|
|
56
|
+
* the dist is installed at runtime over the CDP pipe via `Extensions.loadUnpacked`
|
|
57
|
+
* (see {@link loadExtensionOverPipe}). That command is only accepted over the
|
|
58
|
+
* `--remote-debugging-pipe` transport (fds 3/4) — not `--remote-debugging-port` —
|
|
59
|
+
* and requires `--enable-unsafe-extension-debugging`. Works on branded Chrome,
|
|
60
|
+
* Chrome for Testing, and Chromium alike.
|
|
61
|
+
* @param {{ profileDir: string }} opts
|
|
62
|
+
* @returns {string[]} Chrome args.
|
|
63
|
+
*/
|
|
64
|
+
export function buildLaunchArgs({ profileDir }) {
|
|
65
|
+
return [
|
|
66
|
+
'--remote-debugging-pipe',
|
|
67
|
+
'--enable-unsafe-extension-debugging',
|
|
68
|
+
`--user-data-dir=${profileDir}`,
|
|
69
|
+
'--no-first-run',
|
|
70
|
+
'--no-default-browser-check',
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Build Chrome args for the legacy `--load-extension` path (Chrome for Testing /
|
|
76
|
+
* Chromium, which still honour it and load the extension *persistently*). The dist
|
|
77
|
+
* is loaded at startup, so the seed options URL can ride along as the startup tab.
|
|
47
78
|
* @param {{ distPath: string; profileDir: string; label: string; bridgePort: number }} opts
|
|
48
|
-
* bridgePort: the daemon port to seed (use getDaemonBridgePort() — no default
|
|
49
|
-
* here, to avoid duplicating its canonical 18790).
|
|
50
79
|
* @returns {string[]} Chrome args (the final entry is the seed URL to open).
|
|
51
80
|
*/
|
|
52
|
-
export function
|
|
53
|
-
// Reason: seed BOTH label and bridgePort — the options page persists them so the
|
|
54
|
-
// launched extension connects to the daemon's actual port (matters when
|
|
55
|
-
// DASSI_BRIDGE_PORT moves the daemon off the default 18790; without it the
|
|
56
|
-
// extension falls back to 18790 and the isolated-port launch times out).
|
|
81
|
+
export function buildFlagArgs({ distPath, profileDir, label, bridgePort }) {
|
|
57
82
|
const seed = `options.html?label=${encodeURIComponent(label)}&bridgePort=${bridgePort}`;
|
|
58
83
|
return [
|
|
59
84
|
`--load-extension=${distPath}`,
|
|
@@ -65,6 +90,24 @@ export function buildLaunchArgs({ distPath, profileDir, label, bridgePort }) {
|
|
|
65
90
|
];
|
|
66
91
|
}
|
|
67
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Does this Chrome binary still support a *persistent* `--load-extension`?
|
|
95
|
+
* Branded Google Chrome 137+ disabled it (ERR_BLOCKED_BY_CLIENT); Chrome for Testing
|
|
96
|
+
* and Chromium still honour it. Detected from `--version` output. Defaults to false
|
|
97
|
+
* (→ pipe path) on any error — the pipe path works everywhere, so it's the safe
|
|
98
|
+
* fallback.
|
|
99
|
+
* @param {string} chromePath
|
|
100
|
+
* @param {(p: string) => string} [runVersion] inject for tests
|
|
101
|
+
* @returns {boolean} true → use `--load-extension`; false → use the CDP pipe.
|
|
102
|
+
*/
|
|
103
|
+
export function chromeSupportsLoadFlag(chromePath, runVersion = (p) => execFileSync(p, ['--version'], { encoding: 'utf8' })) {
|
|
104
|
+
try {
|
|
105
|
+
return /for testing|chromium/i.test(runVersion(chromePath));
|
|
106
|
+
} catch {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
68
111
|
/**
|
|
69
112
|
* Read the launches registry. Returns [] if the file is missing or unparseable.
|
|
70
113
|
* @param {string} file
|
|
@@ -146,17 +189,47 @@ async function isLabelConnected({ sendCommand, socketPath, label }) {
|
|
|
146
189
|
}
|
|
147
190
|
|
|
148
191
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* @
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
192
|
+
* Daemon pre-flight for a launch: validate the bridge port, spawn the (non-blocking)
|
|
193
|
+
* daemon, and refuse a duplicate label. Calls `exit(1)` + returns null on failure.
|
|
194
|
+
* @returns {Promise<{ bridgePort: number; socketPath: string } | null>}
|
|
195
|
+
*/
|
|
196
|
+
async function preflightLaunch({ ensureDaemonRunning, getSocketPath, sendCommand, isDaemonRunning, label, error, exit }) {
|
|
197
|
+
// Reason: `dassi launch` reuses the 'default' daemon session, but the session PID
|
|
198
|
+
// doesn't tell us its port. If a non-default DASSI_BRIDGE_PORT is requested while a
|
|
199
|
+
// default daemon is already running, we can't confirm it's on that port — fail clearly.
|
|
200
|
+
const bridgePort = getDaemonBridgePort();
|
|
201
|
+
if (bridgePort !== DEFAULT_BRIDGE_PORT && isDaemonRunning('default')) {
|
|
202
|
+
error(`❌ DASSI_BRIDGE_PORT=${bridgePort} is set, but a daemon is already running for the default session (it may be on a different port). Stop it first, or omit DASSI_BRIDGE_PORT to use the running daemon.`);
|
|
203
|
+
exit(1);
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
// Reason: only SPAWN the daemon (non-blocking) — none has connected yet.
|
|
207
|
+
ensureDaemonRunning('default');
|
|
208
|
+
const socketPath = getSocketPath('default');
|
|
209
|
+
// Reason: a same-label Chrome already running makes waitForProfile falsely succeed.
|
|
210
|
+
if (await isLabelConnected({ sendCommand, socketPath, label })) {
|
|
211
|
+
error(`❌ A profile labelled "${label}" is already connected. Run \`dassi launch --stop ${label}\` first, or use a different --label.`);
|
|
212
|
+
exit(1);
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
return { bridgePort, socketPath };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Launch Chrome with the dev dist loaded under a dedicated profile, wait for the
|
|
220
|
+
* extension to register under `label`, then record it. Auto-detects the load mode
|
|
221
|
+
* (pipe helper for branded Chrome / `--load-extension` for CfT/Chromium).
|
|
222
|
+
* @param {{label:string; dist:string|null; chrome:string|null; profileDir:string|null; loadMode?:string; timeoutMs:number}} opts
|
|
223
|
+
* @param {{ spawn: Function; ensureDaemonRunning: Function; getSocketPath: Function; sendCommand: Function; appDir: string; launchesFile: string; isDaemonRunning?: Function; detectLoadFlag?: Function; helperCommand?: string[]; log?: Function; error?: Function; exit?: Function; mkdir?: Function; kill?: Function }} deps
|
|
224
|
+
* `detectLoadFlag` chooses pipe-vs-flag mode; `helperCommand` is the argv used to spawn the detached pipe-hold helper (both injectable for tests).
|
|
225
|
+
* @returns {Promise<void>} resolves once the launch is recorded (or `deps.exit` is called on failure).
|
|
155
226
|
*/
|
|
156
227
|
export async function handleLaunch(opts, deps) {
|
|
157
228
|
const {
|
|
158
229
|
spawn, ensureDaemonRunning, getSocketPath, sendCommand, appDir, launchesFile,
|
|
159
230
|
isDaemonRunning = isDaemonRunningImpl,
|
|
231
|
+
detectLoadFlag = chromeSupportsLoadFlag,
|
|
232
|
+
helperCommand = [process.execPath, process.argv[1]],
|
|
160
233
|
log = console.log, error = console.error, exit = process.exit,
|
|
161
234
|
mkdir = (d) => mkdirSync(d, { recursive: true }), kill = (pid) => process.kill(pid),
|
|
162
235
|
} = deps;
|
|
@@ -165,65 +238,160 @@ export async function handleLaunch(opts, deps) {
|
|
|
165
238
|
if (!target) return; // resolution failed (exit already called)
|
|
166
239
|
const { distPath, chromePath, profileDir } = target;
|
|
167
240
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
// clearly rather than seed a port the extension can't reach (a silent timeout).
|
|
172
|
-
const bridgePort = getDaemonBridgePort();
|
|
173
|
-
if (bridgePort !== DEFAULT_BRIDGE_PORT && isDaemonRunning('default')) {
|
|
174
|
-
error(`❌ DASSI_BRIDGE_PORT=${bridgePort} is set, but a daemon is already running for the default session (it may be on a different port). Stop it first, or omit DASSI_BRIDGE_PORT to use the running daemon.`);
|
|
175
|
-
return exit(1);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Reason: only SPAWN the daemon (non-blocking). NOT ensureDaemonReady — that waits
|
|
179
|
-
// for the ready file the daemon writes only after an extension connects; none is yet.
|
|
180
|
-
ensureDaemonRunning('default');
|
|
181
|
-
const socketPath = getSocketPath('default');
|
|
182
|
-
|
|
183
|
-
// Reason: a same-label Chrome already running makes waitForProfile falsely succeed
|
|
184
|
-
// (a second launch with the same --user-data-dir hands off to the existing process).
|
|
185
|
-
if (await isLabelConnected({ sendCommand, socketPath, label: opts.label })) {
|
|
186
|
-
error(`❌ A profile labelled "${opts.label}" is already connected. Run \`dassi launch --stop ${opts.label}\` first, or use a different --label.`);
|
|
187
|
-
return exit(1);
|
|
188
|
-
}
|
|
241
|
+
const pre = await preflightLaunch({ ensureDaemonRunning, getSocketPath, sendCommand, isDaemonRunning, label: opts.label, error, exit });
|
|
242
|
+
if (!pre) return; // a guard failed (exit already called)
|
|
243
|
+
const { bridgePort, socketPath } = pre;
|
|
189
244
|
|
|
190
|
-
|
|
245
|
+
// Reason: branded Chrome 137+ disabled --load-extension, so install over the CDP pipe via
|
|
246
|
+
// a persistent helper. CfT/Chromium still honour --load-extension. --load-mode forces it;
|
|
247
|
+
// 'auto' (default) detects from the binary's --version.
|
|
248
|
+
const useFlag = opts.loadMode === 'flag' ? true : opts.loadMode === 'pipe' ? false : detectLoadFlag(chromePath);
|
|
249
|
+
const common = { spawn, kill, sendCommand, socketPath, chromePath, distPath, profileDir, bridgePort, opts, error };
|
|
250
|
+
const pid = useFlag ? await spawnFlagAndConnect(common) : await spawnHelperAndConnect({ ...common, helperCommand });
|
|
191
251
|
if (pid === null) return exit(1);
|
|
192
252
|
|
|
193
|
-
recordLaunch(launchesFile, { label: opts.label, pid, profileDir, startedAt: Date.now() });
|
|
253
|
+
recordLaunch(launchesFile, { label: opts.label, pid, profileDir, mode: useFlag ? 'flag' : 'pipe', startedAt: Date.now() });
|
|
194
254
|
log(`✅ launched "${opts.label}" (pid ${pid}) — drive it with: dassi run "…" --profile ${opts.label}`);
|
|
195
255
|
}
|
|
196
256
|
|
|
197
257
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
258
|
+
* Entry for the hidden `dassi __launch-hold` subcommand: reads the DASSI_HOLD_* env vars
|
|
259
|
+
* (set by spawnHelperAndConnect) and runs the pipe-holding helper. Never returns.
|
|
260
|
+
* @param {Record<string,string|undefined>} [env] Environment variables; defaults to process.env.
|
|
261
|
+
* @param {Function} [run] Pipe-hold runner; defaults to runPipeHoldHelper (injectable for tests).
|
|
262
|
+
* @returns {Promise<void>}
|
|
201
263
|
*/
|
|
202
|
-
async function
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
264
|
+
export async function handleLaunchHold(env = process.env, run = runPipeHoldHelper) {
|
|
265
|
+
await run({
|
|
266
|
+
label: env.DASSI_HOLD_LABEL,
|
|
267
|
+
distPath: env.DASSI_HOLD_DIST,
|
|
268
|
+
profileDir: env.DASSI_HOLD_PROFILE_DIR,
|
|
269
|
+
bridgePort: Number(env.DASSI_HOLD_BRIDGE_PORT),
|
|
270
|
+
chromePath: env.DASSI_HOLD_CHROME,
|
|
208
271
|
});
|
|
209
|
-
|
|
210
|
-
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Route a `launch*` CLI action to its handler. Returns true if it was a launch action
|
|
276
|
+
* (so the caller can `return`), false otherwise. Keeps the launch surface out of dassi.mjs.
|
|
277
|
+
* @param {string} action
|
|
278
|
+
* @param {object} params
|
|
279
|
+
* @param {{ spawn:Function; ensureDaemonRunning:Function; getSocketPath:Function; sendCommand:Function; appDir:string; launchesFile:string; kill?:Function; handleHold?:Function }} deps
|
|
280
|
+
* `handleHold` overrides the `__launch-hold` runner (injectable for tests; defaults to handleLaunchHold).
|
|
281
|
+
* @returns {Promise<boolean>}
|
|
282
|
+
*/
|
|
283
|
+
export async function dispatchLaunch(action, params, deps) {
|
|
284
|
+
if (action === 'launch') { await handleLaunch(params, deps); return true; }
|
|
285
|
+
if (action === 'launch_stop') { handleStop(params, { launchesFile: deps.launchesFile, kill: deps.kill }); return true; }
|
|
286
|
+
if (action === 'launch_hold') { await (deps.handleHold ?? handleLaunchHold)(); return true; }
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Flag mode (Chrome for Testing / Chromium): detached Chrome with a persistent
|
|
292
|
+
* `--load-extension`. The browser keeps the extension after this CLI exits.
|
|
293
|
+
* @returns {Promise<number|null>} the Chrome pid, or null on spawn/connect failure.
|
|
294
|
+
*/
|
|
295
|
+
async function spawnFlagAndConnect({ spawn, kill, sendCommand, socketPath, chromePath, distPath, profileDir, bridgePort, opts, error }) {
|
|
296
|
+
const child = spawn(chromePath, buildFlagArgs({ distPath, profileDir, label: opts.label, bridgePort }), { detached: true, stdio: 'ignore' });
|
|
211
297
|
child.on('error', () => {});
|
|
212
298
|
child.unref();
|
|
213
299
|
if (typeof child.pid !== 'number') {
|
|
214
300
|
error('❌ Failed to launch Chrome — check the Chrome path (--chrome).');
|
|
215
301
|
return null;
|
|
216
302
|
}
|
|
217
|
-
|
|
218
303
|
error(`Launching Chrome (pid ${child.pid}) with ${distPath} — waiting for "${opts.label}" to connect…`);
|
|
219
304
|
if (await waitForProfile({ sendCommand, socketPath, label: opts.label, timeoutMs: opts.timeoutMs })) return child.pid;
|
|
220
|
-
|
|
221
|
-
// Reason: kill the detached Chrome we started so a connect-timeout never orphans a browser.
|
|
222
305
|
try { kill(child.pid); } catch { /* already gone */ }
|
|
223
|
-
error(`❌ "${opts.label}" did not connect within ${opts.timeoutMs}ms (Chrome already using ${profileDir},
|
|
306
|
+
error(`❌ "${opts.label}" did not connect within ${opts.timeoutMs}ms (Chrome already using ${profileDir}, or a stale profile).`);
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Pipe mode (branded Chrome): spawn a detached `dassi __launch-hold` helper that holds the
|
|
312
|
+
* CDP pipe open so the loadUnpacked extension persists. The recorded pid is the HELPER's —
|
|
313
|
+
* `dassi launch --stop` SIGTERMs it, and it closes the pipe + kills its Chrome child.
|
|
314
|
+
* @returns {Promise<number|null>} the helper pid, or null on spawn/connect failure.
|
|
315
|
+
*/
|
|
316
|
+
async function spawnHelperAndConnect({ spawn, kill, sendCommand, socketPath, chromePath, distPath, profileDir, bridgePort, opts, error, helperCommand }) {
|
|
317
|
+
const [node, cli] = helperCommand;
|
|
318
|
+
// Reason: pass the helper's config via env (not flags) so it can't collide with the
|
|
319
|
+
// CLI's global --label/--profile parsing.
|
|
320
|
+
const helper = spawn(node, [cli, '__launch-hold'], {
|
|
321
|
+
detached: true,
|
|
322
|
+
stdio: 'ignore',
|
|
323
|
+
env: {
|
|
324
|
+
...process.env,
|
|
325
|
+
DASSI_HOLD_LABEL: opts.label,
|
|
326
|
+
DASSI_HOLD_DIST: distPath,
|
|
327
|
+
DASSI_HOLD_PROFILE_DIR: profileDir,
|
|
328
|
+
DASSI_HOLD_BRIDGE_PORT: String(bridgePort),
|
|
329
|
+
DASSI_HOLD_CHROME: chromePath,
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
helper.on('error', () => {});
|
|
333
|
+
helper.unref();
|
|
334
|
+
if (typeof helper.pid !== 'number') {
|
|
335
|
+
error('❌ Failed to start the launch helper.');
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
error(`Launching Chrome via pipe helper (pid ${helper.pid}) with ${distPath} — waiting for "${opts.label}" to connect…`);
|
|
339
|
+
if (await waitForProfile({ sendCommand, socketPath, label: opts.label, timeoutMs: opts.timeoutMs })) return helper.pid;
|
|
340
|
+
try { kill(helper.pid); } catch { /* already gone */ }
|
|
341
|
+
error(`❌ "${opts.label}" did not connect within ${opts.timeoutMs}ms (extension installed but the bridge didn't register — daemon port mismatch or a stale profile).`);
|
|
224
342
|
return null;
|
|
225
343
|
}
|
|
226
344
|
|
|
345
|
+
/**
|
|
346
|
+
* Long-lived `dassi __launch-hold` helper (a detached child of `dassi launch` on branded
|
|
347
|
+
* Chrome): spawns Chrome with the CDP pipe, installs the dist, signals readiness, then
|
|
348
|
+
* HOLDS the pipe open until killed — a loadUnpacked extension lives only as long as its
|
|
349
|
+
* debugging session. On SIGTERM/SIGINT (from `dassi launch --stop`) or if Chrome exits, it
|
|
350
|
+
* tears down and exits.
|
|
351
|
+
* @param {{ distPath:string; profileDir:string; label:string; bridgePort:number; chromePath:string;
|
|
352
|
+
* spawn?:Function; loadExtension?:Function; onReady?:Function; hold?:()=>Promise<void>;
|
|
353
|
+
* error?:Function; exit?:Function }} o
|
|
354
|
+
* @returns {Promise<void>} In production never resolves (hold() is infinite until killed);
|
|
355
|
+
* resolves after calling exit(1) on extension-install failure.
|
|
356
|
+
*/
|
|
357
|
+
export async function runPipeHoldHelper(o) {
|
|
358
|
+
const {
|
|
359
|
+
distPath, profileDir, label, bridgePort, chromePath,
|
|
360
|
+
spawn = childSpawn, loadExtension = loadExtensionOverPipe,
|
|
361
|
+
onReady = () => {}, hold = () => new Promise(() => {}),
|
|
362
|
+
error = (m) => process.stderr.write(`${m}\n`), exit = process.exit,
|
|
363
|
+
} = o;
|
|
364
|
+
const child = spawn(chromePath, buildLaunchArgs({ profileDir }), { stdio: ['ignore', 'ignore', 'ignore', 'pipe', 'pipe'] });
|
|
365
|
+
let dispose = () => {};
|
|
366
|
+
let shuttingDown = false;
|
|
367
|
+
const shutdown = () => {
|
|
368
|
+
if (shuttingDown) return;
|
|
369
|
+
shuttingDown = true;
|
|
370
|
+
try { dispose(); } catch { /* ignore */ }
|
|
371
|
+
try { child.kill('SIGTERM'); } catch { /* already gone */ }
|
|
372
|
+
exit(0);
|
|
373
|
+
};
|
|
374
|
+
// Reason: this helper runs as a detached process whose whole job is to hold the CDP
|
|
375
|
+
// pipe open. SIGTERM is how `dassi launch --stop` tears it down; SIGINT covers Ctrl-C.
|
|
376
|
+
// Without these handlers the Chrome child (and its loaded extension) would be orphaned.
|
|
377
|
+
process.on('SIGTERM', shutdown);
|
|
378
|
+
process.on('SIGINT', shutdown);
|
|
379
|
+
child.on('error', () => {});
|
|
380
|
+
child.on('exit', () => { if (!shuttingDown) exit(0); }); // Chrome died → stop holding
|
|
381
|
+
try {
|
|
382
|
+
({ dispose } = await loadExtension({ child, distPath, label, bridgePort }));
|
|
383
|
+
} catch (err) {
|
|
384
|
+
// Reason: set shuttingDown FIRST so the child.on('exit') guard above can't win the
|
|
385
|
+
// race and call exit(0) — a failed install must surface as exit(1), not false success.
|
|
386
|
+
shuttingDown = true;
|
|
387
|
+
error(`launch-hold: failed to install extension: ${err.message}`);
|
|
388
|
+
try { child.kill('SIGTERM'); } catch { /* already gone */ }
|
|
389
|
+
return exit(1);
|
|
390
|
+
}
|
|
391
|
+
onReady();
|
|
392
|
+
await hold(); // hold the pipe open (draining) until killed
|
|
393
|
+
}
|
|
394
|
+
|
|
227
395
|
/**
|
|
228
396
|
* Resolve the dist dir, Chrome binary, and profile dir for a launch.
|
|
229
397
|
* Calls `exit(1)` and returns null on any failure (extracted to keep
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dassi_ai/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "CLI for the Dassi Chrome extension — run browser automation from the terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"format-response.mjs",
|
|
15
15
|
"group-expansion.mjs",
|
|
16
16
|
"launch.mjs",
|
|
17
|
+
"_launch-pipe.mjs",
|
|
17
18
|
"help-text.mjs",
|
|
18
19
|
".claude-plugin/",
|
|
19
20
|
"skills/",
|
|
@@ -32,11 +32,26 @@ Each accepts `--tab <id>` OR `--group <id>` OR `--group-title <name>`, except wh
|
|
|
32
32
|
| `open [url]` | url? | **Single-target only** (`--tab` required). Opens new tab in current group. |
|
|
33
33
|
| `close` | — | Close tab. Fans out across a group = close all member tabs. |
|
|
34
34
|
|
|
35
|
+
## Dev launch commands (loading a local build for testing)
|
|
36
|
+
|
|
37
|
+
| Command | Args | Notes |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| `dassi launch` | `--label <name>` (default `dev`), `--dist <path>` (default `extension/dist`), `--chrome <path>`, `--load-mode auto\|pipe\|flag`, `--timeout <ms>` | Open a dedicated Chrome with a locally-built dev dist loaded, registered under `--label`. Then drive it by adding `--profile <label>` to any command. |
|
|
40
|
+
| `dassi launch --stop [label]` / `--stop-all` | label? | Close a launched Chrome (default label `dev`). |
|
|
41
|
+
| `dassi list-profiles` | `--json` | List connected Chrome instances (profiles), by `label`/id. |
|
|
42
|
+
|
|
43
|
+
**How the extension is loaded** (`--load-mode`, default `auto`):
|
|
44
|
+
- **Branded Google Chrome 137+** disabled the `--load-extension` flag (`ERR_BLOCKED_BY_CLIENT`), so launch installs the dist at runtime via the `Extensions.loadUnpacked` CDP command over `--remote-debugging-pipe`. Such an extension is tied to the debugging session, so launch spawns a detached helper that holds the pipe open; `--stop` kills the helper (which closes the pipe + its Chrome).
|
|
45
|
+
- **Chrome for Testing / Chromium** still honour `--load-extension` (persistent) → used directly, no helper.
|
|
46
|
+
- `--load-mode pipe|flag` forces a mode (e.g. `--chrome <cft> --load-mode pipe` exercises the pipe path on Chrome for Testing); `auto` detects from the binary's `--version`.
|
|
47
|
+
- A freshly launched profile is **signed out** — sign in to that Chrome before `dassi run`/agent commands work in it.
|
|
48
|
+
|
|
35
49
|
## Global options
|
|
36
50
|
|
|
37
51
|
| Flag | Effect |
|
|
38
52
|
|---|---|
|
|
39
53
|
| `--session <name>` | Daemon session name (default `default`). Selects which per-session daemon process and Unix socket the CLI connects to. Each distinct `--session` value spawns its own daemon; only one can be running at a time because they all bind the same WebSocket port (see the "Multi-tab dispatch is sequential" note below). |
|
|
54
|
+
| `--profile <label>` (alias `--label`) | Target a specific connected Chrome instance (e.g. one started by `dassi launch --label qa`). Required when multiple profiles are connected. |
|
|
40
55
|
| `--json` | Raw JSON output (in group fan-out: single JSON array of `{tabId, response}` entries). |
|
|
41
56
|
| `--version`, `--help` | Self-explanatory. |
|
|
42
57
|
|