@phnx-labs/agents-cli 1.22.50 → 1.22.52
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/CHANGELOG.md +219 -0
- package/dist/bootstrap.js +1 -1
- package/dist/commands/attach.js +7 -0
- package/dist/commands/browser.d.ts +10 -0
- package/dist/commands/browser.js +191 -54
- package/dist/commands/config.js +20 -0
- package/dist/commands/daemon.d.ts +2 -0
- package/dist/commands/daemon.js +8 -4
- package/dist/commands/detach.js +1 -1
- package/dist/commands/feedback.js +1 -1
- package/dist/commands/focus.d.ts +1 -10
- package/dist/commands/focus.js +14 -79
- package/dist/commands/go.d.ts +26 -0
- package/dist/commands/go.js +63 -5
- package/dist/commands/menubar.js +6 -4
- package/dist/commands/monitors.js +1 -1
- package/dist/commands/repo.js +31 -3
- package/dist/commands/sessions-resume.d.ts +1 -0
- package/dist/commands/sessions-resume.js +13 -2
- package/dist/commands/sessions-stop.js +1 -1
- package/dist/commands/sessions.d.ts +23 -13
- package/dist/commands/sessions.js +40 -20
- package/dist/commands/setup-browser.d.ts +5 -2
- package/dist/commands/setup-browser.js +14 -29
- package/dist/commands/setup-preferences.d.ts +22 -3
- package/dist/commands/setup-preferences.js +25 -8
- package/dist/commands/share.js +12 -8
- package/dist/commands/status.js +5 -0
- package/dist/commands/sync.js +58 -2
- package/dist/commands/tmux.d.ts +8 -1
- package/dist/commands/tmux.js +167 -17
- package/dist/commands/traces.js +32 -4
- package/dist/lib/browser/ipc.d.ts +44 -0
- package/dist/lib/browser/ipc.js +120 -8
- package/dist/lib/browser/profiles.d.ts +39 -17
- package/dist/lib/browser/profiles.js +51 -52
- package/dist/lib/browser/runtime-state.d.ts +4 -2
- package/dist/lib/browser/runtime-state.js +4 -2
- package/dist/lib/browser/service.js +4 -3
- package/dist/lib/channels/owner-forward.d.ts +88 -0
- package/dist/lib/channels/owner-forward.js +116 -0
- package/dist/lib/channels/owner-sink.js +7 -0
- package/dist/lib/claude-statusline.d.ts +9 -0
- package/dist/lib/claude-statusline.js +45 -4
- package/dist/lib/computer/ssh-tunnel.d.ts +7 -6
- package/dist/lib/computer/ssh-tunnel.js +13 -8
- package/dist/lib/config-keys.d.ts +4 -3
- package/dist/lib/config-keys.js +9 -2
- package/dist/lib/device-config.js +23 -0
- package/dist/lib/exec.d.ts +8 -0
- package/dist/lib/exec.js +7 -0
- package/dist/lib/factory/snapshot.d.ts +1 -1
- package/dist/lib/factory/snapshot.js +1 -1
- package/dist/lib/feed-broadcast.js +15 -1
- package/dist/lib/git.d.ts +93 -0
- package/dist/lib/git.js +232 -0
- package/dist/lib/helper-download.d.ts +12 -2
- package/dist/lib/helper-download.js +12 -2
- package/dist/lib/installations/migrate.js +4 -4
- package/dist/lib/menubar/install-menubar.d.ts +71 -8
- package/dist/lib/menubar/install-menubar.js +183 -24
- package/dist/lib/monitors/remote.d.ts +18 -1
- package/dist/lib/monitors/remote.js +15 -2
- package/dist/lib/notify.d.ts +7 -0
- package/dist/lib/notify.js +15 -1
- package/dist/lib/session/local-tmux-attach.d.ts +69 -0
- package/dist/lib/session/local-tmux-attach.js +164 -0
- package/dist/lib/session/remote-active.d.ts +8 -0
- package/dist/lib/session/remote-active.js +1 -0
- package/dist/lib/share/publish.d.ts +8 -11
- package/dist/lib/share/publish.js +16 -20
- package/dist/lib/share/worker-template.js +99 -12
- package/dist/lib/star-nudge.d.ts +2 -2
- package/dist/lib/star-nudge.js +2 -2
- package/dist/lib/state.d.ts +1 -1
- package/dist/lib/state.js +2 -2
- package/dist/lib/sync-status.d.ts +17 -0
- package/dist/lib/sync-status.js +21 -2
- package/dist/lib/tmux/index.d.ts +1 -1
- package/dist/lib/tmux/index.js +1 -1
- package/dist/lib/tmux/session.d.ts +10 -0
- package/dist/lib/tmux/session.js +29 -0
- package/dist/lib/traces/sync.d.ts +30 -0
- package/dist/lib/traces/sync.js +91 -10
- package/package.json +3 -3
package/dist/lib/browser/ipc.js
CHANGED
|
@@ -69,6 +69,29 @@ const SOCKET_NAME = 'browser.sock';
|
|
|
69
69
|
* coming near the grace window.
|
|
70
70
|
*/
|
|
71
71
|
const IPC_CLOSE_TIMEOUT_MS = 1_500;
|
|
72
|
+
/**
|
|
73
|
+
* How long {@link waitForSocket} waits for the browser daemon to come up before
|
|
74
|
+
* failing loud (PHNX-3289).
|
|
75
|
+
*
|
|
76
|
+
* The old flat 6s ceiling was the wedge: the shared daemon's browser IPC server
|
|
77
|
+
* restarts (version reconcile, supervisor restart, a hard-crashed predecessor's
|
|
78
|
+
* successor claiming the socket), and a client that started its wait *during*
|
|
79
|
+
* one of those restart windows could burn the whole 6s and throw
|
|
80
|
+
* `Timeout waiting for browser daemon socket` on an otherwise-healthy daemon. A
|
|
81
|
+
* browser start/navigate then failed intermittently and self-healed on the next
|
|
82
|
+
* try. 15s comfortably spans a restart; the stable-probe requirement below is
|
|
83
|
+
* what keeps a socket that "appears and is immediately destroyed" (#556) from
|
|
84
|
+
* being mistaken for a ready daemon.
|
|
85
|
+
*/
|
|
86
|
+
const SOCKET_WAIT_TIMEOUT_MS = 15_000;
|
|
87
|
+
/**
|
|
88
|
+
* Consecutive successful probes required before {@link waitForSocket} declares
|
|
89
|
+
* the daemon ready. A single accept can land in the sliver between a restarting
|
|
90
|
+
* server binding and tearing back down; requiring two accepts ~100ms apart means
|
|
91
|
+
* we only return once the daemon is *staying* up, so the caller's real request
|
|
92
|
+
* doesn't race a restart it happened to probe mid-flight.
|
|
93
|
+
*/
|
|
94
|
+
const SOCKET_WAIT_STABLE_PROBES = 2;
|
|
72
95
|
export class BrowserDaemonNotRunningError extends Error {
|
|
73
96
|
constructor() {
|
|
74
97
|
super(formatBrowserDaemonNotRunningError());
|
|
@@ -78,8 +101,8 @@ export class BrowserDaemonNotRunningError extends Error {
|
|
|
78
101
|
export function formatBrowserDaemonNotRunningError() {
|
|
79
102
|
return [
|
|
80
103
|
'Browser daemon not running.',
|
|
81
|
-
'Start it with: agents browser start (
|
|
82
|
-
'
|
|
104
|
+
'Start it with: agents browser start (uses this machine\'s configured default browser)',
|
|
105
|
+
'Pick / pin a profile: agents browser use <name> (or: agents browser start --profile <name>)',
|
|
83
106
|
'List profiles: agents browser profiles list',
|
|
84
107
|
].join('\n');
|
|
85
108
|
}
|
|
@@ -117,15 +140,104 @@ function probeDaemon(endpoint, timeoutMs = 500) {
|
|
|
117
140
|
export async function isDaemonReachable() {
|
|
118
141
|
return probeDaemon(getIpcEndpoint());
|
|
119
142
|
}
|
|
120
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Wait until the browser daemon is genuinely reachable, or throw.
|
|
145
|
+
*
|
|
146
|
+
* Re-probes across the whole window rather than latching on the first accept, so
|
|
147
|
+
* it survives an IPC-server restart that happens mid-wait (PHNX-3289): a restart
|
|
148
|
+
* just resets the consecutive-accept counter, and the loop keeps going until the
|
|
149
|
+
* daemon is *stably* up or the deadline passes. Bounded and fail-loud — a daemon
|
|
150
|
+
* that never comes up throws a message naming the endpoint and the budget, never
|
|
151
|
+
* a silent hang.
|
|
152
|
+
*/
|
|
153
|
+
export async function waitForSocket(_socketPath, timeoutMs = SOCKET_WAIT_TIMEOUT_MS) {
|
|
121
154
|
const endpoint = getIpcEndpoint();
|
|
122
155
|
const deadline = Date.now() + timeoutMs;
|
|
156
|
+
let consecutive = 0;
|
|
123
157
|
while (Date.now() < deadline) {
|
|
124
|
-
if (await probeDaemon(endpoint))
|
|
125
|
-
|
|
158
|
+
if (await probeDaemon(endpoint)) {
|
|
159
|
+
consecutive += 1;
|
|
160
|
+
if (consecutive >= SOCKET_WAIT_STABLE_PROBES)
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// A dropped probe means a restart (or the daemon isn't up yet) — start the
|
|
165
|
+
// stability count over rather than counting accepts from before the gap.
|
|
166
|
+
consecutive = 0;
|
|
167
|
+
}
|
|
168
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
169
|
+
}
|
|
170
|
+
throw new Error(`Timeout waiting for browser daemon socket after ${Math.round(timeoutMs / 1000)}s (${endpoint}).`);
|
|
171
|
+
}
|
|
172
|
+
/** How long {@link resetBrowserDaemon} waits for the endpoint to go quiet after
|
|
173
|
+
* signalling a stop before it clears the socket and re-checks. Bounded so the
|
|
174
|
+
* command fails loud instead of hanging on a daemon that will not die. */
|
|
175
|
+
const DAEMON_RESET_QUIESCE_MS = 5_000;
|
|
176
|
+
/**
|
|
177
|
+
* Clear a wedged browser daemon so a subsequent `start` comes up clean
|
|
178
|
+
* (PHNX-3289). Stops the shared daemon (the same `stopDaemon` path
|
|
179
|
+
* `reconcileDaemonVersion` uses for a stale-version restart), waits for the IPC
|
|
180
|
+
* endpoint to stop accepting, then unlinks any stale `browser.sock` a
|
|
181
|
+
* hard-crashed daemon left behind — the file a fresh `start` would otherwise
|
|
182
|
+
* `unlink` blindly, racing whatever still holds it.
|
|
183
|
+
*
|
|
184
|
+
* Fails loud: if the endpoint is *still* reachable after the quiesce window, a
|
|
185
|
+
* live server is holding it and clearing the socket under it would orphan two
|
|
186
|
+
* servers on one path, so we throw rather than pretend the reset worked. The
|
|
187
|
+
* daemon auto-restarts on the next browser command.
|
|
188
|
+
*/
|
|
189
|
+
export async function resetBrowserDaemon() {
|
|
190
|
+
const endpoint = getIpcEndpoint();
|
|
191
|
+
const wasRunning = await probeDaemon(endpoint);
|
|
192
|
+
stopDaemon();
|
|
193
|
+
// Wait for the listener to actually release the endpoint. We must decide
|
|
194
|
+
// reachability BEFORE touching the socket file: unlinking a path out from
|
|
195
|
+
// under a live server makes new connects ENOENT (so it would *look* cleared)
|
|
196
|
+
// while the server keeps running — the two-servers orphan the eviction
|
|
197
|
+
// protocol exists to prevent. So a still-reachable endpoint fails loud here,
|
|
198
|
+
// and only a genuinely dead one gets its stale file removed below.
|
|
199
|
+
const deadline = Date.now() + DAEMON_RESET_QUIESCE_MS;
|
|
200
|
+
let reachable = wasRunning;
|
|
201
|
+
while (reachable && Date.now() < deadline) {
|
|
126
202
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
203
|
+
reachable = await probeDaemon(endpoint);
|
|
204
|
+
}
|
|
205
|
+
if (reachable) {
|
|
206
|
+
throw new Error(actionable('Browser daemon is still reachable after stop — a live server is holding the socket.', `Endpoint: ${endpoint}`, 'Next: agents daemon status (find and stop the process holding it)'));
|
|
207
|
+
}
|
|
208
|
+
// Nothing is listening now — clear the leftover socket file a hard-crashed
|
|
209
|
+
// daemon left behind, so the next `start` binds clean instead of unlinking it
|
|
210
|
+
// blindly. (Named pipes vanish with their owning process, so Windows has no
|
|
211
|
+
// stale file to clear.)
|
|
212
|
+
const socketCleared = IS_WINDOWS ? false : await clearDeadSocketFile(endpoint, getSocketPath());
|
|
213
|
+
return { wasRunning, socketCleared };
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Remove a leftover browser socket FILE, but only when nothing is listening on
|
|
217
|
+
* it — re-probing liveness IMMEDIATELY before the unlink to close the TOCTOU
|
|
218
|
+
* window (PHNX-3289 review). Between {@link resetBrowserDaemon}'s quiesce loop
|
|
219
|
+
* deciding the endpoint was unreachable and this unlink, a concurrent
|
|
220
|
+
* `browser start` could bind a NEW listener on the same path; an unconditional
|
|
221
|
+
* unlink would then delete a LIVE daemon's socket — the exact two-servers orphan
|
|
222
|
+
* this function exists to prevent. A listener seen here means the wedge is already
|
|
223
|
+
* resolved (a fresh daemon owns the path), so its socket is left intact. Returns
|
|
224
|
+
* true only when a genuinely dead file was removed.
|
|
225
|
+
*/
|
|
226
|
+
export async function clearDeadSocketFile(endpoint, socketPath) {
|
|
227
|
+
if (!fs.existsSync(socketPath))
|
|
228
|
+
return false;
|
|
229
|
+
// A listener bound again since the quiesce loop → do not touch its socket.
|
|
230
|
+
if (await probeDaemon(endpoint))
|
|
231
|
+
return false;
|
|
232
|
+
try {
|
|
233
|
+
fs.unlinkSync(socketPath);
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
// Raced with a fresh start that already claimed it — the goal (no stale
|
|
238
|
+
// socket) still holds, so report cleared only when it is genuinely gone.
|
|
239
|
+
return !fs.existsSync(socketPath);
|
|
127
240
|
}
|
|
128
|
-
throw new Error('Timeout waiting for browser daemon socket');
|
|
129
241
|
}
|
|
130
242
|
/**
|
|
131
243
|
* One long-lived connection to the existing browser daemon. Requests are
|
|
@@ -865,7 +977,7 @@ async function reconcileDaemonVersion(socketPath) {
|
|
|
865
977
|
stopDaemon();
|
|
866
978
|
startDaemon();
|
|
867
979
|
if (!(await isDaemonReachable())) {
|
|
868
|
-
await waitForSocket(socketPath
|
|
980
|
+
await waitForSocket(socketPath);
|
|
869
981
|
}
|
|
870
982
|
await new Promise((r) => setTimeout(r, 300));
|
|
871
983
|
}
|
|
@@ -968,7 +1080,7 @@ async function prepareIPC(action, opts) {
|
|
|
968
1080
|
}
|
|
969
1081
|
startDaemon();
|
|
970
1082
|
if (!(await isDaemonReachable())) {
|
|
971
|
-
await waitForSocket(socketPath
|
|
1083
|
+
await waitForSocket(socketPath);
|
|
972
1084
|
}
|
|
973
1085
|
if (!(await isDaemonReachable())) {
|
|
974
1086
|
throw new Error(actionable('Failed to start browser daemon.', `Log: ${getDaemonLogPath()}`, 'Next: agents doctor (checks for a second agents-cli install)'));
|
|
@@ -2,14 +2,17 @@ import type { BrowserProfile, ProfileName } from './types.js';
|
|
|
2
2
|
export type { BrowserProfile } from './types.js';
|
|
3
3
|
export { declaringDevices, profileKind, profileRegistry, type ProfileDeclaration, } from './registry.js';
|
|
4
4
|
/**
|
|
5
|
-
* Name of the profile
|
|
5
|
+
* Name of the profile the setup wizards pin as this machine's default browser
|
|
6
|
+
* (`agents setup`, `agents setup browser`). Older builds also auto-created it
|
|
7
|
+
* silently on the first `agents browser start`; PHNX-3296 removed that — see
|
|
8
|
+
* {@link ensureDefaultBrowserProfile}.
|
|
6
9
|
*
|
|
7
10
|
* It is `auto-chrome`, NOT `default`, since RUSH-2709: `default` used to be
|
|
8
11
|
* both this concrete profile AND the alias meaning "whatever profile the user
|
|
9
|
-
* configured", so `--profile default` landed on a literal
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
12
|
+
* configured", so `--profile default` landed on a literal Chrome on one command
|
|
13
|
+
* and on the user's configured Comet on another. The alias now lives alone in
|
|
14
|
+
* {@link DEFAULT_PROFILE_ALIAS} and resolves in exactly one place
|
|
15
|
+
* ({@link resolveProfileRef}).
|
|
13
16
|
*/
|
|
14
17
|
export declare const DEFAULT_BROWSER_PROFILE_NAME = "auto-chrome";
|
|
15
18
|
/**
|
|
@@ -106,33 +109,52 @@ export declare function resolveProfileRef(ref?: string): Promise<string | undefi
|
|
|
106
109
|
* no profile of that name) goes through {@link ensureDefaultBrowserProfile} —
|
|
107
110
|
* which additionally verifies the resolved default can launch on THIS machine.
|
|
108
111
|
* An undeclared configured default is an error. A declared default whose
|
|
109
|
-
* browser isn't installed here warns and falls through to
|
|
112
|
+
* browser isn't installed here warns and falls through to an existing profile,
|
|
113
|
+
* else the actionable throw below.
|
|
110
114
|
*
|
|
111
115
|
* `start` is the only command that launches a browser, so it is the only one
|
|
112
116
|
* that may do those things; routing a filter-only command through this would
|
|
113
|
-
* warn about
|
|
117
|
+
* warn about config the user never asked it to touch.
|
|
114
118
|
*
|
|
115
|
-
* Throws when the configured default is
|
|
116
|
-
*
|
|
119
|
+
* Throws ({@link noDefaultBrowserError}) when the configured default is
|
|
120
|
+
* undeclared, or when no profile exists that can launch here.
|
|
117
121
|
*/
|
|
118
122
|
export declare function resolveProfileRefForStart(ref?: string): Promise<string>;
|
|
123
|
+
/**
|
|
124
|
+
* The error a bare `agents browser start` raises when this machine has no
|
|
125
|
+
* launchable default browser. Its own function so the wording — the one thing
|
|
126
|
+
* the user reads when a browser won't start — stays in one place and is
|
|
127
|
+
* testable without spawning anything.
|
|
128
|
+
*
|
|
129
|
+
* Since PHNX-3296 this is a hard stop, NOT a silent auto-create. The old
|
|
130
|
+
* behavior probed the installed Chromium-family browsers and minted a
|
|
131
|
+
* logged-out `auto-chrome` profile on the spot; agents then drove a signed-out
|
|
132
|
+
* Chrome that popped up on the user's Mac unbidden. Which browser agents drive
|
|
133
|
+
* is a choice the user makes once, in `agents setup` — never one this code
|
|
134
|
+
* makes for them.
|
|
135
|
+
*/
|
|
136
|
+
export declare function noDefaultBrowserError(): Error;
|
|
119
137
|
/**
|
|
120
138
|
* Resolve the profile a bare `agents browser start` uses.
|
|
121
139
|
*
|
|
122
140
|
* Order: (1) the device-local configured default (`agents browser use <name>`)
|
|
123
141
|
* when it names a profile that exists and can launch here; (2) an existing
|
|
124
|
-
* auto-detected profile
|
|
125
|
-
*
|
|
126
|
-
*
|
|
142
|
+
* auto-detected profile (`auto-chrome`, or a legacy `default`) that can launch
|
|
143
|
+
* here. When neither resolves, THROW ({@link noDefaultBrowserError}) rather than
|
|
144
|
+
* detect-and-create — see that function for why (PHNX-3296).
|
|
127
145
|
*
|
|
128
146
|
* Two failure modes at the configured-default step are not the same:
|
|
129
147
|
* - No device declares the name (including a leftover central `browser:`
|
|
130
|
-
* entry that was never claimed) → throw.
|
|
131
|
-
* hand the agent a logged-out browser while `browser.profile` still
|
|
132
|
-
* the credentialed one.
|
|
148
|
+
* entry that was never claimed) → throw. Falling back to a minted profile
|
|
149
|
+
* would hand the agent a logged-out browser while `browser.profile` still
|
|
150
|
+
* names the credentialed one.
|
|
133
151
|
* - The name is declared, but its browser/binary is not installed HERE →
|
|
134
|
-
* warn and fall through
|
|
135
|
-
* missing
|
|
152
|
+
* warn and fall through to an existing profile, else the actionable throw.
|
|
153
|
+
* That is a missing binary on this box, not a missing identity.
|
|
154
|
+
*
|
|
155
|
+
* This RECOGNIZES a pre-existing `auto-chrome`/legacy `default` so installs that
|
|
156
|
+
* already carry one keep resolving it (and its running browser + runtime dirs),
|
|
157
|
+
* but it never CREATES one.
|
|
136
158
|
*/
|
|
137
159
|
export declare function ensureDefaultBrowserProfile(): Promise<BrowserProfile>;
|
|
138
160
|
/**
|
|
@@ -4,18 +4,20 @@ import { getBrowserRuntimeDir as getBrowserRuntimeDirRoot, readMeta, updateMeta,
|
|
|
4
4
|
import { getConfigValue } from '../device-config.js';
|
|
5
5
|
import { machineId } from '../machine-id.js';
|
|
6
6
|
import { declaringDevices, profileRegistry, } from './registry.js';
|
|
7
|
-
import { findBrowserPath,
|
|
8
|
-
import { DEFAULT_VIEWPORT } from './devices.js';
|
|
7
|
+
import { findBrowserPath, isPortInUse } from './chrome.js';
|
|
9
8
|
export { declaringDevices, profileKind, profileRegistry, } from './registry.js';
|
|
10
9
|
/**
|
|
11
|
-
* Name of the profile
|
|
10
|
+
* Name of the profile the setup wizards pin as this machine's default browser
|
|
11
|
+
* (`agents setup`, `agents setup browser`). Older builds also auto-created it
|
|
12
|
+
* silently on the first `agents browser start`; PHNX-3296 removed that — see
|
|
13
|
+
* {@link ensureDefaultBrowserProfile}.
|
|
12
14
|
*
|
|
13
15
|
* It is `auto-chrome`, NOT `default`, since RUSH-2709: `default` used to be
|
|
14
16
|
* both this concrete profile AND the alias meaning "whatever profile the user
|
|
15
|
-
* configured", so `--profile default` landed on a literal
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* configured", so `--profile default` landed on a literal Chrome on one command
|
|
18
|
+
* and on the user's configured Comet on another. The alias now lives alone in
|
|
19
|
+
* {@link DEFAULT_PROFILE_ALIAS} and resolves in exactly one place
|
|
20
|
+
* ({@link resolveProfileRef}).
|
|
19
21
|
*/
|
|
20
22
|
export const DEFAULT_BROWSER_PROFILE_NAME = 'auto-chrome';
|
|
21
23
|
/**
|
|
@@ -221,14 +223,15 @@ export async function resolveProfileRef(ref) {
|
|
|
221
223
|
* no profile of that name) goes through {@link ensureDefaultBrowserProfile} —
|
|
222
224
|
* which additionally verifies the resolved default can launch on THIS machine.
|
|
223
225
|
* An undeclared configured default is an error. A declared default whose
|
|
224
|
-
* browser isn't installed here warns and falls through to
|
|
226
|
+
* browser isn't installed here warns and falls through to an existing profile,
|
|
227
|
+
* else the actionable throw below.
|
|
225
228
|
*
|
|
226
229
|
* `start` is the only command that launches a browser, so it is the only one
|
|
227
230
|
* that may do those things; routing a filter-only command through this would
|
|
228
|
-
* warn about
|
|
231
|
+
* warn about config the user never asked it to touch.
|
|
229
232
|
*
|
|
230
|
-
* Throws when the configured default is
|
|
231
|
-
*
|
|
233
|
+
* Throws ({@link noDefaultBrowserError}) when the configured default is
|
|
234
|
+
* undeclared, or when no profile exists that can launch here.
|
|
232
235
|
*/
|
|
233
236
|
export async function resolveProfileRefForStart(ref) {
|
|
234
237
|
if (ref && ref !== DEFAULT_PROFILE_ALIAS)
|
|
@@ -238,23 +241,45 @@ export async function resolveProfileRefForStart(ref) {
|
|
|
238
241
|
return ref;
|
|
239
242
|
return (await ensureDefaultBrowserProfile()).name;
|
|
240
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* The error a bare `agents browser start` raises when this machine has no
|
|
246
|
+
* launchable default browser. Its own function so the wording — the one thing
|
|
247
|
+
* the user reads when a browser won't start — stays in one place and is
|
|
248
|
+
* testable without spawning anything.
|
|
249
|
+
*
|
|
250
|
+
* Since PHNX-3296 this is a hard stop, NOT a silent auto-create. The old
|
|
251
|
+
* behavior probed the installed Chromium-family browsers and minted a
|
|
252
|
+
* logged-out `auto-chrome` profile on the spot; agents then drove a signed-out
|
|
253
|
+
* Chrome that popped up on the user's Mac unbidden. Which browser agents drive
|
|
254
|
+
* is a choice the user makes once, in `agents setup` — never one this code
|
|
255
|
+
* makes for them.
|
|
256
|
+
*/
|
|
257
|
+
export function noDefaultBrowserError() {
|
|
258
|
+
return new Error('No default browser is configured on this machine. ' +
|
|
259
|
+
'Run `agents setup` (or `agents browser use <name>`) to pick the browser agents should drive. ' +
|
|
260
|
+
'If this is a headless worker, use the fleet hub instead: `agents config set browser.device <host>`.');
|
|
261
|
+
}
|
|
241
262
|
/**
|
|
242
263
|
* Resolve the profile a bare `agents browser start` uses.
|
|
243
264
|
*
|
|
244
265
|
* Order: (1) the device-local configured default (`agents browser use <name>`)
|
|
245
266
|
* when it names a profile that exists and can launch here; (2) an existing
|
|
246
|
-
* auto-detected profile
|
|
247
|
-
*
|
|
248
|
-
*
|
|
267
|
+
* auto-detected profile (`auto-chrome`, or a legacy `default`) that can launch
|
|
268
|
+
* here. When neither resolves, THROW ({@link noDefaultBrowserError}) rather than
|
|
269
|
+
* detect-and-create — see that function for why (PHNX-3296).
|
|
249
270
|
*
|
|
250
271
|
* Two failure modes at the configured-default step are not the same:
|
|
251
272
|
* - No device declares the name (including a leftover central `browser:`
|
|
252
|
-
* entry that was never claimed) → throw.
|
|
253
|
-
* hand the agent a logged-out browser while `browser.profile` still
|
|
254
|
-
* the credentialed one.
|
|
273
|
+
* entry that was never claimed) → throw. Falling back to a minted profile
|
|
274
|
+
* would hand the agent a logged-out browser while `browser.profile` still
|
|
275
|
+
* names the credentialed one.
|
|
255
276
|
* - The name is declared, but its browser/binary is not installed HERE →
|
|
256
|
-
* warn and fall through
|
|
257
|
-
* missing
|
|
277
|
+
* warn and fall through to an existing profile, else the actionable throw.
|
|
278
|
+
* That is a missing binary on this box, not a missing identity.
|
|
279
|
+
*
|
|
280
|
+
* This RECOGNIZES a pre-existing `auto-chrome`/legacy `default` so installs that
|
|
281
|
+
* already carry one keep resolving it (and its running browser + runtime dirs),
|
|
282
|
+
* but it never CREATES one.
|
|
258
283
|
*/
|
|
259
284
|
export async function ensureDefaultBrowserProfile() {
|
|
260
285
|
const configured = getConfiguredDefaultProfileName();
|
|
@@ -275,7 +300,7 @@ export async function ensureDefaultBrowserProfile() {
|
|
|
275
300
|
`Or unset the default with: agents browser use --unset`);
|
|
276
301
|
}
|
|
277
302
|
console.warn(`warning: configured default browser profile "${configured}" can't launch on this ` +
|
|
278
|
-
`machine (its browser/binary isn't installed here)
|
|
303
|
+
`machine (its browser/binary isn't installed here). ` +
|
|
279
304
|
`Fix with: agents browser use <name> (or --unset)`);
|
|
280
305
|
}
|
|
281
306
|
// Prefer whichever auto-detected profile this machine already carries: the
|
|
@@ -285,38 +310,12 @@ export async function ensureDefaultBrowserProfile() {
|
|
|
285
310
|
const existing = await getAutoDetectedProfile();
|
|
286
311
|
if (existing && isProfileLaunchableHere(existing))
|
|
287
312
|
return existing;
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
'Chrome DevTools Protocol, which they don\'t implement.');
|
|
295
|
-
}
|
|
296
|
-
const freePort = await findFreeProfilePort();
|
|
297
|
-
const profile = {
|
|
298
|
-
// Regenerate under the name that is already on disk when there is one, so a
|
|
299
|
-
// stale legacy `default` is repaired in place instead of leaving the user
|
|
300
|
-
// with two auto-detected profiles.
|
|
301
|
-
name: existing?.name ?? DEFAULT_BROWSER_PROFILE_NAME,
|
|
302
|
-
description: `Auto-detected ${detected.browserType} profile`,
|
|
303
|
-
browser: detected.browserType,
|
|
304
|
-
binary: detected.binary,
|
|
305
|
-
endpoints: [`cdp://127.0.0.1:${freePort}`],
|
|
306
|
-
viewport: {
|
|
307
|
-
width: DEFAULT_VIEWPORT.width,
|
|
308
|
-
height: DEFAULT_VIEWPORT.height,
|
|
309
|
-
},
|
|
310
|
-
};
|
|
311
|
-
// A stale `default` (auto-created on another OS, unlaunchable here) is
|
|
312
|
-
// regenerated in place; otherwise this is the first-run create.
|
|
313
|
-
if (existing) {
|
|
314
|
-
await updateProfile(profile);
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
await createProfile(profile);
|
|
318
|
-
}
|
|
319
|
-
return profile;
|
|
313
|
+
// No configured default resolves and no existing profile launches here. We
|
|
314
|
+
// used to auto-detect the first installed browser and silently mint (or
|
|
315
|
+
// regenerate) an `auto-chrome` profile at this point — that is exactly the
|
|
316
|
+
// logged-out-Chrome-on-your-Mac bug PHNX-3296 removed. Stop and tell the user
|
|
317
|
+
// how to choose a browser instead.
|
|
318
|
+
throw noDefaultBrowserError();
|
|
320
319
|
}
|
|
321
320
|
/**
|
|
322
321
|
* Compute the LOCAL port a profile will occupy at runtime:
|
|
@@ -203,8 +203,10 @@ export declare const PRUNE_REASON_TEXT: Record<PruneReason, string>;
|
|
|
203
203
|
* - **the configured default** — this machine resolves a bare
|
|
204
204
|
* `agents browser start` to it; removing it breaks that command.
|
|
205
205
|
* - **the auto-detected profile** (`auto-chrome`, or the `default` an older
|
|
206
|
-
* build wrote) —
|
|
207
|
-
*
|
|
206
|
+
* build wrote) — still recognized and resolved by
|
|
207
|
+
* `ensureDefaultBrowserProfile` as this machine's default; since PHNX-3296
|
|
208
|
+
* it is no longer re-created on demand, so pruning it forces the user
|
|
209
|
+
* back through `agents setup` to get a default browser again.
|
|
208
210
|
*
|
|
209
211
|
* Known limitation: `BrowserProfileConfig` records no creation time, so a
|
|
210
212
|
* profile created seconds ago and not yet started is indistinguishable from an
|
|
@@ -343,8 +343,10 @@ export const PRUNE_REASON_TEXT = {
|
|
|
343
343
|
* - **the configured default** — this machine resolves a bare
|
|
344
344
|
* `agents browser start` to it; removing it breaks that command.
|
|
345
345
|
* - **the auto-detected profile** (`auto-chrome`, or the `default` an older
|
|
346
|
-
* build wrote) —
|
|
347
|
-
*
|
|
346
|
+
* build wrote) — still recognized and resolved by
|
|
347
|
+
* `ensureDefaultBrowserProfile` as this machine's default; since PHNX-3296
|
|
348
|
+
* it is no longer re-created on demand, so pruning it forces the user
|
|
349
|
+
* back through `agents setup` to get a default browser again.
|
|
348
350
|
*
|
|
349
351
|
* Known limitation: `BrowserProfileConfig` records no creation time, so a
|
|
350
352
|
* profile created seconds ago and not yet started is indistinguishable from an
|
|
@@ -2330,9 +2330,10 @@ export class BrowserService {
|
|
|
2330
2330
|
if (!opts.createIfMissing)
|
|
2331
2331
|
return null;
|
|
2332
2332
|
// The top-of-function consent gate already refused a fleet-remote create
|
|
2333
|
-
// here — before ensureDefaultBrowserProfile() below
|
|
2334
|
-
//
|
|
2335
|
-
//
|
|
2333
|
+
// here — before ensureDefaultBrowserProfile() below resolves a default — so
|
|
2334
|
+
// a refused request never touches the target machine. Since PHNX-3296 that
|
|
2335
|
+
// resolver never mints a profile: with no launchable default it throws, and
|
|
2336
|
+
// the throw surfaces to the caller exactly like any other start failure.
|
|
2336
2337
|
// Implicit start on the default / named profile.
|
|
2337
2338
|
let profileName = opts.profile;
|
|
2338
2339
|
if (!profileName) {
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forward an owner notification to a capable fleet peer over SSH (PHNX-3303).
|
|
3
|
+
*
|
|
4
|
+
* The owner's delivery provider for the rush-backed channels (imessage /
|
|
5
|
+
* telegram / slack / discord via the `rush` CLI) is macOS-only and
|
|
6
|
+
* keychain-bound, so a headless Linux worker structurally CANNOT ring the
|
|
7
|
+
* owner's phone: `agents feed post --level important` records the post but the
|
|
8
|
+
* owner sink fails with `rush CLI not found on PATH`, and the important post
|
|
9
|
+
* reaches nobody. `probeOwnerSink` (owner-sink.ts) already reports this as the
|
|
10
|
+
* `owner-sink-unreachable` doctor finding; this module is the runtime answer to
|
|
11
|
+
* it — instead of stranding the failure, hand the delivery to a reachable macOS
|
|
12
|
+
* peer that DOES have the provider.
|
|
13
|
+
*
|
|
14
|
+
* This mirrors the SSH reroute `agents message` (decideHostTaskRoute →
|
|
15
|
+
* runOnPeer) and the sessions fan-out already use for work that lives on another
|
|
16
|
+
* box: pick a reachable peer from the device registry and run the same `agents`
|
|
17
|
+
* verb there. Here the verb is `agents send --to owner`, which resolves the
|
|
18
|
+
* peer's own (fleet-synced) owner destination and delivers through its local
|
|
19
|
+
* rush — so the owner is addressed once, from the one box that can reach them.
|
|
20
|
+
*
|
|
21
|
+
* Best-effort seam: it never throws and never blocks the post. When no capable
|
|
22
|
+
* peer is reachable it resolves `undefined` and the caller keeps its original
|
|
23
|
+
* clean local error, exactly as before.
|
|
24
|
+
*/
|
|
25
|
+
import type { Meta } from '../types.js';
|
|
26
|
+
import type { SendResult } from './registry.js';
|
|
27
|
+
import type { DeviceProfile } from '../devices/registry.js';
|
|
28
|
+
/**
|
|
29
|
+
* Env marker set on the forwarded `agents send` so a box that received a
|
|
30
|
+
* forwarded owner notify never forwards it onward. `agents send` does not route
|
|
31
|
+
* through this module today, so this is defense-in-depth against a future
|
|
32
|
+
* consumer wiring forwarding into the send path and creating a fan-out loop.
|
|
33
|
+
*/
|
|
34
|
+
export declare const OWNER_FORWARD_GUARD_ENV = "AGENTS_OWNER_NO_FORWARD";
|
|
35
|
+
/** Why forwarding did not run, so a caller/test can assert the decision. */
|
|
36
|
+
export type OwnerForwardSkip = 'guarded' | 'not-rush-backed' | 'no-capable-peer';
|
|
37
|
+
export interface OwnerForwardPlan {
|
|
38
|
+
/** Ordered machine ids to try — capable (macOS), reachable, self excluded. */
|
|
39
|
+
candidates: string[];
|
|
40
|
+
/** Set when forwarding does not apply; the caller keeps its local error. */
|
|
41
|
+
skip?: OwnerForwardSkip;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* True when the resolved owner transport is the macOS-only rush family — the
|
|
45
|
+
* one case a Linux/headless box structurally cannot deliver and a peer can.
|
|
46
|
+
* `openclaw-telegram` and the local `desktop`/`mailbox` providers are NOT
|
|
47
|
+
* rush-backed, so a failure there is not a wrong-OS problem and is left as-is.
|
|
48
|
+
* Mirrors the same `RUSH_CHANNELS.includes(transport)` gate in owner-sink.ts.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isRushBackedTransport(channel: string, meta: Meta): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Decide which peers can deliver the owner notification, in try order. Pure —
|
|
53
|
+
* no I/O — so the channel gate, the recursion guard, self-exclusion, and the
|
|
54
|
+
* capability/ordering rules are unit-testable without a live tailnet.
|
|
55
|
+
*
|
|
56
|
+
* Only macOS peers are candidates: the rush owner transport is macOS-only, so a
|
|
57
|
+
* Linux/Windows peer could not deliver it either. The configured
|
|
58
|
+
* `interactive.host` (the box the operator sits at, where rush is signed in) is
|
|
59
|
+
* tried first when it is among the candidates.
|
|
60
|
+
*/
|
|
61
|
+
export declare function planOwnerForward(channel: string, meta: Meta, devices: DeviceProfile[], self: string, opts?: {
|
|
62
|
+
guarded?: boolean;
|
|
63
|
+
}): OwnerForwardPlan;
|
|
64
|
+
/**
|
|
65
|
+
* Deliver `text` to the owner FROM one peer over SSH. Runs the peer's own
|
|
66
|
+
* `agents send --to owner --text <text> --json`, which resolves that box's
|
|
67
|
+
* fleet-synced owner destination and delivers through its local provider.
|
|
68
|
+
* Resolves the parsed `SendResult`, or `undefined` when the peer is
|
|
69
|
+
* unreachable / not a dialable device / answered with unparseable output —
|
|
70
|
+
* every one of which means "try the next peer".
|
|
71
|
+
*/
|
|
72
|
+
export type PeerOwnerSender = (machine: string, text: string) => Promise<SendResult | undefined>;
|
|
73
|
+
/**
|
|
74
|
+
* Try each capable peer in order and return the first successful delivery. A
|
|
75
|
+
* peer that is unreachable or reports its own delivery failure is skipped and
|
|
76
|
+
* the next is tried; the first `ok:true` wins and stops the sweep so the owner's
|
|
77
|
+
* phone rings once. Resolves `undefined` when forwarding does not apply or no
|
|
78
|
+
* peer delivered — the caller then keeps its original local error.
|
|
79
|
+
*
|
|
80
|
+
* The transport (`send`) is injectable so the try-order / first-success / stop
|
|
81
|
+
* orchestration is testable without a live SSH host; the default runs the real
|
|
82
|
+
* `agents send --to owner` over SSH.
|
|
83
|
+
*/
|
|
84
|
+
export declare function forwardOwnerNotifyToPeer(text: string, channel: string, meta: Meta, opts?: {
|
|
85
|
+
self?: string;
|
|
86
|
+
devices?: DeviceProfile[];
|
|
87
|
+
send?: PeerOwnerSender;
|
|
88
|
+
}): Promise<SendResult | undefined>;
|