maritime-cli 1.1.0 → 1.3.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.
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Project context — the Vercel/Railway "link a directory to a project" model,
3
+ * applied to agents.
4
+ *
5
+ * .maritime/project.json the LINK: which agent this directory operates on.
6
+ * Machine-local, git-ignored. Written by `link`/`init`.
7
+ * maritime.json the CONFIG: the source-of-truth description of the
8
+ * agent (name, template/framework, persona, env keys,
9
+ * tier). Committed to the repo; `deploy` reconciles
10
+ * the remote agent to it.
11
+ *
12
+ * Both are discovered by walking up from the cwd, so commands work from any
13
+ * subdirectory of a linked project — just like `git`.
14
+ */
15
+ import { existsSync, readFileSync, writeFileSync, mkdirSync, appendFileSync, } from 'node:fs';
16
+ import { dirname, join, resolve } from 'node:path';
17
+ const LINK_DIR = '.maritime';
18
+ const LINK_FILE = 'project.json';
19
+ const CONFIG_FILE = 'maritime.json';
20
+ // ---------------------------------------------------------------------------
21
+ // Generic upward-walk lookup
22
+ // ---------------------------------------------------------------------------
23
+ function findUp(relPath, start = process.cwd()) {
24
+ let dir = resolve(start);
25
+ // eslint-disable-next-line no-constant-condition
26
+ while (true) {
27
+ const candidate = join(dir, relPath);
28
+ if (existsSync(candidate))
29
+ return candidate;
30
+ const parent = dirname(dir);
31
+ if (parent === dir)
32
+ return null;
33
+ dir = parent;
34
+ }
35
+ }
36
+ // ---------------------------------------------------------------------------
37
+ // Link (.maritime/project.json)
38
+ // ---------------------------------------------------------------------------
39
+ export function findLinkPath(start = process.cwd()) {
40
+ return findUp(join(LINK_DIR, LINK_FILE), start);
41
+ }
42
+ export function getLink() {
43
+ const p = findLinkPath();
44
+ if (!p)
45
+ return null;
46
+ try {
47
+ const parsed = JSON.parse(readFileSync(p, 'utf-8'));
48
+ return parsed.agentId ? parsed : null;
49
+ }
50
+ catch {
51
+ return null;
52
+ }
53
+ }
54
+ export function getLinkedAgentId() {
55
+ return getLink()?.agentId ?? null;
56
+ }
57
+ /** Persist the link for `dir`, and git-ignore `.maritime/` so it stays local. */
58
+ export function writeLink(link, dir = process.cwd()) {
59
+ const linkDir = join(dir, LINK_DIR);
60
+ mkdirSync(linkDir, { recursive: true });
61
+ const p = join(linkDir, LINK_FILE);
62
+ writeFileSync(p, JSON.stringify(link, null, 2) + '\n');
63
+ ensureGitignored(LINK_DIR, dir);
64
+ return p;
65
+ }
66
+ // ---------------------------------------------------------------------------
67
+ // Config (maritime.json)
68
+ // ---------------------------------------------------------------------------
69
+ export function findConfigPath(start = process.cwd()) {
70
+ return findUp(CONFIG_FILE, start);
71
+ }
72
+ export function getConfig() {
73
+ const p = findConfigPath();
74
+ if (!p)
75
+ return null;
76
+ try {
77
+ return JSON.parse(readFileSync(p, 'utf-8'));
78
+ }
79
+ catch {
80
+ return null;
81
+ }
82
+ }
83
+ export function configExists(dir = process.cwd()) {
84
+ return existsSync(join(dir, CONFIG_FILE));
85
+ }
86
+ export function writeConfig(cfg, dir = process.cwd()) {
87
+ const p = join(dir, CONFIG_FILE);
88
+ writeFileSync(p, JSON.stringify(cfg, null, 2) + '\n');
89
+ return p;
90
+ }
91
+ export const CONFIG_FILENAME = CONFIG_FILE;
92
+ // ---------------------------------------------------------------------------
93
+ // Helpers
94
+ // ---------------------------------------------------------------------------
95
+ function ensureGitignored(entry, dir) {
96
+ const gi = join(dir, '.gitignore');
97
+ try {
98
+ const current = existsSync(gi) ? readFileSync(gi, 'utf-8') : '';
99
+ const present = current
100
+ .split('\n')
101
+ .some((l) => l.trim() === entry || l.trim() === `${entry}/`);
102
+ if (!present) {
103
+ const prefix = current && !current.endsWith('\n') ? '\n' : '';
104
+ appendFileSync(gi, `${prefix}${entry}\n`);
105
+ }
106
+ }
107
+ catch {
108
+ // Best-effort; never block on .gitignore.
109
+ }
110
+ }
package/dist/index.js CHANGED
@@ -31,6 +31,9 @@ import { scaleCommand } from './commands/scale.js';
31
31
  import { sleepCommand } from './commands/sleep.js';
32
32
  import { checkForUpdates, printUpdateNotice } from './version-check.js';
33
33
  import { guideCommand } from './commands/guide.js';
34
+ import { initCommand } from './commands/init.js';
35
+ import { linkCommand } from './commands/link.js';
36
+ import { getLink } from './context.js';
34
37
  import { handleError } from './output.js';
35
38
  const __dirname = dirname(fileURLToPath(import.meta.url));
36
39
  const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'));
@@ -43,50 +46,74 @@ program
43
46
  .version(pkg.version)
44
47
  .option('--json', 'Output raw JSON instead of formatted tables')
45
48
  .option('--verbose', 'Show detailed request/response info');
49
+ // The lean surface — what shows in `maritime --help`. Everything a human or an
50
+ // AI agent needs on the happy path: authenticate, create, deploy, talk, observe.
51
+ const HIDDEN = { hidden: true };
46
52
  // Auth
47
53
  program.addCommand(loginCommand);
48
- program.addCommand(signupCommand);
49
54
  program.addCommand(logoutCommand);
50
55
  program.addCommand(whoamiCommand);
51
56
  program.addCommand(keysCommand);
52
- // Agent management
57
+ // Project — link a directory to an agent (the Vercel/Railway model)
58
+ program.addCommand(initCommand);
59
+ program.addCommand(linkCommand);
60
+ // Agent lifecycle
53
61
  program.addCommand(createCommand);
54
- program.addCommand(listCommand);
55
62
  program.addCommand(deployCommand);
56
- program.addCommand(startCommand);
57
- program.addCommand(stopCommand);
58
- program.addCommand(restartCommand);
63
+ program.addCommand(listCommand);
59
64
  program.addCommand(deleteCommand);
60
- program.addCommand(sleepCommand);
61
- program.addCommand(scaleCommand);
62
65
  // Interaction
63
66
  program.addCommand(chatCommand);
64
- program.addCommand(execCommand);
65
67
  // Observability
66
68
  program.addCommand(logsCommand);
67
- program.addCommand(envCommand);
68
69
  program.addCommand(statusCommand);
69
- program.addCommand(infoCommand);
70
- program.addCommand(historyCommand);
71
- // Triggers & blueprints
72
- program.addCommand(triggersCommand);
73
- program.addCommand(blueprintCommand);
74
- // Discovery
75
- program.addCommand(templatesCommand);
76
- // Utilities
77
- program.addCommand(openCommand);
70
+ program.addCommand(envCommand);
71
+ // Machine manifest (for agents/scripts driving the CLI)
78
72
  program.addCommand(guideCommand);
73
+ // --- Hidden: still fully functional, just off the main --help to keep the
74
+ // surface small. Lifecycle is mostly automatic (idle-sleep + auto-wake on
75
+ // chat), so these are ops/debug + power-user/reseller tools, not the happy
76
+ // path. They still work exactly as before; `maritime <cmd> --help` shows them. ---
77
+ program.addCommand(signupCommand, HIDDEN);
78
+ program.addCommand(startCommand, HIDDEN);
79
+ program.addCommand(stopCommand, HIDDEN);
80
+ program.addCommand(restartCommand, HIDDEN);
81
+ program.addCommand(sleepCommand, HIDDEN);
82
+ program.addCommand(scaleCommand, HIDDEN);
83
+ program.addCommand(execCommand, HIDDEN);
84
+ program.addCommand(infoCommand, HIDDEN);
85
+ program.addCommand(historyCommand, HIDDEN);
86
+ program.addCommand(triggersCommand, HIDDEN);
87
+ program.addCommand(blueprintCommand, HIDDEN);
88
+ program.addCommand(templatesCommand, HIDDEN);
89
+ program.addCommand(openCommand, HIDDEN);
79
90
  // Make the programmatic contract discoverable from the first thing an agent
80
91
  // runs (`maritime --help`), and point to the one-shot machine manifest.
81
92
  program.addHelpText('after', `
93
+ Quickstart (a directory is an agent):
94
+ maritime init my-agent create + link this folder to an agent
95
+ maritime chat "hello" talk to the linked agent (no name needed)
96
+ maritime deploy push maritime.json changes (persona, tier)
97
+ maritime logs · status · env · open all act on the linked agent
98
+
82
99
  For scripts & AI agents:
83
100
  Auth set MARITIME_TOKEN (mk_… key from \`maritime keys create\`)
84
101
  Output pass --json — results on stdout, errors as JSON on stderr
85
102
  Exit code 0 ok · 1 error · 2 auth · 3 not-found · 4 usage
86
103
  Talk maritime chat <agent> "..." (or pipe the message via stdin)
87
104
  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) {
105
+ const noArgs = process.argv.length <= 2;
106
+ // In a linked directory, the bare `maritime` shows the linked agent's status
107
+ // (the Vercel/Railway "context-aware default"). Outside one, fall back to the
108
+ // interactive picker in a TTY.
109
+ if (noArgs && getLink()) {
110
+ process.argv = [process.argv[0], process.argv[1], 'status'];
111
+ program
112
+ .parseAsync()
113
+ .then(() => printUpdateNotice(pkg.version))
114
+ .catch((error) => handleError(error));
115
+ }
116
+ else if (noArgs && process.stdin.isTTY) {
90
117
  import('./interactive.js').then(async ({ runInteractive }) => {
91
118
  try {
92
119
  const args = await runInteractive();
package/dist/resolve.d.ts CHANGED
@@ -6,4 +6,12 @@ export interface AgentSummary {
6
6
  tier?: string;
7
7
  createdAt?: string;
8
8
  }
9
- export declare function resolveAgent(nameOrId: string): Promise<AgentSummary>;
9
+ /**
10
+ * Resolve an agent for a command.
11
+ *
12
+ * - With a name/ID: exact-name match first, then unique ID-prefix match.
13
+ * - Without one: fall back to the agent this directory is linked to
14
+ * (`.maritime/project.json`), so `maritime logs`, `maritime chat "…"`, etc.
15
+ * "just work" in a linked project — the Vercel/Railway model.
16
+ */
17
+ export declare function resolveAgent(nameOrId?: string): Promise<AgentSummary>;
package/dist/resolve.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { authGet } from './api.js';
2
2
  import { fail, EXIT } from './output.js';
3
+ import { getLink } from './context.js';
3
4
  // Simple in-memory cache for the full agent list (5-second TTL)
4
5
  let cachedAgents = null;
5
6
  let cacheTime = 0;
@@ -13,7 +14,18 @@ async function fetchAllAgents() {
13
14
  cacheTime = now;
14
15
  return cachedAgents;
15
16
  }
17
+ /**
18
+ * Resolve an agent for a command.
19
+ *
20
+ * - With a name/ID: exact-name match first, then unique ID-prefix match.
21
+ * - Without one: fall back to the agent this directory is linked to
22
+ * (`.maritime/project.json`), so `maritime logs`, `maritime chat "…"`, etc.
23
+ * "just work" in a linked project — the Vercel/Railway model.
24
+ */
16
25
  export async function resolveAgent(nameOrId) {
26
+ if (!nameOrId || !nameOrId.trim()) {
27
+ return resolveLinkedAgent();
28
+ }
17
29
  // 1. Try server-side exact name match first (single API call, no full list)
18
30
  const byName = await authGet(`/api/agents?name=${encodeURIComponent(nameOrId)}`);
19
31
  if (byName.length === 1)
@@ -30,3 +42,18 @@ export async function resolveAgent(nameOrId) {
30
42
  }
31
43
  fail(`Agent "${nameOrId}" not found.`, { code: 'not_found', exitCode: EXIT.NOT_FOUND });
32
44
  }
45
+ /** The agent linked to the current directory, or a helpful error if none. */
46
+ function resolveLinkedAgent() {
47
+ const link = getLink();
48
+ if (!link) {
49
+ fail("No agent given and this directory isn't linked. Pass an agent name, or run `maritime link` / `maritime init`.", { code: 'no_agent', exitCode: EXIT.USAGE });
50
+ }
51
+ // Return straight from the link file — no API round-trip. Downstream calls
52
+ // that hit the agent will surface a clear 404 if it was deleted.
53
+ return {
54
+ id: link.agentId,
55
+ name: link.name ?? link.agentId,
56
+ status: 'unknown',
57
+ framework: 'unknown',
58
+ };
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maritime-cli",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Maritime CLI - Deploy and talk to AI agents from your terminal",
5
5
  "type": "module",
6
6
  "license": "MIT",