nox-mem 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +179 -0
- package/dist/api/answer.d.ts +116 -0
- package/dist/api/answer.js +274 -0
- package/dist/api/answer.validate-patch.d.ts +72 -0
- package/dist/api/answer.validate-patch.js +52 -0
- package/dist/api/brief-diversity.d.ts +64 -0
- package/dist/api/brief-diversity.js +91 -0
- package/dist/api/brief.d.ts +114 -0
- package/dist/api/brief.js +524 -0
- package/dist/api/conflict.d.ts +33 -0
- package/dist/api/conflict.js +143 -0
- package/dist/api/cors.d.ts +73 -0
- package/dist/api/cors.js +124 -0
- package/dist/api/events-stream-limited.d.ts +133 -0
- package/dist/api/events-stream-limited.js +217 -0
- package/dist/api/events-stream.d.ts +53 -0
- package/dist/api/events-stream.js +125 -0
- package/dist/api/export.d.ts +42 -0
- package/dist/api/export.js +85 -0
- package/dist/api/health-confidence-adapter.d.ts +29 -0
- package/dist/api/health-confidence-adapter.js +73 -0
- package/dist/api/health-confidence.d.ts +36 -0
- package/dist/api/health-confidence.js +141 -0
- package/dist/api/hooks.d.ts +50 -0
- package/dist/api/hooks.js +115 -0
- package/dist/api/import.d.ts +38 -0
- package/dist/api/import.js +87 -0
- package/dist/api/ingest-event.d.ts +65 -0
- package/dist/api/ingest-event.js +153 -0
- package/dist/api/mark.d.ts +42 -0
- package/dist/api/mark.js +127 -0
- package/dist/api/server-deps-a2.d.ts +55 -0
- package/dist/api/server-deps-a2.js +138 -0
- package/dist/api/server-deps-l2-l3.d.ts +68 -0
- package/dist/api/server-deps-l2-l3.js +123 -0
- package/dist/api/server-deps-p1.d.ts +84 -0
- package/dist/api/server-deps-p1.js +156 -0
- package/dist/api/server-deps-p2.d.ts +32 -0
- package/dist/api/server-deps-p2.js +84 -0
- package/dist/api/server-deps-p5.d.ts +66 -0
- package/dist/api/server-deps-p5.js +139 -0
- package/dist/api/viewer-static.d.ts +30 -0
- package/dist/api/viewer-static.js +102 -0
- package/dist/api/wire-up.d.ts +54 -0
- package/dist/api/wire-up.js +521 -0
- package/dist/api-impact.d.ts +30 -0
- package/dist/api-impact.js +196 -0
- package/dist/api-server.d.ts +2 -0
- package/dist/api-server.js +614 -0
- package/dist/backfill-fts-anchor.d.ts +15 -0
- package/dist/backfill-fts-anchor.js +97 -0
- package/dist/backfill-source-type.d.ts +20 -0
- package/dist/backfill-source-type.js +182 -0
- package/dist/churn.d.ts +31 -0
- package/dist/churn.js +98 -0
- package/dist/cli/answer.d.ts +66 -0
- package/dist/cli/answer.js +287 -0
- package/dist/cli/conflict.d.ts +38 -0
- package/dist/cli/conflict.js +282 -0
- package/dist/cli/export.d.ts +51 -0
- package/dist/cli/export.js +280 -0
- package/dist/cli/hooks.d.ts +54 -0
- package/dist/cli/hooks.js +133 -0
- package/dist/cli/import.d.ts +52 -0
- package/dist/cli/import.js +274 -0
- package/dist/cli/mark.d.ts +33 -0
- package/dist/cli/mark.js +130 -0
- package/dist/cli/ocr-batch.d.ts +12 -0
- package/dist/cli/ocr-batch.js +411 -0
- package/dist/cli/snapshot-main.d.ts +30 -0
- package/dist/cli/snapshot-main.js +47 -0
- package/dist/cli/viewer.d.ts +35 -0
- package/dist/cli/viewer.js +71 -0
- package/dist/cli-telemetry.d.ts +36 -0
- package/dist/cli-telemetry.js +150 -0
- package/dist/compact.d.ts +7 -0
- package/dist/compact.js +147 -0
- package/dist/consolidate.d.ts +18 -0
- package/dist/consolidate.js +475 -0
- package/dist/consolidation.d.ts +32 -0
- package/dist/consolidation.js +212 -0
- package/dist/cross-agent-v2.d.ts +45 -0
- package/dist/cross-agent-v2.js +271 -0
- package/dist/cross-search.d.ts +11 -0
- package/dist/cross-search.js +119 -0
- package/dist/crystallize.d.ts +43 -0
- package/dist/crystallize.js +111 -0
- package/dist/db.d.ts +11 -0
- package/dist/db.js +388 -0
- package/dist/dedup.d.ts +1 -0
- package/dist/dedup.js +106 -0
- package/dist/detect-changes.d.ts +29 -0
- package/dist/detect-changes.js +236 -0
- package/dist/digest.d.ts +1 -0
- package/dist/digest.js +205 -0
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.js +71 -0
- package/dist/embed.d.ts +45 -0
- package/dist/embed.js +257 -0
- package/dist/evals.d.ts +176 -0
- package/dist/evals.js +351 -0
- package/dist/generate-user-profile.d.ts +18 -0
- package/dist/generate-user-profile.js +163 -0
- package/dist/graphify-ingest.d.ts +18 -0
- package/dist/graphify-ingest.js +158 -0
- package/dist/impact.d.ts +39 -0
- package/dist/impact.js +143 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +689 -0
- package/dist/ingest-entity.d.ts +44 -0
- package/dist/ingest-entity.js +197 -0
- package/dist/ingest.d.ts +13 -0
- package/dist/ingest.js +210 -0
- package/dist/kg-llm.d.ts +39 -0
- package/dist/kg-llm.js +295 -0
- package/dist/knowledge-graph.d.ts +72 -0
- package/dist/knowledge-graph.js +507 -0
- package/dist/lib/answer/config.d.ts +41 -0
- package/dist/lib/answer/config.js +70 -0
- package/dist/lib/answer/index.d.ts +47 -0
- package/dist/lib/answer/index.js +221 -0
- package/dist/lib/answer/prompt.d.ts +37 -0
- package/dist/lib/answer/prompt.js +88 -0
- package/dist/lib/answer/provider.d.ts +47 -0
- package/dist/lib/answer/provider.js +101 -0
- package/dist/lib/answer/retrieval.d.ts +36 -0
- package/dist/lib/answer/retrieval.js +92 -0
- package/dist/lib/answer/telemetry.d.ts +99 -0
- package/dist/lib/answer/telemetry.js +154 -0
- package/dist/lib/answer/types.d.ts +108 -0
- package/dist/lib/answer/types.js +1 -0
- package/dist/lib/api/error-leak-fix.d.ts +54 -0
- package/dist/lib/api/error-leak-fix.js +55 -0
- package/dist/lib/api/safe-error-message.d.ts +70 -0
- package/dist/lib/api/safe-error-message.js +122 -0
- package/dist/lib/archive/common-passwords.d.ts +37 -0
- package/dist/lib/archive/common-passwords.js +753 -0
- package/dist/lib/archive/encryption.d.ts +81 -0
- package/dist/lib/archive/encryption.js +236 -0
- package/dist/lib/archive/enforce-strength.d.ts +54 -0
- package/dist/lib/archive/enforce-strength.js +70 -0
- package/dist/lib/archive/entropy.d.ts +34 -0
- package/dist/lib/archive/entropy.js +180 -0
- package/dist/lib/archive/export-locking.d.ts +102 -0
- package/dist/lib/archive/export-locking.js +202 -0
- package/dist/lib/archive/format.d.ts +20 -0
- package/dist/lib/archive/format.js +174 -0
- package/dist/lib/archive/index.d.ts +23 -0
- package/dist/lib/archive/index.js +17 -0
- package/dist/lib/archive/manifest.d.ts +53 -0
- package/dist/lib/archive/manifest.js +183 -0
- package/dist/lib/archive/migration.d.ts +36 -0
- package/dist/lib/archive/migration.js +100 -0
- package/dist/lib/archive/migrations/v18_to_v19.d.ts +16 -0
- package/dist/lib/archive/migrations/v18_to_v19.js +18 -0
- package/dist/lib/archive/orchestrator.d.ts +166 -0
- package/dist/lib/archive/orchestrator.js +428 -0
- package/dist/lib/archive/serializers/chunks.d.ts +30 -0
- package/dist/lib/archive/serializers/chunks.js +113 -0
- package/dist/lib/archive/serializers/embeddings.d.ts +36 -0
- package/dist/lib/archive/serializers/embeddings.js +115 -0
- package/dist/lib/archive/serializers/kg.d.ts +28 -0
- package/dist/lib/archive/serializers/kg.js +184 -0
- package/dist/lib/archive/serializers/ops_audit.d.ts +21 -0
- package/dist/lib/archive/serializers/ops_audit.js +97 -0
- package/dist/lib/archive/server-deps.d.ts +131 -0
- package/dist/lib/archive/server-deps.js +232 -0
- package/dist/lib/archive/strength.d.ts +50 -0
- package/dist/lib/archive/strength.js +77 -0
- package/dist/lib/archive/types.d.ts +159 -0
- package/dist/lib/archive/types.js +45 -0
- package/dist/lib/archive/unpack-streaming.d.ts +70 -0
- package/dist/lib/archive/unpack-streaming.js +255 -0
- package/dist/lib/auth/localhost-guard.d.ts +106 -0
- package/dist/lib/auth/localhost-guard.js +164 -0
- package/dist/lib/confidence/config.d.ts +37 -0
- package/dist/lib/confidence/config.js +107 -0
- package/dist/lib/confidence/db-shim-singleton.d.ts +20 -0
- package/dist/lib/confidence/db-shim-singleton.js +41 -0
- package/dist/lib/confidence/db-shim.d.ts +47 -0
- package/dist/lib/confidence/db-shim.js +141 -0
- package/dist/lib/confidence/mark.d.ts +58 -0
- package/dist/lib/confidence/mark.js +168 -0
- package/dist/lib/confidence/ranking.d.ts +69 -0
- package/dist/lib/confidence/ranking.js +101 -0
- package/dist/lib/confidence/search-filter.d.ts +44 -0
- package/dist/lib/confidence/search-filter.js +103 -0
- package/dist/lib/confidence/types.d.ts +146 -0
- package/dist/lib/confidence/types.js +20 -0
- package/dist/lib/confidence/write-hooks.d.ts +50 -0
- package/dist/lib/confidence/write-hooks.js +159 -0
- package/dist/lib/conflict/audit-fk-check.d.ts +72 -0
- package/dist/lib/conflict/audit-fk-check.js +131 -0
- package/dist/lib/conflict/audit-writer.d.ts +39 -0
- package/dist/lib/conflict/audit-writer.js +133 -0
- package/dist/lib/conflict/db-singleton.d.ts +28 -0
- package/dist/lib/conflict/db-singleton.js +61 -0
- package/dist/lib/conflict/db.d.ts +27 -0
- package/dist/lib/conflict/db.js +20 -0
- package/dist/lib/conflict/detector-direct.d.ts +21 -0
- package/dist/lib/conflict/detector-direct.js +105 -0
- package/dist/lib/conflict/evidence.d.ts +24 -0
- package/dist/lib/conflict/evidence.js +76 -0
- package/dist/lib/conflict/index.d.ts +14 -0
- package/dist/lib/conflict/index.js +12 -0
- package/dist/lib/conflict/scheduler.d.ts +78 -0
- package/dist/lib/conflict/scheduler.js +111 -0
- package/dist/lib/conflict/shadow.d.ts +75 -0
- package/dist/lib/conflict/shadow.js +161 -0
- package/dist/lib/conflict/types.d.ts +133 -0
- package/dist/lib/conflict/types.js +19 -0
- package/dist/lib/cost-cap.d.ts +94 -0
- package/dist/lib/cost-cap.js +129 -0
- package/dist/lib/deps/deps-registry.d.ts +111 -0
- package/dist/lib/deps/deps-registry.js +209 -0
- package/dist/lib/error-sanitizer/middleware.d.ts +43 -0
- package/dist/lib/error-sanitizer/middleware.js +100 -0
- package/dist/lib/error-sanitizer/sanitize.d.ts +78 -0
- package/dist/lib/error-sanitizer/sanitize.js +202 -0
- package/dist/lib/eval-batch.d.ts +34 -0
- package/dist/lib/eval-batch.js +103 -0
- package/dist/lib/eval-metrics.d.ts +36 -0
- package/dist/lib/eval-metrics.js +95 -0
- package/dist/lib/eval.d.ts +106 -0
- package/dist/lib/eval.js +343 -0
- package/dist/lib/events/bus.d.ts +135 -0
- package/dist/lib/events/bus.js +95 -0
- package/dist/lib/fts-anchor.d.ts +1 -0
- package/dist/lib/fts-anchor.js +131 -0
- package/dist/lib/hooks/classifier.d.ts +47 -0
- package/dist/lib/hooks/classifier.js +129 -0
- package/dist/lib/hooks/config.d.ts +49 -0
- package/dist/lib/hooks/config.js +106 -0
- package/dist/lib/hooks/decorators.d.ts +35 -0
- package/dist/lib/hooks/decorators.js +59 -0
- package/dist/lib/hooks/pipeline.d.ts +76 -0
- package/dist/lib/hooks/pipeline.js +213 -0
- package/dist/lib/hooks/privacy-filter-adapter.d.ts +55 -0
- package/dist/lib/hooks/privacy-filter-adapter.js +84 -0
- package/dist/lib/hooks/rate-limit-constant-time.d.ts +57 -0
- package/dist/lib/hooks/rate-limit-constant-time.js +69 -0
- package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +71 -0
- package/dist/lib/hooks/rate-limit-dryrun-fix.js +110 -0
- package/dist/lib/hooks/rate-limit.d.ts +54 -0
- package/dist/lib/hooks/rate-limit.js +122 -0
- package/dist/lib/hooks/server-deps.d.ts +61 -0
- package/dist/lib/hooks/server-deps.js +92 -0
- package/dist/lib/hooks/source-allowlist.d.ts +26 -0
- package/dist/lib/hooks/source-allowlist.js +53 -0
- package/dist/lib/hooks/types.d.ts +129 -0
- package/dist/lib/hooks/types.js +24 -0
- package/dist/lib/hooks/worker.d.ts +56 -0
- package/dist/lib/hooks/worker.js +150 -0
- package/dist/lib/ingest-router.d.ts +25 -0
- package/dist/lib/ingest-router.js +103 -0
- package/dist/lib/ocr-detector.d.ts +61 -0
- package/dist/lib/ocr-detector.js +138 -0
- package/dist/lib/ocr-engine-stub.d.ts +48 -0
- package/dist/lib/ocr-engine-stub.js +190 -0
- package/dist/lib/ocr-engines/google-doc-ai.d.ts +36 -0
- package/dist/lib/ocr-engines/google-doc-ai.js +164 -0
- package/dist/lib/ocr-jobs.d.ts +67 -0
- package/dist/lib/ocr-jobs.js +129 -0
- package/dist/lib/op-audit-extension/ran-at-guard.d.ts +86 -0
- package/dist/lib/op-audit-extension/ran-at-guard.js +110 -0
- package/dist/lib/op-audit.d.ts +71 -0
- package/dist/lib/op-audit.js +777 -0
- package/dist/lib/privacy-br/detector.d.ts +42 -0
- package/dist/lib/privacy-br/detector.js +130 -0
- package/dist/lib/privacy-br/index.d.ts +20 -0
- package/dist/lib/privacy-br/index.js +20 -0
- package/dist/lib/privacy-br/integration.d.ts +71 -0
- package/dist/lib/privacy-br/integration.js +74 -0
- package/dist/lib/privacy-br/patterns.d.ts +117 -0
- package/dist/lib/privacy-br/patterns.js +434 -0
- package/dist/lib/privacy-br/redact.d.ts +42 -0
- package/dist/lib/privacy-br/redact.js +103 -0
- package/dist/lib/privacy-br/types.d.ts +55 -0
- package/dist/lib/privacy-br/types.js +25 -0
- package/dist/lib/regex-extract/extractor.d.ts +30 -0
- package/dist/lib/regex-extract/extractor.js +91 -0
- package/dist/lib/regex-extract/frontmatter.d.ts +44 -0
- package/dist/lib/regex-extract/frontmatter.js +169 -0
- package/dist/lib/regex-extract/index.d.ts +14 -0
- package/dist/lib/regex-extract/index.js +14 -0
- package/dist/lib/regex-extract/ingest-router-l4.d.ts +76 -0
- package/dist/lib/regex-extract/ingest-router-l4.js +102 -0
- package/dist/lib/regex-extract/patterns.d.ts +61 -0
- package/dist/lib/regex-extract/patterns.js +91 -0
- package/dist/lib/regex-extract/production-wire.d.ts +128 -0
- package/dist/lib/regex-extract/production-wire.js +202 -0
- package/dist/lib/regex-extract/reconcile.d.ts +162 -0
- package/dist/lib/regex-extract/reconcile.js +210 -0
- package/dist/lib/regex-extract/strip-code.d.ts +24 -0
- package/dist/lib/regex-extract/strip-code.js +52 -0
- package/dist/lib/regex-extract/types.d.ts +48 -0
- package/dist/lib/regex-extract/types.js +25 -0
- package/dist/lib/reranker.d.ts +80 -0
- package/dist/lib/reranker.js +324 -0
- package/dist/lib/shadow-tracker.d.ts +191 -0
- package/dist/lib/shadow-tracker.js +384 -0
- package/dist/lib/spo-injection.d.ts +52 -0
- package/dist/lib/spo-injection.js +166 -0
- package/dist/lib/telemetry-collector.d.ts +158 -0
- package/dist/lib/telemetry-collector.js +249 -0
- package/dist/lib/temporal-detector.d.ts +27 -0
- package/dist/lib/temporal-detector.js +81 -0
- package/dist/lib/viewer/auth.d.ts +37 -0
- package/dist/lib/viewer/auth.js +70 -0
- package/dist/lib/viewer/backpressure.d.ts +59 -0
- package/dist/lib/viewer/backpressure.js +100 -0
- package/dist/lib/viewer/broadcast-singleton.d.ts +34 -0
- package/dist/lib/viewer/broadcast-singleton.js +49 -0
- package/dist/lib/viewer/broadcast.d.ts +66 -0
- package/dist/lib/viewer/broadcast.js +96 -0
- package/dist/lib/viewer/event-types.d.ts +132 -0
- package/dist/lib/viewer/event-types.js +74 -0
- package/dist/lib/viewer/instrumentation.d.ts +106 -0
- package/dist/lib/viewer/instrumentation.js +224 -0
- package/dist/lib/viewer/migration.d.ts +23 -0
- package/dist/lib/viewer/migration.js +56 -0
- package/dist/lib/viewer/redaction.d.ts +44 -0
- package/dist/lib/viewer/redaction.js +139 -0
- package/dist/lib/viewer/session.d.ts +51 -0
- package/dist/lib/viewer/session.js +87 -0
- package/dist/mcp/tools/answer.d.ts +94 -0
- package/dist/mcp/tools/answer.js +213 -0
- package/dist/mcp/tools/archive.d.ts +152 -0
- package/dist/mcp/tools/archive.js +170 -0
- package/dist/mcp/tools/conflict.d.ts +44 -0
- package/dist/mcp/tools/conflict.js +130 -0
- package/dist/mcp/tools/hooks.d.ts +29 -0
- package/dist/mcp/tools/hooks.js +78 -0
- package/dist/mcp/tools/mark.d.ts +38 -0
- package/dist/mcp/tools/mark.js +82 -0
- package/dist/mcp/tools/viewer.d.ts +58 -0
- package/dist/mcp/tools/viewer.js +64 -0
- package/dist/mcp-server.d.ts +2 -0
- package/dist/mcp-server.js +395 -0
- package/dist/metrics.d.ts +3 -0
- package/dist/metrics.js +59 -0
- package/dist/noise-filter.d.ts +18 -0
- package/dist/noise-filter.js +142 -0
- package/dist/notion-sync.d.ts +7 -0
- package/dist/notion-sync.js +97 -0
- package/dist/observability/adapters/a3-adapter.d.ts +63 -0
- package/dist/observability/adapters/a3-adapter.js +83 -0
- package/dist/observability/adapters/p1-adapter.d.ts +49 -0
- package/dist/observability/adapters/p1-adapter.js +63 -0
- package/dist/observability/adapters/p5-adapter.d.ts +36 -0
- package/dist/observability/adapters/p5-adapter.js +71 -0
- package/dist/observability/cardinality.d.ts +61 -0
- package/dist/observability/cardinality.js +300 -0
- package/dist/observability/collectors/db-stats.collector.d.ts +9 -0
- package/dist/observability/collectors/db-stats.collector.js +88 -0
- package/dist/observability/collectors/eventbus.collector.d.ts +6 -0
- package/dist/observability/collectors/eventbus.collector.js +50 -0
- package/dist/observability/collectors/process.collector.d.ts +7 -0
- package/dist/observability/collectors/process.collector.js +93 -0
- package/dist/observability/collectors/provider-telemetry.collector.d.ts +11 -0
- package/dist/observability/collectors/provider-telemetry.collector.js +112 -0
- package/dist/observability/collectors/search-telemetry.collector.d.ts +12 -0
- package/dist/observability/collectors/search-telemetry.collector.js +76 -0
- package/dist/observability/exporter.d.ts +30 -0
- package/dist/observability/exporter.js +182 -0
- package/dist/observability/index.d.ts +22 -0
- package/dist/observability/index.js +21 -0
- package/dist/observability/metrics.d.ts +53 -0
- package/dist/observability/metrics.js +213 -0
- package/dist/observability/privacy-guard.d.ts +32 -0
- package/dist/observability/privacy-guard.js +116 -0
- package/dist/observability/record.d.ts +83 -0
- package/dist/observability/record.js +217 -0
- package/dist/observability/registry.d.ts +60 -0
- package/dist/observability/registry.js +93 -0
- package/dist/observability/types.d.ts +115 -0
- package/dist/observability/types.js +235 -0
- package/dist/observability.d.ts +131 -0
- package/dist/observability.js +234 -0
- package/dist/plugins/nox-hooks/index.d.ts +61 -0
- package/dist/plugins/nox-hooks/index.js +99 -0
- package/dist/primer.d.ts +1 -0
- package/dist/primer.js +100 -0
- package/dist/privacy/filter.d.ts +27 -0
- package/dist/privacy/filter.js +74 -0
- package/dist/privacy/patterns.d.ts +29 -0
- package/dist/privacy/patterns.js +178 -0
- package/dist/privacy/tag-parser.d.ts +24 -0
- package/dist/privacy/tag-parser.js +29 -0
- package/dist/project-context-gen.d.ts +10 -0
- package/dist/project-context-gen.js +106 -0
- package/dist/providers/embedding/gemini.d.ts +73 -0
- package/dist/providers/embedding/gemini.js +118 -0
- package/dist/providers/embedding/openai.d.ts +76 -0
- package/dist/providers/embedding/openai.js +123 -0
- package/dist/providers/embedding/types.d.ts +39 -0
- package/dist/providers/embedding/types.js +1 -0
- package/dist/providers/embedding/voyage.d.ts +36 -0
- package/dist/providers/embedding/voyage.js +29 -0
- package/dist/providers/index.d.ts +116 -0
- package/dist/providers/index.js +158 -0
- package/dist/providers/llm/anthropic.d.ts +29 -0
- package/dist/providers/llm/anthropic.js +28 -0
- package/dist/providers/llm/chain.d.ts +99 -0
- package/dist/providers/llm/chain.js +213 -0
- package/dist/providers/llm/gemini.d.ts +48 -0
- package/dist/providers/llm/gemini.js +96 -0
- package/dist/providers/llm/openai.d.ts +64 -0
- package/dist/providers/llm/openai.js +109 -0
- package/dist/providers/llm/types.d.ts +47 -0
- package/dist/providers/llm/types.js +1 -0
- package/dist/providers/telemetry.d.ts +87 -0
- package/dist/providers/telemetry.js +156 -0
- package/dist/providers/types.d.ts +42 -0
- package/dist/providers/types.js +59 -0
- package/dist/query-entity-count.d.ts +54 -0
- package/dist/query-entity-count.js +171 -0
- package/dist/reflect.d.ts +26 -0
- package/dist/reflect.js +290 -0
- package/dist/reindex-errors.d.ts +7 -0
- package/dist/reindex-errors.js +21 -0
- package/dist/reindex.d.ts +16 -0
- package/dist/reindex.js +293 -0
- package/dist/retention.d.ts +40 -0
- package/dist/retention.js +86 -0
- package/dist/salience.d.ts +85 -0
- package/dist/salience.js +245 -0
- package/dist/scripts/migrate-v17-ops-audit.d.ts +17 -0
- package/dist/scripts/migrate-v17-ops-audit.js +70 -0
- package/dist/search-dedup.d.ts +44 -0
- package/dist/search-dedup.js +137 -0
- package/dist/search-expansion.d.ts +20 -0
- package/dist/search-expansion.js +99 -0
- package/dist/search.d.ts +62 -0
- package/dist/search.js +582 -0
- package/dist/seh-detector.d.ts +31 -0
- package/dist/seh-detector.js +201 -0
- package/dist/self-improve.d.ts +1 -0
- package/dist/self-improve.js +189 -0
- package/dist/session-distill.d.ts +29 -0
- package/dist/session-distill.js +325 -0
- package/dist/session-update.d.ts +1 -0
- package/dist/session-update.js +54 -0
- package/dist/shared-memory.d.ts +24 -0
- package/dist/shared-memory.js +104 -0
- package/dist/stats.d.ts +1 -0
- package/dist/stats.js +44 -0
- package/dist/temporal-retrieval.d.ts +132 -0
- package/dist/temporal-retrieval.js +495 -0
- package/dist/tier-manager.d.ts +69 -0
- package/dist/tier-manager.js +225 -0
- package/dist/vectorize.d.ts +16 -0
- package/dist/vectorize.js +91 -0
- package/dist/watch.d.ts +8 -0
- package/dist/watch.js +124 -0
- package/package.json +74 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/mcp/tools/answer.ts — P1 T10: `nox_mem_answer` MCP tool.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the HTTP shape (kickoff §5/§6). Single code path: under the hood
|
|
5
|
+
* we call the same `answer()` library function used by CLI/HTTP. The only
|
|
6
|
+
* difference is the MCP `content` envelope expected by the protocol.
|
|
7
|
+
*
|
|
8
|
+
* MCP tool contract (CallToolResult):
|
|
9
|
+
* {
|
|
10
|
+
* content: [{ type: "text", text: "<JSON or human-readable>" }],
|
|
11
|
+
* isError?: boolean
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* We always emit a JSON payload in `content[0].text` so the consumer (LLM
|
|
15
|
+
* agent / Claude desktop) can JSON.parse it deterministically. We also set
|
|
16
|
+
* `isError: true` on hard failures (hallucination_after_retry, llm_error).
|
|
17
|
+
*
|
|
18
|
+
* Registration: production `src/mcp/tools/index.ts` imports
|
|
19
|
+
* `noxMemAnswerTool` and pushes into its tool registry. Shape is intentionally
|
|
20
|
+
* MCP-SDK-agnostic — same factory works with `@modelcontextprotocol/sdk` v0.x
|
|
21
|
+
* or the in-tree minimal MCP runner used by VPS.
|
|
22
|
+
*/
|
|
23
|
+
import type { AnswerOpts, AnswerResult } from "../../lib/answer/index.js";
|
|
24
|
+
import { type TelemetryStore } from "../../lib/answer/telemetry.js";
|
|
25
|
+
export interface McpToolDefinition {
|
|
26
|
+
name: string;
|
|
27
|
+
description: string;
|
|
28
|
+
inputSchema: Record<string, unknown>;
|
|
29
|
+
handler: (input: unknown, ctx?: McpCallContext) => Promise<McpCallResult>;
|
|
30
|
+
}
|
|
31
|
+
export interface McpCallContext {
|
|
32
|
+
sessionId?: string | null;
|
|
33
|
+
telemetryStore?: TelemetryStore;
|
|
34
|
+
/** Test seam: replace answer() under test. */
|
|
35
|
+
answer?: (opts: AnswerOpts) => Promise<AnswerResult>;
|
|
36
|
+
}
|
|
37
|
+
export interface McpCallResult {
|
|
38
|
+
content: Array<{
|
|
39
|
+
type: "text";
|
|
40
|
+
text: string;
|
|
41
|
+
}>;
|
|
42
|
+
isError?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export declare const INPUT_SCHEMA: {
|
|
45
|
+
readonly type: "object";
|
|
46
|
+
readonly properties: {
|
|
47
|
+
readonly question: {
|
|
48
|
+
readonly type: "string";
|
|
49
|
+
readonly minLength: 1;
|
|
50
|
+
readonly maxLength: 2000;
|
|
51
|
+
};
|
|
52
|
+
readonly top_k: {
|
|
53
|
+
readonly type: "integer";
|
|
54
|
+
readonly minimum: 1;
|
|
55
|
+
readonly maximum: 20;
|
|
56
|
+
readonly default: 8;
|
|
57
|
+
};
|
|
58
|
+
readonly max_tokens: {
|
|
59
|
+
readonly type: "integer";
|
|
60
|
+
readonly minimum: 64;
|
|
61
|
+
readonly maximum: 8192;
|
|
62
|
+
readonly default: 1500;
|
|
63
|
+
};
|
|
64
|
+
readonly provider: {
|
|
65
|
+
readonly type: "string";
|
|
66
|
+
};
|
|
67
|
+
readonly model: {
|
|
68
|
+
readonly type: "string";
|
|
69
|
+
};
|
|
70
|
+
readonly temperature: {
|
|
71
|
+
readonly type: "number";
|
|
72
|
+
readonly minimum: 0;
|
|
73
|
+
readonly maximum: 1;
|
|
74
|
+
};
|
|
75
|
+
readonly no_citations: {
|
|
76
|
+
readonly type: "boolean";
|
|
77
|
+
readonly default: false;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
readonly required: readonly ["question"];
|
|
81
|
+
readonly additionalProperties: false;
|
|
82
|
+
};
|
|
83
|
+
interface ParsedInput {
|
|
84
|
+
question: string;
|
|
85
|
+
topK?: number;
|
|
86
|
+
maxTokens?: number;
|
|
87
|
+
provider?: string;
|
|
88
|
+
model?: string;
|
|
89
|
+
temperature?: number;
|
|
90
|
+
noCitations: boolean;
|
|
91
|
+
}
|
|
92
|
+
export declare function parseInput(input: unknown): ParsedInput;
|
|
93
|
+
export declare const noxMemAnswerTool: McpToolDefinition;
|
|
94
|
+
export default noxMemAnswerTool;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/mcp/tools/answer.ts — P1 T10: `nox_mem_answer` MCP tool.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the HTTP shape (kickoff §5/§6). Single code path: under the hood
|
|
5
|
+
* we call the same `answer()` library function used by CLI/HTTP. The only
|
|
6
|
+
* difference is the MCP `content` envelope expected by the protocol.
|
|
7
|
+
*
|
|
8
|
+
* MCP tool contract (CallToolResult):
|
|
9
|
+
* {
|
|
10
|
+
* content: [{ type: "text", text: "<JSON or human-readable>" }],
|
|
11
|
+
* isError?: boolean
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* We always emit a JSON payload in `content[0].text` so the consumer (LLM
|
|
15
|
+
* agent / Claude desktop) can JSON.parse it deterministically. We also set
|
|
16
|
+
* `isError: true` on hard failures (hallucination_after_retry, llm_error).
|
|
17
|
+
*
|
|
18
|
+
* Registration: production `src/mcp/tools/index.ts` imports
|
|
19
|
+
* `noxMemAnswerTool` and pushes into its tool registry. Shape is intentionally
|
|
20
|
+
* MCP-SDK-agnostic — same factory works with `@modelcontextprotocol/sdk` v0.x
|
|
21
|
+
* or the in-tree minimal MCP runner used by VPS.
|
|
22
|
+
*/
|
|
23
|
+
import { answer as defaultAnswer, AnswerError } from "../../lib/answer/index.js";
|
|
24
|
+
import { recordAnswer, } from "../../lib/answer/telemetry.js";
|
|
25
|
+
// ─── Input schema ─────────────────────────────────────────────────────────
|
|
26
|
+
export const INPUT_SCHEMA = {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
question: { type: "string", minLength: 1, maxLength: 2000 },
|
|
30
|
+
top_k: { type: "integer", minimum: 1, maximum: 20, default: 8 },
|
|
31
|
+
max_tokens: { type: "integer", minimum: 64, maximum: 8192, default: 1500 },
|
|
32
|
+
provider: { type: "string" },
|
|
33
|
+
model: { type: "string" },
|
|
34
|
+
temperature: { type: "number", minimum: 0, maximum: 1 },
|
|
35
|
+
no_citations: { type: "boolean", default: false },
|
|
36
|
+
},
|
|
37
|
+
required: ["question"],
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
};
|
|
40
|
+
class McpInputError extends Error {
|
|
41
|
+
}
|
|
42
|
+
export function parseInput(input) {
|
|
43
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
44
|
+
throw new McpInputError("input must be an object");
|
|
45
|
+
}
|
|
46
|
+
const o = input;
|
|
47
|
+
if (typeof o.question !== "string" || o.question.trim().length === 0) {
|
|
48
|
+
throw new McpInputError("question is required (non-empty string)");
|
|
49
|
+
}
|
|
50
|
+
if (o.question.length > 2000) {
|
|
51
|
+
throw new McpInputError("question exceeds 2000 chars");
|
|
52
|
+
}
|
|
53
|
+
const parsed = {
|
|
54
|
+
question: o.question,
|
|
55
|
+
noCitations: false,
|
|
56
|
+
};
|
|
57
|
+
if (o.top_k !== undefined) {
|
|
58
|
+
if (typeof o.top_k !== "number" || !Number.isFinite(o.top_k)) {
|
|
59
|
+
throw new McpInputError("top_k must be a number");
|
|
60
|
+
}
|
|
61
|
+
parsed.topK = o.top_k;
|
|
62
|
+
}
|
|
63
|
+
if (o.max_tokens !== undefined) {
|
|
64
|
+
if (typeof o.max_tokens !== "number" || !Number.isFinite(o.max_tokens)) {
|
|
65
|
+
throw new McpInputError("max_tokens must be a number");
|
|
66
|
+
}
|
|
67
|
+
parsed.maxTokens = o.max_tokens;
|
|
68
|
+
}
|
|
69
|
+
if (o.temperature !== undefined) {
|
|
70
|
+
if (typeof o.temperature !== "number" || !Number.isFinite(o.temperature)) {
|
|
71
|
+
throw new McpInputError("temperature must be a number");
|
|
72
|
+
}
|
|
73
|
+
parsed.temperature = o.temperature;
|
|
74
|
+
}
|
|
75
|
+
if (o.provider !== undefined) {
|
|
76
|
+
if (typeof o.provider !== "string") {
|
|
77
|
+
throw new McpInputError("provider must be a string");
|
|
78
|
+
}
|
|
79
|
+
parsed.provider = o.provider;
|
|
80
|
+
}
|
|
81
|
+
if (o.model !== undefined) {
|
|
82
|
+
if (typeof o.model !== "string") {
|
|
83
|
+
throw new McpInputError("model must be a string");
|
|
84
|
+
}
|
|
85
|
+
parsed.model = o.model;
|
|
86
|
+
}
|
|
87
|
+
if (o.no_citations !== undefined) {
|
|
88
|
+
if (typeof o.no_citations !== "boolean") {
|
|
89
|
+
throw new McpInputError("no_citations must be a boolean");
|
|
90
|
+
}
|
|
91
|
+
parsed.noCitations = o.no_citations;
|
|
92
|
+
}
|
|
93
|
+
return parsed;
|
|
94
|
+
}
|
|
95
|
+
// ─── Handler factory ──────────────────────────────────────────────────────
|
|
96
|
+
const MARKER_RE = /\s?\[chunk_\d+\]/g;
|
|
97
|
+
export const noxMemAnswerTool = {
|
|
98
|
+
name: "nox_mem_answer",
|
|
99
|
+
description: "Answer a question using the nox-mem corpus with grounded citations [chunk_N]. " +
|
|
100
|
+
"Anti-hallucination guard built-in (retry-once on cited markers not in the retrieval set). " +
|
|
101
|
+
"Returns JSON: { answer, citations[], metadata } in content[0].text.",
|
|
102
|
+
inputSchema: INPUT_SCHEMA,
|
|
103
|
+
async handler(input, ctx) {
|
|
104
|
+
let parsed;
|
|
105
|
+
try {
|
|
106
|
+
parsed = parseInput(input);
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
return {
|
|
110
|
+
content: [
|
|
111
|
+
{
|
|
112
|
+
type: "text",
|
|
113
|
+
text: JSON.stringify({
|
|
114
|
+
error: true,
|
|
115
|
+
reason: "invalid_input",
|
|
116
|
+
message: err.message,
|
|
117
|
+
}),
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
isError: true,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const opts = { question: parsed.question };
|
|
124
|
+
if (parsed.topK !== undefined)
|
|
125
|
+
opts.topK = parsed.topK;
|
|
126
|
+
if (parsed.maxTokens !== undefined)
|
|
127
|
+
opts.maxTokens = parsed.maxTokens;
|
|
128
|
+
if (parsed.provider !== undefined)
|
|
129
|
+
opts.provider = parsed.provider;
|
|
130
|
+
if (parsed.model !== undefined)
|
|
131
|
+
opts.model = parsed.model;
|
|
132
|
+
if (parsed.temperature !== undefined)
|
|
133
|
+
opts.temperature = parsed.temperature;
|
|
134
|
+
const run = ctx?.answer ?? defaultAnswer;
|
|
135
|
+
try {
|
|
136
|
+
const res = await run(opts);
|
|
137
|
+
if (ctx?.telemetryStore) {
|
|
138
|
+
recordAnswer(ctx.telemetryStore, {
|
|
139
|
+
question: parsed.question,
|
|
140
|
+
citationCount: res.citations.length,
|
|
141
|
+
metadata: res.metadata,
|
|
142
|
+
sessionId: ctx.sessionId ?? null,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const finalAnswer = parsed.noCitations
|
|
146
|
+
? res.answer.replace(MARKER_RE, "")
|
|
147
|
+
: res.answer;
|
|
148
|
+
return {
|
|
149
|
+
content: [
|
|
150
|
+
{
|
|
151
|
+
type: "text",
|
|
152
|
+
text: JSON.stringify({
|
|
153
|
+
answer: finalAnswer,
|
|
154
|
+
citations: res.citations,
|
|
155
|
+
metadata: res.metadata,
|
|
156
|
+
}),
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
// retrieval_empty is not an error from MCP's perspective — caller sees
|
|
160
|
+
// citations:[] and the canonical "no memory matches" string.
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
catch (err) {
|
|
164
|
+
if (err instanceof AnswerError) {
|
|
165
|
+
if (ctx?.telemetryStore) {
|
|
166
|
+
recordAnswer(ctx.telemetryStore, {
|
|
167
|
+
question: parsed.question,
|
|
168
|
+
citationCount: 0,
|
|
169
|
+
metadata: {
|
|
170
|
+
latency_ms: err.metadata.latency_ms ?? 0,
|
|
171
|
+
tokens_in: err.metadata.tokens_in ?? 0,
|
|
172
|
+
tokens_out: err.metadata.tokens_out ?? 0,
|
|
173
|
+
provider: err.metadata.provider ?? "n/a",
|
|
174
|
+
model: err.metadata.model ?? "n/a",
|
|
175
|
+
retrieval_count: err.metadata.retrieval_count ?? 0,
|
|
176
|
+
fallback_used: err.metadata.fallback_used ?? false,
|
|
177
|
+
failed_reason: err.reason,
|
|
178
|
+
},
|
|
179
|
+
sessionId: ctx.sessionId ?? null,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
content: [
|
|
184
|
+
{
|
|
185
|
+
type: "text",
|
|
186
|
+
text: JSON.stringify({
|
|
187
|
+
error: true,
|
|
188
|
+
reason: err.reason,
|
|
189
|
+
message: err.message,
|
|
190
|
+
metadata: err.metadata,
|
|
191
|
+
}),
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
isError: true,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
content: [
|
|
199
|
+
{
|
|
200
|
+
type: "text",
|
|
201
|
+
text: JSON.stringify({
|
|
202
|
+
error: true,
|
|
203
|
+
reason: "internal_error",
|
|
204
|
+
message: err.message,
|
|
205
|
+
}),
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
isError: true,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
export default noxMemAnswerTool;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T14 — MCP tools `archive_export` + `archive_import`.
|
|
3
|
+
*
|
|
4
|
+
* Adds 2 tools to the existing 16 → 18 MCP tools served by nox-mem.
|
|
5
|
+
* Schema follows the MCP convention: name, description, inputSchema (JSON
|
|
6
|
+
* Schema draft-07-ish), result type. The MCP server in the parent repo wires
|
|
7
|
+
* these into its registry.
|
|
8
|
+
*
|
|
9
|
+
* Security:
|
|
10
|
+
* - `passphrase` parameter accepted ONLY when the MCP transport is
|
|
11
|
+
* authenticated (stdio over OS pipe, OR HTTPS). Parent server enforces
|
|
12
|
+
* transport-level auth; this module does not re-validate.
|
|
13
|
+
* - `passphrase_env` is the preferred parameter — the MCP server expands it
|
|
14
|
+
* from its own process env, never the client's argv.
|
|
15
|
+
*/
|
|
16
|
+
import { ExportRequest } from "../../lib/archive/orchestrator.js";
|
|
17
|
+
import { ChunkRow, KgEntityRow, KgRelationRow, OpsAuditRow } from "../../lib/archive/types.js";
|
|
18
|
+
export declare const archiveExportToolSchema: {
|
|
19
|
+
readonly name: "archive_export";
|
|
20
|
+
readonly description: string;
|
|
21
|
+
readonly inputSchema: {
|
|
22
|
+
readonly type: "object";
|
|
23
|
+
readonly properties: {
|
|
24
|
+
readonly unencrypted: {
|
|
25
|
+
readonly type: "boolean";
|
|
26
|
+
readonly default: false;
|
|
27
|
+
};
|
|
28
|
+
readonly passphrase: {
|
|
29
|
+
readonly type: "string";
|
|
30
|
+
readonly description: string;
|
|
31
|
+
};
|
|
32
|
+
readonly passphrase_env: {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
readonly description: string;
|
|
35
|
+
};
|
|
36
|
+
readonly project: {
|
|
37
|
+
readonly type: "string";
|
|
38
|
+
};
|
|
39
|
+
readonly since: {
|
|
40
|
+
readonly type: "string";
|
|
41
|
+
readonly format: "date-time";
|
|
42
|
+
};
|
|
43
|
+
readonly until: {
|
|
44
|
+
readonly type: "string";
|
|
45
|
+
readonly format: "date-time";
|
|
46
|
+
};
|
|
47
|
+
readonly exclude_embeddings: {
|
|
48
|
+
readonly type: "boolean";
|
|
49
|
+
readonly default: false;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export declare const archiveImportToolSchema: {
|
|
55
|
+
readonly name: "archive_import";
|
|
56
|
+
readonly description: string;
|
|
57
|
+
readonly inputSchema: {
|
|
58
|
+
readonly type: "object";
|
|
59
|
+
readonly required: readonly ["archive_b64"];
|
|
60
|
+
readonly properties: {
|
|
61
|
+
readonly archive_b64: {
|
|
62
|
+
readonly type: "string";
|
|
63
|
+
readonly description: "Base64-encoded archive.";
|
|
64
|
+
};
|
|
65
|
+
readonly passphrase: {
|
|
66
|
+
readonly type: "string";
|
|
67
|
+
};
|
|
68
|
+
readonly passphrase_env: {
|
|
69
|
+
readonly type: "string";
|
|
70
|
+
};
|
|
71
|
+
readonly mode: {
|
|
72
|
+
readonly enum: readonly ["merge", "replace"];
|
|
73
|
+
readonly default: "merge";
|
|
74
|
+
};
|
|
75
|
+
readonly dry_run: {
|
|
76
|
+
readonly type: "boolean";
|
|
77
|
+
readonly default: false;
|
|
78
|
+
};
|
|
79
|
+
readonly verify_only: {
|
|
80
|
+
readonly type: "boolean";
|
|
81
|
+
readonly default: false;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
export interface ArchiveExportInput {
|
|
87
|
+
unencrypted?: boolean;
|
|
88
|
+
passphrase?: string;
|
|
89
|
+
passphrase_env?: string;
|
|
90
|
+
project?: string;
|
|
91
|
+
since?: string;
|
|
92
|
+
until?: string;
|
|
93
|
+
exclude_embeddings?: boolean;
|
|
94
|
+
}
|
|
95
|
+
export interface ArchiveImportInput {
|
|
96
|
+
archive_b64: string;
|
|
97
|
+
passphrase?: string;
|
|
98
|
+
passphrase_env?: string;
|
|
99
|
+
mode?: "merge" | "replace";
|
|
100
|
+
dry_run?: boolean;
|
|
101
|
+
verify_only?: boolean;
|
|
102
|
+
}
|
|
103
|
+
export interface ArchiveExportResult {
|
|
104
|
+
success: true;
|
|
105
|
+
archive_b64: string;
|
|
106
|
+
bytes: number;
|
|
107
|
+
encrypted: boolean;
|
|
108
|
+
manifest: {
|
|
109
|
+
schema_version: number;
|
|
110
|
+
counts: import("../../lib/archive/types.js").ManifestCounts;
|
|
111
|
+
created_at: string;
|
|
112
|
+
};
|
|
113
|
+
duration_ms: number;
|
|
114
|
+
}
|
|
115
|
+
export interface ArchiveExportError {
|
|
116
|
+
success: false;
|
|
117
|
+
error: string;
|
|
118
|
+
code?: string;
|
|
119
|
+
}
|
|
120
|
+
export interface ArchiveImportResult {
|
|
121
|
+
success: true;
|
|
122
|
+
encrypted: boolean;
|
|
123
|
+
applied: boolean;
|
|
124
|
+
schema_version_archive: number;
|
|
125
|
+
schema_version_target: number;
|
|
126
|
+
stats: import("../../lib/archive/orchestrator.js").ImportResult["stats"];
|
|
127
|
+
duration_ms: number;
|
|
128
|
+
}
|
|
129
|
+
export interface ArchiveImportError {
|
|
130
|
+
success: false;
|
|
131
|
+
error: string;
|
|
132
|
+
code?: string;
|
|
133
|
+
}
|
|
134
|
+
export interface McpExportDeps {
|
|
135
|
+
dbReader: () => Promise<Omit<ExportRequest, "passphrase" | "unencrypted" | "signal" | "onProgress">>;
|
|
136
|
+
env?: NodeJS.ProcessEnv;
|
|
137
|
+
signal?: AbortSignal;
|
|
138
|
+
}
|
|
139
|
+
export declare function archiveExportTool(input: ArchiveExportInput, deps: McpExportDeps): Promise<ArchiveExportResult | ArchiveExportError>;
|
|
140
|
+
export interface McpImportDeps {
|
|
141
|
+
loadExisting: () => Promise<{
|
|
142
|
+
chunks: ChunkRow[];
|
|
143
|
+
kg_entities: KgEntityRow[];
|
|
144
|
+
kg_relations: KgRelationRow[];
|
|
145
|
+
ops_audit: OpsAuditRow[];
|
|
146
|
+
}>;
|
|
147
|
+
currentSchemaVersion: () => Promise<number>;
|
|
148
|
+
persist?: (resolved: import("../../lib/archive/orchestrator.js").ImportResult["resolved"]) => Promise<void>;
|
|
149
|
+
env?: NodeJS.ProcessEnv;
|
|
150
|
+
signal?: AbortSignal;
|
|
151
|
+
}
|
|
152
|
+
export declare function archiveImportTool(input: ArchiveImportInput, deps: McpImportDeps): Promise<ArchiveImportResult | ArchiveImportError>;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T14 — MCP tools `archive_export` + `archive_import`.
|
|
3
|
+
*
|
|
4
|
+
* Adds 2 tools to the existing 16 → 18 MCP tools served by nox-mem.
|
|
5
|
+
* Schema follows the MCP convention: name, description, inputSchema (JSON
|
|
6
|
+
* Schema draft-07-ish), result type. The MCP server in the parent repo wires
|
|
7
|
+
* these into its registry.
|
|
8
|
+
*
|
|
9
|
+
* Security:
|
|
10
|
+
* - `passphrase` parameter accepted ONLY when the MCP transport is
|
|
11
|
+
* authenticated (stdio over OS pipe, OR HTTPS). Parent server enforces
|
|
12
|
+
* transport-level auth; this module does not re-validate.
|
|
13
|
+
* - `passphrase_env` is the preferred parameter — the MCP server expands it
|
|
14
|
+
* from its own process env, never the client's argv.
|
|
15
|
+
*/
|
|
16
|
+
import { runExport, runImport, } from "../../lib/archive/orchestrator.js";
|
|
17
|
+
// -- JSON Schemas -------------------------------------------------------------
|
|
18
|
+
export const archiveExportToolSchema = {
|
|
19
|
+
name: "archive_export",
|
|
20
|
+
description: "Export nox-mem memory state to a portable .tgz archive. Encrypt-by-default (D41 #2). " +
|
|
21
|
+
"Returns archive bytes base64 + manifest summary.",
|
|
22
|
+
inputSchema: {
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: {
|
|
25
|
+
unencrypted: { type: "boolean", default: false },
|
|
26
|
+
passphrase: {
|
|
27
|
+
type: "string",
|
|
28
|
+
description: "Passphrase for AES-256-GCM. Required unless unencrypted=true. " +
|
|
29
|
+
"PREFER passphrase_env for automation.",
|
|
30
|
+
},
|
|
31
|
+
passphrase_env: {
|
|
32
|
+
type: "string",
|
|
33
|
+
description: "Name of an env var on the MCP server process containing the passphrase. " +
|
|
34
|
+
"Server reads it; the value never crosses the wire.",
|
|
35
|
+
},
|
|
36
|
+
project: { type: "string" },
|
|
37
|
+
since: { type: "string", format: "date-time" },
|
|
38
|
+
until: { type: "string", format: "date-time" },
|
|
39
|
+
exclude_embeddings: { type: "boolean", default: false },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
export const archiveImportToolSchema = {
|
|
44
|
+
name: "archive_import",
|
|
45
|
+
description: "Import a nox-mem archive. Auto-detects encryption via manifest. " +
|
|
46
|
+
"Validates schema version + checksums BEFORE writing.",
|
|
47
|
+
inputSchema: {
|
|
48
|
+
type: "object",
|
|
49
|
+
required: ["archive_b64"],
|
|
50
|
+
properties: {
|
|
51
|
+
archive_b64: { type: "string", description: "Base64-encoded archive." },
|
|
52
|
+
passphrase: { type: "string" },
|
|
53
|
+
passphrase_env: { type: "string" },
|
|
54
|
+
mode: { enum: ["merge", "replace"], default: "merge" },
|
|
55
|
+
dry_run: { type: "boolean", default: false },
|
|
56
|
+
verify_only: { type: "boolean", default: false },
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
export async function archiveExportTool(input, deps) {
|
|
61
|
+
const env = deps.env ?? process.env;
|
|
62
|
+
let passphrase = input.passphrase;
|
|
63
|
+
if (input.passphrase_env) {
|
|
64
|
+
const v = env[input.passphrase_env];
|
|
65
|
+
if (typeof v !== "string" || v.length === 0) {
|
|
66
|
+
return {
|
|
67
|
+
success: false,
|
|
68
|
+
error: `passphrase_env ${input.passphrase_env} not set on server`,
|
|
69
|
+
code: "MISSING_ENV",
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
passphrase = v;
|
|
73
|
+
}
|
|
74
|
+
if (!input.unencrypted &&
|
|
75
|
+
(typeof passphrase !== "string" || passphrase.length === 0)) {
|
|
76
|
+
return {
|
|
77
|
+
success: false,
|
|
78
|
+
error: "passphrase required (D41 #2 encrypt-by-default) — pass passphrase or passphrase_env",
|
|
79
|
+
code: "PASSPHRASE_REQUIRED",
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const corpus = await deps.dbReader();
|
|
83
|
+
if (input.exclude_embeddings)
|
|
84
|
+
corpus.embeddings = undefined;
|
|
85
|
+
try {
|
|
86
|
+
const out = await runExport({
|
|
87
|
+
...corpus,
|
|
88
|
+
filters: {
|
|
89
|
+
project: input.project ?? null,
|
|
90
|
+
since: input.since ?? null,
|
|
91
|
+
until: input.until ?? null,
|
|
92
|
+
},
|
|
93
|
+
unencrypted: input.unencrypted === true,
|
|
94
|
+
passphrase,
|
|
95
|
+
signal: deps.signal,
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
success: true,
|
|
99
|
+
archive_b64: out.archive.toString("base64"),
|
|
100
|
+
bytes: out.size_bytes,
|
|
101
|
+
encrypted: out.manifest.encryption.enabled,
|
|
102
|
+
manifest: {
|
|
103
|
+
schema_version: out.manifest.schema_version,
|
|
104
|
+
counts: out.manifest.counts,
|
|
105
|
+
created_at: out.manifest.created_at,
|
|
106
|
+
},
|
|
107
|
+
duration_ms: out.duration_ms,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
return {
|
|
112
|
+
success: false,
|
|
113
|
+
error: err.message,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export async function archiveImportTool(input, deps) {
|
|
118
|
+
if (!input.archive_b64) {
|
|
119
|
+
return { success: false, error: "archive_b64 required" };
|
|
120
|
+
}
|
|
121
|
+
const env = deps.env ?? process.env;
|
|
122
|
+
let passphrase = input.passphrase;
|
|
123
|
+
if (input.passphrase_env) {
|
|
124
|
+
const v = env[input.passphrase_env];
|
|
125
|
+
if (typeof v !== "string" || v.length === 0) {
|
|
126
|
+
return {
|
|
127
|
+
success: false,
|
|
128
|
+
error: `passphrase_env ${input.passphrase_env} not set on server`,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
passphrase = v;
|
|
132
|
+
}
|
|
133
|
+
let archive;
|
|
134
|
+
try {
|
|
135
|
+
archive = Buffer.from(input.archive_b64, "base64");
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
return { success: false, error: `bad base64: ${err.message}` };
|
|
139
|
+
}
|
|
140
|
+
const existing = await deps.loadExisting();
|
|
141
|
+
const currentSchemaVersion = await deps.currentSchemaVersion();
|
|
142
|
+
const req = {
|
|
143
|
+
archive,
|
|
144
|
+
passphrase,
|
|
145
|
+
mode: input.mode ?? "merge",
|
|
146
|
+
dry_run: input.dry_run === true,
|
|
147
|
+
verify_only: input.verify_only === true,
|
|
148
|
+
current_schema_version: currentSchemaVersion,
|
|
149
|
+
existing,
|
|
150
|
+
signal: deps.signal,
|
|
151
|
+
};
|
|
152
|
+
try {
|
|
153
|
+
const out = await runImport(req);
|
|
154
|
+
if (!input.dry_run && !input.verify_only && deps.persist) {
|
|
155
|
+
await deps.persist(out.resolved);
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
success: true,
|
|
159
|
+
encrypted: out.manifest.encryption.enabled,
|
|
160
|
+
applied: out.applied,
|
|
161
|
+
schema_version_archive: out.manifest.schema_version,
|
|
162
|
+
schema_version_target: currentSchemaVersion,
|
|
163
|
+
stats: out.stats,
|
|
164
|
+
duration_ms: out.duration_ms,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
return { success: false, error: err.message };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 T9 — MCP tools.
|
|
3
|
+
*
|
|
4
|
+
* Three tools exposed to MCP clients (e.g. Claude Code, agents):
|
|
5
|
+
* - conflict_scan → triggers a detection pass under current mode
|
|
6
|
+
* - conflict_list → list audit rows by status
|
|
7
|
+
* - conflict_resolve → write resolution (terminal status only)
|
|
8
|
+
*
|
|
9
|
+
* MCP write tools must be gated by `NOX_MCP_ALLOW_WRITES=1` per existing
|
|
10
|
+
* pattern in nox-mem MCP server. `conflict_resolve` returns an
|
|
11
|
+
* `mcp_write_disabled` error when the env var is unset.
|
|
12
|
+
*
|
|
13
|
+
* Tools return JSON payloads matching the HTTP API shapes for
|
|
14
|
+
* consistency (see ../../api/conflict.ts).
|
|
15
|
+
*/
|
|
16
|
+
import type { DBHandle } from "../../lib/conflict/db.js";
|
|
17
|
+
import type { ConflictMode, ConflictStatus, ResolutionKind } from "../../lib/conflict/types.js";
|
|
18
|
+
export interface ScanInput {
|
|
19
|
+
min_confidence?: number;
|
|
20
|
+
predicate_allowlist?: string[];
|
|
21
|
+
mode_override?: ConflictMode;
|
|
22
|
+
}
|
|
23
|
+
export interface ListInput {
|
|
24
|
+
status?: ConflictStatus;
|
|
25
|
+
limit?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface ResolveInput {
|
|
28
|
+
id: number;
|
|
29
|
+
kind: ResolutionKind;
|
|
30
|
+
picked_relation_id?: number;
|
|
31
|
+
merge_target?: string;
|
|
32
|
+
notes?: string;
|
|
33
|
+
actor?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ToolResult<T = unknown> {
|
|
36
|
+
ok: boolean;
|
|
37
|
+
data?: T;
|
|
38
|
+
error?: string;
|
|
39
|
+
/** Surface a structured detail object for clients to render. */
|
|
40
|
+
detail?: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
export declare function conflict_scan(db: DBHandle, input?: ScanInput): ToolResult;
|
|
43
|
+
export declare function conflict_list(db: DBHandle, input?: ListInput): ToolResult;
|
|
44
|
+
export declare function conflict_resolve(db: DBHandle, input: ResolveInput, env?: Record<string, string | undefined>): ToolResult;
|