@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,25 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { memoryEngine } from "../../memory/engine.js";
|
|
3
|
+
import { requireAnyAuth } from "../middleware/auth.js";
|
|
4
|
+
export const graphRouter = Router();
|
|
5
|
+
graphRouter.use(requireAnyAuth);
|
|
6
|
+
graphRouter.get("/", (req, res) => {
|
|
7
|
+
const entity = typeof req.query.entity === "string" ? req.query.entity.trim() : "";
|
|
8
|
+
if (!entity) {
|
|
9
|
+
res.status(400).json({ error: "entity query param is required" });
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const hops = Number(req.query.hops ?? 2);
|
|
13
|
+
const skillTag = typeof req.query.skillTag === "string" ? req.query.skillTag : undefined;
|
|
14
|
+
const result = memoryEngine.queryGraph(req.userId, entity, skillTag, Number.isFinite(hops) ? hops : 2);
|
|
15
|
+
res.json(result);
|
|
16
|
+
});
|
|
17
|
+
graphRouter.get("/connections", (req, res) => {
|
|
18
|
+
try {
|
|
19
|
+
const result = memoryEngine.store.getAllConnections(req.userId);
|
|
20
|
+
res.json(result);
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
res.status(500).json({ error: err.message });
|
|
24
|
+
}
|
|
25
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const hooksRouter: import("express-serve-static-core").Router;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { processClaudeCodeHook } from "../../integrations/claude-code.js";
|
|
4
|
+
import { processCodexHook } from "../../integrations/codex.js";
|
|
5
|
+
import { listHostHooks, processGenericMcpHook, registerHostHook, } from "../../integrations/generic-mcp.js";
|
|
6
|
+
import { memoryEngine } from "../../memory/engine.js";
|
|
7
|
+
import { requireAnyAuth } from "../middleware/auth.js";
|
|
8
|
+
export const hooksRouter = Router();
|
|
9
|
+
hooksRouter.use(requireAnyAuth);
|
|
10
|
+
const hookSourceSchema = z.enum(["claude-code", "codex", "generic-mcp"]);
|
|
11
|
+
function scopedUserId(req, requested) {
|
|
12
|
+
const requestedUserId = typeof requested === "string" && requested.trim() ? requested.trim() : undefined;
|
|
13
|
+
if (!requestedUserId || requestedUserId === req.userId)
|
|
14
|
+
return req.userId;
|
|
15
|
+
if (req.isAdmin)
|
|
16
|
+
return requestedUserId;
|
|
17
|
+
throw new Error("Cannot register hooks for another user");
|
|
18
|
+
}
|
|
19
|
+
hooksRouter.post("/register", async (req, res) => {
|
|
20
|
+
try {
|
|
21
|
+
const params = z.object({
|
|
22
|
+
source: hookSourceSchema,
|
|
23
|
+
events: z.array(z.string()).optional(),
|
|
24
|
+
userId: z.string().optional(),
|
|
25
|
+
sessionKey: z.string().optional(),
|
|
26
|
+
sessionId: z.string().optional(),
|
|
27
|
+
workspacePath: z.string().optional(),
|
|
28
|
+
event: z.string().optional(),
|
|
29
|
+
payload: z.record(z.unknown()).optional(),
|
|
30
|
+
metadata: z.record(z.unknown()).optional(),
|
|
31
|
+
}).parse(req.body ?? {});
|
|
32
|
+
const userId = scopedUserId(req, params.userId);
|
|
33
|
+
const hook = registerHostHook({
|
|
34
|
+
userId,
|
|
35
|
+
source: params.source,
|
|
36
|
+
events: params.events,
|
|
37
|
+
sessionKey: params.sessionKey,
|
|
38
|
+
workspacePath: params.workspacePath,
|
|
39
|
+
metadata: params.metadata,
|
|
40
|
+
});
|
|
41
|
+
if (!params.event) {
|
|
42
|
+
res.status(201).json({ registered: hook });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const payload = {
|
|
46
|
+
...(params.payload ?? {}),
|
|
47
|
+
event: params.event,
|
|
48
|
+
userId,
|
|
49
|
+
sessionKey: params.sessionKey,
|
|
50
|
+
sessionId: params.sessionId,
|
|
51
|
+
workspacePath: params.workspacePath,
|
|
52
|
+
};
|
|
53
|
+
const captureResult = params.source === "claude-code"
|
|
54
|
+
? await processClaudeCodeHook(memoryEngine, payload, userId)
|
|
55
|
+
: params.source === "codex"
|
|
56
|
+
? await processCodexHook(memoryEngine, payload, userId)
|
|
57
|
+
: await processGenericMcpHook(memoryEngine, {
|
|
58
|
+
source: "generic-mcp",
|
|
59
|
+
event: params.event,
|
|
60
|
+
userId,
|
|
61
|
+
sessionKey: params.sessionKey ?? hook.sessionKey ?? "generic-mcp",
|
|
62
|
+
sessionId: params.sessionId,
|
|
63
|
+
workspacePath: params.workspacePath,
|
|
64
|
+
args: params.payload,
|
|
65
|
+
metadata: params.metadata,
|
|
66
|
+
});
|
|
67
|
+
res.status(201).json({ registered: hook, captureResult });
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
const message = error instanceof Error ? error.message : "Invalid hook registration body";
|
|
71
|
+
res.status(message.includes("another user") ? 403 : 400).json({ error: message });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
hooksRouter.get("/status", (req, res) => {
|
|
75
|
+
try {
|
|
76
|
+
const params = z.object({
|
|
77
|
+
source: hookSourceSchema.optional(),
|
|
78
|
+
userId: z.string().optional(),
|
|
79
|
+
}).parse(req.query);
|
|
80
|
+
const userId = scopedUserId(req, params.userId);
|
|
81
|
+
const hooks = listHostHooks(userId).filter((hook) => !params.source || hook.source === params.source);
|
|
82
|
+
res.json({ hooks });
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
const message = error instanceof Error ? error.message : "Invalid hook status parameters";
|
|
86
|
+
res.status(message.includes("another user") ? 403 : 400).json({ error: message });
|
|
87
|
+
}
|
|
88
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const memoriesRouter: import("express-serve-static-core").Router;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { memoryEngine } from "../../memory/engine.js";
|
|
3
|
+
import { requireAnyAuth } from "../middleware/auth.js";
|
|
4
|
+
import { decodeCursor, pageItems, PaginationQuerySchema } from "../pagination.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
export const memoriesRouter = Router();
|
|
7
|
+
memoriesRouter.use(requireAnyAuth);
|
|
8
|
+
memoriesRouter.get("/", (req, res) => {
|
|
9
|
+
try {
|
|
10
|
+
const pagination = PaginationQuerySchema.parse(req.query);
|
|
11
|
+
const archived = req.query.archived;
|
|
12
|
+
const filters = {
|
|
13
|
+
query: typeof req.query.query === "string" ? req.query.query : undefined,
|
|
14
|
+
type: typeof req.query.type === "string" ? req.query.type : undefined,
|
|
15
|
+
scene: typeof req.query.scene === "string" ? req.query.scene : undefined,
|
|
16
|
+
skill: typeof req.query.skill === "string" ? req.query.skill : undefined,
|
|
17
|
+
archived: typeof archived === "string" ? archived === "true" : undefined,
|
|
18
|
+
};
|
|
19
|
+
const memories = memoryEngine.listMemories(req.userId, filters, {
|
|
20
|
+
cursor: decodeCursor(pagination.cursor),
|
|
21
|
+
limit: pagination.limit + 1,
|
|
22
|
+
});
|
|
23
|
+
const page = pageItems(memories, pagination.limit, (memory) => ({
|
|
24
|
+
createdTime: memory.createdTime,
|
|
25
|
+
recordId: memory.recordId,
|
|
26
|
+
}));
|
|
27
|
+
res.json({ memories: page.items, nextCursor: page.nextCursor, limit: pagination.limit, hasMore: Boolean(page.nextCursor) });
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
res.status(400).json({ error: error instanceof Error ? error.message : "Invalid pagination parameters" });
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
memoriesRouter.get("/:recordId", (req, res) => {
|
|
34
|
+
const result = memoryEngine.getMemoryById(req.userId, String(req.params.recordId));
|
|
35
|
+
if (!result) {
|
|
36
|
+
res.status(404).json({ error: "Memory not found" });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
res.json(result);
|
|
40
|
+
});
|
|
41
|
+
memoriesRouter.patch("/:recordId", (req, res) => {
|
|
42
|
+
try {
|
|
43
|
+
const body = z.object({
|
|
44
|
+
content: z.string().optional(),
|
|
45
|
+
status: z.enum(["active", "superseded", "archived", "needs_verification"]).optional(),
|
|
46
|
+
confidence: z.number().min(0).max(1).optional(),
|
|
47
|
+
verificationStatus: z.enum(["", "verified", "unverified", "stale"]).optional(),
|
|
48
|
+
note: z.string().optional(),
|
|
49
|
+
}).parse(req.body ?? {});
|
|
50
|
+
if (body.content && body.content.length > 10000) {
|
|
51
|
+
res.status(400).json({ error: "Content too long" });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const result = memoryEngine.updateMemory(req.userId, String(req.params.recordId), body);
|
|
55
|
+
if (!result) {
|
|
56
|
+
res.status(404).json({ error: "Memory not found" });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
res.json(result);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
res.status(400).json({ error: error instanceof Error ? error.message : "Invalid request body" });
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
memoriesRouter.post("/:recordId/evidence", (req, res) => {
|
|
66
|
+
try {
|
|
67
|
+
const body = z.object({
|
|
68
|
+
kind: z.enum(["file", "command", "url", "test", "benchmark", "memory", "other"]),
|
|
69
|
+
ref: z.string().min(1),
|
|
70
|
+
excerpt: z.string().optional().default(""),
|
|
71
|
+
metadata: z.record(z.unknown()).optional().default({}),
|
|
72
|
+
}).parse(req.body ?? {});
|
|
73
|
+
const evidence = memoryEngine.addEvidence(req.userId, String(req.params.recordId), body);
|
|
74
|
+
res.status(201).json({ evidence });
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
res.status(400).json({ error: error instanceof Error ? error.message : "Invalid request body" });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
memoriesRouter.get("/:recordId/evidence", (req, res) => {
|
|
81
|
+
res.json({ evidence: memoryEngine.getEvidence(req.userId, String(req.params.recordId)) });
|
|
82
|
+
});
|
|
83
|
+
memoriesRouter.delete("/:id", (req, res) => {
|
|
84
|
+
const reason = typeof req.body?.reason === "string" ? req.body.reason : "";
|
|
85
|
+
if (reason) {
|
|
86
|
+
memoryEngine.governanceDelete(req.userId, String(req.params.id), reason);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
memoryEngine.deleteMemory(req.userId, String(req.params.id));
|
|
90
|
+
}
|
|
91
|
+
res.json({ success: true });
|
|
92
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const personaRouter: import("express-serve-static-core").Router;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { memoryEngine } from "../../memory/engine.js";
|
|
3
|
+
import { requireAnyAuth } from "../middleware/auth.js";
|
|
4
|
+
export const personaRouter = Router();
|
|
5
|
+
personaRouter.use(requireAnyAuth);
|
|
6
|
+
personaRouter.get("/", (req, res) => {
|
|
7
|
+
const persona = memoryEngine.getPersona(req.userId);
|
|
8
|
+
res.json({ persona });
|
|
9
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const scenesRouter: import("express-serve-static-core").Router;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { memoryEngine } from "../../memory/engine.js";
|
|
3
|
+
import { requireAnyAuth } from "../middleware/auth.js";
|
|
4
|
+
import { decodeCursor, pageItems, PaginationQuerySchema } from "../pagination.js";
|
|
5
|
+
export const scenesRouter = Router();
|
|
6
|
+
scenesRouter.use(requireAnyAuth);
|
|
7
|
+
scenesRouter.get("/", (req, res) => {
|
|
8
|
+
try {
|
|
9
|
+
const pagination = PaginationQuerySchema.parse(req.query);
|
|
10
|
+
const scenes = memoryEngine.getTopScenes(req.userId, pagination.limit + 1, decodeCursor(pagination.cursor));
|
|
11
|
+
const page = pageItems(scenes, pagination.limit, (scene) => ({
|
|
12
|
+
heatScore: scene.heatScore,
|
|
13
|
+
id: scene.id,
|
|
14
|
+
}));
|
|
15
|
+
res.json({ scenes: page.items, nextCursor: page.nextCursor, limit: pagination.limit, hasMore: Boolean(page.nextCursor) });
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
res.status(400).json({ error: error instanceof Error ? error.message : "Invalid pagination parameters" });
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
scenesRouter.delete("/:id", (req, res) => {
|
|
22
|
+
try {
|
|
23
|
+
const sceneId = req.params.id;
|
|
24
|
+
if (!sceneId) {
|
|
25
|
+
res.status(400).json({ error: "Scene ID required" });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const targetId = typeof sceneId === "string" ? sceneId : sceneId[0];
|
|
29
|
+
memoryEngine.store.deleteContextualFocus(req.userId, [targetId]);
|
|
30
|
+
res.json({ success: true });
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
res.status(500).json({ error: error instanceof Error ? error.message : "Failed to delete scene" });
|
|
34
|
+
}
|
|
35
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const skillsRouter: import("express-serve-static-core").Router;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { memoryEngine } from "../../memory/engine.js";
|
|
3
|
+
import { requireAnyAuth } from "../middleware/auth.js";
|
|
4
|
+
export const skillsRouter = Router();
|
|
5
|
+
skillsRouter.use(requireAnyAuth);
|
|
6
|
+
skillsRouter.get("/activations", (req, res) => {
|
|
7
|
+
try {
|
|
8
|
+
const activations = memoryEngine.getSkillActivations(req.userId);
|
|
9
|
+
res.json(activations);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
res.status(500).json({ error: error.message });
|
|
13
|
+
}
|
|
14
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const statsRouter: import("express-serve-static-core").Router;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { memoryEngine } from "../../memory/engine.js";
|
|
3
|
+
import { requireAnyAuth } from "../middleware/auth.js";
|
|
4
|
+
export const statsRouter = Router();
|
|
5
|
+
statsRouter.use(requireAnyAuth);
|
|
6
|
+
statsRouter.get("/", (req, res) => {
|
|
7
|
+
res.json(memoryEngine.getStats(req.userId));
|
|
8
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const usersRouter: import("express-serve-static-core").Router;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { memoryEngine } from "../../memory/engine.js";
|
|
4
|
+
import { requireJwt, requireAdmin } from "../middleware/auth.js";
|
|
5
|
+
import { decodeCursor, pageItems, PaginationQuerySchema } from "../pagination.js";
|
|
6
|
+
export const usersRouter = Router();
|
|
7
|
+
usersRouter.use(requireJwt, requireAdmin);
|
|
8
|
+
usersRouter.get("/", (req, res) => {
|
|
9
|
+
try {
|
|
10
|
+
const pagination = PaginationQuerySchema.parse(req.query);
|
|
11
|
+
const users = memoryEngine.listUsers({
|
|
12
|
+
cursor: decodeCursor(pagination.cursor),
|
|
13
|
+
limit: pagination.limit + 1,
|
|
14
|
+
}).map((u) => ({
|
|
15
|
+
userId: u.userId,
|
|
16
|
+
displayName: u.displayName,
|
|
17
|
+
email: u.email,
|
|
18
|
+
isAdmin: u.isAdmin,
|
|
19
|
+
status: u.status,
|
|
20
|
+
createdAt: u.createdAt,
|
|
21
|
+
}));
|
|
22
|
+
const page = pageItems(users, pagination.limit, (user) => ({
|
|
23
|
+
createdAt: user.createdAt,
|
|
24
|
+
userId: user.userId,
|
|
25
|
+
}));
|
|
26
|
+
res.json({ users: page.items, nextCursor: page.nextCursor, limit: pagination.limit, hasMore: Boolean(page.nextCursor) });
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
res.status(400).json({ error: error instanceof Error ? error.message : "Invalid pagination parameters" });
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
usersRouter.post("/", (req, res) => {
|
|
33
|
+
const userId = String(req.body?.userId ?? "").trim();
|
|
34
|
+
if (!userId) {
|
|
35
|
+
res.status(400).json({ error: "userId is required" });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const displayName = String(req.body?.displayName ?? "").trim();
|
|
39
|
+
const isAdmin = Boolean(req.body?.isAdmin);
|
|
40
|
+
const apiKey = `br_${randomBytes(24).toString("hex")}`;
|
|
41
|
+
try {
|
|
42
|
+
const user = memoryEngine.createUser(userId, apiKey, displayName, isAdmin);
|
|
43
|
+
res.status(201).json({ user });
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
res.status(400).json({ error: error?.message ?? "Failed to create user" });
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
usersRouter.put("/:id/status", (req, res) => {
|
|
50
|
+
const userId = String(req.params.id);
|
|
51
|
+
const status = req.body?.status === "disabled" ? "disabled" : req.body?.status === "active" ? "active" : null;
|
|
52
|
+
if (!status) {
|
|
53
|
+
res.status(400).json({ error: "status must be active or disabled" });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (userId === req.userId && status === "disabled") {
|
|
57
|
+
res.status(400).json({ error: "Cannot disable the current admin user" });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
memoryEngine.updateUserStatus(userId, status);
|
|
61
|
+
res.json({ success: true });
|
|
62
|
+
});
|
|
63
|
+
usersRouter.post("/:id/reset-key", (req, res) => {
|
|
64
|
+
const userId = String(req.params.id);
|
|
65
|
+
const user = memoryEngine.getUserById(userId);
|
|
66
|
+
if (!user) {
|
|
67
|
+
res.status(404).json({ error: "User not found" });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const apiKey = `br_${randomBytes(24).toString("hex")}`;
|
|
71
|
+
memoryEngine.updateUserApiKey(userId, apiKey);
|
|
72
|
+
res.json({ apiKey });
|
|
73
|
+
});
|
|
74
|
+
usersRouter.delete("/:id", (req, res) => {
|
|
75
|
+
const userId = String(req.params.id);
|
|
76
|
+
if (userId === req.userId) {
|
|
77
|
+
res.status(400).json({ error: "Cannot delete the current admin user" });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
memoryEngine.deleteUser(userId);
|
|
81
|
+
res.json({ success: true });
|
|
82
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const workingRouter: import("express-serve-static-core").Router;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { getWorkingContext, offloadWorkingPayload, resetWorkingMemory, listActiveSessions, } from "../../memory/working/offload.js";
|
|
4
|
+
import { requireAnyAuth } from "../middleware/auth.js";
|
|
5
|
+
export const workingRouter = Router();
|
|
6
|
+
workingRouter.use(requireAnyAuth);
|
|
7
|
+
const optionalPositiveInt = z.coerce.number().int().positive().optional();
|
|
8
|
+
const optionalNonnegativeInt = z.coerce.number().int().nonnegative().optional();
|
|
9
|
+
function scopedUserId(req, requested) {
|
|
10
|
+
const requestedUserId = typeof requested === "string" && requested.trim() ? requested.trim() : undefined;
|
|
11
|
+
if (!requestedUserId || requestedUserId === req.userId)
|
|
12
|
+
return req.userId;
|
|
13
|
+
if (req.isAdmin)
|
|
14
|
+
return requestedUserId;
|
|
15
|
+
throw new Error("Cannot access another user's working memory");
|
|
16
|
+
}
|
|
17
|
+
workingRouter.get("/context", (req, res) => {
|
|
18
|
+
try {
|
|
19
|
+
const params = z.object({
|
|
20
|
+
workspacePath: z.string().optional(),
|
|
21
|
+
userId: z.string().optional(),
|
|
22
|
+
sessionKey: z.string().min(1),
|
|
23
|
+
nodeId: z.string().optional(),
|
|
24
|
+
activeNodeId: z.string().optional(),
|
|
25
|
+
contextWindowTokens: optionalPositiveInt,
|
|
26
|
+
estimatedTokens: optionalNonnegativeInt,
|
|
27
|
+
}).parse(req.query);
|
|
28
|
+
const userId = scopedUserId(req, params.userId);
|
|
29
|
+
res.json(getWorkingContext(params.workspacePath, userId, params.sessionKey, {
|
|
30
|
+
nodeId: params.nodeId,
|
|
31
|
+
activeNodeId: params.activeNodeId,
|
|
32
|
+
contextWindowTokens: params.contextWindowTokens,
|
|
33
|
+
estimatedTokens: params.estimatedTokens,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
const message = error instanceof Error ? error.message : "Invalid working context parameters";
|
|
38
|
+
res.status(message.includes("another user") ? 403 : 400).json({ error: message });
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
workingRouter.post("/offload", (req, res) => {
|
|
42
|
+
try {
|
|
43
|
+
const params = z.object({
|
|
44
|
+
workspacePath: z.string().optional(),
|
|
45
|
+
userId: z.string().optional(),
|
|
46
|
+
sessionKey: z.string().min(1),
|
|
47
|
+
payload: z.string().min(1),
|
|
48
|
+
title: z.string().optional(),
|
|
49
|
+
summary: z.string().optional(),
|
|
50
|
+
kind: z.string().optional(),
|
|
51
|
+
contextWindowTokens: z.number().int().positive().optional(),
|
|
52
|
+
estimatedTokens: z.number().int().nonnegative().optional(),
|
|
53
|
+
forceAggressive: z.boolean().optional(),
|
|
54
|
+
}).parse(req.body ?? {});
|
|
55
|
+
const userId = scopedUserId(req, params.userId);
|
|
56
|
+
res.status(201).json(offloadWorkingPayload({ ...params, userId }));
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
const message = error instanceof Error ? error.message : "Invalid working offload body";
|
|
60
|
+
res.status(message.includes("another user") ? 403 : 400).json({ error: message });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
workingRouter.post("/reset", (req, res) => {
|
|
64
|
+
try {
|
|
65
|
+
const params = z.object({
|
|
66
|
+
workspacePath: z.string().optional(),
|
|
67
|
+
userId: z.string().optional(),
|
|
68
|
+
sessionKey: z.string().min(1),
|
|
69
|
+
}).parse(req.body ?? {});
|
|
70
|
+
const userId = scopedUserId(req, params.userId);
|
|
71
|
+
res.json(resetWorkingMemory(params.workspacePath, userId, params.sessionKey));
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
const message = error instanceof Error ? error.message : "Invalid working reset body";
|
|
75
|
+
res.status(message.includes("another user") ? 403 : 400).json({ error: message });
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
workingRouter.get("/sessions", (req, res) => {
|
|
79
|
+
try {
|
|
80
|
+
const userId = scopedUserId(req, req.query.userId);
|
|
81
|
+
const sessions = listActiveSessions(userId);
|
|
82
|
+
res.json({ sessions });
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
const message = error instanceof Error ? error.message : "Failed to list active sessions";
|
|
86
|
+
res.status(message.includes("another user") ? 403 : 400).json({ error: message });
|
|
87
|
+
}
|
|
88
|
+
});
|
package/dist/index.d.ts
ADDED