maritime-cli 1.5.1 → 1.6.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/AGENTS.md CHANGED
@@ -123,6 +123,22 @@ Success shape:
123
123
 
124
124
  Without `--json`, `chat` prints only the reply text on stdout (clean for piping).
125
125
 
126
+ ### Messaging AS an end-user — `message`
127
+
128
+ `chat` targets one agent; `message` routes by YOUR end-user id through the
129
+ agent's project front door: the same `--user` always reaches the same
130
+ dedicated agent, and an unknown id gets one assigned/spawned per the
131
+ project's `newChatPolicy`.
132
+
133
+ ```bash
134
+ maritime message <agent> --user cust_42 "where is my order?" --json | jq -r '.reply'
135
+ maritime message <agent> --user cust_42 --wait 0 "hi" --json # ack now; reply via message.reply webhook
136
+ ```
137
+
138
+ `status:"replied"` carries `.reply` inline; `"provisioning"`/`"queued"` means
139
+ the user's agent is still booting — poll the message id or subscribe to the
140
+ `message.reply` webhook (`POST /api/v1/webhooks`).
141
+
126
142
  ## Sizing (optional)
127
143
 
128
144
  You don't size agents. `maritime create <name>` picks an applicable size for the
@@ -224,7 +240,7 @@ dir the agent is implied: `maritime env set FOO=bar --json`, `maritime env pull`
224
240
  Project: `init`, `link`, `deploy` (a directory ⇄ an agent)
225
241
  Auth / keys: `login`, `logout`, `whoami`, `keys {create,list,revoke}`
226
242
  Lifecycle: `create`, `list`, `deploy`, `delete`
227
- Interaction: `chat`/`send`
243
+ Interaction: `chat`/`send`, `message` (per-end-user front door)
228
244
  Config: `env {set,import,list,remove,reload,pull}`
229
245
  Observe: `status`, `logs`
230
246
 
@@ -164,17 +164,22 @@ envCommand
164
164
  .option('-r, --reload', 'Hot-reload env into the running container afterward')
165
165
  .action(async (agentArg, file, opts) => {
166
166
  try {
167
- // In a linked dir the single positional is the file (agent = linked);
168
- // otherwise it's `<agent> [file]`.
167
+ // Two positionals always mean `<agent> <file>` — even in a linked dir,
168
+ // an explicit agent must win. The single-positional shorthand treats
169
+ // the arg as the file (agent = linked).
169
170
  let target;
170
171
  let srcFile;
171
- if (getLinkedAgentId()) {
172
+ if (file !== undefined) {
173
+ target = agentArg;
174
+ srcFile = file;
175
+ }
176
+ else if (getLinkedAgentId()) {
172
177
  target = undefined;
173
178
  srcFile = agentArg;
174
179
  }
175
180
  else {
176
181
  target = agentArg;
177
- srcFile = file;
182
+ srcFile = undefined;
178
183
  }
179
184
  let text;
180
185
  if (!srcFile || srcFile === '-') {
@@ -238,17 +243,22 @@ envCommand
238
243
  .option('-r, --reload', 'Hot-reload env into the running container afterward')
239
244
  .action(async (agentArg, keyArg, opts) => {
240
245
  try {
241
- // In a linked dir the single positional is the key (agent = linked);
242
- // otherwise it's `<agent> <key>`.
246
+ // Two positionals always mean `<agent> <key>` — even in a linked dir,
247
+ // an explicit agent must win. Only the single-positional shorthand
248
+ // treats the arg as the key (agent = linked).
243
249
  let target;
244
250
  let key;
245
- if (getLinkedAgentId()) {
251
+ if (keyArg !== undefined) {
252
+ target = agentArg;
253
+ key = keyArg;
254
+ }
255
+ else if (getLinkedAgentId()) {
246
256
  target = undefined;
247
257
  key = agentArg;
248
258
  }
249
259
  else {
250
260
  target = agentArg;
251
- key = keyArg;
261
+ key = undefined;
252
262
  }
253
263
  if (!key) {
254
264
  fail('No env key given to remove.', { code: 'usage', exitCode: EXIT.USAGE });
@@ -296,16 +306,22 @@ envCommand
296
306
  .option('-f, --force', 'Overwrite the file if it already exists')
297
307
  .action(async (agentArg, fileArg, opts) => {
298
308
  try {
299
- // In a linked dir the single positional is the output file (agent = linked).
309
+ // Two positionals always mean `<agent> <file>` — even in a linked dir,
310
+ // an explicit agent must win. The single-positional shorthand treats
311
+ // the arg as the output file (agent = linked).
300
312
  let target;
301
313
  let outFile;
302
- if (getLinkedAgentId()) {
314
+ if (fileArg !== undefined) {
315
+ target = agentArg;
316
+ outFile = fileArg;
317
+ }
318
+ else if (getLinkedAgentId()) {
303
319
  target = undefined;
304
320
  outFile = agentArg || '.env';
305
321
  }
306
322
  else {
307
323
  target = agentArg;
308
- outFile = fileArg || '.env';
324
+ outFile = '.env';
309
325
  }
310
326
  const agent = await resolveAgent(target);
311
327
  const vars = await authGet(`/api/agents/${agent.id}/env`);
@@ -13,7 +13,7 @@ const CONTRACT = {
13
13
  auth: 'Set the MARITIME_TOKEN env var to a long-lived API key (mk_…, minted via `maritime keys create`) or a login JWT. The CLI reads it before anything else; never run interactive login in automation.',
14
14
  json: 'Pass --json on every command. Success → one JSON value on stdout, stderr empty. Failure → one JSON object {ok:false,error:{code,message,status?}} on stderr, stdout empty.',
15
15
  exitCodes: { '0': 'ok', '1': 'error', '2': 'auth', '3': 'not_found', '4': 'usage' },
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.',
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. To message AS one of YOUR end-users (sticky per-user agents via the project front door), use `maritime message <agent> --user <externalUserId> <message>` — status:replied carries .reply inline; provisioning/queued means the reply arrives via the message.reply webhook.',
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
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).',
19
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).',
@@ -9,7 +9,7 @@ keysCommand
9
9
  .command('create')
10
10
  .description('Mint a new API key. Shown once — save it as MARITIME_TOKEN.')
11
11
  .option('-n, --name <name>', 'Label for the key', 'cli-agent')
12
- .option('-s, --scopes <scopes>', `Comma-separated scopes (${VALID_SCOPES.join(', ')}); "manage" = all`, 'provision,deploy,secrets')
12
+ .option('-s, --scopes <scopes>', `Comma-separated scopes (${VALID_SCOPES.join(', ')}); "manage" = all. Defaults to full access — pass a narrower set to restrict the key.`, 'provision,deploy,secrets,manage')
13
13
  .action(async (opts) => {
14
14
  try {
15
15
  const scopes = String(opts.scopes)
@@ -0,0 +1,8 @@
1
+ import { Command } from 'commander';
2
+ /**
3
+ * The project front door: send a message AS one of your end-users. Unlike
4
+ * `chat` (which talks to one specific agent), this routes by --user: the same
5
+ * external user id always reaches the same dedicated agent, and an unknown id
6
+ * gets an agent assigned/spawned per the project's newChatPolicy.
7
+ */
8
+ export declare const messageCommand: Command;
@@ -0,0 +1,75 @@
1
+ import { Command } from 'commander';
2
+ import { authGet, authPost } from '../api.js';
3
+ import { resolveAgent } from '../resolve.js';
4
+ import { outputResult, fail, handleError, makeSpinner } from '../output.js';
5
+ /**
6
+ * The project front door: send a message AS one of your end-users. Unlike
7
+ * `chat` (which talks to one specific agent), this routes by --user: the same
8
+ * external user id always reaches the same dedicated agent, and an unknown id
9
+ * gets an agent assigned/spawned per the project's newChatPolicy.
10
+ */
11
+ export const messageCommand = new Command('message')
12
+ .description("Send an end-user's message through an agent's project front door")
13
+ .argument('[agent]', 'Any agent in the project (names the project; optional when linked)')
14
+ .argument('[message...]', 'Message to send')
15
+ .requiredOption('-u, --user <externalUserId>', "YOUR end-user's id (sticky: same id → same agent)")
16
+ .option('-w, --wait <seconds>', 'Seconds to wait for the reply inline (0-60)', '30')
17
+ .option('--display-name <name>', 'Human-readable label stored on the binding')
18
+ .addHelpText('after', `
19
+ Examples:
20
+ maritime message support-bot --user cust_42 "where is my order?"
21
+ maritime message --user cust_42 "hi" # linked directory
22
+ maritime message support-bot --user cust_42 --wait 0 "hi" --json # ack + poll later
23
+
24
+ A 200 with status=replied carries the reply inline. status=provisioning/queued
25
+ means the user's agent is still being set up — the reply arrives via the
26
+ message.reply webhook (maritime guide: webhooks) or GET the message by id.`)
27
+ .action(async (agentPos, messageParts, opts) => {
28
+ try {
29
+ const message = (messageParts || []).join(' ').trim();
30
+ if (!message) {
31
+ fail('No message provided.', { code: 'usage', exitCode: 4 });
32
+ }
33
+ const wait = Math.max(0, Math.min(60, Number(opts.wait) || 0));
34
+ const agent = await resolveAgent(agentPos);
35
+ // The summary omits projectId — fetch the full record for it.
36
+ const full = await authGet(`/api/agents/${agent.id}`);
37
+ if (!full.projectId) {
38
+ fail(`Agent ${agent.name} has no project — recreate it or use \`maritime chat\`.`, {
39
+ code: 'no_project',
40
+ });
41
+ }
42
+ const spinner = await makeSpinner(`Routing to ${opts.user}'s agent...`);
43
+ let state;
44
+ try {
45
+ state = await authPost(`/api/v1/projects/${full.projectId}/messages`, {
46
+ externalUserId: opts.user,
47
+ message,
48
+ wait,
49
+ displayName: opts.displayName,
50
+ });
51
+ }
52
+ catch (error) {
53
+ spinner.fail('Message failed');
54
+ throw error;
55
+ }
56
+ spinner.stop();
57
+ if (state.status === 'failed') {
58
+ fail(state.error || 'Delivery failed', { code: 'delivery_failed' });
59
+ }
60
+ outputResult({ ok: true, ...state }, () => {
61
+ if (state.status === 'replied') {
62
+ const reply = state.reply ?? '';
63
+ process.stdout.write(reply + (reply.endsWith('\n') ? '' : '\n'));
64
+ }
65
+ else {
66
+ process.stdout.write(`${state.status}: ${state.externalUserId}'s agent is getting ready ` +
67
+ `(message ${state.messageId}). The reply will arrive via the ` +
68
+ `message.reply webhook.\n`);
69
+ }
70
+ });
71
+ }
72
+ catch (error) {
73
+ handleError(error);
74
+ }
75
+ });
@@ -26,6 +26,11 @@ export const templatesCommand = new Command('templates')
26
26
  chalk.bold(t.name.padEnd(20)) +
27
27
  fw.padEnd(20) +
28
28
  chalk.dim(t.description || ''));
29
+ // Surface the demo recording so the CLI links the same clip the
30
+ // dashboard template card does.
31
+ if (t.videoUrl) {
32
+ console.log(' ' + ' '.repeat(20) + chalk.cyan('\u25b6 demo: ') + chalk.underline(t.videoUrl));
33
+ }
29
34
  }
30
35
  console.log();
31
36
  }
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ import { openCommand } from './commands/open.js';
24
24
  import { infoCommand } from './commands/info.js';
25
25
  import { execCommand } from './commands/exec.js';
26
26
  import { chatCommand } from './commands/chat.js';
27
+ import { messageCommand } from './commands/message.js';
27
28
  import { historyCommand } from './commands/history.js';
28
29
  import { triggersCommand } from './commands/triggers.js';
29
30
  import { blueprintCommand } from './commands/blueprint.js';
@@ -64,6 +65,7 @@ program.addCommand(listCommand);
64
65
  program.addCommand(deleteCommand);
65
66
  // Interaction
66
67
  program.addCommand(chatCommand);
68
+ program.addCommand(messageCommand);
67
69
  // Observability
68
70
  program.addCommand(logsCommand);
69
71
  program.addCommand(statusCommand);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maritime-cli",
3
- "version": "1.5.1",
3
+ "version": "1.6.1",
4
4
  "description": "Maritime CLI - Deploy and talk to AI agents from your terminal",
5
5
  "type": "module",
6
6
  "license": "MIT",