@rubytech/create-realagent 1.0.832 → 1.0.834
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/dist/index.js +131 -9
- package/package.json +1 -1
- package/payload/platform/lib/admins-write/dist/index.d.ts +87 -0
- package/payload/platform/lib/admins-write/dist/index.d.ts.map +1 -0
- package/payload/platform/lib/admins-write/dist/index.js +248 -0
- package/payload/platform/lib/admins-write/dist/index.js.map +1 -0
- package/payload/platform/lib/admins-write/src/index.ts +311 -0
- package/payload/platform/lib/admins-write/tsconfig.json +8 -0
- package/payload/platform/neo4j/migrations/009-conversation-archive-title.ts +197 -0
- package/payload/platform/neo4j/schema.cypher +1 -1
- package/payload/platform/package.json +2 -2
- package/payload/platform/plugins/admin/PLUGIN.md +1 -1
- package/payload/platform/plugins/admin/mcp/dist/index.js +37 -44
- package/payload/platform/plugins/admin/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/docs/references/internals.md +4 -3
- package/payload/platform/plugins/memory/bin/conversation-archive-ingest.mjs +215 -43
- package/payload/platform/plugins/memory/bin/conversation-archive-ingest.sh +7 -2
- package/payload/platform/plugins/memory/mcp/dist/lib/__tests__/llm-classifier.test.js +75 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/__tests__/llm-classifier.test.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-classifier.d.ts +16 -10
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-classifier.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-classifier.js +155 -100
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-classifier.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-ranker.d.ts +13 -5
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-ranker.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-ranker.js +53 -59
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-ranker.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-ingest.test.js +9 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-ingest.test.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.d.ts +24 -7
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.js +47 -11
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.js.map +1 -1
- package/payload/platform/plugins/memory/skills/conversation-archive/SKILL.md +45 -8
- package/payload/platform/scripts/lib/resolve-account-dir.sh +3 -1
- package/payload/platform/scripts/migrate-import.sh +3 -1
- package/payload/platform/scripts/seed-neo4j.sh +13 -3
- package/payload/server/chunk-CRAIGEXY.js +654 -0
- package/payload/server/chunk-GK4WHM3H.js +9961 -0
- package/payload/server/chunk-I2NOLBQA.js +2123 -0
- package/payload/server/chunk-IVTESKFR.js +9961 -0
- package/payload/server/chunk-KD3XP4IK.js +1116 -0
- package/payload/server/chunk-KKGGT5RH.js +654 -0
- package/payload/server/chunk-MRJGG6CS.js +2124 -0
- package/payload/server/chunk-OJZPS4BL.js +367 -0
- package/payload/server/chunk-ZVW5XKPU.js +1116 -0
- package/payload/server/client-pool-FM3YJWV5.js +32 -0
- package/payload/server/client-pool-J5BCVVI2.js +32 -0
- package/payload/server/cloudflare-task-tracker-FSPEJOTH.js +19 -0
- package/payload/server/cloudflare-task-tracker-XCUO4N74.js +19 -0
- package/payload/server/maxy-edge.js +6 -5
- package/payload/server/neo4j-migrations-5AN2U3YO.js +664 -0
- package/payload/server/neo4j-migrations-XP7XDVPX.js +664 -0
- package/payload/server/public/assets/{Checkbox-CTGhpDKq.js → Checkbox-Bq6ORjz2.js} +1 -1
- package/payload/server/public/assets/admin-CstEkw-G.js +352 -0
- package/payload/server/public/assets/data-DwZZ7qbH.js +1 -0
- package/payload/server/public/assets/graph-DceEv42K.js +1 -0
- package/payload/server/public/assets/{jsx-runtime-D4WovFYk.css → jsx-runtime-DidQeNoZ.css} +1 -1
- package/payload/server/public/assets/page-Bpi_jPw6.js +50 -0
- package/payload/server/public/assets/{page-DkBfWy4C.js → page-CFWoVkgV.js} +1 -1
- package/payload/server/public/assets/{public-BdVIVpv8.js → public-BWMwq5Jj.js} +1 -1
- package/payload/server/public/assets/{useAdminFetch-DmHu0oCx.js → useAdminFetch-B93ig7ef.js} +1 -1
- package/payload/server/public/assets/{useVoiceRecorder-CSc_hxjV.js → useVoiceRecorder-Cb0nAtOo.js} +1 -1
- package/payload/server/public/data.html +5 -5
- package/payload/server/public/graph.html +6 -6
- package/payload/server/public/index.html +8 -8
- package/payload/server/public/public.html +5 -5
- package/payload/server/server.js +376 -167
- package/payload/platform/plugins/admin/mcp/dist/lib/review-tools.d.ts +0 -31
- package/payload/platform/plugins/admin/mcp/dist/lib/review-tools.d.ts.map +0 -1
- package/payload/platform/plugins/admin/mcp/dist/lib/review-tools.js +0 -666
- package/payload/platform/plugins/admin/mcp/dist/lib/review-tools.js.map +0 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/semantic-chunker.d.ts +0 -61
- package/payload/platform/plugins/memory/mcp/dist/lib/semantic-chunker.d.ts.map +0 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/semantic-chunker.js +0 -266
- package/payload/platform/plugins/memory/mcp/dist/lib/semantic-chunker.js.map +0 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-insight-pass.d.ts +0 -27
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-insight-pass.d.ts.map +0 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-insight-pass.js +0 -477
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-insight-pass.js.map +0 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-insight-write.d.ts +0 -27
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-insight-write.d.ts.map +0 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-insight-write.js +0 -160
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-insight-write.js.map +0 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-parse.d.ts +0 -10
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-parse.d.ts.map +0 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-parse.js +0 -29
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-parse.js.map +0 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-preview.d.ts +0 -28
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-preview.d.ts.map +0 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-preview.js +0 -34
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-preview.js.map +0 -1
- package/payload/server/public/assets/admin-BNwPsMhJ.js +0 -352
- package/payload/server/public/assets/data-Y77FLKjs.js +0 -1
- package/payload/server/public/assets/graph-N_Bw-8oT.js +0 -1
- package/payload/server/public/assets/page-BKLGP-th.js +0 -50
- /package/payload/server/public/assets/{jsx-runtime-DkaAusaX.js → jsx-runtime-DH5S-MwB.js} +0 -0
|
@@ -1,666 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* review-tools — admin MCP tools for the proactive log review cadence.
|
|
3
|
-
*
|
|
4
|
-
* Registers seven tools on the admin MCP server:
|
|
5
|
-
*
|
|
6
|
-
* review-rules-list — dump current rules + runtime state (from Neo4j)
|
|
7
|
-
* review-rules-suppress — silence a rule for N hours
|
|
8
|
-
* review-rules-unsuppress — lift a suppression immediately
|
|
9
|
-
* review-rules-add — add a new rule from a structured spec
|
|
10
|
-
* review-rules-remove — delete a rule from the config
|
|
11
|
-
* review-alerts-recent — read-only view of recent ReviewAlert nodes
|
|
12
|
-
* review-digest-compose — schedule-triggered: author daily digest + watchdog
|
|
13
|
-
*
|
|
14
|
-
* Coordination with the in-process detector happens entirely via the rules
|
|
15
|
-
* file on disk and the Neo4j ReviewAlert graph. No shared memory, no IPC.
|
|
16
|
-
*
|
|
17
|
-
* See app/lib/review-detector/ in maxy-ui for the detector implementation
|
|
18
|
-
* and .docs/workflows.md § Review Cadence for the wider architecture.
|
|
19
|
-
*/
|
|
20
|
-
import { z } from "zod";
|
|
21
|
-
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, statSync, openSync, readSync, closeSync } from "node:fs";
|
|
22
|
-
import { resolve, dirname, join } from "node:path";
|
|
23
|
-
import neo4j from "neo4j-driver";
|
|
24
|
-
import { getSession } from "./neo4j.js";
|
|
25
|
-
// review.log grows at roughly 17,280 cycle events / day at a 5s interval.
|
|
26
|
-
// Over a month that's ~500k lines. The digest only needs the last 24h, so
|
|
27
|
-
// cap the read at the tail of the file (8 MB is enough for several days
|
|
28
|
-
// of dense activity including all matches and suppressions). A file that
|
|
29
|
-
// has grown past this size still works — we just read from the tail.
|
|
30
|
-
const MAX_DIGEST_READ_BYTES = 8 * 1024 * 1024;
|
|
31
|
-
function rulesFilePath(configDir) {
|
|
32
|
-
return resolve(configDir, "review-rules.json");
|
|
33
|
-
}
|
|
34
|
-
function reviewLogPath(configDir) {
|
|
35
|
-
return resolve(configDir, "logs", "review.log");
|
|
36
|
-
}
|
|
37
|
-
function loadRulesFile(configDir) {
|
|
38
|
-
const path = rulesFilePath(configDir);
|
|
39
|
-
if (!existsSync(path)) {
|
|
40
|
-
throw new Error(`rules file missing at ${path}. The detector must boot at least once to materialise defaults.`);
|
|
41
|
-
}
|
|
42
|
-
const raw = readFileSync(path, "utf-8");
|
|
43
|
-
const parsed = JSON.parse(raw);
|
|
44
|
-
if (!parsed || typeof parsed.scanIntervalMs !== "number" || !Array.isArray(parsed.rules)) {
|
|
45
|
-
throw new Error("rules file is malformed — run review-rules-list to see the loader error");
|
|
46
|
-
}
|
|
47
|
-
return parsed;
|
|
48
|
-
}
|
|
49
|
-
function saveRulesFile(configDir, file) {
|
|
50
|
-
const path = rulesFilePath(configDir);
|
|
51
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
52
|
-
const tmp = `${path}.tmp.${process.pid}.${Date.now()}`;
|
|
53
|
-
writeFileSync(tmp, JSON.stringify(file, null, 2) + "\n", "utf-8");
|
|
54
|
-
renameSync(tmp, path);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Append a structured event to the review log. Admin tool actions are
|
|
58
|
-
* audit-logged here so `logs-read.sh --tail review` shows both detector
|
|
59
|
-
* activity and every admin mutation.
|
|
60
|
-
*/
|
|
61
|
-
function reviewLog(configDir, event) {
|
|
62
|
-
const path = reviewLogPath(configDir);
|
|
63
|
-
try {
|
|
64
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
65
|
-
const line = `${new Date().toISOString()} [review] ${JSON.stringify({ source: "admin-tool", ...event })}\n`;
|
|
66
|
-
appendFileSync(path, line, "utf-8");
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
console.error(`[review-tool] failed to write review log: ${err instanceof Error ? err.message : String(err)}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
export function registerReviewTools(server, ctx) {
|
|
73
|
-
const { configDir, accountId } = ctx;
|
|
74
|
-
// -------------------------------------------------------------------------
|
|
75
|
-
// review-rules-list
|
|
76
|
-
// -------------------------------------------------------------------------
|
|
77
|
-
server.tool("review-rules-list", "List all declarative log review rules (from review-rules.json) with their current state. For each rule: id, name, type, log source, pattern, thresholds, suggested action, and any active suppression window. Use this before calling review-rules-suppress or review-rules-remove so you know the exact rule id.", {}, async () => {
|
|
78
|
-
try {
|
|
79
|
-
const file = loadRulesFile(configDir);
|
|
80
|
-
const now = Date.now();
|
|
81
|
-
const summary = file.rules.map((r) => {
|
|
82
|
-
const suppressed = r.suppressedUntil && Date.parse(r.suppressedUntil) > now
|
|
83
|
-
? `until ${r.suppressedUntil}`
|
|
84
|
-
: null;
|
|
85
|
-
return {
|
|
86
|
-
id: r.id,
|
|
87
|
-
name: r.name,
|
|
88
|
-
type: r.type,
|
|
89
|
-
logSource: r.logSource,
|
|
90
|
-
pattern: r.pattern,
|
|
91
|
-
thresholdCount: r.thresholdCount,
|
|
92
|
-
thresholdWindowMinutes: r.thresholdWindowMinutes,
|
|
93
|
-
suggestedAction: r.suggestedAction,
|
|
94
|
-
watchPath: r.watchPath ?? null,
|
|
95
|
-
staleHours: r.staleHours ?? null,
|
|
96
|
-
followupPattern: r.followupPattern ?? null,
|
|
97
|
-
followupWindowMs: r.followupWindowMs ?? null,
|
|
98
|
-
suppressedUntil: suppressed,
|
|
99
|
-
};
|
|
100
|
-
});
|
|
101
|
-
return {
|
|
102
|
-
content: [{ type: "text", text: JSON.stringify({ scanIntervalMs: file.scanIntervalMs, rules: summary }, null, 2) }],
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
catch (err) {
|
|
106
|
-
return {
|
|
107
|
-
content: [{ type: "text", text: `[review-tool] failed to load rules: ${err instanceof Error ? err.message : String(err)}` }],
|
|
108
|
-
isError: true,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
// -------------------------------------------------------------------------
|
|
113
|
-
// review-rules-suppress
|
|
114
|
-
// -------------------------------------------------------------------------
|
|
115
|
-
server.tool("review-rules-suppress", "Silence a review rule for a given number of hours. The detector will skip evaluating the rule entirely until the suppression window expires. Use this when you know a matching condition is temporary (e.g. 'suppress reconnect-loop for 24h while I fix Task 384'). Reason is recorded in the review log.", {
|
|
116
|
-
ruleId: z.string().describe("Rule id — get it from review-rules-list."),
|
|
117
|
-
durationHours: z.number().min(0.1).max(720).describe("Suppression window in hours, 0.1 to 720."),
|
|
118
|
-
reason: z.string().min(1).describe("Why the rule is being suppressed — recorded in the audit log."),
|
|
119
|
-
}, async ({ ruleId, durationHours, reason }) => {
|
|
120
|
-
try {
|
|
121
|
-
const file = loadRulesFile(configDir);
|
|
122
|
-
const rule = file.rules.find((r) => r.id === ruleId);
|
|
123
|
-
if (!rule) {
|
|
124
|
-
return {
|
|
125
|
-
content: [{ type: "text", text: `[review-tool] no rule with id "${ruleId}"` }],
|
|
126
|
-
isError: true,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
const until = new Date(Date.now() + durationHours * 60 * 60 * 1000).toISOString();
|
|
130
|
-
rule.suppressedUntil = until;
|
|
131
|
-
saveRulesFile(configDir, file);
|
|
132
|
-
// Suppression must propagate to the Neo4j ReviewAlert node too,
|
|
133
|
-
// otherwise loadSessionContext keeps surfacing the alert on every
|
|
134
|
-
// admin turn for up to 24h — the user asked the agent to silence
|
|
135
|
-
// this rule and the agent would still be shouting about it.
|
|
136
|
-
// Best-effort: a failure here is logged but does not fail the tool,
|
|
137
|
-
// because the on-disk suppression is already in effect (the detector
|
|
138
|
-
// will skip evaluating the rule on its next cycle, so no NEW alert
|
|
139
|
-
// will be created — only an existing one could linger).
|
|
140
|
-
const neoSession = getSession();
|
|
141
|
-
try {
|
|
142
|
-
await neoSession.run(`MATCH (a:ReviewAlert { ruleId: $ruleId, accountId: $accountId })
|
|
143
|
-
WHERE a.resolvedAt IS NULL
|
|
144
|
-
SET a.suppressedUntil = datetime($until)`, { ruleId, accountId, until });
|
|
145
|
-
}
|
|
146
|
-
catch (err) {
|
|
147
|
-
reviewLog(configDir, {
|
|
148
|
-
event: "rule-suppress-graph-sync-failed",
|
|
149
|
-
ruleId,
|
|
150
|
-
error: err instanceof Error ? err.message : String(err),
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
finally {
|
|
154
|
-
await neoSession.close();
|
|
155
|
-
}
|
|
156
|
-
reviewLog(configDir, { event: "rule-suppressed", ruleId, until, reason });
|
|
157
|
-
return {
|
|
158
|
-
content: [{ type: "text", text: `Suppressed ${ruleId} until ${until}. Reason: ${reason}` }],
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
catch (err) {
|
|
162
|
-
return {
|
|
163
|
-
content: [{ type: "text", text: `[review-tool] suppress failed: ${err instanceof Error ? err.message : String(err)}` }],
|
|
164
|
-
isError: true,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
// -------------------------------------------------------------------------
|
|
169
|
-
// review-rules-unsuppress
|
|
170
|
-
// -------------------------------------------------------------------------
|
|
171
|
-
server.tool("review-rules-unsuppress", "Lift an active suppression on a review rule immediately. The detector will start evaluating the rule again on its next scan cycle.", {
|
|
172
|
-
ruleId: z.string().describe("Rule id — get it from review-rules-list."),
|
|
173
|
-
}, async ({ ruleId }) => {
|
|
174
|
-
try {
|
|
175
|
-
const file = loadRulesFile(configDir);
|
|
176
|
-
const rule = file.rules.find((r) => r.id === ruleId);
|
|
177
|
-
if (!rule) {
|
|
178
|
-
return {
|
|
179
|
-
content: [{ type: "text", text: `[review-tool] no rule with id "${ruleId}"` }],
|
|
180
|
-
isError: true,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
rule.suppressedUntil = null;
|
|
184
|
-
saveRulesFile(configDir, file);
|
|
185
|
-
// Clear suppression on the Neo4j ReviewAlert node too so
|
|
186
|
-
// loadSessionContext surfaces the alert again immediately.
|
|
187
|
-
// Best-effort: same rationale as in review-rules-suppress.
|
|
188
|
-
const neoSession = getSession();
|
|
189
|
-
try {
|
|
190
|
-
await neoSession.run(`MATCH (a:ReviewAlert { ruleId: $ruleId, accountId: $accountId })
|
|
191
|
-
WHERE a.resolvedAt IS NULL
|
|
192
|
-
SET a.suppressedUntil = null`, { ruleId, accountId });
|
|
193
|
-
}
|
|
194
|
-
catch (err) {
|
|
195
|
-
reviewLog(configDir, {
|
|
196
|
-
event: "rule-unsuppress-graph-sync-failed",
|
|
197
|
-
ruleId,
|
|
198
|
-
error: err instanceof Error ? err.message : String(err),
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
finally {
|
|
202
|
-
await neoSession.close();
|
|
203
|
-
}
|
|
204
|
-
reviewLog(configDir, { event: "rule-unsuppressed", ruleId });
|
|
205
|
-
return {
|
|
206
|
-
content: [{ type: "text", text: `Unsuppressed ${ruleId}. Rule will fire on next match.` }],
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
catch (err) {
|
|
210
|
-
return {
|
|
211
|
-
content: [{ type: "text", text: `[review-tool] unsuppress failed: ${err instanceof Error ? err.message : String(err)}` }],
|
|
212
|
-
isError: true,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
// -------------------------------------------------------------------------
|
|
217
|
-
// review-rules-add
|
|
218
|
-
// -------------------------------------------------------------------------
|
|
219
|
-
server.tool("review-rules-add", [
|
|
220
|
-
"Add a new declarative log review rule. The agent is responsible for translating a natural-language request from the user into the structured fields below.",
|
|
221
|
-
"Seven rule types are supported:",
|
|
222
|
-
"- reconnect-loop / repeated-error: N matches within thresholdWindowMinutes",
|
|
223
|
-
"- silent-catch / rate-limit: fires on every match (thresholdCount: 0)",
|
|
224
|
-
"- file-write-storm / stale-log: use watchPath (relative to configDir); stale-log requires staleHours",
|
|
225
|
-
"- absent-followup: fires when 'pattern' is observed but 'followupPattern' is NOT observed within 'followupWindowMs'. Requires non-empty pattern, followupPattern (regex), and followupWindowMs in (0, 600000]. thresholdCount/thresholdWindowMinutes are ignored for this type — set both to 0.",
|
|
226
|
-
"",
|
|
227
|
-
"Worked example for absent-followup: detect a [spawn] line that lacks the expected stderr-tee marker within 10s.",
|
|
228
|
-
' id: "subproc-tee-silent-spawn"',
|
|
229
|
-
' type: "absent-followup", logSource: "system", scope: "session"',
|
|
230
|
-
' pattern: "\\\\[spawn\\\\] pid=\\\\d+"',
|
|
231
|
-
' followupPattern: "\\\\[subproc-stderr-tee-attached\\\\]|\\\\[subproc-debug-unavailable\\\\]"',
|
|
232
|
-
" followupWindowMs: 10000, thresholdCount: 0, thresholdWindowMinutes: 0",
|
|
233
|
-
].join("\n"), {
|
|
234
|
-
id: z.string().regex(/^[a-z0-9][a-z0-9-]*$/).describe("Unique kebab-case id used for suppression and storage."),
|
|
235
|
-
name: z.string().min(1).describe("Human-readable display name shown in chat alerts."),
|
|
236
|
-
type: z.enum(["reconnect-loop", "repeated-error", "silent-catch", "file-write-storm", "stale-log", "rate-limit", "absent-followup"]).describe("Rule evaluator type."),
|
|
237
|
-
logSource: z.enum(["any", "server", "vnc", "system", "error", "session", "public", "mcp", "config-dir"]).describe("Which log stream(s) to evaluate against. 'any' means every text log."),
|
|
238
|
-
pattern: z.string().describe("JavaScript regex. Empty for file-write-storm and stale-log (they use watchPath instead). For absent-followup this is the TRIGGER regex."),
|
|
239
|
-
thresholdCount: z.number().min(0).describe("Matches required within the window. 0 fires on first match. Unused by absent-followup — set 0."),
|
|
240
|
-
thresholdWindowMinutes: z.number().min(0).describe("Window length in minutes. 0 disables windowing. Unused by absent-followup — set 0."),
|
|
241
|
-
suggestedAction: z.string().min(1).describe("One-sentence remediation guidance shown in the alert."),
|
|
242
|
-
watchPath: z.string().optional().describe("Relative to configDir. Required for file-write-storm and stale-log."),
|
|
243
|
-
staleHours: z.number().optional().describe("Staleness threshold in hours. Required for stale-log."),
|
|
244
|
-
followupPattern: z.string().optional().describe("Required for absent-followup: regex the followup log line must satisfy (alternation with | is supported to express 'any of these markers')."),
|
|
245
|
-
followupWindowMs: z.number().optional().describe("Required for absent-followup: milliseconds to wait for the followup before firing. Must be in (0, 600000]."),
|
|
246
|
-
scope: z.enum(["global", "session"]).optional().describe("For count-based text rules and absent-followup: 'global' (default) counts/scopes matches across all lines; 'session' groups matches by the conversationId tag so the rule only fires on within-conversation patterns."),
|
|
247
|
-
}, async (params) => {
|
|
248
|
-
try {
|
|
249
|
-
const file = loadRulesFile(configDir);
|
|
250
|
-
if (file.rules.some((r) => r.id === params.id)) {
|
|
251
|
-
return {
|
|
252
|
-
content: [{ type: "text", text: `[review-tool] a rule with id "${params.id}" already exists` }],
|
|
253
|
-
isError: true,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
if (params.pattern.length > 0) {
|
|
257
|
-
try {
|
|
258
|
-
new RegExp(params.pattern);
|
|
259
|
-
}
|
|
260
|
-
catch (err) {
|
|
261
|
-
return {
|
|
262
|
-
content: [{ type: "text", text: `[review-tool] pattern is not a valid regex: ${err instanceof Error ? err.message : String(err)}` }],
|
|
263
|
-
isError: true,
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if ((params.type === "file-write-storm" || params.type === "stale-log") && !params.watchPath) {
|
|
268
|
-
return {
|
|
269
|
-
content: [{ type: "text", text: `[review-tool] ${params.type} rules require watchPath` }],
|
|
270
|
-
isError: true,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
if (params.type === "stale-log" && (params.staleHours === undefined || params.staleHours <= 0)) {
|
|
274
|
-
return {
|
|
275
|
-
content: [{ type: "text", text: `[review-tool] stale-log rules require a positive staleHours` }],
|
|
276
|
-
isError: true,
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
if (params.type === "absent-followup") {
|
|
280
|
-
if (params.pattern.length === 0) {
|
|
281
|
-
return {
|
|
282
|
-
content: [{ type: "text", text: `[review-tool] absent-followup rules require a non-empty pattern (the TRIGGER regex)` }],
|
|
283
|
-
isError: true,
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
if (!params.followupPattern || params.followupPattern.length === 0) {
|
|
287
|
-
return {
|
|
288
|
-
content: [{ type: "text", text: `[review-tool] absent-followup rules require a non-empty followupPattern` }],
|
|
289
|
-
isError: true,
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
try {
|
|
293
|
-
new RegExp(params.followupPattern);
|
|
294
|
-
}
|
|
295
|
-
catch (err) {
|
|
296
|
-
return {
|
|
297
|
-
content: [{ type: "text", text: `[review-tool] followupPattern is not a valid regex: ${err instanceof Error ? err.message : String(err)}` }],
|
|
298
|
-
isError: true,
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
if (params.followupWindowMs === undefined || params.followupWindowMs <= 0 || params.followupWindowMs > 600_000) {
|
|
302
|
-
return {
|
|
303
|
-
content: [{ type: "text", text: `[review-tool] absent-followup rules require followupWindowMs in (0, 600000]` }],
|
|
304
|
-
isError: true,
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
const rule = {
|
|
309
|
-
id: params.id,
|
|
310
|
-
name: params.name,
|
|
311
|
-
type: params.type,
|
|
312
|
-
logSource: params.logSource,
|
|
313
|
-
pattern: params.pattern,
|
|
314
|
-
thresholdCount: params.thresholdCount,
|
|
315
|
-
thresholdWindowMinutes: params.thresholdWindowMinutes,
|
|
316
|
-
suggestedAction: params.suggestedAction,
|
|
317
|
-
watchPath: params.watchPath,
|
|
318
|
-
staleHours: params.staleHours,
|
|
319
|
-
followupPattern: params.followupPattern,
|
|
320
|
-
followupWindowMs: params.followupWindowMs,
|
|
321
|
-
scope: params.scope,
|
|
322
|
-
suppressedUntil: null,
|
|
323
|
-
};
|
|
324
|
-
file.rules.push(rule);
|
|
325
|
-
saveRulesFile(configDir, file);
|
|
326
|
-
reviewLog(configDir, { event: "rule-added", ruleId: rule.id, ruleName: rule.name, type: rule.type });
|
|
327
|
-
return {
|
|
328
|
-
content: [{ type: "text", text: `Added rule "${rule.id}". The detector will pick it up within one scan cycle.` }],
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
catch (err) {
|
|
332
|
-
return {
|
|
333
|
-
content: [{ type: "text", text: `[review-tool] add failed: ${err instanceof Error ? err.message : String(err)}` }],
|
|
334
|
-
isError: true,
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
// -------------------------------------------------------------------------
|
|
339
|
-
// review-rules-remove
|
|
340
|
-
// -------------------------------------------------------------------------
|
|
341
|
-
server.tool("review-rules-remove", "Delete a review rule permanently. Any active ReviewAlert for that rule in Neo4j is also marked resolved so it stops appearing in the admin system prompt. Use review-rules-suppress instead when you want a temporary silence.", {
|
|
342
|
-
ruleId: z.string().describe("Rule id — get it from review-rules-list."),
|
|
343
|
-
}, async ({ ruleId }) => {
|
|
344
|
-
try {
|
|
345
|
-
const file = loadRulesFile(configDir);
|
|
346
|
-
const idx = file.rules.findIndex((r) => r.id === ruleId);
|
|
347
|
-
if (idx === -1) {
|
|
348
|
-
return {
|
|
349
|
-
content: [{ type: "text", text: `[review-tool] no rule with id "${ruleId}"` }],
|
|
350
|
-
isError: true,
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
file.rules.splice(idx, 1);
|
|
354
|
-
saveRulesFile(configDir, file);
|
|
355
|
-
// Also mark any open ReviewAlert as resolved so it drops out of
|
|
356
|
-
// loadSessionContext on the next admin turn.
|
|
357
|
-
const session = getSession();
|
|
358
|
-
try {
|
|
359
|
-
await session.run(`MATCH (a:ReviewAlert { ruleId: $ruleId, accountId: $accountId })
|
|
360
|
-
WHERE a.resolvedAt IS NULL
|
|
361
|
-
SET a.resolvedAt = datetime()`, { ruleId, accountId });
|
|
362
|
-
}
|
|
363
|
-
finally {
|
|
364
|
-
await session.close();
|
|
365
|
-
}
|
|
366
|
-
reviewLog(configDir, { event: "rule-removed", ruleId });
|
|
367
|
-
return {
|
|
368
|
-
content: [{ type: "text", text: `Removed rule "${ruleId}" and resolved any open alerts.` }],
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
catch (err) {
|
|
372
|
-
return {
|
|
373
|
-
content: [{ type: "text", text: `[review-tool] remove failed: ${err instanceof Error ? err.message : String(err)}` }],
|
|
374
|
-
isError: true,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
// -------------------------------------------------------------------------
|
|
379
|
-
// review-alerts-recent
|
|
380
|
-
// -------------------------------------------------------------------------
|
|
381
|
-
server.tool("review-alerts-recent", "Return the most recent ReviewAlert records for this account, including resolved and suppressed ones. Useful for debugging false positives, confirming a rule fired after a known-bad event, or auditing what the detector has been surfacing. Does NOT modify state.", {
|
|
382
|
-
limit: z.number().min(1).max(100).default(20).describe("Max alerts to return, default 20."),
|
|
383
|
-
includeResolved: z.boolean().default(false).describe("Include alerts that have been resolved."),
|
|
384
|
-
}, async ({ limit, includeResolved }) => {
|
|
385
|
-
const session = getSession();
|
|
386
|
-
try {
|
|
387
|
-
const query = includeResolved
|
|
388
|
-
? `MATCH (a:ReviewAlert {accountId: $accountId})
|
|
389
|
-
RETURN a.alertId AS alertId, a.ruleId AS ruleId, a.ruleName AS ruleName,
|
|
390
|
-
a.firstMatchAt AS firstMatchAt, a.lastMatchAt AS lastMatchAt,
|
|
391
|
-
a.cumulativeMatchCount AS count, a.sampleEvidence AS sampleEvidence,
|
|
392
|
-
a.suggestedAction AS suggestedAction,
|
|
393
|
-
a.suppressedUntil AS suppressedUntil, a.resolvedAt AS resolvedAt
|
|
394
|
-
ORDER BY a.lastMatchAt DESC LIMIT $limit`
|
|
395
|
-
: `MATCH (a:ReviewAlert {accountId: $accountId})
|
|
396
|
-
WHERE a.resolvedAt IS NULL
|
|
397
|
-
RETURN a.alertId AS alertId, a.ruleId AS ruleId, a.ruleName AS ruleName,
|
|
398
|
-
a.firstMatchAt AS firstMatchAt, a.lastMatchAt AS lastMatchAt,
|
|
399
|
-
a.cumulativeMatchCount AS count, a.sampleEvidence AS sampleEvidence,
|
|
400
|
-
a.suggestedAction AS suggestedAction,
|
|
401
|
-
a.suppressedUntil AS suppressedUntil, a.resolvedAt AS resolvedAt
|
|
402
|
-
ORDER BY a.lastMatchAt DESC LIMIT $limit`;
|
|
403
|
-
const result = await session.run(query, { accountId, limit: neo4j.int(limit) });
|
|
404
|
-
const alerts = result.records.map((r) => ({
|
|
405
|
-
alertId: r.get("alertId"),
|
|
406
|
-
ruleId: r.get("ruleId"),
|
|
407
|
-
ruleName: r.get("ruleName"),
|
|
408
|
-
firstMatchAt: r.get("firstMatchAt")?.toString?.() ?? null,
|
|
409
|
-
lastMatchAt: r.get("lastMatchAt")?.toString?.() ?? null,
|
|
410
|
-
count: r.get("count")?.toNumber?.() ?? 0,
|
|
411
|
-
sampleEvidence: r.get("sampleEvidence"),
|
|
412
|
-
suggestedAction: r.get("suggestedAction"),
|
|
413
|
-
suppressedUntil: r.get("suppressedUntil")?.toString?.() ?? null,
|
|
414
|
-
resolvedAt: r.get("resolvedAt")?.toString?.() ?? null,
|
|
415
|
-
}));
|
|
416
|
-
return {
|
|
417
|
-
content: [{ type: "text", text: JSON.stringify({ count: alerts.length, alerts }, null, 2) }],
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
catch (err) {
|
|
421
|
-
return {
|
|
422
|
-
content: [{ type: "text", text: `[review-tool] recent alerts query failed: ${err instanceof Error ? err.message : String(err)}` }],
|
|
423
|
-
isError: true,
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
finally {
|
|
427
|
-
await session.close();
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
// -------------------------------------------------------------------------
|
|
431
|
-
// review-digest-compose
|
|
432
|
-
// -------------------------------------------------------------------------
|
|
433
|
-
//
|
|
434
|
-
// Triggered by the scheduled Event (cron 0 8 * * *) via check-due-events.
|
|
435
|
-
// The tool reads the last 24h of review.log and the current ReviewAlert
|
|
436
|
-
// set, authors a short digest, and persists it as a CreativeWork node
|
|
437
|
-
// with title "Review Digest YYYY-MM-DD". loadSessionContext surfaces it on
|
|
438
|
-
// the next admin turn via its existing CreativeWork digest query.
|
|
439
|
-
//
|
|
440
|
-
// Also runs the detector-silence watchdog: if the review log has not been
|
|
441
|
-
// written in more than 2× the detector's scan interval, the tool emits a
|
|
442
|
-
// `[review:watchdog] detector silent` line to server.log so the silence
|
|
443
|
-
// is itself detectable by someone reading server.log.
|
|
444
|
-
server.tool("review-digest-compose", "Compose and persist the daily review digest (scheduled — invoked by check-due-events). Reads the last 24h of review.log and ReviewAlert records, authors a CreativeWork digest, and runs the detector-silence watchdog. Users should not call this directly; the platform schedules it via an Event.", {}, async () => {
|
|
445
|
-
const digestDate = new Date().toISOString().slice(0, 10);
|
|
446
|
-
const title = `Review Digest ${digestDate}`;
|
|
447
|
-
const now = Date.now();
|
|
448
|
-
const windowStartMs = now - 24 * 60 * 60 * 1000;
|
|
449
|
-
// 1. Read the last 24h of review.log. To keep memory bounded on a Pi
|
|
450
|
-
// where review.log can grow to hundreds of megabytes over time, cap
|
|
451
|
-
// the read at MAX_DIGEST_READ_BYTES from the end of the file. The
|
|
452
|
-
// 24h filter below then drops anything older than the cutoff.
|
|
453
|
-
const logPath = reviewLogPath(configDir);
|
|
454
|
-
let recentLines = [];
|
|
455
|
-
let detectorMtime = null;
|
|
456
|
-
if (existsSync(logPath)) {
|
|
457
|
-
try {
|
|
458
|
-
const st = statSync(logPath);
|
|
459
|
-
detectorMtime = st.mtimeMs;
|
|
460
|
-
const size = st.size;
|
|
461
|
-
const readFrom = Math.max(0, size - MAX_DIGEST_READ_BYTES);
|
|
462
|
-
const bufSize = size - readFrom;
|
|
463
|
-
let raw = "";
|
|
464
|
-
if (bufSize > 0) {
|
|
465
|
-
const fd = openSync(logPath, "r");
|
|
466
|
-
try {
|
|
467
|
-
const buf = Buffer.alloc(bufSize);
|
|
468
|
-
readSync(fd, buf, 0, bufSize, readFrom);
|
|
469
|
-
raw = buf.toString("utf-8");
|
|
470
|
-
}
|
|
471
|
-
finally {
|
|
472
|
-
closeSync(fd);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
// When we start mid-file, the first line will almost always be a
|
|
476
|
-
// partial — drop it so we don't try to parse corrupt JSON.
|
|
477
|
-
const all = raw.split("\n").filter((l) => l.length > 0);
|
|
478
|
-
if (readFrom > 0 && all.length > 0)
|
|
479
|
-
all.shift();
|
|
480
|
-
// Filter by timestamp prefix. Lines start with ISO 8601 timestamps so
|
|
481
|
-
// a lexicographic prefix comparison against the cutoff ISO string is
|
|
482
|
-
// correct and cheap.
|
|
483
|
-
const cutoffIso = new Date(windowStartMs).toISOString();
|
|
484
|
-
recentLines = all.filter((l) => l >= cutoffIso);
|
|
485
|
-
}
|
|
486
|
-
catch (err) {
|
|
487
|
-
reviewLog(configDir, {
|
|
488
|
-
event: "digest-read-failed",
|
|
489
|
-
error: err instanceof Error ? err.message : String(err),
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
// 2. Count events by type for the summary.
|
|
494
|
-
const eventCounts = {};
|
|
495
|
-
const ruleMatches = {};
|
|
496
|
-
for (const line of recentLines) {
|
|
497
|
-
const jsonStart = line.indexOf("{");
|
|
498
|
-
if (jsonStart === -1)
|
|
499
|
-
continue;
|
|
500
|
-
try {
|
|
501
|
-
const event = JSON.parse(line.slice(jsonStart));
|
|
502
|
-
if (event.event) {
|
|
503
|
-
eventCounts[event.event] = (eventCounts[event.event] ?? 0) + 1;
|
|
504
|
-
}
|
|
505
|
-
if (event.event === "match" && event.ruleId) {
|
|
506
|
-
ruleMatches[event.ruleId] = (ruleMatches[event.ruleId] ?? 0) + 1;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
catch {
|
|
510
|
-
// Not every line is pure JSON — skip.
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
// 3. Query Neo4j for active alerts to cross-reference.
|
|
514
|
-
let activeAlerts = [];
|
|
515
|
-
try {
|
|
516
|
-
const session = getSession();
|
|
517
|
-
try {
|
|
518
|
-
const result = await session.run(`MATCH (a:ReviewAlert {accountId: $accountId})
|
|
519
|
-
WHERE a.resolvedAt IS NULL
|
|
520
|
-
AND (a.suppressedUntil IS NULL OR a.suppressedUntil < datetime())
|
|
521
|
-
RETURN a.ruleName AS ruleName, a.cumulativeMatchCount AS count,
|
|
522
|
-
a.lastMatchAt AS lastMatchAt, a.suggestedAction AS suggestedAction
|
|
523
|
-
ORDER BY a.lastMatchAt DESC LIMIT 20`, { accountId });
|
|
524
|
-
activeAlerts = result.records.map((r) => {
|
|
525
|
-
const rawCount = r.get("count");
|
|
526
|
-
const count = typeof rawCount === "number"
|
|
527
|
-
? rawCount
|
|
528
|
-
: rawCount?.toNumber?.() ?? 0;
|
|
529
|
-
return {
|
|
530
|
-
ruleName: r.get("ruleName"),
|
|
531
|
-
count,
|
|
532
|
-
lastMatchAt: (r.get("lastMatchAt")?.toString?.() ?? ""),
|
|
533
|
-
suggestedAction: r.get("suggestedAction"),
|
|
534
|
-
};
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
finally {
|
|
538
|
-
await session.close();
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
catch (err) {
|
|
542
|
-
reviewLog(configDir, {
|
|
543
|
-
event: "digest-neo4j-failed",
|
|
544
|
-
error: err instanceof Error ? err.message : String(err),
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
// 4. Detector silence watchdog. Derive the threshold from the current
|
|
548
|
-
// rules file's scanIntervalMs — the detector writes one line per
|
|
549
|
-
// cycle, so silence longer than 2× the configured interval (with
|
|
550
|
-
// a 30s floor to absorb clock jitter and brief Neo4j delays) means
|
|
551
|
-
// the detector is not running. We raise a server.log line so this
|
|
552
|
-
// silence is itself visible on the most-consulted diagnostic surface.
|
|
553
|
-
let watchdogOk = true;
|
|
554
|
-
let watchdogThresholdMs = 30_000;
|
|
555
|
-
try {
|
|
556
|
-
const currentRules = loadRulesFile(configDir);
|
|
557
|
-
watchdogThresholdMs = Math.max(30_000, currentRules.scanIntervalMs * 2);
|
|
558
|
-
}
|
|
559
|
-
catch {
|
|
560
|
-
// Rules file may be missing or malformed — fall back to the 30s floor.
|
|
561
|
-
}
|
|
562
|
-
if (detectorMtime === null) {
|
|
563
|
-
watchdogOk = false;
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
const silentFor = now - detectorMtime;
|
|
567
|
-
if (silentFor > watchdogThresholdMs) {
|
|
568
|
-
watchdogOk = false;
|
|
569
|
-
// server.log is platform-scoped — write directly.
|
|
570
|
-
const serverLogPath = join(configDir, "logs", "server.log");
|
|
571
|
-
try {
|
|
572
|
-
const entry = `${new Date().toISOString()} [review:watchdog] detector silent for ${Math.round(silentFor / 1000)}s (threshold ${Math.round(watchdogThresholdMs / 1000)}s) — last write at ${new Date(detectorMtime).toISOString()}\n`;
|
|
573
|
-
appendFileSync(serverLogPath, entry, "utf-8");
|
|
574
|
-
}
|
|
575
|
-
catch {
|
|
576
|
-
console.error("[review-tool] failed to write watchdog line to server.log");
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
// 5. Compose the abstract.
|
|
581
|
-
const lines = [];
|
|
582
|
-
lines.push(`Review cadence report for ${digestDate} (${recentLines.length} review-log lines in the last 24h).`);
|
|
583
|
-
lines.push("");
|
|
584
|
-
if (activeAlerts.length === 0 && Object.keys(ruleMatches).length === 0 && watchdogOk) {
|
|
585
|
-
lines.push("Logs reviewed. No anomalies. Detector is healthy.");
|
|
586
|
-
}
|
|
587
|
-
else {
|
|
588
|
-
if (activeAlerts.length > 0) {
|
|
589
|
-
lines.push(`### Active alerts (${activeAlerts.length})`);
|
|
590
|
-
for (const alert of activeAlerts) {
|
|
591
|
-
lines.push(`- **${alert.ruleName}** (${alert.count}×, last at ${alert.lastMatchAt.slice(0, 19)})`);
|
|
592
|
-
lines.push(` → ${alert.suggestedAction}`);
|
|
593
|
-
}
|
|
594
|
-
lines.push("");
|
|
595
|
-
}
|
|
596
|
-
if (Object.keys(ruleMatches).length > 0) {
|
|
597
|
-
lines.push(`### Rule matches in window`);
|
|
598
|
-
for (const [ruleId, count] of Object.entries(ruleMatches)) {
|
|
599
|
-
lines.push(`- ${ruleId}: ${count}`);
|
|
600
|
-
}
|
|
601
|
-
lines.push("");
|
|
602
|
-
}
|
|
603
|
-
const notableEvents = ["rate-limit-deferred", "queue-drain", "source-rotated", "source-vanished", "cycle-failed", "rules-reload-failed"];
|
|
604
|
-
const notable = notableEvents.filter((e) => (eventCounts[e] ?? 0) > 0);
|
|
605
|
-
if (notable.length > 0) {
|
|
606
|
-
lines.push(`### Detector events`);
|
|
607
|
-
for (const e of notable) {
|
|
608
|
-
lines.push(`- ${e}: ${eventCounts[e]}`);
|
|
609
|
-
}
|
|
610
|
-
lines.push("");
|
|
611
|
-
}
|
|
612
|
-
if (!watchdogOk) {
|
|
613
|
-
lines.push(`### ⚠️ Detector watchdog`);
|
|
614
|
-
lines.push(detectorMtime === null
|
|
615
|
-
? "- review.log does not exist. The detector may have failed to boot."
|
|
616
|
-
: `- review.log has been silent since ${new Date(detectorMtime).toISOString()}. Investigate.`);
|
|
617
|
-
lines.push("");
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
const abstract = lines.join("\n");
|
|
621
|
-
// 6. Persist as CreativeWork.
|
|
622
|
-
const session = getSession();
|
|
623
|
-
try {
|
|
624
|
-
await session.run(`MERGE (d:CreativeWork {accountId: $accountId, title: $title})
|
|
625
|
-
ON CREATE SET d.createdAt = $createdAt, d.abstract = $abstract
|
|
626
|
-
ON MATCH SET d.createdAt = $createdAt, d.abstract = $abstract`, {
|
|
627
|
-
accountId,
|
|
628
|
-
title,
|
|
629
|
-
createdAt: new Date().toISOString(),
|
|
630
|
-
abstract,
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
catch (err) {
|
|
634
|
-
return {
|
|
635
|
-
content: [{ type: "text", text: `[review-tool] digest compose: Neo4j write failed — ${err instanceof Error ? err.message : String(err)}` }],
|
|
636
|
-
isError: true,
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
finally {
|
|
640
|
-
await session.close();
|
|
641
|
-
}
|
|
642
|
-
// The post-persist steps (audit log + success return) can still fail
|
|
643
|
-
// on a full disk. Wrap them so we always return a structured response
|
|
644
|
-
// rather than propagating an uncaught exception through the MCP layer.
|
|
645
|
-
try {
|
|
646
|
-
reviewLog(configDir, {
|
|
647
|
-
event: "digest-composed",
|
|
648
|
-
title,
|
|
649
|
-
reviewLogLines: recentLines.length,
|
|
650
|
-
activeAlerts: activeAlerts.length,
|
|
651
|
-
ruleMatches: Object.keys(ruleMatches).length,
|
|
652
|
-
watchdogOk,
|
|
653
|
-
});
|
|
654
|
-
return {
|
|
655
|
-
content: [{ type: "text", text: `Composed "${title}". Review log lines: ${recentLines.length}. Active alerts: ${activeAlerts.length}. Watchdog: ${watchdogOk ? "ok" : "silent"}.` }],
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
catch (err) {
|
|
659
|
-
return {
|
|
660
|
-
content: [{ type: "text", text: `[review-tool] digest compose: post-persist step failed — ${err instanceof Error ? err.message : String(err)}. The CreativeWork digest was saved but the audit log line could not be written.` }],
|
|
661
|
-
isError: true,
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
//# sourceMappingURL=review-tools.js.map
|