@mysten-incubation/sui-agent-pass 0.1.19 → 0.1.22
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/README.md +20 -4
- package/dist/cli.js +137 -69
- package/dist/connect-ui.js +85 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ agent-pass connect # connect all detected agents, or choose specific ones
|
|
|
64
64
|
|
|
65
65
|
That is the only command. For each agent you pick it registers the MCP server and links the
|
|
66
66
|
`agent-pass` skill, the playbook built into the package, into the agent's skills folder (Claude
|
|
67
|
-
Code, Codex, Cursor and
|
|
67
|
+
Code, Codex, Cursor, Hermes and OpenClaw), so the agent has the tools and the guidance for them. A link
|
|
68
68
|
follows upgrades; rerun `connect` if you installed through `npx`. Then open the agent and tell
|
|
69
69
|
it what to do with your money. It
|
|
70
70
|
proposes a pass (`propose_authorization`) and opens the review page with the proposal in its URL.
|
|
@@ -94,8 +94,9 @@ writes or prints the entry in the right place:
|
|
|
94
94
|
| `claude-code` | `claude mcp add` in user scope |
|
|
95
95
|
| `claude-desktop` | Writes into `claude_desktop_config.json` |
|
|
96
96
|
| `cursor` | Writes into `~/.cursor/mcp.json` |
|
|
97
|
-
| `hermes` |
|
|
98
|
-
| `codex` |
|
|
97
|
+
| `hermes` | Uses `hermes mcp add`; prints configuration for `--session` |
|
|
98
|
+
| `codex` | Uses `codex mcp add`; prints configuration for `--session` |
|
|
99
|
+
| `openclaw` | Uses `openclaw mcp set` in the active OpenClaw profile |
|
|
99
100
|
| `json` | Prints a generic `mcpServers` entry |
|
|
100
101
|
|
|
101
102
|
The entry is `agent-pass mcp`, a stdio server the client starts when it needs it and stops with
|
|
@@ -105,6 +106,16 @@ also set a pass up. While it runs it also serves each pass's HTTP signer, which
|
|
|
105
106
|
`connect --session <directory>` instead points a client at one session's foreground signer
|
|
106
107
|
(`agent-pass serve`), for agents that cannot start a process themselves.
|
|
107
108
|
|
|
109
|
+
OpenClaw needs a release with native `openclaw mcp set` support. Stop its gateway before
|
|
110
|
+
connecting (`openclaw gateway stop` when running as a service), then run
|
|
111
|
+
`agent-pass connect --client openclaw`. Restart OpenClaw and start a new chat session afterward.
|
|
112
|
+
Registration uses OpenClaw's own CLI and its reported managed skills directory, so custom
|
|
113
|
+
state directories and profiles stay aligned. For a named profile, use
|
|
114
|
+
`OPENCLAW_PROFILE=<name> agent-pass connect --client openclaw`; `OPENCLAW_HOME` and
|
|
115
|
+
`OPENCLAW_STATE_DIR` are passed through to OpenClaw. OpenClaw must run on the machine where
|
|
116
|
+
Agent Pass is installed and have access to a local Node runtime for SDK scripts; remote
|
|
117
|
+
gateways need their own installation.
|
|
118
|
+
|
|
108
119
|
Acting is a Node script against the SDK. `session_info.sdk.install` is the install command
|
|
109
120
|
(`npm install <this checkout>` after `npm run build` while the package is unpublished), then:
|
|
110
121
|
|
|
@@ -207,7 +218,12 @@ Register the agents that may use your passes once with `connect`. It shows the d
|
|
|
207
218
|
and offers to connect them all, or choose specific ones. **Other / manual setup** offers
|
|
208
219
|
undetected clients, Cursor and a generic MCP configuration; Cursor is excluded from detection
|
|
209
220
|
and bulk setup. You can also select a client directly with `--client <name>`. After connecting,
|
|
210
|
-
restart each connected agent and start a new chat session.
|
|
221
|
+
restart each connected agent and start a new chat session. The terminal shows a compact status
|
|
222
|
+
for each agent: green for connected, yellow for manual or incomplete setup, and red for failure.
|
|
223
|
+
Colors are disabled for redirected output and `NO_COLOR`. Use `agent-pass connect --verbose`
|
|
224
|
+
to see native setup output and configuration/skill paths. Claude Desktop receives the playbook
|
|
225
|
+
through MCP; optionally add the packaged skill in its settings (the path is shown with `--verbose`).
|
|
226
|
+
Then start Claude anywhere:
|
|
211
227
|
|
|
212
228
|
```sh
|
|
213
229
|
claude
|
package/dist/cli.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Copyright (c) Mysten Labs, Inc.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import { spawn } from 'node:child_process';
|
|
4
|
+
import { execFile, spawn } from 'node:child_process';
|
|
5
5
|
import { realpathSync } from 'node:fs';
|
|
6
6
|
import { access, cp, lstat, mkdir, readFile, rm, symlink, writeFile } from 'node:fs/promises';
|
|
7
7
|
import { homedir } from 'node:os';
|
|
8
|
-
import { dirname, join, resolve, sep } from 'node:path';
|
|
8
|
+
import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
|
|
9
9
|
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { promisify, stripVTControlCharacters } from 'node:util';
|
|
10
11
|
import { checkbox, select } from '@inquirer/prompts';
|
|
11
12
|
import { Command } from 'commander';
|
|
12
13
|
import { clientFor, readStatus } from './chain.js';
|
|
14
|
+
import { ConnectUI } from './connect-ui.js';
|
|
13
15
|
import { cliInvocation, defaultRoot, forgetSession, openBrowser, servePlugin, servePluginHttp, } from './plugin.js';
|
|
14
16
|
import { startServer } from './server.js';
|
|
15
17
|
import { SessionStore } from './storage.js';
|
|
@@ -17,7 +19,7 @@ const quote = (s) => `'${s.replaceAll("'", "'\\''")}'`;
|
|
|
17
19
|
export async function serve(store, port = 0, open = true) {
|
|
18
20
|
const server = await startServer(store, port);
|
|
19
21
|
console.log(`\nOwner page: ${server.ownerUrl}\nSession address: ${store.state.sessionAddress}\nSession directory: ${store.directory}`);
|
|
20
|
-
console.log(`\nAfter authorization, register the signer with your agent (from the agent's working directory for Claude Code):\n${cliInvocation().map(quote).join(' ')} connect --session ${quote(store.directory)} --client claude-code\nOther clients: --client claude-desktop | cursor | hermes | codex | json\n\nKeep this process running. Ctrl-C stops signing; use the owner page to revoke on chain.`);
|
|
22
|
+
console.log(`\nAfter authorization, register the signer with your agent (from the agent's working directory for Claude Code):\n${cliInvocation().map(quote).join(' ')} connect --session ${quote(store.directory)} --client claude-code\nOther clients: --client claude-desktop | cursor | hermes | codex | openclaw | json\n\nKeep this process running. Ctrl-C stops signing; use the owner page to revoke on chain.`);
|
|
21
23
|
if (open)
|
|
22
24
|
openBrowser(server.ownerUrl);
|
|
23
25
|
const stop = () => {
|
|
@@ -76,55 +78,79 @@ program
|
|
|
76
78
|
const { url } = await servePluginHttp(options, Number(o.http));
|
|
77
79
|
console.error(`agent-pass MCP at ${url}; bearer token in ${join(options.root, 'mcp-http.json')}`);
|
|
78
80
|
});
|
|
79
|
-
const CLIENTS = [
|
|
81
|
+
const CLIENTS = [
|
|
82
|
+
'claude-code',
|
|
83
|
+
'claude-desktop',
|
|
84
|
+
'cursor',
|
|
85
|
+
'hermes',
|
|
86
|
+
'codex',
|
|
87
|
+
'openclaw',
|
|
88
|
+
'json',
|
|
89
|
+
];
|
|
80
90
|
const CLIENT_NAMES = {
|
|
81
91
|
'claude-code': 'Claude Code',
|
|
82
92
|
'claude-desktop': 'Claude Desktop',
|
|
83
93
|
cursor: 'Cursor',
|
|
84
94
|
hermes: 'Hermes',
|
|
85
95
|
codex: 'Codex',
|
|
96
|
+
openclaw: 'OpenClaw',
|
|
86
97
|
json: 'Generic MCP configuration',
|
|
87
98
|
};
|
|
99
|
+
/** OpenClaw's CLI selects named profiles through a root option, not the environment alone. */
|
|
100
|
+
function openclawArgs(args) {
|
|
101
|
+
const profile = process.env.OPENCLAW_PROFILE?.trim();
|
|
102
|
+
return profile ? ['--profile', profile, ...args] : args;
|
|
103
|
+
}
|
|
88
104
|
/** Merges one server entry into a JSON MCP config file, creating it if needed. */
|
|
89
|
-
async function mergeJsonConfig(path, entry) {
|
|
105
|
+
async function mergeJsonConfig(path, entry, detail) {
|
|
90
106
|
const current = await readFile(path, 'utf8')
|
|
91
|
-
.
|
|
92
|
-
.
|
|
107
|
+
.catch((error) => {
|
|
108
|
+
if (error.code === 'ENOENT')
|
|
109
|
+
return '{}';
|
|
110
|
+
throw error;
|
|
111
|
+
})
|
|
112
|
+
.then((text) => {
|
|
113
|
+
try {
|
|
114
|
+
const config = JSON.parse(text);
|
|
115
|
+
const object = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
116
|
+
if (!object(config) || (config.mcpServers !== undefined && !object(config.mcpServers)))
|
|
117
|
+
throw new Error('Invalid config structure');
|
|
118
|
+
return config;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
throw new Error(`Fix the invalid MCP configuration in ${path}, then try again. The file was not changed.`);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
93
124
|
current.mcpServers = { ...(current.mcpServers ?? {}), 'agent-pass': entry };
|
|
94
125
|
await mkdir(dirname(path), { recursive: true });
|
|
95
126
|
await writeFile(path, JSON.stringify(current, null, 2) + '\n', { mode: 0o600 });
|
|
96
|
-
|
|
127
|
+
detail(`Updated ${path}`);
|
|
97
128
|
}
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
129
|
+
/** Capture native setup chatter; preserve useful errors without echoing command arguments/tokens. */
|
|
130
|
+
async function cli(bin, args, detail) {
|
|
131
|
+
try {
|
|
132
|
+
const { stdout, stderr } = await promisify(execFile)(bin, args);
|
|
133
|
+
detail([stdout, stderr].filter(Boolean).join('\n'));
|
|
134
|
+
return stdout;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
const failure = error;
|
|
138
|
+
const output = stripVTControlCharacters(failure.stderr?.trim() || failure.stdout?.trim() || '');
|
|
139
|
+
detail(`${bin}: ${failure.signal ?? failure.code ?? 'process error'}\n${output}`);
|
|
140
|
+
if (failure.code === 'ENOENT')
|
|
141
|
+
throw new Error(`${bin} was not found. Install it, then run connect again.`);
|
|
142
|
+
const reason = output.split('\n').filter(Boolean).slice(0, 4).join('\n');
|
|
143
|
+
throw new Error(`${bin} could not finish setup.${reason ? `\n${reason}` : ` Exit: ${failure.signal ?? failure.code ?? 'unknown'}.`}`);
|
|
144
|
+
}
|
|
110
145
|
}
|
|
111
|
-
|
|
146
|
+
/** Registers agent-pass with Claude Code, replacing an earlier entry in the same scope. */
|
|
147
|
+
async function claudeMcpAdd(args, detail) {
|
|
112
148
|
const scope = args[args.indexOf('--scope') + 1];
|
|
113
|
-
await
|
|
114
|
-
|
|
115
|
-
stdio: 'ignore',
|
|
116
|
-
});
|
|
117
|
-
remove.once('error', () => done());
|
|
118
|
-
remove.once('exit', () => done());
|
|
119
|
-
});
|
|
120
|
-
const child = spawn('claude', ['mcp', 'add', ...args], { stdio: 'inherit' });
|
|
121
|
-
await new Promise((resolve, reject) => {
|
|
122
|
-
child.once('error', reject);
|
|
123
|
-
child.once('exit', (code) => code === 0 ? resolve() : reject(new Error(`claude mcp add exited ${code}`)));
|
|
124
|
-
});
|
|
149
|
+
await cli('claude', ['mcp', 'remove', '--scope', scope, 'agent-pass'], () => { }).catch(() => { });
|
|
150
|
+
await cli('claude', ['mcp', 'add', ...args], detail);
|
|
125
151
|
}
|
|
126
152
|
/** Writes the signer into one client's MCP configuration; the stdio form needs no running process. */
|
|
127
|
-
async function registerClient(client, http) {
|
|
153
|
+
async function registerClient(client, http, detail) {
|
|
128
154
|
const [command, ...args] = cliInvocation();
|
|
129
155
|
const stdio = { command, args: [...args, 'mcp'] };
|
|
130
156
|
const home = homedir();
|
|
@@ -140,7 +166,7 @@ async function registerClient(client, http) {
|
|
|
140
166
|
http.url,
|
|
141
167
|
'--header',
|
|
142
168
|
http.headers.Authorization,
|
|
143
|
-
]);
|
|
169
|
+
], detail);
|
|
144
170
|
else
|
|
145
171
|
await claudeMcpAdd([
|
|
146
172
|
'--transport',
|
|
@@ -151,7 +177,7 @@ async function registerClient(client, http) {
|
|
|
151
177
|
'--',
|
|
152
178
|
stdio.command,
|
|
153
179
|
...stdio.args,
|
|
154
|
-
]);
|
|
180
|
+
], detail);
|
|
155
181
|
return;
|
|
156
182
|
case 'claude-desktop': {
|
|
157
183
|
if (http)
|
|
@@ -161,44 +187,47 @@ async function registerClient(client, http) {
|
|
|
161
187
|
: process.platform === 'win32'
|
|
162
188
|
? join(process.env.APPDATA ?? join(home, 'AppData/Roaming'), 'Claude/claude_desktop_config.json')
|
|
163
189
|
: join(home, '.config/Claude/claude_desktop_config.json');
|
|
164
|
-
|
|
190
|
+
await mergeJsonConfig(path, stdio, detail);
|
|
191
|
+
return;
|
|
165
192
|
}
|
|
166
193
|
case 'cursor':
|
|
167
|
-
|
|
194
|
+
await mergeJsonConfig(join(home, '.cursor/mcp.json'), http ?? stdio, detail);
|
|
195
|
+
return;
|
|
168
196
|
case 'hermes': {
|
|
169
197
|
// `hermes mcp add` writes ~/.hermes/config.yaml itself; an HTTP signer's bearer header
|
|
170
198
|
// has no plain flag there, so that form is printed to paste.
|
|
171
199
|
if (http) {
|
|
172
|
-
|
|
173
|
-
return;
|
|
200
|
+
return `Add to ~/.hermes/config.yaml under mcp_servers:\n\n agent-pass:\n url: "${http.url}"\n headers:\n Authorization: "${http.headers.Authorization}"`;
|
|
174
201
|
}
|
|
175
|
-
await cli('hermes', ['mcp', 'remove', 'agent-pass'],
|
|
176
|
-
await cli('hermes', [
|
|
177
|
-
'mcp',
|
|
178
|
-
'add',
|
|
179
|
-
'agent-pass',
|
|
180
|
-
'--command',
|
|
181
|
-
stdio.command,
|
|
182
|
-
'--args',
|
|
183
|
-
...stdio.args,
|
|
184
|
-
]);
|
|
185
|
-
console.log('Registered agent-pass with Hermes (hermes mcp add).');
|
|
202
|
+
await cli('hermes', ['mcp', 'remove', 'agent-pass'], () => { }).catch(() => { });
|
|
203
|
+
await cli('hermes', ['mcp', 'add', 'agent-pass', '--command', stdio.command, '--args', ...stdio.args], detail);
|
|
186
204
|
return;
|
|
187
205
|
}
|
|
188
206
|
case 'codex': {
|
|
189
207
|
// `codex mcp add` writes ~/.codex/config.toml itself; an HTTP signer's bearer header has
|
|
190
208
|
// no flag there, so that form is printed to paste.
|
|
191
209
|
if (http) {
|
|
192
|
-
|
|
193
|
-
return;
|
|
210
|
+
return `Add to ~/.codex/config.toml:\n\n[mcp_servers.agent-pass]\nurl = "${http.url}"\nhttp_headers = { Authorization = "${http.headers.Authorization}" }`;
|
|
194
211
|
}
|
|
195
|
-
await cli('codex', ['mcp', 'remove', 'agent-pass'],
|
|
196
|
-
await cli('codex', ['mcp', 'add', 'agent-pass', '--', stdio.command, ...stdio.args]);
|
|
197
|
-
console.log('Registered agent-pass with Codex (codex mcp add).');
|
|
212
|
+
await cli('codex', ['mcp', 'remove', 'agent-pass'], () => { }).catch(() => { });
|
|
213
|
+
await cli('codex', ['mcp', 'add', 'agent-pass', '--', stdio.command, ...stdio.args], detail);
|
|
198
214
|
return;
|
|
199
215
|
}
|
|
216
|
+
case 'openclaw':
|
|
217
|
+
// Let OpenClaw validate and update its own registry, including profile/state overrides.
|
|
218
|
+
// `set` replaces only our entry and refuses to write while its gateway owns the state.
|
|
219
|
+
await cli('openclaw', openclawArgs([
|
|
220
|
+
'mcp',
|
|
221
|
+
'set',
|
|
222
|
+
'agent-pass',
|
|
223
|
+
JSON.stringify({
|
|
224
|
+
...(http ? { ...http, transport: 'streamable-http' } : stdio),
|
|
225
|
+
requestTimeoutMs: 180_000, // session_info can wait 120 seconds for wallet consent.
|
|
226
|
+
}),
|
|
227
|
+
]), detail);
|
|
228
|
+
return;
|
|
200
229
|
case 'json':
|
|
201
|
-
|
|
230
|
+
return `Add this to your agent's MCP settings:\n\n${JSON.stringify({ mcpServers: { 'agent-pass': http ?? stdio } }, null, 2)}`;
|
|
202
231
|
}
|
|
203
232
|
}
|
|
204
233
|
/** Where each agent loads personal skills from, under the home directory. */
|
|
@@ -212,18 +241,26 @@ const SKILL_DIRS = {
|
|
|
212
241
|
* Puts the agent-pass skill, the playbook built into this package, where the client loads
|
|
213
242
|
* skills. A link follows upgrades of the package; an npx cache is temporary, so it gets a copy.
|
|
214
243
|
*/
|
|
215
|
-
async function installSkill(client) {
|
|
244
|
+
async function installSkill(client, detail) {
|
|
216
245
|
const source = fileURLToPath(new URL('../skills/agent-pass', import.meta.url));
|
|
217
246
|
if (!(await access(join(source, 'SKILL.md')).then(() => true, () => false)))
|
|
218
247
|
throw new Error(`The skill is missing from ${source}; run npm run build`);
|
|
219
|
-
|
|
248
|
+
let dir = SKILL_DIRS[client];
|
|
249
|
+
if (client === 'openclaw') {
|
|
250
|
+
// Ask the client for its managed directory so profiles and custom state roots stay aligned.
|
|
251
|
+
const stdout = await cli('openclaw', openclawArgs(['skills', 'list', '--json']), () => { });
|
|
252
|
+
const report = JSON.parse(stdout);
|
|
253
|
+
if (typeof report.managedSkillsDir !== 'string' || !isAbsolute(report.managedSkillsDir))
|
|
254
|
+
throw new Error('OpenClaw did not report an absolute managed skills directory');
|
|
255
|
+
dir = report.managedSkillsDir;
|
|
256
|
+
}
|
|
220
257
|
if (!dir) {
|
|
221
|
-
|
|
258
|
+
detail(client === 'claude-desktop'
|
|
222
259
|
? `Claude Desktop takes skills from its own settings; add ${join(source, 'SKILL.md')} there to give it the playbook.`
|
|
223
260
|
: `If the agent loads SKILL.md skills, link ${source} into its skills folder to give it the playbook.`);
|
|
224
261
|
return;
|
|
225
262
|
}
|
|
226
|
-
const target = join(homedir(), dir, 'agent-pass');
|
|
263
|
+
const target = join(isAbsolute(dir) ? dir : join(homedir(), dir), 'agent-pass');
|
|
227
264
|
const existing = await lstat(target).catch(() => null);
|
|
228
265
|
if (existing && !existing.isSymbolicLink()) {
|
|
229
266
|
const ours = await readFile(join(target, 'SKILL.md'), 'utf8').then((t) => /^name: agent-pass$/m.test(t), () => false);
|
|
@@ -238,7 +275,7 @@ async function installSkill(client) {
|
|
|
238
275
|
await cp(source, target, { recursive: true });
|
|
239
276
|
else
|
|
240
277
|
await symlink(source, target, 'dir');
|
|
241
|
-
|
|
278
|
+
detail(`${temporary ? 'Copied' : 'Linked'} skill: ${target}`);
|
|
242
279
|
}
|
|
243
280
|
/** Connect detected agents together; Cursor and undetected clients stay in manual setup. */
|
|
244
281
|
async function chooseClients(http = false) {
|
|
@@ -254,17 +291,19 @@ async function chooseClients(http = false) {
|
|
|
254
291
|
: process.platform === 'win32'
|
|
255
292
|
? join(process.env.APPDATA ?? join(home, 'AppData/Roaming'), 'Claude')
|
|
256
293
|
: join(home, '.config/Claude');
|
|
257
|
-
const [claude, desktop, hermes, codex] = await Promise.all([
|
|
294
|
+
const [claude, desktop, hermes, codex, openclaw] = await Promise.all([
|
|
258
295
|
onPath('claude'),
|
|
259
296
|
found(desktopConfig),
|
|
260
297
|
onPath('hermes'),
|
|
261
298
|
onPath('codex'),
|
|
299
|
+
onPath('openclaw'),
|
|
262
300
|
]);
|
|
263
301
|
const detected = {
|
|
264
302
|
'claude-code': claude,
|
|
265
303
|
'claude-desktop': desktop,
|
|
266
304
|
hermes,
|
|
267
305
|
codex,
|
|
306
|
+
openclaw,
|
|
268
307
|
};
|
|
269
308
|
const choices = CLIENTS.filter((client) => !http || client !== 'claude-desktop').map((client) => ({ name: CLIENT_NAMES[client], value: client, found: !!detected[client] }));
|
|
270
309
|
const available = choices.filter((c) => c.found);
|
|
@@ -321,6 +360,7 @@ program
|
|
|
321
360
|
.description("Register the signer with an agent client. By default the stdio server over every pass on this machine, which the client starts when it needs it. --session registers one session's running HTTP signer (serve) instead.")
|
|
322
361
|
.option('--session <directory>')
|
|
323
362
|
.option('--client <client>', `one of ${CLIENTS.join(', ')}; asked when omitted`)
|
|
363
|
+
.option('--verbose', 'Show setup details and configuration paths')
|
|
324
364
|
.action(async (o) => {
|
|
325
365
|
if (o.client && !CLIENTS.includes(o.client))
|
|
326
366
|
throw new Error(`Unknown client '${o.client}'`);
|
|
@@ -332,16 +372,44 @@ program
|
|
|
332
372
|
const { mcpUrl } = JSON.parse(await readFile(join(store.directory, 'runtime.json'), 'utf8'));
|
|
333
373
|
http = { url: mcpUrl, headers: { Authorization: `Bearer ${await store.mcpToken()}` } };
|
|
334
374
|
}
|
|
375
|
+
const ui = new ConnectUI(!!o.verbose, http ? [http.headers.Authorization] : []);
|
|
376
|
+
ui.heading();
|
|
335
377
|
const clients = o.client ? [o.client] : await chooseClients(!!http);
|
|
378
|
+
if (!clients.length)
|
|
379
|
+
return;
|
|
380
|
+
if (!o.client)
|
|
381
|
+
console.log();
|
|
382
|
+
const width = Math.max(...clients.map((client) => CLIENT_NAMES[client].length));
|
|
383
|
+
const ready = [];
|
|
384
|
+
const manual = [];
|
|
385
|
+
let failed = false;
|
|
336
386
|
for (const client of clients) {
|
|
337
|
-
|
|
338
|
-
|
|
387
|
+
const name = CLIENT_NAMES[client];
|
|
388
|
+
ui.start(name);
|
|
389
|
+
let registered = false;
|
|
390
|
+
try {
|
|
391
|
+
const instructions = await registerClient(client, http, ui.detail);
|
|
392
|
+
registered = instructions === undefined;
|
|
393
|
+
if (instructions)
|
|
394
|
+
manual.push({ name, instructions });
|
|
395
|
+
await installSkill(client, ui.detail);
|
|
396
|
+
ui.finish(name, instructions ? 'Setup needed' : 'Connected', width);
|
|
397
|
+
ready.push(client === 'json' ? 'your agent' : name);
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
ui.finish(name, registered ? 'Setup incomplete' : 'Failed', width, error);
|
|
401
|
+
failed = true;
|
|
402
|
+
}
|
|
339
403
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
console.log(
|
|
404
|
+
for (const { name, instructions } of manual)
|
|
405
|
+
ui.manual(name, instructions);
|
|
406
|
+
if (failed) {
|
|
407
|
+
console.log('\n Resolve the issue above, then run connect again.\n Use --verbose to see setup details.');
|
|
408
|
+
process.exitCode = 1;
|
|
344
409
|
}
|
|
410
|
+
ui.next(ready, manual.length > 0);
|
|
411
|
+
if (!ready.length)
|
|
412
|
+
console.log();
|
|
345
413
|
});
|
|
346
414
|
// Run only when this file is the entry: directly, through tsx in development, or through the
|
|
347
415
|
// package's `agent-pass` bin, which is a symlink to it.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { stripVTControlCharacters, styleText } from 'node:util';
|
|
4
|
+
const STATUS = {
|
|
5
|
+
Connected: { symbol: '✓', color: 'green' },
|
|
6
|
+
'Setup needed': { symbol: '!', color: 'yellow' },
|
|
7
|
+
'Setup incomplete': { symbol: '!', color: 'yellow' },
|
|
8
|
+
Failed: { symbol: '✗', color: 'red' },
|
|
9
|
+
};
|
|
10
|
+
/** Presentation only: registration and skill installation stay with each client's setup. */
|
|
11
|
+
export class ConnectUI {
|
|
12
|
+
verbose;
|
|
13
|
+
secrets;
|
|
14
|
+
timer;
|
|
15
|
+
details = [];
|
|
16
|
+
terminal = !!process.stdout.isTTY && process.env.TERM !== 'dumb';
|
|
17
|
+
color = this.terminal &&
|
|
18
|
+
process.env.NO_COLOR === undefined &&
|
|
19
|
+
process.env.NODE_DISABLE_COLORS !== '1' &&
|
|
20
|
+
process.env.FORCE_COLOR !== '0';
|
|
21
|
+
constructor(verbose, secrets = []) {
|
|
22
|
+
this.verbose = verbose;
|
|
23
|
+
this.secrets = secrets;
|
|
24
|
+
}
|
|
25
|
+
style(format, text) {
|
|
26
|
+
return this.color ? styleText(format, text, { validateStream: false }) : text;
|
|
27
|
+
}
|
|
28
|
+
clean(text) {
|
|
29
|
+
for (const secret of this.secrets)
|
|
30
|
+
text = text.replaceAll(secret, '[redacted]');
|
|
31
|
+
return stripVTControlCharacters(text).trim();
|
|
32
|
+
}
|
|
33
|
+
heading() {
|
|
34
|
+
console.log(`\n ${this.style(['bold', 'cyan'], 'Agent Pass')}\n`);
|
|
35
|
+
}
|
|
36
|
+
start(name) {
|
|
37
|
+
this.details = [];
|
|
38
|
+
if (!this.terminal || process.stdout.columns < name.length + 24)
|
|
39
|
+
return;
|
|
40
|
+
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
41
|
+
let frame = 0;
|
|
42
|
+
const draw = () => process.stdout.write(`\r\x1b[2K ${this.style('cyan', frames[frame++ % frames.length])} ${name} ${this.style('dim', 'Connecting…')}`);
|
|
43
|
+
draw();
|
|
44
|
+
this.timer = setInterval(draw, 90);
|
|
45
|
+
this.timer.unref();
|
|
46
|
+
}
|
|
47
|
+
detail = (text) => {
|
|
48
|
+
if (this.verbose && text.trim())
|
|
49
|
+
this.details.push(this.clean(text));
|
|
50
|
+
};
|
|
51
|
+
finish(name, status, width, error) {
|
|
52
|
+
if (this.timer) {
|
|
53
|
+
clearInterval(this.timer);
|
|
54
|
+
this.timer = undefined;
|
|
55
|
+
process.stdout.write('\r\x1b[2K');
|
|
56
|
+
}
|
|
57
|
+
const { symbol, color } = STATUS[status];
|
|
58
|
+
console.log(` ${this.style(color, symbol)} ${name.padEnd(width + 3)}${this.style(color, status)}`);
|
|
59
|
+
if (error) {
|
|
60
|
+
const message = this.clean(error instanceof Error ? error.message : String(error));
|
|
61
|
+
console.log(message
|
|
62
|
+
.split('\n')
|
|
63
|
+
.map((line) => ` ${line}`)
|
|
64
|
+
.join('\n'));
|
|
65
|
+
}
|
|
66
|
+
for (const detail of this.details)
|
|
67
|
+
console.log(this.style('dim', detail
|
|
68
|
+
.split('\n')
|
|
69
|
+
.map((line) => ` ${line}`)
|
|
70
|
+
.join('\n')));
|
|
71
|
+
}
|
|
72
|
+
manual(name, instructions) {
|
|
73
|
+
console.log(`\n ${this.style('bold', `${name} · Manual setup`)}\n\n${instructions}`);
|
|
74
|
+
}
|
|
75
|
+
next(names, manual) {
|
|
76
|
+
if (!names.length)
|
|
77
|
+
return;
|
|
78
|
+
const who = names.length === 1 ? names[0] : 'the connected agents';
|
|
79
|
+
console.log(`\n ${this.style('bold', 'Next steps')}`);
|
|
80
|
+
if (manual)
|
|
81
|
+
console.log(' Complete the manual setup above first.');
|
|
82
|
+
console.log(` 1. Restart ${who}.`);
|
|
83
|
+
console.log(` 2. Start a new chat session${names.length > 1 ? ' in each' : ''}.\n`);
|
|
84
|
+
}
|
|
85
|
+
}
|