gm-kilo 2.0.39 → 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.
Files changed (2) hide show
  1. package/gm.mjs +39 -21
  2. package/package.json +1 -1
package/gm.mjs CHANGED
@@ -7,28 +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
-
13
10
  const loadAgentRules = () => {
14
- if (agentRules) return agentRules;
15
11
  const agentMd = path.join(pluginDir, 'agents', 'gm.md');
16
- try { agentRules = fs.readFileSync(agentMd, 'utf-8'); } catch (e) {}
17
- return agentRules;
12
+ try { return fs.readFileSync(agentMd, 'utf-8'); } catch (e) { return ''; }
18
13
  };
19
14
 
20
- // Start thorns in background immediately on plugin load
21
- const startThorns = () => {
22
- if (thornsPromise) return thornsPromise;
23
- thornsPromise = new Promise((resolve) => {
24
- exec('bun x mcp-thorns@latest', {
25
- encoding: 'utf-8', cwd: directory, timeout: 180000
26
- }, (err, stdout) => {
27
- thornsOutput = err ? '' : (stdout || '').trim();
28
- resolve(thornsOutput);
29
- });
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());
30
30
  });
31
- return thornsPromise;
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 '';
32
43
  };
33
44
 
34
45
  const prdFile = path.join(directory, '.prd');
@@ -39,12 +50,19 @@ export default async ({ project, client, $, directory, worktree }) => {
39
50
  const prd = fs.existsSync(prdFile) ? fs.readFileSync(prdFile, 'utf-8').trim() : '';
40
51
  let content = rules || '';
41
52
  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)
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)
43
55
  const msgs = input?.messages || [];
44
- const isFirstCall = !msgs.some(m => m.role === 'assistant');
45
- if (isFirstCall) {
46
- const thorns = await startThorns();
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-kilo",
3
- "version": "2.0.39",
3
+ "version": "2.0.40",
4
4
  "description": "State machine agent with hooks, skills, and automated git enforcement",
5
5
  "author": "AnEntrypoint",
6
6
  "license": "MIT",