gm-oc 2.0.40 → 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.
Files changed (3) hide show
  1. package/cli.js +8 -0
  2. package/gm.mjs +13 -43
  3. package/package.json +1 -1
package/cli.js CHANGED
@@ -44,6 +44,14 @@ try {
44
44
 
45
45
  filesToCopy.forEach(([src, dst]) => copyRecursive(path.join(srcDir, src), path.join(destDir, dst)));
46
46
 
47
+ // Also write to plugins/gm-oc.mjs - the actual file OpenCode loads
48
+ const pluginsDir = path.join(destDir, 'plugins');
49
+ fs.mkdirSync(pluginsDir, { recursive: true });
50
+ const gmMjsSrc = path.join(srcDir, 'gm.mjs');
51
+ if (fs.existsSync(gmMjsSrc)) {
52
+ fs.copyFileSync(gmMjsSrc, path.join(pluginsDir, 'gm-oc.mjs'));
53
+ }
54
+
47
55
  const destPath = process.platform === 'win32'
48
56
  ? destDir.replace(/\\/g, '/')
49
57
  : destDir;
package/gm.mjs CHANGED
@@ -1,15 +1,15 @@
1
- import fs from 'fs';
2
- import path from 'path';
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
- export default async ({ project, client, $, directory, worktree }) => {
8
- const pluginDir = __dirname;
9
- let agentRules = '';
6
+ const __dirname = dirname(fileURLToPath(import.meta.url));
7
+
8
+ export async function GmPlugin({ directory }) {
9
+ const agentsDir = join(__dirname, '..', 'agents');
10
+
10
11
  const loadAgentRules = () => {
11
- const agentMd = path.join(pluginDir, 'agents', 'gm.md');
12
- try { return fs.readFileSync(agentMd, 'utf-8'); } catch (e) { return ''; }
12
+ try { return readFileSync(join(agentsDir, 'gm.md'), 'utf-8'); } catch (e) { return ''; }
13
13
  };
14
14
 
15
15
  const runThorns = () => new Promise((resolve) => {
@@ -18,53 +18,23 @@ export default async ({ project, client, $, directory, worktree }) => {
18
18
  }, (err, stdout) => resolve(err ? '' : (stdout || '').trim()));
19
19
  });
20
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
- });
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 '';
43
- };
44
-
45
- const prdFile = path.join(directory, '.prd');
21
+ const prdFile = join(directory, '.prd');
46
22
 
47
23
  return {
48
24
  'experimental.chat.system.transform': async (input, output) => {
49
25
  const rules = loadAgentRules();
50
- const prd = fs.existsSync(prdFile) ? fs.readFileSync(prdFile, 'utf-8').trim() : '';
26
+ const prd = existsSync(prdFile) ? readFileSync(prdFile, 'utf-8').trim() : '';
51
27
  let content = rules || '';
52
28
  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)
29
+ // Run thorns fresh on every user prompt (skip during tool-result-only calls)
55
30
  const msgs = input?.messages || [];
56
31
  const lastMsg = msgs.length > 0 ? msgs[msgs.length - 1] : null;
57
32
  const hasNewUserPrompt = !lastMsg || lastMsg.role === 'user';
58
33
  if (hasNewUserPrompt) {
59
- const userQuery = getLastUserMessage(msgs);
60
- const [thorns, search] = await Promise.all([
61
- runThorns(),
62
- userQuery ? runCodeSearch(userQuery) : Promise.resolve('')
63
- ]);
34
+ const thorns = await runThorns();
64
35
  if (thorns) content += '\n\n=== Repository Analysis (mcp-thorns) ===\n' + thorns;
65
- if (search) content += '\n\n=== Semantic code search results ===\n' + search;
66
36
  }
67
37
  if (content) output.system.push(content);
68
38
  }
69
39
  };
70
- };
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-oc",
3
- "version": "2.0.40",
3
+ "version": "2.0.42",
4
4
  "description": "State machine agent with hooks, skills, and automated git enforcement",
5
5
  "author": "AnEntrypoint",
6
6
  "license": "MIT",