gm-codex 2.0.182 → 2.0.185
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/hooks/prompt-submit-hook.js +31 -20
- package/package.json +1 -1
- package/plugin.json +1 -1
|
@@ -9,26 +9,17 @@ const fs = require('fs');
|
|
|
9
9
|
const path = require('path');
|
|
10
10
|
const { execSync } = require('child_process');
|
|
11
11
|
|
|
12
|
-
const pluginRoot = process.env.CLAUDE_PLUGIN_ROOT || process.env.GEMINI_PROJECT_DIR || process.env.OC_PLUGIN_ROOT || process.env.KILO_PLUGIN_ROOT || path.join(__dirname, '..');
|
|
13
12
|
const projectDir = process.env.CLAUDE_PROJECT_DIR || process.env.GEMINI_PROJECT_DIR || process.env.OC_PROJECT_DIR || process.env.KILO_PROJECT_DIR;
|
|
14
13
|
|
|
15
|
-
const COMPACT_CONTEXT = 'use gm agent | ref: TOOL_INVARIANTS | codesearch for exploration | bun x gm-exec for execution';
|
|
16
|
-
const PLAN_MODE_BLOCK = 'DO NOT use EnterPlanMode. Use GM agent planning (PLAN→EXECUTE→EMIT→VERIFY→COMPLETE state machine) instead. Plan mode is blocked.';
|
|
17
|
-
|
|
18
14
|
const ensureGitignore = () => {
|
|
19
15
|
if (!projectDir) return;
|
|
20
16
|
const gitignorePath = path.join(projectDir, '.gitignore');
|
|
21
17
|
const entry = '.gm-stop-verified';
|
|
22
18
|
try {
|
|
23
|
-
let content = '';
|
|
24
|
-
if (fs.existsSync(gitignorePath)) {
|
|
25
|
-
content = fs.readFileSync(gitignorePath, 'utf-8');
|
|
26
|
-
}
|
|
19
|
+
let content = fs.existsSync(gitignorePath) ? fs.readFileSync(gitignorePath, 'utf-8') : '';
|
|
27
20
|
if (!content.split('\n').some(line => line.trim() === entry)) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
: content + '\n' + entry + '\n';
|
|
31
|
-
fs.writeFileSync(gitignorePath, newContent);
|
|
21
|
+
content = (content.endsWith('\n') || content === '' ? content : content + '\n') + entry + '\n';
|
|
22
|
+
fs.writeFileSync(gitignorePath, content);
|
|
32
23
|
}
|
|
33
24
|
} catch (e) {}
|
|
34
25
|
};
|
|
@@ -39,14 +30,23 @@ const runThorns = () => {
|
|
|
39
30
|
const thornsBin = fs.existsSync(localThorns) ? `node ${localThorns}` : 'bun x mcp-thorns@latest';
|
|
40
31
|
try {
|
|
41
32
|
const out = execSync(`${thornsBin} ${projectDir}`, {
|
|
42
|
-
encoding: 'utf-8',
|
|
43
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
44
|
-
timeout: 15000,
|
|
45
|
-
killSignal: 'SIGTERM'
|
|
33
|
+
encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 15000, killSignal: 'SIGTERM'
|
|
46
34
|
});
|
|
47
35
|
return `=== mcp-thorns ===\n${out.trim()}`;
|
|
48
36
|
} catch (e) {
|
|
49
|
-
|
|
37
|
+
return e.killed ? '=== mcp-thorns ===\nSkipped (timeout)' : '';
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const runCodeSearch = (prompt) => {
|
|
42
|
+
if (!prompt || !projectDir) return '';
|
|
43
|
+
try {
|
|
44
|
+
const out = execSync(`bun x codebasesearch ${JSON.stringify(prompt)}`, {
|
|
45
|
+
encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 10000, killSignal: 'SIGTERM',
|
|
46
|
+
cwd: projectDir
|
|
47
|
+
});
|
|
48
|
+
return `=== codebasesearch ===\n${out.trim()}`;
|
|
49
|
+
} catch (e) {
|
|
50
50
|
return '';
|
|
51
51
|
}
|
|
52
52
|
};
|
|
@@ -55,7 +55,6 @@ const emit = (additionalContext) => {
|
|
|
55
55
|
const isGemini = process.env.GEMINI_PROJECT_DIR !== undefined;
|
|
56
56
|
const isOpenCode = process.env.OC_PROJECT_DIR !== undefined;
|
|
57
57
|
const isKilo = process.env.KILO_PROJECT_DIR !== undefined;
|
|
58
|
-
|
|
59
58
|
if (isGemini) {
|
|
60
59
|
console.log(JSON.stringify({ systemMessage: additionalContext }, null, 2));
|
|
61
60
|
} else if (isOpenCode || isKilo) {
|
|
@@ -66,13 +65,25 @@ const emit = (additionalContext) => {
|
|
|
66
65
|
};
|
|
67
66
|
|
|
68
67
|
try {
|
|
68
|
+
let prompt = '';
|
|
69
|
+
try {
|
|
70
|
+
const input = JSON.parse(fs.readFileSync('/dev/stdin', 'utf-8'));
|
|
71
|
+
prompt = input.prompt || input.message || input.userMessage || '';
|
|
72
|
+
} catch (e) {}
|
|
73
|
+
|
|
69
74
|
ensureGitignore();
|
|
75
|
+
|
|
70
76
|
const parts = [];
|
|
77
|
+
parts.push('Invoke the `gm` skill to begin. DO NOT use EnterPlanMode. DO NOT use gm subagent directly — use the `gm` skill via the Skill tool.');
|
|
78
|
+
|
|
79
|
+
const search = runCodeSearch(prompt);
|
|
80
|
+
if (search) parts.push(search);
|
|
81
|
+
|
|
71
82
|
const thorns = runThorns();
|
|
72
83
|
if (thorns) parts.push(thorns);
|
|
73
|
-
|
|
84
|
+
|
|
74
85
|
emit(parts.join('\n\n'));
|
|
75
86
|
} catch (error) {
|
|
76
|
-
emit('
|
|
87
|
+
emit('Invoke the `gm` skill to begin. Hook error: ' + error.message);
|
|
77
88
|
process.exit(0);
|
|
78
89
|
}
|
package/package.json
CHANGED