gm-oc 2.0.22 → 2.0.23

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 (5) hide show
  1. package/cli.js +27 -40
  2. package/gm-oc.mjs +25 -0
  3. package/gm.js +1 -37
  4. package/index.js +1 -1
  5. package/package.json +2 -1
package/cli.js CHANGED
@@ -2,44 +2,18 @@
2
2
  const fs = require('fs');
3
3
  const path = require('path');
4
4
  const os = require('os');
5
- const { execSync } = require('child_process');
6
5
 
7
6
  const homeDir = process.env.HOME || process.env.USERPROFILE || os.homedir();
8
- const destDir = process.platform === 'win32'
9
- ? path.join(homeDir, 'AppData', 'Roaming', 'opencode', 'plugin')
10
- : path.join(homeDir, '.config', 'opencode', 'plugin');
11
-
7
+ const ocConfigDir = path.join(homeDir, '.config', 'opencode');
12
8
  const srcDir = __dirname;
13
- const isUpgrade = fs.existsSync(destDir);
9
+ const pluginMarker = path.join(ocConfigDir, 'plugins', 'gm-oc.mjs');
10
+ const isUpgrade = fs.existsSync(pluginMarker);
14
11
 
15
12
  console.log(isUpgrade ? 'Upgrading gm-oc...' : 'Installing gm-oc...');
16
13
 
17
14
  try {
18
- // Clean all managed files/dirs except node_modules to remove stale files
19
- if (fs.existsSync(destDir)) {
20
- for (const entry of fs.readdirSync(destDir)) {
21
- if (entry !== 'node_modules' && entry !== 'package-lock.json') {
22
- fs.rmSync(path.join(destDir, entry), { recursive: true, force: true });
23
- }
24
- }
25
- }
26
- fs.mkdirSync(destDir, { recursive: true });
27
-
28
- const filesToCopy = [
29
- ['agents', 'agents'],
30
- ['hooks', 'hooks'],
31
- ['skills', 'skills'],
32
- ['index.js', 'index.js'],
33
- ['gm.js', 'gm.js'],
34
- ['opencode.json', 'opencode.json'],
35
- ['package.json', 'package.json'],
36
- ['.mcp.json', '.mcp.json'],
37
- ['README.md', 'README.md'],
38
- ['LICENSE', 'LICENSE'],
39
- ['CONTRIBUTING.md', 'CONTRIBUTING.md'],
40
- ['.gitignore', '.gitignore'],
41
- ['.editorconfig', '.editorconfig']
42
- ];
15
+ fs.mkdirSync(path.join(ocConfigDir, 'plugins'), { recursive: true });
16
+ fs.mkdirSync(path.join(ocConfigDir, 'agents'), { recursive: true });
43
17
 
44
18
  function copyRecursive(src, dst) {
45
19
  if (!fs.existsSync(src)) return;
@@ -51,19 +25,32 @@ try {
51
25
  }
52
26
  }
53
27
 
54
- filesToCopy.forEach(([src, dst]) => copyRecursive(path.join(srcDir, src), path.join(destDir, dst)));
28
+ // Install ESM plugin for opencode auto-loading from plugins directory
29
+ fs.copyFileSync(path.join(srcDir, 'gm-oc.mjs'), path.join(ocConfigDir, 'plugins', 'gm-oc.mjs'));
30
+
31
+ // Copy agents and skills into opencode config dir
32
+ copyRecursive(path.join(srcDir, 'agents'), path.join(ocConfigDir, 'agents'));
33
+ copyRecursive(path.join(srcDir, 'skills'), path.join(ocConfigDir, 'skills'));
55
34
 
35
+ // Write/update opencode.json — merge MCP from package, set default_agent
36
+ const ocJsonPath = path.join(ocConfigDir, 'opencode.json');
37
+ let ocConfig = {};
38
+ try { ocConfig = JSON.parse(fs.readFileSync(ocJsonPath, 'utf-8')); } catch (e) {}
56
39
  try {
57
- console.log('Installing dependencies...');
58
- execSync('npm install', { cwd: destDir, stdio: 'inherit' });
59
- } catch (e) {
60
- console.warn('npm install encountered an issue, but installation may still work');
40
+ const pkgConfig = JSON.parse(fs.readFileSync(path.join(srcDir, 'opencode.json'), 'utf-8'));
41
+ if (pkgConfig.mcp) ocConfig.mcp = Object.assign({}, pkgConfig.mcp, ocConfig.mcp);
42
+ } catch (e) {}
43
+ ocConfig.default_agent = 'gm';
44
+ fs.writeFileSync(ocJsonPath, JSON.stringify(ocConfig, null, 2) + '\n');
45
+
46
+ // Clean old AppData install location (no longer used by opencode)
47
+ const oldDir = process.platform === 'win32'
48
+ ? path.join(homeDir, 'AppData', 'Roaming', 'opencode', 'plugin') : null;
49
+ if (oldDir && fs.existsSync(oldDir)) {
50
+ try { fs.rmSync(oldDir, { recursive: true, force: true }); } catch (e) {}
61
51
  }
62
52
 
63
- const destPath = process.platform === 'win32'
64
- ? destDir.replace(/\\/g, '/')
65
- : destDir;
66
- console.log(`✓ gm-oc ${isUpgrade ? 'upgraded' : 'installed'} to ${destPath}`);
53
+ console.log(`✓ gm-oc ${isUpgrade ? 'upgraded' : 'installed'} to ${ocConfigDir}`);
67
54
  console.log('Restart OpenCode to activate.');
68
55
  } catch (e) {
69
56
  console.error('Installation failed:', e.message);
package/gm-oc.mjs ADDED
@@ -0,0 +1,25 @@
1
+ import { readFileSync, existsSync } from 'fs';
2
+ import { join, dirname } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const __dirname = dirname(fileURLToPath(import.meta.url));
6
+
7
+ export async function GmPlugin({ directory }) {
8
+ const agentMd = join(__dirname, '..', 'agents', 'gm.md');
9
+ const prdFile = join(directory, '.prd');
10
+
11
+ return {
12
+ 'experimental.chat.system.transform': async (input, output) => {
13
+ try {
14
+ const rules = readFileSync(agentMd, 'utf-8');
15
+ if (rules) output.system.unshift(rules);
16
+ } catch (e) {}
17
+ try {
18
+ if (existsSync(prdFile)) {
19
+ const prd = readFileSync(prdFile, 'utf-8').trim();
20
+ if (prd) output.system.push('\nPENDING WORK (.prd):\n' + prd);
21
+ }
22
+ } catch (e) {}
23
+ }
24
+ };
25
+ }
package/gm.js CHANGED
@@ -1,37 +1 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- const GmPlugin = async ({ project, client, $, directory, worktree }) => {
5
- const pluginDir = __dirname;
6
- let agentRules = '';
7
-
8
- const loadAgentRules = () => {
9
- if (agentRules) return agentRules;
10
- const agentMd = path.join(pluginDir, 'agents', 'gm.md');
11
- try { agentRules = fs.readFileSync(agentMd, 'utf-8'); } catch (e) {}
12
- return agentRules;
13
- };
14
-
15
- const prdFile = path.join(directory, '.prd');
16
-
17
- return {
18
- onLoad: async () => {
19
- console.log('✓ gm plugin loaded');
20
- },
21
-
22
- getSystemPrompt: async () => {
23
- const rules = loadAgentRules();
24
- const prd = fs.existsSync(prdFile) ? fs.readFileSync(prdFile, 'utf-8').trim() : '';
25
- let prompt = rules || '';
26
- if (prd) prompt += '\n\nPENDING WORK (.prd):\n' + prd;
27
- return prompt;
28
- },
29
-
30
- onSessionEnd: async () => {
31
- const prd = fs.existsSync(prdFile) ? fs.readFileSync(prdFile, 'utf-8').trim() : '';
32
- if (prd) throw new Error('Work items remain in .prd - commit changes before exiting');
33
- }
34
- };
35
- };
36
-
37
- module.exports = { GmPlugin };
1
+ module.exports = require('./gm-oc.mjs');
package/index.js CHANGED
@@ -1 +1 @@
1
- module.exports = { GmPlugin: require('./gm.js').GmPlugin };
1
+ module.exports = { GmPlugin: require('./gm-oc.mjs').GmPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-oc",
3
- "version": "2.0.22",
3
+ "version": "2.0.23",
4
4
  "description": "Advanced Claude Code plugin with WFGY integration, MCP tools, and automated hooks",
5
5
  "author": "AnEntrypoint",
6
6
  "license": "MIT",
@@ -42,6 +42,7 @@
42
42
  "skills/",
43
43
  "scripts/",
44
44
  "gm.js",
45
+ "gm-oc.mjs",
45
46
  "index.js",
46
47
  "opencode.json",
47
48
  ".github/",