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,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/cli/answer.ts — P1 T8: `nox-mem answer "<question>" [flags]`.
|
|
3
|
+
*
|
|
4
|
+
* Thin wrapper over `lib/answer/index.ts`. No business logic here;
|
|
5
|
+
* we only parse argv, invoke answer(), and render to stdout.
|
|
6
|
+
*
|
|
7
|
+
* Flags (mirrors kickoff §T8 DoD + §5 AnswerRequest):
|
|
8
|
+
* --top-k N top-K retrieval (1..20, default 8)
|
|
9
|
+
* --max-tokens N LLM output budget (default 1500)
|
|
10
|
+
* --provider X 'gemini' (default) | 'mock'
|
|
11
|
+
* --model Y override (default 'gemini-2.5-flash-lite' per D41 #1)
|
|
12
|
+
* --temperature N 0..1, default 0.2
|
|
13
|
+
* --cite include numbered citation block (default ON)
|
|
14
|
+
* --no-cite suppress citation block (markers still kept inline)
|
|
15
|
+
* --no-citations strip [chunk_N] markers from rendered answer too
|
|
16
|
+
* --json machine-readable JSON; suppresses pretty output
|
|
17
|
+
* --session-id X passthrough for telemetry correlation
|
|
18
|
+
* --help, -h print usage and exit 0
|
|
19
|
+
*
|
|
20
|
+
* Exit codes (kickoff §6 status-code parity, mapped to shell-friendly ints):
|
|
21
|
+
* 0 ok
|
|
22
|
+
* 2 invalid argv (bad flag, missing question)
|
|
23
|
+
* 3 retrieval_empty
|
|
24
|
+
* 4 hallucination_after_retry
|
|
25
|
+
* 5 llm_error / llm_timeout
|
|
26
|
+
* 1 unexpected runtime error
|
|
27
|
+
*
|
|
28
|
+
* Test seams: pass `argv`, `stdout`, `stderr`, `runAnswer`, `telemetryStore`
|
|
29
|
+
* via runCli(opts). The bin shim (`bin/answer.ts` or `src/cli/index.ts`
|
|
30
|
+
* dispatcher) calls runCli(process.argv.slice(2)) with prod defaults.
|
|
31
|
+
*/
|
|
32
|
+
import { answer as defaultAnswer, AnswerError } from "../lib/answer/index.js";
|
|
33
|
+
import { recordAnswer, } from "../lib/answer/telemetry.js";
|
|
34
|
+
export class CliArgError extends Error {
|
|
35
|
+
constructor(message) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = "CliArgError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Parse argv into ParsedArgs. Pure function — easy to unit-test. */
|
|
41
|
+
export function parseArgs(argv) {
|
|
42
|
+
const out = {
|
|
43
|
+
question: "",
|
|
44
|
+
showCitations: true,
|
|
45
|
+
stripMarkers: false,
|
|
46
|
+
json: false,
|
|
47
|
+
help: false,
|
|
48
|
+
};
|
|
49
|
+
const positionals = [];
|
|
50
|
+
for (let i = 0; i < argv.length; i++) {
|
|
51
|
+
const tok = argv[i];
|
|
52
|
+
if (tok === undefined)
|
|
53
|
+
continue;
|
|
54
|
+
switch (tok) {
|
|
55
|
+
case "-h":
|
|
56
|
+
case "--help":
|
|
57
|
+
out.help = true;
|
|
58
|
+
break;
|
|
59
|
+
case "--json":
|
|
60
|
+
out.json = true;
|
|
61
|
+
break;
|
|
62
|
+
case "--cite":
|
|
63
|
+
out.showCitations = true;
|
|
64
|
+
break;
|
|
65
|
+
case "--no-cite":
|
|
66
|
+
out.showCitations = false;
|
|
67
|
+
break;
|
|
68
|
+
case "--no-citations":
|
|
69
|
+
out.showCitations = false;
|
|
70
|
+
out.stripMarkers = true;
|
|
71
|
+
break;
|
|
72
|
+
case "--top-k":
|
|
73
|
+
case "--topk": {
|
|
74
|
+
const v = argv[++i];
|
|
75
|
+
if (v === undefined)
|
|
76
|
+
throw new CliArgError(`${tok} requires a value`);
|
|
77
|
+
const n = parseInt(v, 10);
|
|
78
|
+
if (!Number.isFinite(n)) {
|
|
79
|
+
throw new CliArgError(`${tok} must be an integer, got '${v}'`);
|
|
80
|
+
}
|
|
81
|
+
out.topK = n;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case "--max-tokens": {
|
|
85
|
+
const v = argv[++i];
|
|
86
|
+
if (v === undefined)
|
|
87
|
+
throw new CliArgError(`${tok} requires a value`);
|
|
88
|
+
const n = parseInt(v, 10);
|
|
89
|
+
if (!Number.isFinite(n)) {
|
|
90
|
+
throw new CliArgError(`${tok} must be an integer, got '${v}'`);
|
|
91
|
+
}
|
|
92
|
+
out.maxTokens = n;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case "--provider": {
|
|
96
|
+
const v = argv[++i];
|
|
97
|
+
if (v === undefined)
|
|
98
|
+
throw new CliArgError(`${tok} requires a value`);
|
|
99
|
+
out.provider = v;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case "--model": {
|
|
103
|
+
const v = argv[++i];
|
|
104
|
+
if (v === undefined)
|
|
105
|
+
throw new CliArgError(`${tok} requires a value`);
|
|
106
|
+
out.model = v;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case "--temperature":
|
|
110
|
+
case "--temp": {
|
|
111
|
+
const v = argv[++i];
|
|
112
|
+
if (v === undefined)
|
|
113
|
+
throw new CliArgError(`${tok} requires a value`);
|
|
114
|
+
const n = parseFloat(v);
|
|
115
|
+
if (!Number.isFinite(n)) {
|
|
116
|
+
throw new CliArgError(`${tok} must be a number, got '${v}'`);
|
|
117
|
+
}
|
|
118
|
+
out.temperature = n;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
case "--session-id": {
|
|
122
|
+
const v = argv[++i];
|
|
123
|
+
if (v === undefined)
|
|
124
|
+
throw new CliArgError(`${tok} requires a value`);
|
|
125
|
+
out.sessionId = v;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
default:
|
|
129
|
+
if (tok.startsWith("--") || (tok.startsWith("-") && tok.length > 1)) {
|
|
130
|
+
throw new CliArgError(`unknown flag: ${tok}`);
|
|
131
|
+
}
|
|
132
|
+
positionals.push(tok);
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (out.help)
|
|
137
|
+
return out;
|
|
138
|
+
if (positionals.length === 0) {
|
|
139
|
+
throw new CliArgError("missing required <question> positional");
|
|
140
|
+
}
|
|
141
|
+
out.question = positionals.join(" ");
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
// ─── Help text ────────────────────────────────────────────────────────────
|
|
145
|
+
export const HELP_TEXT = `nox-mem answer — answer questions from nox-mem corpus with grounded citations.
|
|
146
|
+
|
|
147
|
+
Usage:
|
|
148
|
+
nox-mem answer "<question>" [flags]
|
|
149
|
+
|
|
150
|
+
Flags:
|
|
151
|
+
--top-k N top-K retrieval (1..20, default 8)
|
|
152
|
+
--max-tokens N max LLM output tokens (64..8192, default 1500)
|
|
153
|
+
--provider X 'gemini' (default) | 'mock'
|
|
154
|
+
--model Y model id (default gemini-2.5-flash-lite per D41 #1)
|
|
155
|
+
--temperature N 0..1, default 0.2
|
|
156
|
+
--cite include numbered citation block (default)
|
|
157
|
+
--no-cite suppress citation block
|
|
158
|
+
--no-citations also strip [chunk_N] markers from answer text
|
|
159
|
+
--json emit AnswerResponse JSON to stdout
|
|
160
|
+
--session-id X correlation tag (telemetry only)
|
|
161
|
+
-h, --help show this help and exit
|
|
162
|
+
|
|
163
|
+
Examples:
|
|
164
|
+
nox-mem answer "What is the salience formula?"
|
|
165
|
+
nox-mem answer "Which retention default for lessons?" --top-k 12 --json
|
|
166
|
+
NOX_ANSWER_MODEL=gemini-2.5-flash nox-mem answer "Provider swap test"
|
|
167
|
+
|
|
168
|
+
Exit codes: 0 ok | 2 bad argv | 3 retrieval_empty | 4 hallucination_after_retry | 5 llm_error
|
|
169
|
+
`;
|
|
170
|
+
// ─── Renderer ─────────────────────────────────────────────────────────────
|
|
171
|
+
const MARKER_RE = /\s?\[chunk_\d+\]/g;
|
|
172
|
+
export function renderHuman(res, args) {
|
|
173
|
+
const body = args.stripMarkers ? res.answer.replace(MARKER_RE, "") : res.answer;
|
|
174
|
+
const parts = [body.trimEnd()];
|
|
175
|
+
if (args.showCitations && res.citations.length > 0) {
|
|
176
|
+
parts.push("", "Citations:");
|
|
177
|
+
for (const c of res.citations) {
|
|
178
|
+
const range = c.line_range ? ` ${c.line_range}` : "";
|
|
179
|
+
parts.push(` [${c.marker_id}] ${c.file_path}${range}`);
|
|
180
|
+
parts.push(` ${c.snippet}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
parts.push("", `(model=${res.metadata.model} latency=${res.metadata.latency_ms}ms ` +
|
|
184
|
+
`retrieved=${res.metadata.retrieval_count} cited=${res.citations.length})`);
|
|
185
|
+
return parts.join("\n");
|
|
186
|
+
}
|
|
187
|
+
export function renderJson(res, args) {
|
|
188
|
+
const body = args.stripMarkers ? res.answer.replace(MARKER_RE, "") : res.answer;
|
|
189
|
+
const obj = {
|
|
190
|
+
answer: body,
|
|
191
|
+
citations: res.citations,
|
|
192
|
+
metadata: res.metadata,
|
|
193
|
+
};
|
|
194
|
+
return JSON.stringify(obj);
|
|
195
|
+
}
|
|
196
|
+
export async function runCli(opts) {
|
|
197
|
+
let parsed;
|
|
198
|
+
try {
|
|
199
|
+
parsed = parseArgs(opts.argv);
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
if (err instanceof CliArgError) {
|
|
203
|
+
opts.stderr(`error: ${err.message}\n${HELP_TEXT}`);
|
|
204
|
+
return 2;
|
|
205
|
+
}
|
|
206
|
+
opts.stderr(`unexpected argv error: ${err.message}`);
|
|
207
|
+
return 1;
|
|
208
|
+
}
|
|
209
|
+
if (parsed.help) {
|
|
210
|
+
opts.stdout(HELP_TEXT);
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
const callOpts = { question: parsed.question };
|
|
214
|
+
if (parsed.topK !== undefined)
|
|
215
|
+
callOpts.topK = parsed.topK;
|
|
216
|
+
if (parsed.maxTokens !== undefined)
|
|
217
|
+
callOpts.maxTokens = parsed.maxTokens;
|
|
218
|
+
if (parsed.provider !== undefined)
|
|
219
|
+
callOpts.provider = parsed.provider;
|
|
220
|
+
if (parsed.model !== undefined)
|
|
221
|
+
callOpts.model = parsed.model;
|
|
222
|
+
if (parsed.temperature !== undefined)
|
|
223
|
+
callOpts.temperature = parsed.temperature;
|
|
224
|
+
const run = opts.runAnswer ?? defaultAnswer;
|
|
225
|
+
try {
|
|
226
|
+
const res = await run(callOpts);
|
|
227
|
+
if (opts.telemetryStore) {
|
|
228
|
+
recordAnswer(opts.telemetryStore, {
|
|
229
|
+
question: parsed.question,
|
|
230
|
+
citationCount: res.citations.length,
|
|
231
|
+
metadata: res.metadata,
|
|
232
|
+
sessionId: parsed.sessionId ?? null,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
opts.stdout(parsed.json ? renderJson(res, parsed) : renderHuman(res, parsed));
|
|
236
|
+
// retrieval_empty surfaces via failed_reason on metadata; map to exit 3.
|
|
237
|
+
if (res.metadata.failed_reason === "retrieval_empty")
|
|
238
|
+
return 3;
|
|
239
|
+
return 0;
|
|
240
|
+
}
|
|
241
|
+
catch (err) {
|
|
242
|
+
if (err instanceof AnswerError) {
|
|
243
|
+
if (opts.telemetryStore) {
|
|
244
|
+
recordAnswer(opts.telemetryStore, {
|
|
245
|
+
question: parsed.question,
|
|
246
|
+
citationCount: 0,
|
|
247
|
+
metadata: {
|
|
248
|
+
latency_ms: err.metadata.latency_ms ?? 0,
|
|
249
|
+
tokens_in: err.metadata.tokens_in ?? 0,
|
|
250
|
+
tokens_out: err.metadata.tokens_out ?? 0,
|
|
251
|
+
provider: err.metadata.provider ?? "n/a",
|
|
252
|
+
model: err.metadata.model ?? "n/a",
|
|
253
|
+
retrieval_count: err.metadata.retrieval_count ?? 0,
|
|
254
|
+
fallback_used: err.metadata.fallback_used ?? false,
|
|
255
|
+
failed_reason: err.reason,
|
|
256
|
+
},
|
|
257
|
+
sessionId: parsed.sessionId ?? null,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
const payload = parsed.json
|
|
261
|
+
? JSON.stringify({
|
|
262
|
+
error: true,
|
|
263
|
+
reason: err.reason,
|
|
264
|
+
message: err.message,
|
|
265
|
+
metadata: err.metadata,
|
|
266
|
+
})
|
|
267
|
+
: `error: ${err.message} (${err.reason})`;
|
|
268
|
+
opts.stderr(payload);
|
|
269
|
+
switch (err.reason) {
|
|
270
|
+
case "retrieval_empty":
|
|
271
|
+
return 3;
|
|
272
|
+
case "hallucination_after_retry":
|
|
273
|
+
case "hallucinated_citation":
|
|
274
|
+
return 4;
|
|
275
|
+
case "llm_error":
|
|
276
|
+
case "llm_timeout":
|
|
277
|
+
return 5;
|
|
278
|
+
case "invalid_input":
|
|
279
|
+
return 2;
|
|
280
|
+
default:
|
|
281
|
+
return 1;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
opts.stderr(`unexpected: ${err.message}`);
|
|
285
|
+
return 1;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 T7 — CLI subcommands.
|
|
3
|
+
*
|
|
4
|
+
* Top-level: `nox-mem conflict <action>`. Actions:
|
|
5
|
+
* - scan runs detector + audit-writer; prints summary
|
|
6
|
+
* - list [--status ...] lists audit rows
|
|
7
|
+
* - show <id> prints one row + evidence
|
|
8
|
+
* - resolve <id> --pick <relation_id>
|
|
9
|
+
* - resolve <id> --merge "<new_target>"
|
|
10
|
+
* - resolve <id> --dismiss [--notes "..."]
|
|
11
|
+
*
|
|
12
|
+
* Output formats:
|
|
13
|
+
* - default: human-friendly table-ish
|
|
14
|
+
* - --json: machine-readable
|
|
15
|
+
*
|
|
16
|
+
* Implementation: pure functions that take a DBHandle + parsed argv.
|
|
17
|
+
* The runtime entrypoint (`dist/index.js` in production) wires these to
|
|
18
|
+
* the singleton sqlite handle. Tests pass FakeDB.
|
|
19
|
+
*/
|
|
20
|
+
import type { DBHandle } from "../lib/conflict/db.js";
|
|
21
|
+
export interface CliResult {
|
|
22
|
+
/** Exit code. 0 = success, 1 = usage error, 2 = runtime error. */
|
|
23
|
+
code: number;
|
|
24
|
+
/** Lines to print to stdout (newline-joined). */
|
|
25
|
+
stdout: string[];
|
|
26
|
+
/** Lines to print to stderr. */
|
|
27
|
+
stderr: string[];
|
|
28
|
+
/** Machine-readable result (when --json). */
|
|
29
|
+
json?: unknown;
|
|
30
|
+
}
|
|
31
|
+
export interface CliEnv {
|
|
32
|
+
/** Override resolveMode() — primarily for tests. */
|
|
33
|
+
mode_override?: string;
|
|
34
|
+
/** ISO actor id (e.g. user name) for resolve writes. */
|
|
35
|
+
actor?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Entry point — dispatch on action verb. */
|
|
38
|
+
export declare function runConflictCli(db: DBHandle, argv: readonly string[], env?: CliEnv): CliResult;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 T7 — CLI subcommands.
|
|
3
|
+
*
|
|
4
|
+
* Top-level: `nox-mem conflict <action>`. Actions:
|
|
5
|
+
* - scan runs detector + audit-writer; prints summary
|
|
6
|
+
* - list [--status ...] lists audit rows
|
|
7
|
+
* - show <id> prints one row + evidence
|
|
8
|
+
* - resolve <id> --pick <relation_id>
|
|
9
|
+
* - resolve <id> --merge "<new_target>"
|
|
10
|
+
* - resolve <id> --dismiss [--notes "..."]
|
|
11
|
+
*
|
|
12
|
+
* Output formats:
|
|
13
|
+
* - default: human-friendly table-ish
|
|
14
|
+
* - --json: machine-readable
|
|
15
|
+
*
|
|
16
|
+
* Implementation: pure functions that take a DBHandle + parsed argv.
|
|
17
|
+
* The runtime entrypoint (`dist/index.js` in production) wires these to
|
|
18
|
+
* the singleton sqlite handle. Tests pass FakeDB.
|
|
19
|
+
*/
|
|
20
|
+
import { updateConflictStatus, getConflictById, listConflicts, } from "../lib/conflict/audit-writer.js";
|
|
21
|
+
import { collectEvidence } from "../lib/conflict/evidence.js";
|
|
22
|
+
import { resolveMode, runConflictPass } from "../lib/conflict/shadow.js";
|
|
23
|
+
/** Entry point — dispatch on action verb. */
|
|
24
|
+
export function runConflictCli(db, argv, env = {}) {
|
|
25
|
+
const [action, ...rest] = argv;
|
|
26
|
+
switch (action) {
|
|
27
|
+
case "scan":
|
|
28
|
+
return cmdScan(db, rest, env);
|
|
29
|
+
case "list":
|
|
30
|
+
return cmdList(db, rest, env);
|
|
31
|
+
case "show":
|
|
32
|
+
return cmdShow(db, rest);
|
|
33
|
+
case "resolve":
|
|
34
|
+
return cmdResolve(db, rest, env);
|
|
35
|
+
case undefined:
|
|
36
|
+
case "":
|
|
37
|
+
return { code: 1, stdout: [], stderr: [usage()] };
|
|
38
|
+
default:
|
|
39
|
+
return {
|
|
40
|
+
code: 1,
|
|
41
|
+
stdout: [],
|
|
42
|
+
stderr: [`unknown action: ${action}`, usage()],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function usage() {
|
|
47
|
+
return [
|
|
48
|
+
"nox-mem conflict <action> [options]",
|
|
49
|
+
" scan run detector pass + record audit rows",
|
|
50
|
+
" list [--status <s>] [--limit N] list audit rows (default status=open)",
|
|
51
|
+
" show <id> show one row + evidence",
|
|
52
|
+
" resolve <id> --pick <relation_id> mark as resolved_pick_one",
|
|
53
|
+
" resolve <id> --merge \"<target>\" mark as resolved_merged",
|
|
54
|
+
" resolve <id> --dismiss mark as dismissed",
|
|
55
|
+
" [--notes \"...\"] attach analyst note",
|
|
56
|
+
" [--json] machine-readable output",
|
|
57
|
+
" [--min-confidence 0.5] scan threshold",
|
|
58
|
+
" [--predicate ...] (repeatable) restrict scan to predicate(s)",
|
|
59
|
+
].join("\n");
|
|
60
|
+
}
|
|
61
|
+
// ─── scan ────────────────────────────────────────────────────────────────────
|
|
62
|
+
function cmdScan(db, args, env) {
|
|
63
|
+
const opts = parseArgs(args);
|
|
64
|
+
if (opts.error)
|
|
65
|
+
return { code: 1, stdout: [], stderr: [opts.error] };
|
|
66
|
+
const mode = resolveMode(env.mode_override);
|
|
67
|
+
// CLI scan must work even in 'disabled' mode — operator opt-in by explicit
|
|
68
|
+
// CLI call counts as run-once. We bypass the env gate by forcing shadow.
|
|
69
|
+
const effectiveMode = mode === "disabled" ? "shadow" : mode;
|
|
70
|
+
const result = runConflictPass(db, {
|
|
71
|
+
min_confidence: opts.minConfidence,
|
|
72
|
+
predicate_allowlist: opts.predicates.length > 0 ? opts.predicates : undefined,
|
|
73
|
+
}, effectiveMode);
|
|
74
|
+
if (opts.json) {
|
|
75
|
+
return { code: 0, stdout: [JSON.stringify(result)], stderr: [], json: result };
|
|
76
|
+
}
|
|
77
|
+
const out = [
|
|
78
|
+
`mode: ${result.mode}`,
|
|
79
|
+
`scanned_at: ${new Date(result.scanned_at).toISOString()}`,
|
|
80
|
+
`detected: ${result.detected}`,
|
|
81
|
+
`recorded: ${result.recorded}`,
|
|
82
|
+
`deduplicated: ${result.deduplicated}`,
|
|
83
|
+
];
|
|
84
|
+
if (result.audit_ids.length > 0) {
|
|
85
|
+
out.push(`new audit ids: ${result.audit_ids.join(", ")}`);
|
|
86
|
+
}
|
|
87
|
+
return { code: 0, stdout: out, stderr: [], json: result };
|
|
88
|
+
}
|
|
89
|
+
// ─── list ────────────────────────────────────────────────────────────────────
|
|
90
|
+
function cmdList(db, args, _env) {
|
|
91
|
+
const opts = parseArgs(args);
|
|
92
|
+
if (opts.error)
|
|
93
|
+
return { code: 1, stdout: [], stderr: [opts.error] };
|
|
94
|
+
const status = (opts.status ?? "open");
|
|
95
|
+
const rows = listConflicts(db, status, opts.limit ?? 20);
|
|
96
|
+
if (opts.json) {
|
|
97
|
+
return { code: 0, stdout: [JSON.stringify(rows)], stderr: [], json: rows };
|
|
98
|
+
}
|
|
99
|
+
const out = [];
|
|
100
|
+
out.push(`status=${status} rows=${rows.length}`);
|
|
101
|
+
for (const r of rows) {
|
|
102
|
+
out.push(` [${r.id}] ${r.kind} subject=${r.subject_entity_id} predicate=${r.predicate} relations=[${r.target_relation_ids.join(",")}] shadow=${r.shadow_mode}`);
|
|
103
|
+
}
|
|
104
|
+
return { code: 0, stdout: out, stderr: [], json: rows };
|
|
105
|
+
}
|
|
106
|
+
// ─── show ────────────────────────────────────────────────────────────────────
|
|
107
|
+
function cmdShow(db, args) {
|
|
108
|
+
const idStr = args[0];
|
|
109
|
+
if (!idStr)
|
|
110
|
+
return { code: 1, stdout: [], stderr: ["show: missing <id>"] };
|
|
111
|
+
const id = Number(idStr);
|
|
112
|
+
if (!Number.isFinite(id) || id <= 0) {
|
|
113
|
+
return { code: 1, stdout: [], stderr: ["show: invalid <id>"] };
|
|
114
|
+
}
|
|
115
|
+
const json = args.includes("--json");
|
|
116
|
+
const row = getConflictById(db, id);
|
|
117
|
+
if (!row) {
|
|
118
|
+
return { code: 2, stdout: [], stderr: [`conflict ${id} not found`] };
|
|
119
|
+
}
|
|
120
|
+
// Reconstruct a Conflict shape from the audit row to drive collectEvidence().
|
|
121
|
+
const conflict = {
|
|
122
|
+
kind: row.kind,
|
|
123
|
+
subject_entity_id: row.subject_entity_id,
|
|
124
|
+
predicate: row.predicate,
|
|
125
|
+
variants: row.variants,
|
|
126
|
+
};
|
|
127
|
+
const evidence = collectEvidence(db, conflict);
|
|
128
|
+
if (json) {
|
|
129
|
+
const payload = { row, evidence };
|
|
130
|
+
return { code: 0, stdout: [JSON.stringify(payload)], stderr: [], json: payload };
|
|
131
|
+
}
|
|
132
|
+
const out = [];
|
|
133
|
+
out.push(`conflict ${row.id} kind=${row.kind} status=${row.status} shadow=${row.shadow_mode}`);
|
|
134
|
+
out.push(`subject_entity_id=${row.subject_entity_id} predicate=${row.predicate}`);
|
|
135
|
+
out.push(`target_relation_ids: ${row.target_relation_ids.join(", ")}`);
|
|
136
|
+
if (row.notes)
|
|
137
|
+
out.push(`notes: ${row.notes}`);
|
|
138
|
+
out.push("variants:");
|
|
139
|
+
for (const ve of evidence.variants) {
|
|
140
|
+
out.push(` rel ${ve.variant.relation_id} → target ${ve.variant.target_entity_id} conf=${ve.variant.confidence.toFixed(2)} method=${ve.variant.extraction_method ?? "n/a"} weight=${ve.weighted_score.toFixed(2)}`);
|
|
141
|
+
for (const c of ve.chunks) {
|
|
142
|
+
out.push(` chunk ${c.chunk_id}: ${c.snippet}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return { code: 0, stdout: out, stderr: [], json: { row, evidence } };
|
|
146
|
+
}
|
|
147
|
+
// ─── resolve ─────────────────────────────────────────────────────────────────
|
|
148
|
+
function cmdResolve(db, args, env) {
|
|
149
|
+
const idStr = args[0];
|
|
150
|
+
if (!idStr)
|
|
151
|
+
return { code: 1, stdout: [], stderr: ["resolve: missing <id>"] };
|
|
152
|
+
const id = Number(idStr);
|
|
153
|
+
if (!Number.isFinite(id) || id <= 0) {
|
|
154
|
+
return { code: 1, stdout: [], stderr: ["resolve: invalid <id>"] };
|
|
155
|
+
}
|
|
156
|
+
const opts = parseArgs(args.slice(1));
|
|
157
|
+
if (opts.error)
|
|
158
|
+
return { code: 1, stdout: [], stderr: [opts.error] };
|
|
159
|
+
const actor = env.actor ?? "cli-user";
|
|
160
|
+
let resolution;
|
|
161
|
+
if (opts.pick != null) {
|
|
162
|
+
resolution = {
|
|
163
|
+
status: "resolved_pick_one",
|
|
164
|
+
resolved_by: actor,
|
|
165
|
+
resolution_kind: "pick_one",
|
|
166
|
+
picked_relation_id: opts.pick,
|
|
167
|
+
notes: opts.notes,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
else if (opts.merge != null) {
|
|
171
|
+
resolution = {
|
|
172
|
+
status: "resolved_merged",
|
|
173
|
+
resolved_by: actor,
|
|
174
|
+
resolution_kind: "merged",
|
|
175
|
+
merge_target: opts.merge,
|
|
176
|
+
notes: opts.notes,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
else if (opts.dismiss) {
|
|
180
|
+
resolution = {
|
|
181
|
+
status: "dismissed",
|
|
182
|
+
resolved_by: actor,
|
|
183
|
+
resolution_kind: "dismissed",
|
|
184
|
+
notes: opts.notes,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
else if (opts.bothValid) {
|
|
188
|
+
resolution = {
|
|
189
|
+
status: "resolved_both_valid",
|
|
190
|
+
resolved_by: actor,
|
|
191
|
+
resolution_kind: "both_valid",
|
|
192
|
+
notes: opts.notes,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
return {
|
|
197
|
+
code: 1,
|
|
198
|
+
stdout: [],
|
|
199
|
+
stderr: ["resolve: one of --pick, --merge, --dismiss, --both-valid required"],
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
updateConflictStatus(db, id, resolution);
|
|
204
|
+
}
|
|
205
|
+
catch (err) {
|
|
206
|
+
return {
|
|
207
|
+
code: 2,
|
|
208
|
+
stdout: [],
|
|
209
|
+
stderr: [`resolve failed: ${err.message}`],
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const row = getConflictById(db, id);
|
|
213
|
+
if (opts.json) {
|
|
214
|
+
return { code: 0, stdout: [JSON.stringify(row)], stderr: [], json: row };
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
code: 0,
|
|
218
|
+
stdout: [`conflict ${id} → ${resolution.status} (by ${actor})`],
|
|
219
|
+
stderr: [],
|
|
220
|
+
json: row,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function parseArgs(args) {
|
|
224
|
+
const out = { predicates: [], dismiss: false, bothValid: false, json: false };
|
|
225
|
+
for (let i = 0; i < args.length; i++) {
|
|
226
|
+
const a = args[i];
|
|
227
|
+
switch (a) {
|
|
228
|
+
case "--status":
|
|
229
|
+
out.status = args[++i];
|
|
230
|
+
break;
|
|
231
|
+
case "--limit": {
|
|
232
|
+
const n = Number(args[++i]);
|
|
233
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
234
|
+
out.error = `invalid --limit: ${args[i]}`;
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
out.limit = n;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case "--min-confidence": {
|
|
241
|
+
const n = Number(args[++i]);
|
|
242
|
+
if (!Number.isFinite(n) || n < 0 || n > 1) {
|
|
243
|
+
out.error = `invalid --min-confidence: ${args[i]}`;
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
out.minConfidence = n;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
case "--predicate":
|
|
250
|
+
out.predicates.push(args[++i] ?? "");
|
|
251
|
+
break;
|
|
252
|
+
case "--pick": {
|
|
253
|
+
const n = Number(args[++i]);
|
|
254
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
255
|
+
out.error = `invalid --pick: ${args[i]}`;
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
258
|
+
out.pick = n;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case "--merge":
|
|
262
|
+
out.merge = args[++i];
|
|
263
|
+
break;
|
|
264
|
+
case "--dismiss":
|
|
265
|
+
out.dismiss = true;
|
|
266
|
+
break;
|
|
267
|
+
case "--both-valid":
|
|
268
|
+
out.bothValid = true;
|
|
269
|
+
break;
|
|
270
|
+
case "--notes":
|
|
271
|
+
out.notes = args[++i];
|
|
272
|
+
break;
|
|
273
|
+
case "--json":
|
|
274
|
+
out.json = true;
|
|
275
|
+
break;
|
|
276
|
+
default:
|
|
277
|
+
// ignore positional args (handled by callers)
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return out;
|
|
282
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A2.1 T4 — CLI `nox-mem export` patched with passphrase entropy enforcement.
|
|
3
|
+
*
|
|
4
|
+
* Diff vs staged-A2 `src/cli/export.ts`:
|
|
5
|
+
* 1) New CLI flag `--allow-weak` (boolean) — explicit opt-out for weak pass.
|
|
6
|
+
* 2) After resolving passphrase, call `enforcePassphraseStrength()`.
|
|
7
|
+
* 3) On WeakPassphraseError default-deny path: emit strength meter on
|
|
8
|
+
* stderr AND error message, exit code 2 (user-correctable).
|
|
9
|
+
* 4) On --allow-weak / NOX_A2_ALLOW_WEAK_PASSPHRASE=1 bypass: emit meter +
|
|
10
|
+
* one-line warn, continue with the weak passphrase.
|
|
11
|
+
* 5) `--unencrypted` path unchanged (no entropy check, since no key derived).
|
|
12
|
+
*
|
|
13
|
+
* Strength meter is rendered via `renderStrengthMeter()` from strength.ts —
|
|
14
|
+
* printed to stderr so stdout (archivePath) stays machine-parseable.
|
|
15
|
+
*
|
|
16
|
+
* Threat-model ref: docs/security/THREAT-MODEL.md §5.2 T-A2-1 / Gap G1.
|
|
17
|
+
*/
|
|
18
|
+
import { ExportRequest } from "../lib/archive/orchestrator.js";
|
|
19
|
+
export interface CliExportArgs {
|
|
20
|
+
out?: string;
|
|
21
|
+
unencrypted?: boolean;
|
|
22
|
+
passphraseEnv?: string;
|
|
23
|
+
project?: string;
|
|
24
|
+
since?: string;
|
|
25
|
+
until?: string;
|
|
26
|
+
excludeEmbeddings?: boolean;
|
|
27
|
+
ackUnencrypted?: boolean;
|
|
28
|
+
/** A2.1 — explicit consent to bypass entropy enforcement. */
|
|
29
|
+
allowWeak?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** Pure argv parser. Throws on `--passphrase` flag (security hard rule). */
|
|
32
|
+
export declare function parseExportArgs(argv: string[]): CliExportArgs;
|
|
33
|
+
export interface RunCliExportDeps {
|
|
34
|
+
dbReader: () => Promise<Omit<ExportRequest, "passphrase" | "unencrypted" | "signal" | "onProgress">>;
|
|
35
|
+
writeArchive?: (path: string, buf: Buffer) => Promise<void>;
|
|
36
|
+
promptPassphrase?: () => Promise<string>;
|
|
37
|
+
env?: NodeJS.ProcessEnv;
|
|
38
|
+
log?: (msg: string) => void;
|
|
39
|
+
/** Separate stderr sink for the strength meter so machine parsers ignore. */
|
|
40
|
+
logErr?: (msg: string) => void;
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
isTTY?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface CliExportOutcome {
|
|
45
|
+
exitCode: number;
|
|
46
|
+
archivePath?: string;
|
|
47
|
+
manifest?: import("../lib/archive/types.js").ManifestV1;
|
|
48
|
+
bytes?: number;
|
|
49
|
+
duration_ms?: number;
|
|
50
|
+
}
|
|
51
|
+
export declare function runCliExport(argv: string[], deps: RunCliExportDeps): Promise<CliExportOutcome>;
|