nox-mem 3.1.1 → 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 +1 -22
- 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/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/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/version.d.ts +0 -1
- package/dist/watch.d.ts +0 -8
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* G16 — File-based advisory lock for runExport / runImport (Wave G)
|
|
3
|
-
*
|
|
4
|
-
* BACKGROUND
|
|
5
|
-
* `runExport()` and `runImport()` in `staged-A2/edits/src/lib/archive/
|
|
6
|
-
* orchestrator.ts` are long-running (minutes for >1GB DB). Two concurrent
|
|
7
|
-
* runExport calls against the same output path race on:
|
|
8
|
-
* - manifest writes
|
|
9
|
-
* - encryption nonce reuse (CRITICAL — GCM nonce reuse breaks AES-GCM
|
|
10
|
-
* confidentiality + authenticity)
|
|
11
|
-
* - tar block boundaries
|
|
12
|
-
*
|
|
13
|
-
* THREAT (G16, R-A2-Orch-1)
|
|
14
|
-
* Two concurrent exports → corrupted archive OR (worse) AES-GCM nonce
|
|
15
|
-
* reuse if both runs share the same passphrase + salt.
|
|
16
|
-
*
|
|
17
|
-
* FIX
|
|
18
|
-
* File-based advisory lock written to `<output>.lock` at runExport start,
|
|
19
|
-
* removed on completion / failure. Manual lock-file pattern (works on all
|
|
20
|
-
* platforms — flock(2) on linux/mac when available, else exclusive
|
|
21
|
-
* O_CREAT|O_EXCL semantics). Includes PID + start-time JSON so a stale
|
|
22
|
-
* lock (process gone, or >30 min idle) can be safely broken.
|
|
23
|
-
*
|
|
24
|
-
* Lock file shape (`<output>.lock`, mode 0600):
|
|
25
|
-
* {
|
|
26
|
-
* "pid": 12345,
|
|
27
|
-
* "started_at_ms": 1716050000000,
|
|
28
|
-
* "hostname": "nox-vps-1",
|
|
29
|
-
* "op": "export",
|
|
30
|
-
* "v": 1
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* Behavior:
|
|
34
|
-
* - First caller writes lock with O_EXCL. If success, holds it.
|
|
35
|
-
* - Subsequent caller checks for existing lock:
|
|
36
|
-
* - If pid is alive AND started_at_ms within 30 min → 409 Conflict.
|
|
37
|
-
* - If pid is dead OR started_at_ms > 30 min ago → log WARN, break
|
|
38
|
-
* the stale lock, take it.
|
|
39
|
-
* - On crash mid-export, the lock persists until next caller breaks it
|
|
40
|
-
* by age. This is correct — we don't want to silently delete locks
|
|
41
|
-
* just because OS reused a pid.
|
|
42
|
-
*
|
|
43
|
-
* Backward compat:
|
|
44
|
-
* - Module is opt-in. Caller (orchestrator) wraps runExport with
|
|
45
|
-
* `withExportLock(outputPath, async () => runExport(...))`.
|
|
46
|
-
* - No changes to existing exports if module not adopted (forward
|
|
47
|
-
* migration path).
|
|
48
|
-
*/
|
|
49
|
-
import path from "node:path";
|
|
50
|
-
export interface LockMetadata {
|
|
51
|
-
pid: number;
|
|
52
|
-
started_at_ms: number;
|
|
53
|
-
hostname: string;
|
|
54
|
-
op: "export" | "import";
|
|
55
|
-
v: 1;
|
|
56
|
-
}
|
|
57
|
-
/** Default stale-after (ms). 30 minutes — covers typical 1-2GB exports. */
|
|
58
|
-
export declare const DEFAULT_STALE_MS: number;
|
|
59
|
-
export declare class ExportLockBusyError extends Error {
|
|
60
|
-
readonly status = 409;
|
|
61
|
-
readonly lockPath: string;
|
|
62
|
-
readonly heldBy: LockMetadata;
|
|
63
|
-
constructor(lockPath: string, heldBy: LockMetadata);
|
|
64
|
-
}
|
|
65
|
-
export interface AcquireLockOptions {
|
|
66
|
-
/** Stale threshold (ms). Default 30 min. */
|
|
67
|
-
staleMs?: number;
|
|
68
|
-
/** "export" or "import". Default "export". */
|
|
69
|
-
op?: "export" | "import";
|
|
70
|
-
/** WARN logger when breaking a stale lock. Default console.warn. */
|
|
71
|
-
onWarn?: (msg: string) => void;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Try to acquire an exclusive advisory lock for the given output path.
|
|
75
|
-
* Throws ExportLockBusyError when an active lock blocks acquisition.
|
|
76
|
-
*
|
|
77
|
-
* Returns a release handle. Caller MUST invoke `release()` (preferably in
|
|
78
|
-
* a `try/finally`).
|
|
79
|
-
*/
|
|
80
|
-
export declare function acquireExportLock(outputPath: string, opts?: AcquireLockOptions): Promise<{
|
|
81
|
-
release: () => Promise<void>;
|
|
82
|
-
lockPath: string;
|
|
83
|
-
}>;
|
|
84
|
-
/**
|
|
85
|
-
* Convenience wrapper. Acquires lock, runs fn, releases unconditionally.
|
|
86
|
-
*
|
|
87
|
-
* const result = await withExportLock(outputPath, () => runExport(...));
|
|
88
|
-
*/
|
|
89
|
-
export declare function withExportLock<T>(outputPath: string, fn: () => Promise<T>, opts?: AcquireLockOptions): Promise<T>;
|
|
90
|
-
/**
|
|
91
|
-
* Inspect a lock file without acquiring. Returns null when absent.
|
|
92
|
-
*/
|
|
93
|
-
export declare function inspectExportLock(outputPath: string): Promise<LockMetadata | null>;
|
|
94
|
-
/**
|
|
95
|
-
* Pure helper for tests / docs. Returns the canonical lock path.
|
|
96
|
-
*/
|
|
97
|
-
export declare function getLockPath(outputPath: string): string;
|
|
98
|
-
/**
|
|
99
|
-
* Pure helper — used to inspect file existence in scripts.
|
|
100
|
-
*/
|
|
101
|
-
export declare function lockExistsSync(outputPath: string): boolean;
|
|
102
|
-
export { path as _path };
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* G16 — File-based advisory lock for runExport / runImport (Wave G)
|
|
3
|
-
*
|
|
4
|
-
* BACKGROUND
|
|
5
|
-
* `runExport()` and `runImport()` in `staged-A2/edits/src/lib/archive/
|
|
6
|
-
* orchestrator.ts` are long-running (minutes for >1GB DB). Two concurrent
|
|
7
|
-
* runExport calls against the same output path race on:
|
|
8
|
-
* - manifest writes
|
|
9
|
-
* - encryption nonce reuse (CRITICAL — GCM nonce reuse breaks AES-GCM
|
|
10
|
-
* confidentiality + authenticity)
|
|
11
|
-
* - tar block boundaries
|
|
12
|
-
*
|
|
13
|
-
* THREAT (G16, R-A2-Orch-1)
|
|
14
|
-
* Two concurrent exports → corrupted archive OR (worse) AES-GCM nonce
|
|
15
|
-
* reuse if both runs share the same passphrase + salt.
|
|
16
|
-
*
|
|
17
|
-
* FIX
|
|
18
|
-
* File-based advisory lock written to `<output>.lock` at runExport start,
|
|
19
|
-
* removed on completion / failure. Manual lock-file pattern (works on all
|
|
20
|
-
* platforms — flock(2) on linux/mac when available, else exclusive
|
|
21
|
-
* O_CREAT|O_EXCL semantics). Includes PID + start-time JSON so a stale
|
|
22
|
-
* lock (process gone, or >30 min idle) can be safely broken.
|
|
23
|
-
*
|
|
24
|
-
* Lock file shape (`<output>.lock`, mode 0600):
|
|
25
|
-
* {
|
|
26
|
-
* "pid": 12345,
|
|
27
|
-
* "started_at_ms": 1716050000000,
|
|
28
|
-
* "hostname": "nox-vps-1",
|
|
29
|
-
* "op": "export",
|
|
30
|
-
* "v": 1
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* Behavior:
|
|
34
|
-
* - First caller writes lock with O_EXCL. If success, holds it.
|
|
35
|
-
* - Subsequent caller checks for existing lock:
|
|
36
|
-
* - If pid is alive AND started_at_ms within 30 min → 409 Conflict.
|
|
37
|
-
* - If pid is dead OR started_at_ms > 30 min ago → log WARN, break
|
|
38
|
-
* the stale lock, take it.
|
|
39
|
-
* - On crash mid-export, the lock persists until next caller breaks it
|
|
40
|
-
* by age. This is correct — we don't want to silently delete locks
|
|
41
|
-
* just because OS reused a pid.
|
|
42
|
-
*
|
|
43
|
-
* Backward compat:
|
|
44
|
-
* - Module is opt-in. Caller (orchestrator) wraps runExport with
|
|
45
|
-
* `withExportLock(outputPath, async () => runExport(...))`.
|
|
46
|
-
* - No changes to existing exports if module not adopted (forward
|
|
47
|
-
* migration path).
|
|
48
|
-
*/
|
|
49
|
-
import { promises as fs, existsSync } from "node:fs";
|
|
50
|
-
import path from "node:path";
|
|
51
|
-
import os from "node:os";
|
|
52
|
-
/** Default stale-after (ms). 30 minutes — covers typical 1-2GB exports. */
|
|
53
|
-
export const DEFAULT_STALE_MS = 30 * 60 * 1000;
|
|
54
|
-
// ── public errors ───────────────────────────────────────────────────────────
|
|
55
|
-
export class ExportLockBusyError extends Error {
|
|
56
|
-
status = 409;
|
|
57
|
-
lockPath;
|
|
58
|
-
heldBy;
|
|
59
|
-
constructor(lockPath, heldBy) {
|
|
60
|
-
super(`Export lock at ${lockPath} held by pid=${heldBy.pid} on host=${heldBy.hostname} (started ${new Date(heldBy.started_at_ms).toISOString()})`);
|
|
61
|
-
this.name = "ExportLockBusyError";
|
|
62
|
-
this.lockPath = lockPath;
|
|
63
|
-
this.heldBy = heldBy;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// ── helpers ────────────────────────────────────────────────────────────────
|
|
67
|
-
function lockPathFor(outputPath) {
|
|
68
|
-
return outputPath + ".lock";
|
|
69
|
-
}
|
|
70
|
-
function isAlive(pid) {
|
|
71
|
-
if (!Number.isFinite(pid) || pid <= 0)
|
|
72
|
-
return false;
|
|
73
|
-
try {
|
|
74
|
-
// signal 0 → "does pid exist" check (POSIX). Throws ESRCH if not.
|
|
75
|
-
process.kill(pid, 0);
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
const err = e;
|
|
80
|
-
if (err.code === "EPERM")
|
|
81
|
-
return true; // exists but we lack rights
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async function readLock(lockPath) {
|
|
86
|
-
try {
|
|
87
|
-
const raw = await fs.readFile(lockPath, "utf8");
|
|
88
|
-
const parsed = JSON.parse(raw);
|
|
89
|
-
if (parsed.v !== 1 || typeof parsed.pid !== "number")
|
|
90
|
-
return null;
|
|
91
|
-
return parsed;
|
|
92
|
-
}
|
|
93
|
-
catch (e) {
|
|
94
|
-
const err = e;
|
|
95
|
-
if (err.code === "ENOENT")
|
|
96
|
-
return null;
|
|
97
|
-
return null; // malformed — caller may opt to break it
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
async function writeLock(lockPath, meta, exclusive) {
|
|
101
|
-
const data = JSON.stringify(meta, null, 2);
|
|
102
|
-
// O_EXCL semantics via `flag: 'wx'`. If we want to overwrite stale, use 'w'.
|
|
103
|
-
await fs.writeFile(lockPath, data, {
|
|
104
|
-
encoding: "utf8",
|
|
105
|
-
flag: exclusive ? "wx" : "w",
|
|
106
|
-
mode: 0o600,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Try to acquire an exclusive advisory lock for the given output path.
|
|
111
|
-
* Throws ExportLockBusyError when an active lock blocks acquisition.
|
|
112
|
-
*
|
|
113
|
-
* Returns a release handle. Caller MUST invoke `release()` (preferably in
|
|
114
|
-
* a `try/finally`).
|
|
115
|
-
*/
|
|
116
|
-
export async function acquireExportLock(outputPath, opts = {}) {
|
|
117
|
-
const lockPath = lockPathFor(outputPath);
|
|
118
|
-
const staleMs = opts.staleMs ?? DEFAULT_STALE_MS;
|
|
119
|
-
const op = opts.op ?? "export";
|
|
120
|
-
const meta = {
|
|
121
|
-
pid: process.pid,
|
|
122
|
-
started_at_ms: Date.now(),
|
|
123
|
-
hostname: os.hostname(),
|
|
124
|
-
op,
|
|
125
|
-
v: 1,
|
|
126
|
-
};
|
|
127
|
-
// 1. Try exclusive write.
|
|
128
|
-
try {
|
|
129
|
-
await writeLock(lockPath, meta, true);
|
|
130
|
-
return { release: () => releaseLock(lockPath, meta), lockPath };
|
|
131
|
-
}
|
|
132
|
-
catch (e) {
|
|
133
|
-
const err = e;
|
|
134
|
-
if (err.code !== "EEXIST")
|
|
135
|
-
throw err;
|
|
136
|
-
}
|
|
137
|
-
// 2. Lock exists. Decide: stale or active?
|
|
138
|
-
const existing = await readLock(lockPath);
|
|
139
|
-
if (existing) {
|
|
140
|
-
const ageMs = Date.now() - existing.started_at_ms;
|
|
141
|
-
const stale = ageMs > staleMs || !isAlive(existing.pid);
|
|
142
|
-
if (!stale) {
|
|
143
|
-
throw new ExportLockBusyError(lockPath, existing);
|
|
144
|
-
}
|
|
145
|
-
(opts.onWarn ?? console.warn)(`[export-lock] Breaking stale lock at ${lockPath} (pid=${existing.pid} alive=${isAlive(existing.pid)} ageMs=${ageMs})`);
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
(opts.onWarn ?? console.warn)(`[export-lock] Lock file at ${lockPath} unreadable/malformed — breaking it`);
|
|
149
|
-
}
|
|
150
|
-
// 3. Break stale + take.
|
|
151
|
-
await writeLock(lockPath, meta, false);
|
|
152
|
-
return { release: () => releaseLock(lockPath, meta), lockPath };
|
|
153
|
-
}
|
|
154
|
-
async function releaseLock(lockPath, expectedMeta) {
|
|
155
|
-
// Defensive: only delete if we still own it. Re-read first.
|
|
156
|
-
try {
|
|
157
|
-
const current = await readLock(lockPath);
|
|
158
|
-
if (current &&
|
|
159
|
-
current.pid === expectedMeta.pid &&
|
|
160
|
-
current.started_at_ms === expectedMeta.started_at_ms) {
|
|
161
|
-
await fs.unlink(lockPath);
|
|
162
|
-
}
|
|
163
|
-
// else: someone else broke + reused our lock — leave it alone.
|
|
164
|
-
}
|
|
165
|
-
catch {
|
|
166
|
-
// Best-effort; file system may have been cleaned by another process.
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Convenience wrapper. Acquires lock, runs fn, releases unconditionally.
|
|
171
|
-
*
|
|
172
|
-
* const result = await withExportLock(outputPath, () => runExport(...));
|
|
173
|
-
*/
|
|
174
|
-
export async function withExportLock(outputPath, fn, opts = {}) {
|
|
175
|
-
const handle = await acquireExportLock(outputPath, opts);
|
|
176
|
-
try {
|
|
177
|
-
return await fn();
|
|
178
|
-
}
|
|
179
|
-
finally {
|
|
180
|
-
await handle.release();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Inspect a lock file without acquiring. Returns null when absent.
|
|
185
|
-
*/
|
|
186
|
-
export async function inspectExportLock(outputPath) {
|
|
187
|
-
return readLock(lockPathFor(outputPath));
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Pure helper for tests / docs. Returns the canonical lock path.
|
|
191
|
-
*/
|
|
192
|
-
export function getLockPath(outputPath) {
|
|
193
|
-
return lockPathFor(outputPath);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Pure helper — used to inspect file existence in scripts.
|
|
197
|
-
*/
|
|
198
|
-
export function lockExistsSync(outputPath) {
|
|
199
|
-
return existsSync(lockPathFor(outputPath));
|
|
200
|
-
}
|
|
201
|
-
// Re-export for namespace cleanliness.
|
|
202
|
-
export { path as _path };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T1 — Archive format module (TAR + gzip).
|
|
3
|
-
*
|
|
4
|
-
* Pure-Node ustar implementation. No external tar dep — keeps staged-A2 buildable
|
|
5
|
-
* without npm install. tar produced here is `tar -tzf` compatible (validated in tests).
|
|
6
|
-
*
|
|
7
|
-
* Streaming surface area is implemented via async iterables + Node Streams. We
|
|
8
|
-
* deliberately keep public APIs Buffer-based for in-memory tests; the real CLI
|
|
9
|
-
* (T10) will wrap these with `fs.createReadStream`/`createWriteStream` pipes.
|
|
10
|
-
*/
|
|
11
|
-
import { Readable } from "node:stream";
|
|
12
|
-
import { ArchiveEntry } from "./types.js";
|
|
13
|
-
/** Pack archive entries into a single gzipped tar Buffer. */
|
|
14
|
-
export declare function packArchive(entries: ArchiveEntry[]): Buffer;
|
|
15
|
-
/** Unpack a gzipped tar Buffer into a list of entries. */
|
|
16
|
-
export declare function unpackArchive(gzipped: Buffer): ArchiveEntry[];
|
|
17
|
-
/** List entry names without materializing contents. */
|
|
18
|
-
export declare function listArchive(gzipped: Buffer): string[];
|
|
19
|
-
/** Streaming pack — for very large archives. Returns a Readable of gzip bytes. */
|
|
20
|
-
export declare function packArchiveStream(entries: AsyncIterable<ArchiveEntry>): Readable;
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T1 — Archive format module (TAR + gzip).
|
|
3
|
-
*
|
|
4
|
-
* Pure-Node ustar implementation. No external tar dep — keeps staged-A2 buildable
|
|
5
|
-
* without npm install. tar produced here is `tar -tzf` compatible (validated in tests).
|
|
6
|
-
*
|
|
7
|
-
* Streaming surface area is implemented via async iterables + Node Streams. We
|
|
8
|
-
* deliberately keep public APIs Buffer-based for in-memory tests; the real CLI
|
|
9
|
-
* (T10) will wrap these with `fs.createReadStream`/`createWriteStream` pipes.
|
|
10
|
-
*/
|
|
11
|
-
import { createGzip, gunzipSync, gzipSync } from "node:zlib";
|
|
12
|
-
import { Readable } from "node:stream";
|
|
13
|
-
import { ArchiveFormatError } from "./types.js";
|
|
14
|
-
const BLOCK_SIZE = 512;
|
|
15
|
-
const ZERO_BLOCK = Buffer.alloc(BLOCK_SIZE);
|
|
16
|
-
/** Pack archive entries into a single gzipped tar Buffer. */
|
|
17
|
-
export function packArchive(entries) {
|
|
18
|
-
if (entries.length === 0) {
|
|
19
|
-
throw new ArchiveFormatError("packArchive: refuse to pack empty archive");
|
|
20
|
-
}
|
|
21
|
-
const parts = [];
|
|
22
|
-
for (const entry of entries) {
|
|
23
|
-
parts.push(buildTarBlock(entry));
|
|
24
|
-
}
|
|
25
|
-
// Two trailing zero blocks terminate the tar stream (POSIX).
|
|
26
|
-
parts.push(ZERO_BLOCK, ZERO_BLOCK);
|
|
27
|
-
const tarBuf = Buffer.concat(parts);
|
|
28
|
-
return gzipSync(tarBuf);
|
|
29
|
-
}
|
|
30
|
-
/** Unpack a gzipped tar Buffer into a list of entries. */
|
|
31
|
-
export function unpackArchive(gzipped) {
|
|
32
|
-
const tarBuf = gunzipSync(gzipped);
|
|
33
|
-
return parseTarBlocks(tarBuf);
|
|
34
|
-
}
|
|
35
|
-
/** List entry names without materializing contents. */
|
|
36
|
-
export function listArchive(gzipped) {
|
|
37
|
-
const entries = unpackArchive(gzipped);
|
|
38
|
-
return entries.map((e) => e.name);
|
|
39
|
-
}
|
|
40
|
-
/** Streaming pack — for very large archives. Returns a Readable of gzip bytes. */
|
|
41
|
-
export function packArchiveStream(entries) {
|
|
42
|
-
let emitted = false;
|
|
43
|
-
const reader = Readable.from((async function* () {
|
|
44
|
-
for await (const e of entries) {
|
|
45
|
-
emitted = true;
|
|
46
|
-
yield buildTarBlock(e);
|
|
47
|
-
}
|
|
48
|
-
if (!emitted) {
|
|
49
|
-
throw new ArchiveFormatError("packArchiveStream: empty");
|
|
50
|
-
}
|
|
51
|
-
yield ZERO_BLOCK;
|
|
52
|
-
yield ZERO_BLOCK;
|
|
53
|
-
})());
|
|
54
|
-
const gzip = createGzip();
|
|
55
|
-
return reader.pipe(gzip);
|
|
56
|
-
}
|
|
57
|
-
// -- internals ---------------------------------------------------------------
|
|
58
|
-
function buildTarBlock(entry) {
|
|
59
|
-
const name = entry.name;
|
|
60
|
-
if (name.length === 0) {
|
|
61
|
-
throw new ArchiveFormatError("Empty entry name");
|
|
62
|
-
}
|
|
63
|
-
if (name.length > 100) {
|
|
64
|
-
throw new ArchiveFormatError(`Entry name too long for ustar (${name.length} > 100): ${name}. ` +
|
|
65
|
-
`Long-name extension not implemented in v1; rename or shorten paths.`);
|
|
66
|
-
}
|
|
67
|
-
const content = entry.content;
|
|
68
|
-
if (content.length > 0o77777777777) {
|
|
69
|
-
throw new ArchiveFormatError(`Entry too large for ustar: ${entry.name}`);
|
|
70
|
-
}
|
|
71
|
-
const mtime = entry.mtime ?? Math.floor(Date.now() / 1000);
|
|
72
|
-
const mode = entry.mode ?? 0o644;
|
|
73
|
-
const header = Buffer.alloc(BLOCK_SIZE);
|
|
74
|
-
// name (100)
|
|
75
|
-
header.write(name, 0, 100, "utf8");
|
|
76
|
-
// mode (8) — octal, null+space terminated per POSIX
|
|
77
|
-
header.write(padOctal(mode, 7) + "\0", 100, 8, "ascii");
|
|
78
|
-
// uid (8), gid (8)
|
|
79
|
-
header.write(padOctal(0, 7) + "\0", 108, 8, "ascii");
|
|
80
|
-
header.write(padOctal(0, 7) + "\0", 116, 8, "ascii");
|
|
81
|
-
// size (12)
|
|
82
|
-
header.write(padOctal(content.length, 11) + "\0", 124, 12, "ascii");
|
|
83
|
-
// mtime (12)
|
|
84
|
-
header.write(padOctal(mtime, 11) + "\0", 136, 12, "ascii");
|
|
85
|
-
// checksum placeholder (8 spaces)
|
|
86
|
-
header.write(" ", 148, 8, "ascii");
|
|
87
|
-
// typeflag '0' (regular file)
|
|
88
|
-
header.write("0", 156, 1, "ascii");
|
|
89
|
-
// linkname (100) — empty
|
|
90
|
-
// magic + version "ustar\000" + "00"
|
|
91
|
-
header.write("ustar\0", 257, 6, "ascii");
|
|
92
|
-
header.write("00", 263, 2, "ascii");
|
|
93
|
-
// uname/gname empty
|
|
94
|
-
// Compute checksum
|
|
95
|
-
let sum = 0;
|
|
96
|
-
for (let i = 0; i < BLOCK_SIZE; i++)
|
|
97
|
-
sum += header[i];
|
|
98
|
-
const checksum = padOctal(sum, 6) + "\0 ";
|
|
99
|
-
header.write(checksum, 148, 8, "ascii");
|
|
100
|
-
// Pad content to 512
|
|
101
|
-
const padLen = (BLOCK_SIZE - (content.length % BLOCK_SIZE)) % BLOCK_SIZE;
|
|
102
|
-
const padding = Buffer.alloc(padLen);
|
|
103
|
-
return Buffer.concat([header, content, padding]);
|
|
104
|
-
}
|
|
105
|
-
function parseTarBlocks(tar) {
|
|
106
|
-
const out = [];
|
|
107
|
-
let offset = 0;
|
|
108
|
-
while (offset + BLOCK_SIZE <= tar.length) {
|
|
109
|
-
const header = tar.subarray(offset, offset + BLOCK_SIZE);
|
|
110
|
-
if (isZeroBlock(header)) {
|
|
111
|
-
// POSIX: two trailing zero blocks. Either way, stop.
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
const name = readCString(header, 0, 100);
|
|
115
|
-
const sizeStr = readCString(header, 124, 12);
|
|
116
|
-
const size = parseInt(sizeStr.trim() || "0", 8);
|
|
117
|
-
const mtimeStr = readCString(header, 136, 12);
|
|
118
|
-
const mtime = parseInt(mtimeStr.trim() || "0", 8);
|
|
119
|
-
const checksumStr = readCString(header, 148, 8);
|
|
120
|
-
const declaredChecksum = parseInt(checksumStr.trim() || "0", 8);
|
|
121
|
-
const computedChecksum = computeHeaderChecksum(header);
|
|
122
|
-
if (declaredChecksum !== computedChecksum) {
|
|
123
|
-
throw new ArchiveFormatError(`tar header checksum mismatch for ${name}: declared=${declaredChecksum} computed=${computedChecksum}`);
|
|
124
|
-
}
|
|
125
|
-
const typeflag = String.fromCharCode(header[156] ?? 0x30);
|
|
126
|
-
offset += BLOCK_SIZE;
|
|
127
|
-
if (Number.isNaN(size) || size < 0) {
|
|
128
|
-
throw new ArchiveFormatError(`Invalid size in tar header for ${name}`);
|
|
129
|
-
}
|
|
130
|
-
if (typeflag === "0" || typeflag === "\0") {
|
|
131
|
-
const content = Buffer.from(tar.subarray(offset, offset + size));
|
|
132
|
-
out.push({ name, content, mtime });
|
|
133
|
-
offset += size;
|
|
134
|
-
const pad = (BLOCK_SIZE - (size % BLOCK_SIZE)) % BLOCK_SIZE;
|
|
135
|
-
offset += pad;
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
// Skip unknown types (directories, links). Still advance.
|
|
139
|
-
offset += size;
|
|
140
|
-
const pad = (BLOCK_SIZE - (size % BLOCK_SIZE)) % BLOCK_SIZE;
|
|
141
|
-
offset += pad;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return out;
|
|
145
|
-
}
|
|
146
|
-
function computeHeaderChecksum(header) {
|
|
147
|
-
let sum = 0;
|
|
148
|
-
for (let i = 0; i < BLOCK_SIZE; i++) {
|
|
149
|
-
if (i >= 148 && i < 156)
|
|
150
|
-
sum += 0x20; // checksum field treated as spaces
|
|
151
|
-
else
|
|
152
|
-
sum += header[i];
|
|
153
|
-
}
|
|
154
|
-
return sum;
|
|
155
|
-
}
|
|
156
|
-
function isZeroBlock(buf) {
|
|
157
|
-
for (let i = 0; i < BLOCK_SIZE; i++)
|
|
158
|
-
if (buf[i] !== 0)
|
|
159
|
-
return false;
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
162
|
-
function readCString(buf, offset, len) {
|
|
163
|
-
let end = offset;
|
|
164
|
-
const max = offset + len;
|
|
165
|
-
while (end < max && buf[end] !== 0)
|
|
166
|
-
end++;
|
|
167
|
-
return buf.toString("utf8", offset, end);
|
|
168
|
-
}
|
|
169
|
-
function padOctal(n, width) {
|
|
170
|
-
let s = n.toString(8);
|
|
171
|
-
while (s.length < width)
|
|
172
|
-
s = "0" + s;
|
|
173
|
-
return s;
|
|
174
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public API for the A2 archive primitives.
|
|
3
|
-
*
|
|
4
|
-
* Importers should reach into specific modules for serializer-level types;
|
|
5
|
-
* this barrel re-exports the most common surface used by the CLI/HTTP layers
|
|
6
|
-
* that will land in T10-T13.
|
|
7
|
-
*/
|
|
8
|
-
export * from "./types.js";
|
|
9
|
-
export { packArchive, unpackArchive, listArchive, packArchiveStream, } from "./format.js";
|
|
10
|
-
export { buildManifest, defaultEncryptionDisabled, canonicalize, writeManifest, parseManifest, manifestAADSource, manifestAADHash, } from "./manifest.js";
|
|
11
|
-
export type { ManifestSeed } from "./manifest.js";
|
|
12
|
-
export { serializeChunks, parseChunks, serializeChunkRow, parseChunkRow, planChunkImport, } from "./serializers/chunks.js";
|
|
13
|
-
export { serializeEmbeddings, parseEmbeddings, } from "./serializers/embeddings.js";
|
|
14
|
-
export type { EmbeddingInput, EmbeddingsBundle } from "./serializers/embeddings.js";
|
|
15
|
-
export { serializeKgEntities, parseKgEntities, serializeKgRelations, parseKgRelations, planKgMerge, } from "./serializers/kg.js";
|
|
16
|
-
export type { KgMergeResult } from "./serializers/kg.js";
|
|
17
|
-
export { serializeOpsAudit, parseOpsAudit, planOpsAuditImport, } from "./serializers/ops_audit.js";
|
|
18
|
-
export { deriveKey, encryptBuffer, decryptBuffer, decryptArchiveFile, verifyCiphertextSha256, getPassphrase, buildEncryptionMetadata, SCRYPT_N, SCRYPT_R, SCRYPT_P, KEY_LEN, SALT_LEN, NONCE_LEN, TAG_LEN, } from "./encryption.js";
|
|
19
|
-
export type { EncryptResult } from "./encryption.js";
|
|
20
|
-
export { canImport, migrationPath, migrateChunks, listMigrations, } from "./migration.js";
|
|
21
|
-
export type { ImportabilityResult } from "./migration.js";
|
|
22
|
-
export { runExport, runImport, listArchiveEntries, } from "./orchestrator.js";
|
|
23
|
-
export type { ExportRequest, ExportResult, ImportRequest, ImportResult, ProgressEvent, } from "./orchestrator.js";
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public API for the A2 archive primitives.
|
|
3
|
-
*
|
|
4
|
-
* Importers should reach into specific modules for serializer-level types;
|
|
5
|
-
* this barrel re-exports the most common surface used by the CLI/HTTP layers
|
|
6
|
-
* that will land in T10-T13.
|
|
7
|
-
*/
|
|
8
|
-
export * from "./types.js";
|
|
9
|
-
export { packArchive, unpackArchive, listArchive, packArchiveStream, } from "./format.js";
|
|
10
|
-
export { buildManifest, defaultEncryptionDisabled, canonicalize, writeManifest, parseManifest, manifestAADSource, manifestAADHash, } from "./manifest.js";
|
|
11
|
-
export { serializeChunks, parseChunks, serializeChunkRow, parseChunkRow, planChunkImport, } from "./serializers/chunks.js";
|
|
12
|
-
export { serializeEmbeddings, parseEmbeddings, } from "./serializers/embeddings.js";
|
|
13
|
-
export { serializeKgEntities, parseKgEntities, serializeKgRelations, parseKgRelations, planKgMerge, } from "./serializers/kg.js";
|
|
14
|
-
export { serializeOpsAudit, parseOpsAudit, planOpsAuditImport, } from "./serializers/ops_audit.js";
|
|
15
|
-
export { deriveKey, encryptBuffer, decryptBuffer, decryptArchiveFile, verifyCiphertextSha256, getPassphrase, buildEncryptionMetadata, SCRYPT_N, SCRYPT_R, SCRYPT_P, KEY_LEN, SALT_LEN, NONCE_LEN, TAG_LEN, } from "./encryption.js";
|
|
16
|
-
export { canImport, migrationPath, migrateChunks, listMigrations, } from "./migration.js";
|
|
17
|
-
export { runExport, runImport, listArchiveEntries, } from "./orchestrator.js";
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T2 — Manifest schema, canonical writer, parser.
|
|
3
|
-
*
|
|
4
|
-
* Canonical JSON serialization (sorted keys, no extra whitespace, UTF-8) is
|
|
5
|
-
* mandatory because the manifest plaintext is the AAD source for AES-256-GCM.
|
|
6
|
-
* Any whitespace or key-order drift between writer and parser would break
|
|
7
|
-
* `sha256(manifestBytes)` equality on the receiving end → all encrypted files
|
|
8
|
-
* fail decrypt. T2 owns this invariant.
|
|
9
|
-
*/
|
|
10
|
-
import { EncryptionMetadata, ManifestCounts, ManifestFilters, ManifestV1 } from "./types.js";
|
|
11
|
-
export interface ManifestSeed {
|
|
12
|
-
schema_version: number;
|
|
13
|
-
source_hostname: string;
|
|
14
|
-
source_nox_mem_version: string;
|
|
15
|
-
embedding_provider: string;
|
|
16
|
-
embedding_model: string;
|
|
17
|
-
embedding_dim: number;
|
|
18
|
-
sqlite_vec_version?: string | null;
|
|
19
|
-
includes: ManifestV1["includes"];
|
|
20
|
-
filters?: Partial<ManifestFilters>;
|
|
21
|
-
counts: ManifestCounts;
|
|
22
|
-
checksums: Record<string, string>;
|
|
23
|
-
encryption?: EncryptionMetadata;
|
|
24
|
-
integrity_warnings?: string[];
|
|
25
|
-
created_at?: string;
|
|
26
|
-
}
|
|
27
|
-
/** Build an in-memory ManifestV1 from a seed. Encryption defaults to disabled. */
|
|
28
|
-
export declare function buildManifest(seed: ManifestSeed): ManifestV1;
|
|
29
|
-
export declare function defaultEncryptionDisabled(): EncryptionMetadata;
|
|
30
|
-
/**
|
|
31
|
-
* Canonical JSON serializer. Sorts object keys recursively, no whitespace.
|
|
32
|
-
* Stable across Node versions (does NOT depend on V8 object insertion order).
|
|
33
|
-
*/
|
|
34
|
-
export declare function canonicalize(value: unknown): string;
|
|
35
|
-
/** Serialize manifest to a UTF-8 Buffer using canonical JSON. */
|
|
36
|
-
export declare function writeManifest(m: ManifestV1): Buffer;
|
|
37
|
-
/** Parse manifest bytes. Throws ManifestError on schema mismatch. */
|
|
38
|
-
export declare function parseManifest(buf: Buffer): ManifestV1;
|
|
39
|
-
/**
|
|
40
|
-
* AAD source: sha256 of the canonical manifest bytes computed BEFORE any
|
|
41
|
-
* encryption metadata is filled in. The full encryption block (enabled flag,
|
|
42
|
-
* algorithm, KDF params, salt, per-file nonces/tags, etc.) is stripped to the
|
|
43
|
-
* "disabled" sentinel so the AAD is identical pre/post-encrypt write.
|
|
44
|
-
*
|
|
45
|
-
* Pipeline:
|
|
46
|
-
* 1. Build manifest with `encryption: defaultEncryptionDisabled()`
|
|
47
|
-
* 2. AAD = sha256(manifestAADSource(this))
|
|
48
|
-
* 3. Encrypt files using that AAD
|
|
49
|
-
* 4. Re-assemble manifest with full `encryption: ...` filled in
|
|
50
|
-
* 5. AAD source still produces the SAME bytes → tag verifies on decrypt
|
|
51
|
-
*/
|
|
52
|
-
export declare function manifestAADSource(m: ManifestV1): Buffer;
|
|
53
|
-
export declare function manifestAADHash(m: ManifestV1): Buffer;
|