gm-kilo 2.0.95 → 2.0.97
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/hooks.json +12 -0
- package/hooks/post-tool-use-hook.js +143 -0
- package/package.json +1 -1
package/hooks/hooks.json
CHANGED
|
@@ -13,6 +13,18 @@
|
|
|
13
13
|
]
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
|
+
"tool.execute.after": [
|
|
17
|
+
{
|
|
18
|
+
"matcher": "*",
|
|
19
|
+
"hooks": [
|
|
20
|
+
{
|
|
21
|
+
"type": "command",
|
|
22
|
+
"command": "node ${KILO_PLUGIN_ROOT}/hooks/post-tool-use-hook.js",
|
|
23
|
+
"timeout": 30000
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
],
|
|
16
28
|
"message.updated": [
|
|
17
29
|
{
|
|
18
30
|
"matcher": "*",
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Post-tool-use hook: Eager linting report
|
|
5
|
+
*
|
|
6
|
+
* If linting is available (eslint, prettier, etc.), run it on modified files.
|
|
7
|
+
* If linting issues found, report them to agent immediately.
|
|
8
|
+
* If no issues or no linter available, silent (do nothing).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const { execSync } = require('child_process');
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
|
|
15
|
+
const cwd = process.cwd();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Detect available linters and run them
|
|
19
|
+
* Returns array of issue reports
|
|
20
|
+
*/
|
|
21
|
+
function runLinters() {
|
|
22
|
+
const issues = [];
|
|
23
|
+
|
|
24
|
+
// Detect ESLint
|
|
25
|
+
try {
|
|
26
|
+
if (fs.existsSync(path.join(cwd, '.eslintrc.json')) ||
|
|
27
|
+
fs.existsSync(path.join(cwd, '.eslintrc.js')) ||
|
|
28
|
+
fs.existsSync(path.join(cwd, 'eslint.config.js')) ||
|
|
29
|
+
hasPackageDependency('eslint')) {
|
|
30
|
+
const eslintOutput = execSync('npx eslint . --format=json 2>/dev/null || true', {
|
|
31
|
+
cwd,
|
|
32
|
+
encoding: 'utf-8',
|
|
33
|
+
maxBuffer: 10 * 1024 * 1024
|
|
34
|
+
}).trim();
|
|
35
|
+
|
|
36
|
+
if (eslintOutput) {
|
|
37
|
+
try {
|
|
38
|
+
const results = JSON.parse(eslintOutput);
|
|
39
|
+
const filtered = results.filter(r => r.messages?.length > 0);
|
|
40
|
+
if (filtered.length > 0) {
|
|
41
|
+
issues.push({
|
|
42
|
+
tool: 'ESLint',
|
|
43
|
+
issues: filtered
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
} catch (e) {
|
|
47
|
+
// JSON parse failed, skip
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {
|
|
52
|
+
// ESLint not available, continue
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Detect Prettier
|
|
56
|
+
try {
|
|
57
|
+
if (fs.existsSync(path.join(cwd, '.prettierrc')) ||
|
|
58
|
+
fs.existsSync(path.join(cwd, '.prettierrc.json')) ||
|
|
59
|
+
fs.existsSync(path.join(cwd, 'prettier.config.js')) ||
|
|
60
|
+
hasPackageDependency('prettier')) {
|
|
61
|
+
const prettierOutput = execSync('npx prettier . --check 2>&1 || true', {
|
|
62
|
+
cwd,
|
|
63
|
+
encoding: 'utf-8',
|
|
64
|
+
maxBuffer: 10 * 1024 * 1024
|
|
65
|
+
}).trim();
|
|
66
|
+
|
|
67
|
+
if (prettierOutput && !prettierOutput.includes('All matched files use Prettier code style')) {
|
|
68
|
+
issues.push({
|
|
69
|
+
tool: 'Prettier',
|
|
70
|
+
output: prettierOutput
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
// Prettier not available, continue
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return issues;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Check if package has a dependency (in package.json)
|
|
83
|
+
*/
|
|
84
|
+
function hasPackageDependency(pkg) {
|
|
85
|
+
try {
|
|
86
|
+
const pkgPath = path.join(cwd, 'package.json');
|
|
87
|
+
if (fs.existsSync(pkgPath)) {
|
|
88
|
+
const content = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
89
|
+
return !!(
|
|
90
|
+
content.dependencies?.[pkg] ||
|
|
91
|
+
content.devDependencies?.[pkg] ||
|
|
92
|
+
content.optionalDependencies?.[pkg]
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
} catch (e) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Format and report linting issues
|
|
103
|
+
*/
|
|
104
|
+
function reportIssues(issues) {
|
|
105
|
+
if (!issues || issues.length === 0) {
|
|
106
|
+
return; // Silent if no issues
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let report = '\n⚠️ LINTING ISSUES DETECTED:\n\n';
|
|
110
|
+
|
|
111
|
+
issues.forEach(({ tool, issues: eslintIssues, output }) => {
|
|
112
|
+
report += `## ${tool}\n`;
|
|
113
|
+
|
|
114
|
+
if (eslintIssues) {
|
|
115
|
+
// ESLint format
|
|
116
|
+
eslintIssues.forEach(file => {
|
|
117
|
+
if (file.messages.length > 0) {
|
|
118
|
+
report += `\n**${file.filePath}**\n`;
|
|
119
|
+
file.messages.forEach(msg => {
|
|
120
|
+
const severity = msg.severity === 2 ? '❌ ERROR' : '⚠️ WARN';
|
|
121
|
+
report += ` ${severity} (${msg.line}:${msg.column}) ${msg.message} [${msg.ruleId}]\n`;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
} else if (output) {
|
|
126
|
+
// Prettier format
|
|
127
|
+
report += `\n${output}\n`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
report += '\n';
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
report += 'Fix these issues before marking work complete.\n';
|
|
134
|
+
console.log(report);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Main
|
|
138
|
+
try {
|
|
139
|
+
const issues = runLinters();
|
|
140
|
+
reportIssues(issues);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
// Silent on errors - don't break the workflow
|
|
143
|
+
}
|