gm-oc 2.0.374 → 2.0.376
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/gm-oc.mjs +13 -11
- package/lang/browser.js +37 -0
- package/package.json +1 -1
package/gm-oc.mjs
CHANGED
|
@@ -27,17 +27,19 @@ function safePrintf(s) {
|
|
|
27
27
|
function stripFooter(s) { return s ? s.replace(/\n\[Running tools\][\s\S]*$/, '').trimEnd() : ''; }
|
|
28
28
|
|
|
29
29
|
function tryLangPlugin(lang, code, cwd) {
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
const projectDir = cwd || process.cwd();
|
|
31
|
+
const candidates = [join(projectDir, 'lang', lang+'.js'), join(__dirname, '..', 'lang', lang+'.js')];
|
|
32
|
+
for (const langPluginFile of candidates) {
|
|
33
|
+
if (!existsSync(langPluginFile)) continue;
|
|
34
|
+
try {
|
|
35
|
+
const plugin = require(langPluginFile);
|
|
36
|
+
if (plugin && plugin.exec && plugin.exec.run) {
|
|
37
|
+
const result = plugin.exec.run(code, projectDir);
|
|
38
|
+
if (result && typeof result.then === 'function') continue;
|
|
39
|
+
return String(result === undefined ? '' : result);
|
|
40
|
+
}
|
|
41
|
+
} catch(e) {}
|
|
42
|
+
}
|
|
41
43
|
return null;
|
|
42
44
|
}
|
|
43
45
|
|
package/lang/browser.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const { spawnSync, execSync } = require('child_process');
|
|
5
|
+
const fsSync = require('fs');
|
|
6
|
+
|
|
7
|
+
function findPlugkit() {
|
|
8
|
+
try { execSync('plugkit --version', { encoding: 'utf-8', timeout: 3000 }); return 'plugkit'; } catch (_) {}
|
|
9
|
+
const candidates = [
|
|
10
|
+
path.join(os.homedir(), '.local', 'bin', 'plugkit'),
|
|
11
|
+
path.join(os.homedir(), '.claude', 'plugins', 'marketplaces', 'gm-cc', 'bin', 'plugkit'),
|
|
12
|
+
];
|
|
13
|
+
for (const p of candidates) {
|
|
14
|
+
if (fsSync.existsSync(p)) return p;
|
|
15
|
+
}
|
|
16
|
+
return 'plugkit';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
id: 'browser',
|
|
21
|
+
exec: {
|
|
22
|
+
run(code, cwd) {
|
|
23
|
+
const tmp = path.join(os.tmpdir(), 'gm-browser-' + Date.now() + '.js');
|
|
24
|
+
try {
|
|
25
|
+
fsSync.writeFileSync(tmp, code, 'utf-8');
|
|
26
|
+
const plugkit = findPlugkit();
|
|
27
|
+
const opts = { encoding: 'utf-8', timeout: 120000, ...(cwd && { cwd }) };
|
|
28
|
+
const r = spawnSync(plugkit, ['exec', '--lang', 'browser', '--file', tmp], opts);
|
|
29
|
+
const out = (r.stdout || '').trimEnd();
|
|
30
|
+
const err = (r.stderr || '').trimEnd();
|
|
31
|
+
return out && err ? out + '\n[stderr]\n' + err : out || err || '(no output)';
|
|
32
|
+
} finally {
|
|
33
|
+
try { fsSync.unlinkSync(tmp); } catch (_) {}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|