maritime-cli 1.1.0 → 1.3.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
@@ -62,15 +62,50 @@ Always read stdout for results and branch on the exit code. Never parse human te
62
62
  | `3` | not found (no such agent) |
63
63
  | `4` | usage error (missing/invalid arguments) |
64
64
 
65
+ ## The project model — a directory is an agent
66
+
67
+ Like `vercel` / `railway`, you can link a directory to an agent and then run
68
+ commands without naming it. Two files:
69
+
70
+ - **`maritime.json`** — committed config describing the agent: `name`,
71
+ `template` (or `framework`), persona `instructions`, env `["KEY", …]` (keys
72
+ only), optional `tier`. The source of truth.
73
+ - **`.maritime/project.json`** — machine-local link (git-ignored) pointing at
74
+ the agent this directory operates on.
75
+
76
+ ```bash
77
+ maritime init <name> --json # scaffold maritime.json + AGENTS.md, create + link
78
+ maritime link <agent> --json # link this dir to an existing agent
79
+ maritime deploy --json # reconcile the agent to maritime.json, then ship
80
+ ```
81
+
82
+ Once linked, the `<agent>` argument is **optional on every command** — it falls
83
+ back to the linked agent (resolved by walking up from the cwd):
84
+
85
+ ```bash
86
+ maritime chat "what's open?" --json # talks to the linked agent
87
+ maritime logs --json # linked agent's logs
88
+ maritime env set FOO=bar --json # linked agent's env (KEY=value ⇒ no agent token)
89
+ maritime status --json # linked agent's detail
90
+ ```
91
+
92
+ For automation you can ignore linking entirely and pass `<agent>` on every call
93
+ (below). To target a different agent from inside a linked dir, pass it
94
+ explicitly: `-a/--agent` on `chat`, or the positional name on commands that take
95
+ a single agent.
96
+
65
97
  ## The interaction primitive — `chat`
66
98
 
67
99
  Send a message to a deployed agent and get its reply. Sleeping serverless
68
100
  agents are auto-woken by the backend.
69
101
 
70
102
  ```bash
71
- # message as argument
103
+ # explicit agent + message
72
104
  maritime chat <agent> "summarize today's incidents" --json
73
105
 
106
+ # linked dir: positionals are the message, target = linked agent
107
+ maritime chat "summarize today's incidents" --json
108
+
74
109
  # message piped via stdin (best for long / multi-line prompts)
75
110
  cat prompt.txt | maritime chat <agent> --json
76
111
 
@@ -78,7 +113,7 @@ cat prompt.txt | maritime chat <agent> --json
78
113
  maritime chat <agent> "and the one before that?" --conversation-id abc123 --json
79
114
  ```
80
115
 
81
- `<agent>` is a name (exact match) or an ID prefix.
116
+ `<agent>` is a name (exact match), an ID prefix, or — omitted — the linked agent.
82
117
 
83
118
  Success shape:
84
119
 
@@ -88,13 +123,17 @@ Success shape:
88
123
 
89
124
  Without `--json`, `chat` prints only the reply text on stdout (clean for piping).
90
125
 
91
- ## Per-agent resources (serverless)
126
+ ## Sizing (optional)
127
+
128
+ You don't size agents. `maritime create <name>` picks an applicable size for the
129
+ framework, and the agent auto-sleeps when idle and wakes on the next `chat`.
92
130
 
93
- Each agent can override the tier defaults at create time. Omitted flags inherit
94
- the tier; values are per-agent (no server pinning).
131
+ For hand-tuning one agent (e.g. a reseller dialing resources per client), `create`
132
+ accepts optional per-agent overrides. They're hidden from `--help` but fully
133
+ supported; omitted flags inherit the tier default.
95
134
 
96
135
  ```bash
97
- maritime create my-agent --source github --repo … \
136
+ maritime create my-agent \
98
137
  --ram 2048 \ # RAM in MB
99
138
  --cpu 1.5 \ # vCPU cores (fractional OK)
100
139
  --idle 600 \ # auto-sleep 600s after the last request
@@ -129,19 +168,26 @@ cat prod.env | maritime env import <agent> - --reload --json
129
168
  maritime env list <agent> --json
130
169
  maritime env remove <agent> OPENAI_API_KEY --reload --json
131
170
  maritime env reload <agent> --json # hot-reload without changing values
171
+ maritime env pull <agent> .env --json # write env to a local .env (secret VALUES masked)
132
172
  ```
133
173
 
134
174
  `import`/`set` return `{ok, uploaded:[…], failed:[{key,error}], reloaded}`.
135
- A partial failure exits `1` with the failed keys listed in `failed`.
175
+ A partial failure exits `1` with the failed keys listed in `failed`. In a linked
176
+ dir the agent is implied: `maritime env set FOO=bar --json`, `maritime env pull`.
136
177
 
137
178
  ## Command map
138
179
 
180
+ Project: `init`, `link`, `deploy` (a directory ⇄ an agent)
139
181
  Auth / keys: `login`, `logout`, `whoami`, `keys {create,list,revoke}`
140
- Lifecycle: `create`, `list`, `start`, `stop`, `restart`, `sleep`, `delete`, `scale <tier>`, `deploy`
141
- Interaction: `chat`/`send`, `exec <agent> <cmd...>`
142
- Config: `env {set,import,list,remove,reload}`
143
- Observe: `status`, `info`, `logs`, `history`, `triggers`, `blueprint`
144
- Discovery: `templates`
182
+ Lifecycle: `create`, `list`, `deploy`, `delete`
183
+ Interaction: `chat`/`send`
184
+ Config: `env {set,import,list,remove,reload,pull}`
185
+ Observe: `status`, `logs`
186
+
187
+ Advanced / ops (hidden from `--help`, still fully supported): `start`, `stop`,
188
+ `restart`, `sleep`, `scale <tier>`, `exec <agent> <cmd...>`, `info`, `history`,
189
+ `triggers`, `blueprint`, `templates`. You rarely need these — lifecycle is
190
+ automatic (idle-sleep + auto-wake on `chat`).
145
191
 
146
192
  Run `maritime <cmd> --help` for flags. Every command accepts the global
147
193
  `--json` and `--verbose`.
@@ -153,7 +199,7 @@ Run `maritime <cmd> --help` for flags. Every command accepts the global
153
199
  maritime status my-agent --json | jq -r '.status'
154
200
 
155
201
  # Create, then talk to it
156
- ID=$(maritime create --name researcher --template openclaw --json | jq -r '.id')
202
+ ID=$(maritime create researcher --template openclaw --json | jq -r '.id')
157
203
  maritime chat "$ID" "introduce yourself" --json | jq -r '.response'
158
204
 
159
205
  # Run a shell command inside the container
@@ -167,7 +213,7 @@ maritime logs my-agent --level error --json
167
213
 
168
214
  - `delete` refuses to run non-interactively without `--yes` (exit `4`); pass
169
215
  `--yes` deliberately.
170
- - `create` requires `--name` when non-interactive (exit `4`).
216
+ - `create` needs a name (positional `<name>`, or `--name`) when non-interactive (exit `4`).
171
217
  - Non-2xx that the backend reports inside a body (e.g. agent not running for
172
218
  `chat`) surfaces as `error.code = "agent_unavailable"`, exit `1`.
173
219
  - The API base URL can be overridden with `MARITIME_API_URL` (default
@@ -1,6 +1,7 @@
1
1
  import { Command } from 'commander';
2
2
  import { authPost } from '../api.js';
3
3
  import { resolveAgent } from '../resolve.js';
4
+ import { getLinkedAgentId } from '../context.js';
4
5
  import { outputResult, fail, handleError, makeSpinner } from '../output.js';
5
6
  /** Read all of stdin (used when the message isn't passed as an argument). */
6
7
  function readStdin() {
@@ -36,18 +37,37 @@ function extractReply(response) {
36
37
  export const chatCommand = new Command('chat')
37
38
  .alias('send')
38
39
  .description('Send a message to an agent and print its reply')
39
- .argument('<agent>', 'Agent name or ID')
40
+ .argument('[agent]', 'Agent name or ID (optional in a linked directory)')
40
41
  .argument('[message...]', 'Message to send (reads stdin if omitted)')
42
+ .option('-a, --agent <name>', 'Target a specific agent (overrides the linked one)')
41
43
  .option('-c, --conversation-id <id>', 'Conversation ID for multi-turn context')
42
44
  .addHelpText('after', `
43
45
  Examples:
44
- maritime chat my-agent "what's the status?" --json
45
- cat prompt.txt | maritime chat my-agent --json
46
- maritime chat my-agent "and then?" --conversation-id abc123`)
47
- .action(async (agentArg, messageParts, opts) => {
46
+ maritime chat "what's the status?" # linked agent
47
+ maritime chat my-agent "what's the status?" # explicit agent
48
+ cat prompt.txt | maritime chat --json # linked agent, long prompt
49
+ maritime chat -a other "and then?" --conversation-id abc123`)
50
+ .action(async (agentPos, messageParts, opts) => {
48
51
  try {
49
- // Message comes from args, or stdin when piped (great for long prompts).
50
- let message = (messageParts || []).join(' ').trim();
52
+ // Disambiguate "which agent" vs "the message" using the linked context:
53
+ // in a linked dir all positionals are the message (target = linked agent,
54
+ // overridable with -a); otherwise the first positional is the agent.
55
+ const positionals = [agentPos, ...(messageParts || [])].filter(Boolean);
56
+ let targetArg;
57
+ let message;
58
+ if (opts.agent) {
59
+ targetArg = opts.agent;
60
+ message = positionals.join(' ');
61
+ }
62
+ else if (getLinkedAgentId()) {
63
+ targetArg = undefined;
64
+ message = positionals.join(' ');
65
+ }
66
+ else {
67
+ targetArg = agentPos;
68
+ message = (messageParts || []).join(' ');
69
+ }
70
+ message = message.trim();
51
71
  if (!message && !process.stdin.isTTY) {
52
72
  message = (await readStdin()).trim();
53
73
  }
@@ -57,7 +77,7 @@ Examples:
57
77
  exitCode: 4,
58
78
  });
59
79
  }
60
- const agent = await resolveAgent(agentArg);
80
+ const agent = await resolveAgent(targetArg);
61
81
  const spinner = await makeSpinner(`Waiting for ${agent.name}...`);
62
82
  let result;
63
83
  try {
@@ -1,4 +1,4 @@
1
- import { Command } from 'commander';
1
+ import { Command, Option } from 'commander';
2
2
  import chalk from 'chalk';
3
3
  import { authGet, authPost } from '../api.js';
4
4
  import { promptForValue } from '../prompt.js';
@@ -21,25 +21,30 @@ function parseEnvPairs(pairs) {
21
21
  }
22
22
  export const createCommand = new Command('create')
23
23
  .description('Create a new agent')
24
- .option('-n, --name <name>', 'Agent name')
25
- .option('-t, --template <template>', 'Template ID')
26
- .option('--framework <framework>', 'Framework (default: custom)')
27
- .option('--tier <tier>', 'Tier (smart, extended, always_on)')
24
+ .argument('[name]', 'Agent name')
25
+ .option('-t, --template <template>', 'Template to base the agent on (see `maritime templates`)')
28
26
  .option('-e, --env <pairs...>', 'Environment variables (KEY=value)')
29
- .option('--ram <mb>', 'RAM in MB (per-agent override of the tier default)')
30
- .option('--cpu <cores>', 'vCPU cores, e.g. 0.5 or 2 (per-agent override)')
31
- .option('--idle <seconds>', 'Auto-sleep this many seconds after the last request')
32
- .option('--always-on', 'Never auto-sleep (mutually exclusive with --idle)')
33
- .option('--disk <gb>', 'Workspace SSD size in GB (per-agent override)')
34
- .option('--max-compute <minutes>', 'Hard cap: auto-sleep after N compute-minutes per billing period')
27
+ // Advanced overrides — kept fully working but off the main --help so the
28
+ // happy path stays flag-free. By default the platform picks the applicable
29
+ // size for the framework and auto-sleeps when idle; you only reach for these
30
+ // to hand-tune a specific agent (e.g. a reseller dialing RAM per client).
31
+ .addOption(new Option('-n, --name <name>', 'Agent name (alias for the positional argument)').hideHelp())
32
+ .addOption(new Option('--framework <framework>', 'Framework (default: custom)').hideHelp())
33
+ .addOption(new Option('--tier <tier>', 'Tier (smart, extended, always_on)').hideHelp())
34
+ .addOption(new Option('--ram <mb>', 'RAM in MB (per-agent override of the tier default)').hideHelp())
35
+ .addOption(new Option('--cpu <cores>', 'vCPU cores, e.g. 0.5 or 2 (per-agent override)').hideHelp())
36
+ .addOption(new Option('--idle <seconds>', 'Auto-sleep this many seconds after the last request').hideHelp())
37
+ .addOption(new Option('--always-on', 'Never auto-sleep (mutually exclusive with --idle)').hideHelp())
38
+ .addOption(new Option('--disk <gb>', 'Workspace SSD size in GB (per-agent override)').hideHelp())
39
+ .addOption(new Option('--max-compute <minutes>', 'Hard cap: auto-sleep after N compute-minutes per billing period').hideHelp())
35
40
  .addHelpText('after', `
36
41
  Examples:
37
- maritime create researcher --template openclaw --json
38
- maritime create acme-bot --ram 2048 --cpu 1.5 --idle 600 --json
39
- maritime create client-x --disk 20 --max-compute 120 --always-on --json`)
40
- .action(async (opts) => {
42
+ maritime create researcher
43
+ maritime create acme-bot --template openclaw --json
44
+ maritime create client-x -e OPENAI_API_KEY=sk-...`)
45
+ .action(async (nameArg, opts) => {
41
46
  try {
42
- let name = opts.name;
47
+ let name = nameArg || opts.name;
43
48
  let templateId = opts.template;
44
49
  const interactive = !isJsonMode() && process.stdin.isTTY;
45
50
  // Interactive mode if no name given
@@ -6,7 +6,7 @@ import { promptForValue } from '../prompt.js';
6
6
  import { isJsonMode, outputResult, fail, handleError, makeSpinner, EXIT } from '../output.js';
7
7
  export const deleteCommand = new Command('delete')
8
8
  .description('Delete an agent')
9
- .argument('<agent>', 'Agent name or ID')
9
+ .argument('[agent]', 'Agent name or ID (defaults to the linked agent)')
10
10
  .option('-y, --yes', 'Skip confirmation')
11
11
  .action(async (agentArg, opts) => {
12
12
  try {
@@ -1,82 +1,147 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
3
  import ora from 'ora';
4
- import { authPost } from '../api.js';
4
+ import { authPost, authPut } from '../api.js';
5
5
  import { resolveAgent } from '../resolve.js';
6
- import { isJsonMode, outputJson, handleError } from '../output.js';
6
+ import { getConfig, getLinkedAgentId, writeLink } from '../context.js';
7
+ import { isJsonMode, outputJson, fail, handleError, EXIT } from '../output.js';
7
8
  import { connectWs } from '../websocket.js';
8
9
  export const deployCommand = new Command('deploy')
9
- .description('Deploy an agent')
10
- .argument('<agent>', 'Agent name or ID')
11
- .option('--source <source>', 'Deploy source (github, docker, template)', 'template')
10
+ .description('Deploy this directory: reconcile the agent to maritime.json, then ship it')
11
+ .argument('[agent]', 'Agent name or ID (defaults to the linked agent / maritime.json)')
12
+ .option('--source <source>', 'Deploy source (github, docker, template)')
12
13
  .option('--repo <url>', 'GitHub repository URL')
13
14
  .option('--image <name>', 'Docker image name')
14
15
  .option('--branch <branch>', 'Git branch')
15
16
  .option('-w, --wait', 'Wait for deployment to complete')
17
+ .addHelpText('after', `
18
+ In a linked project, just run \`maritime deploy\` — it reads maritime.json,
19
+ creates the agent if needed, applies the persona/tier, and redeploys.
20
+ Explicit sources still work: \`maritime deploy --source github --repo <url>\`.`)
16
21
  .action(async (agentArg, opts) => {
17
- const agent = await resolveAgent(agentArg);
18
- const body = {
19
- agentId: agent.id,
20
- source: opts.source,
21
- };
22
- if (opts.repo)
23
- body.repoUrl = opts.repo;
24
- if (opts.image)
25
- body.imageName = opts.image;
26
- if (opts.branch)
27
- body.branch = opts.branch;
28
- const spinner = ora(`Deploying ${chalk.bold(agent.name)}...`).start();
29
22
  try {
30
- const deployment = await authPost('/api/deploy', body);
31
- if (isJsonMode() && !opts.wait) {
32
- spinner.stop();
33
- outputJson(deployment);
34
- return;
23
+ const config = getConfig();
24
+ const explicitSource = Boolean(opts.source || opts.repo || opts.image);
25
+ // ── Resolve (or create) the target agent ──────────────────────────
26
+ let agent;
27
+ if (agentArg) {
28
+ agent = await resolveAgent(agentArg);
35
29
  }
36
- if (!opts.wait) {
37
- spinner.succeed(chalk.green('Deployment started for ') + chalk.bold(agent.name));
38
- console.log(chalk.dim(` Deployment ID: ${deployment.id}`));
39
- console.log(chalk.dim(` Status: ${deployment.status}`));
40
- return;
30
+ else if (getLinkedAgentId()) {
31
+ agent = await resolveAgent(); // linked
41
32
  }
42
- // --wait: stream deploy progress via WebSocket
43
- spinner.text = `Building ${chalk.bold(agent.name)}...`;
44
- await new Promise((resolve, reject) => {
45
- const cleanup = connectWs(`/api/deploy/${agent.id}/status`, {
46
- onMessage(data) {
47
- try {
48
- const msg = JSON.parse(data);
49
- if (msg.message) {
50
- spinner.text = msg.message;
51
- }
52
- if (msg.status === 'success' || msg.status === 'completed') {
53
- spinner.succeed(chalk.green('Deployment complete: ') + chalk.bold(agent.name));
54
- cleanup();
55
- resolve();
33
+ else if (config?.name) {
34
+ // First deploy of a configured-but-not-yet-created project: create it
35
+ // from maritime.json and link this directory (the `vercel` first run).
36
+ agent = await createFromConfig(config);
37
+ writeLink({ agentId: agent.id, name: agent.name });
38
+ // create auto-deploys, so we're done unless the user forced a source.
39
+ if (!explicitSource) {
40
+ 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)));
41
+ return;
42
+ }
43
+ }
44
+ else {
45
+ fail('Nothing to deploy. Pass an agent, link one (`maritime link`), or add maritime.json (`maritime init`).', { code: 'no_agent', exitCode: EXIT.USAGE });
46
+ }
47
+ // ── Reconcile the agent to maritime.json (persona + tier) ─────────
48
+ if (config && !explicitSource) {
49
+ await reconcile(agent.id, config);
50
+ }
51
+ // ── Trigger the deployment ────────────────────────────────────────
52
+ const body = {
53
+ agentId: agent.id,
54
+ source: opts.source || 'template',
55
+ };
56
+ if (opts.repo)
57
+ body.repoUrl = opts.repo;
58
+ if (opts.image)
59
+ body.imageName = opts.image;
60
+ if (opts.branch)
61
+ body.branch = opts.branch;
62
+ const spinner = isJsonMode() ? null : ora(`Deploying ${chalk.bold(agent.name)}...`).start();
63
+ try {
64
+ const deployment = await authPost('/api/deploy', body);
65
+ if (!opts.wait) {
66
+ spinner?.succeed(chalk.green('Deployment started for ') + chalk.bold(agent.name));
67
+ finish(deployment, () => {
68
+ console.log(chalk.dim(` Deployment ID: ${deployment.id}`));
69
+ console.log(chalk.dim(` Status: ${deployment.status}`));
70
+ });
71
+ return;
72
+ }
73
+ // --wait: stream deploy progress via WebSocket
74
+ if (spinner)
75
+ spinner.text = `Building ${chalk.bold(agent.name)}...`;
76
+ await new Promise((resolve, reject) => {
77
+ const cleanup = connectWs(`/api/deploy/${agent.id}/status`, {
78
+ onMessage(data) {
79
+ try {
80
+ const msg = JSON.parse(data);
81
+ if (msg.message && spinner)
82
+ spinner.text = msg.message;
83
+ if (msg.status === 'success' || msg.status === 'completed') {
84
+ spinner?.succeed(chalk.green('Deployment complete: ') + chalk.bold(agent.name));
85
+ cleanup();
86
+ resolve();
87
+ }
88
+ else if (msg.status === 'failed') {
89
+ spinner?.fail(chalk.red('Deployment failed: ') + (msg.message || 'unknown error'));
90
+ cleanup();
91
+ reject(new Error('Deployment failed'));
92
+ }
56
93
  }
57
- else if (msg.status === 'failed') {
58
- spinner.fail(chalk.red('Deployment failed: ') + (msg.message || 'unknown error'));
59
- cleanup();
60
- reject(new Error('Deployment failed'));
94
+ catch {
95
+ if (spinner)
96
+ spinner.text = data.trim();
61
97
  }
62
- }
63
- catch {
64
- // Non-JSON message, show as build output
65
- spinner.text = data.trim();
66
- }
67
- },
68
- onClose() {
69
- resolve();
70
- },
71
- maxReconnects: 3,
98
+ },
99
+ onClose() {
100
+ resolve();
101
+ },
102
+ maxReconnects: 3,
103
+ });
72
104
  });
73
- });
74
- if (isJsonMode()) {
75
- outputJson(deployment);
105
+ finish(deployment, () => { });
106
+ }
107
+ catch (error) {
108
+ spinner?.fail('Deployment failed');
109
+ throw error;
76
110
  }
77
111
  }
78
112
  catch (error) {
79
- spinner.fail('Deployment failed');
80
113
  handleError(error);
81
114
  }
82
115
  });
116
+ /** Create an agent from a maritime.json config (template/framework + persona). */
117
+ async function createFromConfig(config) {
118
+ const body = { name: config.name };
119
+ if (config.template)
120
+ body.templateId = config.template;
121
+ if (config.framework)
122
+ body.framework = config.framework;
123
+ if (config.tier)
124
+ body.tier = config.tier;
125
+ if (config.instructions)
126
+ body.instructions = config.instructions;
127
+ return authPost('/api/agents', body);
128
+ }
129
+ /** Apply persona + tier from config to an existing agent (env takes effect on redeploy). */
130
+ async function reconcile(agentId, config) {
131
+ if (config.instructions) {
132
+ await authPost(`/api/agents/${agentId}/env`, {
133
+ key: 'MARITIME_INSTRUCTIONS',
134
+ value: config.instructions,
135
+ is_secret: false,
136
+ });
137
+ }
138
+ if (config.tier) {
139
+ await authPut(`/api/agents/${agentId}`, { tier: config.tier });
140
+ }
141
+ }
142
+ function finish(json, human) {
143
+ if (isJsonMode())
144
+ outputJson(json);
145
+ else
146
+ human();
147
+ }