@krmxd/onegpt 0.0.0-beta → 0.0.1-beta
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/bin/ogpt.js +7 -0
- package/package.json +1 -4
- package/src/tools.js +50 -2
package/bin/ogpt.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
+
const [maj] = process.versions.node.split(".").map(Number);
|
|
5
|
+
if (maj < 18) {
|
|
6
|
+
console.error(`OGPT needs Node.js 18+ - you are running ${process.versions.node}.`);
|
|
7
|
+
console.error("Update Node, then try again: https://nodejs.org");
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
|
|
4
11
|
const { CLI } = require("../src/cli");
|
|
5
12
|
const { getConfig } = require("../src/config");
|
|
6
13
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krmxd/onegpt",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-beta",
|
|
4
4
|
"description": "OGPT - AI coding assistant for the terminal with a built-in local engine",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -21,9 +21,6 @@
|
|
|
21
21
|
],
|
|
22
22
|
"author": "OGPT Team",
|
|
23
23
|
"license": "MIT",
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"ollama": "^0.5.0"
|
|
26
|
-
},
|
|
27
24
|
"engines": {
|
|
28
25
|
"node": ">=18.0.0"
|
|
29
26
|
},
|
package/src/tools.js
CHANGED
|
@@ -397,8 +397,35 @@ async function runShell(command, cwd = ".", timeout = 30000) {
|
|
|
397
397
|
|
|
398
398
|
// Run code with an interpreter directly (argv, never a shell) so user code
|
|
399
399
|
// can't be mangled by quoting and packages install safely.
|
|
400
|
+
const _BIN_FALLBACKS = {
|
|
401
|
+
node: ["/usr/bin/node", "/usr/local/bin/node",
|
|
402
|
+
"/data/data/com.termux/files/usr/bin/node"],
|
|
403
|
+
python3: ["/usr/bin/python3", "/usr/local/bin/python3",
|
|
404
|
+
"/data/data/com.termux/files/usr/bin/python3"],
|
|
405
|
+
python: ["/usr/bin/python", "/data/data/com.termux/files/usr/bin/python"],
|
|
406
|
+
pip: ["/usr/bin/pip", "/usr/local/bin/pip",
|
|
407
|
+
"/data/data/com.termux/files/usr/bin/pip"],
|
|
408
|
+
pip3: ["/usr/bin/pip3", "/data/data/com.termux/files/usr/bin/pip3"],
|
|
409
|
+
npm: ["/usr/bin/npm", "/usr/local/bin/npm",
|
|
410
|
+
"/data/data/com.termux/files/usr/bin/npm"],
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
function resolveBin(bin) {
|
|
414
|
+
// spawnSync needs an absolute path when PATH is stripped in some
|
|
415
|
+
// sandboxes/Termux sessions - probe fallbacks before giving up.
|
|
416
|
+
try {
|
|
417
|
+
const found = require("child_process").execSync(
|
|
418
|
+
`command -v ${bin} 2>/dev/null`, { encoding: "utf-8", timeout: 3000 }).trim();
|
|
419
|
+
if (found) return found;
|
|
420
|
+
} catch {}
|
|
421
|
+
for (const p of _BIN_FALLBACKS[bin] || []) {
|
|
422
|
+
try { if (fs.existsSync(p)) return p; } catch {}
|
|
423
|
+
}
|
|
424
|
+
return bin; // let spawnSync produce its own ENOENT
|
|
425
|
+
}
|
|
426
|
+
|
|
400
427
|
function runInterpreter(bin, argv, cwd, timeout) {
|
|
401
|
-
const r = spawnSync(bin, argv, {
|
|
428
|
+
const r = spawnSync(resolveBin(bin), argv, {
|
|
402
429
|
cwd: path.resolve(cwd || "."), timeout: timeout || 30000,
|
|
403
430
|
encoding: "utf-8", maxBuffer: 16 * 1024 * 1024,
|
|
404
431
|
env: { ...process.env, PYTHONDONTWRITEBYTECODE: "1" },
|
|
@@ -786,6 +813,9 @@ const IMPLEMENTATIONS = {
|
|
|
786
813
|
if (!code.trim() && !file) {
|
|
787
814
|
return new ToolResult("", "Provide 'code' (Python source to run) or 'path' (a .py file)", false);
|
|
788
815
|
}
|
|
816
|
+
if (file && !fs.existsSync(path.resolve(args.cwd || ".", file))) {
|
|
817
|
+
return new ToolResult("", `File not found: ${file} (use a path relative to your workspace)`, false);
|
|
818
|
+
}
|
|
789
819
|
const argv = file ? [file] : ["-c", code];
|
|
790
820
|
return runInterpreter("python3", argv, args.cwd || ".", parseInt(args.timeout || 60, 10) * 1000);
|
|
791
821
|
},
|
|
@@ -796,7 +826,25 @@ const IMPLEMENTATIONS = {
|
|
|
796
826
|
if (!code.trim() && !file) {
|
|
797
827
|
return new ToolResult("", "Provide 'code' (JavaScript source to run) or 'path' (a .js file)", false);
|
|
798
828
|
}
|
|
799
|
-
|
|
829
|
+
let argv;
|
|
830
|
+
if (file) {
|
|
831
|
+
if (!fs.existsSync(path.resolve(args.cwd || ".", file))) {
|
|
832
|
+
return new ToolResult("", `File not found: ${file} (use a path relative to your workspace)`, false);
|
|
833
|
+
}
|
|
834
|
+
argv = [file];
|
|
835
|
+
} else if (/^\s*import\s|^\s*export\s|await\s+import\(/m.test(code)) {
|
|
836
|
+
// ESM code can't run through -e; stage it as a temp .mjs module.
|
|
837
|
+
const tmp = path.join(os.tmpdir(), `ogpt-run-${Date.now()}.mjs`);
|
|
838
|
+
fs.writeFileSync(tmp, code);
|
|
839
|
+
try {
|
|
840
|
+
return runInterpreter("node", [tmp], args.cwd || ".",
|
|
841
|
+
parseInt(args.timeout || 60, 10) * 1000);
|
|
842
|
+
} finally {
|
|
843
|
+
try { fs.unlinkSync(tmp); } catch {}
|
|
844
|
+
}
|
|
845
|
+
} else {
|
|
846
|
+
argv = ["-e", code];
|
|
847
|
+
}
|
|
800
848
|
return runInterpreter("node", argv, args.cwd || ".", parseInt(args.timeout || 60, 10) * 1000);
|
|
801
849
|
},
|
|
802
850
|
|