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,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T3 + T5 — Entity ref + code-path extractors.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions: no IO, no DB, no async. Caller composes with stripCodeBlocks
|
|
5
|
+
* (default) and frontmatter parsing in the router (T6).
|
|
6
|
+
*
|
|
7
|
+
* Adapted from gbrain/src/core/link-extraction.ts (MIT) — adjusted to nox-mem
|
|
8
|
+
* domain (DIR_PATTERN whitelist, FK-id resolution deferred to router).
|
|
9
|
+
*
|
|
10
|
+
* Spec: specs/2026-05-18-L4-regex-first-extraction.md §6.2-§6.4.
|
|
11
|
+
*/
|
|
12
|
+
import { CodeRef, EntityRef } from "./types.js";
|
|
13
|
+
/**
|
|
14
|
+
* Pure regex-based entity-ref extractor.
|
|
15
|
+
*
|
|
16
|
+
* Pipeline:
|
|
17
|
+
* 1. stripCodeBlocks (suppress matches inside ```code```)
|
|
18
|
+
* 2. Markdown links `[Name](type/slug)`
|
|
19
|
+
* 3. Obsidian wikilinks `[[type/slug|Display]]`
|
|
20
|
+
* 4. Bare refs `type/slug` (boundary-anchored)
|
|
21
|
+
* 5. Dedupe by canonical key
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractEntityRefsRegex(content: string): EntityRef[];
|
|
24
|
+
/**
|
|
25
|
+
* T5 — extract code-path references (`src/foo.ts:42`, `specs/X.md`).
|
|
26
|
+
*
|
|
27
|
+
* Stripped of code fences first (gbrain pattern — avoid recursive matches
|
|
28
|
+
* inside example fences).
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractCodeRefs(content: string): CodeRef[];
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T3 + T5 — Entity ref + code-path extractors.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions: no IO, no DB, no async. Caller composes with stripCodeBlocks
|
|
5
|
+
* (default) and frontmatter parsing in the router (T6).
|
|
6
|
+
*
|
|
7
|
+
* Adapted from gbrain/src/core/link-extraction.ts (MIT) — adjusted to nox-mem
|
|
8
|
+
* domain (DIR_PATTERN whitelist, FK-id resolution deferred to router).
|
|
9
|
+
*
|
|
10
|
+
* Spec: specs/2026-05-18-L4-regex-first-extraction.md §6.2-§6.4.
|
|
11
|
+
*/
|
|
12
|
+
import { stripCodeBlocks } from "./strip-code.js";
|
|
13
|
+
import { buildBareRefRe, buildCodeRefRe, buildMarkdownLinkRe, buildWikilinkRe, } from "./patterns.js";
|
|
14
|
+
import { NOX_ENTITY_TYPES, } from "./types.js";
|
|
15
|
+
const ENTITY_TYPE_SET = new Set(NOX_ENTITY_TYPES);
|
|
16
|
+
function asEntityType(value) {
|
|
17
|
+
return ENTITY_TYPE_SET.has(value) ? value : null;
|
|
18
|
+
}
|
|
19
|
+
function pushRef(bucket, rawEntityType, rawSlug, source, display) {
|
|
20
|
+
const entityType = asEntityType(rawEntityType);
|
|
21
|
+
if (!entityType)
|
|
22
|
+
return;
|
|
23
|
+
const slug = rawSlug.toLowerCase();
|
|
24
|
+
if (!slug)
|
|
25
|
+
return;
|
|
26
|
+
const key = `${entityType}/${slug}`;
|
|
27
|
+
const existing = bucket.get(key);
|
|
28
|
+
if (existing) {
|
|
29
|
+
// Prefer explicit display from markdown_link/wikilink over bare_ref.
|
|
30
|
+
if (!existing.display && display)
|
|
31
|
+
existing.display = display;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
bucket.set(key, { entityType, slug, key, source, display });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Pure regex-based entity-ref extractor.
|
|
38
|
+
*
|
|
39
|
+
* Pipeline:
|
|
40
|
+
* 1. stripCodeBlocks (suppress matches inside ```code```)
|
|
41
|
+
* 2. Markdown links `[Name](type/slug)`
|
|
42
|
+
* 3. Obsidian wikilinks `[[type/slug|Display]]`
|
|
43
|
+
* 4. Bare refs `type/slug` (boundary-anchored)
|
|
44
|
+
* 5. Dedupe by canonical key
|
|
45
|
+
*/
|
|
46
|
+
export function extractEntityRefsRegex(content) {
|
|
47
|
+
if (!content)
|
|
48
|
+
return [];
|
|
49
|
+
const { stripped } = stripCodeBlocks(content);
|
|
50
|
+
const refs = new Map();
|
|
51
|
+
const mdRe = buildMarkdownLinkRe();
|
|
52
|
+
for (const m of stripped.matchAll(mdRe)) {
|
|
53
|
+
pushRef(refs, m[2] ?? "", m[3] ?? "", "markdown_link", m[1]?.trim());
|
|
54
|
+
}
|
|
55
|
+
const wikiRe = buildWikilinkRe();
|
|
56
|
+
for (const m of stripped.matchAll(wikiRe)) {
|
|
57
|
+
pushRef(refs, m[1] ?? "", m[2] ?? "", "wikilink", m[3]?.trim());
|
|
58
|
+
}
|
|
59
|
+
const bareRe = buildBareRefRe();
|
|
60
|
+
for (const m of stripped.matchAll(bareRe)) {
|
|
61
|
+
pushRef(refs, m[1] ?? "", m[2] ?? "", "bare_ref");
|
|
62
|
+
}
|
|
63
|
+
return Array.from(refs.values());
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* T5 — extract code-path references (`src/foo.ts:42`, `specs/X.md`).
|
|
67
|
+
*
|
|
68
|
+
* Stripped of code fences first (gbrain pattern — avoid recursive matches
|
|
69
|
+
* inside example fences).
|
|
70
|
+
*/
|
|
71
|
+
export function extractCodeRefs(content) {
|
|
72
|
+
if (!content)
|
|
73
|
+
return [];
|
|
74
|
+
const { stripped } = stripCodeBlocks(content);
|
|
75
|
+
const seen = new Map();
|
|
76
|
+
const re = buildCodeRefRe();
|
|
77
|
+
for (const m of stripped.matchAll(re)) {
|
|
78
|
+
const root = (m[1] ?? "").toLowerCase();
|
|
79
|
+
const path = m[2] ?? "";
|
|
80
|
+
if (!root || !path)
|
|
81
|
+
continue;
|
|
82
|
+
const lineRaw = m[4];
|
|
83
|
+
const line = lineRaw ? Number.parseInt(lineRaw, 10) : undefined;
|
|
84
|
+
const normalized = `${root}/${path}`.toLowerCase();
|
|
85
|
+
const key = `codepath/${normalized}${line ? `:${line}` : ""}`;
|
|
86
|
+
if (seen.has(key))
|
|
87
|
+
continue;
|
|
88
|
+
seen.set(key, { root, path, line, key });
|
|
89
|
+
}
|
|
90
|
+
return Array.from(seen.values());
|
|
91
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T4 — extractFrontmatterRelations.
|
|
3
|
+
*
|
|
4
|
+
* Parses a small, well-known subset of YAML frontmatter (scalars + flow/block
|
|
5
|
+
* arrays of scalars) — enough to support the 6 rules in spec §5 without an
|
|
6
|
+
* external dep. If consumers need full YAML they can preprocess and pass the
|
|
7
|
+
* already-parsed object via {@link extractFrontmatterRelationsFromObject}.
|
|
8
|
+
*
|
|
9
|
+
* Spec: specs/2026-05-18-L4-regex-first-extraction.md §5.
|
|
10
|
+
*/
|
|
11
|
+
import { FrontmatterRelation } from "./types.js";
|
|
12
|
+
/** Pull the `---`-delimited block from the head of a markdown doc. */
|
|
13
|
+
export declare function extractFrontmatterBlock(content: string): string | null;
|
|
14
|
+
interface ParsedField {
|
|
15
|
+
key: string;
|
|
16
|
+
/** Single scalar value (no array). */
|
|
17
|
+
scalar?: string;
|
|
18
|
+
/** Array values (collected from flow `[a, b]` or block `- a\n- b`). */
|
|
19
|
+
array?: string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Minimal YAML scalar/array parser for top-level fields. NOT a full YAML
|
|
23
|
+
* implementation — handles:
|
|
24
|
+
* - `key: value`
|
|
25
|
+
* - `key: "quoted value"`
|
|
26
|
+
* - `key: [a, b, c]` (flow array)
|
|
27
|
+
* - block array:
|
|
28
|
+
* key:
|
|
29
|
+
* - a
|
|
30
|
+
* - b
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseFrontmatterFields(block: string): ParsedField[];
|
|
33
|
+
/**
|
|
34
|
+
* Parse frontmatter block + emit typed relations per spec §5 table.
|
|
35
|
+
*
|
|
36
|
+
* Returns [] when the doc has no frontmatter.
|
|
37
|
+
*/
|
|
38
|
+
export declare function extractFrontmatterRelations(content: string): FrontmatterRelation[];
|
|
39
|
+
/**
|
|
40
|
+
* Variant for callers that already parsed YAML (e.g. via gray-matter elsewhere
|
|
41
|
+
* in the pipeline). Object values may be string | string[].
|
|
42
|
+
*/
|
|
43
|
+
export declare function extractFrontmatterRelationsFromObject(data: Record<string, unknown>): FrontmatterRelation[];
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T4 — extractFrontmatterRelations.
|
|
3
|
+
*
|
|
4
|
+
* Parses a small, well-known subset of YAML frontmatter (scalars + flow/block
|
|
5
|
+
* arrays of scalars) — enough to support the 6 rules in spec §5 without an
|
|
6
|
+
* external dep. If consumers need full YAML they can preprocess and pass the
|
|
7
|
+
* already-parsed object via {@link extractFrontmatterRelationsFromObject}.
|
|
8
|
+
*
|
|
9
|
+
* Spec: specs/2026-05-18-L4-regex-first-extraction.md §5.
|
|
10
|
+
*/
|
|
11
|
+
/** Match a leading `---\n...\n---` block. */
|
|
12
|
+
const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
|
|
13
|
+
const FIELD_TO_RELATION = {
|
|
14
|
+
agent: "is_agent_of",
|
|
15
|
+
references: "references",
|
|
16
|
+
supersedes: "supersedes",
|
|
17
|
+
caused_by: "caused_by",
|
|
18
|
+
resolves: "resolves",
|
|
19
|
+
decided_by: "decided_by",
|
|
20
|
+
};
|
|
21
|
+
/** Strip surrounding quotes (single or double). */
|
|
22
|
+
function unquote(s) {
|
|
23
|
+
const t = s.trim();
|
|
24
|
+
if (t.length >= 2) {
|
|
25
|
+
const first = t[0];
|
|
26
|
+
const last = t[t.length - 1];
|
|
27
|
+
if ((first === '"' && last === '"') || (first === "'" && last === "'")) {
|
|
28
|
+
return t.slice(1, -1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return t;
|
|
32
|
+
}
|
|
33
|
+
/** Pull the `---`-delimited block from the head of a markdown doc. */
|
|
34
|
+
export function extractFrontmatterBlock(content) {
|
|
35
|
+
const m = content.match(FRONTMATTER_RE);
|
|
36
|
+
return m ? (m[1] ?? null) : null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Minimal YAML scalar/array parser for top-level fields. NOT a full YAML
|
|
40
|
+
* implementation — handles:
|
|
41
|
+
* - `key: value`
|
|
42
|
+
* - `key: "quoted value"`
|
|
43
|
+
* - `key: [a, b, c]` (flow array)
|
|
44
|
+
* - block array:
|
|
45
|
+
* key:
|
|
46
|
+
* - a
|
|
47
|
+
* - b
|
|
48
|
+
*/
|
|
49
|
+
export function parseFrontmatterFields(block) {
|
|
50
|
+
const lines = block.split(/\r?\n/);
|
|
51
|
+
const out = [];
|
|
52
|
+
let i = 0;
|
|
53
|
+
while (i < lines.length) {
|
|
54
|
+
const line = lines[i] ?? "";
|
|
55
|
+
const trimmed = line.trim();
|
|
56
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
57
|
+
i++;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const colonIdx = trimmed.indexOf(":");
|
|
61
|
+
if (colonIdx <= 0) {
|
|
62
|
+
i++;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const key = trimmed.slice(0, colonIdx).trim();
|
|
66
|
+
const rest = trimmed.slice(colonIdx + 1).trim();
|
|
67
|
+
if (!rest) {
|
|
68
|
+
// Possible block array — peek subsequent indented `- ` lines.
|
|
69
|
+
const items = [];
|
|
70
|
+
let j = i + 1;
|
|
71
|
+
while (j < lines.length) {
|
|
72
|
+
const peek = lines[j] ?? "";
|
|
73
|
+
const peekTrim = peek.trim();
|
|
74
|
+
if (peekTrim.startsWith("- ")) {
|
|
75
|
+
items.push(unquote(peekTrim.slice(2)));
|
|
76
|
+
j++;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (peekTrim === "") {
|
|
80
|
+
j++;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
if (items.length > 0) {
|
|
86
|
+
out.push({ key, array: items });
|
|
87
|
+
i = j;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
out.push({ key, scalar: "" });
|
|
91
|
+
i++;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (rest.startsWith("[") && rest.endsWith("]")) {
|
|
95
|
+
const inner = rest.slice(1, -1).trim();
|
|
96
|
+
const items = inner ? inner.split(",").map((p) => unquote(p)) : [];
|
|
97
|
+
out.push({ key, array: items.filter(Boolean) });
|
|
98
|
+
i++;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
out.push({ key, scalar: unquote(rest) });
|
|
102
|
+
i++;
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
function relationFrom(field, raw) {
|
|
107
|
+
const rel = FIELD_TO_RELATION[field];
|
|
108
|
+
if (!rel)
|
|
109
|
+
return null;
|
|
110
|
+
const target = raw.trim();
|
|
111
|
+
if (!target)
|
|
112
|
+
return null;
|
|
113
|
+
return { relationType: rel, target, raw };
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Parse frontmatter block + emit typed relations per spec §5 table.
|
|
117
|
+
*
|
|
118
|
+
* Returns [] when the doc has no frontmatter.
|
|
119
|
+
*/
|
|
120
|
+
export function extractFrontmatterRelations(content) {
|
|
121
|
+
const block = extractFrontmatterBlock(content);
|
|
122
|
+
if (!block)
|
|
123
|
+
return [];
|
|
124
|
+
const fields = parseFrontmatterFields(block);
|
|
125
|
+
const out = [];
|
|
126
|
+
for (const f of fields) {
|
|
127
|
+
if (!(f.key in FIELD_TO_RELATION))
|
|
128
|
+
continue;
|
|
129
|
+
if (f.array) {
|
|
130
|
+
for (const v of f.array) {
|
|
131
|
+
const rel = relationFrom(f.key, v);
|
|
132
|
+
if (rel)
|
|
133
|
+
out.push(rel);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else if (f.scalar !== undefined && f.scalar !== "") {
|
|
137
|
+
const rel = relationFrom(f.key, f.scalar);
|
|
138
|
+
if (rel)
|
|
139
|
+
out.push(rel);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Variant for callers that already parsed YAML (e.g. via gray-matter elsewhere
|
|
146
|
+
* in the pipeline). Object values may be string | string[].
|
|
147
|
+
*/
|
|
148
|
+
export function extractFrontmatterRelationsFromObject(data) {
|
|
149
|
+
const out = [];
|
|
150
|
+
for (const [k, v] of Object.entries(data)) {
|
|
151
|
+
if (!(k in FIELD_TO_RELATION))
|
|
152
|
+
continue;
|
|
153
|
+
if (Array.isArray(v)) {
|
|
154
|
+
for (const item of v) {
|
|
155
|
+
if (typeof item !== "string")
|
|
156
|
+
continue;
|
|
157
|
+
const rel = relationFrom(k, item);
|
|
158
|
+
if (rel)
|
|
159
|
+
out.push(rel);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else if (typeof v === "string") {
|
|
163
|
+
const rel = relationFrom(k, v);
|
|
164
|
+
if (rel)
|
|
165
|
+
out.push(rel);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L4 regex-extract — public surface (T1-T6).
|
|
3
|
+
*
|
|
4
|
+
* gbrain-inspired (MIT, Garry Tan) regex-first KG extraction with Gemini
|
|
5
|
+
* fallback. See specs/2026-05-18-L4-regex-first-extraction.md.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
export { stripCodeBlocks, type StripResult } from "./strip-code.js";
|
|
9
|
+
export { DIR_PATTERN, OPTIONAL_TOP, SLUG_CHARS, buildMarkdownLinkRe, buildWikilinkRe, buildBareRefRe, buildCodeRefRe, } from "./patterns.js";
|
|
10
|
+
export { extractEntityRefsRegex, extractCodeRefs } from "./extractor.js";
|
|
11
|
+
export { extractFrontmatterBlock, parseFrontmatterFields, extractFrontmatterRelations, extractFrontmatterRelationsFromObject, } from "./frontmatter.js";
|
|
12
|
+
export { decideExtraction, mergeRelations, type ChunkContext, type ExtractionTelemetry, type IngestDecision, type MergedRelation, } from "./ingest-router-l4.js";
|
|
13
|
+
export { reconcileEntityLinks, extractTargetSlugsFromContent, detectSlugChange, rewriteChunksForRename, detectCircularRename, STALE_CONFIDENCE, STALE_REASON, type ReconcilerRelation, type ReconcileAction, type ReconcileResult, type ReconcileOptions, type ChunkRewriteResult, } from "./reconcile.js";
|
|
14
|
+
export { runProductionFastPath, filterHighConfidence, mergeWithLlmRelations, relationDedupKey, isRegexEnabled, isSkipGeminiEnabled, scoreEntityRef, scoreFrontmatterRelation, CONFIDENCE_THRESHOLD, CONFIDENCE_FRONTMATTER, CONFIDENCE_EXPLICIT_LINK, CONFIDENCE_BARE_REF, type ScoredRelation, type ProductionWireResult, } from "./production-wire.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L4 regex-extract — public surface (T1-T6).
|
|
3
|
+
*
|
|
4
|
+
* gbrain-inspired (MIT, Garry Tan) regex-first KG extraction with Gemini
|
|
5
|
+
* fallback. See specs/2026-05-18-L4-regex-first-extraction.md.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
export { stripCodeBlocks } from "./strip-code.js";
|
|
9
|
+
export { DIR_PATTERN, OPTIONAL_TOP, SLUG_CHARS, buildMarkdownLinkRe, buildWikilinkRe, buildBareRefRe, buildCodeRefRe, } from "./patterns.js";
|
|
10
|
+
export { extractEntityRefsRegex, extractCodeRefs } from "./extractor.js";
|
|
11
|
+
export { extractFrontmatterBlock, parseFrontmatterFields, extractFrontmatterRelations, extractFrontmatterRelationsFromObject, } from "./frontmatter.js";
|
|
12
|
+
export { decideExtraction, mergeRelations, } from "./ingest-router-l4.js";
|
|
13
|
+
export { reconcileEntityLinks, extractTargetSlugsFromContent, detectSlugChange, rewriteChunksForRename, detectCircularRename, STALE_CONFIDENCE, STALE_REASON, } from "./reconcile.js";
|
|
14
|
+
export { runProductionFastPath, filterHighConfidence, mergeWithLlmRelations, relationDedupKey, isRegexEnabled, isSkipGeminiEnabled, scoreEntityRef, scoreFrontmatterRelation, CONFIDENCE_THRESHOLD, CONFIDENCE_FRONTMATTER, CONFIDENCE_EXPLICIT_LINK, CONFIDENCE_BARE_REF, } from "./production-wire.js";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T6 — Ingest router integration: regex-first KG extraction with Gemini fallback.
|
|
3
|
+
*
|
|
4
|
+
* Pure orchestration layer — no DB writes, no Gemini API calls. Returns a
|
|
5
|
+
* structured decision payload that the actual ingest router (production
|
|
6
|
+
* `src/lib/ingest-router.ts`) consumes to:
|
|
7
|
+
* 1) write `kg_relations` rows tagged `extraction_method`
|
|
8
|
+
* 2) decide whether to invoke `geminiKgExtract`
|
|
9
|
+
* 3) merge + dedup results
|
|
10
|
+
* 4) emit telemetry per spec §7
|
|
11
|
+
*
|
|
12
|
+
* Keeping this layer pure means it's covered by unit tests without DB or
|
|
13
|
+
* network fixtures — the integration test layer (T7+ deferred) wires the
|
|
14
|
+
* production ingestor.
|
|
15
|
+
*
|
|
16
|
+
* Spec: specs/2026-05-18-L4-regex-first-extraction.md §3 + §7.
|
|
17
|
+
*/
|
|
18
|
+
import { RegexExtractionResult } from "./types.js";
|
|
19
|
+
/** Chunk metadata that the production ingest router already maintains. */
|
|
20
|
+
export interface ChunkContext {
|
|
21
|
+
/** Chunk section per schema v10 (NULL for legacy/unsectioned chunks). */
|
|
22
|
+
section: "compiled" | "frontmatter" | "timeline" | "prose" | null;
|
|
23
|
+
/** Chunk type taxonomy (used to force Gemini for conversation logs). */
|
|
24
|
+
type: "entity" | "spec" | "audit" | "conversation" | "daily_log" | "freeform" | "code" | "other";
|
|
25
|
+
/** Raw chunk content (markdown). */
|
|
26
|
+
content: string;
|
|
27
|
+
/** Approximate chunk size in characters — used to short-circuit tiny chunks. */
|
|
28
|
+
size?: number;
|
|
29
|
+
}
|
|
30
|
+
/** Per-chunk telemetry record emitted per spec §7. */
|
|
31
|
+
export interface ExtractionTelemetry {
|
|
32
|
+
section: ChunkContext["section"];
|
|
33
|
+
extraction_method: "regex_only" | "gemini_only" | "regex_primary_gemini_secondary" | "gemini_only_after_regex_zero";
|
|
34
|
+
regex_relations_count: number;
|
|
35
|
+
/** Set by production caller once Gemini returns; unset here. */
|
|
36
|
+
gemini_relations_count: number | null;
|
|
37
|
+
gemini_call_skipped: boolean;
|
|
38
|
+
latency_ms: {
|
|
39
|
+
regex: number;
|
|
40
|
+
gemini: number | null;
|
|
41
|
+
total: number | null;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Decision returned by the router pre-Gemini. */
|
|
45
|
+
export interface IngestDecision {
|
|
46
|
+
/** All regex-extracted artifacts (entity refs + frontmatter rels + code refs). */
|
|
47
|
+
regex: RegexExtractionResult;
|
|
48
|
+
/** Total count of regex relations (refs + frontmatter; code refs counted separately). */
|
|
49
|
+
regexRelationsCount: number;
|
|
50
|
+
/** Whether the caller should SKIP the Gemini KG call. */
|
|
51
|
+
skipGemini: boolean;
|
|
52
|
+
/** Telemetry placeholder — Gemini fields filled by caller post-call. */
|
|
53
|
+
telemetry: ExtractionTelemetry;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Run regex extraction + decide whether Gemini should be skipped.
|
|
57
|
+
*
|
|
58
|
+
* Skip-gate (spec §7):
|
|
59
|
+
* section ∈ {compiled, frontmatter, timeline}
|
|
60
|
+
* AND regex_relations_count ≥ 1
|
|
61
|
+
* AND chunk.type ∉ {conversation, daily_log, freeform}
|
|
62
|
+
*/
|
|
63
|
+
export declare function decideExtraction(chunk: ChunkContext): IngestDecision;
|
|
64
|
+
/**
|
|
65
|
+
* Merge regex + Gemini relations into a single dedup'd set ready for insert.
|
|
66
|
+
* Production caller passes Gemini relations after the API call when skipGemini
|
|
67
|
+
* was false. Dedup key = `<source>|<target>|<type>` (case-insensitive).
|
|
68
|
+
*/
|
|
69
|
+
export interface MergedRelation {
|
|
70
|
+
/** Source entity key (chunk-owning entity), resolved by caller. */
|
|
71
|
+
source: string;
|
|
72
|
+
target: string;
|
|
73
|
+
relationType: string;
|
|
74
|
+
extraction_method: "regex" | "gemini";
|
|
75
|
+
}
|
|
76
|
+
export declare function mergeRelations(regex: MergedRelation[], gemini: MergedRelation[]): MergedRelation[];
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T6 — Ingest router integration: regex-first KG extraction with Gemini fallback.
|
|
3
|
+
*
|
|
4
|
+
* Pure orchestration layer — no DB writes, no Gemini API calls. Returns a
|
|
5
|
+
* structured decision payload that the actual ingest router (production
|
|
6
|
+
* `src/lib/ingest-router.ts`) consumes to:
|
|
7
|
+
* 1) write `kg_relations` rows tagged `extraction_method`
|
|
8
|
+
* 2) decide whether to invoke `geminiKgExtract`
|
|
9
|
+
* 3) merge + dedup results
|
|
10
|
+
* 4) emit telemetry per spec §7
|
|
11
|
+
*
|
|
12
|
+
* Keeping this layer pure means it's covered by unit tests without DB or
|
|
13
|
+
* network fixtures — the integration test layer (T7+ deferred) wires the
|
|
14
|
+
* production ingestor.
|
|
15
|
+
*
|
|
16
|
+
* Spec: specs/2026-05-18-L4-regex-first-extraction.md §3 + §7.
|
|
17
|
+
*/
|
|
18
|
+
import { extractEntityRefsRegex, extractCodeRefs } from "./extractor.js";
|
|
19
|
+
import { extractFrontmatterRelations } from "./frontmatter.js";
|
|
20
|
+
/** Sections eligible for the skip-Gemini fast path. */
|
|
21
|
+
const SKIP_ELIGIBLE_SECTIONS = new Set([
|
|
22
|
+
"compiled",
|
|
23
|
+
"frontmatter",
|
|
24
|
+
"timeline",
|
|
25
|
+
]);
|
|
26
|
+
/** Chunk types that ALWAYS run Gemini (prose-heavy, weak structure). */
|
|
27
|
+
const FORCE_GEMINI_TYPES = new Set([
|
|
28
|
+
"conversation",
|
|
29
|
+
"daily_log",
|
|
30
|
+
"freeform",
|
|
31
|
+
]);
|
|
32
|
+
/**
|
|
33
|
+
* Run regex extraction + decide whether Gemini should be skipped.
|
|
34
|
+
*
|
|
35
|
+
* Skip-gate (spec §7):
|
|
36
|
+
* section ∈ {compiled, frontmatter, timeline}
|
|
37
|
+
* AND regex_relations_count ≥ 1
|
|
38
|
+
* AND chunk.type ∉ {conversation, daily_log, freeform}
|
|
39
|
+
*/
|
|
40
|
+
export function decideExtraction(chunk) {
|
|
41
|
+
const t0 = performanceNowSafe();
|
|
42
|
+
const entityRefs = extractEntityRefsRegex(chunk.content);
|
|
43
|
+
const frontmatterRelations = extractFrontmatterRelations(chunk.content);
|
|
44
|
+
const codeRefs = extractCodeRefs(chunk.content);
|
|
45
|
+
const regexElapsed = performanceNowSafe() - t0;
|
|
46
|
+
const regexRelationsCount = entityRefs.length + frontmatterRelations.length + codeRefs.length;
|
|
47
|
+
const sectionEligible = chunk.section
|
|
48
|
+
? SKIP_ELIGIBLE_SECTIONS.has(chunk.section)
|
|
49
|
+
: false;
|
|
50
|
+
const typeAllowsSkip = !FORCE_GEMINI_TYPES.has(chunk.type);
|
|
51
|
+
const skipGemini = sectionEligible && typeAllowsSkip && regexRelationsCount >= 1;
|
|
52
|
+
let method;
|
|
53
|
+
if (skipGemini) {
|
|
54
|
+
method = "regex_only";
|
|
55
|
+
}
|
|
56
|
+
else if (regexRelationsCount === 0) {
|
|
57
|
+
method = "gemini_only_after_regex_zero";
|
|
58
|
+
}
|
|
59
|
+
else if (sectionEligible) {
|
|
60
|
+
method = "regex_primary_gemini_secondary";
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
method = "gemini_only";
|
|
64
|
+
}
|
|
65
|
+
const regex = {
|
|
66
|
+
entityRefs,
|
|
67
|
+
frontmatterRelations,
|
|
68
|
+
codeRefs,
|
|
69
|
+
hadCodeFences: chunk.content.includes("`"),
|
|
70
|
+
};
|
|
71
|
+
const telemetry = {
|
|
72
|
+
section: chunk.section,
|
|
73
|
+
extraction_method: method,
|
|
74
|
+
regex_relations_count: regexRelationsCount,
|
|
75
|
+
gemini_relations_count: null,
|
|
76
|
+
gemini_call_skipped: skipGemini,
|
|
77
|
+
latency_ms: { regex: regexElapsed, gemini: null, total: null },
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
regex,
|
|
81
|
+
regexRelationsCount,
|
|
82
|
+
skipGemini,
|
|
83
|
+
telemetry,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export function mergeRelations(regex, gemini) {
|
|
87
|
+
const seen = new Set();
|
|
88
|
+
const out = [];
|
|
89
|
+
for (const r of [...regex, ...gemini]) {
|
|
90
|
+
const k = `${r.source}|${r.target}|${r.relationType}`.toLowerCase();
|
|
91
|
+
if (seen.has(k))
|
|
92
|
+
continue;
|
|
93
|
+
seen.add(k);
|
|
94
|
+
out.push(r);
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
/** Cross-platform high-resolution timer; falls back to Date.now() on Edge runtimes. */
|
|
99
|
+
function performanceNowSafe() {
|
|
100
|
+
const g = globalThis;
|
|
101
|
+
return g.performance?.now?.() ?? Date.now();
|
|
102
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
/** `(?:feedback|person|...)` literal alternation snippet — non-capturing. */
|
|
12
|
+
export declare const DIR_PATTERN: string;
|
|
13
|
+
/** Top-level dir prefix `entities/` is optional in wikilinks. */
|
|
14
|
+
export declare const OPTIONAL_TOP = "(?:entities\\/)?";
|
|
15
|
+
/** Slug character class: letters, digits, underscore, dash. NO dots (drops `.md`). */
|
|
16
|
+
export declare const SLUG_CHARS = "[a-z0-9_\\-]+";
|
|
17
|
+
/**
|
|
18
|
+
* Markdown-link form: `[Name](path/to/entityType/slug)`, optional `.md`, optional
|
|
19
|
+
* tooltip `"..."`. Path may have `../` prefix.
|
|
20
|
+
*
|
|
21
|
+
* Groups:
|
|
22
|
+
* 1 — display text
|
|
23
|
+
* 2 — entity type
|
|
24
|
+
* 3 — slug (no .md, no anchor)
|
|
25
|
+
*/
|
|
26
|
+
export declare function buildMarkdownLinkRe(): RegExp;
|
|
27
|
+
/**
|
|
28
|
+
* Obsidian wikilink form: `[[entityType/slug]]`, optional `entities/` prefix,
|
|
29
|
+
* optional `#anchor`, optional `|display`. Accept ASCII-aware slugs only —
|
|
30
|
+
* Unicode boundary issues handled in extractor via stripping non-slug chars.
|
|
31
|
+
*
|
|
32
|
+
* Groups:
|
|
33
|
+
* 1 — entity type
|
|
34
|
+
* 2 — slug
|
|
35
|
+
* 3 — display (after `|`, optional)
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildWikilinkRe(): RegExp;
|
|
38
|
+
/**
|
|
39
|
+
* Bare slug form: standalone `entityType/slug` token, only when surrounded by
|
|
40
|
+
* whitespace/start/punctuation boundary. Uses lookbehind/lookahead WITHOUT
|
|
41
|
+
* `\b` (MEMORY.md `JS regex \b falha em Unicode`).
|
|
42
|
+
*
|
|
43
|
+
* Tightly anchored to avoid URL false-positives — disallow `/` directly before
|
|
44
|
+
* the token (so `example.com/feedback/foo` does NOT match).
|
|
45
|
+
*
|
|
46
|
+
* Groups:
|
|
47
|
+
* 1 — entity type
|
|
48
|
+
* 2 — slug
|
|
49
|
+
*/
|
|
50
|
+
export declare function buildBareRefRe(): RegExp;
|
|
51
|
+
/**
|
|
52
|
+
* Code-path references (`src/lib/op-audit.ts:42`, `specs/foo.md`). Domain dirs
|
|
53
|
+
* are whitelisted to suppress matches against unrelated path-like text.
|
|
54
|
+
*
|
|
55
|
+
* Groups:
|
|
56
|
+
* 1 — top-level dir
|
|
57
|
+
* 2 — path under root (extension included)
|
|
58
|
+
* 3 — extension
|
|
59
|
+
* 4 — line number (optional)
|
|
60
|
+
*/
|
|
61
|
+
export declare function buildCodeRefRe(): RegExp;
|