nox-mem 3.1.0 → 3.2.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/README.md +24 -16
- package/dist/__tests__/brief-diversity.test.js +266 -0
- package/dist/__tests__/brief.test.js +287 -0
- package/dist/__tests__/churn.test.js +66 -0
- package/dist/__tests__/edge-typing.test.js +99 -0
- package/dist/__tests__/ingest-event.test.js +151 -0
- package/dist/__tests__/op-audit-e2e.test.js +130 -0
- package/dist/__tests__/pragma-alignment.test.js +123 -0
- package/dist/__tests__/reranker.test.js +326 -0
- package/dist/__tests__/retention.test.js +99 -0
- package/dist/__tests__/search-track-access.test.js +49 -0
- package/dist/__tests__/spo-injection.test.js +172 -0
- package/dist/__tests__/temporal-detector.test.js +103 -0
- package/dist/api/wire-up.js +12 -381
- package/dist/api-server.js +6 -102
- package/dist/db.js +61 -2
- package/dist/embed.js +23 -2
- package/dist/index.js +3 -23
- package/dist/knowledge-graph.js +20 -0
- package/dist/lib/answer/__tests__/e2e-gemini.test.js +229 -0
- package/dist/lib/answer/__tests__/integration-sqlite.test.js +388 -0
- package/dist/lib/answer/__tests__/integration.test.js +347 -0
- package/dist/lib/answer/__tests__/prompt.test.js +117 -0
- package/dist/lib/answer/__tests__/t5-t10.test.js +501 -0
- package/dist/lib/answer/provider.js +29 -4
- package/dist/lib/api/__tests__/safe-error-message.test.js +155 -0
- package/dist/lib/auth/__tests__/localhost-guard.test.js +144 -0
- package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +354 -0
- package/dist/lib/events/__tests__/bus.test.js +208 -0
- package/dist/lib/ingest-router.js +0 -43
- package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +109 -0
- package/dist/lib/regex-extract/__tests__/extractor.test.js +197 -0
- package/dist/lib/regex-extract/__tests__/frontmatter.test.js +75 -0
- package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +139 -0
- package/dist/lib/regex-extract/__tests__/production-wire.test.js +177 -0
- package/dist/lib/regex-extract/__tests__/reconcile.test.js +170 -0
- package/dist/lib/regex-extract/__tests__/strip-code.test.js +36 -0
- package/dist/mcp-server.js +2 -1
- package/dist/privacy/__tests__/filter.test.js +352 -0
- package/dist/providers/__tests__/conformance-extended.test.js +249 -0
- package/dist/providers/__tests__/conformance.test.js +98 -0
- package/dist/providers/__tests__/cost-cap.test.js +151 -0
- package/dist/providers/__tests__/e2e-real.test.js +79 -0
- package/dist/providers/__tests__/factory.test.js +80 -0
- package/dist/providers/__tests__/fallback.test.js +223 -0
- package/dist/providers/__tests__/gemini.test.js +191 -0
- package/dist/providers/__tests__/health.test.js +128 -0
- package/dist/providers/__tests__/telemetry.test.js +219 -0
- package/dist/reindex.js +2 -2
- package/dist/version.js +22 -0
- package/package.json +3 -4
- package/dist/api/answer.d.ts +0 -116
- package/dist/api/answer.validate-patch.d.ts +0 -72
- package/dist/api/brief-diversity.d.ts +0 -64
- package/dist/api/brief.d.ts +0 -114
- package/dist/api/conflict.d.ts +0 -33
- package/dist/api/conflict.js +0 -143
- package/dist/api/cors.d.ts +0 -73
- package/dist/api/events-stream-limited.d.ts +0 -133
- package/dist/api/events-stream-limited.js +0 -217
- package/dist/api/events-stream.d.ts +0 -53
- package/dist/api/events-stream.js +0 -125
- package/dist/api/export.d.ts +0 -42
- package/dist/api/export.js +0 -85
- package/dist/api/health-confidence-adapter.d.ts +0 -29
- package/dist/api/health-confidence-adapter.js +0 -73
- package/dist/api/health-confidence.d.ts +0 -36
- package/dist/api/health-confidence.js +0 -141
- package/dist/api/hooks.d.ts +0 -50
- package/dist/api/hooks.js +0 -115
- package/dist/api/import.d.ts +0 -38
- package/dist/api/import.js +0 -87
- package/dist/api/ingest-event.d.ts +0 -65
- package/dist/api/mark.d.ts +0 -42
- package/dist/api/mark.js +0 -127
- package/dist/api/server-deps-a2.d.ts +0 -55
- package/dist/api/server-deps-a2.js +0 -138
- package/dist/api/server-deps-l2-l3.d.ts +0 -68
- package/dist/api/server-deps-l2-l3.js +0 -123
- package/dist/api/server-deps-p1.d.ts +0 -84
- package/dist/api/server-deps-p2.d.ts +0 -32
- package/dist/api/server-deps-p2.js +0 -84
- package/dist/api/server-deps-p5.d.ts +0 -66
- package/dist/api/server-deps-p5.js +0 -139
- package/dist/api/viewer-static.d.ts +0 -30
- package/dist/api/viewer-static.js +0 -102
- package/dist/api/wire-up.d.ts +0 -54
- package/dist/api-impact.d.ts +0 -30
- package/dist/api-server.d.ts +0 -2
- package/dist/backfill-fts-anchor.d.ts +0 -15
- package/dist/backfill-source-type.d.ts +0 -20
- package/dist/churn.d.ts +0 -31
- package/dist/cli/answer.d.ts +0 -66
- package/dist/cli/conflict.d.ts +0 -38
- package/dist/cli/conflict.js +0 -282
- package/dist/cli/export.d.ts +0 -51
- package/dist/cli/export.js +0 -280
- package/dist/cli/hooks.d.ts +0 -54
- package/dist/cli/hooks.js +0 -133
- package/dist/cli/import.d.ts +0 -52
- package/dist/cli/import.js +0 -274
- package/dist/cli/mark.d.ts +0 -33
- package/dist/cli/mark.js +0 -130
- package/dist/cli/ocr-batch.d.ts +0 -12
- package/dist/cli/ocr-batch.js +0 -411
- package/dist/cli/snapshot-main.d.ts +0 -30
- package/dist/cli/snapshot-main.js +0 -47
- package/dist/cli/viewer.d.ts +0 -35
- package/dist/cli/viewer.js +0 -71
- package/dist/cli-telemetry.d.ts +0 -36
- package/dist/cli-telemetry.js +0 -150
- package/dist/compact.d.ts +0 -7
- package/dist/consolidate.d.ts +0 -18
- package/dist/consolidation.d.ts +0 -32
- package/dist/cross-agent-v2.d.ts +0 -45
- package/dist/cross-search.d.ts +0 -11
- package/dist/crystallize.d.ts +0 -43
- package/dist/db.d.ts +0 -11
- package/dist/dedup.d.ts +0 -1
- package/dist/detect-changes.d.ts +0 -29
- package/dist/digest.d.ts +0 -1
- package/dist/doctor.d.ts +0 -1
- package/dist/embed.d.ts +0 -57
- package/dist/evals.d.ts +0 -176
- package/dist/evals.js +0 -351
- package/dist/generate-user-profile.d.ts +0 -18
- package/dist/graphify-ingest.d.ts +0 -18
- package/dist/impact.d.ts +0 -39
- package/dist/index.d.ts +0 -2
- package/dist/ingest-entity.d.ts +0 -44
- package/dist/ingest.d.ts +0 -13
- package/dist/kg-llm.d.ts +0 -39
- package/dist/knowledge-graph.d.ts +0 -72
- package/dist/lib/answer/config.d.ts +0 -41
- package/dist/lib/answer/index.d.ts +0 -47
- package/dist/lib/answer/prompt.d.ts +0 -37
- package/dist/lib/answer/provider.d.ts +0 -47
- package/dist/lib/answer/retrieval.d.ts +0 -36
- package/dist/lib/answer/telemetry.d.ts +0 -99
- package/dist/lib/answer/types.d.ts +0 -108
- package/dist/lib/api/error-leak-fix.d.ts +0 -54
- package/dist/lib/api/safe-error-message.d.ts +0 -70
- package/dist/lib/archive/common-passwords.d.ts +0 -37
- package/dist/lib/archive/common-passwords.js +0 -753
- package/dist/lib/archive/encryption.d.ts +0 -81
- package/dist/lib/archive/encryption.js +0 -236
- package/dist/lib/archive/enforce-strength.d.ts +0 -54
- package/dist/lib/archive/enforce-strength.js +0 -70
- package/dist/lib/archive/entropy.d.ts +0 -34
- package/dist/lib/archive/entropy.js +0 -180
- package/dist/lib/archive/export-locking.d.ts +0 -102
- package/dist/lib/archive/export-locking.js +0 -202
- package/dist/lib/archive/format.d.ts +0 -20
- package/dist/lib/archive/format.js +0 -174
- package/dist/lib/archive/index.d.ts +0 -23
- package/dist/lib/archive/index.js +0 -17
- package/dist/lib/archive/manifest.d.ts +0 -53
- package/dist/lib/archive/manifest.js +0 -183
- package/dist/lib/archive/migration.d.ts +0 -36
- package/dist/lib/archive/migration.js +0 -100
- package/dist/lib/archive/migrations/v18_to_v19.d.ts +0 -16
- package/dist/lib/archive/migrations/v18_to_v19.js +0 -18
- package/dist/lib/archive/orchestrator.d.ts +0 -166
- package/dist/lib/archive/orchestrator.js +0 -428
- package/dist/lib/archive/serializers/chunks.d.ts +0 -30
- package/dist/lib/archive/serializers/chunks.js +0 -113
- package/dist/lib/archive/serializers/embeddings.d.ts +0 -36
- package/dist/lib/archive/serializers/embeddings.js +0 -115
- package/dist/lib/archive/serializers/kg.d.ts +0 -28
- package/dist/lib/archive/serializers/kg.js +0 -184
- package/dist/lib/archive/serializers/ops_audit.d.ts +0 -21
- package/dist/lib/archive/serializers/ops_audit.js +0 -97
- package/dist/lib/archive/server-deps.d.ts +0 -131
- package/dist/lib/archive/server-deps.js +0 -232
- package/dist/lib/archive/strength.d.ts +0 -50
- package/dist/lib/archive/strength.js +0 -77
- package/dist/lib/archive/types.d.ts +0 -159
- package/dist/lib/archive/types.js +0 -45
- package/dist/lib/archive/unpack-streaming.d.ts +0 -70
- package/dist/lib/archive/unpack-streaming.js +0 -255
- package/dist/lib/auth/localhost-guard.d.ts +0 -106
- package/dist/lib/confidence/config.d.ts +0 -37
- package/dist/lib/confidence/config.js +0 -107
- package/dist/lib/confidence/db-shim-singleton.d.ts +0 -20
- package/dist/lib/confidence/db-shim-singleton.js +0 -41
- package/dist/lib/confidence/db-shim.d.ts +0 -47
- package/dist/lib/confidence/db-shim.js +0 -141
- package/dist/lib/confidence/mark.d.ts +0 -58
- package/dist/lib/confidence/mark.js +0 -168
- package/dist/lib/confidence/ranking.d.ts +0 -69
- package/dist/lib/confidence/ranking.js +0 -101
- package/dist/lib/confidence/search-filter.d.ts +0 -44
- package/dist/lib/confidence/search-filter.js +0 -103
- package/dist/lib/confidence/types.d.ts +0 -146
- package/dist/lib/confidence/types.js +0 -20
- package/dist/lib/confidence/write-hooks.d.ts +0 -50
- package/dist/lib/confidence/write-hooks.js +0 -159
- package/dist/lib/conflict/audit-fk-check.d.ts +0 -72
- package/dist/lib/conflict/audit-fk-check.js +0 -131
- package/dist/lib/conflict/audit-writer.d.ts +0 -39
- package/dist/lib/conflict/audit-writer.js +0 -133
- package/dist/lib/conflict/db-singleton.d.ts +0 -28
- package/dist/lib/conflict/db-singleton.js +0 -61
- package/dist/lib/conflict/db.d.ts +0 -27
- package/dist/lib/conflict/db.js +0 -20
- package/dist/lib/conflict/detector-direct.d.ts +0 -21
- package/dist/lib/conflict/detector-direct.js +0 -105
- package/dist/lib/conflict/evidence.d.ts +0 -24
- package/dist/lib/conflict/evidence.js +0 -76
- package/dist/lib/conflict/index.d.ts +0 -14
- package/dist/lib/conflict/index.js +0 -12
- package/dist/lib/conflict/scheduler.d.ts +0 -78
- package/dist/lib/conflict/scheduler.js +0 -111
- package/dist/lib/conflict/shadow.d.ts +0 -75
- package/dist/lib/conflict/shadow.js +0 -161
- package/dist/lib/conflict/types.d.ts +0 -133
- package/dist/lib/conflict/types.js +0 -19
- package/dist/lib/cost-cap.d.ts +0 -94
- package/dist/lib/deps/deps-registry.d.ts +0 -111
- package/dist/lib/error-sanitizer/middleware.d.ts +0 -43
- package/dist/lib/error-sanitizer/sanitize.d.ts +0 -78
- package/dist/lib/eval-batch.d.ts +0 -34
- package/dist/lib/eval-batch.js +0 -103
- package/dist/lib/eval-metrics.d.ts +0 -36
- package/dist/lib/eval-metrics.js +0 -95
- package/dist/lib/eval.d.ts +0 -106
- package/dist/lib/eval.js +0 -343
- package/dist/lib/events/bus.d.ts +0 -135
- package/dist/lib/fts-anchor.d.ts +0 -1
- package/dist/lib/hooks/classifier.d.ts +0 -47
- package/dist/lib/hooks/classifier.js +0 -129
- package/dist/lib/hooks/config.d.ts +0 -49
- package/dist/lib/hooks/config.js +0 -106
- package/dist/lib/hooks/decorators.d.ts +0 -35
- package/dist/lib/hooks/decorators.js +0 -59
- package/dist/lib/hooks/pipeline.d.ts +0 -76
- package/dist/lib/hooks/pipeline.js +0 -213
- package/dist/lib/hooks/privacy-filter-adapter.d.ts +0 -55
- package/dist/lib/hooks/privacy-filter-adapter.js +0 -84
- package/dist/lib/hooks/rate-limit-constant-time.d.ts +0 -57
- package/dist/lib/hooks/rate-limit-constant-time.js +0 -69
- package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +0 -71
- package/dist/lib/hooks/rate-limit-dryrun-fix.js +0 -110
- package/dist/lib/hooks/rate-limit.d.ts +0 -54
- package/dist/lib/hooks/rate-limit.js +0 -122
- package/dist/lib/hooks/server-deps.d.ts +0 -61
- package/dist/lib/hooks/server-deps.js +0 -92
- package/dist/lib/hooks/source-allowlist.d.ts +0 -26
- package/dist/lib/hooks/source-allowlist.js +0 -53
- package/dist/lib/hooks/types.d.ts +0 -129
- package/dist/lib/hooks/types.js +0 -24
- package/dist/lib/hooks/worker.d.ts +0 -56
- package/dist/lib/hooks/worker.js +0 -150
- package/dist/lib/ingest-router.d.ts +0 -25
- package/dist/lib/ocr-detector.d.ts +0 -61
- package/dist/lib/ocr-detector.js +0 -138
- package/dist/lib/ocr-engine-stub.d.ts +0 -48
- package/dist/lib/ocr-engine-stub.js +0 -190
- package/dist/lib/ocr-engines/google-doc-ai.d.ts +0 -36
- package/dist/lib/ocr-engines/google-doc-ai.js +0 -164
- package/dist/lib/ocr-jobs.d.ts +0 -67
- package/dist/lib/ocr-jobs.js +0 -129
- package/dist/lib/op-audit-extension/ran-at-guard.d.ts +0 -86
- package/dist/lib/op-audit.d.ts +0 -71
- package/dist/lib/privacy-br/detector.d.ts +0 -42
- package/dist/lib/privacy-br/detector.js +0 -130
- package/dist/lib/privacy-br/index.d.ts +0 -20
- package/dist/lib/privacy-br/index.js +0 -20
- package/dist/lib/privacy-br/integration.d.ts +0 -71
- package/dist/lib/privacy-br/integration.js +0 -74
- package/dist/lib/privacy-br/patterns.d.ts +0 -117
- package/dist/lib/privacy-br/patterns.js +0 -434
- package/dist/lib/privacy-br/redact.d.ts +0 -42
- package/dist/lib/privacy-br/redact.js +0 -103
- package/dist/lib/privacy-br/types.d.ts +0 -55
- package/dist/lib/privacy-br/types.js +0 -25
- package/dist/lib/regex-extract/extractor.d.ts +0 -30
- package/dist/lib/regex-extract/frontmatter.d.ts +0 -44
- package/dist/lib/regex-extract/index.d.ts +0 -14
- package/dist/lib/regex-extract/ingest-router-l4.d.ts +0 -76
- package/dist/lib/regex-extract/patterns.d.ts +0 -61
- package/dist/lib/regex-extract/production-wire.d.ts +0 -128
- package/dist/lib/regex-extract/reconcile.d.ts +0 -162
- package/dist/lib/regex-extract/strip-code.d.ts +0 -24
- package/dist/lib/regex-extract/types.d.ts +0 -48
- package/dist/lib/reranker.d.ts +0 -80
- package/dist/lib/shadow-tracker.d.ts +0 -191
- package/dist/lib/shadow-tracker.js +0 -384
- package/dist/lib/spo-injection.d.ts +0 -52
- package/dist/lib/telemetry-collector.d.ts +0 -158
- package/dist/lib/telemetry-collector.js +0 -249
- package/dist/lib/temporal-detector.d.ts +0 -27
- package/dist/lib/viewer/auth.d.ts +0 -37
- package/dist/lib/viewer/auth.js +0 -70
- package/dist/lib/viewer/backpressure.d.ts +0 -59
- package/dist/lib/viewer/backpressure.js +0 -100
- package/dist/lib/viewer/broadcast-singleton.d.ts +0 -34
- package/dist/lib/viewer/broadcast-singleton.js +0 -49
- package/dist/lib/viewer/broadcast.d.ts +0 -66
- package/dist/lib/viewer/broadcast.js +0 -96
- package/dist/lib/viewer/event-types.d.ts +0 -132
- package/dist/lib/viewer/event-types.js +0 -74
- package/dist/lib/viewer/instrumentation.d.ts +0 -106
- package/dist/lib/viewer/instrumentation.js +0 -224
- package/dist/lib/viewer/migration.d.ts +0 -23
- package/dist/lib/viewer/migration.js +0 -56
- package/dist/lib/viewer/redaction.d.ts +0 -44
- package/dist/lib/viewer/redaction.js +0 -139
- package/dist/lib/viewer/session.d.ts +0 -51
- package/dist/lib/viewer/session.js +0 -87
- package/dist/mcp/tools/answer.d.ts +0 -94
- package/dist/mcp/tools/archive.d.ts +0 -152
- package/dist/mcp/tools/archive.js +0 -170
- package/dist/mcp/tools/conflict.d.ts +0 -44
- package/dist/mcp/tools/conflict.js +0 -130
- package/dist/mcp/tools/hooks.d.ts +0 -29
- package/dist/mcp/tools/hooks.js +0 -78
- package/dist/mcp/tools/mark.d.ts +0 -38
- package/dist/mcp/tools/mark.js +0 -82
- package/dist/mcp/tools/viewer.d.ts +0 -58
- package/dist/mcp/tools/viewer.js +0 -64
- package/dist/mcp-server.d.ts +0 -2
- package/dist/metrics.d.ts +0 -3
- package/dist/noise-filter.d.ts +0 -18
- package/dist/notion-sync.d.ts +0 -7
- package/dist/notion-sync.js +0 -97
- package/dist/observability/adapters/a3-adapter.d.ts +0 -63
- package/dist/observability/adapters/a3-adapter.js +0 -83
- package/dist/observability/adapters/p1-adapter.d.ts +0 -49
- package/dist/observability/adapters/p1-adapter.js +0 -63
- package/dist/observability/adapters/p5-adapter.d.ts +0 -36
- package/dist/observability/adapters/p5-adapter.js +0 -71
- package/dist/observability/cardinality.d.ts +0 -61
- package/dist/observability/cardinality.js +0 -300
- package/dist/observability/collectors/db-stats.collector.d.ts +0 -9
- package/dist/observability/collectors/db-stats.collector.js +0 -88
- package/dist/observability/collectors/eventbus.collector.d.ts +0 -6
- package/dist/observability/collectors/eventbus.collector.js +0 -50
- package/dist/observability/collectors/process.collector.d.ts +0 -7
- package/dist/observability/collectors/process.collector.js +0 -93
- package/dist/observability/collectors/provider-telemetry.collector.d.ts +0 -11
- package/dist/observability/collectors/provider-telemetry.collector.js +0 -112
- package/dist/observability/collectors/search-telemetry.collector.d.ts +0 -12
- package/dist/observability/collectors/search-telemetry.collector.js +0 -76
- package/dist/observability/exporter.d.ts +0 -30
- package/dist/observability/exporter.js +0 -182
- package/dist/observability/index.d.ts +0 -22
- package/dist/observability/index.js +0 -21
- package/dist/observability/metrics.d.ts +0 -53
- package/dist/observability/metrics.js +0 -213
- package/dist/observability/privacy-guard.d.ts +0 -32
- package/dist/observability/privacy-guard.js +0 -116
- package/dist/observability/record.d.ts +0 -83
- package/dist/observability/record.js +0 -217
- package/dist/observability/registry.d.ts +0 -60
- package/dist/observability/registry.js +0 -93
- package/dist/observability/types.d.ts +0 -115
- package/dist/observability/types.js +0 -235
- package/dist/observability.d.ts +0 -131
- package/dist/plugins/nox-hooks/index.d.ts +0 -61
- package/dist/plugins/nox-hooks/index.js +0 -99
- package/dist/primer.d.ts +0 -1
- package/dist/privacy/filter.d.ts +0 -27
- package/dist/privacy/patterns.d.ts +0 -29
- package/dist/privacy/tag-parser.d.ts +0 -24
- package/dist/project-context-gen.d.ts +0 -10
- package/dist/providers/embedding/gemini.d.ts +0 -73
- package/dist/providers/embedding/openai.d.ts +0 -76
- package/dist/providers/embedding/types.d.ts +0 -39
- package/dist/providers/embedding/voyage.d.ts +0 -36
- package/dist/providers/index.d.ts +0 -116
- package/dist/providers/llm/anthropic.d.ts +0 -29
- package/dist/providers/llm/chain.d.ts +0 -99
- package/dist/providers/llm/gemini.d.ts +0 -48
- package/dist/providers/llm/openai.d.ts +0 -64
- package/dist/providers/llm/types.d.ts +0 -47
- package/dist/providers/telemetry.d.ts +0 -87
- package/dist/providers/types.d.ts +0 -42
- package/dist/query-entity-count.d.ts +0 -54
- package/dist/reflect.d.ts +0 -26
- package/dist/reindex-errors.d.ts +0 -7
- package/dist/reindex.d.ts +0 -16
- package/dist/retention.d.ts +0 -40
- package/dist/salience.d.ts +0 -85
- package/dist/scripts/migrate-v17-ops-audit.d.ts +0 -17
- package/dist/search-dedup.d.ts +0 -44
- package/dist/search-expansion.d.ts +0 -20
- package/dist/search.d.ts +0 -62
- package/dist/seh-detector.d.ts +0 -31
- package/dist/self-improve.d.ts +0 -1
- package/dist/session-distill.d.ts +0 -29
- package/dist/session-update.d.ts +0 -1
- package/dist/shared-memory.d.ts +0 -24
- package/dist/stats.d.ts +0 -1
- package/dist/temporal-retrieval.d.ts +0 -132
- package/dist/tier-manager.d.ts +0 -69
- package/dist/vectorize.d.ts +0 -16
- package/dist/watch.d.ts +0 -8
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// E13 — Temporal-aware Ranking tests.
|
|
2
|
+
// Spec: memoria-nox/specs/2026-05-06-E13-temporal-aware-ranking.md
|
|
3
|
+
//
|
|
4
|
+
// Run: cd /root/.openclaw/workspace/tools/nox-mem && npx tsc &&
|
|
5
|
+
// node --test dist/__tests__/temporal-detector.test.js
|
|
6
|
+
import { test, beforeEach } from "node:test";
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { isTemporalQuery, effectiveSectionBoost, getOverride, getMode, SECTION_BOOST_TEMPORAL, } from "../lib/temporal-detector.js";
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
delete process.env.NOX_TEMPORAL_BOOST_MODE;
|
|
11
|
+
delete process.env.NOX_TEMPORAL_BOOST_LOG;
|
|
12
|
+
});
|
|
13
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
14
|
+
// 1. detector positive cases (PT-BR triggers)
|
|
15
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
16
|
+
test("isTemporalQuery: 'quando o salience foi ativado' → true", () => {
|
|
17
|
+
assert.equal(isTemporalQuery("quando o salience foi ativado"), true);
|
|
18
|
+
});
|
|
19
|
+
test("isTemporalQuery: 'primeira lição do incident' → true", () => {
|
|
20
|
+
assert.equal(isTemporalQuery("primeira lição do incident"), true);
|
|
21
|
+
});
|
|
22
|
+
test("isTemporalQuery: 'ativado' single token → true", () => {
|
|
23
|
+
assert.equal(isTemporalQuery("ativado"), true);
|
|
24
|
+
});
|
|
25
|
+
test("isTemporalQuery: ISO date '2026-04-25' in query → true", () => {
|
|
26
|
+
assert.equal(isTemporalQuery("query com 2026-04-25 contexto"), true);
|
|
27
|
+
});
|
|
28
|
+
test("isTemporalQuery: 'Quando subiu schema v12?' (case-insensitive) → true", () => {
|
|
29
|
+
assert.equal(isTemporalQuery("Quando subiu schema v12?"), true);
|
|
30
|
+
});
|
|
31
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
32
|
+
// 2. detector negative cases
|
|
33
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
34
|
+
test("isTemporalQuery: 'o que é nox-mem' → false (factual)", () => {
|
|
35
|
+
assert.equal(isTemporalQuery("o que é nox-mem"), false);
|
|
36
|
+
});
|
|
37
|
+
test("isTemporalQuery: 'relação entre A e B' → false", () => {
|
|
38
|
+
assert.equal(isTemporalQuery("relação entre A e B"), false);
|
|
39
|
+
});
|
|
40
|
+
test("isTemporalQuery: empty/short query → false", () => {
|
|
41
|
+
assert.equal(isTemporalQuery(""), false);
|
|
42
|
+
assert.equal(isTemporalQuery("ab"), false);
|
|
43
|
+
});
|
|
44
|
+
// Edge: "deployment" sozinho NÃO bate (precisa "deployado/deployed/deployamento")
|
|
45
|
+
test("isTemporalQuery: 'deployment automatizado' → false (radical sem modifier)", () => {
|
|
46
|
+
assert.equal(isTemporalQuery("deployment automatizado"), false);
|
|
47
|
+
});
|
|
48
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
49
|
+
// 3. effectiveSectionBoost — override só em mode=active
|
|
50
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
51
|
+
test("effectiveSectionBoost: mode=off retorna baseline (sem override)", () => {
|
|
52
|
+
// baseline timeline = 0.8; override seria 1.4
|
|
53
|
+
const v = effectiveSectionBoost(0.8, "timeline", true, "off");
|
|
54
|
+
assert.equal(v, 0.8);
|
|
55
|
+
});
|
|
56
|
+
test("effectiveSectionBoost: mode=shadow retorna baseline (não muta)", () => {
|
|
57
|
+
const v = effectiveSectionBoost(0.8, "timeline", true, "shadow");
|
|
58
|
+
assert.equal(v, 0.8);
|
|
59
|
+
});
|
|
60
|
+
test("effectiveSectionBoost: mode=active + isTemporal + section=timeline → 1.4 override", () => {
|
|
61
|
+
const v = effectiveSectionBoost(0.8, "timeline", true, "active");
|
|
62
|
+
assert.equal(v, 1.4);
|
|
63
|
+
});
|
|
64
|
+
test("effectiveSectionBoost: mode=active + isTemporal + section=compiled → 1.0 (neutro)", () => {
|
|
65
|
+
const v = effectiveSectionBoost(2.0, "compiled", true, "active");
|
|
66
|
+
assert.equal(v, 1.0);
|
|
67
|
+
});
|
|
68
|
+
test("effectiveSectionBoost: mode=active mas isTemporal=false → baseline preservado", () => {
|
|
69
|
+
const v = effectiveSectionBoost(2.0, "compiled", false, "active");
|
|
70
|
+
assert.equal(v, 2.0);
|
|
71
|
+
});
|
|
72
|
+
test("effectiveSectionBoost: section=null → baseline retornado", () => {
|
|
73
|
+
const v = effectiveSectionBoost(1.0, null, true, "active");
|
|
74
|
+
assert.equal(v, 1.0);
|
|
75
|
+
});
|
|
76
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
77
|
+
// 4. getMode env reader (off/shadow/active fallback)
|
|
78
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
79
|
+
test("getMode: default off quando env unset", () => {
|
|
80
|
+
delete process.env.NOX_TEMPORAL_BOOST_MODE;
|
|
81
|
+
assert.equal(getMode(), "off");
|
|
82
|
+
});
|
|
83
|
+
test("getMode: lowercase shadow", () => {
|
|
84
|
+
process.env.NOX_TEMPORAL_BOOST_MODE = "SHADOW";
|
|
85
|
+
assert.equal(getMode(), "shadow");
|
|
86
|
+
});
|
|
87
|
+
test("getMode: invalid value → off fallback", () => {
|
|
88
|
+
process.env.NOX_TEMPORAL_BOOST_MODE = "garbage";
|
|
89
|
+
assert.equal(getMode(), "off");
|
|
90
|
+
});
|
|
91
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
92
|
+
// 5. getOverride pure lookup
|
|
93
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
94
|
+
test("getOverride: timeline → 1.4", () => {
|
|
95
|
+
assert.equal(getOverride("timeline"), 1.4);
|
|
96
|
+
});
|
|
97
|
+
test("getOverride: section desconhecida → null", () => {
|
|
98
|
+
assert.equal(getOverride("xyz"), null);
|
|
99
|
+
});
|
|
100
|
+
test("SECTION_BOOST_TEMPORAL: invariants — timeline>compiled>frontmatter", () => {
|
|
101
|
+
assert.ok(SECTION_BOOST_TEMPORAL.timeline > SECTION_BOOST_TEMPORAL.compiled);
|
|
102
|
+
assert.ok(SECTION_BOOST_TEMPORAL.compiled > SECTION_BOOST_TEMPORAL.frontmatter);
|
|
103
|
+
});
|
package/dist/api/wire-up.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* src/api/wire-up.ts —
|
|
3
|
+
* src/api/wire-up.ts — HTTP route registration for handlers that live under
|
|
4
|
+
* `src/api/*.ts` but aren't part of the native `src/api-server.ts` switch/case.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* conflict, mark, hooks)
|
|
8
|
-
* dispatch) was never updated to mount them. Result: every new endpoint
|
|
9
|
-
* returns 404.
|
|
6
|
+
* Core kit: the only wired route is `POST /api/answer` (the flagship
|
|
7
|
+
* synthesis endpoint). Enterprise/niche routes (export/import, SSE viewer,
|
|
8
|
+
* conflict, confidence mark, hooks) were trimmed from the public package.
|
|
10
9
|
*
|
|
11
10
|
* This module exports `registerWireUpRoutes()` — a single function called
|
|
12
|
-
* from `src/api-server.ts` immediately
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* 404 reply.
|
|
11
|
+
* from `src/api-server.ts` immediately before its `default` (404) arm. It
|
|
12
|
+
* pattern-matches the request path and delegates to the handler. Returns
|
|
13
|
+
* `true` when the request was handled; `false` lets the host fall through to
|
|
14
|
+
* the existing 404 reply.
|
|
17
15
|
*
|
|
18
16
|
* Framework constraint (regra "match existing routing pattern"):
|
|
19
17
|
* - Native Node `http` (`IncomingMessage` / `ServerResponse`). No Express.
|
|
@@ -23,26 +21,6 @@
|
|
|
23
21
|
* Security defaults applied here:
|
|
24
22
|
* - G5 (error sanitizer): every catch funnels through `sanitizeErrorForHttp`
|
|
25
23
|
* so stack traces and internal paths never leak in 500 responses.
|
|
26
|
-
* - G6 (localhost guard): every mutating endpoint (`POST /api/import`,
|
|
27
|
-
* `POST /api/conflict/:id/resolve`, `POST /api/chunk/:id/mark`,
|
|
28
|
-
* `POST /api/chunk/:id/supersede`, `POST /api/hooks/dryrun`) gates on
|
|
29
|
-
* `makeLocalhostGuard()`. Read-only endpoints stay open (parity with
|
|
30
|
-
* `/api/health`, `/api/kg`, etc.).
|
|
31
|
-
*
|
|
32
|
-
* Caller contract (`api-server.ts`):
|
|
33
|
-
*
|
|
34
|
-
* import { registerWireUpRoutes } from "./api/wire-up.js";
|
|
35
|
-
*
|
|
36
|
-
* async function handleRequest(req, res) {
|
|
37
|
-
* // … existing switch/case …
|
|
38
|
-
* // before falling through to 404, ask the wire-up router:
|
|
39
|
-
* if (await registerWireUpRoutes(req, res)) return;
|
|
40
|
-
* // existing 404 reply
|
|
41
|
-
* }
|
|
42
|
-
*
|
|
43
|
-
* The handlers are imported lazily (`await import(…)`) so that the existing
|
|
44
|
-
* API server boots even when a staged-* dir hasn't been deployed yet
|
|
45
|
-
* (degraded mode: route returns 503 not_implemented, never 500).
|
|
46
24
|
*/
|
|
47
25
|
// ─── CORS / JSON helpers (parity with src/api-server.ts) ────────────────────
|
|
48
26
|
const CORS_HEADERS = {
|
|
@@ -58,13 +36,8 @@ function writeJson(res, data, status = 200, extraHeaders = {}) {
|
|
|
58
36
|
});
|
|
59
37
|
res.end(typeof data === "string" ? data : JSON.stringify(data));
|
|
60
38
|
}
|
|
61
|
-
function writeBuffer(res, body, status, headers) {
|
|
62
|
-
res.writeHead(status, { ...CORS_HEADERS, ...headers });
|
|
63
|
-
res.end(body);
|
|
64
|
-
}
|
|
65
39
|
// ─── Body parsing ────────────────────────────────────────────────────────────
|
|
66
40
|
function readBody(req, limit = 64 * 1024 * 1024) {
|
|
67
|
-
// 64 MiB upper bound for /api/import archive_b64 payloads.
|
|
68
41
|
return new Promise((resolve, reject) => {
|
|
69
42
|
let data = "";
|
|
70
43
|
let size = 0;
|
|
@@ -92,20 +65,7 @@ async function readJsonBody(req, limit) {
|
|
|
92
65
|
throw new Error("Invalid JSON body");
|
|
93
66
|
}
|
|
94
67
|
}
|
|
95
|
-
function parseQueryString(url) {
|
|
96
|
-
const idx = url.indexOf("?");
|
|
97
|
-
if (idx === -1)
|
|
98
|
-
return {};
|
|
99
|
-
const params = {};
|
|
100
|
-
for (const part of url.substring(idx + 1).split("&")) {
|
|
101
|
-
const [k, v] = part.split("=");
|
|
102
|
-
if (k)
|
|
103
|
-
params[decodeURIComponent(k)] = decodeURIComponent(v || "");
|
|
104
|
-
}
|
|
105
|
-
return params;
|
|
106
|
-
}
|
|
107
68
|
let _sanitizer = null;
|
|
108
|
-
let _guard = null;
|
|
109
69
|
async function getSanitizer() {
|
|
110
70
|
if (_sanitizer)
|
|
111
71
|
return _sanitizer;
|
|
@@ -115,7 +75,7 @@ async function getSanitizer() {
|
|
|
115
75
|
}
|
|
116
76
|
catch {
|
|
117
77
|
// Fallback when G5 isn't deployed: minimal redaction (no stack, no paths).
|
|
118
|
-
_sanitizer = (
|
|
78
|
+
_sanitizer = () => ({
|
|
119
79
|
status: 500,
|
|
120
80
|
body: {
|
|
121
81
|
error: "internal error",
|
|
@@ -126,26 +86,6 @@ async function getSanitizer() {
|
|
|
126
86
|
}
|
|
127
87
|
return _sanitizer;
|
|
128
88
|
}
|
|
129
|
-
async function getLocalhostGuard() {
|
|
130
|
-
if (_guard)
|
|
131
|
-
return _guard;
|
|
132
|
-
try {
|
|
133
|
-
const mod = await import("../lib/auth/localhost-guard.js");
|
|
134
|
-
_guard = mod.defaultLocalhostGuard;
|
|
135
|
-
}
|
|
136
|
-
catch {
|
|
137
|
-
// Fallback when G6 isn't deployed: default-deny remote, allow local.
|
|
138
|
-
_guard = (req, res) => {
|
|
139
|
-
const addr = req.socket?.remoteAddress ?? "";
|
|
140
|
-
const local = addr === "127.0.0.1" || addr === "::1" || addr === "::ffff:127.0.0.1";
|
|
141
|
-
if (local)
|
|
142
|
-
return false;
|
|
143
|
-
writeJson(res, { error: "forbidden", reason: "localhost-only" }, 403);
|
|
144
|
-
return true;
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
return _guard;
|
|
148
|
-
}
|
|
149
89
|
// Helper: header lookup (case-insensitive).
|
|
150
90
|
function getReqHeader(req, name) {
|
|
151
91
|
const v = req.headers[name.toLowerCase()];
|
|
@@ -166,40 +106,10 @@ async function safeHandle(req, res, fn) {
|
|
|
166
106
|
}
|
|
167
107
|
}
|
|
168
108
|
// ─── Route table ────────────────────────────────────────────────────────────
|
|
169
|
-
const CONFLICT_ID_RE = /^\/api\/conflict\/(\d+)$/;
|
|
170
|
-
const CONFLICT_RESOLVE_RE = /^\/api\/conflict\/(\d+)\/resolve$/;
|
|
171
|
-
const CHUNK_MARK_RE = /^\/api\/chunk\/(\d+)\/mark$/;
|
|
172
|
-
const CHUNK_SUPERSEDE_RE = /^\/api\/chunk\/(\d+)\/supersede$/;
|
|
173
109
|
/** Cheap probe — caller can detect "is this URL ours?" without parsing body. */
|
|
174
110
|
export function matchesWireUpRoute(method, path) {
|
|
175
111
|
if (method === "POST" && path === "/api/answer")
|
|
176
112
|
return true;
|
|
177
|
-
if (method === "POST" && path === "/api/export")
|
|
178
|
-
return true;
|
|
179
|
-
if (method === "POST" && path === "/api/import")
|
|
180
|
-
return true;
|
|
181
|
-
if (method === "GET" && path === "/api/events/stream")
|
|
182
|
-
return true;
|
|
183
|
-
if (method === "GET" && path.startsWith("/viewer"))
|
|
184
|
-
return true;
|
|
185
|
-
if (method === "GET" && path === "/api/conflict")
|
|
186
|
-
return true;
|
|
187
|
-
if (method === "GET" && CONFLICT_ID_RE.test(path))
|
|
188
|
-
return true;
|
|
189
|
-
if (method === "POST" && CONFLICT_RESOLVE_RE.test(path))
|
|
190
|
-
return true;
|
|
191
|
-
if (method === "POST" && CHUNK_MARK_RE.test(path))
|
|
192
|
-
return true;
|
|
193
|
-
if (method === "POST" && CHUNK_SUPERSEDE_RE.test(path))
|
|
194
|
-
return true;
|
|
195
|
-
if (method === "GET" && path === "/api/hooks/status")
|
|
196
|
-
return true;
|
|
197
|
-
if (method === "GET" && path === "/api/hooks/recent")
|
|
198
|
-
return true;
|
|
199
|
-
if (method === "POST" && path === "/api/hooks/dryrun")
|
|
200
|
-
return true;
|
|
201
|
-
if (method === "GET" && path === "/api/health/confidence")
|
|
202
|
-
return true;
|
|
203
113
|
return false;
|
|
204
114
|
}
|
|
205
115
|
/**
|
|
@@ -225,297 +135,18 @@ export async function registerWireUpRoutes(req, res) {
|
|
|
225
135
|
});
|
|
226
136
|
return true;
|
|
227
137
|
}
|
|
228
|
-
// ── A2: POST /api/export ───────────────────────────────────────────────
|
|
229
|
-
if (method === "POST" && path === "/api/export") {
|
|
230
|
-
// Read-only on the corpus, but produces large encrypted blob — keep
|
|
231
|
-
// open to localhost; remote access controlled at network layer (G6
|
|
232
|
-
// bind host). No mutation = no guard required here.
|
|
233
|
-
await safeHandle(req, res, async () => {
|
|
234
|
-
const body = await readJsonBody(req);
|
|
235
|
-
const handlerMod = await import("./export.js");
|
|
236
|
-
const depsMod = await tryImport("../lib/archive/server-deps.js");
|
|
237
|
-
if (!depsMod || typeof depsMod.buildExportDeps !== "function") {
|
|
238
|
-
writeJson(res, {
|
|
239
|
-
error: "not_implemented",
|
|
240
|
-
reason: "export deps not deployed",
|
|
241
|
-
hint: "deploy staged-A2 + lib/archive/server-deps.js (post-A2 wire-up needs DB reader binding)",
|
|
242
|
-
}, 503);
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
const out = await handlerMod.handleExport(body, await depsMod.buildExportDeps());
|
|
246
|
-
writeBuffer(res, out.body, out.status, out.headers);
|
|
247
|
-
});
|
|
248
|
-
return true;
|
|
249
|
-
}
|
|
250
|
-
// ── A2: POST /api/import ───────────────────────────────────────────────
|
|
251
|
-
if (method === "POST" && path === "/api/import") {
|
|
252
|
-
const guard = await getLocalhostGuard();
|
|
253
|
-
if (guard(req, res))
|
|
254
|
-
return true;
|
|
255
|
-
await safeHandle(req, res, async () => {
|
|
256
|
-
const body = await readJsonBody(req); // 64 MiB cap
|
|
257
|
-
const handlerMod = await import("./import.js");
|
|
258
|
-
const depsMod = await tryImport("../lib/archive/server-deps.js");
|
|
259
|
-
if (!depsMod || typeof depsMod.buildImportDeps !== "function") {
|
|
260
|
-
writeJson(res, {
|
|
261
|
-
error: "not_implemented",
|
|
262
|
-
reason: "import deps not deployed",
|
|
263
|
-
hint: "deploy staged-A2 + lib/archive/server-deps.js",
|
|
264
|
-
}, 503);
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
const out = await handlerMod.handleImport(body, await depsMod.buildImportDeps());
|
|
268
|
-
writeJson(res, out.body, out.status, out.headers);
|
|
269
|
-
});
|
|
270
|
-
return true;
|
|
271
|
-
}
|
|
272
|
-
// ── P5: GET /api/events/stream (SSE) ───────────────────────────────────
|
|
273
|
-
if (method === "GET" && path === "/api/events/stream") {
|
|
274
|
-
await safeHandle(req, res, async () => {
|
|
275
|
-
const sseMod = await import("./events-stream.js");
|
|
276
|
-
const brMod = await tryImport("../lib/viewer/broadcast.js");
|
|
277
|
-
if (!brMod || typeof brMod.getBroadcaster !== "function") {
|
|
278
|
-
writeJson(res, { error: "not_implemented", reason: "viewer broadcaster not deployed" }, 503);
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
const broadcaster = brMod.getBroadcaster();
|
|
282
|
-
const lastEventId = sseMod.parseLastEventId(req.headers);
|
|
283
|
-
const clientId = (await import("node:crypto")).randomUUID();
|
|
284
|
-
const sse = sseMod.openSseStream({ broadcaster, clientId, lastEventId });
|
|
285
|
-
res.writeHead(200, { ...CORS_HEADERS, ...sse.headers });
|
|
286
|
-
req.on("close", () => sse.close());
|
|
287
|
-
try {
|
|
288
|
-
for await (const chunk of sse.iter) {
|
|
289
|
-
if (!res.write(chunk)) {
|
|
290
|
-
await new Promise((r) => res.once("drain", r));
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
finally {
|
|
295
|
-
sse.close();
|
|
296
|
-
res.end();
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
return true;
|
|
300
|
-
}
|
|
301
|
-
// ── P5: GET /viewer/* (static) ─────────────────────────────────────────
|
|
302
|
-
if (method === "GET" && path.startsWith("/viewer")) {
|
|
303
|
-
await safeHandle(req, res, async () => {
|
|
304
|
-
const mod = await import("./viewer-static.js");
|
|
305
|
-
const out = mod.serveViewerFile(path);
|
|
306
|
-
writeBuffer(res, out.body, out.status, out.headers);
|
|
307
|
-
});
|
|
308
|
-
return true;
|
|
309
|
-
}
|
|
310
|
-
// ── L2: GET /api/conflict ──────────────────────────────────────────────
|
|
311
|
-
if (method === "GET" && path === "/api/conflict") {
|
|
312
|
-
await safeHandle(req, res, async () => {
|
|
313
|
-
const mod = await import("./conflict.js");
|
|
314
|
-
const dbMod = await tryImport("../lib/conflict/db.js");
|
|
315
|
-
if (!dbMod || typeof dbMod.getConflictDb !== "function") {
|
|
316
|
-
writeJson(res, { error: "not_implemented", reason: "L2 db not deployed" }, 503);
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
// Ensure singleton is warmed before the synchronous getConflictDb() call.
|
|
320
|
-
// On a cold start the async warmup() hasn't settled yet; awaiting
|
|
321
|
-
// ensureConflictDb() guarantees a non-null handle (or surfaces a real
|
|
322
|
-
// DB-open failure as a 500 via safeHandle rather than a misleading 503).
|
|
323
|
-
if (typeof dbMod.ensureConflictDb === "function") {
|
|
324
|
-
await dbMod.ensureConflictDb();
|
|
325
|
-
}
|
|
326
|
-
const db = dbMod.getConflictDb();
|
|
327
|
-
if (!db) {
|
|
328
|
-
writeJson(res, { error: "not_implemented", reason: "L2 db not available" }, 503);
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
const out = mod.dispatchConflictApi(db, {
|
|
332
|
-
method: "GET",
|
|
333
|
-
path,
|
|
334
|
-
query: parseQueryString(url),
|
|
335
|
-
});
|
|
336
|
-
writeJson(res, out.body, out.status);
|
|
337
|
-
});
|
|
338
|
-
return true;
|
|
339
|
-
}
|
|
340
|
-
// ── L2: GET /api/conflict/:id ──────────────────────────────────────────
|
|
341
|
-
if (method === "GET" && CONFLICT_ID_RE.test(path)) {
|
|
342
|
-
await safeHandle(req, res, async () => {
|
|
343
|
-
const mod = await import("./conflict.js");
|
|
344
|
-
const dbMod = await tryImport("../lib/conflict/db.js");
|
|
345
|
-
if (!dbMod || typeof dbMod.getConflictDb !== "function") {
|
|
346
|
-
writeJson(res, { error: "not_implemented", reason: "L2 db not deployed" }, 503);
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
if (typeof dbMod.ensureConflictDb === "function") {
|
|
350
|
-
await dbMod.ensureConflictDb();
|
|
351
|
-
}
|
|
352
|
-
const db = dbMod.getConflictDb();
|
|
353
|
-
if (!db) {
|
|
354
|
-
writeJson(res, { error: "not_implemented", reason: "L2 db not available" }, 503);
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
const out = mod.dispatchConflictApi(db, {
|
|
358
|
-
method: "GET",
|
|
359
|
-
path,
|
|
360
|
-
});
|
|
361
|
-
writeJson(res, out.body, out.status);
|
|
362
|
-
});
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
// ── L2: POST /api/conflict/:id/resolve ─────────────────────────────────
|
|
366
|
-
if (method === "POST" && CONFLICT_RESOLVE_RE.test(path)) {
|
|
367
|
-
const guard = await getLocalhostGuard();
|
|
368
|
-
if (guard(req, res))
|
|
369
|
-
return true;
|
|
370
|
-
await safeHandle(req, res, async () => {
|
|
371
|
-
const body = await readJsonBody(req);
|
|
372
|
-
const mod = await import("./conflict.js");
|
|
373
|
-
const dbMod = await tryImport("../lib/conflict/db.js");
|
|
374
|
-
if (!dbMod || typeof dbMod.getConflictDb !== "function") {
|
|
375
|
-
writeJson(res, { error: "not_implemented", reason: "L2 db not deployed" }, 503);
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
if (typeof dbMod.ensureConflictDb === "function") {
|
|
379
|
-
await dbMod.ensureConflictDb();
|
|
380
|
-
}
|
|
381
|
-
const db = dbMod.getConflictDb();
|
|
382
|
-
if (!db) {
|
|
383
|
-
writeJson(res, { error: "not_implemented", reason: "L2 db not available" }, 503);
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
const actor = getReqHeader(req, "x-actor") ?? "api";
|
|
387
|
-
const out = mod.dispatchConflictApi(db, {
|
|
388
|
-
method: "POST",
|
|
389
|
-
path,
|
|
390
|
-
body,
|
|
391
|
-
actor,
|
|
392
|
-
});
|
|
393
|
-
writeJson(res, out.body, out.status);
|
|
394
|
-
});
|
|
395
|
-
return true;
|
|
396
|
-
}
|
|
397
|
-
// ── L3: POST /api/chunk/:id/mark ───────────────────────────────────────
|
|
398
|
-
if (method === "POST" && CHUNK_MARK_RE.test(path)) {
|
|
399
|
-
const guard = await getLocalhostGuard();
|
|
400
|
-
if (guard(req, res))
|
|
401
|
-
return true;
|
|
402
|
-
await safeHandle(req, res, async () => {
|
|
403
|
-
const m = CHUNK_MARK_RE.exec(path);
|
|
404
|
-
const idStr = m[1];
|
|
405
|
-
const body = await readJsonBody(req);
|
|
406
|
-
const mod = await import("./mark.js");
|
|
407
|
-
const shimMod = await tryImport("../lib/confidence/db-shim.js");
|
|
408
|
-
if (!shimMod || typeof shimMod.getConfidenceDb !== "function") {
|
|
409
|
-
writeJson(res, { error: "not_implemented", reason: "L3 db not deployed" }, 503);
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
const out = mod.handleMarkRequest(shimMod.getConfidenceDb(), idStr, body);
|
|
413
|
-
writeJson(res, out.body, out.status);
|
|
414
|
-
});
|
|
415
|
-
return true;
|
|
416
|
-
}
|
|
417
|
-
// ── L3: POST /api/chunk/:id/supersede ──────────────────────────────────
|
|
418
|
-
if (method === "POST" && CHUNK_SUPERSEDE_RE.test(path)) {
|
|
419
|
-
const guard = await getLocalhostGuard();
|
|
420
|
-
if (guard(req, res))
|
|
421
|
-
return true;
|
|
422
|
-
await safeHandle(req, res, async () => {
|
|
423
|
-
const m = CHUNK_SUPERSEDE_RE.exec(path);
|
|
424
|
-
const idStr = m[1];
|
|
425
|
-
const body = await readJsonBody(req);
|
|
426
|
-
const mod = await import("./mark.js");
|
|
427
|
-
const shimMod = await tryImport("../lib/confidence/db-shim.js");
|
|
428
|
-
if (!shimMod || typeof shimMod.getConfidenceDb !== "function") {
|
|
429
|
-
writeJson(res, { error: "not_implemented", reason: "L3 db not deployed" }, 503);
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
const out = mod.handleSupersedeRequest(shimMod.getConfidenceDb(), idStr, body);
|
|
433
|
-
writeJson(res, out.body, out.status);
|
|
434
|
-
});
|
|
435
|
-
return true;
|
|
436
|
-
}
|
|
437
|
-
// ── L3: GET /api/health/confidence ─────────────────────────────────────
|
|
438
|
-
if (method === "GET" && path === "/api/health/confidence") {
|
|
439
|
-
await safeHandle(req, res, async () => {
|
|
440
|
-
const mod = await tryImport("./health-confidence.js");
|
|
441
|
-
if (!mod || typeof mod.handleHealthConfidence !== "function") {
|
|
442
|
-
writeJson(res, { error: "not_implemented", reason: "L3 health not deployed" }, 503);
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
const out = await mod.handleHealthConfidence();
|
|
446
|
-
writeJson(res, out.body, out.status);
|
|
447
|
-
});
|
|
448
|
-
return true;
|
|
449
|
-
}
|
|
450
|
-
// ── P2: GET /api/hooks/status ──────────────────────────────────────────
|
|
451
|
-
if (method === "GET" && path === "/api/hooks/status") {
|
|
452
|
-
await safeHandle(req, res, async () => {
|
|
453
|
-
const mod = await import("./hooks.js");
|
|
454
|
-
const depsMod = await tryImport("../lib/hooks/server-deps.js");
|
|
455
|
-
if (!depsMod || typeof depsMod.buildHooksDeps !== "function") {
|
|
456
|
-
writeJson(res, { error: "not_implemented", reason: "P2 deps not deployed" }, 503);
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
const out = await mod.handleHooksRequest({ method: "GET", path }, await depsMod.buildHooksDeps());
|
|
460
|
-
writeJson(res, out.body, out.status);
|
|
461
|
-
});
|
|
462
|
-
return true;
|
|
463
|
-
}
|
|
464
|
-
// ── P2: GET /api/hooks/recent ──────────────────────────────────────────
|
|
465
|
-
if (method === "GET" && path === "/api/hooks/recent") {
|
|
466
|
-
await safeHandle(req, res, async () => {
|
|
467
|
-
const mod = await import("./hooks.js");
|
|
468
|
-
const depsMod = await tryImport("../lib/hooks/server-deps.js");
|
|
469
|
-
if (!depsMod || typeof depsMod.buildHooksDeps !== "function") {
|
|
470
|
-
writeJson(res, { error: "not_implemented", reason: "P2 deps not deployed" }, 503);
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
|
-
const out = await mod.handleHooksRequest({ method: "GET", path, query: parseQueryString(url) }, await depsMod.buildHooksDeps());
|
|
474
|
-
writeJson(res, out.body, out.status);
|
|
475
|
-
});
|
|
476
|
-
return true;
|
|
477
|
-
}
|
|
478
|
-
// ── P2: POST /api/hooks/dryrun ─────────────────────────────────────────
|
|
479
|
-
if (method === "POST" && path === "/api/hooks/dryrun") {
|
|
480
|
-
const guard = await getLocalhostGuard();
|
|
481
|
-
if (guard(req, res))
|
|
482
|
-
return true;
|
|
483
|
-
await safeHandle(req, res, async () => {
|
|
484
|
-
const body = await readJsonBody(req);
|
|
485
|
-
const mod = await import("./hooks.js");
|
|
486
|
-
const depsMod = await tryImport("../lib/hooks/server-deps.js");
|
|
487
|
-
if (!depsMod || typeof depsMod.buildHooksDeps !== "function") {
|
|
488
|
-
writeJson(res, { error: "not_implemented", reason: "P2 deps not deployed" }, 503);
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
const out = await mod.handleHooksRequest({ method: "POST", path, body }, await depsMod.buildHooksDeps());
|
|
492
|
-
writeJson(res, out.body, out.status);
|
|
493
|
-
});
|
|
494
|
-
return true;
|
|
495
|
-
}
|
|
496
138
|
// Should be unreachable (matchesWireUpRoute already filtered), but be safe.
|
|
497
139
|
return false;
|
|
498
140
|
}
|
|
499
|
-
// ───
|
|
500
|
-
async function tryImport(spec) {
|
|
501
|
-
try {
|
|
502
|
-
return await import(spec);
|
|
503
|
-
}
|
|
504
|
-
catch {
|
|
505
|
-
return null;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
// ─── Patch to src/api-server.ts (caller integration) ────────────────────────
|
|
141
|
+
// ─── Caller integration (src/api-server.ts) ──────────────────────────────────
|
|
509
142
|
//
|
|
510
143
|
// Add this line near the top:
|
|
511
144
|
//
|
|
512
145
|
// import { registerWireUpRoutes } from "./api/wire-up.js";
|
|
513
146
|
//
|
|
514
147
|
// Then, inside `handleRequest()`, BEFORE the `default:` arm of the existing
|
|
515
|
-
// switch/case
|
|
516
|
-
// insert:
|
|
148
|
+
// switch/case, insert:
|
|
517
149
|
//
|
|
518
150
|
// if (await registerWireUpRoutes(req, res)) return;
|
|
519
151
|
//
|
|
520
152
|
// The function is idempotent and side-effect-free for paths it does not own.
|
|
521
|
-
// Order matters only when the host has a conflicting route — currently none.
|