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
package/dist/index.js
ADDED
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { search, searchHybrid, formatResults } from "./search.js";
|
|
4
|
+
import { reindex } from "./reindex.js";
|
|
5
|
+
import { primer } from "./primer.js";
|
|
6
|
+
import { getStats } from "./stats.js";
|
|
7
|
+
import { getDb, closeDb, checkLargeDbIngestGuard } from "./db.js";
|
|
8
|
+
import { syncProjectContexts, listProjects } from "./project-context-gen.js";
|
|
9
|
+
import { crossSearch, formatCrossResults, getCrossStats } from "./cross-search.js";
|
|
10
|
+
import { compact } from "./compact.js";
|
|
11
|
+
import { getMetrics } from "./metrics.js";
|
|
12
|
+
import { updateSessionState } from "./session-update.js";
|
|
13
|
+
import { buildGraph, getGraphStats, formatEntityQuery, mergeEntities, pruneKnowledgeGraph, formatPruneResult, upsertDecision, getDecisionHistory, listDecisions, getCurrentDecision } from "./knowledge-graph.js";
|
|
14
|
+
import { shareInsight, pullSharedInsights, sharedStats } from "./shared-memory.js";
|
|
15
|
+
import { selfImprove } from "./self-improve.js";
|
|
16
|
+
import { getTierStats, evaluateTiers } from "./tier-manager.js";
|
|
17
|
+
import { getNoiseStats, isNoise } from "./noise-filter.js";
|
|
18
|
+
import { distillSessions } from "./session-distill.js";
|
|
19
|
+
import { startWatch } from "./watch.js";
|
|
20
|
+
const program = new Command();
|
|
21
|
+
program.name("nox-mem").description("Nox Supermem — search, consolidate, recover").version("2.3.0");
|
|
22
|
+
program
|
|
23
|
+
.command("search <query>")
|
|
24
|
+
.description("Search memory (FTS5 + boost + recency)")
|
|
25
|
+
.option("-n, --limit <n>", "Number of results", "5")
|
|
26
|
+
.option("--no-hybrid", "Disable semantic search (FTS5 only)")
|
|
27
|
+
.action(async (query, opts) => {
|
|
28
|
+
if (opts.hybrid) {
|
|
29
|
+
const results = await searchHybrid(query, parseInt(opts.limit, 10));
|
|
30
|
+
console.log(formatResults(results));
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
console.log(formatResults(search(query, parseInt(opts.limit, 10))));
|
|
34
|
+
}
|
|
35
|
+
closeDb();
|
|
36
|
+
});
|
|
37
|
+
program
|
|
38
|
+
.command("vectorize")
|
|
39
|
+
.description("Build/update vector index for all chunks (semantic search)")
|
|
40
|
+
.option("--force", "Re-embed all chunks, even already indexed", false)
|
|
41
|
+
.action(async (opts) => {
|
|
42
|
+
const { vectorize } = await import("./vectorize.js");
|
|
43
|
+
const result = await vectorize({ force: opts.force });
|
|
44
|
+
console.log(`[INFO] Vectorize complete: ${result.embedded} embedded, ${result.skipped} skipped, ${result.total} total`);
|
|
45
|
+
closeDb();
|
|
46
|
+
});
|
|
47
|
+
program
|
|
48
|
+
.command("ingest <file>")
|
|
49
|
+
.description("Index a specific .md or .json file")
|
|
50
|
+
.option("--allow-prod", "Skip large-DB ingest guard (required for prod ops, see CLAUDE.md §6)")
|
|
51
|
+
.action(async (file, opts) => {
|
|
52
|
+
// Large-DB guard (postmortem 2026-05-19): abort if DB looks like prod
|
|
53
|
+
// and operator hasn't explicitly opted in. Override via --allow-prod flag
|
|
54
|
+
// or NOX_ALLOW_PROD_INGEST=1 env var.
|
|
55
|
+
if (opts.allowProd) {
|
|
56
|
+
process.env.NOX_ALLOW_PROD_INGEST = "1";
|
|
57
|
+
}
|
|
58
|
+
checkLargeDbIngestGuard(getDb(), "ingest");
|
|
59
|
+
const { routeIngest } = await import("./lib/ingest-router.js");
|
|
60
|
+
const result = await routeIngest(file);
|
|
61
|
+
console.log(`[INFO] Ingested ${file}: ${result.chunks} chunks (kind=${result.kind}, via=${result.routedTo})`);
|
|
62
|
+
closeDb();
|
|
63
|
+
});
|
|
64
|
+
program
|
|
65
|
+
.command("ingest-entity <file>")
|
|
66
|
+
.description("Ingest entity file (3-secoes) via routeIngest — preserva section/retention (incident 2026-04-25)")
|
|
67
|
+
.option("--allow-prod", "Skip large-DB ingest guard (required for prod ops, see CLAUDE.md §6)")
|
|
68
|
+
.action(async (file, opts) => {
|
|
69
|
+
if (opts.allowProd) {
|
|
70
|
+
process.env.NOX_ALLOW_PROD_INGEST = "1";
|
|
71
|
+
}
|
|
72
|
+
checkLargeDbIngestGuard(getDb(), "ingest");
|
|
73
|
+
const { routeIngest } = await import("./lib/ingest-router.js");
|
|
74
|
+
const result = await routeIngest(file);
|
|
75
|
+
console.log(`[INFO] Ingested ${file}: ${result.chunks} chunks (kind=${result.kind}, via=${result.routedTo})`);
|
|
76
|
+
closeDb();
|
|
77
|
+
});
|
|
78
|
+
program
|
|
79
|
+
.command("reindex")
|
|
80
|
+
.description("Rebuild entire index from markdown files (preserves consolidation state)")
|
|
81
|
+
.action(async () => {
|
|
82
|
+
const result = await reindex();
|
|
83
|
+
console.log(`[INFO] Reindexed ${result.files} files, ${result.chunks} chunks`);
|
|
84
|
+
});
|
|
85
|
+
program
|
|
86
|
+
.command("primer")
|
|
87
|
+
.description("Generate context recovery summary (~500 tokens)")
|
|
88
|
+
.action(async () => {
|
|
89
|
+
console.log(primer());
|
|
90
|
+
closeDb();
|
|
91
|
+
});
|
|
92
|
+
program
|
|
93
|
+
.command("stats")
|
|
94
|
+
.description("Show memory statistics")
|
|
95
|
+
.action(async () => {
|
|
96
|
+
console.log(getStats());
|
|
97
|
+
closeDb();
|
|
98
|
+
});
|
|
99
|
+
program
|
|
100
|
+
.command("consolidate")
|
|
101
|
+
.description("Consolidate daily notes into topic files (requires Ollama)")
|
|
102
|
+
.action(async () => {
|
|
103
|
+
const { consolidate } = await import("./consolidate.js");
|
|
104
|
+
const { syncToNotion } = await import("./notion-sync.js");
|
|
105
|
+
const result = await consolidate();
|
|
106
|
+
if (result.notionItems.length > 0) {
|
|
107
|
+
await syncToNotion(result.notionItems);
|
|
108
|
+
}
|
|
109
|
+
if (result.remaining > 0) {
|
|
110
|
+
console.log(`[INFO] ${result.remaining} daily notes still pending — run again or wait for next cron`);
|
|
111
|
+
}
|
|
112
|
+
closeDb();
|
|
113
|
+
});
|
|
114
|
+
program
|
|
115
|
+
.command("retry-failed")
|
|
116
|
+
.description("Retry consolidation of previously failed daily notes")
|
|
117
|
+
.action(async () => {
|
|
118
|
+
const { consolidate } = await import("./consolidate.js");
|
|
119
|
+
const { syncToNotion } = await import("./notion-sync.js");
|
|
120
|
+
const result = await consolidate({ retryFailed: true });
|
|
121
|
+
if (result.notionItems.length > 0) {
|
|
122
|
+
await syncToNotion(result.notionItems);
|
|
123
|
+
}
|
|
124
|
+
closeDb();
|
|
125
|
+
});
|
|
126
|
+
program
|
|
127
|
+
.command("digest")
|
|
128
|
+
.description("Generate weekly digest")
|
|
129
|
+
.action(async () => {
|
|
130
|
+
const { digest } = await import("./digest.js");
|
|
131
|
+
await digest();
|
|
132
|
+
closeDb();
|
|
133
|
+
});
|
|
134
|
+
program
|
|
135
|
+
.command("sync-notion")
|
|
136
|
+
.description("Re-sync last consolidation items to Notion")
|
|
137
|
+
.action(async () => {
|
|
138
|
+
const { syncToNotion, loadSyncLog } = await import("./notion-sync.js");
|
|
139
|
+
const items = loadSyncLog();
|
|
140
|
+
if (items.length === 0) {
|
|
141
|
+
console.log("[INFO] No items to sync — run consolidate first");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
console.log(`[INFO] Re-syncing ${items.length} items from last consolidation...`);
|
|
145
|
+
await syncToNotion(items);
|
|
146
|
+
});
|
|
147
|
+
program
|
|
148
|
+
.command("doctor")
|
|
149
|
+
.description("Diagnostic check — Ollama, SQLite, FTS5, watcher, Notion")
|
|
150
|
+
.action(async () => {
|
|
151
|
+
const { doctor } = await import("./doctor.js");
|
|
152
|
+
await doctor();
|
|
153
|
+
closeDb();
|
|
154
|
+
});
|
|
155
|
+
program
|
|
156
|
+
.command("projects")
|
|
157
|
+
.description("List all projects with last update date")
|
|
158
|
+
.action(async () => {
|
|
159
|
+
listProjects();
|
|
160
|
+
closeDb();
|
|
161
|
+
});
|
|
162
|
+
program
|
|
163
|
+
.command("project-sync")
|
|
164
|
+
.description("Sync PROJECT_CONTEXT.md files from memory database")
|
|
165
|
+
.action(async () => {
|
|
166
|
+
const result = syncProjectContexts();
|
|
167
|
+
console.log(`[PROJECT-SYNC] Updated: ${result.updated}, Created: ${result.created}, Errors: ${result.errors}`);
|
|
168
|
+
closeDb();
|
|
169
|
+
});
|
|
170
|
+
program
|
|
171
|
+
.command("cross-search <query>")
|
|
172
|
+
.description("Search across ALL agent memory databases")
|
|
173
|
+
.option("-n, --limit <n>", "Number of results", "10")
|
|
174
|
+
.action((query, opts) => {
|
|
175
|
+
const results = crossSearch(query, parseInt(opts.limit, 10));
|
|
176
|
+
console.log(formatCrossResults(results));
|
|
177
|
+
});
|
|
178
|
+
program
|
|
179
|
+
.command("cross-stats")
|
|
180
|
+
.description("Show chunk counts across all agent databases")
|
|
181
|
+
.action(async () => {
|
|
182
|
+
console.log(getCrossStats());
|
|
183
|
+
});
|
|
184
|
+
program
|
|
185
|
+
.command("compact")
|
|
186
|
+
.description("Compress old chunks (>30 days) into summaries")
|
|
187
|
+
.option("--age <days>", "Minimum age in days", "30")
|
|
188
|
+
.option("--dry-run", "Preview without making changes", false)
|
|
189
|
+
.action(async (opts) => {
|
|
190
|
+
const result = await compact(parseInt(opts.age, 10), opts.dryRun);
|
|
191
|
+
console.log("[COMPACT] Done: " + result.compacted + " compacted, " + result.summaries + " summaries, " + result.deleted + " removed");
|
|
192
|
+
closeDb();
|
|
193
|
+
});
|
|
194
|
+
program
|
|
195
|
+
.command("metrics")
|
|
196
|
+
.description("Show daily observability metrics")
|
|
197
|
+
.option("-d, --days <n>", "Number of days to show", "7")
|
|
198
|
+
.action((opts) => {
|
|
199
|
+
console.log(getMetrics(parseInt(opts.days, 10)));
|
|
200
|
+
closeDb();
|
|
201
|
+
});
|
|
202
|
+
program
|
|
203
|
+
.command("update-session")
|
|
204
|
+
.description("Auto-update SESSION-STATE.md from latest memory")
|
|
205
|
+
.action(async () => {
|
|
206
|
+
updateSessionState();
|
|
207
|
+
closeDb();
|
|
208
|
+
});
|
|
209
|
+
program
|
|
210
|
+
.command("kg-build")
|
|
211
|
+
.description("Build knowledge graph from memory chunks (incremental)")
|
|
212
|
+
.option("-n, --limit <n>", "Max chunks to process", "200")
|
|
213
|
+
.action(async (opts) => {
|
|
214
|
+
const result = buildGraph(parseInt(opts.limit, 10));
|
|
215
|
+
console.log("[KG] Built: " + result.entities + " entities, " + result.relations + " relations");
|
|
216
|
+
closeDb();
|
|
217
|
+
});
|
|
218
|
+
program
|
|
219
|
+
.command("kg-query <entity>")
|
|
220
|
+
.description("Query knowledge graph for an entity and its relations")
|
|
221
|
+
.action(async (entity) => {
|
|
222
|
+
console.log(formatEntityQuery(entity));
|
|
223
|
+
closeDb();
|
|
224
|
+
});
|
|
225
|
+
program
|
|
226
|
+
.command("kg-stats")
|
|
227
|
+
.description("Show knowledge graph statistics")
|
|
228
|
+
.action(async () => {
|
|
229
|
+
console.log(getGraphStats());
|
|
230
|
+
closeDb();
|
|
231
|
+
});
|
|
232
|
+
program
|
|
233
|
+
.command("self-improve")
|
|
234
|
+
.description("Run agent self-improvement analysis (contradictions, patterns, gaps)")
|
|
235
|
+
.action(async () => {
|
|
236
|
+
const report = await selfImprove();
|
|
237
|
+
console.log(report);
|
|
238
|
+
closeDb();
|
|
239
|
+
});
|
|
240
|
+
program
|
|
241
|
+
.command("kg-merge")
|
|
242
|
+
.description("Merge duplicate entities in knowledge graph (normalizes names)")
|
|
243
|
+
.option("--dry-run", "Show what would be merged without mutating (preview JSON)", false)
|
|
244
|
+
.action(async (opts) => {
|
|
245
|
+
// audit #20 fix — kg-merge does DELETE+UPDATE on kg_entities/kg_relations.
|
|
246
|
+
// Wrap in withOpAudit for atomic snapshot pre-op (CLAUDE.md rule #6) and
|
|
247
|
+
// expose --dry-run for safe preview without mutation.
|
|
248
|
+
if (opts.dryRun) {
|
|
249
|
+
const { previewMergeEntities } = await import("./knowledge-graph.js");
|
|
250
|
+
const preview = previewMergeEntities();
|
|
251
|
+
console.log(JSON.stringify({
|
|
252
|
+
op: "kg-merge",
|
|
253
|
+
dry_run: true,
|
|
254
|
+
would_merge: preview.wouldMerge,
|
|
255
|
+
groups: preview.groups,
|
|
256
|
+
}, null, 2));
|
|
257
|
+
closeDb();
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const { withOpAudit } = await import("./lib/op-audit.js");
|
|
261
|
+
const result = await withOpAudit("kg-merge", async () => {
|
|
262
|
+
const r = mergeEntities();
|
|
263
|
+
return { affected_rows: r.merged };
|
|
264
|
+
});
|
|
265
|
+
const merged = typeof result === "object" && result && "affected_rows" in result
|
|
266
|
+
? result.affected_rows
|
|
267
|
+
: 0;
|
|
268
|
+
console.log("[KG] Merged " + merged + " duplicate entities");
|
|
269
|
+
closeDb();
|
|
270
|
+
});
|
|
271
|
+
program
|
|
272
|
+
.command("kg-prune")
|
|
273
|
+
.description("Prune expired/low-confidence relations from knowledge graph (TTL decay)")
|
|
274
|
+
.option("--dry-run", "Show what would be pruned without deleting")
|
|
275
|
+
.action(async (opts) => {
|
|
276
|
+
const result = pruneKnowledgeGraph(opts.dryRun ?? false);
|
|
277
|
+
console.log(formatPruneResult(result));
|
|
278
|
+
if (opts.dryRun)
|
|
279
|
+
console.log("[KG-PRUNE] Dry run — no changes made");
|
|
280
|
+
closeDb();
|
|
281
|
+
});
|
|
282
|
+
// ─── Decision versioning ────────────────────────────────────────────────────
|
|
283
|
+
program
|
|
284
|
+
.command("decision-set <key> <content>")
|
|
285
|
+
.description("Set/update a versioned decision (tracks full history)")
|
|
286
|
+
.option("--author <name>", "Author name", "system")
|
|
287
|
+
.action((key, content, opts) => {
|
|
288
|
+
const v = upsertDecision(key, content, undefined, opts.author);
|
|
289
|
+
console.log(`✅ Decision "${key}" → v${v}`);
|
|
290
|
+
closeDb();
|
|
291
|
+
});
|
|
292
|
+
program
|
|
293
|
+
.command("decision-get <key>")
|
|
294
|
+
.description("Get current value of a decision")
|
|
295
|
+
.action((key) => {
|
|
296
|
+
const current = getCurrentDecision(key);
|
|
297
|
+
if (!current) {
|
|
298
|
+
console.log(`Decision "${key}" not found`);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
console.log(current);
|
|
302
|
+
}
|
|
303
|
+
closeDb();
|
|
304
|
+
});
|
|
305
|
+
program
|
|
306
|
+
.command("decision-history <key>")
|
|
307
|
+
.description("Show full version history of a decision")
|
|
308
|
+
.action((key) => {
|
|
309
|
+
const history = getDecisionHistory(key);
|
|
310
|
+
if (history.length === 0) {
|
|
311
|
+
console.log(`No history for "${key}"`);
|
|
312
|
+
closeDb();
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
for (const h of history) {
|
|
316
|
+
const flag = h.is_current ? " [CURRENT]" : ` [superseded ${h.superseded_at}]`;
|
|
317
|
+
console.log(`v${h.version}${flag} — ${h.created_at}`);
|
|
318
|
+
console.log(` ${h.content}\n`);
|
|
319
|
+
}
|
|
320
|
+
closeDb();
|
|
321
|
+
});
|
|
322
|
+
program
|
|
323
|
+
.command("decision-list")
|
|
324
|
+
.description("List all current decisions")
|
|
325
|
+
.action(() => {
|
|
326
|
+
const decisions = listDecisions();
|
|
327
|
+
if (decisions.length === 0) {
|
|
328
|
+
console.log("No decisions recorded");
|
|
329
|
+
closeDb();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
for (const d of decisions) {
|
|
333
|
+
console.log(`[${d.decision_key}] v${d.version} (${d.created_at})`);
|
|
334
|
+
console.log(` ${d.content.substring(0, 120)}\n`);
|
|
335
|
+
}
|
|
336
|
+
closeDb();
|
|
337
|
+
});
|
|
338
|
+
// ─── Shared memory (cross-agent) ────────────────────────────────────────────
|
|
339
|
+
program
|
|
340
|
+
.command("share <text>")
|
|
341
|
+
.description("Share an insight to the cross-agent shared memory pool")
|
|
342
|
+
.option("--type <type>", "Chunk type", "insight")
|
|
343
|
+
.option("--tags <tags>", "Comma-separated tags", "")
|
|
344
|
+
.option("--reason <reason>", "Why sharing this")
|
|
345
|
+
.action(async (text, opts) => {
|
|
346
|
+
const tags = opts.tags ? opts.tags.split(",").map(t => t.trim()) : [];
|
|
347
|
+
const id = shareInsight(text, opts.type, tags, opts.reason);
|
|
348
|
+
console.log(`✅ Shared (id=${id})`);
|
|
349
|
+
closeDb();
|
|
350
|
+
});
|
|
351
|
+
program
|
|
352
|
+
.command("pull-shared")
|
|
353
|
+
.description("Pull unprocessed shared insights from other agents into this DB")
|
|
354
|
+
.option("--agent <name>", "Agent name to pull for")
|
|
355
|
+
.action(async (opts) => {
|
|
356
|
+
const imported = await pullSharedInsights(opts.agent);
|
|
357
|
+
console.log(`✅ Imported ${imported} shared insights`);
|
|
358
|
+
closeDb();
|
|
359
|
+
});
|
|
360
|
+
program
|
|
361
|
+
.command("shared-stats")
|
|
362
|
+
.description("Show stats on the cross-agent shared memory pool")
|
|
363
|
+
.action(() => {
|
|
364
|
+
const stats = sharedStats();
|
|
365
|
+
console.log(`Total shared: ${stats.total}`);
|
|
366
|
+
for (const a of stats.byAgent)
|
|
367
|
+
console.log(` ${a.agent}: ${a.count}`);
|
|
368
|
+
closeDb();
|
|
369
|
+
});
|
|
370
|
+
// ─── Knowledge Graph v2: LLM extraction ──────────────────────────────────────
|
|
371
|
+
program
|
|
372
|
+
.command("kg-extract")
|
|
373
|
+
.description("Extract entities/relations from chunks using LLM (Ollama)")
|
|
374
|
+
.option("-n, --limit <n>", "Chunks to process", "50")
|
|
375
|
+
.action(async (opts) => {
|
|
376
|
+
const { extractWithLLM } = await import("./kg-llm.js");
|
|
377
|
+
const { ensureGraphTables, buildGraph } = await import("./knowledge-graph.js");
|
|
378
|
+
const { getDb, closeDb } = await import("./db.js");
|
|
379
|
+
ensureGraphTables();
|
|
380
|
+
const db = getDb();
|
|
381
|
+
const lastProcessed = db.prepare("SELECT value FROM meta WHERE key = 'kg_llm_last_chunk_id'").get()?.value || "0";
|
|
382
|
+
const chunks = db.prepare("SELECT id, chunk_text, chunk_type FROM chunks WHERE id > ? ORDER BY id ASC LIMIT ?").all(parseInt(lastProcessed), parseInt(opts.limit));
|
|
383
|
+
if (chunks.length === 0) {
|
|
384
|
+
console.log("[KG-LLM] No new chunks");
|
|
385
|
+
closeDb();
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
let totalE = 0, totalR = 0, maxId = parseInt(lastProcessed);
|
|
389
|
+
let fastPathChunks = 0, llmChunks = 0;
|
|
390
|
+
for (const chunk of chunks) {
|
|
391
|
+
const result = await extractWithLLM(chunk.chunk_text);
|
|
392
|
+
if (result.fast_path_used)
|
|
393
|
+
fastPathChunks++;
|
|
394
|
+
else
|
|
395
|
+
llmChunks++;
|
|
396
|
+
for (const e of result.entities) {
|
|
397
|
+
// Fase 1.7a: ontology attributes — merge JSON ao upsert.
|
|
398
|
+
const newAttrs = e.attributes || null;
|
|
399
|
+
const existing = db.prepare("SELECT id, attributes FROM kg_entities WHERE name = ? AND entity_type = ?").get(e.name, e.type);
|
|
400
|
+
if (existing) {
|
|
401
|
+
// Merge: preserva attributes existentes; chaves novas sobrescrevem.
|
|
402
|
+
let merged = {};
|
|
403
|
+
try {
|
|
404
|
+
merged = existing.attributes ? JSON.parse(existing.attributes) : {};
|
|
405
|
+
}
|
|
406
|
+
catch {
|
|
407
|
+
merged = {};
|
|
408
|
+
}
|
|
409
|
+
if (newAttrs)
|
|
410
|
+
merged = { ...merged, ...newAttrs };
|
|
411
|
+
const mergedJson = Object.keys(merged).length > 0 ? JSON.stringify(merged) : null;
|
|
412
|
+
db.prepare("UPDATE kg_entities SET mention_count = mention_count + 1, last_seen = datetime('now'), attributes = ? WHERE id = ?").run(mergedJson, existing.id);
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
db.prepare("INSERT INTO kg_entities (name, entity_type, attributes) VALUES (?, ?, ?)").run(e.name, e.type, newAttrs ? JSON.stringify(newAttrs) : null);
|
|
416
|
+
}
|
|
417
|
+
totalE++;
|
|
418
|
+
}
|
|
419
|
+
for (const r of result.relations) {
|
|
420
|
+
const src = db.prepare("SELECT id FROM kg_entities WHERE name = ?").get(r.source);
|
|
421
|
+
const tgt = db.prepare("SELECT id FROM kg_entities WHERE name = ?").get(r.target);
|
|
422
|
+
if (src && tgt) {
|
|
423
|
+
db.prepare("INSERT OR IGNORE INTO kg_relations (source_entity_id, relation_type, target_entity_id, evidence_chunk_id) VALUES (?, ?, ?, ?)").run(src.id, r.relation, tgt.id, chunk.id);
|
|
424
|
+
totalR++;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
maxId = Math.max(maxId, chunk.id);
|
|
428
|
+
process.stdout.write(`\r[KG-LLM] ${chunks.indexOf(chunk) + 1}/${chunks.length} — ${totalE}E ${totalR}R (fast:${fastPathChunks} llm:${llmChunks})`);
|
|
429
|
+
}
|
|
430
|
+
db.prepare("INSERT OR REPLACE INTO meta (key, value) VALUES ('kg_llm_last_chunk_id', ?)").run(String(maxId));
|
|
431
|
+
const savedPct = chunks.length > 0 ? Math.round((fastPathChunks / chunks.length) * 100) : 0;
|
|
432
|
+
console.log(`\n[KG-LLM] Done: ${totalE} entities, ${totalR} relations from ${chunks.length} chunks · fast-path ${savedPct}% (${fastPathChunks}/${chunks.length}) — Gemini calls saved`);
|
|
433
|
+
closeDb();
|
|
434
|
+
});
|
|
435
|
+
// ─── Cross-Agent Intelligence v2 ─────────────────────────────────────────────
|
|
436
|
+
program
|
|
437
|
+
.command("agent-profiles")
|
|
438
|
+
.description("Show expertise profiles for all agents")
|
|
439
|
+
.action(async () => {
|
|
440
|
+
const { profileAllAgents, formatProfiles } = await import("./cross-agent-v2.js");
|
|
441
|
+
console.log(formatProfiles(profileAllAgents()));
|
|
442
|
+
});
|
|
443
|
+
program
|
|
444
|
+
.command("agent-insights")
|
|
445
|
+
.description("Pull lessons and decisions from all agents")
|
|
446
|
+
.option("--from <agent>", "Pull from specific agent")
|
|
447
|
+
.option("-n, --limit <n>", "Results per agent", "5")
|
|
448
|
+
.action(async (opts) => {
|
|
449
|
+
const { pullInsightsFrom, pullAllInsights } = await import("./cross-agent-v2.js");
|
|
450
|
+
const limit = parseInt(opts.limit);
|
|
451
|
+
const insights = opts.from
|
|
452
|
+
? pullInsightsFrom(opts.from, ["decision", "lesson"], limit)
|
|
453
|
+
: pullAllInsights(undefined, ["decision", "lesson"], limit);
|
|
454
|
+
if (insights.length === 0) {
|
|
455
|
+
console.log("No insights found.");
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
for (const i of insights) {
|
|
459
|
+
const preview = i.text.substring(0, 200).replace(/\n/g, " ");
|
|
460
|
+
console.log(`[@${i.agent}] [${i.type}] ${i.date || "?"}`);
|
|
461
|
+
console.log(` ${preview}...\n`);
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
program
|
|
465
|
+
.command("cross-kg")
|
|
466
|
+
.description("Merge and display knowledge graphs across all agents")
|
|
467
|
+
.action(async () => {
|
|
468
|
+
const { mergeCrossKnowledgeGraphs, formatCrossKG } = await import("./cross-agent-v2.js");
|
|
469
|
+
console.log(formatCrossKG(mergeCrossKnowledgeGraphs()));
|
|
470
|
+
});
|
|
471
|
+
program
|
|
472
|
+
.command("kg-path <from> <to>")
|
|
473
|
+
.description("Find relationship path between two entities")
|
|
474
|
+
.action(async (from, to) => {
|
|
475
|
+
const { findPath, formatPath } = await import("./cross-agent-v2.js");
|
|
476
|
+
console.log(formatPath(findPath(from, to)));
|
|
477
|
+
});
|
|
478
|
+
// ─── Churn detection (item 2 plano Cipher simbiose 2026-06-05) ───────────────
|
|
479
|
+
program
|
|
480
|
+
.command("churn")
|
|
481
|
+
.description("Detecta re-decisões (knowledge gaps) por similaridade de embedding — read-only, $0")
|
|
482
|
+
.requiredOption("--changed-since <date>", "ISO date: só chunks criados desde essa data")
|
|
483
|
+
.option("--threshold <n>", "similaridade cosseno mínima", "0.80")
|
|
484
|
+
.option("--types <csv>", "filtro de chunk_type dos chunks novos (default: sem filtro)")
|
|
485
|
+
.option("--max-new <n>", "cap de chunks novos processados", "2000")
|
|
486
|
+
.option("--report <path>", "grava report markdown nesse path")
|
|
487
|
+
.option("--json", "output JSON em vez de markdown", false)
|
|
488
|
+
.action(async (opts) => {
|
|
489
|
+
const { detectChurn, churnReportMd } = await import("./churn.js");
|
|
490
|
+
const db = getDb();
|
|
491
|
+
const pairs = detectChurn(db, {
|
|
492
|
+
since: opts.changedSince,
|
|
493
|
+
threshold: parseFloat(opts.threshold),
|
|
494
|
+
types: opts.types ? opts.types.split(",").map((s) => s.trim()) : undefined,
|
|
495
|
+
maxNew: parseInt(opts.maxNew, 10),
|
|
496
|
+
});
|
|
497
|
+
if (opts.json)
|
|
498
|
+
console.log(JSON.stringify(pairs, null, 2));
|
|
499
|
+
else
|
|
500
|
+
console.log(churnReportMd(pairs, opts.changedSince));
|
|
501
|
+
if (opts.report) {
|
|
502
|
+
const { writeFileSync, mkdirSync } = await import("node:fs");
|
|
503
|
+
const { dirname } = await import("node:path");
|
|
504
|
+
mkdirSync(dirname(opts.report), { recursive: true });
|
|
505
|
+
writeFileSync(opts.report, churnReportMd(pairs, opts.changedSince));
|
|
506
|
+
console.log(`[CHURN] report: ${opts.report}`);
|
|
507
|
+
}
|
|
508
|
+
closeDb();
|
|
509
|
+
});
|
|
510
|
+
// ─── Session distill ──────────────────────────────────────────────────────────
|
|
511
|
+
program
|
|
512
|
+
.command("session-distill")
|
|
513
|
+
.description("Distill memories from historical agent session JSONL files")
|
|
514
|
+
.option("--agents <ids>", "Comma-separated agent ids (default: nox,forge,atlas,cipher,boris,lex)")
|
|
515
|
+
.option("--lookback-days <n>", "Days to look back (default: 30)", "30")
|
|
516
|
+
.option("--max-sessions <n>", "Max sessions per run (default: 50)", "50")
|
|
517
|
+
.option("--dry-run", "Show what would be processed without ingesting", false)
|
|
518
|
+
.action(async (opts) => {
|
|
519
|
+
const agentIds = opts.agents ? opts.agents.split(",").map((s) => s.trim()) : undefined;
|
|
520
|
+
const result = await distillSessions({
|
|
521
|
+
agentIds,
|
|
522
|
+
lookbackDays: parseInt(opts.lookbackDays, 10),
|
|
523
|
+
maxSessionsPerRun: parseInt(opts.maxSessions, 10),
|
|
524
|
+
dryRun: opts.dryRun,
|
|
525
|
+
});
|
|
526
|
+
console.log("\nSummary:");
|
|
527
|
+
console.log(` Sessions processed: ${result.processedSessions}`);
|
|
528
|
+
console.log(` Sessions skipped: ${result.skippedSessions}`);
|
|
529
|
+
console.log(` Messages read: ${result.messagesRead}`);
|
|
530
|
+
console.log(` Memories extracted: ${result.memoriesExtracted}`);
|
|
531
|
+
console.log(` Memories deduped: ${result.memoriesDeduplicated}`);
|
|
532
|
+
console.log(` Memories ingested: ${result.memoriesIngested}`);
|
|
533
|
+
closeDb();
|
|
534
|
+
});
|
|
535
|
+
// ─── Noise filter ─────────────────────────────────────────────────────────────
|
|
536
|
+
const noiseCmd = program.command("noise").description("Noise filter management");
|
|
537
|
+
noiseCmd
|
|
538
|
+
.command("stats")
|
|
539
|
+
.description("Show noise filter stats")
|
|
540
|
+
.action(() => {
|
|
541
|
+
const db = getDb();
|
|
542
|
+
const stats = getNoiseStats(db);
|
|
543
|
+
console.log("Noise filter:");
|
|
544
|
+
console.log(` Built-in prototypes: ${stats.builtin}`);
|
|
545
|
+
console.log(` Learned prototypes: ${stats.learned}`);
|
|
546
|
+
console.log(` Total hits: ${stats.totalHits}`);
|
|
547
|
+
closeDb();
|
|
548
|
+
});
|
|
549
|
+
noiseCmd
|
|
550
|
+
.command("check <text>")
|
|
551
|
+
.description("Check if a text would be filtered as noise")
|
|
552
|
+
.action((text) => {
|
|
553
|
+
const db = getDb();
|
|
554
|
+
const result = isNoise(text, db);
|
|
555
|
+
console.log(result ? `[NOISE] Would be filtered: "${text}"` : `[OK] Would pass: "${text}"`);
|
|
556
|
+
closeDb();
|
|
557
|
+
});
|
|
558
|
+
// ─── Tier management ──────────────────────────────────────────────────────────
|
|
559
|
+
const tiersCmd = program.command("tiers").description("Manage memory tiers (core/working/peripheral)");
|
|
560
|
+
tiersCmd
|
|
561
|
+
.command("stats")
|
|
562
|
+
.description("Show chunk distribution by tier")
|
|
563
|
+
.action(() => {
|
|
564
|
+
const db = getDb();
|
|
565
|
+
const stats = getTierStats(db);
|
|
566
|
+
const total = Object.values(stats).reduce((a, b) => a + b, 0) || 1;
|
|
567
|
+
console.log("Tier distribution:");
|
|
568
|
+
console.log(` 🔵 core: ${stats.core ?? 0} (${((stats.core ?? 0) / total * 100).toFixed(1)}%)`);
|
|
569
|
+
console.log(` 🟡 working: ${stats.working ?? 0} (${((stats.working ?? 0) / total * 100).toFixed(1)}%)`);
|
|
570
|
+
console.log(` ⬜ peripheral: ${stats.peripheral ?? 0} (${((stats.peripheral ?? 0) / total * 100).toFixed(1)}%)`);
|
|
571
|
+
closeDb();
|
|
572
|
+
});
|
|
573
|
+
tiersCmd
|
|
574
|
+
.command("evaluate")
|
|
575
|
+
.description("Evaluate and adjust tiers based on access patterns")
|
|
576
|
+
.action(() => {
|
|
577
|
+
const db = getDb();
|
|
578
|
+
const result = evaluateTiers(db);
|
|
579
|
+
console.log(`Tier evaluation complete:`);
|
|
580
|
+
console.log(` Promoted: ${result.promoted} chunks`);
|
|
581
|
+
console.log(` Demoted: ${result.demoted} chunks`);
|
|
582
|
+
const stats = getTierStats(db);
|
|
583
|
+
console.log(`\nCurrent distribution:`);
|
|
584
|
+
console.log(` 🔵 core: ${stats.core ?? 0}`);
|
|
585
|
+
console.log(` 🟡 working: ${stats.working ?? 0}`);
|
|
586
|
+
console.log(` ⬜ peripheral: ${stats.peripheral ?? 0}`);
|
|
587
|
+
closeDb();
|
|
588
|
+
});
|
|
589
|
+
// ─── Watch mode ───────────────────────────────────────────────────────────────
|
|
590
|
+
program
|
|
591
|
+
.command("watch")
|
|
592
|
+
.description("Watch memory directories and auto-ingest on change (real-time)")
|
|
593
|
+
.option("-v, --verbose", "Show skipped directories", false)
|
|
594
|
+
.option("--allow-prod", "Skip large-DB ingest guard (required for prod ops, see CLAUDE.md §6)")
|
|
595
|
+
.action((opts) => {
|
|
596
|
+
// audit #20 fix — Large-DB ingest guard at watcher boot. Watcher ingests via
|
|
597
|
+
// ingestFile() in a long-running loop; if it accidentally points at prod DB
|
|
598
|
+
// without explicit opt-in, abort before mutating. Override: --allow-prod or
|
|
599
|
+
// NOX_ALLOW_PROD_INGEST=1. (Watcher is INSERT-only via ingestFile so no
|
|
600
|
+
// withOpAudit wrap is needed — defense is at-boot gate, not per-write.)
|
|
601
|
+
if (opts.allowProd) {
|
|
602
|
+
process.env.NOX_ALLOW_PROD_INGEST = "1";
|
|
603
|
+
}
|
|
604
|
+
checkLargeDbIngestGuard(getDb(), "watch");
|
|
605
|
+
startWatch(opts.verbose);
|
|
606
|
+
// Keep process alive
|
|
607
|
+
process.on("SIGINT", () => {
|
|
608
|
+
console.log("\n[WATCH] Stopped.");
|
|
609
|
+
closeDb();
|
|
610
|
+
process.exit(0);
|
|
611
|
+
});
|
|
612
|
+
process.on("SIGTERM", () => {
|
|
613
|
+
closeDb();
|
|
614
|
+
process.exit(0);
|
|
615
|
+
});
|
|
616
|
+
});
|
|
617
|
+
// ─── Reflect (deep KG synthesis) ──────────────────────────────────────────────
|
|
618
|
+
program
|
|
619
|
+
.command("reflect <question>")
|
|
620
|
+
.description("Deep synthesis over memory + KG — reasons over evidence, not just retrieves")
|
|
621
|
+
.option("--no-cache", "Force fresh synthesis")
|
|
622
|
+
.action(async (question, opts) => {
|
|
623
|
+
const { reflect, formatReflect } = await import("./reflect.js");
|
|
624
|
+
const result = await reflect(question, { noCache: !opts.cache });
|
|
625
|
+
console.log(formatReflect(result));
|
|
626
|
+
});
|
|
627
|
+
// ─── Crystallize (save procedure) ─────────────────────────────────────────────
|
|
628
|
+
program
|
|
629
|
+
.command("crystallize")
|
|
630
|
+
.description("Save a multi-step procedure as a reusable skill")
|
|
631
|
+
.requiredOption("--title <title>", "Procedure title")
|
|
632
|
+
.option("--agent <agent>", "Origin agent", "system")
|
|
633
|
+
.option("--tags <tags>", "Comma-separated tags")
|
|
634
|
+
.action(async (opts) => {
|
|
635
|
+
const readline = await import("readline");
|
|
636
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
637
|
+
console.log("Enter steps (one per line, empty line to finish):");
|
|
638
|
+
const steps = [];
|
|
639
|
+
const askStep = () => new Promise((resolve) => {
|
|
640
|
+
rl.question(` Step ${steps.length + 1}: `, (line) => {
|
|
641
|
+
if (line.trim() === "") {
|
|
642
|
+
rl.close();
|
|
643
|
+
resolve();
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
steps.push(line.trim());
|
|
647
|
+
askStep().then(resolve);
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
await askStep();
|
|
651
|
+
if (steps.length === 0) {
|
|
652
|
+
console.log("No steps — aborted.");
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
const { crystallize } = await import("./crystallize.js");
|
|
656
|
+
const id = await crystallize({ title: opts.title, steps, agent: opts.agent, tags: opts.tags?.split(",").map(t => t.trim()) || [] });
|
|
657
|
+
console.log(`✅ Crystallized as chunk #${id}: "${opts.title}" (${steps.length} steps)`);
|
|
658
|
+
});
|
|
659
|
+
program
|
|
660
|
+
.command("crystallize-validate <id>")
|
|
661
|
+
.description("Record a validation run for a procedure (tracks outcome + agent + notes)")
|
|
662
|
+
.option("--outcome <outcome>", "success | failure | partial", "success")
|
|
663
|
+
.option("--agent <agent>", "Agent running the validation", "system")
|
|
664
|
+
.option("--notes <notes>", "Free-form notes about the run")
|
|
665
|
+
.action(async (id, opts) => {
|
|
666
|
+
const { validateProcedure } = await import("./crystallize.js");
|
|
667
|
+
const outcome = (["success", "failure", "partial"].includes(opts.outcome) ? opts.outcome : "success");
|
|
668
|
+
validateProcedure(parseInt(id, 10), { outcome, agent: opts.agent, notes: opts.notes });
|
|
669
|
+
console.log(`✅ Procedure #${id} validation recorded: outcome=${outcome} agent=${opts.agent}`);
|
|
670
|
+
});
|
|
671
|
+
program
|
|
672
|
+
.command("backfill-source-type")
|
|
673
|
+
.description("Backfill source_type column from source_file path patterns (98% NULL → mapped)")
|
|
674
|
+
.option("--dry-run", "Preview distribution, no mutation", false)
|
|
675
|
+
.option("--limit <n>", "Process at most N chunks")
|
|
676
|
+
.option("--batch-size <n>", "Transaction size (default 2000)")
|
|
677
|
+
.option("--force", "Overwrite existing values (preserves 'external')", false)
|
|
678
|
+
.action(async (opts) => {
|
|
679
|
+
const { backfillSourceType, formatResult } = await import("./backfill-source-type.js");
|
|
680
|
+
const result = await backfillSourceType({
|
|
681
|
+
dryRun: opts.dryRun,
|
|
682
|
+
limit: opts.limit ? parseInt(opts.limit, 10) : undefined,
|
|
683
|
+
batchSize: opts.batchSize ? parseInt(opts.batchSize, 10) : undefined,
|
|
684
|
+
force: opts.force,
|
|
685
|
+
});
|
|
686
|
+
console.log(formatResult(result));
|
|
687
|
+
closeDb();
|
|
688
|
+
});
|
|
689
|
+
program.parse();
|