nox-mem 3.1.1 → 3.2.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/README.md +24 -16
- package/dist/__tests__/brief-diversity.test.js +266 -0
- package/dist/__tests__/brief.test.js +287 -0
- package/dist/__tests__/churn.test.js +66 -0
- package/dist/__tests__/edge-typing.test.js +99 -0
- package/dist/__tests__/ingest-event.test.js +151 -0
- package/dist/__tests__/op-audit-e2e.test.js +130 -0
- package/dist/__tests__/pragma-alignment.test.js +123 -0
- package/dist/__tests__/reranker.test.js +326 -0
- package/dist/__tests__/retention.test.js +99 -0
- package/dist/__tests__/search-track-access.test.js +49 -0
- package/dist/__tests__/spo-injection.test.js +172 -0
- package/dist/__tests__/temporal-detector.test.js +103 -0
- package/dist/api/wire-up.js +12 -381
- package/dist/api-server.js +6 -102
- package/dist/db.js +61 -2
- package/dist/embed.js +23 -2
- package/dist/index.js +1 -22
- package/dist/knowledge-graph.js +20 -0
- package/dist/lib/answer/__tests__/e2e-gemini.test.js +229 -0
- package/dist/lib/answer/__tests__/integration-sqlite.test.js +388 -0
- package/dist/lib/answer/__tests__/integration.test.js +347 -0
- package/dist/lib/answer/__tests__/prompt.test.js +117 -0
- package/dist/lib/answer/__tests__/t5-t10.test.js +501 -0
- package/dist/lib/answer/provider.js +29 -4
- package/dist/lib/api/__tests__/safe-error-message.test.js +155 -0
- package/dist/lib/auth/__tests__/localhost-guard.test.js +144 -0
- package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +354 -0
- package/dist/lib/events/__tests__/bus.test.js +208 -0
- package/dist/lib/ingest-router.js +0 -43
- package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +109 -0
- package/dist/lib/regex-extract/__tests__/extractor.test.js +197 -0
- package/dist/lib/regex-extract/__tests__/frontmatter.test.js +75 -0
- package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +139 -0
- package/dist/lib/regex-extract/__tests__/production-wire.test.js +177 -0
- package/dist/lib/regex-extract/__tests__/reconcile.test.js +170 -0
- package/dist/lib/regex-extract/__tests__/strip-code.test.js +36 -0
- package/dist/privacy/__tests__/filter.test.js +352 -0
- package/dist/providers/__tests__/conformance-extended.test.js +249 -0
- package/dist/providers/__tests__/conformance.test.js +98 -0
- package/dist/providers/__tests__/cost-cap.test.js +151 -0
- package/dist/providers/__tests__/e2e-real.test.js +79 -0
- package/dist/providers/__tests__/factory.test.js +80 -0
- package/dist/providers/__tests__/fallback.test.js +223 -0
- package/dist/providers/__tests__/gemini.test.js +191 -0
- package/dist/providers/__tests__/health.test.js +128 -0
- package/dist/providers/__tests__/telemetry.test.js +219 -0
- package/dist/reindex.js +2 -2
- package/package.json +3 -4
- package/dist/api/answer.d.ts +0 -116
- package/dist/api/answer.validate-patch.d.ts +0 -72
- package/dist/api/brief-diversity.d.ts +0 -64
- package/dist/api/brief.d.ts +0 -114
- package/dist/api/conflict.d.ts +0 -33
- package/dist/api/conflict.js +0 -143
- package/dist/api/cors.d.ts +0 -73
- package/dist/api/events-stream-limited.d.ts +0 -133
- package/dist/api/events-stream-limited.js +0 -217
- package/dist/api/events-stream.d.ts +0 -53
- package/dist/api/events-stream.js +0 -125
- package/dist/api/export.d.ts +0 -42
- package/dist/api/export.js +0 -85
- package/dist/api/health-confidence-adapter.d.ts +0 -29
- package/dist/api/health-confidence-adapter.js +0 -73
- package/dist/api/health-confidence.d.ts +0 -36
- package/dist/api/health-confidence.js +0 -141
- package/dist/api/hooks.d.ts +0 -50
- package/dist/api/hooks.js +0 -115
- package/dist/api/import.d.ts +0 -38
- package/dist/api/import.js +0 -87
- package/dist/api/ingest-event.d.ts +0 -65
- package/dist/api/mark.d.ts +0 -42
- package/dist/api/mark.js +0 -127
- package/dist/api/server-deps-a2.d.ts +0 -55
- package/dist/api/server-deps-a2.js +0 -138
- package/dist/api/server-deps-l2-l3.d.ts +0 -68
- package/dist/api/server-deps-l2-l3.js +0 -123
- package/dist/api/server-deps-p1.d.ts +0 -84
- package/dist/api/server-deps-p2.d.ts +0 -32
- package/dist/api/server-deps-p2.js +0 -84
- package/dist/api/server-deps-p5.d.ts +0 -66
- package/dist/api/server-deps-p5.js +0 -139
- package/dist/api/viewer-static.d.ts +0 -30
- package/dist/api/viewer-static.js +0 -102
- package/dist/api/wire-up.d.ts +0 -54
- package/dist/api-impact.d.ts +0 -30
- package/dist/api-server.d.ts +0 -2
- package/dist/backfill-fts-anchor.d.ts +0 -15
- package/dist/backfill-source-type.d.ts +0 -20
- package/dist/churn.d.ts +0 -31
- package/dist/cli/answer.d.ts +0 -66
- package/dist/cli/conflict.d.ts +0 -38
- package/dist/cli/conflict.js +0 -282
- package/dist/cli/export.d.ts +0 -51
- package/dist/cli/export.js +0 -280
- package/dist/cli/hooks.d.ts +0 -54
- package/dist/cli/hooks.js +0 -133
- package/dist/cli/import.d.ts +0 -52
- package/dist/cli/import.js +0 -274
- package/dist/cli/mark.d.ts +0 -33
- package/dist/cli/mark.js +0 -130
- package/dist/cli/ocr-batch.d.ts +0 -12
- package/dist/cli/ocr-batch.js +0 -411
- package/dist/cli/snapshot-main.d.ts +0 -30
- package/dist/cli/snapshot-main.js +0 -47
- package/dist/cli/viewer.d.ts +0 -35
- package/dist/cli/viewer.js +0 -71
- package/dist/cli-telemetry.d.ts +0 -36
- package/dist/cli-telemetry.js +0 -150
- package/dist/compact.d.ts +0 -7
- package/dist/consolidate.d.ts +0 -18
- package/dist/consolidation.d.ts +0 -32
- package/dist/cross-agent-v2.d.ts +0 -45
- package/dist/cross-search.d.ts +0 -11
- package/dist/crystallize.d.ts +0 -43
- package/dist/db.d.ts +0 -11
- package/dist/dedup.d.ts +0 -1
- package/dist/detect-changes.d.ts +0 -29
- package/dist/digest.d.ts +0 -1
- package/dist/doctor.d.ts +0 -1
- package/dist/embed.d.ts +0 -57
- package/dist/evals.d.ts +0 -176
- package/dist/evals.js +0 -351
- package/dist/generate-user-profile.d.ts +0 -18
- package/dist/graphify-ingest.d.ts +0 -18
- package/dist/impact.d.ts +0 -39
- package/dist/index.d.ts +0 -2
- package/dist/ingest-entity.d.ts +0 -44
- package/dist/ingest.d.ts +0 -13
- package/dist/kg-llm.d.ts +0 -39
- package/dist/knowledge-graph.d.ts +0 -72
- package/dist/lib/answer/config.d.ts +0 -41
- package/dist/lib/answer/index.d.ts +0 -47
- package/dist/lib/answer/prompt.d.ts +0 -37
- package/dist/lib/answer/provider.d.ts +0 -47
- package/dist/lib/answer/retrieval.d.ts +0 -36
- package/dist/lib/answer/telemetry.d.ts +0 -99
- package/dist/lib/answer/types.d.ts +0 -108
- package/dist/lib/api/error-leak-fix.d.ts +0 -54
- package/dist/lib/api/safe-error-message.d.ts +0 -70
- package/dist/lib/archive/common-passwords.d.ts +0 -37
- package/dist/lib/archive/common-passwords.js +0 -753
- package/dist/lib/archive/encryption.d.ts +0 -81
- package/dist/lib/archive/encryption.js +0 -236
- package/dist/lib/archive/enforce-strength.d.ts +0 -54
- package/dist/lib/archive/enforce-strength.js +0 -70
- package/dist/lib/archive/entropy.d.ts +0 -34
- package/dist/lib/archive/entropy.js +0 -180
- package/dist/lib/archive/export-locking.d.ts +0 -102
- package/dist/lib/archive/export-locking.js +0 -202
- package/dist/lib/archive/format.d.ts +0 -20
- package/dist/lib/archive/format.js +0 -174
- package/dist/lib/archive/index.d.ts +0 -23
- package/dist/lib/archive/index.js +0 -17
- package/dist/lib/archive/manifest.d.ts +0 -53
- package/dist/lib/archive/manifest.js +0 -183
- package/dist/lib/archive/migration.d.ts +0 -36
- package/dist/lib/archive/migration.js +0 -100
- package/dist/lib/archive/migrations/v18_to_v19.d.ts +0 -16
- package/dist/lib/archive/migrations/v18_to_v19.js +0 -18
- package/dist/lib/archive/orchestrator.d.ts +0 -166
- package/dist/lib/archive/orchestrator.js +0 -428
- package/dist/lib/archive/serializers/chunks.d.ts +0 -30
- package/dist/lib/archive/serializers/chunks.js +0 -113
- package/dist/lib/archive/serializers/embeddings.d.ts +0 -36
- package/dist/lib/archive/serializers/embeddings.js +0 -115
- package/dist/lib/archive/serializers/kg.d.ts +0 -28
- package/dist/lib/archive/serializers/kg.js +0 -184
- package/dist/lib/archive/serializers/ops_audit.d.ts +0 -21
- package/dist/lib/archive/serializers/ops_audit.js +0 -97
- package/dist/lib/archive/server-deps.d.ts +0 -131
- package/dist/lib/archive/server-deps.js +0 -232
- package/dist/lib/archive/strength.d.ts +0 -50
- package/dist/lib/archive/strength.js +0 -77
- package/dist/lib/archive/types.d.ts +0 -159
- package/dist/lib/archive/types.js +0 -45
- package/dist/lib/archive/unpack-streaming.d.ts +0 -70
- package/dist/lib/archive/unpack-streaming.js +0 -255
- package/dist/lib/auth/localhost-guard.d.ts +0 -106
- package/dist/lib/confidence/config.d.ts +0 -37
- package/dist/lib/confidence/config.js +0 -107
- package/dist/lib/confidence/db-shim-singleton.d.ts +0 -20
- package/dist/lib/confidence/db-shim-singleton.js +0 -41
- package/dist/lib/confidence/db-shim.d.ts +0 -47
- package/dist/lib/confidence/db-shim.js +0 -141
- package/dist/lib/confidence/mark.d.ts +0 -58
- package/dist/lib/confidence/mark.js +0 -168
- package/dist/lib/confidence/ranking.d.ts +0 -69
- package/dist/lib/confidence/ranking.js +0 -101
- package/dist/lib/confidence/search-filter.d.ts +0 -44
- package/dist/lib/confidence/search-filter.js +0 -103
- package/dist/lib/confidence/types.d.ts +0 -146
- package/dist/lib/confidence/types.js +0 -20
- package/dist/lib/confidence/write-hooks.d.ts +0 -50
- package/dist/lib/confidence/write-hooks.js +0 -159
- package/dist/lib/conflict/audit-fk-check.d.ts +0 -72
- package/dist/lib/conflict/audit-fk-check.js +0 -131
- package/dist/lib/conflict/audit-writer.d.ts +0 -39
- package/dist/lib/conflict/audit-writer.js +0 -133
- package/dist/lib/conflict/db-singleton.d.ts +0 -28
- package/dist/lib/conflict/db-singleton.js +0 -61
- package/dist/lib/conflict/db.d.ts +0 -27
- package/dist/lib/conflict/db.js +0 -20
- package/dist/lib/conflict/detector-direct.d.ts +0 -21
- package/dist/lib/conflict/detector-direct.js +0 -105
- package/dist/lib/conflict/evidence.d.ts +0 -24
- package/dist/lib/conflict/evidence.js +0 -76
- package/dist/lib/conflict/index.d.ts +0 -14
- package/dist/lib/conflict/index.js +0 -12
- package/dist/lib/conflict/scheduler.d.ts +0 -78
- package/dist/lib/conflict/scheduler.js +0 -111
- package/dist/lib/conflict/shadow.d.ts +0 -75
- package/dist/lib/conflict/shadow.js +0 -161
- package/dist/lib/conflict/types.d.ts +0 -133
- package/dist/lib/conflict/types.js +0 -19
- package/dist/lib/cost-cap.d.ts +0 -94
- package/dist/lib/deps/deps-registry.d.ts +0 -111
- package/dist/lib/error-sanitizer/middleware.d.ts +0 -43
- package/dist/lib/error-sanitizer/sanitize.d.ts +0 -78
- package/dist/lib/eval-batch.d.ts +0 -34
- package/dist/lib/eval-batch.js +0 -103
- package/dist/lib/eval-metrics.d.ts +0 -36
- package/dist/lib/eval-metrics.js +0 -95
- package/dist/lib/eval.d.ts +0 -106
- package/dist/lib/eval.js +0 -343
- package/dist/lib/events/bus.d.ts +0 -135
- package/dist/lib/fts-anchor.d.ts +0 -1
- package/dist/lib/hooks/classifier.d.ts +0 -47
- package/dist/lib/hooks/classifier.js +0 -129
- package/dist/lib/hooks/config.d.ts +0 -49
- package/dist/lib/hooks/config.js +0 -106
- package/dist/lib/hooks/decorators.d.ts +0 -35
- package/dist/lib/hooks/decorators.js +0 -59
- package/dist/lib/hooks/pipeline.d.ts +0 -76
- package/dist/lib/hooks/pipeline.js +0 -213
- package/dist/lib/hooks/privacy-filter-adapter.d.ts +0 -55
- package/dist/lib/hooks/privacy-filter-adapter.js +0 -84
- package/dist/lib/hooks/rate-limit-constant-time.d.ts +0 -57
- package/dist/lib/hooks/rate-limit-constant-time.js +0 -69
- package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +0 -71
- package/dist/lib/hooks/rate-limit-dryrun-fix.js +0 -110
- package/dist/lib/hooks/rate-limit.d.ts +0 -54
- package/dist/lib/hooks/rate-limit.js +0 -122
- package/dist/lib/hooks/server-deps.d.ts +0 -61
- package/dist/lib/hooks/server-deps.js +0 -92
- package/dist/lib/hooks/source-allowlist.d.ts +0 -26
- package/dist/lib/hooks/source-allowlist.js +0 -53
- package/dist/lib/hooks/types.d.ts +0 -129
- package/dist/lib/hooks/types.js +0 -24
- package/dist/lib/hooks/worker.d.ts +0 -56
- package/dist/lib/hooks/worker.js +0 -150
- package/dist/lib/ingest-router.d.ts +0 -25
- package/dist/lib/ocr-detector.d.ts +0 -61
- package/dist/lib/ocr-detector.js +0 -138
- package/dist/lib/ocr-engine-stub.d.ts +0 -48
- package/dist/lib/ocr-engine-stub.js +0 -190
- package/dist/lib/ocr-engines/google-doc-ai.d.ts +0 -36
- package/dist/lib/ocr-engines/google-doc-ai.js +0 -164
- package/dist/lib/ocr-jobs.d.ts +0 -67
- package/dist/lib/ocr-jobs.js +0 -129
- package/dist/lib/op-audit-extension/ran-at-guard.d.ts +0 -86
- package/dist/lib/op-audit.d.ts +0 -71
- package/dist/lib/privacy-br/detector.d.ts +0 -42
- package/dist/lib/privacy-br/detector.js +0 -130
- package/dist/lib/privacy-br/index.d.ts +0 -20
- package/dist/lib/privacy-br/index.js +0 -20
- package/dist/lib/privacy-br/integration.d.ts +0 -71
- package/dist/lib/privacy-br/integration.js +0 -74
- package/dist/lib/privacy-br/patterns.d.ts +0 -117
- package/dist/lib/privacy-br/patterns.js +0 -434
- package/dist/lib/privacy-br/redact.d.ts +0 -42
- package/dist/lib/privacy-br/redact.js +0 -103
- package/dist/lib/privacy-br/types.d.ts +0 -55
- package/dist/lib/privacy-br/types.js +0 -25
- package/dist/lib/regex-extract/extractor.d.ts +0 -30
- package/dist/lib/regex-extract/frontmatter.d.ts +0 -44
- package/dist/lib/regex-extract/index.d.ts +0 -14
- package/dist/lib/regex-extract/ingest-router-l4.d.ts +0 -76
- package/dist/lib/regex-extract/patterns.d.ts +0 -61
- package/dist/lib/regex-extract/production-wire.d.ts +0 -128
- package/dist/lib/regex-extract/reconcile.d.ts +0 -162
- package/dist/lib/regex-extract/strip-code.d.ts +0 -24
- package/dist/lib/regex-extract/types.d.ts +0 -48
- package/dist/lib/reranker.d.ts +0 -80
- package/dist/lib/shadow-tracker.d.ts +0 -191
- package/dist/lib/shadow-tracker.js +0 -384
- package/dist/lib/spo-injection.d.ts +0 -52
- package/dist/lib/telemetry-collector.d.ts +0 -158
- package/dist/lib/telemetry-collector.js +0 -249
- package/dist/lib/temporal-detector.d.ts +0 -27
- package/dist/lib/viewer/auth.d.ts +0 -37
- package/dist/lib/viewer/auth.js +0 -70
- package/dist/lib/viewer/backpressure.d.ts +0 -59
- package/dist/lib/viewer/backpressure.js +0 -100
- package/dist/lib/viewer/broadcast-singleton.d.ts +0 -34
- package/dist/lib/viewer/broadcast-singleton.js +0 -49
- package/dist/lib/viewer/broadcast.d.ts +0 -66
- package/dist/lib/viewer/broadcast.js +0 -96
- package/dist/lib/viewer/event-types.d.ts +0 -132
- package/dist/lib/viewer/event-types.js +0 -74
- package/dist/lib/viewer/instrumentation.d.ts +0 -106
- package/dist/lib/viewer/instrumentation.js +0 -224
- package/dist/lib/viewer/migration.d.ts +0 -23
- package/dist/lib/viewer/migration.js +0 -56
- package/dist/lib/viewer/redaction.d.ts +0 -44
- package/dist/lib/viewer/redaction.js +0 -139
- package/dist/lib/viewer/session.d.ts +0 -51
- package/dist/lib/viewer/session.js +0 -87
- package/dist/mcp/tools/answer.d.ts +0 -94
- package/dist/mcp/tools/archive.d.ts +0 -152
- package/dist/mcp/tools/archive.js +0 -170
- package/dist/mcp/tools/conflict.d.ts +0 -44
- package/dist/mcp/tools/conflict.js +0 -130
- package/dist/mcp/tools/hooks.d.ts +0 -29
- package/dist/mcp/tools/hooks.js +0 -78
- package/dist/mcp/tools/mark.d.ts +0 -38
- package/dist/mcp/tools/mark.js +0 -82
- package/dist/mcp/tools/viewer.d.ts +0 -58
- package/dist/mcp/tools/viewer.js +0 -64
- package/dist/mcp-server.d.ts +0 -2
- package/dist/metrics.d.ts +0 -3
- package/dist/noise-filter.d.ts +0 -18
- package/dist/notion-sync.d.ts +0 -7
- package/dist/notion-sync.js +0 -97
- package/dist/observability/adapters/a3-adapter.d.ts +0 -63
- package/dist/observability/adapters/a3-adapter.js +0 -83
- package/dist/observability/adapters/p1-adapter.d.ts +0 -49
- package/dist/observability/adapters/p1-adapter.js +0 -63
- package/dist/observability/adapters/p5-adapter.d.ts +0 -36
- package/dist/observability/adapters/p5-adapter.js +0 -71
- package/dist/observability/cardinality.d.ts +0 -61
- package/dist/observability/cardinality.js +0 -300
- package/dist/observability/collectors/db-stats.collector.d.ts +0 -9
- package/dist/observability/collectors/db-stats.collector.js +0 -88
- package/dist/observability/collectors/eventbus.collector.d.ts +0 -6
- package/dist/observability/collectors/eventbus.collector.js +0 -50
- package/dist/observability/collectors/process.collector.d.ts +0 -7
- package/dist/observability/collectors/process.collector.js +0 -93
- package/dist/observability/collectors/provider-telemetry.collector.d.ts +0 -11
- package/dist/observability/collectors/provider-telemetry.collector.js +0 -112
- package/dist/observability/collectors/search-telemetry.collector.d.ts +0 -12
- package/dist/observability/collectors/search-telemetry.collector.js +0 -76
- package/dist/observability/exporter.d.ts +0 -30
- package/dist/observability/exporter.js +0 -182
- package/dist/observability/index.d.ts +0 -22
- package/dist/observability/index.js +0 -21
- package/dist/observability/metrics.d.ts +0 -53
- package/dist/observability/metrics.js +0 -213
- package/dist/observability/privacy-guard.d.ts +0 -32
- package/dist/observability/privacy-guard.js +0 -116
- package/dist/observability/record.d.ts +0 -83
- package/dist/observability/record.js +0 -217
- package/dist/observability/registry.d.ts +0 -60
- package/dist/observability/registry.js +0 -93
- package/dist/observability/types.d.ts +0 -115
- package/dist/observability/types.js +0 -235
- package/dist/observability.d.ts +0 -131
- package/dist/plugins/nox-hooks/index.d.ts +0 -61
- package/dist/plugins/nox-hooks/index.js +0 -99
- package/dist/primer.d.ts +0 -1
- package/dist/privacy/filter.d.ts +0 -27
- package/dist/privacy/patterns.d.ts +0 -29
- package/dist/privacy/tag-parser.d.ts +0 -24
- package/dist/project-context-gen.d.ts +0 -10
- package/dist/providers/embedding/gemini.d.ts +0 -73
- package/dist/providers/embedding/openai.d.ts +0 -76
- package/dist/providers/embedding/types.d.ts +0 -39
- package/dist/providers/embedding/voyage.d.ts +0 -36
- package/dist/providers/index.d.ts +0 -116
- package/dist/providers/llm/anthropic.d.ts +0 -29
- package/dist/providers/llm/chain.d.ts +0 -99
- package/dist/providers/llm/gemini.d.ts +0 -48
- package/dist/providers/llm/openai.d.ts +0 -64
- package/dist/providers/llm/types.d.ts +0 -47
- package/dist/providers/telemetry.d.ts +0 -87
- package/dist/providers/types.d.ts +0 -42
- package/dist/query-entity-count.d.ts +0 -54
- package/dist/reflect.d.ts +0 -26
- package/dist/reindex-errors.d.ts +0 -7
- package/dist/reindex.d.ts +0 -16
- package/dist/retention.d.ts +0 -40
- package/dist/salience.d.ts +0 -85
- package/dist/scripts/migrate-v17-ops-audit.d.ts +0 -17
- package/dist/search-dedup.d.ts +0 -44
- package/dist/search-expansion.d.ts +0 -20
- package/dist/search.d.ts +0 -62
- package/dist/seh-detector.d.ts +0 -31
- package/dist/self-improve.d.ts +0 -1
- package/dist/session-distill.d.ts +0 -29
- package/dist/session-update.d.ts +0 -1
- package/dist/shared-memory.d.ts +0 -24
- package/dist/stats.d.ts +0 -1
- package/dist/temporal-retrieval.d.ts +0 -132
- package/dist/tier-manager.d.ts +0 -69
- package/dist/vectorize.d.ts +0 -16
- package/dist/version.d.ts +0 -1
- package/dist/watch.d.ts +0 -8
|
@@ -1,30 +0,0 @@
|
|
|
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[];
|
|
@@ -1,44 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,14 +0,0 @@
|
|
|
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";
|
|
@@ -1,76 +0,0 @@
|
|
|
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[];
|
|
@@ -1,61 +0,0 @@
|
|
|
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;
|
|
@@ -1,128 +0,0 @@
|
|
|
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;
|
|
@@ -1,162 +0,0 @@
|
|
|
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;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T1 — stripCodeBlocks helper.
|
|
3
|
-
*
|
|
4
|
-
* Adapted from gbrain/src/core/link-extraction.ts (MIT, Garry Tan, https://github.com/garry-tan/gbrain).
|
|
5
|
-
* Spec: specs/2026-05-18-L4-regex-first-extraction.md §6.1.
|
|
6
|
-
*
|
|
7
|
-
* Replaces fenced ``` blocks (with optional language tag) AND inline `code`
|
|
8
|
-
* with whitespace of equivalent length. Preserving length keeps any downstream
|
|
9
|
-
* offset/line maths stable across the strip — callers can run regexes over the
|
|
10
|
-
* stripped buffer and report locations against the original text.
|
|
11
|
-
*/
|
|
12
|
-
/** Stable result of stripping. */
|
|
13
|
-
export interface StripResult {
|
|
14
|
-
stripped: string;
|
|
15
|
-
hadFences: boolean;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Strip fenced + inline + indented-4 code spans from markdown, returning a
|
|
19
|
-
* length-preserved string safe for further regex matching.
|
|
20
|
-
*
|
|
21
|
-
* Order matters: fences first (so triple-backtick inline doesn't get clipped),
|
|
22
|
-
* then inline backticks.
|
|
23
|
-
*/
|
|
24
|
-
export declare function stripCodeBlocks(text: string): StripResult;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* L4 regex-extract — shared types.
|
|
3
|
-
*
|
|
4
|
-
* Cross-ref: specs/2026-05-18-L4-regex-first-extraction.md §4-§7.
|
|
5
|
-
*/
|
|
6
|
-
/** Whitelist of recognized entity types (DIR_PATTERN sources). */
|
|
7
|
-
export declare const NOX_ENTITY_TYPES: readonly ["feedback", "person", "lesson", "decision", "project", "team", "daily", "pending", "graph_node", "agent", "incident", "spec", "audit", "skill", "persona", "reference", "entities"];
|
|
8
|
-
export type NoxEntityType = (typeof NOX_ENTITY_TYPES)[number];
|
|
9
|
-
/** A single extracted entity reference (markdown link / wikilink / bare). */
|
|
10
|
-
export interface EntityRef {
|
|
11
|
-
/** Entity type bucket. */
|
|
12
|
-
entityType: NoxEntityType;
|
|
13
|
-
/** Slug (no extension, no fragment). */
|
|
14
|
-
slug: string;
|
|
15
|
-
/** Canonical key `<entityType>/<slug>` — dedup key. */
|
|
16
|
-
key: string;
|
|
17
|
-
/** Visible display text (markdown alt-text / wikilink pipe). */
|
|
18
|
-
display?: string;
|
|
19
|
-
/** Source pattern that matched. */
|
|
20
|
-
source: "markdown_link" | "wikilink" | "bare_ref";
|
|
21
|
-
}
|
|
22
|
-
/** Frontmatter-derived typed relation (§5 table). */
|
|
23
|
-
export interface FrontmatterRelation {
|
|
24
|
-
relationType: "is_agent_of" | "references" | "supersedes" | "caused_by" | "resolves" | "decided_by";
|
|
25
|
-
/** Target entity key `<entityType>/<slug>`; may be unqualified — caller resolves stub. */
|
|
26
|
-
target: string;
|
|
27
|
-
/** Raw field value from YAML for audit. */
|
|
28
|
-
raw: string;
|
|
29
|
-
}
|
|
30
|
-
/** Code-path reference (e.g. `src/lib/op-audit.ts:42`). */
|
|
31
|
-
export interface CodeRef {
|
|
32
|
-
/** Top-level dir (src, specs, audits, etc.). */
|
|
33
|
-
root: string;
|
|
34
|
-
/** Full path under root (e.g. `lib/op-audit.ts`). */
|
|
35
|
-
path: string;
|
|
36
|
-
/** Optional 1-based line number. */
|
|
37
|
-
line?: number;
|
|
38
|
-
/** Virtual entity key `codepath/<normalized_path>` for KG storage. */
|
|
39
|
-
key: string;
|
|
40
|
-
}
|
|
41
|
-
/** Aggregated regex extraction result. */
|
|
42
|
-
export interface RegexExtractionResult {
|
|
43
|
-
entityRefs: EntityRef[];
|
|
44
|
-
frontmatterRelations: FrontmatterRelation[];
|
|
45
|
-
codeRefs: CodeRef[];
|
|
46
|
-
/** True when stripCodeBlocks removed at least one fence/inline span. */
|
|
47
|
-
hadCodeFences: boolean;
|
|
48
|
-
}
|
package/dist/lib/reranker.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
export type RerankerMode = "off" | "shadow" | "active";
|
|
2
|
-
export interface RerankCandidate {
|
|
3
|
-
id?: number;
|
|
4
|
-
chunk_text: string;
|
|
5
|
-
[k: string]: any;
|
|
6
|
-
}
|
|
7
|
-
export interface RerankSummary {
|
|
8
|
-
mode: RerankerMode;
|
|
9
|
-
topKIn: number;
|
|
10
|
-
topKOut: number;
|
|
11
|
-
latencyMs: number;
|
|
12
|
-
positionChanges: number;
|
|
13
|
-
liftScore: number;
|
|
14
|
-
failed: boolean;
|
|
15
|
-
failureReason?: string;
|
|
16
|
-
}
|
|
17
|
-
export declare const DEFAULT_TOP_K_IN = 50;
|
|
18
|
-
export declare const DEFAULT_TOP_K_OUT = 10;
|
|
19
|
-
export declare const DEFAULT_MODEL = "Xenova/bge-reranker-base";
|
|
20
|
-
export declare const DEFAULT_TIMEOUT_MS = 2000;
|
|
21
|
-
export declare function getMode(): RerankerMode;
|
|
22
|
-
export declare function getTopKIn(): number;
|
|
23
|
-
export declare function getTopKOut(): number;
|
|
24
|
-
export declare function getModelName(): string;
|
|
25
|
-
export declare function getTimeoutMs(): number;
|
|
26
|
-
export type RerankerFn = (pairs: Array<{
|
|
27
|
-
text: string;
|
|
28
|
-
text_pair: string;
|
|
29
|
-
}>) => Promise<Array<{
|
|
30
|
-
score: number;
|
|
31
|
-
}>>;
|
|
32
|
-
/**
|
|
33
|
-
* Test hook: injetar uma fn mock pra evitar download do modelo.
|
|
34
|
-
* Em produção, NÃO chamar — `rerank()` carrega lazy via @xenova/transformers.
|
|
35
|
-
*
|
|
36
|
-
* Quando fn=null + reset=true (default), limpa singleton + cached error.
|
|
37
|
-
* Use reset=false só pra cenários onde você quer preservar erro cacheado.
|
|
38
|
-
*/
|
|
39
|
-
export declare function __setRerankerFnForTesting(fn: RerankerFn | null, reset?: boolean): void;
|
|
40
|
-
/**
|
|
41
|
-
* Pre-warm o singleton do modelo. Chamado pelo nox-mem-api boot quando
|
|
42
|
-
* NOX_RERANKER_MODE != off, pra evitar cold-start de ~12-90s no primeiro
|
|
43
|
-
* search request (D01 spec §risks §1). Idempotente: subsequent calls são no-op.
|
|
44
|
-
*/
|
|
45
|
-
export declare function preloadModel(): Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Conta chunks que mudaram posição entre os top-K original e o pós-rerank.
|
|
48
|
-
* Trabalha por id (campo opcional). Chunks sem id são ignorados (não rastreáveis).
|
|
49
|
-
*/
|
|
50
|
-
export declare function computePositionChanges(origTopK: RerankCandidate[], newTopK: RerankCandidate[]): number;
|
|
51
|
-
/**
|
|
52
|
-
* Lift score: mean displacement normalizado em [0, 1].
|
|
53
|
-
*
|
|
54
|
-
* Combina dois sinais:
|
|
55
|
-
* 1) displacement intra-intersection: |orig_pos − new_pos| pra ids em ambos
|
|
56
|
-
* 2) turnover (set churn): id que entrou OU saiu conta como displacement = K
|
|
57
|
-
*
|
|
58
|
-
* Total = sum(deltas) / (count * K), onde K = max(|orig|, |new|).
|
|
59
|
-
*
|
|
60
|
-
* Edge cases:
|
|
61
|
-
* - sets disjoint → todos turnover, score = 1
|
|
62
|
-
* - identical → 0
|
|
63
|
-
* - swap top-2 (K=5) → 2 ids movem 1 cada → 2/(5*4) = 0.1
|
|
64
|
-
*/
|
|
65
|
-
export declare function computeLiftScore(origTopK: RerankCandidate[], newTopK: RerankCandidate[]): number;
|
|
66
|
-
/**
|
|
67
|
-
* Rerank candidates via cross-encoder. Comportamento per mode:
|
|
68
|
-
*
|
|
69
|
-
* - off: no-op, retorna candidates.slice(0, topK), summary mode='off'
|
|
70
|
-
* - shadow: roda reranker, calcula lift, retorna candidates ORIGINAIS top-K
|
|
71
|
-
* (não muta ranking — caller recebe ordem pre-rerank)
|
|
72
|
-
* - active: roda reranker, retorna pós-rerank top-K (muta ranking)
|
|
73
|
-
*
|
|
74
|
-
* Fail-open: qualquer erro (model load, timeout, ONNX crash) → retorna
|
|
75
|
-
* candidates.slice(0, topK) original com summary.failed=true. Não joga.
|
|
76
|
-
*/
|
|
77
|
-
export declare function rerank(query: string, candidates: RerankCandidate[], topKOut?: number): Promise<{
|
|
78
|
-
results: RerankCandidate[];
|
|
79
|
-
summary: RerankSummary;
|
|
80
|
-
}>;
|