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,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/confidence/search-filter.ts — opt-in `--min-confidence` filter.
|
|
3
|
+
*
|
|
4
|
+
* Wired into search via CLI flag `--min-confidence 0.5`, HTTP query param
|
|
5
|
+
* `min_confidence=0.5`, MCP arg `min_confidence: 0.5`.
|
|
6
|
+
*
|
|
7
|
+
* Default: undefined (no filter). When set, chunks with confidence < threshold
|
|
8
|
+
* are removed from the search result set BEFORE ranking. This is purely
|
|
9
|
+
* additive and DOES NOT depend on NOX_RANKING_CONFIDENCE mode — caller-side
|
|
10
|
+
* choice, useful for "show me only high-trust facts" client UX.
|
|
11
|
+
*
|
|
12
|
+
* Threshold range: [0.0, 1.0]. Out-of-range values are clamped (loose
|
|
13
|
+
* validation; we never want to drop entire results due to typo).
|
|
14
|
+
*/
|
|
15
|
+
function clamp01(v) {
|
|
16
|
+
if (!Number.isFinite(v))
|
|
17
|
+
return 0;
|
|
18
|
+
return Math.min(1, Math.max(0, v));
|
|
19
|
+
}
|
|
20
|
+
/** Validates + normalises the threshold. Returns undefined to skip filtering. */
|
|
21
|
+
export function parseMinConfidence(raw) {
|
|
22
|
+
if (raw === undefined || raw === null)
|
|
23
|
+
return undefined;
|
|
24
|
+
let n;
|
|
25
|
+
if (typeof raw === "number")
|
|
26
|
+
n = raw;
|
|
27
|
+
else {
|
|
28
|
+
const parsed = parseFloat(raw);
|
|
29
|
+
if (!Number.isFinite(parsed))
|
|
30
|
+
return undefined;
|
|
31
|
+
n = parsed;
|
|
32
|
+
}
|
|
33
|
+
return clamp01(n);
|
|
34
|
+
}
|
|
35
|
+
/** Apply filter to a result set. Returns new array — does not mutate input. */
|
|
36
|
+
export function filterByConfidence(results, opts = {}) {
|
|
37
|
+
const threshold = opts.min_confidence ?? undefined;
|
|
38
|
+
const excludeNull = opts.exclude_null === true;
|
|
39
|
+
const excludeSuperseded = opts.exclude_superseded === true;
|
|
40
|
+
const excludeRefuted = opts.exclude_refuted === true;
|
|
41
|
+
if (threshold === undefined &&
|
|
42
|
+
!excludeNull &&
|
|
43
|
+
!excludeSuperseded &&
|
|
44
|
+
!excludeRefuted) {
|
|
45
|
+
return results; // no-op
|
|
46
|
+
}
|
|
47
|
+
return results.filter((r) => {
|
|
48
|
+
const conf = r.confidence;
|
|
49
|
+
const confIsNull = conf === null || conf === undefined;
|
|
50
|
+
if (excludeNull && confIsNull)
|
|
51
|
+
return false;
|
|
52
|
+
if (threshold !== undefined) {
|
|
53
|
+
if (confIsNull) {
|
|
54
|
+
// NULL counts as 0.8 baseline (DB default before v19); allow through
|
|
55
|
+
// unless excludeNull also requested.
|
|
56
|
+
if (0.8 < threshold)
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
else if (conf < threshold) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (excludeSuperseded) {
|
|
64
|
+
const sb = r.superseded_by;
|
|
65
|
+
if (sb !== null && sb !== undefined)
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
if (excludeRefuted) {
|
|
69
|
+
const kind = r.provenance_kind;
|
|
70
|
+
const c = confIsNull ? 0.8 : conf;
|
|
71
|
+
if (kind === "user-marked" && c < 0.3)
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Convenience: build the SQL WHERE clause fragment for direct DB-level
|
|
79
|
+
* filtering (more efficient than client-side). Returns null if no filter.
|
|
80
|
+
*
|
|
81
|
+
* Example output:
|
|
82
|
+
* { sql: "AND chunks.confidence >= ?", params: [0.5] }
|
|
83
|
+
*/
|
|
84
|
+
export function buildConfidenceWhereClause(opts) {
|
|
85
|
+
const fragments = [];
|
|
86
|
+
const params = [];
|
|
87
|
+
if (opts.min_confidence !== undefined && opts.min_confidence !== null) {
|
|
88
|
+
fragments.push("(chunks.confidence >= ? OR (chunks.confidence IS NULL AND 0.8 >= ?))");
|
|
89
|
+
params.push(opts.min_confidence, opts.min_confidence);
|
|
90
|
+
}
|
|
91
|
+
if (opts.exclude_null) {
|
|
92
|
+
fragments.push("chunks.confidence IS NOT NULL");
|
|
93
|
+
}
|
|
94
|
+
if (opts.exclude_superseded) {
|
|
95
|
+
fragments.push("chunks.superseded_by IS NULL");
|
|
96
|
+
}
|
|
97
|
+
if (opts.exclude_refuted) {
|
|
98
|
+
fragments.push("NOT (chunks.provenance_kind = 'user-marked' AND chunks.confidence < 0.3)");
|
|
99
|
+
}
|
|
100
|
+
if (fragments.length === 0)
|
|
101
|
+
return null;
|
|
102
|
+
return { sql: " AND " + fragments.join(" AND "), params };
|
|
103
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/confidence/types.ts — Public interfaces for L3 confidence + provenance.
|
|
3
|
+
*
|
|
4
|
+
* Schema reference: staged-migrations/v19.sql
|
|
5
|
+
* - chunks.confidence REAL DEFAULT 0.8 CHECK (0..1)
|
|
6
|
+
* - chunks.provenance_kind TEXT CHECK IN ('observed','declared','inferred','derived','user-marked') OR NULL
|
|
7
|
+
* - kg_relations.confidence REAL DEFAULT 0.7
|
|
8
|
+
* - kg_relations.superseded_by_relation_id INTEGER FK
|
|
9
|
+
* - kg_relations.superseded_at INTEGER (epoch_ms)
|
|
10
|
+
* - kg_relations.superseded_reason TEXT
|
|
11
|
+
* - kg_relations.created_at / updated_at INTEGER (epoch_ms)
|
|
12
|
+
* - kg_relations.extraction_method TEXT
|
|
13
|
+
*
|
|
14
|
+
* Spec reference: specs/2026-05-17-L3-confidence-field.md
|
|
15
|
+
*
|
|
16
|
+
* NB: The DB-level `user-marked` provenance is a SINGLE bucket; CLI exposes
|
|
17
|
+
* three sub-variants (canonical / refuted / stale) via different
|
|
18
|
+
* (confidence, provenance_kind) tuples — see write-hooks.ts and mark.ts.
|
|
19
|
+
*/
|
|
20
|
+
/** DB-level provenance enum (matches CHECK constraint in v19.sql). */
|
|
21
|
+
export type ProvenanceKind = "observed" | "declared" | "inferred" | "derived" | "user-marked";
|
|
22
|
+
/** Ingest-source enum — driver for write-side defaults. */
|
|
23
|
+
export type IngestSource = "entity-compiled" | "entity-frontmatter" | "entity-timeline" | "markdown" | "graphify" | "kg-extract" | "consolidate" | "crystallize" | "cli-explicit";
|
|
24
|
+
/** Mark-workflow operations available via CLI / HTTP / MCP. */
|
|
25
|
+
export type MarkKind = "canonical" | "refuted" | "stale";
|
|
26
|
+
/** Ranking integration mode — defaults to "disabled" per CLAUDE.md regra #5. */
|
|
27
|
+
export type RankingMode = "disabled" | "shadow" | "active";
|
|
28
|
+
/** Reason recorded when a chunk supersedes another (mirrors kg_relations.superseded_reason). */
|
|
29
|
+
export type SupersedeReason = "auto_supersede_temporal" | "manual_resolution" | "stale_link_reconciliation" | "dismiss";
|
|
30
|
+
/** Resolved configuration object (post env merge). */
|
|
31
|
+
export interface ConfidenceConfig {
|
|
32
|
+
/** Default confidence for observed chunks (witnessed/recorded). */
|
|
33
|
+
default_observed: number;
|
|
34
|
+
/** Default confidence for declared chunks (frontmatter/compiled truth). */
|
|
35
|
+
default_declared: number;
|
|
36
|
+
/** Default confidence for inferred chunks (LLM-extracted). */
|
|
37
|
+
default_inferred: number;
|
|
38
|
+
/** Default confidence for derived chunks (consolidate/crystallize). */
|
|
39
|
+
default_derived: number;
|
|
40
|
+
/** Default confidence for graphify-generated chunks. */
|
|
41
|
+
default_graphify: number;
|
|
42
|
+
/** Value applied to user_marked_canonical chunks. */
|
|
43
|
+
user_marked_canonical: number;
|
|
44
|
+
/** Value applied to user_marked_refuted chunks. */
|
|
45
|
+
user_marked_refuted: number;
|
|
46
|
+
/** Floor below which chunks are filtered out when ranking mode=active. */
|
|
47
|
+
active_floor: number;
|
|
48
|
+
/** Ranking integration mode. */
|
|
49
|
+
ranking_mode: RankingMode;
|
|
50
|
+
/** Optional half-life decay window (days). Disabled in v1 (-1). */
|
|
51
|
+
decay_halflife_days: number;
|
|
52
|
+
}
|
|
53
|
+
/** Input for write-side hooks — minimal chunk shape produced by ingest. */
|
|
54
|
+
export interface ChunkDataPartial {
|
|
55
|
+
/** Optional pre-existing confidence (rare; cli-explicit only). */
|
|
56
|
+
confidence?: number;
|
|
57
|
+
/** Optional pre-existing provenance kind. */
|
|
58
|
+
provenance_kind?: ProvenanceKind | null;
|
|
59
|
+
/** Pain field (used by ranking integration, decay rule). */
|
|
60
|
+
pain?: number;
|
|
61
|
+
/** Section field (already in schema v10). */
|
|
62
|
+
section?: string | null;
|
|
63
|
+
}
|
|
64
|
+
/** Output of applyConfidence() — chunk with confidence + provenance set. */
|
|
65
|
+
export interface ChunkDataWithConfidence extends ChunkDataPartial {
|
|
66
|
+
confidence: number;
|
|
67
|
+
provenance_kind: ProvenanceKind | null;
|
|
68
|
+
}
|
|
69
|
+
/** Extraction-metadata input from kg-extract pipeline. */
|
|
70
|
+
export interface ExtractionMetadata {
|
|
71
|
+
/** Confidence the LLM/regex extractor assigned. */
|
|
72
|
+
confidence?: number;
|
|
73
|
+
/** Extraction method (regex_only, gemini_only, ...). */
|
|
74
|
+
extraction_method?: string;
|
|
75
|
+
/** Whether this relation came from frontmatter (high-trust path). */
|
|
76
|
+
source_section?: "frontmatter" | "compiled" | "timeline" | "body";
|
|
77
|
+
}
|
|
78
|
+
/** Output for applyConfidenceToRelation(). */
|
|
79
|
+
export interface RelationDataWithConfidence {
|
|
80
|
+
confidence: number;
|
|
81
|
+
extraction_method?: string;
|
|
82
|
+
provenance_kind: ProvenanceKind;
|
|
83
|
+
}
|
|
84
|
+
/** Mark-operation request shape. */
|
|
85
|
+
export interface MarkOpts {
|
|
86
|
+
/** Chunk id to mark. */
|
|
87
|
+
chunk_id: number;
|
|
88
|
+
/** Kind of mark. */
|
|
89
|
+
kind: MarkKind;
|
|
90
|
+
/** Optional free-text note (logged to ops_audit). */
|
|
91
|
+
notes?: string;
|
|
92
|
+
}
|
|
93
|
+
/** Supersede-operation request shape. */
|
|
94
|
+
export interface SupersedeOpts {
|
|
95
|
+
/** Older chunk being superseded. */
|
|
96
|
+
chunk_id: number;
|
|
97
|
+
/** Newer chunk that replaces it. */
|
|
98
|
+
by_chunk_id: number;
|
|
99
|
+
/** Optional reason text. */
|
|
100
|
+
notes?: string;
|
|
101
|
+
}
|
|
102
|
+
/** Result of a mark/supersede write — returned to API/CLI/MCP layer. */
|
|
103
|
+
export interface MarkResult {
|
|
104
|
+
ok: true;
|
|
105
|
+
chunk_id: number;
|
|
106
|
+
applied: {
|
|
107
|
+
confidence: number;
|
|
108
|
+
provenance_kind: ProvenanceKind;
|
|
109
|
+
superseded_by?: number | null;
|
|
110
|
+
};
|
|
111
|
+
audit_id: number;
|
|
112
|
+
}
|
|
113
|
+
/** Telemetry slice exposed on /api/health. */
|
|
114
|
+
export interface ConfidenceHealthSlice {
|
|
115
|
+
provenance: {
|
|
116
|
+
observed: number;
|
|
117
|
+
declared: number;
|
|
118
|
+
inferred: number;
|
|
119
|
+
derived: number;
|
|
120
|
+
"user-marked": number;
|
|
121
|
+
null: number;
|
|
122
|
+
};
|
|
123
|
+
confidence_distribution: {
|
|
124
|
+
mean: number;
|
|
125
|
+
p25: number;
|
|
126
|
+
p50: number;
|
|
127
|
+
p75: number;
|
|
128
|
+
p95: number;
|
|
129
|
+
stddev: number;
|
|
130
|
+
};
|
|
131
|
+
superseded_count: number;
|
|
132
|
+
ranking_mode: RankingMode;
|
|
133
|
+
}
|
|
134
|
+
/** Eval result delta-row stored in confidence_eval_log table (v22). */
|
|
135
|
+
export interface ConfidenceEvalDelta {
|
|
136
|
+
/** Query id from golden set (e.g., "GS-042"). */
|
|
137
|
+
query_id: string;
|
|
138
|
+
/** Variant label: 'A','B','C','D' (see spec §6). */
|
|
139
|
+
variant: "A" | "B" | "C" | "D";
|
|
140
|
+
/** nDCG@10 score for this run. */
|
|
141
|
+
ndcg_at_10: number;
|
|
142
|
+
/** Delta vs baseline A (0 for variant A itself). */
|
|
143
|
+
delta_vs_baseline: number;
|
|
144
|
+
/** ISO timestamp when run captured. */
|
|
145
|
+
ran_at: string;
|
|
146
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/confidence/types.ts — Public interfaces for L3 confidence + provenance.
|
|
3
|
+
*
|
|
4
|
+
* Schema reference: staged-migrations/v19.sql
|
|
5
|
+
* - chunks.confidence REAL DEFAULT 0.8 CHECK (0..1)
|
|
6
|
+
* - chunks.provenance_kind TEXT CHECK IN ('observed','declared','inferred','derived','user-marked') OR NULL
|
|
7
|
+
* - kg_relations.confidence REAL DEFAULT 0.7
|
|
8
|
+
* - kg_relations.superseded_by_relation_id INTEGER FK
|
|
9
|
+
* - kg_relations.superseded_at INTEGER (epoch_ms)
|
|
10
|
+
* - kg_relations.superseded_reason TEXT
|
|
11
|
+
* - kg_relations.created_at / updated_at INTEGER (epoch_ms)
|
|
12
|
+
* - kg_relations.extraction_method TEXT
|
|
13
|
+
*
|
|
14
|
+
* Spec reference: specs/2026-05-17-L3-confidence-field.md
|
|
15
|
+
*
|
|
16
|
+
* NB: The DB-level `user-marked` provenance is a SINGLE bucket; CLI exposes
|
|
17
|
+
* three sub-variants (canonical / refuted / stale) via different
|
|
18
|
+
* (confidence, provenance_kind) tuples — see write-hooks.ts and mark.ts.
|
|
19
|
+
*/
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/confidence/write-hooks.ts — write-side hooks for L3.
|
|
3
|
+
*
|
|
4
|
+
* Two responsibilities:
|
|
5
|
+
* 1. applyConfidence(chunk, source) — set confidence + provenance on insert,
|
|
6
|
+
* driven by the IngestSource (entity-compiled / markdown / graphify / ...)
|
|
7
|
+
* 2. applyConfidenceToRelation(rel, meta) — set kg_relations.confidence from
|
|
8
|
+
* the kg-extract extraction_metadata (already present in v19).
|
|
9
|
+
*
|
|
10
|
+
* Mapping from IngestSource → (confidence, provenance_kind) follows
|
|
11
|
+
* spec §4a (routing table). Callers (ingest-router, kg-extract, consolidate,
|
|
12
|
+
* crystallize) call this BEFORE persistence.
|
|
13
|
+
*
|
|
14
|
+
* Per spec §4 + §11, these hooks NEVER overwrite an existing explicit value —
|
|
15
|
+
* cli-explicit takes precedence; legacy chunks with pre-set confidence pass
|
|
16
|
+
* through untouched.
|
|
17
|
+
*/
|
|
18
|
+
import type { ChunkDataPartial, ChunkDataWithConfidence, ConfidenceConfig, ExtractionMetadata, IngestSource, ProvenanceKind, RelationDataWithConfidence } from "./types.js";
|
|
19
|
+
/** Returns (confidence, provenance_kind) tuple for the given ingest source. */
|
|
20
|
+
export declare function defaultsForSource(source: IngestSource, cfg: ConfidenceConfig): {
|
|
21
|
+
confidence: number;
|
|
22
|
+
provenance_kind: ProvenanceKind | null;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* applyConfidence() — fills confidence + provenance on a chunk-data object.
|
|
26
|
+
*
|
|
27
|
+
* Behaviour:
|
|
28
|
+
* - If chunkData.confidence is ALREADY set (not undefined, not null), preserve it.
|
|
29
|
+
* - Otherwise use defaults from the IngestSource.
|
|
30
|
+
* - confidence is always clamp01'd as final guard.
|
|
31
|
+
*
|
|
32
|
+
* Returns a NEW object — never mutates input.
|
|
33
|
+
*/
|
|
34
|
+
export declare function applyConfidence(chunkData: ChunkDataPartial, source: IngestSource, cfgOverride?: ConfidenceConfig): ChunkDataWithConfidence;
|
|
35
|
+
/**
|
|
36
|
+
* applyConfidenceToRelation() — fills confidence on a kg_relation insert.
|
|
37
|
+
*
|
|
38
|
+
* The v19 schema gives kg_relations.confidence DEFAULT 0.7. We override based
|
|
39
|
+
* on the ExtractionMetadata that the kg-extract pipeline already produces:
|
|
40
|
+
*
|
|
41
|
+
* - If meta.confidence is explicit, use it (clamped)
|
|
42
|
+
* - Else if extraction_method='frontmatter', confidence = default_declared (0.9)
|
|
43
|
+
* - Else if extraction_method='regex_only', confidence = 0.85 (regex deterministic)
|
|
44
|
+
* - Else if extraction_method='manual', confidence = 1.0
|
|
45
|
+
* - Else (gemini_only / regex_primary_gemini_secondary), default_inferred (0.65)
|
|
46
|
+
*
|
|
47
|
+
* provenance_kind: 'inferred' for LLM-extracted; 'observed' for manual or
|
|
48
|
+
* regex_only (deterministic); 'declared' for frontmatter.
|
|
49
|
+
*/
|
|
50
|
+
export declare function applyConfidenceToRelation(meta?: ExtractionMetadata, cfgOverride?: ConfidenceConfig): RelationDataWithConfidence;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/confidence/write-hooks.ts — write-side hooks for L3.
|
|
3
|
+
*
|
|
4
|
+
* Two responsibilities:
|
|
5
|
+
* 1. applyConfidence(chunk, source) — set confidence + provenance on insert,
|
|
6
|
+
* driven by the IngestSource (entity-compiled / markdown / graphify / ...)
|
|
7
|
+
* 2. applyConfidenceToRelation(rel, meta) — set kg_relations.confidence from
|
|
8
|
+
* the kg-extract extraction_metadata (already present in v19).
|
|
9
|
+
*
|
|
10
|
+
* Mapping from IngestSource → (confidence, provenance_kind) follows
|
|
11
|
+
* spec §4a (routing table). Callers (ingest-router, kg-extract, consolidate,
|
|
12
|
+
* crystallize) call this BEFORE persistence.
|
|
13
|
+
*
|
|
14
|
+
* Per spec §4 + §11, these hooks NEVER overwrite an existing explicit value —
|
|
15
|
+
* cli-explicit takes precedence; legacy chunks with pre-set confidence pass
|
|
16
|
+
* through untouched.
|
|
17
|
+
*/
|
|
18
|
+
import { clamp01, resolveConfig } from "./config.js";
|
|
19
|
+
/** Returns (confidence, provenance_kind) tuple for the given ingest source. */
|
|
20
|
+
export function defaultsForSource(source, cfg) {
|
|
21
|
+
switch (source) {
|
|
22
|
+
case "entity-compiled":
|
|
23
|
+
case "entity-frontmatter":
|
|
24
|
+
return {
|
|
25
|
+
confidence: cfg.default_declared,
|
|
26
|
+
provenance_kind: "declared",
|
|
27
|
+
};
|
|
28
|
+
case "entity-timeline":
|
|
29
|
+
return {
|
|
30
|
+
confidence: cfg.default_observed,
|
|
31
|
+
provenance_kind: "observed",
|
|
32
|
+
};
|
|
33
|
+
case "markdown":
|
|
34
|
+
// Generic markdown → confidence 0.8 floor (legacy default), NULL kind.
|
|
35
|
+
return { confidence: 0.8, provenance_kind: null };
|
|
36
|
+
case "graphify":
|
|
37
|
+
return {
|
|
38
|
+
confidence: cfg.default_graphify,
|
|
39
|
+
provenance_kind: "derived",
|
|
40
|
+
};
|
|
41
|
+
case "kg-extract":
|
|
42
|
+
return {
|
|
43
|
+
confidence: cfg.default_inferred,
|
|
44
|
+
provenance_kind: "inferred",
|
|
45
|
+
};
|
|
46
|
+
case "consolidate":
|
|
47
|
+
return {
|
|
48
|
+
confidence: cfg.default_derived,
|
|
49
|
+
provenance_kind: "derived",
|
|
50
|
+
};
|
|
51
|
+
case "crystallize":
|
|
52
|
+
// crystallize produces summarised truth — slight bump over consolidate
|
|
53
|
+
return {
|
|
54
|
+
confidence: Math.min(cfg.default_derived + 0.1, 1.0),
|
|
55
|
+
provenance_kind: "derived",
|
|
56
|
+
};
|
|
57
|
+
case "cli-explicit":
|
|
58
|
+
// Caller MUST pass confidence + provenance via chunkData; we no-op here.
|
|
59
|
+
return { confidence: 0.8, provenance_kind: null };
|
|
60
|
+
default: {
|
|
61
|
+
// Exhaustiveness check — never reach
|
|
62
|
+
const _exhaustive = source;
|
|
63
|
+
void _exhaustive;
|
|
64
|
+
return { confidence: 0.8, provenance_kind: null };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* applyConfidence() — fills confidence + provenance on a chunk-data object.
|
|
70
|
+
*
|
|
71
|
+
* Behaviour:
|
|
72
|
+
* - If chunkData.confidence is ALREADY set (not undefined, not null), preserve it.
|
|
73
|
+
* - Otherwise use defaults from the IngestSource.
|
|
74
|
+
* - confidence is always clamp01'd as final guard.
|
|
75
|
+
*
|
|
76
|
+
* Returns a NEW object — never mutates input.
|
|
77
|
+
*/
|
|
78
|
+
export function applyConfidence(chunkData, source, cfgOverride) {
|
|
79
|
+
const cfg = cfgOverride ?? resolveConfig();
|
|
80
|
+
const defaults = defaultsForSource(source, cfg);
|
|
81
|
+
const hasExplicitConf = chunkData.confidence !== undefined && chunkData.confidence !== null;
|
|
82
|
+
const hasExplicitKind = chunkData.provenance_kind !== undefined &&
|
|
83
|
+
chunkData.provenance_kind !== null;
|
|
84
|
+
const confidence = clamp01(hasExplicitConf ? chunkData.confidence : defaults.confidence);
|
|
85
|
+
const provenance_kind = hasExplicitKind
|
|
86
|
+
? chunkData.provenance_kind
|
|
87
|
+
: defaults.provenance_kind;
|
|
88
|
+
return {
|
|
89
|
+
...chunkData,
|
|
90
|
+
confidence,
|
|
91
|
+
provenance_kind,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* applyConfidenceToRelation() — fills confidence on a kg_relation insert.
|
|
96
|
+
*
|
|
97
|
+
* The v19 schema gives kg_relations.confidence DEFAULT 0.7. We override based
|
|
98
|
+
* on the ExtractionMetadata that the kg-extract pipeline already produces:
|
|
99
|
+
*
|
|
100
|
+
* - If meta.confidence is explicit, use it (clamped)
|
|
101
|
+
* - Else if extraction_method='frontmatter', confidence = default_declared (0.9)
|
|
102
|
+
* - Else if extraction_method='regex_only', confidence = 0.85 (regex deterministic)
|
|
103
|
+
* - Else if extraction_method='manual', confidence = 1.0
|
|
104
|
+
* - Else (gemini_only / regex_primary_gemini_secondary), default_inferred (0.65)
|
|
105
|
+
*
|
|
106
|
+
* provenance_kind: 'inferred' for LLM-extracted; 'observed' for manual or
|
|
107
|
+
* regex_only (deterministic); 'declared' for frontmatter.
|
|
108
|
+
*/
|
|
109
|
+
export function applyConfidenceToRelation(meta = {}, cfgOverride) {
|
|
110
|
+
const cfg = cfgOverride ?? resolveConfig();
|
|
111
|
+
// Explicit confidence wins (clamped).
|
|
112
|
+
if (typeof meta.confidence === "number" && Number.isFinite(meta.confidence)) {
|
|
113
|
+
const c = clamp01(meta.confidence);
|
|
114
|
+
return {
|
|
115
|
+
confidence: c,
|
|
116
|
+
extraction_method: meta.extraction_method,
|
|
117
|
+
provenance_kind: pickProvenanceForMethod(meta.extraction_method),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const method = meta.extraction_method;
|
|
121
|
+
const section = meta.source_section;
|
|
122
|
+
let confidence;
|
|
123
|
+
let provenance_kind;
|
|
124
|
+
if (section === "frontmatter" || method === "frontmatter") {
|
|
125
|
+
confidence = cfg.default_declared;
|
|
126
|
+
provenance_kind = "declared";
|
|
127
|
+
}
|
|
128
|
+
else if (method === "manual") {
|
|
129
|
+
confidence = 1.0;
|
|
130
|
+
provenance_kind = "observed";
|
|
131
|
+
}
|
|
132
|
+
else if (method === "regex_only") {
|
|
133
|
+
confidence = 0.85;
|
|
134
|
+
provenance_kind = "observed";
|
|
135
|
+
}
|
|
136
|
+
else if (method === "gemini_only" ||
|
|
137
|
+
method === "regex_primary_gemini_secondary") {
|
|
138
|
+
confidence = cfg.default_inferred;
|
|
139
|
+
provenance_kind = "inferred";
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
confidence = cfg.default_inferred;
|
|
143
|
+
provenance_kind = "inferred";
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
confidence: clamp01(confidence),
|
|
147
|
+
extraction_method: method,
|
|
148
|
+
provenance_kind,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function pickProvenanceForMethod(method) {
|
|
152
|
+
if (method === "frontmatter")
|
|
153
|
+
return "declared";
|
|
154
|
+
if (method === "manual")
|
|
155
|
+
return "observed";
|
|
156
|
+
if (method === "regex_only")
|
|
157
|
+
return "observed";
|
|
158
|
+
return "inferred";
|
|
159
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* G15 — conflict_audit FK validation (Wave G)
|
|
3
|
+
*
|
|
4
|
+
* BACKGROUND
|
|
5
|
+
* `conflict_audit.target_relation_ids` is a JSON array of `kg_relations.id`
|
|
6
|
+
* values (string-encoded). The v21 schema explicitly chose to skip a hard
|
|
7
|
+
* foreign-key for cheap migration cost — but means INSERT accepts any
|
|
8
|
+
* integer, including non-existent FK ids ("dangling" audit rows).
|
|
9
|
+
*
|
|
10
|
+
* Same risk applies to:
|
|
11
|
+
* - `picked_relation_id` (resolution: pick_one)
|
|
12
|
+
* - `subject_entity_id` (FK kg_entities.id)
|
|
13
|
+
*
|
|
14
|
+
* THREAT (G15, R-L2-2.1)
|
|
15
|
+
* Attacker (or buggy writer) inserts a row referencing a deleted/never-
|
|
16
|
+
* existed relation. Downstream `evidence.ts` then yields empty
|
|
17
|
+
* evidence — confusing analysts and breaking the audit chain.
|
|
18
|
+
*
|
|
19
|
+
* FIX
|
|
20
|
+
* 1. Validation function `validateConflictAuditFK(db, conflict)` — runs the
|
|
21
|
+
* check ahead of any INSERT/UPDATE; returns the list of missing ids
|
|
22
|
+
* (empty = pass). Caller (audit-writer.ts) decides to reject or warn.
|
|
23
|
+
* 2. Plus a CHECK constraint addendum SQL (v25 migration) that enforces
|
|
24
|
+
* JSON shape — array of positive integers. Existence check must remain
|
|
25
|
+
* in code (SQLite CHECK can't reach across tables in pre-3.x SQLite
|
|
26
|
+
* and is brittle even with FK pragma).
|
|
27
|
+
*
|
|
28
|
+
* Backward compat:
|
|
29
|
+
* - Function is opt-in — caller can wrap audit-writer.ts INSERT_SQL with
|
|
30
|
+
* a pre-flight call.
|
|
31
|
+
* - JSON shape CHECK is additive; rolls back via v25-rollback.sql.
|
|
32
|
+
*/
|
|
33
|
+
export interface ConflictAuditFKInput {
|
|
34
|
+
subject_entity_id: number;
|
|
35
|
+
target_relation_ids: number[];
|
|
36
|
+
/** Optional. Only validated when present (resolution path). */
|
|
37
|
+
picked_relation_id?: number | null;
|
|
38
|
+
}
|
|
39
|
+
export interface FKValidationResult {
|
|
40
|
+
valid: boolean;
|
|
41
|
+
/** subject_entity_id missing in kg_entities? */
|
|
42
|
+
missingSubject: boolean;
|
|
43
|
+
/** Subset of target_relation_ids not found in kg_relations. */
|
|
44
|
+
missingRelationIds: number[];
|
|
45
|
+
/** True if picked_relation_id was supplied and not found. */
|
|
46
|
+
missingPicked: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface DBHandleMinimal {
|
|
49
|
+
prepare: (sql: string) => {
|
|
50
|
+
all: (...params: unknown[]) => Array<{
|
|
51
|
+
id: number;
|
|
52
|
+
}>;
|
|
53
|
+
get: (...params: unknown[]) => unknown;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Run all FK existence checks for a conflict_audit row. Pure read-only.
|
|
58
|
+
*
|
|
59
|
+
* Performance: O(1) prepared statements; single query per category.
|
|
60
|
+
* No `IN (?, ?, ...)` placeholder explosion — uses `json_each` instead.
|
|
61
|
+
*/
|
|
62
|
+
export declare function validateConflictAuditFK(db: DBHandleMinimal, input: ConflictAuditFKInput): FKValidationResult;
|
|
63
|
+
/**
|
|
64
|
+
* Drop-in helper for audit-writer.ts. Throws a structured Error on FK
|
|
65
|
+
* miss so the caller can `try/catch` and map to a 4xx.
|
|
66
|
+
*/
|
|
67
|
+
export declare class ConflictAuditFKError extends Error {
|
|
68
|
+
readonly result: FKValidationResult;
|
|
69
|
+
constructor(result: FKValidationResult);
|
|
70
|
+
}
|
|
71
|
+
export declare function assertConflictAuditFK(db: DBHandleMinimal, input: ConflictAuditFKInput): void;
|
|
72
|
+
export declare const JSON_SHAPE_CHECK_SQL = "\n-- v25-conflict-audit-json-shape.sql (G15 addendum)\n-- Adds a CHECK constraint to conflict_audit.target_relation_ids guaranteeing\n-- the column is a non-empty JSON array of positive integers.\n--\n-- SQLite limitation: ALTER TABLE ADD CONSTRAINT is unsupported, so this\n-- ships as a trigger instead (BEFORE INSERT/UPDATE OF target_relation_ids).\n\nBEGIN;\n\nDROP TRIGGER IF EXISTS trg_conflict_audit_target_relation_ids_shape;\nCREATE TRIGGER trg_conflict_audit_target_relation_ids_shape\nBEFORE INSERT ON conflict_audit\nBEGIN\n SELECT\n CASE\n WHEN json_valid(NEW.target_relation_ids) = 0\n OR json_type(NEW.target_relation_ids) != 'array'\n OR (\n SELECT COUNT(*)\n FROM json_each(NEW.target_relation_ids)\n WHERE typeof(value) != 'integer' OR value <= 0\n ) > 0\n OR (SELECT COUNT(*) FROM json_each(NEW.target_relation_ids)) = 0\n THEN RAISE(ABORT, 'conflict_audit.target_relation_ids must be a non-empty JSON array of positive integers (G15)')\n END;\nEND;\n\nPRAGMA user_version = 25;\n\nCOMMIT;\n";
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* G15 — conflict_audit FK validation (Wave G)
|
|
3
|
+
*
|
|
4
|
+
* BACKGROUND
|
|
5
|
+
* `conflict_audit.target_relation_ids` is a JSON array of `kg_relations.id`
|
|
6
|
+
* values (string-encoded). The v21 schema explicitly chose to skip a hard
|
|
7
|
+
* foreign-key for cheap migration cost — but means INSERT accepts any
|
|
8
|
+
* integer, including non-existent FK ids ("dangling" audit rows).
|
|
9
|
+
*
|
|
10
|
+
* Same risk applies to:
|
|
11
|
+
* - `picked_relation_id` (resolution: pick_one)
|
|
12
|
+
* - `subject_entity_id` (FK kg_entities.id)
|
|
13
|
+
*
|
|
14
|
+
* THREAT (G15, R-L2-2.1)
|
|
15
|
+
* Attacker (or buggy writer) inserts a row referencing a deleted/never-
|
|
16
|
+
* existed relation. Downstream `evidence.ts` then yields empty
|
|
17
|
+
* evidence — confusing analysts and breaking the audit chain.
|
|
18
|
+
*
|
|
19
|
+
* FIX
|
|
20
|
+
* 1. Validation function `validateConflictAuditFK(db, conflict)` — runs the
|
|
21
|
+
* check ahead of any INSERT/UPDATE; returns the list of missing ids
|
|
22
|
+
* (empty = pass). Caller (audit-writer.ts) decides to reject or warn.
|
|
23
|
+
* 2. Plus a CHECK constraint addendum SQL (v25 migration) that enforces
|
|
24
|
+
* JSON shape — array of positive integers. Existence check must remain
|
|
25
|
+
* in code (SQLite CHECK can't reach across tables in pre-3.x SQLite
|
|
26
|
+
* and is brittle even with FK pragma).
|
|
27
|
+
*
|
|
28
|
+
* Backward compat:
|
|
29
|
+
* - Function is opt-in — caller can wrap audit-writer.ts INSERT_SQL with
|
|
30
|
+
* a pre-flight call.
|
|
31
|
+
* - JSON shape CHECK is additive; rolls back via v25-rollback.sql.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Run all FK existence checks for a conflict_audit row. Pure read-only.
|
|
35
|
+
*
|
|
36
|
+
* Performance: O(1) prepared statements; single query per category.
|
|
37
|
+
* No `IN (?, ?, ...)` placeholder explosion — uses `json_each` instead.
|
|
38
|
+
*/
|
|
39
|
+
export function validateConflictAuditFK(db, input) {
|
|
40
|
+
// 1. subject_entity_id check.
|
|
41
|
+
const subjectRow = db
|
|
42
|
+
.prepare("SELECT id FROM kg_entities WHERE id = ?")
|
|
43
|
+
.get(input.subject_entity_id);
|
|
44
|
+
const missingSubject = !subjectRow;
|
|
45
|
+
// 2. target_relation_ids — bulk existence query.
|
|
46
|
+
const targets = input.target_relation_ids ?? [];
|
|
47
|
+
let missingRelationIds = [];
|
|
48
|
+
if (targets.length > 0) {
|
|
49
|
+
const idsJson = JSON.stringify(targets);
|
|
50
|
+
const existing = db
|
|
51
|
+
.prepare("SELECT kr.id AS id FROM kg_relations kr WHERE kr.id IN (SELECT value FROM json_each(?))")
|
|
52
|
+
.all(idsJson);
|
|
53
|
+
const existingSet = new Set(existing.map((r) => r.id));
|
|
54
|
+
missingRelationIds = targets.filter((id) => !existingSet.has(id));
|
|
55
|
+
}
|
|
56
|
+
// 3. picked_relation_id (resolution path).
|
|
57
|
+
let missingPicked = false;
|
|
58
|
+
if (input.picked_relation_id !== undefined &&
|
|
59
|
+
input.picked_relation_id !== null) {
|
|
60
|
+
const row = db
|
|
61
|
+
.prepare("SELECT id FROM kg_relations WHERE id = ?")
|
|
62
|
+
.get(input.picked_relation_id);
|
|
63
|
+
missingPicked = !row;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
valid: !missingSubject && missingRelationIds.length === 0 && !missingPicked,
|
|
67
|
+
missingSubject,
|
|
68
|
+
missingRelationIds,
|
|
69
|
+
missingPicked,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Drop-in helper for audit-writer.ts. Throws a structured Error on FK
|
|
74
|
+
* miss so the caller can `try/catch` and map to a 4xx.
|
|
75
|
+
*/
|
|
76
|
+
export class ConflictAuditFKError extends Error {
|
|
77
|
+
result;
|
|
78
|
+
constructor(result) {
|
|
79
|
+
super(`conflict_audit FK validation failed: ${JSON.stringify({
|
|
80
|
+
missingSubject: result.missingSubject,
|
|
81
|
+
missingRelationIds: result.missingRelationIds,
|
|
82
|
+
missingPicked: result.missingPicked,
|
|
83
|
+
})}`);
|
|
84
|
+
this.name = "ConflictAuditFKError";
|
|
85
|
+
this.result = result;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export function assertConflictAuditFK(db, input) {
|
|
89
|
+
const r = validateConflictAuditFK(db, input);
|
|
90
|
+
if (!r.valid)
|
|
91
|
+
throw new ConflictAuditFKError(r);
|
|
92
|
+
}
|
|
93
|
+
// ── SQL addendum: JSON shape CHECK (optional v25 migration) ────────────────
|
|
94
|
+
//
|
|
95
|
+
// SQLite CHECK constraint can verify that `target_relation_ids` parses as a
|
|
96
|
+
// JSON array of positive integers. Existence checks remain code-side.
|
|
97
|
+
//
|
|
98
|
+
// This SQL is exported as a string so callers can compose it into a future
|
|
99
|
+
// v25 migration if desired. Not auto-applied here (additive, opt-in).
|
|
100
|
+
export const JSON_SHAPE_CHECK_SQL = `
|
|
101
|
+
-- v25-conflict-audit-json-shape.sql (G15 addendum)
|
|
102
|
+
-- Adds a CHECK constraint to conflict_audit.target_relation_ids guaranteeing
|
|
103
|
+
-- the column is a non-empty JSON array of positive integers.
|
|
104
|
+
--
|
|
105
|
+
-- SQLite limitation: ALTER TABLE ADD CONSTRAINT is unsupported, so this
|
|
106
|
+
-- ships as a trigger instead (BEFORE INSERT/UPDATE OF target_relation_ids).
|
|
107
|
+
|
|
108
|
+
BEGIN;
|
|
109
|
+
|
|
110
|
+
DROP TRIGGER IF EXISTS trg_conflict_audit_target_relation_ids_shape;
|
|
111
|
+
CREATE TRIGGER trg_conflict_audit_target_relation_ids_shape
|
|
112
|
+
BEFORE INSERT ON conflict_audit
|
|
113
|
+
BEGIN
|
|
114
|
+
SELECT
|
|
115
|
+
CASE
|
|
116
|
+
WHEN json_valid(NEW.target_relation_ids) = 0
|
|
117
|
+
OR json_type(NEW.target_relation_ids) != 'array'
|
|
118
|
+
OR (
|
|
119
|
+
SELECT COUNT(*)
|
|
120
|
+
FROM json_each(NEW.target_relation_ids)
|
|
121
|
+
WHERE typeof(value) != 'integer' OR value <= 0
|
|
122
|
+
) > 0
|
|
123
|
+
OR (SELECT COUNT(*) FROM json_each(NEW.target_relation_ids)) = 0
|
|
124
|
+
THEN RAISE(ABORT, 'conflict_audit.target_relation_ids must be a non-empty JSON array of positive integers (G15)')
|
|
125
|
+
END;
|
|
126
|
+
END;
|
|
127
|
+
|
|
128
|
+
PRAGMA user_version = 25;
|
|
129
|
+
|
|
130
|
+
COMMIT;
|
|
131
|
+
`;
|