gm-kilo 2.0.40 → 2.0.43
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 +11 -19
- package/package.json +1 -1
package/gm.mjs
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
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
|
-
|
|
9
|
-
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
|
|
8
|
+
export default async ({ directory }) => {
|
|
9
|
+
const agentsDir = join(__dirname, 'agents');
|
|
10
10
|
const loadAgentRules = () => {
|
|
11
|
-
|
|
12
|
-
try { return fs.readFileSync(agentMd, 'utf-8'); } catch (e) { return ''; }
|
|
11
|
+
try { return readFileSync(join(agentsDir, 'gm.md'), 'utf-8'); } catch (e) { return ''; }
|
|
13
12
|
};
|
|
14
|
-
|
|
15
13
|
const runThorns = () => new Promise((resolve) => {
|
|
16
14
|
exec('bun x mcp-thorns@latest', {
|
|
17
15
|
encoding: 'utf-8', cwd: directory, timeout: 180000
|
|
18
16
|
}, (err, stdout) => resolve(err ? '' : (stdout || '').trim()));
|
|
19
17
|
});
|
|
20
|
-
|
|
21
18
|
const runCodeSearch = (query) => new Promise((resolve) => {
|
|
22
19
|
const q = query.replace(/"/g, '\\"').substring(0, 200);
|
|
23
20
|
exec('bun x codebasesearch@latest "' + q + '"', {
|
|
24
|
-
encoding: 'utf-8', cwd: directory, timeout:
|
|
21
|
+
encoding: 'utf-8', cwd: directory, timeout: 300000
|
|
25
22
|
}, (err, stdout) => {
|
|
26
23
|
if (err) return resolve('');
|
|
27
24
|
const lines = (stdout || '').split('\n');
|
|
@@ -29,7 +26,6 @@ export default async ({ project, client, $, directory, worktree }) => {
|
|
|
29
26
|
resolve(start >= 0 ? lines.slice(start).join('\n').trim() : (stdout || '').trim());
|
|
30
27
|
});
|
|
31
28
|
});
|
|
32
|
-
|
|
33
29
|
const getLastUserMessage = (msgs) => {
|
|
34
30
|
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
35
31
|
const m = msgs[i];
|
|
@@ -41,17 +37,13 @@ export default async ({ project, client, $, directory, worktree }) => {
|
|
|
41
37
|
}
|
|
42
38
|
return '';
|
|
43
39
|
};
|
|
44
|
-
|
|
45
|
-
const prdFile = path.join(directory, '.prd');
|
|
46
|
-
|
|
40
|
+
const prdFile = join(directory, '.prd');
|
|
47
41
|
return {
|
|
48
42
|
'experimental.chat.system.transform': async (input, output) => {
|
|
49
43
|
const rules = loadAgentRules();
|
|
50
|
-
const prd =
|
|
44
|
+
const prd = existsSync(prdFile) ? readFileSync(prdFile, 'utf-8').trim() : '';
|
|
51
45
|
let content = rules || '';
|
|
52
46
|
if (prd) content += '\n\nPENDING WORK (.prd):\n' + prd;
|
|
53
|
-
// On every user prompt: run thorns fresh + codebasesearch
|
|
54
|
-
// Skip if last message is from assistant (no new user prompt, e.g. tool result inject)
|
|
55
47
|
const msgs = input?.messages || [];
|
|
56
48
|
const lastMsg = msgs.length > 0 ? msgs[msgs.length - 1] : null;
|
|
57
49
|
const hasNewUserPrompt = !lastMsg || lastMsg.role === 'user';
|
|
@@ -62,7 +54,7 @@ export default async ({ project, client, $, directory, worktree }) => {
|
|
|
62
54
|
userQuery ? runCodeSearch(userQuery) : Promise.resolve('')
|
|
63
55
|
]);
|
|
64
56
|
if (thorns) content += '\n\n=== Repository Analysis (mcp-thorns) ===\n' + thorns;
|
|
65
|
-
if (search) content += '\n\n=== Semantic
|
|
57
|
+
if (search) content += '\n\n=== Semantic Code Search Results ===\n' + search;
|
|
66
58
|
}
|
|
67
59
|
if (content) output.system.push(content);
|
|
68
60
|
}
|