gm-kilo 2.0.39 → 2.0.42
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.mjs +17 -34
- package/package.json +1 -1
package/gm.mjs
CHANGED
|
@@ -1,49 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { readFileSync, existsSync } from 'fs';
|
|
2
|
+
import { join, dirname } from 'path';
|
|
3
3
|
import { exec } from 'child_process';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
const pluginDir = __dirname;
|
|
9
|
-
let agentRules = '';
|
|
10
|
-
let thornsPromise = null;
|
|
11
|
-
let thornsOutput = '';
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
7
|
|
|
8
|
+
export default async ({ directory }) => {
|
|
9
|
+
const agentsDir = join(__dirname, 'agents');
|
|
13
10
|
const loadAgentRules = () => {
|
|
14
|
-
|
|
15
|
-
const agentMd = path.join(pluginDir, 'agents', 'gm.md');
|
|
16
|
-
try { agentRules = fs.readFileSync(agentMd, 'utf-8'); } catch (e) {}
|
|
17
|
-
return agentRules;
|
|
11
|
+
try { return readFileSync(join(agentsDir, 'gm.md'), 'utf-8'); } catch (e) { return ''; }
|
|
18
12
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
encoding: 'utf-8', cwd: directory, timeout: 180000
|
|
26
|
-
}, (err, stdout) => {
|
|
27
|
-
thornsOutput = err ? '' : (stdout || '').trim();
|
|
28
|
-
resolve(thornsOutput);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
return thornsPromise;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const prdFile = path.join(directory, '.prd');
|
|
35
|
-
|
|
13
|
+
const runThorns = () => new Promise((resolve) => {
|
|
14
|
+
exec('bun x mcp-thorns@latest', {
|
|
15
|
+
encoding: 'utf-8', cwd: directory, timeout: 180000
|
|
16
|
+
}, (err, stdout) => resolve(err ? '' : (stdout || '').trim()));
|
|
17
|
+
});
|
|
18
|
+
const prdFile = join(directory, '.prd');
|
|
36
19
|
return {
|
|
37
20
|
'experimental.chat.system.transform': async (input, output) => {
|
|
38
21
|
const rules = loadAgentRules();
|
|
39
|
-
const prd =
|
|
22
|
+
const prd = existsSync(prdFile) ? readFileSync(prdFile, 'utf-8').trim() : '';
|
|
40
23
|
let content = rules || '';
|
|
41
24
|
if (prd) content += '\n\nPENDING WORK (.prd):\n' + prd;
|
|
42
|
-
// Inject thorns only on the first API call of a conversation (no assistant messages yet)
|
|
43
25
|
const msgs = input?.messages || [];
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
26
|
+
const lastMsg = msgs.length > 0 ? msgs[msgs.length - 1] : null;
|
|
27
|
+
const hasNewUserPrompt = !lastMsg || lastMsg.role === 'user';
|
|
28
|
+
if (hasNewUserPrompt) {
|
|
29
|
+
const thorns = await runThorns();
|
|
47
30
|
if (thorns) content += '\n\n=== Repository Analysis (mcp-thorns) ===\n' + thorns;
|
|
48
31
|
}
|
|
49
32
|
if (content) output.system.push(content);
|