maritime-cli 1.9.0 → 2.0.1
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 +16 -0
- package/archives/checksums.txt +6 -0
- package/archives/maritime_2.0.1_darwin_amd64.tar.gz +0 -0
- package/archives/maritime_2.0.1_darwin_arm64.tar.gz +0 -0
- package/archives/maritime_2.0.1_linux_amd64.tar.gz +0 -0
- package/archives/maritime_2.0.1_linux_arm64.tar.gz +0 -0
- package/archives/maritime_2.0.1_windows_amd64.zip +0 -0
- package/archives/maritime_2.0.1_windows_arm64.zip +0 -0
- package/bin/maritime.js +40 -0
- package/install.js +131 -0
- package/package.json +23 -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/index.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { dirname, join } from 'node:path';
|
|
5
|
-
import { Command } from 'commander';
|
|
6
|
-
import chalk from 'chalk';
|
|
7
|
-
import { loginCommand } from './commands/login.js';
|
|
8
|
-
import { signupCommand } from './commands/signup.js';
|
|
9
|
-
import { logoutCommand } from './commands/logout.js';
|
|
10
|
-
import { whoamiCommand } from './commands/whoami.js';
|
|
11
|
-
import { keysCommand } from './commands/keys.js';
|
|
12
|
-
import { createCommand } from './commands/create.js';
|
|
13
|
-
import { deployCommand } from './commands/deploy.js';
|
|
14
|
-
import { listCommand } from './commands/list.js';
|
|
15
|
-
import { startCommand } from './commands/start.js';
|
|
16
|
-
import { stopCommand } from './commands/stop.js';
|
|
17
|
-
import { restartCommand } from './commands/restart.js';
|
|
18
|
-
import { deleteCommand } from './commands/delete.js';
|
|
19
|
-
import { logsCommand } from './commands/logs.js';
|
|
20
|
-
import { envCommand } from './commands/env.js';
|
|
21
|
-
import { templatesCommand } from './commands/templates.js';
|
|
22
|
-
import { statusCommand } from './commands/status.js';
|
|
23
|
-
import { openCommand } from './commands/open.js';
|
|
24
|
-
import { infoCommand } from './commands/info.js';
|
|
25
|
-
import { execCommand } from './commands/exec.js';
|
|
26
|
-
import { chatCommand } from './commands/chat.js';
|
|
27
|
-
import { messageCommand } from './commands/message.js';
|
|
28
|
-
import { historyCommand } from './commands/history.js';
|
|
29
|
-
import { triggersCommand } from './commands/triggers.js';
|
|
30
|
-
import { sleepCommand } from './commands/sleep.js';
|
|
31
|
-
import { checkForUpdates, printUpdateNotice, versionCheckSettled } from './version-check.js';
|
|
32
|
-
import { guideCommand } from './commands/guide.js';
|
|
33
|
-
import { initCommand } from './commands/init.js';
|
|
34
|
-
import { linkCommand } from './commands/link.js';
|
|
35
|
-
import { getLink } from './context.js';
|
|
36
|
-
import { ExitSignal, handleError } from './output.js';
|
|
37
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
38
|
-
const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'));
|
|
39
|
-
// Daily update check (skipped in --json / non-TTY / CI; awaited in finishRun
|
|
40
|
-
// so its network work can never race process teardown).
|
|
41
|
-
checkForUpdates(pkg.version);
|
|
42
|
-
const program = new Command();
|
|
43
|
-
// Commander's default help/version/usage-error paths call process.exit()
|
|
44
|
-
// internally, which is exactly the hard-exit-with-live-handles pattern that
|
|
45
|
-
// crashes on Windows (see ExitSignal). Route them through ExitSignal too.
|
|
46
|
-
program.exitOverride((err) => {
|
|
47
|
-
throw new ExitSignal(err.exitCode ?? 0);
|
|
48
|
-
});
|
|
49
|
-
program
|
|
50
|
-
.name('maritime')
|
|
51
|
-
.description(chalk.hex('#8B5CF6')('Maritime') + ' · Deploy AI agents from your terminal')
|
|
52
|
-
.version(pkg.version)
|
|
53
|
-
.option('--json', 'Output raw JSON instead of formatted tables')
|
|
54
|
-
.option('--verbose', 'Show detailed request/response info');
|
|
55
|
-
// The lean surface: what shows in `maritime --help`. Everything a human or an
|
|
56
|
-
// AI agent needs on the happy path: authenticate, create, deploy, talk, observe.
|
|
57
|
-
const HIDDEN = { hidden: true };
|
|
58
|
-
// Auth
|
|
59
|
-
program.addCommand(loginCommand);
|
|
60
|
-
program.addCommand(signupCommand);
|
|
61
|
-
program.addCommand(logoutCommand);
|
|
62
|
-
program.addCommand(whoamiCommand);
|
|
63
|
-
program.addCommand(keysCommand);
|
|
64
|
-
// Project: link a directory to an agent (the Vercel/Railway model)
|
|
65
|
-
program.addCommand(initCommand);
|
|
66
|
-
program.addCommand(linkCommand);
|
|
67
|
-
// Agent lifecycle
|
|
68
|
-
program.addCommand(createCommand);
|
|
69
|
-
program.addCommand(deployCommand);
|
|
70
|
-
program.addCommand(listCommand);
|
|
71
|
-
program.addCommand(deleteCommand);
|
|
72
|
-
// Interaction
|
|
73
|
-
program.addCommand(chatCommand);
|
|
74
|
-
program.addCommand(messageCommand);
|
|
75
|
-
// Observability
|
|
76
|
-
program.addCommand(logsCommand);
|
|
77
|
-
program.addCommand(statusCommand);
|
|
78
|
-
program.addCommand(envCommand);
|
|
79
|
-
// Machine manifest (for agents/scripts driving the CLI)
|
|
80
|
-
program.addCommand(guideCommand);
|
|
81
|
-
// --- Hidden: still fully functional, just off the main --help to keep the
|
|
82
|
-
// surface small. Lifecycle is mostly automatic (idle-sleep + auto-wake on
|
|
83
|
-
// chat), so these are ops/debug + power-user/reseller tools, not the happy
|
|
84
|
-
// path. They still work exactly as before; `maritime <cmd> --help` shows them. ---
|
|
85
|
-
program.addCommand(startCommand, HIDDEN);
|
|
86
|
-
program.addCommand(stopCommand, HIDDEN);
|
|
87
|
-
program.addCommand(restartCommand, HIDDEN);
|
|
88
|
-
program.addCommand(sleepCommand, HIDDEN);
|
|
89
|
-
program.addCommand(execCommand, HIDDEN);
|
|
90
|
-
program.addCommand(infoCommand, HIDDEN);
|
|
91
|
-
program.addCommand(historyCommand, HIDDEN);
|
|
92
|
-
program.addCommand(triggersCommand, HIDDEN);
|
|
93
|
-
program.addCommand(templatesCommand, HIDDEN);
|
|
94
|
-
program.addCommand(openCommand, HIDDEN);
|
|
95
|
-
// Make the programmatic contract discoverable from the first thing an agent
|
|
96
|
-
// runs (`maritime --help`), and point to the one-shot machine manifest.
|
|
97
|
-
program.addHelpText('after', `
|
|
98
|
-
Quickstart (a directory is an agent):
|
|
99
|
-
maritime init my-agent create + link this folder to an agent
|
|
100
|
-
maritime chat "hello" talk to the linked agent (no name needed)
|
|
101
|
-
maritime deploy push maritime.json changes (persona)
|
|
102
|
-
maritime logs · status · env · open all act on the linked agent
|
|
103
|
-
|
|
104
|
-
For scripts & AI agents:
|
|
105
|
-
Auth set MARITIME_TOKEN (mk_… key from \`maritime keys create\`)
|
|
106
|
-
Output pass --json: results on stdout, errors as JSON on stderr
|
|
107
|
-
Exit code 0 ok · 1 error · 2 auth · 3 not-found · 4 usage
|
|
108
|
-
Talk maritime chat <agent> "..." (or pipe the message via stdin)
|
|
109
|
-
Full spec maritime guide (human) · maritime guide --json (manifest)`);
|
|
110
|
-
const noArgs = process.argv.length <= 2;
|
|
111
|
-
/**
|
|
112
|
-
* Map any escaped error to an exit code WITHOUT calling process.exit().
|
|
113
|
-
* ExitSignal carries an explicit code (fail(), commander overrides); anything
|
|
114
|
-
* else goes through handleError, which prints a structured failure and
|
|
115
|
-
* throws its own ExitSignal.
|
|
116
|
-
*/
|
|
117
|
-
function settleFatal(error) {
|
|
118
|
-
if (error instanceof ExitSignal) {
|
|
119
|
-
process.exitCode = error.exitCode;
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
try {
|
|
123
|
-
handleError(error);
|
|
124
|
-
}
|
|
125
|
-
catch (signal) {
|
|
126
|
-
process.exitCode = signal instanceof ExitSignal ? signal.exitCode : 1;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* End-of-run: wait for the (bounded, at most daily) update check so no
|
|
131
|
-
* network work is in flight at teardown, print the notice, then arm an
|
|
132
|
-
* unref'd failsafe timer. Normal runs exit the moment the loop drains and
|
|
133
|
-
* never see the timer; if a stray handle (raw-mode stdin left by a prompt
|
|
134
|
-
* library, a wedged socket) keeps the loop alive, the timer force-exits
|
|
135
|
-
* after 2s. By then nothing is in flight, so even the hard exit is safe
|
|
136
|
-
* from the Windows uv_async_send-during-close assertion.
|
|
137
|
-
*/
|
|
138
|
-
async function finishRun() {
|
|
139
|
-
await versionCheckSettled();
|
|
140
|
-
printUpdateNotice(pkg.version);
|
|
141
|
-
const failsafe = setTimeout(() => process.exit(process.exitCode ?? 0), 2000);
|
|
142
|
-
failsafe.unref();
|
|
143
|
-
}
|
|
144
|
-
// In a linked directory, the bare `maritime` shows the linked agent's status
|
|
145
|
-
// (the Vercel/Railway "context-aware default"). Outside one, fall back to the
|
|
146
|
-
// interactive picker in a TTY.
|
|
147
|
-
if (noArgs && getLink()) {
|
|
148
|
-
process.argv = [process.argv[0], process.argv[1], 'status'];
|
|
149
|
-
program
|
|
150
|
-
.parseAsync()
|
|
151
|
-
.catch(settleFatal)
|
|
152
|
-
.finally(() => {
|
|
153
|
-
void finishRun();
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
else if (noArgs && process.stdin.isTTY) {
|
|
157
|
-
import('./interactive.js').then(async ({ runInteractive }) => {
|
|
158
|
-
try {
|
|
159
|
-
const args = await runInteractive();
|
|
160
|
-
// Re-parse with selected command
|
|
161
|
-
process.argv = [process.argv[0], process.argv[1], ...args];
|
|
162
|
-
await program.parseAsync();
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
// Inquirer signals Ctrl-C with ExitPromptError: conventional 130,
|
|
166
|
-
// no error output. Everything else is a real failure.
|
|
167
|
-
if (error?.name === 'ExitPromptError') {
|
|
168
|
-
process.exitCode = 130;
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
settleFatal(error);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
finally {
|
|
175
|
-
void finishRun();
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
program
|
|
181
|
-
.parseAsync()
|
|
182
|
-
.catch(settleFatal)
|
|
183
|
-
.finally(() => {
|
|
184
|
-
void finishRun();
|
|
185
|
-
});
|
|
186
|
-
}
|
package/dist/interactive.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function runInteractive(): Promise<string[]>;
|
package/dist/interactive.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { select } from '@inquirer/prompts';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { authGet } from './api.js';
|
|
4
|
-
const COMMANDS = [
|
|
5
|
-
{ name: 'list', value: 'list', description: 'List your agents', needsAgent: false },
|
|
6
|
-
{ name: 'create', value: 'create', description: 'Create a new agent', needsAgent: false },
|
|
7
|
-
{ name: 'status', value: 'status', description: 'Show agent status', needsAgent: true },
|
|
8
|
-
{ name: 'info', value: 'info', description: 'Show full agent details', needsAgent: true },
|
|
9
|
-
{ name: 'logs', value: 'logs', description: 'View agent logs', needsAgent: true },
|
|
10
|
-
{ name: 'deploy', value: 'deploy', description: 'Deploy an agent', needsAgent: true },
|
|
11
|
-
{ name: 'start', value: 'start', description: 'Start an agent', needsAgent: true },
|
|
12
|
-
{ name: 'stop', value: 'stop', description: 'Stop an agent', needsAgent: true },
|
|
13
|
-
{ name: 'sleep', value: 'sleep', description: 'Put agent to sleep', needsAgent: true },
|
|
14
|
-
{ name: 'restart', value: 'restart', description: 'Restart an agent', needsAgent: true },
|
|
15
|
-
{ name: 'env', value: 'env', description: 'Manage environment variables', needsAgent: false },
|
|
16
|
-
{ name: 'triggers', value: 'triggers', description: 'Manage triggers', needsAgent: false },
|
|
17
|
-
{ name: 'templates', value: 'templates', description: 'Browse templates', needsAgent: false },
|
|
18
|
-
{ name: 'history', value: 'history', description: 'View deploy history', needsAgent: true },
|
|
19
|
-
{ name: 'open', value: 'open', description: 'Open agent in browser', needsAgent: true },
|
|
20
|
-
{ name: 'whoami', value: 'whoami', description: 'Show current user', needsAgent: false },
|
|
21
|
-
{ name: 'logout', value: 'logout', description: 'Log out', needsAgent: false },
|
|
22
|
-
];
|
|
23
|
-
export async function runInteractive() {
|
|
24
|
-
console.log(chalk.hex('#8B5CF6')('\n Maritime') + chalk.dim(' · interactive mode\n'));
|
|
25
|
-
const command = await select({
|
|
26
|
-
message: 'What would you like to do?',
|
|
27
|
-
choices: COMMANDS.map((c) => ({
|
|
28
|
-
name: `${c.name.padEnd(12)} ${chalk.dim(c.description)}`,
|
|
29
|
-
value: c.value,
|
|
30
|
-
})),
|
|
31
|
-
});
|
|
32
|
-
const chosen = COMMANDS.find((c) => c.value === command);
|
|
33
|
-
if (!chosen?.needsAgent) {
|
|
34
|
-
return [command];
|
|
35
|
-
}
|
|
36
|
-
// For agent-targeting commands, show agent picker
|
|
37
|
-
try {
|
|
38
|
-
const agents = await authGet('/api/agents');
|
|
39
|
-
if (agents.length === 0) {
|
|
40
|
-
console.log(chalk.yellow('No agents found.') + ' Run `maritime create` first.');
|
|
41
|
-
return [command];
|
|
42
|
-
}
|
|
43
|
-
const agentName = await select({
|
|
44
|
-
message: 'Select an agent:',
|
|
45
|
-
choices: agents.map((a) => ({
|
|
46
|
-
name: `${a.name.padEnd(24)} ${statusBadge(a.status)}`,
|
|
47
|
-
value: a.name,
|
|
48
|
-
})),
|
|
49
|
-
});
|
|
50
|
-
return [command, agentName];
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
// If auth fails, run command without agent (it will show auth error)
|
|
54
|
-
return [command];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function statusBadge(status) {
|
|
58
|
-
switch (status) {
|
|
59
|
-
case 'active': return chalk.green(status);
|
|
60
|
-
case 'sleeping': return chalk.blue(status);
|
|
61
|
-
case 'deploying': return chalk.yellow(status);
|
|
62
|
-
case 'error': return chalk.red(status);
|
|
63
|
-
case 'stopped': return chalk.gray(status);
|
|
64
|
-
default: return status;
|
|
65
|
-
}
|
|
66
|
-
}
|
package/dist/output.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output + error helpers.
|
|
3
|
-
*
|
|
4
|
-
* Two audiences share this CLI: humans at a terminal, and programs/AI agents
|
|
5
|
-
* that shell out and parse stdout. The `--json` flag switches to a strict
|
|
6
|
-
* machine contract:
|
|
7
|
-
*
|
|
8
|
-
* - success → a single JSON object on STDOUT, nothing else
|
|
9
|
-
* - failure → a single JSON object on STDERR, nothing else
|
|
10
|
-
* - spinners, colors, and the update notice are suppressed
|
|
11
|
-
* - exit code reflects the outcome (see EXIT)
|
|
12
|
-
*
|
|
13
|
-
* In human mode, errors go to STDERR (not stdout) so that even without --json,
|
|
14
|
-
* stdout stays clean enough to pipe.
|
|
15
|
-
*/
|
|
16
|
-
/** Stable exit codes so callers can branch on outcome without parsing text. */
|
|
17
|
-
export declare const EXIT: {
|
|
18
|
-
readonly OK: 0;
|
|
19
|
-
readonly ERROR: 1;
|
|
20
|
-
readonly AUTH: 2;
|
|
21
|
-
readonly NOT_FOUND: 3;
|
|
22
|
-
readonly USAGE: 4;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Thrown instead of calling process.exit(). The entrypoint catches it, sets
|
|
26
|
-
* process.exitCode, and lets the event loop drain naturally.
|
|
27
|
-
*
|
|
28
|
-
* Why: hard process.exit() while libuv handles are still live (undici
|
|
29
|
-
* keep-alive sockets, an in-flight fetch, raw-mode stdin) races handle
|
|
30
|
-
* teardown on Windows and dies with
|
|
31
|
-
* "Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), src\\win\\async.c"
|
|
32
|
-
* (nodejs/node#56645). Draining the loop is the fix; unwinding via a throw
|
|
33
|
-
* also runs finally blocks (spinners, tty restore) that process.exit skips.
|
|
34
|
-
*/
|
|
35
|
-
export declare class ExitSignal extends Error {
|
|
36
|
-
readonly exitCode: number;
|
|
37
|
-
constructor(exitCode: number);
|
|
38
|
-
}
|
|
39
|
-
export declare function isJsonMode(): boolean;
|
|
40
|
-
/** Emit a success payload on stdout (used by --json). */
|
|
41
|
-
export declare function outputJson(data: unknown): void;
|
|
42
|
-
/**
|
|
43
|
-
* Print a result. In --json mode, emits `jsonData` as JSON on stdout.
|
|
44
|
-
* Otherwise runs `human` (a string or a function that prints).
|
|
45
|
-
*/
|
|
46
|
-
export declare function outputResult(jsonData: unknown, human: string | (() => void)): void;
|
|
47
|
-
interface FailOptions {
|
|
48
|
-
/** Override the exit code (defaults to EXIT.ERROR). */
|
|
49
|
-
exitCode?: number;
|
|
50
|
-
/** Machine-stable error code for --json consumers. */
|
|
51
|
-
code?: string;
|
|
52
|
-
/** Optional HTTP status to surface in --json. */
|
|
53
|
-
status?: number;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Print an error and end the command. JSON mode → `{ok:false, error:{...}}`
|
|
57
|
-
* on stderr. Human mode → red "Error:" line on stderr. Never returns: it
|
|
58
|
-
* throws ExitSignal, which the entrypoint turns into process.exitCode so the
|
|
59
|
-
* event loop drains before the process ends (see ExitSignal).
|
|
60
|
-
*/
|
|
61
|
-
export declare function fail(message: string, opts?: FailOptions): never;
|
|
62
|
-
/**
|
|
63
|
-
* Centralized catch-block handler. Maps CliHttpError → fail() with the right
|
|
64
|
-
* code/exit, and turns any other Error into a structured failure too, so an
|
|
65
|
-
* AI agent never has to scrape an uncaught stack trace.
|
|
66
|
-
*/
|
|
67
|
-
export declare function handleError(error: unknown): never;
|
|
68
|
-
/**
|
|
69
|
-
* A spinner that disappears in --json / non-TTY contexts so it can never
|
|
70
|
-
* corrupt machine output. Lazily loads `ora` only when actually needed.
|
|
71
|
-
*/
|
|
72
|
-
export interface Spinner {
|
|
73
|
-
/** Live status line (mirrors ora's `.text`); ignored in degraded modes. */
|
|
74
|
-
text?: string;
|
|
75
|
-
succeed(text?: string): void;
|
|
76
|
-
fail(text?: string): void;
|
|
77
|
-
stop(): void;
|
|
78
|
-
}
|
|
79
|
-
export declare function makeSpinner(text: string): Promise<Spinner>;
|
|
80
|
-
export {};
|
package/dist/output.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output + error helpers.
|
|
3
|
-
*
|
|
4
|
-
* Two audiences share this CLI: humans at a terminal, and programs/AI agents
|
|
5
|
-
* that shell out and parse stdout. The `--json` flag switches to a strict
|
|
6
|
-
* machine contract:
|
|
7
|
-
*
|
|
8
|
-
* - success → a single JSON object on STDOUT, nothing else
|
|
9
|
-
* - failure → a single JSON object on STDERR, nothing else
|
|
10
|
-
* - spinners, colors, and the update notice are suppressed
|
|
11
|
-
* - exit code reflects the outcome (see EXIT)
|
|
12
|
-
*
|
|
13
|
-
* In human mode, errors go to STDERR (not stdout) so that even without --json,
|
|
14
|
-
* stdout stays clean enough to pipe.
|
|
15
|
-
*/
|
|
16
|
-
import chalk from 'chalk';
|
|
17
|
-
import { CliHttpError } from './api.js';
|
|
18
|
-
/** Stable exit codes so callers can branch on outcome without parsing text. */
|
|
19
|
-
export const EXIT = {
|
|
20
|
-
OK: 0,
|
|
21
|
-
ERROR: 1,
|
|
22
|
-
AUTH: 2,
|
|
23
|
-
NOT_FOUND: 3,
|
|
24
|
-
USAGE: 4,
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Thrown instead of calling process.exit(). The entrypoint catches it, sets
|
|
28
|
-
* process.exitCode, and lets the event loop drain naturally.
|
|
29
|
-
*
|
|
30
|
-
* Why: hard process.exit() while libuv handles are still live (undici
|
|
31
|
-
* keep-alive sockets, an in-flight fetch, raw-mode stdin) races handle
|
|
32
|
-
* teardown on Windows and dies with
|
|
33
|
-
* "Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), src\\win\\async.c"
|
|
34
|
-
* (nodejs/node#56645). Draining the loop is the fix; unwinding via a throw
|
|
35
|
-
* also runs finally blocks (spinners, tty restore) that process.exit skips.
|
|
36
|
-
*/
|
|
37
|
-
export class ExitSignal extends Error {
|
|
38
|
-
exitCode;
|
|
39
|
-
constructor(exitCode) {
|
|
40
|
-
super(`exit ${exitCode}`);
|
|
41
|
-
this.exitCode = exitCode;
|
|
42
|
-
this.name = 'ExitSignal';
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export function isJsonMode() {
|
|
46
|
-
return process.argv.includes('--json');
|
|
47
|
-
}
|
|
48
|
-
/** Emit a success payload on stdout (used by --json). */
|
|
49
|
-
export function outputJson(data) {
|
|
50
|
-
process.stdout.write(JSON.stringify(data, null, 2) + '\n');
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Print a result. In --json mode, emits `jsonData` as JSON on stdout.
|
|
54
|
-
* Otherwise runs `human` (a string or a function that prints).
|
|
55
|
-
*/
|
|
56
|
-
export function outputResult(jsonData, human) {
|
|
57
|
-
if (isJsonMode()) {
|
|
58
|
-
outputJson(jsonData);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (typeof human === 'function')
|
|
62
|
-
human();
|
|
63
|
-
else
|
|
64
|
-
console.log(human);
|
|
65
|
-
}
|
|
66
|
-
/** Map an HTTP status to one of our stable exit codes. */
|
|
67
|
-
function exitCodeForStatus(status) {
|
|
68
|
-
if (status === 401 || status === 403)
|
|
69
|
-
return EXIT.AUTH;
|
|
70
|
-
if (status === 404)
|
|
71
|
-
return EXIT.NOT_FOUND;
|
|
72
|
-
return EXIT.ERROR;
|
|
73
|
-
}
|
|
74
|
-
/** Short machine-stable error code, paired with the human message. */
|
|
75
|
-
function errorCodeForStatus(status) {
|
|
76
|
-
switch (status) {
|
|
77
|
-
case 0:
|
|
78
|
-
return 'network_error';
|
|
79
|
-
case 401:
|
|
80
|
-
case 403:
|
|
81
|
-
return 'unauthorized';
|
|
82
|
-
case 402:
|
|
83
|
-
return 'payment_required';
|
|
84
|
-
case 404:
|
|
85
|
-
return 'not_found';
|
|
86
|
-
case 409:
|
|
87
|
-
return 'conflict';
|
|
88
|
-
case 503:
|
|
89
|
-
return 'unavailable';
|
|
90
|
-
default:
|
|
91
|
-
return status >= 500 ? 'server_error' : 'request_failed';
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Print an error and end the command. JSON mode → `{ok:false, error:{...}}`
|
|
96
|
-
* on stderr. Human mode → red "Error:" line on stderr. Never returns: it
|
|
97
|
-
* throws ExitSignal, which the entrypoint turns into process.exitCode so the
|
|
98
|
-
* event loop drains before the process ends (see ExitSignal).
|
|
99
|
-
*/
|
|
100
|
-
export function fail(message, opts = {}) {
|
|
101
|
-
const exitCode = opts.exitCode ?? EXIT.ERROR;
|
|
102
|
-
if (isJsonMode()) {
|
|
103
|
-
process.stderr.write(JSON.stringify({
|
|
104
|
-
ok: false,
|
|
105
|
-
error: {
|
|
106
|
-
code: opts.code ?? 'error',
|
|
107
|
-
message,
|
|
108
|
-
...(opts.status !== undefined ? { status: opts.status } : {}),
|
|
109
|
-
},
|
|
110
|
-
}, null, 2) + '\n');
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
process.stderr.write(chalk.red('Error:') + ` ${message}\n`);
|
|
114
|
-
}
|
|
115
|
-
throw new ExitSignal(exitCode);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Centralized catch-block handler. Maps CliHttpError → fail() with the right
|
|
119
|
-
* code/exit, and turns any other Error into a structured failure too, so an
|
|
120
|
-
* AI agent never has to scrape an uncaught stack trace.
|
|
121
|
-
*/
|
|
122
|
-
export function handleError(error) {
|
|
123
|
-
// ExitSignal is control flow, not a failure to report: a nested fail()
|
|
124
|
-
// already printed its message and chose its exit code. Re-wrapping it
|
|
125
|
-
// here would clobber the code (usage errors became exit 1) and print a
|
|
126
|
-
// second, useless "exit 4" error line.
|
|
127
|
-
if (error instanceof ExitSignal)
|
|
128
|
-
throw error;
|
|
129
|
-
if (error instanceof CliHttpError) {
|
|
130
|
-
// The server's own code wins when it sent one: a 402 that says
|
|
131
|
-
// `seat_limit` tells the caller exactly which gate closed, where the
|
|
132
|
-
// status-derived fallback would only say `payment_required`. The
|
|
133
|
-
// message is always the server's detail verbatim, which for billing
|
|
134
|
-
// gates is already a complete sentence naming the fix.
|
|
135
|
-
fail(error.detail, {
|
|
136
|
-
status: error.status,
|
|
137
|
-
code: error.code ?? errorCodeForStatus(error.status),
|
|
138
|
-
exitCode: exitCodeForStatus(error.status),
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
if (error instanceof Error) {
|
|
142
|
-
fail(error.message, { code: 'error' });
|
|
143
|
-
}
|
|
144
|
-
fail(String(error), { code: 'error' });
|
|
145
|
-
}
|
|
146
|
-
export async function makeSpinner(text) {
|
|
147
|
-
if (isJsonMode() || !process.stderr.isTTY) {
|
|
148
|
-
return { succeed() { }, fail() { }, stop() { } };
|
|
149
|
-
}
|
|
150
|
-
// Degenerate PTYs — script(1), some CI wrappers — report a 0×0 winsize.
|
|
151
|
-
// ora's line-wrap math then clears "text ÷ 0" lines per frame: a multi-MB/s
|
|
152
|
-
// ANSI write storm whose backpressure starves the event loop, so the await
|
|
153
|
-
// the spinner is covering never resolves. Degrade to static lines instead.
|
|
154
|
-
const cols = process.stderr.columns;
|
|
155
|
-
if (!cols || cols < 20) {
|
|
156
|
-
process.stderr.write(`${text}\n`);
|
|
157
|
-
return {
|
|
158
|
-
succeed: (t) => process.stderr.write(`✔ ${t ?? 'done'}\n`),
|
|
159
|
-
fail: (t) => process.stderr.write(`✖ ${t ?? 'failed'}\n`),
|
|
160
|
-
stop() { },
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
const { default: ora } = await import('ora');
|
|
164
|
-
// discardStdin grabs stdin in raw mode; in wrapped PTYs that can keep the
|
|
165
|
-
// process alive after the command finishes. We never need it.
|
|
166
|
-
const spinner = ora({ text, stream: process.stderr, discardStdin: false }).start();
|
|
167
|
-
return {
|
|
168
|
-
set text(t) {
|
|
169
|
-
if (t !== undefined)
|
|
170
|
-
spinner.text = t;
|
|
171
|
-
},
|
|
172
|
-
succeed: (t) => spinner.succeed(t),
|
|
173
|
-
fail: (t) => spinner.fail(t),
|
|
174
|
-
stop: () => spinner.stop(),
|
|
175
|
-
};
|
|
176
|
-
}
|
package/dist/prompt.d.ts
DELETED
package/dist/prompt.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { createInterface } from 'node:readline/promises';
|
|
2
|
-
import { stdin as input, stdout as output } from 'node:process';
|
|
3
|
-
function createPrompt() {
|
|
4
|
-
return createInterface({ input, output });
|
|
5
|
-
}
|
|
6
|
-
export async function promptForValue(label, preset) {
|
|
7
|
-
if (preset) {
|
|
8
|
-
return preset;
|
|
9
|
-
}
|
|
10
|
-
const rl = createPrompt();
|
|
11
|
-
try {
|
|
12
|
-
return (await rl.question(`${label}: `)).trim();
|
|
13
|
-
}
|
|
14
|
-
finally {
|
|
15
|
-
rl.close();
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export async function promptForPassword(preset) {
|
|
19
|
-
if (preset) {
|
|
20
|
-
return preset;
|
|
21
|
-
}
|
|
22
|
-
if (!input.isTTY || !output.isTTY) {
|
|
23
|
-
return promptForValue('Password');
|
|
24
|
-
}
|
|
25
|
-
output.write('Password: ');
|
|
26
|
-
const wasRaw = input.isRaw;
|
|
27
|
-
const chunks = [];
|
|
28
|
-
return await new Promise((resolve) => {
|
|
29
|
-
input.setRawMode?.(true);
|
|
30
|
-
input.resume();
|
|
31
|
-
const cleanup = () => {
|
|
32
|
-
input.removeListener('data', onData);
|
|
33
|
-
input.setRawMode?.(Boolean(wasRaw));
|
|
34
|
-
output.write('\n');
|
|
35
|
-
};
|
|
36
|
-
const finish = () => {
|
|
37
|
-
cleanup();
|
|
38
|
-
resolve(chunks.join('').trim());
|
|
39
|
-
};
|
|
40
|
-
const onData = (buffer) => {
|
|
41
|
-
const value = buffer.toString('utf8');
|
|
42
|
-
if (value === '\u0003') {
|
|
43
|
-
cleanup();
|
|
44
|
-
// Deliberate hard exit: Ctrl-C during a password prompt must be
|
|
45
|
-
// immediate. Pause stdin first so the only live handle is gone;
|
|
46
|
-
// this path runs before any network work, so nothing is in flight.
|
|
47
|
-
input.pause();
|
|
48
|
-
process.exit(130);
|
|
49
|
-
}
|
|
50
|
-
if (value === '\r' || value === '\n') {
|
|
51
|
-
finish();
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (value === '\u007f') {
|
|
55
|
-
chunks.pop();
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
chunks.push(value);
|
|
59
|
-
};
|
|
60
|
-
input.on('data', onData);
|
|
61
|
-
});
|
|
62
|
-
}
|
package/dist/resolve.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export interface AgentSummary {
|
|
2
|
-
id: string;
|
|
3
|
-
name: string;
|
|
4
|
-
status: string;
|
|
5
|
-
framework: string;
|
|
6
|
-
createdAt?: string;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Resolve an agent for a command.
|
|
10
|
-
*
|
|
11
|
-
* - With a name/ID: exact-name match first, then unique ID-prefix match.
|
|
12
|
-
* - Without one: fall back to the agent this directory is linked to
|
|
13
|
-
* (`.maritime/project.json`), so `maritime logs`, `maritime chat "…"`, etc.
|
|
14
|
-
* "just work" in a linked project — the Vercel/Railway model.
|
|
15
|
-
*/
|
|
16
|
-
export declare function resolveAgent(nameOrId?: string): Promise<AgentSummary>;
|
package/dist/resolve.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { authGet } from './api.js';
|
|
2
|
-
import { fail, EXIT } from './output.js';
|
|
3
|
-
import { getLink } from './context.js';
|
|
4
|
-
// Simple in-memory cache for the full agent list (5-second TTL)
|
|
5
|
-
let cachedAgents = null;
|
|
6
|
-
let cacheTime = 0;
|
|
7
|
-
const CACHE_TTL = 5_000;
|
|
8
|
-
async function fetchAllAgents() {
|
|
9
|
-
const now = Date.now();
|
|
10
|
-
if (cachedAgents && now - cacheTime < CACHE_TTL) {
|
|
11
|
-
return cachedAgents;
|
|
12
|
-
}
|
|
13
|
-
cachedAgents = await authGet('/api/agents');
|
|
14
|
-
cacheTime = now;
|
|
15
|
-
return cachedAgents;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Resolve an agent for a command.
|
|
19
|
-
*
|
|
20
|
-
* - With a name/ID: exact-name match first, then unique ID-prefix match.
|
|
21
|
-
* - Without one: fall back to the agent this directory is linked to
|
|
22
|
-
* (`.maritime/project.json`), so `maritime logs`, `maritime chat "…"`, etc.
|
|
23
|
-
* "just work" in a linked project — the Vercel/Railway model.
|
|
24
|
-
*/
|
|
25
|
-
export async function resolveAgent(nameOrId) {
|
|
26
|
-
if (!nameOrId || !nameOrId.trim()) {
|
|
27
|
-
return resolveLinkedAgent();
|
|
28
|
-
}
|
|
29
|
-
// 1. Try server-side exact name match first (single API call, no full list)
|
|
30
|
-
const byName = await authGet(`/api/agents?name=${encodeURIComponent(nameOrId)}`);
|
|
31
|
-
if (byName.length === 1)
|
|
32
|
-
return byName[0];
|
|
33
|
-
// 2. Fall back to full list and match by ID prefix
|
|
34
|
-
const agents = await fetchAllAgents();
|
|
35
|
-
const byId = agents.filter((a) => a.id.startsWith(nameOrId));
|
|
36
|
-
if (byId.length === 1)
|
|
37
|
-
return byId[0];
|
|
38
|
-
if (byId.length > 1) {
|
|
39
|
-
fail(`Ambiguous agent "${nameOrId}". Multiple ID prefix matches.`, {
|
|
40
|
-
code: 'ambiguous_agent',
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
fail(`Agent "${nameOrId}" not found.`, { code: 'not_found', exitCode: EXIT.NOT_FOUND });
|
|
44
|
-
}
|
|
45
|
-
/** The agent linked to the current directory, or a helpful error if none. */
|
|
46
|
-
function resolveLinkedAgent() {
|
|
47
|
-
const link = getLink();
|
|
48
|
-
if (!link) {
|
|
49
|
-
fail("No agent given and this directory isn't linked. Pass an agent name, or run `maritime link` / `maritime init`.", { code: 'no_agent', exitCode: EXIT.USAGE });
|
|
50
|
-
}
|
|
51
|
-
// Return straight from the link file — no API round-trip. Downstream calls
|
|
52
|
-
// that hit the agent will surface a clear 404 if it was deleted.
|
|
53
|
-
return {
|
|
54
|
-
id: link.agentId,
|
|
55
|
-
name: link.name ?? link.agentId,
|
|
56
|
-
status: 'unknown',
|
|
57
|
-
framework: 'unknown',
|
|
58
|
-
};
|
|
59
|
-
}
|
package/dist/version-check.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Daily check against the npm registry.
|
|
3
|
-
*
|
|
4
|
-
* Runs at most once per 24h (throttled at ATTEMPT time, not success time,
|
|
5
|
-
* so an offline machine doesn't re-fire the request on every command), and
|
|
6
|
-
* never in machine/CI contexts where the notice would not be printed
|
|
7
|
-
* anyway. Returns immediately; await versionCheckSettled() before exit.
|
|
8
|
-
*/
|
|
9
|
-
export declare function checkForUpdates(currentVersion: string): void;
|
|
10
|
-
/**
|
|
11
|
-
* Resolves when the (at most one) in-flight update check has settled.
|
|
12
|
-
* Bounded by the fetch's own 3s AbortSignal; resolves immediately when no
|
|
13
|
-
* check ran this invocation (the usual case, 24h throttle).
|
|
14
|
-
*/
|
|
15
|
-
export declare function versionCheckSettled(): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* Print update notice if a newer version was found.
|
|
18
|
-
* Call at the end of command execution.
|
|
19
|
-
*/
|
|
20
|
-
export declare function printUpdateNotice(currentVersion: string): void;
|