@kinqs/brainrouter-mcp-server 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +144 -0
- package/README.md +56 -0
- package/agents/README.md +120 -0
- package/agents/code-reviewer.md +97 -0
- package/agents/security-auditor.md +101 -0
- package/agents/test-engineer.md +95 -0
- package/dist/__tests__/agent_mode.test.d.ts +1 -0
- package/dist/__tests__/api-routes.test.d.ts +1 -0
- package/dist/__tests__/api-routes.test.js +170 -0
- package/dist/__tests__/crypto.test.d.ts +1 -0
- package/dist/__tests__/crypto.test.js +28 -0
- package/dist/__tests__/host-integrations.test.d.ts +1 -0
- package/dist/__tests__/host-integrations.test.js +82 -0
- package/dist/__tests__/integration.test.d.ts +1 -0
- package/dist/__tests__/integration.test.js +50 -0
- package/dist/__tests__/loader.test.d.ts +1 -0
- package/dist/__tests__/loader.test.js +89 -0
- package/dist/__tests__/neural-spark.test.d.ts +1 -0
- package/dist/__tests__/neural-spark.test.js +112 -0
- package/dist/__tests__/pagination.test.d.ts +1 -0
- package/dist/__tests__/pagination.test.js +23 -0
- package/dist/__tests__/redaction.test.d.ts +1 -0
- package/dist/__tests__/redaction.test.js +17 -0
- package/dist/__tests__/registry.test.d.ts +1 -0
- package/dist/__tests__/registry.test.js +56 -0
- package/dist/__tests__/retry.test.d.ts +1 -0
- package/dist/__tests__/retry.test.js +30 -0
- package/dist/__tests__/skill-activation.test.d.ts +1 -0
- package/dist/__tests__/skill-activation.test.js +112 -0
- package/dist/__tests__/working-memory.test.d.ts +1 -0
- package/dist/__tests__/working-memory.test.js +200 -0
- package/dist/__tests__/workspace-paths.test.d.ts +1 -0
- package/dist/__tests__/workspace-paths.test.js +56 -0
- package/dist/__tests__/writer.test.d.ts +1 -0
- package/dist/__tests__/writer.test.js +94 -0
- package/dist/api/auth/crypto.d.ts +4 -0
- package/dist/api/auth/crypto.js +54 -0
- package/dist/api/middleware/auth.d.ts +12 -0
- package/dist/api/middleware/auth.js +90 -0
- package/dist/api/pagination.d.ts +18 -0
- package/dist/api/pagination.js +32 -0
- package/dist/api/routes/auth.d.ts +1 -0
- package/dist/api/routes/auth.js +130 -0
- package/dist/api/routes/chat-completions.d.ts +7 -0
- package/dist/api/routes/chat-completions.js +474 -0
- package/dist/api/routes/contradictions.d.ts +1 -0
- package/dist/api/routes/contradictions.js +28 -0
- package/dist/api/routes/evidence.d.ts +1 -0
- package/dist/api/routes/evidence.js +59 -0
- package/dist/api/routes/governance.d.ts +1 -0
- package/dist/api/routes/governance.js +95 -0
- package/dist/api/routes/graph.d.ts +1 -0
- package/dist/api/routes/graph.js +25 -0
- package/dist/api/routes/hooks.d.ts +1 -0
- package/dist/api/routes/hooks.js +88 -0
- package/dist/api/routes/memories.d.ts +1 -0
- package/dist/api/routes/memories.js +92 -0
- package/dist/api/routes/persona.d.ts +1 -0
- package/dist/api/routes/persona.js +9 -0
- package/dist/api/routes/scenes.d.ts +1 -0
- package/dist/api/routes/scenes.js +35 -0
- package/dist/api/routes/skills.d.ts +1 -0
- package/dist/api/routes/skills.js +14 -0
- package/dist/api/routes/stats.d.ts +1 -0
- package/dist/api/routes/stats.js +8 -0
- package/dist/api/routes/users.d.ts +1 -0
- package/dist/api/routes/users.js +82 -0
- package/dist/api/routes/working.d.ts +1 -0
- package/dist/api/routes/working.js +88 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +492 -0
- package/dist/integrations/claude-code.d.ts +12 -0
- package/dist/integrations/claude-code.js +35 -0
- package/dist/integrations/codex.d.ts +12 -0
- package/dist/integrations/codex.js +34 -0
- package/dist/integrations/generic-mcp.d.ts +52 -0
- package/dist/integrations/generic-mcp.js +118 -0
- package/dist/loader.d.ts +29 -0
- package/dist/loader.js +200 -0
- package/dist/memory/capture.d.ts +35 -0
- package/dist/memory/capture.js +230 -0
- package/dist/memory/config.d.ts +2 -0
- package/dist/memory/config.js +3 -0
- package/dist/memory/engine.d.ts +203 -0
- package/dist/memory/engine.js +626 -0
- package/dist/memory/llm-semaphore.d.ts +41 -0
- package/dist/memory/llm-semaphore.js +81 -0
- package/dist/memory/memory-type-config.d.ts +11 -0
- package/dist/memory/memory-type-config.js +65 -0
- package/dist/memory/pipeline/cognitive-contradiction.d.ts +7 -0
- package/dist/memory/pipeline/cognitive-contradiction.js +59 -0
- package/dist/memory/pipeline/cognitive-dedup.d.ts +23 -0
- package/dist/memory/pipeline/cognitive-dedup.js +38 -0
- package/dist/memory/pipeline/cognitive-extractor.d.ts +21 -0
- package/dist/memory/pipeline/cognitive-extractor.js +183 -0
- package/dist/memory/pipeline/contextual-focus-builder.d.ts +13 -0
- package/dist/memory/pipeline/contextual-focus-builder.js +135 -0
- package/dist/memory/pipeline/focus-direction-shift.d.ts +10 -0
- package/dist/memory/pipeline/focus-direction-shift.js +27 -0
- package/dist/memory/pipeline/graph-builder.d.ts +11 -0
- package/dist/memory/pipeline/graph-builder.js +88 -0
- package/dist/memory/pipeline/graph-recall.d.ts +13 -0
- package/dist/memory/pipeline/graph-recall.js +55 -0
- package/dist/memory/pipeline/identity-distiller.d.ts +15 -0
- package/dist/memory/pipeline/identity-distiller.js +40 -0
- package/dist/memory/pipeline/l1-contradiction.d.ts +7 -0
- package/dist/memory/pipeline/l1-contradiction.js +66 -0
- package/dist/memory/pipeline/l1-dedup.d.ts +23 -0
- package/dist/memory/pipeline/l1-dedup.js +39 -0
- package/dist/memory/pipeline/l1-extractor.d.ts +21 -0
- package/dist/memory/pipeline/l1-extractor.js +180 -0
- package/dist/memory/pipeline/l2-direction-shift.d.ts +10 -0
- package/dist/memory/pipeline/l2-direction-shift.js +27 -0
- package/dist/memory/pipeline/l2-scene.d.ts +15 -0
- package/dist/memory/pipeline/l2-scene.js +140 -0
- package/dist/memory/pipeline/l3-distiller.d.ts +15 -0
- package/dist/memory/pipeline/l3-distiller.js +40 -0
- package/dist/memory/pipeline/neural-spark.d.ts +27 -0
- package/dist/memory/pipeline/neural-spark.js +78 -0
- package/dist/memory/pipeline/skill-prewarm.d.ts +63 -0
- package/dist/memory/pipeline/skill-prewarm.js +127 -0
- package/dist/memory/pipeline/task-queue.d.ts +54 -0
- package/dist/memory/pipeline/task-queue.js +117 -0
- package/dist/memory/prompts/cognitive-contradiction.d.ts +1 -0
- package/dist/memory/prompts/cognitive-contradiction.js +25 -0
- package/dist/memory/prompts/cognitive-extraction.d.ts +10 -0
- package/dist/memory/prompts/cognitive-extraction.js +114 -0
- package/dist/memory/prompts/core-identity.d.ts +6 -0
- package/dist/memory/prompts/core-identity.js +60 -0
- package/dist/memory/prompts/focus-direction-shift.d.ts +5 -0
- package/dist/memory/prompts/focus-direction-shift.js +32 -0
- package/dist/memory/prompts/focus-scene-cluster.d.ts +2 -0
- package/dist/memory/prompts/focus-scene-cluster.js +33 -0
- package/dist/memory/prompts/focus-scene.d.ts +7 -0
- package/dist/memory/prompts/focus-scene.js +40 -0
- package/dist/memory/prompts/graph-extraction-batch.d.ts +14 -0
- package/dist/memory/prompts/graph-extraction-batch.js +54 -0
- package/dist/memory/prompts/graph-extraction.d.ts +2 -0
- package/dist/memory/prompts/graph-extraction.js +53 -0
- package/dist/memory/prompts/l1-contradiction-batch.d.ts +16 -0
- package/dist/memory/prompts/l1-contradiction-batch.js +47 -0
- package/dist/memory/prompts/l1-contradiction.d.ts +1 -0
- package/dist/memory/prompts/l1-contradiction.js +25 -0
- package/dist/memory/prompts/l1-extraction.d.ts +10 -0
- package/dist/memory/prompts/l1-extraction.js +114 -0
- package/dist/memory/prompts/l2-direction-shift.d.ts +5 -0
- package/dist/memory/prompts/l2-direction-shift.js +32 -0
- package/dist/memory/prompts/l2-scene-cluster.d.ts +2 -0
- package/dist/memory/prompts/l2-scene-cluster.js +33 -0
- package/dist/memory/prompts/l2-scene.d.ts +7 -0
- package/dist/memory/prompts/l2-scene.js +40 -0
- package/dist/memory/prompts/l3-persona.d.ts +6 -0
- package/dist/memory/prompts/l3-persona.js +60 -0
- package/dist/memory/recall.d.ts +47 -0
- package/dist/memory/recall.js +427 -0
- package/dist/memory/redaction.d.ts +1 -0
- package/dist/memory/redaction.js +24 -0
- package/dist/memory/retry.d.ts +13 -0
- package/dist/memory/retry.js +53 -0
- package/dist/memory/scheduler.d.ts +9 -0
- package/dist/memory/scheduler.js +16 -0
- package/dist/memory/skill-hints-loader.d.ts +30 -0
- package/dist/memory/skill-hints-loader.js +100 -0
- package/dist/memory/store/embedding.d.ts +16 -0
- package/dist/memory/store/embedding.js +68 -0
- package/dist/memory/store/reranker.d.ts +24 -0
- package/dist/memory/store/reranker.js +83 -0
- package/dist/memory/store/sqlite.d.ts +167 -0
- package/dist/memory/store/sqlite.js +1816 -0
- package/dist/memory/store/types.d.ts +101 -0
- package/dist/memory/store/types.js +1 -0
- package/dist/memory/types.d.ts +207 -0
- package/dist/memory/types.js +7 -0
- package/dist/memory/validation.d.ts +441 -0
- package/dist/memory/validation.js +129 -0
- package/dist/memory/working/canvas.d.ts +5 -0
- package/dist/memory/working/canvas.js +43 -0
- package/dist/memory/working/offload.d.ts +71 -0
- package/dist/memory/working/offload.js +211 -0
- package/dist/memory/working/step-log.d.ts +16 -0
- package/dist/memory/working/step-log.js +35 -0
- package/dist/registry.d.ts +34 -0
- package/dist/registry.js +305 -0
- package/dist/resolver.d.ts +17 -0
- package/dist/resolver.js +126 -0
- package/dist/scripts/validate-foreign-workspace-path.d.ts +1 -0
- package/dist/scripts/validate-foreign-workspace-path.js +39 -0
- package/dist/tools/agent_memory_tools.d.ts +485 -0
- package/dist/tools/agent_memory_tools.js +793 -0
- package/dist/tools/create_skill.d.ts +46 -0
- package/dist/tools/create_skill.js +46 -0
- package/dist/tools/get_doc.d.ts +21 -0
- package/dist/tools/get_doc.js +24 -0
- package/dist/tools/get_persona.d.ts +15 -0
- package/dist/tools/get_persona.js +20 -0
- package/dist/tools/get_reference.d.ts +15 -0
- package/dist/tools/get_reference.js +20 -0
- package/dist/tools/get_skill.d.ts +34 -0
- package/dist/tools/get_skill.js +65 -0
- package/dist/tools/get_template_doc.d.ts +21 -0
- package/dist/tools/get_template_doc.js +24 -0
- package/dist/tools/list_docs.d.ts +15 -0
- package/dist/tools/list_docs.js +16 -0
- package/dist/tools/list_skills.d.ts +18 -0
- package/dist/tools/list_skills.js +17 -0
- package/dist/tools/list_template_docs.d.ts +15 -0
- package/dist/tools/list_template_docs.js +16 -0
- package/dist/tools/memory-engineering.d.ts +225 -0
- package/dist/tools/memory-engineering.js +284 -0
- package/dist/tools/memory-explain.d.ts +34 -0
- package/dist/tools/memory-explain.js +109 -0
- package/dist/tools/memory-governance.d.ts +171 -0
- package/dist/tools/memory-governance.js +224 -0
- package/dist/tools/memory-hooks.d.ts +67 -0
- package/dist/tools/memory-hooks.js +102 -0
- package/dist/tools/memory-working.d.ts +98 -0
- package/dist/tools/memory-working.js +101 -0
- package/dist/tools/memory_capture_turn.d.ts +66 -0
- package/dist/tools/memory_capture_turn.js +85 -0
- package/dist/tools/memory_consolidate.d.ts +55 -0
- package/dist/tools/memory_consolidate.js +176 -0
- package/dist/tools/memory_contradictions.d.ts +53 -0
- package/dist/tools/memory_contradictions.js +52 -0
- package/dist/tools/memory_graph_query.d.ts +51 -0
- package/dist/tools/memory_graph_query.js +35 -0
- package/dist/tools/memory_mark_cited.d.ts +43 -0
- package/dist/tools/memory_mark_cited.js +63 -0
- package/dist/tools/memory_recall.d.ts +77 -0
- package/dist/tools/memory_recall.js +81 -0
- package/dist/tools/memory_register_skill_hints.d.ts +49 -0
- package/dist/tools/memory_register_skill_hints.js +55 -0
- package/dist/tools/memory_resolve_session.d.ts +24 -0
- package/dist/tools/memory_resolve_session.js +133 -0
- package/dist/tools/memory_search.d.ts +146 -0
- package/dist/tools/memory_search.js +84 -0
- package/dist/tools/search_skills.d.ts +18 -0
- package/dist/tools/search_skills.js +17 -0
- package/dist/tools/update_doc.d.ts +24 -0
- package/dist/tools/update_doc.js +35 -0
- package/dist/tools/update_skill.d.ts +30 -0
- package/dist/tools/update_skill.js +80 -0
- package/dist/types.d.ts +81 -0
- package/dist/types.js +4 -0
- package/dist/writer.d.ts +30 -0
- package/dist/writer.js +220 -0
- package/docs/TEMPLATE ONLY +1 -0
- package/docs/api/API.md +64 -0
- package/docs/api/security/SECURITY.md +58 -0
- package/docs/deployment/DockerDeployment.md +30 -0
- package/docs/design/Design.md +59 -0
- package/docs/design/themes/apple.md +101 -0
- package/docs/design/themes/dieter-grid.md +100 -0
- package/docs/design/themes/gallery-white.md +100 -0
- package/docs/design/themes/pinterest.md +101 -0
- package/docs/design/themes/realty-open-house.md +101 -0
- package/docs/design/themes/vodafone.md +101 -0
- package/docs/hooks/Hooks.md +30 -0
- package/docs/schema/Schema.md +35 -0
- package/docs/strategy/ScalingStrategy.md +19 -0
- package/package.json +88 -0
- package/references/accessibility-checklist.md +160 -0
- package/references/orchestration-patterns.md +370 -0
- package/references/performance-checklist.md +153 -0
- package/references/security-checklist.md +134 -0
- package/references/testing-patterns.md +236 -0
- package/skills/agent/adr-skill/SKILL.md +299 -0
- package/skills/agent/agentic-engineering-workflow/SKILL.md +95 -0
- package/skills/agent/bootstrap-skill/SKILL.md +103 -0
- package/skills/agent/context-engineering/SKILL.md +307 -0
- package/skills/agent/debugging-and-error-recovery/SKILL.md +308 -0
- package/skills/agent/developer-growth-analysis/SKILL.md +328 -0
- package/skills/agent/doubt-driven-skill/SKILL.md +249 -0
- package/skills/agent/handover-skill/SKILL.md +112 -0
- package/skills/agent/idea-refine-skill/SKILL.md +185 -0
- package/skills/agent/idea-refine-skill/examples.md +238 -0
- package/skills/agent/idea-refine-skill/frameworks.md +99 -0
- package/skills/agent/idea-refine-skill/refinement-criteria.md +113 -0
- package/skills/agent/interview-skill/SKILL.md +226 -0
- package/skills/agent/planning-skill/SKILL.md +270 -0
- package/skills/agent/skill-authoring/SKILL.md +189 -0
- package/skills/agent/source-driven-skill/SKILL.md +197 -0
- package/skills/agent/spec-driven-skill/SKILL.md +221 -0
- package/skills/agent/sync-skill/SKILL.md +92 -0
- package/skills/agent/using-agent-skills/SKILL.md +189 -0
- package/skills/api/a11y-skill/SKILL.md +88 -0
- package/skills/api/api-skill/SKILL.md +123 -0
- package/skills/api/auth-skill/SKILL.md +80 -0
- package/skills/api/debug-skill/SKILL.md +535 -0
- package/skills/api/performance-skill/SKILL.md +100 -0
- package/skills/api/testing-skill/SKILL.md +100 -0
- package/skills/codebase/code-review-and-quality/SKILL.md +228 -0
- package/skills/codebase/code-simplification/SKILL.md +352 -0
- package/skills/codebase/code-structure-cleanup/SKILL.md +142 -0
- package/skills/codebase/concerns-skill/SKILL.md +89 -0
- package/skills/codebase/conventions-skill/SKILL.md +95 -0
- package/skills/codebase/doc-management-skill/SKILL.md +47 -0
- package/skills/codebase/git-workflow-skill/SKILL.md +312 -0
- package/skills/communication/1-3-1-rule/SKILL.md +120 -0
- package/skills/design/brutalist-skill/SKILL.md +131 -0
- package/skills/design/concept-diagrams/SKILL.md +387 -0
- package/skills/design/concept-diagrams/examples/apartment-floor-plan-conversion.md +244 -0
- package/skills/design/concept-diagrams/examples/automated-password-reset-flow.md +276 -0
- package/skills/design/concept-diagrams/examples/autonomous-llm-research-agent-flow.md +240 -0
- package/skills/design/concept-diagrams/examples/banana-journey-tree-to-smoothie.md +161 -0
- package/skills/design/concept-diagrams/examples/commercial-aircraft-structure.md +209 -0
- package/skills/design/concept-diagrams/examples/cpu-ooo-microarchitecture.md +236 -0
- package/skills/design/concept-diagrams/examples/electricity-grid-flow.md +182 -0
- package/skills/design/concept-diagrams/examples/feature-film-production-pipeline.md +172 -0
- package/skills/design/concept-diagrams/examples/hospital-emergency-department-flow.md +165 -0
- package/skills/design/concept-diagrams/examples/ml-benchmark-grouped-bar-chart.md +114 -0
- package/skills/design/concept-diagrams/examples/place-order-uml-sequence.md +325 -0
- package/skills/design/concept-diagrams/examples/smart-city-infrastructure.md +173 -0
- package/skills/design/concept-diagrams/examples/smartphone-layer-anatomy.md +154 -0
- package/skills/design/concept-diagrams/examples/sn2-reaction-mechanism.md +247 -0
- package/skills/design/concept-diagrams/examples/wind-turbine-structure.md +338 -0
- package/skills/design/concept-diagrams/references/dashboard-patterns.md +43 -0
- package/skills/design/concept-diagrams/references/infrastructure-patterns.md +144 -0
- package/skills/design/concept-diagrams/references/physical-shape-cookbook.md +42 -0
- package/skills/design/concept-diagrams/templates/template.html +174 -0
- package/skills/design/gpt-tasteskill/SKILL.md +114 -0
- package/skills/design/minimalist-skill/SKILL.md +116 -0
- package/skills/design/output-skill/SKILL.md +87 -0
- package/skills/design/redesign-skill/SKILL.md +213 -0
- package/skills/design/soft-skill/SKILL.md +132 -0
- package/skills/design/stitch-skill/EXAMPLE.md +121 -0
- package/skills/design/stitch-skill/SKILL.md +222 -0
- package/skills/design/taste-skill/SKILL.md +269 -0
- package/skills/devops/ci-cd-skill/SKILL.md +402 -0
- package/skills/devops/docker-skill/SKILL.md +297 -0
- package/skills/devops/domain-skill/SKILL.md +234 -0
- package/skills/lifecycle/changelog-generator/SKILL.md +135 -0
- package/skills/lifecycle/incremental-skill/SKILL.md +257 -0
- package/skills/lifecycle/migration-skill/SKILL.md +218 -0
- package/skills/lifecycle/shipping-skill/SKILL.md +321 -0
- package/skills/memory/agent-memory/SKILL.md +122 -0
- package/skills/qa/browser-testing-skill/SKILL.md +314 -0
- package/skills/ux/adversarial-ux-skill/SKILL.md +168 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { getWorkingContext, offloadWorkingPayload, resetWorkingMemory, } from "../memory/working/offload.js";
|
|
3
|
+
function toolResult(value) {
|
|
4
|
+
return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
|
|
5
|
+
}
|
|
6
|
+
const baseWorkingInput = {
|
|
7
|
+
workspacePath: z.string().optional(),
|
|
8
|
+
userId: z.string().optional(),
|
|
9
|
+
sessionKey: z.string().min(1),
|
|
10
|
+
};
|
|
11
|
+
export const memoryWorkingToolSchemas = [
|
|
12
|
+
{
|
|
13
|
+
name: "memory_working_context",
|
|
14
|
+
description: "Return the current working-memory canvas and injected state block without raw payloads. Optionally fetch one raw ref by nodeId.",
|
|
15
|
+
inputSchema: {
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {
|
|
18
|
+
workspacePath: { type: "string" },
|
|
19
|
+
userId: { type: "string" },
|
|
20
|
+
sessionKey: { type: "string" },
|
|
21
|
+
nodeId: { type: "string", description: "Optional ref node to fetch raw payload for." },
|
|
22
|
+
activeNodeId: { type: "string", description: "Optional node to highlight in the returned Mermaid canvas." },
|
|
23
|
+
contextWindowTokens: { type: "number" },
|
|
24
|
+
estimatedTokens: { type: "number" },
|
|
25
|
+
},
|
|
26
|
+
required: ["sessionKey"],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "memory_working_offload",
|
|
31
|
+
description: "Offload a large short-term working payload to .brainrouter/work refs and update step log, canvas, and injected state.",
|
|
32
|
+
inputSchema: {
|
|
33
|
+
type: "object",
|
|
34
|
+
properties: {
|
|
35
|
+
workspacePath: { type: "string" },
|
|
36
|
+
userId: { type: "string" },
|
|
37
|
+
sessionKey: { type: "string" },
|
|
38
|
+
payload: { type: "string" },
|
|
39
|
+
title: { type: "string" },
|
|
40
|
+
summary: { type: "string" },
|
|
41
|
+
kind: { type: "string" },
|
|
42
|
+
contextWindowTokens: { type: "number" },
|
|
43
|
+
estimatedTokens: { type: "number" },
|
|
44
|
+
forceAggressive: { type: "boolean" },
|
|
45
|
+
},
|
|
46
|
+
required: ["sessionKey", "payload"],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "memory_working_reset",
|
|
51
|
+
description: "Clear working memory files for a session after session end or when starting a clean task context.",
|
|
52
|
+
inputSchema: {
|
|
53
|
+
type: "object",
|
|
54
|
+
properties: {
|
|
55
|
+
workspacePath: { type: "string" },
|
|
56
|
+
userId: { type: "string" },
|
|
57
|
+
sessionKey: { type: "string" },
|
|
58
|
+
},
|
|
59
|
+
required: ["sessionKey"],
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
export async function handleMemoryWorkingTool(name, args, options) {
|
|
64
|
+
switch (name) {
|
|
65
|
+
case "memory_working_context": {
|
|
66
|
+
const params = z.object({
|
|
67
|
+
...baseWorkingInput,
|
|
68
|
+
nodeId: z.string().optional(),
|
|
69
|
+
activeNodeId: z.string().optional(),
|
|
70
|
+
contextWindowTokens: z.number().int().positive().optional(),
|
|
71
|
+
estimatedTokens: z.number().int().nonnegative().optional(),
|
|
72
|
+
}).parse(args);
|
|
73
|
+
const result = getWorkingContext(params.workspacePath, params.userId ?? options?.defaultUserId ?? "default", params.sessionKey, {
|
|
74
|
+
nodeId: params.nodeId,
|
|
75
|
+
activeNodeId: params.activeNodeId,
|
|
76
|
+
contextWindowTokens: params.contextWindowTokens,
|
|
77
|
+
estimatedTokens: params.estimatedTokens,
|
|
78
|
+
});
|
|
79
|
+
return toolResult(result);
|
|
80
|
+
}
|
|
81
|
+
case "memory_working_offload": {
|
|
82
|
+
const params = z.object({
|
|
83
|
+
...baseWorkingInput,
|
|
84
|
+
payload: z.string().min(1),
|
|
85
|
+
title: z.string().optional(),
|
|
86
|
+
summary: z.string().optional(),
|
|
87
|
+
kind: z.string().optional(),
|
|
88
|
+
contextWindowTokens: z.number().int().positive().optional(),
|
|
89
|
+
estimatedTokens: z.number().int().nonnegative().optional(),
|
|
90
|
+
forceAggressive: z.boolean().optional(),
|
|
91
|
+
}).parse(args);
|
|
92
|
+
return toolResult(offloadWorkingPayload({ ...params, userId: params.userId ?? options?.defaultUserId ?? "default" }));
|
|
93
|
+
}
|
|
94
|
+
case "memory_working_reset": {
|
|
95
|
+
const params = z.object(baseWorkingInput).parse(args);
|
|
96
|
+
return toolResult(resetWorkingMemory(params.workspacePath, params.userId ?? options?.defaultUserId ?? "default", params.sessionKey));
|
|
97
|
+
}
|
|
98
|
+
default:
|
|
99
|
+
throw new Error(`Unknown working memory tool: ${name}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export declare const memoryCaptureTurnToolSchema: {
|
|
2
|
+
readonly name: "memory_capture_turn";
|
|
3
|
+
readonly description: "Record a completed conversation turn for memory processing. Call this passively after every agent response to ensure accurate tracking.";
|
|
4
|
+
readonly inputSchema: {
|
|
5
|
+
readonly type: "object";
|
|
6
|
+
readonly properties: {
|
|
7
|
+
readonly userId: {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly description: "The ID of the user (enforces multi-tenant isolation).";
|
|
10
|
+
};
|
|
11
|
+
readonly sessionKey: {
|
|
12
|
+
readonly type: "string";
|
|
13
|
+
readonly description: "A stable identifier for this conversation channel/session.";
|
|
14
|
+
};
|
|
15
|
+
readonly sessionId: {
|
|
16
|
+
readonly type: "string";
|
|
17
|
+
readonly description: "An optional sub-session identifier.";
|
|
18
|
+
};
|
|
19
|
+
readonly messages: {
|
|
20
|
+
readonly type: "array";
|
|
21
|
+
readonly items: {
|
|
22
|
+
readonly type: "object";
|
|
23
|
+
readonly properties: {
|
|
24
|
+
readonly role: {
|
|
25
|
+
readonly type: "string";
|
|
26
|
+
readonly enum: readonly ["user", "assistant", "tool"];
|
|
27
|
+
};
|
|
28
|
+
readonly content: {
|
|
29
|
+
readonly type: "string";
|
|
30
|
+
};
|
|
31
|
+
readonly timestamp: {
|
|
32
|
+
readonly type: "number";
|
|
33
|
+
readonly description: "Epoch timestamp in milliseconds";
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
readonly required: readonly ["role", "content", "timestamp"];
|
|
37
|
+
};
|
|
38
|
+
readonly description: "The new messages that occurred in this turn.";
|
|
39
|
+
};
|
|
40
|
+
readonly activeSkill: {
|
|
41
|
+
readonly type: "string";
|
|
42
|
+
readonly description: "The name of the BrainRouter skill currently being executed (if any).";
|
|
43
|
+
};
|
|
44
|
+
readonly skillHints: {
|
|
45
|
+
readonly type: "string";
|
|
46
|
+
readonly description: "Skill-specific extraction hints provided by the active skill.";
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
readonly required: readonly ["sessionKey", "messages"];
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export declare function handleMemoryCaptureTurn(args: any, options?: {
|
|
53
|
+
defaultUserId?: string;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
content: {
|
|
56
|
+
type: string;
|
|
57
|
+
text: string;
|
|
58
|
+
}[];
|
|
59
|
+
isError?: undefined;
|
|
60
|
+
} | {
|
|
61
|
+
isError: boolean;
|
|
62
|
+
content: {
|
|
63
|
+
type: string;
|
|
64
|
+
text: string;
|
|
65
|
+
}[];
|
|
66
|
+
}>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { memoryEngine } from "../memory/engine.js";
|
|
3
|
+
export const memoryCaptureTurnToolSchema = {
|
|
4
|
+
name: "memory_capture_turn",
|
|
5
|
+
description: "Record a completed conversation turn for memory processing. Call this passively after every agent response to ensure accurate tracking.",
|
|
6
|
+
inputSchema: {
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {
|
|
9
|
+
userId: {
|
|
10
|
+
type: "string",
|
|
11
|
+
description: "The ID of the user (enforces multi-tenant isolation)."
|
|
12
|
+
},
|
|
13
|
+
sessionKey: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "A stable identifier for this conversation channel/session."
|
|
16
|
+
},
|
|
17
|
+
sessionId: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "An optional sub-session identifier."
|
|
20
|
+
},
|
|
21
|
+
messages: {
|
|
22
|
+
type: "array",
|
|
23
|
+
items: {
|
|
24
|
+
type: "object",
|
|
25
|
+
properties: {
|
|
26
|
+
role: { type: "string", enum: ["user", "assistant", "tool"] },
|
|
27
|
+
content: { type: "string" },
|
|
28
|
+
timestamp: { type: "number", description: "Epoch timestamp in milliseconds" }
|
|
29
|
+
},
|
|
30
|
+
required: ["role", "content", "timestamp"]
|
|
31
|
+
},
|
|
32
|
+
description: "The new messages that occurred in this turn."
|
|
33
|
+
},
|
|
34
|
+
activeSkill: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "The name of the BrainRouter skill currently being executed (if any)."
|
|
37
|
+
},
|
|
38
|
+
skillHints: {
|
|
39
|
+
type: "string",
|
|
40
|
+
description: "Skill-specific extraction hints provided by the active skill."
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
required: ["sessionKey", "messages"]
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export async function handleMemoryCaptureTurn(args, options) {
|
|
47
|
+
const params = z.object({
|
|
48
|
+
userId: z.string().optional(),
|
|
49
|
+
sessionKey: z.string(),
|
|
50
|
+
sessionId: z.string().optional(),
|
|
51
|
+
messages: z.array(z.object({
|
|
52
|
+
role: z.enum(["user", "assistant", "tool"]),
|
|
53
|
+
content: z.string(),
|
|
54
|
+
timestamp: z.number()
|
|
55
|
+
})),
|
|
56
|
+
activeSkill: z.string().optional(),
|
|
57
|
+
skillHints: z.string().optional()
|
|
58
|
+
}).parse(args);
|
|
59
|
+
const effectiveUserId = params.userId ?? options?.defaultUserId ?? "default";
|
|
60
|
+
try {
|
|
61
|
+
if (params.activeSkill) {
|
|
62
|
+
memoryEngine.spikeSkill(effectiveUserId, params.activeSkill);
|
|
63
|
+
}
|
|
64
|
+
const result = await memoryEngine.capture({
|
|
65
|
+
userId: effectiveUserId,
|
|
66
|
+
sessionKey: params.sessionKey,
|
|
67
|
+
sessionId: params.sessionId,
|
|
68
|
+
messages: params.messages,
|
|
69
|
+
activeSkill: params.activeSkill,
|
|
70
|
+
skillHints: params.skillHints
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
content: [{
|
|
74
|
+
type: "text",
|
|
75
|
+
text: JSON.stringify(result, null, 2)
|
|
76
|
+
}]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
return {
|
|
81
|
+
isError: true,
|
|
82
|
+
content: [{ type: "text", text: `Capture failed: ${err.message}` }]
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP-side memory consolidation. Collapses recall records into per-type
|
|
3
|
+
* markdown files under `<workspace>/.brainrouter/memories/` so the user
|
|
4
|
+
* has a human-readable view of what the cognitive memory engine has
|
|
5
|
+
* learned across sessions.
|
|
6
|
+
*
|
|
7
|
+
* The MCP server already exposes recall + capture. This tool exposes the
|
|
8
|
+
* filesystem consolidation step so any MCP-speaking client can write the
|
|
9
|
+
* same artifacts without re-implementing the bucketing logic.
|
|
10
|
+
*/
|
|
11
|
+
export declare const memoryConsolidateToolSchema: {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
inputSchema: {
|
|
15
|
+
type: string;
|
|
16
|
+
properties: {
|
|
17
|
+
userId: {
|
|
18
|
+
type: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
sessionKey: {
|
|
22
|
+
type: string;
|
|
23
|
+
description: string;
|
|
24
|
+
};
|
|
25
|
+
workspacePath: {
|
|
26
|
+
type: string;
|
|
27
|
+
description: string;
|
|
28
|
+
};
|
|
29
|
+
query: {
|
|
30
|
+
type: string;
|
|
31
|
+
description: string;
|
|
32
|
+
};
|
|
33
|
+
limit: {
|
|
34
|
+
type: string;
|
|
35
|
+
description: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
required: string[];
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export declare function handleMemoryConsolidate(args: unknown, options?: {
|
|
42
|
+
defaultUserId?: string;
|
|
43
|
+
}): Promise<{
|
|
44
|
+
content: {
|
|
45
|
+
type: string;
|
|
46
|
+
text: string;
|
|
47
|
+
}[];
|
|
48
|
+
isError?: undefined;
|
|
49
|
+
} | {
|
|
50
|
+
isError: boolean;
|
|
51
|
+
content: {
|
|
52
|
+
type: string;
|
|
53
|
+
text: string;
|
|
54
|
+
}[];
|
|
55
|
+
}>;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { memoryEngine } from '../memory/engine.js';
|
|
5
|
+
/**
|
|
6
|
+
* MCP-side memory consolidation. Collapses recall records into per-type
|
|
7
|
+
* markdown files under `<workspace>/.brainrouter/memories/` so the user
|
|
8
|
+
* has a human-readable view of what the cognitive memory engine has
|
|
9
|
+
* learned across sessions.
|
|
10
|
+
*
|
|
11
|
+
* The MCP server already exposes recall + capture. This tool exposes the
|
|
12
|
+
* filesystem consolidation step so any MCP-speaking client can write the
|
|
13
|
+
* same artifacts without re-implementing the bucketing logic.
|
|
14
|
+
*/
|
|
15
|
+
export const memoryConsolidateToolSchema = {
|
|
16
|
+
name: 'memory_consolidate',
|
|
17
|
+
description: 'Read recent memory records and write them to per-type markdown files ' +
|
|
18
|
+
'(user.md, feedback.md, project.md, reference.md, raw_memories.md, MEMORY.md) ' +
|
|
19
|
+
'under <workspacePath>/.brainrouter/memories/. Use this at session end or on demand ' +
|
|
20
|
+
'to produce a human-readable consolidation of what the agent learned.',
|
|
21
|
+
inputSchema: {
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
userId: { type: 'string', description: 'User identifier for isolation' },
|
|
25
|
+
sessionKey: { type: 'string', description: 'Session identifier' },
|
|
26
|
+
workspacePath: { type: 'string', description: 'Absolute path to the workspace where files will be written.' },
|
|
27
|
+
query: { type: 'string', description: 'Optional query to filter records before consolidation. Defaults to "*".' },
|
|
28
|
+
limit: { type: 'number', description: 'Max records to consider (default 200).' },
|
|
29
|
+
},
|
|
30
|
+
required: ['sessionKey', 'workspacePath'],
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
const inputSchema = z.object({
|
|
34
|
+
userId: z.string().optional(),
|
|
35
|
+
sessionKey: z.string(),
|
|
36
|
+
workspacePath: z.string(),
|
|
37
|
+
query: z.string().optional(),
|
|
38
|
+
limit: z.number().int().positive().optional(),
|
|
39
|
+
});
|
|
40
|
+
export async function handleMemoryConsolidate(args, options) {
|
|
41
|
+
const params = inputSchema.parse(args);
|
|
42
|
+
const effectiveUserId = params.userId ?? options?.defaultUserId ?? 'default';
|
|
43
|
+
const limit = params.limit ?? 200;
|
|
44
|
+
const query = params.query ?? '*';
|
|
45
|
+
try {
|
|
46
|
+
const result = await memoryEngine.recall({
|
|
47
|
+
userId: effectiveUserId,
|
|
48
|
+
sessionKey: params.sessionKey,
|
|
49
|
+
query,
|
|
50
|
+
});
|
|
51
|
+
const records = extractRecords(result ?? {});
|
|
52
|
+
if (records.length > limit)
|
|
53
|
+
records.length = limit;
|
|
54
|
+
const dir = path.join(params.workspacePath, '.brainrouter', 'memories');
|
|
55
|
+
fs.mkdirSync(path.join(dir, 'rollout_summaries'), { recursive: true });
|
|
56
|
+
const buckets = { user: [], feedback: [], project: [], reference: [], raw: [] };
|
|
57
|
+
for (const rec of records) {
|
|
58
|
+
const t = String(rec.type ?? '').toLowerCase();
|
|
59
|
+
if (t === 'user' || t === 'feedback' || t === 'project' || t === 'reference') {
|
|
60
|
+
buckets[t].push(rec);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
buckets.raw.push(rec);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const filesWritten = [];
|
|
67
|
+
for (const t of ['user', 'feedback', 'project', 'reference', 'raw']) {
|
|
68
|
+
const file = path.join(dir, t === 'raw' ? 'raw_memories.md' : `${t}.md`);
|
|
69
|
+
fs.writeFileSync(file, renderTypeFile(t, buckets[t]), 'utf8');
|
|
70
|
+
filesWritten.push(path.relative(params.workspacePath, file));
|
|
71
|
+
}
|
|
72
|
+
const indexFile = path.join(dir, 'MEMORY.md');
|
|
73
|
+
fs.writeFileSync(indexFile, renderIndex(records, buckets), 'utf8');
|
|
74
|
+
filesWritten.push(path.relative(params.workspacePath, indexFile));
|
|
75
|
+
return {
|
|
76
|
+
content: [{
|
|
77
|
+
type: 'text',
|
|
78
|
+
text: JSON.stringify({
|
|
79
|
+
totalRecords: records.length,
|
|
80
|
+
perType: Object.fromEntries(Object.entries(buckets).map(([k, v]) => [k, v.length])),
|
|
81
|
+
files: filesWritten,
|
|
82
|
+
dir: path.relative(params.workspacePath, dir),
|
|
83
|
+
}, null, 2),
|
|
84
|
+
}],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
return {
|
|
89
|
+
isError: true,
|
|
90
|
+
content: [{ type: 'text', text: `memory_consolidate failed: ${err.message}` }],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function extractRecords(parsed) {
|
|
95
|
+
if (!parsed)
|
|
96
|
+
return [];
|
|
97
|
+
const sources = [
|
|
98
|
+
parsed.records, parsed.results, parsed.items,
|
|
99
|
+
Array.isArray(parsed) ? parsed : undefined,
|
|
100
|
+
].filter((x) => Array.isArray(x));
|
|
101
|
+
for (const list of sources) {
|
|
102
|
+
const out = [];
|
|
103
|
+
for (const r of list) {
|
|
104
|
+
if (!r)
|
|
105
|
+
continue;
|
|
106
|
+
const recordId = String(r.recordId ?? r.id ?? r.record_id ?? '');
|
|
107
|
+
if (!recordId)
|
|
108
|
+
continue;
|
|
109
|
+
out.push({
|
|
110
|
+
recordId,
|
|
111
|
+
type: String(r.type ?? r.memoryType ?? 'raw'),
|
|
112
|
+
content: String(r.content ?? r.text ?? r.body ?? r.summary ?? ''),
|
|
113
|
+
scene: r.scene ?? r.focusScene,
|
|
114
|
+
capturedAt: r.capturedAt ?? r.createdAt ?? r.timestamp,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (out.length > 0)
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
function renderTypeFile(type, records) {
|
|
123
|
+
const heading = type === 'raw' ? 'Raw memories' : `${cap(type)} memory`;
|
|
124
|
+
const intro = type === 'raw'
|
|
125
|
+
? 'Memories that were not classified into user/feedback/project/reference.'
|
|
126
|
+
: descriptionFor(type);
|
|
127
|
+
if (records.length === 0) {
|
|
128
|
+
return `# ${heading}\n\n${intro}\n\n_(empty — no records of this type yet)_\n`;
|
|
129
|
+
}
|
|
130
|
+
const body = records.sort((a, b) => a.recordId.localeCompare(b.recordId)).map(renderRecord).join('\n\n');
|
|
131
|
+
return `# ${heading}\n\n${intro}\n\n${body}\n`;
|
|
132
|
+
}
|
|
133
|
+
function renderRecord(rec) {
|
|
134
|
+
const lines = [`## ${rec.recordId}`];
|
|
135
|
+
if (rec.scene)
|
|
136
|
+
lines.push(`*Scene: ${rec.scene}*`);
|
|
137
|
+
if (rec.capturedAt)
|
|
138
|
+
lines.push(`*Captured: ${rec.capturedAt}*`);
|
|
139
|
+
lines.push('', rec.content.trim());
|
|
140
|
+
return lines.join('\n');
|
|
141
|
+
}
|
|
142
|
+
function renderIndex(records, buckets) {
|
|
143
|
+
const lines = [];
|
|
144
|
+
lines.push('# Memory index');
|
|
145
|
+
lines.push('');
|
|
146
|
+
lines.push(`_${records.length} consolidated memory records across ${Object.keys(buckets).length} files._`);
|
|
147
|
+
lines.push('');
|
|
148
|
+
for (const t of ['user', 'feedback', 'project', 'reference', 'raw']) {
|
|
149
|
+
const list = buckets[t];
|
|
150
|
+
if (list.length === 0)
|
|
151
|
+
continue;
|
|
152
|
+
const file = t === 'raw' ? 'raw_memories.md' : `${t}.md`;
|
|
153
|
+
lines.push(`## ${cap(t)} (${list.length})`);
|
|
154
|
+
lines.push(`File: [${file}](${file})`);
|
|
155
|
+
lines.push('');
|
|
156
|
+
for (const r of list.slice(0, 12)) {
|
|
157
|
+
lines.push(`- \`${r.recordId}\` — ${r.content.split('\n')[0].slice(0, 140)}`);
|
|
158
|
+
}
|
|
159
|
+
if (list.length > 12)
|
|
160
|
+
lines.push(`- _…and ${list.length - 12} more in ${file}_`);
|
|
161
|
+
lines.push('');
|
|
162
|
+
}
|
|
163
|
+
return lines.join('\n');
|
|
164
|
+
}
|
|
165
|
+
function descriptionFor(type) {
|
|
166
|
+
switch (type) {
|
|
167
|
+
case 'user': return 'Profile facts about the user — role, expertise, goals.';
|
|
168
|
+
case 'feedback': return 'Validated guidance from the user about how to approach work (do/avoid).';
|
|
169
|
+
case 'project': return 'In-flight project context: deadlines, stakeholders, motivation.';
|
|
170
|
+
case 'reference': return 'Pointers to external systems (Linear, Grafana, GitHub) where authoritative info lives.';
|
|
171
|
+
default: return '';
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function cap(s) {
|
|
175
|
+
return s ? s[0].toUpperCase() + s.slice(1) : s;
|
|
176
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const memoryContradictionsToolSchema: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
userId: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
action: {
|
|
13
|
+
type: string;
|
|
14
|
+
enum: string[];
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
contradictionId: {
|
|
18
|
+
type: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
resolutionStatus: {
|
|
22
|
+
type: string;
|
|
23
|
+
enum: string[];
|
|
24
|
+
description: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
required: never[];
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export declare const memoryContradictionsSchema: z.ZodObject<{
|
|
31
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
32
|
+
action: z.ZodDefault<z.ZodEnum<["list", "resolve"]>>;
|
|
33
|
+
contradictionId: z.ZodOptional<z.ZodString>;
|
|
34
|
+
resolutionStatus: z.ZodOptional<z.ZodEnum<["resolved", "dismissed"]>>;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
action: "list" | "resolve";
|
|
37
|
+
contradictionId?: string | undefined;
|
|
38
|
+
userId?: string | undefined;
|
|
39
|
+
resolutionStatus?: "resolved" | "dismissed" | undefined;
|
|
40
|
+
}, {
|
|
41
|
+
contradictionId?: string | undefined;
|
|
42
|
+
userId?: string | undefined;
|
|
43
|
+
action?: "list" | "resolve" | undefined;
|
|
44
|
+
resolutionStatus?: "resolved" | "dismissed" | undefined;
|
|
45
|
+
}>;
|
|
46
|
+
export declare function handleMemoryContradictions(args: unknown, options?: {
|
|
47
|
+
defaultUserId?: string;
|
|
48
|
+
}): Promise<{
|
|
49
|
+
content: {
|
|
50
|
+
type: string;
|
|
51
|
+
text: string;
|
|
52
|
+
}[];
|
|
53
|
+
}>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { memoryEngine } from '../memory/engine.js';
|
|
3
|
+
export const memoryContradictionsToolSchema = {
|
|
4
|
+
name: 'memory_contradictions',
|
|
5
|
+
description: 'List unresolved semantic contradictions in memory or resolve them. Default action is "list". If action is "resolve", provide contradictionId and resolutionStatus.',
|
|
6
|
+
inputSchema: {
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: {
|
|
9
|
+
userId: { type: 'string', description: 'User identifier' },
|
|
10
|
+
action: { type: 'string', enum: ['list', 'resolve'], description: 'Action to perform. Default is list.' },
|
|
11
|
+
contradictionId: { type: 'string', description: 'ID of the contradiction to resolve (required if action is resolve)' },
|
|
12
|
+
resolutionStatus: { type: 'string', enum: ['resolved', 'dismissed'], description: 'Status to set (required if action is resolve)' },
|
|
13
|
+
},
|
|
14
|
+
required: [],
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export const memoryContradictionsSchema = z.object({
|
|
18
|
+
userId: z.string().optional(),
|
|
19
|
+
action: z.enum(['list', 'resolve']).default('list'),
|
|
20
|
+
contradictionId: z.string().optional(),
|
|
21
|
+
resolutionStatus: z.enum(['resolved', 'dismissed']).optional(),
|
|
22
|
+
});
|
|
23
|
+
export async function handleMemoryContradictions(args, options) {
|
|
24
|
+
const { userId, action, contradictionId, resolutionStatus } = memoryContradictionsSchema.parse(args);
|
|
25
|
+
const effectiveUserId = userId ?? options?.defaultUserId ?? "default";
|
|
26
|
+
if (action === 'resolve') {
|
|
27
|
+
if (!contradictionId || !resolutionStatus) {
|
|
28
|
+
throw new Error('contradictionId and resolutionStatus are required when action is "resolve"');
|
|
29
|
+
}
|
|
30
|
+
memoryEngine.resolveContradiction(contradictionId, effectiveUserId, resolutionStatus);
|
|
31
|
+
return {
|
|
32
|
+
content: [
|
|
33
|
+
{
|
|
34
|
+
type: 'text',
|
|
35
|
+
text: `Successfully marked contradiction ${contradictionId} as ${resolutionStatus}.`,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Handle 'list' action
|
|
41
|
+
const results = memoryEngine.getPendingContradictions(effectiveUserId);
|
|
42
|
+
return {
|
|
43
|
+
content: [
|
|
44
|
+
{
|
|
45
|
+
type: 'text',
|
|
46
|
+
text: results.length > 0
|
|
47
|
+
? JSON.stringify(results, null, 2)
|
|
48
|
+
: "No pending contradictions found.",
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const memoryGraphQueryToolSchema: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
userId: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
entity: {
|
|
13
|
+
type: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
skillTag: {
|
|
17
|
+
type: string;
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
maxHops: {
|
|
21
|
+
type: string;
|
|
22
|
+
description: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
required: string[];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export declare const memoryGraphQuerySchema: z.ZodObject<{
|
|
29
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
30
|
+
entity: z.ZodString;
|
|
31
|
+
skillTag: z.ZodOptional<z.ZodString>;
|
|
32
|
+
maxHops: z.ZodOptional<z.ZodNumber>;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
entity: string;
|
|
35
|
+
userId?: string | undefined;
|
|
36
|
+
skillTag?: string | undefined;
|
|
37
|
+
maxHops?: number | undefined;
|
|
38
|
+
}, {
|
|
39
|
+
entity: string;
|
|
40
|
+
userId?: string | undefined;
|
|
41
|
+
skillTag?: string | undefined;
|
|
42
|
+
maxHops?: number | undefined;
|
|
43
|
+
}>;
|
|
44
|
+
export declare function handleMemoryGraphQuery(args: unknown, options?: {
|
|
45
|
+
defaultUserId?: string;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
content: {
|
|
48
|
+
type: string;
|
|
49
|
+
text: string;
|
|
50
|
+
}[];
|
|
51
|
+
}>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { memoryEngine } from '../memory/engine.js';
|
|
3
|
+
export const memoryGraphQueryToolSchema = {
|
|
4
|
+
name: 'memory_graph_query',
|
|
5
|
+
description: 'Query the GraphRAG knowledge graph to retrieve entities and relationships within 2 hops of a starting entity, optionally filtered by active skill.',
|
|
6
|
+
inputSchema: {
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: {
|
|
9
|
+
userId: { type: 'string', description: 'User identifier for isolation' },
|
|
10
|
+
entity: { type: 'string', description: 'The starting entity to search for' },
|
|
11
|
+
skillTag: { type: 'string', description: 'Filter relationships matching this skill' },
|
|
12
|
+
maxHops: { type: 'number', description: 'Max hops to traverse (default 2)' },
|
|
13
|
+
},
|
|
14
|
+
required: ['entity'],
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export const memoryGraphQuerySchema = z.object({
|
|
18
|
+
userId: z.string().optional(),
|
|
19
|
+
entity: z.string(),
|
|
20
|
+
skillTag: z.string().optional(),
|
|
21
|
+
maxHops: z.number().optional(),
|
|
22
|
+
});
|
|
23
|
+
export async function handleMemoryGraphQuery(args, options) {
|
|
24
|
+
const params = memoryGraphQuerySchema.parse(args);
|
|
25
|
+
const effectiveUserId = params.userId ?? options?.defaultUserId ?? "default";
|
|
26
|
+
const result = memoryEngine.queryGraph(effectiveUserId, params.entity, params.skillTag, params.maxHops);
|
|
27
|
+
return {
|
|
28
|
+
content: [
|
|
29
|
+
{
|
|
30
|
+
type: 'text',
|
|
31
|
+
text: JSON.stringify(result, null, 2),
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
}
|