@ampcode/cli 0.0.0-placeholder → 0.0.1778577695-g97a828

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,3 +1,9 @@
1
- # @ampcode/cli
1
+ # Amp CLI
2
2
 
3
- This is a placeholder package for Amp CLI. Do not install it directly.
3
+ We recommend installing Amp CLI using the steps in the [Amp Owner's Manual](https://ampcode.com/manual). This npm package can be used by enterprises that want to manage distribution of the Amp CLI through internal package archives.
4
+
5
+ ```bash
6
+ npm install -g @ampcode/cli
7
+ ```
8
+
9
+ This package contains prebuilt binaries for the Amp CLI for various platforms. The prior package name was `@sourcegraph/amp`; that package name still works for backwards compatibility for the time being.
package/bin/amp.exe ADDED
@@ -0,0 +1,3 @@
1
+ echo "Error: Amp native binary not installed." >&2
2
+ echo "Run postinstall manually or reinstall with: npm install -g @ampcode/cli" >&2
3
+ exit 1
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env node
2
+ const { spawnSync } = require('node:child_process')
3
+ const { arch, constants } = require('node:os')
4
+ const path = require('node:path')
5
+
6
+ const WRAPPER_NAME = require('./package.json').name
7
+ const PLATFORMS = {
8
+ 'darwin-arm64': { pkg: '@ampcode/cli-darwin-arm64', bin: 'amp' },
9
+ 'darwin-x64': { pkg: '@ampcode/cli-darwin-x64', bin: 'amp' },
10
+ 'linux-arm64': { pkg: '@ampcode/cli-linux-arm64', bin: 'amp' },
11
+ 'linux-x64': { pkg: '@ampcode/cli-linux-x64', bin: 'amp' },
12
+ 'win32-x64': { pkg: '@ampcode/cli-win32-x64', bin: 'amp.exe' },
13
+ }
14
+
15
+ function printHelp() {
16
+ console.error(' For help, visit https://ampcode.com/manual or email amp-devs@ampcode.com.')
17
+ }
18
+
19
+ function detectMusl() {
20
+ if (process.platform !== 'linux') {
21
+ return false
22
+ }
23
+ const report = typeof process.report?.getReport === 'function' ? process.report.getReport() : null
24
+ return report != null && report.header?.glibcVersionRuntime === undefined
25
+ }
26
+
27
+ function getPlatformKey() {
28
+ let cpu = arch()
29
+ if (process.platform === 'linux') {
30
+ return 'linux-' + cpu + (detectMusl() ? '-musl' : '')
31
+ }
32
+ if (process.platform === 'darwin' && cpu === 'x64') {
33
+ const result = spawnSync('sysctl', ['-n', 'sysctl.proc_translated'], { encoding: 'utf8' })
34
+ if (result.stdout?.trim() === '1') {
35
+ cpu = 'arm64'
36
+ }
37
+ }
38
+ return process.platform + '-' + cpu
39
+ }
40
+
41
+ function getBinaryPath() {
42
+ const platformKey = getPlatformKey()
43
+ const info = PLATFORMS[platformKey]
44
+ if (!info) {
45
+ console.error(`[${WRAPPER_NAME}] Unsupported platform: ${process.platform} ${arch()}. Supported: ${Object.keys(PLATFORMS).join(', ')}`)
46
+ printHelp()
47
+ process.exit(1)
48
+ }
49
+ try {
50
+ const pkgDir = path.dirname(require.resolve(info.pkg + '/package.json'))
51
+ return path.join(pkgDir, info.bin)
52
+ } catch {
53
+ console.error(`[${WRAPPER_NAME}] Could not find native binary package "${info.pkg}".`)
54
+ console.error(' Try reinstalling without --ignore-scripts / --omit=optional.')
55
+ printHelp()
56
+ process.exit(1)
57
+ }
58
+ }
59
+
60
+ function main() {
61
+ const binaryPath = getBinaryPath()
62
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
63
+ stdio: 'inherit',
64
+ env: process.env,
65
+ })
66
+ if (result.error) {
67
+ console.error(`[${WRAPPER_NAME}] Failed to execute native binary at ${binaryPath}`)
68
+ console.error(' ' + result.error.message)
69
+ printHelp()
70
+ process.exit(1)
71
+ }
72
+ if (result.signal) {
73
+ const signum = constants.signals[result.signal] ?? 0
74
+ process.exit(128 + signum)
75
+ }
76
+ process.exit(result.status ?? 1)
77
+ }
78
+
79
+ main()
package/install.cjs ADDED
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+ const { spawnSync } = require('node:child_process')
3
+ const { copyFileSync, linkSync, unlinkSync, chmodSync, statSync, readFileSync, writeFileSync } = require('node:fs')
4
+ const { arch } = require('node:os')
5
+ const path = require('node:path')
6
+
7
+ const WRAPPER_NAME = require('./package.json').name
8
+ const PLATFORMS = {
9
+ 'darwin-arm64': { pkg: '@ampcode/cli-darwin-arm64', bin: 'amp' },
10
+ 'darwin-x64': { pkg: '@ampcode/cli-darwin-x64', bin: 'amp' },
11
+ 'linux-arm64': { pkg: '@ampcode/cli-linux-arm64', bin: 'amp' },
12
+ 'linux-x64': { pkg: '@ampcode/cli-linux-x64', bin: 'amp' },
13
+ 'win32-x64': { pkg: '@ampcode/cli-win32-x64', bin: 'amp.exe' },
14
+ }
15
+
16
+ function printHelp() {
17
+ console.error(' For help, visit https://ampcode.com/manual or email amp-devs@ampcode.com.')
18
+ }
19
+
20
+ function detectMusl() {
21
+ if (process.platform !== 'linux') {
22
+ return false
23
+ }
24
+ const report = typeof process.report?.getReport === 'function' ? process.report.getReport() : null
25
+ return report != null && report.header?.glibcVersionRuntime === undefined
26
+ }
27
+
28
+ function getPlatformKey() {
29
+ let cpu = arch()
30
+ if (process.platform === 'linux') {
31
+ return 'linux-' + cpu + (detectMusl() ? '-musl' : '')
32
+ }
33
+ if (process.platform === 'darwin' && cpu === 'x64') {
34
+ const result = spawnSync('sysctl', ['-n', 'sysctl.proc_translated'], { encoding: 'utf8' })
35
+ if (result.stdout?.trim() === '1') {
36
+ cpu = 'arm64'
37
+ }
38
+ }
39
+ return process.platform + '-' + cpu
40
+ }
41
+
42
+ function placeBinary(src, dest) {
43
+ try {
44
+ linkSync(src, dest)
45
+ } catch (error) {
46
+ if (error.code === 'EEXIST') {
47
+ const stub = statSync(dest).size < 4096 ? readFileSync(dest) : null
48
+ unlinkSync(dest)
49
+ try {
50
+ linkSync(src, dest)
51
+ } catch {
52
+ try {
53
+ copyFileSync(src, dest)
54
+ } catch (copyError) {
55
+ if (stub) {
56
+ try {
57
+ writeFileSync(dest, stub, { mode: 0o755 })
58
+ } catch {}
59
+ }
60
+ throw copyError
61
+ }
62
+ }
63
+ } else if (error.code === 'EXDEV' || error.code === 'EPERM') {
64
+ copyFileSync(src, dest)
65
+ } else {
66
+ throw error
67
+ }
68
+ }
69
+ if (process.platform !== 'win32') {
70
+ chmodSync(dest, 0o755)
71
+ }
72
+ }
73
+
74
+ function main() {
75
+ const platformKey = getPlatformKey()
76
+ const info = PLATFORMS[platformKey]
77
+ if (!info) {
78
+ console.error(`[${WRAPPER_NAME} postinstall] Unsupported platform: ${process.platform} ${arch()}`)
79
+ console.error(` Supported: ${Object.keys(PLATFORMS).join(', ')}`)
80
+ printHelp()
81
+ return
82
+ }
83
+
84
+ let src
85
+ try {
86
+ const pkgDir = path.dirname(require.resolve(info.pkg + '/package.json'))
87
+ src = path.join(pkgDir, info.bin)
88
+ } catch {
89
+ console.error(`[${WRAPPER_NAME} postinstall] Native package "${info.pkg}" not found.`)
90
+ console.error(' This happens with --omit=optional or when the download failed.')
91
+ console.error(' Fallback: node ' + path.join(__dirname, 'cli-wrapper.cjs'))
92
+ printHelp()
93
+ return
94
+ }
95
+
96
+ try {
97
+ placeBinary(src, path.join(__dirname, 'bin', 'amp.exe'))
98
+ } catch (error) {
99
+ console.error(`[${WRAPPER_NAME} postinstall] Failed to place binary: ${error.message}`)
100
+ console.error(' Fallback: node ' + path.join(__dirname, 'cli-wrapper.cjs'))
101
+ printHelp()
102
+ process.exitCode = 1
103
+ }
104
+ }
105
+
106
+ main()
package/package.json CHANGED
@@ -1,11 +1,27 @@
1
1
  {
2
2
  "name": "@ampcode/cli",
3
- "version": "0.0.0-placeholder",
4
- "description": "Placeholder package for Amp CLI.",
3
+ "version": "0.0.1778577695-g97a828",
4
+ "description": "CLI for Amp, the frontier coding agent.",
5
5
  "homepage": "https://ampcode.com/",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
7
7
  "type": "module",
8
+ "bin": {
9
+ "amp": "bin/amp.exe"
10
+ },
11
+ "scripts": {
12
+ "postinstall": "node install.cjs"
13
+ },
14
+ "optionalDependencies": {
15
+ "@ampcode/cli-darwin-arm64": "0.0.1778577695-g97a828",
16
+ "@ampcode/cli-darwin-x64": "0.0.1778577695-g97a828",
17
+ "@ampcode/cli-linux-arm64": "0.0.1778577695-g97a828",
18
+ "@ampcode/cli-linux-x64": "0.0.1778577695-g97a828",
19
+ "@ampcode/cli-win32-x64": "0.0.1778577695-g97a828"
20
+ },
8
21
  "files": [
22
+ "bin/amp.exe",
23
+ "cli-wrapper.cjs",
24
+ "install.cjs",
9
25
  "README.md",
10
26
  "LICENSE.md"
11
27
  ]