gm-kilo 2.0.38 → 2.0.40
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 +40 -22
- package/package.json +1 -1
package/gm.mjs
CHANGED
|
@@ -7,29 +7,39 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
7
7
|
export default async ({ project, client, $, directory, worktree }) => {
|
|
8
8
|
const pluginDir = __dirname;
|
|
9
9
|
let agentRules = '';
|
|
10
|
-
let thornsPromise = null;
|
|
11
|
-
let thornsOutput = '';
|
|
12
|
-
let thornsInjected = false;
|
|
13
|
-
|
|
14
10
|
const loadAgentRules = () => {
|
|
15
|
-
if (agentRules) return agentRules;
|
|
16
11
|
const agentMd = path.join(pluginDir, 'agents', 'gm.md');
|
|
17
|
-
try {
|
|
18
|
-
return agentRules;
|
|
12
|
+
try { return fs.readFileSync(agentMd, 'utf-8'); } catch (e) { return ''; }
|
|
19
13
|
};
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
const runThorns = () => new Promise((resolve) => {
|
|
16
|
+
exec('bun x mcp-thorns@latest', {
|
|
17
|
+
encoding: 'utf-8', cwd: directory, timeout: 180000
|
|
18
|
+
}, (err, stdout) => resolve(err ? '' : (stdout || '').trim()));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const runCodeSearch = (query) => new Promise((resolve) => {
|
|
22
|
+
const q = query.replace(/"/g, '\\"').substring(0, 200);
|
|
23
|
+
exec('bun x codebasesearch@latest "' + q + '"', {
|
|
24
|
+
encoding: 'utf-8', cwd: directory, timeout: 55000
|
|
25
|
+
}, (err, stdout) => {
|
|
26
|
+
if (err) return resolve('');
|
|
27
|
+
const lines = (stdout || '').split('\n');
|
|
28
|
+
const start = lines.findIndex(l => l.includes('Searching for:'));
|
|
29
|
+
resolve(start >= 0 ? lines.slice(start).join('\n').trim() : (stdout || '').trim());
|
|
31
30
|
});
|
|
32
|
-
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const getLastUserMessage = (msgs) => {
|
|
34
|
+
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
35
|
+
const m = msgs[i];
|
|
36
|
+
if (m.role === 'user') {
|
|
37
|
+
const parts = Array.isArray(m.content) ? m.content : [m.content];
|
|
38
|
+
const text = parts.map(p => typeof p === 'string' ? p : (p?.text || '')).join(' ').trim();
|
|
39
|
+
if (text) return text;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return '';
|
|
33
43
|
};
|
|
34
44
|
|
|
35
45
|
const prdFile = path.join(directory, '.prd');
|
|
@@ -40,11 +50,19 @@ export default async ({ project, client, $, directory, worktree }) => {
|
|
|
40
50
|
const prd = fs.existsSync(prdFile) ? fs.readFileSync(prdFile, 'utf-8').trim() : '';
|
|
41
51
|
let content = rules || '';
|
|
42
52
|
if (prd) content += '\n\nPENDING WORK (.prd):\n' + prd;
|
|
43
|
-
//
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
const msgs = input?.messages || [];
|
|
56
|
+
const lastMsg = msgs.length > 0 ? msgs[msgs.length - 1] : null;
|
|
57
|
+
const hasNewUserPrompt = !lastMsg || lastMsg.role === 'user';
|
|
58
|
+
if (hasNewUserPrompt) {
|
|
59
|
+
const userQuery = getLastUserMessage(msgs);
|
|
60
|
+
const [thorns, search] = await Promise.all([
|
|
61
|
+
runThorns(),
|
|
62
|
+
userQuery ? runCodeSearch(userQuery) : Promise.resolve('')
|
|
63
|
+
]);
|
|
47
64
|
if (thorns) content += '\n\n=== Repository Analysis (mcp-thorns) ===\n' + thorns;
|
|
65
|
+
if (search) content += '\n\n=== Semantic code search results ===\n' + search;
|
|
48
66
|
}
|
|
49
67
|
if (content) output.system.push(content);
|
|
50
68
|
}
|