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
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/observability/registry.ts — MetricsRegistry singleton (T2).
|
|
3
|
-
*
|
|
4
|
-
* The Registry is the central index of all metrics. It is the only place
|
|
5
|
-
* exposed to the exporter (`/metrics`) and the recording API.
|
|
6
|
-
*
|
|
7
|
-
* INVARIANTS:
|
|
8
|
-
* - At most ONE metric per name across the whole process.
|
|
9
|
-
* - Re-registering the SAME object (idempotent) is allowed; re-registering
|
|
10
|
-
* a DIFFERENT object with the same name throws.
|
|
11
|
-
* - The registry is in-process (Node.js single-threaded); no external lock
|
|
12
|
-
* is required.
|
|
13
|
-
* - `collect()` returns an immutable snapshot — safe to render concurrently.
|
|
14
|
-
*
|
|
15
|
-
* SINGLETON PATTERN:
|
|
16
|
-
* `getDefaultRegistry()` returns a process-wide instance.
|
|
17
|
-
* Tests should construct a `new MetricsRegistry()` to stay isolated.
|
|
18
|
-
*
|
|
19
|
-
* THREAD-SAFETY:
|
|
20
|
-
* Node.js is single-threaded for JS; the only race is yielding between
|
|
21
|
-
* await points. The registry mutations (register/unregister) are
|
|
22
|
-
* synchronous so cannot interleave.
|
|
23
|
-
*/
|
|
24
|
-
import { Counter, Gauge, Histogram, type MetricKind } from "./types.js";
|
|
25
|
-
export type AnyMetric = Counter | Gauge | Histogram;
|
|
26
|
-
export interface RegistrySnapshot {
|
|
27
|
-
/** Wall-clock ms when snapshot was taken. */
|
|
28
|
-
readonly takenAt: number;
|
|
29
|
-
readonly counters: readonly Counter[];
|
|
30
|
-
readonly gauges: readonly Gauge[];
|
|
31
|
-
readonly histograms: readonly Histogram[];
|
|
32
|
-
}
|
|
33
|
-
export declare class MetricsRegistry {
|
|
34
|
-
private readonly byName;
|
|
35
|
-
/**
|
|
36
|
-
* Register a metric. Idempotent if the same object is re-registered;
|
|
37
|
-
* throws if a DIFFERENT object claims the same name.
|
|
38
|
-
*/
|
|
39
|
-
register<M extends AnyMetric>(metric: M): M;
|
|
40
|
-
/** Remove a metric by name. Returns true if it existed. */
|
|
41
|
-
unregister(name: string): boolean;
|
|
42
|
-
/** Look up a metric by name (typed by kind). */
|
|
43
|
-
get<K extends MetricKind>(name: string, kind?: K): AnyMetric | undefined;
|
|
44
|
-
/** Total number of distinct metric *names* (not series). */
|
|
45
|
-
get size(): number;
|
|
46
|
-
/** All metric names currently registered. */
|
|
47
|
-
names(): string[];
|
|
48
|
-
/**
|
|
49
|
-
* Take an immutable snapshot of all metrics.
|
|
50
|
-
* Returned arrays are sorted by metric name for stable exposition.
|
|
51
|
-
*/
|
|
52
|
-
collect(): RegistrySnapshot;
|
|
53
|
-
/** Test-only — wipe all metrics. */
|
|
54
|
-
clear(): void;
|
|
55
|
-
/** Total series across all metrics (used for cardinality observability). */
|
|
56
|
-
totalSeries(): number;
|
|
57
|
-
}
|
|
58
|
-
export declare function getDefaultRegistry(): MetricsRegistry;
|
|
59
|
-
/** Reset the default registry — test-only. */
|
|
60
|
-
export declare function resetDefaultRegistry(): void;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
export class MetricsRegistry {
|
|
2
|
-
byName = new Map();
|
|
3
|
-
/**
|
|
4
|
-
* Register a metric. Idempotent if the same object is re-registered;
|
|
5
|
-
* throws if a DIFFERENT object claims the same name.
|
|
6
|
-
*/
|
|
7
|
-
register(metric) {
|
|
8
|
-
const existing = this.byName.get(metric.meta.name);
|
|
9
|
-
if (existing) {
|
|
10
|
-
if (existing === metric)
|
|
11
|
-
return metric; // idempotent
|
|
12
|
-
throw new Error(`metric ${JSON.stringify(metric.meta.name)} already registered with different instance`);
|
|
13
|
-
}
|
|
14
|
-
this.byName.set(metric.meta.name, metric);
|
|
15
|
-
return metric;
|
|
16
|
-
}
|
|
17
|
-
/** Remove a metric by name. Returns true if it existed. */
|
|
18
|
-
unregister(name) {
|
|
19
|
-
return this.byName.delete(name);
|
|
20
|
-
}
|
|
21
|
-
/** Look up a metric by name (typed by kind). */
|
|
22
|
-
get(name, kind) {
|
|
23
|
-
const m = this.byName.get(name);
|
|
24
|
-
if (!m)
|
|
25
|
-
return undefined;
|
|
26
|
-
if (kind && m.meta.kind !== kind)
|
|
27
|
-
return undefined;
|
|
28
|
-
return m;
|
|
29
|
-
}
|
|
30
|
-
/** Total number of distinct metric *names* (not series). */
|
|
31
|
-
get size() {
|
|
32
|
-
return this.byName.size;
|
|
33
|
-
}
|
|
34
|
-
/** All metric names currently registered. */
|
|
35
|
-
names() {
|
|
36
|
-
return [...this.byName.keys()].sort();
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Take an immutable snapshot of all metrics.
|
|
40
|
-
* Returned arrays are sorted by metric name for stable exposition.
|
|
41
|
-
*/
|
|
42
|
-
collect() {
|
|
43
|
-
const counters = [];
|
|
44
|
-
const gauges = [];
|
|
45
|
-
const histograms = [];
|
|
46
|
-
const sortedNames = this.names();
|
|
47
|
-
for (const name of sortedNames) {
|
|
48
|
-
const m = this.byName.get(name);
|
|
49
|
-
if (!m)
|
|
50
|
-
continue;
|
|
51
|
-
switch (m.meta.kind) {
|
|
52
|
-
case "counter":
|
|
53
|
-
counters.push(m);
|
|
54
|
-
break;
|
|
55
|
-
case "gauge":
|
|
56
|
-
gauges.push(m);
|
|
57
|
-
break;
|
|
58
|
-
case "histogram":
|
|
59
|
-
histograms.push(m);
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return Object.freeze({
|
|
64
|
-
takenAt: Date.now(),
|
|
65
|
-
counters: Object.freeze(counters),
|
|
66
|
-
gauges: Object.freeze(gauges),
|
|
67
|
-
histograms: Object.freeze(histograms),
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
/** Test-only — wipe all metrics. */
|
|
71
|
-
clear() {
|
|
72
|
-
this.byName.clear();
|
|
73
|
-
}
|
|
74
|
-
/** Total series across all metrics (used for cardinality observability). */
|
|
75
|
-
totalSeries() {
|
|
76
|
-
let n = 0;
|
|
77
|
-
for (const m of this.byName.values()) {
|
|
78
|
-
n += m.seriesCount;
|
|
79
|
-
}
|
|
80
|
-
return n;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// ─── Process-wide default ────────────────────────────────────────────────────
|
|
84
|
-
let _default;
|
|
85
|
-
export function getDefaultRegistry() {
|
|
86
|
-
if (!_default)
|
|
87
|
-
_default = new MetricsRegistry();
|
|
88
|
-
return _default;
|
|
89
|
-
}
|
|
90
|
-
/** Reset the default registry — test-only. */
|
|
91
|
-
export function resetDefaultRegistry() {
|
|
92
|
-
_default = new MetricsRegistry();
|
|
93
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/observability/types.ts — Prometheus / OpenMetrics metric primitives (T1).
|
|
3
|
-
*
|
|
4
|
-
* Provides three core types — Counter, Gauge, Histogram — implementing the
|
|
5
|
-
* OpenMetrics text exposition format used by Prometheus, VictoriaMetrics and
|
|
6
|
-
* Grafana Agent.
|
|
7
|
-
*
|
|
8
|
-
* DESIGN PROPERTIES (non-negotiable):
|
|
9
|
-
* - Labels are multi-dimensional but bounded: cardinality is enforced by the
|
|
10
|
-
* CardinalityGuard (see ./cardinality.ts). This module does NOT enforce
|
|
11
|
-
* limits — that is the responsibility of the Registry.
|
|
12
|
-
* - All recording APIs are synchronous and side-effect-free (no I/O).
|
|
13
|
-
* - Counter is monotonic: a `reset()` is provided only for tests.
|
|
14
|
-
* - Gauge supports `inc/dec/set`.
|
|
15
|
-
* - Histogram is bucketed with `le` semantics (less-or-equal upper bound)
|
|
16
|
-
* and accumulates `+Inf` bucket implicitly via `count`.
|
|
17
|
-
*
|
|
18
|
-
* The metric *name* is what is exported. Label *names* must match `[a-zA-Z_]
|
|
19
|
-
* [a-zA-Z0-9_]*` and label *values* are UTF-8 strings (escaped on render).
|
|
20
|
-
*
|
|
21
|
-
* Refs:
|
|
22
|
-
* - https://prometheus.io/docs/instrumenting/exposition_formats/
|
|
23
|
-
* - https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md
|
|
24
|
-
*/
|
|
25
|
-
export type MetricKind = "counter" | "gauge" | "histogram";
|
|
26
|
-
export type Labels = Readonly<Record<string, string>>;
|
|
27
|
-
export interface MetricMeta {
|
|
28
|
-
/** Metric name (snake_case, prom convention). */
|
|
29
|
-
readonly name: string;
|
|
30
|
-
/** Help text shown on /metrics output (`# HELP` line). */
|
|
31
|
-
readonly help: string;
|
|
32
|
-
/** Type marker (`# TYPE` line). */
|
|
33
|
-
readonly kind: MetricKind;
|
|
34
|
-
/** Allowed label keys. If empty, the metric has no labels. */
|
|
35
|
-
readonly labelKeys: readonly string[];
|
|
36
|
-
/** Optional unit suffix per OpenMetrics (e.g. "seconds", "bytes"). */
|
|
37
|
-
readonly unit?: string;
|
|
38
|
-
}
|
|
39
|
-
export interface CounterSample {
|
|
40
|
-
labels: Labels;
|
|
41
|
-
value: number;
|
|
42
|
-
}
|
|
43
|
-
export interface GaugeSample {
|
|
44
|
-
labels: Labels;
|
|
45
|
-
value: number;
|
|
46
|
-
}
|
|
47
|
-
export interface HistogramSample {
|
|
48
|
-
labels: Labels;
|
|
49
|
-
/** Bucket boundaries (sorted ascending), excluding +Inf. */
|
|
50
|
-
buckets: readonly number[];
|
|
51
|
-
/** Cumulative counts per bucket (parallel to `buckets`). */
|
|
52
|
-
bucketCounts: number[];
|
|
53
|
-
/** Total observations (== count of +Inf bucket). */
|
|
54
|
-
count: number;
|
|
55
|
-
/** Sum of observed values. */
|
|
56
|
-
sum: number;
|
|
57
|
-
}
|
|
58
|
-
export declare function validateLabelName(name: string): void;
|
|
59
|
-
/** Stable string key for a label set (canonical form). */
|
|
60
|
-
export declare function labelsKey(labels: Labels): string;
|
|
61
|
-
/** Escape a label value per OpenMetrics spec (backslash, double-quote, newline). */
|
|
62
|
-
export declare function escapeLabelValue(v: string): string;
|
|
63
|
-
/** Filter a labels object to only the allowed keys; missing keys default to "". */
|
|
64
|
-
export declare function normalizeLabels(labels: Labels, allowed: readonly string[]): Labels;
|
|
65
|
-
/**
|
|
66
|
-
* Monotonic counter. Use for events that only go up (requests, errors, bytes).
|
|
67
|
-
*/
|
|
68
|
-
export declare class Counter {
|
|
69
|
-
readonly meta: MetricMeta;
|
|
70
|
-
private readonly values;
|
|
71
|
-
constructor(meta: Omit<MetricMeta, "kind">);
|
|
72
|
-
inc(labels?: Labels, delta?: number): void;
|
|
73
|
-
/** Get the current value for a specific label set (0 if absent). */
|
|
74
|
-
get(labels?: Labels): number;
|
|
75
|
-
/** Test-only: clear all observations. */
|
|
76
|
-
reset(): void;
|
|
77
|
-
/** Snapshot — used by the exporter. */
|
|
78
|
-
collect(): CounterSample[];
|
|
79
|
-
/** Number of distinct label series tracked. */
|
|
80
|
-
get seriesCount(): number;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Gauge — value that goes up and down (queue length, memory, in-flight count).
|
|
84
|
-
*/
|
|
85
|
-
export declare class Gauge {
|
|
86
|
-
readonly meta: MetricMeta;
|
|
87
|
-
private readonly values;
|
|
88
|
-
constructor(meta: Omit<MetricMeta, "kind">);
|
|
89
|
-
set(labels: Labels, value: number): void;
|
|
90
|
-
set(value: number): void;
|
|
91
|
-
inc(labels?: Labels, delta?: number): void;
|
|
92
|
-
dec(labels?: Labels, delta?: number): void;
|
|
93
|
-
get(labels?: Labels): number;
|
|
94
|
-
reset(): void;
|
|
95
|
-
collect(): GaugeSample[];
|
|
96
|
-
get seriesCount(): number;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Histogram — observations bucketed by upper bound. Used for latencies and
|
|
100
|
-
* sizes. Follows Prometheus `_bucket{le="..."}` conventions.
|
|
101
|
-
*/
|
|
102
|
-
export declare class Histogram {
|
|
103
|
-
readonly meta: MetricMeta;
|
|
104
|
-
readonly buckets: readonly number[];
|
|
105
|
-
private readonly entries;
|
|
106
|
-
constructor(meta: Omit<MetricMeta, "kind">, buckets: readonly number[]);
|
|
107
|
-
observe(labels: Labels, value: number): void;
|
|
108
|
-
observe(value: number): void;
|
|
109
|
-
reset(): void;
|
|
110
|
-
collect(): HistogramSample[];
|
|
111
|
-
get seriesCount(): number;
|
|
112
|
-
}
|
|
113
|
-
export declare const DURATION_BUCKETS_SECONDS: readonly number[];
|
|
114
|
-
export declare const RESULT_COUNT_BUCKETS: readonly number[];
|
|
115
|
-
export declare const SIZE_BUCKETS_BYTES: readonly number[];
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/observability/types.ts — Prometheus / OpenMetrics metric primitives (T1).
|
|
3
|
-
*
|
|
4
|
-
* Provides three core types — Counter, Gauge, Histogram — implementing the
|
|
5
|
-
* OpenMetrics text exposition format used by Prometheus, VictoriaMetrics and
|
|
6
|
-
* Grafana Agent.
|
|
7
|
-
*
|
|
8
|
-
* DESIGN PROPERTIES (non-negotiable):
|
|
9
|
-
* - Labels are multi-dimensional but bounded: cardinality is enforced by the
|
|
10
|
-
* CardinalityGuard (see ./cardinality.ts). This module does NOT enforce
|
|
11
|
-
* limits — that is the responsibility of the Registry.
|
|
12
|
-
* - All recording APIs are synchronous and side-effect-free (no I/O).
|
|
13
|
-
* - Counter is monotonic: a `reset()` is provided only for tests.
|
|
14
|
-
* - Gauge supports `inc/dec/set`.
|
|
15
|
-
* - Histogram is bucketed with `le` semantics (less-or-equal upper bound)
|
|
16
|
-
* and accumulates `+Inf` bucket implicitly via `count`.
|
|
17
|
-
*
|
|
18
|
-
* The metric *name* is what is exported. Label *names* must match `[a-zA-Z_]
|
|
19
|
-
* [a-zA-Z0-9_]*` and label *values* are UTF-8 strings (escaped on render).
|
|
20
|
-
*
|
|
21
|
-
* Refs:
|
|
22
|
-
* - https://prometheus.io/docs/instrumenting/exposition_formats/
|
|
23
|
-
* - https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md
|
|
24
|
-
*/
|
|
25
|
-
// ─── Label helpers ───────────────────────────────────────────────────────────
|
|
26
|
-
const LABEL_NAME_RE = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
27
|
-
export function validateLabelName(name) {
|
|
28
|
-
if (!LABEL_NAME_RE.test(name)) {
|
|
29
|
-
throw new Error(`invalid label name: ${JSON.stringify(name)}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/** Stable string key for a label set (canonical form). */
|
|
33
|
-
export function labelsKey(labels) {
|
|
34
|
-
const keys = Object.keys(labels).sort();
|
|
35
|
-
if (keys.length === 0)
|
|
36
|
-
return "";
|
|
37
|
-
const parts = [];
|
|
38
|
-
for (const k of keys) {
|
|
39
|
-
parts.push(`${k}="${escapeLabelValue(labels[k] ?? "")}"`);
|
|
40
|
-
}
|
|
41
|
-
return parts.join(",");
|
|
42
|
-
}
|
|
43
|
-
/** Escape a label value per OpenMetrics spec (backslash, double-quote, newline). */
|
|
44
|
-
export function escapeLabelValue(v) {
|
|
45
|
-
return v.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/"/g, '\\"');
|
|
46
|
-
}
|
|
47
|
-
/** Filter a labels object to only the allowed keys; missing keys default to "". */
|
|
48
|
-
export function normalizeLabels(labels, allowed) {
|
|
49
|
-
const out = {};
|
|
50
|
-
for (const k of allowed) {
|
|
51
|
-
const v = labels[k];
|
|
52
|
-
out[k] = typeof v === "string" ? v : "";
|
|
53
|
-
}
|
|
54
|
-
return Object.freeze(out);
|
|
55
|
-
}
|
|
56
|
-
// ─── Counter ─────────────────────────────────────────────────────────────────
|
|
57
|
-
/**
|
|
58
|
-
* Monotonic counter. Use for events that only go up (requests, errors, bytes).
|
|
59
|
-
*/
|
|
60
|
-
export class Counter {
|
|
61
|
-
meta;
|
|
62
|
-
values = new Map();
|
|
63
|
-
constructor(meta) {
|
|
64
|
-
for (const k of meta.labelKeys)
|
|
65
|
-
validateLabelName(k);
|
|
66
|
-
this.meta = { ...meta, kind: "counter" };
|
|
67
|
-
}
|
|
68
|
-
inc(labels = {}, delta = 1) {
|
|
69
|
-
if (delta < 0 || !Number.isFinite(delta)) {
|
|
70
|
-
throw new Error(`counter increment must be a non-negative finite number, got ${delta}`);
|
|
71
|
-
}
|
|
72
|
-
const norm = normalizeLabels(labels, this.meta.labelKeys);
|
|
73
|
-
const key = labelsKey(norm);
|
|
74
|
-
const entry = this.values.get(key);
|
|
75
|
-
if (entry) {
|
|
76
|
-
entry.value += delta;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
this.values.set(key, { labels: norm, value: delta });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/** Get the current value for a specific label set (0 if absent). */
|
|
83
|
-
get(labels = {}) {
|
|
84
|
-
const norm = normalizeLabels(labels, this.meta.labelKeys);
|
|
85
|
-
const key = labelsKey(norm);
|
|
86
|
-
return this.values.get(key)?.value ?? 0;
|
|
87
|
-
}
|
|
88
|
-
/** Test-only: clear all observations. */
|
|
89
|
-
reset() {
|
|
90
|
-
this.values.clear();
|
|
91
|
-
}
|
|
92
|
-
/** Snapshot — used by the exporter. */
|
|
93
|
-
collect() {
|
|
94
|
-
const out = [];
|
|
95
|
-
for (const e of this.values.values()) {
|
|
96
|
-
out.push({ labels: e.labels, value: e.value });
|
|
97
|
-
}
|
|
98
|
-
return out;
|
|
99
|
-
}
|
|
100
|
-
/** Number of distinct label series tracked. */
|
|
101
|
-
get seriesCount() {
|
|
102
|
-
return this.values.size;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// ─── Gauge ───────────────────────────────────────────────────────────────────
|
|
106
|
-
/**
|
|
107
|
-
* Gauge — value that goes up and down (queue length, memory, in-flight count).
|
|
108
|
-
*/
|
|
109
|
-
export class Gauge {
|
|
110
|
-
meta;
|
|
111
|
-
values = new Map();
|
|
112
|
-
constructor(meta) {
|
|
113
|
-
for (const k of meta.labelKeys)
|
|
114
|
-
validateLabelName(k);
|
|
115
|
-
this.meta = { ...meta, kind: "gauge" };
|
|
116
|
-
}
|
|
117
|
-
set(labelsOrValue, maybeValue) {
|
|
118
|
-
const { labels, value } = typeof labelsOrValue === "number"
|
|
119
|
-
? { labels: {}, value: labelsOrValue }
|
|
120
|
-
: { labels: labelsOrValue, value: maybeValue };
|
|
121
|
-
if (!Number.isFinite(value)) {
|
|
122
|
-
throw new Error(`gauge value must be finite, got ${value}`);
|
|
123
|
-
}
|
|
124
|
-
const norm = normalizeLabels(labels, this.meta.labelKeys);
|
|
125
|
-
const key = labelsKey(norm);
|
|
126
|
-
this.values.set(key, { labels: norm, value });
|
|
127
|
-
}
|
|
128
|
-
inc(labels = {}, delta = 1) {
|
|
129
|
-
const cur = this.get(labels);
|
|
130
|
-
this.set(labels, cur + delta);
|
|
131
|
-
}
|
|
132
|
-
dec(labels = {}, delta = 1) {
|
|
133
|
-
const cur = this.get(labels);
|
|
134
|
-
this.set(labels, cur - delta);
|
|
135
|
-
}
|
|
136
|
-
get(labels = {}) {
|
|
137
|
-
const norm = normalizeLabels(labels, this.meta.labelKeys);
|
|
138
|
-
return this.values.get(labelsKey(norm))?.value ?? 0;
|
|
139
|
-
}
|
|
140
|
-
reset() {
|
|
141
|
-
this.values.clear();
|
|
142
|
-
}
|
|
143
|
-
collect() {
|
|
144
|
-
const out = [];
|
|
145
|
-
for (const e of this.values.values()) {
|
|
146
|
-
out.push({ labels: e.labels, value: e.value });
|
|
147
|
-
}
|
|
148
|
-
return out;
|
|
149
|
-
}
|
|
150
|
-
get seriesCount() {
|
|
151
|
-
return this.values.size;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// ─── Histogram ───────────────────────────────────────────────────────────────
|
|
155
|
-
/**
|
|
156
|
-
* Histogram — observations bucketed by upper bound. Used for latencies and
|
|
157
|
-
* sizes. Follows Prometheus `_bucket{le="..."}` conventions.
|
|
158
|
-
*/
|
|
159
|
-
export class Histogram {
|
|
160
|
-
meta;
|
|
161
|
-
buckets;
|
|
162
|
-
entries = new Map();
|
|
163
|
-
constructor(meta, buckets) {
|
|
164
|
-
for (const k of meta.labelKeys)
|
|
165
|
-
validateLabelName(k);
|
|
166
|
-
if (buckets.length === 0) {
|
|
167
|
-
throw new Error("histogram requires at least one bucket boundary");
|
|
168
|
-
}
|
|
169
|
-
// Buckets must be strictly increasing and finite.
|
|
170
|
-
for (let i = 0; i < buckets.length; i++) {
|
|
171
|
-
const b = buckets[i];
|
|
172
|
-
if (!Number.isFinite(b)) {
|
|
173
|
-
throw new Error(`bucket ${i} must be finite, got ${b}`);
|
|
174
|
-
}
|
|
175
|
-
if (i > 0 && b <= buckets[i - 1]) {
|
|
176
|
-
throw new Error(`buckets must be strictly increasing (idx=${i})`);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
this.buckets = Object.freeze([...buckets]);
|
|
180
|
-
this.meta = { ...meta, kind: "histogram" };
|
|
181
|
-
}
|
|
182
|
-
observe(labelsOrValue, maybeValue) {
|
|
183
|
-
const { labels, value } = typeof labelsOrValue === "number"
|
|
184
|
-
? { labels: {}, value: labelsOrValue }
|
|
185
|
-
: { labels: labelsOrValue, value: maybeValue };
|
|
186
|
-
if (!Number.isFinite(value)) {
|
|
187
|
-
return; // silently ignore NaN/Inf — never block hot path
|
|
188
|
-
}
|
|
189
|
-
const norm = normalizeLabels(labels, this.meta.labelKeys);
|
|
190
|
-
const key = labelsKey(norm);
|
|
191
|
-
let entry = this.entries.get(key);
|
|
192
|
-
if (!entry) {
|
|
193
|
-
entry = {
|
|
194
|
-
labels: norm,
|
|
195
|
-
bucketCounts: new Array(this.buckets.length).fill(0),
|
|
196
|
-
count: 0,
|
|
197
|
-
sum: 0,
|
|
198
|
-
};
|
|
199
|
-
this.entries.set(key, entry);
|
|
200
|
-
}
|
|
201
|
-
entry.count += 1;
|
|
202
|
-
entry.sum += value;
|
|
203
|
-
for (let i = 0; i < this.buckets.length; i++) {
|
|
204
|
-
if (value <= this.buckets[i])
|
|
205
|
-
entry.bucketCounts[i] += 1;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
reset() {
|
|
209
|
-
this.entries.clear();
|
|
210
|
-
}
|
|
211
|
-
collect() {
|
|
212
|
-
const out = [];
|
|
213
|
-
for (const e of this.entries.values()) {
|
|
214
|
-
out.push({
|
|
215
|
-
labels: e.labels,
|
|
216
|
-
buckets: this.buckets,
|
|
217
|
-
bucketCounts: [...e.bucketCounts],
|
|
218
|
-
count: e.count,
|
|
219
|
-
sum: e.sum,
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
return out;
|
|
223
|
-
}
|
|
224
|
-
get seriesCount() {
|
|
225
|
-
return this.entries.size;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
// ─── Common bucket presets ───────────────────────────────────────────────────
|
|
229
|
-
export const DURATION_BUCKETS_SECONDS = Object.freeze([
|
|
230
|
-
0.001, 0.01, 0.1, 0.5, 1, 5,
|
|
231
|
-
]);
|
|
232
|
-
export const RESULT_COUNT_BUCKETS = Object.freeze([1, 5, 10, 20, 50, 100]);
|
|
233
|
-
export const SIZE_BUCKETS_BYTES = Object.freeze([
|
|
234
|
-
256, 1024, 4096, 16384, 65536, 262144, 1048576,
|
|
235
|
-
]);
|
package/dist/observability.d.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* observability.ts — F10 Phase A endpoints (Prod Health)
|
|
3
|
-
*
|
|
4
|
-
* Adds three read-only endpoints under `/api/observability/*`:
|
|
5
|
-
*
|
|
6
|
-
* GET /api/observability/health
|
|
7
|
-
* Same shape as /api/health PLUS delta vs ~24h ago for key metrics
|
|
8
|
-
* (chunks.total, dbSizeMB, knowledgeGraph.entities, knowledgeGraph.relations).
|
|
9
|
-
* The 24h snapshot is cached in-memory and refreshed once per call when older
|
|
10
|
-
* than ~24h; first call after process start has no delta available.
|
|
11
|
-
*
|
|
12
|
-
* GET /api/observability/recent-ops?n=10
|
|
13
|
-
* Last N rows from ops_audit WHERE status IN ('failed','crashed') ORDER BY
|
|
14
|
-
* started_at DESC. Default n=10, max n=50.
|
|
15
|
-
*
|
|
16
|
-
* GET /api/observability/canary-tail?n=3
|
|
17
|
-
* Last N entries from /var/log/nox-schema-invariants.log (F05 cron output).
|
|
18
|
-
* Default n=3, max n=20. Empty list if file missing.
|
|
19
|
-
*
|
|
20
|
-
* Spec: specs/2026-05-01-F10-observability-dashboard.md (refresh 2026-05-21)
|
|
21
|
-
* Status: Phase A implementation-ready
|
|
22
|
-
*
|
|
23
|
-
* Module design:
|
|
24
|
-
* - Exports three handler functions invoked from the api-server.ts switch.
|
|
25
|
-
* - Handlers do NOT touch ServerResponse directly; they return plain objects
|
|
26
|
-
* and a status code. Caller (api-server.ts) wraps with the existing json()
|
|
27
|
-
* helper. This keeps boundary thin and unit-testable.
|
|
28
|
-
* - The 24h snapshot cache lives at module scope (single-process server),
|
|
29
|
-
* reset on import. Test harness imports a fresh module via cache-bust to
|
|
30
|
-
* reset state.
|
|
31
|
-
*/
|
|
32
|
-
import type { Database } from "better-sqlite3";
|
|
33
|
-
interface HealthSnapshot {
|
|
34
|
-
taken_at_ms: number;
|
|
35
|
-
chunks_total: number;
|
|
36
|
-
db_size_mb: number;
|
|
37
|
-
kg_entities: number;
|
|
38
|
-
kg_relations: number;
|
|
39
|
-
}
|
|
40
|
-
/** Read live metrics from DB into a snapshot shape. */
|
|
41
|
-
declare function takeSnapshot(db: Database): HealthSnapshot;
|
|
42
|
-
/**
|
|
43
|
-
* Returns current snapshot AND the most recent snapshot that is older than
|
|
44
|
-
* `minAgeMs` (default 24h). When no qualifying historical snapshot exists,
|
|
45
|
-
* `historical` is null and dashboard renders deltas as "—".
|
|
46
|
-
*
|
|
47
|
-
* Cache logic: keep one snapshot at module scope. When the cached snapshot is
|
|
48
|
-
* older than minAgeMs, return it as `historical` and replace it with `current`
|
|
49
|
-
* for next time. This converges to a rolling 24h window without a separate cron.
|
|
50
|
-
*/
|
|
51
|
-
export declare function snapshotPair(db: Database, minAgeMs?: number): {
|
|
52
|
-
current: HealthSnapshot;
|
|
53
|
-
historical: HealthSnapshot | null;
|
|
54
|
-
};
|
|
55
|
-
/** Exposed for tests — reset the snapshot cache between cases. */
|
|
56
|
-
export declare function _resetSnapshotCache(): void;
|
|
57
|
-
export type HealthLevel = "green" | "yellow" | "red";
|
|
58
|
-
export interface HealthIndicators {
|
|
59
|
-
vector: HealthLevel;
|
|
60
|
-
canary: HealthLevel;
|
|
61
|
-
recentOps: HealthLevel;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Vector coverage health:
|
|
65
|
-
* green — embedded == total AND orphans == 0
|
|
66
|
-
* yellow — embedded < total by <= 5 chunks OR orphans <= 5
|
|
67
|
-
* red — anything worse
|
|
68
|
-
*/
|
|
69
|
-
export declare function vectorHealth(embedded: number, total: number, orphans: number): HealthLevel;
|
|
70
|
-
/**
|
|
71
|
-
* Canary log health based on age of last entry:
|
|
72
|
-
* green — last entry < 20 minutes ago (cron runs every 15min)
|
|
73
|
-
* yellow — 20 < age < 60 minutes
|
|
74
|
-
* red — age >= 60 minutes OR no log present
|
|
75
|
-
*/
|
|
76
|
-
export declare function canaryHealth(lastEntryAgeMs: number | null): HealthLevel;
|
|
77
|
-
/**
|
|
78
|
-
* Recent ops health:
|
|
79
|
-
* green — zero failed/crashed in last 24h
|
|
80
|
-
* yellow — 1–3 failed/crashed (transient)
|
|
81
|
-
* red — 4+ failed/crashed (pattern)
|
|
82
|
-
*/
|
|
83
|
-
export declare function recentOpsHealth(failedCount: number): HealthLevel;
|
|
84
|
-
export interface ObsHealthResponse {
|
|
85
|
-
current: HealthSnapshot & {
|
|
86
|
-
vector_coverage: {
|
|
87
|
-
embedded: number;
|
|
88
|
-
total: number;
|
|
89
|
-
orphans: number;
|
|
90
|
-
};
|
|
91
|
-
salience_mode: string;
|
|
92
|
-
};
|
|
93
|
-
delta_24h: {
|
|
94
|
-
chunks: number | null;
|
|
95
|
-
db_size_mb: number | null;
|
|
96
|
-
kg_entities: number | null;
|
|
97
|
-
kg_relations: number | null;
|
|
98
|
-
};
|
|
99
|
-
indicators: HealthIndicators;
|
|
100
|
-
generated_at_ms: number;
|
|
101
|
-
}
|
|
102
|
-
export declare function handleObsHealth(db: Database, opts?: {
|
|
103
|
-
canaryLogPath?: string;
|
|
104
|
-
lastFailedOps24h?: number;
|
|
105
|
-
}): ObsHealthResponse;
|
|
106
|
-
export interface RecentOpRow {
|
|
107
|
-
id: number;
|
|
108
|
-
op_name: string;
|
|
109
|
-
status: string;
|
|
110
|
-
db_source: string;
|
|
111
|
-
started_at_ms: number;
|
|
112
|
-
duration_ms: number | null;
|
|
113
|
-
error_message: string | null;
|
|
114
|
-
}
|
|
115
|
-
export declare function handleObsRecentOps(db: Database, n?: number): RecentOpRow[];
|
|
116
|
-
export interface CanaryLine {
|
|
117
|
-
raw: string;
|
|
118
|
-
timestamp: string | null;
|
|
119
|
-
ok: boolean;
|
|
120
|
-
}
|
|
121
|
-
/** Parse a single canary log line; returns null fields on best-effort failure. */
|
|
122
|
-
export declare function parseCanaryLine(raw: string): CanaryLine;
|
|
123
|
-
export declare function handleObsCanaryTail(n?: number, opts?: {
|
|
124
|
-
canaryLogPath?: string;
|
|
125
|
-
}): CanaryLine[];
|
|
126
|
-
export declare const _internals: {
|
|
127
|
-
SNAPSHOT_TTL_MS: number;
|
|
128
|
-
takeSnapshot: typeof takeSnapshot;
|
|
129
|
-
CANARY_TS_RE: RegExp;
|
|
130
|
-
};
|
|
131
|
-
export {};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/plugins/nox-hooks/index.ts — T8: OpenClaw plugin entrypoint.
|
|
3
|
-
*
|
|
4
|
-
* OpenClaw lifecycle (see ~/Claude/Projetos/openclaw-vps/infra/CLAUDE.md):
|
|
5
|
-
* afterTurn(payload) → fires after each user/assistant turn
|
|
6
|
-
* sessionStart(meta) → fires once at session boot
|
|
7
|
-
* sessionEnd(summary) → fires at session close
|
|
8
|
-
*
|
|
9
|
-
* This plugin:
|
|
10
|
-
* 1. Constructs HookEvent from OpenClaw payload (role + content + meta).
|
|
11
|
-
* 2. Enqueues into the worker (non-blocking).
|
|
12
|
-
* 3. Never throws — failures are logged via the host's logger and
|
|
13
|
-
* reported as telemetry; the host turn is unaffected.
|
|
14
|
-
*
|
|
15
|
-
* The worker is created lazily on first afterTurn so the plugin loads
|
|
16
|
-
* even when NOX_HOOKS_ENABLED=0 (Layer 1 will reject the events cheaply).
|
|
17
|
-
*/
|
|
18
|
-
import { type IngestFn, type TelemetrySink } from "../../lib/hooks/pipeline.js";
|
|
19
|
-
import { loadConfig } from "../../lib/hooks/config.js";
|
|
20
|
-
/** Shape of OpenClaw afterTurn payload (subset we care about). */
|
|
21
|
-
export interface AfterTurnPayload {
|
|
22
|
-
role: string;
|
|
23
|
-
content?: string;
|
|
24
|
-
text?: string;
|
|
25
|
-
session_id?: string;
|
|
26
|
-
cwd?: string;
|
|
27
|
-
meta?: Record<string, string | number | boolean>;
|
|
28
|
-
}
|
|
29
|
-
export interface PluginDeps {
|
|
30
|
-
/** Where to send captured chunks. Must be wired at plugin install. */
|
|
31
|
-
ingest: IngestFn;
|
|
32
|
-
/** Telemetry sink (writes to agent_events). */
|
|
33
|
-
telemetry: TelemetrySink;
|
|
34
|
-
/** Override staged-A1 redact. Default = identity (T11 will swap). */
|
|
35
|
-
redact?: (s: string) => {
|
|
36
|
-
text: string;
|
|
37
|
-
redactionCount: number;
|
|
38
|
-
kinds: string[];
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export interface PluginHandle {
|
|
42
|
-
afterTurn(payload: AfterTurnPayload): {
|
|
43
|
-
accepted: boolean;
|
|
44
|
-
reason: string;
|
|
45
|
-
};
|
|
46
|
-
sessionStart(meta?: {
|
|
47
|
-
session_id?: string;
|
|
48
|
-
cwd?: string;
|
|
49
|
-
}): void;
|
|
50
|
-
sessionEnd(): Promise<void>;
|
|
51
|
-
/** Inspection for CLI/HTTP. */
|
|
52
|
-
inspect(): {
|
|
53
|
-
config: ReturnType<typeof loadConfig>;
|
|
54
|
-
queueDepth: number;
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Build a plugin handle. Worker starts on first afterTurn().
|
|
59
|
-
* Each plugin instance owns a single pipeline + worker.
|
|
60
|
-
*/
|
|
61
|
-
export declare function createPlugin(deps: PluginDeps): PluginHandle;
|