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,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 T5 — Audit writer (append-only).
|
|
3
|
+
*
|
|
4
|
+
* - `recordConflict(db, conflict, evidence?)` — INSERT new audit row.
|
|
5
|
+
* Idempotency: skips when an OPEN row already exists for the same
|
|
6
|
+
* (subject_entity_id, predicate) — the v21 schema lets us use the partial
|
|
7
|
+
* index `idx_conflict_audit_open` for a fast existence check.
|
|
8
|
+
*
|
|
9
|
+
* - `updateConflictStatus(db, id, resolution)` — UPDATE status + resolution
|
|
10
|
+
* columns ONLY. Raw conflict data (kind/subject/predicate/target_relation_ids/
|
|
11
|
+
* variants/ts) is immutable per the v21 triggers. Status transitions
|
|
12
|
+
* matching a terminal-row reopen are blocked by trigger
|
|
13
|
+
* `trg_conflict_audit_no_reopen`.
|
|
14
|
+
*
|
|
15
|
+
* Regra de ouro #2 (v1 NEVER mutates kg_relations) is honored — this module
|
|
16
|
+
* touches conflict_audit only.
|
|
17
|
+
*/
|
|
18
|
+
import type { DBHandle } from "./db.js";
|
|
19
|
+
import type { Conflict, ConflictAuditRow, ConflictEvidence, ConflictStatus, ResolutionInput } from "./types.js";
|
|
20
|
+
export interface RecordResult {
|
|
21
|
+
/** New row id on insert, existing row id on dedupe. */
|
|
22
|
+
id: number;
|
|
23
|
+
/** True when an existing open row was found and INSERT skipped. */
|
|
24
|
+
deduplicated: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface RecordOptions {
|
|
27
|
+
/** Default 1 (shadow). Pass 0 to record an "active" row. */
|
|
28
|
+
shadow_mode?: 0 | 1;
|
|
29
|
+
/** Default 'open'. Use 'reviewed' for batch import workflows that mark seen. */
|
|
30
|
+
initial_status?: Extract<ConflictStatus, "open" | "reviewed">;
|
|
31
|
+
/** When true, skip the dedupe pre-check and always insert. */
|
|
32
|
+
force?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare function recordConflict(db: DBHandle, conflict: Conflict, evidence?: ConflictEvidence | null, opts?: RecordOptions): RecordResult;
|
|
35
|
+
export declare function updateConflictStatus(db: DBHandle, id: number, resolution: ResolutionInput): void;
|
|
36
|
+
export declare function getConflictById(db: DBHandle, id: number): ConflictAuditRow | null;
|
|
37
|
+
export declare function listConflicts(db: DBHandle, status?: ConflictStatus, limit?: number): ConflictAuditRow[];
|
|
38
|
+
/** Aggregate counts by status — used by shadow telemetry. */
|
|
39
|
+
export declare function statusCounts(db: DBHandle): Record<ConflictStatus, number>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 T5 — Audit writer (append-only).
|
|
3
|
+
*
|
|
4
|
+
* - `recordConflict(db, conflict, evidence?)` — INSERT new audit row.
|
|
5
|
+
* Idempotency: skips when an OPEN row already exists for the same
|
|
6
|
+
* (subject_entity_id, predicate) — the v21 schema lets us use the partial
|
|
7
|
+
* index `idx_conflict_audit_open` for a fast existence check.
|
|
8
|
+
*
|
|
9
|
+
* - `updateConflictStatus(db, id, resolution)` — UPDATE status + resolution
|
|
10
|
+
* columns ONLY. Raw conflict data (kind/subject/predicate/target_relation_ids/
|
|
11
|
+
* variants/ts) is immutable per the v21 triggers. Status transitions
|
|
12
|
+
* matching a terminal-row reopen are blocked by trigger
|
|
13
|
+
* `trg_conflict_audit_no_reopen`.
|
|
14
|
+
*
|
|
15
|
+
* Regra de ouro #2 (v1 NEVER mutates kg_relations) is honored — this module
|
|
16
|
+
* touches conflict_audit only.
|
|
17
|
+
*/
|
|
18
|
+
const INSERT_SQL = `
|
|
19
|
+
INSERT INTO conflict_audit (kind, subject_entity_id, predicate, target_relation_ids, variants, status, shadow_mode)
|
|
20
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
21
|
+
`.trim();
|
|
22
|
+
const UPDATE_SQL = `
|
|
23
|
+
UPDATE conflict_audit
|
|
24
|
+
SET status = ?, resolution_kind = ?, resolved_by = ?, resolved_at = ?, picked_relation_id = ?, merge_target = ?, notes = ?
|
|
25
|
+
WHERE id = ?
|
|
26
|
+
`.trim();
|
|
27
|
+
const EXISTS_OPEN_SQL = `
|
|
28
|
+
SELECT id FROM conflict_audit
|
|
29
|
+
WHERE subject_entity_id = ? AND predicate = ? AND status = ?
|
|
30
|
+
LIMIT 1
|
|
31
|
+
`.trim();
|
|
32
|
+
const GET_BY_ID_SQL = `SELECT * FROM conflict_audit WHERE id = ?`;
|
|
33
|
+
const LIST_BY_STATUS_SQL = `SELECT * FROM conflict_audit WHERE status = ? LIMIT 500`;
|
|
34
|
+
const COUNT_BY_STATUS_SQL = `SELECT status, COUNT(*) AS count FROM conflict_audit GROUP BY status`;
|
|
35
|
+
export function recordConflict(db, conflict, evidence = null, opts = {}) {
|
|
36
|
+
const shadowMode = opts.shadow_mode ?? 1;
|
|
37
|
+
const status = opts.initial_status ?? "open";
|
|
38
|
+
if (!opts.force) {
|
|
39
|
+
const existing = db
|
|
40
|
+
.prepare(EXISTS_OPEN_SQL)
|
|
41
|
+
.get(conflict.subject_entity_id, conflict.predicate, "open");
|
|
42
|
+
if (existing) {
|
|
43
|
+
return { id: Number(existing.id), deduplicated: true };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const targetIds = conflict.variants.map((v) => v.relation_id);
|
|
47
|
+
const variantsJson = JSON.stringify(enrichVariantsWithEvidence(conflict.variants, evidence));
|
|
48
|
+
const res = db
|
|
49
|
+
.prepare(INSERT_SQL)
|
|
50
|
+
.run(conflict.kind, conflict.subject_entity_id, conflict.predicate, JSON.stringify(targetIds), variantsJson, status, shadowMode);
|
|
51
|
+
return { id: Number(res.lastInsertRowid), deduplicated: false };
|
|
52
|
+
}
|
|
53
|
+
export function updateConflictStatus(db, id, resolution) {
|
|
54
|
+
const now = Date.now();
|
|
55
|
+
const picked = resolution.picked_relation_id ?? null;
|
|
56
|
+
const merge = resolution.merge_target ?? null;
|
|
57
|
+
const notes = resolution.notes ?? null;
|
|
58
|
+
// Defensive validation — picked_relation_id required for pick_one.
|
|
59
|
+
if (resolution.resolution_kind === "pick_one" && picked == null) {
|
|
60
|
+
throw new Error("pick_one resolution requires picked_relation_id (got null/undefined)");
|
|
61
|
+
}
|
|
62
|
+
if (resolution.resolution_kind === "merged" && (merge == null || merge === "")) {
|
|
63
|
+
throw new Error("merged resolution requires non-empty merge_target");
|
|
64
|
+
}
|
|
65
|
+
// Trigger trg_conflict_audit_no_reopen will block invalid transitions.
|
|
66
|
+
db.prepare(UPDATE_SQL).run(resolution.status, resolution.resolution_kind, resolution.resolved_by, now, picked, merge, notes, id);
|
|
67
|
+
}
|
|
68
|
+
export function getConflictById(db, id) {
|
|
69
|
+
const row = db.prepare(GET_BY_ID_SQL).get(id);
|
|
70
|
+
if (!row)
|
|
71
|
+
return null;
|
|
72
|
+
return rowToAudit(row);
|
|
73
|
+
}
|
|
74
|
+
export function listConflicts(db, status = "open", limit = 50) {
|
|
75
|
+
const safeLimit = Math.max(1, Math.min(500, limit));
|
|
76
|
+
const sql = `SELECT * FROM conflict_audit WHERE status = ? LIMIT ${safeLimit}`;
|
|
77
|
+
const rows = db.prepare(sql).all(status);
|
|
78
|
+
return rows.map(rowToAudit);
|
|
79
|
+
}
|
|
80
|
+
/** Aggregate counts by status — used by shadow telemetry. */
|
|
81
|
+
export function statusCounts(db) {
|
|
82
|
+
const empty = {
|
|
83
|
+
open: 0,
|
|
84
|
+
reviewed: 0,
|
|
85
|
+
resolved_pick_one: 0,
|
|
86
|
+
resolved_both_valid: 0,
|
|
87
|
+
resolved_merged: 0,
|
|
88
|
+
dismissed: 0,
|
|
89
|
+
};
|
|
90
|
+
const rows = db.prepare(COUNT_BY_STATUS_SQL).all();
|
|
91
|
+
for (const r of rows) {
|
|
92
|
+
if (r.status in empty) {
|
|
93
|
+
empty[r.status] = Number(r.count);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return empty;
|
|
97
|
+
}
|
|
98
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
99
|
+
// Internal helpers
|
|
100
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
101
|
+
function enrichVariantsWithEvidence(variants, evidence) {
|
|
102
|
+
if (!evidence)
|
|
103
|
+
return variants;
|
|
104
|
+
const byId = new Map();
|
|
105
|
+
for (const v of variants)
|
|
106
|
+
byId.set(v.relation_id, v);
|
|
107
|
+
return evidence.variants.map((ve) => ({
|
|
108
|
+
...ve.variant,
|
|
109
|
+
evidence_chunks: ve.chunks,
|
|
110
|
+
weighted_score: ve.weighted_score,
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
function rowToAudit(row) {
|
|
114
|
+
const trIds = row.target_relation_ids;
|
|
115
|
+
const variants = row.variants;
|
|
116
|
+
return {
|
|
117
|
+
id: Number(row.id),
|
|
118
|
+
ts: Number(row.ts),
|
|
119
|
+
kind: row.kind,
|
|
120
|
+
subject_entity_id: Number(row.subject_entity_id),
|
|
121
|
+
predicate: String(row.predicate),
|
|
122
|
+
target_relation_ids: typeof trIds === "string" ? JSON.parse(trIds) : trIds ?? [],
|
|
123
|
+
variants: typeof variants === "string" ? JSON.parse(variants) : variants ?? [],
|
|
124
|
+
status: row.status,
|
|
125
|
+
resolved_by: row.resolved_by ?? null,
|
|
126
|
+
resolved_at: row.resolved_at == null ? null : Number(row.resolved_at),
|
|
127
|
+
resolution_kind: row.resolution_kind ?? null,
|
|
128
|
+
picked_relation_id: row.picked_relation_id == null ? null : Number(row.picked_relation_id),
|
|
129
|
+
merge_target: row.merge_target ?? null,
|
|
130
|
+
notes: row.notes ?? null,
|
|
131
|
+
shadow_mode: (Number(row.shadow_mode) === 0 ? 0 : 1),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/conflict/db-singleton.ts — Wave O T4 (L2 piece).
|
|
3
|
+
*
|
|
4
|
+
* Wire-up.ts expects `lib/conflict/db.js::getConflictDb(): DBHandle`.
|
|
5
|
+
* staged-L2 ships only the `DBHandle` interface — no factory. This adapter
|
|
6
|
+
* adds the factory.
|
|
7
|
+
*
|
|
8
|
+
* Apply step appends one line to staged-L2's `db.ts`:
|
|
9
|
+
*
|
|
10
|
+
* export { getConflictDb, resetConflictDbForTests } from "./db-singleton.js";
|
|
11
|
+
*
|
|
12
|
+
* Resolution path: `getConflictDb()` delegates to `deps-registry.getDb()`,
|
|
13
|
+
* sharing the same nox-mem.db connection used by every other pillar.
|
|
14
|
+
*
|
|
15
|
+
* Schema dep: L2 reads/writes `conflict_audit` (created by L2 migration v18).
|
|
16
|
+
* When the table is missing the upstream `dispatchConflictApi` returns 500;
|
|
17
|
+
* the wire-up's G5 sanitizer catches it and returns a redacted 500.
|
|
18
|
+
*
|
|
19
|
+
* Build-time: ESM TLA loads deps-registry at module init.
|
|
20
|
+
*/
|
|
21
|
+
type DBHandle = unknown;
|
|
22
|
+
export declare function getConflictDb(): DBHandle | null;
|
|
23
|
+
/** Warm up the singleton at boot. Returns the handle once ready. */
|
|
24
|
+
export declare function ensureConflictDb(): Promise<DBHandle | null>;
|
|
25
|
+
/** Inject a fake DB for tests. Pass null to clear. */
|
|
26
|
+
export declare function __setConflictDbForTests(db: DBHandle | null): void;
|
|
27
|
+
export declare function resetConflictDbForTests(): void;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/conflict/db-singleton.ts — Wave O T4 (L2 piece).
|
|
3
|
+
*
|
|
4
|
+
* Wire-up.ts expects `lib/conflict/db.js::getConflictDb(): DBHandle`.
|
|
5
|
+
* staged-L2 ships only the `DBHandle` interface — no factory. This adapter
|
|
6
|
+
* adds the factory.
|
|
7
|
+
*
|
|
8
|
+
* Apply step appends one line to staged-L2's `db.ts`:
|
|
9
|
+
*
|
|
10
|
+
* export { getConflictDb, resetConflictDbForTests } from "./db-singleton.js";
|
|
11
|
+
*
|
|
12
|
+
* Resolution path: `getConflictDb()` delegates to `deps-registry.getDb()`,
|
|
13
|
+
* sharing the same nox-mem.db connection used by every other pillar.
|
|
14
|
+
*
|
|
15
|
+
* Schema dep: L2 reads/writes `conflict_audit` (created by L2 migration v18).
|
|
16
|
+
* When the table is missing the upstream `dispatchConflictApi` returns 500;
|
|
17
|
+
* the wire-up's G5 sanitizer catches it and returns a redacted 500.
|
|
18
|
+
*
|
|
19
|
+
* Build-time: ESM TLA loads deps-registry at module init.
|
|
20
|
+
*/
|
|
21
|
+
import { getDb } from "../deps/deps-registry.js";
|
|
22
|
+
let _override = null;
|
|
23
|
+
/**
|
|
24
|
+
* Sync accessor — wire-up calls `dbMod.getConflictDb()` synchronously.
|
|
25
|
+
* We warm up the singleton in deps-registry at first call.
|
|
26
|
+
*
|
|
27
|
+
* Returns `null` when no DB is available; wire-up's null-check then emits
|
|
28
|
+
* 503 not_implemented.
|
|
29
|
+
*/
|
|
30
|
+
let _cached;
|
|
31
|
+
export function getConflictDb() {
|
|
32
|
+
if (_override !== null)
|
|
33
|
+
return _override;
|
|
34
|
+
if (_cached !== undefined)
|
|
35
|
+
return _cached ?? null;
|
|
36
|
+
// Kick off the async resolve; the first call may return null until the
|
|
37
|
+
// warmup completes. Production startup invokes `await ensureConflictDb()`
|
|
38
|
+
// in the API boot sequence.
|
|
39
|
+
void warmup();
|
|
40
|
+
return _cached ?? null;
|
|
41
|
+
}
|
|
42
|
+
async function warmup() {
|
|
43
|
+
if (_cached !== undefined)
|
|
44
|
+
return;
|
|
45
|
+
const db = await getDb();
|
|
46
|
+
_cached = db;
|
|
47
|
+
}
|
|
48
|
+
/** Warm up the singleton at boot. Returns the handle once ready. */
|
|
49
|
+
export async function ensureConflictDb() {
|
|
50
|
+
await warmup();
|
|
51
|
+
return _cached ?? null;
|
|
52
|
+
}
|
|
53
|
+
// ─── Test seam ───────────────────────────────────────────────────────────────
|
|
54
|
+
/** Inject a fake DB for tests. Pass null to clear. */
|
|
55
|
+
export function __setConflictDbForTests(db) {
|
|
56
|
+
_override = db;
|
|
57
|
+
}
|
|
58
|
+
export function resetConflictDbForTests() {
|
|
59
|
+
_override = null;
|
|
60
|
+
_cached = undefined;
|
|
61
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal DB abstraction for L2 staged code.
|
|
3
|
+
*
|
|
4
|
+
* The production codebase wires better-sqlite3 directly. To keep this staged
|
|
5
|
+
* package zero-dependency for tests (and avoid forcing a `npm install` to run
|
|
6
|
+
* the test suite), we expose a tiny interface that matches the better-sqlite3
|
|
7
|
+
* `Statement`/`Database` shape. Real callers pass `Database.prototype` from
|
|
8
|
+
* better-sqlite3; tests pass a synchronous in-memory fake (see
|
|
9
|
+
* `__tests__/fakes.ts`).
|
|
10
|
+
*/
|
|
11
|
+
export interface RunResult {
|
|
12
|
+
changes: number;
|
|
13
|
+
lastInsertRowid: number | bigint;
|
|
14
|
+
}
|
|
15
|
+
export interface PreparedStatement {
|
|
16
|
+
run(...params: unknown[]): RunResult;
|
|
17
|
+
get(...params: unknown[]): unknown;
|
|
18
|
+
all(...params: unknown[]): unknown[];
|
|
19
|
+
iterate?(...params: unknown[]): IterableIterator<unknown>;
|
|
20
|
+
}
|
|
21
|
+
export interface DBHandle {
|
|
22
|
+
prepare(sql: string): PreparedStatement;
|
|
23
|
+
exec(sql: string): void;
|
|
24
|
+
transaction?<T>(fn: () => T): () => T;
|
|
25
|
+
pragma?(query: string): unknown;
|
|
26
|
+
}
|
|
27
|
+
export { getConflictDb, ensureConflictDb, resetConflictDbForTests, __setConflictDbForTests, } from "./db-singleton.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal DB abstraction for L2 staged code.
|
|
3
|
+
*
|
|
4
|
+
* The production codebase wires better-sqlite3 directly. To keep this staged
|
|
5
|
+
* package zero-dependency for tests (and avoid forcing a `npm install` to run
|
|
6
|
+
* the test suite), we expose a tiny interface that matches the better-sqlite3
|
|
7
|
+
* `Statement`/`Database` shape. Real callers pass `Database.prototype` from
|
|
8
|
+
* better-sqlite3; tests pass a synchronous in-memory fake (see
|
|
9
|
+
* `__tests__/fakes.ts`).
|
|
10
|
+
*/
|
|
11
|
+
// ─── Singleton factory (adapter apply step) ────────────────────────────────
|
|
12
|
+
// Wire-up.ts resolves `lib/conflict/db.js::getConflictDb()`. The singleton
|
|
13
|
+
// lives in the staged-wire-up-adapters layer; we re-export it here so the
|
|
14
|
+
// `tryImport("../lib/conflict/db.js")` call in wire-up.ts finds the symbol.
|
|
15
|
+
//
|
|
16
|
+
// `ensureConflictDb()` MUST be awaited during API boot to pre-warm the
|
|
17
|
+
// async better-sqlite3 open before the first synchronous `getConflictDb()`
|
|
18
|
+
// call. Without it, the first request arrives before warmup() resolves and
|
|
19
|
+
// getConflictDb() returns null → wire-up emits 503 not_implemented.
|
|
20
|
+
export { getConflictDb, ensureConflictDb, resetConflictDbForTests, __setConflictDbForTests, } from "./db-singleton.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 T3 — Direct conflict detector (Type 1).
|
|
3
|
+
*
|
|
4
|
+
* Algorithm (spec §4.1):
|
|
5
|
+
* 1. Group active kg_relations by (source_entity_id, predicate)
|
|
6
|
+
* 2. Flag groups where COUNT(DISTINCT target_entity_id) > 1
|
|
7
|
+
* 3. Hydrate each group with per-variant metadata (confidence, extraction
|
|
8
|
+
* method, evidence chunk, created_at)
|
|
9
|
+
* 4. Apply allowlist/blocklist + extraction_method weight bias
|
|
10
|
+
*
|
|
11
|
+
* v1 scope: produces `kind='direct'` conflicts only. Type 3 (temporal
|
|
12
|
+
* supersession) is a downstream refinement — left for L2.1 ranking phase.
|
|
13
|
+
*
|
|
14
|
+
* Defensive checks (spec §3 regra de ouro #4 — confidence threshold gate):
|
|
15
|
+
* - min_confidence default 0.5 (filtered in SQL via parameter)
|
|
16
|
+
* - superseded relations (superseded_by_relation_id IS NOT NULL) excluded
|
|
17
|
+
* by SQL clause; this preserves discoverability but keeps detector quiet
|
|
18
|
+
*/
|
|
19
|
+
import type { DBHandle } from "./db.js";
|
|
20
|
+
import { type Conflict, type DetectorOptions } from "./types.js";
|
|
21
|
+
export declare function detectDirectConflicts(db: DBHandle, opts?: DetectorOptions): Conflict[];
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 T3 — Direct conflict detector (Type 1).
|
|
3
|
+
*
|
|
4
|
+
* Algorithm (spec §4.1):
|
|
5
|
+
* 1. Group active kg_relations by (source_entity_id, predicate)
|
|
6
|
+
* 2. Flag groups where COUNT(DISTINCT target_entity_id) > 1
|
|
7
|
+
* 3. Hydrate each group with per-variant metadata (confidence, extraction
|
|
8
|
+
* method, evidence chunk, created_at)
|
|
9
|
+
* 4. Apply allowlist/blocklist + extraction_method weight bias
|
|
10
|
+
*
|
|
11
|
+
* v1 scope: produces `kind='direct'` conflicts only. Type 3 (temporal
|
|
12
|
+
* supersession) is a downstream refinement — left for L2.1 ranking phase.
|
|
13
|
+
*
|
|
14
|
+
* Defensive checks (spec §3 regra de ouro #4 — confidence threshold gate):
|
|
15
|
+
* - min_confidence default 0.5 (filtered in SQL via parameter)
|
|
16
|
+
* - superseded relations (superseded_by_relation_id IS NOT NULL) excluded
|
|
17
|
+
* by SQL clause; this preserves discoverability but keeps detector quiet
|
|
18
|
+
*/
|
|
19
|
+
import { DEFAULT_MIN_CONFIDENCE, DEFAULT_SCAN_LIMIT, } from "./types.js";
|
|
20
|
+
const DETECTOR_SQL = `
|
|
21
|
+
SELECT
|
|
22
|
+
source_entity_id,
|
|
23
|
+
predicate,
|
|
24
|
+
COUNT(DISTINCT target_entity_id) AS distinct_targets,
|
|
25
|
+
GROUP_CONCAT(id) AS relation_ids_csv
|
|
26
|
+
FROM kg_relations
|
|
27
|
+
WHERE confidence >= ?
|
|
28
|
+
AND superseded_by_relation_id IS NULL
|
|
29
|
+
GROUP BY source_entity_id, predicate
|
|
30
|
+
HAVING COUNT(DISTINCT target_entity_id) > 1
|
|
31
|
+
`.trim();
|
|
32
|
+
const HYDRATE_SQL = `
|
|
33
|
+
SELECT id, target_entity_id, confidence, extraction_method, evidence_chunk_id, created_at, user_marked
|
|
34
|
+
FROM kg_relations
|
|
35
|
+
WHERE source_entity_id = ? AND predicate = ? AND confidence >= ? AND superseded_by_relation_id IS NULL
|
|
36
|
+
`.trim();
|
|
37
|
+
const ENTITY_LABEL_SQL = `SELECT id, name FROM kg_entities WHERE id = ?`;
|
|
38
|
+
export function detectDirectConflicts(db, opts = {}) {
|
|
39
|
+
const minConf = opts.min_confidence ?? DEFAULT_MIN_CONFIDENCE;
|
|
40
|
+
const limit = opts.limit ?? DEFAULT_SCAN_LIMIT;
|
|
41
|
+
const scanTs = opts.scan_ts ?? Date.now();
|
|
42
|
+
// Confidence threshold validation — protect against pathological inputs.
|
|
43
|
+
if (minConf < 0 || minConf > 1) {
|
|
44
|
+
throw new RangeError(`min_confidence out of range [0..1]: ${minConf}`);
|
|
45
|
+
}
|
|
46
|
+
const allow = opts.predicate_allowlist?.length
|
|
47
|
+
? new Set(opts.predicate_allowlist)
|
|
48
|
+
: null;
|
|
49
|
+
const block = opts.predicate_blocklist?.length
|
|
50
|
+
? new Set(opts.predicate_blocklist)
|
|
51
|
+
: null;
|
|
52
|
+
const weights = opts.extraction_method_weights ?? {};
|
|
53
|
+
const groups = db.prepare(DETECTOR_SQL).all(minConf);
|
|
54
|
+
const conflicts = [];
|
|
55
|
+
for (const g of groups) {
|
|
56
|
+
if (allow && !allow.has(g.predicate))
|
|
57
|
+
continue;
|
|
58
|
+
if (block && block.has(g.predicate))
|
|
59
|
+
continue;
|
|
60
|
+
const variantRows = db
|
|
61
|
+
.prepare(HYDRATE_SQL)
|
|
62
|
+
.all(g.source_entity_id, g.predicate, minConf);
|
|
63
|
+
// Apply extraction_method weighting — annotate confidence with bias.
|
|
64
|
+
// Weight is multiplicative; default 1.0 (no bias).
|
|
65
|
+
const variants = variantRows.map((r) => {
|
|
66
|
+
const w = (r.extraction_method && weights[r.extraction_method]) ?? 1.0;
|
|
67
|
+
// Clamp adjusted confidence to [0,1] — weighted bias must never push
|
|
68
|
+
// outside the canonical CHECK constraint range.
|
|
69
|
+
const adjusted = Math.max(0, Math.min(1, r.confidence * w));
|
|
70
|
+
return {
|
|
71
|
+
relation_id: r.id,
|
|
72
|
+
target_entity_id: r.target_entity_id,
|
|
73
|
+
confidence: adjusted,
|
|
74
|
+
extraction_method: r.extraction_method,
|
|
75
|
+
evidence_chunk_id: r.evidence_chunk_id,
|
|
76
|
+
created_at: r.created_at,
|
|
77
|
+
user_marked: Boolean(r.user_marked),
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
// Distinct-target invariant after weighting: a group might collapse if
|
|
81
|
+
// weighting pulled all variants below minConf — re-check.
|
|
82
|
+
const distinctTargets = new Set(variants.map((v) => v.target_entity_id));
|
|
83
|
+
if (distinctTargets.size < 2)
|
|
84
|
+
continue;
|
|
85
|
+
// Try to resolve subject label (cheap join — single row per conflict).
|
|
86
|
+
let subjectLabel;
|
|
87
|
+
const entRow = db
|
|
88
|
+
.prepare(ENTITY_LABEL_SQL)
|
|
89
|
+
.get(g.source_entity_id);
|
|
90
|
+
if (entRow?.name)
|
|
91
|
+
subjectLabel = entRow.name;
|
|
92
|
+
const kind = distinctTargets.size > 2 ? "multi_target" : "direct";
|
|
93
|
+
conflicts.push({
|
|
94
|
+
kind,
|
|
95
|
+
subject_entity_id: g.source_entity_id,
|
|
96
|
+
subject_label: subjectLabel,
|
|
97
|
+
predicate: g.predicate,
|
|
98
|
+
variants,
|
|
99
|
+
detected_at: scanTs,
|
|
100
|
+
});
|
|
101
|
+
if (limit > 0 && conflicts.length >= limit)
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
return conflicts;
|
|
105
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 T4 — Evidence collector.
|
|
3
|
+
*
|
|
4
|
+
* Joins kg_relations.evidence_chunk_id → chunks.*, returning a ranked evidence
|
|
5
|
+
* bundle per conflict. Used by:
|
|
6
|
+
* - audit-writer (variants serialized into conflict_audit.variants JSON)
|
|
7
|
+
* - CLI `conflict show <id>`
|
|
8
|
+
* - HTTP `GET /api/conflict/:id`
|
|
9
|
+
*
|
|
10
|
+
* Ranking heuristic — within a single conflict, variants are returned in
|
|
11
|
+
* (a) created_at DESC (recency) then (b) confidence DESC — newer + higher
|
|
12
|
+
* confidence first. The weighted_score is informational: avg(relation.conf,
|
|
13
|
+
* chunk.conf) — surfaces "does the chunk back up the relation's confidence?"
|
|
14
|
+
*
|
|
15
|
+
* Snippet is truncated to DEFAULT_EVIDENCE_SNIPPET_LEN with an ellipsis marker.
|
|
16
|
+
* Caller can request full content via chunk_id lookup.
|
|
17
|
+
*/
|
|
18
|
+
import type { DBHandle } from "./db.js";
|
|
19
|
+
import { type Conflict, type ConflictEvidence } from "./types.js";
|
|
20
|
+
export interface CollectEvidenceOptions {
|
|
21
|
+
/** Snippet length cap. Default DEFAULT_EVIDENCE_SNIPPET_LEN (320). */
|
|
22
|
+
snippet_len?: number;
|
|
23
|
+
}
|
|
24
|
+
export declare function collectEvidence(db: DBHandle, conflict: Conflict, opts?: CollectEvidenceOptions): ConflictEvidence;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 T4 — Evidence collector.
|
|
3
|
+
*
|
|
4
|
+
* Joins kg_relations.evidence_chunk_id → chunks.*, returning a ranked evidence
|
|
5
|
+
* bundle per conflict. Used by:
|
|
6
|
+
* - audit-writer (variants serialized into conflict_audit.variants JSON)
|
|
7
|
+
* - CLI `conflict show <id>`
|
|
8
|
+
* - HTTP `GET /api/conflict/:id`
|
|
9
|
+
*
|
|
10
|
+
* Ranking heuristic — within a single conflict, variants are returned in
|
|
11
|
+
* (a) created_at DESC (recency) then (b) confidence DESC — newer + higher
|
|
12
|
+
* confidence first. The weighted_score is informational: avg(relation.conf,
|
|
13
|
+
* chunk.conf) — surfaces "does the chunk back up the relation's confidence?"
|
|
14
|
+
*
|
|
15
|
+
* Snippet is truncated to DEFAULT_EVIDENCE_SNIPPET_LEN with an ellipsis marker.
|
|
16
|
+
* Caller can request full content via chunk_id lookup.
|
|
17
|
+
*/
|
|
18
|
+
import { DEFAULT_EVIDENCE_SNIPPET_LEN, } from "./types.js";
|
|
19
|
+
export function collectEvidence(db, conflict, opts = {}) {
|
|
20
|
+
const snippetLen = opts.snippet_len ?? DEFAULT_EVIDENCE_SNIPPET_LEN;
|
|
21
|
+
if (snippetLen <= 0) {
|
|
22
|
+
throw new RangeError(`snippet_len must be > 0: ${snippetLen}`);
|
|
23
|
+
}
|
|
24
|
+
// Sort variants for stable display order.
|
|
25
|
+
const sorted = [...conflict.variants].sort((a, b) => {
|
|
26
|
+
if (b.created_at !== a.created_at)
|
|
27
|
+
return b.created_at - a.created_at;
|
|
28
|
+
return b.confidence - a.confidence;
|
|
29
|
+
});
|
|
30
|
+
const variants = sorted.map((v) => {
|
|
31
|
+
const chunks = [];
|
|
32
|
+
if (v.evidence_chunk_id != null) {
|
|
33
|
+
// Single-id IN clause — fake & real both accept this shape.
|
|
34
|
+
const rows = db
|
|
35
|
+
.prepare(`SELECT id, content, ts, source_session_id, confidence, provenance_kind FROM chunks WHERE id = ?`)
|
|
36
|
+
.all(v.evidence_chunk_id);
|
|
37
|
+
for (const r of rows) {
|
|
38
|
+
chunks.push({
|
|
39
|
+
chunk_id: r.id,
|
|
40
|
+
snippet: snippet(r.content, snippetLen),
|
|
41
|
+
full_length: r.content?.length ?? 0,
|
|
42
|
+
ts: r.ts,
|
|
43
|
+
source_session_id: r.source_session_id,
|
|
44
|
+
chunk_confidence: r.confidence,
|
|
45
|
+
provenance_kind: r.provenance_kind,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// weighted_score: avg of relation + chunk confidence (or relation alone if no chunk)
|
|
50
|
+
let weighted = v.confidence;
|
|
51
|
+
if (chunks.length > 0) {
|
|
52
|
+
const chunkConfs = chunks
|
|
53
|
+
.map((c) => c.chunk_confidence ?? null)
|
|
54
|
+
.filter((c) => c != null);
|
|
55
|
+
if (chunkConfs.length > 0) {
|
|
56
|
+
const avg = chunkConfs.reduce((a, b) => a + b, 0) / chunkConfs.length;
|
|
57
|
+
weighted = (v.confidence + avg) / 2;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { variant: v, chunks, weighted_score: weighted };
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
conflict_subject_entity_id: conflict.subject_entity_id,
|
|
64
|
+
predicate: conflict.predicate,
|
|
65
|
+
variants,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function snippet(content, max) {
|
|
69
|
+
if (!content)
|
|
70
|
+
return "";
|
|
71
|
+
// Collapse whitespace for a clean snippet — the original chunk is intact in DB.
|
|
72
|
+
const flat = content.replace(/\s+/g, " ").trim();
|
|
73
|
+
if (flat.length <= max)
|
|
74
|
+
return flat;
|
|
75
|
+
return flat.slice(0, max - 1).trimEnd() + "…";
|
|
76
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 conflict-detection — public re-exports.
|
|
3
|
+
*
|
|
4
|
+
* Consumers (CLI, HTTP, MCP, daemon) should import from here, not from
|
|
5
|
+
* sibling modules directly. This is the stable surface.
|
|
6
|
+
*/
|
|
7
|
+
export type { Conflict, ConflictAuditRow, ConflictEvidence, ConflictKind, ConflictMode, ConflictStatus, DetectorOptions, EvidenceChunk, ExtractionMethod, ResolutionInput, ResolutionKind, VariantEvidence, VariantRelation, } from "./types.js";
|
|
8
|
+
export { DEFAULT_CONFLICT_MODE, DEFAULT_EVIDENCE_SNIPPET_LEN, DEFAULT_MIN_CONFIDENCE, DEFAULT_SCAN_LIMIT, } from "./types.js";
|
|
9
|
+
export { detectDirectConflicts } from "./detector-direct.js";
|
|
10
|
+
export { collectEvidence } from "./evidence.js";
|
|
11
|
+
export { recordConflict, updateConflictStatus, getConflictById, listConflicts, statusCounts, type RecordOptions, type RecordResult, } from "./audit-writer.js";
|
|
12
|
+
export { resolveMode, runConflictPass, annotateRelations, getShadowTelemetry, getConflictsForRelations, makeConflictContext, type ConflictContext, type PassResult, type ShadowTelemetry, } from "./shadow.js";
|
|
13
|
+
export { parseCronExpression, nextRunAfter, shouldRunScan, runScheduledScan, type ParsedCron, type SchedulerOptions, type ScheduledRunResult, } from "./scheduler.js";
|
|
14
|
+
export type { DBHandle, PreparedStatement, RunResult } from "./db.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 conflict-detection — public re-exports.
|
|
3
|
+
*
|
|
4
|
+
* Consumers (CLI, HTTP, MCP, daemon) should import from here, not from
|
|
5
|
+
* sibling modules directly. This is the stable surface.
|
|
6
|
+
*/
|
|
7
|
+
export { DEFAULT_CONFLICT_MODE, DEFAULT_EVIDENCE_SNIPPET_LEN, DEFAULT_MIN_CONFIDENCE, DEFAULT_SCAN_LIMIT, } from "./types.js";
|
|
8
|
+
export { detectDirectConflicts } from "./detector-direct.js";
|
|
9
|
+
export { collectEvidence } from "./evidence.js";
|
|
10
|
+
export { recordConflict, updateConflictStatus, getConflictById, listConflicts, statusCounts, } from "./audit-writer.js";
|
|
11
|
+
export { resolveMode, runConflictPass, annotateRelations, getShadowTelemetry, getConflictsForRelations, makeConflictContext, } from "./shadow.js";
|
|
12
|
+
export { parseCronExpression, nextRunAfter, shouldRunScan, runScheduledScan, } from "./scheduler.js";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 T10 — Periodic scanner scaffolding (cron pattern).
|
|
3
|
+
*
|
|
4
|
+
* NOT an actual scheduler — daemon-side opt-in cron scaffold. The real
|
|
5
|
+
* nox-mem daemon is `nox-mem-api` (port 18802). This module exposes:
|
|
6
|
+
* - `parseCronExpression(expr)` — minimal validator + next-run calculator
|
|
7
|
+
* for the limited set of cron expressions we expect (M H * * *).
|
|
8
|
+
* - `shouldRunScan(now, lastRunAt, cronExpr, tzOffsetMinutes)` — pure
|
|
9
|
+
* decision function for "is it time to scan?"
|
|
10
|
+
* - `runScheduledScan(db, opts)` — idempotent scan wrapper that records
|
|
11
|
+
* the last-run timestamp.
|
|
12
|
+
*
|
|
13
|
+
* Default cron: `0 3 * * *` (03:00 BRT — after backup-all at 02:00).
|
|
14
|
+
* Env var: `NOX_CONFLICT_SCAN_CRON`.
|
|
15
|
+
*
|
|
16
|
+
* Idempotency: skipping conflicts already open is handled at audit-writer
|
|
17
|
+
* dedupe layer (see audit-writer.recordConflict). This module only handles
|
|
18
|
+
* "should the pass run now?" — not what to do once running.
|
|
19
|
+
*/
|
|
20
|
+
import type { DBHandle } from "./db.js";
|
|
21
|
+
import type { PassResult } from "./shadow.js";
|
|
22
|
+
import type { DetectorOptions, ConflictMode } from "./types.js";
|
|
23
|
+
export interface ParsedCron {
|
|
24
|
+
/** Minute 0-59 */
|
|
25
|
+
minute: number;
|
|
26
|
+
/** Hour 0-23 */
|
|
27
|
+
hour: number;
|
|
28
|
+
/** Day-of-month — '*' allowed; v1 only supports '*' */
|
|
29
|
+
dom: "*";
|
|
30
|
+
/** Month — '*' only */
|
|
31
|
+
month: "*";
|
|
32
|
+
/** Day-of-week — '*' only */
|
|
33
|
+
dow: "*";
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Parse a restricted cron expression `M H * * *`. v1 explicitly rejects
|
|
37
|
+
* non-trivial DOM/month/DOW patterns to keep the scheduler boring.
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseCronExpression(expr: string): ParsedCron;
|
|
40
|
+
/**
|
|
41
|
+
* Returns next-run unix-ms timestamp at or after `now`, in local timezone
|
|
42
|
+
* (caller passes tzOffsetMinutes relative to UTC; default -180 = BRT).
|
|
43
|
+
*/
|
|
44
|
+
export declare function nextRunAfter(now: number, cron: ParsedCron, tzOffsetMinutes?: number): number;
|
|
45
|
+
/**
|
|
46
|
+
* Should we run a scan now? True when `now >= nextRunAfter(lastRunAt)`.
|
|
47
|
+
* On first run (lastRunAt is null), returns true only if the scheduled
|
|
48
|
+
* time has already passed at least once today.
|
|
49
|
+
*/
|
|
50
|
+
export declare function shouldRunScan(now: number, lastRunAt: number | null, cron: ParsedCron, tzOffsetMinutes?: number): boolean;
|
|
51
|
+
export interface SchedulerState {
|
|
52
|
+
lastRunAt: number | null;
|
|
53
|
+
cron: ParsedCron;
|
|
54
|
+
tzOffsetMinutes: number;
|
|
55
|
+
mode: ConflictMode;
|
|
56
|
+
}
|
|
57
|
+
export interface SchedulerOptions {
|
|
58
|
+
cronExpr?: string;
|
|
59
|
+
tzOffsetMinutes?: number;
|
|
60
|
+
modeOverride?: ConflictMode;
|
|
61
|
+
detectorOpts?: DetectorOptions;
|
|
62
|
+
/** Test hook — current time. Defaults to Date.now(). */
|
|
63
|
+
now?: number;
|
|
64
|
+
/** Test hook — last-run timestamp from previous invocation. */
|
|
65
|
+
lastRunAt?: number | null;
|
|
66
|
+
}
|
|
67
|
+
export interface ScheduledRunResult {
|
|
68
|
+
ran: boolean;
|
|
69
|
+
reason: "first_run" | "due" | "not_due" | "disabled";
|
|
70
|
+
result: PassResult | null;
|
|
71
|
+
nextRunAt: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Decide-then-run scaffold. Caller manages persistence of lastRunAt
|
|
75
|
+
* (DB row, file, in-memory) and threads it through. Idempotent: same
|
|
76
|
+
* (now, lastRunAt) input returns the same decision.
|
|
77
|
+
*/
|
|
78
|
+
export declare function runScheduledScan(db: DBHandle, opts?: SchedulerOptions): ScheduledRunResult;
|