neuralbrain 0.0.2 → 0.1.0
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/.env.example +2 -2
- package/README.md +19 -4
- package/dist/ai/chat.d.ts +1 -2
- package/dist/ai/chat.d.ts.map +1 -1
- package/dist/ai/chat.js +1 -2
- package/dist/ai/chat.js.map +1 -1
- package/dist/ai/config.d.ts +1 -1
- package/dist/ai/config.js +2 -2
- package/dist/ai/config.js.map +1 -1
- package/dist/app.d.ts +1 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +417 -50
- package/dist/app.js.map +1 -1
- package/dist/cli.d.ts +53 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +437 -37
- package/dist/cli.js.map +1 -1
- package/dist/consolidation/candidates.d.ts.map +1 -1
- package/dist/consolidation/candidates.js +19 -4
- package/dist/consolidation/candidates.js.map +1 -1
- package/dist/consolidation/fixtures.js +1 -1
- package/dist/consolidation/fixtures.js.map +1 -1
- package/dist/consolidation/gate.d.ts.map +1 -1
- package/dist/consolidation/gate.js +145 -109
- package/dist/consolidation/gate.js.map +1 -1
- package/dist/consolidation/runner.d.ts +6 -0
- package/dist/consolidation/runner.d.ts.map +1 -1
- package/dist/consolidation/runner.js +22 -2
- package/dist/consolidation/runner.js.map +1 -1
- package/dist/dashboard/clientScript.d.ts +1 -1
- package/dist/dashboard/clientScript.d.ts.map +1 -1
- package/dist/dashboard/clientScript.js +3774 -905
- package/dist/dashboard/clientScript.js.map +1 -1
- package/dist/dashboard/html.d.ts.map +1 -1
- package/dist/dashboard/html.js +605 -101
- package/dist/dashboard/html.js.map +1 -1
- package/dist/dashboard/styles.d.ts +1 -1
- package/dist/dashboard/styles.d.ts.map +1 -1
- package/dist/dashboard/styles.js +1591 -359
- package/dist/dashboard/styles.js.map +1 -1
- package/dist/learning/embedWorker.d.ts +13 -0
- package/dist/learning/embedWorker.d.ts.map +1 -1
- package/dist/learning/embedWorker.js +329 -59
- package/dist/learning/embedWorker.js.map +1 -1
- package/dist/learning/embedding.d.ts +1 -0
- package/dist/learning/embedding.d.ts.map +1 -1
- package/dist/learning/embedding.js +101 -26
- package/dist/learning/embedding.js.map +1 -1
- package/dist/learning/engine.js +1 -1
- package/dist/learning/engine.js.map +1 -1
- package/dist/learning/search.d.ts +17 -1
- package/dist/learning/search.d.ts.map +1 -1
- package/dist/learning/search.js +2094 -354
- package/dist/learning/search.js.map +1 -1
- package/dist/learning/storeMeta.d.ts +9 -0
- package/dist/learning/storeMeta.d.ts.map +1 -1
- package/dist/learning/storeMeta.js +30 -24
- package/dist/learning/storeMeta.js.map +1 -1
- package/dist/learning/types.d.ts +57 -8
- package/dist/learning/types.d.ts.map +1 -1
- package/dist/lib/condenser.d.ts +112 -0
- package/dist/lib/condenser.d.ts.map +1 -0
- package/dist/lib/condenser.js +1337 -0
- package/dist/lib/condenser.js.map +1 -0
- package/dist/lib/db.d.ts +10 -0
- package/dist/lib/db.d.ts.map +1 -1
- package/dist/lib/db.js +654 -167
- package/dist/lib/db.js.map +1 -1
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +3 -2
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/projectSlug.d.ts +12 -5
- package/dist/lib/projectSlug.d.ts.map +1 -1
- package/dist/lib/projectSlug.js +62 -23
- package/dist/lib/projectSlug.js.map +1 -1
- package/dist/lib/recurrence.d.ts +16 -0
- package/dist/lib/recurrence.d.ts.map +1 -0
- package/dist/lib/recurrence.js +293 -0
- package/dist/lib/recurrence.js.map +1 -0
- package/dist/lib/scope.d.ts +36 -1
- package/dist/lib/scope.d.ts.map +1 -1
- package/dist/lib/scope.js +183 -19
- package/dist/lib/scope.js.map +1 -1
- package/dist/lib/signalTags.d.ts +39 -0
- package/dist/lib/signalTags.d.ts.map +1 -0
- package/dist/lib/signalTags.js +203 -0
- package/dist/lib/signalTags.js.map +1 -0
- package/dist/lib/spool.d.ts +2 -0
- package/dist/lib/spool.d.ts.map +1 -1
- package/dist/lib/spool.js +176 -65
- package/dist/lib/spool.js.map +1 -1
- package/dist/lib/storeDiagnostics.d.ts +41 -0
- package/dist/lib/storeDiagnostics.d.ts.map +1 -0
- package/dist/lib/storeDiagnostics.js +148 -0
- package/dist/lib/storeDiagnostics.js.map +1 -0
- package/dist/lib/temporal.d.ts +44 -0
- package/dist/lib/temporal.d.ts.map +1 -0
- package/dist/lib/temporal.js +1063 -0
- package/dist/lib/temporal.js.map +1 -0
- package/dist/mcp/server.d.ts +93 -3
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +499 -68
- package/dist/mcp/server.js.map +1 -1
- package/dist/memory/actionStore.d.ts +94 -3
- package/dist/memory/actionStore.d.ts.map +1 -1
- package/dist/memory/actionStore.js +412 -124
- package/dist/memory/actionStore.js.map +1 -1
- package/dist/memory/deadLetterStore.d.ts.map +1 -1
- package/dist/memory/deadLetterStore.js +4 -2
- package/dist/memory/deadLetterStore.js.map +1 -1
- package/dist/memory/embedQueueStore.d.ts +19 -8
- package/dist/memory/embedQueueStore.d.ts.map +1 -1
- package/dist/memory/embedQueueStore.js +55 -25
- package/dist/memory/embedQueueStore.js.map +1 -1
- package/dist/memory/failurePatternStore.d.ts +17 -1
- package/dist/memory/failurePatternStore.d.ts.map +1 -1
- package/dist/memory/failurePatternStore.js +54 -31
- package/dist/memory/failurePatternStore.js.map +1 -1
- package/dist/memory/graphStore.d.ts +133 -3
- package/dist/memory/graphStore.d.ts.map +1 -1
- package/dist/memory/graphStore.js +980 -155
- package/dist/memory/graphStore.js.map +1 -1
- package/dist/memory/noteStore.d.ts +27 -2
- package/dist/memory/noteStore.d.ts.map +1 -1
- package/dist/memory/noteStore.js +89 -26
- package/dist/memory/noteStore.js.map +1 -1
- package/dist/memory/observationStore.d.ts +11 -1
- package/dist/memory/observationStore.d.ts.map +1 -1
- package/dist/memory/observationStore.js +90 -15
- package/dist/memory/observationStore.js.map +1 -1
- package/dist/memory/projectRename.d.ts.map +1 -1
- package/dist/memory/projectRename.js +5 -1
- package/dist/memory/projectRename.js.map +1 -1
- package/dist/memory/rollupSweeper.d.ts.map +1 -1
- package/dist/memory/rollupSweeper.js +43 -23
- package/dist/memory/rollupSweeper.js.map +1 -1
- package/dist/memory/sessionStore.d.ts +25 -7
- package/dist/memory/sessionStore.d.ts.map +1 -1
- package/dist/memory/sessionStore.js +145 -33
- package/dist/memory/sessionStore.js.map +1 -1
- package/dist/memory/trajectoryStore.d.ts +8 -0
- package/dist/memory/trajectoryStore.d.ts.map +1 -1
- package/dist/memory/trajectoryStore.js +196 -130
- package/dist/memory/trajectoryStore.js.map +1 -1
- package/dist/middleware/rateLimiter.d.ts.map +1 -1
- package/dist/middleware/rateLimiter.js +24 -1
- package/dist/middleware/rateLimiter.js.map +1 -1
- package/dist/routes/dashboard.d.ts.map +1 -1
- package/dist/routes/dashboard.js +181 -8
- package/dist/routes/dashboard.js.map +1 -1
- package/dist/routes/mcp.d.ts.map +1 -1
- package/dist/routes/mcp.js +173 -21
- package/dist/routes/mcp.js.map +1 -1
- package/dist/routes/memories.js +9 -1
- package/dist/routes/memories.js.map +1 -1
- package/dist/scripts/doctor.d.ts +26 -2
- package/dist/scripts/doctor.d.ts.map +1 -1
- package/dist/scripts/doctor.js +371 -259
- package/dist/scripts/doctor.js.map +1 -1
- package/dist/scripts/installAgent.d.ts.map +1 -1
- package/dist/scripts/installAgent.js +101 -19
- package/dist/scripts/installAgent.js.map +1 -1
- package/dist/scripts/migrateAgentMemory.js +2 -2
- package/dist/scripts/smokeTest.js +1 -1
- package/dist/scripts/smokeTest.js.map +1 -1
- package/docker-compose.yml +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/plugin/hooks/postToolUse.js +155 -50
- package/plugin/hooks/sessionStart.js +179 -27
- package/plugin/hooks/sessionStop.js +152 -37
- package/plugin/plugin.json +1 -1
- package/plugin/rules/AGENTS.md +10 -8
- package/plugin/skills/brain-memory/REFERENCE.md +15 -14
- package/plugin/skills/brain-memory/SKILL.md +2 -2
- package/plugin/skills/digest/SKILL.md +1 -1
- package/plugin/skills/handoff/SKILL.md +1 -1
- package/plugin/skills/save/SKILL.md +2 -2
- package/plugin/skills/search/SKILL.md +2 -2
- package/src/ai/chat.ts +1 -2
- package/src/ai/config.ts +2 -2
- package/src/app.ts +475 -54
- package/src/cli.ts +500 -38
- package/src/consolidation/candidates.ts +22 -4
- package/src/consolidation/fixtures.ts +1 -1
- package/src/consolidation/gate.ts +177 -140
- package/src/consolidation/runner.ts +26 -2
- package/src/dashboard/clientScript.ts +3774 -905
- package/src/dashboard/html.ts +605 -101
- package/src/dashboard/styles.ts +1591 -359
- package/src/learning/embedWorker.ts +350 -70
- package/src/learning/embedding.ts +141 -28
- package/src/learning/engine.ts +1 -1
- package/src/learning/search.ts +2533 -397
- package/src/learning/storeMeta.ts +36 -29
- package/src/learning/types.ts +66 -8
- package/src/lib/condenser.ts +1515 -0
- package/src/lib/db.ts +690 -171
- package/src/lib/logger.ts +4 -2
- package/src/lib/projectSlug.ts +77 -23
- package/src/lib/recurrence.ts +382 -0
- package/src/lib/scope.ts +220 -22
- package/src/lib/signalTags.ts +257 -0
- package/src/lib/spool.ts +181 -71
- package/src/lib/storeDiagnostics.ts +181 -0
- package/src/lib/temporal.ts +1250 -0
- package/src/mcp/server.ts +559 -88
- package/src/memory/actionStore.ts +642 -171
- package/src/memory/deadLetterStore.ts +4 -2
- package/src/memory/embedQueueStore.ts +63 -27
- package/src/memory/failurePatternStore.ts +84 -31
- package/src/memory/graphStore.ts +1396 -215
- package/src/memory/noteStore.ts +151 -30
- package/src/memory/observationStore.ts +117 -17
- package/src/memory/projectRename.ts +6 -2
- package/src/memory/rollupSweeper.ts +46 -23
- package/src/memory/sessionStore.ts +197 -38
- package/src/memory/trajectoryStore.ts +260 -140
- package/src/middleware/rateLimiter.ts +24 -1
- package/src/routes/dashboard.ts +194 -9
- package/src/routes/mcp.ts +185 -26
- package/src/routes/memories.ts +8 -1
- package/src/scripts/doctor.ts +461 -262
- package/src/scripts/installAgent.ts +106 -19
- package/src/scripts/migrateAgentMemory.ts +2 -2
- package/src/scripts/smokeTest.ts +1 -1
package/dist/app.js
CHANGED
|
@@ -4,14 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.app = void 0;
|
|
7
|
+
exports.parseOptionalBoolQuery = parseOptionalBoolQuery;
|
|
7
8
|
exports.createApp = createApp;
|
|
8
9
|
const express_1 = __importDefault(require("express"));
|
|
9
10
|
const crypto_1 = __importDefault(require("crypto"));
|
|
10
11
|
const db_1 = require("./lib/db");
|
|
11
12
|
const logger_1 = require("./lib/logger");
|
|
13
|
+
const recurrence_1 = require("./lib/recurrence");
|
|
12
14
|
const tracing_1 = require("./middleware/tracing");
|
|
13
15
|
const rateLimiter_1 = require("./middleware/rateLimiter");
|
|
14
16
|
const auth_1 = require("./middleware/auth");
|
|
17
|
+
const storeDiagnostics_1 = require("./lib/storeDiagnostics");
|
|
15
18
|
const observationStore_1 = require("./memory/observationStore");
|
|
16
19
|
const trajectoryStore_1 = require("./memory/trajectoryStore");
|
|
17
20
|
const noteStore_1 = require("./memory/noteStore");
|
|
@@ -36,6 +39,7 @@ const memories_1 = require("./routes/memories");
|
|
|
36
39
|
const learning_1 = require("./routes/learning");
|
|
37
40
|
const dashboard_1 = require("./routes/dashboard");
|
|
38
41
|
const mcp_1 = require("./routes/mcp");
|
|
42
|
+
const SUMMARY_PUBLIC_COLUMNS = 'id, scope, project_id, kind, window_from, window_to, outcome, producer_tier, producer_model, prompt_version, verified, version, supersedes, is_latest, sources_expired, created_at';
|
|
39
43
|
function parseBoundedLimit(raw, defaultLimit = 50, maxLimit = 200) {
|
|
40
44
|
if (raw === undefined || raw === null || raw === '')
|
|
41
45
|
return defaultLimit;
|
|
@@ -44,6 +48,28 @@ function parseBoundedLimit(raw, defaultLimit = 50, maxLimit = 200) {
|
|
|
44
48
|
return defaultLimit;
|
|
45
49
|
return Math.min(parsed, maxLimit);
|
|
46
50
|
}
|
|
51
|
+
function parseBoundedOffset(raw, defaultOffset = 0) {
|
|
52
|
+
if (raw === undefined || raw === null || raw === '')
|
|
53
|
+
return defaultOffset;
|
|
54
|
+
const parsed = parseInt(String(raw), 10);
|
|
55
|
+
if (!Number.isFinite(parsed) || parsed < 0)
|
|
56
|
+
return defaultOffset;
|
|
57
|
+
return parsed;
|
|
58
|
+
}
|
|
59
|
+
function parseOptionalBoolQuery(raw) {
|
|
60
|
+
if (raw === true)
|
|
61
|
+
return true;
|
|
62
|
+
if (raw === false)
|
|
63
|
+
return false;
|
|
64
|
+
if (typeof raw === 'string') {
|
|
65
|
+
const norm = raw.trim().toLowerCase();
|
|
66
|
+
if (norm === 'true' || norm === '1')
|
|
67
|
+
return true;
|
|
68
|
+
if (norm === 'false' || norm === '0')
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
47
73
|
function createApp() {
|
|
48
74
|
const app = (0, express_1.default)();
|
|
49
75
|
// Basic middleware
|
|
@@ -53,6 +79,10 @@ function createApp() {
|
|
|
53
79
|
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
54
80
|
res.setHeader('X-Frame-Options', 'DENY');
|
|
55
81
|
res.setHeader('Permissions-Policy', 'camera=(), microphone=(), geolocation=()');
|
|
82
|
+
res.setHeader('Referrer-Policy', 'no-referrer');
|
|
83
|
+
if (process.env.BRAIN_HTTPS === '1') {
|
|
84
|
+
res.setHeader('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
|
|
85
|
+
}
|
|
56
86
|
next();
|
|
57
87
|
});
|
|
58
88
|
// Middleware pipeline order: tracing -> auth -> rate limiter -> routes
|
|
@@ -208,11 +238,14 @@ function createApp() {
|
|
|
208
238
|
app.get('/notes', (req, res) => {
|
|
209
239
|
const scope = req.query.scope;
|
|
210
240
|
const projectId = (req.query.project_id || req.query.projectId);
|
|
211
|
-
const
|
|
241
|
+
const includeAncestors = parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
242
|
+
const includeChildren = parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
243
|
+
const includeGlobal = parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? true;
|
|
244
|
+
const userId = (req.query.user_id || req.query.userId);
|
|
212
245
|
const concept = req.query.concept;
|
|
213
246
|
const filePath = (req.query.file_path || req.query.filePath);
|
|
214
|
-
const limit =
|
|
215
|
-
const offset =
|
|
247
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
248
|
+
const offset = parseBoundedOffset(req.query.offset, 0);
|
|
216
249
|
let type;
|
|
217
250
|
if (req.query.type) {
|
|
218
251
|
type = Array.isArray(req.query.type)
|
|
@@ -222,7 +255,10 @@ function createApp() {
|
|
|
222
255
|
const notes = (0, noteStore_1.listNotes)({
|
|
223
256
|
scope,
|
|
224
257
|
projectId,
|
|
258
|
+
includeAncestors,
|
|
259
|
+
includeChildren,
|
|
225
260
|
includeGlobal,
|
|
261
|
+
userId,
|
|
226
262
|
type,
|
|
227
263
|
concept,
|
|
228
264
|
filePath,
|
|
@@ -234,16 +270,32 @@ function createApp() {
|
|
|
234
270
|
// Files -> Notes associations (support URL-encoded and wildcard paths)
|
|
235
271
|
app.get(/^\/files\/(.+)\/notes$/, (req, res) => {
|
|
236
272
|
const rawPath = Array.isArray(req.params[0]) ? req.params[0][0] : req.params[0];
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
273
|
+
let decodedPath;
|
|
274
|
+
try {
|
|
275
|
+
decodedPath = decodeURIComponent(String(rawPath));
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
res.status(400).json({
|
|
279
|
+
error: {
|
|
280
|
+
code: 'BAD_REQUEST',
|
|
281
|
+
message: 'Malformed percent-encoding in file path',
|
|
282
|
+
trace_id: (0, tracing_1.getCorrelationId)(req),
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
245
287
|
const projectId = (req.query.project_id || req.query.projectId);
|
|
246
|
-
const
|
|
288
|
+
const includeAncestors = parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
289
|
+
const includeChildren = parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
290
|
+
const includeGlobal = parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? true;
|
|
291
|
+
const userId = (req.query.user_id || req.query.userId);
|
|
292
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
293
|
+
const notes = (0, noteStore_1.getNotesByFile)(decodedPath, projectId, limit, {
|
|
294
|
+
includeAncestors,
|
|
295
|
+
includeChildren,
|
|
296
|
+
includeGlobal,
|
|
297
|
+
userId,
|
|
298
|
+
});
|
|
247
299
|
res.json(notes);
|
|
248
300
|
});
|
|
249
301
|
// -------------------------------------------------------------------------
|
|
@@ -267,6 +319,10 @@ function createApp() {
|
|
|
267
319
|
app.get('/trajectories', (req, res) => {
|
|
268
320
|
const projectId = (req.query.project_id || req.query.projectId);
|
|
269
321
|
const scope = req.query.scope;
|
|
322
|
+
const includeAncestors = parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
323
|
+
const includeChildren = parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
324
|
+
const includeGlobal = parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? false;
|
|
325
|
+
const userId = (req.query.user_id || req.query.userId);
|
|
270
326
|
const taskType = (req.query.task_type || req.query.taskType);
|
|
271
327
|
// 'unknown' is a third answer here, not a missing one: a swept rollup has
|
|
272
328
|
// no outcome, and folding it into either branch would invent one.
|
|
@@ -279,11 +335,15 @@ function createApp() {
|
|
|
279
335
|
const rollupSource = rollupSourceParam === 'signalled' || rollupSourceParam === 'swept'
|
|
280
336
|
? rollupSourceParam
|
|
281
337
|
: undefined;
|
|
282
|
-
const limit =
|
|
283
|
-
const offset =
|
|
338
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
339
|
+
const offset = parseBoundedOffset(req.query.offset, 0);
|
|
284
340
|
const list = (0, trajectoryStore_1.listTrajectories)({
|
|
285
341
|
projectId,
|
|
286
342
|
scope,
|
|
343
|
+
includeAncestors,
|
|
344
|
+
includeChildren,
|
|
345
|
+
includeGlobal,
|
|
346
|
+
userId,
|
|
287
347
|
taskType,
|
|
288
348
|
success,
|
|
289
349
|
successUnknown,
|
|
@@ -314,13 +374,21 @@ function createApp() {
|
|
|
314
374
|
app.get('/observations', (req, res) => {
|
|
315
375
|
const projectId = (req.query.project_id || req.query.projectId);
|
|
316
376
|
const scope = req.query.scope;
|
|
377
|
+
const includeAncestors = parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
378
|
+
const includeChildren = parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
379
|
+
const includeGlobal = parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? false;
|
|
380
|
+
const userId = (req.query.user_id || req.query.userId);
|
|
317
381
|
const sessionId = (req.query.session_id || req.query.sessionId);
|
|
318
382
|
const failed = req.query.failed !== undefined ? parseInt(String(req.query.failed), 10) : undefined;
|
|
319
|
-
const limit =
|
|
320
|
-
const offset =
|
|
383
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
384
|
+
const offset = parseBoundedOffset(req.query.offset, 0);
|
|
321
385
|
const list = (0, observationStore_1.listObservations)({
|
|
322
386
|
projectId,
|
|
323
387
|
scope,
|
|
388
|
+
includeAncestors,
|
|
389
|
+
includeChildren,
|
|
390
|
+
includeGlobal,
|
|
391
|
+
userId,
|
|
324
392
|
sessionId,
|
|
325
393
|
failed,
|
|
326
394
|
limit,
|
|
@@ -335,7 +403,7 @@ function createApp() {
|
|
|
335
403
|
const id = Array.isArray(req.params.id) ? req.params.id[0] : req.params.id;
|
|
336
404
|
const db = (0, db_1.getDb)();
|
|
337
405
|
const summary = db
|
|
338
|
-
.prepare(
|
|
406
|
+
.prepare(`SELECT ${SUMMARY_PUBLIC_COLUMNS} FROM summaries WHERE id = ?`)
|
|
339
407
|
.get(id);
|
|
340
408
|
if (!summary) {
|
|
341
409
|
res.status(404).json({
|
|
@@ -351,7 +419,7 @@ function createApp() {
|
|
|
351
419
|
.prepare('SELECT id, summary_id, text, ordinal FROM summary_claims WHERE summary_id = ? ORDER BY ordinal ASC')
|
|
352
420
|
.all(summary.id);
|
|
353
421
|
const sources = db
|
|
354
|
-
.prepare('SELECT summary_id, claim_id, record_id,
|
|
422
|
+
.prepare('SELECT summary_id, claim_id, record_id, record_type FROM summary_sources WHERE summary_id = ?')
|
|
355
423
|
.all(summary.id);
|
|
356
424
|
res.json({
|
|
357
425
|
...summary,
|
|
@@ -379,11 +447,11 @@ function createApp() {
|
|
|
379
447
|
conditions.push('is_latest = 1');
|
|
380
448
|
}
|
|
381
449
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
382
|
-
const limit =
|
|
383
|
-
const offset =
|
|
450
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
451
|
+
const offset = parseBoundedOffset(req.query.offset, 0);
|
|
384
452
|
params.push(limit, offset);
|
|
385
453
|
const summaries = db
|
|
386
|
-
.prepare(`SELECT
|
|
454
|
+
.prepare(`SELECT ${SUMMARY_PUBLIC_COLUMNS} FROM summaries ${whereClause} ORDER BY created_at DESC LIMIT ? OFFSET ?`)
|
|
387
455
|
.all(...params);
|
|
388
456
|
if (summaries.length === 0) {
|
|
389
457
|
res.json([]);
|
|
@@ -395,7 +463,7 @@ function createApp() {
|
|
|
395
463
|
.prepare(`SELECT id, summary_id, text, ordinal FROM summary_claims WHERE summary_id IN (${placeholders}) ORDER BY ordinal ASC`)
|
|
396
464
|
.all(...summaryIds);
|
|
397
465
|
const allSources = db
|
|
398
|
-
.prepare(`SELECT summary_id, claim_id, record_id,
|
|
466
|
+
.prepare(`SELECT summary_id, claim_id, record_id, record_type FROM summary_sources WHERE summary_id IN (${placeholders})`)
|
|
399
467
|
.all(...summaryIds);
|
|
400
468
|
const claimsBySummary = new Map();
|
|
401
469
|
for (const c of allClaims) {
|
|
@@ -450,15 +518,31 @@ function createApp() {
|
|
|
450
518
|
});
|
|
451
519
|
app.get('/sessions', (req, res) => {
|
|
452
520
|
const projectId = (req.query.project_id || req.query.projectId);
|
|
521
|
+
const includeAncestors = parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
522
|
+
const includeChildren = parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
523
|
+
const rawIncludeGlobal = parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal);
|
|
524
|
+
const includeGlobal = projectId ? (rawIncludeGlobal ?? false) : rawIncludeGlobal;
|
|
525
|
+
const userId = (req.query.user_id || req.query.userId);
|
|
453
526
|
const status = req.query.status;
|
|
454
527
|
const agentName = (req.query.agent_name || req.query.agentName);
|
|
455
528
|
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
456
|
-
const sessions = (0, sessionStore_1.listSessions)({
|
|
529
|
+
const sessions = (0, sessionStore_1.listSessions)({
|
|
530
|
+
projectId,
|
|
531
|
+
includeAncestors,
|
|
532
|
+
includeChildren,
|
|
533
|
+
includeGlobal,
|
|
534
|
+
userId,
|
|
535
|
+
status,
|
|
536
|
+
agentName,
|
|
537
|
+
limit,
|
|
538
|
+
});
|
|
457
539
|
res.json({ sessions });
|
|
458
540
|
});
|
|
459
541
|
app.get('/sessions/:id', (req, res) => {
|
|
460
542
|
const id = Array.isArray(req.params.id) ? req.params.id[0] : req.params.id;
|
|
461
|
-
const
|
|
543
|
+
const limit = parseBoundedLimit(req.query.limit, 200, 500);
|
|
544
|
+
const offset = parseBoundedOffset(req.query.offset);
|
|
545
|
+
const details = (0, sessionStore_1.getSessionDetails)(id, { limit, offset });
|
|
462
546
|
if (!details) {
|
|
463
547
|
res.status(404).json({
|
|
464
548
|
error: {
|
|
@@ -473,7 +557,9 @@ function createApp() {
|
|
|
473
557
|
});
|
|
474
558
|
app.get('/sessions/:id/replay', (req, res) => {
|
|
475
559
|
const id = Array.isArray(req.params.id) ? req.params.id[0] : req.params.id;
|
|
476
|
-
const
|
|
560
|
+
const limit = parseBoundedLimit(req.query.limit, 200, 500);
|
|
561
|
+
const offset = parseBoundedOffset(req.query.offset);
|
|
562
|
+
const replay = (0, sessionStore_1.getSessionReplay)(id, { limit, offset });
|
|
477
563
|
if (!replay) {
|
|
478
564
|
res.status(404).json({
|
|
479
565
|
error: {
|
|
@@ -493,6 +579,123 @@ function createApp() {
|
|
|
493
579
|
const graph = (0, graphStore_1.getKnowledgeGraph)((0, graphStore_1.parseGraphQuery)(req.query));
|
|
494
580
|
res.json(graph);
|
|
495
581
|
});
|
|
582
|
+
app.post('/graph/entities', (req, res, next) => {
|
|
583
|
+
try {
|
|
584
|
+
if (!req.body || typeof req.body !== 'object' || Array.isArray(req.body)) {
|
|
585
|
+
res.status(400).json({
|
|
586
|
+
error: {
|
|
587
|
+
code: 'SCHEMA_INVALID',
|
|
588
|
+
message: 'Request body must be a JSON object',
|
|
589
|
+
trace_id: (0, tracing_1.getCorrelationId)(req),
|
|
590
|
+
},
|
|
591
|
+
});
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
const entity = (0, graphStore_1.upsertEntity)(req.body);
|
|
595
|
+
res.status(201).json({ entity });
|
|
596
|
+
}
|
|
597
|
+
catch (err) {
|
|
598
|
+
next(err);
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
app.get('/graph/entities', (req, res) => {
|
|
602
|
+
const projectId = (req.query.project_id || req.query.projectId);
|
|
603
|
+
const scope = req.query.scope;
|
|
604
|
+
const includeAncestors = parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
605
|
+
const includeChildren = parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
606
|
+
const includeGlobal = parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal);
|
|
607
|
+
const entityType = (req.query.entity_type || req.query.entityType);
|
|
608
|
+
const externalRef = (req.query.external_ref || req.query.externalRef);
|
|
609
|
+
const userId = (req.query.user_id || req.query.userId);
|
|
610
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
611
|
+
const entities = (0, graphStore_1.listEntities)({
|
|
612
|
+
projectId,
|
|
613
|
+
scope,
|
|
614
|
+
includeAncestors,
|
|
615
|
+
includeChildren,
|
|
616
|
+
includeGlobal,
|
|
617
|
+
entityType,
|
|
618
|
+
externalRef,
|
|
619
|
+
userId,
|
|
620
|
+
limit,
|
|
621
|
+
});
|
|
622
|
+
res.json({ entities });
|
|
623
|
+
});
|
|
624
|
+
app.get('/graph/entities/:id', (req, res) => {
|
|
625
|
+
const id = Array.isArray(req.params.id) ? req.params.id[0] : req.params.id;
|
|
626
|
+
const entity = (0, graphStore_1.getEntity)(id);
|
|
627
|
+
if (!entity) {
|
|
628
|
+
res.status(404).json({
|
|
629
|
+
error: {
|
|
630
|
+
code: 'NOT_FOUND',
|
|
631
|
+
message: `Entity '${id}' not found`,
|
|
632
|
+
trace_id: (0, tracing_1.getCorrelationId)(req),
|
|
633
|
+
},
|
|
634
|
+
});
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
res.json({ entity });
|
|
638
|
+
});
|
|
639
|
+
app.post('/graph/edges', (req, res, next) => {
|
|
640
|
+
try {
|
|
641
|
+
if (!req.body || typeof req.body !== 'object' || Array.isArray(req.body)) {
|
|
642
|
+
res.status(400).json({
|
|
643
|
+
error: {
|
|
644
|
+
code: 'SCHEMA_INVALID',
|
|
645
|
+
message: 'Request body must be a JSON object',
|
|
646
|
+
trace_id: (0, tracing_1.getCorrelationId)(req),
|
|
647
|
+
},
|
|
648
|
+
});
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
const edge = (0, graphStore_1.linkEntities)(req.body);
|
|
652
|
+
res.status(201).json({ edge });
|
|
653
|
+
}
|
|
654
|
+
catch (err) {
|
|
655
|
+
next(err);
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
app.delete('/graph/edges', (req, res, next) => {
|
|
659
|
+
try {
|
|
660
|
+
const body = req.body && typeof req.body === 'object' && !Array.isArray(req.body) ? req.body : {};
|
|
661
|
+
const result = (0, graphStore_1.unlinkEntities)({
|
|
662
|
+
id: (body.id ?? req.query.id),
|
|
663
|
+
source_id: (body.source_id ??
|
|
664
|
+
body.sourceId ??
|
|
665
|
+
req.query.source_id ??
|
|
666
|
+
req.query.sourceId),
|
|
667
|
+
target_id: (body.target_id ??
|
|
668
|
+
body.targetId ??
|
|
669
|
+
req.query.target_id ??
|
|
670
|
+
req.query.targetId),
|
|
671
|
+
relation: (body.relation ?? req.query.relation),
|
|
672
|
+
});
|
|
673
|
+
res.json(result);
|
|
674
|
+
}
|
|
675
|
+
catch (err) {
|
|
676
|
+
next(err);
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
app.delete('/graph/edges/:id', (req, res, next) => {
|
|
680
|
+
try {
|
|
681
|
+
const id = Array.isArray(req.params.id) ? req.params.id[0] : req.params.id;
|
|
682
|
+
const result = (0, graphStore_1.unlinkEntities)({ id });
|
|
683
|
+
if (result.deleted === 0) {
|
|
684
|
+
res.status(404).json({
|
|
685
|
+
error: {
|
|
686
|
+
code: 'NOT_FOUND',
|
|
687
|
+
message: `Edge '${id}' not found`,
|
|
688
|
+
trace_id: (0, tracing_1.getCorrelationId)(req),
|
|
689
|
+
},
|
|
690
|
+
});
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
res.json(result);
|
|
694
|
+
}
|
|
695
|
+
catch (err) {
|
|
696
|
+
next(err);
|
|
697
|
+
}
|
|
698
|
+
});
|
|
496
699
|
// -------------------------------------------------------------------------
|
|
497
700
|
// Actions
|
|
498
701
|
// -------------------------------------------------------------------------
|
|
@@ -505,25 +708,147 @@ function createApp() {
|
|
|
505
708
|
next(err);
|
|
506
709
|
}
|
|
507
710
|
});
|
|
508
|
-
app.get('/actions', (req, res) => {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
711
|
+
app.get('/actions/due', (req, res, next) => {
|
|
712
|
+
try {
|
|
713
|
+
const projectId = (req.query.project_id || req.query.projectId);
|
|
714
|
+
const includeAncestors = parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
715
|
+
const includeChildren = parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
716
|
+
const includeGlobal = parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? true;
|
|
717
|
+
const userId = (req.query.user_id || req.query.userId);
|
|
718
|
+
const before = req.query.before;
|
|
719
|
+
const unremindedOnly = parseOptionalBoolQuery(req.query.unreminded_only ?? req.query.unremindedOnly);
|
|
720
|
+
const rawCooldownMs = req.query.cooldown_ms ?? req.query.cooldownMs;
|
|
721
|
+
let cooldownMs;
|
|
722
|
+
if (rawCooldownMs !== undefined && rawCooldownMs !== '') {
|
|
723
|
+
cooldownMs = Number(rawCooldownMs);
|
|
724
|
+
}
|
|
725
|
+
else if (typeof req.query.cooldown === 'string' && req.query.cooldown.trim() !== '') {
|
|
726
|
+
const parsedMs = (0, recurrence_1.parseDurationMs)(req.query.cooldown);
|
|
727
|
+
if (parsedMs === null) {
|
|
728
|
+
const err = new Error(`Invalid cooldown duration '${req.query.cooldown}'`);
|
|
729
|
+
err.code = 'SCHEMA_INVALID';
|
|
730
|
+
throw err;
|
|
731
|
+
}
|
|
732
|
+
cooldownMs = parsedMs;
|
|
733
|
+
}
|
|
734
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
735
|
+
const actions = (0, actionStore_1.getDueActions)({
|
|
736
|
+
projectId,
|
|
737
|
+
includeAncestors,
|
|
738
|
+
includeChildren,
|
|
739
|
+
includeGlobal,
|
|
740
|
+
userId,
|
|
741
|
+
before,
|
|
742
|
+
unremindedOnly,
|
|
743
|
+
cooldownMs,
|
|
744
|
+
limit,
|
|
745
|
+
});
|
|
746
|
+
res.json({ actions });
|
|
747
|
+
}
|
|
748
|
+
catch (err) {
|
|
749
|
+
next(err);
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
app.post('/actions/reminders/check', (req, res, next) => {
|
|
753
|
+
try {
|
|
754
|
+
const body = req.body && typeof req.body === 'object' && !Array.isArray(req.body) ? req.body : {};
|
|
755
|
+
const projectId = (body.project_id ?? body.projectId);
|
|
756
|
+
const includeAncestors = parseOptionalBoolQuery(body.include_ancestors ?? body.includeAncestors) ?? true;
|
|
757
|
+
const includeChildren = parseOptionalBoolQuery(body.include_children ?? body.includeChildren) ?? false;
|
|
758
|
+
const includeGlobal = parseOptionalBoolQuery(body.include_global ?? body.includeGlobal) ?? true;
|
|
759
|
+
const userId = (body.user_id ?? body.userId);
|
|
760
|
+
const before = body.before;
|
|
761
|
+
const rawCooldownMs = body.cooldown_ms ?? body.cooldownMs;
|
|
762
|
+
let cooldownMs;
|
|
763
|
+
if (rawCooldownMs !== undefined && rawCooldownMs !== null && rawCooldownMs !== '') {
|
|
764
|
+
cooldownMs = typeof rawCooldownMs === 'boolean' ? Number.NaN : Number(rawCooldownMs);
|
|
765
|
+
}
|
|
766
|
+
else if (typeof body.cooldown === 'string' && body.cooldown.trim() !== '') {
|
|
767
|
+
const parsedMs = (0, recurrence_1.parseDurationMs)(body.cooldown);
|
|
768
|
+
if (parsedMs === null) {
|
|
769
|
+
const err = new Error(`Invalid cooldown duration '${body.cooldown}'`);
|
|
770
|
+
err.code = 'SCHEMA_INVALID';
|
|
771
|
+
throw err;
|
|
772
|
+
}
|
|
773
|
+
cooldownMs = parsedMs;
|
|
774
|
+
}
|
|
775
|
+
const dryRun = parseOptionalBoolQuery(body.dry_run ?? body.dryRun) ?? false;
|
|
776
|
+
const limit = body.limit !== undefined && body.limit !== null && body.limit !== ''
|
|
777
|
+
? parseBoundedLimit(body.limit, 50, 200)
|
|
778
|
+
: undefined;
|
|
779
|
+
const result = (0, actionStore_1.checkReminders)({
|
|
780
|
+
projectId,
|
|
781
|
+
includeAncestors,
|
|
782
|
+
includeChildren,
|
|
783
|
+
includeGlobal,
|
|
784
|
+
userId,
|
|
785
|
+
before,
|
|
786
|
+
cooldownMs,
|
|
787
|
+
dryRun,
|
|
788
|
+
limit,
|
|
789
|
+
});
|
|
790
|
+
res.json(result);
|
|
791
|
+
}
|
|
792
|
+
catch (err) {
|
|
793
|
+
next(err);
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
app.post('/actions/reminders/ack', (req, res, next) => {
|
|
797
|
+
try {
|
|
798
|
+
if (!req.body ||
|
|
799
|
+
typeof req.body !== 'object' ||
|
|
800
|
+
Array.isArray(req.body) ||
|
|
801
|
+
!Array.isArray(req.body.ids)) {
|
|
802
|
+
res.status(400).json({
|
|
803
|
+
error: {
|
|
804
|
+
code: 'SCHEMA_INVALID',
|
|
805
|
+
message: 'ids must be an array of action IDs',
|
|
806
|
+
trace_id: (0, tracing_1.getCorrelationId)(req),
|
|
807
|
+
},
|
|
808
|
+
});
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
const result = (0, actionStore_1.ackReminders)(req.body.ids, req.body.reminded_at ?? req.body.remindedAt);
|
|
812
|
+
res.json(result);
|
|
813
|
+
}
|
|
814
|
+
catch (err) {
|
|
815
|
+
next(err);
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
app.get('/actions', (req, res, next) => {
|
|
819
|
+
try {
|
|
820
|
+
const projectId = (req.query.project_id || req.query.projectId);
|
|
821
|
+
const includeAncestors = parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
822
|
+
const includeChildren = parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
823
|
+
const includeGlobal = parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? true;
|
|
824
|
+
const userId = (req.query.user_id || req.query.userId);
|
|
825
|
+
const sessionId = (req.query.session_id || req.query.sessionId);
|
|
826
|
+
const dueOnly = parseOptionalBoolQuery(req.query.due_only ?? req.query.dueOnly) ?? false;
|
|
827
|
+
const before = req.query.before;
|
|
828
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
829
|
+
let status;
|
|
830
|
+
if (req.query.status) {
|
|
831
|
+
status = Array.isArray(req.query.status)
|
|
832
|
+
? req.query.status
|
|
833
|
+
: String(req.query.status);
|
|
834
|
+
}
|
|
835
|
+
const actions = (0, actionStore_1.listActions)({
|
|
836
|
+
projectId,
|
|
837
|
+
includeAncestors,
|
|
838
|
+
includeChildren,
|
|
839
|
+
includeGlobal,
|
|
840
|
+
userId,
|
|
841
|
+
status,
|
|
842
|
+
sessionId,
|
|
843
|
+
dueOnly,
|
|
844
|
+
before,
|
|
845
|
+
limit,
|
|
846
|
+
});
|
|
847
|
+
res.json({ actions });
|
|
848
|
+
}
|
|
849
|
+
catch (err) {
|
|
850
|
+
next(err);
|
|
518
851
|
}
|
|
519
|
-
const actions = (0, actionStore_1.listActions)({
|
|
520
|
-
projectId,
|
|
521
|
-
includeGlobal,
|
|
522
|
-
status,
|
|
523
|
-
sessionId,
|
|
524
|
-
limit,
|
|
525
|
-
});
|
|
526
|
-
res.json({ actions });
|
|
527
852
|
});
|
|
528
853
|
app.patch('/actions/:id', (req, res, next) => {
|
|
529
854
|
try {
|
|
@@ -551,32 +876,51 @@ function createApp() {
|
|
|
551
876
|
app.get('/inject', (req, res) => {
|
|
552
877
|
const projectId = (req.query.project_id || req.query.projectId);
|
|
553
878
|
const taskType = (req.query.task_type || req.query.taskType);
|
|
879
|
+
const userId = (req.query.user_id || req.query.userId);
|
|
554
880
|
const limit = parseBoundedLimit(req.query.limit, 5, 200);
|
|
555
881
|
const failure_patterns = (0, failurePatternStore_1.getFailurePatterns)({
|
|
556
882
|
projectId,
|
|
557
883
|
taskType,
|
|
884
|
+
includeAncestors: true,
|
|
558
885
|
includeGlobal: true,
|
|
886
|
+
userId,
|
|
559
887
|
limit,
|
|
560
888
|
});
|
|
561
889
|
const prior_outcomes = (0, trajectoryStore_1.listTrajectories)({
|
|
562
890
|
projectId,
|
|
563
891
|
taskType,
|
|
892
|
+
includeAncestors: true,
|
|
893
|
+
userId,
|
|
564
894
|
limit,
|
|
565
895
|
});
|
|
566
896
|
const ready_actions = (0, actionStore_1.getReadyActions)({
|
|
567
897
|
projectId,
|
|
898
|
+
includeAncestors: true,
|
|
899
|
+
includeGlobal: true,
|
|
900
|
+
userId,
|
|
901
|
+
limit,
|
|
902
|
+
});
|
|
903
|
+
const due_actions = (0, actionStore_1.getDueActions)({
|
|
904
|
+
projectId,
|
|
905
|
+
includeAncestors: true,
|
|
906
|
+
includeGlobal: true,
|
|
907
|
+
userId,
|
|
568
908
|
limit,
|
|
569
909
|
});
|
|
570
910
|
const latest_session_summary = (0, sessionStore_1.getLatestSessionSummary)(projectId);
|
|
571
911
|
const lessons = (0, noteStore_1.listNotes)({
|
|
572
912
|
projectId,
|
|
913
|
+
includeAncestors: true,
|
|
573
914
|
includeGlobal: true,
|
|
915
|
+
userId,
|
|
574
916
|
type: ['lesson', 'bug', 'pattern'],
|
|
575
917
|
limit,
|
|
576
918
|
});
|
|
577
919
|
const notes = (0, noteStore_1.listNotes)({
|
|
578
920
|
projectId,
|
|
921
|
+
includeAncestors: true,
|
|
579
922
|
includeGlobal: true,
|
|
923
|
+
userId,
|
|
580
924
|
type: ['architecture', 'workflow', 'preference', 'fact'],
|
|
581
925
|
limit,
|
|
582
926
|
});
|
|
@@ -586,6 +930,7 @@ function createApp() {
|
|
|
586
930
|
failure_patterns,
|
|
587
931
|
prior_outcomes,
|
|
588
932
|
ready_actions,
|
|
933
|
+
due_actions,
|
|
589
934
|
latest_session_summary,
|
|
590
935
|
lessons,
|
|
591
936
|
notes,
|
|
@@ -598,10 +943,13 @@ function createApp() {
|
|
|
598
943
|
// -------------------------------------------------------------------------
|
|
599
944
|
app.get('/consolidate/candidates', (req, res) => {
|
|
600
945
|
const projectId = (req.query.project_id || req.query.projectId);
|
|
601
|
-
const limit =
|
|
602
|
-
const
|
|
946
|
+
const limit = parseBoundedLimit(req.query.limit, 5, 200);
|
|
947
|
+
const rawLeaseDuration = req.query.lease_duration_sec !== undefined
|
|
603
948
|
? parseInt(String(req.query.lease_duration_sec), 10)
|
|
604
949
|
: undefined;
|
|
950
|
+
const leaseDurationSec = rawLeaseDuration !== undefined && Number.isFinite(rawLeaseDuration) && rawLeaseDuration > 0
|
|
951
|
+
? rawLeaseDuration
|
|
952
|
+
: undefined;
|
|
605
953
|
const result = (0, candidates_1.getConsolidationCandidates)({
|
|
606
954
|
projectId,
|
|
607
955
|
limit,
|
|
@@ -886,6 +1234,18 @@ function createApp() {
|
|
|
886
1234
|
const diagnostics = (0, fixtures_1.runAiConformanceDiagnostics)();
|
|
887
1235
|
res.json(diagnostics);
|
|
888
1236
|
});
|
|
1237
|
+
// Read-only store inspection for `neuralbrain doctor`. The doctor asks the
|
|
1238
|
+
// service instead of opening the database file itself, so the service stays
|
|
1239
|
+
// the only process with the file open for writing.
|
|
1240
|
+
app.get('/diagnostics/store', (_req, res) => {
|
|
1241
|
+
const db = (0, db_1.getDb)();
|
|
1242
|
+
const health = (0, storeDiagnostics_1.inspectDatabaseHealth)(db);
|
|
1243
|
+
res.json({
|
|
1244
|
+
db: health,
|
|
1245
|
+
schema: health.ok ? (0, storeDiagnostics_1.inspectSchemaAlignment)(db) : { aligned: false, issues: ['database unavailable'] },
|
|
1246
|
+
counts: health.ok ? (0, storeDiagnostics_1.countStoreRecords)(db) : null,
|
|
1247
|
+
});
|
|
1248
|
+
});
|
|
889
1249
|
// Resolved generative configuration. Never includes an API key or any part
|
|
890
1250
|
// of one — it reports only which env var a tier needs.
|
|
891
1251
|
app.get('/diagnostics/ai-config', (_req, res) => {
|
|
@@ -897,11 +1257,18 @@ function createApp() {
|
|
|
897
1257
|
app.get('/failure-patterns', (req, res) => {
|
|
898
1258
|
const projectId = (req.query.project_id || req.query.projectId);
|
|
899
1259
|
const taskType = (req.query.task_type || req.query.taskType);
|
|
900
|
-
const
|
|
1260
|
+
const includeAncestors = parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
1261
|
+
const includeChildren = parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
1262
|
+
const includeGlobal = parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? true;
|
|
1263
|
+
const userId = (req.query.user_id || req.query.userId);
|
|
1264
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
901
1265
|
const patterns = (0, failurePatternStore_1.getFailurePatterns)({
|
|
902
1266
|
projectId,
|
|
903
1267
|
taskType,
|
|
904
|
-
|
|
1268
|
+
includeAncestors,
|
|
1269
|
+
includeChildren,
|
|
1270
|
+
includeGlobal,
|
|
1271
|
+
userId,
|
|
905
1272
|
limit,
|
|
906
1273
|
});
|
|
907
1274
|
res.json(patterns);
|
|
@@ -910,8 +1277,8 @@ function createApp() {
|
|
|
910
1277
|
const source = req.query.source;
|
|
911
1278
|
const reason = req.query.reason;
|
|
912
1279
|
const producer = req.query.producer;
|
|
913
|
-
const limit =
|
|
914
|
-
const offset =
|
|
1280
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
1281
|
+
const offset = parseBoundedOffset(req.query.offset, 0);
|
|
915
1282
|
const deadLetters = (0, deadLetterStore_1.listDeadLetters)({
|
|
916
1283
|
source,
|
|
917
1284
|
reason,
|
|
@@ -1002,7 +1369,7 @@ function createApp() {
|
|
|
1002
1369
|
res.status(500).json({
|
|
1003
1370
|
error: {
|
|
1004
1371
|
code: 'INTERNAL_SERVER_ERROR',
|
|
1005
|
-
message:
|
|
1372
|
+
message: 'Internal Server Error',
|
|
1006
1373
|
trace_id: traceId,
|
|
1007
1374
|
},
|
|
1008
1375
|
});
|