@infinitedusky/indusk-mcp 1.13.0 → 1.13.2
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/eval-trigger.js +53 -12
- package/package.json +1 -1
package/hooks/eval-trigger.js
CHANGED
|
@@ -11,10 +11,21 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { execSync, spawn } from "node:child_process";
|
|
14
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
14
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
15
15
|
import { dirname, resolve } from "node:path";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
17
|
|
|
18
|
+
// System log — writes to .indusk/eval/system.log for full visibility into eval lifecycle
|
|
19
|
+
function syslog(projectRoot, msg) {
|
|
20
|
+
try {
|
|
21
|
+
const logDir = resolve(projectRoot || ".", ".indusk", "eval");
|
|
22
|
+
mkdirSync(logDir, { recursive: true });
|
|
23
|
+
appendFileSync(resolve(logDir, "system.log"), `${new Date().toISOString()} ${msg}\n`);
|
|
24
|
+
} catch {
|
|
25
|
+
// ignore — logging should never break the hook
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
18
29
|
// Read hook input from stdin
|
|
19
30
|
let input = "";
|
|
20
31
|
for await (const chunk of process.stdin) {
|
|
@@ -24,9 +35,13 @@ for await (const chunk of process.stdin) {
|
|
|
24
35
|
const event = JSON.parse(input);
|
|
25
36
|
const toolInput = event.tool_input ?? {};
|
|
26
37
|
const command = toolInput.command ?? "";
|
|
38
|
+
const cwd = event.cwd ?? process.cwd();
|
|
39
|
+
|
|
40
|
+
syslog(cwd, `hook fired — tool: ${event.tool_name}, command: ${command.slice(0, 100)}`);
|
|
27
41
|
|
|
28
42
|
// Fast path: not a jj describe command
|
|
29
43
|
if (!command.includes("jj describe")) {
|
|
44
|
+
syslog(cwd, "skip — no jj describe in command");
|
|
30
45
|
process.exit(0);
|
|
31
46
|
}
|
|
32
47
|
|
|
@@ -61,11 +76,14 @@ function readEvalConfig(projectRoot) {
|
|
|
61
76
|
}
|
|
62
77
|
}
|
|
63
78
|
|
|
64
|
-
const projectRoot = findProjectRoot(
|
|
79
|
+
const projectRoot = findProjectRoot(cwd);
|
|
65
80
|
const evalConfig = readEvalConfig(projectRoot);
|
|
66
81
|
|
|
82
|
+
syslog(projectRoot, `projectRoot: ${projectRoot}, eval.enabled: ${evalConfig.enabled}`);
|
|
83
|
+
|
|
67
84
|
// Check if eval is disabled
|
|
68
85
|
if (!evalConfig.enabled) {
|
|
86
|
+
syslog(projectRoot, "skip — eval disabled in config");
|
|
69
87
|
process.exit(0);
|
|
70
88
|
}
|
|
71
89
|
|
|
@@ -117,11 +135,13 @@ const candidates = [
|
|
|
117
135
|
];
|
|
118
136
|
let judgeRunnerPath = null;
|
|
119
137
|
for (const c of candidates) {
|
|
138
|
+
syslog(projectRoot, `candidate: ${c} — ${existsSync(c) ? "found" : "missing"}`);
|
|
120
139
|
if (existsSync(c)) {
|
|
121
140
|
judgeRunnerPath = c;
|
|
122
141
|
break;
|
|
123
142
|
}
|
|
124
143
|
}
|
|
144
|
+
syslog(projectRoot, `judgeRunnerPath: ${judgeRunnerPath ?? "NOT FOUND"}`);
|
|
125
145
|
|
|
126
146
|
if (!judgeRunnerPath) {
|
|
127
147
|
// Can't find the package — log error and exit
|
|
@@ -165,19 +185,40 @@ const persistentJudgePath = judgeRunnerPath.replace("judge-runner.js", "persiste
|
|
|
165
185
|
const useModule = existsSync(persistentJudgePath) ? persistentJudgePath : judgeRunnerPath;
|
|
166
186
|
const useFunction = existsSync(persistentJudgePath) ? "runPersistentEval" : "runJudgeSync";
|
|
167
187
|
|
|
188
|
+
syslog(
|
|
189
|
+
projectRoot,
|
|
190
|
+
`spawning judge — module: ${useModule}, function: ${useFunction}, changeId: ${changeId}`,
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
const syslogPath = resolve(projectRoot, ".indusk", "eval", "system.log");
|
|
168
194
|
const judgeScript = `
|
|
195
|
+
const fs = require("fs");
|
|
196
|
+
const path = require("path");
|
|
197
|
+
function syslog(msg) {
|
|
198
|
+
try {
|
|
199
|
+
fs.mkdirSync(path.dirname("${syslogPath}"), { recursive: true });
|
|
200
|
+
fs.appendFileSync("${syslogPath}", new Date().toISOString() + " " + msg + "\\n");
|
|
201
|
+
} catch {}
|
|
202
|
+
}
|
|
203
|
+
syslog("judge process started — changeId: ${changeId}");
|
|
169
204
|
import("${useModule}")
|
|
170
|
-
.then(m =>
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
205
|
+
.then(m => {
|
|
206
|
+
syslog("judge module loaded — calling ${useFunction}");
|
|
207
|
+
return m.${useFunction}({
|
|
208
|
+
projectRoot: ${JSON.stringify(projectRoot)},
|
|
209
|
+
changeId: ${JSON.stringify(changeId)},
|
|
210
|
+
transcriptPath: ${JSON.stringify(transcriptPath)},
|
|
211
|
+
mode: "eval",
|
|
212
|
+
evalEndpoint: ${JSON.stringify(evalConfig.endpoint)},
|
|
213
|
+
});
|
|
214
|
+
})
|
|
215
|
+
.then((result) => {
|
|
216
|
+
const hasError = result && result.error;
|
|
217
|
+
syslog("judge completed — " + (hasError ? "error: " + result.message : "scorecard written"));
|
|
218
|
+
process.exit(0);
|
|
219
|
+
})
|
|
178
220
|
.catch(err => {
|
|
179
|
-
|
|
180
|
-
const path = require("path");
|
|
221
|
+
syslog("judge crashed — " + (err.message || String(err)));
|
|
181
222
|
const logPath = path.join(${JSON.stringify(projectRoot)}, ".indusk", "eval", "results.log");
|
|
182
223
|
fs.mkdirSync(path.dirname(logPath), { recursive: true });
|
|
183
224
|
const entry = JSON.stringify({
|