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,131 @@
|
|
|
1
|
+
// E-lite-2 v5 — vocab expansion pra security/temporal/scan_dependent gaps
|
|
2
|
+
// Adiciona ~35 termos novos baseados em análise das queries reais que falharam.
|
|
3
|
+
const COGNATES = new Set([
|
|
4
|
+
// v4 base
|
|
5
|
+
"chunk", "schema", "embedding", "cache", "query", "search", "index",
|
|
6
|
+
"batch", "cron", "snapshot", "backup", "database", "token", "pipeline",
|
|
7
|
+
"fts5", "rrf", "bm25", "cosine", "hybrid", "semantic", "dense", "lexical",
|
|
8
|
+
"tier", "salience", "pain", "boost", "reason", "temporal",
|
|
9
|
+
"webhook", "gateway", "openclaw", "systemd", "process",
|
|
10
|
+
"docker", "container", "service", "restart", "sigkill",
|
|
11
|
+
"gemini", "flash", "haiku", "opus", "sonnet", "model", "agent", "rerank",
|
|
12
|
+
"graph", "entity", "relation", "triple", "injection",
|
|
13
|
+
"shadow", "active", "auth", "reindex", "consolidate", "vectorize",
|
|
14
|
+
"fratricide", "compact", "audit", "monkey-patch",
|
|
15
|
+
"api", "fts", "spo", "kg",
|
|
16
|
+
"plugin", "section", "retention", "heartbeat", "watchdog", "probe",
|
|
17
|
+
"migration", "rollback", "recovery", "protocol", "sanitizer",
|
|
18
|
+
"degradation", "fallback", "fault",
|
|
19
|
+
// v5 NEW — security vocab
|
|
20
|
+
"secret", "credential", "chmod", "chattr", "permission",
|
|
21
|
+
"binary", "risk", "vulnerable", "exploit", "leak",
|
|
22
|
+
"rotate", "rotation", "key", "sed", "rsync",
|
|
23
|
+
// v5 NEW — temporal vocab
|
|
24
|
+
"when", "first", "last", "deployed", "activated", "bumped",
|
|
25
|
+
"incident", "milestone",
|
|
26
|
+
// v5 NEW — scan/OCR vocab
|
|
27
|
+
"ocr", "scan", "scanned", "document", "pdf", "tesseract",
|
|
28
|
+
"contract", "certificate", "notary", "protocol",
|
|
29
|
+
]);
|
|
30
|
+
const TRANSLATIONS = new Map([
|
|
31
|
+
// v4 base
|
|
32
|
+
["reindexar", "reindex"], ["reiniciar", "restart"], ["ativar", "activate"],
|
|
33
|
+
["desativar", "deactivate"], ["erro", "error"], ["falha", "failure"],
|
|
34
|
+
["segurança", "security"], ["configuração", "configuration"], ["busca", "search"],
|
|
35
|
+
["memória", "memory"], ["arquivo", "file"], ["pasta", "folder"],
|
|
36
|
+
["comando", "command"], ["consulta", "query"], ["resposta", "response"],
|
|
37
|
+
["mudança", "change"], ["execução", "execution"], ["desempenho", "performance"],
|
|
38
|
+
["latência", "latency"], ["rede", "network"], ["banco", "database"],
|
|
39
|
+
["tabela", "table"], ["coluna", "column"], ["agente", "agent"],
|
|
40
|
+
["recuperação", "recovery"], ["restauração", "restoration"],
|
|
41
|
+
["registro", "log"], ["ferramenta", "tool"], ["evolução", "evolution"],
|
|
42
|
+
["fluxo", "flow"], ["rotina", "routine"], ["incidente", "incident"],
|
|
43
|
+
["gatilho", "trigger"], ["seção", "section"], ["retenção", "retention"],
|
|
44
|
+
["porta", "port"], ["regra", "rule"],
|
|
45
|
+
// v5 NEW — security
|
|
46
|
+
["segredos", "secrets"], ["credenciais", "credentials"], ["chave", "key"],
|
|
47
|
+
["permissão", "permission"], ["rotacionar", "rotate"], ["binário", "binary"],
|
|
48
|
+
["vulnerável", "vulnerable"], ["vazamento", "leak"],
|
|
49
|
+
// v5 NEW — temporal
|
|
50
|
+
["quando", "when"], ["primeira", "first"], ["última", "last"],
|
|
51
|
+
["deployado", "deployed"], ["subiu", "bumped"], ["mudou", "changed"],
|
|
52
|
+
["lição", "lesson"],
|
|
53
|
+
// v5 NEW — scan/OCR
|
|
54
|
+
["documento", "document"], ["digitalizado", "scanned"],
|
|
55
|
+
["escaneado", "scanned"], ["escritura", "deed"], ["cartório", "notary"],
|
|
56
|
+
["consulado", "consulate"], ["cidadania", "citizenship"],
|
|
57
|
+
["contrato", "contract"], ["protocolo", "protocol"], ["certidão", "certificate"],
|
|
58
|
+
["imóvel", "property"], ["cláusula", "clause"],
|
|
59
|
+
]);
|
|
60
|
+
const REVERSE_TRANSLATIONS = new Map([...TRANSLATIONS.entries()].map(([pt, en]) => [en, pt]));
|
|
61
|
+
// Base entity set: neutral tech/platform names always recognized.
|
|
62
|
+
// Personal agent aliases and org names are configurable via NOX_PROTECTED_NAMES
|
|
63
|
+
// (comma-separated). Default is empty so a standalone operator gets no origin
|
|
64
|
+
// names baked in — set NOX_PROTECTED_NAMES=atlas,boris,nox,myorg in .env.
|
|
65
|
+
const _BASE_ENTITIES = new Set([
|
|
66
|
+
"gemini", "claude", "openai", "cohere",
|
|
67
|
+
"discord", "slack", "whatsapp", "telegram", "hotmart", "github",
|
|
68
|
+
"sqlite", "postgres", "redis",
|
|
69
|
+
]);
|
|
70
|
+
const _protectedNames = (process.env.NOX_PROTECTED_NAMES ?? "")
|
|
71
|
+
.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
|
|
72
|
+
const ENTITIES = new Set([..._BASE_ENTITIES, ..._protectedNames]);
|
|
73
|
+
function escapeRegex(s) {
|
|
74
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
75
|
+
}
|
|
76
|
+
function makePattern(term) {
|
|
77
|
+
const escaped = escapeRegex(term);
|
|
78
|
+
if (term.length <= 3) {
|
|
79
|
+
return new RegExp(`(?<![A-Za-z0-9_])${escaped}(?![A-Za-z0-9_])`, "i");
|
|
80
|
+
}
|
|
81
|
+
return new RegExp(`(?<![A-Za-z0-9_])(${escaped})\\w*(?![A-Za-z0-9])`, "i");
|
|
82
|
+
}
|
|
83
|
+
const COGNATE_PATTERNS = new Map([...COGNATES].map((t) => [t, makePattern(t)]));
|
|
84
|
+
const TRANS_PATTERNS = new Map([...TRANSLATIONS.keys()].map((pt) => [pt, makePattern(pt)]));
|
|
85
|
+
const REV_TRANS_PATTERNS = new Map([...REVERSE_TRANSLATIONS.keys()].map((en) => [en, makePattern(en)]));
|
|
86
|
+
const ENTITY_PATTERNS = new Map([...ENTITIES].map((t) => [t, makePattern(t)]));
|
|
87
|
+
const IDENTIFIER_PATTERNS = [
|
|
88
|
+
/(?<![A-Za-z0-9_])[A-Z][A-Z_]{3,}(?![A-Za-z0-9_])/g,
|
|
89
|
+
/(?<![A-Za-z0-9_])[a-z]+[A-Z][a-zA-Z]+(?![A-Za-z0-9_])/g,
|
|
90
|
+
/(?<![A-Za-z0-9_])[a-z][a-z]+_[a-z][a-z_]+(?![A-Za-z0-9_])/g,
|
|
91
|
+
/(?<![A-Za-z0-9_])v\d+(?:\.\d+){1,2}(?![A-Za-z0-9])/g,
|
|
92
|
+
/(?<![A-Za-z0-9_])(?:schema|version|migration)\s+v?\d+/gi,
|
|
93
|
+
/(?<![A-Za-z0-9_])nox-mem\s+\w+/gi,
|
|
94
|
+
/(?<![A-Za-z0-9_])[a-z_][a-z_]{2,}\.(?:ts|js|py|md|sh|json|yaml|yml)(?![A-Za-z0-9])/g,
|
|
95
|
+
/(?<![A-Za-z0-9_])\d{4}-\d{2}-\d{2}(?![A-Za-z0-9])/g,
|
|
96
|
+
];
|
|
97
|
+
export function extractAnchors(text) {
|
|
98
|
+
const anchors = new Set();
|
|
99
|
+
for (const [term, pattern] of COGNATE_PATTERNS) {
|
|
100
|
+
if (pattern.test(text))
|
|
101
|
+
anchors.add(term);
|
|
102
|
+
}
|
|
103
|
+
for (const [pt, pattern] of TRANS_PATTERNS) {
|
|
104
|
+
if (pattern.test(text)) {
|
|
105
|
+
const en = TRANSLATIONS.get(pt);
|
|
106
|
+
if (en)
|
|
107
|
+
anchors.add(en);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
for (const [en, pattern] of REV_TRANS_PATTERNS) {
|
|
111
|
+
if (pattern.test(text)) {
|
|
112
|
+
const pt = REVERSE_TRANSLATIONS.get(en);
|
|
113
|
+
if (pt)
|
|
114
|
+
anchors.add(pt);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const [term, pattern] of ENTITY_PATTERNS) {
|
|
118
|
+
if (pattern.test(text))
|
|
119
|
+
anchors.add(term);
|
|
120
|
+
}
|
|
121
|
+
for (const pat of IDENTIFIER_PATTERNS) {
|
|
122
|
+
const matches = text.match(pat);
|
|
123
|
+
if (matches) {
|
|
124
|
+
for (const m of matches) {
|
|
125
|
+
if (m.length >= 4)
|
|
126
|
+
anchors.add(m.toLowerCase());
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return [...anchors].sort().join(" ");
|
|
131
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/hooks/classifier.ts — T4: Layer 4 of pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Heuristics-first content classifier. Decides if a redacted text chunk
|
|
5
|
+
* is "worth capturing" or noise. Cheap regex/length checks before any LLM.
|
|
6
|
+
*
|
|
7
|
+
* Heuristics (each contributes a small signal):
|
|
8
|
+
* - length > NOX_HOOK_MIN_LENGTH (default 20) → +0.25
|
|
9
|
+
* - not pure code (no ratio ≥0.8 of /[{};=<>]/) → +0.15
|
|
10
|
+
* - not pure URLs (≥50% chars in URL tokens drops to 0)
|
|
11
|
+
* - contains noun-phrase markers (capitalized words, common conjunctions) → +0.20
|
|
12
|
+
* - contains sentence terminator (. ! ?) → +0.15
|
|
13
|
+
* - has lowercase + uppercase mix → +0.10
|
|
14
|
+
* - not just whitespace/punctuation → +0.15
|
|
15
|
+
*
|
|
16
|
+
* Final score in [0, 1]. Decision:
|
|
17
|
+
* score < 0.4 → reject (low signal)
|
|
18
|
+
* score > 0.6 → accept
|
|
19
|
+
* 0.4..0.6 → ambiguous; LLM fallback if NOX_HOOK_LLM_CLASSIFY=1, else
|
|
20
|
+
* accept (lean towards capture in ambiguous-mid range)
|
|
21
|
+
*
|
|
22
|
+
* No content escapes this module; only score + reason.
|
|
23
|
+
*/
|
|
24
|
+
import type { CaptureDecision, HookContext } from "./types.js";
|
|
25
|
+
export interface ClassifierOpts {
|
|
26
|
+
/** Min chars to even consider capturing. Mirrors config.minLength. */
|
|
27
|
+
minLength?: number;
|
|
28
|
+
/** Allow LLM fallback for ambiguous (score 0.4..0.6). Default false. */
|
|
29
|
+
llmFallback?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Pluggable LLM-classify hook. Called only when score ambiguous AND
|
|
32
|
+
* llmFallback=true. Returns {capture, reason}. The pipeline can wire
|
|
33
|
+
* this to flash-lite per D41 if desired.
|
|
34
|
+
*/
|
|
35
|
+
llmClassify?: (text: string) => {
|
|
36
|
+
capture: boolean;
|
|
37
|
+
reason: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Score a text in isolation. Pure, deterministic, no LLM.
|
|
42
|
+
*/
|
|
43
|
+
export declare function scoreText(text: string, minLength: number): number;
|
|
44
|
+
/**
|
|
45
|
+
* Apply Layer 4 to a HookContext (uses ctx.redacted.text if present, else event.content).
|
|
46
|
+
*/
|
|
47
|
+
export declare function applyClassifier(ctx: HookContext, opts?: ClassifierOpts): CaptureDecision;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/hooks/classifier.ts — T4: Layer 4 of pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Heuristics-first content classifier. Decides if a redacted text chunk
|
|
5
|
+
* is "worth capturing" or noise. Cheap regex/length checks before any LLM.
|
|
6
|
+
*
|
|
7
|
+
* Heuristics (each contributes a small signal):
|
|
8
|
+
* - length > NOX_HOOK_MIN_LENGTH (default 20) → +0.25
|
|
9
|
+
* - not pure code (no ratio ≥0.8 of /[{};=<>]/) → +0.15
|
|
10
|
+
* - not pure URLs (≥50% chars in URL tokens drops to 0)
|
|
11
|
+
* - contains noun-phrase markers (capitalized words, common conjunctions) → +0.20
|
|
12
|
+
* - contains sentence terminator (. ! ?) → +0.15
|
|
13
|
+
* - has lowercase + uppercase mix → +0.10
|
|
14
|
+
* - not just whitespace/punctuation → +0.15
|
|
15
|
+
*
|
|
16
|
+
* Final score in [0, 1]. Decision:
|
|
17
|
+
* score < 0.4 → reject (low signal)
|
|
18
|
+
* score > 0.6 → accept
|
|
19
|
+
* 0.4..0.6 → ambiguous; LLM fallback if NOX_HOOK_LLM_CLASSIFY=1, else
|
|
20
|
+
* accept (lean towards capture in ambiguous-mid range)
|
|
21
|
+
*
|
|
22
|
+
* No content escapes this module; only score + reason.
|
|
23
|
+
*/
|
|
24
|
+
const URL_RE = /\bhttps?:\/\/\S+/gi;
|
|
25
|
+
const CODE_TOKENS_RE = /[{};=<>()[\]]/g;
|
|
26
|
+
const SENTENCE_TERM_RE = /[.!?](\s|$)/;
|
|
27
|
+
const NOUN_HINT_RE = /\b[A-Z][a-z]{2,}\b|\b(the|a|an|and|or|but|because|when|if|while|that|this)\b/i;
|
|
28
|
+
const WHITESPACE_OR_PUNCT_RE = /^[\s\p{P}]+$/u;
|
|
29
|
+
/**
|
|
30
|
+
* Score a text in isolation. Pure, deterministic, no LLM.
|
|
31
|
+
*/
|
|
32
|
+
export function scoreText(text, minLength) {
|
|
33
|
+
if (text.length < minLength)
|
|
34
|
+
return 0;
|
|
35
|
+
if (WHITESPACE_OR_PUNCT_RE.test(text))
|
|
36
|
+
return 0;
|
|
37
|
+
let score = 0;
|
|
38
|
+
// Length bonus
|
|
39
|
+
score += 0.25;
|
|
40
|
+
// URL ratio kills the score
|
|
41
|
+
const urlMatches = text.match(URL_RE) ?? [];
|
|
42
|
+
const urlChars = urlMatches.reduce((sum, m) => sum + m.length, 0);
|
|
43
|
+
if (urlChars / text.length >= 0.5)
|
|
44
|
+
return Math.min(score, 0.1);
|
|
45
|
+
// Code ratio
|
|
46
|
+
const codeChars = (text.match(CODE_TOKENS_RE) ?? []).length;
|
|
47
|
+
const codeRatio = codeChars / Math.max(1, text.length);
|
|
48
|
+
if (codeRatio >= 0.08) {
|
|
49
|
+
// looks like code — heavy penalty
|
|
50
|
+
score -= 0.15;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
score += 0.15;
|
|
54
|
+
}
|
|
55
|
+
// Noun-phrase / conjunction hint
|
|
56
|
+
if (NOUN_HINT_RE.test(text))
|
|
57
|
+
score += 0.2;
|
|
58
|
+
// Sentence terminator
|
|
59
|
+
if (SENTENCE_TERM_RE.test(text))
|
|
60
|
+
score += 0.15;
|
|
61
|
+
// Mixed case (proxy for natural prose)
|
|
62
|
+
if (/[a-z]/.test(text) && /[A-Z]/.test(text))
|
|
63
|
+
score += 0.1;
|
|
64
|
+
// Has non-whitespace, non-punct chars
|
|
65
|
+
if (/\w/.test(text))
|
|
66
|
+
score += 0.15;
|
|
67
|
+
if (score < 0)
|
|
68
|
+
score = 0;
|
|
69
|
+
if (score > 1)
|
|
70
|
+
score = 1;
|
|
71
|
+
return score;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Apply Layer 4 to a HookContext (uses ctx.redacted.text if present, else event.content).
|
|
75
|
+
*/
|
|
76
|
+
export function applyClassifier(ctx, opts = {}) {
|
|
77
|
+
const minLength = opts.minLength ?? 20;
|
|
78
|
+
const llmFallback = opts.llmFallback ?? false;
|
|
79
|
+
const text = ctx.redacted?.text ?? ctx.event.content;
|
|
80
|
+
const score = scoreText(text, minLength);
|
|
81
|
+
ctx.classification = { score, reason: `heuristic_score=${score.toFixed(2)}` };
|
|
82
|
+
if (score < 0.4) {
|
|
83
|
+
return {
|
|
84
|
+
capture: false,
|
|
85
|
+
reason: `low_signal score=${score.toFixed(2)} len=${text.length}`,
|
|
86
|
+
layer: "classifier",
|
|
87
|
+
score,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (score > 0.6) {
|
|
91
|
+
return {
|
|
92
|
+
capture: true,
|
|
93
|
+
reason: `high_signal score=${score.toFixed(2)}`,
|
|
94
|
+
layer: "classifier",
|
|
95
|
+
score,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Ambiguous range 0.4..0.6
|
|
99
|
+
if (llmFallback && opts.llmClassify) {
|
|
100
|
+
try {
|
|
101
|
+
const llm = opts.llmClassify(text);
|
|
102
|
+
ctx.classification = {
|
|
103
|
+
score,
|
|
104
|
+
reason: `llm_fallback decision=${llm.capture ? "yes" : "no"} reason=${llm.reason}`,
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
capture: llm.capture,
|
|
108
|
+
reason: `llm_fallback ${llm.reason} (heuristic=${score.toFixed(2)})`,
|
|
109
|
+
layer: "classifier",
|
|
110
|
+
score,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
return {
|
|
115
|
+
capture: true,
|
|
116
|
+
reason: `llm_fallback_failed lean_capture err=${e.message}`,
|
|
117
|
+
layer: "classifier",
|
|
118
|
+
score,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Default: ambiguous → lean towards capture (Toto's bias = better recall over precision here)
|
|
123
|
+
return {
|
|
124
|
+
capture: true,
|
|
125
|
+
reason: `ambiguous_lean_capture score=${score.toFixed(2)}`,
|
|
126
|
+
layer: "classifier",
|
|
127
|
+
score,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/hooks/config.ts — T7: Env config loader + validator.
|
|
3
|
+
*
|
|
4
|
+
* Reads the following env vars (all OPT-IN — defaults are most-restrictive):
|
|
5
|
+
*
|
|
6
|
+
* NOX_HOOKS_ENABLED → "1" | "0" (default "0" — Layer 1 gate is OFF)
|
|
7
|
+
* NOX_HOOK_SOURCES → CSV of HookSource (default "openclaw")
|
|
8
|
+
* NOX_HOOK_RATE_LIMIT → captures/min (default 30, min 1, max 1000)
|
|
9
|
+
* NOX_HOOK_DEDUP_THRESHOLD→ cosine threshold (default 0.95, range 0.5..0.999)
|
|
10
|
+
* NOX_HOOK_LLM_CLASSIFY → "1" | "0" (default "0" — heuristics only)
|
|
11
|
+
* NOX_HOOK_DRY_RUN → "1" | "0" (default "0")
|
|
12
|
+
* NOX_HOOK_QUEUE_SIZE → worker queue max (default 10000)
|
|
13
|
+
* NOX_HOOK_MIN_LENGTH → classifier min chars (default 20)
|
|
14
|
+
* NOX_HOOK_PII_POLICY → "redact" | "drop" (default "redact")
|
|
15
|
+
*
|
|
16
|
+
* Defensive: invalid values fall back to defaults + warn() to telemetry.
|
|
17
|
+
*/
|
|
18
|
+
import type { HookSource } from "./types.js";
|
|
19
|
+
export interface HookConfig {
|
|
20
|
+
enabled: boolean;
|
|
21
|
+
allowedSources: ReadonlySet<HookSource>;
|
|
22
|
+
rateLimitPerMin: number;
|
|
23
|
+
dedupThreshold: number;
|
|
24
|
+
llmClassify: boolean;
|
|
25
|
+
dryRun: boolean;
|
|
26
|
+
queueSize: number;
|
|
27
|
+
minLength: number;
|
|
28
|
+
piiPolicy: "redact" | "drop";
|
|
29
|
+
}
|
|
30
|
+
export declare const DEFAULTS: HookConfig;
|
|
31
|
+
/** Parse "1"/"true"/"yes" as true; everything else false. */
|
|
32
|
+
declare function parseBool(v: string | undefined, fallback: boolean): boolean;
|
|
33
|
+
declare function parseInt0(v: string | undefined, fallback: number, lo: number, hi: number): number;
|
|
34
|
+
declare function parseFloat0(v: string | undefined, fallback: number, lo: number, hi: number): number;
|
|
35
|
+
declare function parseSources(v: string | undefined, fallback: ReadonlySet<HookSource>): ReadonlySet<HookSource>;
|
|
36
|
+
declare function parsePolicy(v: string | undefined): "redact" | "drop";
|
|
37
|
+
/**
|
|
38
|
+
* Build a HookConfig from process.env (or a passed-in env-like object for tests).
|
|
39
|
+
*/
|
|
40
|
+
export declare function loadConfig(env?: NodeJS.ProcessEnv): HookConfig;
|
|
41
|
+
/** Internal helper kept exported for tests. */
|
|
42
|
+
export declare const __test: {
|
|
43
|
+
parseBool: typeof parseBool;
|
|
44
|
+
parseInt0: typeof parseInt0;
|
|
45
|
+
parseFloat0: typeof parseFloat0;
|
|
46
|
+
parseSources: typeof parseSources;
|
|
47
|
+
parsePolicy: typeof parsePolicy;
|
|
48
|
+
};
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/hooks/config.ts — T7: Env config loader + validator.
|
|
3
|
+
*
|
|
4
|
+
* Reads the following env vars (all OPT-IN — defaults are most-restrictive):
|
|
5
|
+
*
|
|
6
|
+
* NOX_HOOKS_ENABLED → "1" | "0" (default "0" — Layer 1 gate is OFF)
|
|
7
|
+
* NOX_HOOK_SOURCES → CSV of HookSource (default "openclaw")
|
|
8
|
+
* NOX_HOOK_RATE_LIMIT → captures/min (default 30, min 1, max 1000)
|
|
9
|
+
* NOX_HOOK_DEDUP_THRESHOLD→ cosine threshold (default 0.95, range 0.5..0.999)
|
|
10
|
+
* NOX_HOOK_LLM_CLASSIFY → "1" | "0" (default "0" — heuristics only)
|
|
11
|
+
* NOX_HOOK_DRY_RUN → "1" | "0" (default "0")
|
|
12
|
+
* NOX_HOOK_QUEUE_SIZE → worker queue max (default 10000)
|
|
13
|
+
* NOX_HOOK_MIN_LENGTH → classifier min chars (default 20)
|
|
14
|
+
* NOX_HOOK_PII_POLICY → "redact" | "drop" (default "redact")
|
|
15
|
+
*
|
|
16
|
+
* Defensive: invalid values fall back to defaults + warn() to telemetry.
|
|
17
|
+
*/
|
|
18
|
+
export const DEFAULTS = Object.freeze({
|
|
19
|
+
enabled: false,
|
|
20
|
+
allowedSources: new Set(["openclaw"]),
|
|
21
|
+
rateLimitPerMin: 30,
|
|
22
|
+
dedupThreshold: 0.95,
|
|
23
|
+
llmClassify: false,
|
|
24
|
+
dryRun: false,
|
|
25
|
+
queueSize: 10_000,
|
|
26
|
+
minLength: 20,
|
|
27
|
+
piiPolicy: "redact",
|
|
28
|
+
});
|
|
29
|
+
const VALID_SOURCES = new Set([
|
|
30
|
+
"openclaw",
|
|
31
|
+
"cli",
|
|
32
|
+
"manual",
|
|
33
|
+
"mcp",
|
|
34
|
+
"api",
|
|
35
|
+
"unknown",
|
|
36
|
+
]);
|
|
37
|
+
/** Parse "1"/"true"/"yes" as true; everything else false. */
|
|
38
|
+
function parseBool(v, fallback) {
|
|
39
|
+
if (v === undefined)
|
|
40
|
+
return fallback;
|
|
41
|
+
const s = v.trim().toLowerCase();
|
|
42
|
+
if (["1", "true", "yes", "on"].includes(s))
|
|
43
|
+
return true;
|
|
44
|
+
if (["0", "false", "no", "off", ""].includes(s))
|
|
45
|
+
return false;
|
|
46
|
+
return fallback;
|
|
47
|
+
}
|
|
48
|
+
function parseInt0(v, fallback, lo, hi) {
|
|
49
|
+
if (v === undefined)
|
|
50
|
+
return fallback;
|
|
51
|
+
const n = Number.parseInt(v.trim(), 10);
|
|
52
|
+
if (!Number.isFinite(n) || Number.isNaN(n))
|
|
53
|
+
return fallback;
|
|
54
|
+
if (n < lo || n > hi)
|
|
55
|
+
return fallback;
|
|
56
|
+
return n;
|
|
57
|
+
}
|
|
58
|
+
function parseFloat0(v, fallback, lo, hi) {
|
|
59
|
+
if (v === undefined)
|
|
60
|
+
return fallback;
|
|
61
|
+
const n = Number.parseFloat(v.trim());
|
|
62
|
+
if (!Number.isFinite(n) || Number.isNaN(n))
|
|
63
|
+
return fallback;
|
|
64
|
+
if (n < lo || n > hi)
|
|
65
|
+
return fallback;
|
|
66
|
+
return n;
|
|
67
|
+
}
|
|
68
|
+
function parseSources(v, fallback) {
|
|
69
|
+
if (v === undefined || v.trim() === "")
|
|
70
|
+
return fallback;
|
|
71
|
+
const items = v.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
|
|
72
|
+
const out = new Set();
|
|
73
|
+
for (const it of items) {
|
|
74
|
+
if (VALID_SOURCES.has(it))
|
|
75
|
+
out.add(it);
|
|
76
|
+
}
|
|
77
|
+
if (out.size === 0)
|
|
78
|
+
return fallback;
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
function parsePolicy(v) {
|
|
82
|
+
if (v === undefined)
|
|
83
|
+
return DEFAULTS.piiPolicy;
|
|
84
|
+
const s = v.trim().toLowerCase();
|
|
85
|
+
if (s === "drop")
|
|
86
|
+
return "drop";
|
|
87
|
+
return "redact";
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Build a HookConfig from process.env (or a passed-in env-like object for tests).
|
|
91
|
+
*/
|
|
92
|
+
export function loadConfig(env = process.env) {
|
|
93
|
+
return Object.freeze({
|
|
94
|
+
enabled: parseBool(env["NOX_HOOKS_ENABLED"], DEFAULTS.enabled),
|
|
95
|
+
allowedSources: parseSources(env["NOX_HOOK_SOURCES"], DEFAULTS.allowedSources),
|
|
96
|
+
rateLimitPerMin: parseInt0(env["NOX_HOOK_RATE_LIMIT"], DEFAULTS.rateLimitPerMin, 1, 1000),
|
|
97
|
+
dedupThreshold: parseFloat0(env["NOX_HOOK_DEDUP_THRESHOLD"], DEFAULTS.dedupThreshold, 0.5, 0.999),
|
|
98
|
+
llmClassify: parseBool(env["NOX_HOOK_LLM_CLASSIFY"], DEFAULTS.llmClassify),
|
|
99
|
+
dryRun: parseBool(env["NOX_HOOK_DRY_RUN"], DEFAULTS.dryRun),
|
|
100
|
+
queueSize: parseInt0(env["NOX_HOOK_QUEUE_SIZE"], DEFAULTS.queueSize, 100, 1_000_000),
|
|
101
|
+
minLength: parseInt0(env["NOX_HOOK_MIN_LENGTH"], DEFAULTS.minLength, 1, 10_000),
|
|
102
|
+
piiPolicy: parsePolicy(env["NOX_HOOK_PII_POLICY"]),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** Internal helper kept exported for tests. */
|
|
106
|
+
export const __test = { parseBool, parseInt0, parseFloat0, parseSources, parsePolicy };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/hooks/decorators.ts — T10: Explicit user override of classifier.
|
|
3
|
+
*
|
|
4
|
+
* Users (or upstream agents) can mark content with inline annotations:
|
|
5
|
+
*
|
|
6
|
+
* // @nox:capture → force capture, bypassing classifier (but NOT
|
|
7
|
+
* privacy filter or rate-limit/dedup)
|
|
8
|
+
* // @nox:skip → force skip, short-circuit pipeline immediately
|
|
9
|
+
*
|
|
10
|
+
* Supported comment shapes (case-insensitive, leading whitespace allowed):
|
|
11
|
+
* "// @nox:capture", "/* @nox:capture *\/", "# @nox:capture",
|
|
12
|
+
* "<!-- @nox:capture -->"
|
|
13
|
+
*
|
|
14
|
+
* The decorator is detected on the FIRST 4 lines of the content body to
|
|
15
|
+
* avoid scanning huge transcripts. False positives in code-style text are
|
|
16
|
+
* acceptable — the user opt-in is explicit.
|
|
17
|
+
*/
|
|
18
|
+
import type { HookEvent } from "./types.js";
|
|
19
|
+
export type Decorator = "capture" | "skip";
|
|
20
|
+
/**
|
|
21
|
+
* Parse decorators from the first MAX_LINES lines of `content`.
|
|
22
|
+
* Returns deduped, ordered list.
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseDecorators(content: string, MAX_LINES?: number): Decorator[];
|
|
25
|
+
/**
|
|
26
|
+
* Mutates event.decorators with parsed results if not already set.
|
|
27
|
+
*/
|
|
28
|
+
export declare function attachDecorators(event: HookEvent): HookEvent;
|
|
29
|
+
/**
|
|
30
|
+
* Returns "capture" if force-capture decorator present, "skip" if force-skip,
|
|
31
|
+
* else null (no override).
|
|
32
|
+
*
|
|
33
|
+
* Precedence: skip wins over capture (defensive).
|
|
34
|
+
*/
|
|
35
|
+
export declare function decoratorOverride(event: HookEvent): Decorator | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/hooks/decorators.ts — T10: Explicit user override of classifier.
|
|
3
|
+
*
|
|
4
|
+
* Users (or upstream agents) can mark content with inline annotations:
|
|
5
|
+
*
|
|
6
|
+
* // @nox:capture → force capture, bypassing classifier (but NOT
|
|
7
|
+
* privacy filter or rate-limit/dedup)
|
|
8
|
+
* // @nox:skip → force skip, short-circuit pipeline immediately
|
|
9
|
+
*
|
|
10
|
+
* Supported comment shapes (case-insensitive, leading whitespace allowed):
|
|
11
|
+
* "// @nox:capture", "/* @nox:capture *\/", "# @nox:capture",
|
|
12
|
+
* "<!-- @nox:capture -->"
|
|
13
|
+
*
|
|
14
|
+
* The decorator is detected on the FIRST 4 lines of the content body to
|
|
15
|
+
* avoid scanning huge transcripts. False positives in code-style text are
|
|
16
|
+
* acceptable — the user opt-in is explicit.
|
|
17
|
+
*/
|
|
18
|
+
const PATTERNS = [
|
|
19
|
+
{ re: /(^|\s)(?:\/\/|#|<!--|\/\*)\s*@nox:capture\b/i, kind: "capture" },
|
|
20
|
+
{ re: /(^|\s)(?:\/\/|#|<!--|\/\*)\s*@nox:skip\b/i, kind: "skip" },
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Parse decorators from the first MAX_LINES lines of `content`.
|
|
24
|
+
* Returns deduped, ordered list.
|
|
25
|
+
*/
|
|
26
|
+
export function parseDecorators(content, MAX_LINES = 4) {
|
|
27
|
+
if (!content)
|
|
28
|
+
return [];
|
|
29
|
+
const head = content.split("\n").slice(0, MAX_LINES).join("\n");
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
for (const p of PATTERNS) {
|
|
32
|
+
if (p.re.test(head))
|
|
33
|
+
seen.add(p.kind);
|
|
34
|
+
}
|
|
35
|
+
return Array.from(seen);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Mutates event.decorators with parsed results if not already set.
|
|
39
|
+
*/
|
|
40
|
+
export function attachDecorators(event) {
|
|
41
|
+
if (event.decorators && event.decorators.length > 0)
|
|
42
|
+
return event;
|
|
43
|
+
const decorators = parseDecorators(event.content);
|
|
44
|
+
return decorators.length > 0 ? { ...event, decorators } : event;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns "capture" if force-capture decorator present, "skip" if force-skip,
|
|
48
|
+
* else null (no override).
|
|
49
|
+
*
|
|
50
|
+
* Precedence: skip wins over capture (defensive).
|
|
51
|
+
*/
|
|
52
|
+
export function decoratorOverride(event) {
|
|
53
|
+
const decorators = event.decorators ?? parseDecorators(event.content);
|
|
54
|
+
if (decorators.includes("skip"))
|
|
55
|
+
return "skip";
|
|
56
|
+
if (decorators.includes("capture"))
|
|
57
|
+
return "capture";
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/lib/hooks/pipeline.ts — T6: 5-layer orchestrator.
|
|
3
|
+
*
|
|
4
|
+
* Chains layers in load-bearing order:
|
|
5
|
+
*
|
|
6
|
+
* Layer 1: env gate (config.enabled)
|
|
7
|
+
* Layer 2: source allowlist (source-allowlist.ts)
|
|
8
|
+
* Layer 3: privacy filter (privacy-filter-adapter.ts)
|
|
9
|
+
* Layer 4: classifier (classifier.ts)
|
|
10
|
+
* Layer 5: rate-limit+dedup (rate-limit.ts)
|
|
11
|
+
*
|
|
12
|
+
* Decorator overrides (T10):
|
|
13
|
+
* - "@nox:skip" short-circuits at Layer 1 (before anything else)
|
|
14
|
+
* - "@nox:capture" bypasses Layer 4 (classifier) but NOT Layers 1/2/3/5
|
|
15
|
+
*
|
|
16
|
+
* Telemetry: emits one row per pipeline run via the injected telemetry
|
|
17
|
+
* sink — captured OR rejected. NEVER includes raw content.
|
|
18
|
+
*
|
|
19
|
+
* Dry-run: when config.dryRun is true, the pipeline still runs through
|
|
20
|
+
* every layer but does NOT call ingestFn at the end. Outcome reports
|
|
21
|
+
* dry_run=true.
|
|
22
|
+
*/
|
|
23
|
+
import { type HookConfig } from "./config.js";
|
|
24
|
+
import { type RedactFn } from "./privacy-filter-adapter.js";
|
|
25
|
+
import { type SimilarityFn } from "./rate-limit.js";
|
|
26
|
+
import type { HookEvent, HookResult, HookTelemetryRow } from "./types.js";
|
|
27
|
+
/** ingestText sink — pipeline writes here on capture. */
|
|
28
|
+
export type IngestFn = (params: {
|
|
29
|
+
text: string;
|
|
30
|
+
source: string;
|
|
31
|
+
session_id: string;
|
|
32
|
+
project_slug: string;
|
|
33
|
+
provenance: "hook";
|
|
34
|
+
redaction_count: number;
|
|
35
|
+
ts: string;
|
|
36
|
+
event_id: string;
|
|
37
|
+
}) => Promise<{
|
|
38
|
+
chunk_id: number;
|
|
39
|
+
} | {
|
|
40
|
+
chunk_id: null;
|
|
41
|
+
error: string;
|
|
42
|
+
}>;
|
|
43
|
+
/** Telemetry sink — pipeline emits one row per event. */
|
|
44
|
+
export type TelemetrySink = (row: HookTelemetryRow) => void | Promise<void>;
|
|
45
|
+
export interface PipelineDeps {
|
|
46
|
+
config?: HookConfig;
|
|
47
|
+
redact?: RedactFn;
|
|
48
|
+
similarity?: SimilarityFn;
|
|
49
|
+
ingest?: IngestFn;
|
|
50
|
+
telemetry?: TelemetrySink;
|
|
51
|
+
/** Inject clock (tests). */
|
|
52
|
+
now?: () => number;
|
|
53
|
+
/** Inject llm classify (T4). */
|
|
54
|
+
llmClassify?: (text: string) => {
|
|
55
|
+
capture: boolean;
|
|
56
|
+
reason: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export interface PipelineHandle {
|
|
60
|
+
run(event: HookEvent): Promise<HookResult>;
|
|
61
|
+
/** Reset internal rate-limit/dedup state (tests, manual). */
|
|
62
|
+
resetState(): void;
|
|
63
|
+
/** Exposed for inspection (CLI/HTTP status). */
|
|
64
|
+
inspect(): {
|
|
65
|
+
config: HookConfig;
|
|
66
|
+
rateLimitTokens: number;
|
|
67
|
+
recentBufferSize: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Build a pipeline handle. Stateful: keeps a RateLimitState across calls.
|
|
72
|
+
*
|
|
73
|
+
* Each invocation runs the 5 layers in order. Every rejection emits ONE
|
|
74
|
+
* telemetry row. A capture emits ONE telemetry row plus the ingest call.
|
|
75
|
+
*/
|
|
76
|
+
export declare function createPipeline(deps?: PipelineDeps): PipelineHandle;
|