maritime-cli 0.2.1 → 1.2.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 +182 -0
- package/dist/api.d.ts +1 -0
- package/dist/api.js +130 -13
- package/dist/commands/blueprint.d.ts +2 -0
- package/dist/commands/blueprint.js +93 -0
- package/dist/commands/chat.d.ts +2 -0
- package/dist/commands/chat.js +93 -0
- package/dist/commands/create.js +138 -54
- package/dist/commands/delete.js +28 -18
- package/dist/commands/deploy.js +51 -9
- package/dist/commands/env.js +206 -43
- package/dist/commands/exec.d.ts +2 -0
- package/dist/commands/exec.js +28 -0
- package/dist/commands/guide.d.ts +2 -0
- package/dist/commands/guide.js +83 -0
- package/dist/commands/history.d.ts +2 -0
- package/dist/commands/history.js +56 -0
- package/dist/commands/info.d.ts +2 -0
- package/dist/commands/info.js +74 -0
- package/dist/commands/keys.d.ts +2 -0
- package/dist/commands/keys.js +90 -0
- package/dist/commands/list.js +13 -10
- package/dist/commands/login.js +70 -10
- package/dist/commands/logs.js +38 -14
- package/dist/commands/open.d.ts +2 -0
- package/dist/commands/open.js +24 -0
- package/dist/commands/restart.js +13 -11
- package/dist/commands/scale.d.ts +2 -0
- package/dist/commands/scale.js +30 -0
- package/dist/commands/sleep.d.ts +2 -0
- package/dist/commands/sleep.js +23 -0
- package/dist/commands/start.js +14 -11
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +73 -0
- package/dist/commands/stop.js +13 -11
- package/dist/commands/templates.js +11 -9
- package/dist/commands/triggers.d.ts +2 -0
- package/dist/commands/triggers.js +79 -0
- package/dist/commands/whoami.js +65 -24
- package/dist/config.js +8 -0
- package/dist/index.js +86 -10
- package/dist/interactive.d.ts +1 -0
- package/dist/interactive.js +68 -0
- package/dist/output.d.ts +61 -0
- package/dist/output.js +123 -0
- package/dist/resolve.d.ts +2 -3
- package/dist/resolve.js +23 -10
- package/dist/version-check.d.ts +10 -0
- package/dist/version-check.js +43 -0
- package/dist/websocket.d.ts +13 -0
- package/dist/websocket.js +55 -0
- package/package.json +8 -4
package/dist/commands/restart.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import
|
|
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 restartCommand = new Command('restart')
|
|
7
7
|
.description('Restart 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(`Restarting ${chalk.bold(agent.name)}...`).start();
|
|
12
10
|
try {
|
|
13
|
-
await
|
|
11
|
+
const agent = await resolveAgent(agentArg);
|
|
12
|
+
const spinner = await makeSpinner(`Restarting ${chalk.bold(agent.name)}...`);
|
|
13
|
+
try {
|
|
14
|
+
await authPost(`/api/agents/${agent.id}/restart`);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
spinner.fail('Failed to restart agent');
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
14
20
|
spinner.succeed(chalk.green('Restarted ') + chalk.bold(agent.name));
|
|
21
|
+
outputResult({ ok: true, action: 'restart', agentId: agent.id, name: agent.name }, () => { });
|
|
15
22
|
}
|
|
16
23
|
catch (error) {
|
|
17
|
-
|
|
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
|
});
|
|
@@ -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,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
|
+
});
|
package/dist/commands/start.js
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import
|
|
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
|
|
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
|
-
|
|
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,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
|
+
}
|
package/dist/commands/stop.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import
|
|
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
|
|
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
|
-
|
|
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 {
|
|
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(
|
|
20
|
+
chalk.dim('FRAMEWORK'.padEnd(20)) +
|
|
16
21
|
chalk.dim('DESCRIPTION'));
|
|
17
|
-
console.log(chalk.dim(' ' + '\u2500'.repeat(
|
|
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
|
-
|
|
27
|
+
fw.padEnd(20) +
|
|
22
28
|
chalk.dim(t.description || ''));
|
|
23
29
|
}
|
|
24
30
|
console.log();
|
|
25
31
|
}
|
|
26
32
|
catch (error) {
|
|
27
|
-
|
|
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,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);
|
package/dist/commands/whoami.js
CHANGED
|
@@ -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
|
|
17
|
+
.description('Show the current authentication (token source, user, expiry)')
|
|
6
18
|
.action(() => {
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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,29 +19,104 @@ 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');
|
|
46
|
+
// The lean surface — what shows in `maritime --help`. Everything a human or an
|
|
47
|
+
// AI agent needs on the happy path: authenticate, create, deploy, talk, observe.
|
|
48
|
+
const HIDDEN = { hidden: true };
|
|
28
49
|
// Auth
|
|
29
50
|
program.addCommand(loginCommand);
|
|
30
|
-
program.addCommand(signupCommand);
|
|
31
51
|
program.addCommand(logoutCommand);
|
|
32
52
|
program.addCommand(whoamiCommand);
|
|
33
|
-
|
|
53
|
+
program.addCommand(keysCommand);
|
|
54
|
+
// Agent lifecycle
|
|
34
55
|
program.addCommand(createCommand);
|
|
35
|
-
program.addCommand(listCommand);
|
|
36
56
|
program.addCommand(deployCommand);
|
|
37
|
-
program.addCommand(
|
|
38
|
-
program.addCommand(stopCommand);
|
|
39
|
-
program.addCommand(restartCommand);
|
|
57
|
+
program.addCommand(listCommand);
|
|
40
58
|
program.addCommand(deleteCommand);
|
|
59
|
+
// Interaction
|
|
60
|
+
program.addCommand(chatCommand);
|
|
41
61
|
// Observability
|
|
42
62
|
program.addCommand(logsCommand);
|
|
63
|
+
program.addCommand(statusCommand);
|
|
43
64
|
program.addCommand(envCommand);
|
|
44
|
-
//
|
|
45
|
-
program.addCommand(
|
|
46
|
-
|
|
65
|
+
// Machine manifest (for agents/scripts driving the CLI)
|
|
66
|
+
program.addCommand(guideCommand);
|
|
67
|
+
// --- Hidden: still fully functional, just off the main --help to keep the
|
|
68
|
+
// surface small. Lifecycle is mostly automatic (idle-sleep + auto-wake on
|
|
69
|
+
// chat), so these are ops/debug + power-user/reseller tools, not the happy
|
|
70
|
+
// path. They still work exactly as before; `maritime <cmd> --help` shows them. ---
|
|
71
|
+
program.addCommand(signupCommand, HIDDEN);
|
|
72
|
+
program.addCommand(startCommand, HIDDEN);
|
|
73
|
+
program.addCommand(stopCommand, HIDDEN);
|
|
74
|
+
program.addCommand(restartCommand, HIDDEN);
|
|
75
|
+
program.addCommand(sleepCommand, HIDDEN);
|
|
76
|
+
program.addCommand(scaleCommand, HIDDEN);
|
|
77
|
+
program.addCommand(execCommand, HIDDEN);
|
|
78
|
+
program.addCommand(infoCommand, HIDDEN);
|
|
79
|
+
program.addCommand(historyCommand, HIDDEN);
|
|
80
|
+
program.addCommand(triggersCommand, HIDDEN);
|
|
81
|
+
program.addCommand(blueprintCommand, HIDDEN);
|
|
82
|
+
program.addCommand(templatesCommand, HIDDEN);
|
|
83
|
+
program.addCommand(openCommand, HIDDEN);
|
|
84
|
+
// Make the programmatic contract discoverable from the first thing an agent
|
|
85
|
+
// runs (`maritime --help`), and point to the one-shot machine manifest.
|
|
86
|
+
program.addHelpText('after', `
|
|
87
|
+
For scripts & AI agents:
|
|
88
|
+
Auth set MARITIME_TOKEN (mk_… key from \`maritime keys create\`)
|
|
89
|
+
Output pass --json — results on stdout, errors as JSON on stderr
|
|
90
|
+
Exit code 0 ok · 1 error · 2 auth · 3 not-found · 4 usage
|
|
91
|
+
Talk maritime chat <agent> "..." (or pipe the message via stdin)
|
|
92
|
+
Full spec maritime guide (human) · maritime guide --json (manifest)`);
|
|
93
|
+
// Interactive mode: launch when no args in a TTY
|
|
94
|
+
if (process.argv.length <= 2 && process.stdin.isTTY) {
|
|
95
|
+
import('./interactive.js').then(async ({ runInteractive }) => {
|
|
96
|
+
try {
|
|
97
|
+
const args = await runInteractive();
|
|
98
|
+
// Re-parse with selected command
|
|
99
|
+
process.argv = [process.argv[0], process.argv[1], ...args];
|
|
100
|
+
await program.parseAsync();
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// User cancelled (Ctrl+C)
|
|
104
|
+
process.exit(130);
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
printUpdateNotice(pkg.version);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
program
|
|
113
|
+
.parseAsync()
|
|
114
|
+
.then(() => {
|
|
115
|
+
printUpdateNotice(pkg.version);
|
|
116
|
+
})
|
|
117
|
+
.catch((error) => {
|
|
118
|
+
// Safety net: any error that escapes a command handler becomes a
|
|
119
|
+
// structured failure rather than an uncaught stack trace.
|
|
120
|
+
handleError(error);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runInteractive(): Promise<string[]>;
|