gm-kilo 2.0.173 → 2.0.174
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/hooks/pre-tool-use-hook.js +13 -5
- package/package.json +1 -1
|
@@ -81,8 +81,9 @@ const run = () => {
|
|
|
81
81
|
const langAliases = { js: 'nodejs', javascript: 'nodejs', ts: 'typescript', node: 'nodejs', py: 'python', sh: 'bash', shell: 'bash', zsh: 'bash', powershell: 'bash', ps1: 'bash', cmd: 'bash', browser: 'agent-browser', ab: 'agent-browser' };
|
|
82
82
|
const lang = langAliases[rawLang] || rawLang || detectLang(code);
|
|
83
83
|
const stripFooter = (s) => s.replace(/\n\[Running tools\][\s\S]*$/, '').trimEnd();
|
|
84
|
+
const IS_WIN = process.platform === 'win32';
|
|
84
85
|
const gmExecLangs = new Set(['go', 'rust', 'c', 'cpp', 'java']);
|
|
85
|
-
const langExts = { nodejs: 'mjs', typescript: 'ts', deno: 'ts', python: 'py', bash: 'ps1', go: 'go', rust: 'rs', c: 'c', cpp: 'cpp', java: 'java' };
|
|
86
|
+
const langExts = { nodejs: 'mjs', typescript: 'ts', deno: 'ts', python: 'py', bash: IS_WIN ? 'ps1' : 'sh', go: 'go', rust: 'rs', c: 'c', cpp: 'cpp', java: 'java' };
|
|
86
87
|
const spawnDirect = (bin, args, input) => {
|
|
87
88
|
const opts = { encoding: 'utf-8', timeout: 60000 };
|
|
88
89
|
if (cwd) opts.cwd = cwd;
|
|
@@ -114,11 +115,18 @@ const run = () => {
|
|
|
114
115
|
try {
|
|
115
116
|
let result;
|
|
116
117
|
if (lang === 'bash') {
|
|
117
|
-
const
|
|
118
|
+
const ext = IS_WIN ? 'ps1' : 'sh';
|
|
119
|
+
const shFile = path.join(os.tmpdir(), `gm-exec-${Date.now()}.${ext}`);
|
|
118
120
|
fs.writeFileSync(shFile, code, 'utf-8');
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
if (IS_WIN) {
|
|
122
|
+
result = spawnDirect('powershell', ['-NoProfile', '-NonInteractive', '-File', shFile]);
|
|
123
|
+
try { fs.unlinkSync(shFile); } catch (e) {}
|
|
124
|
+
if (!result || result.startsWith('[spawn error:')) result = runWithFile('bash', code);
|
|
125
|
+
} else {
|
|
126
|
+
result = spawnDirect('bash', [shFile]);
|
|
127
|
+
try { fs.unlinkSync(shFile); } catch (e) {}
|
|
128
|
+
if (!result || result.startsWith('[spawn error:')) result = runWithFile('bash', code);
|
|
129
|
+
}
|
|
122
130
|
} else if (lang === 'python') {
|
|
123
131
|
result = spawnDirect('python3', ['-c', code]);
|
|
124
132
|
if (!result || result.startsWith('[spawn error:')) result = spawnDirect('python', ['-c', code]);
|