mochiii 0.0.0-stage → 1.2.2
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 +122 -0
- package/README.md +31 -2
- package/THIRD_PARTY_LICENSES.txt +4002 -0
- package/bin/mochiii +43 -0
- package/install.js +43 -0
- package/package.json +45 -4
- package/platform.js +75 -0
package/bin/mochiii
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The `mochiii` command of the npm package: it runs the native binary from the
|
|
3
|
+
// platform package npm installed beside it (@mochiii/<platform>).
|
|
4
|
+
//
|
|
5
|
+
// On macOS and Linux this file is usually not what runs: the package's
|
|
6
|
+
// postinstall (install.js) replaces it with the binary itself, so starting
|
|
7
|
+
// mochiii costs no Node. It runs when install scripts were off (npm
|
|
8
|
+
// --ignore-scripts, pnpm by default) and always on Windows, where npm starts
|
|
9
|
+
// every package command through Node.
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const { spawn } = require('child_process');
|
|
13
|
+
const { findBinary } = require('../platform.js');
|
|
14
|
+
|
|
15
|
+
let bin;
|
|
16
|
+
try {
|
|
17
|
+
bin = findBinary();
|
|
18
|
+
} catch (err) {
|
|
19
|
+
console.error(`mochiii: ${err.message}`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// The terminal, signals and exit status all belong to the binary. Ctrl-C in a
|
|
24
|
+
// terminal reaches it directly (the whole foreground process group gets it), so
|
|
25
|
+
// this process ignores SIGINT rather than dying first; SIGTERM and SIGHUP, which
|
|
26
|
+
// are sent to this process alone, are passed on.
|
|
27
|
+
const child = spawn(bin, process.argv.slice(2), { stdio: 'inherit', windowsHide: false });
|
|
28
|
+
process.on('SIGINT', () => {});
|
|
29
|
+
for (const sig of ['SIGTERM', 'SIGHUP']) {
|
|
30
|
+
process.on(sig, () => child.kill(sig));
|
|
31
|
+
}
|
|
32
|
+
child.on('error', (err) => {
|
|
33
|
+
console.error(`mochiii: could not start ${bin}: ${err.message}`);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
});
|
|
36
|
+
child.on('exit', (code, signal) => {
|
|
37
|
+
if (signal) {
|
|
38
|
+
process.removeAllListeners(signal);
|
|
39
|
+
process.kill(process.pid, signal);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
process.exit(code === null ? 1 : code);
|
|
43
|
+
});
|
package/install.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// postinstall: put the native binary where the `mochiii` command points, so
|
|
4
|
+
// that starting Mochiii does not start Node first.
|
|
5
|
+
//
|
|
6
|
+
// npm links the `mochiii` command to bin/mochiii, a small Node launcher. On
|
|
7
|
+
// macOS and Linux this replaces that file with the binary from the platform
|
|
8
|
+
// package -- a hard link where it can, else a copy -- the way esbuild's npm
|
|
9
|
+
// package does. The binary needs nothing from Node: it is the one `mochiii`
|
|
10
|
+
// program, and it finds its own background service and helper by its own path.
|
|
11
|
+
//
|
|
12
|
+
// It changes nothing on Windows, where npm starts every package command through
|
|
13
|
+
// Node regardless, and it never fails the install: with no platform package,
|
|
14
|
+
// or a file it cannot replace, the launcher stays, and the launcher says what is
|
|
15
|
+
// missing when it runs.
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const { findBinary } = require('./platform.js');
|
|
19
|
+
|
|
20
|
+
function main() {
|
|
21
|
+
if (process.platform === 'win32') return;
|
|
22
|
+
let bin;
|
|
23
|
+
try {
|
|
24
|
+
bin = findBinary();
|
|
25
|
+
} catch {
|
|
26
|
+
return; // the launcher will say why
|
|
27
|
+
}
|
|
28
|
+
const launcher = path.join(__dirname, 'bin', 'mochiii');
|
|
29
|
+
const tmp = `${launcher}.native.${process.pid}`;
|
|
30
|
+
try {
|
|
31
|
+
try {
|
|
32
|
+
fs.linkSync(bin, tmp);
|
|
33
|
+
} catch {
|
|
34
|
+
fs.copyFileSync(bin, tmp);
|
|
35
|
+
}
|
|
36
|
+
fs.chmodSync(tmp, 0o755);
|
|
37
|
+
fs.renameSync(tmp, launcher);
|
|
38
|
+
} catch {
|
|
39
|
+
try { fs.unlinkSync(tmp); } catch { /* nothing to remove */ }
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mochiii",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "Mochiii: the terminal coding assistant that knows your codebase.",
|
|
4
|
+
"version": "1.2.2",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"homepage": "https://github.com/Rav-2007/codeterminal-core",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/Rav-2007/codeterminal-core.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/Rav-2007/codeterminal-core/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"ai",
|
|
16
|
+
"coding-assistant",
|
|
17
|
+
"terminal",
|
|
18
|
+
"cli",
|
|
19
|
+
"agent",
|
|
20
|
+
"code-search"
|
|
21
|
+
],
|
|
22
|
+
"bin": {
|
|
23
|
+
"mochiii": "bin/mochiii"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"postinstall": "node install.js"
|
|
27
|
+
},
|
|
28
|
+
"optionalDependencies": {
|
|
29
|
+
"@mochiii/linux-x64": "1.2.2",
|
|
30
|
+
"@mochiii/win32-x64": "1.2.2",
|
|
31
|
+
"@mochiii/darwin-arm64": "1.2.2",
|
|
32
|
+
"@mochiii/linux-arm64": "1.2.2",
|
|
33
|
+
"@mochiii/linux-x64-musl": "1.2.2",
|
|
34
|
+
"@mochiii/linux-arm64-musl": "1.2.2"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"bin/",
|
|
41
|
+
"install.js",
|
|
42
|
+
"platform.js",
|
|
43
|
+
"README.md",
|
|
44
|
+
"LICENSE",
|
|
45
|
+
"THIRD_PARTY_LICENSES.txt"
|
|
46
|
+
]
|
|
47
|
+
}
|
package/platform.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Which @mochiii/<platform> package carries the binary for this computer.
|
|
4
|
+
//
|
|
5
|
+
// Windows on ARM runs the x64 build under Windows' own emulation, so win32-x64
|
|
6
|
+
// declares both CPUs. Intel Macs have no package: onnxruntime, which runs the
|
|
7
|
+
// code-search model, publishes no Intel Mac build. Linux has two packages per
|
|
8
|
+
// CPU: the regular build, which needs glibc, and the static -musl build without
|
|
9
|
+
// code search, for Alpine and other musl systems; their `libc` fields let npm
|
|
10
|
+
// install only the one that fits.
|
|
11
|
+
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
// The platform packages, as npm/build.js makes them. Kept here, beside the
|
|
15
|
+
// mapping that reads it; build.js checks the two agree.
|
|
16
|
+
const SUPPORTED = ['linux-x64', 'linux-arm64', 'darwin-arm64', 'win32-x64', 'linux-x64-musl', 'linux-arm64-musl'];
|
|
17
|
+
|
|
18
|
+
// The packages that could carry this computer's binary, best first: on Linux
|
|
19
|
+
// the glibc build, then the musl one.
|
|
20
|
+
function platformPackages(platform = process.platform, arch = process.arch) {
|
|
21
|
+
if (platform === 'darwin' && arch !== 'arm64') {
|
|
22
|
+
throw new Error("Intel Macs aren't supported: onnxruntime, which runs Mochiii's code search, has no Intel Mac build.");
|
|
23
|
+
}
|
|
24
|
+
const cpu = platform === 'win32' ? 'x64' : arch;
|
|
25
|
+
const base = `${platform}-${cpu}`;
|
|
26
|
+
const names = [base, `${base}-musl`].filter((n) => SUPPORTED.includes(n));
|
|
27
|
+
if (names.length === 0) {
|
|
28
|
+
throw new Error(`there is no Mochiii build for ${platform}/${arch} (there are builds for ${SUPPORTED.join(', ')}).`);
|
|
29
|
+
}
|
|
30
|
+
return names.map((n) => `@mochiii/${n}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The package for this computer, given whether its libc is musl.
|
|
34
|
+
function platformPackage(platform = process.platform, arch = process.arch, musl = false) {
|
|
35
|
+
const names = platformPackages(platform, arch);
|
|
36
|
+
return (musl && names.find((n) => n.endsWith('-musl'))) || names[0];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// The binary inside a platform package, given that package's package.json.
|
|
40
|
+
function binaryPath(packageJSON, platform = process.platform) {
|
|
41
|
+
return path.join(path.dirname(packageJSON), 'bin', platform === 'win32' ? 'mochiii.exe' : 'mochiii');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Whether this Linux runs on musl rather than glibc. Asking costs about 10 ms,
|
|
45
|
+
// so it is asked only when npm installed both Linux packages, as an npm too old
|
|
46
|
+
// to read `libc` does.
|
|
47
|
+
function usesMusl() {
|
|
48
|
+
try {
|
|
49
|
+
return process.platform === 'linux' && !process.report.getReport().header.glibcVersionRuntime;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The installed binary for this computer, or an Error that says, to whoever
|
|
56
|
+
// typed `mochiii`, why there is none.
|
|
57
|
+
function findBinary() {
|
|
58
|
+
const found = [];
|
|
59
|
+
for (const pkg of platformPackages()) {
|
|
60
|
+
try {
|
|
61
|
+
found.push([pkg, binaryPath(require.resolve(`${pkg}/package.json`))]);
|
|
62
|
+
} catch (err) {
|
|
63
|
+
if (err.code !== 'MODULE_NOT_FOUND') throw err;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (found.length === 1) return found[0][1];
|
|
67
|
+
if (found.length > 1) {
|
|
68
|
+
const want = platformPackage(process.platform, process.arch, usesMusl());
|
|
69
|
+
return found.find(([pkg]) => pkg === want)[1];
|
|
70
|
+
}
|
|
71
|
+
throw new Error(`the package for this computer (${platformPackage(process.platform, process.arch, usesMusl())}) ` +
|
|
72
|
+
'is not installed. Reinstall with: npm install -g mochiii');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = { platformPackage, platformPackages, binaryPath, findBinary, usesMusl, SUPPORTED };
|