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/mcp/server.js
CHANGED
|
@@ -12,20 +12,40 @@ const tls_1 = require("../lib/tls");
|
|
|
12
12
|
exports.MCP_INSTRUCTIONS = [
|
|
13
13
|
'call brain_search before starting non-trivial work, not after failing',
|
|
14
14
|
'include record_types: ["summary"] (or ["note", "trajectory", "summary"]) in brain_search when resuming prior work on a file, debugging a recurring error, or when no curated notes exist yet',
|
|
15
|
-
'check ready next actions (via /inject or brain_action_list) at task start before picking up work',
|
|
15
|
+
'check ready and due next actions (via /inject, brain_action_due, or brain_action_list) at task start before picking up work',
|
|
16
16
|
'/inject content arrives unasked at task start; do not re-query for it',
|
|
17
17
|
'use brain_sessions to inspect prior agent sessions or replay a session timeline when resuming work',
|
|
18
|
-
'use brain_graph to explore relationships across notes, lessons, concepts, files, sessions, actions, and summaries',
|
|
18
|
+
'use brain_graph to explore multi-hop relationships or upsert/link persistent entities (upsert_entity, link, unlink) across notes, lessons, concepts, files, sessions, actions, entities, and summaries',
|
|
19
19
|
'save a note when a correction or a non-obvious decision happens, not at session end when the detail is gone',
|
|
20
20
|
'save a note via brain_save immediately when you fix a non-trivial bug, hit an unexpected gotcha, make an architectural decision, or receive a user correction',
|
|
21
21
|
'before finishing any non-trivial task, verify whether any durable insight should be saved with brain_save',
|
|
22
22
|
'if /inject includes a CONSOLIDATION REMINDER, let the user know and suggest they start a new session with an example prompt (e.g., "Consolidate the brain observations for this project.")',
|
|
23
23
|
'when consolidating observations, redact any API keys, tokens, passwords, or other sensitive info before submitting via brain_submit_summary',
|
|
24
|
-
'surface unfinished work or
|
|
24
|
+
'surface unfinished work, blockers, or scheduled follow-ups (due_at, remind_at, recurrence, snooze_until) via brain_action_add / brain_action_update and check overdue items with brain_action_due',
|
|
25
25
|
'call brain_session_end at session completion or pause to record a clean cross-agent handoff summary',
|
|
26
26
|
'pass scope: "unknown" rather than guessing',
|
|
27
|
-
'for project scope, project_id is the
|
|
27
|
+
'for project scope, project_id is the project_id configured in .brainrc / .brain.json if present (that value wins over the folder name and may be a flat slug like "neuralbrain" or a hierarchical slash-path slug like "acme/socials/calendar"), otherwise the lowercase name of the git repo root (the main repo for a worktree), otherwise the folder the session started in — never a subfolder or filesystem path, so all agents come up with the same id; child subprojects automatically inherit parent project context while isolating sibling subprojects',
|
|
28
28
|
].join('\n');
|
|
29
|
+
function validateScopeAndProject(scope, projectId, defaultProjectId) {
|
|
30
|
+
if (!scope || (scope !== 'project' && scope !== 'global' && scope !== 'unknown')) {
|
|
31
|
+
return {
|
|
32
|
+
error: {
|
|
33
|
+
code: 'SCOPE_REQUIRED',
|
|
34
|
+
message: "SCOPE_REQUIRED: Scope is required and must be 'project', 'global', or 'unknown'",
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const effectiveProjectId = projectId || (scope === 'project' ? defaultProjectId : undefined);
|
|
39
|
+
if (scope === 'project' && !effectiveProjectId) {
|
|
40
|
+
return {
|
|
41
|
+
error: {
|
|
42
|
+
code: 'SCHEMA_INVALID',
|
|
43
|
+
message: "SCHEMA_INVALID: project_id is required when scope is 'project' (use the project_id in .brainrc if present, else the git repo root folder name, e.g. 'neuralbrain' or 'acme/socials/calendar', not a subfolder or filesystem path)",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return { effectiveProjectId };
|
|
48
|
+
}
|
|
29
49
|
function createBrainMcpHandlers(options = {}) {
|
|
30
50
|
const apiBaseUrl = (options.apiBaseUrl ||
|
|
31
51
|
process.env.BRAIN_API_URL ||
|
|
@@ -48,7 +68,23 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
48
68
|
const body = {
|
|
49
69
|
q: args.q,
|
|
50
70
|
record_types: requestedTypes && requestedTypes.length > 0 ? requestedTypes : ['note', 'trajectory'],
|
|
71
|
+
include_ancestors: args.include_ancestors !== false,
|
|
72
|
+
include_children: Boolean(args.include_children),
|
|
51
73
|
include_global: args.include_global !== false,
|
|
74
|
+
include_history: Boolean(args.include_history),
|
|
75
|
+
include_sources: Boolean(args.include_sources),
|
|
76
|
+
...(args.user_id !== undefined ? { user_id: args.user_id } : {}),
|
|
77
|
+
...(args.after !== undefined ? { after: args.after } : {}),
|
|
78
|
+
...(args.before !== undefined ? { before: args.before } : {}),
|
|
79
|
+
...(args.as_of !== undefined ? { as_of: args.as_of } : {}),
|
|
80
|
+
...(args.reference_date !== undefined ? { reference_date: args.reference_date } : {}),
|
|
81
|
+
...(args.temporal_bias !== undefined ? { temporal_bias: args.temporal_bias } : {}),
|
|
82
|
+
...(args.snippet_mode !== undefined ? { snippet_mode: args.snippet_mode } : {}),
|
|
83
|
+
...(args.max_record_chars !== undefined ? { max_record_chars: args.max_record_chars } : {}),
|
|
84
|
+
...(args.kind_weights !== undefined ? { kind_weights: args.kind_weights } : {}),
|
|
85
|
+
...(args.max_kind_share !== undefined ? { max_kind_share: args.max_kind_share } : {}),
|
|
86
|
+
...(args.sources_limit !== undefined ? { sources_limit: args.sources_limit } : {}),
|
|
87
|
+
...(args.sources_offset !== undefined ? { sources_offset: args.sources_offset } : {}),
|
|
52
88
|
limit: args.limit ?? 10,
|
|
53
89
|
};
|
|
54
90
|
if (targetProjectId) {
|
|
@@ -62,6 +98,18 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
62
98
|
if (args.file_path) {
|
|
63
99
|
filters.file_path = args.file_path;
|
|
64
100
|
}
|
|
101
|
+
if (args.entity_type) {
|
|
102
|
+
filters.entity_type = args.entity_type;
|
|
103
|
+
}
|
|
104
|
+
if (args.memory_layer) {
|
|
105
|
+
filters.memory_layer = args.memory_layer;
|
|
106
|
+
}
|
|
107
|
+
if (args.signal_tag) {
|
|
108
|
+
filters.signal_tag = args.signal_tag;
|
|
109
|
+
}
|
|
110
|
+
if (args.user_id) {
|
|
111
|
+
filters.user_id = args.user_id;
|
|
112
|
+
}
|
|
65
113
|
if (Object.keys(filters).length > 0) {
|
|
66
114
|
body.filters = filters;
|
|
67
115
|
}
|
|
@@ -75,12 +123,12 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
75
123
|
const data = await res.json().catch(() => ({}));
|
|
76
124
|
if (!res.ok) {
|
|
77
125
|
return {
|
|
78
|
-
content: [{ type: 'text', text: JSON.stringify(data
|
|
126
|
+
content: [{ type: 'text', text: JSON.stringify(data) }],
|
|
79
127
|
isError: true,
|
|
80
128
|
};
|
|
81
129
|
}
|
|
82
130
|
return {
|
|
83
|
-
content: [{ type: 'text', text: JSON.stringify(data
|
|
131
|
+
content: [{ type: 'text', text: JSON.stringify(data) }],
|
|
84
132
|
};
|
|
85
133
|
}
|
|
86
134
|
catch (err) {
|
|
@@ -91,17 +139,14 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
91
139
|
}
|
|
92
140
|
};
|
|
93
141
|
const brainSave = async (args) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (args.scope === 'project' && !effectiveProjectId) {
|
|
101
|
-
const err = new Error("SCHEMA_INVALID: project_id is required when scope is 'project' (use the project root folder name, e.g. 'neuralbrain' — from .brainrc or the git repo root, not a subfolder or filesystem path)");
|
|
102
|
-
err.code = 'SCHEMA_INVALID';
|
|
103
|
-
throw err;
|
|
142
|
+
const check = validateScopeAndProject(args.scope, args.project_id, defaultProjectId);
|
|
143
|
+
if (check.error) {
|
|
144
|
+
return {
|
|
145
|
+
content: [{ type: 'text', text: JSON.stringify({ error: check.error }) }],
|
|
146
|
+
isError: true,
|
|
147
|
+
};
|
|
104
148
|
}
|
|
149
|
+
const effectiveProjectId = check.effectiveProjectId;
|
|
105
150
|
const payload = {
|
|
106
151
|
type: args.type,
|
|
107
152
|
title: args.title,
|
|
@@ -113,9 +158,18 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
113
158
|
files: args.files || [],
|
|
114
159
|
supersedes: args.supersedes || null,
|
|
115
160
|
};
|
|
116
|
-
if (args.session_id !== undefined)
|
|
161
|
+
if (args.session_id !== undefined)
|
|
117
162
|
payload.session_id = args.session_id;
|
|
118
|
-
|
|
163
|
+
if (args.user_id !== undefined)
|
|
164
|
+
payload.user_id = args.user_id;
|
|
165
|
+
if (args.agent_id !== undefined)
|
|
166
|
+
payload.agent_id = args.agent_id;
|
|
167
|
+
if (args.event_at !== undefined)
|
|
168
|
+
payload.event_at = args.event_at;
|
|
169
|
+
if (args.valid_from !== undefined)
|
|
170
|
+
payload.valid_from = args.valid_from;
|
|
171
|
+
if (args.valid_until !== undefined)
|
|
172
|
+
payload.valid_until = args.valid_until;
|
|
119
173
|
try {
|
|
120
174
|
const res = await fetchFn(`${apiBaseUrl}/notes`, {
|
|
121
175
|
method: 'POST',
|
|
@@ -126,18 +180,15 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
126
180
|
const data = await res.json().catch(() => ({}));
|
|
127
181
|
if (!res.ok) {
|
|
128
182
|
return {
|
|
129
|
-
content: [{ type: 'text', text: JSON.stringify(data
|
|
183
|
+
content: [{ type: 'text', text: JSON.stringify(data) }],
|
|
130
184
|
isError: true,
|
|
131
185
|
};
|
|
132
186
|
}
|
|
133
187
|
return {
|
|
134
|
-
content: [{ type: 'text', text: JSON.stringify(data
|
|
188
|
+
content: [{ type: 'text', text: JSON.stringify(data) }],
|
|
135
189
|
};
|
|
136
190
|
}
|
|
137
191
|
catch (err) {
|
|
138
|
-
if (err?.code === 'SCOPE_REQUIRED' || err?.code === 'SCHEMA_INVALID') {
|
|
139
|
-
throw err;
|
|
140
|
-
}
|
|
141
192
|
return {
|
|
142
193
|
content: [{ type: 'text', text: `MCP Transport Error: ${err instanceof Error ? err.message : String(err)}` }],
|
|
143
194
|
isError: true,
|
|
@@ -152,6 +203,17 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
152
203
|
query.set('project_id', targetProjectId);
|
|
153
204
|
if (args.task_type)
|
|
154
205
|
query.set('task_type', args.task_type);
|
|
206
|
+
if (args.include_ancestors !== undefined) {
|
|
207
|
+
query.set('include_ancestors', String(args.include_ancestors));
|
|
208
|
+
}
|
|
209
|
+
if (args.include_children !== undefined) {
|
|
210
|
+
query.set('include_children', String(args.include_children));
|
|
211
|
+
}
|
|
212
|
+
if (args.include_global !== undefined) {
|
|
213
|
+
query.set('include_global', String(args.include_global));
|
|
214
|
+
}
|
|
215
|
+
if (args.user_id)
|
|
216
|
+
query.set('user_id', args.user_id);
|
|
155
217
|
if (args.limit)
|
|
156
218
|
query.set('limit', String(args.limit));
|
|
157
219
|
const url = `${apiBaseUrl}/failure-patterns${query.toString() ? `?${query.toString()}` : ''}`;
|
|
@@ -163,7 +225,7 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
163
225
|
const data = await res.json().catch(() => []);
|
|
164
226
|
if (!res.ok) {
|
|
165
227
|
return {
|
|
166
|
-
content: [{ type: 'text', text: JSON.stringify(data
|
|
228
|
+
content: [{ type: 'text', text: JSON.stringify(data) }],
|
|
167
229
|
isError: true,
|
|
168
230
|
};
|
|
169
231
|
}
|
|
@@ -173,9 +235,11 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
173
235
|
error_text: p.error_text,
|
|
174
236
|
count: p.count,
|
|
175
237
|
last_seen_at: p.last_seen_at,
|
|
238
|
+
project_id: p.project_id ?? null,
|
|
239
|
+
match_tier: p.match_tier ?? null,
|
|
176
240
|
}));
|
|
177
241
|
return {
|
|
178
|
-
content: [{ type: 'text', text: JSON.stringify(result
|
|
242
|
+
content: [{ type: 'text', text: JSON.stringify(result) }],
|
|
179
243
|
};
|
|
180
244
|
}
|
|
181
245
|
catch (err) {
|
|
@@ -202,12 +266,12 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
202
266
|
const data = await res.json().catch(() => ({ candidates: [] }));
|
|
203
267
|
if (!res.ok) {
|
|
204
268
|
return {
|
|
205
|
-
content: [{ type: 'text', text: JSON.stringify(data
|
|
269
|
+
content: [{ type: 'text', text: JSON.stringify(data) }],
|
|
206
270
|
isError: true,
|
|
207
271
|
};
|
|
208
272
|
}
|
|
209
273
|
return {
|
|
210
|
-
content: [{ type: 'text', text: JSON.stringify(data
|
|
274
|
+
content: [{ type: 'text', text: JSON.stringify(data) }],
|
|
211
275
|
};
|
|
212
276
|
}
|
|
213
277
|
catch (err) {
|
|
@@ -237,12 +301,12 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
237
301
|
const data = await res.json().catch(() => ({}));
|
|
238
302
|
if (!res.ok) {
|
|
239
303
|
return {
|
|
240
|
-
content: [{ type: 'text', text: JSON.stringify(data
|
|
304
|
+
content: [{ type: 'text', text: JSON.stringify(data) }],
|
|
241
305
|
isError: true,
|
|
242
306
|
};
|
|
243
307
|
}
|
|
244
308
|
return {
|
|
245
|
-
content: [{ type: 'text', text: JSON.stringify(data
|
|
309
|
+
content: [{ type: 'text', text: JSON.stringify(data) }],
|
|
246
310
|
};
|
|
247
311
|
}
|
|
248
312
|
catch (err) {
|
|
@@ -261,12 +325,12 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
261
325
|
const data = await res.json().catch(() => ({}));
|
|
262
326
|
if (!res.ok) {
|
|
263
327
|
return {
|
|
264
|
-
content: [{ type: 'text', text: JSON.stringify(data
|
|
328
|
+
content: [{ type: 'text', text: JSON.stringify(data) }],
|
|
265
329
|
isError: true,
|
|
266
330
|
};
|
|
267
331
|
}
|
|
268
332
|
return {
|
|
269
|
-
content: [{ type: 'text', text: JSON.stringify(data
|
|
333
|
+
content: [{ type: 'text', text: JSON.stringify(data) }],
|
|
270
334
|
};
|
|
271
335
|
}
|
|
272
336
|
catch (err) {
|
|
@@ -277,17 +341,14 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
277
341
|
}
|
|
278
342
|
};
|
|
279
343
|
const brainActionAdd = async (args) => {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if (args.scope === 'project' && !effectiveProjectId) {
|
|
287
|
-
const err = new Error("SCHEMA_INVALID: project_id is required when scope is 'project' (use the project root folder name, e.g. 'neuralbrain' — from .brainrc or the git repo root, not a subfolder or filesystem path)");
|
|
288
|
-
err.code = 'SCHEMA_INVALID';
|
|
289
|
-
throw err;
|
|
344
|
+
const check = validateScopeAndProject(args.scope, args.project_id, defaultProjectId);
|
|
345
|
+
if (check.error) {
|
|
346
|
+
return {
|
|
347
|
+
content: [{ type: 'text', text: JSON.stringify({ error: check.error }) }],
|
|
348
|
+
isError: true,
|
|
349
|
+
};
|
|
290
350
|
}
|
|
351
|
+
const effectiveProjectId = check.effectiveProjectId;
|
|
291
352
|
const payload = {
|
|
292
353
|
title: args.title,
|
|
293
354
|
scope: args.scope,
|
|
@@ -296,6 +357,10 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
296
357
|
payload.description = args.description;
|
|
297
358
|
if (effectiveProjectId)
|
|
298
359
|
payload.project_id = effectiveProjectId;
|
|
360
|
+
if (args.user_id !== undefined)
|
|
361
|
+
payload.user_id = args.user_id;
|
|
362
|
+
if (args.agent_id !== undefined)
|
|
363
|
+
payload.agent_id = args.agent_id;
|
|
299
364
|
if (args.session_id !== undefined)
|
|
300
365
|
payload.session_id = args.session_id;
|
|
301
366
|
if (args.status !== undefined)
|
|
@@ -306,6 +371,14 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
306
371
|
payload.blocked_reason = args.blocked_reason;
|
|
307
372
|
if (args.files !== undefined)
|
|
308
373
|
payload.files = args.files;
|
|
374
|
+
if (args.due_at !== undefined)
|
|
375
|
+
payload.due_at = args.due_at;
|
|
376
|
+
if (args.remind_at !== undefined)
|
|
377
|
+
payload.remind_at = args.remind_at;
|
|
378
|
+
if (args.recurrence !== undefined)
|
|
379
|
+
payload.recurrence = args.recurrence;
|
|
380
|
+
if (args.snooze_until !== undefined)
|
|
381
|
+
payload.snooze_until = args.snooze_until;
|
|
309
382
|
return requestJson(`${apiBaseUrl}/actions`, {
|
|
310
383
|
method: 'POST',
|
|
311
384
|
headers: authHeaders,
|
|
@@ -317,8 +390,20 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
317
390
|
const query = new URLSearchParams();
|
|
318
391
|
if (targetProjectId)
|
|
319
392
|
query.set('project_id', targetProjectId);
|
|
393
|
+
if (args.include_ancestors !== undefined) {
|
|
394
|
+
query.set('include_ancestors', String(args.include_ancestors));
|
|
395
|
+
}
|
|
396
|
+
if (args.include_children !== undefined) {
|
|
397
|
+
query.set('include_children', String(args.include_children));
|
|
398
|
+
}
|
|
320
399
|
if (args.include_global !== undefined)
|
|
321
400
|
query.set('include_global', String(args.include_global));
|
|
401
|
+
if (args.due_only !== undefined)
|
|
402
|
+
query.set('due_only', String(args.due_only));
|
|
403
|
+
if (args.before)
|
|
404
|
+
query.set('before', args.before);
|
|
405
|
+
if (args.user_id)
|
|
406
|
+
query.set('user_id', args.user_id);
|
|
322
407
|
if (args.status)
|
|
323
408
|
query.set('status', args.status);
|
|
324
409
|
if (args.limit !== undefined)
|
|
@@ -343,12 +428,49 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
343
428
|
payload.blocked_reason = args.blocked_reason;
|
|
344
429
|
if (args.resolved_by_session_id !== undefined)
|
|
345
430
|
payload.resolved_by_session_id = args.resolved_by_session_id;
|
|
431
|
+
if (args.due_at !== undefined)
|
|
432
|
+
payload.due_at = args.due_at;
|
|
433
|
+
if (args.remind_at !== undefined)
|
|
434
|
+
payload.remind_at = args.remind_at;
|
|
435
|
+
if (args.recurrence !== undefined)
|
|
436
|
+
payload.recurrence = args.recurrence;
|
|
437
|
+
if (args.snooze_until !== undefined)
|
|
438
|
+
payload.snooze_until = args.snooze_until;
|
|
439
|
+
if (args.user_id !== undefined)
|
|
440
|
+
payload.user_id = args.user_id;
|
|
441
|
+
if (args.agent_id !== undefined)
|
|
442
|
+
payload.agent_id = args.agent_id;
|
|
346
443
|
return requestJson(`${apiBaseUrl}/actions/${encodeURIComponent(args.id)}`, {
|
|
347
444
|
method: 'PATCH',
|
|
348
445
|
headers: authHeaders,
|
|
349
446
|
body: JSON.stringify(payload),
|
|
350
447
|
});
|
|
351
448
|
};
|
|
449
|
+
const brainActionDue = async (args = {}) => {
|
|
450
|
+
const targetProjectId = args.project_id || defaultProjectId;
|
|
451
|
+
const query = new URLSearchParams();
|
|
452
|
+
if (targetProjectId)
|
|
453
|
+
query.set('project_id', targetProjectId);
|
|
454
|
+
if (args.include_ancestors !== undefined) {
|
|
455
|
+
query.set('include_ancestors', String(args.include_ancestors));
|
|
456
|
+
}
|
|
457
|
+
if (args.include_children !== undefined) {
|
|
458
|
+
query.set('include_children', String(args.include_children));
|
|
459
|
+
}
|
|
460
|
+
if (args.include_global !== undefined)
|
|
461
|
+
query.set('include_global', String(args.include_global));
|
|
462
|
+
if (args.before)
|
|
463
|
+
query.set('before', args.before);
|
|
464
|
+
if (args.user_id)
|
|
465
|
+
query.set('user_id', args.user_id);
|
|
466
|
+
if (args.limit !== undefined)
|
|
467
|
+
query.set('limit', String(args.limit));
|
|
468
|
+
const url = `${apiBaseUrl}/actions/due${query.toString() ? `?${query.toString()}` : ''}`;
|
|
469
|
+
return requestJson(url, {
|
|
470
|
+
method: 'GET',
|
|
471
|
+
headers: authHeaders,
|
|
472
|
+
});
|
|
473
|
+
};
|
|
352
474
|
const brainSessions = async (args = {}) => {
|
|
353
475
|
const mode = args.mode || 'list';
|
|
354
476
|
if (mode === 'get' || mode === 'replay') {
|
|
@@ -362,7 +484,7 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
362
484
|
code: 'SCHEMA_INVALID',
|
|
363
485
|
message: `session_id is required when mode is '${mode}'`,
|
|
364
486
|
},
|
|
365
|
-
}
|
|
487
|
+
}),
|
|
366
488
|
},
|
|
367
489
|
],
|
|
368
490
|
isError: true,
|
|
@@ -378,6 +500,17 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
378
500
|
const query = new URLSearchParams();
|
|
379
501
|
if (targetProjectId)
|
|
380
502
|
query.set('project_id', targetProjectId);
|
|
503
|
+
if (args.include_ancestors !== undefined) {
|
|
504
|
+
query.set('include_ancestors', String(args.include_ancestors));
|
|
505
|
+
}
|
|
506
|
+
if (args.include_children !== undefined) {
|
|
507
|
+
query.set('include_children', String(args.include_children));
|
|
508
|
+
}
|
|
509
|
+
if (args.include_global !== undefined) {
|
|
510
|
+
query.set('include_global', String(args.include_global));
|
|
511
|
+
}
|
|
512
|
+
if (args.user_id)
|
|
513
|
+
query.set('user_id', args.user_id);
|
|
381
514
|
if (args.status)
|
|
382
515
|
query.set('status', args.status);
|
|
383
516
|
if (args.agent_name)
|
|
@@ -407,12 +540,104 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
407
540
|
});
|
|
408
541
|
};
|
|
409
542
|
const brainGraph = async (args = {}) => {
|
|
543
|
+
const mode = args.mode || 'query';
|
|
544
|
+
if (mode === 'upsert_entity') {
|
|
545
|
+
const check = validateScopeAndProject(args.scope, args.project_id, defaultProjectId);
|
|
546
|
+
if (check.error) {
|
|
547
|
+
return {
|
|
548
|
+
content: [{ type: 'text', text: JSON.stringify({ error: check.error }) }],
|
|
549
|
+
isError: true,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
const payload = {
|
|
553
|
+
scope: args.scope,
|
|
554
|
+
};
|
|
555
|
+
if (check.effectiveProjectId)
|
|
556
|
+
payload.project_id = check.effectiveProjectId;
|
|
557
|
+
const entityId = args.entity_id ?? args.id;
|
|
558
|
+
if (entityId !== undefined)
|
|
559
|
+
payload.id = entityId;
|
|
560
|
+
if (args.entity_type !== undefined)
|
|
561
|
+
payload.entity_type = args.entity_type;
|
|
562
|
+
if (args.name !== undefined)
|
|
563
|
+
payload.name = args.name;
|
|
564
|
+
if (args.description !== undefined)
|
|
565
|
+
payload.description = args.description;
|
|
566
|
+
if (args.external_ref !== undefined)
|
|
567
|
+
payload.external_ref = args.external_ref;
|
|
568
|
+
if (args.metadata !== undefined)
|
|
569
|
+
payload.metadata = args.metadata;
|
|
570
|
+
if (args.user_id !== undefined)
|
|
571
|
+
payload.user_id = args.user_id;
|
|
572
|
+
if (args.agent_id !== undefined)
|
|
573
|
+
payload.agent_id = args.agent_id;
|
|
574
|
+
return requestJson(`${apiBaseUrl}/graph/entities`, {
|
|
575
|
+
method: 'POST',
|
|
576
|
+
headers: authHeaders,
|
|
577
|
+
body: JSON.stringify(payload),
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
if (mode === 'link') {
|
|
581
|
+
const payload = {};
|
|
582
|
+
if (args.source_type !== undefined)
|
|
583
|
+
payload.source_type = args.source_type;
|
|
584
|
+
if (args.source_id !== undefined)
|
|
585
|
+
payload.source_id = args.source_id;
|
|
586
|
+
if (args.target_type !== undefined)
|
|
587
|
+
payload.target_type = args.target_type;
|
|
588
|
+
if (args.target_id !== undefined)
|
|
589
|
+
payload.target_id = args.target_id;
|
|
590
|
+
if (args.relation !== undefined)
|
|
591
|
+
payload.relation = args.relation;
|
|
592
|
+
if (args.metadata !== undefined)
|
|
593
|
+
payload.metadata = args.metadata;
|
|
594
|
+
return requestJson(`${apiBaseUrl}/graph/edges`, {
|
|
595
|
+
method: 'POST',
|
|
596
|
+
headers: authHeaders,
|
|
597
|
+
body: JSON.stringify(payload),
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
if (mode === 'unlink') {
|
|
601
|
+
const payload = {};
|
|
602
|
+
if (args.id !== undefined)
|
|
603
|
+
payload.id = args.id;
|
|
604
|
+
if (args.source_id !== undefined)
|
|
605
|
+
payload.source_id = args.source_id;
|
|
606
|
+
if (args.target_id !== undefined)
|
|
607
|
+
payload.target_id = args.target_id;
|
|
608
|
+
if (args.relation !== undefined)
|
|
609
|
+
payload.relation = args.relation;
|
|
610
|
+
return requestJson(`${apiBaseUrl}/graph/edges`, {
|
|
611
|
+
method: 'DELETE',
|
|
612
|
+
headers: authHeaders,
|
|
613
|
+
body: JSON.stringify(payload),
|
|
614
|
+
});
|
|
615
|
+
}
|
|
410
616
|
const targetProjectId = args.project_id || (args.scope === 'global' || args.scope === 'unknown' ? undefined : defaultProjectId);
|
|
411
617
|
const query = new URLSearchParams();
|
|
412
618
|
if (targetProjectId)
|
|
413
619
|
query.set('project_id', targetProjectId);
|
|
414
620
|
if (args.scope)
|
|
415
621
|
query.set('scope', args.scope);
|
|
622
|
+
if (args.include_ancestors !== undefined) {
|
|
623
|
+
query.set('include_ancestors', String(args.include_ancestors));
|
|
624
|
+
}
|
|
625
|
+
if (args.include_children !== undefined) {
|
|
626
|
+
query.set('include_children', String(args.include_children));
|
|
627
|
+
}
|
|
628
|
+
if (args.include_global !== undefined) {
|
|
629
|
+
query.set('include_global', String(args.include_global));
|
|
630
|
+
}
|
|
631
|
+
if (args.depth !== undefined)
|
|
632
|
+
query.set('depth', String(args.depth));
|
|
633
|
+
if (args.node_id)
|
|
634
|
+
query.set('node_id', args.node_id);
|
|
635
|
+
if (args.entity_type)
|
|
636
|
+
query.set('entity_type', args.entity_type);
|
|
637
|
+
if (args.relation)
|
|
638
|
+
query.set('relation', args.relation);
|
|
639
|
+
if (args.user_id)
|
|
640
|
+
query.set('user_id', args.user_id);
|
|
416
641
|
if (args.limit !== undefined)
|
|
417
642
|
query.set('limit', String(args.limit));
|
|
418
643
|
const url = `${apiBaseUrl}/graph${query.toString() ? `?${query.toString()}` : ''}`;
|
|
@@ -430,6 +655,7 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
430
655
|
brainActionAdd,
|
|
431
656
|
brainActionList,
|
|
432
657
|
brainActionUpdate,
|
|
658
|
+
brainActionDue,
|
|
433
659
|
brainSessions,
|
|
434
660
|
brainSessionEnd,
|
|
435
661
|
brainGraph,
|
|
@@ -438,26 +664,106 @@ function createBrainMcpHandlers(options = {}) {
|
|
|
438
664
|
function createBrainMcpServer(options = {}) {
|
|
439
665
|
const server = new mcp_js_1.McpServer({
|
|
440
666
|
name: 'neuralbrain',
|
|
441
|
-
version: '0.0
|
|
667
|
+
version: '0.1.0',
|
|
442
668
|
}, {
|
|
443
669
|
instructions: exports.MCP_INSTRUCTIONS,
|
|
444
670
|
});
|
|
445
671
|
const handlers = options.handlers ?? createBrainMcpHandlers(options);
|
|
446
672
|
// 1. brain_search
|
|
447
|
-
server.tool('brain_search', 'Search across memories, trajectories, observations, and
|
|
673
|
+
server.tool('brain_search', 'Search across memories, trajectories, observations, summaries, entities, and actions with 3-signal hybrid dense + FTS5 BM25 + Entity-Graph RRF retrieval. Surfaces "degraded" verbatim when vector search is unavailable so the agent can tell BM25-only results from hybrid ones. Call before starting non-trivial work.', {
|
|
448
674
|
q: zod_1.z.string().describe('Search query text'),
|
|
449
675
|
record_types: zod_1.z
|
|
450
676
|
.array(zod_1.z.string())
|
|
451
677
|
.default(['note', 'trajectory'])
|
|
452
|
-
.describe("Memory record types to search (default: ['note', 'trajectory']). Options: 'note' (curated facts/decisions/bugs), 'trajectory' (session outcome rollups), 'summary' (consolidated session claims, touched files, and verbatim errors
|
|
678
|
+
.describe("Memory record types to search (default: ['note', 'trajectory']). Options: 'note' (curated facts/decisions/bugs), 'trajectory' (session outcome rollups), 'summary' (consolidated session claims, touched files, and verbatim errors), 'observation' (raw tool calls/prompts), 'entity' (persistent entity nodes), 'action' (Next Actions and reminders)."),
|
|
453
679
|
project_id: zod_1.z
|
|
454
680
|
.string()
|
|
455
681
|
.optional()
|
|
456
|
-
.describe('Project ID
|
|
682
|
+
.describe('Project ID or hierarchical slug (e.g. "neuralbrain" or "acme/socials/calendar"); omit for global-only. Never pass a filesystem path.'),
|
|
683
|
+
include_ancestors: zod_1.z
|
|
684
|
+
.boolean()
|
|
685
|
+
.default(true)
|
|
686
|
+
.describe('Whether to include ancestor projects when project_id is hierarchical (default true)'),
|
|
687
|
+
include_children: zod_1.z
|
|
688
|
+
.boolean()
|
|
689
|
+
.default(false)
|
|
690
|
+
.describe('Whether to include child subprojects below project_id (default false)'),
|
|
457
691
|
include_global: zod_1.z.boolean().default(true).describe('Whether to include global records when project_id is specified'),
|
|
692
|
+
include_history: zod_1.z
|
|
693
|
+
.boolean()
|
|
694
|
+
.default(false)
|
|
695
|
+
.describe('Whether to include superseded historical versions of notes and summaries (default false)'),
|
|
696
|
+
user_id: zod_1.z.string().optional().describe('Optional user_id filter'),
|
|
697
|
+
after: zod_1.z.string().optional().describe('ISO-8601 lower bound timestamp filter'),
|
|
698
|
+
before: zod_1.z.string().optional().describe('ISO-8601 upper bound timestamp filter'),
|
|
699
|
+
as_of: zod_1.z.string().optional().describe('ISO-8601 point-in-time validity filter for notes (valid_from <= as_of <= valid_until)'),
|
|
700
|
+
reference_date: zod_1.z
|
|
701
|
+
.string()
|
|
702
|
+
.optional()
|
|
703
|
+
.describe('Optional ISO-8601 reference timestamp used to anchor relative temporal expressions in q (e.g. "four weeks ago", "last month", "in March"); defaults to current time'),
|
|
704
|
+
temporal_bias: zod_1.z
|
|
705
|
+
.enum(['none', 'recent', 'upcoming'])
|
|
706
|
+
.optional()
|
|
707
|
+
.describe("Optional temporal ranking bias ('none', 'recent', or 'upcoming')"),
|
|
708
|
+
snippet_mode: zod_1.z
|
|
709
|
+
.enum(['query_focused', 'condensed', 'raw'])
|
|
710
|
+
.optional()
|
|
711
|
+
.describe("Observation snippet mode: 'query_focused' (default — extracts query-matching passages from full observation text), 'condensed' (uses precomputed extractive condensed_text), or 'raw' (full raw input/output)"),
|
|
712
|
+
max_record_chars: zod_1.z
|
|
713
|
+
.number()
|
|
714
|
+
.int()
|
|
715
|
+
.min(32)
|
|
716
|
+
.max(100000)
|
|
717
|
+
.optional()
|
|
718
|
+
.describe('Optional character budget cap for returned observation fields and snippet'),
|
|
719
|
+
kind_weights: zod_1.z
|
|
720
|
+
.object({
|
|
721
|
+
prompt: zod_1.z.number().min(0.1).max(5).optional(),
|
|
722
|
+
response: zod_1.z.number().min(0.1).max(5).optional(),
|
|
723
|
+
tool_call: zod_1.z.number().min(0.1).max(5).optional(),
|
|
724
|
+
})
|
|
725
|
+
.optional()
|
|
726
|
+
.describe('Optional per-kind score multipliers overriding intent-aware defaults for observations'),
|
|
727
|
+
max_kind_share: zod_1.z
|
|
728
|
+
.object({
|
|
729
|
+
prompt: zod_1.z.number().gt(0).max(1).optional(),
|
|
730
|
+
response: zod_1.z.number().gt(0).max(1).optional(),
|
|
731
|
+
tool_call: zod_1.z.number().gt(0).max(1).optional(),
|
|
732
|
+
})
|
|
733
|
+
.optional()
|
|
734
|
+
.describe('Optional maximum result-set share (0..1] per observation kind with score-ordered backfill'),
|
|
735
|
+
entity_type: zod_1.z
|
|
736
|
+
.string()
|
|
737
|
+
.optional()
|
|
738
|
+
.describe("Optional entity_type filter (e.g. 'brand', 'person', 'asset', 'metric', 'document', 'tool')"),
|
|
739
|
+
memory_layer: zod_1.z
|
|
740
|
+
.enum(['semantic', 'procedural'])
|
|
741
|
+
.optional()
|
|
742
|
+
.describe("Optional note layer filter: 'semantic' (fact/architecture/preference) or 'procedural' (workflow/pattern/lesson/bug)"),
|
|
743
|
+
signal_tag: zod_1.z
|
|
744
|
+
.enum(['preference', 'state_update', 'completed_action', 'planned_action'])
|
|
745
|
+
.optional()
|
|
746
|
+
.describe("Optional observation linguistic signal tag filter ('preference', 'state_update', 'completed_action', or 'planned_action')"),
|
|
458
747
|
type: zod_1.z.array(zod_1.z.string()).optional().describe('Note type filter (fact, architecture, pattern, workflow, bug, preference, lesson)'),
|
|
459
748
|
file_path: zod_1.z.string().optional().describe('File path filter ("what do we know about this file?")'),
|
|
460
|
-
|
|
749
|
+
include_sources: zod_1.z
|
|
750
|
+
.boolean()
|
|
751
|
+
.default(false)
|
|
752
|
+
.describe('Include paginated source provenance entries (with observation titles) on summary results (default false)'),
|
|
753
|
+
sources_limit: zod_1.z
|
|
754
|
+
.number()
|
|
755
|
+
.int()
|
|
756
|
+
.min(1)
|
|
757
|
+
.max(100)
|
|
758
|
+
.default(20)
|
|
759
|
+
.describe('Maximum number of source entries per summary when include_sources is true (default 20)'),
|
|
760
|
+
sources_offset: zod_1.z
|
|
761
|
+
.number()
|
|
762
|
+
.int()
|
|
763
|
+
.min(0)
|
|
764
|
+
.default(0)
|
|
765
|
+
.describe('Offset into summary sources for pagination when include_sources is true (default 0)'),
|
|
766
|
+
limit: zod_1.z.number().int().min(1).max(100).default(10).describe('Maximum number of results to return'),
|
|
461
767
|
}, async (args) => {
|
|
462
768
|
return handlers.brainSearch(args);
|
|
463
769
|
});
|
|
@@ -470,22 +776,40 @@ function createBrainMcpServer(options = {}) {
|
|
|
470
776
|
project_id: zod_1.z
|
|
471
777
|
.string()
|
|
472
778
|
.optional()
|
|
473
|
-
.describe("Required iff scope is 'project'. Use the project root folder name
|
|
779
|
+
.describe("Required iff scope is 'project'. Use the project root folder name or hierarchical slug (e.g. 'neuralbrain' or 'acme/socials/calendar') — never a filesystem path. If unsure, use scope 'unknown'"),
|
|
780
|
+
user_id: zod_1.z.string().optional().describe('Optional user_id attribution'),
|
|
781
|
+
agent_id: zod_1.z.string().optional().describe('Optional agent_id provenance (stored, never filtered)'),
|
|
474
782
|
session_id: zod_1.z.string().optional().describe('Optional session ID that authored this note'),
|
|
475
783
|
concepts: zod_1.z.array(zod_1.z.string()).optional().describe('Concepts associated with this note'),
|
|
476
784
|
files: zod_1.z.array(zod_1.z.string()).optional().describe('File paths associated with this note'),
|
|
477
785
|
supersedes: zod_1.z.string().optional().describe('Previous note id being superseded'),
|
|
786
|
+
event_at: zod_1.z.string().optional().describe('Optional ISO-8601 timestamp when the event occurred'),
|
|
787
|
+
valid_from: zod_1.z.string().optional().describe('Optional ISO-8601 start of fact validity window'),
|
|
788
|
+
valid_until: zod_1.z.string().optional().describe('Optional ISO-8601 end of fact validity window'),
|
|
478
789
|
}, async (args) => {
|
|
479
790
|
return handlers.brainSave(args);
|
|
480
791
|
});
|
|
481
792
|
// 3. brain_recent_failures
|
|
482
|
-
server.tool('brain_recent_failures', 'Retrieve recent failure patterns and counts. Returns { task_type, error_text, count, last_seen_at }[] where count is from SQL.', {
|
|
793
|
+
server.tool('brain_recent_failures', 'Retrieve recent failure patterns and counts. Returns { task_type, error_text, count, last_seen_at, project_id, match_tier }[] where count is from SQL.', {
|
|
483
794
|
project_id: zod_1.z
|
|
484
795
|
.string()
|
|
485
796
|
.optional()
|
|
486
|
-
.describe('Project ID to filter by (
|
|
797
|
+
.describe('Project ID or hierarchical slug to filter by (never a filesystem path); omit for global'),
|
|
487
798
|
task_type: zod_1.z.string().optional().describe('Task type filter'),
|
|
488
|
-
|
|
799
|
+
include_ancestors: zod_1.z
|
|
800
|
+
.boolean()
|
|
801
|
+
.default(true)
|
|
802
|
+
.describe('Whether to include ancestor projects when project_id is hierarchical (default true)'),
|
|
803
|
+
include_children: zod_1.z
|
|
804
|
+
.boolean()
|
|
805
|
+
.default(false)
|
|
806
|
+
.describe('Whether to include child subprojects below project_id (default false)'),
|
|
807
|
+
include_global: zod_1.z
|
|
808
|
+
.boolean()
|
|
809
|
+
.default(true)
|
|
810
|
+
.describe('Whether to include global failure patterns when project_id is specified (default true)'),
|
|
811
|
+
user_id: zod_1.z.string().optional().describe('Optional user_id filter'),
|
|
812
|
+
limit: zod_1.z.number().int().min(1).max(200).default(5).describe('Maximum number of failures to return'),
|
|
489
813
|
}, async (args) => {
|
|
490
814
|
return handlers.brainRecentFailures(args);
|
|
491
815
|
});
|
|
@@ -495,7 +819,7 @@ function createBrainMcpServer(options = {}) {
|
|
|
495
819
|
.string()
|
|
496
820
|
.optional()
|
|
497
821
|
.describe('Filter candidates by project (use the project root folder name, e.g. "neuralbrain"; never a subfolder or filesystem path)'),
|
|
498
|
-
limit: zod_1.z.number().int().optional().describe('Maximum number of candidate leases to retrieve'),
|
|
822
|
+
limit: zod_1.z.number().int().min(1).max(200).optional().describe('Maximum number of candidate leases to retrieve'),
|
|
499
823
|
}, async (args) => {
|
|
500
824
|
return handlers.brainConsolidateCandidates(args);
|
|
501
825
|
});
|
|
@@ -514,36 +838,53 @@ function createBrainMcpServer(options = {}) {
|
|
|
514
838
|
return handlers.brainSubmitSummary(args);
|
|
515
839
|
});
|
|
516
840
|
// 6. brain_action_add
|
|
517
|
-
server.tool('brain_action_add', 'Create a Next Action to surface unfinished work, follow-ups, or blockers for future sessions. Scope is REQUIRED (project, global, or unknown).', {
|
|
841
|
+
server.tool('brain_action_add', 'Create a Next Action (or scheduled/recurring reminder) to surface unfinished work, follow-ups, or blockers for future sessions. Scope is REQUIRED (project, global, or unknown).', {
|
|
518
842
|
title: zod_1.z.string().describe('Short, actionable title of the next action'),
|
|
519
843
|
description: zod_1.z.string().optional().describe('Detailed description or context for the next action'),
|
|
520
844
|
scope: zod_1.z.enum(['project', 'global', 'unknown']).describe("Scope: 'project', 'global', or 'unknown'. REQUIRED, never inferred!"),
|
|
521
845
|
project_id: zod_1.z
|
|
522
846
|
.string()
|
|
523
847
|
.optional()
|
|
524
|
-
.describe("Required iff scope is 'project'. Use the project root folder name
|
|
848
|
+
.describe("Required iff scope is 'project'. Use the project root folder name or hierarchical slug (e.g. 'neuralbrain' or 'acme/socials/calendar') — never a filesystem path"),
|
|
849
|
+
user_id: zod_1.z.string().optional().describe('Optional user_id attribution'),
|
|
850
|
+
agent_id: zod_1.z.string().optional().describe('Optional agent_id provenance (stored, never filtered)'),
|
|
525
851
|
session_id: zod_1.z.string().optional().describe('Optional session ID that created this action'),
|
|
526
852
|
status: zod_1.z.enum(['ready', 'blocked', 'in_progress', 'done', 'dismissed']).optional().describe("Action status ('ready', 'blocked', 'in_progress', 'done', 'dismissed')"),
|
|
527
853
|
priority: zod_1.z.enum(['low', 'normal', 'high', 'urgent']).optional().describe("Priority level ('low', 'normal', 'high', 'urgent')"),
|
|
528
854
|
blocked_reason: zod_1.z.string().optional().describe('Reason the action is blocked, if status is blocked'),
|
|
529
855
|
files: zod_1.z.array(zod_1.z.string()).optional().describe('File paths associated with this action'),
|
|
856
|
+
due_at: zod_1.z.string().optional().describe('Optional ISO-8601 due date/time (normalized to UTC)'),
|
|
857
|
+
remind_at: zod_1.z.string().optional().describe('Optional ISO-8601 reminder trigger date/time (normalized to UTC)'),
|
|
858
|
+
recurrence: zod_1.z.string().optional().describe("Optional recurrence expression: 5-field UTC cron, macro (@daily, @weekly), or ISO-8601 duration (P1D, P1W, PT2H)"),
|
|
859
|
+
snooze_until: zod_1.z.string().optional().describe('Optional ISO-8601 timestamp until which reminders are snoozed'),
|
|
530
860
|
}, async (args) => {
|
|
531
861
|
return handlers.brainActionAdd(args);
|
|
532
862
|
});
|
|
533
863
|
// 7. brain_action_list
|
|
534
|
-
server.tool('brain_action_list', 'List Next Actions for a project (and optionally global actions), filtered by status.', {
|
|
864
|
+
server.tool('brain_action_list', 'List Next Actions for a project (and optionally ancestors, children, and global actions), filtered by status, due_only, before, or user_id.', {
|
|
535
865
|
project_id: zod_1.z
|
|
536
866
|
.string()
|
|
537
867
|
.optional()
|
|
538
|
-
.describe('Project ID to filter by (
|
|
539
|
-
|
|
868
|
+
.describe('Project ID or hierarchical slug to filter by (never a filesystem path)'),
|
|
869
|
+
include_ancestors: zod_1.z
|
|
870
|
+
.boolean()
|
|
871
|
+
.default(true)
|
|
872
|
+
.describe('Whether to include ancestor projects when project_id is hierarchical (default true)'),
|
|
873
|
+
include_children: zod_1.z
|
|
874
|
+
.boolean()
|
|
875
|
+
.default(false)
|
|
876
|
+
.describe('Whether to include child subprojects below project_id (default false)'),
|
|
877
|
+
include_global: zod_1.z.boolean().optional().describe('Whether to include global actions when project_id is specified (default true)'),
|
|
878
|
+
due_only: zod_1.z.boolean().optional().describe('When true, return only open actions that are currently due/reminded and not snoozed'),
|
|
879
|
+
before: zod_1.z.string().optional().describe('ISO-8601 upper bound cutoff for due_at / remind_at'),
|
|
880
|
+
user_id: zod_1.z.string().optional().describe('Optional user_id filter'),
|
|
540
881
|
status: zod_1.z.string().optional().describe("Filter by status (e.g. 'ready', 'in_progress', 'blocked', 'done')"),
|
|
541
|
-
limit: zod_1.z.number().int().optional().describe('Maximum number of actions to return'),
|
|
882
|
+
limit: zod_1.z.number().int().min(1).max(200).optional().describe('Maximum number of actions to return'),
|
|
542
883
|
}, async (args) => {
|
|
543
884
|
return handlers.brainActionList(args);
|
|
544
885
|
});
|
|
545
886
|
// 8. brain_action_update
|
|
546
|
-
server.tool('brain_action_update', 'Update an existing Next Action (status, priority, title, description, blocked_reason, or resolved_by_session_id).', {
|
|
887
|
+
server.tool('brain_action_update', 'Update an existing Next Action (status, priority, title, description, blocked_reason, due_at, remind_at, recurrence, snooze_until, user_id, agent_id, or resolved_by_session_id). Completing a recurring action spawns its next occurrence.', {
|
|
547
888
|
id: zod_1.z.string().describe('ID of the action to update'),
|
|
548
889
|
status: zod_1.z.enum(['ready', 'blocked', 'in_progress', 'done', 'dismissed']).optional().describe("Updated status ('ready', 'blocked', 'in_progress', 'done', 'dismissed')"),
|
|
549
890
|
priority: zod_1.z.enum(['low', 'normal', 'high', 'urgent']).optional().describe("Updated priority ('low', 'normal', 'high', 'urgent')"),
|
|
@@ -551,10 +892,40 @@ function createBrainMcpServer(options = {}) {
|
|
|
551
892
|
description: zod_1.z.string().optional().describe('Updated description'),
|
|
552
893
|
blocked_reason: zod_1.z.string().optional().describe('Updated blocked reason'),
|
|
553
894
|
resolved_by_session_id: zod_1.z.string().optional().describe('Session ID that resolved this action'),
|
|
895
|
+
due_at: zod_1.z.string().nullable().optional().describe('Updated ISO-8601 due date/time (or null to clear)'),
|
|
896
|
+
remind_at: zod_1.z.string().nullable().optional().describe('Updated ISO-8601 reminder trigger date/time (or null to clear)'),
|
|
897
|
+
recurrence: zod_1.z.string().nullable().optional().describe('Updated cron/macro/ISO-8601 recurrence expression (or null to clear)'),
|
|
898
|
+
snooze_until: zod_1.z.string().nullable().optional().describe('Updated ISO-8601 snooze cutoff timestamp (or null to clear)'),
|
|
899
|
+
user_id: zod_1.z.string().nullable().optional().describe('Updated user_id attribution (or null to clear)'),
|
|
900
|
+
agent_id: zod_1.z.string().nullable().optional().describe('Updated agent_id provenance (or null to clear)'),
|
|
554
901
|
}, async (args) => {
|
|
555
902
|
return handlers.brainActionUpdate(args);
|
|
556
903
|
});
|
|
557
|
-
// 9.
|
|
904
|
+
// 9. brain_action_due
|
|
905
|
+
server.tool('brain_action_due', 'List due, reminded, or overdue Next Actions that are open and not snoozed.', {
|
|
906
|
+
project_id: zod_1.z
|
|
907
|
+
.string()
|
|
908
|
+
.optional()
|
|
909
|
+
.describe('Project ID or hierarchical slug to filter by (never a filesystem path)'),
|
|
910
|
+
include_ancestors: zod_1.z
|
|
911
|
+
.boolean()
|
|
912
|
+
.default(true)
|
|
913
|
+
.describe('Whether to include ancestor projects when project_id is hierarchical (default true)'),
|
|
914
|
+
include_children: zod_1.z
|
|
915
|
+
.boolean()
|
|
916
|
+
.default(false)
|
|
917
|
+
.describe('Whether to include child subprojects below project_id (default false)'),
|
|
918
|
+
include_global: zod_1.z
|
|
919
|
+
.boolean()
|
|
920
|
+
.default(true)
|
|
921
|
+
.describe('Whether to include global actions when project_id is specified (default true)'),
|
|
922
|
+
before: zod_1.z.string().optional().describe('ISO-8601 upper bound cutoff timestamp (defaults to now)'),
|
|
923
|
+
user_id: zod_1.z.string().optional().describe('Optional user_id filter'),
|
|
924
|
+
limit: zod_1.z.number().int().min(1).max(200).optional().describe('Maximum number of due actions to return'),
|
|
925
|
+
}, async (args) => {
|
|
926
|
+
return handlers.brainActionDue(args);
|
|
927
|
+
});
|
|
928
|
+
// 10. brain_sessions
|
|
558
929
|
server.tool('brain_sessions', 'Inspect prior agent sessions: list sessions, fetch a single session with its details, or replay a session timeline chronologically.', {
|
|
559
930
|
mode: zod_1.z
|
|
560
931
|
.enum(['list', 'get', 'replay'])
|
|
@@ -567,14 +938,27 @@ function createBrainMcpServer(options = {}) {
|
|
|
567
938
|
project_id: zod_1.z
|
|
568
939
|
.string()
|
|
569
940
|
.optional()
|
|
570
|
-
.describe('Project ID to filter by when listing sessions (
|
|
941
|
+
.describe('Project ID or hierarchical slug to filter by when listing sessions (never a filesystem path)'),
|
|
942
|
+
include_ancestors: zod_1.z
|
|
943
|
+
.boolean()
|
|
944
|
+
.default(true)
|
|
945
|
+
.describe('Whether to include ancestor projects when listing sessions (default true)'),
|
|
946
|
+
include_children: zod_1.z
|
|
947
|
+
.boolean()
|
|
948
|
+
.default(false)
|
|
949
|
+
.describe('Whether to include child subprojects when listing sessions (default false)'),
|
|
950
|
+
include_global: zod_1.z
|
|
951
|
+
.boolean()
|
|
952
|
+
.default(false)
|
|
953
|
+
.describe('Whether to include global sessions when project_id is specified (default false)'),
|
|
954
|
+
user_id: zod_1.z.string().optional().describe('Optional user_id filter when listing sessions'),
|
|
571
955
|
status: zod_1.z.string().optional().describe("Filter sessions by status when listing (e.g. 'active', 'completed', 'paused', 'abandoned')"),
|
|
572
956
|
agent_name: zod_1.z.string().optional().describe('Filter sessions by agent name when listing'),
|
|
573
|
-
limit: zod_1.z.number().int().optional().describe('Maximum number of sessions to return when listing'),
|
|
957
|
+
limit: zod_1.z.number().int().min(1).max(200).optional().describe('Maximum number of sessions to return when listing'),
|
|
574
958
|
}, async (args) => {
|
|
575
959
|
return handlers.brainSessions(args);
|
|
576
960
|
});
|
|
577
|
-
//
|
|
961
|
+
// 11. brain_session_end
|
|
578
962
|
server.tool('brain_session_end', 'End or pause a session and record a clean cross-agent handoff summary, files touched, and optional handoff_summary_id.', {
|
|
579
963
|
session_id: zod_1.z.string().describe('ID of the session to end'),
|
|
580
964
|
status: zod_1.z
|
|
@@ -587,17 +971,64 @@ function createBrainMcpServer(options = {}) {
|
|
|
587
971
|
}, async (args) => {
|
|
588
972
|
return handlers.brainSessionEnd(args);
|
|
589
973
|
});
|
|
590
|
-
//
|
|
591
|
-
server.tool('brain_graph', 'Explore the relational knowledge graph across notes, lessons, concepts, files, sessions, actions, and summaries.', {
|
|
974
|
+
// 12. brain_graph
|
|
975
|
+
server.tool('brain_graph', 'Explore or mutate the relational knowledge graph across notes, lessons, concepts, files, sessions, actions, entities, and summaries. Supports mode: query (1..3 hop BFS), upsert_entity (requires explicit scope), link, and unlink.', {
|
|
976
|
+
mode: zod_1.z
|
|
977
|
+
.enum(['query', 'upsert_entity', 'link', 'unlink'])
|
|
978
|
+
.default('query')
|
|
979
|
+
.describe("Operation mode: 'query' (default), 'upsert_entity', 'link', or 'unlink'"),
|
|
592
980
|
project_id: zod_1.z
|
|
593
981
|
.string()
|
|
594
982
|
.optional()
|
|
595
|
-
.describe('Project ID
|
|
983
|
+
.describe('Project ID or hierarchical slug (required iff mode is upsert_entity and scope is project; never a filesystem path)'),
|
|
596
984
|
scope: zod_1.z
|
|
597
985
|
.enum(['project', 'global', 'unknown'])
|
|
598
986
|
.optional()
|
|
599
|
-
.describe("
|
|
600
|
-
|
|
987
|
+
.describe("Scope ('project', 'global', or 'unknown'). REQUIRED when mode is 'upsert_entity'"),
|
|
988
|
+
include_ancestors: zod_1.z
|
|
989
|
+
.boolean()
|
|
990
|
+
.default(true)
|
|
991
|
+
.describe('Whether to include ancestor projects in query mode (default true)'),
|
|
992
|
+
include_children: zod_1.z
|
|
993
|
+
.boolean()
|
|
994
|
+
.default(false)
|
|
995
|
+
.describe('Whether to include child subprojects in query mode (default false)'),
|
|
996
|
+
include_global: zod_1.z
|
|
997
|
+
.boolean()
|
|
998
|
+
.default(false)
|
|
999
|
+
.describe('Whether to include global nodes in query mode (default false)'),
|
|
1000
|
+
depth: zod_1.z
|
|
1001
|
+
.number()
|
|
1002
|
+
.int()
|
|
1003
|
+
.min(1)
|
|
1004
|
+
.max(3)
|
|
1005
|
+
.optional()
|
|
1006
|
+
.describe('Multi-hop BFS depth across entity_edges in query mode (1..3, default 1)'),
|
|
1007
|
+
node_id: zod_1.z.string().optional().describe('Optional focal node ID to expand from in query mode'),
|
|
1008
|
+
entity_type: zod_1.z
|
|
1009
|
+
.string()
|
|
1010
|
+
.optional()
|
|
1011
|
+
.describe("Entity type (required when mode is 'upsert_entity', optional filter in 'query' mode; e.g. 'brand', 'person', 'asset', 'metric', 'document', 'tool')"),
|
|
1012
|
+
relation: zod_1.z
|
|
1013
|
+
.string()
|
|
1014
|
+
.optional()
|
|
1015
|
+
.describe("Edge relation (required for 'link', optional filter for 'query'/'unlink'; e.g. 'part_of', 'depends_on', 'references', 'owns', 'produced_by', 'blocks', 'related_to')"),
|
|
1016
|
+
user_id: zod_1.z.string().optional().describe('Optional user_id attribution/filter'),
|
|
1017
|
+
agent_id: zod_1.z.string().optional().describe('Optional agent_id provenance (stored, never filtered)'),
|
|
1018
|
+
id: zod_1.z.string().optional().describe("Entity ID (for upsert_entity) or Edge ID (for unlink)"),
|
|
1019
|
+
entity_id: zod_1.z.string().optional().describe("Optional explicit entity ID alias for mode='upsert_entity'"),
|
|
1020
|
+
name: zod_1.z.string().optional().describe("Entity display name (required when mode is 'upsert_entity')"),
|
|
1021
|
+
description: zod_1.z.string().optional().describe("Entity description (for mode='upsert_entity')"),
|
|
1022
|
+
external_ref: zod_1.z.string().optional().describe("External URI/ID pointer (for mode='upsert_entity', e.g. 's3://...', 'https://...')"),
|
|
1023
|
+
metadata: zod_1.z
|
|
1024
|
+
.union([zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()), zod_1.z.string()])
|
|
1025
|
+
.optional()
|
|
1026
|
+
.describe('Optional JSON object or JSON string metadata for entity or edge'),
|
|
1027
|
+
source_type: zod_1.z.string().optional().describe("Source node type for mode='link' (auto-resolved if omitted)"),
|
|
1028
|
+
source_id: zod_1.z.string().optional().describe("Source node ID (required for 'link', optional for 'unlink')"),
|
|
1029
|
+
target_type: zod_1.z.string().optional().describe("Target node type for mode='link' (auto-resolved if omitted)"),
|
|
1030
|
+
target_id: zod_1.z.string().optional().describe("Target node ID (required for 'link', optional for 'unlink')"),
|
|
1031
|
+
limit: zod_1.z.number().int().min(1).max(200).optional().describe('Maximum number of seed graph nodes to return in query mode'),
|
|
601
1032
|
}, async (args) => {
|
|
602
1033
|
return handlers.brainGraph(args);
|
|
603
1034
|
});
|