maritime-cli 1.8.0 → 2.0.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 (79) hide show
  1. package/README.md +17 -0
  2. package/bin/maritime.js +40 -0
  3. package/install.js +118 -0
  4. package/package.json +22 -36
  5. package/AGENTS.md +0 -309
  6. package/dist/api.d.ts +0 -30
  7. package/dist/api.js +0 -240
  8. package/dist/commands/chat.d.ts +0 -2
  9. package/dist/commands/chat.js +0 -120
  10. package/dist/commands/create.d.ts +0 -2
  11. package/dist/commands/create.js +0 -310
  12. package/dist/commands/delete.d.ts +0 -2
  13. package/dist/commands/delete.js +0 -43
  14. package/dist/commands/deploy.d.ts +0 -2
  15. package/dist/commands/deploy.js +0 -180
  16. package/dist/commands/env.d.ts +0 -2
  17. package/dist/commands/env.js +0 -368
  18. package/dist/commands/exec.d.ts +0 -2
  19. package/dist/commands/exec.js +0 -31
  20. package/dist/commands/guide.d.ts +0 -2
  21. package/dist/commands/guide.js +0 -87
  22. package/dist/commands/history.d.ts +0 -2
  23. package/dist/commands/history.js +0 -56
  24. package/dist/commands/info.d.ts +0 -2
  25. package/dist/commands/info.js +0 -78
  26. package/dist/commands/init.d.ts +0 -2
  27. package/dist/commands/init.js +0 -114
  28. package/dist/commands/keys.d.ts +0 -2
  29. package/dist/commands/keys.js +0 -90
  30. package/dist/commands/link.d.ts +0 -4
  31. package/dist/commands/link.js +0 -65
  32. package/dist/commands/list.d.ts +0 -2
  33. package/dist/commands/list.js +0 -55
  34. package/dist/commands/login.d.ts +0 -2
  35. package/dist/commands/login.js +0 -209
  36. package/dist/commands/logout.d.ts +0 -2
  37. package/dist/commands/logout.js +0 -12
  38. package/dist/commands/logs.d.ts +0 -2
  39. package/dist/commands/logs.js +0 -89
  40. package/dist/commands/message.d.ts +0 -8
  41. package/dist/commands/message.js +0 -75
  42. package/dist/commands/open.d.ts +0 -2
  43. package/dist/commands/open.js +0 -25
  44. package/dist/commands/restart.d.ts +0 -2
  45. package/dist/commands/restart.js +0 -26
  46. package/dist/commands/signup.d.ts +0 -2
  47. package/dist/commands/signup.js +0 -45
  48. package/dist/commands/sleep.d.ts +0 -2
  49. package/dist/commands/sleep.js +0 -22
  50. package/dist/commands/start.d.ts +0 -2
  51. package/dist/commands/start.js +0 -27
  52. package/dist/commands/status.d.ts +0 -2
  53. package/dist/commands/status.js +0 -69
  54. package/dist/commands/stop.d.ts +0 -2
  55. package/dist/commands/stop.js +0 -26
  56. package/dist/commands/templates.d.ts +0 -2
  57. package/dist/commands/templates.js +0 -40
  58. package/dist/commands/triggers.d.ts +0 -2
  59. package/dist/commands/triggers.js +0 -89
  60. package/dist/commands/whoami.d.ts +0 -2
  61. package/dist/commands/whoami.js +0 -76
  62. package/dist/config.d.ts +0 -2
  63. package/dist/config.js +0 -14
  64. package/dist/context.d.ts +0 -39
  65. package/dist/context.js +0 -110
  66. package/dist/index.d.ts +0 -2
  67. package/dist/index.js +0 -186
  68. package/dist/interactive.d.ts +0 -1
  69. package/dist/interactive.js +0 -66
  70. package/dist/output.d.ts +0 -80
  71. package/dist/output.js +0 -176
  72. package/dist/prompt.d.ts +0 -2
  73. package/dist/prompt.js +0 -62
  74. package/dist/resolve.d.ts +0 -16
  75. package/dist/resolve.js +0 -59
  76. package/dist/version-check.d.ts +0 -20
  77. package/dist/version-check.js +0 -81
  78. package/dist/websocket.d.ts +0 -22
  79. package/dist/websocket.js +0 -89
@@ -1,43 +0,0 @@
1
- import { Command } from 'commander';
2
- import chalk from 'chalk';
3
- import { authDelete } from '../api.js';
4
- import { resolveAgent } from '../resolve.js';
5
- import { promptForValue } from '../prompt.js';
6
- import { isJsonMode, outputResult, fail, handleError, makeSpinner, EXIT } from '../output.js';
7
- export const deleteCommand = new Command('delete')
8
- .description('Delete an agent')
9
- .argument('[agent]', 'Agent name or ID (defaults to the linked agent)')
10
- .option('-y, --yes', 'Skip confirmation')
11
- .action(async (agentArg, opts) => {
12
- try {
13
- // Fail fast (before any network/auth) when a non-interactive caller
14
- // (AI agent, CI, --json) omits --yes and couldn't answer a prompt anyway.
15
- if (!opts.yes && (isJsonMode() || !process.stdin.isTTY)) {
16
- fail('Refusing to delete without confirmation. Pass --yes to proceed.', {
17
- code: 'confirmation_required',
18
- exitCode: EXIT.USAGE,
19
- });
20
- }
21
- const agent = await resolveAgent(agentArg);
22
- if (!opts.yes) {
23
- const confirm = await promptForValue(`Type "${agent.name}" to confirm deletion`);
24
- if (confirm !== agent.name) {
25
- console.log(chalk.yellow('Cancelled.'));
26
- return;
27
- }
28
- }
29
- const spinner = await makeSpinner(`Deleting ${chalk.bold(agent.name)}...`);
30
- try {
31
- await authDelete(`/api/agents/${agent.id}`);
32
- }
33
- catch (error) {
34
- spinner.fail('Failed to delete agent');
35
- throw error;
36
- }
37
- spinner.succeed(chalk.green('Deleted ') + chalk.bold(agent.name));
38
- outputResult({ ok: true, action: 'delete', agentId: agent.id, name: agent.name }, () => { });
39
- }
40
- catch (error) {
41
- handleError(error);
42
- }
43
- });
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const deployCommand: Command;
@@ -1,180 +0,0 @@
1
- import { Command } from 'commander';
2
- import chalk from 'chalk';
3
- import { authPost } from '../api.js';
4
- import { resolveAgent } from '../resolve.js';
5
- import { getConfig, getLinkedAgentId, writeLink } from '../context.js';
6
- import { isJsonMode, outputJson, fail, handleError, makeSpinner, EXIT } from '../output.js';
7
- import { connectWs } from '../websocket.js';
8
- // Upper bound for `deploy --wait`. Repo builds + micro-VM ship normally
9
- // finish in 1-3 minutes; 15 minutes covers cold image pulls with margin.
10
- const WAIT_TIMEOUT_MS = 15 * 60 * 1000;
11
- export const deployCommand = new Command('deploy')
12
- .description('Deploy this directory: reconcile the agent to maritime.json, then ship it')
13
- .argument('[agent]', 'Agent name or ID (defaults to the linked agent / maritime.json)')
14
- .option('--source <source>', 'Deploy source (github, docker, template)')
15
- .option('--repo <url>', 'GitHub repository URL')
16
- .option('--image <name>', 'Docker image name')
17
- .option('--branch <branch>', 'Git branch')
18
- .option('-w, --wait', 'Wait for deployment to complete')
19
- .addHelpText('after', `
20
- In a linked project, just run \`maritime deploy\`: it reads maritime.json,
21
- creates the agent if needed, applies the persona, and redeploys.
22
- Explicit sources still work: \`maritime deploy --source github --repo <url>\`.`)
23
- .action(async (agentArg, opts) => {
24
- try {
25
- const config = getConfig();
26
- const explicitSource = Boolean(opts.source || opts.repo || opts.image);
27
- // ── Resolve (or create) the target agent ──────────────────────────
28
- let agent;
29
- if (agentArg) {
30
- agent = await resolveAgent(agentArg);
31
- }
32
- else if (getLinkedAgentId()) {
33
- agent = await resolveAgent(); // linked
34
- }
35
- else if (config?.name) {
36
- // First deploy of a configured-but-not-yet-created project: create it
37
- // from maritime.json and link this directory (the `vercel` first run).
38
- agent = await createFromConfig(config);
39
- writeLink({ agentId: agent.id, name: agent.name });
40
- // create auto-deploys, so we're done unless the user forced a source.
41
- if (!explicitSource) {
42
- 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)));
43
- return;
44
- }
45
- }
46
- else {
47
- fail('Nothing to deploy. Pass an agent, link one (`maritime link`), or add maritime.json (`maritime init`).', { code: 'no_agent', exitCode: EXIT.USAGE });
48
- }
49
- // ── Reconcile the agent to maritime.json (persona) ────────────────
50
- if (config && !explicitSource) {
51
- await reconcile(agent.id, config);
52
- }
53
- // ── Trigger the deployment ────────────────────────────────────────
54
- const body = {
55
- agentId: agent.id,
56
- source: opts.source || 'template',
57
- };
58
- if (opts.repo)
59
- body.repoUrl = opts.repo;
60
- if (opts.image)
61
- body.imageName = opts.image;
62
- if (opts.branch)
63
- body.branch = opts.branch;
64
- // makeSpinner (not raw ora): degrades to static lines on 0-width PTYs —
65
- // raw ora write-storms there (the create/chat bug fixed in 1.5.0).
66
- const spinner = isJsonMode() ? null : await makeSpinner(`Deploying ${chalk.bold(agent.name)}...`);
67
- try {
68
- const deployment = await authPost('/api/deploy', body);
69
- if (!opts.wait) {
70
- spinner?.succeed(chalk.green('Deployment started for ') + chalk.bold(agent.name));
71
- finish(deployment, () => {
72
- console.log(chalk.dim(` Deployment ID: ${deployment.id}`));
73
- console.log(chalk.dim(` Status: ${deployment.status}`));
74
- });
75
- return;
76
- }
77
- // --wait: stream deploy progress via WebSocket. The server closes
78
- // the socket on terminal status; the client-side timeout is the
79
- // last-resort bound so --wait can never hang a script forever.
80
- if (spinner)
81
- spinner.text = `Building ${chalk.bold(agent.name)}...`;
82
- let gatewayUnconfirmed = false;
83
- await new Promise((resolve, reject) => {
84
- let settled = false;
85
- const settle = (fn) => {
86
- if (settled)
87
- return;
88
- settled = true;
89
- clearTimeout(timer);
90
- fn();
91
- };
92
- const timer = setTimeout(() => {
93
- settle(() => {
94
- cleanup();
95
- spinner?.fail('Timed out waiting for the deployment');
96
- reject(new Error(`Timed out after ${WAIT_TIMEOUT_MS / 60000} minutes waiting for the deployment. ` +
97
- 'It may still complete: check `maritime status` / `maritime logs`.'));
98
- });
99
- }, WAIT_TIMEOUT_MS);
100
- const cleanup = connectWs(`/api/deploy/${agent.id}/status`, {
101
- onMessage(data) {
102
- try {
103
- const msg = JSON.parse(data);
104
- if (msg.message && spinner)
105
- spinner.text = msg.message;
106
- if (msg.build_log && /did not confirm ready/i.test(msg.build_log)) {
107
- gatewayUnconfirmed = true;
108
- }
109
- if (msg.status === 'success' || msg.status === 'completed') {
110
- spinner?.succeed(chalk.green('Deployment complete: ') + chalk.bold(agent.name));
111
- settle(() => {
112
- cleanup();
113
- resolve();
114
- });
115
- }
116
- else if (msg.status === 'failed') {
117
- spinner?.fail(chalk.red('Deployment failed: ') + (msg.message || 'unknown error'));
118
- settle(() => {
119
- cleanup();
120
- reject(new Error('Deployment failed'));
121
- });
122
- }
123
- }
124
- catch {
125
- if (spinner)
126
- spinner.text = data.trim();
127
- }
128
- },
129
- onClose() {
130
- settle(resolve);
131
- },
132
- maxReconnects: 3,
133
- });
134
- });
135
- // Deploy success with an unconfirmed gateway means the VM booted but
136
- // the app never answered on $PORT: historically that is a dead-on-
137
- // arrival agent. Say so instead of reporting a clean success.
138
- if (gatewayUnconfirmed && !isJsonMode()) {
139
- console.log(chalk.yellow('Warning:') +
140
- ' the app never confirmed it was listening on $PORT. If the public URL 502s,' +
141
- ' check `maritime logs` for the container output (a crashed process takes the whole micro-VM down).');
142
- }
143
- finish({ ...deployment, gatewayUnconfirmed }, () => { });
144
- }
145
- catch (error) {
146
- spinner?.fail('Deployment failed');
147
- throw error;
148
- }
149
- }
150
- catch (error) {
151
- handleError(error);
152
- }
153
- });
154
- /** Create an agent from a maritime.json config (template/framework + persona). */
155
- async function createFromConfig(config) {
156
- const body = { name: config.name };
157
- if (config.template)
158
- body.templateId = config.template;
159
- if (config.framework)
160
- body.framework = config.framework;
161
- if (config.instructions)
162
- body.instructions = config.instructions;
163
- return authPost('/api/agents', body);
164
- }
165
- /** Apply persona from config to an existing agent (env takes effect on redeploy). */
166
- async function reconcile(agentId, config) {
167
- if (config.instructions) {
168
- await authPost(`/api/agents/${agentId}/env`, {
169
- key: 'MARITIME_INSTRUCTIONS',
170
- value: config.instructions,
171
- is_secret: false,
172
- });
173
- }
174
- }
175
- function finish(json, human) {
176
- if (isJsonMode())
177
- outputJson(json);
178
- else
179
- human();
180
- }
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const envCommand: Command;
@@ -1,368 +0,0 @@
1
- import { readFileSync, writeFileSync, existsSync } from 'node:fs';
2
- import { Command } from 'commander';
3
- import chalk from 'chalk';
4
- import { authGet, authPost, authDelete } from '../api.js';
5
- import { resolveAgent } from '../resolve.js';
6
- import { getLinkedAgentId } from '../context.js';
7
- import { isJsonMode, outputJson, outputResult, fail, handleError, makeSpinner, EXIT } from '../output.js';
8
- /** Parse a single KEY=value token (as passed on the command line). */
9
- function parsePair(pair) {
10
- const eqIdx = pair.indexOf('=');
11
- if (eqIdx <= 0) {
12
- fail(`Invalid format: "${pair}". Use KEY=value.`, { code: 'usage', exitCode: EXIT.USAGE });
13
- }
14
- return { key: pair.slice(0, eqIdx), value: pair.slice(eqIdx + 1) };
15
- }
16
- /**
17
- * Parse a dotenv-style document into key/value pairs. Supports blank lines,
18
- * `#` comments, an optional `export ` prefix, and single/double-quoted values.
19
- */
20
- function parseDotenv(text) {
21
- const pairs = [];
22
- for (const rawLine of text.split('\n')) {
23
- let line = rawLine.trim();
24
- if (!line || line.startsWith('#'))
25
- continue;
26
- if (line.startsWith('export '))
27
- line = line.slice('export '.length).trim();
28
- const eqIdx = line.indexOf('=');
29
- if (eqIdx <= 0)
30
- continue; // skip malformed lines rather than abort the batch
31
- const key = line.slice(0, eqIdx).trim();
32
- let value = line.slice(eqIdx + 1).trim();
33
- // Strip matching surrounding quotes; unescape \n only inside double quotes.
34
- if ((value.startsWith('"') && value.endsWith('"')) ||
35
- (value.startsWith("'") && value.endsWith("'"))) {
36
- const quote = value[0];
37
- value = value.slice(1, -1);
38
- if (quote === '"')
39
- value = value.replace(/\\n/g, '\n');
40
- }
41
- if (key)
42
- pairs.push({ key, value });
43
- }
44
- return pairs;
45
- }
46
- /** Upload a batch of vars sequentially; collect per-key outcomes. */
47
- async function uploadVars(agentId, pairs, isSecret) {
48
- const uploaded = [];
49
- const failed = [];
50
- // The backend warns when a deploy is mid-flight: that boot reads env at
51
- // container start and may miss these values. One warning covers the batch.
52
- let warning = null;
53
- for (const { key, value } of pairs) {
54
- try {
55
- const resp = await authPost(`/api/agents/${agentId}/env`, { key, value, is_secret: isSecret });
56
- if (resp?.warning)
57
- warning = resp.warning;
58
- uploaded.push(key);
59
- }
60
- catch (error) {
61
- failed.push({ key, error: error instanceof Error ? error.message : String(error) });
62
- }
63
- }
64
- return { uploaded, failed, warning };
65
- }
66
- /** Hot-reload env into the running container (falls back to restart server-side). */
67
- async function reloadEnv(agentId) {
68
- await authPost(`/api/agents/${agentId}/reload-env`);
69
- }
70
- export const envCommand = new Command('env')
71
- .description('Manage environment variables')
72
- .addHelpText('after', `
73
- Examples:
74
- maritime env set my-agent OPENAI_API_KEY=sk-… --json
75
- maritime env import my-agent ./prod.env --reload --json
76
- maritime env reload my-agent --json
77
- Secrets are encrypted and marked secret by default; changes apply on next
78
- boot unless you pass --reload.`);
79
- // --- list -----------------------------------------------------------------
80
- envCommand
81
- .command('list [agent]')
82
- .alias('ls')
83
- .description('List environment variables')
84
- .action(async (agentArg) => {
85
- try {
86
- const agent = await resolveAgent(agentArg);
87
- const vars = await authGet(`/api/agents/${agent.id}/env`);
88
- if (isJsonMode()) {
89
- outputJson(vars);
90
- return;
91
- }
92
- if (vars.length === 0) {
93
- console.log(chalk.dim(`\nNo environment variables set for ${chalk.bold(agent.name)}.`));
94
- return;
95
- }
96
- console.log(chalk.dim(`\nEnvironment variables for ${chalk.bold(agent.name)}:\n`));
97
- for (const v of vars) {
98
- const display = v.is_secret ? chalk.dim('••••••••') : v.value;
99
- console.log(` ${chalk.bold(v.key.padEnd(24))} = ${display}`);
100
- }
101
- console.log();
102
- }
103
- catch (error) {
104
- handleError(error);
105
- }
106
- });
107
- // --- set (one or many pairs) ----------------------------------------------
108
- envCommand
109
- .command('set [agent] [pairs...]')
110
- .description('Set one or more environment variables (KEY=value KEY2=value2 …)')
111
- .option('--no-secret', 'Store as plain (non-secret) values')
112
- .option('-r, --reload', 'Hot-reload env into the running container afterward')
113
- .action(async (agentArg, rawPairs, opts) => {
114
- try {
115
- // A leading token without "=" is the agent name; otherwise everything is
116
- // pairs and the agent comes from the linked directory.
117
- const positionals = [agentArg, ...(rawPairs || [])].filter(Boolean);
118
- let target;
119
- let pairTokens;
120
- if (positionals.length > 0 && !positionals[0].includes('=')) {
121
- target = positionals[0];
122
- pairTokens = positionals.slice(1);
123
- }
124
- else {
125
- target = undefined;
126
- pairTokens = positionals;
127
- }
128
- if (pairTokens.length === 0) {
129
- fail('No KEY=value pairs given.', { code: 'usage', exitCode: EXIT.USAGE });
130
- }
131
- const pairs = pairTokens.map(parsePair);
132
- const agent = await resolveAgent(target);
133
- const spinner = await makeSpinner(`Setting ${pairs.length} var${pairs.length === 1 ? '' : 's'} for ${agent.name}...`);
134
- const { uploaded, failed, warning } = await uploadVars(agent.id, pairs, opts.secret);
135
- let reloaded = false;
136
- if (opts.reload && uploaded.length > 0) {
137
- try {
138
- await reloadEnv(agent.id);
139
- reloaded = true;
140
- }
141
- catch {
142
- // Surface reload failure but don't undo the writes.
143
- }
144
- }
145
- if (failed.length > 0)
146
- spinner.fail(`Set ${uploaded.length}, failed ${failed.length}`);
147
- else
148
- spinner.succeed(`Set ${uploaded.length} var${uploaded.length === 1 ? '' : 's'} for ${chalk.bold(agent.name)}`);
149
- outputResult({ ok: failed.length === 0, agentId: agent.id, uploaded, failed, reloaded, warning }, () => {
150
- for (const f of failed)
151
- console.error(chalk.red(` ${f.key}: ${f.error}`));
152
- if (warning)
153
- console.log(chalk.yellow(` ${warning}`));
154
- if (reloaded)
155
- console.log(chalk.dim(' Reloaded into running container.'));
156
- else if (opts.reload)
157
- console.log(chalk.yellow(' Reload skipped or failed; changes land on next boot.'));
158
- });
159
- if (failed.length > 0)
160
- process.exitCode = EXIT.ERROR;
161
- }
162
- catch (error) {
163
- handleError(error);
164
- }
165
- });
166
- // --- import (.env file or stdin) ------------------------------------------
167
- envCommand
168
- .command('import [agent] [file]')
169
- .description('Upload all keys from a .env file (or stdin if file is "-" / omitted)')
170
- .option('--plain', 'Store as plain (non-secret) values')
171
- .option('-r, --reload', 'Hot-reload env into the running container afterward')
172
- .action(async (agentArg, file, opts) => {
173
- try {
174
- // Two positionals always mean `<agent> <file>` — even in a linked dir,
175
- // an explicit agent must win. The single-positional shorthand treats
176
- // the arg as the file (agent = linked).
177
- let target;
178
- let srcFile;
179
- if (file !== undefined) {
180
- target = agentArg;
181
- srcFile = file;
182
- }
183
- else if (getLinkedAgentId()) {
184
- target = undefined;
185
- srcFile = agentArg;
186
- }
187
- else {
188
- target = agentArg;
189
- srcFile = undefined;
190
- }
191
- let text;
192
- if (!srcFile || srcFile === '-') {
193
- if (process.stdin.isTTY) {
194
- fail('No input. Pass a .env file path or pipe one via stdin.', {
195
- code: 'usage',
196
- exitCode: EXIT.USAGE,
197
- });
198
- }
199
- text = readFileSync(0, 'utf8'); // fd 0 = stdin
200
- }
201
- else {
202
- try {
203
- text = readFileSync(srcFile, 'utf8');
204
- }
205
- catch {
206
- fail(`Cannot read file: ${srcFile}`, { code: 'usage', exitCode: EXIT.USAGE });
207
- }
208
- }
209
- const pairs = parseDotenv(text);
210
- if (pairs.length === 0) {
211
- fail('No KEY=value pairs found in input.', { code: 'usage', exitCode: EXIT.USAGE });
212
- }
213
- const agent = await resolveAgent(target);
214
- const spinner = await makeSpinner(`Importing ${pairs.length} vars into ${agent.name}...`);
215
- const { uploaded, failed, warning } = await uploadVars(agent.id, pairs, !opts.plain);
216
- let reloaded = false;
217
- if (opts.reload && uploaded.length > 0) {
218
- try {
219
- await reloadEnv(agent.id);
220
- reloaded = true;
221
- }
222
- catch {
223
- /* keep writes; report below */
224
- }
225
- }
226
- if (failed.length > 0)
227
- spinner.fail(`Imported ${uploaded.length}, failed ${failed.length}`);
228
- else
229
- spinner.succeed(`Imported ${uploaded.length} vars into ${chalk.bold(agent.name)}`);
230
- outputResult({ ok: failed.length === 0, agentId: agent.id, uploaded, failed, reloaded, warning }, () => {
231
- for (const f of failed)
232
- console.error(chalk.red(` ${f.key}: ${f.error}`));
233
- if (warning)
234
- console.log(chalk.yellow(` ${warning}`));
235
- if (reloaded)
236
- console.log(chalk.dim(' Reloaded into running container.'));
237
- else if (opts.reload)
238
- console.log(chalk.yellow(' Reload skipped or failed; changes land on next boot.'));
239
- });
240
- if (failed.length > 0)
241
- process.exitCode = EXIT.ERROR;
242
- }
243
- catch (error) {
244
- handleError(error);
245
- }
246
- });
247
- // --- remove ----------------------------------------------------------------
248
- envCommand
249
- .command('remove [agent] [key]')
250
- .alias('rm')
251
- .description('Remove an environment variable')
252
- .option('-r, --reload', 'Hot-reload env into the running container afterward')
253
- .action(async (agentArg, keyArg, opts) => {
254
- try {
255
- // Two positionals always mean `<agent> <key>` — even in a linked dir,
256
- // an explicit agent must win. Only the single-positional shorthand
257
- // treats the arg as the key (agent = linked).
258
- let target;
259
- let key;
260
- if (keyArg !== undefined) {
261
- target = agentArg;
262
- key = keyArg;
263
- }
264
- else if (getLinkedAgentId()) {
265
- target = undefined;
266
- key = agentArg;
267
- }
268
- else {
269
- target = agentArg;
270
- key = undefined;
271
- }
272
- if (!key) {
273
- fail('No env key given to remove.', { code: 'usage', exitCode: EXIT.USAGE });
274
- }
275
- const agent = await resolveAgent(target);
276
- const spinner = await makeSpinner(`Removing ${key} from ${agent.name}...`);
277
- await authDelete(`/api/agents/${agent.id}/env/${encodeURIComponent(key)}`);
278
- let reloaded = false;
279
- if (opts.reload) {
280
- try {
281
- await reloadEnv(agent.id);
282
- reloaded = true;
283
- }
284
- catch {
285
- /* ignore */
286
- }
287
- }
288
- spinner.succeed(`Removed ${chalk.bold(key)} from ${chalk.bold(agent.name)}`);
289
- outputResult({ ok: true, agentId: agent.id, removed: key, reloaded }, () => { });
290
- }
291
- catch (error) {
292
- handleError(error);
293
- }
294
- });
295
- // --- reload ----------------------------------------------------------------
296
- envCommand
297
- .command('reload [agent]')
298
- .description('Hot-reload env vars into the running container')
299
- .action(async (agentArg) => {
300
- try {
301
- const agent = await resolveAgent(agentArg);
302
- const spinner = await makeSpinner(`Reloading env for ${agent.name}...`);
303
- await reloadEnv(agent.id);
304
- spinner.succeed(`Reloaded env for ${chalk.bold(agent.name)}`);
305
- outputResult({ ok: true, agentId: agent.id, reloaded: true }, () => { });
306
- }
307
- catch (error) {
308
- handleError(error);
309
- }
310
- });
311
- // --- pull ------------------------------------------------------------------
312
- envCommand
313
- .command('pull [agent] [file]')
314
- .description('Write the agent’s env to a local .env file (secret values are masked)')
315
- .option('-f, --force', 'Overwrite the file if it already exists')
316
- .action(async (agentArg, fileArg, opts) => {
317
- try {
318
- // Two positionals always mean `<agent> <file>` — even in a linked dir,
319
- // an explicit agent must win. The single-positional shorthand treats
320
- // the arg as the output file (agent = linked).
321
- let target;
322
- let outFile;
323
- if (fileArg !== undefined) {
324
- target = agentArg;
325
- outFile = fileArg;
326
- }
327
- else if (getLinkedAgentId()) {
328
- target = undefined;
329
- outFile = agentArg || '.env';
330
- }
331
- else {
332
- target = agentArg;
333
- outFile = '.env';
334
- }
335
- const agent = await resolveAgent(target);
336
- const vars = await authGet(`/api/agents/${agent.id}/env`);
337
- const lines = [];
338
- const keys = [];
339
- const secretKeys = [];
340
- for (const v of vars) {
341
- keys.push(v.key);
342
- if (v.is_secret) {
343
- secretKeys.push(v.key);
344
- lines.push(`${v.key}= # secret: value not exported; fill it in`);
345
- }
346
- else {
347
- lines.push(`${v.key}=${v.value}`);
348
- }
349
- }
350
- const text = lines.length ? lines.join('\n') + '\n' : '';
351
- if (existsSync(outFile) && !opts.force) {
352
- fail(`${outFile} already exists. Pass --force to overwrite.`, {
353
- code: 'usage',
354
- exitCode: EXIT.USAGE,
355
- });
356
- }
357
- writeFileSync(outFile, text);
358
- outputResult({ ok: true, agentId: agent.id, file: outFile, keys, secretKeys }, () => {
359
- console.log(chalk.green(`Pulled ${keys.length} var(s) → `) + chalk.bold(outFile));
360
- if (secretKeys.length) {
361
- console.log(chalk.dim(` ${secretKeys.length} secret value(s) masked. Fill in: ${secretKeys.join(', ')}`));
362
- }
363
- });
364
- }
365
- catch (error) {
366
- handleError(error);
367
- }
368
- });
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const execCommand: Command;
@@ -1,31 +0,0 @@
1
- import { Command } from 'commander';
2
- import { authPost } from '../api.js';
3
- import { resolveAgent } from '../resolve.js';
4
- import { isJsonMode, outputJson, handleError } from '../output.js';
5
- export const execCommand = new Command('exec')
6
- .description('Execute a command in an agent container')
7
- .argument('<agent>', 'Agent name or ID')
8
- .argument('<cmd...>', 'Command to run')
9
- .action(async (agentArg, cmd) => {
10
- try {
11
- const agent = await resolveAgent(agentArg);
12
- const result = await authPost(`/api/agents/${agent.id}/exec`, {
13
- command: cmd,
14
- });
15
- if (isJsonMode()) {
16
- outputJson(result);
17
- return;
18
- }
19
- if (result.stdout)
20
- process.stdout.write(result.stdout);
21
- if (result.stderr)
22
- process.stderr.write(result.stderr);
23
- // exitCode + return (NOT process.exit): letting the loop drain flushes
24
- // stdout on Windows pipes and avoids the libuv teardown assertion that
25
- // intermittently killed `maritime exec` right after printing.
26
- process.exitCode = result.exitCode ?? 0;
27
- }
28
- catch (error) {
29
- handleError(error);
30
- }
31
- });
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const guideCommand: Command;