maritime-cli 1.5.0 → 1.6.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.
@@ -1,9 +1,8 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
- import ora from 'ora';
4
3
  import { authGet, authPost } from '../api.js';
5
4
  import { resolveAgent } from '../resolve.js';
6
- import { isJsonMode, outputJson, handleError } from '../output.js';
5
+ import { isJsonMode, outputJson, handleError, makeSpinner } from '../output.js';
7
6
  const blueprintListCmd = new Command('list')
8
7
  .description('List your blueprints')
9
8
  .action(async () => {
@@ -44,7 +43,7 @@ const blueprintCreateCmd = new Command('create')
44
43
  .action(async (agentArg, opts) => {
45
44
  try {
46
45
  const agent = await resolveAgent(agentArg);
47
- const spinner = ora('Creating blueprint...').start();
46
+ const spinner = await makeSpinner('Creating blueprint...');
48
47
  const blueprint = await authPost('/api/blueprints', {
49
48
  agentId: agent.id,
50
49
  name: opts.name || agent.name,
@@ -68,7 +67,7 @@ const blueprintDeployCmd = new Command('deploy')
68
67
  .option('--name <name>', 'Name for the new agent')
69
68
  .action(async (slug, opts) => {
70
69
  try {
71
- const spinner = ora('Deploying from blueprint...').start();
70
+ const spinner = await makeSpinner('Deploying from blueprint...');
72
71
  const body = {};
73
72
  if (opts.name)
74
73
  body.name = opts.name;
@@ -1,10 +1,9 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
- import ora from 'ora';
4
3
  import { authPost, authPut } from '../api.js';
5
4
  import { resolveAgent } from '../resolve.js';
6
5
  import { getConfig, getLinkedAgentId, writeLink } from '../context.js';
7
- import { isJsonMode, outputJson, fail, handleError, EXIT } from '../output.js';
6
+ import { isJsonMode, outputJson, fail, handleError, makeSpinner, EXIT } from '../output.js';
8
7
  import { connectWs } from '../websocket.js';
9
8
  export const deployCommand = new Command('deploy')
10
9
  .description('Deploy this directory: reconcile the agent to maritime.json, then ship it')
@@ -59,7 +58,9 @@ Explicit sources still work: \`maritime deploy --source github --repo <url>\`.`)
59
58
  body.imageName = opts.image;
60
59
  if (opts.branch)
61
60
  body.branch = opts.branch;
62
- const spinner = isJsonMode() ? null : ora(`Deploying ${chalk.bold(agent.name)}...`).start();
61
+ // makeSpinner (not raw ora): degrades to static lines on 0-width PTYs —
62
+ // raw ora write-storms there (the create/chat bug fixed in 1.5.0).
63
+ const spinner = isJsonMode() ? null : await makeSpinner(`Deploying ${chalk.bold(agent.name)}...`);
63
64
  try {
64
65
  const deployment = await authPost('/api/deploy', body);
65
66
  if (!opts.wait) {
@@ -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`);
@@ -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)
@@ -2,10 +2,10 @@ import http from 'node:http';
2
2
  import crypto from 'node:crypto';
3
3
  import { Command } from 'commander';
4
4
  import chalk from 'chalk';
5
- import ora from 'ora';
6
5
  import open from 'open';
7
6
  import { config } from '../config.js';
8
7
  import { CliHttpError, getApiUrl, postJson } from '../api.js';
8
+ import { makeSpinner } from '../output.js';
9
9
  import { promptForPassword, promptForValue } from '../prompt.js';
10
10
  const APP_URL = process.env.MARITIME_APP_URL || 'https://maritime.sh';
11
11
  const TIMEOUT_MS = 120_000;
@@ -115,7 +115,7 @@ export const loginCommand = new Command('login')
115
115
  console.log(chalk.red('Error:') + ' email and password are required');
116
116
  process.exit(1);
117
117
  }
118
- const spinner = ora('Authenticating...').start();
118
+ const spinner = await makeSpinner('Authenticating...');
119
119
  try {
120
120
  const auth = await postJson('/api/auth/cli-login', {
121
121
  email,
@@ -152,7 +152,7 @@ export const loginCommand = new Command('login')
152
152
  return;
153
153
  }
154
154
  // 3. Default: browser-based login.
155
- const spinner = ora('Opening browser for authentication...').start();
155
+ const spinner = await makeSpinner('Opening browser for authentication...');
156
156
  try {
157
157
  const token = await browserLogin();
158
158
  const payload = decodeJwt(token);
@@ -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
+ });
@@ -1,8 +1,8 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
- import ora from 'ora';
4
3
  import { config } from '../config.js';
5
4
  import { CliHttpError, postJson } from '../api.js';
5
+ import { makeSpinner } from '../output.js';
6
6
  import { promptForPassword, promptForValue } from '../prompt.js';
7
7
  export const signupCommand = new Command('signup')
8
8
  .description('Create a Maritime account with email and password')
@@ -17,7 +17,7 @@ export const signupCommand = new Command('signup')
17
17
  console.log(chalk.red('Error:') + ' email and password are required');
18
18
  process.exit(1);
19
19
  }
20
- const spinner = ora('Creating account...').start();
20
+ const spinner = await makeSpinner('Creating account...');
21
21
  try {
22
22
  const auth = await postJson('/api/auth/cli-signup', {
23
23
  email,
@@ -1,16 +1,15 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
- import ora from 'ora';
4
3
  import { authPost } from '../api.js';
5
4
  import { resolveAgent } from '../resolve.js';
6
- import { isJsonMode, outputJson, handleError } from '../output.js';
5
+ import { isJsonMode, outputJson, handleError, makeSpinner } from '../output.js';
7
6
  export const sleepCommand = new Command('sleep')
8
7
  .description('Put an agent to sleep')
9
8
  .argument('[agent]', 'Agent name or ID (defaults to the linked agent)')
10
9
  .action(async (agentArg) => {
11
10
  try {
12
11
  const agent = await resolveAgent(agentArg);
13
- const spinner = ora(`Sleeping ${chalk.bold(agent.name)}...`).start();
12
+ const spinner = await makeSpinner(`Sleeping ${chalk.bold(agent.name)}...`);
14
13
  const result = await authPost(`/api/agents/${agent.id}/sleep`);
15
14
  spinner.succeed(chalk.green('Agent is now sleeping: ') + chalk.bold(agent.name));
16
15
  if (isJsonMode()) {
@@ -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/dist/output.d.ts CHANGED
@@ -53,6 +53,8 @@ export declare function handleError(error: unknown): never;
53
53
  * corrupt machine output. Lazily loads `ora` only when actually needed.
54
54
  */
55
55
  export interface Spinner {
56
+ /** Live status line (mirrors ora's `.text`); ignored in degraded modes. */
57
+ text?: string;
56
58
  succeed(text?: string): void;
57
59
  fail(text?: string): void;
58
60
  stop(): void;
package/dist/output.js CHANGED
@@ -131,6 +131,10 @@ export async function makeSpinner(text) {
131
131
  // process alive after the command finishes. We never need it.
132
132
  const spinner = ora({ text, stream: process.stderr, discardStdin: false }).start();
133
133
  return {
134
+ set text(t) {
135
+ if (t !== undefined)
136
+ spinner.text = t;
137
+ },
134
138
  succeed: (t) => spinner.succeed(t),
135
139
  fail: (t) => spinner.fail(t),
136
140
  stop: () => spinner.stop(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maritime-cli",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Maritime CLI - Deploy and talk to AI agents from your terminal",
5
5
  "type": "module",
6
6
  "license": "MIT",