maritime-cli 2.0.1 → 2.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.
package/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # maritime-cli
2
2
 
3
- The Maritime command line client. This package ships the `maritime` binary
4
- for every supported platform and unpacks the one for yours at install time,
5
- after checking its SHA-256.
3
+ The Maritime command line client. This package holds the `maritime` launcher.
4
+ npm installs the binary for your platform from one of its optional
5
+ dependencies, `@maritimesh/cli-<platform>-<arch>`, so an install downloads one
6
+ binary and no other platform's.
6
7
 
7
8
  ```bash
8
9
  npm i -g maritime-cli
package/bin/maritime.js CHANGED
@@ -1,28 +1,35 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict'
3
- // Runs the Maritime CLI binary that install.js placed under vendor/, passing
4
- // every argument through and exiting with the binary's status. When the
5
- // binary is missing, for example after an install with --ignore-scripts, it
6
- // is downloaded first.
3
+ // Runs the maritime binary from the platform package npm installed as an
4
+ // optional dependency, passing every argument through and exiting with the
5
+ // binary's status.
7
6
 
8
7
  const { spawn } = require('node:child_process')
9
- const fs = require('node:fs')
10
- const { install, binaryPath } = require('../install.js')
8
+ const { packageName, binaryName } = require('../platform.js')
11
9
 
12
10
  const SIGNALS = ['SIGINT', 'SIGTERM', 'SIGHUP']
13
11
  const EXIT_ON_SIGNAL = 128
14
12
 
15
- async function main() {
16
- const bin = binaryPath()
17
- if (!fs.existsSync(bin)) {
18
- await install()
13
+ /** Returns the installed binary path, or throws a message that says what to do. */
14
+ function binaryPath() {
15
+ const name = packageName(process.platform, process.arch)
16
+ if (name === null) {
17
+ throw new Error(`no binary for ${process.platform}/${process.arch}`)
19
18
  }
20
- const child = spawn(bin, process.argv.slice(2), { stdio: 'inherit', windowsHide: true })
19
+ try {
20
+ return require.resolve(`${name}/bin/${binaryName(process.platform)}`)
21
+ } catch {
22
+ throw new Error(`${name} is not installed. Reinstall maritime-cli without --omit=optional.`)
23
+ }
24
+ }
25
+
26
+ function main() {
27
+ const child = spawn(binaryPath(), process.argv.slice(2), { stdio: 'inherit', windowsHide: true })
21
28
  for (const signal of SIGNALS) {
22
29
  process.on(signal, () => child.kill(signal))
23
30
  }
24
31
  child.on('error', (error) => {
25
- console.error(`maritime-cli: cannot run ${bin}: ${error.message}`)
32
+ console.error(`maritime-cli: cannot run the binary: ${error.message}`)
26
33
  process.exit(1)
27
34
  })
28
35
  child.on('exit', (code, signal) => {
@@ -34,7 +41,9 @@ async function main() {
34
41
  })
35
42
  }
36
43
 
37
- main().catch((error) => {
44
+ try {
45
+ main()
46
+ } catch (error) {
38
47
  console.error(`maritime-cli: ${error.message}`)
39
48
  process.exit(1)
40
- })
49
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "maritime-cli",
3
- "version": "2.0.1",
3
+ "version": "2.3.0",
4
4
  "description": "Maritime command line client: provision, operate, and inspect AI agents on maritime.sh.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/maritime-sh/maritime.git",
8
+ "url": "git+https://github.com/maritime-sh/maritime.git",
9
9
  "directory": "cli/npm"
10
10
  },
11
11
  "homepage": "https://maritime.sh",
@@ -14,12 +14,16 @@
14
14
  },
15
15
  "files": [
16
16
  "bin",
17
- "install.js",
18
- "archives",
17
+ "platform.js",
19
18
  "README.md"
20
19
  ],
21
- "scripts": {
22
- "postinstall": "node install.js"
20
+ "optionalDependencies": {
21
+ "@maritimesh/cli-darwin-arm64": "2.3.0",
22
+ "@maritimesh/cli-darwin-x64": "2.3.0",
23
+ "@maritimesh/cli-linux-arm64": "2.3.0",
24
+ "@maritimesh/cli-linux-x64": "2.3.0",
25
+ "@maritimesh/cli-win32-arm64": "2.3.0",
26
+ "@maritimesh/cli-win32-x64": "2.3.0"
23
27
  },
24
28
  "engines": {
25
29
  "node": ">=18"
package/platform.js ADDED
@@ -0,0 +1,31 @@
1
+ 'use strict'
2
+ // The per-platform packages that hold the maritime binary, one table shared
3
+ // by bin/maritime.js, which resolves the one for this machine, and by
4
+ // platform/make-packages.js, which builds all of them from the release
5
+ // archives. Keys are Node's process.platform and process.arch. The platform
6
+ // packages are scoped (NPM_SCOPE): npm refused the unscoped
7
+ // maritime-cli-win32-x64 as spam.
8
+
9
+ const NPM_SCOPE = '@maritimesh'
10
+
11
+ const PLATFORMS = {
12
+ 'darwin-arm64': { goos: 'darwin', goarch: 'arm64' },
13
+ 'darwin-x64': { goos: 'darwin', goarch: 'amd64' },
14
+ 'linux-arm64': { goos: 'linux', goarch: 'arm64' },
15
+ 'linux-x64': { goos: 'linux', goarch: 'amd64' },
16
+ 'win32-arm64': { goos: 'windows', goarch: 'arm64' },
17
+ 'win32-x64': { goos: 'windows', goarch: 'amd64' },
18
+ }
19
+
20
+ /** Returns the platform package name for platform/arch, or null when unsupported. */
21
+ function packageName(platform, arch) {
22
+ const key = `${platform}-${arch}`
23
+ return PLATFORMS[key] ? `${NPM_SCOPE}/cli-${key}` : null
24
+ }
25
+
26
+ /** Returns the binary file name inside a platform package. */
27
+ function binaryName(platform) {
28
+ return platform === 'win32' ? 'maritime.exe' : 'maritime'
29
+ }
30
+
31
+ module.exports = { NPM_SCOPE, PLATFORMS, packageName, binaryName }
@@ -1,6 +0,0 @@
1
- db571b75258dcc13f10deee1fcb2b0d0338ba3d08213b69c26cce783eb313830 maritime_2.0.1_darwin_amd64.tar.gz
2
- 1f6b25fcfe5e5771d3f40bee2ef00a6ff11fe654224d002134d6befd4607ea77 maritime_2.0.1_darwin_arm64.tar.gz
3
- c41a060161f5bdb20b58af5feff7098da69187b9c03b83f909c300ab98797efc maritime_2.0.1_linux_amd64.tar.gz
4
- 53eb11396800f22b41486291fb8874eb9755cbdc40c7a5802347789b4c606719 maritime_2.0.1_linux_arm64.tar.gz
5
- f58e42877b03dbc05cfa053af1db8a6ea9fd492d78cc7e6faea3b5c924f12ea8 maritime_2.0.1_windows_amd64.zip
6
- 6a913ff1ff4d3352da061fbdcfc38699c975bbaa3aac04abb4a362951bfd6bf3 maritime_2.0.1_windows_arm64.zip
package/install.js DELETED
@@ -1,131 +0,0 @@
1
- 'use strict'
2
- // Unpacks the Maritime CLI binary for this platform next to this file.
3
- //
4
- // The package ships the release archives for every platform under archives/
5
- // together with their checksums.txt, so an install needs no network. When a
6
- // bundled archive is missing, the archive is downloaded from
7
- // MARITIME_CLI_DOWNLOAD_BASE, or from the GitHub release of this version.
8
- // Either way the SHA-256 is verified before anything is unpacked.
9
- //
10
- // Runs as the package's postinstall step. Running it again is safe: an
11
- // existing binary of the right version is kept.
12
-
13
- const { createHash } = require('node:crypto')
14
- const fs = require('node:fs')
15
- const os = require('node:os')
16
- const path = require('node:path')
17
- const { execFileSync } = require('node:child_process')
18
-
19
- const pkg = require('./package.json')
20
- const VERSION = pkg.version
21
- const RELEASE_TAG = `cli-v${VERSION}`
22
- const DEFAULT_BASE = `https://github.com/maritime-sh/maritime/releases/download/${RELEASE_TAG}`
23
- const VENDOR_DIR = path.join(__dirname, 'vendor')
24
- const ARCHIVE_DIR = path.join(__dirname, 'archives')
25
- const MARKER = path.join(VENDOR_DIR, 'version')
26
- const CHECKSUMS = 'checksums.txt'
27
- const SHA256_HEX_LENGTH = 64
28
- const DOWNLOAD_TIMEOUT_MS = 120000
29
-
30
- const PLATFORMS = { darwin: 'darwin', linux: 'linux', win32: 'windows' }
31
- const ARCHES = { x64: 'amd64', arm64: 'arm64' }
32
-
33
- /** Returns the archive name for this machine, or throws for an unsupported one. */
34
- function archiveName() {
35
- const goos = PLATFORMS[process.platform]
36
- const goarch = ARCHES[process.arch]
37
- if (!goos || !goarch) {
38
- throw new Error(`maritime-cli has no binary for ${process.platform}/${process.arch}`)
39
- }
40
- const ext = goos === 'windows' ? 'zip' : 'tar.gz'
41
- return `maritime_${VERSION}_${goos}_${goarch}.${ext}`
42
- }
43
-
44
- /** Returns the installed binary path for this machine. */
45
- function binaryPath() {
46
- return path.join(VENDOR_DIR, process.platform === 'win32' ? 'maritime.exe' : 'maritime')
47
- }
48
-
49
- /** Returns the bundled file, or fetches it from base when it is not bundled. */
50
- async function obtain(base, name) {
51
- const bundled = path.join(ARCHIVE_DIR, name)
52
- if (fs.existsSync(bundled)) {
53
- return fs.readFileSync(bundled)
54
- }
55
- return download(`${base}/${name}`)
56
- }
57
-
58
- /** Fetches url and returns its body as a Buffer. */
59
- async function download(url) {
60
- const controller = new AbortController()
61
- const timer = setTimeout(() => controller.abort(), DOWNLOAD_TIMEOUT_MS)
62
- try {
63
- const response = await fetch(url, { redirect: 'follow', signal: controller.signal })
64
- if (!response.ok) {
65
- throw new Error(`${url}: HTTP ${response.status}`)
66
- }
67
- return Buffer.from(await response.arrayBuffer())
68
- } finally {
69
- clearTimeout(timer)
70
- }
71
- }
72
-
73
- /** Returns the expected SHA-256 of name from the checksums file text. */
74
- function expectedChecksum(checksums, name) {
75
- for (const line of checksums.split('\n')) {
76
- const [hash, file] = line.trim().split(/\s+/)
77
- if (file === name && hash && hash.length === SHA256_HEX_LENGTH) {
78
- return hash
79
- }
80
- }
81
- throw new Error(`${CHECKSUMS} has no entry for ${name}`)
82
- }
83
-
84
- /** Unpacks archive (tar.gz or zip) into dir with the system tar. */
85
- function extract(archive, dir) {
86
- // bsdtar on macOS and Windows 10+, GNU tar on Linux; all read both formats.
87
- execFileSync('tar', ['-xf', archive, '-C', dir], { stdio: 'inherit' })
88
- }
89
-
90
- async function install() {
91
- const name = archiveName()
92
- const bin = binaryPath()
93
- if (fs.existsSync(bin) && fs.existsSync(MARKER) && fs.readFileSync(MARKER, 'utf8').trim() === VERSION) {
94
- return
95
- }
96
- const base = (process.env.MARITIME_CLI_DOWNLOAD_BASE || DEFAULT_BASE).replace(/\/+$/, '')
97
- const [archive, checksums] = await Promise.all([
98
- obtain(base, name),
99
- obtain(base, CHECKSUMS),
100
- ])
101
- const actual = createHash('sha256').update(archive).digest('hex')
102
- const expected = expectedChecksum(checksums.toString('utf8'), name)
103
- if (actual !== expected) {
104
- throw new Error(`${name}: SHA-256 ${actual} does not match ${CHECKSUMS} (${expected})`)
105
- }
106
- fs.rmSync(VENDOR_DIR, { recursive: true, force: true })
107
- fs.mkdirSync(VENDOR_DIR, { recursive: true })
108
- const tmp = path.join(os.tmpdir(), `maritime-cli-${process.pid}-${name}`)
109
- fs.writeFileSync(tmp, archive)
110
- try {
111
- extract(tmp, VENDOR_DIR)
112
- } finally {
113
- fs.rmSync(tmp, { force: true })
114
- }
115
- if (!fs.existsSync(bin)) {
116
- throw new Error(`${name} did not contain ${path.basename(bin)}`)
117
- }
118
- if (process.platform !== 'win32') {
119
- fs.chmodSync(bin, 0o755)
120
- }
121
- fs.writeFileSync(MARKER, `${VERSION}\n`)
122
- }
123
-
124
- module.exports = { install, binaryPath }
125
-
126
- if (require.main === module) {
127
- install().catch((error) => {
128
- console.error(`maritime-cli: ${error.message}`)
129
- process.exit(1)
130
- })
131
- }