@phnx-labs/agents-cli 1.20.68 → 1.20.70

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +30 -7
  3. package/dist/bin/agents +0 -0
  4. package/dist/commands/computer.d.ts +26 -0
  5. package/dist/commands/computer.js +173 -149
  6. package/dist/commands/doctor.js +5 -0
  7. package/dist/commands/exec.d.ts +18 -0
  8. package/dist/commands/exec.js +88 -6
  9. package/dist/commands/fork.d.ts +9 -0
  10. package/dist/commands/fork.js +67 -0
  11. package/dist/commands/run-account-picker.d.ts +14 -0
  12. package/dist/commands/run-account-picker.js +131 -0
  13. package/dist/commands/setup-browser.d.ts +18 -0
  14. package/dist/commands/setup-browser.js +142 -0
  15. package/dist/commands/setup-computer.d.ts +19 -0
  16. package/dist/commands/setup-computer.js +133 -0
  17. package/dist/commands/setup-share.d.ts +17 -0
  18. package/dist/commands/setup-share.js +85 -0
  19. package/dist/commands/setup.d.ts +1 -1
  20. package/dist/commands/setup.js +58 -1
  21. package/dist/commands/share.d.ts +15 -0
  22. package/dist/commands/share.js +10 -4
  23. package/dist/commands/ssh.js +202 -9
  24. package/dist/commands/view.d.ts +4 -14
  25. package/dist/commands/view.js +32 -30
  26. package/dist/index.js +2 -1
  27. package/dist/lib/agents.d.ts +10 -0
  28. package/dist/lib/agents.js +32 -0
  29. package/dist/lib/auth-health.d.ts +141 -0
  30. package/dist/lib/auth-health.js +277 -0
  31. package/dist/lib/browser/chrome.d.ts +9 -0
  32. package/dist/lib/browser/chrome.js +22 -0
  33. package/dist/lib/computer/download.d.ts +54 -0
  34. package/dist/lib/computer/download.js +146 -0
  35. package/dist/lib/computer-rpc.js +9 -3
  36. package/dist/lib/daemon.js +38 -0
  37. package/dist/lib/devices/connect.d.ts +15 -0
  38. package/dist/lib/devices/connect.js +17 -5
  39. package/dist/lib/devices/health-report.d.ts +11 -0
  40. package/dist/lib/devices/health-report.js +73 -4
  41. package/dist/lib/devices/stats-cache.d.ts +36 -0
  42. package/dist/lib/devices/stats-cache.js +115 -0
  43. package/dist/lib/devices/terminfo.d.ts +44 -0
  44. package/dist/lib/devices/terminfo.js +167 -0
  45. package/dist/lib/rotate.d.ts +12 -8
  46. package/dist/lib/rotate.js +22 -23
  47. package/dist/lib/session/fork.d.ts +32 -0
  48. package/dist/lib/session/fork.js +101 -0
  49. package/dist/lib/startup/command-registry.d.ts +1 -0
  50. package/dist/lib/startup/command-registry.js +2 -0
  51. package/dist/lib/usage.d.ts +23 -0
  52. package/dist/lib/usage.js +84 -0
  53. package/package.json +1 -1
@@ -0,0 +1,133 @@
1
+ /**
2
+ * `agents setup computer` — guided setup for `agents computer` on macOS: fetch +
3
+ * verify the signed helper, install it, then walk the user through the two TCC
4
+ * permission grants (Accessibility + Screen Recording) by opening the exact
5
+ * System Settings panes and polling until the grant lands.
6
+ *
7
+ * The plain `agents computer setup` / `start` commands remain for scripted use;
8
+ * this wizard chains them with the permission hand-holding a fresh machine needs.
9
+ * Idempotent: re-running re-installs the current helper and re-checks trust.
10
+ */
11
+ import os from 'node:os';
12
+ import { execFileSync } from 'node:child_process';
13
+ import chalk from 'chalk';
14
+ import { installComputerHelperMacLocal, activateComputerHelperMacLocal, probeComputerTrust, } from './computer.js';
15
+ import { isInteractiveTerminal, isPromptCancelled } from './utils.js';
16
+ const ACCESSIBILITY_PANE = 'x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility';
17
+ const SCREEN_PANE = 'x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture';
18
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
19
+ /** Open a System Settings Privacy pane (best-effort — never throws). */
20
+ function openPane(pane) {
21
+ try {
22
+ execFileSync('/usr/bin/open', [pane], { stdio: 'ignore' });
23
+ }
24
+ catch {
25
+ // ignore — we print the manual path as a fallback
26
+ }
27
+ }
28
+ /**
29
+ * Interactive computer setup. Returns true if the helper is installed and trust
30
+ * is granted (or the user chose to finish later), false if unsupported/aborted.
31
+ * Never throws on cancel — the `agents setup` hub relies on that.
32
+ */
33
+ export async function runComputerWizard() {
34
+ if (os.platform() !== 'darwin') {
35
+ console.log(chalk.yellow('`agents setup computer` configures the macOS helper (local control).'));
36
+ console.log(chalk.dim('On Windows, provision a remote host from a Mac/Linux box instead: `agents computer setup --host <device>`.'));
37
+ return false;
38
+ }
39
+ // 1. Download + verify + install the signed, notarized helper.
40
+ console.log(chalk.bold('Installing the Computer Helper...'));
41
+ try {
42
+ await installComputerHelperMacLocal();
43
+ }
44
+ catch (err) {
45
+ console.error(chalk.red(`Install failed: ${err.message}`));
46
+ return false;
47
+ }
48
+ // 2. Activate the daemon so macOS can attribute the TCC grants to it.
49
+ console.log(chalk.bold('\nStarting the helper...'));
50
+ let trusted = false;
51
+ try {
52
+ ({ trusted } = await activateComputerHelperMacLocal());
53
+ }
54
+ catch (err) {
55
+ console.error(chalk.red(`Could not start the helper: ${err.message}`));
56
+ return false;
57
+ }
58
+ // 3. Guide the two permission grants if not already trusted.
59
+ if (!trusted) {
60
+ console.log(chalk.bold('\nGrant two permissions to "Computer Helper" (one-time):'));
61
+ console.log(' 1. ' + chalk.cyan('Accessibility') + chalk.dim(' — lets it click/type'));
62
+ console.log(' 2. ' + chalk.cyan('Screen Recording') + chalk.dim(' — lets it screenshot windows'));
63
+ console.log(chalk.dim('\nOpening System Settings > Privacy & Security ...'));
64
+ openPane(ACCESSIBILITY_PANE);
65
+ if (isInteractiveTerminal()) {
66
+ trusted = await pollForTrust();
67
+ }
68
+ // Also nudge the Screen Recording pane so both are visible.
69
+ openPane(SCREEN_PANE);
70
+ if (!trusted) {
71
+ console.log(chalk.yellow('\nAccessibility not granted yet.'));
72
+ console.log(chalk.dim('Finish both grants in System Settings, then run: ') + chalk.cyan('agents computer start'));
73
+ console.log(chalk.dim(' Accessibility: System Settings > Privacy & Security > Accessibility'));
74
+ console.log(chalk.dim(' Screen Recording: System Settings > Privacy & Security > Screen Recording'));
75
+ }
76
+ }
77
+ if (trusted) {
78
+ console.log(chalk.green('\nComputer control is ready.'));
79
+ }
80
+ // 4. App allow-list guidance (deny-by-default) — always shown; it's the gate
81
+ // between "trusted" and "can actually drive an app".
82
+ console.log(chalk.bold('\nWhitelist the apps the helper may drive (default is deny-all):'));
83
+ console.log(chalk.dim(' Add a YAML under ~/.agents/permissions/groups/, e.g. computer.yaml:'));
84
+ console.log(chalk.dim(' name: computer'));
85
+ console.log(chalk.dim(' allow:'));
86
+ console.log(chalk.dim(' - "Computer(com.apple.finder)"'));
87
+ console.log(chalk.dim(' - "Computer(com.apple.notes)"'));
88
+ console.log(chalk.dim(' Then reload: ') + chalk.cyan('agents computer reload'));
89
+ return trusted;
90
+ }
91
+ /**
92
+ * Poll the daemon's trust status while the user toggles the Accessibility
93
+ * checkbox in System Settings. Bounded to ~2 minutes; the user can Ctrl+C.
94
+ */
95
+ async function pollForTrust() {
96
+ const { default: ora } = await import('ora');
97
+ const spinner = ora('Waiting for Accessibility to be granted (toggle the checkbox in System Settings)...').start();
98
+ const deadline = Date.now() + 120_000;
99
+ try {
100
+ while (Date.now() < deadline) {
101
+ if (await probeComputerTrust()) {
102
+ spinner.succeed('Accessibility granted.');
103
+ return true;
104
+ }
105
+ await sleep(2000);
106
+ }
107
+ spinner.stop();
108
+ return false;
109
+ }
110
+ catch {
111
+ spinner.stop();
112
+ return false;
113
+ }
114
+ }
115
+ /** Register `agents setup computer` under the parent `setup` command. */
116
+ export function registerSetupComputerCommand(setupCmd) {
117
+ setupCmd
118
+ .command('computer')
119
+ .description('Set up `agents computer` (macOS) — install the signed helper and grant control permissions.')
120
+ .action(async () => {
121
+ try {
122
+ await runComputerWizard();
123
+ }
124
+ catch (err) {
125
+ if (isPromptCancelled(err)) {
126
+ console.log(chalk.yellow('\nCancelled'));
127
+ return;
128
+ }
129
+ console.error(chalk.red(err.message));
130
+ process.exitCode = 1;
131
+ }
132
+ });
133
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * `agents setup share` — interactive wizard to configure the `agents share`
3
+ * endpoint (Cloudflare R2 + Worker). A friendly front door over the existing
4
+ * `agents share setup` (provision) and `agents share join` flows, reusing their
5
+ * exact logic so there is a single source of truth for provisioning.
6
+ *
7
+ * Idempotent: re-running shows the current endpoint and offers to reconfigure.
8
+ */
9
+ import type { Command } from 'commander';
10
+ /**
11
+ * Interactive share setup. Returns true if the user configured (or already had)
12
+ * an endpoint, false if they skipped. Never throws on user cancel — callers
13
+ * (the `agents setup` hub) rely on that to keep the fresh-machine flow going.
14
+ */
15
+ export declare function runShareWizard(): Promise<boolean>;
16
+ /** Register `agents setup share` under the parent `setup` command. */
17
+ export declare function registerSetupShareCommand(setupCmd: Command): void;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * `agents setup share` — interactive wizard to configure the `agents share`
3
+ * endpoint (Cloudflare R2 + Worker). A friendly front door over the existing
4
+ * `agents share setup` (provision) and `agents share join` flows, reusing their
5
+ * exact logic so there is a single source of truth for provisioning.
6
+ *
7
+ * Idempotent: re-running shows the current endpoint and offers to reconfigure.
8
+ */
9
+ import chalk from 'chalk';
10
+ import { DEFAULT_BUCKET_NAME, DEFAULT_CF_BUNDLE, DEFAULT_WORKER_NAME, readShareConfig, } from '../lib/share/config.js';
11
+ import { runShareProvision, runShareJoin } from './share.js';
12
+ import { isInteractiveTerminal, isPromptCancelled } from './utils.js';
13
+ /**
14
+ * Interactive share setup. Returns true if the user configured (or already had)
15
+ * an endpoint, false if they skipped. Never throws on user cancel — callers
16
+ * (the `agents setup` hub) rely on that to keep the fresh-machine flow going.
17
+ */
18
+ export async function runShareWizard() {
19
+ if (!isInteractiveTerminal()) {
20
+ console.error(chalk.red('agents setup share needs an interactive terminal. ' +
21
+ 'Non-interactively, use `agents share setup` (provision) or `agents share join <url>`.'));
22
+ return false;
23
+ }
24
+ const existing = readShareConfig();
25
+ if (existing) {
26
+ console.log(chalk.dim(`Share is already configured → ${chalk.green(existing.baseUrl)}`));
27
+ console.log(chalk.dim(` worker ${existing.workerName} · bucket ${existing.bucketName} · account ${existing.accountId}`));
28
+ const { confirm } = await import('@inquirer/prompts');
29
+ const reconfigure = await confirm({ message: 'Reconfigure the share endpoint?', default: false });
30
+ if (!reconfigure) {
31
+ console.log(chalk.dim('Keeping the current endpoint.'));
32
+ return true;
33
+ }
34
+ }
35
+ const { select } = await import('@inquirer/prompts');
36
+ const mode = await select({
37
+ message: 'How do you want to publish shared links?',
38
+ choices: [
39
+ {
40
+ name: 'Provision my own (Cloudflare R2 + Worker)',
41
+ value: 'provision',
42
+ description: 'One-time: creates a bucket + Worker on your Cloudflare account (~$0). Needs a Cloudflare API token.',
43
+ },
44
+ {
45
+ name: 'Join an existing endpoint (a teammate already provisioned one)',
46
+ value: 'join',
47
+ description: 'Paste the base URL + write token from whoever owns the endpoint.',
48
+ },
49
+ ],
50
+ });
51
+ if (mode === 'provision') {
52
+ await runShareProvision({
53
+ bundle: DEFAULT_CF_BUNDLE,
54
+ worker: DEFAULT_WORKER_NAME,
55
+ bucket: DEFAULT_BUCKET_NAME,
56
+ });
57
+ return true;
58
+ }
59
+ const { input } = await import('@inquirer/prompts');
60
+ const baseUrl = await input({
61
+ message: 'Endpoint base URL (e.g. https://share.agents-cli.sh)',
62
+ validate: (v) => (v.trim().startsWith('http') ? true : 'Enter the full https:// URL of the endpoint.'),
63
+ });
64
+ await runShareJoin(baseUrl.trim());
65
+ return true;
66
+ }
67
+ /** Register `agents setup share` under the parent `setup` command. */
68
+ export function registerSetupShareCommand(setupCmd) {
69
+ setupCmd
70
+ .command('share')
71
+ .description('Configure the `agents share` endpoint (Cloudflare R2 + Worker) — provision your own or join one.')
72
+ .action(async () => {
73
+ try {
74
+ await runShareWizard();
75
+ }
76
+ catch (err) {
77
+ if (isPromptCancelled(err)) {
78
+ console.log(chalk.yellow('\nCancelled'));
79
+ return;
80
+ }
81
+ console.error(chalk.red(err.message));
82
+ process.exitCode = 1;
83
+ }
84
+ });
85
+ }
@@ -18,5 +18,5 @@ export declare function runSetup(program: Command, options?: {
18
18
  * error and exit.
19
19
  */
20
20
  export declare function ensureInitialized(program: Command): Promise<void>;
21
- /** Register the `agents setup` command. */
21
+ /** Register the `agents setup` command and its capability subcommands. */
22
22
  export declare function registerSetupCommand(program: Command): void;
@@ -18,6 +18,9 @@ import { AGENTS, agentConfigDirName, getUnmanagedAgentInstalls, countSessionFile
18
18
  import { setGlobalDefault } from '../lib/versions.js';
19
19
  import { ensureShimCurrent, switchHomeFileSymlinks, isShimsInPath, addShimsToPath, getPathSetupInstructions } from '../lib/shims.js';
20
20
  import { setHelpSections } from '../lib/help.js';
21
+ import { registerSetupBrowserCommand, runBrowserWizard } from './setup-browser.js';
22
+ import { registerSetupComputerCommand, runComputerWizard } from './setup-computer.js';
23
+ import { registerSetupShareCommand, runShareWizard } from './setup-share.js';
21
24
  const HOME = os.homedir();
22
25
  /**
23
26
  * Import an existing unmanaged agent installation into agents-cli.
@@ -186,6 +189,10 @@ export async function runSetup(program, options = {}) {
186
189
  }
187
190
  if (options.suppressFooter)
188
191
  return;
192
+ // Fresh-machine hub: offer to set up the optional capabilities that need their
193
+ // own guided flow. TTY-only and fully opt-in — a non-interactive `agents setup`
194
+ // stops at the system-repo bootstrap above, unchanged.
195
+ await runSetupHub();
189
196
  console.log(chalk.bold('\nSetup complete. Try:'));
190
197
  console.log(chalk.cyan(' agents view ') + chalk.gray(' # see what\'s installed'));
191
198
  console.log(chalk.cyan(' agents run <agent> "hello" ') + chalk.gray(' # run an agent'));
@@ -217,13 +224,52 @@ export async function ensureInitialized(program) {
217
224
  }
218
225
  await runSetup(program, { suppressFooter: true });
219
226
  }
220
- /** Register the `agents setup` command. */
227
+ /**
228
+ * Interactive "what else do you want to set up?" menu shown after the bare
229
+ * `agents setup` finishes on a TTY. Each pick runs that capability's guided
230
+ * wizard. Never throws — a cancel or an optional wizard's error just skips the
231
+ * rest and lets core setup complete.
232
+ */
233
+ async function runSetupHub() {
234
+ if (!isInteractiveTerminal())
235
+ return;
236
+ try {
237
+ const { checkbox } = await import('@inquirer/prompts');
238
+ const picks = await checkbox({
239
+ message: 'Set up optional capabilities now? (space to select, enter to confirm)',
240
+ choices: [
241
+ { name: 'browser — drive a real Chrome/Brave/Edge for web automation', value: 'browser' },
242
+ { name: 'computer — control native macOS apps (screenshot, click, type)', value: 'computer' },
243
+ { name: 'share — publish shareable links (Cloudflare R2 + Worker)', value: 'share' },
244
+ ],
245
+ });
246
+ for (const pick of picks) {
247
+ console.log();
248
+ if (pick === 'browser')
249
+ await runBrowserWizard();
250
+ else if (pick === 'computer')
251
+ await runComputerWizard();
252
+ else if (pick === 'share')
253
+ await runShareWizard();
254
+ }
255
+ }
256
+ catch (err) {
257
+ if (isPromptCancelled(err))
258
+ return;
259
+ console.log(chalk.yellow(`Optional setup skipped: ${err.message}`));
260
+ }
261
+ }
262
+ /** Register the `agents setup` command and its capability subcommands. */
221
263
  export function registerSetupCommand(program) {
222
264
  const setupCmd = program
223
265
  .command('setup')
224
266
  .description('First-time setup. Clones a config repo and installs agent CLIs.')
225
267
  .option('-f, --force', 'Re-run setup even if ~/.agents/.system/ already exists (use with caution)')
226
268
  .option('--no-system-repo', 'Skip cloning the system repo (you must populate ~/.agents/.system/ yourself)');
269
+ // Capability subcommands: `agents setup browser|computer|share`.
270
+ registerSetupBrowserCommand(setupCmd);
271
+ registerSetupComputerCommand(setupCmd);
272
+ registerSetupShareCommand(setupCmd);
227
273
  setHelpSections(setupCmd, {
228
274
  examples: `
229
275
  # First-time setup (clones the system repo into ~/.agents/.system/)
@@ -231,11 +277,22 @@ export function registerSetupCommand(program) {
231
277
 
232
278
  # Re-run after corruption or to repair ~/.agents/.system/
233
279
  agents setup --force
280
+
281
+ # Set up a specific capability on its own
282
+ agents setup browser
283
+ agents setup computer
284
+ agents setup share
234
285
  `,
235
286
  notes: `
236
287
  What it does:
237
288
  1. Clones the system repo into ~/.agents/.system/
238
289
  2. Imports any unmanaged agent installations it finds
290
+ 3. On a TTY, offers to set up optional capabilities (browser/computer/share)
291
+
292
+ Capability setup can also be run any time on its own:
293
+ agents setup browser # detect a browser + create the default profile
294
+ agents setup computer # install the signed macOS helper + grant permissions
295
+ agents setup share # provision or join a Cloudflare share endpoint
239
296
 
240
297
  To install CLIs from agents.yaml and sync resources into version homes:
241
298
  agents repo refresh -y
@@ -1,2 +1,17 @@
1
1
  import type { Command } from 'commander';
2
2
  export declare function registerShareCommands(program: Command): void;
3
+ /** Provision a fresh R2 bucket + Worker on the user's Cloudflare and persist the
4
+ * endpoint config + write token. Shared by `agents share setup` and the unified
5
+ * `agents setup share` wizard. */
6
+ export declare function runShareProvision(opts: {
7
+ bundle: string;
8
+ worker: string;
9
+ bucket: string;
10
+ account?: string;
11
+ token?: string;
12
+ domain?: string;
13
+ }): Promise<void>;
14
+ /** Join an existing share endpoint (no provisioning): prompt for the endpoint
15
+ * details + write token and persist them. Shared by `agents share join` and the
16
+ * unified `agents setup share` wizard. */
17
+ export declare function runShareJoin(baseUrl: string): Promise<void>;
@@ -52,7 +52,7 @@ export function registerShareCommands(program) {
52
52
  .option('--domain <host>', 'also map a custom domain (e.g. share.agents-cli.sh) if the token owns the zone')
53
53
  .action(async (opts) => {
54
54
  try {
55
- await runSetup(opts);
55
+ await runShareProvision(opts);
56
56
  }
57
57
  catch (e) {
58
58
  console.error(chalk.red(e.message));
@@ -65,7 +65,7 @@ export function registerShareCommands(program) {
65
65
  .argument('<baseUrl>', 'base URL of the endpoint, e.g. https://share.agents-cli.sh')
66
66
  .action(async (baseUrl) => {
67
67
  try {
68
- await runJoin(baseUrl);
68
+ await runShareJoin(baseUrl);
69
69
  }
70
70
  catch (e) {
71
71
  console.error(chalk.red(e.message));
@@ -85,7 +85,10 @@ export function registerShareCommands(program) {
85
85
  console.log(chalk.dim(`worker ${cfg.workerName} · bucket ${cfg.bucketName} · account ${cfg.accountId}`));
86
86
  });
87
87
  }
88
- async function runSetup(opts) {
88
+ /** Provision a fresh R2 bucket + Worker on the user's Cloudflare and persist the
89
+ * endpoint config + write token. Shared by `agents share setup` and the unified
90
+ * `agents setup share` wizard. */
91
+ export async function runShareProvision(opts) {
89
92
  const { default: ora } = await import('ora');
90
93
  const { input } = await import('@inquirer/prompts');
91
94
  const { apiToken, accountId: acctFromBundle } = readCloudflareCreds(opts.bundle, {
@@ -132,7 +135,10 @@ async function runSetup(opts) {
132
135
  throw e;
133
136
  }
134
137
  }
135
- async function runJoin(baseUrl) {
138
+ /** Join an existing share endpoint (no provisioning): prompt for the endpoint
139
+ * details + write token and persist them. Shared by `agents share join` and the
140
+ * unified `agents setup share` wizard. */
141
+ export async function runShareJoin(baseUrl) {
136
142
  const { password, input } = await import('@inquirer/prompts');
137
143
  const clean = baseUrl.replace(/\/+$/, '');
138
144
  const workerName = await input({ message: 'Worker name', default: DEFAULT_WORKER_NAME });