@lemmy00/lemex 0.0.0-bootstrap → 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/README.md +32 -2
- package/bin/lemex.js +308 -0
- package/package.json +28 -6
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
# Lemex
|
|
1
|
+
# Lemex CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lemex is a local coding agent based on OpenAI Codex. It runs as `lemex` and stores its configuration in `~/.lemex`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
With Node.js 22 or later:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install -g @lemmy00/lemex
|
|
11
|
+
lemex setup
|
|
12
|
+
lemex
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Prebuilt packages support macOS and Linux on Intel/AMD and ARM64. On Windows, run these commands inside WSL2. npm installs only the native package for your computer; Rust, Python, and a compiler are not required.
|
|
16
|
+
|
|
17
|
+
`lemex setup` asks for an API key and endpoint. It installs the bundled configuration and model catalog without replacing existing files. The default endpoint is `https://inference.rcp.epfl.ch/v1`. You can use another compatible provider:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
lemex setup --base-url https://api.example.com/v1 --model your-model-id
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
To run a single task from your project:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
lemex exec "Explain this codebase"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Update with `npm install -g @lemmy00/lemex@latest`. Check your setup with `lemex doctor`.
|
|
30
|
+
|
|
31
|
+
See the [installation guide](https://github.com/Lemmy00/lemex/blob/main/docs/install.md) and [configuration guide](https://github.com/Lemmy00/lemex/blob/main/docs/config.md).
|
|
32
|
+
|
|
33
|
+
Licensed under Apache-2.0. External analytics and feedback reporting are removed; local logs and token usage are preserved.
|
package/bin/lemex.js
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Unified entry point for the Lemex CLI.
|
|
3
|
+
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { existsSync, readFileSync, realpathSync } from "fs";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { fileURLToPath } from "url";
|
|
9
|
+
|
|
10
|
+
// __dirname equivalent in ESM
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
const lemexPackageRoot = realpathSync(path.join(__dirname, ".."));
|
|
15
|
+
const lemexPackageName = JSON.parse(
|
|
16
|
+
readFileSync(path.join(lemexPackageRoot, "package.json"), "utf8"),
|
|
17
|
+
).name;
|
|
18
|
+
|
|
19
|
+
const PLATFORM_PACKAGE_BY_TARGET = {
|
|
20
|
+
"x86_64-unknown-linux-musl": "lemex-linux-x64",
|
|
21
|
+
"aarch64-unknown-linux-musl": "lemex-linux-arm64",
|
|
22
|
+
"x86_64-apple-darwin": "lemex-darwin-x64",
|
|
23
|
+
"aarch64-apple-darwin": "lemex-darwin-arm64",
|
|
24
|
+
"x86_64-pc-windows-msvc": "lemex-win32-x64",
|
|
25
|
+
"aarch64-pc-windows-msvc": "lemex-win32-arm64",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const { platform, arch } = process;
|
|
29
|
+
|
|
30
|
+
let targetTriple = null;
|
|
31
|
+
switch (platform) {
|
|
32
|
+
case "linux":
|
|
33
|
+
case "android":
|
|
34
|
+
switch (arch) {
|
|
35
|
+
case "x64":
|
|
36
|
+
targetTriple = "x86_64-unknown-linux-musl";
|
|
37
|
+
break;
|
|
38
|
+
case "arm64":
|
|
39
|
+
targetTriple = "aarch64-unknown-linux-musl";
|
|
40
|
+
break;
|
|
41
|
+
default:
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case "darwin":
|
|
46
|
+
switch (arch) {
|
|
47
|
+
case "x64":
|
|
48
|
+
targetTriple = "x86_64-apple-darwin";
|
|
49
|
+
break;
|
|
50
|
+
case "arm64":
|
|
51
|
+
targetTriple = "aarch64-apple-darwin";
|
|
52
|
+
break;
|
|
53
|
+
default:
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
case "win32":
|
|
58
|
+
switch (arch) {
|
|
59
|
+
case "x64":
|
|
60
|
+
targetTriple = "x86_64-pc-windows-msvc";
|
|
61
|
+
break;
|
|
62
|
+
case "arm64":
|
|
63
|
+
targetTriple = "aarch64-pc-windows-msvc";
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!targetTriple) {
|
|
74
|
+
throw new Error(`Unsupported platform: ${platform} (${arch})`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const platformPackage = PLATFORM_PACKAGE_BY_TARGET[targetTriple];
|
|
78
|
+
if (!platformPackage) {
|
|
79
|
+
throw new Error(`Unsupported target triple: ${targetTriple}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function findLemexExecutable() {
|
|
83
|
+
let vendorRoot;
|
|
84
|
+
try {
|
|
85
|
+
const packageJsonPath = require.resolve(`${platformPackage}/package.json`);
|
|
86
|
+
vendorRoot = path.join(path.dirname(packageJsonPath), "vendor");
|
|
87
|
+
} catch {
|
|
88
|
+
vendorRoot = path.join(__dirname, "..", "vendor");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const localTargets = [targetTriple];
|
|
92
|
+
if (targetTriple.endsWith("-unknown-linux-musl")) {
|
|
93
|
+
localTargets.push(targetTriple.replace(/-musl$/, "-gnu"));
|
|
94
|
+
}
|
|
95
|
+
for (const localTarget of localTargets) {
|
|
96
|
+
const lemexExecutable = path.join(
|
|
97
|
+
vendorRoot,
|
|
98
|
+
localTarget,
|
|
99
|
+
"bin",
|
|
100
|
+
process.platform === "win32" ? "lemex.exe" : "lemex",
|
|
101
|
+
);
|
|
102
|
+
if (existsSync(lemexExecutable)) {
|
|
103
|
+
return lemexExecutable;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const packageManager = detectPackageManager();
|
|
108
|
+
const updateCommand =
|
|
109
|
+
packageManager === "bun"
|
|
110
|
+
? "bun install -g @lemmy00/lemex@latest"
|
|
111
|
+
: packageManager === "pnpm"
|
|
112
|
+
? "pnpm add -g @lemmy00/lemex@latest"
|
|
113
|
+
: packageManager === "vite-plus"
|
|
114
|
+
? "vp install -g @lemmy00/lemex@latest"
|
|
115
|
+
: "npm install -g @lemmy00/lemex@latest";
|
|
116
|
+
throw new Error(
|
|
117
|
+
`Missing optional dependency ${platformPackage}. Reinstall Lemex: ${updateCommand}`,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const binaryPath = findLemexExecutable();
|
|
122
|
+
|
|
123
|
+
// Use an asynchronous spawn instead of spawnSync so that Node is able to
|
|
124
|
+
// respond to signals (e.g. Ctrl-C / SIGINT) while the native binary is
|
|
125
|
+
// executing. This allows us to forward those signals to the child process
|
|
126
|
+
// and guarantees that when either the child terminates or the parent
|
|
127
|
+
// receives a fatal signal, both processes exit in a predictable manner.
|
|
128
|
+
|
|
129
|
+
function isPnpmOwnedLemexInstall(nodeModulesDir) {
|
|
130
|
+
if (!existsSync(path.join(nodeModulesDir, ".modules.yaml"))) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
return [lemexPackageName].some((name) => {
|
|
136
|
+
const candidate = path.join(nodeModulesDir, name);
|
|
137
|
+
return (
|
|
138
|
+
existsSync(candidate) && realpathSync(candidate) === lemexPackageRoot
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
} catch {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function isVitePlusOwnedCodexInstall(packagesDir) {
|
|
147
|
+
if (path.basename(packagesDir) !== "packages") {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
const metadata = JSON.parse(
|
|
153
|
+
readFileSync(path.join(packagesDir, `${lemexPackageName}.json`), "utf8"),
|
|
154
|
+
);
|
|
155
|
+
if (metadata.name !== lemexPackageName) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Vite+ records the active global installation in packages/lemex.json.
|
|
160
|
+
// Older installs have no ID or append a #-prefixed ID to the package name;
|
|
161
|
+
// newer installs put the ID in a subdirectory of the package prefix.
|
|
162
|
+
const installId = metadata.installId || "";
|
|
163
|
+
const installDir = installId.startsWith("#")
|
|
164
|
+
? path.join(packagesDir, `${lemexPackageName}${installId}`)
|
|
165
|
+
: path.join(packagesDir, lemexPackageName, installId);
|
|
166
|
+
for (const nodeModulesDir of [
|
|
167
|
+
path.join(installDir, "lib", "node_modules"),
|
|
168
|
+
path.join(installDir, "node_modules"),
|
|
169
|
+
]) {
|
|
170
|
+
const packageRoot = path.join(nodeModulesDir, lemexPackageName);
|
|
171
|
+
if (
|
|
172
|
+
existsSync(packageRoot) &&
|
|
173
|
+
realpathSync(packageRoot) === lemexPackageRoot
|
|
174
|
+
) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
} catch {
|
|
179
|
+
// Missing or unreadable ownership metadata must not prevent Codex starting.
|
|
180
|
+
}
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Use heuristics to detect the package manager that was used to install Lemex
|
|
186
|
+
* in order to give the user a hint about how to update it.
|
|
187
|
+
*/
|
|
188
|
+
function detectPackageManager() {
|
|
189
|
+
// Package-manager ownership metadata can be several parents above the package.
|
|
190
|
+
// Search ancestors of both the canonical package root and lexical entrypoint
|
|
191
|
+
// because the package manager may link either path.
|
|
192
|
+
const entrypointDir = path.dirname(path.resolve(process.argv[1]));
|
|
193
|
+
for (const startDir of new Set([lemexPackageRoot, entrypointDir])) {
|
|
194
|
+
const filesystemRoot = path.parse(startDir).root;
|
|
195
|
+
for (
|
|
196
|
+
let currentDir = startDir;
|
|
197
|
+
currentDir !== filesystemRoot;
|
|
198
|
+
currentDir = path.dirname(currentDir)
|
|
199
|
+
) {
|
|
200
|
+
if (isVitePlusOwnedCodexInstall(currentDir)) {
|
|
201
|
+
return "vite-plus";
|
|
202
|
+
}
|
|
203
|
+
if (isPnpmOwnedLemexInstall(path.join(currentDir, "node_modules"))) {
|
|
204
|
+
return "pnpm";
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (isPnpmOwnedLemexInstall(path.join(filesystemRoot, "node_modules"))) {
|
|
209
|
+
return "pnpm";
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
214
|
+
if (/\bbun\//.test(userAgent)) {
|
|
215
|
+
return "bun";
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const execPath = process.env.npm_execpath || "";
|
|
219
|
+
if (execPath.includes("bun")) {
|
|
220
|
+
return "bun";
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (
|
|
224
|
+
__dirname.includes(".bun/install/global") ||
|
|
225
|
+
__dirname.includes(".bun\\install\\global")
|
|
226
|
+
) {
|
|
227
|
+
return "bun";
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return userAgent ? "npm" : null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const packageManager = detectPackageManager();
|
|
234
|
+
const packageManagerEnvVar =
|
|
235
|
+
packageManager === "bun"
|
|
236
|
+
? "LEMEX_MANAGED_BY_BUN"
|
|
237
|
+
: packageManager === "pnpm"
|
|
238
|
+
? "LEMEX_MANAGED_BY_PNPM"
|
|
239
|
+
: packageManager === "vite-plus"
|
|
240
|
+
? "LEMEX_MANAGED_BY_VITE_PLUS"
|
|
241
|
+
: "LEMEX_MANAGED_BY_NPM";
|
|
242
|
+
const env = {
|
|
243
|
+
...process.env,
|
|
244
|
+
LEMEX_MANAGED_PACKAGE_ROOT: lemexPackageRoot,
|
|
245
|
+
// The native doctor's upstream provenance check still uses this name.
|
|
246
|
+
CODEX_MANAGED_PACKAGE_ROOT: lemexPackageRoot,
|
|
247
|
+
};
|
|
248
|
+
delete env.LEMEX_MANAGED_BY_NPM;
|
|
249
|
+
delete env.LEMEX_MANAGED_BY_BUN;
|
|
250
|
+
delete env.LEMEX_MANAGED_BY_PNPM;
|
|
251
|
+
delete env.LEMEX_MANAGED_BY_VITE_PLUS;
|
|
252
|
+
env[packageManagerEnvVar] = "1";
|
|
253
|
+
|
|
254
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
255
|
+
stdio: "inherit",
|
|
256
|
+
env,
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
child.on("error", (err) => {
|
|
260
|
+
// Typically triggered when the binary is missing or not executable.
|
|
261
|
+
// Re-throwing here will terminate the parent with a non-zero exit code
|
|
262
|
+
// while still printing a helpful stack trace.
|
|
263
|
+
// eslint-disable-next-line no-console
|
|
264
|
+
console.error(err);
|
|
265
|
+
process.exit(1);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// Forward common termination signals to the child so that it shuts down
|
|
269
|
+
// gracefully. In the handler we temporarily disable the default behavior of
|
|
270
|
+
// exiting immediately; once the child has been signaled we simply wait for
|
|
271
|
+
// its exit event which will in turn terminate the parent (see below).
|
|
272
|
+
const forwardSignal = (signal) => {
|
|
273
|
+
if (child.killed) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
child.kill(signal);
|
|
278
|
+
} catch {
|
|
279
|
+
/* ignore */
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
["SIGINT", "SIGTERM", "SIGHUP"].forEach((sig) => {
|
|
284
|
+
process.on(sig, () => forwardSignal(sig));
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// When the child exits, mirror its termination reason in the parent so that
|
|
288
|
+
// shell scripts and other tooling observe the correct exit status.
|
|
289
|
+
// Wrap the lifetime of the child process in a Promise so that we can await
|
|
290
|
+
// its termination in a structured way. The Promise resolves with an object
|
|
291
|
+
// describing how the child exited: either via exit code or due to a signal.
|
|
292
|
+
const childResult = await new Promise((resolve) => {
|
|
293
|
+
child.on("exit", (code, signal) => {
|
|
294
|
+
if (signal) {
|
|
295
|
+
resolve({ type: "signal", signal });
|
|
296
|
+
} else {
|
|
297
|
+
resolve({ type: "code", exitCode: code ?? 1 });
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
if (childResult.type === "signal") {
|
|
303
|
+
// Re-emit the same signal so that the parent terminates with the expected
|
|
304
|
+
// semantics (this also sets the correct exit code of 128 + n).
|
|
305
|
+
process.kill(process.pid, childResult.signal);
|
|
306
|
+
} else {
|
|
307
|
+
process.exit(childResult.exitCode);
|
|
308
|
+
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemmy00/lemex",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Lemex CLI is a fork of the OpenAI Codex coding agent.",
|
|
3
5
|
"license": "Apache-2.0",
|
|
6
|
+
"bin": {
|
|
7
|
+
"lemex": "bin/lemex.js"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=22"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin/lemex.js",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"NOTICE"
|
|
17
|
+
],
|
|
4
18
|
"repository": {
|
|
5
19
|
"type": "git",
|
|
6
20
|
"url": "git+https://github.com/Lemmy00/lemex.git",
|
|
7
21
|
"directory": "codex-cli"
|
|
8
22
|
},
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"LICENSE",
|
|
14
|
-
"NOTICE"
|
|
23
|
+
"packageManager": "pnpm@10.34.5+sha512.a4ee05f2f73658255bd6a89859c065a45c28a57daefae2c893a168ee2b73168c37b91e83e57ea67654ad03f03031746430e8bce38e362e042605fb8abc80192e",
|
|
24
|
+
"os": [
|
|
25
|
+
"darwin",
|
|
26
|
+
"linux"
|
|
15
27
|
],
|
|
28
|
+
"cpu": [
|
|
29
|
+
"x64",
|
|
30
|
+
"arm64"
|
|
31
|
+
],
|
|
32
|
+
"optionalDependencies": {
|
|
33
|
+
"lemex-linux-x64": "npm:@lemmy00/lemex@0.1.0-linux-x64",
|
|
34
|
+
"lemex-linux-arm64": "npm:@lemmy00/lemex@0.1.0-linux-arm64",
|
|
35
|
+
"lemex-darwin-x64": "npm:@lemmy00/lemex@0.1.0-darwin-x64",
|
|
36
|
+
"lemex-darwin-arm64": "npm:@lemmy00/lemex@0.1.0-darwin-arm64"
|
|
37
|
+
},
|
|
16
38
|
"publishConfig": {
|
|
17
39
|
"access": "public",
|
|
18
40
|
"registry": "https://registry.npmjs.org/"
|