@awmate/cli 0.0.0-stage → 2.2.48

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/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@awmate/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "bin": {
4
+ "awmate": "./bin/awmate"
5
+ },
6
+ "scripts": {
7
+ "postinstall": "node ./postinstall.mjs"
8
+ },
9
+ "version": "2.2.48",
10
+ "description": "AWMate (Assistive Workmate) — the coding agent CLI",
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/devnxtgensec/awmate.git"
15
+ },
16
+ "os": [
17
+ "darwin",
18
+ "linux",
19
+ "win32"
20
+ ],
21
+ "cpu": [
22
+ "arm64",
23
+ "x64"
24
+ ],
25
+ "optionalDependencies": {
26
+ "@awmate/cli-darwin-arm64": "2.2.48",
27
+ "@awmate/cli-darwin-x64": "2.2.48",
28
+ "@awmate/cli-darwin-x64-baseline": "2.2.48",
29
+ "@awmate/cli-linux-arm64": "2.2.48",
30
+ "@awmate/cli-linux-x64": "2.2.48",
31
+ "@awmate/cli-linux-x64-baseline": "2.2.48",
32
+ "@awmate/cli-windows-arm64": "2.2.48",
33
+ "@awmate/cli-windows-x64": "2.2.48",
34
+ "@awmate/cli-windows-x64-baseline": "2.2.48"
35
+ }
6
36
  }
@@ -0,0 +1,170 @@
1
+ #!/usr/bin/env node
2
+
3
+ import childProcess from "node:child_process"
4
+ import fs from "node:fs"
5
+ import os from "node:os"
6
+ import path from "node:path"
7
+ import { createRequire } from "node:module"
8
+ import { fileURLToPath } from "node:url"
9
+
10
+ const directory = path.dirname(fileURLToPath(import.meta.url))
11
+ const require = createRequire(import.meta.url)
12
+ const packageJson = JSON.parse(fs.readFileSync(path.join(directory, "package.json"), "utf8"))
13
+ const command = Object.keys(packageJson.bin ?? {})[0]
14
+ if (!command) throw new Error("AWMate package does not declare a binary")
15
+ const sourceCommand = packageJson.awmateSourceBinary ?? command
16
+
17
+ const platform = { darwin: "darwin", linux: "linux", win32: "windows" }[os.platform()] ?? os.platform()
18
+ const nodeArch = { x64: "x64", arm64: "arm64", arm: "arm" }[os.arch()] ?? os.arch()
19
+ // x64 Node runs emulated on Windows ARM64, but PROCESSOR_IDENTIFIER still names the host CPU.
20
+ const arch =
21
+ platform === "windows" && nodeArch === "x64" && process.env.PROCESSOR_IDENTIFIER?.startsWith("ARM")
22
+ ? "arm64"
23
+ : nodeArch
24
+ // Windows cannot spawn npm's .cmd shim directly, so reuse the npm CLI that runs this script.
25
+ const npm = process.env.npm_execpath?.endsWith("npm-cli.js") ? [process.execPath, process.env.npm_execpath] : ["npm"]
26
+ const sourceBinary = platform === "windows" ? `${sourceCommand}.exe` : sourceCommand
27
+ const targetBinary = path.resolve(directory, packageJson.bin[command])
28
+ const dependencies = packageJson.optionalDependencies ?? {}
29
+ const base = Object.keys(dependencies).find((name) => name.endsWith(`-${platform}-${arch}`))
30
+ if (!base) throw new Error(`AWMate does not provide a binary for ${platform}-${arch}`)
31
+
32
+ function supportsAvx2() {
33
+ if (arch !== "x64") return false
34
+ if (platform === "linux") {
35
+ try {
36
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
37
+ } catch {
38
+ return false
39
+ }
40
+ }
41
+ if (platform === "darwin") {
42
+ try {
43
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
44
+ encoding: "utf8",
45
+ timeout: 1500,
46
+ })
47
+ return result.status === 0 && (result.stdout || "").trim() === "1"
48
+ } catch {
49
+ return false
50
+ }
51
+ }
52
+ if (platform === "windows") {
53
+ const script =
54
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
55
+ for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
56
+ try {
57
+ const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", script], {
58
+ encoding: "utf8",
59
+ timeout: 3000,
60
+ windowsHide: true,
61
+ })
62
+ if (result.status !== 0) continue
63
+ const output = (result.stdout || "").trim().toLowerCase()
64
+ if (output === "true" || output === "1") return true
65
+ if (output === "false" || output === "0") return false
66
+ } catch {
67
+ continue
68
+ }
69
+ }
70
+ }
71
+ return false
72
+ }
73
+
74
+ function packageNames() {
75
+ const baseline = arch === "x64" && !supportsAvx2()
76
+ const names =
77
+ arch === "x64"
78
+ ? baseline
79
+ ? [`${base}-baseline`, base]
80
+ : [base, `${base}-baseline`]
81
+ : [base]
82
+ // Windows 11 on ARM64 can still run the x64 binary under emulation when the native one fails.
83
+ const x64 = base.replace(/-arm64$/, "-x64")
84
+ const emulated = platform === "windows" && arch === "arm64" ? [`${x64}-baseline`, x64] : []
85
+ return [...names, ...emulated].filter((name) => dependencies[name])
86
+ }
87
+
88
+ function copyBinary(source) {
89
+ if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)
90
+ fs.mkdirSync(path.dirname(targetBinary), { recursive: true })
91
+ if (fs.existsSync(targetBinary)) {
92
+ try {
93
+ fs.unlinkSync(targetBinary)
94
+ } catch {}
95
+ }
96
+ try {
97
+ fs.linkSync(source, targetBinary)
98
+ } catch {
99
+ fs.copyFileSync(source, targetBinary)
100
+ }
101
+ fs.chmodSync(targetBinary, 0o755)
102
+ }
103
+
104
+ function resolveBinary(name) {
105
+ const packagePath = require.resolve(`${name}/package.json`)
106
+ // Package managers keep an older platform package when the matching version is not yet on the registry,
107
+ // which would silently install the previous release under the new launcher.
108
+ const version = JSON.parse(fs.readFileSync(packagePath, "utf8")).version
109
+ if (version !== dependencies[name]) throw new Error(`${name} is ${version}, expected ${dependencies[name]}`)
110
+ return path.join(path.dirname(packagePath), "bin", sourceBinary)
111
+ }
112
+
113
+ function installPackage(name) {
114
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), "awmate-install-"))
115
+ try {
116
+ const result = childProcess.spawnSync(
117
+ npm[0],
118
+ [
119
+ ...npm.slice(1),
120
+ "install",
121
+ "--ignore-scripts",
122
+ "--no-save",
123
+ "--loglevel=error",
124
+ // npm rejects a package built for another CPU, such as arm64 under emulated x64 Node, unless forced.
125
+ ...(name.includes(`-${platform}-${nodeArch}`) ? [] : ["--force"]),
126
+ "--prefix",
127
+ temp,
128
+ `${name}@${dependencies[name]}`,
129
+ ],
130
+ { stdio: "inherit", windowsHide: true },
131
+ )
132
+ if (result.status !== 0) return false
133
+ copyBinary(path.join(temp, "node_modules", name, "bin", sourceBinary))
134
+ return true
135
+ } finally {
136
+ fs.rmSync(temp, { recursive: true, force: true })
137
+ }
138
+ }
139
+
140
+ function verifyBinary() {
141
+ return (
142
+ childProcess.spawnSync(targetBinary, ["--version"], {
143
+ stdio: "ignore",
144
+ windowsHide: true,
145
+ }).status === 0
146
+ )
147
+ }
148
+
149
+ function main() {
150
+ const names = packageNames()
151
+ for (const name of names) {
152
+ try {
153
+ copyBinary(resolveBinary(name))
154
+ if (verifyBinary()) return
155
+ } catch {
156
+ if (installPackage(name) && verifyBinary()) return
157
+ }
158
+ }
159
+
160
+ throw new Error(
161
+ `Failed to install AWMate. Try manually installing ${names.map((name) => JSON.stringify(name)).join(" or ")}.`,
162
+ )
163
+ }
164
+
165
+ try {
166
+ main()
167
+ } catch (error) {
168
+ console.error(error instanceof Error ? error.message : String(error))
169
+ process.exit(1)
170
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.