neuralbrain 0.0.1 → 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 +3 -2
- 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/src/app.ts
CHANGED
|
@@ -2,9 +2,11 @@ import express, { Request, Response, NextFunction } from 'express';
|
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import { getDb, isDatabaseUnavailableError } from './lib/db';
|
|
4
4
|
import { logger } from './lib/logger';
|
|
5
|
+
import { parseDurationMs } from './lib/recurrence';
|
|
5
6
|
import { getCorrelationId, requestTracing } from './middleware/tracing';
|
|
6
7
|
import { createRateLimiter } from './middleware/rateLimiter';
|
|
7
8
|
import { apiKeyAuth, hashApiKey, setDashboardSessionCookie } from './middleware/auth';
|
|
9
|
+
import { countStoreRecords, inspectDatabaseHealth, inspectSchemaAlignment } from './lib/storeDiagnostics';
|
|
8
10
|
import { captureObservations, getObservation, listObservations } from './memory/observationStore';
|
|
9
11
|
import {
|
|
10
12
|
captureTrajectories,
|
|
@@ -31,10 +33,21 @@ import {
|
|
|
31
33
|
listSessions,
|
|
32
34
|
startSession,
|
|
33
35
|
} from './memory/sessionStore';
|
|
34
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
getEntity,
|
|
38
|
+
getKnowledgeGraph,
|
|
39
|
+
linkEntities,
|
|
40
|
+
listEntities,
|
|
41
|
+
parseGraphQuery,
|
|
42
|
+
unlinkEntities,
|
|
43
|
+
upsertEntity,
|
|
44
|
+
} from './memory/graphStore';
|
|
35
45
|
import { renameProject } from './memory/projectRename';
|
|
36
46
|
import {
|
|
47
|
+
ackReminders,
|
|
48
|
+
checkReminders,
|
|
37
49
|
createAction,
|
|
50
|
+
getDueActions,
|
|
38
51
|
getReadyActions,
|
|
39
52
|
listActions,
|
|
40
53
|
updateAction,
|
|
@@ -62,6 +75,9 @@ import { learningRouter } from './routes/learning';
|
|
|
62
75
|
import { dashboardRouter } from './routes/dashboard';
|
|
63
76
|
import { mcpRouter } from './routes/mcp';
|
|
64
77
|
|
|
78
|
+
const SUMMARY_PUBLIC_COLUMNS =
|
|
79
|
+
'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';
|
|
80
|
+
|
|
65
81
|
function parseBoundedLimit(raw: unknown, defaultLimit = 50, maxLimit = 200): number {
|
|
66
82
|
if (raw === undefined || raw === null || raw === '') return defaultLimit;
|
|
67
83
|
const parsed = parseInt(String(raw), 10);
|
|
@@ -69,6 +85,24 @@ function parseBoundedLimit(raw: unknown, defaultLimit = 50, maxLimit = 200): num
|
|
|
69
85
|
return Math.min(parsed, maxLimit);
|
|
70
86
|
}
|
|
71
87
|
|
|
88
|
+
function parseBoundedOffset(raw: unknown, defaultOffset = 0): number {
|
|
89
|
+
if (raw === undefined || raw === null || raw === '') return defaultOffset;
|
|
90
|
+
const parsed = parseInt(String(raw), 10);
|
|
91
|
+
if (!Number.isFinite(parsed) || parsed < 0) return defaultOffset;
|
|
92
|
+
return parsed;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function parseOptionalBoolQuery(raw: unknown): boolean | undefined {
|
|
96
|
+
if (raw === true) return true;
|
|
97
|
+
if (raw === false) return false;
|
|
98
|
+
if (typeof raw === 'string') {
|
|
99
|
+
const norm = raw.trim().toLowerCase();
|
|
100
|
+
if (norm === 'true' || norm === '1') return true;
|
|
101
|
+
if (norm === 'false' || norm === '0') return false;
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
|
|
72
106
|
export function createApp(): express.Application {
|
|
73
107
|
const app = express();
|
|
74
108
|
|
|
@@ -80,6 +114,10 @@ export function createApp(): express.Application {
|
|
|
80
114
|
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
81
115
|
res.setHeader('X-Frame-Options', 'DENY');
|
|
82
116
|
res.setHeader('Permissions-Policy', 'camera=(), microphone=(), geolocation=()');
|
|
117
|
+
res.setHeader('Referrer-Policy', 'no-referrer');
|
|
118
|
+
if (process.env.BRAIN_HTTPS === '1') {
|
|
119
|
+
res.setHeader('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
|
|
120
|
+
}
|
|
83
121
|
next();
|
|
84
122
|
});
|
|
85
123
|
|
|
@@ -249,11 +287,17 @@ export function createApp(): express.Application {
|
|
|
249
287
|
app.get('/notes', (req: Request, res: Response) => {
|
|
250
288
|
const scope = req.query.scope as string | undefined;
|
|
251
289
|
const projectId = (req.query.project_id || req.query.projectId) as string | undefined;
|
|
252
|
-
const
|
|
290
|
+
const includeAncestors =
|
|
291
|
+
parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
292
|
+
const includeChildren =
|
|
293
|
+
parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
294
|
+
const includeGlobal =
|
|
295
|
+
parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? true;
|
|
296
|
+
const userId = (req.query.user_id || req.query.userId) as string | undefined;
|
|
253
297
|
const concept = req.query.concept as string | undefined;
|
|
254
298
|
const filePath = (req.query.file_path || req.query.filePath) as string | undefined;
|
|
255
|
-
const limit =
|
|
256
|
-
const offset =
|
|
299
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
300
|
+
const offset = parseBoundedOffset(req.query.offset, 0);
|
|
257
301
|
|
|
258
302
|
let type: string[] | undefined;
|
|
259
303
|
if (req.query.type) {
|
|
@@ -265,7 +309,10 @@ export function createApp(): express.Application {
|
|
|
265
309
|
const notes = listNotes({
|
|
266
310
|
scope,
|
|
267
311
|
projectId,
|
|
312
|
+
includeAncestors,
|
|
313
|
+
includeChildren,
|
|
268
314
|
includeGlobal,
|
|
315
|
+
userId,
|
|
269
316
|
type,
|
|
270
317
|
concept,
|
|
271
318
|
filePath,
|
|
@@ -278,17 +325,34 @@ export function createApp(): express.Application {
|
|
|
278
325
|
// Files -> Notes associations (support URL-encoded and wildcard paths)
|
|
279
326
|
app.get(/^\/files\/(.+)\/notes$/, (req: Request, res: Response) => {
|
|
280
327
|
const rawPath = Array.isArray(req.params[0]) ? req.params[0][0] : req.params[0];
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
328
|
+
let decodedPath: string;
|
|
329
|
+
try {
|
|
330
|
+
decodedPath = decodeURIComponent(String(rawPath));
|
|
331
|
+
} catch {
|
|
332
|
+
res.status(400).json({
|
|
333
|
+
error: {
|
|
334
|
+
code: 'BAD_REQUEST',
|
|
335
|
+
message: 'Malformed percent-encoding in file path',
|
|
336
|
+
trace_id: getCorrelationId(req),
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
290
341
|
const projectId = (req.query.project_id || req.query.projectId) as string | undefined;
|
|
291
|
-
const
|
|
342
|
+
const includeAncestors =
|
|
343
|
+
parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
344
|
+
const includeChildren =
|
|
345
|
+
parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
346
|
+
const includeGlobal =
|
|
347
|
+
parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? true;
|
|
348
|
+
const userId = (req.query.user_id || req.query.userId) as string | undefined;
|
|
349
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
350
|
+
const notes = getNotesByFile(decodedPath, projectId, limit, {
|
|
351
|
+
includeAncestors,
|
|
352
|
+
includeChildren,
|
|
353
|
+
includeGlobal,
|
|
354
|
+
userId,
|
|
355
|
+
});
|
|
292
356
|
res.json(notes);
|
|
293
357
|
});
|
|
294
358
|
|
|
@@ -314,6 +378,13 @@ export function createApp(): express.Application {
|
|
|
314
378
|
app.get('/trajectories', (req: Request, res: Response) => {
|
|
315
379
|
const projectId = (req.query.project_id || req.query.projectId) as string | undefined;
|
|
316
380
|
const scope = req.query.scope as string | undefined;
|
|
381
|
+
const includeAncestors =
|
|
382
|
+
parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
383
|
+
const includeChildren =
|
|
384
|
+
parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
385
|
+
const includeGlobal =
|
|
386
|
+
parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? false;
|
|
387
|
+
const userId = (req.query.user_id || req.query.userId) as string | undefined;
|
|
317
388
|
const taskType = (req.query.task_type || req.query.taskType) as string | undefined;
|
|
318
389
|
// 'unknown' is a third answer here, not a missing one: a swept rollup has
|
|
319
390
|
// no outcome, and folding it into either branch would invent one.
|
|
@@ -330,12 +401,16 @@ export function createApp(): express.Application {
|
|
|
330
401
|
rollupSourceParam === 'signalled' || rollupSourceParam === 'swept'
|
|
331
402
|
? rollupSourceParam
|
|
332
403
|
: undefined;
|
|
333
|
-
const limit =
|
|
334
|
-
const offset =
|
|
404
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
405
|
+
const offset = parseBoundedOffset(req.query.offset, 0);
|
|
335
406
|
|
|
336
407
|
const list = listTrajectories({
|
|
337
408
|
projectId,
|
|
338
409
|
scope,
|
|
410
|
+
includeAncestors,
|
|
411
|
+
includeChildren,
|
|
412
|
+
includeGlobal,
|
|
413
|
+
userId,
|
|
339
414
|
taskType,
|
|
340
415
|
success,
|
|
341
416
|
successUnknown,
|
|
@@ -368,15 +443,26 @@ export function createApp(): express.Application {
|
|
|
368
443
|
app.get('/observations', (req: Request, res: Response) => {
|
|
369
444
|
const projectId = (req.query.project_id || req.query.projectId) as string | undefined;
|
|
370
445
|
const scope = req.query.scope as string | undefined;
|
|
446
|
+
const includeAncestors =
|
|
447
|
+
parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
448
|
+
const includeChildren =
|
|
449
|
+
parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
450
|
+
const includeGlobal =
|
|
451
|
+
parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? false;
|
|
452
|
+
const userId = (req.query.user_id || req.query.userId) as string | undefined;
|
|
371
453
|
const sessionId = (req.query.session_id || req.query.sessionId) as string | undefined;
|
|
372
454
|
const failed =
|
|
373
455
|
req.query.failed !== undefined ? parseInt(String(req.query.failed), 10) : undefined;
|
|
374
|
-
const limit =
|
|
375
|
-
const offset =
|
|
456
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
457
|
+
const offset = parseBoundedOffset(req.query.offset, 0);
|
|
376
458
|
|
|
377
459
|
const list = listObservations({
|
|
378
460
|
projectId,
|
|
379
461
|
scope,
|
|
462
|
+
includeAncestors,
|
|
463
|
+
includeChildren,
|
|
464
|
+
includeGlobal,
|
|
465
|
+
userId,
|
|
380
466
|
sessionId,
|
|
381
467
|
failed,
|
|
382
468
|
limit,
|
|
@@ -392,7 +478,7 @@ export function createApp(): express.Application {
|
|
|
392
478
|
const id = Array.isArray(req.params.id) ? req.params.id[0] : req.params.id;
|
|
393
479
|
const db = getDb();
|
|
394
480
|
const summary = db
|
|
395
|
-
.prepare(
|
|
481
|
+
.prepare(`SELECT ${SUMMARY_PUBLIC_COLUMNS} FROM summaries WHERE id = ?`)
|
|
396
482
|
.get(id) as any;
|
|
397
483
|
|
|
398
484
|
if (!summary) {
|
|
@@ -410,7 +496,7 @@ export function createApp(): express.Application {
|
|
|
410
496
|
.prepare('SELECT id, summary_id, text, ordinal FROM summary_claims WHERE summary_id = ? ORDER BY ordinal ASC')
|
|
411
497
|
.all(summary.id);
|
|
412
498
|
const sources = db
|
|
413
|
-
.prepare('SELECT summary_id, claim_id, record_id,
|
|
499
|
+
.prepare('SELECT summary_id, claim_id, record_id, record_type FROM summary_sources WHERE summary_id = ?')
|
|
414
500
|
.all(summary.id);
|
|
415
501
|
|
|
416
502
|
res.json({
|
|
@@ -442,12 +528,12 @@ export function createApp(): express.Application {
|
|
|
442
528
|
}
|
|
443
529
|
|
|
444
530
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
445
|
-
const limit =
|
|
446
|
-
const offset =
|
|
531
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
532
|
+
const offset = parseBoundedOffset(req.query.offset, 0);
|
|
447
533
|
params.push(limit, offset);
|
|
448
534
|
|
|
449
535
|
const summaries = db
|
|
450
|
-
.prepare(`SELECT
|
|
536
|
+
.prepare(`SELECT ${SUMMARY_PUBLIC_COLUMNS} FROM summaries ${whereClause} ORDER BY created_at DESC LIMIT ? OFFSET ?`)
|
|
451
537
|
.all(...params) as any[];
|
|
452
538
|
|
|
453
539
|
if (summaries.length === 0) {
|
|
@@ -466,7 +552,7 @@ export function createApp(): express.Application {
|
|
|
466
552
|
|
|
467
553
|
const allSources = db
|
|
468
554
|
.prepare(
|
|
469
|
-
`SELECT summary_id, claim_id, record_id,
|
|
555
|
+
`SELECT summary_id, claim_id, record_id, record_type FROM summary_sources WHERE summary_id IN (${placeholders})`
|
|
470
556
|
)
|
|
471
557
|
.all(...summaryIds) as any[];
|
|
472
558
|
|
|
@@ -527,17 +613,37 @@ export function createApp(): express.Application {
|
|
|
527
613
|
|
|
528
614
|
app.get('/sessions', (req: Request, res: Response) => {
|
|
529
615
|
const projectId = (req.query.project_id || req.query.projectId) as string | undefined;
|
|
616
|
+
const includeAncestors =
|
|
617
|
+
parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
618
|
+
const includeChildren =
|
|
619
|
+
parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
620
|
+
const rawIncludeGlobal = parseOptionalBoolQuery(
|
|
621
|
+
req.query.include_global ?? req.query.includeGlobal
|
|
622
|
+
);
|
|
623
|
+
const includeGlobal = projectId ? (rawIncludeGlobal ?? false) : rawIncludeGlobal;
|
|
624
|
+
const userId = (req.query.user_id || req.query.userId) as string | undefined;
|
|
530
625
|
const status = req.query.status as string | undefined;
|
|
531
626
|
const agentName = (req.query.agent_name || req.query.agentName) as string | undefined;
|
|
532
627
|
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
533
628
|
|
|
534
|
-
const sessions = listSessions({
|
|
629
|
+
const sessions = listSessions({
|
|
630
|
+
projectId,
|
|
631
|
+
includeAncestors,
|
|
632
|
+
includeChildren,
|
|
633
|
+
includeGlobal,
|
|
634
|
+
userId,
|
|
635
|
+
status,
|
|
636
|
+
agentName,
|
|
637
|
+
limit,
|
|
638
|
+
});
|
|
535
639
|
res.json({ sessions });
|
|
536
640
|
});
|
|
537
641
|
|
|
538
642
|
app.get('/sessions/:id', (req: Request, res: Response) => {
|
|
539
643
|
const id = Array.isArray(req.params.id) ? req.params.id[0] : req.params.id;
|
|
540
|
-
const
|
|
644
|
+
const limit = parseBoundedLimit(req.query.limit, 200, 500);
|
|
645
|
+
const offset = parseBoundedOffset(req.query.offset);
|
|
646
|
+
const details = getSessionDetails(id, { limit, offset });
|
|
541
647
|
if (!details) {
|
|
542
648
|
res.status(404).json({
|
|
543
649
|
error: {
|
|
@@ -553,7 +659,9 @@ export function createApp(): express.Application {
|
|
|
553
659
|
|
|
554
660
|
app.get('/sessions/:id/replay', (req: Request, res: Response) => {
|
|
555
661
|
const id = Array.isArray(req.params.id) ? req.params.id[0] : req.params.id;
|
|
556
|
-
const
|
|
662
|
+
const limit = parseBoundedLimit(req.query.limit, 200, 500);
|
|
663
|
+
const offset = parseBoundedOffset(req.query.offset);
|
|
664
|
+
const replay = getSessionReplay(id, { limit, offset });
|
|
557
665
|
if (!replay) {
|
|
558
666
|
res.status(404).json({
|
|
559
667
|
error: {
|
|
@@ -575,6 +683,131 @@ export function createApp(): express.Application {
|
|
|
575
683
|
res.json(graph);
|
|
576
684
|
});
|
|
577
685
|
|
|
686
|
+
app.post('/graph/entities', (req: Request, res: Response, next: NextFunction) => {
|
|
687
|
+
try {
|
|
688
|
+
if (!req.body || typeof req.body !== 'object' || Array.isArray(req.body)) {
|
|
689
|
+
res.status(400).json({
|
|
690
|
+
error: {
|
|
691
|
+
code: 'SCHEMA_INVALID',
|
|
692
|
+
message: 'Request body must be a JSON object',
|
|
693
|
+
trace_id: getCorrelationId(req),
|
|
694
|
+
},
|
|
695
|
+
});
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
const entity = upsertEntity(req.body);
|
|
699
|
+
res.status(201).json({ entity });
|
|
700
|
+
} catch (err) {
|
|
701
|
+
next(err);
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
app.get('/graph/entities', (req: Request, res: Response) => {
|
|
706
|
+
const projectId = (req.query.project_id || req.query.projectId) as string | undefined;
|
|
707
|
+
const scope = req.query.scope as string | undefined;
|
|
708
|
+
const includeAncestors =
|
|
709
|
+
parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
710
|
+
const includeChildren =
|
|
711
|
+
parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
712
|
+
const includeGlobal = parseOptionalBoolQuery(
|
|
713
|
+
req.query.include_global ?? req.query.includeGlobal
|
|
714
|
+
);
|
|
715
|
+
const entityType = (req.query.entity_type || req.query.entityType) as string | undefined;
|
|
716
|
+
const externalRef = (req.query.external_ref || req.query.externalRef) as string | undefined;
|
|
717
|
+
const userId = (req.query.user_id || req.query.userId) as string | undefined;
|
|
718
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
719
|
+
|
|
720
|
+
const entities = listEntities({
|
|
721
|
+
projectId,
|
|
722
|
+
scope,
|
|
723
|
+
includeAncestors,
|
|
724
|
+
includeChildren,
|
|
725
|
+
includeGlobal,
|
|
726
|
+
entityType,
|
|
727
|
+
externalRef,
|
|
728
|
+
userId,
|
|
729
|
+
limit,
|
|
730
|
+
});
|
|
731
|
+
res.json({ entities });
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
app.get('/graph/entities/:id', (req: Request, res: Response) => {
|
|
735
|
+
const id = Array.isArray(req.params.id) ? req.params.id[0] : req.params.id;
|
|
736
|
+
const entity = getEntity(id);
|
|
737
|
+
if (!entity) {
|
|
738
|
+
res.status(404).json({
|
|
739
|
+
error: {
|
|
740
|
+
code: 'NOT_FOUND',
|
|
741
|
+
message: `Entity '${id}' not found`,
|
|
742
|
+
trace_id: getCorrelationId(req),
|
|
743
|
+
},
|
|
744
|
+
});
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
res.json({ entity });
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
app.post('/graph/edges', (req: Request, res: Response, next: NextFunction) => {
|
|
751
|
+
try {
|
|
752
|
+
if (!req.body || typeof req.body !== 'object' || Array.isArray(req.body)) {
|
|
753
|
+
res.status(400).json({
|
|
754
|
+
error: {
|
|
755
|
+
code: 'SCHEMA_INVALID',
|
|
756
|
+
message: 'Request body must be a JSON object',
|
|
757
|
+
trace_id: getCorrelationId(req),
|
|
758
|
+
},
|
|
759
|
+
});
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
const edge = linkEntities(req.body);
|
|
763
|
+
res.status(201).json({ edge });
|
|
764
|
+
} catch (err) {
|
|
765
|
+
next(err);
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
app.delete('/graph/edges', (req: Request, res: Response, next: NextFunction) => {
|
|
770
|
+
try {
|
|
771
|
+
const body =
|
|
772
|
+
req.body && typeof req.body === 'object' && !Array.isArray(req.body) ? req.body : {};
|
|
773
|
+
const result = unlinkEntities({
|
|
774
|
+
id: (body.id ?? req.query.id) as string | undefined,
|
|
775
|
+
source_id: (body.source_id ??
|
|
776
|
+
body.sourceId ??
|
|
777
|
+
req.query.source_id ??
|
|
778
|
+
req.query.sourceId) as string | undefined,
|
|
779
|
+
target_id: (body.target_id ??
|
|
780
|
+
body.targetId ??
|
|
781
|
+
req.query.target_id ??
|
|
782
|
+
req.query.targetId) as string | undefined,
|
|
783
|
+
relation: (body.relation ?? req.query.relation) as string | undefined,
|
|
784
|
+
});
|
|
785
|
+
res.json(result);
|
|
786
|
+
} catch (err) {
|
|
787
|
+
next(err);
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
app.delete('/graph/edges/:id', (req: Request, res: Response, next: NextFunction) => {
|
|
792
|
+
try {
|
|
793
|
+
const id = Array.isArray(req.params.id) ? req.params.id[0] : req.params.id;
|
|
794
|
+
const result = unlinkEntities({ id });
|
|
795
|
+
if (result.deleted === 0) {
|
|
796
|
+
res.status(404).json({
|
|
797
|
+
error: {
|
|
798
|
+
code: 'NOT_FOUND',
|
|
799
|
+
message: `Edge '${id}' not found`,
|
|
800
|
+
trace_id: getCorrelationId(req),
|
|
801
|
+
},
|
|
802
|
+
});
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
res.json(result);
|
|
806
|
+
} catch (err) {
|
|
807
|
+
next(err);
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
|
|
578
811
|
// -------------------------------------------------------------------------
|
|
579
812
|
// Actions
|
|
580
813
|
// -------------------------------------------------------------------------
|
|
@@ -587,27 +820,166 @@ export function createApp(): express.Application {
|
|
|
587
820
|
}
|
|
588
821
|
});
|
|
589
822
|
|
|
590
|
-
app.get('/actions', (req: Request, res: Response) => {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
823
|
+
app.get('/actions/due', (req: Request, res: Response, next: NextFunction) => {
|
|
824
|
+
try {
|
|
825
|
+
const projectId = (req.query.project_id || req.query.projectId) as string | undefined;
|
|
826
|
+
const includeAncestors =
|
|
827
|
+
parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
828
|
+
const includeChildren =
|
|
829
|
+
parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
830
|
+
const includeGlobal =
|
|
831
|
+
parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? true;
|
|
832
|
+
const userId = (req.query.user_id || req.query.userId) as string | undefined;
|
|
833
|
+
const before = req.query.before as string | undefined;
|
|
834
|
+
const unremindedOnly = parseOptionalBoolQuery(
|
|
835
|
+
req.query.unreminded_only ?? req.query.unremindedOnly
|
|
836
|
+
);
|
|
837
|
+
const rawCooldownMs = req.query.cooldown_ms ?? req.query.cooldownMs;
|
|
838
|
+
let cooldownMs: number | undefined;
|
|
839
|
+
if (rawCooldownMs !== undefined && rawCooldownMs !== '') {
|
|
840
|
+
cooldownMs = Number(rawCooldownMs);
|
|
841
|
+
} else if (typeof req.query.cooldown === 'string' && req.query.cooldown.trim() !== '') {
|
|
842
|
+
const parsedMs = parseDurationMs(req.query.cooldown);
|
|
843
|
+
if (parsedMs === null) {
|
|
844
|
+
const err = new Error(`Invalid cooldown duration '${req.query.cooldown}'`);
|
|
845
|
+
(err as any).code = 'SCHEMA_INVALID';
|
|
846
|
+
throw err;
|
|
847
|
+
}
|
|
848
|
+
cooldownMs = parsedMs;
|
|
849
|
+
}
|
|
850
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
851
|
+
|
|
852
|
+
const actions = getDueActions({
|
|
853
|
+
projectId,
|
|
854
|
+
includeAncestors,
|
|
855
|
+
includeChildren,
|
|
856
|
+
includeGlobal,
|
|
857
|
+
userId,
|
|
858
|
+
before,
|
|
859
|
+
unremindedOnly,
|
|
860
|
+
cooldownMs,
|
|
861
|
+
limit,
|
|
862
|
+
});
|
|
863
|
+
res.json({ actions });
|
|
864
|
+
} catch (err) {
|
|
865
|
+
next(err);
|
|
866
|
+
}
|
|
867
|
+
});
|
|
595
868
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
869
|
+
app.post('/actions/reminders/check', (req: Request, res: Response, next: NextFunction) => {
|
|
870
|
+
try {
|
|
871
|
+
const body =
|
|
872
|
+
req.body && typeof req.body === 'object' && !Array.isArray(req.body) ? req.body : {};
|
|
873
|
+
const projectId = (body.project_id ?? body.projectId) as string | undefined;
|
|
874
|
+
const includeAncestors =
|
|
875
|
+
parseOptionalBoolQuery(body.include_ancestors ?? body.includeAncestors) ?? true;
|
|
876
|
+
const includeChildren =
|
|
877
|
+
parseOptionalBoolQuery(body.include_children ?? body.includeChildren) ?? false;
|
|
878
|
+
const includeGlobal =
|
|
879
|
+
parseOptionalBoolQuery(body.include_global ?? body.includeGlobal) ?? true;
|
|
880
|
+
const userId = (body.user_id ?? body.userId) as string | undefined;
|
|
881
|
+
const before = body.before as string | undefined;
|
|
882
|
+
const rawCooldownMs = body.cooldown_ms ?? body.cooldownMs;
|
|
883
|
+
let cooldownMs: number | undefined;
|
|
884
|
+
if (rawCooldownMs !== undefined && rawCooldownMs !== null && rawCooldownMs !== '') {
|
|
885
|
+
cooldownMs = typeof rawCooldownMs === 'boolean' ? Number.NaN : Number(rawCooldownMs);
|
|
886
|
+
} else if (typeof body.cooldown === 'string' && body.cooldown.trim() !== '') {
|
|
887
|
+
const parsedMs = parseDurationMs(body.cooldown);
|
|
888
|
+
if (parsedMs === null) {
|
|
889
|
+
const err = new Error(`Invalid cooldown duration '${body.cooldown}'`);
|
|
890
|
+
(err as any).code = 'SCHEMA_INVALID';
|
|
891
|
+
throw err;
|
|
892
|
+
}
|
|
893
|
+
cooldownMs = parsedMs;
|
|
894
|
+
}
|
|
895
|
+
const dryRun = parseOptionalBoolQuery(body.dry_run ?? body.dryRun) ?? false;
|
|
896
|
+
const limit =
|
|
897
|
+
body.limit !== undefined && body.limit !== null && body.limit !== ''
|
|
898
|
+
? parseBoundedLimit(body.limit, 50, 200)
|
|
899
|
+
: undefined;
|
|
900
|
+
|
|
901
|
+
const result = checkReminders({
|
|
902
|
+
projectId,
|
|
903
|
+
includeAncestors,
|
|
904
|
+
includeChildren,
|
|
905
|
+
includeGlobal,
|
|
906
|
+
userId,
|
|
907
|
+
before,
|
|
908
|
+
cooldownMs,
|
|
909
|
+
dryRun,
|
|
910
|
+
limit,
|
|
911
|
+
});
|
|
912
|
+
res.json(result);
|
|
913
|
+
} catch (err) {
|
|
914
|
+
next(err);
|
|
601
915
|
}
|
|
916
|
+
});
|
|
602
917
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
918
|
+
app.post('/actions/reminders/ack', (req: Request, res: Response, next: NextFunction) => {
|
|
919
|
+
try {
|
|
920
|
+
if (
|
|
921
|
+
!req.body ||
|
|
922
|
+
typeof req.body !== 'object' ||
|
|
923
|
+
Array.isArray(req.body) ||
|
|
924
|
+
!Array.isArray(req.body.ids)
|
|
925
|
+
) {
|
|
926
|
+
res.status(400).json({
|
|
927
|
+
error: {
|
|
928
|
+
code: 'SCHEMA_INVALID',
|
|
929
|
+
message: 'ids must be an array of action IDs',
|
|
930
|
+
trace_id: getCorrelationId(req),
|
|
931
|
+
},
|
|
932
|
+
});
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
const result = ackReminders(
|
|
936
|
+
req.body.ids,
|
|
937
|
+
req.body.reminded_at ?? req.body.remindedAt
|
|
938
|
+
);
|
|
939
|
+
res.json(result);
|
|
940
|
+
} catch (err) {
|
|
941
|
+
next(err);
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
|
|
945
|
+
app.get('/actions', (req: Request, res: Response, next: NextFunction) => {
|
|
946
|
+
try {
|
|
947
|
+
const projectId = (req.query.project_id || req.query.projectId) as string | undefined;
|
|
948
|
+
const includeAncestors =
|
|
949
|
+
parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
950
|
+
const includeChildren =
|
|
951
|
+
parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
952
|
+
const includeGlobal =
|
|
953
|
+
parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? true;
|
|
954
|
+
const userId = (req.query.user_id || req.query.userId) as string | undefined;
|
|
955
|
+
const sessionId = (req.query.session_id || req.query.sessionId) as string | undefined;
|
|
956
|
+
const dueOnly = parseOptionalBoolQuery(req.query.due_only ?? req.query.dueOnly) ?? false;
|
|
957
|
+
const before = req.query.before as string | undefined;
|
|
958
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
959
|
+
|
|
960
|
+
let status: string | string[] | undefined;
|
|
961
|
+
if (req.query.status) {
|
|
962
|
+
status = Array.isArray(req.query.status)
|
|
963
|
+
? (req.query.status as string[])
|
|
964
|
+
: String(req.query.status);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
const actions = listActions({
|
|
968
|
+
projectId,
|
|
969
|
+
includeAncestors,
|
|
970
|
+
includeChildren,
|
|
971
|
+
includeGlobal,
|
|
972
|
+
userId,
|
|
973
|
+
status,
|
|
974
|
+
sessionId,
|
|
975
|
+
dueOnly,
|
|
976
|
+
before,
|
|
977
|
+
limit,
|
|
978
|
+
});
|
|
979
|
+
res.json({ actions });
|
|
980
|
+
} catch (err) {
|
|
981
|
+
next(err);
|
|
982
|
+
}
|
|
611
983
|
});
|
|
612
984
|
|
|
613
985
|
app.patch('/actions/:id', (req: Request, res: Response, next: NextFunction) => {
|
|
@@ -636,23 +1008,39 @@ export function createApp(): express.Application {
|
|
|
636
1008
|
app.get('/inject', (req: Request, res: Response) => {
|
|
637
1009
|
const projectId = (req.query.project_id || req.query.projectId) as string | undefined;
|
|
638
1010
|
const taskType = (req.query.task_type || req.query.taskType) as string | undefined;
|
|
1011
|
+
const userId = (req.query.user_id || req.query.userId) as string | undefined;
|
|
639
1012
|
const limit = parseBoundedLimit(req.query.limit, 5, 200);
|
|
640
1013
|
|
|
641
1014
|
const failure_patterns = getFailurePatterns({
|
|
642
1015
|
projectId,
|
|
643
1016
|
taskType,
|
|
1017
|
+
includeAncestors: true,
|
|
644
1018
|
includeGlobal: true,
|
|
1019
|
+
userId,
|
|
645
1020
|
limit,
|
|
646
1021
|
});
|
|
647
1022
|
|
|
648
1023
|
const prior_outcomes = listTrajectories({
|
|
649
1024
|
projectId,
|
|
650
1025
|
taskType,
|
|
1026
|
+
includeAncestors: true,
|
|
1027
|
+
userId,
|
|
651
1028
|
limit,
|
|
652
1029
|
});
|
|
653
1030
|
|
|
654
1031
|
const ready_actions = getReadyActions({
|
|
655
1032
|
projectId,
|
|
1033
|
+
includeAncestors: true,
|
|
1034
|
+
includeGlobal: true,
|
|
1035
|
+
userId,
|
|
1036
|
+
limit,
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
const due_actions = getDueActions({
|
|
1040
|
+
projectId,
|
|
1041
|
+
includeAncestors: true,
|
|
1042
|
+
includeGlobal: true,
|
|
1043
|
+
userId,
|
|
656
1044
|
limit,
|
|
657
1045
|
});
|
|
658
1046
|
|
|
@@ -660,14 +1048,18 @@ export function createApp(): express.Application {
|
|
|
660
1048
|
|
|
661
1049
|
const lessons = listNotes({
|
|
662
1050
|
projectId,
|
|
1051
|
+
includeAncestors: true,
|
|
663
1052
|
includeGlobal: true,
|
|
1053
|
+
userId,
|
|
664
1054
|
type: ['lesson', 'bug', 'pattern'],
|
|
665
1055
|
limit,
|
|
666
1056
|
});
|
|
667
1057
|
|
|
668
1058
|
const notes = listNotes({
|
|
669
1059
|
projectId,
|
|
1060
|
+
includeAncestors: true,
|
|
670
1061
|
includeGlobal: true,
|
|
1062
|
+
userId,
|
|
671
1063
|
type: ['architecture', 'workflow', 'preference', 'fact'],
|
|
672
1064
|
limit,
|
|
673
1065
|
});
|
|
@@ -682,6 +1074,7 @@ export function createApp(): express.Application {
|
|
|
682
1074
|
failure_patterns,
|
|
683
1075
|
prior_outcomes,
|
|
684
1076
|
ready_actions,
|
|
1077
|
+
due_actions,
|
|
685
1078
|
latest_session_summary,
|
|
686
1079
|
lessons,
|
|
687
1080
|
notes,
|
|
@@ -695,10 +1088,15 @@ export function createApp(): express.Application {
|
|
|
695
1088
|
// -------------------------------------------------------------------------
|
|
696
1089
|
app.get('/consolidate/candidates', (req: Request, res: Response) => {
|
|
697
1090
|
const projectId = (req.query.project_id || req.query.projectId) as string | undefined;
|
|
698
|
-
const limit =
|
|
699
|
-
const
|
|
700
|
-
|
|
701
|
-
|
|
1091
|
+
const limit = parseBoundedLimit(req.query.limit, 5, 200);
|
|
1092
|
+
const rawLeaseDuration =
|
|
1093
|
+
req.query.lease_duration_sec !== undefined
|
|
1094
|
+
? parseInt(String(req.query.lease_duration_sec), 10)
|
|
1095
|
+
: undefined;
|
|
1096
|
+
const leaseDurationSec =
|
|
1097
|
+
rawLeaseDuration !== undefined && Number.isFinite(rawLeaseDuration) && rawLeaseDuration > 0
|
|
1098
|
+
? rawLeaseDuration
|
|
1099
|
+
: undefined;
|
|
702
1100
|
|
|
703
1101
|
const result = getConsolidationCandidates({
|
|
704
1102
|
projectId,
|
|
@@ -1004,6 +1402,19 @@ export function createApp(): express.Application {
|
|
|
1004
1402
|
res.json(diagnostics);
|
|
1005
1403
|
});
|
|
1006
1404
|
|
|
1405
|
+
// Read-only store inspection for `neuralbrain doctor`. The doctor asks the
|
|
1406
|
+
// service instead of opening the database file itself, so the service stays
|
|
1407
|
+
// the only process with the file open for writing.
|
|
1408
|
+
app.get('/diagnostics/store', (_req: Request, res: Response) => {
|
|
1409
|
+
const db = getDb();
|
|
1410
|
+
const health = inspectDatabaseHealth(db);
|
|
1411
|
+
res.json({
|
|
1412
|
+
db: health,
|
|
1413
|
+
schema: health.ok ? inspectSchemaAlignment(db) : { aligned: false, issues: ['database unavailable'] },
|
|
1414
|
+
counts: health.ok ? countStoreRecords(db) : null,
|
|
1415
|
+
});
|
|
1416
|
+
});
|
|
1417
|
+
|
|
1007
1418
|
// Resolved generative configuration. Never includes an API key or any part
|
|
1008
1419
|
// of one — it reports only which env var a tier needs.
|
|
1009
1420
|
app.get('/diagnostics/ai-config', (_req: Request, res: Response) => {
|
|
@@ -1016,12 +1427,22 @@ export function createApp(): express.Application {
|
|
|
1016
1427
|
app.get('/failure-patterns', (req: Request, res: Response) => {
|
|
1017
1428
|
const projectId = (req.query.project_id || req.query.projectId) as string | undefined;
|
|
1018
1429
|
const taskType = (req.query.task_type || req.query.taskType) as string | undefined;
|
|
1019
|
-
const
|
|
1430
|
+
const includeAncestors =
|
|
1431
|
+
parseOptionalBoolQuery(req.query.include_ancestors ?? req.query.includeAncestors) ?? true;
|
|
1432
|
+
const includeChildren =
|
|
1433
|
+
parseOptionalBoolQuery(req.query.include_children ?? req.query.includeChildren) ?? false;
|
|
1434
|
+
const includeGlobal =
|
|
1435
|
+
parseOptionalBoolQuery(req.query.include_global ?? req.query.includeGlobal) ?? true;
|
|
1436
|
+
const userId = (req.query.user_id || req.query.userId) as string | undefined;
|
|
1437
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
1020
1438
|
|
|
1021
1439
|
const patterns = getFailurePatterns({
|
|
1022
1440
|
projectId,
|
|
1023
1441
|
taskType,
|
|
1024
|
-
|
|
1442
|
+
includeAncestors,
|
|
1443
|
+
includeChildren,
|
|
1444
|
+
includeGlobal,
|
|
1445
|
+
userId,
|
|
1025
1446
|
limit,
|
|
1026
1447
|
});
|
|
1027
1448
|
res.json(patterns);
|
|
@@ -1031,8 +1452,8 @@ export function createApp(): express.Application {
|
|
|
1031
1452
|
const source = req.query.source as string | undefined;
|
|
1032
1453
|
const reason = req.query.reason as string | undefined;
|
|
1033
1454
|
const producer = req.query.producer as string | undefined;
|
|
1034
|
-
const limit =
|
|
1035
|
-
const offset =
|
|
1455
|
+
const limit = parseBoundedLimit(req.query.limit, 50, 200);
|
|
1456
|
+
const offset = parseBoundedOffset(req.query.offset, 0);
|
|
1036
1457
|
|
|
1037
1458
|
const deadLetters = listDeadLetters({
|
|
1038
1459
|
source,
|
|
@@ -1138,7 +1559,7 @@ export function createApp(): express.Application {
|
|
|
1138
1559
|
res.status(500).json({
|
|
1139
1560
|
error: {
|
|
1140
1561
|
code: 'INTERNAL_SERVER_ERROR',
|
|
1141
|
-
message:
|
|
1562
|
+
message: 'Internal Server Error',
|
|
1142
1563
|
trace_id: traceId,
|
|
1143
1564
|
},
|
|
1144
1565
|
});
|