@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,441 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { SqliteMemoryStore } from "./store/sqlite.js";
|
|
3
|
+
export declare const MemoryTypeSchema: z.ZodEnum<["persona", "episodic", "instruction", "skill_context"]>;
|
|
4
|
+
export declare const L1MemoryItemSchema: z.ZodObject<{
|
|
5
|
+
content: z.ZodString;
|
|
6
|
+
type: z.ZodEnum<["persona", "episodic", "instruction", "skill_context"]>;
|
|
7
|
+
priority: z.ZodDefault<z.ZodNumber>;
|
|
8
|
+
skillTag: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
9
|
+
metadata: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
type: "persona" | "episodic" | "instruction" | "skill_context";
|
|
12
|
+
content: string;
|
|
13
|
+
skillTag: string;
|
|
14
|
+
priority: number;
|
|
15
|
+
metadata: Record<string, any>;
|
|
16
|
+
}, {
|
|
17
|
+
type: "persona" | "episodic" | "instruction" | "skill_context";
|
|
18
|
+
content: string;
|
|
19
|
+
skillTag?: string | undefined;
|
|
20
|
+
priority?: number | undefined;
|
|
21
|
+
metadata?: Record<string, any> | undefined;
|
|
22
|
+
}>;
|
|
23
|
+
export declare const L1SceneGroupSchema: z.ZodObject<{
|
|
24
|
+
sceneName: z.ZodString;
|
|
25
|
+
memories: z.ZodArray<z.ZodObject<{
|
|
26
|
+
content: z.ZodString;
|
|
27
|
+
type: z.ZodEnum<["persona", "episodic", "instruction", "skill_context"]>;
|
|
28
|
+
priority: z.ZodDefault<z.ZodNumber>;
|
|
29
|
+
skillTag: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
30
|
+
metadata: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
31
|
+
}, "strip", z.ZodTypeAny, {
|
|
32
|
+
type: "persona" | "episodic" | "instruction" | "skill_context";
|
|
33
|
+
content: string;
|
|
34
|
+
skillTag: string;
|
|
35
|
+
priority: number;
|
|
36
|
+
metadata: Record<string, any>;
|
|
37
|
+
}, {
|
|
38
|
+
type: "persona" | "episodic" | "instruction" | "skill_context";
|
|
39
|
+
content: string;
|
|
40
|
+
skillTag?: string | undefined;
|
|
41
|
+
priority?: number | undefined;
|
|
42
|
+
metadata?: Record<string, any> | undefined;
|
|
43
|
+
}>, "many">;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
sceneName: string;
|
|
46
|
+
memories: {
|
|
47
|
+
type: "persona" | "episodic" | "instruction" | "skill_context";
|
|
48
|
+
content: string;
|
|
49
|
+
skillTag: string;
|
|
50
|
+
priority: number;
|
|
51
|
+
metadata: Record<string, any>;
|
|
52
|
+
}[];
|
|
53
|
+
}, {
|
|
54
|
+
sceneName: string;
|
|
55
|
+
memories: {
|
|
56
|
+
type: "persona" | "episodic" | "instruction" | "skill_context";
|
|
57
|
+
content: string;
|
|
58
|
+
skillTag?: string | undefined;
|
|
59
|
+
priority?: number | undefined;
|
|
60
|
+
metadata?: Record<string, any> | undefined;
|
|
61
|
+
}[];
|
|
62
|
+
}>;
|
|
63
|
+
export declare const L1CommitPayloadSchema: z.ZodObject<{
|
|
64
|
+
userId: z.ZodString;
|
|
65
|
+
sessionKey: z.ZodString;
|
|
66
|
+
sessionId: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
67
|
+
sourceL0Ids: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
68
|
+
scenes: z.ZodArray<z.ZodObject<{
|
|
69
|
+
sceneName: z.ZodString;
|
|
70
|
+
memories: z.ZodArray<z.ZodObject<{
|
|
71
|
+
content: z.ZodString;
|
|
72
|
+
type: z.ZodEnum<["persona", "episodic", "instruction", "skill_context"]>;
|
|
73
|
+
priority: z.ZodDefault<z.ZodNumber>;
|
|
74
|
+
skillTag: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
75
|
+
metadata: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
76
|
+
}, "strip", z.ZodTypeAny, {
|
|
77
|
+
type: "persona" | "episodic" | "instruction" | "skill_context";
|
|
78
|
+
content: string;
|
|
79
|
+
skillTag: string;
|
|
80
|
+
priority: number;
|
|
81
|
+
metadata: Record<string, any>;
|
|
82
|
+
}, {
|
|
83
|
+
type: "persona" | "episodic" | "instruction" | "skill_context";
|
|
84
|
+
content: string;
|
|
85
|
+
skillTag?: string | undefined;
|
|
86
|
+
priority?: number | undefined;
|
|
87
|
+
metadata?: Record<string, any> | undefined;
|
|
88
|
+
}>, "many">;
|
|
89
|
+
}, "strip", z.ZodTypeAny, {
|
|
90
|
+
sceneName: string;
|
|
91
|
+
memories: {
|
|
92
|
+
type: "persona" | "episodic" | "instruction" | "skill_context";
|
|
93
|
+
content: string;
|
|
94
|
+
skillTag: string;
|
|
95
|
+
priority: number;
|
|
96
|
+
metadata: Record<string, any>;
|
|
97
|
+
}[];
|
|
98
|
+
}, {
|
|
99
|
+
sceneName: string;
|
|
100
|
+
memories: {
|
|
101
|
+
type: "persona" | "episodic" | "instruction" | "skill_context";
|
|
102
|
+
content: string;
|
|
103
|
+
skillTag?: string | undefined;
|
|
104
|
+
priority?: number | undefined;
|
|
105
|
+
metadata?: Record<string, any> | undefined;
|
|
106
|
+
}[];
|
|
107
|
+
}>, "many">;
|
|
108
|
+
}, "strip", z.ZodTypeAny, {
|
|
109
|
+
userId: string;
|
|
110
|
+
sessionKey: string;
|
|
111
|
+
sessionId: string;
|
|
112
|
+
sourceL0Ids: string[];
|
|
113
|
+
scenes: {
|
|
114
|
+
sceneName: string;
|
|
115
|
+
memories: {
|
|
116
|
+
type: "persona" | "episodic" | "instruction" | "skill_context";
|
|
117
|
+
content: string;
|
|
118
|
+
skillTag: string;
|
|
119
|
+
priority: number;
|
|
120
|
+
metadata: Record<string, any>;
|
|
121
|
+
}[];
|
|
122
|
+
}[];
|
|
123
|
+
}, {
|
|
124
|
+
userId: string;
|
|
125
|
+
sessionKey: string;
|
|
126
|
+
scenes: {
|
|
127
|
+
sceneName: string;
|
|
128
|
+
memories: {
|
|
129
|
+
type: "persona" | "episodic" | "instruction" | "skill_context";
|
|
130
|
+
content: string;
|
|
131
|
+
skillTag?: string | undefined;
|
|
132
|
+
priority?: number | undefined;
|
|
133
|
+
metadata?: Record<string, any> | undefined;
|
|
134
|
+
}[];
|
|
135
|
+
}[];
|
|
136
|
+
sessionId?: string | undefined;
|
|
137
|
+
sourceL0Ids?: string[] | undefined;
|
|
138
|
+
}>;
|
|
139
|
+
export declare const ContradictionDecisionItemSchema: z.ZodObject<{
|
|
140
|
+
newRecordId: z.ZodString;
|
|
141
|
+
existingRecordId: z.ZodString;
|
|
142
|
+
decision: z.ZodEnum<["no_conflict", "temporal_update", "genuine_conflict"]>;
|
|
143
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
144
|
+
confidence: z.ZodDefault<z.ZodNumber>;
|
|
145
|
+
}, "strip", z.ZodTypeAny, {
|
|
146
|
+
confidence: number;
|
|
147
|
+
newRecordId: string;
|
|
148
|
+
existingRecordId: string;
|
|
149
|
+
decision: "temporal_update" | "genuine_conflict" | "no_conflict";
|
|
150
|
+
reason?: string | undefined;
|
|
151
|
+
}, {
|
|
152
|
+
newRecordId: string;
|
|
153
|
+
existingRecordId: string;
|
|
154
|
+
decision: "temporal_update" | "genuine_conflict" | "no_conflict";
|
|
155
|
+
confidence?: number | undefined;
|
|
156
|
+
reason?: string | undefined;
|
|
157
|
+
}>;
|
|
158
|
+
export declare const ContradictionDecisionCommitSchema: z.ZodObject<{
|
|
159
|
+
userId: z.ZodString;
|
|
160
|
+
decisions: z.ZodArray<z.ZodObject<{
|
|
161
|
+
newRecordId: z.ZodString;
|
|
162
|
+
existingRecordId: z.ZodString;
|
|
163
|
+
decision: z.ZodEnum<["no_conflict", "temporal_update", "genuine_conflict"]>;
|
|
164
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
165
|
+
confidence: z.ZodDefault<z.ZodNumber>;
|
|
166
|
+
}, "strip", z.ZodTypeAny, {
|
|
167
|
+
confidence: number;
|
|
168
|
+
newRecordId: string;
|
|
169
|
+
existingRecordId: string;
|
|
170
|
+
decision: "temporal_update" | "genuine_conflict" | "no_conflict";
|
|
171
|
+
reason?: string | undefined;
|
|
172
|
+
}, {
|
|
173
|
+
newRecordId: string;
|
|
174
|
+
existingRecordId: string;
|
|
175
|
+
decision: "temporal_update" | "genuine_conflict" | "no_conflict";
|
|
176
|
+
confidence?: number | undefined;
|
|
177
|
+
reason?: string | undefined;
|
|
178
|
+
}>, "many">;
|
|
179
|
+
}, "strip", z.ZodTypeAny, {
|
|
180
|
+
userId: string;
|
|
181
|
+
decisions: {
|
|
182
|
+
confidence: number;
|
|
183
|
+
newRecordId: string;
|
|
184
|
+
existingRecordId: string;
|
|
185
|
+
decision: "temporal_update" | "genuine_conflict" | "no_conflict";
|
|
186
|
+
reason?: string | undefined;
|
|
187
|
+
}[];
|
|
188
|
+
}, {
|
|
189
|
+
userId: string;
|
|
190
|
+
decisions: {
|
|
191
|
+
newRecordId: string;
|
|
192
|
+
existingRecordId: string;
|
|
193
|
+
decision: "temporal_update" | "genuine_conflict" | "no_conflict";
|
|
194
|
+
confidence?: number | undefined;
|
|
195
|
+
reason?: string | undefined;
|
|
196
|
+
}[];
|
|
197
|
+
}>;
|
|
198
|
+
export declare const GraphEntityItemSchema: z.ZodObject<{
|
|
199
|
+
entity: z.ZodString;
|
|
200
|
+
type: z.ZodDefault<z.ZodString>;
|
|
201
|
+
confidence: z.ZodDefault<z.ZodNumber>;
|
|
202
|
+
skillTag: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
203
|
+
sourceRecordId: z.ZodOptional<z.ZodString>;
|
|
204
|
+
}, "strip", z.ZodTypeAny, {
|
|
205
|
+
type: string;
|
|
206
|
+
entity: string;
|
|
207
|
+
skillTag: string;
|
|
208
|
+
confidence: number;
|
|
209
|
+
sourceRecordId?: string | undefined;
|
|
210
|
+
}, {
|
|
211
|
+
entity: string;
|
|
212
|
+
type?: string | undefined;
|
|
213
|
+
skillTag?: string | undefined;
|
|
214
|
+
confidence?: number | undefined;
|
|
215
|
+
sourceRecordId?: string | undefined;
|
|
216
|
+
}>;
|
|
217
|
+
export declare const GraphRelationItemSchema: z.ZodObject<{
|
|
218
|
+
from: z.ZodString;
|
|
219
|
+
to: z.ZodString;
|
|
220
|
+
relation: z.ZodDefault<z.ZodString>;
|
|
221
|
+
confidence: z.ZodDefault<z.ZodNumber>;
|
|
222
|
+
skillTag: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
223
|
+
sourceRecordId: z.ZodOptional<z.ZodString>;
|
|
224
|
+
}, "strip", z.ZodTypeAny, {
|
|
225
|
+
skillTag: string;
|
|
226
|
+
confidence: number;
|
|
227
|
+
from: string;
|
|
228
|
+
to: string;
|
|
229
|
+
relation: string;
|
|
230
|
+
sourceRecordId?: string | undefined;
|
|
231
|
+
}, {
|
|
232
|
+
from: string;
|
|
233
|
+
to: string;
|
|
234
|
+
skillTag?: string | undefined;
|
|
235
|
+
confidence?: number | undefined;
|
|
236
|
+
sourceRecordId?: string | undefined;
|
|
237
|
+
relation?: string | undefined;
|
|
238
|
+
}>;
|
|
239
|
+
export declare const GraphCommitSchema: z.ZodObject<{
|
|
240
|
+
userId: z.ZodString;
|
|
241
|
+
sourceRecordId: z.ZodOptional<z.ZodString>;
|
|
242
|
+
entities: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
243
|
+
entity: z.ZodString;
|
|
244
|
+
type: z.ZodDefault<z.ZodString>;
|
|
245
|
+
confidence: z.ZodDefault<z.ZodNumber>;
|
|
246
|
+
skillTag: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
247
|
+
sourceRecordId: z.ZodOptional<z.ZodString>;
|
|
248
|
+
}, "strip", z.ZodTypeAny, {
|
|
249
|
+
type: string;
|
|
250
|
+
entity: string;
|
|
251
|
+
skillTag: string;
|
|
252
|
+
confidence: number;
|
|
253
|
+
sourceRecordId?: string | undefined;
|
|
254
|
+
}, {
|
|
255
|
+
entity: string;
|
|
256
|
+
type?: string | undefined;
|
|
257
|
+
skillTag?: string | undefined;
|
|
258
|
+
confidence?: number | undefined;
|
|
259
|
+
sourceRecordId?: string | undefined;
|
|
260
|
+
}>, "many">>;
|
|
261
|
+
relations: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
262
|
+
from: z.ZodString;
|
|
263
|
+
to: z.ZodString;
|
|
264
|
+
relation: z.ZodDefault<z.ZodString>;
|
|
265
|
+
confidence: z.ZodDefault<z.ZodNumber>;
|
|
266
|
+
skillTag: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
267
|
+
sourceRecordId: z.ZodOptional<z.ZodString>;
|
|
268
|
+
}, "strip", z.ZodTypeAny, {
|
|
269
|
+
skillTag: string;
|
|
270
|
+
confidence: number;
|
|
271
|
+
from: string;
|
|
272
|
+
to: string;
|
|
273
|
+
relation: string;
|
|
274
|
+
sourceRecordId?: string | undefined;
|
|
275
|
+
}, {
|
|
276
|
+
from: string;
|
|
277
|
+
to: string;
|
|
278
|
+
skillTag?: string | undefined;
|
|
279
|
+
confidence?: number | undefined;
|
|
280
|
+
sourceRecordId?: string | undefined;
|
|
281
|
+
relation?: string | undefined;
|
|
282
|
+
}>, "many">>;
|
|
283
|
+
}, "strip", z.ZodTypeAny, {
|
|
284
|
+
userId: string;
|
|
285
|
+
entities: {
|
|
286
|
+
type: string;
|
|
287
|
+
entity: string;
|
|
288
|
+
skillTag: string;
|
|
289
|
+
confidence: number;
|
|
290
|
+
sourceRecordId?: string | undefined;
|
|
291
|
+
}[];
|
|
292
|
+
relations: {
|
|
293
|
+
skillTag: string;
|
|
294
|
+
confidence: number;
|
|
295
|
+
from: string;
|
|
296
|
+
to: string;
|
|
297
|
+
relation: string;
|
|
298
|
+
sourceRecordId?: string | undefined;
|
|
299
|
+
}[];
|
|
300
|
+
sourceRecordId?: string | undefined;
|
|
301
|
+
}, {
|
|
302
|
+
userId: string;
|
|
303
|
+
sourceRecordId?: string | undefined;
|
|
304
|
+
entities?: {
|
|
305
|
+
entity: string;
|
|
306
|
+
type?: string | undefined;
|
|
307
|
+
skillTag?: string | undefined;
|
|
308
|
+
confidence?: number | undefined;
|
|
309
|
+
sourceRecordId?: string | undefined;
|
|
310
|
+
}[] | undefined;
|
|
311
|
+
relations?: {
|
|
312
|
+
from: string;
|
|
313
|
+
to: string;
|
|
314
|
+
skillTag?: string | undefined;
|
|
315
|
+
confidence?: number | undefined;
|
|
316
|
+
sourceRecordId?: string | undefined;
|
|
317
|
+
relation?: string | undefined;
|
|
318
|
+
}[] | undefined;
|
|
319
|
+
}>;
|
|
320
|
+
export declare const L2RenameItemSchema: z.ZodObject<{
|
|
321
|
+
oldName: z.ZodString;
|
|
322
|
+
newName: z.ZodString;
|
|
323
|
+
}, "strip", z.ZodTypeAny, {
|
|
324
|
+
oldName: string;
|
|
325
|
+
newName: string;
|
|
326
|
+
}, {
|
|
327
|
+
oldName: string;
|
|
328
|
+
newName: string;
|
|
329
|
+
}>;
|
|
330
|
+
export declare const L2SceneItemSchema: z.ZodObject<{
|
|
331
|
+
sceneName: z.ZodString;
|
|
332
|
+
summaryMd: z.ZodString;
|
|
333
|
+
heatScore: z.ZodOptional<z.ZodNumber>;
|
|
334
|
+
}, "strip", z.ZodTypeAny, {
|
|
335
|
+
sceneName: string;
|
|
336
|
+
summaryMd: string;
|
|
337
|
+
heatScore?: number | undefined;
|
|
338
|
+
}, {
|
|
339
|
+
sceneName: string;
|
|
340
|
+
summaryMd: string;
|
|
341
|
+
heatScore?: number | undefined;
|
|
342
|
+
}>;
|
|
343
|
+
export declare const L2MergeItemSchema: z.ZodObject<{
|
|
344
|
+
sceneIds: z.ZodArray<z.ZodString, "many">;
|
|
345
|
+
mergedSummaryMd: z.ZodString;
|
|
346
|
+
}, "strip", z.ZodTypeAny, {
|
|
347
|
+
sceneIds: string[];
|
|
348
|
+
mergedSummaryMd: string;
|
|
349
|
+
}, {
|
|
350
|
+
sceneIds: string[];
|
|
351
|
+
mergedSummaryMd: string;
|
|
352
|
+
}>;
|
|
353
|
+
export declare const L2CommitSchema: z.ZodObject<{
|
|
354
|
+
userId: z.ZodString;
|
|
355
|
+
renames: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
356
|
+
oldName: z.ZodString;
|
|
357
|
+
newName: z.ZodString;
|
|
358
|
+
}, "strip", z.ZodTypeAny, {
|
|
359
|
+
oldName: string;
|
|
360
|
+
newName: string;
|
|
361
|
+
}, {
|
|
362
|
+
oldName: string;
|
|
363
|
+
newName: string;
|
|
364
|
+
}>, "many">>>;
|
|
365
|
+
scenes: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
366
|
+
sceneName: z.ZodString;
|
|
367
|
+
summaryMd: z.ZodString;
|
|
368
|
+
heatScore: z.ZodOptional<z.ZodNumber>;
|
|
369
|
+
}, "strip", z.ZodTypeAny, {
|
|
370
|
+
sceneName: string;
|
|
371
|
+
summaryMd: string;
|
|
372
|
+
heatScore?: number | undefined;
|
|
373
|
+
}, {
|
|
374
|
+
sceneName: string;
|
|
375
|
+
summaryMd: string;
|
|
376
|
+
heatScore?: number | undefined;
|
|
377
|
+
}>, "many">>>;
|
|
378
|
+
merges: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
379
|
+
sceneIds: z.ZodArray<z.ZodString, "many">;
|
|
380
|
+
mergedSummaryMd: z.ZodString;
|
|
381
|
+
}, "strip", z.ZodTypeAny, {
|
|
382
|
+
sceneIds: string[];
|
|
383
|
+
mergedSummaryMd: string;
|
|
384
|
+
}, {
|
|
385
|
+
sceneIds: string[];
|
|
386
|
+
mergedSummaryMd: string;
|
|
387
|
+
}>, "many">>>;
|
|
388
|
+
}, "strip", z.ZodTypeAny, {
|
|
389
|
+
userId: string;
|
|
390
|
+
scenes: {
|
|
391
|
+
sceneName: string;
|
|
392
|
+
summaryMd: string;
|
|
393
|
+
heatScore?: number | undefined;
|
|
394
|
+
}[];
|
|
395
|
+
renames: {
|
|
396
|
+
oldName: string;
|
|
397
|
+
newName: string;
|
|
398
|
+
}[];
|
|
399
|
+
merges: {
|
|
400
|
+
sceneIds: string[];
|
|
401
|
+
mergedSummaryMd: string;
|
|
402
|
+
}[];
|
|
403
|
+
}, {
|
|
404
|
+
userId: string;
|
|
405
|
+
scenes?: {
|
|
406
|
+
sceneName: string;
|
|
407
|
+
summaryMd: string;
|
|
408
|
+
heatScore?: number | undefined;
|
|
409
|
+
}[] | undefined;
|
|
410
|
+
renames?: {
|
|
411
|
+
oldName: string;
|
|
412
|
+
newName: string;
|
|
413
|
+
}[] | undefined;
|
|
414
|
+
merges?: {
|
|
415
|
+
sceneIds: string[];
|
|
416
|
+
mergedSummaryMd: string;
|
|
417
|
+
}[] | undefined;
|
|
418
|
+
}>;
|
|
419
|
+
export declare const L3CommitSchema: z.ZodObject<{
|
|
420
|
+
userId: z.ZodString;
|
|
421
|
+
personaMd: z.ZodString;
|
|
422
|
+
}, "strip", z.ZodTypeAny, {
|
|
423
|
+
userId: string;
|
|
424
|
+
personaMd: string;
|
|
425
|
+
}, {
|
|
426
|
+
userId: string;
|
|
427
|
+
personaMd: string;
|
|
428
|
+
}>;
|
|
429
|
+
export declare function normalizeSceneName(name: string): string;
|
|
430
|
+
export declare function normalizeEntityName(name: string): string;
|
|
431
|
+
export declare function normalizeSkillTag(tag: string): string;
|
|
432
|
+
export declare function normalizeMemoryContent(content: string): string;
|
|
433
|
+
/**
|
|
434
|
+
* Ensures multi-tenant isolation by checking that all referenced L1 record IDs
|
|
435
|
+
* belong strictly to the provided userId. Throws an error if ownership is violated.
|
|
436
|
+
*/
|
|
437
|
+
export declare function validateL1RecordOwnership(store: SqliteMemoryStore, userId: string, recordIds: string[]): void;
|
|
438
|
+
/**
|
|
439
|
+
* Checks if a specific L0 record belongs to the user.
|
|
440
|
+
*/
|
|
441
|
+
export declare function validateL0RecordOwnership(store: SqliteMemoryStore, userId: string, recordIds: string[]): void;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// ============================
|
|
3
|
+
// Shared Zod Schemas
|
|
4
|
+
// ============================
|
|
5
|
+
export const MemoryTypeSchema = z.enum(["persona", "episodic", "instruction", "skill_context"]);
|
|
6
|
+
export const L1MemoryItemSchema = z.object({
|
|
7
|
+
content: z.string().min(1, "Memory content cannot be empty"),
|
|
8
|
+
type: MemoryTypeSchema,
|
|
9
|
+
priority: z.number().int().min(0).max(100).default(50),
|
|
10
|
+
skillTag: z.string().optional().default(""),
|
|
11
|
+
metadata: z.record(z.any()).optional().default({}),
|
|
12
|
+
});
|
|
13
|
+
export const L1SceneGroupSchema = z.object({
|
|
14
|
+
sceneName: z.string().min(1, "Scene name cannot be empty"),
|
|
15
|
+
memories: z.array(L1MemoryItemSchema).min(1, "Scene must contain at least one memory"),
|
|
16
|
+
});
|
|
17
|
+
export const L1CommitPayloadSchema = z.object({
|
|
18
|
+
userId: z.string().min(1, "userId is required"),
|
|
19
|
+
sessionKey: z.string().min(1, "sessionKey is required"),
|
|
20
|
+
sessionId: z.string().optional().default(""),
|
|
21
|
+
sourceL0Ids: z.array(z.string()).optional().default([]),
|
|
22
|
+
scenes: z.array(L1SceneGroupSchema).min(1, "At least one scene group is required"),
|
|
23
|
+
});
|
|
24
|
+
export const ContradictionDecisionItemSchema = z.object({
|
|
25
|
+
newRecordId: z.string().min(1, "newRecordId is required"),
|
|
26
|
+
existingRecordId: z.string().min(1, "existingRecordId is required"),
|
|
27
|
+
decision: z.enum(["no_conflict", "temporal_update", "genuine_conflict"]),
|
|
28
|
+
reason: z.string().optional(),
|
|
29
|
+
confidence: z.number().min(0).max(1).default(1.0),
|
|
30
|
+
});
|
|
31
|
+
export const ContradictionDecisionCommitSchema = z.object({
|
|
32
|
+
userId: z.string().min(1, "userId is required"),
|
|
33
|
+
decisions: z.array(ContradictionDecisionItemSchema).min(1, "At least one decision is required"),
|
|
34
|
+
});
|
|
35
|
+
export const GraphEntityItemSchema = z.object({
|
|
36
|
+
entity: z.string().min(1, "Entity name cannot be empty"),
|
|
37
|
+
type: z.string().default("concept"),
|
|
38
|
+
confidence: z.number().min(0).max(1).default(1.0),
|
|
39
|
+
skillTag: z.string().optional().default(""),
|
|
40
|
+
sourceRecordId: z.string().optional(),
|
|
41
|
+
});
|
|
42
|
+
export const GraphRelationItemSchema = z.object({
|
|
43
|
+
from: z.string().min(1, "from entity name is required"),
|
|
44
|
+
to: z.string().min(1, "to entity name is required"),
|
|
45
|
+
relation: z.string().default("relates_to"),
|
|
46
|
+
confidence: z.number().min(0).max(1).default(1.0),
|
|
47
|
+
skillTag: z.string().optional().default(""),
|
|
48
|
+
sourceRecordId: z.string().optional(),
|
|
49
|
+
});
|
|
50
|
+
export const GraphCommitSchema = z.object({
|
|
51
|
+
userId: z.string().min(1, "userId is required"),
|
|
52
|
+
sourceRecordId: z.string().optional(),
|
|
53
|
+
entities: z.array(GraphEntityItemSchema).default([]),
|
|
54
|
+
relations: z.array(GraphRelationItemSchema).default([]),
|
|
55
|
+
});
|
|
56
|
+
export const L2RenameItemSchema = z.object({
|
|
57
|
+
oldName: z.string().min(1),
|
|
58
|
+
newName: z.string().min(1),
|
|
59
|
+
});
|
|
60
|
+
export const L2SceneItemSchema = z.object({
|
|
61
|
+
sceneName: z.string().min(1),
|
|
62
|
+
summaryMd: z.string().min(1),
|
|
63
|
+
heatScore: z.number().min(0).max(100).optional(),
|
|
64
|
+
});
|
|
65
|
+
export const L2MergeItemSchema = z.object({
|
|
66
|
+
sceneIds: z.array(z.string()).min(2, "At least two scene IDs are required to merge"),
|
|
67
|
+
mergedSummaryMd: z.string().min(1),
|
|
68
|
+
});
|
|
69
|
+
export const L2CommitSchema = z.object({
|
|
70
|
+
userId: z.string().min(1, "userId is required"),
|
|
71
|
+
renames: z.array(L2RenameItemSchema).optional().default([]),
|
|
72
|
+
scenes: z.array(L2SceneItemSchema).optional().default([]),
|
|
73
|
+
merges: z.array(L2MergeItemSchema).optional().default([]),
|
|
74
|
+
});
|
|
75
|
+
export const L3CommitSchema = z.object({
|
|
76
|
+
userId: z.string().min(1, "userId is required"),
|
|
77
|
+
personaMd: z.string().min(1, "personaMd cannot be empty"),
|
|
78
|
+
});
|
|
79
|
+
// ============================
|
|
80
|
+
// Normalization Helpers
|
|
81
|
+
// ============================
|
|
82
|
+
export function normalizeSceneName(name) {
|
|
83
|
+
const trimmed = name.trim();
|
|
84
|
+
return trimmed === "" ? "general" : trimmed;
|
|
85
|
+
}
|
|
86
|
+
export function normalizeEntityName(name) {
|
|
87
|
+
const trimmed = name.trim();
|
|
88
|
+
return trimmed === "" ? "unknown" : trimmed;
|
|
89
|
+
}
|
|
90
|
+
export function normalizeSkillTag(tag) {
|
|
91
|
+
return tag.trim().toLowerCase();
|
|
92
|
+
}
|
|
93
|
+
export function normalizeMemoryContent(content) {
|
|
94
|
+
return content.trim();
|
|
95
|
+
}
|
|
96
|
+
// ============================
|
|
97
|
+
// Ownership & Tenant Isolation Validation
|
|
98
|
+
// ============================
|
|
99
|
+
/**
|
|
100
|
+
* Ensures multi-tenant isolation by checking that all referenced L1 record IDs
|
|
101
|
+
* belong strictly to the provided userId. Throws an error if ownership is violated.
|
|
102
|
+
*/
|
|
103
|
+
export function validateL1RecordOwnership(store, userId, recordIds) {
|
|
104
|
+
if (recordIds.length === 0)
|
|
105
|
+
return;
|
|
106
|
+
const placeholders = recordIds.map(() => "?").join(",");
|
|
107
|
+
const stmt = store.db.prepare(`SELECT record_id, user_id FROM l1_records WHERE record_id IN (${placeholders})`);
|
|
108
|
+
const rows = stmt.all(...recordIds);
|
|
109
|
+
for (const row of rows) {
|
|
110
|
+
if (row.user_id !== userId) {
|
|
111
|
+
throw new Error(`[Tenant Isolation Violation] Record ${row.record_id} is owned by user ${row.user_id}, but requested by ${userId}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Checks if a specific L0 record belongs to the user.
|
|
117
|
+
*/
|
|
118
|
+
export function validateL0RecordOwnership(store, userId, recordIds) {
|
|
119
|
+
if (recordIds.length === 0)
|
|
120
|
+
return;
|
|
121
|
+
const placeholders = recordIds.map(() => "?").join(",");
|
|
122
|
+
const stmt = store.db.prepare(`SELECT record_id, user_id FROM l0_conversations WHERE record_id IN (${placeholders})`);
|
|
123
|
+
const rows = stmt.all(...recordIds);
|
|
124
|
+
for (const row of rows) {
|
|
125
|
+
if (row.user_id !== userId) {
|
|
126
|
+
throw new Error(`[Tenant Isolation Violation] L0 Message ${row.record_id} belongs to user ${row.user_id}, but requested by ${userId}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { WorkingStep } from "./step-log.js";
|
|
2
|
+
export declare function buildWorkingCanvas(steps: WorkingStep[]): string;
|
|
3
|
+
export declare function buildAnnotatedCanvas(steps: WorkingStep[], activeNodeId?: string): string;
|
|
4
|
+
export declare function writeWorkingCanvas(workDir: string, steps: WorkingStep[]): string;
|
|
5
|
+
export declare function readWorkingCanvas(workDir: string): string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
function escapeMermaidLabel(value) {
|
|
4
|
+
return value
|
|
5
|
+
.replaceAll("\\", "\\\\")
|
|
6
|
+
.replaceAll("\"", "'")
|
|
7
|
+
.replaceAll("\n", " ")
|
|
8
|
+
.slice(0, 96);
|
|
9
|
+
}
|
|
10
|
+
export function buildWorkingCanvas(steps) {
|
|
11
|
+
return buildAnnotatedCanvas(steps);
|
|
12
|
+
}
|
|
13
|
+
export function buildAnnotatedCanvas(steps, activeNodeId) {
|
|
14
|
+
const lines = ["flowchart TD"];
|
|
15
|
+
if (steps.length === 0) {
|
|
16
|
+
lines.push(" empty[\"No working memory steps yet\"]");
|
|
17
|
+
return lines.join("\n");
|
|
18
|
+
}
|
|
19
|
+
for (const step of steps) {
|
|
20
|
+
const label = escapeMermaidLabel(`${step.title}\\n${step.summary}`);
|
|
21
|
+
const prefix = step.nodeId === activeNodeId ? "🌟 " : "";
|
|
22
|
+
lines.push(` ${step.nodeId}["${prefix}${label}"]`);
|
|
23
|
+
}
|
|
24
|
+
for (let index = 1; index < steps.length; index += 1) {
|
|
25
|
+
lines.push(` ${steps[index - 1].nodeId} --> ${steps[index].nodeId}`);
|
|
26
|
+
}
|
|
27
|
+
if (activeNodeId && steps.some((step) => step.nodeId === activeNodeId)) {
|
|
28
|
+
lines.push(` style ${activeNodeId} fill:#2b6cb0,stroke:#3182ce,stroke-width:2px,color:#fff`);
|
|
29
|
+
}
|
|
30
|
+
return lines.join("\n");
|
|
31
|
+
}
|
|
32
|
+
export function writeWorkingCanvas(workDir, steps) {
|
|
33
|
+
const canvas = buildWorkingCanvas(steps);
|
|
34
|
+
fs.mkdirSync(workDir, { recursive: true });
|
|
35
|
+
fs.writeFileSync(path.join(workDir, "canvas.mmd"), canvas, "utf8");
|
|
36
|
+
return canvas;
|
|
37
|
+
}
|
|
38
|
+
export function readWorkingCanvas(workDir) {
|
|
39
|
+
const canvasPath = path.join(workDir, "canvas.mmd");
|
|
40
|
+
if (!fs.existsSync(canvasPath))
|
|
41
|
+
return buildWorkingCanvas([]);
|
|
42
|
+
return fs.readFileSync(canvasPath, "utf8");
|
|
43
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type WorkingStep } from "./step-log.js";
|
|
2
|
+
export type TokenPressureLevel = "none" | "mild" | "aggressive";
|
|
3
|
+
export interface WorkingMemoryState {
|
|
4
|
+
sessionKey: string;
|
|
5
|
+
workDir: string;
|
|
6
|
+
pressureLevel: TokenPressureLevel;
|
|
7
|
+
contextWindowTokens: number;
|
|
8
|
+
estimatedTokens: number;
|
|
9
|
+
injectedState: {
|
|
10
|
+
currentNode?: WorkingStep;
|
|
11
|
+
recentSteps: WorkingStep[];
|
|
12
|
+
refs: Array<{
|
|
13
|
+
nodeId: string;
|
|
14
|
+
refPath?: string;
|
|
15
|
+
title: string;
|
|
16
|
+
}>;
|
|
17
|
+
rawPayloadsIncluded: false;
|
|
18
|
+
};
|
|
19
|
+
updatedAt: string;
|
|
20
|
+
}
|
|
21
|
+
export interface WorkingContextResult {
|
|
22
|
+
sessionKey: string;
|
|
23
|
+
workDir: string;
|
|
24
|
+
canvas: string;
|
|
25
|
+
annotatedCanvas?: string;
|
|
26
|
+
state: WorkingMemoryState;
|
|
27
|
+
steps: WorkingStep[];
|
|
28
|
+
ref?: {
|
|
29
|
+
nodeId: string;
|
|
30
|
+
path: string;
|
|
31
|
+
content: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export interface WorkingOffloadInput {
|
|
35
|
+
workspacePath?: string;
|
|
36
|
+
userId: string;
|
|
37
|
+
sessionKey: string;
|
|
38
|
+
payload: string;
|
|
39
|
+
title?: string;
|
|
40
|
+
summary?: string;
|
|
41
|
+
kind?: string;
|
|
42
|
+
contextWindowTokens?: number;
|
|
43
|
+
estimatedTokens?: number;
|
|
44
|
+
forceAggressive?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface WorkingOffloadResult {
|
|
47
|
+
nodeId: string;
|
|
48
|
+
refPath: string;
|
|
49
|
+
pressureLevel: TokenPressureLevel;
|
|
50
|
+
canvas: string;
|
|
51
|
+
state: WorkingMemoryState;
|
|
52
|
+
}
|
|
53
|
+
export declare function detectTokenPressure(estimatedTokens: number, contextWindowTokens: number): TokenPressureLevel;
|
|
54
|
+
export declare function getWorkingMemoryDir(workspacePath: string | undefined, userId: string, sessionKey: string): string;
|
|
55
|
+
export declare function offloadWorkingPayload(input: WorkingOffloadInput): WorkingOffloadResult;
|
|
56
|
+
export declare function getWorkingContext(workspacePath: string | undefined, userId: string, sessionKey: string, options?: {
|
|
57
|
+
nodeId?: string;
|
|
58
|
+
activeNodeId?: string;
|
|
59
|
+
contextWindowTokens?: number;
|
|
60
|
+
estimatedTokens?: number;
|
|
61
|
+
}): WorkingContextResult;
|
|
62
|
+
export declare function resetWorkingMemory(workspacePath: string | undefined, userId: string, sessionKey: string): {
|
|
63
|
+
deleted: boolean;
|
|
64
|
+
workDir: string;
|
|
65
|
+
};
|
|
66
|
+
export interface ActiveSessionInfo {
|
|
67
|
+
sessionKey: string;
|
|
68
|
+
workspaceId: string;
|
|
69
|
+
updatedAt: string;
|
|
70
|
+
}
|
|
71
|
+
export declare function listActiveSessions(userId: string): ActiveSessionInfo[];
|