@reviewsensei/cli 0.1.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/LICENSE +21 -0
- package/README.md +19 -0
- package/bin/review-sensei.js +309 -0
- package/package.json +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mohamad Alsabbagh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @reviewsensei/cli
|
|
2
|
+
|
|
3
|
+
This package is a small, shell-free launcher for the ReviewSensei native
|
|
4
|
+
standalone executable. It forwards the command line to the optional package
|
|
5
|
+
for the current supported operating-system/architecture pair; review logic
|
|
6
|
+
continues to live in the Python `review_sensei.cli:main` entry point bundled
|
|
7
|
+
by PyInstaller.
|
|
8
|
+
|
|
9
|
+
Requirements: Node.js 22 or newer and an external `git` executable when using
|
|
10
|
+
`prepare-diff`. The launcher never downloads a runtime, runs an install hook,
|
|
11
|
+
or contacts a provider. Install the exact version and invoke it with:
|
|
12
|
+
|
|
13
|
+
```console
|
|
14
|
+
npx --yes @reviewsensei/cli@0.1.0 --version
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Supported targets are macOS arm64/x64, Linux arm64/x64 with glibc, and
|
|
18
|
+
Windows x64. Linux musl systems and other architectures fail with a bounded
|
|
19
|
+
unsupported-target error.
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { createRequire } = require("node:module");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const fs = require("node:fs");
|
|
7
|
+
const os = require("node:os");
|
|
8
|
+
const childProcess = require("node:child_process");
|
|
9
|
+
|
|
10
|
+
const launcherPackage = require("../package.json");
|
|
11
|
+
const launcherRequire = createRequire(path.join(__dirname, "..", "package.json"));
|
|
12
|
+
|
|
13
|
+
// Keep this table deliberately boring and explicit. Adding an alias here is a
|
|
14
|
+
// public support commitment and must be accompanied by a native build lane.
|
|
15
|
+
const TARGETS = Object.freeze([
|
|
16
|
+
Object.freeze({
|
|
17
|
+
id: "darwin-arm64",
|
|
18
|
+
platform: "darwin",
|
|
19
|
+
arch: "arm64",
|
|
20
|
+
packageName: "@reviewsensei/cli-darwin-arm64",
|
|
21
|
+
payload: "bin/review-sensei",
|
|
22
|
+
}),
|
|
23
|
+
Object.freeze({
|
|
24
|
+
id: "darwin-x64",
|
|
25
|
+
platform: "darwin",
|
|
26
|
+
arch: "x64",
|
|
27
|
+
packageName: "@reviewsensei/cli-darwin-x64",
|
|
28
|
+
payload: "bin/review-sensei",
|
|
29
|
+
}),
|
|
30
|
+
Object.freeze({
|
|
31
|
+
id: "linux-arm64-gnu",
|
|
32
|
+
platform: "linux",
|
|
33
|
+
arch: "arm64",
|
|
34
|
+
packageName: "@reviewsensei/cli-linux-arm64-gnu",
|
|
35
|
+
payload: "bin/review-sensei",
|
|
36
|
+
}),
|
|
37
|
+
Object.freeze({
|
|
38
|
+
id: "linux-x64-gnu",
|
|
39
|
+
platform: "linux",
|
|
40
|
+
arch: "x64",
|
|
41
|
+
packageName: "@reviewsensei/cli-linux-x64-gnu",
|
|
42
|
+
payload: "bin/review-sensei",
|
|
43
|
+
}),
|
|
44
|
+
Object.freeze({
|
|
45
|
+
id: "win32-x64",
|
|
46
|
+
platform: "win32",
|
|
47
|
+
arch: "x64",
|
|
48
|
+
packageName: "@reviewsensei/cli-win32-x64",
|
|
49
|
+
payload: "bin/review-sensei.exe",
|
|
50
|
+
}),
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
const SUPPORTED_TARGETS = TARGETS.map((target) => target.id).join(", ");
|
|
54
|
+
const SIGNALS = Object.freeze(["SIGINT", "SIGTERM", "SIGHUP"]);
|
|
55
|
+
|
|
56
|
+
class LauncherError extends Error {
|
|
57
|
+
constructor(code, message) {
|
|
58
|
+
super(message);
|
|
59
|
+
this.name = "LauncherError";
|
|
60
|
+
this.code = code;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function unsupportedTarget(platform, arch, reason) {
|
|
65
|
+
const suffix = reason ? ` (${reason})` : "";
|
|
66
|
+
return new LauncherError(
|
|
67
|
+
"UNSUPPORTED_TARGET",
|
|
68
|
+
`unsupported target ${String(platform)}/${String(arch)}${suffix}; supported targets: ${SUPPORTED_TARGETS}`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function glibcVersion(report) {
|
|
73
|
+
try {
|
|
74
|
+
const value = typeof report === "function" ? report() : report;
|
|
75
|
+
const version = value && value.header && value.header.glibcVersionRuntime;
|
|
76
|
+
return typeof version === "string" ? version.trim() : "";
|
|
77
|
+
} catch (_error) {
|
|
78
|
+
return "";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Return the one supported target for a Node platform/architecture pair. */
|
|
83
|
+
function selectTarget(
|
|
84
|
+
platform = process.platform,
|
|
85
|
+
arch = process.arch,
|
|
86
|
+
report = process.report,
|
|
87
|
+
) {
|
|
88
|
+
const target = TARGETS.find(
|
|
89
|
+
(candidate) => candidate.platform === platform && candidate.arch === arch,
|
|
90
|
+
);
|
|
91
|
+
if (!target) {
|
|
92
|
+
throw unsupportedTarget(platform, arch);
|
|
93
|
+
}
|
|
94
|
+
const reportValue =
|
|
95
|
+
report && typeof report.getReport === "function"
|
|
96
|
+
? report.getReport.bind(report)
|
|
97
|
+
: report;
|
|
98
|
+
if (platform === "linux" && !glibcVersion(reportValue)) {
|
|
99
|
+
throw unsupportedTarget(platform, arch, "glibc runtime was not detected");
|
|
100
|
+
}
|
|
101
|
+
return target;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function packageManifestPath(target, requirePackageJson, resolvePackageJson) {
|
|
105
|
+
if (typeof resolvePackageJson === "function") {
|
|
106
|
+
return resolvePackageJson(`${target.packageName}/package.json`);
|
|
107
|
+
}
|
|
108
|
+
return requirePackageJson.resolve(`${target.packageName}/package.json`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Resolve the executable from the installed optional package.
|
|
113
|
+
*
|
|
114
|
+
* Only the package's own package.json is loaded. The package and binary are
|
|
115
|
+
* checked before any process is spawned, so a partial npm installation fails
|
|
116
|
+
* closed without a fallback downloader or system-Python invocation.
|
|
117
|
+
*/
|
|
118
|
+
function resolvePlatformExecutable(target, options = {}) {
|
|
119
|
+
const requirePackageJson = options.requirePackageJson || launcherRequire;
|
|
120
|
+
const expectedVersion = options.launcherVersion || launcherPackage.version;
|
|
121
|
+
let manifestPath;
|
|
122
|
+
let manifest;
|
|
123
|
+
try {
|
|
124
|
+
manifestPath = packageManifestPath(
|
|
125
|
+
target,
|
|
126
|
+
requirePackageJson,
|
|
127
|
+
options.resolvePackageJson,
|
|
128
|
+
);
|
|
129
|
+
manifest = options.loadPackageJson
|
|
130
|
+
? options.loadPackageJson(`${target.packageName}/package.json`)
|
|
131
|
+
: requirePackageJson(`${target.packageName}/package.json`);
|
|
132
|
+
} catch (_error) {
|
|
133
|
+
throw new LauncherError(
|
|
134
|
+
"PLATFORM_PACKAGE_MISSING",
|
|
135
|
+
`supported platform package ${target.packageName} is not installed`,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!manifest || manifest.name !== target.packageName) {
|
|
140
|
+
throw new LauncherError(
|
|
141
|
+
"PLATFORM_PACKAGE_INVALID",
|
|
142
|
+
`platform package ${target.packageName} has invalid metadata`,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
if (manifest.version !== expectedVersion) {
|
|
146
|
+
throw new LauncherError(
|
|
147
|
+
"PLATFORM_VERSION_MISMATCH",
|
|
148
|
+
`platform package ${target.packageName} does not match launcher version`,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
// Platform packages intentionally have no npm `bin` field. The launcher is
|
|
152
|
+
// the sole owner of the public command, avoiding a transitive optional
|
|
153
|
+
// dependency shadowing this shim in node_modules/.bin.
|
|
154
|
+
if (Object.prototype.hasOwnProperty.call(manifest, "bin")) {
|
|
155
|
+
throw new LauncherError(
|
|
156
|
+
"PLATFORM_PAYLOAD_INVALID",
|
|
157
|
+
`platform package ${target.packageName} must not expose a command`,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const packageRoot = path.dirname(manifestPath);
|
|
162
|
+
const executable = path.resolve(packageRoot, target.payload);
|
|
163
|
+
const relative = path.relative(packageRoot, executable);
|
|
164
|
+
if (!relative || relative.startsWith(".." + path.sep) || path.isAbsolute(relative)) {
|
|
165
|
+
throw new LauncherError(
|
|
166
|
+
"PLATFORM_PAYLOAD_INVALID",
|
|
167
|
+
`platform package ${target.packageName} executable is outside its package`,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
let stat;
|
|
171
|
+
try {
|
|
172
|
+
stat = options.lstatSync
|
|
173
|
+
? options.lstatSync(executable)
|
|
174
|
+
: fs.lstatSync(executable);
|
|
175
|
+
} catch (_error) {
|
|
176
|
+
throw new LauncherError(
|
|
177
|
+
"PLATFORM_PAYLOAD_INVALID",
|
|
178
|
+
`platform package ${target.packageName} executable is not a regular file`,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
if (!stat.isFile() || (typeof stat.isSymbolicLink === "function" && stat.isSymbolicLink())) {
|
|
182
|
+
throw new LauncherError(
|
|
183
|
+
"PLATFORM_PAYLOAD_INVALID",
|
|
184
|
+
`platform package ${target.packageName} executable is not a regular file`,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
return executable;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function safeErrorMessage(error) {
|
|
191
|
+
if (error instanceof LauncherError) return error.message;
|
|
192
|
+
return "unable to start the ReviewSensei platform executable";
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function signalExitStatus(signal) {
|
|
196
|
+
const number = os.constants.signals && os.constants.signals[signal];
|
|
197
|
+
return 128 + (typeof number === "number" ? number : 1);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Spawn the selected native executable while forwarding raw argv and process
|
|
202
|
+
* behavior. The optional seams are intentionally small so this contract can
|
|
203
|
+
* be tested with Node's built-in test runner without a child process.
|
|
204
|
+
*/
|
|
205
|
+
function run(argv = [], options = {}) {
|
|
206
|
+
const runtime = options.process || process;
|
|
207
|
+
const writeError =
|
|
208
|
+
options.writeError ||
|
|
209
|
+
((message) => {
|
|
210
|
+
if (runtime.stderr && typeof runtime.stderr.write === "function") {
|
|
211
|
+
runtime.stderr.write(`${message}\n`);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
let target;
|
|
215
|
+
let executable;
|
|
216
|
+
try {
|
|
217
|
+
target =
|
|
218
|
+
options.target ||
|
|
219
|
+
selectTarget(
|
|
220
|
+
options.platform === undefined ? runtime.platform : options.platform,
|
|
221
|
+
options.arch === undefined ? runtime.arch : options.arch,
|
|
222
|
+
options.report === undefined ? runtime.report : options.report,
|
|
223
|
+
);
|
|
224
|
+
executable = (options.resolveExecutable || resolvePlatformExecutable)(target, {
|
|
225
|
+
launcherVersion: options.launcherVersion || launcherPackage.version,
|
|
226
|
+
requirePackageJson: options.requirePackageJson,
|
|
227
|
+
resolvePackageJson: options.resolvePackageJson,
|
|
228
|
+
loadPackageJson: options.loadPackageJson,
|
|
229
|
+
lstatSync: options.lstatSync,
|
|
230
|
+
});
|
|
231
|
+
} catch (error) {
|
|
232
|
+
writeError(`review-sensei: ${safeErrorMessage(error)}`);
|
|
233
|
+
return Promise.resolve(1);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const spawn = options.spawn || childProcess.spawn;
|
|
237
|
+
const spawnOptions = {
|
|
238
|
+
shell: false,
|
|
239
|
+
stdio: "inherit",
|
|
240
|
+
cwd: runtime.cwd(),
|
|
241
|
+
env: runtime.env,
|
|
242
|
+
};
|
|
243
|
+
let child;
|
|
244
|
+
try {
|
|
245
|
+
child = spawn(executable, [...argv], spawnOptions);
|
|
246
|
+
} catch (_error) {
|
|
247
|
+
writeError("review-sensei: unable to start the ReviewSensei platform executable");
|
|
248
|
+
return Promise.resolve(1);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return new Promise((resolve) => {
|
|
252
|
+
let settled = false;
|
|
253
|
+
const removers = [];
|
|
254
|
+
const cleanup = () => {
|
|
255
|
+
for (const remove of removers.splice(0)) remove();
|
|
256
|
+
};
|
|
257
|
+
const finish = (code) => {
|
|
258
|
+
if (settled) return;
|
|
259
|
+
settled = true;
|
|
260
|
+
cleanup();
|
|
261
|
+
resolve(code);
|
|
262
|
+
};
|
|
263
|
+
const onExit = (code, signal) => {
|
|
264
|
+
if (typeof code === "number") finish(code);
|
|
265
|
+
else if (typeof signal === "string" && signal) finish(signalExitStatus(signal));
|
|
266
|
+
else finish(1);
|
|
267
|
+
};
|
|
268
|
+
if (child && typeof child.once === "function") {
|
|
269
|
+
child.once("error", () => {
|
|
270
|
+
writeError("review-sensei: unable to start the ReviewSensei platform executable");
|
|
271
|
+
finish(1);
|
|
272
|
+
});
|
|
273
|
+
child.once("exit", onExit);
|
|
274
|
+
} else {
|
|
275
|
+
finish(1);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const add = typeof runtime.on === "function" ? "on" : null;
|
|
279
|
+
const remove =
|
|
280
|
+
typeof runtime.off === "function"
|
|
281
|
+
? "off"
|
|
282
|
+
: typeof runtime.removeListener === "function"
|
|
283
|
+
? "removeListener"
|
|
284
|
+
: null;
|
|
285
|
+
if (add && remove && child && typeof child.kill === "function") {
|
|
286
|
+
for (const signal of SIGNALS) {
|
|
287
|
+
const forward = () => child.kill(signal);
|
|
288
|
+
runtime[add](signal, forward);
|
|
289
|
+
removers.push(() => runtime[remove](signal, forward));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
module.exports = {
|
|
296
|
+
LauncherError,
|
|
297
|
+
SIGNALS,
|
|
298
|
+
SUPPORTED_TARGETS,
|
|
299
|
+
TARGETS,
|
|
300
|
+
resolvePlatformExecutable,
|
|
301
|
+
run,
|
|
302
|
+
selectTarget,
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
if (require.main === module) {
|
|
306
|
+
run(process.argv.slice(2)).then((code) => {
|
|
307
|
+
process.exitCode = code;
|
|
308
|
+
});
|
|
309
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reviewsensei/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ReviewSensei launcher for the native standalone CLI",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/malsabbagh/review-sensei.git"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=22"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"review-sensei": "bin/review-sensei.js"
|
|
15
|
+
},
|
|
16
|
+
"optionalDependencies": {
|
|
17
|
+
"@reviewsensei/cli-darwin-arm64": "0.1.0",
|
|
18
|
+
"@reviewsensei/cli-darwin-x64": "0.1.0",
|
|
19
|
+
"@reviewsensei/cli-linux-arm64-gnu": "0.1.0",
|
|
20
|
+
"@reviewsensei/cli-linux-x64-gnu": "0.1.0",
|
|
21
|
+
"@reviewsensei/cli-win32-x64": "0.1.0"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"bin",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
]
|
|
31
|
+
}
|