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,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T2 — DIR_PATTERN + entity-ref regexes.
|
|
3
|
+
*
|
|
4
|
+
* Adapted from gbrain/src/core/link-extraction.ts (MIT). Adjusted for nox-mem
|
|
5
|
+
* entity-type whitelist (specs/2026-05-18-L4-regex-first-extraction.md §4).
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: All consumer regexes carry the global flag (`g`). Always reset
|
|
8
|
+
* `.lastIndex = 0` before reuse or instantiate a fresh RegExp; callers in
|
|
9
|
+
* extractor.ts do so by constructing per call via {@link buildEntityRefRe}.
|
|
10
|
+
*/
|
|
11
|
+
import { NOX_ENTITY_TYPES } from "./types.js";
|
|
12
|
+
/** `(?:feedback|person|...)` literal alternation snippet — non-capturing. */
|
|
13
|
+
export const DIR_PATTERN = `(?:${NOX_ENTITY_TYPES.filter((t) => t !== "entities").join("|")})`;
|
|
14
|
+
/** Top-level dir prefix `entities/` is optional in wikilinks. */
|
|
15
|
+
export const OPTIONAL_TOP = `(?:entities\\/)?`;
|
|
16
|
+
/** Slug character class: letters, digits, underscore, dash. NO dots (drops `.md`). */
|
|
17
|
+
export const SLUG_CHARS = `[a-z0-9_\\-]+`;
|
|
18
|
+
/**
|
|
19
|
+
* Markdown-link form: `[Name](path/to/entityType/slug)`, optional `.md`, optional
|
|
20
|
+
* tooltip `"..."`. Path may have `../` prefix.
|
|
21
|
+
*
|
|
22
|
+
* Groups:
|
|
23
|
+
* 1 — display text
|
|
24
|
+
* 2 — entity type
|
|
25
|
+
* 3 — slug (no .md, no anchor)
|
|
26
|
+
*/
|
|
27
|
+
export function buildMarkdownLinkRe() {
|
|
28
|
+
return new RegExp(String.raw `\[([^\]\n]+?)\]\(` +
|
|
29
|
+
String.raw `(?:\.{1,2}\/)*` +
|
|
30
|
+
`(?:entities\\/)?` +
|
|
31
|
+
`(${DIR_PATTERN})\\/` +
|
|
32
|
+
`(${SLUG_CHARS})` +
|
|
33
|
+
String.raw `(?:\.md)?` +
|
|
34
|
+
String.raw `(?:#[^)\s]*)?` +
|
|
35
|
+
String.raw `(?:\s+"[^"]*")?` +
|
|
36
|
+
String.raw `\)`, "g");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Obsidian wikilink form: `[[entityType/slug]]`, optional `entities/` prefix,
|
|
40
|
+
* optional `#anchor`, optional `|display`. Accept ASCII-aware slugs only —
|
|
41
|
+
* Unicode boundary issues handled in extractor via stripping non-slug chars.
|
|
42
|
+
*
|
|
43
|
+
* Groups:
|
|
44
|
+
* 1 — entity type
|
|
45
|
+
* 2 — slug
|
|
46
|
+
* 3 — display (after `|`, optional)
|
|
47
|
+
*/
|
|
48
|
+
export function buildWikilinkRe() {
|
|
49
|
+
return new RegExp(String.raw `\[\[` +
|
|
50
|
+
`(?:entities\\/)?` +
|
|
51
|
+
`(${DIR_PATTERN})\\/` +
|
|
52
|
+
`(${SLUG_CHARS})` +
|
|
53
|
+
String.raw `(?:#[^|\]\n]*)?` +
|
|
54
|
+
String.raw `(?:\|([^\]\n]+?))?` +
|
|
55
|
+
String.raw `\]\]`, "g");
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Bare slug form: standalone `entityType/slug` token, only when surrounded by
|
|
59
|
+
* whitespace/start/punctuation boundary. Uses lookbehind/lookahead WITHOUT
|
|
60
|
+
* `\b` (MEMORY.md `JS regex \b falha em Unicode`).
|
|
61
|
+
*
|
|
62
|
+
* Tightly anchored to avoid URL false-positives — disallow `/` directly before
|
|
63
|
+
* the token (so `example.com/feedback/foo` does NOT match).
|
|
64
|
+
*
|
|
65
|
+
* Groups:
|
|
66
|
+
* 1 — entity type
|
|
67
|
+
* 2 — slug
|
|
68
|
+
*/
|
|
69
|
+
export function buildBareRefRe() {
|
|
70
|
+
return new RegExp(`(?<=^|[\\s(,;:'"\`])` +
|
|
71
|
+
`(${DIR_PATTERN})\\/` +
|
|
72
|
+
`(${SLUG_CHARS})` +
|
|
73
|
+
`(?=$|[\\s).,?!;:'"\`])`, "gm");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Code-path references (`src/lib/op-audit.ts:42`, `specs/foo.md`). Domain dirs
|
|
77
|
+
* are whitelisted to suppress matches against unrelated path-like text.
|
|
78
|
+
*
|
|
79
|
+
* Groups:
|
|
80
|
+
* 1 — top-level dir
|
|
81
|
+
* 2 — path under root (extension included)
|
|
82
|
+
* 3 — extension
|
|
83
|
+
* 4 — line number (optional)
|
|
84
|
+
*/
|
|
85
|
+
export function buildCodeRefRe() {
|
|
86
|
+
return new RegExp(`(?<=^|[\\s(,;:'"\`])` +
|
|
87
|
+
`(src|specs|audits|eval|validation|memory|paper|docs|runbooks|scripts|lessons|benchmark)` +
|
|
88
|
+
`\\/` +
|
|
89
|
+
`([a-z0-9_\\-\\/\\.]+\\.(ts|js|md|sh|json|yaml|yml|sql|py))` +
|
|
90
|
+
`(?::(\\d+))?`, "gmi");
|
|
91
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T9 — Production wire-up: regex extractor as FAST-PATH before LLM extraction.
|
|
3
|
+
*
|
|
4
|
+
* Hooks the regex extractor into the existing `ingestFile()` pipeline as a
|
|
5
|
+
* fast-path check BEFORE calling Gemini for KG extraction.
|
|
6
|
+
*
|
|
7
|
+
* Decision rule (spec §7 + T9):
|
|
8
|
+
* If regex extraction confidence ≥ CONFIDENCE_THRESHOLD (0.8):
|
|
9
|
+
* - Typed link from frontmatter (is_agent_of, supersedes, etc.) → confidence=0.95
|
|
10
|
+
* - Explicit [[wikilink]] or [md-link](slug) → confidence=0.90
|
|
11
|
+
* - Bare ref `entityType/slug` → confidence=0.75 (below threshold → falls through)
|
|
12
|
+
* → SKIP Gemini for this chunk
|
|
13
|
+
* Else:
|
|
14
|
+
* → Fall through to LLM (existing path)
|
|
15
|
+
*
|
|
16
|
+
* Telemetry: `extraction_method` logged per kg_relations row.
|
|
17
|
+
*
|
|
18
|
+
* This module is a pure adapter — it wraps `decideExtraction` with the
|
|
19
|
+
* confidence-gate logic and returns a wire-compatible result. The production
|
|
20
|
+
* `ingestFile()` router imports this and acts on the decision.
|
|
21
|
+
*
|
|
22
|
+
* Spec: specs/2026-05-18-L4-regex-first-extraction.md §3, §7, T9.
|
|
23
|
+
*/
|
|
24
|
+
import { type ChunkContext, type IngestDecision } from "./ingest-router-l4.js";
|
|
25
|
+
import { type EntityRef, type FrontmatterRelation } from "./types.js";
|
|
26
|
+
/**
|
|
27
|
+
* Minimum confidence required to skip LLM extraction.
|
|
28
|
+
* Below this, fall through to Gemini (existing path).
|
|
29
|
+
*/
|
|
30
|
+
export declare const CONFIDENCE_THRESHOLD = 0.8;
|
|
31
|
+
/** Confidence for frontmatter typed-link relations (highest precision). */
|
|
32
|
+
export declare const CONFIDENCE_FRONTMATTER = 0.95;
|
|
33
|
+
/** Confidence for explicit [[wikilink]] or [md-link](slug) matches. */
|
|
34
|
+
export declare const CONFIDENCE_EXPLICIT_LINK = 0.9;
|
|
35
|
+
/** Confidence for bare `entityType/slug` references. */
|
|
36
|
+
export declare const CONFIDENCE_BARE_REF = 0.75;
|
|
37
|
+
/**
|
|
38
|
+
* Confidence-scored relation ready for kg_relations insert.
|
|
39
|
+
* All fields are production-wire compatible (no DB types imported here).
|
|
40
|
+
*/
|
|
41
|
+
export interface ScoredRelation {
|
|
42
|
+
/** Source entity slug (chunk-owning entity). */
|
|
43
|
+
sourceSlug: string;
|
|
44
|
+
/** Target entity slug. */
|
|
45
|
+
targetSlug: string;
|
|
46
|
+
/** Relation type. */
|
|
47
|
+
relationType: string;
|
|
48
|
+
/** Confidence score [0.0, 1.0]. */
|
|
49
|
+
confidence: number;
|
|
50
|
+
/** Extraction method for telemetry. */
|
|
51
|
+
extraction_method: "regex" | "llm";
|
|
52
|
+
/** Raw reason tag for kg_relations.relation_reason. */
|
|
53
|
+
relation_reason: "regex_extracted" | "gemini_extracted";
|
|
54
|
+
}
|
|
55
|
+
/** Wire-compatible result from the fast-path check. */
|
|
56
|
+
export interface ProductionWireResult {
|
|
57
|
+
/** Relations from regex with confidence scores. */
|
|
58
|
+
regexRelations: ScoredRelation[];
|
|
59
|
+
/** Maximum confidence seen in any relation (gate decision basis). */
|
|
60
|
+
maxConfidence: number;
|
|
61
|
+
/** Whether to skip the LLM call (max confidence ≥ threshold). */
|
|
62
|
+
skipLlm: boolean;
|
|
63
|
+
/** Extraction decision from decideExtraction (for telemetry). */
|
|
64
|
+
decision: IngestDecision;
|
|
65
|
+
/** Telemetry fields for logging to kg_relations. */
|
|
66
|
+
telemetry: {
|
|
67
|
+
extraction_method: "regex_only" | "gemini_only" | "regex_primary_gemini_secondary" | "gemini_only_after_regex_zero";
|
|
68
|
+
regex_relations_count: number;
|
|
69
|
+
gemini_call_skipped: boolean;
|
|
70
|
+
latency_ms_regex: number;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Compute confidence for a single entity ref based on its source pattern.
|
|
75
|
+
* Spec §7: frontmatter > explicit link > bare ref.
|
|
76
|
+
*/
|
|
77
|
+
export declare function scoreEntityRef(ref: EntityRef): number;
|
|
78
|
+
/**
|
|
79
|
+
* Compute confidence for a frontmatter-derived typed relation.
|
|
80
|
+
* Frontmatter fields are explicitly authored → highest precision.
|
|
81
|
+
*/
|
|
82
|
+
export declare function scoreFrontmatterRelation(_rel: FrontmatterRelation): number;
|
|
83
|
+
/**
|
|
84
|
+
* Run the regex fast-path check for a chunk.
|
|
85
|
+
*
|
|
86
|
+
* 1. Calls `decideExtraction` to get regex hits and LLM skip decision.
|
|
87
|
+
* 2. Scores each relation by confidence.
|
|
88
|
+
* 3. If max confidence ≥ CONFIDENCE_THRESHOLD → skipLlm=true.
|
|
89
|
+
* 4. Returns scored relations ready for kg_relations insert.
|
|
90
|
+
*
|
|
91
|
+
* @param chunk Chunk metadata + content.
|
|
92
|
+
* @param sourceSlug The entity slug this chunk belongs to (for FK resolution).
|
|
93
|
+
*/
|
|
94
|
+
export declare function runProductionFastPath(chunk: ChunkContext, sourceSlug: string): ProductionWireResult;
|
|
95
|
+
/**
|
|
96
|
+
* Filter a list of scored relations to only those above the confidence gate.
|
|
97
|
+
* Used when merging regex + LLM output — only high-confidence regex relations
|
|
98
|
+
* suppress their LLM counterparts.
|
|
99
|
+
*/
|
|
100
|
+
export declare function filterHighConfidence(relations: ScoredRelation[], threshold?: number): ScoredRelation[];
|
|
101
|
+
/**
|
|
102
|
+
* Build a dedup key for a relation — used to merge regex + LLM output.
|
|
103
|
+
* Key = `<sourceSlug>|<targetSlug>|<relationType>` (case-insensitive).
|
|
104
|
+
*/
|
|
105
|
+
export declare function relationDedupKey(r: {
|
|
106
|
+
sourceSlug: string;
|
|
107
|
+
targetSlug: string;
|
|
108
|
+
relationType: string;
|
|
109
|
+
}): string;
|
|
110
|
+
/**
|
|
111
|
+
* Merge regex scored relations with LLM relations. Deduplicates by key,
|
|
112
|
+
* preferring high-confidence regex entries over LLM for the same triple.
|
|
113
|
+
*/
|
|
114
|
+
export declare function mergeWithLlmRelations(regexRelations: ScoredRelation[], llmRelations: Array<{
|
|
115
|
+
sourceSlug: string;
|
|
116
|
+
targetSlug: string;
|
|
117
|
+
relationType: string;
|
|
118
|
+
}>): ScoredRelation[];
|
|
119
|
+
/**
|
|
120
|
+
* Returns true when the L4 regex feature is enabled via env flag.
|
|
121
|
+
* Feature is opt-in via `NOX_L4_REGEX_ENABLED=1`.
|
|
122
|
+
*/
|
|
123
|
+
export declare function isRegexEnabled(): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Returns true when the skip-Gemini gate is enabled.
|
|
126
|
+
* Requires both `NOX_L4_REGEX_ENABLED=1` AND `NOX_L4_SKIP_GEMINI=1`.
|
|
127
|
+
*/
|
|
128
|
+
export declare function isSkipGeminiEnabled(): boolean;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T9 — Production wire-up: regex extractor as FAST-PATH before LLM extraction.
|
|
3
|
+
*
|
|
4
|
+
* Hooks the regex extractor into the existing `ingestFile()` pipeline as a
|
|
5
|
+
* fast-path check BEFORE calling Gemini for KG extraction.
|
|
6
|
+
*
|
|
7
|
+
* Decision rule (spec §7 + T9):
|
|
8
|
+
* If regex extraction confidence ≥ CONFIDENCE_THRESHOLD (0.8):
|
|
9
|
+
* - Typed link from frontmatter (is_agent_of, supersedes, etc.) → confidence=0.95
|
|
10
|
+
* - Explicit [[wikilink]] or [md-link](slug) → confidence=0.90
|
|
11
|
+
* - Bare ref `entityType/slug` → confidence=0.75 (below threshold → falls through)
|
|
12
|
+
* → SKIP Gemini for this chunk
|
|
13
|
+
* Else:
|
|
14
|
+
* → Fall through to LLM (existing path)
|
|
15
|
+
*
|
|
16
|
+
* Telemetry: `extraction_method` logged per kg_relations row.
|
|
17
|
+
*
|
|
18
|
+
* This module is a pure adapter — it wraps `decideExtraction` with the
|
|
19
|
+
* confidence-gate logic and returns a wire-compatible result. The production
|
|
20
|
+
* `ingestFile()` router imports this and acts on the decision.
|
|
21
|
+
*
|
|
22
|
+
* Spec: specs/2026-05-18-L4-regex-first-extraction.md §3, §7, T9.
|
|
23
|
+
*/
|
|
24
|
+
import { decideExtraction } from "./ingest-router-l4.js";
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Confidence thresholds
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
/**
|
|
29
|
+
* Minimum confidence required to skip LLM extraction.
|
|
30
|
+
* Below this, fall through to Gemini (existing path).
|
|
31
|
+
*/
|
|
32
|
+
export const CONFIDENCE_THRESHOLD = 0.8;
|
|
33
|
+
/** Confidence for frontmatter typed-link relations (highest precision). */
|
|
34
|
+
export const CONFIDENCE_FRONTMATTER = 0.95;
|
|
35
|
+
/** Confidence for explicit [[wikilink]] or [md-link](slug) matches. */
|
|
36
|
+
export const CONFIDENCE_EXPLICIT_LINK = 0.90;
|
|
37
|
+
/** Confidence for bare `entityType/slug` references. */
|
|
38
|
+
export const CONFIDENCE_BARE_REF = 0.75;
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Confidence scoring
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
/**
|
|
43
|
+
* Compute confidence for a single entity ref based on its source pattern.
|
|
44
|
+
* Spec §7: frontmatter > explicit link > bare ref.
|
|
45
|
+
*/
|
|
46
|
+
export function scoreEntityRef(ref) {
|
|
47
|
+
switch (ref.source) {
|
|
48
|
+
case "markdown_link":
|
|
49
|
+
case "wikilink":
|
|
50
|
+
return CONFIDENCE_EXPLICIT_LINK;
|
|
51
|
+
case "bare_ref":
|
|
52
|
+
return CONFIDENCE_BARE_REF;
|
|
53
|
+
default:
|
|
54
|
+
return CONFIDENCE_BARE_REF;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Compute confidence for a frontmatter-derived typed relation.
|
|
59
|
+
* Frontmatter fields are explicitly authored → highest precision.
|
|
60
|
+
*/
|
|
61
|
+
export function scoreFrontmatterRelation(_rel) {
|
|
62
|
+
return CONFIDENCE_FRONTMATTER;
|
|
63
|
+
}
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
// Core fast-path check
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
/**
|
|
68
|
+
* Run the regex fast-path check for a chunk.
|
|
69
|
+
*
|
|
70
|
+
* 1. Calls `decideExtraction` to get regex hits and LLM skip decision.
|
|
71
|
+
* 2. Scores each relation by confidence.
|
|
72
|
+
* 3. If max confidence ≥ CONFIDENCE_THRESHOLD → skipLlm=true.
|
|
73
|
+
* 4. Returns scored relations ready for kg_relations insert.
|
|
74
|
+
*
|
|
75
|
+
* @param chunk Chunk metadata + content.
|
|
76
|
+
* @param sourceSlug The entity slug this chunk belongs to (for FK resolution).
|
|
77
|
+
*/
|
|
78
|
+
export function runProductionFastPath(chunk, sourceSlug) {
|
|
79
|
+
const decision = decideExtraction(chunk);
|
|
80
|
+
const { regex } = decision;
|
|
81
|
+
const regexRelations = [];
|
|
82
|
+
let maxConfidence = 0;
|
|
83
|
+
// Score frontmatter relations (highest confidence).
|
|
84
|
+
for (const rel of regex.frontmatterRelations) {
|
|
85
|
+
const confidence = scoreFrontmatterRelation(rel);
|
|
86
|
+
maxConfidence = Math.max(maxConfidence, confidence);
|
|
87
|
+
regexRelations.push({
|
|
88
|
+
sourceSlug,
|
|
89
|
+
targetSlug: rel.target,
|
|
90
|
+
relationType: rel.relationType,
|
|
91
|
+
confidence,
|
|
92
|
+
extraction_method: "regex",
|
|
93
|
+
relation_reason: "regex_extracted",
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
// Score entity refs (wikilink/markdown_link/bare_ref).
|
|
97
|
+
for (const ref of regex.entityRefs) {
|
|
98
|
+
const confidence = scoreEntityRef(ref);
|
|
99
|
+
maxConfidence = Math.max(maxConfidence, confidence);
|
|
100
|
+
regexRelations.push({
|
|
101
|
+
sourceSlug,
|
|
102
|
+
targetSlug: ref.key,
|
|
103
|
+
relationType: "references",
|
|
104
|
+
confidence,
|
|
105
|
+
extraction_method: "regex",
|
|
106
|
+
relation_reason: "regex_extracted",
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
// Code refs: treated as bare-ref confidence level.
|
|
110
|
+
for (const cref of regex.codeRefs) {
|
|
111
|
+
const confidence = CONFIDENCE_BARE_REF;
|
|
112
|
+
maxConfidence = Math.max(maxConfidence, confidence);
|
|
113
|
+
regexRelations.push({
|
|
114
|
+
sourceSlug,
|
|
115
|
+
targetSlug: cref.key,
|
|
116
|
+
relationType: "code_ref",
|
|
117
|
+
confidence,
|
|
118
|
+
extraction_method: "regex",
|
|
119
|
+
relation_reason: "regex_extracted",
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
// Override skip decision: also check our confidence gate.
|
|
123
|
+
// decideExtraction may say skipGemini=true via section/type gate;
|
|
124
|
+
// we additionally require maxConfidence ≥ CONFIDENCE_THRESHOLD.
|
|
125
|
+
const skipLlm = decision.skipGemini && maxConfidence >= CONFIDENCE_THRESHOLD;
|
|
126
|
+
const telemetry = {
|
|
127
|
+
extraction_method: skipLlm
|
|
128
|
+
? "regex_only"
|
|
129
|
+
: decision.telemetry.extraction_method,
|
|
130
|
+
regex_relations_count: regexRelations.length,
|
|
131
|
+
gemini_call_skipped: skipLlm,
|
|
132
|
+
latency_ms_regex: decision.telemetry.latency_ms.regex,
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
regexRelations,
|
|
136
|
+
maxConfidence,
|
|
137
|
+
skipLlm,
|
|
138
|
+
decision,
|
|
139
|
+
telemetry,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
// Filter helpers (for production ingestFile() integration)
|
|
144
|
+
// ---------------------------------------------------------------------------
|
|
145
|
+
/**
|
|
146
|
+
* Filter a list of scored relations to only those above the confidence gate.
|
|
147
|
+
* Used when merging regex + LLM output — only high-confidence regex relations
|
|
148
|
+
* suppress their LLM counterparts.
|
|
149
|
+
*/
|
|
150
|
+
export function filterHighConfidence(relations, threshold = CONFIDENCE_THRESHOLD) {
|
|
151
|
+
return relations.filter((r) => r.confidence >= threshold);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Build a dedup key for a relation — used to merge regex + LLM output.
|
|
155
|
+
* Key = `<sourceSlug>|<targetSlug>|<relationType>` (case-insensitive).
|
|
156
|
+
*/
|
|
157
|
+
export function relationDedupKey(r) {
|
|
158
|
+
return `${r.sourceSlug}|${r.targetSlug}|${r.relationType}`.toLowerCase();
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Merge regex scored relations with LLM relations. Deduplicates by key,
|
|
162
|
+
* preferring high-confidence regex entries over LLM for the same triple.
|
|
163
|
+
*/
|
|
164
|
+
export function mergeWithLlmRelations(regexRelations, llmRelations) {
|
|
165
|
+
const seen = new Map();
|
|
166
|
+
// Regex first (higher priority for dedup).
|
|
167
|
+
for (const r of regexRelations) {
|
|
168
|
+
const k = relationDedupKey(r);
|
|
169
|
+
if (!seen.has(k))
|
|
170
|
+
seen.set(k, r);
|
|
171
|
+
}
|
|
172
|
+
// LLM fills gaps not covered by regex.
|
|
173
|
+
for (const r of llmRelations) {
|
|
174
|
+
const k = relationDedupKey(r);
|
|
175
|
+
if (!seen.has(k)) {
|
|
176
|
+
seen.set(k, {
|
|
177
|
+
...r,
|
|
178
|
+
confidence: 0.7, // default LLM confidence
|
|
179
|
+
extraction_method: "llm",
|
|
180
|
+
relation_reason: "gemini_extracted",
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return Array.from(seen.values());
|
|
185
|
+
}
|
|
186
|
+
// ---------------------------------------------------------------------------
|
|
187
|
+
// Env-flag helpers
|
|
188
|
+
// ---------------------------------------------------------------------------
|
|
189
|
+
/**
|
|
190
|
+
* Returns true when the L4 regex feature is enabled via env flag.
|
|
191
|
+
* Feature is opt-in via `NOX_L4_REGEX_ENABLED=1`.
|
|
192
|
+
*/
|
|
193
|
+
export function isRegexEnabled() {
|
|
194
|
+
return process.env["NOX_L4_REGEX_ENABLED"] === "1";
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Returns true when the skip-Gemini gate is enabled.
|
|
198
|
+
* Requires both `NOX_L4_REGEX_ENABLED=1` AND `NOX_L4_SKIP_GEMINI=1`.
|
|
199
|
+
*/
|
|
200
|
+
export function isSkipGeminiEnabled() {
|
|
201
|
+
return isRegexEnabled() && process.env["NOX_L4_SKIP_GEMINI"] === "1";
|
|
202
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T7 — Stale-link reconciliation on entity file update.
|
|
3
|
+
*
|
|
4
|
+
* When an entity file is renamed or edited, links pointing to the old slug may
|
|
5
|
+
* become stale. This module handles two modes:
|
|
6
|
+
*
|
|
7
|
+
* - stale-mark (default): sets `confidence` to STALE_CONFIDENCE + adds a
|
|
8
|
+
* `superseded_by` pointer to the new slug in each affected relation.
|
|
9
|
+
* - auto-rename (env `NOX_L4_AUTO_RENAME=1`): rewrites old slug → new slug
|
|
10
|
+
* across all affected kg_relations records.
|
|
11
|
+
*
|
|
12
|
+
* CRITICAL: auto-rename is DESTRUCTIVE — must require explicit env opt-in.
|
|
13
|
+
* Default is stale-mark (append-only philosophy per CLAUDE.md regra 6).
|
|
14
|
+
*
|
|
15
|
+
* Spec: specs/2026-05-18-L4-regex-first-extraction.md §8.
|
|
16
|
+
*/
|
|
17
|
+
/** Confidence assigned to stale relations (low — known stale). */
|
|
18
|
+
export declare const STALE_CONFIDENCE = 0.3;
|
|
19
|
+
/**
|
|
20
|
+
* Reason string written to superseded_reason when stale-marking a relation.
|
|
21
|
+
* Matches the reason used in the stale-link reconciliation flow (spec §8).
|
|
22
|
+
*/
|
|
23
|
+
export declare const STALE_REASON = "stale_link_reconciliation";
|
|
24
|
+
/** A single KG relation as seen by the reconciler (minimal projection). */
|
|
25
|
+
export interface ReconcilerRelation {
|
|
26
|
+
/** Composite key identifying this relation: `<sourceSlug>|<targetSlug>|<relationType>`. */
|
|
27
|
+
key: string;
|
|
28
|
+
/** Source entity slug (e.g. `feedback/no_secrets`). */
|
|
29
|
+
sourceSlug: string;
|
|
30
|
+
/** Target entity slug (e.g. `decision/d41`). */
|
|
31
|
+
targetSlug: string;
|
|
32
|
+
/** Relation type label. */
|
|
33
|
+
relationType: string;
|
|
34
|
+
/** Extraction method tag (only regex-extracted rels are managed by this reconciler). */
|
|
35
|
+
extraction_method: "regex" | "gemini" | string;
|
|
36
|
+
/** Current confidence score (0.0-1.0). */
|
|
37
|
+
confidence: number;
|
|
38
|
+
/** Whether already superseded. */
|
|
39
|
+
superseded?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** Discriminated reconciliation action. */
|
|
42
|
+
export type ReconcileAction = {
|
|
43
|
+
type: "mark_stale";
|
|
44
|
+
relation: ReconcilerRelation;
|
|
45
|
+
/** New confidence value written (STALE_CONFIDENCE). */
|
|
46
|
+
newConfidence: number;
|
|
47
|
+
/** Reason written to superseded_reason. */
|
|
48
|
+
supersededReason: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: "auto_rename";
|
|
51
|
+
relation: ReconcilerRelation;
|
|
52
|
+
/** Old target slug being replaced. */
|
|
53
|
+
oldTargetSlug: string;
|
|
54
|
+
/** New target slug replacing the old one. */
|
|
55
|
+
newTargetSlug: string;
|
|
56
|
+
} | {
|
|
57
|
+
type: "add";
|
|
58
|
+
/** New target slug extracted from updated content. */
|
|
59
|
+
targetSlug: string;
|
|
60
|
+
relationType: string;
|
|
61
|
+
} | {
|
|
62
|
+
type: "noop";
|
|
63
|
+
targetSlug: string;
|
|
64
|
+
};
|
|
65
|
+
/** Full reconciliation result. */
|
|
66
|
+
export interface ReconcileResult {
|
|
67
|
+
actions: ReconcileAction[];
|
|
68
|
+
/** Relations newly found (adds). */
|
|
69
|
+
added: string[];
|
|
70
|
+
/** Relations removed from active content (marked stale or auto-renamed). */
|
|
71
|
+
removed: string[];
|
|
72
|
+
/** Relations unchanged. */
|
|
73
|
+
unchanged: string[];
|
|
74
|
+
/** Operating mode used. */
|
|
75
|
+
mode: "stale_mark" | "auto_rename";
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Derive the full set of target slugs found in `content` via regex extraction
|
|
79
|
+
* (entity refs + frontmatter relations combined). Code refs are excluded from
|
|
80
|
+
* reconciliation — they're not direct KG entity slugs.
|
|
81
|
+
*/
|
|
82
|
+
export declare function extractTargetSlugsFromContent(content: string): Set<string>;
|
|
83
|
+
export interface ReconcileOptions {
|
|
84
|
+
/**
|
|
85
|
+
* If true, auto-rename is enabled (env `NOX_L4_AUTO_RENAME=1`).
|
|
86
|
+
* Default: false (stale-mark mode).
|
|
87
|
+
*
|
|
88
|
+
* CRITICAL: auto-rename rewrites relations in-place. Never default to true.
|
|
89
|
+
*/
|
|
90
|
+
autoRename?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* When autoRename=true and the old slug has been replaced by a known new
|
|
93
|
+
* slug, pass it here so the auto-rename action can record the mapping.
|
|
94
|
+
* If not provided, stale-mark is used even in auto-rename mode.
|
|
95
|
+
*/
|
|
96
|
+
newSlug?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Reconcile kg_relations for a given entity when its content changes.
|
|
100
|
+
*
|
|
101
|
+
* Algorithm (spec §8):
|
|
102
|
+
* 1. Extract new target slugs from `newContent` via regex.
|
|
103
|
+
* 2. Diff `existingRelations` vs new slug set:
|
|
104
|
+
* - Added: in new set, not in existing → emit `add` action.
|
|
105
|
+
* - Removed: in existing (regex_extracted only), not in new set → emit
|
|
106
|
+
* `mark_stale` or `auto_rename` action.
|
|
107
|
+
* - Unchanged: present in both → emit `noop`.
|
|
108
|
+
* 3. Gemini relations (extraction_method='gemini') are NEVER touched —
|
|
109
|
+
* deferred to next Gemini run.
|
|
110
|
+
* 4. Already-superseded relations are skipped.
|
|
111
|
+
*
|
|
112
|
+
* @param sourceSlug The entity being reconciled (e.g. `feedback/no_secrets`).
|
|
113
|
+
* @param newContent New markdown content of the entity file.
|
|
114
|
+
* @param existingRelations Current `kg_relations` rows for this entity.
|
|
115
|
+
* @param opts Reconcile options.
|
|
116
|
+
*/
|
|
117
|
+
export declare function reconcileEntityLinks(sourceSlug: string, newContent: string, existingRelations: ReconcilerRelation[], opts?: ReconcileOptions): ReconcileResult;
|
|
118
|
+
/**
|
|
119
|
+
* Detect whether an entity slug has changed between two content snapshots by
|
|
120
|
+
* comparing the `slug` frontmatter field (or the first heading). Returns the
|
|
121
|
+
* detected new slug if different, null if no change detected.
|
|
122
|
+
*
|
|
123
|
+
* This is a lightweight heuristic — the definitive source is the filesystem
|
|
124
|
+
* rename event from the watcher. Use this as a sanity check.
|
|
125
|
+
*/
|
|
126
|
+
export declare function detectSlugChange(oldContent: string, newContent: string): {
|
|
127
|
+
changed: boolean;
|
|
128
|
+
oldSlug: string | null;
|
|
129
|
+
newSlug: string | null;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Apply auto-rename across a set of chunk texts that reference `oldSlug`.
|
|
133
|
+
* Rewrites `oldSlug` → `newSlug` in:
|
|
134
|
+
* - Markdown links `[label](oldSlug)`
|
|
135
|
+
* - Wikilinks `[[oldSlug]]`
|
|
136
|
+
* - Bare refs ` oldSlug ` (boundary-sensitive)
|
|
137
|
+
*
|
|
138
|
+
* Returns an array of results: `{ chunkId, original, rewritten, changed }`.
|
|
139
|
+
*
|
|
140
|
+
* CRITICAL: Only call when `NOX_L4_AUTO_RENAME=1`. The caller is responsible
|
|
141
|
+
* for writing the rewritten texts back to the DB.
|
|
142
|
+
*/
|
|
143
|
+
export interface ChunkRewriteResult {
|
|
144
|
+
chunkId: string;
|
|
145
|
+
original: string;
|
|
146
|
+
rewritten: string;
|
|
147
|
+
changed: boolean;
|
|
148
|
+
}
|
|
149
|
+
export declare function rewriteChunksForRename(chunks: Array<{
|
|
150
|
+
chunkId: string;
|
|
151
|
+
content: string;
|
|
152
|
+
}>, oldSlug: string, newSlug: string): ChunkRewriteResult[];
|
|
153
|
+
/**
|
|
154
|
+
* Validate a sequence of renames for circular dependencies.
|
|
155
|
+
* Returns an error string if a cycle is detected, null otherwise.
|
|
156
|
+
*
|
|
157
|
+
* A cycle exists when following rename chain A→B→C→A.
|
|
158
|
+
*/
|
|
159
|
+
export declare function detectCircularRename(renames: Array<{
|
|
160
|
+
from: string;
|
|
161
|
+
to: string;
|
|
162
|
+
}>): string | null;
|