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,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T3 — SSE handler (framework-agnostic)
|
|
3
|
+
*
|
|
4
|
+
* Returns an async iterable of SSE lines + the header set to attach.
|
|
5
|
+
* Caller (Express / Fastify / raw http) wires this onto a response stream:
|
|
6
|
+
*
|
|
7
|
+
* const sse = openSseStream({ broadcaster, clientId, lastEventId });
|
|
8
|
+
* res.writeHead(200, sse.headers);
|
|
9
|
+
* for await (const chunk of sse.iter) {
|
|
10
|
+
* if (!res.write(chunk)) await once(res, "drain");
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* On client disconnect, caller invokes `sse.close()` to release resources.
|
|
14
|
+
*/
|
|
15
|
+
import { Broadcaster, type BroadcastEnvelope } from "../lib/viewer/broadcast.js";
|
|
16
|
+
export interface OpenSseStreamOptions {
|
|
17
|
+
broadcaster: Broadcaster;
|
|
18
|
+
/** Client id (UUIDv4). Caller mints + injects. */
|
|
19
|
+
clientId: string;
|
|
20
|
+
/** Last-Event-ID from request header, if any. */
|
|
21
|
+
lastEventId?: number;
|
|
22
|
+
/** Heartbeat interval ms. Default 15000. */
|
|
23
|
+
heartbeatMs?: number;
|
|
24
|
+
/** Hook called whenever an envelope is written (for telemetry). */
|
|
25
|
+
onWrite?: (env: BroadcastEnvelope) => void;
|
|
26
|
+
/** Hook called whenever a drop happens (queue full). */
|
|
27
|
+
onDrop?: (count: number) => void;
|
|
28
|
+
}
|
|
29
|
+
export interface SseStream {
|
|
30
|
+
headers: Record<string, string>;
|
|
31
|
+
iter: AsyncIterable<string>;
|
|
32
|
+
close: () => void;
|
|
33
|
+
}
|
|
34
|
+
export declare const SSE_HEADERS: Record<string, string>;
|
|
35
|
+
/**
|
|
36
|
+
* Format a ViewerEvent envelope as a single SSE message.
|
|
37
|
+
* Multi-line `data:` is correctly emitted per RFC.
|
|
38
|
+
*/
|
|
39
|
+
export declare function formatSseMessage(env: BroadcastEnvelope): string;
|
|
40
|
+
/** Heartbeat is an SSE comment line — ignored by EventSource, keeps proxies alive. */
|
|
41
|
+
export declare function formatHeartbeat(ringSize: number, clients: number): string;
|
|
42
|
+
/**
|
|
43
|
+
* Construct a complete SSE stream:
|
|
44
|
+
* - subscribes to the Broadcaster
|
|
45
|
+
* - emits SSE-formatted lines via async iterator
|
|
46
|
+
* - sends heartbeats on schedule
|
|
47
|
+
* - cleans up on `close()`
|
|
48
|
+
*/
|
|
49
|
+
export declare function openSseStream(opts: OpenSseStreamOptions): SseStream;
|
|
50
|
+
/**
|
|
51
|
+
* Parse the Last-Event-ID header (case-insensitive). Numeric only.
|
|
52
|
+
*/
|
|
53
|
+
export declare function parseLastEventId(headers: Record<string, string | string[] | undefined>): number | undefined;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T3 — SSE handler (framework-agnostic)
|
|
3
|
+
*
|
|
4
|
+
* Returns an async iterable of SSE lines + the header set to attach.
|
|
5
|
+
* Caller (Express / Fastify / raw http) wires this onto a response stream:
|
|
6
|
+
*
|
|
7
|
+
* const sse = openSseStream({ broadcaster, clientId, lastEventId });
|
|
8
|
+
* res.writeHead(200, sse.headers);
|
|
9
|
+
* for await (const chunk of sse.iter) {
|
|
10
|
+
* if (!res.write(chunk)) await once(res, "drain");
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* On client disconnect, caller invokes `sse.close()` to release resources.
|
|
14
|
+
*/
|
|
15
|
+
import { eventKindLabel } from "../lib/viewer/event-types.js";
|
|
16
|
+
export const SSE_HEADERS = {
|
|
17
|
+
"Content-Type": "text/event-stream; charset=utf-8",
|
|
18
|
+
"Cache-Control": "no-cache, no-transform",
|
|
19
|
+
Connection: "keep-alive",
|
|
20
|
+
"X-Accel-Buffering": "no", // disable nginx buffering
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Format a ViewerEvent envelope as a single SSE message.
|
|
24
|
+
* Multi-line `data:` is correctly emitted per RFC.
|
|
25
|
+
*/
|
|
26
|
+
export function formatSseMessage(env) {
|
|
27
|
+
const ev = env.ev;
|
|
28
|
+
const kindLabel = eventKindLabel(ev);
|
|
29
|
+
const payload = JSON.stringify(ev);
|
|
30
|
+
// SSE: id, event, data — each on its own line; record terminated by blank line.
|
|
31
|
+
return `id: ${env.id}\nevent: ${kindLabel}\ndata: ${payload}\n\n`;
|
|
32
|
+
}
|
|
33
|
+
/** Heartbeat is an SSE comment line — ignored by EventSource, keeps proxies alive. */
|
|
34
|
+
export function formatHeartbeat(ringSize, clients) {
|
|
35
|
+
const ts = new Date().toISOString();
|
|
36
|
+
return `: heartbeat ${ts} ring=${ringSize} clients=${clients}\n\n`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Construct a complete SSE stream:
|
|
40
|
+
* - subscribes to the Broadcaster
|
|
41
|
+
* - emits SSE-formatted lines via async iterator
|
|
42
|
+
* - sends heartbeats on schedule
|
|
43
|
+
* - cleans up on `close()`
|
|
44
|
+
*/
|
|
45
|
+
export function openSseStream(opts) {
|
|
46
|
+
const heartbeatMs = opts.heartbeatMs ?? 15_000;
|
|
47
|
+
let closed = false;
|
|
48
|
+
let wakeup = null;
|
|
49
|
+
let lastReportedDrops = 0;
|
|
50
|
+
const wake = () => {
|
|
51
|
+
if (wakeup) {
|
|
52
|
+
const cb = wakeup;
|
|
53
|
+
wakeup = null;
|
|
54
|
+
cb();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const client = opts.broadcaster.addClient(opts.clientId, wake, opts.lastEventId);
|
|
58
|
+
let heartbeatDue = false;
|
|
59
|
+
const heartbeatTimer = setInterval(() => {
|
|
60
|
+
heartbeatDue = true;
|
|
61
|
+
if (!closed)
|
|
62
|
+
wake();
|
|
63
|
+
}, heartbeatMs);
|
|
64
|
+
// Don't prevent process exit if forgotten.
|
|
65
|
+
if (typeof heartbeatTimer.unref === "function")
|
|
66
|
+
heartbeatTimer.unref();
|
|
67
|
+
async function* iter() {
|
|
68
|
+
// Initial line — tells the client we're connected and arms reconnect.
|
|
69
|
+
yield ": connected\n\n";
|
|
70
|
+
while (!closed) {
|
|
71
|
+
// Drain any queued envelopes first.
|
|
72
|
+
const batch = client.queue.drain();
|
|
73
|
+
const droppedNow = client.queue.stats().dropped;
|
|
74
|
+
if (droppedNow > lastReportedDrops) {
|
|
75
|
+
const delta = droppedNow - lastReportedDrops;
|
|
76
|
+
lastReportedDrops = droppedNow;
|
|
77
|
+
opts.onDrop?.(delta);
|
|
78
|
+
}
|
|
79
|
+
for (const env of batch) {
|
|
80
|
+
client.lastSentId = env.id;
|
|
81
|
+
opts.onWrite?.(env);
|
|
82
|
+
yield formatSseMessage(env);
|
|
83
|
+
}
|
|
84
|
+
if (heartbeatDue) {
|
|
85
|
+
heartbeatDue = false;
|
|
86
|
+
yield formatHeartbeat(opts.broadcaster.ringSnapshot().length, opts.broadcaster.clientCount());
|
|
87
|
+
}
|
|
88
|
+
if (closed)
|
|
89
|
+
break;
|
|
90
|
+
// Wait for next wake-up.
|
|
91
|
+
await new Promise((resolve) => {
|
|
92
|
+
wakeup = resolve;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
headers: { ...SSE_HEADERS },
|
|
98
|
+
iter: iter(),
|
|
99
|
+
close: () => {
|
|
100
|
+
if (closed)
|
|
101
|
+
return;
|
|
102
|
+
closed = true;
|
|
103
|
+
clearInterval(heartbeatTimer);
|
|
104
|
+
opts.broadcaster.removeClient(opts.clientId);
|
|
105
|
+
// Wake the iterator so it exits cleanly.
|
|
106
|
+
wake();
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Parse the Last-Event-ID header (case-insensitive). Numeric only.
|
|
112
|
+
*/
|
|
113
|
+
export function parseLastEventId(headers) {
|
|
114
|
+
for (const key of Object.keys(headers)) {
|
|
115
|
+
if (key.toLowerCase() === "last-event-id") {
|
|
116
|
+
const v = headers[key];
|
|
117
|
+
const raw = Array.isArray(v) ? v[0] : v;
|
|
118
|
+
if (raw === undefined)
|
|
119
|
+
return undefined;
|
|
120
|
+
const n = Number(raw);
|
|
121
|
+
return Number.isFinite(n) && n >= 0 ? n : undefined;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T13 — HTTP `POST /api/export` handler (framework-agnostic).
|
|
3
|
+
*
|
|
4
|
+
* Returns a `{ status, headers, body }` shape so the host server (express,
|
|
5
|
+
* fastify, plain http.Server) can adapt without coupling. The actual streaming
|
|
6
|
+
* write happens in the caller; we return the archive Buffer plus suggested
|
|
7
|
+
* headers (Content-Type, Content-Disposition, Content-Length).
|
|
8
|
+
*
|
|
9
|
+
* Body schema:
|
|
10
|
+
* { unencrypted?: bool,
|
|
11
|
+
* passphrase?: string, // accepted ONLY over POST body (TLS-protected)
|
|
12
|
+
* project?: string,
|
|
13
|
+
* since?: string,
|
|
14
|
+
* until?: string,
|
|
15
|
+
* exclude_embeddings?: bool }
|
|
16
|
+
*
|
|
17
|
+
* Auth: the parent API layer enforces middleware (regra #4 — port 18802 +
|
|
18
|
+
* existing auth). This module is unauthenticated by design; never expose it
|
|
19
|
+
* directly.
|
|
20
|
+
*/
|
|
21
|
+
import { ExportRequest, ProgressEvent } from "../lib/archive/orchestrator.js";
|
|
22
|
+
export interface HttpExportBody {
|
|
23
|
+
unencrypted?: boolean;
|
|
24
|
+
passphrase?: string;
|
|
25
|
+
project?: string;
|
|
26
|
+
since?: string;
|
|
27
|
+
until?: string;
|
|
28
|
+
exclude_embeddings?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface HttpResponse {
|
|
31
|
+
status: number;
|
|
32
|
+
headers: Record<string, string>;
|
|
33
|
+
body: Buffer | string;
|
|
34
|
+
}
|
|
35
|
+
export interface HttpExportDeps {
|
|
36
|
+
dbReader: () => Promise<Omit<ExportRequest, "passphrase" | "unencrypted" | "signal" | "onProgress">>;
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
onProgress?: (ev: ProgressEvent) => void;
|
|
39
|
+
/** Optional max archive size guard (defaults to 5 GiB). */
|
|
40
|
+
maxBytes?: number;
|
|
41
|
+
}
|
|
42
|
+
export declare function handleExport(body: HttpExportBody, deps: HttpExportDeps): Promise<HttpResponse>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T13 — HTTP `POST /api/export` handler (framework-agnostic).
|
|
3
|
+
*
|
|
4
|
+
* Returns a `{ status, headers, body }` shape so the host server (express,
|
|
5
|
+
* fastify, plain http.Server) can adapt without coupling. The actual streaming
|
|
6
|
+
* write happens in the caller; we return the archive Buffer plus suggested
|
|
7
|
+
* headers (Content-Type, Content-Disposition, Content-Length).
|
|
8
|
+
*
|
|
9
|
+
* Body schema:
|
|
10
|
+
* { unencrypted?: bool,
|
|
11
|
+
* passphrase?: string, // accepted ONLY over POST body (TLS-protected)
|
|
12
|
+
* project?: string,
|
|
13
|
+
* since?: string,
|
|
14
|
+
* until?: string,
|
|
15
|
+
* exclude_embeddings?: bool }
|
|
16
|
+
*
|
|
17
|
+
* Auth: the parent API layer enforces middleware (regra #4 — port 18802 +
|
|
18
|
+
* existing auth). This module is unauthenticated by design; never expose it
|
|
19
|
+
* directly.
|
|
20
|
+
*/
|
|
21
|
+
import { runExport, } from "../lib/archive/orchestrator.js";
|
|
22
|
+
const DEFAULT_MAX_BYTES = 5 * 1024 * 1024 * 1024;
|
|
23
|
+
export async function handleExport(body, deps) {
|
|
24
|
+
// Validate
|
|
25
|
+
if (!body.unencrypted &&
|
|
26
|
+
(typeof body.passphrase !== "string" || body.passphrase.length === 0)) {
|
|
27
|
+
return jsonResponse(400, {
|
|
28
|
+
error: "passphrase required when not unencrypted (D41 #2 encrypt-by-default)",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const corpus = await deps.dbReader();
|
|
32
|
+
if (body.exclude_embeddings) {
|
|
33
|
+
corpus.embeddings = undefined;
|
|
34
|
+
}
|
|
35
|
+
let result;
|
|
36
|
+
try {
|
|
37
|
+
result = await runExport({
|
|
38
|
+
...corpus,
|
|
39
|
+
filters: {
|
|
40
|
+
project: body.project ?? null,
|
|
41
|
+
since: body.since ?? null,
|
|
42
|
+
until: body.until ?? null,
|
|
43
|
+
},
|
|
44
|
+
unencrypted: body.unencrypted === true,
|
|
45
|
+
passphrase: body.passphrase,
|
|
46
|
+
signal: deps.signal,
|
|
47
|
+
onProgress: deps.onProgress,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
const msg = err.message;
|
|
52
|
+
if (/cancel/i.test(msg)) {
|
|
53
|
+
return jsonResponse(499, { error: "client closed request" });
|
|
54
|
+
}
|
|
55
|
+
return jsonResponse(500, { error: msg });
|
|
56
|
+
}
|
|
57
|
+
const max = deps.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
58
|
+
if (result.archive.length > max) {
|
|
59
|
+
return jsonResponse(413, {
|
|
60
|
+
error: `archive too large: ${result.archive.length} > ${max} bytes`,
|
|
61
|
+
hint: "use --project / --since filters or split via multiple exports",
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
65
|
+
const fileName = `nox-mem-export-${date}.tgz`;
|
|
66
|
+
return {
|
|
67
|
+
status: 200,
|
|
68
|
+
headers: {
|
|
69
|
+
"Content-Type": "application/gzip",
|
|
70
|
+
"Content-Disposition": `attachment; filename="${fileName}"`,
|
|
71
|
+
"Content-Length": String(result.archive.length),
|
|
72
|
+
"X-Archive-Encrypted": String(result.manifest.encryption.enabled),
|
|
73
|
+
"X-Archive-Chunks": String(result.manifest.counts.chunks),
|
|
74
|
+
"X-Archive-Duration-Ms": String(result.duration_ms),
|
|
75
|
+
},
|
|
76
|
+
body: result.archive,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function jsonResponse(status, payload) {
|
|
80
|
+
return {
|
|
81
|
+
status,
|
|
82
|
+
headers: { "Content-Type": "application/json" },
|
|
83
|
+
body: JSON.stringify(payload),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/api/health-confidence-adapter.ts — Wave O T4 (L3 health piece).
|
|
3
|
+
*
|
|
4
|
+
* Wire-up.ts (#92, line 446) does:
|
|
5
|
+
*
|
|
6
|
+
* const mod = await tryImport("./health-confidence.js");
|
|
7
|
+
* if (!mod?.handleHealthConfidence) writeJson(res, ..., 503);
|
|
8
|
+
* const out = await mod.handleHealthConfidence();
|
|
9
|
+
*
|
|
10
|
+
* staged-L3 ships `computeConfidenceHealth(db, rankingMode?)` — not the
|
|
11
|
+
* arg-free `handleHealthConfidence()` the wire-up needs. This adapter wraps
|
|
12
|
+
* the upstream function with deps-registry's DB singleton.
|
|
13
|
+
*
|
|
14
|
+
* Apply step appends to staged-L3's `health-confidence.ts`:
|
|
15
|
+
*
|
|
16
|
+
* export { handleHealthConfidence } from "./health-confidence-adapter.js";
|
|
17
|
+
*
|
|
18
|
+
* The adapter returns `{status, body}` per the wire-up contract.
|
|
19
|
+
*/
|
|
20
|
+
interface ConfidenceHealthResponse {
|
|
21
|
+
status: number;
|
|
22
|
+
body: unknown;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Wire-up-shaped handler. No args — pulls DB from registry; returns 503 when
|
|
26
|
+
* the L3 health module or the DB is unavailable.
|
|
27
|
+
*/
|
|
28
|
+
export declare function handleHealthConfidence(): Promise<ConfidenceHealthResponse>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/api/health-confidence-adapter.ts — Wave O T4 (L3 health piece).
|
|
3
|
+
*
|
|
4
|
+
* Wire-up.ts (#92, line 446) does:
|
|
5
|
+
*
|
|
6
|
+
* const mod = await tryImport("./health-confidence.js");
|
|
7
|
+
* if (!mod?.handleHealthConfidence) writeJson(res, ..., 503);
|
|
8
|
+
* const out = await mod.handleHealthConfidence();
|
|
9
|
+
*
|
|
10
|
+
* staged-L3 ships `computeConfidenceHealth(db, rankingMode?)` — not the
|
|
11
|
+
* arg-free `handleHealthConfidence()` the wire-up needs. This adapter wraps
|
|
12
|
+
* the upstream function with deps-registry's DB singleton.
|
|
13
|
+
*
|
|
14
|
+
* Apply step appends to staged-L3's `health-confidence.ts`:
|
|
15
|
+
*
|
|
16
|
+
* export { handleHealthConfidence } from "./health-confidence-adapter.js";
|
|
17
|
+
*
|
|
18
|
+
* The adapter returns `{status, body}` per the wire-up contract.
|
|
19
|
+
*/
|
|
20
|
+
import { getDb } from "../lib/deps/deps-registry.js";
|
|
21
|
+
/**
|
|
22
|
+
* Wire-up-shaped handler. No args — pulls DB from registry; returns 503 when
|
|
23
|
+
* the L3 health module or the DB is unavailable.
|
|
24
|
+
*/
|
|
25
|
+
export async function handleHealthConfidence() {
|
|
26
|
+
const db = await getDb();
|
|
27
|
+
if (!db) {
|
|
28
|
+
return {
|
|
29
|
+
status: 503,
|
|
30
|
+
body: { error: "not_implemented", reason: "DB unavailable" },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// String indirection — `./health-confidence.js` is co-located only after
|
|
34
|
+
// staged-L3 is rsynced; here in the staged-wire-up-adapters tree the file
|
|
35
|
+
// isn't present, so we let the dynamic import fail and return 503.
|
|
36
|
+
const HC_SPEC = "./health-confidence.js";
|
|
37
|
+
let mod;
|
|
38
|
+
try {
|
|
39
|
+
mod = await import(HC_SPEC);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return {
|
|
43
|
+
status: 503,
|
|
44
|
+
body: {
|
|
45
|
+
error: "not_implemented",
|
|
46
|
+
reason: "L3 health-confidence module not deployed",
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const compute = mod.computeConfidenceHealth ?? mod.default?.computeConfidenceHealth;
|
|
51
|
+
if (typeof compute !== "function") {
|
|
52
|
+
return {
|
|
53
|
+
status: 503,
|
|
54
|
+
body: {
|
|
55
|
+
error: "not_implemented",
|
|
56
|
+
reason: "computeConfidenceHealth export missing",
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const slice = compute(db);
|
|
62
|
+
return { status: 200, body: { confidence: slice } };
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
return {
|
|
66
|
+
status: 500,
|
|
67
|
+
body: {
|
|
68
|
+
error: "internal_error",
|
|
69
|
+
message: err.message ?? "compute failed",
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/api/health-confidence.ts — confidence telemetry slice for /api/health.
|
|
3
|
+
*
|
|
4
|
+
* Surface added per spec §7-8:
|
|
5
|
+
* /api/health.confidence = {
|
|
6
|
+
* ranking_mode,
|
|
7
|
+
* provenance: { observed, declared, inferred, derived, "user-marked", null },
|
|
8
|
+
* confidence_distribution: { mean, p25, p50, p75, p95, stddev },
|
|
9
|
+
* superseded_count
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* Implementation:
|
|
13
|
+
* - One SQL query for provenance histogram (GROUP BY provenance_kind)
|
|
14
|
+
* - One SQL query for confidence percentiles (single-pass via NTILE)
|
|
15
|
+
* - One SQL query for superseded_count
|
|
16
|
+
*
|
|
17
|
+
* For sqlite-compat, percentiles are computed via `quantile` simulated by
|
|
18
|
+
* pulling sorted values + index math. Modest cost (<10ms even on 100k chunks).
|
|
19
|
+
*
|
|
20
|
+
* Falls back gracefully if columns don't exist (pre-v19 DB) — returns
|
|
21
|
+
* "schema_version_lt_19" marker in result.
|
|
22
|
+
*/
|
|
23
|
+
import type { Db } from "../lib/confidence/db-shim.js";
|
|
24
|
+
import type { ConfidenceHealthSlice, RankingMode } from "../lib/confidence/types.js";
|
|
25
|
+
declare function percentile(sorted: number[], q: number): number;
|
|
26
|
+
declare function meanStddev(vals: number[]): {
|
|
27
|
+
mean: number;
|
|
28
|
+
stddev: number;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Returns the confidence slice for /api/health.
|
|
32
|
+
* `rankingMode` defaults to current cfg.ranking_mode.
|
|
33
|
+
*/
|
|
34
|
+
export declare function computeConfidenceHealth(db: Db, rankingMode?: RankingMode): ConfidenceHealthSlice;
|
|
35
|
+
export { percentile, meanStddev };
|
|
36
|
+
export { handleHealthConfidence } from "./health-confidence-adapter.js";
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/api/health-confidence.ts — confidence telemetry slice for /api/health.
|
|
3
|
+
*
|
|
4
|
+
* Surface added per spec §7-8:
|
|
5
|
+
* /api/health.confidence = {
|
|
6
|
+
* ranking_mode,
|
|
7
|
+
* provenance: { observed, declared, inferred, derived, "user-marked", null },
|
|
8
|
+
* confidence_distribution: { mean, p25, p50, p75, p95, stddev },
|
|
9
|
+
* superseded_count
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* Implementation:
|
|
13
|
+
* - One SQL query for provenance histogram (GROUP BY provenance_kind)
|
|
14
|
+
* - One SQL query for confidence percentiles (single-pass via NTILE)
|
|
15
|
+
* - One SQL query for superseded_count
|
|
16
|
+
*
|
|
17
|
+
* For sqlite-compat, percentiles are computed via `quantile` simulated by
|
|
18
|
+
* pulling sorted values + index math. Modest cost (<10ms even on 100k chunks).
|
|
19
|
+
*
|
|
20
|
+
* Falls back gracefully if columns don't exist (pre-v19 DB) — returns
|
|
21
|
+
* "schema_version_lt_19" marker in result.
|
|
22
|
+
*/
|
|
23
|
+
import { resolveConfig } from "../lib/confidence/config.js";
|
|
24
|
+
const KNOWN_KINDS = [
|
|
25
|
+
"observed",
|
|
26
|
+
"declared",
|
|
27
|
+
"inferred",
|
|
28
|
+
"derived",
|
|
29
|
+
"user-marked",
|
|
30
|
+
"null",
|
|
31
|
+
];
|
|
32
|
+
function emptyProvenance() {
|
|
33
|
+
return {
|
|
34
|
+
observed: 0,
|
|
35
|
+
declared: 0,
|
|
36
|
+
inferred: 0,
|
|
37
|
+
derived: 0,
|
|
38
|
+
"user-marked": 0,
|
|
39
|
+
null: 0,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function emptyDistribution() {
|
|
43
|
+
return { mean: 0, p25: 0, p50: 0, p75: 0, p95: 0, stddev: 0 };
|
|
44
|
+
}
|
|
45
|
+
function percentile(sorted, q) {
|
|
46
|
+
if (sorted.length === 0)
|
|
47
|
+
return 0;
|
|
48
|
+
if (sorted.length === 1)
|
|
49
|
+
return sorted[0];
|
|
50
|
+
const pos = q * (sorted.length - 1);
|
|
51
|
+
const lo = Math.floor(pos);
|
|
52
|
+
const hi = Math.ceil(pos);
|
|
53
|
+
if (lo === hi)
|
|
54
|
+
return sorted[lo];
|
|
55
|
+
const frac = pos - lo;
|
|
56
|
+
return sorted[lo] * (1 - frac) + sorted[hi] * frac;
|
|
57
|
+
}
|
|
58
|
+
function meanStddev(vals) {
|
|
59
|
+
if (vals.length === 0)
|
|
60
|
+
return { mean: 0, stddev: 0 };
|
|
61
|
+
const mean = vals.reduce((a, b) => a + b, 0) / vals.length;
|
|
62
|
+
const variance = vals.reduce((a, b) => a + (b - mean) ** 2, 0) / vals.length;
|
|
63
|
+
return { mean, stddev: Math.sqrt(variance) };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns the confidence slice for /api/health.
|
|
67
|
+
* `rankingMode` defaults to current cfg.ranking_mode.
|
|
68
|
+
*/
|
|
69
|
+
export function computeConfidenceHealth(db, rankingMode) {
|
|
70
|
+
const mode = rankingMode ?? resolveConfig().ranking_mode;
|
|
71
|
+
let provenanceRows = [];
|
|
72
|
+
try {
|
|
73
|
+
provenanceRows = db
|
|
74
|
+
.prepare("SELECT provenance_kind, COUNT(*) AS count FROM chunks GROUP BY provenance_kind")
|
|
75
|
+
.all();
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Pre-v19 schema → empty histogram
|
|
79
|
+
return {
|
|
80
|
+
provenance: emptyProvenance(),
|
|
81
|
+
confidence_distribution: emptyDistribution(),
|
|
82
|
+
superseded_count: 0,
|
|
83
|
+
ranking_mode: mode,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const provenance = emptyProvenance();
|
|
87
|
+
for (const row of provenanceRows) {
|
|
88
|
+
const key = (row.provenance_kind ?? "null");
|
|
89
|
+
if (KNOWN_KINDS.includes(key)) {
|
|
90
|
+
provenance[key] = row.count;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
provenance.null += row.count;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
let confidenceVals = [];
|
|
97
|
+
try {
|
|
98
|
+
const rows = db
|
|
99
|
+
.prepare("SELECT confidence FROM chunks WHERE confidence IS NOT NULL ORDER BY confidence ASC")
|
|
100
|
+
.all();
|
|
101
|
+
confidenceVals = rows
|
|
102
|
+
.map((r) => r.confidence)
|
|
103
|
+
.filter((v) => typeof v === "number" && Number.isFinite(v));
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
confidenceVals = [];
|
|
107
|
+
}
|
|
108
|
+
const { mean, stddev } = meanStddev(confidenceVals);
|
|
109
|
+
const distribution = {
|
|
110
|
+
mean,
|
|
111
|
+
stddev,
|
|
112
|
+
p25: percentile(confidenceVals, 0.25),
|
|
113
|
+
p50: percentile(confidenceVals, 0.5),
|
|
114
|
+
p75: percentile(confidenceVals, 0.75),
|
|
115
|
+
p95: percentile(confidenceVals, 0.95),
|
|
116
|
+
};
|
|
117
|
+
let superseded_count = 0;
|
|
118
|
+
try {
|
|
119
|
+
const row = db
|
|
120
|
+
.prepare("SELECT COUNT(*) AS count FROM chunks WHERE superseded_by IS NOT NULL")
|
|
121
|
+
.get();
|
|
122
|
+
superseded_count = row?.count ?? 0;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
superseded_count = 0;
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
provenance,
|
|
129
|
+
confidence_distribution: distribution,
|
|
130
|
+
superseded_count,
|
|
131
|
+
ranking_mode: mode,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export { percentile, meanStddev };
|
|
135
|
+
// ─── Wire-up adapter re-export ──────────────────────────────────────────────
|
|
136
|
+
// handleHealthConfidence() is the arg-free wire-up contract; the real impl
|
|
137
|
+
// lives in health-confidence-adapter.ts which wraps computeConfidenceHealth()
|
|
138
|
+
// with DB injection via deps-registry. Without this re-export, wire-up.ts
|
|
139
|
+
// tryImport("./health-confidence.js") finds the module but not the symbol →
|
|
140
|
+
// 503 "L3 health not deployed". Same pattern as L2 db.ts re-export (PR #115).
|
|
141
|
+
export { handleHealthConfidence } from "./health-confidence-adapter.js";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/api/hooks.ts — T12: HTTP endpoints for hooks inspection + dryrun.
|
|
3
|
+
*
|
|
4
|
+
* Routes (mounted under /api/hooks):
|
|
5
|
+
*
|
|
6
|
+
* GET /api/hooks/status → 200 { config, queueDepth, rateLimitTokens }
|
|
7
|
+
* GET /api/hooks/recent → 200 { rows: [...metadata only...] }
|
|
8
|
+
* POST /api/hooks/dryrun → 200 { result, trace } — accepts { text } body
|
|
9
|
+
*
|
|
10
|
+
* Output sanitization:
|
|
11
|
+
* - status returns config + counters; never raw events
|
|
12
|
+
* - recent returns only metadata fields (event_uuid, ts, redaction_count,
|
|
13
|
+
* kind, session_id, project_slug); NEVER payload content
|
|
14
|
+
* - dryrun returns per-layer trace (layer + reason) and the redacted
|
|
15
|
+
* output preview (truncated to 200 chars)
|
|
16
|
+
*/
|
|
17
|
+
import { type TelemetrySink } from "../lib/hooks/pipeline.js";
|
|
18
|
+
import { type HookConfig } from "../lib/hooks/config.js";
|
|
19
|
+
export interface HttpRequest {
|
|
20
|
+
method: string;
|
|
21
|
+
path: string;
|
|
22
|
+
query?: Record<string, string>;
|
|
23
|
+
body?: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface HttpResponse {
|
|
26
|
+
status: number;
|
|
27
|
+
body: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
export interface HooksApiDeps {
|
|
30
|
+
readRecent: (limit: number) => Promise<Array<{
|
|
31
|
+
event_uuid: string;
|
|
32
|
+
session_id: string;
|
|
33
|
+
project_slug: string;
|
|
34
|
+
kind: string;
|
|
35
|
+
timestamp: string;
|
|
36
|
+
redaction_count: number;
|
|
37
|
+
}>>;
|
|
38
|
+
config?: HookConfig;
|
|
39
|
+
telemetry?: TelemetrySink;
|
|
40
|
+
/** Inject queue inspector (e.g., from plugin handle). Default returns 0. */
|
|
41
|
+
inspectQueue?: () => {
|
|
42
|
+
queueDepth: number;
|
|
43
|
+
rateLimitTokens?: number;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Route a single HTTP request. Returns an HttpResponse.
|
|
48
|
+
* No Express/Fastify dep — host wires this into whichever framework.
|
|
49
|
+
*/
|
|
50
|
+
export declare function handleHooksRequest(req: HttpRequest, deps: HooksApiDeps): Promise<HttpResponse>;
|