agent-guardrails 0.3.3 → 0.3.4
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/lib/daemon/worker.js +12 -0
- package/lib/mcp/server.js +45 -0
- package/package.json +1 -1
package/lib/daemon/worker.js
CHANGED
|
@@ -197,6 +197,18 @@ export async function createCheckRunner(repoRoot, config, log, t) {
|
|
|
197
197
|
.then((result) => {
|
|
198
198
|
const ok = result?.ok;
|
|
199
199
|
log(ok ? "Check passed" : "Check completed with issues");
|
|
200
|
+
|
|
201
|
+
// 保存结构化结果供 MCP 读取
|
|
202
|
+
try {
|
|
203
|
+
const resultFile = path.join(repoRoot, ".agent-guardrails", "daemon-result.json");
|
|
204
|
+
const dir = path.dirname(resultFile);
|
|
205
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
206
|
+
fs.writeFileSync(resultFile, JSON.stringify({
|
|
207
|
+
timestamp: new Date().toISOString(),
|
|
208
|
+
ok: !!ok,
|
|
209
|
+
result
|
|
210
|
+
}, null, 2));
|
|
211
|
+
} catch { /* ignore */ }
|
|
200
212
|
})
|
|
201
213
|
.catch((err) => {
|
|
202
214
|
log(`Check error: ${err.message}`);
|
package/lib/mcp/server.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
1
3
|
import { executeCheck } from "../commands/check.js";
|
|
2
4
|
import {
|
|
3
5
|
finishAgentNativeLoop,
|
|
@@ -193,6 +195,20 @@ const TOOL_DEFINITIONS = [
|
|
|
193
195
|
required: ["task"],
|
|
194
196
|
additionalProperties: false
|
|
195
197
|
}
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: "read_daemon_status",
|
|
201
|
+
description: "Read the latest daemon check result and status. Returns daemon running state, check count, and the structured result of the most recent guardrail check. Call this after code changes to check if the daemon detected any issues.",
|
|
202
|
+
inputSchema: {
|
|
203
|
+
type: "object",
|
|
204
|
+
properties: {
|
|
205
|
+
repoRoot: {
|
|
206
|
+
type: "string",
|
|
207
|
+
description: "Absolute path to the repository root."
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
additionalProperties: false
|
|
211
|
+
}
|
|
196
212
|
}
|
|
197
213
|
];
|
|
198
214
|
|
|
@@ -428,6 +444,35 @@ async function callTool(name, args, defaultRepoRoot) {
|
|
|
428
444
|
});
|
|
429
445
|
}
|
|
430
446
|
|
|
447
|
+
if (name === "read_daemon_status") {
|
|
448
|
+
const repoRoot = args.repoRoot || defaultRepoRoot;
|
|
449
|
+
const { isDaemonRunning, getDaemonConfig } = await import("../commands/daemon.js");
|
|
450
|
+
const status = isDaemonRunning(repoRoot);
|
|
451
|
+
const config = getDaemonConfig(repoRoot);
|
|
452
|
+
|
|
453
|
+
const resultPath = path.join(repoRoot, ".agent-guardrails", "daemon-result.json");
|
|
454
|
+
let lastResult = null;
|
|
455
|
+
try {
|
|
456
|
+
if (fs.existsSync(resultPath)) {
|
|
457
|
+
lastResult = JSON.parse(fs.readFileSync(resultPath, "utf8"));
|
|
458
|
+
}
|
|
459
|
+
} catch { /* ignore */ }
|
|
460
|
+
|
|
461
|
+
return createJsonResult({
|
|
462
|
+
running: status.running,
|
|
463
|
+
pid: status.pid || null,
|
|
464
|
+
startTime: status.startTime || null,
|
|
465
|
+
checksRun: status.checksRun || 0,
|
|
466
|
+
lastCheck: status.lastCheck || null,
|
|
467
|
+
config: {
|
|
468
|
+
watchPaths: config.watchPaths,
|
|
469
|
+
checkInterval: config.checkInterval,
|
|
470
|
+
blockOnHighRisk: config.blockOnHighRisk
|
|
471
|
+
},
|
|
472
|
+
lastResult
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
431
476
|
throw createError(-32601, `Unknown tool "${name}".`);
|
|
432
477
|
}
|
|
433
478
|
|