maritime-cli 1.4.0 → 1.5.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/AGENTS.md CHANGED
@@ -152,6 +152,50 @@ auto-sleeps the agent for the rest of the billing period when hit).
152
152
  `status <agent> --json` echoes `memMb`, `vcpus`, `idleTtlSeconds`
153
153
  (`0` = always-on, `null` = inherits tier), `diskMb`, and `computeMinutesLimit`.
154
154
 
155
+ ## Fleets — `create --count`
156
+
157
+ `maritime create <name> --count <n>` (n = 2–50) spins up **n identical agents**
158
+ in a single call. `<name>` becomes the prefix — agents are named
159
+ `<name>-1` … `<name>-n`. `--count 1` (the default) is the classic single-agent
160
+ path, unchanged.
161
+
162
+ ```bash
163
+ maritime create swarm --template openclaw --count 5 --idle 3600 --json
164
+ ```
165
+
166
+ Flags supported alongside `--count > 1`: `--template`, `--tier`,
167
+ `--idle`/`--always-on`, `--repo`, and `-e/--env` (applied to every agent).
168
+ In the fleet path `--idle 0` means always-on (same as `--always-on`).
169
+ Any other `create` flag (`--branch`, `--public`, `--port`, `--framework`,
170
+ `--ram`, `--cpu`, `--disk`, `--max-compute`) combined with `--count > 1` is a
171
+ usage error (exit `4`) — nothing is silently dropped. `--count` above 50 is
172
+ also exit `4`; the 50-agent cap is enforced server-side too.
173
+
174
+ Success shape (`--json`, the backend response verbatim):
175
+
176
+ ```json
177
+ {
178
+ "created": [{ "id": "…", "name": "swarm-1", "status": "deploying" }],
179
+ "failed": [{ "name": "swarm-3", "error": "…" }],
180
+ "requested": 5,
181
+ "monthlyCostCents": 500
182
+ }
183
+ ```
184
+
185
+ Exit codes: `0` = **all** requested agents created (`failed` empty);
186
+ `1` = partial or none — inspect `created`/`failed` on stdout. Billing/limit
187
+ rejections surface as the standard error object on stderr with exit `1`:
188
+ `402` → `error.code = "insufficient_balance"` (each agent bills $1/mo from the
189
+ wallet; n agents need n×$1 available), `403` → `error.code =
190
+ "fleet_cap_exceeded"`.
191
+
192
+ ```bash
193
+ # Recipe: spin up a 5-agent fleet, then fan a message out to every member
194
+ maritime create swarm --template openclaw --count 5 --idle 3600 --json \
195
+ | jq -r '.created[].name' \
196
+ | xargs -I{} maritime chat {} "introduce yourself" --json
197
+ ```
198
+
155
199
  ## Environment variables
156
200
 
157
201
  Values are secret (encrypted) by default. Env changes apply on the next
@@ -1,8 +1,13 @@
1
1
  import { Command, Option } from 'commander';
2
2
  import chalk from 'chalk';
3
- import { authGet, authPost } from '../api.js';
3
+ import { authGet, authPost, CliHttpError } from '../api.js';
4
4
  import { promptForValue } from '../prompt.js';
5
5
  import { isJsonMode, outputResult, fail, handleError, makeSpinner, EXIT } from '../output.js';
6
+ const FLEET_CAP = 50;
7
+ /** Format integer cents as a dollar string ($5 or $7.50). */
8
+ function formatDollars(cents) {
9
+ return cents % 100 === 0 ? `$${cents / 100}` : `$${(cents / 100).toFixed(2)}`;
10
+ }
6
11
  function parseEnvPairs(pairs) {
7
12
  return pairs.map((pair) => {
8
13
  const eqIdx = pair.indexOf('=');
@@ -24,6 +29,7 @@ export const createCommand = new Command('create')
24
29
  .argument('[name]', 'Agent name')
25
30
  .option('-t, --template <template>', 'Template to base the agent on (see `maritime templates`)')
26
31
  .option('-e, --env <pairs...>', 'Environment variables (KEY=value)')
32
+ .option('--count <n>', 'Spin up N identical agents in one call (fleet) — names become <name>-1..<name>-N')
27
33
  .option('-r, --repo <url>', 'Deploy from a GitHub repo (must contain a Dockerfile)')
28
34
  .option('-b, --branch <branch>', 'Git branch to deploy (with --repo)')
29
35
  .option('--public', 'Serve a public, no-login web URL for this agent (web apps)')
@@ -46,11 +52,27 @@ Examples:
46
52
  maritime create researcher
47
53
  maritime create acme-bot --template openclaw --json
48
54
  maritime create my-app --repo https://github.com/you/app --public # public web agent
49
- maritime create client-x -e OPENAI_API_KEY=sk-...`)
55
+ maritime create client-x -e OPENAI_API_KEY=sk-...
56
+ maritime create swarm --template openclaw --count 5 # fleet: swarm-1..swarm-5`)
50
57
  .action(async (nameArg, opts) => {
51
58
  try {
52
59
  let name = nameArg || opts.name;
53
60
  let templateId = opts.template;
61
+ // --count: fleet spin-up. 1 (default) = the classic single-agent path.
62
+ let count = 1;
63
+ if (opts.count !== undefined) {
64
+ const n = Number(opts.count);
65
+ if (!Number.isInteger(n) || n < 1) {
66
+ fail('--count must be an integer between 1 and 50.', {
67
+ code: 'usage',
68
+ exitCode: EXIT.USAGE,
69
+ });
70
+ }
71
+ if (n > FLEET_CAP) {
72
+ fail('Fleet spin-ups 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 });
73
+ }
74
+ count = n;
75
+ }
54
76
  const interactive = !isJsonMode() && process.stdin.isTTY;
55
77
  // Interactive mode if no name given
56
78
  if (!name) {
@@ -86,6 +108,111 @@ Examples:
86
108
  // Templates fetch failed; continue without template
87
109
  }
88
110
  }
111
+ // ── Fleet path (--count > 1): one POST /api/fleet/batch call ──
112
+ if (count > 1) {
113
+ // The batch endpoint only understands a subset of create's flags.
114
+ // Anything it can't honor is a hard usage error — never silently dropped.
115
+ const unsupported = [];
116
+ if (opts.branch !== undefined)
117
+ unsupported.push('--branch');
118
+ if (opts.public)
119
+ unsupported.push('--public');
120
+ if (opts.port !== undefined)
121
+ unsupported.push('--port');
122
+ if (opts.framework !== undefined)
123
+ unsupported.push('--framework');
124
+ if (opts.ram !== undefined)
125
+ unsupported.push('--ram');
126
+ if (opts.cpu !== undefined)
127
+ unsupported.push('--cpu');
128
+ if (opts.disk !== undefined)
129
+ unsupported.push('--disk');
130
+ if (opts.maxCompute !== undefined)
131
+ unsupported.push('--max-compute');
132
+ if (unsupported.length > 0) {
133
+ fail(`${unsupported.join(', ')} cannot be combined with --count > 1. ` +
134
+ 'Fleet spin-ups support --template, --tier, --idle/--always-on, --repo, and -e/--env.', { code: 'usage', exitCode: EXIT.USAGE });
135
+ }
136
+ if (opts.alwaysOn && opts.idle !== undefined) {
137
+ fail('--always-on and --idle are mutually exclusive.', { code: 'usage', exitCode: EXIT.USAGE });
138
+ }
139
+ const batchBody = { namePrefix: name, count };
140
+ if (templateId)
141
+ batchBody.templateId = templateId;
142
+ if (opts.tier)
143
+ batchBody.tier = opts.tier;
144
+ if (opts.repo)
145
+ batchBody.githubRepo = opts.repo;
146
+ if (opts.env)
147
+ batchBody.envVars = parseEnvPairs(opts.env);
148
+ if (opts.alwaysOn) {
149
+ batchBody.idleTtlSeconds = 0; // 0 = always-on (never auto-sleep)
150
+ }
151
+ else if (opts.idle !== undefined) {
152
+ const secs = Number(opts.idle);
153
+ if (!Number.isInteger(secs) || secs < 0) {
154
+ fail('--idle must be an integer number of seconds (0 = always-on).', {
155
+ code: 'usage',
156
+ exitCode: EXIT.USAGE,
157
+ });
158
+ }
159
+ batchBody.idleTtlSeconds = secs; // 0 = always-on
160
+ }
161
+ const spinner = await makeSpinner(`Creating fleet ${chalk.bold(name)} × ${count}...`);
162
+ let result;
163
+ try {
164
+ result = await authPost('/api/fleet/batch', batchBody);
165
+ }
166
+ catch (error) {
167
+ spinner.fail('Failed to create fleet');
168
+ if (error instanceof CliHttpError && (error.status === 402 || error.status === 403)) {
169
+ // 402 = wallet can't cover count × $1/mo; 403 = server-enforced cap.
170
+ // Both are request failures, not auth failures → exit 1.
171
+ fail(error.detail, {
172
+ status: error.status,
173
+ code: error.status === 402 ? 'insufficient_balance' : 'fleet_cap_exceeded',
174
+ exitCode: EXIT.ERROR,
175
+ });
176
+ }
177
+ throw error;
178
+ }
179
+ const allCreated = result.failed.length === 0 && result.created.length > 0;
180
+ if (allCreated) {
181
+ spinner.succeed(chalk.green('Created ') + chalk.bold(`${result.created.length} agents`));
182
+ }
183
+ else {
184
+ spinner.stop();
185
+ }
186
+ // --json → the backend response verbatim on stdout.
187
+ outputResult(result, () => {
188
+ if (result.created.length > 0) {
189
+ console.log('\n ' +
190
+ chalk.dim('NAME'.padEnd(24)) +
191
+ chalk.dim('ID'.padEnd(28)) +
192
+ chalk.dim('STATUS'));
193
+ console.log(chalk.dim(' ' + '─'.repeat(62)));
194
+ for (const a of result.created) {
195
+ const shortName = a.name.length > 22 ? a.name.slice(0, 21) + '…' : a.name;
196
+ console.log(' ' + chalk.bold(shortName.padEnd(24)) + chalk.dim(a.id.padEnd(28)) + a.status);
197
+ }
198
+ }
199
+ if (result.failed.length > 0) {
200
+ console.log('\n ' + chalk.red(`Failed (${result.failed.length}):`));
201
+ for (const f of result.failed) {
202
+ console.log(' ' + chalk.bold(f.name.padEnd(24)) + chalk.red(f.error));
203
+ }
204
+ }
205
+ console.log('\n ' +
206
+ `${result.created.length}/${result.requested} created` +
207
+ chalk.dim(' · ') +
208
+ `${formatDollars(result.monthlyCostCents)}/mo`);
209
+ console.log();
210
+ });
211
+ // Exit contract: 0 = all created, 1 = partial or none.
212
+ if (!allCreated)
213
+ process.exit(EXIT.ERROR);
214
+ return;
215
+ }
89
216
  const body = { name };
90
217
  if (templateId)
91
218
  body.templateId = templateId;
@@ -15,6 +15,7 @@ const CONTRACT = {
15
15
  exitCodes: { '0': 'ok', '1': 'error', '2': 'auth', '3': 'not_found', '4': 'usage' },
16
16
  interaction: 'Talk to a deployed agent with `maritime chat <agent> <message>` (or pipe the message via stdin). Returns the reply text (or {response} under --json). Sleeping serverless agents auto-wake.',
17
17
  resources: 'create accepts per-agent overrides: --ram <mb>, --cpu <cores>, --idle <seconds> | --always-on, --disk <gb>, --max-compute <minutes>. Omitted = inherit the tier/plan.',
18
+ fleet: 'create --count <n> (2–50) spins up n identical agents named <name>-1..<name>-n in one call. Supported alongside --count: --template, --tier, --idle/--always-on, --repo, -e/--env; other create flags exit 4. --json returns {created:[{id,name,status}],failed:[{name,error}],requested,monthlyCostCents}. Exit 0 = all created, 1 = partial/none (402 insufficient wallet balance, 403 over the 50-agent cap → exit 1).',
18
19
  project: 'A directory can be linked to an agent (like vercel/railway). `maritime init <name>` scaffolds maritime.json + AGENTS.md and links it; `maritime link <agent>` links an existing one; `maritime deploy` reconciles the agent to maritime.json. Once linked, the <agent> argument is optional on every command (resolved from .maritime/project.json, walking up from cwd).',
19
20
  apiBase: 'Override the API base with MARITIME_API_URL (default https://api.maritime.sh).',
20
21
  };
package/dist/output.js CHANGED
@@ -113,8 +113,23 @@ export async function makeSpinner(text) {
113
113
  if (isJsonMode() || !process.stderr.isTTY) {
114
114
  return { succeed() { }, fail() { }, stop() { } };
115
115
  }
116
+ // Degenerate PTYs — script(1), some CI wrappers — report a 0×0 winsize.
117
+ // ora's line-wrap math then clears "text ÷ 0" lines per frame: a multi-MB/s
118
+ // ANSI write storm whose backpressure starves the event loop, so the await
119
+ // the spinner is covering never resolves. Degrade to static lines instead.
120
+ const cols = process.stderr.columns;
121
+ if (!cols || cols < 20) {
122
+ process.stderr.write(`${text}\n`);
123
+ return {
124
+ succeed: (t) => process.stderr.write(`✔ ${t ?? 'done'}\n`),
125
+ fail: (t) => process.stderr.write(`✖ ${t ?? 'failed'}\n`),
126
+ stop() { },
127
+ };
128
+ }
116
129
  const { default: ora } = await import('ora');
117
- const spinner = ora(text).start();
130
+ // discardStdin grabs stdin in raw mode; in wrapped PTYs that can keep the
131
+ // process alive after the command finishes. We never need it.
132
+ const spinner = ora({ text, stream: process.stderr, discardStdin: false }).start();
118
133
  return {
119
134
  succeed: (t) => spinner.succeed(t),
120
135
  fail: (t) => spinner.fail(t),
@@ -1,6 +1,16 @@
1
1
  import chalk from 'chalk';
2
2
  import { config } from './config.js';
3
3
  const ONE_DAY = 24 * 60 * 60 * 1000;
4
+ /** True when `a` is a strictly newer semver than `b` (numeric x.y.z compare). */
5
+ function isNewer(a, b) {
6
+ const pa = a.split('.').map((n) => parseInt(n, 10) || 0);
7
+ const pb = b.split('.').map((n) => parseInt(n, 10) || 0);
8
+ for (let i = 0; i < 3; i++) {
9
+ if ((pa[i] || 0) !== (pb[i] || 0))
10
+ return (pa[i] || 0) > (pb[i] || 0);
11
+ }
12
+ return false;
13
+ }
4
14
  /**
5
15
  * Non-blocking daily check against npm registry.
6
16
  * Prints a one-line update notice after command output if a newer version exists.
@@ -17,9 +27,15 @@ export function checkForUpdates(currentVersion) {
17
27
  .then((data) => {
18
28
  config.set('lastVersionCheck', Date.now());
19
29
  const latest = data.version;
20
- if (latest && latest !== currentVersion) {
30
+ // Store only genuinely-newer versions, and clear anything stale —
31
+ // otherwise an old cached value survives upgrades forever and the
32
+ // banner suggests a "downgrade" (the 1.x → 0.2.1 bug).
33
+ if (latest && isNewer(latest, currentVersion)) {
21
34
  config.set('latestVersion', latest);
22
35
  }
36
+ else {
37
+ config.delete('latestVersion');
38
+ }
23
39
  })
24
40
  .catch(() => {
25
41
  // Silently ignore — this is a non-blocking check
@@ -34,7 +50,7 @@ export function printUpdateNotice(currentVersion) {
34
50
  if (process.argv.includes('--json'))
35
51
  return;
36
52
  const latest = config.get('latestVersion');
37
- if (latest && latest !== currentVersion) {
53
+ if (latest && isNewer(latest, currentVersion)) {
38
54
  console.log(chalk.dim(`\n Update available: ${currentVersion} → ${chalk.bold(latest)}`) +
39
55
  chalk.dim(' Run ') +
40
56
  chalk.bold('npm i -g maritime-cli') +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maritime-cli",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Maritime CLI - Deploy and talk to AI agents from your terminal",
5
5
  "type": "module",
6
6
  "license": "MIT",