maritime-cli 2.0.0 → 2.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/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # maritime-cli
2
2
 
3
- The Maritime command line client. This package downloads the `maritime`
4
- binary for your platform from the matching GitHub release and verifies its
5
- SHA-256 before it runs.
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
@@ -13,5 +14,4 @@ Documentation, the command reference, and the source live in
13
14
  [cli/go](https://github.com/maritime-sh/maritime/tree/main/cli/go) of the
14
15
  Maritime repository.
15
16
 
16
- Set `MARITIME_CLI_DOWNLOAD_BASE` to install from a mirror of the release
17
- assets. Every command name from maritime-cli 1.x keeps working.
17
+ Every command name from maritime-cli 1.x keeps working.
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.0",
3
+ "version": "2.2.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,11 +14,16 @@
14
14
  },
15
15
  "files": [
16
16
  "bin",
17
- "install.js",
17
+ "platform.js",
18
18
  "README.md"
19
19
  ],
20
- "scripts": {
21
- "postinstall": "node install.js"
20
+ "optionalDependencies": {
21
+ "@maritimesh/cli-darwin-arm64": "2.2.0",
22
+ "@maritimesh/cli-darwin-x64": "2.2.0",
23
+ "@maritimesh/cli-linux-arm64": "2.2.0",
24
+ "@maritimesh/cli-linux-x64": "2.2.0",
25
+ "@maritimesh/cli-win32-arm64": "2.2.0",
26
+ "@maritimesh/cli-win32-x64": "2.2.0"
22
27
  },
23
28
  "engines": {
24
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 }
package/install.js DELETED
@@ -1,118 +0,0 @@
1
- 'use strict'
2
- // Downloads the Maritime CLI binary for this platform from the GitHub
3
- // release that matches package.json's version, verifies its SHA-256 against
4
- // the release's checksums.txt, and unpacks it next to this file.
5
- //
6
- // Runs as the package's postinstall step. Running it again is safe: an
7
- // existing binary of the right version is kept. Set
8
- // MARITIME_CLI_DOWNLOAD_BASE to install from a mirror of the release assets.
9
-
10
- const { createHash } = require('node:crypto')
11
- const fs = require('node:fs')
12
- const os = require('node:os')
13
- const path = require('node:path')
14
- const { execFileSync } = require('node:child_process')
15
-
16
- const pkg = require('./package.json')
17
- const VERSION = pkg.version
18
- const RELEASE_TAG = `cli-v${VERSION}`
19
- const DEFAULT_BASE = `https://github.com/maritime-sh/maritime/releases/download/${RELEASE_TAG}`
20
- const VENDOR_DIR = path.join(__dirname, 'vendor')
21
- const MARKER = path.join(VENDOR_DIR, 'version')
22
- const CHECKSUMS = 'checksums.txt'
23
- const SHA256_HEX_LENGTH = 64
24
- const DOWNLOAD_TIMEOUT_MS = 120000
25
-
26
- const PLATFORMS = { darwin: 'darwin', linux: 'linux', win32: 'windows' }
27
- const ARCHES = { x64: 'amd64', arm64: 'arm64' }
28
-
29
- /** Returns the archive name for this machine, or throws for an unsupported one. */
30
- function archiveName() {
31
- const goos = PLATFORMS[process.platform]
32
- const goarch = ARCHES[process.arch]
33
- if (!goos || !goarch) {
34
- throw new Error(`maritime-cli has no binary for ${process.platform}/${process.arch}`)
35
- }
36
- const ext = goos === 'windows' ? 'zip' : 'tar.gz'
37
- return `maritime_${VERSION}_${goos}_${goarch}.${ext}`
38
- }
39
-
40
- /** Returns the installed binary path for this machine. */
41
- function binaryPath() {
42
- return path.join(VENDOR_DIR, process.platform === 'win32' ? 'maritime.exe' : 'maritime')
43
- }
44
-
45
- /** Fetches url and returns its body as a Buffer. */
46
- async function download(url) {
47
- const controller = new AbortController()
48
- const timer = setTimeout(() => controller.abort(), DOWNLOAD_TIMEOUT_MS)
49
- try {
50
- const response = await fetch(url, { redirect: 'follow', signal: controller.signal })
51
- if (!response.ok) {
52
- throw new Error(`${url}: HTTP ${response.status}`)
53
- }
54
- return Buffer.from(await response.arrayBuffer())
55
- } finally {
56
- clearTimeout(timer)
57
- }
58
- }
59
-
60
- /** Returns the expected SHA-256 of name from the checksums file text. */
61
- function expectedChecksum(checksums, name) {
62
- for (const line of checksums.split('\n')) {
63
- const [hash, file] = line.trim().split(/\s+/)
64
- if (file === name && hash && hash.length === SHA256_HEX_LENGTH) {
65
- return hash
66
- }
67
- }
68
- throw new Error(`${CHECKSUMS} has no entry for ${name}`)
69
- }
70
-
71
- /** Unpacks archive (tar.gz or zip) into dir with the system tar. */
72
- function extract(archive, dir) {
73
- // bsdtar on macOS and Windows 10+, GNU tar on Linux; all read both formats.
74
- execFileSync('tar', ['-xf', archive, '-C', dir], { stdio: 'inherit' })
75
- }
76
-
77
- async function install() {
78
- const name = archiveName()
79
- const bin = binaryPath()
80
- if (fs.existsSync(bin) && fs.existsSync(MARKER) && fs.readFileSync(MARKER, 'utf8').trim() === VERSION) {
81
- return
82
- }
83
- const base = (process.env.MARITIME_CLI_DOWNLOAD_BASE || DEFAULT_BASE).replace(/\/+$/, '')
84
- const [archive, checksums] = await Promise.all([
85
- download(`${base}/${name}`),
86
- download(`${base}/${CHECKSUMS}`),
87
- ])
88
- const actual = createHash('sha256').update(archive).digest('hex')
89
- const expected = expectedChecksum(checksums.toString('utf8'), name)
90
- if (actual !== expected) {
91
- throw new Error(`${name}: SHA-256 ${actual} does not match ${CHECKSUMS} (${expected})`)
92
- }
93
- fs.rmSync(VENDOR_DIR, { recursive: true, force: true })
94
- fs.mkdirSync(VENDOR_DIR, { recursive: true })
95
- const tmp = path.join(os.tmpdir(), `maritime-cli-${process.pid}-${name}`)
96
- fs.writeFileSync(tmp, archive)
97
- try {
98
- extract(tmp, VENDOR_DIR)
99
- } finally {
100
- fs.rmSync(tmp, { force: true })
101
- }
102
- if (!fs.existsSync(bin)) {
103
- throw new Error(`${name} did not contain ${path.basename(bin)}`)
104
- }
105
- if (process.platform !== 'win32') {
106
- fs.chmodSync(bin, 0o755)
107
- }
108
- fs.writeFileSync(MARKER, `${VERSION}\n`)
109
- }
110
-
111
- module.exports = { install, binaryPath }
112
-
113
- if (require.main === module) {
114
- install().catch((error) => {
115
- console.error(`maritime-cli: ${error.message}`)
116
- process.exit(1)
117
- })
118
- }