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,212 @@
|
|
|
1
|
+
// E10 (2026-05-03): Consolidation merge candidate detection (DRY-RUN ONLY).
|
|
2
|
+
// Gate D01 (R01 nDCG≥0.6) NÃO passou — apply bloqueado. Esta versão só identifica candidatos.
|
|
3
|
+
// Quando R01 atingir 0.6, adicionar --apply protegido por withOpAudit().
|
|
4
|
+
import { getDb } from "./db.js";
|
|
5
|
+
function normalize(s) {
|
|
6
|
+
// CODE-FIX HIGH: literal combining marks brittle across editors → use ̀-ͯ escape
|
|
7
|
+
return s
|
|
8
|
+
.toLowerCase()
|
|
9
|
+
.normalize("NFD").replace(/[̀-ͯ]/g, "") // strip diacritics (combining marks block)
|
|
10
|
+
.replace(/[^a-z0-9]+/g, " ")
|
|
11
|
+
.trim()
|
|
12
|
+
.replace(/\s+/g, " ");
|
|
13
|
+
}
|
|
14
|
+
function levenshtein(a, b) {
|
|
15
|
+
if (a === b)
|
|
16
|
+
return 0;
|
|
17
|
+
const al = a.length, bl = b.length;
|
|
18
|
+
if (al === 0)
|
|
19
|
+
return bl;
|
|
20
|
+
if (bl === 0)
|
|
21
|
+
return al;
|
|
22
|
+
const v0 = new Array(bl + 1);
|
|
23
|
+
const v1 = new Array(bl + 1);
|
|
24
|
+
for (let i = 0; i <= bl; i++)
|
|
25
|
+
v0[i] = i;
|
|
26
|
+
for (let i = 0; i < al; i++) {
|
|
27
|
+
v1[0] = i + 1;
|
|
28
|
+
for (let j = 0; j < bl; j++) {
|
|
29
|
+
const cost = a[i] === b[j] ? 0 : 1;
|
|
30
|
+
v1[j + 1] = Math.min(v1[j] + 1, v0[j + 1] + 1, v0[j] + cost);
|
|
31
|
+
}
|
|
32
|
+
for (let k = 0; k <= bl; k++)
|
|
33
|
+
v0[k] = v1[k];
|
|
34
|
+
}
|
|
35
|
+
return v1[bl];
|
|
36
|
+
}
|
|
37
|
+
function levRatio(a, b) {
|
|
38
|
+
const maxLen = Math.max(a.length, b.length);
|
|
39
|
+
if (maxLen === 0)
|
|
40
|
+
return 1;
|
|
41
|
+
return 1 - levenshtein(a, b) / maxLen;
|
|
42
|
+
}
|
|
43
|
+
// NOX_PROTECTED_NAMES: comma-separated names that should NEVER be auto-merged.
|
|
44
|
+
// Default is empty — a new standalone operator has no personal names to protect.
|
|
45
|
+
// On the origin VPS restore the original behavior by setting:
|
|
46
|
+
// NOX_PROTECTED_NAMES=toto,nox,forge,atlas,boris,cipher,lex,openclaw,anthropic,gemini,claude
|
|
47
|
+
const PROTECTED_NAMES = new Set(process.env.NOX_PROTECTED_NAMES
|
|
48
|
+
? process.env.NOX_PROTECTED_NAMES.split(",").map(s => s.trim().toLowerCase()).filter(Boolean)
|
|
49
|
+
: [] // empty: standalone operators have no pre-set protected names
|
|
50
|
+
); // never auto-merge names in this set: FP risk catastrophic
|
|
51
|
+
function assessFpRisk(c) {
|
|
52
|
+
const reasons = [];
|
|
53
|
+
let risk = 'low';
|
|
54
|
+
const pNorm = normalize(c.primary.name);
|
|
55
|
+
const dNorm = normalize(c.duplicate.name);
|
|
56
|
+
if (PROTECTED_NAMES.has(pNorm) || PROTECTED_NAMES.has(dNorm)) {
|
|
57
|
+
reasons.push("protected name (NOX_PROTECTED_NAMES — never auto-merge)");
|
|
58
|
+
risk = 'high';
|
|
59
|
+
}
|
|
60
|
+
// mention_count disparity: high diff = different entities
|
|
61
|
+
const mentionRatio = Math.max(c.primary.mentions, c.duplicate.mentions) / Math.max(1, Math.min(c.primary.mentions, c.duplicate.mentions));
|
|
62
|
+
if (mentionRatio > 10) {
|
|
63
|
+
reasons.push(`mention disparity ${mentionRatio.toFixed(1)}× — likely distinct entities`);
|
|
64
|
+
if (risk !== 'high')
|
|
65
|
+
risk = 'medium';
|
|
66
|
+
}
|
|
67
|
+
// No shared evidence chunks: weak link
|
|
68
|
+
if (c.shared_evidence_chunks === 0 && c.similarity < 0.95) {
|
|
69
|
+
reasons.push("zero shared evidence chunks + sim<0.95");
|
|
70
|
+
if (risk !== 'high')
|
|
71
|
+
risk = 'medium';
|
|
72
|
+
}
|
|
73
|
+
// Names that are pure abbreviations of each other (e.g. "AI" vs "AI Corp")
|
|
74
|
+
const lenDiff = Math.abs(pNorm.length - dNorm.length);
|
|
75
|
+
if (lenDiff > 8 && c.reason === 'substring') {
|
|
76
|
+
reasons.push("substring + large length diff — possible abbreviation FP");
|
|
77
|
+
if (risk !== 'high')
|
|
78
|
+
risk = 'medium';
|
|
79
|
+
}
|
|
80
|
+
if (reasons.length === 0)
|
|
81
|
+
reasons.push("clean: same type, high sim, mention parity");
|
|
82
|
+
return { risk, reasons };
|
|
83
|
+
}
|
|
84
|
+
export function findMergeCandidates(opts = {}) {
|
|
85
|
+
const start = Date.now();
|
|
86
|
+
const db = getDb();
|
|
87
|
+
const minSim = opts.minSim ?? 0.85;
|
|
88
|
+
const maxPerType = opts.maxPerType ?? 1000;
|
|
89
|
+
const entities = db.prepare("SELECT id, name, entity_type as type, mention_count as mentions FROM kg_entities ORDER BY entity_type, mention_count DESC").all();
|
|
90
|
+
// CODE-FIX HIGH: pré-computa entity → chunks set em UMA query, evita N² SQL inner
|
|
91
|
+
const entityChunks = new Map();
|
|
92
|
+
const allRels = db.prepare("SELECT source_entity_id, target_entity_id, evidence_chunk_id FROM kg_relations WHERE evidence_chunk_id IS NOT NULL").all();
|
|
93
|
+
for (const r of allRels) {
|
|
94
|
+
if (!entityChunks.has(r.source_entity_id))
|
|
95
|
+
entityChunks.set(r.source_entity_id, new Set());
|
|
96
|
+
if (!entityChunks.has(r.target_entity_id))
|
|
97
|
+
entityChunks.set(r.target_entity_id, new Set());
|
|
98
|
+
entityChunks.get(r.source_entity_id).add(r.evidence_chunk_id);
|
|
99
|
+
entityChunks.get(r.target_entity_id).add(r.evidence_chunk_id);
|
|
100
|
+
}
|
|
101
|
+
const candidates = [];
|
|
102
|
+
const byType = new Map();
|
|
103
|
+
for (const e of entities) {
|
|
104
|
+
if (!byType.has(e.type))
|
|
105
|
+
byType.set(e.type, []);
|
|
106
|
+
byType.get(e.type).push(e);
|
|
107
|
+
}
|
|
108
|
+
for (const [, group] of byType) {
|
|
109
|
+
if (group.length > maxPerType)
|
|
110
|
+
continue; // skip pathological groups
|
|
111
|
+
for (let i = 0; i < group.length; i++) {
|
|
112
|
+
const a = group[i];
|
|
113
|
+
const aNorm = normalize(a.name);
|
|
114
|
+
for (let j = i + 1; j < group.length; j++) {
|
|
115
|
+
const b = group[j];
|
|
116
|
+
const bNorm = normalize(b.name);
|
|
117
|
+
let sim = 0;
|
|
118
|
+
let reason = null;
|
|
119
|
+
if (aNorm === bNorm) {
|
|
120
|
+
sim = 1.0;
|
|
121
|
+
reason = 'normalized';
|
|
122
|
+
}
|
|
123
|
+
else if (aNorm.length >= 4 && bNorm.length >= 4 && (aNorm.includes(bNorm) || bNorm.includes(aNorm))) {
|
|
124
|
+
sim = Math.min(aNorm.length, bNorm.length) / Math.max(aNorm.length, bNorm.length);
|
|
125
|
+
reason = 'substring';
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const ratio = levRatio(aNorm, bNorm);
|
|
129
|
+
if (ratio >= minSim) {
|
|
130
|
+
sim = ratio;
|
|
131
|
+
reason = 'levenshtein';
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!reason || sim < minSim)
|
|
135
|
+
continue;
|
|
136
|
+
// CODE-FIX HIGH: in-memory intersect from precomputed map (was N+1 SQL inner)
|
|
137
|
+
const aChunks = entityChunks.get(a.id);
|
|
138
|
+
const bChunks = entityChunks.get(b.id);
|
|
139
|
+
let sharedCount = 0;
|
|
140
|
+
if (aChunks && bChunks) {
|
|
141
|
+
// iterate menor pra performance
|
|
142
|
+
const [smaller, larger] = aChunks.size <= bChunks.size ? [aChunks, bChunks] : [bChunks, aChunks];
|
|
143
|
+
for (const c of smaller)
|
|
144
|
+
if (larger.has(c))
|
|
145
|
+
sharedCount++;
|
|
146
|
+
}
|
|
147
|
+
const sharedEvidence = { c: sharedCount };
|
|
148
|
+
const primary = a.mentions >= b.mentions ? a : b;
|
|
149
|
+
const duplicate = primary === a ? b : a;
|
|
150
|
+
const baseCand = {
|
|
151
|
+
primary: { id: primary.id, name: primary.name, type: primary.type, mentions: primary.mentions },
|
|
152
|
+
duplicate: { id: duplicate.id, name: duplicate.name, type: duplicate.type, mentions: duplicate.mentions },
|
|
153
|
+
similarity: Math.round(sim * 1000) / 1000,
|
|
154
|
+
reason,
|
|
155
|
+
shared_evidence_chunks: sharedEvidence.c,
|
|
156
|
+
};
|
|
157
|
+
const fp = assessFpRisk(baseCand);
|
|
158
|
+
candidates.push({ ...baseCand, fp_risk: fp.risk, fp_reasons: fp.reasons });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// Sort by sim desc, then by mentions
|
|
163
|
+
candidates.sort((a, b) => b.similarity - a.similarity || b.primary.mentions - a.primary.mentions);
|
|
164
|
+
const byTypeCount = {};
|
|
165
|
+
const byFpRisk = { low: 0, medium: 0, high: 0 };
|
|
166
|
+
for (const c of candidates) {
|
|
167
|
+
byTypeCount[c.primary.type] = (byTypeCount[c.primary.type] || 0) + 1;
|
|
168
|
+
byFpRisk[c.fp_risk]++;
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
scanned_entities: entities.length,
|
|
172
|
+
candidate_pairs: candidates.length,
|
|
173
|
+
by_type: byTypeCount,
|
|
174
|
+
by_fp_risk: byFpRisk,
|
|
175
|
+
candidates,
|
|
176
|
+
duration_ms: Date.now() - start,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export function formatConsolidation(r, mode = 'text', limit = 30) {
|
|
180
|
+
if (mode === 'json')
|
|
181
|
+
return JSON.stringify(r, null, 2);
|
|
182
|
+
const lines = [];
|
|
183
|
+
lines.push(`## consolidate-merge (E10 dry-run — gate D01 R01≥0.6 not yet passed, apply blocked)`);
|
|
184
|
+
lines.push(`Scanned: ${r.scanned_entities} entities | Candidates: ${r.candidate_pairs} pairs | Duration: ${r.duration_ms}ms`);
|
|
185
|
+
lines.push(`By FP risk: low=${r.by_fp_risk.low} medium=${r.by_fp_risk.medium} high=${r.by_fp_risk.high}`);
|
|
186
|
+
lines.push(`By type: ${Object.entries(r.by_type).map(([t, n]) => `${t}=${n}`).join(", ")}`);
|
|
187
|
+
if (r.candidate_pairs === 0) {
|
|
188
|
+
lines.push(`\n(no candidates above similarity threshold — KG already consolidated for this scan)`);
|
|
189
|
+
return lines.join("\n");
|
|
190
|
+
}
|
|
191
|
+
const safeCandidates = r.candidates.filter((c) => c.fp_risk === 'low').slice(0, limit);
|
|
192
|
+
if (safeCandidates.length > 0) {
|
|
193
|
+
lines.push(`\n### 🟢 LOW FP risk (${r.by_fp_risk.low}) — first ${safeCandidates.length}`);
|
|
194
|
+
for (const c of safeCandidates) {
|
|
195
|
+
lines.push(` sim=${c.similarity} [${c.primary.type}] "${c.primary.name}" (${c.primary.mentions} m, id=${c.primary.id}) ⊕ "${c.duplicate.name}" (${c.duplicate.mentions} m, id=${c.duplicate.id}) via ${c.reason}, shared_evidence=${c.shared_evidence_chunks}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (r.by_fp_risk.medium > 0) {
|
|
199
|
+
lines.push(`\n### 🟡 MEDIUM FP risk (${r.by_fp_risk.medium}) — sample`);
|
|
200
|
+
for (const c of r.candidates.filter((c) => c.fp_risk === 'medium').slice(0, 10)) {
|
|
201
|
+
lines.push(` sim=${c.similarity} [${c.primary.type}] "${c.primary.name}" ⊕ "${c.duplicate.name}" — ${c.fp_reasons.join("; ")}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (r.by_fp_risk.high > 0) {
|
|
205
|
+
lines.push(`\n### 🔴 HIGH FP risk (${r.by_fp_risk.high}) — protected/risky, NEVER auto-merge`);
|
|
206
|
+
for (const c of r.candidates.filter((c) => c.fp_risk === 'high').slice(0, 10)) {
|
|
207
|
+
lines.push(` sim=${c.similarity} [${c.primary.type}] "${c.primary.name}" ⊕ "${c.duplicate.name}" — ${c.fp_reasons.join("; ")}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
lines.push(`\n📌 Apply blocked: gate D01 = R01 nDCG ≥ 0.6 + dry-run zero FP. Current Run #9 = 0.519. Reactivate when R01c improves.`);
|
|
211
|
+
return lines.join("\n");
|
|
212
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface AgentProfile {
|
|
2
|
+
agent: string;
|
|
3
|
+
totalChunks: number;
|
|
4
|
+
topTypes: Array<{
|
|
5
|
+
type: string;
|
|
6
|
+
count: number;
|
|
7
|
+
}>;
|
|
8
|
+
topTopics: string[];
|
|
9
|
+
lastActivity: string | null;
|
|
10
|
+
uniqueStrength: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function profileAgent(agentName: string): AgentProfile | null;
|
|
13
|
+
export declare function profileAllAgents(): AgentProfile[];
|
|
14
|
+
export interface SharedInsight {
|
|
15
|
+
agent: string;
|
|
16
|
+
type: string;
|
|
17
|
+
text: string;
|
|
18
|
+
date: string | null;
|
|
19
|
+
relevance: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function pullInsightsFrom(sourceAgent: string, types?: string[], limit?: number): SharedInsight[];
|
|
22
|
+
export declare function pullAllInsights(excludeAgent?: string, types?: string[], limitPerAgent?: number): SharedInsight[];
|
|
23
|
+
export interface CrossEntity {
|
|
24
|
+
name: string;
|
|
25
|
+
type: string;
|
|
26
|
+
agents: string[];
|
|
27
|
+
totalMentions: number;
|
|
28
|
+
}
|
|
29
|
+
export declare function mergeCrossKnowledgeGraphs(): {
|
|
30
|
+
entities: CrossEntity[];
|
|
31
|
+
totalRelations: number;
|
|
32
|
+
};
|
|
33
|
+
export declare function findPath(startName: string, endName: string, maxDepth?: number): Array<{
|
|
34
|
+
entity: string;
|
|
35
|
+
relation: string;
|
|
36
|
+
}> | null;
|
|
37
|
+
export declare function formatProfiles(profiles: AgentProfile[]): string;
|
|
38
|
+
export declare function formatPath(path: Array<{
|
|
39
|
+
entity: string;
|
|
40
|
+
relation: string;
|
|
41
|
+
}> | null): string;
|
|
42
|
+
export declare function formatCrossKG(result: {
|
|
43
|
+
entities: CrossEntity[];
|
|
44
|
+
totalRelations: number;
|
|
45
|
+
}): string;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cross-agent-v2.ts — Cross-Agent Intelligence: knowledge sharing + expertise profiling
|
|
3
|
+
*/
|
|
4
|
+
import Database from "better-sqlite3";
|
|
5
|
+
import { resolve } from "path";
|
|
6
|
+
import { existsSync } from "fs";
|
|
7
|
+
const AGENTS_DIR = "/root/.openclaw/agents";
|
|
8
|
+
const WORKSPACE_DB = "/root/.openclaw/workspace/tools/nox-mem/nox-mem.db";
|
|
9
|
+
const AGENT_NAMES = ["nox", "atlas", "boris", "cipher", "forge", "lex"];
|
|
10
|
+
function getAgentDb(agent) {
|
|
11
|
+
const p = resolve(AGENTS_DIR, agent, "tools", "nox-mem", "nox-mem.db");
|
|
12
|
+
if (!existsSync(p))
|
|
13
|
+
return null;
|
|
14
|
+
try {
|
|
15
|
+
return new Database(p, { readonly: true });
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function profileAgent(agentName) {
|
|
22
|
+
const db = getAgentDb(agentName);
|
|
23
|
+
if (!db)
|
|
24
|
+
return null;
|
|
25
|
+
try {
|
|
26
|
+
const total = db.prepare("SELECT COUNT(*) as c FROM chunks").get().c;
|
|
27
|
+
const types = db.prepare("SELECT chunk_type, COUNT(*) as c FROM chunks GROUP BY chunk_type ORDER BY c DESC LIMIT 5").all();
|
|
28
|
+
// Extract top topics via FTS5 term frequency
|
|
29
|
+
let topTopics = [];
|
|
30
|
+
try {
|
|
31
|
+
const terms = db.prepare(`
|
|
32
|
+
SELECT term, SUM(cnt) as total FROM (
|
|
33
|
+
SELECT DISTINCT term, cnt FROM chunks_fts_data
|
|
34
|
+
WHERE col = 0 AND term NOT IN ('the','and','for','that','this','with','from','are','was','been','have','has','not','but','they','you','all')
|
|
35
|
+
ORDER BY cnt DESC LIMIT 20
|
|
36
|
+
) GROUP BY term ORDER BY total DESC LIMIT 10
|
|
37
|
+
`).all();
|
|
38
|
+
topTopics = terms.map(t => t.term);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// FTS internal tables may not be accessible
|
|
42
|
+
}
|
|
43
|
+
const lastDate = db.prepare("SELECT MAX(source_date) as d FROM chunks WHERE source_date IS NOT NULL").get();
|
|
44
|
+
// Determine unique strength based on dominant type
|
|
45
|
+
const dominant = types[0]?.chunk_type || "general";
|
|
46
|
+
const strengthMap = {
|
|
47
|
+
"team": "team coordination & shared knowledge",
|
|
48
|
+
"decision": "decision tracking & rationale",
|
|
49
|
+
"lesson": "lessons learned & pattern recognition",
|
|
50
|
+
"daily": "daily operations & activity logging",
|
|
51
|
+
"project": "project management & tracking",
|
|
52
|
+
"person": "people & relationship management",
|
|
53
|
+
"other": "general knowledge & context",
|
|
54
|
+
};
|
|
55
|
+
db.close();
|
|
56
|
+
return {
|
|
57
|
+
agent: agentName,
|
|
58
|
+
totalChunks: total,
|
|
59
|
+
topTypes: types.map(t => ({ type: t.chunk_type, count: t.c })),
|
|
60
|
+
topTopics,
|
|
61
|
+
lastActivity: lastDate.d,
|
|
62
|
+
uniqueStrength: strengthMap[dominant] || dominant,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
db.close();
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function profileAllAgents() {
|
|
71
|
+
return AGENT_NAMES.map(profileAgent).filter(Boolean);
|
|
72
|
+
}
|
|
73
|
+
export function pullInsightsFrom(sourceAgent, types = ["decision", "lesson"], limit = 10) {
|
|
74
|
+
const db = getAgentDb(sourceAgent);
|
|
75
|
+
if (!db)
|
|
76
|
+
return [];
|
|
77
|
+
try {
|
|
78
|
+
const placeholders = types.map(() => "?").join(",");
|
|
79
|
+
const rows = db.prepare(`
|
|
80
|
+
SELECT chunk_text, chunk_type, source_date, source_file
|
|
81
|
+
FROM chunks
|
|
82
|
+
WHERE chunk_type IN (${placeholders})
|
|
83
|
+
ORDER BY created_at DESC
|
|
84
|
+
LIMIT ?
|
|
85
|
+
`).all(...types, limit);
|
|
86
|
+
db.close();
|
|
87
|
+
return rows.map(r => ({
|
|
88
|
+
agent: sourceAgent,
|
|
89
|
+
type: r.chunk_type,
|
|
90
|
+
text: r.chunk_text,
|
|
91
|
+
date: r.source_date,
|
|
92
|
+
relevance: 1.0,
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
db.close();
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export function pullAllInsights(excludeAgent, types = ["decision", "lesson"], limitPerAgent = 5) {
|
|
101
|
+
const all = [];
|
|
102
|
+
for (const agent of AGENT_NAMES) {
|
|
103
|
+
if (agent === excludeAgent)
|
|
104
|
+
continue;
|
|
105
|
+
all.push(...pullInsightsFrom(agent, types, limitPerAgent));
|
|
106
|
+
}
|
|
107
|
+
// Sort by date descending
|
|
108
|
+
all.sort((a, b) => {
|
|
109
|
+
if (!a.date)
|
|
110
|
+
return 1;
|
|
111
|
+
if (!b.date)
|
|
112
|
+
return -1;
|
|
113
|
+
return b.date.localeCompare(a.date);
|
|
114
|
+
});
|
|
115
|
+
return all;
|
|
116
|
+
}
|
|
117
|
+
export function mergeCrossKnowledgeGraphs() {
|
|
118
|
+
const entityMap = new Map();
|
|
119
|
+
let totalRelations = 0;
|
|
120
|
+
for (const agent of AGENT_NAMES) {
|
|
121
|
+
const db = getAgentDb(agent);
|
|
122
|
+
if (!db)
|
|
123
|
+
continue;
|
|
124
|
+
try {
|
|
125
|
+
// Check if KG tables exist
|
|
126
|
+
const hasKg = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='kg_entities'").get();
|
|
127
|
+
if (!hasKg) {
|
|
128
|
+
db.close();
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const entities = db.prepare("SELECT name, entity_type, mention_count FROM kg_entities").all();
|
|
132
|
+
for (const e of entities) {
|
|
133
|
+
const key = `${e.entity_type}:${e.name.toLowerCase()}`;
|
|
134
|
+
if (entityMap.has(key)) {
|
|
135
|
+
const existing = entityMap.get(key);
|
|
136
|
+
existing.agents.push(agent);
|
|
137
|
+
existing.totalMentions += e.mention_count;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
entityMap.set(key, {
|
|
141
|
+
name: e.name,
|
|
142
|
+
type: e.entity_type,
|
|
143
|
+
agents: [agent],
|
|
144
|
+
totalMentions: e.mention_count,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const relCount = db.prepare("SELECT COUNT(*) as c FROM kg_relations").get().c;
|
|
149
|
+
totalRelations += relCount;
|
|
150
|
+
db.close();
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
db.close();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Also merge workspace KG
|
|
157
|
+
try {
|
|
158
|
+
const wsDb = new Database(WORKSPACE_DB, { readonly: true });
|
|
159
|
+
const hasKg = wsDb.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='kg_entities'").get();
|
|
160
|
+
if (hasKg) {
|
|
161
|
+
const entities = wsDb.prepare("SELECT name, entity_type, mention_count FROM kg_entities").all();
|
|
162
|
+
for (const e of entities) {
|
|
163
|
+
const key = `${e.entity_type}:${e.name.toLowerCase()}`;
|
|
164
|
+
if (entityMap.has(key)) {
|
|
165
|
+
const existing = entityMap.get(key);
|
|
166
|
+
if (!existing.agents.includes("workspace"))
|
|
167
|
+
existing.agents.push("workspace");
|
|
168
|
+
existing.totalMentions += e.mention_count;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
entityMap.set(key, {
|
|
172
|
+
name: e.name, type: e.entity_type,
|
|
173
|
+
agents: ["workspace"], totalMentions: e.mention_count,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const relCount = wsDb.prepare("SELECT COUNT(*) as c FROM kg_relations").get().c;
|
|
178
|
+
totalRelations += relCount;
|
|
179
|
+
}
|
|
180
|
+
wsDb.close();
|
|
181
|
+
}
|
|
182
|
+
catch { }
|
|
183
|
+
const entities = Array.from(entityMap.values())
|
|
184
|
+
.sort((a, b) => b.totalMentions - a.totalMentions);
|
|
185
|
+
return { entities, totalRelations };
|
|
186
|
+
}
|
|
187
|
+
// ─── Graph Traversal: Find path between entities ─────────────────────────────
|
|
188
|
+
export function findPath(startName, endName, maxDepth = 4) {
|
|
189
|
+
const db = new Database(WORKSPACE_DB, { readonly: true });
|
|
190
|
+
try {
|
|
191
|
+
const hasKg = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='kg_entities'").get();
|
|
192
|
+
if (!hasKg) {
|
|
193
|
+
db.close();
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
const startEntity = db.prepare("SELECT id, name FROM kg_entities WHERE name LIKE ? LIMIT 1").get(`%${startName}%`);
|
|
197
|
+
const endEntity = db.prepare("SELECT id, name FROM kg_entities WHERE name LIKE ? LIMIT 1").get(`%${endName}%`);
|
|
198
|
+
if (!startEntity || !endEntity) {
|
|
199
|
+
db.close();
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
// BFS
|
|
203
|
+
const queue = [
|
|
204
|
+
{ entityId: startEntity.id, path: [{ entity: startEntity.name, relation: "START" }] }
|
|
205
|
+
];
|
|
206
|
+
const visited = new Set([startEntity.id]);
|
|
207
|
+
while (queue.length > 0) {
|
|
208
|
+
const current = queue.shift();
|
|
209
|
+
if (current.path.length > maxDepth)
|
|
210
|
+
continue;
|
|
211
|
+
// Get neighbors
|
|
212
|
+
const neighbors = db.prepare(`
|
|
213
|
+
SELECT
|
|
214
|
+
CASE WHEN r.source_entity_id = ? THEN r.target_entity_id ELSE r.source_entity_id END as neighbor_id,
|
|
215
|
+
CASE WHEN r.source_entity_id = ? THEN e2.name ELSE e1.name END as neighbor_name,
|
|
216
|
+
r.relation_type
|
|
217
|
+
FROM kg_relations r
|
|
218
|
+
JOIN kg_entities e1 ON e1.id = r.source_entity_id
|
|
219
|
+
JOIN kg_entities e2 ON e2.id = r.target_entity_id
|
|
220
|
+
WHERE r.source_entity_id = ? OR r.target_entity_id = ?
|
|
221
|
+
`).all(current.entityId, current.entityId, current.entityId, current.entityId);
|
|
222
|
+
for (const n of neighbors) {
|
|
223
|
+
if (n.neighbor_id === endEntity.id) {
|
|
224
|
+
db.close();
|
|
225
|
+
return [...current.path, { entity: n.neighbor_name, relation: n.relation_type }];
|
|
226
|
+
}
|
|
227
|
+
if (!visited.has(n.neighbor_id)) {
|
|
228
|
+
visited.add(n.neighbor_id);
|
|
229
|
+
queue.push({
|
|
230
|
+
entityId: n.neighbor_id,
|
|
231
|
+
path: [...current.path, { entity: n.neighbor_name, relation: n.relation_type }],
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
db.close();
|
|
237
|
+
return null; // No path found
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
db.close();
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
// ─── Formatters ──────────────────────────────────────────────────────────────
|
|
245
|
+
export function formatProfiles(profiles) {
|
|
246
|
+
return profiles.map(p => {
|
|
247
|
+
const types = p.topTypes.map(t => `${t.type}:${t.count}`).join(", ");
|
|
248
|
+
return `📋 ${p.agent} (${p.totalChunks} chunks)\n Strength: ${p.uniqueStrength}\n Types: ${types}\n Last: ${p.lastActivity || "unknown"}`;
|
|
249
|
+
}).join("\n\n");
|
|
250
|
+
}
|
|
251
|
+
export function formatPath(path) {
|
|
252
|
+
if (!path)
|
|
253
|
+
return "No path found between entities.";
|
|
254
|
+
return path.map((step, i) => {
|
|
255
|
+
if (i === 0)
|
|
256
|
+
return `🟢 ${step.entity}`;
|
|
257
|
+
return ` —[${step.relation}]→ ${step.entity}`;
|
|
258
|
+
}).join("\n");
|
|
259
|
+
}
|
|
260
|
+
export function formatCrossKG(result) {
|
|
261
|
+
const lines = [
|
|
262
|
+
`=== Cross-Agent Knowledge Graph ===`,
|
|
263
|
+
`Total unique entities: ${result.entities.length}`,
|
|
264
|
+
`Total relations: ${result.totalRelations}\n`,
|
|
265
|
+
`Top entities (by mentions):`,
|
|
266
|
+
];
|
|
267
|
+
for (const e of result.entities.slice(0, 15)) {
|
|
268
|
+
lines.push(` ${e.name} (${e.type}) — ${e.totalMentions} mentions [${e.agents.join(", ")}]`);
|
|
269
|
+
}
|
|
270
|
+
return lines.join("\n");
|
|
271
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface CrossSearchResult {
|
|
2
|
+
agent: string;
|
|
3
|
+
score: number;
|
|
4
|
+
source_file: string;
|
|
5
|
+
chunk_type: string;
|
|
6
|
+
chunk_text: string;
|
|
7
|
+
source_date: string | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function crossSearch(query: string, limit?: number): CrossSearchResult[];
|
|
10
|
+
export declare function formatCrossResults(results: CrossSearchResult[]): string;
|
|
11
|
+
export declare function getCrossStats(): string;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cross-search.ts — Search across ALL agent memory databases
|
|
3
|
+
* Enables any agent to query memories from other agents
|
|
4
|
+
*/
|
|
5
|
+
import Database from "better-sqlite3";
|
|
6
|
+
import { resolve } from "path";
|
|
7
|
+
import { existsSync } from "fs";
|
|
8
|
+
// NOX_AGENTS_DIR: base directory for agent sub-dirs. Defaults to the OpenClaw layout.
|
|
9
|
+
// NOX_AGENTS: comma-separated agent name list.
|
|
10
|
+
// NOX_WORKSPACE_DB: explicit path to the workspace DB (overrides OPENCLAW_WORKSPACE derivation).
|
|
11
|
+
// When AGENTS_DIR doesn't exist on disk, searchInDb() already returns [] via existsSync guard.
|
|
12
|
+
const _WORKSPACE = process.env.OPENCLAW_WORKSPACE ?? "/root/.openclaw/workspace";
|
|
13
|
+
const AGENTS_DIR = process.env.NOX_AGENTS_DIR ?? "/root/.openclaw/agents";
|
|
14
|
+
const WORKSPACE_DB = process.env.NOX_WORKSPACE_DB ?? resolve(_WORKSPACE, "tools/nox-mem/nox-mem.db");
|
|
15
|
+
const AGENT_NAMES = process.env.NOX_AGENTS
|
|
16
|
+
? process.env.NOX_AGENTS.split(",").map(s => s.trim()).filter(Boolean)
|
|
17
|
+
: ["nox", "atlas", "boris", "cipher", "forge", "lex"];
|
|
18
|
+
function getAgentDbPath(agent) {
|
|
19
|
+
return resolve(AGENTS_DIR, agent, "tools", "nox-mem", "nox-mem.db");
|
|
20
|
+
}
|
|
21
|
+
function searchInDb(dbPath, agentName, query, limit) {
|
|
22
|
+
if (!existsSync(dbPath))
|
|
23
|
+
return [];
|
|
24
|
+
let db = null;
|
|
25
|
+
try {
|
|
26
|
+
db = new Database(dbPath, { readonly: true });
|
|
27
|
+
const sanitized = query.replace(/['"{}()\[\]:*^~&|!]/g, " ").trim();
|
|
28
|
+
if (!sanitized)
|
|
29
|
+
return [];
|
|
30
|
+
const rows = db.prepare(`
|
|
31
|
+
SELECT c.source_file, c.chunk_type, c.chunk_text, c.source_date,
|
|
32
|
+
bm25(chunks_fts, 1.0, 0.5, 0.5) as rank
|
|
33
|
+
FROM chunks_fts
|
|
34
|
+
JOIN chunks c ON c.id = chunks_fts.rowid
|
|
35
|
+
WHERE chunks_fts MATCH ?
|
|
36
|
+
ORDER BY rank LIMIT ?
|
|
37
|
+
`).all(sanitized, limit);
|
|
38
|
+
return rows.map(r => ({
|
|
39
|
+
agent: agentName,
|
|
40
|
+
score: Math.round(Math.abs(r.rank) * 100) / 100,
|
|
41
|
+
source_file: r.source_file,
|
|
42
|
+
chunk_type: r.chunk_type,
|
|
43
|
+
chunk_text: r.chunk_text,
|
|
44
|
+
source_date: r.source_date,
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
console.error(`[WARN] Failed to search ${agentName}: ${err instanceof Error ? err.message : String(err)}`);
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
if (db)
|
|
53
|
+
db.close();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function crossSearch(query, limit = 10) {
|
|
57
|
+
const allResults = [];
|
|
58
|
+
// Search workspace
|
|
59
|
+
allResults.push(...searchInDb(WORKSPACE_DB, "workspace", query, limit));
|
|
60
|
+
// Search all agent DBs
|
|
61
|
+
for (const agent of AGENT_NAMES) {
|
|
62
|
+
const dbPath = getAgentDbPath(agent);
|
|
63
|
+
allResults.push(...searchInDb(dbPath, agent, query, limit));
|
|
64
|
+
}
|
|
65
|
+
// Sort by score descending, deduplicate by content similarity
|
|
66
|
+
allResults.sort((a, b) => b.score - a.score);
|
|
67
|
+
// Simple dedup: skip if same first 100 chars exist
|
|
68
|
+
const seen = new Set();
|
|
69
|
+
const deduped = [];
|
|
70
|
+
for (const r of allResults) {
|
|
71
|
+
const key = r.chunk_text.substring(0, 100);
|
|
72
|
+
if (!seen.has(key)) {
|
|
73
|
+
seen.add(key);
|
|
74
|
+
deduped.push(r);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return deduped.slice(0, limit);
|
|
78
|
+
}
|
|
79
|
+
export function formatCrossResults(results) {
|
|
80
|
+
if (results.length === 0)
|
|
81
|
+
return "No results found across agents.";
|
|
82
|
+
return results
|
|
83
|
+
.map((r, i) => {
|
|
84
|
+
const preview = r.chunk_text.substring(0, 200).replace(/\n/g, " ");
|
|
85
|
+
return `#${i + 1} [${r.score} @${r.agent}] ${r.source_file}\n "${preview}..."`;
|
|
86
|
+
})
|
|
87
|
+
.join("\n\n");
|
|
88
|
+
}
|
|
89
|
+
export function getCrossStats() {
|
|
90
|
+
const stats = ["=== Cross-Agent Memory Stats ===\n"];
|
|
91
|
+
// Workspace
|
|
92
|
+
try {
|
|
93
|
+
const db = new Database(WORKSPACE_DB, { readonly: true });
|
|
94
|
+
const count = db.prepare("SELECT COUNT(*) as c FROM chunks").get().c;
|
|
95
|
+
stats.push(`workspace: ${count} chunks`);
|
|
96
|
+
db.close();
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
stats.push("workspace: unavailable");
|
|
100
|
+
}
|
|
101
|
+
// Agents
|
|
102
|
+
for (const agent of AGENT_NAMES) {
|
|
103
|
+
const dbPath = getAgentDbPath(agent);
|
|
104
|
+
try {
|
|
105
|
+
if (!existsSync(dbPath)) {
|
|
106
|
+
stats.push(`${agent}: no DB`);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const db = new Database(dbPath, { readonly: true });
|
|
110
|
+
const count = db.prepare("SELECT COUNT(*) as c FROM chunks").get().c;
|
|
111
|
+
stats.push(`${agent}: ${count} chunks`);
|
|
112
|
+
db.close();
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
stats.push(`${agent}: error`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return stats.join("\n");
|
|
119
|
+
}
|