maritime-cli 1.9.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/bin/maritime.js +40 -0
- package/install.js +118 -0
- package/package.json +22 -37
- package/AGENTS.md +0 -361
- package/SKILL.md +0 -181
- package/dist/api.d.ts +0 -30
- package/dist/api.js +0 -246
- package/dist/bundled.d.ts +0 -11
- package/dist/bundled.js +0 -25
- package/dist/commands/chat.d.ts +0 -2
- package/dist/commands/chat.js +0 -120
- package/dist/commands/create.d.ts +0 -2
- package/dist/commands/create.js +0 -310
- package/dist/commands/delete.d.ts +0 -2
- package/dist/commands/delete.js +0 -43
- package/dist/commands/deploy.d.ts +0 -2
- package/dist/commands/deploy.js +0 -180
- package/dist/commands/env.d.ts +0 -2
- package/dist/commands/env.js +0 -368
- package/dist/commands/exec.d.ts +0 -2
- package/dist/commands/exec.js +0 -31
- package/dist/commands/guide.d.ts +0 -2
- package/dist/commands/guide.js +0 -75
- package/dist/commands/history.d.ts +0 -2
- package/dist/commands/history.js +0 -56
- package/dist/commands/info.d.ts +0 -2
- package/dist/commands/info.js +0 -78
- package/dist/commands/init.d.ts +0 -2
- package/dist/commands/init.js +0 -143
- package/dist/commands/keys.d.ts +0 -2
- package/dist/commands/keys.js +0 -90
- package/dist/commands/link.d.ts +0 -4
- package/dist/commands/link.js +0 -65
- package/dist/commands/list.d.ts +0 -2
- package/dist/commands/list.js +0 -55
- package/dist/commands/login.d.ts +0 -2
- package/dist/commands/login.js +0 -368
- package/dist/commands/logout.d.ts +0 -2
- package/dist/commands/logout.js +0 -12
- package/dist/commands/logs.d.ts +0 -2
- package/dist/commands/logs.js +0 -89
- package/dist/commands/message.d.ts +0 -8
- package/dist/commands/message.js +0 -75
- package/dist/commands/open.d.ts +0 -2
- package/dist/commands/open.js +0 -25
- package/dist/commands/restart.d.ts +0 -2
- package/dist/commands/restart.js +0 -26
- package/dist/commands/signup.d.ts +0 -2
- package/dist/commands/signup.js +0 -72
- package/dist/commands/sleep.d.ts +0 -2
- package/dist/commands/sleep.js +0 -22
- package/dist/commands/start.d.ts +0 -2
- package/dist/commands/start.js +0 -27
- package/dist/commands/status.d.ts +0 -2
- package/dist/commands/status.js +0 -69
- package/dist/commands/stop.d.ts +0 -2
- package/dist/commands/stop.js +0 -26
- package/dist/commands/templates.d.ts +0 -2
- package/dist/commands/templates.js +0 -40
- package/dist/commands/triggers.d.ts +0 -2
- package/dist/commands/triggers.js +0 -89
- package/dist/commands/whoami.d.ts +0 -2
- package/dist/commands/whoami.js +0 -76
- package/dist/config.d.ts +0 -2
- package/dist/config.js +0 -14
- package/dist/context.d.ts +0 -39
- package/dist/context.js +0 -110
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -186
- package/dist/interactive.d.ts +0 -1
- package/dist/interactive.js +0 -66
- package/dist/output.d.ts +0 -80
- package/dist/output.js +0 -176
- package/dist/prompt.d.ts +0 -2
- package/dist/prompt.js +0 -62
- package/dist/resolve.d.ts +0 -16
- package/dist/resolve.js +0 -59
- package/dist/version-check.d.ts +0 -20
- package/dist/version-check.js +0 -81
- package/dist/websocket.d.ts +0 -22
- package/dist/websocket.js +0 -89
package/dist/commands/login.js
DELETED
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
import http from 'node:http';
|
|
2
|
-
import crypto from 'node:crypto';
|
|
3
|
-
import { readFileSync } from 'node:fs';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
6
|
-
import { Command } from 'commander';
|
|
7
|
-
import chalk from 'chalk';
|
|
8
|
-
import open from 'open';
|
|
9
|
-
import { config } from '../config.js';
|
|
10
|
-
import { CliHttpError, getApiUrl, postJson } from '../api.js';
|
|
11
|
-
import { EXIT, fail, handleError, isJsonMode, makeSpinner, outputResult } from '../output.js';
|
|
12
|
-
import { promptForPassword, promptForValue } from '../prompt.js';
|
|
13
|
-
const APP_URL = process.env.MARITIME_APP_URL || 'https://maritime.sh';
|
|
14
|
-
const TIMEOUT_MS = 120_000;
|
|
15
|
-
const MS_PER_SECOND = 1000;
|
|
16
|
-
const SECONDS_PER_MINUTE = 60;
|
|
17
|
-
/** Added to the poll interval every time the server answers `slow_down`. */
|
|
18
|
-
const DEVICE_SLOW_DOWN_EXTRA_SECONDS = 5;
|
|
19
|
-
const DEVICE_CLIENT_NAME = 'maritime-cli';
|
|
20
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
21
|
-
/** Thrown by the browser flow when the browser itself could not be opened. */
|
|
22
|
-
class BrowserOpenError extends Error {
|
|
23
|
-
loginUrl;
|
|
24
|
-
constructor(loginUrl) {
|
|
25
|
-
super('Could not open a browser');
|
|
26
|
-
this.loginUrl = loginUrl;
|
|
27
|
-
this.name = 'BrowserOpenError';
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function decodeJwt(token) {
|
|
31
|
-
const parts = token.split('.');
|
|
32
|
-
if (parts.length !== 3)
|
|
33
|
-
return null;
|
|
34
|
-
try {
|
|
35
|
-
return JSON.parse(Buffer.from(parts[1], 'base64url').toString());
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function persistToken(token, payload) {
|
|
42
|
-
config.set('token', token);
|
|
43
|
-
config.set('user', payload.email ?? '');
|
|
44
|
-
config.set('userId', payload.sub ?? payload.id ?? '');
|
|
45
|
-
config.set('apiUrl', getApiUrl());
|
|
46
|
-
}
|
|
47
|
-
/** Returns the installed CLI version from the bundled package.json, or "unknown". */
|
|
48
|
-
function readCliVersion() {
|
|
49
|
-
try {
|
|
50
|
-
// dist/commands/login.js: the package root is two levels up.
|
|
51
|
-
const pkg = JSON.parse(readFileSync(join(__dirname, '..', '..', 'package.json'), 'utf-8'));
|
|
52
|
-
return pkg.version ?? 'unknown';
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
return 'unknown';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function sleep(ms) {
|
|
59
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
60
|
-
}
|
|
61
|
-
function browserLogin() {
|
|
62
|
-
return new Promise((resolve, reject) => {
|
|
63
|
-
const state = crypto.randomBytes(16).toString('hex');
|
|
64
|
-
const server = http.createServer((req, res) => {
|
|
65
|
-
const url = new URL(req.url || '/', `http://localhost`);
|
|
66
|
-
if (url.pathname !== '/callback') {
|
|
67
|
-
res.writeHead(404);
|
|
68
|
-
res.end();
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const token = url.searchParams.get('token');
|
|
72
|
-
const returnedState = url.searchParams.get('state');
|
|
73
|
-
if (returnedState !== state || !token) {
|
|
74
|
-
res.writeHead(400, { 'Content-Type': 'text/html' });
|
|
75
|
-
res.end('<html><body><h2>Authentication failed.</h2><p>State mismatch or missing token. Please try again.</p></body></html>');
|
|
76
|
-
cleanup(new Error('State mismatch or missing token'));
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
80
|
-
res.end('<html><body><h2>Authenticated!</h2><p>You can close this tab and return to the terminal.</p></body></html>');
|
|
81
|
-
cleanup(null, token);
|
|
82
|
-
});
|
|
83
|
-
const timer = setTimeout(() => {
|
|
84
|
-
cleanup(new Error('Login timed out. Try `maritime login --device` or `maritime login --token <token>` (get one at ' + APP_URL + '/cli/auth) instead.'));
|
|
85
|
-
}, TIMEOUT_MS);
|
|
86
|
-
function cleanup(err, token) {
|
|
87
|
-
clearTimeout(timer);
|
|
88
|
-
server.close();
|
|
89
|
-
if (err)
|
|
90
|
-
reject(err);
|
|
91
|
-
else
|
|
92
|
-
resolve(token);
|
|
93
|
-
}
|
|
94
|
-
server.listen(0, '127.0.0.1', () => {
|
|
95
|
-
const addr = server.address();
|
|
96
|
-
if (!addr || typeof addr === 'string') {
|
|
97
|
-
cleanup(new Error('Failed to start local server'));
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const port = addr.port;
|
|
101
|
-
const loginUrl = `${APP_URL}/cli/auth?port=${port}&state=${state}`;
|
|
102
|
-
// No browser here (headless box, container, agent sandbox): the caller
|
|
103
|
-
// falls back to the device flow instead of waiting for a callback
|
|
104
|
-
// that can never arrive.
|
|
105
|
-
open(loginUrl).catch(() => cleanup(new BrowserOpenError(loginUrl)));
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Prints the user code and where to enter it.
|
|
111
|
-
*
|
|
112
|
-
* Human mode writes the block to stdout. JSON mode writes one JSON line to
|
|
113
|
-
* stderr so a program driving the CLI can show the code to its user while
|
|
114
|
-
* stdout stays reserved for the single final result.
|
|
115
|
-
*/
|
|
116
|
-
function announceDeviceCode(code) {
|
|
117
|
-
if (isJsonMode()) {
|
|
118
|
-
process.stderr.write(JSON.stringify({
|
|
119
|
-
ok: true,
|
|
120
|
-
action: 'device_code',
|
|
121
|
-
user_code: code.user_code,
|
|
122
|
-
verification_uri_complete: code.verification_uri_complete,
|
|
123
|
-
expires_in: code.expires_in,
|
|
124
|
-
}) + '\n');
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const minutes = Math.round(code.expires_in / SECONDS_PER_MINUTE);
|
|
128
|
-
console.log(`Open ${chalk.bold(code.verification_uri)} and enter the code:\n`);
|
|
129
|
-
console.log(` ${chalk.bold(code.user_code)}\n`);
|
|
130
|
-
console.log(chalk.dim(`Waiting for approval (expires in ${minutes} minutes)...`));
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Signs in with a device code: asks the server for a code pair, shows the
|
|
134
|
-
* user code, then polls until the human approves it on the dashboard.
|
|
135
|
-
*
|
|
136
|
-
* Never returns on denial or expiry: those end the command through `fail()`
|
|
137
|
-
* with exit code 2.
|
|
138
|
-
*
|
|
139
|
-
* @returns The token and user the server issued after approval.
|
|
140
|
-
*/
|
|
141
|
-
async function deviceLogin() {
|
|
142
|
-
const code = await postJson('/api/auth/device/code', {
|
|
143
|
-
client: DEVICE_CLIENT_NAME,
|
|
144
|
-
version: readCliVersion(),
|
|
145
|
-
});
|
|
146
|
-
announceDeviceCode(code);
|
|
147
|
-
const deadline = Date.now() + code.expires_in * MS_PER_SECOND;
|
|
148
|
-
let intervalSeconds = code.interval;
|
|
149
|
-
while (Date.now() < deadline) {
|
|
150
|
-
await sleep(intervalSeconds * MS_PER_SECOND);
|
|
151
|
-
try {
|
|
152
|
-
return await postJson('/api/auth/device/token', {
|
|
153
|
-
device_code: code.device_code,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
if (!(error instanceof CliHttpError))
|
|
158
|
-
throw error;
|
|
159
|
-
if (error.code === 'authorization_pending')
|
|
160
|
-
continue;
|
|
161
|
-
if (error.code === 'slow_down') {
|
|
162
|
-
intervalSeconds += DEVICE_SLOW_DOWN_EXTRA_SECONDS;
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
if (error.code === 'access_denied') {
|
|
166
|
-
fail('Sign-in was denied in the browser.', {
|
|
167
|
-
code: 'access_denied',
|
|
168
|
-
status: error.status,
|
|
169
|
-
exitCode: EXIT.AUTH,
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
if (error.code === 'expired_token') {
|
|
173
|
-
fail('The code expired before it was approved. Run `maritime login --device` again.', {
|
|
174
|
-
code: 'expired_token',
|
|
175
|
-
status: error.status,
|
|
176
|
-
exitCode: EXIT.AUTH,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
throw error;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
fail('The code expired before it was approved. Run `maritime login --device` again.', {
|
|
183
|
-
code: 'expired_token',
|
|
184
|
-
exitCode: EXIT.AUTH,
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
/** Runs the device flow and stores the result. */
|
|
188
|
-
async function runDeviceLogin() {
|
|
189
|
-
try {
|
|
190
|
-
const auth = await deviceLogin();
|
|
191
|
-
config.set('token', auth.token);
|
|
192
|
-
config.set('user', auth.user.email);
|
|
193
|
-
config.set('userId', auth.user.id);
|
|
194
|
-
config.set('apiUrl', getApiUrl());
|
|
195
|
-
outputResult({ ok: true, action: 'login', method: 'device', user: auth.user.email }, chalk.green('Authenticated as ') + chalk.bold(auth.user.email));
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
// Every device-flow failure is an auth failure to the caller (exit 2),
|
|
199
|
-
// also a 404 from a backend that predates the device endpoints.
|
|
200
|
-
if (error instanceof CliHttpError) {
|
|
201
|
-
fail(error.detail, {
|
|
202
|
-
code: error.code ?? 'device_login_failed',
|
|
203
|
-
status: error.status,
|
|
204
|
-
exitCode: EXIT.AUTH,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
handleError(error);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* True when a browser callback to 127.0.0.1 cannot work: no terminal, an
|
|
212
|
-
* SSH session, CI, or a program driving the CLI with --json.
|
|
213
|
-
*/
|
|
214
|
-
function browserUnavailable() {
|
|
215
|
-
return (!process.stdin.isTTY ||
|
|
216
|
-
!process.stdout.isTTY ||
|
|
217
|
-
Boolean(process.env.SSH_CONNECTION) ||
|
|
218
|
-
Boolean(process.env.CI) ||
|
|
219
|
-
isJsonMode());
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Asks the server to send the email verification link again.
|
|
223
|
-
*
|
|
224
|
-
* The server always answers ok, also for an address with no account or an
|
|
225
|
-
* address that is already verified, so "Sent" does not confirm an account.
|
|
226
|
-
*
|
|
227
|
-
* @param emailFlag The value of `-e`. When absent, the email of the stored login is used.
|
|
228
|
-
*/
|
|
229
|
-
async function resendVerification(emailFlag) {
|
|
230
|
-
const email = (emailFlag ?? config.get('user') ?? '').trim();
|
|
231
|
-
if (!email) {
|
|
232
|
-
fail('No email to send to. Run `maritime login --resend -e <email>`.', {
|
|
233
|
-
code: 'email_required',
|
|
234
|
-
exitCode: EXIT.USAGE,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
try {
|
|
238
|
-
await postJson('/api/auth/resend-verification', { email });
|
|
239
|
-
}
|
|
240
|
-
catch (error) {
|
|
241
|
-
handleError(error);
|
|
242
|
-
}
|
|
243
|
-
outputResult({ ok: true, action: 'resend_verification', email }, `Sent. Check ${email}.`);
|
|
244
|
-
}
|
|
245
|
-
export const loginCommand = new Command('login')
|
|
246
|
-
.description('Authenticate with Maritime')
|
|
247
|
-
.option('-e, --email <email>', 'Email address (for non-interactive login)')
|
|
248
|
-
.option('-p, --password <password>', 'Password (for non-interactive login)')
|
|
249
|
-
.option('-t, --token <token>', `Paste a token from ${APP_URL}/cli/auth (works for SSO / headless / CI)`)
|
|
250
|
-
.option('--device', `Sign in from a machine without a browser: prints a code to enter at ${APP_URL}/cli/device`)
|
|
251
|
-
.option('--resend', 'Send the email verification link again (uses -e, else the logged-in email)')
|
|
252
|
-
.action(async (opts) => {
|
|
253
|
-
if (opts.resend) {
|
|
254
|
-
await resendVerification(opts.email);
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
// 1. Token paste: the universal path. Works for any account, including
|
|
258
|
-
// OAuth-only (Google/GitHub) users who have no password to type.
|
|
259
|
-
// Generate one at <app>/cli/auth.
|
|
260
|
-
if (opts.token) {
|
|
261
|
-
const token = String(opts.token).trim();
|
|
262
|
-
const payload = decodeJwt(token);
|
|
263
|
-
if (!payload) {
|
|
264
|
-
console.log(chalk.red('Error:') + ' that does not look like a valid token.');
|
|
265
|
-
console.log(chalk.dim(` Copy a fresh one from ${APP_URL}/cli/auth`));
|
|
266
|
-
process.exitCode = 1;
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
if (payload.exp && Date.now() >= payload.exp * 1000) {
|
|
270
|
-
console.log(chalk.red('Error:') + ' that token has expired.');
|
|
271
|
-
console.log(chalk.dim(` Generate a new one at ${APP_URL}/cli/auth`));
|
|
272
|
-
process.exitCode = 1;
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
persistToken(token, payload);
|
|
276
|
-
console.log(chalk.green('Authenticated as ') + chalk.bold(payload.email || 'your account'));
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
// 2. Email/password (non-interactive). OAuth-only accounts have no
|
|
280
|
-
// password, so they get pointed at the browser / token flow below.
|
|
281
|
-
if (opts.email || opts.password) {
|
|
282
|
-
if (opts.password) {
|
|
283
|
-
console.log(chalk.yellow('Warning:') +
|
|
284
|
-
' Passing --password on the command line may expose it in shell history.' +
|
|
285
|
-
'\n Prefer `maritime login` (browser) or `maritime login --token` for CI.');
|
|
286
|
-
}
|
|
287
|
-
const email = await promptForValue('Email', opts.email);
|
|
288
|
-
const password = await promptForPassword(opts.password);
|
|
289
|
-
if (!email || !password) {
|
|
290
|
-
console.log(chalk.red('Error:') + ' email and password are required');
|
|
291
|
-
process.exitCode = 1;
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
const spinner = await makeSpinner('Authenticating...');
|
|
295
|
-
try {
|
|
296
|
-
const auth = await postJson('/api/auth/cli-login', {
|
|
297
|
-
email,
|
|
298
|
-
password,
|
|
299
|
-
});
|
|
300
|
-
config.set('token', auth.token);
|
|
301
|
-
config.set('user', auth.user.email);
|
|
302
|
-
config.set('userId', auth.user.id);
|
|
303
|
-
config.set('apiUrl', getApiUrl());
|
|
304
|
-
spinner.succeed(chalk.green('Authenticated as ') + chalk.bold(auth.user.email));
|
|
305
|
-
}
|
|
306
|
-
catch (error) {
|
|
307
|
-
spinner.fail('Authentication failed');
|
|
308
|
-
if (error instanceof CliHttpError) {
|
|
309
|
-
// OAuth-only accounts (no password): guide the user to a path that
|
|
310
|
-
// actually works for them instead of the raw "oauth_only:google".
|
|
311
|
-
if (error.detail.startsWith('oauth_only:')) {
|
|
312
|
-
const providers = error.detail
|
|
313
|
-
.slice('oauth_only:'.length)
|
|
314
|
-
.split(',')
|
|
315
|
-
.join(', ');
|
|
316
|
-
console.log(chalk.red('Error:') +
|
|
317
|
-
` this account signs in with ${chalk.bold(providers)}. There's no password to use here.`);
|
|
318
|
-
console.log('\nAuthenticate one of these ways instead:');
|
|
319
|
-
console.log(' ' + chalk.bold('maritime login') + chalk.dim(' open the browser and approve'));
|
|
320
|
-
console.log(' ' + chalk.bold('maritime login --device') + chalk.dim(' enter a code at ' + APP_URL + '/cli/device'));
|
|
321
|
-
console.log(' ' + chalk.bold('maritime login --token <token>') + chalk.dim(` paste a token from ${APP_URL}/cli/auth`));
|
|
322
|
-
process.exitCode = 2;
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
console.log(chalk.red('Error:') + ` ${error.detail}`);
|
|
326
|
-
process.exitCode = error.status === 401 ? 2 : 1;
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
throw error;
|
|
330
|
-
}
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
// 3. Device code: no browser on this machine (headless box, container,
|
|
334
|
-
// an AI coding agent's sandbox). Also the automatic fallback below.
|
|
335
|
-
if (opts.device || browserUnavailable()) {
|
|
336
|
-
await runDeviceLogin();
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
// 4. Default: browser-based login.
|
|
340
|
-
const spinner = await makeSpinner('Opening browser for authentication...');
|
|
341
|
-
try {
|
|
342
|
-
const token = await browserLogin();
|
|
343
|
-
const payload = decodeJwt(token);
|
|
344
|
-
if (!payload) {
|
|
345
|
-
throw new Error('Received a malformed token from the browser.');
|
|
346
|
-
}
|
|
347
|
-
persistToken(token, payload);
|
|
348
|
-
spinner.succeed(chalk.green('Authenticated as ') + chalk.bold(payload.email || 'your account'));
|
|
349
|
-
}
|
|
350
|
-
catch (error) {
|
|
351
|
-
if (error instanceof BrowserOpenError) {
|
|
352
|
-
spinner.stop();
|
|
353
|
-
console.log(chalk.yellow('Could not open a browser.') + ' Switching to the code flow.\n');
|
|
354
|
-
await runDeviceLogin();
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
spinner.fail('Authentication failed');
|
|
358
|
-
if (error instanceof Error) {
|
|
359
|
-
console.log(chalk.red('Error:') + ` ${error.message}`);
|
|
360
|
-
}
|
|
361
|
-
console.log(chalk.dim('\nOn a headless / SSH box? Run ') +
|
|
362
|
-
chalk.bold('maritime login --device') +
|
|
363
|
-
chalk.dim(' or ') +
|
|
364
|
-
chalk.bold('maritime login --token <token>') +
|
|
365
|
-
chalk.dim(` with a token from ${APP_URL}/cli/auth`));
|
|
366
|
-
process.exitCode = 1;
|
|
367
|
-
}
|
|
368
|
-
});
|
package/dist/commands/logout.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { config } from '../config.js';
|
|
4
|
-
export const logoutCommand = new Command('logout')
|
|
5
|
-
.description('Log out of Maritime')
|
|
6
|
-
.action(() => {
|
|
7
|
-
config.delete('token');
|
|
8
|
-
config.delete('user');
|
|
9
|
-
config.delete('userId');
|
|
10
|
-
config.delete('apiUrl');
|
|
11
|
-
console.log(chalk.green('Logged out.'));
|
|
12
|
-
});
|
package/dist/commands/logs.d.ts
DELETED
package/dist/commands/logs.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { authGet } from '../api.js';
|
|
4
|
-
import { resolveAgent } from '../resolve.js';
|
|
5
|
-
import { isJsonMode, outputJson, handleError, fail, EXIT } from '../output.js';
|
|
6
|
-
import { connectWs } from '../websocket.js';
|
|
7
|
-
const VALID_LEVELS = ['info', 'warn', 'error', 'debug'];
|
|
8
|
-
const levelColors = {
|
|
9
|
-
info: chalk.blue,
|
|
10
|
-
warn: chalk.yellow,
|
|
11
|
-
error: chalk.red,
|
|
12
|
-
debug: chalk.gray,
|
|
13
|
-
};
|
|
14
|
-
function formatEntry(entry) {
|
|
15
|
-
const ts = entry.timestamp
|
|
16
|
-
? chalk.dim(new Date(entry.timestamp).toLocaleTimeString())
|
|
17
|
-
: chalk.dim('--:--:--');
|
|
18
|
-
const level = entry.level || 'info';
|
|
19
|
-
const colorFn = levelColors[level] || chalk.white;
|
|
20
|
-
const levelStr = colorFn(level.toUpperCase().padEnd(5));
|
|
21
|
-
return `${ts} ${levelStr} ${entry.message}`;
|
|
22
|
-
}
|
|
23
|
-
export const logsCommand = new Command('logs')
|
|
24
|
-
.description('View logs from an agent')
|
|
25
|
-
.argument('[agent]', 'Agent name or ID (defaults to the linked agent)')
|
|
26
|
-
.option('-n, --lines <num>', 'Number of lines', '50')
|
|
27
|
-
.option('--level <level>', 'Filter by level (info, warn, error, debug)')
|
|
28
|
-
.option('-f, --follow', 'Follow log output')
|
|
29
|
-
.action(async (agentArg, opts) => {
|
|
30
|
-
// Validate --level
|
|
31
|
-
if (opts.level && !VALID_LEVELS.includes(opts.level)) {
|
|
32
|
-
fail('--level must be one of info, warn, error, debug', {
|
|
33
|
-
code: 'usage',
|
|
34
|
-
exitCode: EXIT.USAGE,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
// Validate --lines
|
|
38
|
-
const lines = parseInt(opts.lines, 10);
|
|
39
|
-
if (isNaN(lines) || lines <= 0) {
|
|
40
|
-
fail('--lines must be a positive integer', {
|
|
41
|
-
code: 'usage',
|
|
42
|
-
exitCode: EXIT.USAGE,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
const agent = await resolveAgent(agentArg);
|
|
46
|
-
let path = `/api/agents/${agent.id}/logs?limit=${lines}`;
|
|
47
|
-
if (opts.level)
|
|
48
|
-
path += `&level=${opts.level}`;
|
|
49
|
-
try {
|
|
50
|
-
const entries = await authGet(path);
|
|
51
|
-
if (isJsonMode() && !opts.follow) {
|
|
52
|
-
outputJson(entries);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (entries.length === 0 && !opts.follow) {
|
|
56
|
-
console.log(chalk.dim('No logs found.'));
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
for (const entry of entries) {
|
|
60
|
-
console.log(formatEntry(entry));
|
|
61
|
-
}
|
|
62
|
-
// --follow: stream logs via WebSocket. Await the stream's end so the
|
|
63
|
-
// action only resolves when following is done: the command finishes
|
|
64
|
-
// through the normal exit path (loop drains, no hard process.exit
|
|
65
|
-
// from inside a socket callback).
|
|
66
|
-
if (opts.follow) {
|
|
67
|
-
await new Promise((resolve) => {
|
|
68
|
-
connectWs(`/api/agents/${agent.id}/logs`, {
|
|
69
|
-
onMessage(data) {
|
|
70
|
-
try {
|
|
71
|
-
const entry = JSON.parse(data);
|
|
72
|
-
console.log(formatEntry(entry));
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
// Plain text message
|
|
76
|
-
console.log(data);
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
onClose() {
|
|
80
|
-
resolve();
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
handleError(error);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
/**
|
|
3
|
-
* The project front door: send a message AS one of your end-users. Unlike
|
|
4
|
-
* `chat` (which talks to one specific agent), this routes by --user: the same
|
|
5
|
-
* external user id always reaches the same dedicated agent, and an unknown id
|
|
6
|
-
* gets an agent assigned/spawned per the project's newChatPolicy.
|
|
7
|
-
*/
|
|
8
|
-
export declare const messageCommand: Command;
|
package/dist/commands/message.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { authGet, authPost } from '../api.js';
|
|
3
|
-
import { resolveAgent } from '../resolve.js';
|
|
4
|
-
import { outputResult, fail, handleError, makeSpinner } from '../output.js';
|
|
5
|
-
/**
|
|
6
|
-
* The project front door: send a message AS one of your end-users. Unlike
|
|
7
|
-
* `chat` (which talks to one specific agent), this routes by --user: the same
|
|
8
|
-
* external user id always reaches the same dedicated agent, and an unknown id
|
|
9
|
-
* gets an agent assigned/spawned per the project's newChatPolicy.
|
|
10
|
-
*/
|
|
11
|
-
export const messageCommand = new Command('message')
|
|
12
|
-
.description("Send an end-user's message through an agent's project front door")
|
|
13
|
-
.argument('[agent]', 'Any agent in the project (names the project; optional when linked)')
|
|
14
|
-
.argument('[message...]', 'Message to send')
|
|
15
|
-
.requiredOption('-u, --user <externalUserId>', "YOUR end-user's id (sticky: same id → same agent)")
|
|
16
|
-
.option('-w, --wait <seconds>', 'Seconds to wait for the reply inline (0-60)', '30')
|
|
17
|
-
.option('--display-name <name>', 'Human-readable label stored on the binding')
|
|
18
|
-
.addHelpText('after', `
|
|
19
|
-
Examples:
|
|
20
|
-
maritime message support-bot --user cust_42 "where is my order?"
|
|
21
|
-
maritime message --user cust_42 "hi" # linked directory
|
|
22
|
-
maritime message support-bot --user cust_42 --wait 0 "hi" --json # ack + poll later
|
|
23
|
-
|
|
24
|
-
A 200 with status=replied carries the reply inline. status=provisioning/queued
|
|
25
|
-
means the user's agent is still being set up. The reply arrives via the
|
|
26
|
-
message.reply webhook (maritime guide: webhooks) or GET the message by id.`)
|
|
27
|
-
.action(async (agentPos, messageParts, opts) => {
|
|
28
|
-
try {
|
|
29
|
-
const message = (messageParts || []).join(' ').trim();
|
|
30
|
-
if (!message) {
|
|
31
|
-
fail('No message provided.', { code: 'usage', exitCode: 4 });
|
|
32
|
-
}
|
|
33
|
-
const wait = Math.max(0, Math.min(60, Number(opts.wait) || 0));
|
|
34
|
-
const agent = await resolveAgent(agentPos);
|
|
35
|
-
// The summary omits projectId — fetch the full record for it.
|
|
36
|
-
const full = await authGet(`/api/agents/${agent.id}`);
|
|
37
|
-
if (!full.projectId) {
|
|
38
|
-
fail(`Agent ${agent.name} has no project. Recreate it or use \`maritime chat\`.`, {
|
|
39
|
-
code: 'no_project',
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
const spinner = await makeSpinner(`Routing to ${opts.user}'s agent...`);
|
|
43
|
-
let state;
|
|
44
|
-
try {
|
|
45
|
-
state = await authPost(`/api/v1/projects/${full.projectId}/messages`, {
|
|
46
|
-
externalUserId: opts.user,
|
|
47
|
-
message,
|
|
48
|
-
wait,
|
|
49
|
-
displayName: opts.displayName,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
spinner.fail('Message failed');
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
spinner.stop();
|
|
57
|
-
if (state.status === 'failed') {
|
|
58
|
-
fail(state.error || 'Delivery failed', { code: 'delivery_failed' });
|
|
59
|
-
}
|
|
60
|
-
outputResult({ ok: true, ...state }, () => {
|
|
61
|
-
if (state.status === 'replied') {
|
|
62
|
-
const reply = state.reply ?? '';
|
|
63
|
-
process.stdout.write(reply + (reply.endsWith('\n') ? '' : '\n'));
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
process.stdout.write(`${state.status}: ${state.externalUserId}'s agent is getting ready ` +
|
|
67
|
-
`(message ${state.messageId}). The reply will arrive via the ` +
|
|
68
|
-
`message.reply webhook.\n`);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
handleError(error);
|
|
74
|
-
}
|
|
75
|
-
});
|
package/dist/commands/open.d.ts
DELETED
package/dist/commands/open.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import open from 'open';
|
|
4
|
-
import { CliHttpError } from '../api.js';
|
|
5
|
-
import { resolveAgent } from '../resolve.js';
|
|
6
|
-
const APP_URL = process.env.MARITIME_APP_URL || 'https://maritime.sh';
|
|
7
|
-
export const openCommand = new Command('open')
|
|
8
|
-
.description('Open an agent in the dashboard')
|
|
9
|
-
.argument('[agent]', 'Agent name or ID (defaults to the linked agent)')
|
|
10
|
-
.action(async (agentArg) => {
|
|
11
|
-
try {
|
|
12
|
-
const agent = await resolveAgent(agentArg);
|
|
13
|
-
const url = `${APP_URL}/dashboard/agents/${agent.id}`;
|
|
14
|
-
console.log(chalk.dim(`Opening ${url}`));
|
|
15
|
-
await open(url);
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
if (error instanceof CliHttpError) {
|
|
19
|
-
console.log(chalk.red('Error:') + ` ${error.detail}`);
|
|
20
|
-
process.exitCode = 1;
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
25
|
-
});
|
package/dist/commands/restart.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { authPost } from '../api.js';
|
|
4
|
-
import { resolveAgent } from '../resolve.js';
|
|
5
|
-
import { outputResult, handleError, makeSpinner } from '../output.js';
|
|
6
|
-
export const restartCommand = new Command('restart')
|
|
7
|
-
.description('Restart an agent')
|
|
8
|
-
.argument('[agent]', 'Agent name or ID (defaults to the linked agent)')
|
|
9
|
-
.action(async (agentArg) => {
|
|
10
|
-
try {
|
|
11
|
-
const agent = await resolveAgent(agentArg);
|
|
12
|
-
const spinner = await makeSpinner(`Restarting ${chalk.bold(agent.name)}...`);
|
|
13
|
-
try {
|
|
14
|
-
await authPost(`/api/agents/${agent.id}/restart`);
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
spinner.fail('Failed to restart agent');
|
|
18
|
-
throw error;
|
|
19
|
-
}
|
|
20
|
-
spinner.succeed(chalk.green('Restarted ') + chalk.bold(agent.name));
|
|
21
|
-
outputResult({ ok: true, action: 'restart', agentId: agent.id, name: agent.name }, () => { });
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
handleError(error);
|
|
25
|
-
}
|
|
26
|
-
});
|