@kmugalkhod/lightcode 0.4.0 → 0.6.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 +20 -1
- package/cli.js +1575 -935
- package/lightcode.cjs +63 -18
- package/package.json +2 -1
- package/server.js +695 -238
package/lightcode.cjs
CHANGED
|
@@ -8,22 +8,67 @@ const path = require("path");
|
|
|
8
8
|
const fs = require("fs");
|
|
9
9
|
const os = require("os");
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
// Resolve a usable Bun (>= 1.3.0). Prefer the Bun bundled as a dependency of
|
|
12
|
+
// this package (so a plain `npm install -g` works with no separate Bun
|
|
13
|
+
// install), then fall back to a Bun already on PATH.
|
|
14
|
+
function isUsableBun(bunCmd) {
|
|
15
|
+
try {
|
|
16
|
+
const result = spawnSync(bunCmd, ["--version"], { encoding: "utf8" });
|
|
17
|
+
if (result.status !== 0 || !result.stdout) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const [major, minor] = result.stdout.trim().split(".").map(Number);
|
|
21
|
+
return major > 1 || (major === 1 && minor >= 3);
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function resolveBun() {
|
|
28
|
+
// __dirname is the realpath of this launcher even when invoked via npm's
|
|
29
|
+
// global bin symlink (process.argv[1] would be the symlink path on macOS/Linux).
|
|
30
|
+
const launcherDir = __dirname;
|
|
31
|
+
const candidates = [];
|
|
32
|
+
|
|
33
|
+
// Bun shipped as a dependency, inside this package's own node_modules. The
|
|
34
|
+
// npm "bun" package names its executable bin/bun.exe on EVERY platform
|
|
35
|
+
// (macOS and Linux included), so read the real path from its "bin" field
|
|
36
|
+
// rather than guessing a filename.
|
|
37
|
+
try {
|
|
38
|
+
const bunPkgPath = require.resolve("bun/package.json", {
|
|
39
|
+
paths: [launcherDir],
|
|
40
|
+
});
|
|
41
|
+
const bunDir = path.dirname(bunPkgPath);
|
|
42
|
+
const bin = JSON.parse(fs.readFileSync(bunPkgPath, "utf8")).bin;
|
|
43
|
+
const rel = typeof bin === "string" ? bin : bin && bin.bun;
|
|
44
|
+
if (rel) {
|
|
45
|
+
candidates.push(path.join(bunDir, rel));
|
|
46
|
+
}
|
|
47
|
+
} catch {}
|
|
48
|
+
|
|
49
|
+
// npm's bin shim (symlink) and conventional names, as fallbacks.
|
|
50
|
+
const shim = process.platform === "win32" ? "bun.exe" : "bun";
|
|
51
|
+
candidates.push(path.join(launcherDir, "node_modules", ".bin", shim));
|
|
52
|
+
candidates.push(path.join(launcherDir, "node_modules", "bun", "bin", "bun.exe"));
|
|
53
|
+
candidates.push(path.join(launcherDir, "node_modules", "bun", "bin", "bun"));
|
|
54
|
+
|
|
55
|
+
for (const candidate of candidates) {
|
|
56
|
+
if (fs.existsSync(candidate) && isUsableBun(candidate)) {
|
|
57
|
+
return candidate;
|
|
58
|
+
}
|
|
16
59
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
console.error("Lightcode requires Bun >= 1.3.0. Found: " + version);
|
|
22
|
-
console.error("Install the latest Bun from https://bun.sh");
|
|
23
|
-
process.exit(1);
|
|
60
|
+
|
|
61
|
+
// Fall back to a system Bun on PATH.
|
|
62
|
+
if (isUsableBun("bun")) {
|
|
63
|
+
return "bun";
|
|
24
64
|
}
|
|
25
|
-
|
|
26
|
-
|
|
65
|
+
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const bunPath = resolveBun();
|
|
70
|
+
if (!bunPath) {
|
|
71
|
+
console.error("Lightcode requires Bun >= 1.3.0, which could not be found.");
|
|
27
72
|
console.error("Install Bun from https://bun.sh or:");
|
|
28
73
|
console.error(" curl -fsSL https://bun.sh/install | bash");
|
|
29
74
|
console.error(" # on Windows (PowerShell):");
|
|
@@ -84,9 +129,9 @@ if (process.platform === "win32" && !process.env.NODE_EXTRA_CA_CERTS) {
|
|
|
84
129
|
}
|
|
85
130
|
}
|
|
86
131
|
|
|
87
|
-
// Get the directory of this launcher and find cli.js next to it
|
|
88
|
-
|
|
89
|
-
const cliPath = path.join(
|
|
132
|
+
// Get the directory of this launcher and find cli.js next to it. Use __dirname
|
|
133
|
+
// (realpath-resolved) so this works when run via npm's global bin symlink.
|
|
134
|
+
const cliPath = path.join(__dirname, "cli.js");
|
|
90
135
|
|
|
91
136
|
// Ensure cli.js exists
|
|
92
137
|
if (!fs.existsSync(cliPath)) {
|
|
@@ -97,7 +142,7 @@ if (!fs.existsSync(cliPath)) {
|
|
|
97
142
|
// Exec Bun with the cli.js script using spawnSync for proper argument handling
|
|
98
143
|
try {
|
|
99
144
|
const args = process.argv.slice(2);
|
|
100
|
-
const result = spawnSync(
|
|
145
|
+
const result = spawnSync(bunPath, [cliPath, ...args], {
|
|
101
146
|
stdio: "inherit",
|
|
102
147
|
env: process.env,
|
|
103
148
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kmugalkhod/lightcode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Lightcode — a personal AI coding agent with a terminal UI and local session storage.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"LICENSE"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"bun": "1.3.13",
|
|
21
22
|
"@ai-sdk/anthropic": "3.0.77",
|
|
22
23
|
"@ai-sdk/openai-compatible": "2.0.48",
|
|
23
24
|
"@ai-sdk/react": "3.0.184",
|