@phnx-labs/agents-cli 1.20.68 → 1.20.69
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 +45 -0
- package/README.md +11 -1
- package/dist/bin/agents +0 -0
- package/dist/commands/computer.d.ts +26 -0
- package/dist/commands/computer.js +173 -149
- package/dist/commands/exec.d.ts +18 -0
- package/dist/commands/exec.js +88 -6
- package/dist/commands/fork.d.ts +9 -0
- package/dist/commands/fork.js +67 -0
- package/dist/commands/run-account-picker.d.ts +14 -0
- package/dist/commands/run-account-picker.js +131 -0
- package/dist/commands/setup-browser.d.ts +18 -0
- package/dist/commands/setup-browser.js +142 -0
- package/dist/commands/setup-computer.d.ts +19 -0
- package/dist/commands/setup-computer.js +133 -0
- package/dist/commands/setup-share.d.ts +17 -0
- package/dist/commands/setup-share.js +85 -0
- package/dist/commands/setup.d.ts +1 -1
- package/dist/commands/setup.js +58 -1
- package/dist/commands/share.d.ts +15 -0
- package/dist/commands/share.js +10 -4
- package/dist/commands/ssh.js +164 -0
- package/dist/commands/view.d.ts +3 -14
- package/dist/commands/view.js +27 -28
- package/dist/index.js +2 -1
- package/dist/lib/agents.d.ts +10 -0
- package/dist/lib/agents.js +32 -0
- package/dist/lib/auth-health.d.ts +103 -0
- package/dist/lib/auth-health.js +232 -0
- package/dist/lib/browser/chrome.d.ts +9 -0
- package/dist/lib/browser/chrome.js +22 -0
- package/dist/lib/computer/download.d.ts +51 -0
- package/dist/lib/computer/download.js +145 -0
- package/dist/lib/computer-rpc.js +9 -3
- package/dist/lib/devices/connect.d.ts +15 -0
- package/dist/lib/devices/connect.js +17 -5
- package/dist/lib/devices/terminfo.d.ts +44 -0
- package/dist/lib/devices/terminfo.js +167 -0
- package/dist/lib/menubar/MenubarHelper.app/Contents/MacOS/MenubarHelper +0 -0
- package/dist/lib/rotate.d.ts +12 -8
- package/dist/lib/rotate.js +22 -23
- package/dist/lib/session/fork.d.ts +32 -0
- package/dist/lib/session/fork.js +101 -0
- package/dist/lib/startup/command-registry.d.ts +1 -0
- package/dist/lib/startup/command-registry.js +2 -0
- package/dist/lib/usage.d.ts +23 -0
- package/dist/lib/usage.js +84 -0
- 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
|
+
}
|
package/dist/commands/setup.d.ts
CHANGED
|
@@ -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;
|
package/dist/commands/setup.js
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
package/dist/commands/share.d.ts
CHANGED
|
@@ -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>;
|
package/dist/commands/share.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 });
|
package/dist/commands/ssh.js
CHANGED
|
@@ -29,6 +29,7 @@ import { isInteractiveTerminal, isPromptCancelled } from './utils.js';
|
|
|
29
29
|
import { hostNameFor, renderSshConfig } from '../lib/devices/ssh-config.js';
|
|
30
30
|
import { ASKPASS_BUNDLE_ENV, ASKPASS_KEY_ENV, buildSshInvocation, writeAskpassShim, } from '../lib/devices/connect.js';
|
|
31
31
|
import { ensureManagedKnownHostsDir, isHostPinned } from '../lib/devices/known-hosts.js';
|
|
32
|
+
import { shouldSyncTerminfo, syncTerminfoToDevice, terminfoHostKey } from '../lib/devices/terminfo.js';
|
|
32
33
|
import { fanOutDevices, planFleetTargets, remoteFleetTargets, runFleet, skipLabel, upgradeCommand, } from '../lib/devices/fleet.js';
|
|
33
34
|
import { fleetCapacity, fmtBytes, headroom, probeLocalStats, probeFleetStats, } from '../lib/devices/health.js';
|
|
34
35
|
import { buildFleetHealthReport, renderFleetMatrix, renderFleetWarnings, } from '../lib/devices/health-report.js';
|
|
@@ -36,6 +37,8 @@ import { checkSyncStatus, countOrphans } from '../lib/drift.js';
|
|
|
36
37
|
import { checkAllClis } from '../lib/teams/agents.js';
|
|
37
38
|
import { buildRemoteAgentsInvocation } from '../lib/hosts/remote-cmd.js';
|
|
38
39
|
import { sshExecAsync } from '../lib/ssh-exec.js';
|
|
40
|
+
import { ALL_AGENT_IDS } from '../lib/agents.js';
|
|
41
|
+
import { formatCheckedAge, isDeadVerdict, probeLocalFleetAuth, summarizeVerdicts, verdictLabel, writeFleetAuthRows, } from '../lib/auth-health.js';
|
|
39
42
|
/** One-line summary of a device for `list`. `isSelf` marks the machine this
|
|
40
43
|
* command is running on so it stands out from the rest of the tailnet. */
|
|
41
44
|
function deviceSummary(d, isSelf = false) {
|
|
@@ -311,6 +314,150 @@ async function runFleetStatus(opts) {
|
|
|
311
314
|
if (opts.strict && report.hasWarnings)
|
|
312
315
|
process.exitCode = 1;
|
|
313
316
|
}
|
|
317
|
+
/** SSH into a host and run its local auth probe, returning its rows. */
|
|
318
|
+
async function probeRemoteAuth(target) {
|
|
319
|
+
const isWin = /^win/i.test((target.platform ?? '').trim());
|
|
320
|
+
const env = isWin ? undefined : { PATH: '$HOME/.agents/.cache/shims:$HOME/.local/bin:$PATH' };
|
|
321
|
+
const cmd = buildRemoteAgentsInvocation(['devices', 'ping', '--local', '--json'], undefined, isWin ? 'windows' : undefined, env);
|
|
322
|
+
const res = await sshExecAsync(target.name, cmd, { timeoutMs: 60000, multiplex: true });
|
|
323
|
+
if (res.code !== 0) {
|
|
324
|
+
throw new Error(res.timedOut ? 'timed out' : (res.stderr.trim() || `exit ${res.code ?? 'unknown'}`));
|
|
325
|
+
}
|
|
326
|
+
const parsed = JSON.parse(res.stdout);
|
|
327
|
+
return parsed.rows ?? [];
|
|
328
|
+
}
|
|
329
|
+
async function runFleetPing(opts) {
|
|
330
|
+
const self = machineId();
|
|
331
|
+
const cliVersion = getCliVersion();
|
|
332
|
+
// --local: probe just this host. Used both directly and as the fan-out worker.
|
|
333
|
+
if (opts.local) {
|
|
334
|
+
const rows = await probeLocalFleetAuth({ cliVersion });
|
|
335
|
+
writeFleetAuthRows(self, rows);
|
|
336
|
+
if (opts.json) {
|
|
337
|
+
console.log(JSON.stringify({ host: self, rows }));
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
for (const line of renderAuthMatrix([{ host: self, rows }], { verbose: opts.verbose }))
|
|
341
|
+
console.log(line);
|
|
342
|
+
}
|
|
343
|
+
if (opts.strict && rows.some((r) => isDeadVerdict(r.health.verdict))) {
|
|
344
|
+
process.exitCode = 1;
|
|
345
|
+
}
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
// Origin: probe locally, then fan out to the rest of the fleet in parallel.
|
|
349
|
+
const reg = await loadDevices();
|
|
350
|
+
const planned = planFleetTargets(reg);
|
|
351
|
+
const results = [];
|
|
352
|
+
const localRows = await probeLocalFleetAuth({ cliVersion });
|
|
353
|
+
writeFleetAuthRows(self, localRows);
|
|
354
|
+
results.push({ host: self, rows: localRows });
|
|
355
|
+
const remoteTargets = remoteFleetTargets(planned, self).map((t) => ({
|
|
356
|
+
name: t.device.name,
|
|
357
|
+
platform: t.device.platform,
|
|
358
|
+
skip: t.skip,
|
|
359
|
+
}));
|
|
360
|
+
const probeable = remoteTargets.filter((t) => !t.skip).length;
|
|
361
|
+
const spinner = isInteractiveTerminal() && !opts.json
|
|
362
|
+
? ora(`Pinging ${probeable} device${probeable === 1 ? '' : 's'}…`).start()
|
|
363
|
+
: undefined;
|
|
364
|
+
let remote;
|
|
365
|
+
try {
|
|
366
|
+
remote = await fanOutDevices(remoteTargets, probeRemoteAuth);
|
|
367
|
+
}
|
|
368
|
+
finally {
|
|
369
|
+
spinner?.stop();
|
|
370
|
+
}
|
|
371
|
+
for (const r of remote) {
|
|
372
|
+
if (r.status === 'ok' && r.value) {
|
|
373
|
+
results.push({ host: r.name, rows: r.value });
|
|
374
|
+
writeFleetAuthRows(r.name, r.value);
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
results.push({
|
|
378
|
+
host: r.name,
|
|
379
|
+
rows: [],
|
|
380
|
+
error: r.error,
|
|
381
|
+
skipped: r.reason ? String(r.reason) : undefined,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (opts.json) {
|
|
386
|
+
console.log(JSON.stringify(results, null, 2));
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
for (const line of renderAuthMatrix(results, { verbose: opts.verbose }))
|
|
390
|
+
console.log(line);
|
|
391
|
+
}
|
|
392
|
+
const anyBad = results.some((r) => r.rows.some((row) => isDeadVerdict(row.health.verdict)));
|
|
393
|
+
if (opts.strict && anyBad)
|
|
394
|
+
process.exitCode = 1;
|
|
395
|
+
}
|
|
396
|
+
/** Color a per-host×agent cell: green all-live, red any revoked/expired, yellow degraded. */
|
|
397
|
+
function authCell(summary, width) {
|
|
398
|
+
if (summary.total === 0)
|
|
399
|
+
return chalk.dim('·'.padEnd(width));
|
|
400
|
+
const text = `${summary.live}/${summary.total}`;
|
|
401
|
+
const padded = text.padEnd(width);
|
|
402
|
+
if (summary.bad > 0)
|
|
403
|
+
return chalk.red(padded);
|
|
404
|
+
if (summary.warn > 0)
|
|
405
|
+
return chalk.yellow(padded);
|
|
406
|
+
return chalk.green(padded);
|
|
407
|
+
}
|
|
408
|
+
/** Render the fleet auth matrix (device rows × agent columns) plus an optional per-account breakdown. */
|
|
409
|
+
function renderAuthMatrix(results, opts) {
|
|
410
|
+
// Only show agent columns that appear somewhere in the results.
|
|
411
|
+
const present = new Set();
|
|
412
|
+
for (const r of results)
|
|
413
|
+
for (const row of r.rows)
|
|
414
|
+
present.add(row.agent);
|
|
415
|
+
const agents = ALL_AGENT_IDS.filter((a) => present.has(a));
|
|
416
|
+
const cellW = 6; // 6 disambiguates opencode/openclaw (both 'openc' at 5)
|
|
417
|
+
const nameW = Math.max(6, ...results.map((r) => r.host.length));
|
|
418
|
+
const lines = [chalk.bold('Fleet auth')];
|
|
419
|
+
const header = ` ${'Device'.padEnd(nameW)} ${agents.map((a) => a.slice(0, cellW).padEnd(cellW)).join(' ')}`;
|
|
420
|
+
lines.push(chalk.gray(header));
|
|
421
|
+
for (const r of results) {
|
|
422
|
+
const cells = agents.map((a) => {
|
|
423
|
+
const verdicts = r.rows.filter((row) => row.agent === a).map((row) => row.health.verdict);
|
|
424
|
+
return authCell(summarizeVerdicts(verdicts), cellW);
|
|
425
|
+
});
|
|
426
|
+
let note = '';
|
|
427
|
+
if (r.skipped)
|
|
428
|
+
note = chalk.dim(` ${r.skipped}`);
|
|
429
|
+
else if (r.error)
|
|
430
|
+
note = chalk.red(` ${r.error}`);
|
|
431
|
+
else {
|
|
432
|
+
const dead = r.rows.filter((row) => isDeadVerdict(row.health.verdict)).length;
|
|
433
|
+
if (dead > 0)
|
|
434
|
+
note = chalk.red(` ${dead} revoked — re-login`);
|
|
435
|
+
}
|
|
436
|
+
lines.push(` ${r.host.padEnd(nameW)} ${cells.join(' ')}${note}`);
|
|
437
|
+
}
|
|
438
|
+
lines.push('');
|
|
439
|
+
lines.push(chalk.gray(' cell = live/total accounts · green all live · red revoked (re-login) · yellow expired/unverified/limited'));
|
|
440
|
+
if (opts?.verbose) {
|
|
441
|
+
lines.push('');
|
|
442
|
+
lines.push(chalk.bold('Accounts'));
|
|
443
|
+
for (const r of results) {
|
|
444
|
+
if (r.rows.length === 0)
|
|
445
|
+
continue;
|
|
446
|
+
for (const row of r.rows.slice().sort((x, y) => (x.agent + x.version).localeCompare(y.agent + y.version))) {
|
|
447
|
+
const v = row.health.verdict;
|
|
448
|
+
const label = v === 'live' ? chalk.green(verdictLabel(v))
|
|
449
|
+
: (v === 'revoked' || v === 'expired') ? chalk.red(verdictLabel(v))
|
|
450
|
+
: chalk.yellow(verdictLabel(v));
|
|
451
|
+
const acctRaw = row.account ?? '—';
|
|
452
|
+
const acct = row.account ? chalk.cyan(acctRaw.padEnd(28)) : chalk.dim(acctRaw.padEnd(28));
|
|
453
|
+
const detail = row.health.detail ? chalk.dim(` ${row.health.detail}`) : '';
|
|
454
|
+
const age = chalk.dim(` · ${formatCheckedAge(row.health.checkedAt)}`);
|
|
455
|
+
lines.push(` ${r.host.padEnd(nameW)} ${`${row.agent}@${row.version}`.padEnd(22)} ${acct} ${label}${detail}${age}`);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return lines;
|
|
460
|
+
}
|
|
314
461
|
/** Register the `agents devices` command tree (also aliased as `fleet`). */
|
|
315
462
|
function registerDevicesCommands(program) {
|
|
316
463
|
const devicesCmd = program
|
|
@@ -447,6 +594,16 @@ Typical workflow:
|
|
|
447
594
|
.action(async (opts) => {
|
|
448
595
|
await runFleetStatus(opts);
|
|
449
596
|
});
|
|
597
|
+
devicesCmd
|
|
598
|
+
.command('ping')
|
|
599
|
+
.description('Live auth health: complete a real request for every agent account across the fleet (unlike the cached "signed in" flag). Writes the shared auth-health cache read by `agents view` and `fleet status`.')
|
|
600
|
+
.option('--json', 'output machine-readable JSON')
|
|
601
|
+
.option('--local', 'probe only this host (used internally for fan-out)')
|
|
602
|
+
.option('--verbose', 'show a per-account breakdown, not just the per-host rollup')
|
|
603
|
+
.option('--strict', 'exit non-zero when any account is revoked (expired is soft — it self-refreshes)')
|
|
604
|
+
.action(async (opts) => {
|
|
605
|
+
await runFleetPing(opts);
|
|
606
|
+
});
|
|
450
607
|
devicesCmd
|
|
451
608
|
.command('show <name>')
|
|
452
609
|
.description('Show the full profile for one device.')
|
|
@@ -668,6 +825,13 @@ secrets bundle via an askpass shim — the password never touches argv.
|
|
|
668
825
|
const addr = hostNameFor(device);
|
|
669
826
|
const pinned = addr ? isHostPinned(addr) : false;
|
|
670
827
|
const { args, env } = buildSshInvocation(device, cmd, shim, { pinned });
|
|
828
|
+
// Interactive login: make the local terminal's terminfo (e.g.
|
|
829
|
+
// xterm-ghostty) available on the remote so backspace/colors/clear work.
|
|
830
|
+
// Best-effort + cached per host — never blocks the login (see terminfo.ts).
|
|
831
|
+
if (cmd.length === 0 && shouldSyncTerminfo({ term: process.env.TERM, shell: device.shell, interactive: process.stdout.isTTY ?? false })) {
|
|
832
|
+
const { args: tinfoArgs, env: tinfoEnv } = buildSshInvocation(device, ['tic', '-x', '-'], shim, { pinned });
|
|
833
|
+
syncTerminfoToDevice({ device, host: terminfoHostKey(device, addr), term: process.env.TERM, sshArgs: tinfoArgs, sshEnv: tinfoEnv });
|
|
834
|
+
}
|
|
671
835
|
const res = spawnSync('ssh', args, {
|
|
672
836
|
stdio: 'inherit',
|
|
673
837
|
env: { ...process.env, ...env },
|
package/dist/commands/view.d.ts
CHANGED
|
@@ -7,23 +7,12 @@
|
|
|
7
7
|
* rules, hooks, and promptcuts synced to that version.
|
|
8
8
|
*/
|
|
9
9
|
import type { Command } from 'commander';
|
|
10
|
+
import { accountDisplayLabel } from '../lib/agents.js';
|
|
10
11
|
import type { AccountInfo } from '../lib/agents.js';
|
|
11
12
|
import type { AgentId } from '../lib/types.js';
|
|
12
13
|
import { type ProfileSummary } from '../lib/profiles.js';
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
* signed-in agent whose credential carries no email but does carry an opaque
|
|
16
|
-
* account id (Kimi's user_id), show `id:<user_id>` so distinct accounts read
|
|
17
|
-
* distinctly instead of a generic "signed in". Falls back to "signed in" when we
|
|
18
|
-
* have neither (Antigravity), and empty when signed out.
|
|
19
|
-
*
|
|
20
|
-
* When the account carries a Claude organizationType, the org badge is appended
|
|
21
|
-
* — "email (Turing Labs · Team)" — so two installs signed into the same email
|
|
22
|
-
* under different orgs (personal Max vs a Team seat) read distinctly. The
|
|
23
|
-
* suffix is plain text inside the label so the existing column-width pass
|
|
24
|
-
* measures and pads it for free.
|
|
25
|
-
*/
|
|
26
|
-
export declare function accountColumnLabel(info?: Pick<AccountInfo, 'email' | 'accountId' | 'signedIn' | 'organizationType' | 'organizationName'> | null): string;
|
|
14
|
+
/** Shared account identity formatter, re-exported for the view-specific tests. */
|
|
15
|
+
export declare const accountColumnLabel: typeof accountDisplayLabel;
|
|
27
16
|
type SyncState = 'synced' | 'new' | 'modified' | 'deleted';
|
|
28
17
|
/** Per-section filter flags. When any are true, only those sections render. */
|
|
29
18
|
export interface ViewSectionFilter {
|