maritime-cli 1.9.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 (82) 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 -37
  5. package/AGENTS.md +0 -361
  6. package/SKILL.md +0 -181
  7. package/dist/api.d.ts +0 -30
  8. package/dist/api.js +0 -246
  9. package/dist/bundled.d.ts +0 -11
  10. package/dist/bundled.js +0 -25
  11. package/dist/commands/chat.d.ts +0 -2
  12. package/dist/commands/chat.js +0 -120
  13. package/dist/commands/create.d.ts +0 -2
  14. package/dist/commands/create.js +0 -310
  15. package/dist/commands/delete.d.ts +0 -2
  16. package/dist/commands/delete.js +0 -43
  17. package/dist/commands/deploy.d.ts +0 -2
  18. package/dist/commands/deploy.js +0 -180
  19. package/dist/commands/env.d.ts +0 -2
  20. package/dist/commands/env.js +0 -368
  21. package/dist/commands/exec.d.ts +0 -2
  22. package/dist/commands/exec.js +0 -31
  23. package/dist/commands/guide.d.ts +0 -2
  24. package/dist/commands/guide.js +0 -75
  25. package/dist/commands/history.d.ts +0 -2
  26. package/dist/commands/history.js +0 -56
  27. package/dist/commands/info.d.ts +0 -2
  28. package/dist/commands/info.js +0 -78
  29. package/dist/commands/init.d.ts +0 -2
  30. package/dist/commands/init.js +0 -143
  31. package/dist/commands/keys.d.ts +0 -2
  32. package/dist/commands/keys.js +0 -90
  33. package/dist/commands/link.d.ts +0 -4
  34. package/dist/commands/link.js +0 -65
  35. package/dist/commands/list.d.ts +0 -2
  36. package/dist/commands/list.js +0 -55
  37. package/dist/commands/login.d.ts +0 -2
  38. package/dist/commands/login.js +0 -368
  39. package/dist/commands/logout.d.ts +0 -2
  40. package/dist/commands/logout.js +0 -12
  41. package/dist/commands/logs.d.ts +0 -2
  42. package/dist/commands/logs.js +0 -89
  43. package/dist/commands/message.d.ts +0 -8
  44. package/dist/commands/message.js +0 -75
  45. package/dist/commands/open.d.ts +0 -2
  46. package/dist/commands/open.js +0 -25
  47. package/dist/commands/restart.d.ts +0 -2
  48. package/dist/commands/restart.js +0 -26
  49. package/dist/commands/signup.d.ts +0 -2
  50. package/dist/commands/signup.js +0 -72
  51. package/dist/commands/sleep.d.ts +0 -2
  52. package/dist/commands/sleep.js +0 -22
  53. package/dist/commands/start.d.ts +0 -2
  54. package/dist/commands/start.js +0 -27
  55. package/dist/commands/status.d.ts +0 -2
  56. package/dist/commands/status.js +0 -69
  57. package/dist/commands/stop.d.ts +0 -2
  58. package/dist/commands/stop.js +0 -26
  59. package/dist/commands/templates.d.ts +0 -2
  60. package/dist/commands/templates.js +0 -40
  61. package/dist/commands/triggers.d.ts +0 -2
  62. package/dist/commands/triggers.js +0 -89
  63. package/dist/commands/whoami.d.ts +0 -2
  64. package/dist/commands/whoami.js +0 -76
  65. package/dist/config.d.ts +0 -2
  66. package/dist/config.js +0 -14
  67. package/dist/context.d.ts +0 -39
  68. package/dist/context.js +0 -110
  69. package/dist/index.d.ts +0 -2
  70. package/dist/index.js +0 -186
  71. package/dist/interactive.d.ts +0 -1
  72. package/dist/interactive.js +0 -66
  73. package/dist/output.d.ts +0 -80
  74. package/dist/output.js +0 -176
  75. package/dist/prompt.d.ts +0 -2
  76. package/dist/prompt.js +0 -62
  77. package/dist/resolve.d.ts +0 -16
  78. package/dist/resolve.js +0 -59
  79. package/dist/version-check.d.ts +0 -20
  80. package/dist/version-check.js +0 -81
  81. package/dist/websocket.d.ts +0 -22
  82. package/dist/websocket.js +0 -89
@@ -1,81 +0,0 @@
1
- import chalk from 'chalk';
2
- import { config } from './config.js';
3
- const ONE_DAY = 24 * 60 * 60 * 1000;
4
- /** True when `a` is a strictly newer semver than `b` (numeric x.y.z compare). */
5
- function isNewer(a, b) {
6
- const pa = a.split('.').map((n) => parseInt(n, 10) || 0);
7
- const pb = b.split('.').map((n) => parseInt(n, 10) || 0);
8
- for (let i = 0; i < 3; i++) {
9
- if ((pa[i] || 0) !== (pb[i] || 0))
10
- return (pa[i] || 0) > (pb[i] || 0);
11
- }
12
- return false;
13
- }
14
- // The single in-flight registry request (at most one per day). The
15
- // entrypoint awaits this before finishing so the process never exits with
16
- // the fetch's DNS/TLS work still on the libuv threadpool: that in-flight
17
- // work racing a hard exit was the most common trigger of the Windows
18
- // `uv_async_send during close` assertion, because this check used to run
19
- // unawaited on EVERY command.
20
- let inflight = null;
21
- /**
22
- * Daily check against the npm registry.
23
- *
24
- * Runs at most once per 24h (throttled at ATTEMPT time, not success time,
25
- * so an offline machine doesn't re-fire the request on every command), and
26
- * never in machine/CI contexts where the notice would not be printed
27
- * anyway. Returns immediately; await versionCheckSettled() before exit.
28
- */
29
- export function checkForUpdates(currentVersion) {
30
- // Machine mode / non-interactive: the notice is suppressed there, so the
31
- // network request is pure liability (latency + teardown race).
32
- if (process.argv.includes('--json') || !process.stderr.isTTY || process.env.CI)
33
- return;
34
- const lastCheck = config.get('lastVersionCheck');
35
- if (lastCheck && Date.now() - lastCheck < ONE_DAY)
36
- return;
37
- config.set('lastVersionCheck', Date.now());
38
- inflight = fetch('https://registry.npmjs.org/maritime-cli/latest', {
39
- signal: AbortSignal.timeout(3000),
40
- })
41
- .then((r) => r.json())
42
- .then((data) => {
43
- const latest = data.version;
44
- // Store only genuinely-newer versions, and clear anything stale;
45
- // otherwise an old cached value survives upgrades forever and the
46
- // banner suggests a "downgrade" (the 1.x to 0.2.1 bug).
47
- if (latest && isNewer(latest, currentVersion)) {
48
- config.set('latestVersion', latest);
49
- }
50
- else {
51
- config.delete('latestVersion');
52
- }
53
- })
54
- .catch(() => {
55
- // Silently ignore: this is a best-effort check.
56
- });
57
- }
58
- /**
59
- * Resolves when the (at most one) in-flight update check has settled.
60
- * Bounded by the fetch's own 3s AbortSignal; resolves immediately when no
61
- * check ran this invocation (the usual case, 24h throttle).
62
- */
63
- export function versionCheckSettled() {
64
- return inflight ?? Promise.resolve();
65
- }
66
- /**
67
- * Print update notice if a newer version was found.
68
- * Call at the end of command execution.
69
- */
70
- export function printUpdateNotice(currentVersion) {
71
- // Never emit chatter on stdout in machine mode — it corrupts JSON output.
72
- if (process.argv.includes('--json'))
73
- return;
74
- const latest = config.get('latestVersion');
75
- if (latest && isNewer(latest, currentVersion)) {
76
- console.log(chalk.dim(`\n Update available: ${currentVersion} → ${chalk.bold(latest)}`) +
77
- chalk.dim(' Run ') +
78
- chalk.bold('npm i -g maritime-cli') +
79
- chalk.dim(' to update'));
80
- }
81
- }
@@ -1,22 +0,0 @@
1
- export interface WsOptions {
2
- /** Called for each text message received */
3
- onMessage: (data: string) => void;
4
- /** Called when connection closes cleanly */
5
- onClose?: () => void;
6
- /** Max reconnect attempts on transient failures */
7
- maxReconnects?: number;
8
- }
9
- /**
10
- * Connect to a Maritime WebSocket endpoint with auth token.
11
- * Returns a cleanup function that closes the connection.
12
- *
13
- * Teardown rules (Windows-safe: no handle may outlive the command):
14
- * - a pending reconnect timer is cleared on cleanup;
15
- * - CONNECTING sockets are terminated, not orphaned;
16
- * - a server close with code 1000 is final (the deploy-status endpoint
17
- * closes with 1000 on terminal status): reconnecting would just replay
18
- * the terminal frame and burn the backoff;
19
- * - the SIGINT listener is removed as soon as the connection is done,
20
- * whether via cleanup() or the server ending the stream.
21
- */
22
- export declare function connectWs(path: string, opts: WsOptions): () => void;
package/dist/websocket.js DELETED
@@ -1,89 +0,0 @@
1
- import { WebSocket } from 'ws';
2
- import chalk from 'chalk';
3
- import { getApiUrl, requireAuth } from './api.js';
4
- /**
5
- * Connect to a Maritime WebSocket endpoint with auth token.
6
- * Returns a cleanup function that closes the connection.
7
- *
8
- * Teardown rules (Windows-safe: no handle may outlive the command):
9
- * - a pending reconnect timer is cleared on cleanup;
10
- * - CONNECTING sockets are terminated, not orphaned;
11
- * - a server close with code 1000 is final (the deploy-status endpoint
12
- * closes with 1000 on terminal status): reconnecting would just replay
13
- * the terminal frame and burn the backoff;
14
- * - the SIGINT listener is removed as soon as the connection is done,
15
- * whether via cleanup() or the server ending the stream.
16
- */
17
- export function connectWs(path, opts) {
18
- const token = requireAuth();
19
- const baseUrl = getApiUrl().replace(/^http/, 'ws');
20
- const sep = path.includes('?') ? '&' : '?';
21
- const url = `${baseUrl}${path}${sep}token=${token}`;
22
- const maxReconnects = opts.maxReconnects ?? 2;
23
- let reconnects = 0;
24
- let closed = false;
25
- let finished = false;
26
- let reconnectTimer;
27
- let ws;
28
- function finish() {
29
- if (finished)
30
- return;
31
- finished = true;
32
- process.removeListener('SIGINT', sigHandler);
33
- opts.onClose?.();
34
- }
35
- function connect() {
36
- ws = new WebSocket(url);
37
- ws.on('message', (raw) => {
38
- opts.onMessage(raw.toString());
39
- });
40
- ws.on('close', (code) => {
41
- if (closed || code === 1000) {
42
- finish();
43
- return;
44
- }
45
- if (reconnects < maxReconnects) {
46
- reconnects++;
47
- reconnectTimer = setTimeout(connect, 1000 * reconnects);
48
- }
49
- else {
50
- finish();
51
- }
52
- });
53
- ws.on('error', (err) => {
54
- if (!closed) {
55
- console.error(chalk.dim(`WebSocket error: ${err.message}`));
56
- }
57
- });
58
- }
59
- connect();
60
- // Clean shutdown on SIGINT
61
- const sigHandler = () => {
62
- cleanup();
63
- };
64
- process.on('SIGINT', sigHandler);
65
- function cleanup() {
66
- closed = true;
67
- if (reconnectTimer) {
68
- clearTimeout(reconnectTimer);
69
- reconnectTimer = undefined;
70
- // No socket is open when a reconnect was pending; end the stream now.
71
- finish();
72
- return;
73
- }
74
- if (ws) {
75
- if (ws.readyState === WebSocket.OPEN) {
76
- ws.close();
77
- }
78
- else if (ws.readyState === WebSocket.CONNECTING) {
79
- // close() during the handshake leaves the socket to finish
80
- // connecting in the background; terminate() drops it now.
81
- ws.terminate();
82
- }
83
- else {
84
- finish();
85
- }
86
- }
87
- }
88
- return cleanup;
89
- }