gm-cc 2.0.246 → 2.0.250
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/.claude-plugin/marketplace.json +1 -1
- package/hooks/hooks.json +12 -7
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/scripts/bootstrap.js +45 -0
- package/scripts/postinstall-kilo.js +55 -42
- package/scripts/postinstall-oc.js +57 -42
- package/scripts/postinstall.js +137 -101
- package/hooks/pre-tool-use-hook.js +0 -504
- package/hooks/prompt-submit-hook.js +0 -177
- package/hooks/session-start-hook.js +0 -188
- package/hooks/stop-hook-git.js +0 -190
- package/hooks/stop-hook.js +0 -57
package/scripts/postinstall.js
CHANGED
|
@@ -1,101 +1,137 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function safeCopyFile(src, dst) {
|
|
24
|
-
try {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
if (!
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const https = require('https');
|
|
6
|
+
|
|
7
|
+
const PLUGKIT_REPO = 'AnEntrypoint/rs-plugkit';
|
|
8
|
+
|
|
9
|
+
function isInsideNodeModules() {
|
|
10
|
+
return __dirname.includes(path.sep + 'node_modules' + path.sep);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getProjectRoot() {
|
|
14
|
+
if (!isInsideNodeModules()) return null;
|
|
15
|
+
let current = __dirname;
|
|
16
|
+
while (current !== path.dirname(current)) {
|
|
17
|
+
current = path.dirname(current);
|
|
18
|
+
if (path.basename(current) === 'node_modules') return path.dirname(current);
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function safeCopyFile(src, dst) {
|
|
24
|
+
try {
|
|
25
|
+
const dstDir = path.dirname(dst);
|
|
26
|
+
if (!fs.existsSync(dstDir)) fs.mkdirSync(dstDir, { recursive: true });
|
|
27
|
+
fs.writeFileSync(dst, fs.readFileSync(src));
|
|
28
|
+
return true;
|
|
29
|
+
} catch { return false; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function safeCopyDirectory(src, dst) {
|
|
33
|
+
try {
|
|
34
|
+
if (!fs.existsSync(src)) return false;
|
|
35
|
+
fs.mkdirSync(dst, { recursive: true });
|
|
36
|
+
fs.readdirSync(src, { withFileTypes: true }).forEach(entry => {
|
|
37
|
+
const srcPath = path.join(src, entry.name);
|
|
38
|
+
const dstPath = path.join(dst, entry.name);
|
|
39
|
+
if (entry.isDirectory()) safeCopyDirectory(srcPath, dstPath);
|
|
40
|
+
else if (entry.isFile()) safeCopyFile(srcPath, dstPath);
|
|
41
|
+
});
|
|
42
|
+
return true;
|
|
43
|
+
} catch { return false; }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function updateGitignore(projectRoot) {
|
|
47
|
+
try {
|
|
48
|
+
const gitignorePath = path.join(projectRoot, '.gitignore');
|
|
49
|
+
const entry = '.gm-stop-verified';
|
|
50
|
+
let content = fs.existsSync(gitignorePath) ? fs.readFileSync(gitignorePath, 'utf-8') : '';
|
|
51
|
+
if (content.includes(entry)) return;
|
|
52
|
+
if (content && !content.endsWith('\n')) content += '\n';
|
|
53
|
+
fs.writeFileSync(gitignorePath, content + entry + '\n', 'utf-8');
|
|
54
|
+
} catch {}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function getRequiredVersion(sourceDir) {
|
|
58
|
+
try {
|
|
59
|
+
const gm = JSON.parse(fs.readFileSync(path.join(sourceDir, 'gm.json'), 'utf-8'));
|
|
60
|
+
return gm.plugkitVersion || null;
|
|
61
|
+
} catch { return null; }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getInstalledVersion(binPath) {
|
|
65
|
+
try {
|
|
66
|
+
const { spawnSync } = require('child_process');
|
|
67
|
+
const r = spawnSync(binPath, ['--version'], { encoding: 'utf8', timeout: 5000 });
|
|
68
|
+
const out = (r.stdout || '').trim();
|
|
69
|
+
const m = out.match(/(\d+\.\d+\.\d+)/);
|
|
70
|
+
return m ? m[1] : null;
|
|
71
|
+
} catch { return null; }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function downloadBin(version, dest, callback) {
|
|
75
|
+
const IS_WIN = process.platform === 'win32';
|
|
76
|
+
const asset = IS_WIN ? 'plugkit.exe' : 'plugkit';
|
|
77
|
+
const tag = version ? `v${version}` : 'latest';
|
|
78
|
+
const urlPath = version
|
|
79
|
+
? `/AnEntrypoint/rs-plugkit/releases/download/v${version}/${asset}`
|
|
80
|
+
: `/AnEntrypoint/rs-plugkit/releases/latest/download/${asset}`;
|
|
81
|
+
|
|
82
|
+
const destDir = path.dirname(dest);
|
|
83
|
+
if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });
|
|
84
|
+
|
|
85
|
+
const follow = (url) => {
|
|
86
|
+
const isHttps = url.startsWith('https');
|
|
87
|
+
const mod = isHttps ? https : require('http');
|
|
88
|
+
const options = typeof url === 'string'
|
|
89
|
+
? { ...require('url').parse(url), headers: { 'User-Agent': 'gm-postinstall' } }
|
|
90
|
+
: url;
|
|
91
|
+
mod.get(options, res => {
|
|
92
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
93
|
+
return follow(res.headers.location);
|
|
94
|
+
}
|
|
95
|
+
if (res.statusCode !== 200) return callback(new Error(`HTTP ${res.statusCode}`));
|
|
96
|
+
const chunks = [];
|
|
97
|
+
res.on('data', c => chunks.push(c));
|
|
98
|
+
res.on('end', () => {
|
|
99
|
+
try {
|
|
100
|
+
fs.writeFileSync(dest, Buffer.concat(chunks));
|
|
101
|
+
try { fs.chmodSync(dest, 0o755); } catch {}
|
|
102
|
+
callback(null);
|
|
103
|
+
} catch (e) { callback(e); }
|
|
104
|
+
});
|
|
105
|
+
}).on('error', callback);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
follow(`https://github.com${urlPath}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function install() {
|
|
112
|
+
if (!isInsideNodeModules()) return;
|
|
113
|
+
const projectRoot = getProjectRoot();
|
|
114
|
+
if (!projectRoot) return;
|
|
115
|
+
|
|
116
|
+
const claudeDir = path.join(projectRoot, '.claude');
|
|
117
|
+
const sourceDir = path.dirname(__dirname);
|
|
118
|
+
|
|
119
|
+
safeCopyDirectory(path.join(sourceDir, 'agents'), path.join(claudeDir, 'agents'));
|
|
120
|
+
safeCopyDirectory(path.join(sourceDir, 'hooks'), path.join(claudeDir, 'hooks'));
|
|
121
|
+
safeCopyFile(path.join(sourceDir, '.mcp.json'), path.join(claudeDir, '.mcp.json'));
|
|
122
|
+
|
|
123
|
+
updateGitignore(projectRoot);
|
|
124
|
+
|
|
125
|
+
const IS_WIN = process.platform === 'win32';
|
|
126
|
+
const binDest = path.join(claudeDir, 'bin', IS_WIN ? 'plugkit.exe' : 'plugkit');
|
|
127
|
+
const requiredVersion = getRequiredVersion(sourceDir);
|
|
128
|
+
const installedVersion = fs.existsSync(binDest) ? getInstalledVersion(binDest) : null;
|
|
129
|
+
|
|
130
|
+
if (!installedVersion || (requiredVersion && installedVersion !== requiredVersion)) {
|
|
131
|
+
downloadBin(requiredVersion, binDest, (err) => {
|
|
132
|
+
if (err) process.stderr.write('plugkit download failed: ' + err.message + '\n');
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
install();
|