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.
Files changed (82) hide show
  1. package/README.md +17 -0
  2. package/bin/maritime.js +40 -0
  3. package/install.js +118 -0
  4. package/package.json +22 -37
  5. package/AGENTS.md +0 -361
  6. package/SKILL.md +0 -181
  7. package/dist/api.d.ts +0 -30
  8. package/dist/api.js +0 -246
  9. package/dist/bundled.d.ts +0 -11
  10. package/dist/bundled.js +0 -25
  11. package/dist/commands/chat.d.ts +0 -2
  12. package/dist/commands/chat.js +0 -120
  13. package/dist/commands/create.d.ts +0 -2
  14. package/dist/commands/create.js +0 -310
  15. package/dist/commands/delete.d.ts +0 -2
  16. package/dist/commands/delete.js +0 -43
  17. package/dist/commands/deploy.d.ts +0 -2
  18. package/dist/commands/deploy.js +0 -180
  19. package/dist/commands/env.d.ts +0 -2
  20. package/dist/commands/env.js +0 -368
  21. package/dist/commands/exec.d.ts +0 -2
  22. package/dist/commands/exec.js +0 -31
  23. package/dist/commands/guide.d.ts +0 -2
  24. package/dist/commands/guide.js +0 -75
  25. package/dist/commands/history.d.ts +0 -2
  26. package/dist/commands/history.js +0 -56
  27. package/dist/commands/info.d.ts +0 -2
  28. package/dist/commands/info.js +0 -78
  29. package/dist/commands/init.d.ts +0 -2
  30. package/dist/commands/init.js +0 -143
  31. package/dist/commands/keys.d.ts +0 -2
  32. package/dist/commands/keys.js +0 -90
  33. package/dist/commands/link.d.ts +0 -4
  34. package/dist/commands/link.js +0 -65
  35. package/dist/commands/list.d.ts +0 -2
  36. package/dist/commands/list.js +0 -55
  37. package/dist/commands/login.d.ts +0 -2
  38. package/dist/commands/login.js +0 -368
  39. package/dist/commands/logout.d.ts +0 -2
  40. package/dist/commands/logout.js +0 -12
  41. package/dist/commands/logs.d.ts +0 -2
  42. package/dist/commands/logs.js +0 -89
  43. package/dist/commands/message.d.ts +0 -8
  44. package/dist/commands/message.js +0 -75
  45. package/dist/commands/open.d.ts +0 -2
  46. package/dist/commands/open.js +0 -25
  47. package/dist/commands/restart.d.ts +0 -2
  48. package/dist/commands/restart.js +0 -26
  49. package/dist/commands/signup.d.ts +0 -2
  50. package/dist/commands/signup.js +0 -72
  51. package/dist/commands/sleep.d.ts +0 -2
  52. package/dist/commands/sleep.js +0 -22
  53. package/dist/commands/start.d.ts +0 -2
  54. package/dist/commands/start.js +0 -27
  55. package/dist/commands/status.d.ts +0 -2
  56. package/dist/commands/status.js +0 -69
  57. package/dist/commands/stop.d.ts +0 -2
  58. package/dist/commands/stop.js +0 -26
  59. package/dist/commands/templates.d.ts +0 -2
  60. package/dist/commands/templates.js +0 -40
  61. package/dist/commands/triggers.d.ts +0 -2
  62. package/dist/commands/triggers.js +0 -89
  63. package/dist/commands/whoami.d.ts +0 -2
  64. package/dist/commands/whoami.js +0 -76
  65. package/dist/config.d.ts +0 -2
  66. package/dist/config.js +0 -14
  67. package/dist/context.d.ts +0 -39
  68. package/dist/context.js +0 -110
  69. package/dist/index.d.ts +0 -2
  70. package/dist/index.js +0 -186
  71. package/dist/interactive.d.ts +0 -1
  72. package/dist/interactive.js +0 -66
  73. package/dist/output.d.ts +0 -80
  74. package/dist/output.js +0 -176
  75. package/dist/prompt.d.ts +0 -2
  76. package/dist/prompt.js +0 -62
  77. package/dist/resolve.d.ts +0 -16
  78. package/dist/resolve.js +0 -59
  79. package/dist/version-check.d.ts +0 -20
  80. package/dist/version-check.js +0 -81
  81. package/dist/websocket.d.ts +0 -22
  82. package/dist/websocket.js +0 -89
@@ -1,310 +0,0 @@
1
- import { Command, Option } from 'commander';
2
- import chalk from 'chalk';
3
- import { authGet, authPost, CliHttpError } from '../api.js';
4
- import { promptForValue } from '../prompt.js';
5
- import { isJsonMode, outputResult, fail, handleError, makeSpinner, EXIT } from '../output.js';
6
- const BATCH_CAP = 50;
7
- function parseEnvPairs(pairs) {
8
- return pairs.map((pair) => {
9
- const eqIdx = pair.indexOf('=');
10
- if (eqIdx <= 0) {
11
- fail(`Invalid env var format: "${pair}". Use KEY=value.`, {
12
- code: 'usage',
13
- exitCode: EXIT.USAGE,
14
- });
15
- }
16
- return {
17
- key: pair.slice(0, eqIdx),
18
- value: pair.slice(eqIdx + 1),
19
- isSecret: true,
20
- };
21
- });
22
- }
23
- export const createCommand = new Command('create')
24
- .description('Create a new agent')
25
- .argument('[name]', 'Agent name')
26
- .option('-t, --template <template>', 'Template to base the agent on (see `maritime templates`)')
27
- .option('-e, --env <pairs...>', 'Environment variables (KEY=value)')
28
- .option('--count <n>', 'Spin up N identical agents in one call. Names become <name>-1..<name>-N')
29
- .option('-r, --repo <url>', 'Deploy from a GitHub repo (must contain a Dockerfile)')
30
- .option('-b, --branch <branch>', 'Git branch to deploy (with --repo)')
31
- .option('--public', 'Serve a public, no-login web URL for this agent (web apps)')
32
- .option('--port <n>', 'Port your app listens on (exposed publicly; default 8080)')
33
- // Advanced overrides, kept fully working but off the main --help so the
34
- // happy path stays flag-free. By default the platform picks the applicable
35
- // size for the framework and auto-sleeps when idle; you only reach for these
36
- // to hand-tune a specific agent (e.g. a reseller dialing RAM per client).
37
- .addOption(new Option('-n, --name <name>', 'Agent name (alias for the positional argument)').hideHelp())
38
- .addOption(new Option('--framework <framework>', 'Framework (default: custom)').hideHelp())
39
- .addOption(new Option('--ram <mb>', 'RAM in MB (2048 included; above that is a paid add-on)').hideHelp())
40
- .addOption(new Option('--cpu <cores>', 'vCPU cores, e.g. 0.5 or 2 (per-agent override)').hideHelp())
41
- .addOption(new Option('--idle <seconds>', 'Auto-sleep this many seconds after the last request').hideHelp())
42
- .addOption(new Option('--always-on', 'Never auto-sleep (a paid add-on; mutually exclusive with --idle)').hideHelp())
43
- .addOption(new Option('--disk <gb>', 'Workspace SSD size in GB (5 included; above that is a paid add-on)').hideHelp())
44
- .addHelpText('after', `
45
- Examples:
46
- maritime create researcher
47
- maritime create acme-bot --template openclaw --json
48
- maritime create my-app --repo https://github.com/you/app --public # public web agent
49
- maritime create client-x -e OPENAI_API_KEY=sk-...
50
- maritime create swarm --template openclaw --count 5 # swarm-1..swarm-5`)
51
- .action(async (nameArg, opts) => {
52
- try {
53
- let name = nameArg || opts.name;
54
- let templateId = opts.template;
55
- // --count: batch spin-up. 1 (default) = the classic single-agent path.
56
- let count = 1;
57
- if (opts.count !== undefined) {
58
- const n = Number(opts.count);
59
- if (!Number.isInteger(n) || n < 1) {
60
- fail('--count must be an integer between 1 and 50.', {
61
- code: 'usage',
62
- exitCode: EXIT.USAGE,
63
- });
64
- }
65
- if (n > BATCH_CAP) {
66
- fail('Batch creates are capped at 50 agents. Contact us if you need more. We keep the cap to protect shared server capacity.', { code: 'usage', exitCode: EXIT.USAGE });
67
- }
68
- count = n;
69
- }
70
- const interactive = !isJsonMode() && process.stdin.isTTY;
71
- // Interactive mode if no name given
72
- if (!name) {
73
- if (!interactive) {
74
- fail('Agent name is required. Pass --name <name>.', {
75
- code: 'usage',
76
- exitCode: EXIT.USAGE,
77
- });
78
- }
79
- name = await promptForValue('Agent name');
80
- if (!name) {
81
- fail('Agent name is required.', { code: 'usage', exitCode: EXIT.USAGE });
82
- }
83
- }
84
- // If no template specified interactively, show available templates
85
- if (interactive && !templateId && !opts.framework) {
86
- try {
87
- const templates = await authGet('/api/templates');
88
- if (templates.length > 0) {
89
- console.log(chalk.dim('\nAvailable templates:'));
90
- templates.forEach((t, i) => {
91
- console.log(` ${chalk.bold(String(i + 1))}. ${t.name} (${t.framework})${t.description ? ' · ' + t.description : ''}`);
92
- });
93
- console.log();
94
- const choice = await promptForValue('Template number (or press Enter to skip)');
95
- const idx = parseInt(choice, 10);
96
- if (idx >= 1 && idx <= templates.length) {
97
- templateId = templates[idx - 1].id;
98
- }
99
- }
100
- }
101
- catch {
102
- // Templates fetch failed; continue without template
103
- }
104
- }
105
- // ── Batch path (--count > 1): one POST /api/fleet/batch call ──
106
- if (count > 1) {
107
- // The batch endpoint only understands a subset of create's flags.
108
- // Anything it can't honor is a hard usage error, never silently dropped.
109
- const unsupported = [];
110
- if (opts.branch !== undefined)
111
- unsupported.push('--branch');
112
- if (opts.public)
113
- unsupported.push('--public');
114
- if (opts.port !== undefined)
115
- unsupported.push('--port');
116
- if (opts.framework !== undefined)
117
- unsupported.push('--framework');
118
- if (opts.ram !== undefined)
119
- unsupported.push('--ram');
120
- if (opts.cpu !== undefined)
121
- unsupported.push('--cpu');
122
- if (opts.disk !== undefined)
123
- unsupported.push('--disk');
124
- if (unsupported.length > 0) {
125
- fail(`${unsupported.join(', ')} cannot be combined with --count > 1. ` +
126
- 'Batch creates support --template, --idle/--always-on, --repo, and -e/--env.', { code: 'usage', exitCode: EXIT.USAGE });
127
- }
128
- if (opts.alwaysOn && opts.idle !== undefined) {
129
- fail('--always-on and --idle are mutually exclusive.', { code: 'usage', exitCode: EXIT.USAGE });
130
- }
131
- const batchBody = { namePrefix: name, count };
132
- if (templateId)
133
- batchBody.templateId = templateId;
134
- if (opts.repo)
135
- batchBody.githubRepo = opts.repo;
136
- if (opts.env)
137
- batchBody.envVars = parseEnvPairs(opts.env);
138
- if (opts.alwaysOn) {
139
- batchBody.idleTtlSeconds = 0; // 0 = always-on (never auto-sleep)
140
- }
141
- else if (opts.idle !== undefined) {
142
- const secs = Number(opts.idle);
143
- if (!Number.isInteger(secs) || secs < 0) {
144
- fail('--idle must be an integer number of seconds (0 = always-on).', {
145
- code: 'usage',
146
- exitCode: EXIT.USAGE,
147
- });
148
- }
149
- batchBody.idleTtlSeconds = secs; // 0 = always-on
150
- }
151
- const spinner = await makeSpinner(`Creating ${chalk.bold(name)} × ${count}...`);
152
- let result;
153
- try {
154
- result = await authPost('/api/fleet/batch', batchBody);
155
- }
156
- catch (error) {
157
- spinner.fail('Failed to create agents');
158
- if (error instanceof CliHttpError && (error.status === 402 || error.status === 403)) {
159
- // 402 = the plan's agent cap (code seat_limit); the server's detail
160
- // is already a complete sentence naming the fix and the billing
161
- // link, so print it verbatim. 403 = the server-enforced batch cap.
162
- // Both are request failures, not auth failures, so exit 1.
163
- fail(error.detail, {
164
- status: error.status,
165
- code: error.code ?? (error.status === 402 ? 'seat_limit' : 'fleet_cap_exceeded'),
166
- exitCode: EXIT.ERROR,
167
- });
168
- }
169
- throw error;
170
- }
171
- const allCreated = result.failed.length === 0 && result.created.length > 0;
172
- if (allCreated) {
173
- spinner.succeed(chalk.green('Created ') + chalk.bold(`${result.created.length} agents`));
174
- }
175
- else {
176
- spinner.stop();
177
- }
178
- // --json → the backend response verbatim on stdout.
179
- outputResult(result, () => {
180
- if (result.created.length > 0) {
181
- console.log('\n ' +
182
- chalk.dim('NAME'.padEnd(24)) +
183
- chalk.dim('ID'.padEnd(28)) +
184
- chalk.dim('STATUS'));
185
- console.log(chalk.dim(' ' + '─'.repeat(62)));
186
- for (const a of result.created) {
187
- const shortName = a.name.length > 22 ? a.name.slice(0, 21) + '…' : a.name;
188
- console.log(' ' + chalk.bold(shortName.padEnd(24)) + chalk.dim(a.id.padEnd(28)) + a.status);
189
- }
190
- }
191
- if (result.failed.length > 0) {
192
- console.log('\n ' + chalk.red(`Failed (${result.failed.length}):`));
193
- for (const f of result.failed) {
194
- console.log(' ' + chalk.bold(f.name.padEnd(24)) + chalk.red(f.error));
195
- }
196
- }
197
- console.log('\n ' + `${result.created.length}/${result.requested} created`);
198
- console.log();
199
- });
200
- // Exit contract: 0 = all created, 1 = partial or none.
201
- if (!allCreated)
202
- process.exitCode = EXIT.ERROR;
203
- return;
204
- }
205
- const body = { name };
206
- if (templateId)
207
- body.templateId = templateId;
208
- if (opts.framework)
209
- body.framework = opts.framework;
210
- if (opts.env)
211
- body.initialEnvVars = parseEnvPairs(opts.env);
212
- if (opts.repo) {
213
- body.githubRepo = opts.repo;
214
- // Source builds need a chance to identify their runtime before boot.
215
- // This preserves an explicit framework or template, while allowing an
216
- // OpenClaw repository to receive its required gateway credential.
217
- if (!templateId && !opts.framework)
218
- body.framework = 'auto';
219
- }
220
- if (opts.branch)
221
- body.branch = opts.branch;
222
- if (opts.public) {
223
- body.publicWeb = true;
224
- // A public web app is a bring-your-own-code agent unless a template was chosen.
225
- if (!templateId && !opts.framework)
226
- body.framework = 'custom';
227
- }
228
- if (opts.port)
229
- body.exposedPort = Number(opts.port);
230
- else if (opts.public)
231
- body.exposedPort = 8080;
232
- // Per-agent resource overrides (serverless). Omitted fields inherit the defaults.
233
- if (opts.alwaysOn && opts.idle !== undefined) {
234
- fail('--always-on and --idle are mutually exclusive.', { code: 'usage', exitCode: 4 });
235
- }
236
- if (opts.ram !== undefined) {
237
- const mb = Number(opts.ram);
238
- if (!Number.isInteger(mb) || mb < 128) {
239
- fail('--ram must be an integer >= 128 (MB).', { code: 'usage', exitCode: 4 });
240
- }
241
- body.memMb = mb;
242
- }
243
- if (opts.cpu !== undefined) {
244
- const cores = Number(opts.cpu);
245
- if (!Number.isFinite(cores) || cores <= 0) {
246
- fail('--cpu must be a positive number of cores (e.g. 0.5, 1, 2).', { code: 'usage', exitCode: 4 });
247
- }
248
- body.vcpus = cores;
249
- }
250
- if (opts.alwaysOn) {
251
- body.idleTtlSeconds = 0; // 0 = always-on (never auto-sleep)
252
- }
253
- else if (opts.idle !== undefined) {
254
- const secs = Number(opts.idle);
255
- if (!Number.isInteger(secs) || secs < 1) {
256
- fail('--idle must be a positive integer (seconds).', { code: 'usage', exitCode: 4 });
257
- }
258
- body.idleTtlSeconds = secs;
259
- }
260
- if (opts.disk !== undefined) {
261
- const gb = Number(opts.disk);
262
- if (!Number.isFinite(gb) || gb <= 0) {
263
- fail('--disk must be a positive number of GB.', { code: 'usage', exitCode: 4 });
264
- }
265
- body.diskGb = gb;
266
- }
267
- const spinner = await makeSpinner(`Creating agent ${chalk.bold(name)}...`);
268
- let agent;
269
- try {
270
- agent = await authPost('/api/agents', body);
271
- }
272
- catch (error) {
273
- spinner.fail('Failed to create agent');
274
- if (error instanceof CliHttpError && error.status === 402) {
275
- // Billing gate, not a crash. The server's detail is already a
276
- // complete user-ready sentence naming the fix (e.g. the free plan
277
- // includes 3 agents: delete one or upgrade) and carrying
278
- // https://maritime.sh/billing, so print it verbatim rather than
279
- // guessing at a reason here.
280
- fail(error.detail, {
281
- status: 402,
282
- code: error.code ?? 'payment_required',
283
- exitCode: EXIT.ERROR,
284
- });
285
- }
286
- throw error;
287
- }
288
- spinner.succeed(chalk.green('Created ') + chalk.bold(agent.name) + chalk.dim(` (${agent.id})`));
289
- outputResult({ ok: true, action: 'create', ...agent }, () => {
290
- console.log(chalk.dim(` Framework: ${agent.framework} | Status: ${agent.status}`));
291
- const res = [];
292
- if (agent.memMb)
293
- res.push(`RAM ${agent.memMb}MB`);
294
- if (agent.vcpus)
295
- res.push(`CPU ${agent.vcpus}`);
296
- if (agent.idleTtlSeconds != null) {
297
- res.push(agent.idleTtlSeconds <= 0 ? 'always-on' : `idle ${agent.idleTtlSeconds}s`);
298
- }
299
- if (agent.diskMb)
300
- res.push(`disk ${(agent.diskMb / 1024).toFixed(1)}GB`);
301
- if (res.length)
302
- console.log(chalk.dim(` Resources: ${res.join(' | ')}`));
303
- if (agent.publicUrl)
304
- console.log(chalk.green(' Public URL: ') + chalk.bold(agent.publicUrl));
305
- });
306
- }
307
- catch (error) {
308
- handleError(error);
309
- }
310
- });
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const deleteCommand: Command;
@@ -1,43 +0,0 @@
1
- import { Command } from 'commander';
2
- import chalk from 'chalk';
3
- import { authDelete } from '../api.js';
4
- import { resolveAgent } from '../resolve.js';
5
- import { promptForValue } from '../prompt.js';
6
- import { isJsonMode, outputResult, fail, handleError, makeSpinner, EXIT } from '../output.js';
7
- export const deleteCommand = new Command('delete')
8
- .description('Delete an agent')
9
- .argument('[agent]', 'Agent name or ID (defaults to the linked agent)')
10
- .option('-y, --yes', 'Skip confirmation')
11
- .action(async (agentArg, opts) => {
12
- try {
13
- // Fail fast (before any network/auth) when a non-interactive caller
14
- // (AI agent, CI, --json) omits --yes and couldn't answer a prompt anyway.
15
- if (!opts.yes && (isJsonMode() || !process.stdin.isTTY)) {
16
- fail('Refusing to delete without confirmation. Pass --yes to proceed.', {
17
- code: 'confirmation_required',
18
- exitCode: EXIT.USAGE,
19
- });
20
- }
21
- const agent = await resolveAgent(agentArg);
22
- if (!opts.yes) {
23
- const confirm = await promptForValue(`Type "${agent.name}" to confirm deletion`);
24
- if (confirm !== agent.name) {
25
- console.log(chalk.yellow('Cancelled.'));
26
- return;
27
- }
28
- }
29
- const spinner = await makeSpinner(`Deleting ${chalk.bold(agent.name)}...`);
30
- try {
31
- await authDelete(`/api/agents/${agent.id}`);
32
- }
33
- catch (error) {
34
- spinner.fail('Failed to delete agent');
35
- throw error;
36
- }
37
- spinner.succeed(chalk.green('Deleted ') + chalk.bold(agent.name));
38
- outputResult({ ok: true, action: 'delete', agentId: agent.id, name: agent.name }, () => { });
39
- }
40
- catch (error) {
41
- handleError(error);
42
- }
43
- });
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const deployCommand: Command;
@@ -1,180 +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 { getConfig, getLinkedAgentId, writeLink } from '../context.js';
6
- import { isJsonMode, outputJson, fail, handleError, makeSpinner, EXIT } from '../output.js';
7
- import { connectWs } from '../websocket.js';
8
- // Upper bound for `deploy --wait`. Repo builds + micro-VM ship normally
9
- // finish in 1-3 minutes; 15 minutes covers cold image pulls with margin.
10
- const WAIT_TIMEOUT_MS = 15 * 60 * 1000;
11
- export const deployCommand = new Command('deploy')
12
- .description('Deploy this directory: reconcile the agent to maritime.json, then ship it')
13
- .argument('[agent]', 'Agent name or ID (defaults to the linked agent / maritime.json)')
14
- .option('--source <source>', 'Deploy source (github, docker, template)')
15
- .option('--repo <url>', 'GitHub repository URL')
16
- .option('--image <name>', 'Docker image name')
17
- .option('--branch <branch>', 'Git branch')
18
- .option('-w, --wait', 'Wait for deployment to complete')
19
- .addHelpText('after', `
20
- In a linked project, just run \`maritime deploy\`: it reads maritime.json,
21
- creates the agent if needed, applies the persona, and redeploys.
22
- Explicit sources still work: \`maritime deploy --source github --repo <url>\`.`)
23
- .action(async (agentArg, opts) => {
24
- try {
25
- const config = getConfig();
26
- const explicitSource = Boolean(opts.source || opts.repo || opts.image);
27
- // ── Resolve (or create) the target agent ──────────────────────────
28
- let agent;
29
- if (agentArg) {
30
- agent = await resolveAgent(agentArg);
31
- }
32
- else if (getLinkedAgentId()) {
33
- agent = await resolveAgent(); // linked
34
- }
35
- else if (config?.name) {
36
- // First deploy of a configured-but-not-yet-created project: create it
37
- // from maritime.json and link this directory (the `vercel` first run).
38
- agent = await createFromConfig(config);
39
- writeLink({ agentId: agent.id, name: agent.name });
40
- // create auto-deploys, so we're done unless the user forced a source.
41
- if (!explicitSource) {
42
- finish({ ok: true, action: 'deploy', created: true, agentId: agent.id, agentName: agent.name, status: 'deploying' }, () => console.log(chalk.green('Created + deploying ') + chalk.bold(agent.name)));
43
- return;
44
- }
45
- }
46
- else {
47
- fail('Nothing to deploy. Pass an agent, link one (`maritime link`), or add maritime.json (`maritime init`).', { code: 'no_agent', exitCode: EXIT.USAGE });
48
- }
49
- // ── Reconcile the agent to maritime.json (persona) ────────────────
50
- if (config && !explicitSource) {
51
- await reconcile(agent.id, config);
52
- }
53
- // ── Trigger the deployment ────────────────────────────────────────
54
- const body = {
55
- agentId: agent.id,
56
- source: opts.source || 'template',
57
- };
58
- if (opts.repo)
59
- body.repoUrl = opts.repo;
60
- if (opts.image)
61
- body.imageName = opts.image;
62
- if (opts.branch)
63
- body.branch = opts.branch;
64
- // makeSpinner (not raw ora): degrades to static lines on 0-width PTYs —
65
- // raw ora write-storms there (the create/chat bug fixed in 1.5.0).
66
- const spinner = isJsonMode() ? null : await makeSpinner(`Deploying ${chalk.bold(agent.name)}...`);
67
- try {
68
- const deployment = await authPost('/api/deploy', body);
69
- if (!opts.wait) {
70
- spinner?.succeed(chalk.green('Deployment started for ') + chalk.bold(agent.name));
71
- finish(deployment, () => {
72
- console.log(chalk.dim(` Deployment ID: ${deployment.id}`));
73
- console.log(chalk.dim(` Status: ${deployment.status}`));
74
- });
75
- return;
76
- }
77
- // --wait: stream deploy progress via WebSocket. The server closes
78
- // the socket on terminal status; the client-side timeout is the
79
- // last-resort bound so --wait can never hang a script forever.
80
- if (spinner)
81
- spinner.text = `Building ${chalk.bold(agent.name)}...`;
82
- let gatewayUnconfirmed = false;
83
- await new Promise((resolve, reject) => {
84
- let settled = false;
85
- const settle = (fn) => {
86
- if (settled)
87
- return;
88
- settled = true;
89
- clearTimeout(timer);
90
- fn();
91
- };
92
- const timer = setTimeout(() => {
93
- settle(() => {
94
- cleanup();
95
- spinner?.fail('Timed out waiting for the deployment');
96
- reject(new Error(`Timed out after ${WAIT_TIMEOUT_MS / 60000} minutes waiting for the deployment. ` +
97
- 'It may still complete: check `maritime status` / `maritime logs`.'));
98
- });
99
- }, WAIT_TIMEOUT_MS);
100
- const cleanup = connectWs(`/api/deploy/${agent.id}/status`, {
101
- onMessage(data) {
102
- try {
103
- const msg = JSON.parse(data);
104
- if (msg.message && spinner)
105
- spinner.text = msg.message;
106
- if (msg.build_log && /did not confirm ready/i.test(msg.build_log)) {
107
- gatewayUnconfirmed = true;
108
- }
109
- if (msg.status === 'success' || msg.status === 'completed') {
110
- spinner?.succeed(chalk.green('Deployment complete: ') + chalk.bold(agent.name));
111
- settle(() => {
112
- cleanup();
113
- resolve();
114
- });
115
- }
116
- else if (msg.status === 'failed') {
117
- spinner?.fail(chalk.red('Deployment failed: ') + (msg.message || 'unknown error'));
118
- settle(() => {
119
- cleanup();
120
- reject(new Error('Deployment failed'));
121
- });
122
- }
123
- }
124
- catch {
125
- if (spinner)
126
- spinner.text = data.trim();
127
- }
128
- },
129
- onClose() {
130
- settle(resolve);
131
- },
132
- maxReconnects: 3,
133
- });
134
- });
135
- // Deploy success with an unconfirmed gateway means the VM booted but
136
- // the app never answered on $PORT: historically that is a dead-on-
137
- // arrival agent. Say so instead of reporting a clean success.
138
- if (gatewayUnconfirmed && !isJsonMode()) {
139
- console.log(chalk.yellow('Warning:') +
140
- ' the app never confirmed it was listening on $PORT. If the public URL 502s,' +
141
- ' check `maritime logs` for the container output (a crashed process takes the whole micro-VM down).');
142
- }
143
- finish({ ...deployment, gatewayUnconfirmed }, () => { });
144
- }
145
- catch (error) {
146
- spinner?.fail('Deployment failed');
147
- throw error;
148
- }
149
- }
150
- catch (error) {
151
- handleError(error);
152
- }
153
- });
154
- /** Create an agent from a maritime.json config (template/framework + persona). */
155
- async function createFromConfig(config) {
156
- const body = { name: config.name };
157
- if (config.template)
158
- body.templateId = config.template;
159
- if (config.framework)
160
- body.framework = config.framework;
161
- if (config.instructions)
162
- body.instructions = config.instructions;
163
- return authPost('/api/agents', body);
164
- }
165
- /** Apply persona from config to an existing agent (env takes effect on redeploy). */
166
- async function reconcile(agentId, config) {
167
- if (config.instructions) {
168
- await authPost(`/api/agents/${agentId}/env`, {
169
- key: 'MARITIME_INSTRUCTIONS',
170
- value: config.instructions,
171
- is_secret: false,
172
- });
173
- }
174
- }
175
- function finish(json, human) {
176
- if (isJsonMode())
177
- outputJson(json);
178
- else
179
- human();
180
- }
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const envCommand: Command;