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,97 @@
|
|
|
1
|
+
// E-lite-2 backfill CLI subcommand (E14 Wave 1 Fase 1, 2026-05-17)
|
|
2
|
+
// Wrapped in withOpAudit for snapshot pre-op + audit trail.
|
|
3
|
+
// SHADOW mode: populates chunks.fts_anchor column WITHOUT recreating FTS5
|
|
4
|
+
// virtual table. Active mode (Fase 2): drop+recreate chunks_fts indexing
|
|
5
|
+
// fts_anchor + update triggers.
|
|
6
|
+
//
|
|
7
|
+
// Spec: specs/2026-05-10-E14-retrieval-evolution.md Addendum B
|
|
8
|
+
//
|
|
9
|
+
// Usage:
|
|
10
|
+
// nox-mem backfill-fts-anchor [--dry-run] [--limit N] [--batch-size N]
|
|
11
|
+
import { withOpAudit } from "./lib/op-audit.js";
|
|
12
|
+
import { getDb } from "./db.js";
|
|
13
|
+
import { extractAnchors } from "./lib/fts-anchor.js";
|
|
14
|
+
export async function backfillFtsAnchor(opts = {}) {
|
|
15
|
+
const batchSize = opts.batchSize ?? 2000;
|
|
16
|
+
const dryRun = opts.dryRun ?? false;
|
|
17
|
+
const t0 = Date.now();
|
|
18
|
+
const exec = async () => {
|
|
19
|
+
const db = getDb();
|
|
20
|
+
const totalQ = opts.force ? "SELECT COUNT(*) AS n FROM chunks" : "SELECT COUNT(*) AS n FROM chunks WHERE fts_anchor IS NULL OR fts_anchor = ''";
|
|
21
|
+
const totalRow = db.prepare(totalQ).get();
|
|
22
|
+
const totalChunks = totalRow.n;
|
|
23
|
+
const cap = opts.limit ? Math.min(totalChunks, opts.limit) : totalChunks;
|
|
24
|
+
let processed = 0;
|
|
25
|
+
let withAnchors = 0;
|
|
26
|
+
let withoutAnchors = 0;
|
|
27
|
+
let totalTerms = 0;
|
|
28
|
+
const selectStmt = opts.force
|
|
29
|
+
? db.prepare("SELECT id, chunk_text FROM chunks ORDER BY id ASC LIMIT ? OFFSET ?")
|
|
30
|
+
: db.prepare("SELECT id, chunk_text FROM chunks WHERE fts_anchor IS NULL OR fts_anchor = '' ORDER BY id ASC LIMIT ?");
|
|
31
|
+
const updateStmt = db.prepare("UPDATE chunks SET fts_anchor = ? WHERE id = ?");
|
|
32
|
+
while (processed < cap) {
|
|
33
|
+
const remaining = cap - processed;
|
|
34
|
+
const fetchSize = Math.min(batchSize, remaining);
|
|
35
|
+
const batch = (opts.force
|
|
36
|
+
? selectStmt.all(fetchSize, processed)
|
|
37
|
+
: selectStmt.all(fetchSize));
|
|
38
|
+
if (batch.length === 0)
|
|
39
|
+
break;
|
|
40
|
+
const updates = [];
|
|
41
|
+
for (const { id, chunk_text } of batch) {
|
|
42
|
+
const anchors = extractAnchors(chunk_text);
|
|
43
|
+
const terms = anchors ? anchors.split(" ").length : 0;
|
|
44
|
+
if (anchors)
|
|
45
|
+
withAnchors++;
|
|
46
|
+
else
|
|
47
|
+
withoutAnchors++;
|
|
48
|
+
totalTerms += terms;
|
|
49
|
+
updates.push([anchors, id]);
|
|
50
|
+
}
|
|
51
|
+
if (!dryRun) {
|
|
52
|
+
const tx = db.transaction((items) => {
|
|
53
|
+
for (const [anchors, id] of items)
|
|
54
|
+
updateStmt.run(anchors, id);
|
|
55
|
+
});
|
|
56
|
+
tx(updates);
|
|
57
|
+
}
|
|
58
|
+
processed += batch.length;
|
|
59
|
+
if (processed % 5000 === 0 || processed === cap) {
|
|
60
|
+
const pct = ((processed / cap) * 100).toFixed(1);
|
|
61
|
+
console.log(`[backfill-fts-anchor] ${processed}/${cap} (${pct}%) — withAnchors=${withAnchors} mean=${(totalTerms / processed).toFixed(1)}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
totalChunks,
|
|
66
|
+
processed,
|
|
67
|
+
withAnchors,
|
|
68
|
+
withoutAnchors,
|
|
69
|
+
meanTerms: processed > 0 ? totalTerms / processed : 0,
|
|
70
|
+
durationMs: Date.now() - t0,
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
if (dryRun) {
|
|
74
|
+
console.log("[backfill-fts-anchor] DRY-RUN mode — no UPDATEs will be executed");
|
|
75
|
+
return await exec();
|
|
76
|
+
}
|
|
77
|
+
// Wrap in withOpAudit for snapshot + audit trail
|
|
78
|
+
const auditResult = await withOpAudit("backfill-fts-anchor-shadow", async () => {
|
|
79
|
+
const r = await exec();
|
|
80
|
+
return {
|
|
81
|
+
affected_rows: r.processed,
|
|
82
|
+
notes: `withAnchors=${r.withAnchors} withoutAnchors=${r.withoutAnchors} meanTerms=${r.meanTerms.toFixed(2)} batchSize=${batchSize} limit=${opts.limit ?? "all"}`,
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
console.log(`[backfill-fts-anchor] op-audit success — affected=${auditResult.affected_rows} notes=${auditResult.notes}`);
|
|
86
|
+
// exec ran inside withOpAudit but result not exposed; re-query DB for final stats
|
|
87
|
+
const db = getDb();
|
|
88
|
+
const finalRow = db.prepare("SELECT COUNT(*) AS n, COUNT(CASE WHEN fts_anchor != '' THEN 1 END) AS with_a FROM chunks").get();
|
|
89
|
+
return {
|
|
90
|
+
totalChunks: finalRow.n,
|
|
91
|
+
processed: auditResult.affected_rows ?? 0,
|
|
92
|
+
withAnchors: finalRow.with_a,
|
|
93
|
+
withoutAnchors: finalRow.n - finalRow.with_a,
|
|
94
|
+
meanTerms: 0, // approximate; real value in audit notes
|
|
95
|
+
durationMs: Date.now() - t0,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface BackfillSourceTypeOpts {
|
|
2
|
+
dryRun?: boolean;
|
|
3
|
+
limit?: number;
|
|
4
|
+
batchSize?: number;
|
|
5
|
+
force?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface BackfillSourceTypeResult {
|
|
8
|
+
totalChunks: number;
|
|
9
|
+
processed: number;
|
|
10
|
+
byType: Record<string, number>;
|
|
11
|
+
durationMs: number;
|
|
12
|
+
dryRun: boolean;
|
|
13
|
+
affected_rows?: number;
|
|
14
|
+
notes?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const PATTERNS: Array<[RegExp, string]>;
|
|
17
|
+
export declare function classifyPath(sourceFile: string): string;
|
|
18
|
+
export declare function backfillSourceType(opts?: BackfillSourceTypeOpts): Promise<BackfillSourceTypeResult>;
|
|
19
|
+
export declare function parseArgs(argv: string[]): BackfillSourceTypeOpts;
|
|
20
|
+
export declare function formatResult(r: BackfillSourceTypeResult): string;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// backfill-source-type.ts — Populate `source_type` column for legacy chunks
|
|
2
|
+
// (Task F, 2026-05-19; companion to PR #150 salience refactor)
|
|
3
|
+
//
|
|
4
|
+
// Motivation: G4 ablation A5 (source_type_boost only) = 0.4817 = A0 baseline (no boosts)
|
|
5
|
+
// → SOURCE_TYPE_BOOST is INERT. Audit 2026-05-19 found 67,949 chunks (98.48%) with
|
|
6
|
+
// `source_type IS NULL`. This script derives source_type from `source_file` path
|
|
7
|
+
// patterns and backfills in batches.
|
|
8
|
+
//
|
|
9
|
+
// Wrapped in withOpAudit (CLAUDE.md rule #6) — snapshot pre-op + audit row.
|
|
10
|
+
//
|
|
11
|
+
// Mapping defined in docs/audits/2026-05-19-source-type-backfill-mapping.md.
|
|
12
|
+
//
|
|
13
|
+
// Usage:
|
|
14
|
+
// nox-mem backfill-source-type [--dry-run] [--limit N] [--batch-size N] [--force]
|
|
15
|
+
//
|
|
16
|
+
// --dry-run Preview counts per source_type, no mutation
|
|
17
|
+
// --limit N Process at most N chunks
|
|
18
|
+
// --batch-size N Transaction size (default 2000)
|
|
19
|
+
// --force Overwrite existing source_type values (NOT just NULL/empty)
|
|
20
|
+
import { withOpAudit } from "./lib/op-audit.js";
|
|
21
|
+
import { getDb } from "./db.js";
|
|
22
|
+
// ─── Path → source_type mapping (canonical, audit 2026-05-19) ─────────────────
|
|
23
|
+
// Order matters: first match wins. Most specific patterns first.
|
|
24
|
+
// Each alternative is its own entry to avoid regex operator-precedence
|
|
25
|
+
// ambiguity (CodeQL js/regex/missing-regexp-anchor).
|
|
26
|
+
// `(?:^|\/)<prefix>\/` matches the prefix at start-of-string OR after any
|
|
27
|
+
// path separator. This handles BOTH relative paths (e.g. `sessions/foo.md`)
|
|
28
|
+
// AND nested paths (e.g. `memory/sessions/foo.md`). Empirical fix discovered
|
|
29
|
+
// during initial dry-run 2026-05-19 22:36 BRT — prior `\/<prefix>\/` only
|
|
30
|
+
// matched nested paths, missing 99% of corpus rooted at relative prefixes.
|
|
31
|
+
export const PATTERNS = [
|
|
32
|
+
[/(?:^|\/)entities\//, "entity"],
|
|
33
|
+
[/(?:^|\/)cache\/ocr\//, "ocr-cache"],
|
|
34
|
+
[/(?:^|\/)sessions\//, "session"],
|
|
35
|
+
[/(?:^|\/)shared\/imports\/Claude\/skills\//, "skill"],
|
|
36
|
+
[/(?:^|\/)shared\/imports\/Claude\/commands\//, "command"],
|
|
37
|
+
[/(?:^|\/)shared\/lex-biblioteca\//, "legal-template"],
|
|
38
|
+
[/(?:^|\/)Claude\/Projetos\//, "project-doc"],
|
|
39
|
+
[/(?:^|\/)memory\/mac-docs\//, "personal-doc"],
|
|
40
|
+
[/(?:^|\/)memory\/lessons\//, "lesson"],
|
|
41
|
+
[/-lessons\.md$/, "lesson"],
|
|
42
|
+
[/\.md$/, "note"],
|
|
43
|
+
];
|
|
44
|
+
const FALLBACK_TYPE = "other";
|
|
45
|
+
export function classifyPath(sourceFile) {
|
|
46
|
+
if (!sourceFile)
|
|
47
|
+
return FALLBACK_TYPE;
|
|
48
|
+
for (const [rx, type] of PATTERNS) {
|
|
49
|
+
if (rx.test(sourceFile))
|
|
50
|
+
return type;
|
|
51
|
+
}
|
|
52
|
+
return FALLBACK_TYPE;
|
|
53
|
+
}
|
|
54
|
+
// ─── Main entry ───────────────────────────────────────────────────────────────
|
|
55
|
+
export async function backfillSourceType(opts = {}) {
|
|
56
|
+
const batchSize = opts.batchSize ?? 2000;
|
|
57
|
+
const dryRun = opts.dryRun ?? false;
|
|
58
|
+
const force = opts.force ?? false;
|
|
59
|
+
const t0 = Date.now();
|
|
60
|
+
const exec = async () => {
|
|
61
|
+
const db = getDb();
|
|
62
|
+
const totalQ = force
|
|
63
|
+
? "SELECT COUNT(*) AS n FROM chunks"
|
|
64
|
+
: "SELECT COUNT(*) AS n FROM chunks WHERE source_type IS NULL OR source_type = ''";
|
|
65
|
+
const totalRow = db.prepare(totalQ).get();
|
|
66
|
+
const totalChunks = totalRow.n;
|
|
67
|
+
const cap = opts.limit ? Math.min(totalChunks, opts.limit) : totalChunks;
|
|
68
|
+
const byType = {};
|
|
69
|
+
let processed = 0;
|
|
70
|
+
// BOTH modes use keyset pagination (WHERE id > :lastId) for two reasons:
|
|
71
|
+
// 1. Avoid OFFSET skew under concurrent ingest watcher (review HIGH #1)
|
|
72
|
+
// 2. dry-run safety: without keyset, non-force dry-run re-queries the
|
|
73
|
+
// same NULL-filtered batch forever (bug found empirically 2026-05-19 22:42).
|
|
74
|
+
// In APPLY mode UPDATE removes rows from filter so old approach worked
|
|
75
|
+
// by accident; in dry-run the filter never shrinks so iteration repeats.
|
|
76
|
+
// `--force`: overwrite ALL non-'external' rows (preserves curated values).
|
|
77
|
+
const selectStmt = force
|
|
78
|
+
? db.prepare("SELECT id, source_file FROM chunks WHERE id > ? AND (source_type IS NULL OR source_type != 'external') ORDER BY id ASC LIMIT ?")
|
|
79
|
+
: db.prepare("SELECT id, source_file FROM chunks WHERE id > ? AND (source_type IS NULL OR source_type = '') ORDER BY id ASC LIMIT ?");
|
|
80
|
+
// NOTE: do NOT touch updated_at — column-correction migration, not user
|
|
81
|
+
// activity. Bulk-stamping 67k chunks corrupts recency signal in salience.
|
|
82
|
+
// The `AND (source_type IS NULL OR source_type != 'external')` guard
|
|
83
|
+
// preserves curated 'external' values even under --force (review MEDIUM #6).
|
|
84
|
+
const updateStmt = db.prepare("UPDATE chunks SET source_type = ? WHERE id = ? AND (source_type IS NULL OR source_type != 'external')");
|
|
85
|
+
// Keyset pagination cursor (both modes).
|
|
86
|
+
let lastId = 0;
|
|
87
|
+
let nextHeartbeat = 10000;
|
|
88
|
+
while (processed < cap) {
|
|
89
|
+
const remaining = cap - processed;
|
|
90
|
+
const fetchSize = Math.min(batchSize, remaining);
|
|
91
|
+
const batch = selectStmt.all(lastId, fetchSize);
|
|
92
|
+
if (batch.length === 0)
|
|
93
|
+
break;
|
|
94
|
+
const updates = [];
|
|
95
|
+
for (const { id, source_file } of batch) {
|
|
96
|
+
const stype = classifyPath(source_file);
|
|
97
|
+
byType[stype] = (byType[stype] ?? 0) + 1;
|
|
98
|
+
updates.push([stype, id]);
|
|
99
|
+
if (id > lastId)
|
|
100
|
+
lastId = id;
|
|
101
|
+
}
|
|
102
|
+
if (!dryRun) {
|
|
103
|
+
const tx = db.transaction((items) => {
|
|
104
|
+
for (const [stype, id] of items)
|
|
105
|
+
updateStmt.run(stype, id);
|
|
106
|
+
});
|
|
107
|
+
tx(updates);
|
|
108
|
+
}
|
|
109
|
+
processed += batch.length;
|
|
110
|
+
// Heartbeat every ~10k rows regardless of batchSize (review LOW heartbeat fix).
|
|
111
|
+
if (processed >= nextHeartbeat || processed === cap) {
|
|
112
|
+
const elapsed = ((Date.now() - t0) / 1000).toFixed(1);
|
|
113
|
+
console.error(`[backfill-source-type] ${dryRun ? "DRY-RUN " : ""}${processed}/${cap} chunks (${elapsed}s)`);
|
|
114
|
+
nextHeartbeat = Math.ceil((processed + 1) / 10000) * 10000;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
totalChunks,
|
|
119
|
+
processed,
|
|
120
|
+
byType,
|
|
121
|
+
durationMs: Date.now() - t0,
|
|
122
|
+
dryRun,
|
|
123
|
+
// OpResult fields — populated for audit log clarity:
|
|
124
|
+
affected_rows: dryRun ? 0 : processed,
|
|
125
|
+
notes: `backfill-source-type ${dryRun ? "DRY-RUN" : "applied"} (force=${force}, batch=${batchSize})`,
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
// Dry-run skips withOpAudit (no mutation → no snapshot needed).
|
|
129
|
+
if (dryRun) {
|
|
130
|
+
return await exec();
|
|
131
|
+
}
|
|
132
|
+
// Wrap mutation in withOpAudit per CLAUDE.md rule #6.
|
|
133
|
+
return await withOpAudit("backfill-source-type", exec);
|
|
134
|
+
}
|
|
135
|
+
// ─── CLI entry-point glue (wired by src/index.ts) ─────────────────────────────
|
|
136
|
+
export function parseArgs(argv) {
|
|
137
|
+
const opts = {};
|
|
138
|
+
for (let i = 0; i < argv.length; i++) {
|
|
139
|
+
const a = argv[i];
|
|
140
|
+
if (a === "--dry-run")
|
|
141
|
+
opts.dryRun = true;
|
|
142
|
+
else if (a === "--force")
|
|
143
|
+
opts.force = true;
|
|
144
|
+
else if (a === "--limit" && argv[i + 1]) {
|
|
145
|
+
const raw = argv[++i];
|
|
146
|
+
const n = Number.parseInt(raw, 10);
|
|
147
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
148
|
+
throw new Error(`--limit requires positive integer, got: '${raw}'`);
|
|
149
|
+
}
|
|
150
|
+
opts.limit = n;
|
|
151
|
+
}
|
|
152
|
+
else if (a === "--batch-size" && argv[i + 1]) {
|
|
153
|
+
const raw = argv[++i];
|
|
154
|
+
const n = Number.parseInt(raw, 10);
|
|
155
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
156
|
+
throw new Error(`--batch-size requires positive integer, got: '${raw}'`);
|
|
157
|
+
}
|
|
158
|
+
opts.batchSize = n;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return opts;
|
|
162
|
+
}
|
|
163
|
+
export function formatResult(r) {
|
|
164
|
+
if (r.processed === 0) {
|
|
165
|
+
return `${r.dryRun ? "[DRY-RUN] " : ""}No chunks to process (totalChunks=${r.totalChunks})`;
|
|
166
|
+
}
|
|
167
|
+
const lines = [];
|
|
168
|
+
lines.push(`${r.dryRun ? "[DRY-RUN] " : ""}Backfill complete: ${r.processed}/${r.totalChunks} chunks in ${(r.durationMs / 1000).toFixed(1)}s`);
|
|
169
|
+
lines.push("");
|
|
170
|
+
lines.push("Distribution:");
|
|
171
|
+
const entries = Object.entries(r.byType).sort((a, b) => b[1] - a[1]);
|
|
172
|
+
if (entries.length === 0) {
|
|
173
|
+
lines.push(" (empty)");
|
|
174
|
+
return lines.join("\n");
|
|
175
|
+
}
|
|
176
|
+
const maxLabel = Math.max(...entries.map(([k]) => k.length));
|
|
177
|
+
for (const [type, count] of entries) {
|
|
178
|
+
const pct = ((count * 100) / r.processed).toFixed(2);
|
|
179
|
+
lines.push(` ${type.padEnd(maxLabel)} ${String(count).padStart(7)} (${pct}%)`);
|
|
180
|
+
}
|
|
181
|
+
return lines.join("\n");
|
|
182
|
+
}
|
package/dist/churn.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/churn.ts — item 2 do plano Cipher×nox-mem (2026-06-05).
|
|
3
|
+
* Spec: memoria-nox specs/2026-06-05-cipher-simbiose-itens-1-2-3.md
|
|
4
|
+
*
|
|
5
|
+
* Detecção de churn: chunk NOVO (created_at >= since) semanticamente próximo
|
|
6
|
+
* de chunk ANTIGO = re-decisão sobre o mesmo tópico = knowledge gap (a memória
|
|
7
|
+
* não preveniu retrabalho). Read-only; $0 Gemini — usa embeddings já
|
|
8
|
+
* materializados em vec_chunks via KNN sqlite-vec (padrão semanticSearch de
|
|
9
|
+
* embed.ts). Métrica: L2 sobre vetores normalizados ⇒ cos = 1 - d²/2.
|
|
10
|
+
*/
|
|
11
|
+
import type Database from "better-sqlite3";
|
|
12
|
+
export interface ChurnOpts {
|
|
13
|
+
since: string;
|
|
14
|
+
threshold?: number;
|
|
15
|
+
types?: string[];
|
|
16
|
+
k?: number;
|
|
17
|
+
maxNew?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface ChurnPair {
|
|
20
|
+
newChunkId: number;
|
|
21
|
+
newFile: string;
|
|
22
|
+
newText: string;
|
|
23
|
+
newCreatedAt: string;
|
|
24
|
+
oldChunkId: number;
|
|
25
|
+
oldFile: string;
|
|
26
|
+
oldText: string;
|
|
27
|
+
oldCreatedAt: string;
|
|
28
|
+
similarity: number;
|
|
29
|
+
}
|
|
30
|
+
export declare function detectChurn(db: Database.Database, opts: ChurnOpts): ChurnPair[];
|
|
31
|
+
export declare function churnReportMd(pairs: ChurnPair[], since: string): string;
|
package/dist/churn.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** L2 sobre embeddings normalizados (gemini-embedding-001 3072d): cos = 1 - d²/2 */
|
|
2
|
+
function distToSim(d) {
|
|
3
|
+
return 1 - (d * d) / 2;
|
|
4
|
+
}
|
|
5
|
+
export function detectChurn(db, opts) {
|
|
6
|
+
const threshold = opts.threshold ?? 0.8;
|
|
7
|
+
const k = opts.k ?? 5;
|
|
8
|
+
const maxNew = opts.maxNew ?? 2000;
|
|
9
|
+
const typeFilter = opts.types?.length
|
|
10
|
+
? `AND c.chunk_type IN (${opts.types.map(() => "?").join(",")})`
|
|
11
|
+
: "";
|
|
12
|
+
const newChunks = db
|
|
13
|
+
.prepare(`SELECT c.id, c.source_file, c.chunk_text, c.created_at, vc.embedding
|
|
14
|
+
FROM chunks c
|
|
15
|
+
JOIN vec_chunk_map m ON m.chunk_id = c.id
|
|
16
|
+
JOIN vec_chunks vc ON vc.rowid = m.vec_rowid
|
|
17
|
+
WHERE c.created_at >= datetime(?) ${typeFilter}
|
|
18
|
+
ORDER BY c.created_at DESC
|
|
19
|
+
LIMIT ?`)
|
|
20
|
+
.all(opts.since, ...(opts.types ?? []), maxNew);
|
|
21
|
+
// Mesmo shape do semanticSearch (embed.ts): MATCH + k, vec_rowid no map.
|
|
22
|
+
const knn = db.prepare(`SELECT m.chunk_id, vc.distance, c.source_file, c.chunk_text, c.created_at
|
|
23
|
+
FROM vec_chunks vc
|
|
24
|
+
JOIN vec_chunk_map m ON m.vec_rowid = vc.rowid
|
|
25
|
+
JOIN chunks c ON c.id = m.chunk_id
|
|
26
|
+
WHERE vc.embedding MATCH ?
|
|
27
|
+
AND k = ?
|
|
28
|
+
ORDER BY vc.distance`);
|
|
29
|
+
const pairs = [];
|
|
30
|
+
for (const nc of newChunks) {
|
|
31
|
+
const neighbors = knn.all(nc.embedding, k + 1);
|
|
32
|
+
for (const nb of neighbors) {
|
|
33
|
+
if (nb.chunk_id === nc.id)
|
|
34
|
+
continue; // ele mesmo
|
|
35
|
+
if (nb.created_at >= nc.created_at)
|
|
36
|
+
continue; // só vizinho mais ANTIGO conta
|
|
37
|
+
const olderThanSince = db
|
|
38
|
+
.prepare("SELECT ? < datetime(?) AS old")
|
|
39
|
+
.get(nb.created_at, opts.since);
|
|
40
|
+
if (!olderThanSince.old)
|
|
41
|
+
continue; // vizinho dentro do período = não é re-decisão
|
|
42
|
+
const sim = distToSim(nb.distance);
|
|
43
|
+
if (sim >= threshold) {
|
|
44
|
+
pairs.push({
|
|
45
|
+
newChunkId: nc.id,
|
|
46
|
+
newFile: nc.source_file,
|
|
47
|
+
newText: nc.chunk_text,
|
|
48
|
+
newCreatedAt: nc.created_at,
|
|
49
|
+
oldChunkId: nb.chunk_id,
|
|
50
|
+
oldFile: nb.source_file,
|
|
51
|
+
oldText: nb.chunk_text,
|
|
52
|
+
oldCreatedAt: nb.created_at,
|
|
53
|
+
similarity: Math.round(sim * 1000) / 1000,
|
|
54
|
+
});
|
|
55
|
+
break; // 1 par por chunk novo (o vizinho antigo mais próximo)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return pairs.sort((a, b) => b.similarity - a.similarity);
|
|
60
|
+
}
|
|
61
|
+
const clip = (s, n = 80) => (s.length > n ? s.slice(0, n - 1) + "…" : s).replace(/\s+/g, " ");
|
|
62
|
+
export function churnReportMd(pairs, since) {
|
|
63
|
+
const EXACT = 0.995;
|
|
64
|
+
const exact = pairs.filter((p) => p.similarity >= EXACT);
|
|
65
|
+
const semantic = pairs.filter((p) => p.similarity < EXACT);
|
|
66
|
+
const lines = [
|
|
67
|
+
`# Churn report — desde ${since}`,
|
|
68
|
+
"",
|
|
69
|
+
`${pairs.length} pares detectados: ${semantic.length} re-decisões semânticas + ${exact.length} duplicatas exatas. Re-decisão = knowledge gap: a memória não preveniu retrabalho. Ação: Cipher propõe consolidação (NUNCA auto-muta).`,
|
|
70
|
+
"",
|
|
71
|
+
`## Re-decisões semânticas (0.80 ≤ sim < ${EXACT})`,
|
|
72
|
+
"",
|
|
73
|
+
];
|
|
74
|
+
for (const p of semantic) {
|
|
75
|
+
lines.push(`- **${p.similarity}** novo #${p.newChunkId} "${clip(p.newText)}" (${p.newCreatedAt.slice(0, 10)}) ↔ antigo #${p.oldChunkId} "${clip(p.oldText)}" (${p.oldCreatedAt.slice(0, 10)})`);
|
|
76
|
+
}
|
|
77
|
+
if (!semantic.length)
|
|
78
|
+
lines.push("_Nenhuma re-decisão semântica no período._");
|
|
79
|
+
lines.push("", `## Duplicatas exatas (sim ≥ ${EXACT}) — agrupadas por par de arquivos`, "");
|
|
80
|
+
const groups = new Map();
|
|
81
|
+
for (const p of exact) {
|
|
82
|
+
const key = `${p.newFile} ↔ ${p.oldFile}`;
|
|
83
|
+
const g = groups.get(key);
|
|
84
|
+
if (g)
|
|
85
|
+
g.count++;
|
|
86
|
+
else
|
|
87
|
+
groups.set(key, { count: 1, sample: p });
|
|
88
|
+
}
|
|
89
|
+
const sorted = [...groups.entries()].sort((a, b) => b[1].count - a[1].count);
|
|
90
|
+
for (const [key, g] of sorted) {
|
|
91
|
+
lines.push(`- **${g.count}× chunks** ${key} (ex: novo #${g.sample.newChunkId} ↔ antigo #${g.sample.oldChunkId})`);
|
|
92
|
+
}
|
|
93
|
+
if (!exact.length)
|
|
94
|
+
lines.push("_Nenhuma duplicata exata no período._");
|
|
95
|
+
if (!pairs.length)
|
|
96
|
+
lines.push("", "_Nenhum churn no período._");
|
|
97
|
+
return lines.join("\n") + "\n";
|
|
98
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/cli/answer.ts — P1 T8: `nox-mem answer "<question>" [flags]`.
|
|
3
|
+
*
|
|
4
|
+
* Thin wrapper over `lib/answer/index.ts`. No business logic here;
|
|
5
|
+
* we only parse argv, invoke answer(), and render to stdout.
|
|
6
|
+
*
|
|
7
|
+
* Flags (mirrors kickoff §T8 DoD + §5 AnswerRequest):
|
|
8
|
+
* --top-k N top-K retrieval (1..20, default 8)
|
|
9
|
+
* --max-tokens N LLM output budget (default 1500)
|
|
10
|
+
* --provider X 'gemini' (default) | 'mock'
|
|
11
|
+
* --model Y override (default 'gemini-2.5-flash-lite' per D41 #1)
|
|
12
|
+
* --temperature N 0..1, default 0.2
|
|
13
|
+
* --cite include numbered citation block (default ON)
|
|
14
|
+
* --no-cite suppress citation block (markers still kept inline)
|
|
15
|
+
* --no-citations strip [chunk_N] markers from rendered answer too
|
|
16
|
+
* --json machine-readable JSON; suppresses pretty output
|
|
17
|
+
* --session-id X passthrough for telemetry correlation
|
|
18
|
+
* --help, -h print usage and exit 0
|
|
19
|
+
*
|
|
20
|
+
* Exit codes (kickoff §6 status-code parity, mapped to shell-friendly ints):
|
|
21
|
+
* 0 ok
|
|
22
|
+
* 2 invalid argv (bad flag, missing question)
|
|
23
|
+
* 3 retrieval_empty
|
|
24
|
+
* 4 hallucination_after_retry
|
|
25
|
+
* 5 llm_error / llm_timeout
|
|
26
|
+
* 1 unexpected runtime error
|
|
27
|
+
*
|
|
28
|
+
* Test seams: pass `argv`, `stdout`, `stderr`, `runAnswer`, `telemetryStore`
|
|
29
|
+
* via runCli(opts). The bin shim (`bin/answer.ts` or `src/cli/index.ts`
|
|
30
|
+
* dispatcher) calls runCli(process.argv.slice(2)) with prod defaults.
|
|
31
|
+
*/
|
|
32
|
+
import type { AnswerOpts, AnswerResult } from "../lib/answer/index.js";
|
|
33
|
+
import { type TelemetryStore } from "../lib/answer/telemetry.js";
|
|
34
|
+
export interface ParsedArgs {
|
|
35
|
+
question: string;
|
|
36
|
+
topK?: number;
|
|
37
|
+
maxTokens?: number;
|
|
38
|
+
provider?: string;
|
|
39
|
+
model?: string;
|
|
40
|
+
temperature?: number;
|
|
41
|
+
/** include citation block beneath answer */
|
|
42
|
+
showCitations: boolean;
|
|
43
|
+
/** also strip [chunk_N] markers from the answer text itself */
|
|
44
|
+
stripMarkers: boolean;
|
|
45
|
+
json: boolean;
|
|
46
|
+
sessionId?: string;
|
|
47
|
+
help: boolean;
|
|
48
|
+
}
|
|
49
|
+
export declare class CliArgError extends Error {
|
|
50
|
+
constructor(message: string);
|
|
51
|
+
}
|
|
52
|
+
/** Parse argv into ParsedArgs. Pure function — easy to unit-test. */
|
|
53
|
+
export declare function parseArgs(argv: readonly string[]): ParsedArgs;
|
|
54
|
+
export declare const HELP_TEXT = "nox-mem answer \u2014 answer questions from nox-mem corpus with grounded citations.\n\nUsage:\n nox-mem answer \"<question>\" [flags]\n\nFlags:\n --top-k N top-K retrieval (1..20, default 8)\n --max-tokens N max LLM output tokens (64..8192, default 1500)\n --provider X 'gemini' (default) | 'mock'\n --model Y model id (default gemini-2.5-flash-lite per D41 #1)\n --temperature N 0..1, default 0.2\n --cite include numbered citation block (default)\n --no-cite suppress citation block\n --no-citations also strip [chunk_N] markers from answer text\n --json emit AnswerResponse JSON to stdout\n --session-id X correlation tag (telemetry only)\n -h, --help show this help and exit\n\nExamples:\n nox-mem answer \"What is the salience formula?\"\n nox-mem answer \"Which retention default for lessons?\" --top-k 12 --json\n NOX_ANSWER_MODEL=gemini-2.5-flash nox-mem answer \"Provider swap test\"\n\nExit codes: 0 ok | 2 bad argv | 3 retrieval_empty | 4 hallucination_after_retry | 5 llm_error\n";
|
|
55
|
+
export declare function renderHuman(res: AnswerResult, args: ParsedArgs): string;
|
|
56
|
+
export declare function renderJson(res: AnswerResult, args: ParsedArgs): string;
|
|
57
|
+
export interface RunCliOpts {
|
|
58
|
+
argv: readonly string[];
|
|
59
|
+
stdout: (line: string) => void;
|
|
60
|
+
stderr: (line: string) => void;
|
|
61
|
+
/** Test seam: replace answer() with a stub. */
|
|
62
|
+
runAnswer?: (opts: AnswerOpts) => Promise<AnswerResult>;
|
|
63
|
+
/** Test seam: optional telemetry sink. CLI writes one row per call. */
|
|
64
|
+
telemetryStore?: TelemetryStore;
|
|
65
|
+
}
|
|
66
|
+
export declare function runCli(opts: RunCliOpts): Promise<number>;
|