maritime-cli 0.2.1 → 1.1.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 (52) hide show
  1. package/AGENTS.md +174 -0
  2. package/dist/api.d.ts +1 -0
  3. package/dist/api.js +130 -13
  4. package/dist/commands/blueprint.d.ts +2 -0
  5. package/dist/commands/blueprint.js +93 -0
  6. package/dist/commands/chat.d.ts +2 -0
  7. package/dist/commands/chat.js +93 -0
  8. package/dist/commands/create.js +127 -48
  9. package/dist/commands/delete.js +28 -18
  10. package/dist/commands/deploy.js +51 -9
  11. package/dist/commands/env.js +206 -43
  12. package/dist/commands/exec.d.ts +2 -0
  13. package/dist/commands/exec.js +28 -0
  14. package/dist/commands/guide.d.ts +2 -0
  15. package/dist/commands/guide.js +83 -0
  16. package/dist/commands/history.d.ts +2 -0
  17. package/dist/commands/history.js +56 -0
  18. package/dist/commands/info.d.ts +2 -0
  19. package/dist/commands/info.js +74 -0
  20. package/dist/commands/keys.d.ts +2 -0
  21. package/dist/commands/keys.js +78 -0
  22. package/dist/commands/list.js +13 -10
  23. package/dist/commands/login.js +70 -10
  24. package/dist/commands/logs.js +38 -14
  25. package/dist/commands/open.d.ts +2 -0
  26. package/dist/commands/open.js +24 -0
  27. package/dist/commands/restart.js +13 -11
  28. package/dist/commands/scale.d.ts +2 -0
  29. package/dist/commands/scale.js +30 -0
  30. package/dist/commands/sleep.d.ts +2 -0
  31. package/dist/commands/sleep.js +23 -0
  32. package/dist/commands/start.js +14 -11
  33. package/dist/commands/status.d.ts +2 -0
  34. package/dist/commands/status.js +73 -0
  35. package/dist/commands/stop.js +13 -11
  36. package/dist/commands/templates.js +11 -9
  37. package/dist/commands/triggers.d.ts +2 -0
  38. package/dist/commands/triggers.js +79 -0
  39. package/dist/commands/whoami.js +65 -24
  40. package/dist/config.js +8 -0
  41. package/dist/index.js +73 -2
  42. package/dist/interactive.d.ts +1 -0
  43. package/dist/interactive.js +68 -0
  44. package/dist/output.d.ts +61 -0
  45. package/dist/output.js +123 -0
  46. package/dist/resolve.d.ts +2 -3
  47. package/dist/resolve.js +23 -10
  48. package/dist/version-check.d.ts +10 -0
  49. package/dist/version-check.js +43 -0
  50. package/dist/websocket.d.ts +13 -0
  51. package/dist/websocket.js +55 -0
  52. package/package.json +8 -4
@@ -0,0 +1,30 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import { authPut } from '../api.js';
4
+ import { resolveAgent } from '../resolve.js';
5
+ import { isJsonMode, outputJson, handleError } from '../output.js';
6
+ const VALID_TIERS = ['smart', 'extended', 'always_on'];
7
+ export const scaleCommand = new Command('scale')
8
+ .description('Change an agent tier')
9
+ .argument('<agent>', 'Agent name or ID')
10
+ .argument('<tier>', 'Target tier (smart, extended, always_on)')
11
+ .action(async (agentArg, tier) => {
12
+ if (!VALID_TIERS.includes(tier)) {
13
+ console.log(chalk.red('Error:') + ` Invalid tier "${tier}". Must be one of: ${VALID_TIERS.join(', ')}`);
14
+ process.exit(1);
15
+ }
16
+ try {
17
+ const agent = await resolveAgent(agentArg);
18
+ const result = await authPut(`/api/agents/${agent.id}`, {
19
+ tier,
20
+ });
21
+ if (isJsonMode()) {
22
+ outputJson(result);
23
+ return;
24
+ }
25
+ console.log(chalk.green('Tier updated:') + ` ${chalk.bold(agent.name)} is now ${chalk.bold(tier)}`);
26
+ }
27
+ catch (error) {
28
+ handleError(error);
29
+ }
30
+ });
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare const sleepCommand: Command;
@@ -0,0 +1,23 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import ora from 'ora';
4
+ import { authPost } from '../api.js';
5
+ import { resolveAgent } from '../resolve.js';
6
+ import { isJsonMode, outputJson, handleError } from '../output.js';
7
+ export const sleepCommand = new Command('sleep')
8
+ .description('Put an agent to sleep')
9
+ .argument('<agent>', 'Agent name or ID')
10
+ .action(async (agentArg) => {
11
+ try {
12
+ const agent = await resolveAgent(agentArg);
13
+ const spinner = ora(`Sleeping ${chalk.bold(agent.name)}...`).start();
14
+ const result = await authPost(`/api/agents/${agent.id}/sleep`);
15
+ spinner.succeed(chalk.green('Agent is now sleeping: ') + chalk.bold(agent.name));
16
+ if (isJsonMode()) {
17
+ outputJson(result);
18
+ }
19
+ }
20
+ catch (error) {
21
+ handleError(error);
22
+ }
23
+ });
@@ -1,24 +1,27 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
- import ora from 'ora';
4
- import { authPost, CliHttpError } from '../api.js';
3
+ import { authPost } from '../api.js';
5
4
  import { resolveAgent } from '../resolve.js';
5
+ import { outputResult, handleError, makeSpinner } from '../output.js';
6
6
  export const startCommand = new Command('start')
7
7
  .description('Start an agent')
8
8
  .argument('<agent>', 'Agent name or ID')
9
9
  .action(async (agentArg) => {
10
- const agent = await resolveAgent(agentArg);
11
- const spinner = ora(`Starting ${chalk.bold(agent.name)}...`).start();
12
10
  try {
13
- await authPost(`/api/agents/${agent.id}/start`);
11
+ const agent = await resolveAgent(agentArg);
12
+ const spinner = await makeSpinner(`Starting ${chalk.bold(agent.name)}...`);
13
+ try {
14
+ await authPost(`/api/agents/${agent.id}/start`);
15
+ }
16
+ catch (error) {
17
+ spinner.fail('Failed to start agent');
18
+ throw error;
19
+ }
14
20
  spinner.succeed(chalk.green('Started ') + chalk.bold(agent.name));
21
+ // Spinner already printed the human line; only --json needs output here.
22
+ outputResult({ ok: true, action: 'start', agentId: agent.id, name: agent.name }, () => { });
15
23
  }
16
24
  catch (error) {
17
- spinner.fail('Failed to start agent');
18
- if (error instanceof CliHttpError) {
19
- console.log(chalk.red('Error:') + ` ${error.detail}`);
20
- process.exit(1);
21
- }
22
- throw error;
25
+ handleError(error);
23
26
  }
24
27
  });
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare const statusCommand: Command;
@@ -0,0 +1,73 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import { authGet } from '../api.js';
4
+ import { resolveAgent } from '../resolve.js';
5
+ import { isJsonMode, outputJson, handleError } from '../output.js';
6
+ export const statusCommand = new Command('status')
7
+ .description('Show detailed status for an agent')
8
+ .argument('<agent>', 'Agent name or ID')
9
+ .action(async (agentArg) => {
10
+ try {
11
+ const summary = await resolveAgent(agentArg);
12
+ const agent = await authGet(`/api/agents/${summary.id}`);
13
+ if (isJsonMode()) {
14
+ outputJson(agent);
15
+ return;
16
+ }
17
+ console.log();
18
+ console.log(chalk.bold(agent.name));
19
+ console.log(chalk.dim('─'.repeat(40)));
20
+ console.log(` ${'Status:'.padEnd(16)} ${statusColor(agent.status)}`);
21
+ console.log(` ${'Framework:'.padEnd(16)} ${agent.framework}`);
22
+ console.log(` ${'Tier:'.padEnd(16)} ${agent.tier}`);
23
+ const resParts = [];
24
+ if (agent.memMb)
25
+ resParts.push(`${agent.memMb}MB`);
26
+ if (agent.vcpus)
27
+ resParts.push(`${agent.vcpus} vCPU`);
28
+ if (agent.diskMb)
29
+ resParts.push(`${(agent.diskMb / 1024).toFixed(1)}GB disk`);
30
+ if (resParts.length)
31
+ console.log(` ${'Resources:'.padEnd(16)} ${resParts.join(' / ')} ${chalk.dim('(override)')}`);
32
+ if (agent.idleTtlSeconds != null) {
33
+ const idle = agent.idleTtlSeconds <= 0 ? 'always-on' : `${agent.idleTtlSeconds}s after request`;
34
+ console.log(` ${'Idle:'.padEnd(16)} ${idle}`);
35
+ }
36
+ if (agent.computeMinutesLimit) {
37
+ console.log(` ${'Compute cap:'.padEnd(16)} ${agent.computeMinutesLimit} min / period`);
38
+ }
39
+ console.log(` ${'ID:'.padEnd(16)} ${chalk.dim(agent.id)}`);
40
+ if (agent.invocationCount !== undefined) {
41
+ console.log(` ${'Invocations:'.padEnd(16)} ${agent.invocationCount}`);
42
+ }
43
+ if (agent.createdAt) {
44
+ console.log(` ${'Created:'.padEnd(16)} ${new Date(agent.createdAt).toLocaleString()}`);
45
+ }
46
+ if (agent.updatedAt) {
47
+ console.log(` ${'Updated:'.padEnd(16)} ${new Date(agent.updatedAt).toLocaleString()}`);
48
+ }
49
+ if (agent.containerId) {
50
+ console.log(` ${'Container:'.padEnd(16)} ${chalk.dim(agent.containerId.slice(0, 12))}`);
51
+ }
52
+ console.log();
53
+ }
54
+ catch (error) {
55
+ handleError(error);
56
+ }
57
+ });
58
+ function statusColor(status) {
59
+ switch (status) {
60
+ case 'active':
61
+ return chalk.green(status);
62
+ case 'sleeping':
63
+ return chalk.blue(status);
64
+ case 'deploying':
65
+ return chalk.yellow(status);
66
+ case 'error':
67
+ return chalk.red(status);
68
+ case 'stopped':
69
+ return chalk.gray(status);
70
+ default:
71
+ return status;
72
+ }
73
+ }
@@ -1,24 +1,26 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
- import ora from 'ora';
4
- import { authPost, CliHttpError } from '../api.js';
3
+ import { authPost } from '../api.js';
5
4
  import { resolveAgent } from '../resolve.js';
5
+ import { outputResult, handleError, makeSpinner } from '../output.js';
6
6
  export const stopCommand = new Command('stop')
7
7
  .description('Stop an agent')
8
8
  .argument('<agent>', 'Agent name or ID')
9
9
  .action(async (agentArg) => {
10
- const agent = await resolveAgent(agentArg);
11
- const spinner = ora(`Stopping ${chalk.bold(agent.name)}...`).start();
12
10
  try {
13
- await authPost(`/api/agents/${agent.id}/stop`);
11
+ const agent = await resolveAgent(agentArg);
12
+ const spinner = await makeSpinner(`Stopping ${chalk.bold(agent.name)}...`);
13
+ try {
14
+ await authPost(`/api/agents/${agent.id}/stop`);
15
+ }
16
+ catch (error) {
17
+ spinner.fail('Failed to stop agent');
18
+ throw error;
19
+ }
14
20
  spinner.succeed(chalk.green('Stopped ') + chalk.bold(agent.name));
21
+ outputResult({ ok: true, action: 'stop', agentId: agent.id, name: agent.name }, () => { });
15
22
  }
16
23
  catch (error) {
17
- spinner.fail('Failed to stop agent');
18
- if (error instanceof CliHttpError) {
19
- console.log(chalk.red('Error:') + ` ${error.detail}`);
20
- process.exit(1);
21
- }
22
- throw error;
24
+ handleError(error);
23
25
  }
24
26
  });
@@ -1,33 +1,35 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
- import { CliHttpError, publicGet } from '../api.js';
3
+ import { publicGet } from '../api.js';
4
+ import { isJsonMode, outputJson, handleError } from '../output.js';
4
5
  export const templatesCommand = new Command('templates')
5
6
  .description('List available agent templates')
6
7
  .action(async () => {
7
8
  try {
8
9
  const templates = await publicGet('/api/templates');
10
+ if (isJsonMode()) {
11
+ outputJson(templates);
12
+ return;
13
+ }
9
14
  if (templates.length === 0) {
10
15
  console.log(chalk.dim('No templates available.'));
11
16
  return;
12
17
  }
13
18
  console.log('\n ' +
14
19
  chalk.dim('NAME'.padEnd(20)) +
15
- chalk.dim('FRAMEWORK'.padEnd(14)) +
20
+ chalk.dim('FRAMEWORK'.padEnd(20)) +
16
21
  chalk.dim('DESCRIPTION'));
17
- console.log(chalk.dim(' ' + '\u2500'.repeat(60)));
22
+ console.log(chalk.dim(' ' + '\u2500'.repeat(66)));
18
23
  for (const t of templates) {
24
+ const fw = t.framework.length > 18 ? t.framework.slice(0, 17) + '\u2026' : t.framework;
19
25
  console.log(' ' +
20
26
  chalk.bold(t.name.padEnd(20)) +
21
- t.framework.padEnd(14) +
27
+ fw.padEnd(20) +
22
28
  chalk.dim(t.description || ''));
23
29
  }
24
30
  console.log();
25
31
  }
26
32
  catch (error) {
27
- if (error instanceof CliHttpError) {
28
- console.log(chalk.red('Error:') + ` ${error.detail}`);
29
- process.exit(1);
30
- }
31
- throw error;
33
+ handleError(error);
32
34
  }
33
35
  });
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare const triggersCommand: Command;
@@ -0,0 +1,79 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import { authGet, authPost, authDelete } from '../api.js';
4
+ import { resolveAgent } from '../resolve.js';
5
+ import { isJsonMode, outputJson, handleError } from '../output.js';
6
+ const triggerListCmd = new Command('list')
7
+ .description('List triggers for an agent')
8
+ .argument('<agent>', 'Agent name or ID')
9
+ .action(async (agentArg) => {
10
+ try {
11
+ const agent = await resolveAgent(agentArg);
12
+ const triggers = await authGet(`/api/agents/${agent.id}/triggers`);
13
+ if (isJsonMode()) {
14
+ outputJson(triggers);
15
+ return;
16
+ }
17
+ if (triggers.length === 0) {
18
+ console.log(chalk.dim('No triggers configured.'));
19
+ return;
20
+ }
21
+ console.log('\n ' +
22
+ chalk.dim('ID'.padEnd(14)) +
23
+ chalk.dim('TYPE'.padEnd(14)) +
24
+ chalk.dim('CONFIG'));
25
+ console.log(chalk.dim(' ' + '\u2500'.repeat(50)));
26
+ for (const t of triggers) {
27
+ const configStr = t.config ? JSON.stringify(t.config) : '';
28
+ console.log(' ' +
29
+ chalk.dim(t.id.slice(0, 12).padEnd(14)) +
30
+ t.type.padEnd(14) +
31
+ chalk.dim(configStr.length > 40 ? configStr.slice(0, 39) + '\u2026' : configStr));
32
+ }
33
+ console.log();
34
+ }
35
+ catch (error) {
36
+ handleError(error);
37
+ }
38
+ });
39
+ const triggerCreateCmd = new Command('create')
40
+ .description('Create a trigger for an agent')
41
+ .argument('<agent>', 'Agent name or ID')
42
+ .requiredOption('--type <type>', 'Trigger type (webhook, cron, email)')
43
+ .option('--cron <expression>', 'Cron expression (for cron triggers)')
44
+ .action(async (agentArg, opts) => {
45
+ try {
46
+ const agent = await resolveAgent(agentArg);
47
+ const body = { type: opts.type };
48
+ if (opts.cron)
49
+ body.config = { cron: opts.cron };
50
+ const trigger = await authPost(`/api/agents/${agent.id}/triggers`, body);
51
+ if (isJsonMode()) {
52
+ outputJson(trigger);
53
+ return;
54
+ }
55
+ console.log(chalk.green('Trigger created:') + ` ${trigger.id} (${trigger.type})`);
56
+ }
57
+ catch (error) {
58
+ handleError(error);
59
+ }
60
+ });
61
+ const triggerDeleteCmd = new Command('delete')
62
+ .description('Delete a trigger')
63
+ .argument('<agent>', 'Agent name or ID')
64
+ .argument('<trigger-id>', 'Trigger ID')
65
+ .action(async (agentArg, triggerId) => {
66
+ try {
67
+ const agent = await resolveAgent(agentArg);
68
+ await authDelete(`/api/agents/${agent.id}/triggers/${triggerId}`);
69
+ console.log(chalk.green('Trigger deleted.'));
70
+ }
71
+ catch (error) {
72
+ handleError(error);
73
+ }
74
+ });
75
+ export const triggersCommand = new Command('triggers')
76
+ .description('Manage agent triggers')
77
+ .addCommand(triggerListCmd)
78
+ .addCommand(triggerCreateCmd)
79
+ .addCommand(triggerDeleteCmd);
@@ -1,34 +1,75 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
3
  import { config } from '../config.js';
4
+ import { isJsonMode, outputResult, fail, EXIT } from '../output.js';
5
+ function decodeJwt(token) {
6
+ try {
7
+ const parts = token.split('.');
8
+ if (parts.length !== 3)
9
+ return null;
10
+ return JSON.parse(Buffer.from(parts[1], 'base64url').toString());
11
+ }
12
+ catch {
13
+ return null;
14
+ }
15
+ }
4
16
  export const whoamiCommand = new Command('whoami')
5
- .description('Show current authenticated user')
17
+ .description('Show the current authentication (token source, user, expiry)')
6
18
  .action(() => {
7
- const token = config.get('token');
19
+ // Env var wins (how an AI agent / CI authenticates), then stored login.
20
+ const envToken = process.env.MARITIME_TOKEN;
21
+ const token = envToken || config.get('token');
8
22
  if (!token) {
9
- console.log(chalk.yellow('Not logged in.') + ' Run `maritime login` first.');
10
- process.exit(1);
11
- }
12
- try {
13
- const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64url').toString());
14
- const email = payload.email || 'unknown';
15
- const exp = payload.exp ? new Date(payload.exp * 1000) : null;
16
- console.log(chalk.bold('Email: ') + email);
17
- if (payload.name) {
18
- console.log(chalk.bold('Name: ') + payload.name);
19
- }
20
- if (exp) {
21
- const now = Date.now();
22
- if (exp.getTime() < now) {
23
- console.log(chalk.bold('Token: ') + chalk.red('expired'));
24
- }
25
- else {
26
- console.log(chalk.bold('Token: ') + chalk.green('valid') + chalk.dim(` (expires ${exp.toLocaleDateString()})`));
27
- }
23
+ if (isJsonMode()) {
24
+ // Not an error per se, but exit non-zero so scripts can branch.
25
+ process.stdout.write(JSON.stringify({ authenticated: false }, null, 2) + '\n');
26
+ process.exit(EXIT.AUTH);
28
27
  }
28
+ fail('Not logged in. Run `maritime login`, or set MARITIME_TOKEN.', {
29
+ code: 'not_authenticated',
30
+ exitCode: EXIT.AUTH,
31
+ });
29
32
  }
30
- catch {
31
- console.log(chalk.red('Error:') + ' Failed to decode token. Try logging in again.');
32
- process.exit(1);
33
+ const source = envToken ? 'env:MARITIME_TOKEN' : 'login';
34
+ // API keys (mk_…) aren't JWTs — report them as a long-lived key.
35
+ if (token.startsWith('mk_')) {
36
+ outputResult({ authenticated: true, method: 'api_key', source, expires: null }, () => {
37
+ console.log(chalk.bold('Method: ') + 'API key (mk_…)');
38
+ console.log(chalk.bold('Source: ') + source);
39
+ console.log(chalk.bold('Token: ') + chalk.green('valid') + chalk.dim(' (does not expire)'));
40
+ });
41
+ return;
33
42
  }
43
+ const payload = decodeJwt(token);
44
+ if (!payload) {
45
+ fail('Could not decode token. Re-run `maritime login` or check MARITIME_TOKEN.', {
46
+ code: 'bad_token',
47
+ exitCode: EXIT.AUTH,
48
+ });
49
+ }
50
+ const email = payload.email || null;
51
+ const name = payload.name || null;
52
+ const expMs = typeof payload.exp === 'number' ? payload.exp * 1000 : null;
53
+ const expired = expMs !== null && Date.now() >= expMs;
54
+ outputResult({
55
+ authenticated: !expired,
56
+ method: 'jwt',
57
+ source,
58
+ email,
59
+ name,
60
+ expiresAt: expMs ? new Date(expMs).toISOString() : null,
61
+ expired,
62
+ }, () => {
63
+ if (email)
64
+ console.log(chalk.bold('Email: ') + email);
65
+ if (name)
66
+ console.log(chalk.bold('Name: ') + name);
67
+ console.log(chalk.bold('Source: ') + source);
68
+ if (expMs) {
69
+ console.log(chalk.bold('Token: ') +
70
+ (expired ? chalk.red('expired') : chalk.green('valid') + chalk.dim(` (expires ${new Date(expMs).toLocaleDateString()})`)));
71
+ }
72
+ });
73
+ if (expired)
74
+ process.exit(EXIT.AUTH);
34
75
  });
package/dist/config.js CHANGED
@@ -1,6 +1,14 @@
1
+ import { chmodSync } from 'node:fs';
1
2
  import Conf from 'conf';
2
3
  const configDir = process.env.MARITIME_CONFIG_DIR;
3
4
  export const config = new Conf({
4
5
  projectName: 'maritime',
5
6
  ...(configDir ? { cwd: configDir } : {}),
6
7
  });
8
+ // Restrict config file permissions to owner-only (ignored on Windows)
9
+ try {
10
+ chmodSync(config.path, 0o600);
11
+ }
12
+ catch {
13
+ // chmodSync may fail on Windows or read-only filesystems
14
+ }
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import { loginCommand } from './commands/login.js';
8
8
  import { signupCommand } from './commands/signup.js';
9
9
  import { logoutCommand } from './commands/logout.js';
10
10
  import { whoamiCommand } from './commands/whoami.js';
11
+ import { keysCommand } from './commands/keys.js';
11
12
  import { createCommand } from './commands/create.js';
12
13
  import { deployCommand } from './commands/deploy.js';
13
14
  import { listCommand } from './commands/list.js';
@@ -18,18 +19,36 @@ import { deleteCommand } from './commands/delete.js';
18
19
  import { logsCommand } from './commands/logs.js';
19
20
  import { envCommand } from './commands/env.js';
20
21
  import { templatesCommand } from './commands/templates.js';
22
+ import { statusCommand } from './commands/status.js';
23
+ import { openCommand } from './commands/open.js';
24
+ import { infoCommand } from './commands/info.js';
25
+ import { execCommand } from './commands/exec.js';
26
+ import { chatCommand } from './commands/chat.js';
27
+ import { historyCommand } from './commands/history.js';
28
+ import { triggersCommand } from './commands/triggers.js';
29
+ import { blueprintCommand } from './commands/blueprint.js';
30
+ import { scaleCommand } from './commands/scale.js';
31
+ import { sleepCommand } from './commands/sleep.js';
32
+ import { checkForUpdates, printUpdateNotice } from './version-check.js';
33
+ import { guideCommand } from './commands/guide.js';
34
+ import { handleError } from './output.js';
21
35
  const __dirname = dirname(fileURLToPath(import.meta.url));
22
36
  const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'));
37
+ // Non-blocking version check
38
+ checkForUpdates(pkg.version);
23
39
  const program = new Command();
24
40
  program
25
41
  .name('maritime')
26
42
  .description(chalk.hex('#8B5CF6')('Maritime') + ' \u2014 Deploy AI agents from your terminal')
27
- .version(pkg.version);
43
+ .version(pkg.version)
44
+ .option('--json', 'Output raw JSON instead of formatted tables')
45
+ .option('--verbose', 'Show detailed request/response info');
28
46
  // Auth
29
47
  program.addCommand(loginCommand);
30
48
  program.addCommand(signupCommand);
31
49
  program.addCommand(logoutCommand);
32
50
  program.addCommand(whoamiCommand);
51
+ program.addCommand(keysCommand);
33
52
  // Agent management
34
53
  program.addCommand(createCommand);
35
54
  program.addCommand(listCommand);
@@ -38,9 +57,61 @@ program.addCommand(startCommand);
38
57
  program.addCommand(stopCommand);
39
58
  program.addCommand(restartCommand);
40
59
  program.addCommand(deleteCommand);
60
+ program.addCommand(sleepCommand);
61
+ program.addCommand(scaleCommand);
62
+ // Interaction
63
+ program.addCommand(chatCommand);
64
+ program.addCommand(execCommand);
41
65
  // Observability
42
66
  program.addCommand(logsCommand);
43
67
  program.addCommand(envCommand);
68
+ program.addCommand(statusCommand);
69
+ program.addCommand(infoCommand);
70
+ program.addCommand(historyCommand);
71
+ // Triggers & blueprints
72
+ program.addCommand(triggersCommand);
73
+ program.addCommand(blueprintCommand);
44
74
  // Discovery
45
75
  program.addCommand(templatesCommand);
46
- program.parse();
76
+ // Utilities
77
+ program.addCommand(openCommand);
78
+ program.addCommand(guideCommand);
79
+ // Make the programmatic contract discoverable from the first thing an agent
80
+ // runs (`maritime --help`), and point to the one-shot machine manifest.
81
+ program.addHelpText('after', `
82
+ For scripts & AI agents:
83
+ Auth set MARITIME_TOKEN (mk_… key from \`maritime keys create\`)
84
+ Output pass --json — results on stdout, errors as JSON on stderr
85
+ Exit code 0 ok · 1 error · 2 auth · 3 not-found · 4 usage
86
+ Talk maritime chat <agent> "..." (or pipe the message via stdin)
87
+ Full spec maritime guide (human) · maritime guide --json (manifest)`);
88
+ // Interactive mode: launch when no args in a TTY
89
+ if (process.argv.length <= 2 && process.stdin.isTTY) {
90
+ import('./interactive.js').then(async ({ runInteractive }) => {
91
+ try {
92
+ const args = await runInteractive();
93
+ // Re-parse with selected command
94
+ process.argv = [process.argv[0], process.argv[1], ...args];
95
+ await program.parseAsync();
96
+ }
97
+ catch {
98
+ // User cancelled (Ctrl+C)
99
+ process.exit(130);
100
+ }
101
+ finally {
102
+ printUpdateNotice(pkg.version);
103
+ }
104
+ });
105
+ }
106
+ else {
107
+ program
108
+ .parseAsync()
109
+ .then(() => {
110
+ printUpdateNotice(pkg.version);
111
+ })
112
+ .catch((error) => {
113
+ // Safety net: any error that escapes a command handler becomes a
114
+ // structured failure rather than an uncaught stack trace.
115
+ handleError(error);
116
+ });
117
+ }
@@ -0,0 +1 @@
1
+ export declare function runInteractive(): Promise<string[]>;
@@ -0,0 +1,68 @@
1
+ import { select } from '@inquirer/prompts';
2
+ import chalk from 'chalk';
3
+ import { authGet } from './api.js';
4
+ const COMMANDS = [
5
+ { name: 'list', value: 'list', description: 'List your agents', needsAgent: false },
6
+ { name: 'create', value: 'create', description: 'Create a new agent', needsAgent: false },
7
+ { name: 'status', value: 'status', description: 'Show agent status', needsAgent: true },
8
+ { name: 'info', value: 'info', description: 'Show full agent details', needsAgent: true },
9
+ { name: 'logs', value: 'logs', description: 'View agent logs', needsAgent: true },
10
+ { name: 'deploy', value: 'deploy', description: 'Deploy an agent', needsAgent: true },
11
+ { name: 'start', value: 'start', description: 'Start an agent', needsAgent: true },
12
+ { name: 'stop', value: 'stop', description: 'Stop an agent', needsAgent: true },
13
+ { name: 'sleep', value: 'sleep', description: 'Put agent to sleep', needsAgent: true },
14
+ { name: 'restart', value: 'restart', description: 'Restart an agent', needsAgent: true },
15
+ { name: 'env', value: 'env', description: 'Manage environment variables', needsAgent: false },
16
+ { name: 'triggers', value: 'triggers', description: 'Manage triggers', needsAgent: false },
17
+ { name: 'templates', value: 'templates', description: 'Browse templates', needsAgent: false },
18
+ { name: 'history', value: 'history', description: 'View deploy history', needsAgent: true },
19
+ { name: 'blueprint', value: 'blueprint', description: 'Manage blueprints', needsAgent: false },
20
+ { name: 'scale', value: 'scale', description: 'Change agent tier', needsAgent: true },
21
+ { name: 'open', value: 'open', description: 'Open agent in browser', needsAgent: true },
22
+ { name: 'whoami', value: 'whoami', description: 'Show current user', needsAgent: false },
23
+ { name: 'logout', value: 'logout', description: 'Log out', needsAgent: false },
24
+ ];
25
+ export async function runInteractive() {
26
+ console.log(chalk.hex('#8B5CF6')('\n Maritime') + chalk.dim(' — interactive mode\n'));
27
+ const command = await select({
28
+ message: 'What would you like to do?',
29
+ choices: COMMANDS.map((c) => ({
30
+ name: `${c.name.padEnd(12)} ${chalk.dim(c.description)}`,
31
+ value: c.value,
32
+ })),
33
+ });
34
+ const chosen = COMMANDS.find((c) => c.value === command);
35
+ if (!chosen?.needsAgent) {
36
+ return [command];
37
+ }
38
+ // For agent-targeting commands, show agent picker
39
+ try {
40
+ const agents = await authGet('/api/agents');
41
+ if (agents.length === 0) {
42
+ console.log(chalk.yellow('No agents found.') + ' Run `maritime create` first.');
43
+ return [command];
44
+ }
45
+ const agentName = await select({
46
+ message: 'Select an agent:',
47
+ choices: agents.map((a) => ({
48
+ name: `${a.name.padEnd(24)} ${statusBadge(a.status)}`,
49
+ value: a.name,
50
+ })),
51
+ });
52
+ return [command, agentName];
53
+ }
54
+ catch {
55
+ // If auth fails, run command without agent (it will show auth error)
56
+ return [command];
57
+ }
58
+ }
59
+ function statusBadge(status) {
60
+ switch (status) {
61
+ case 'active': return chalk.green(status);
62
+ case 'sleeping': return chalk.blue(status);
63
+ case 'deploying': return chalk.yellow(status);
64
+ case 'error': return chalk.red(status);
65
+ case 'stopped': return chalk.gray(status);
66
+ default: return status;
67
+ }
68
+ }