@atomicmemory/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/LICENSE +201 -0
- package/README.md +314 -0
- package/dist/app/bind-ephemeral.d.ts +18 -0
- package/dist/app/bind-ephemeral.js +22 -0
- package/dist/app/cors-headers.d.ts +12 -0
- package/dist/app/cors-headers.js +18 -0
- package/dist/app/create-app.d.ts +25 -0
- package/dist/app/create-app.js +156 -0
- package/dist/app/runtime-config-route-snapshot.d.ts +27 -0
- package/dist/app/runtime-config-route-snapshot.js +27 -0
- package/dist/app/runtime-container.d.ts +281 -0
- package/dist/app/runtime-container.js +297 -0
- package/dist/app/startup-checks.d.ts +28 -0
- package/dist/app/startup-checks.js +45 -0
- package/dist/bin.d.ts +17 -0
- package/dist/bin.js +128 -0
- package/dist/config.d.ts +680 -0
- package/dist/config.js +808 -0
- package/dist/db/agent-trust-repository.d.ts +49 -0
- package/dist/db/agent-trust-repository.js +66 -0
- package/dist/db/belief-edges-repository.d.ts +68 -0
- package/dist/db/belief-edges-repository.js +124 -0
- package/dist/db/claim-repository.d.ts +6 -0
- package/dist/db/claim-repository.js +4 -0
- package/dist/db/contradictions-repository.d.ts +56 -0
- package/dist/db/contradictions-repository.js +88 -0
- package/dist/db/document-chunk-repository.d.ts +48 -0
- package/dist/db/document-chunk-repository.js +145 -0
- package/dist/db/document-chunk-types.d.ts +35 -0
- package/dist/db/document-chunk-types.js +9 -0
- package/dist/db/document-list-cursor.d.ts +45 -0
- package/dist/db/document-list-cursor.js +111 -0
- package/dist/db/document-list-repository.d.ts +103 -0
- package/dist/db/document-list-repository.js +204 -0
- package/dist/db/entity-cards-repository.d.ts +37 -0
- package/dist/db/entity-cards-repository.js +46 -0
- package/dist/db/entity-values-repository.d.ts +26 -0
- package/dist/db/entity-values-repository.js +57 -0
- package/dist/db/link-repository.d.ts +30 -0
- package/dist/db/link-repository.js +54 -0
- package/dist/db/memory-repository.d.ts +163 -0
- package/dist/db/memory-repository.js +232 -0
- package/dist/db/migrate.d.ts +6 -0
- package/dist/db/migrate.js +36 -0
- package/dist/db/mmr.d.ts +14 -0
- package/dist/db/mmr.js +57 -0
- package/dist/db/passport-feed-repository.d.ts +91 -0
- package/dist/db/passport-feed-repository.js +198 -0
- package/dist/db/pg-episode-store.d.ts +19 -0
- package/dist/db/pg-episode-store.js +17 -0
- package/dist/db/pg-link-store.d.ts +17 -0
- package/dist/db/pg-link-store.js +14 -0
- package/dist/db/pg-memory-store.d.ts +68 -0
- package/dist/db/pg-memory-store.js +53 -0
- package/dist/db/pg-recap-store.d.ts +13 -0
- package/dist/db/pg-recap-store.js +19 -0
- package/dist/db/pg-representation-store.d.ts +17 -0
- package/dist/db/pg-representation-store.js +17 -0
- package/dist/db/pg-search-store.d.ts +29 -0
- package/dist/db/pg-search-store.js +47 -0
- package/dist/db/pool.d.ts +5 -0
- package/dist/db/pool.js +21 -0
- package/dist/db/ppr.d.ts +56 -0
- package/dist/db/ppr.js +178 -0
- package/dist/db/query-helpers.d.ts +44 -0
- package/dist/db/query-helpers.js +60 -0
- package/dist/db/raw-doc-artifact-sync.d.ts +128 -0
- package/dist/db/raw-doc-artifact-sync.js +259 -0
- package/dist/db/raw-document-blob-repository.d.ts +148 -0
- package/dist/db/raw-document-blob-repository.js +300 -0
- package/dist/db/raw-document-repository.d.ts +104 -0
- package/dist/db/raw-document-repository.js +410 -0
- package/dist/db/raw-document-status-repository.d.ts +122 -0
- package/dist/db/raw-document-status-repository.js +183 -0
- package/dist/db/raw-document-types.d.ts +236 -0
- package/dist/db/raw-document-types.js +10 -0
- package/dist/db/raw-storage-reconciliation-repository.d.ts +110 -0
- package/dist/db/raw-storage-reconciliation-repository.js +200 -0
- package/dist/db/reflection-jobs-repository.d.ts +33 -0
- package/dist/db/reflection-jobs-repository.js +48 -0
- package/dist/db/reflections-repository.d.ts +41 -0
- package/dist/db/reflections-repository.js +83 -0
- package/dist/db/repository-claims.d.ts +141 -0
- package/dist/db/repository-claims.js +376 -0
- package/dist/db/repository-deferred-audn.d.ts +33 -0
- package/dist/db/repository-deferred-audn.js +69 -0
- package/dist/db/repository-document-delete.d.ts +53 -0
- package/dist/db/repository-document-delete.js +156 -0
- package/dist/db/repository-entities.d.ts +114 -0
- package/dist/db/repository-entities.js +317 -0
- package/dist/db/repository-entity-attributes.d.ts +41 -0
- package/dist/db/repository-entity-attributes.js +65 -0
- package/dist/db/repository-entity-graph.d.ts +32 -0
- package/dist/db/repository-entity-graph.js +87 -0
- package/dist/db/repository-first-mentions.d.ts +41 -0
- package/dist/db/repository-first-mentions.js +79 -0
- package/dist/db/repository-lessons.d.ts +51 -0
- package/dist/db/repository-lessons.js +90 -0
- package/dist/db/repository-links.d.ts +26 -0
- package/dist/db/repository-links.js +105 -0
- package/dist/db/repository-observation.d.ts +26 -0
- package/dist/db/repository-observation.js +51 -0
- package/dist/db/repository-read.d.ts +56 -0
- package/dist/db/repository-read.js +271 -0
- package/dist/db/repository-recaps.d.ts +59 -0
- package/dist/db/repository-recaps.js +158 -0
- package/dist/db/repository-representations.d.ts +48 -0
- package/dist/db/repository-representations.js +162 -0
- package/dist/db/repository-temporal-state.d.ts +35 -0
- package/dist/db/repository-temporal-state.js +46 -0
- package/dist/db/repository-tll.d.ts +88 -0
- package/dist/db/repository-tll.js +179 -0
- package/dist/db/repository-types.d.ts +313 -0
- package/dist/db/repository-types.js +142 -0
- package/dist/db/repository-user-profiles.d.ts +17 -0
- package/dist/db/repository-user-profiles.js +28 -0
- package/dist/db/repository-vector-search.d.ts +33 -0
- package/dist/db/repository-vector-search.js +373 -0
- package/dist/db/repository-wipe.d.ts +34 -0
- package/dist/db/repository-wipe.js +94 -0
- package/dist/db/repository-write.d.ts +61 -0
- package/dist/db/repository-write.js +279 -0
- package/dist/db/schema.sql +1355 -0
- package/dist/db/storage-artifact-delete-tx.d.ts +56 -0
- package/dist/db/storage-artifact-delete-tx.js +123 -0
- package/dist/db/storage-artifact-providers.d.ts +21 -0
- package/dist/db/storage-artifact-providers.js +21 -0
- package/dist/db/storage-artifact-recovery-repository.d.ts +66 -0
- package/dist/db/storage-artifact-recovery-repository.js +58 -0
- package/dist/db/storage-artifact-repository.d.ts +329 -0
- package/dist/db/storage-artifact-repository.js +497 -0
- package/dist/db/stores.d.ts +220 -0
- package/dist/db/stores.js +12 -0
- package/dist/db/summaries-repository.d.ts +74 -0
- package/dist/db/summaries-repository.js +125 -0
- package/dist/eval/beam-10m-loader.d.ts +98 -0
- package/dist/eval/beam-10m-loader.js +128 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +17 -0
- package/dist/middleware/require-bearer.d.ts +27 -0
- package/dist/middleware/require-bearer.js +60 -0
- package/dist/middleware/validate-response.d.ts +33 -0
- package/dist/middleware/validate-response.js +55 -0
- package/dist/middleware/validate.d.ts +43 -0
- package/dist/middleware/validate.js +85 -0
- package/dist/routes/agents.d.ts +13 -0
- package/dist/routes/agents.js +89 -0
- package/dist/routes/document-response-formatters.d.ts +98 -0
- package/dist/routes/document-response-formatters.js +243 -0
- package/dist/routes/documents.d.ts +74 -0
- package/dist/routes/documents.js +425 -0
- package/dist/routes/memories.d.ts +29 -0
- package/dist/routes/memories.js +725 -0
- package/dist/routes/memory-response-formatters.d.ts +179 -0
- package/dist/routes/memory-response-formatters.js +210 -0
- package/dist/routes/public-raw-storage-metadata.d.ts +54 -0
- package/dist/routes/public-raw-storage-metadata.js +56 -0
- package/dist/routes/reflect.d.ts +14 -0
- package/dist/routes/reflect.js +19 -0
- package/dist/routes/response-schema-map.d.ts +14 -0
- package/dist/routes/response-schema-map.js +69 -0
- package/dist/routes/route-errors.d.ts +12 -0
- package/dist/routes/route-errors.js +30 -0
- package/dist/routes/storage-error-handlers.d.ts +34 -0
- package/dist/routes/storage-error-handlers.js +185 -0
- package/dist/routes/storage-response-formatters.d.ts +44 -0
- package/dist/routes/storage-response-formatters.js +155 -0
- package/dist/routes/storage.d.ts +38 -0
- package/dist/routes/storage.js +369 -0
- package/dist/routes/upstream-provider-errors.d.ts +19 -0
- package/dist/routes/upstream-provider-errors.js +95 -0
- package/dist/schemas/agents.d.ts +79 -0
- package/dist/schemas/agents.js +126 -0
- package/dist/schemas/common.d.ts +110 -0
- package/dist/schemas/common.js +190 -0
- package/dist/schemas/document-list-responses.d.ts +102 -0
- package/dist/schemas/document-list-responses.js +87 -0
- package/dist/schemas/document-list-schemas.d.ts +123 -0
- package/dist/schemas/document-list-schemas.js +174 -0
- package/dist/schemas/document-response-schemas.d.ts +610 -0
- package/dist/schemas/document-response-schemas.js +264 -0
- package/dist/schemas/document-status-envelope.d.ts +48 -0
- package/dist/schemas/document-status-envelope.js +54 -0
- package/dist/schemas/documents.d.ts +292 -0
- package/dist/schemas/documents.js +449 -0
- package/dist/schemas/errors.d.ts +75 -0
- package/dist/schemas/errors.js +105 -0
- package/dist/schemas/memories.d.ts +378 -0
- package/dist/schemas/memories.js +542 -0
- package/dist/schemas/openapi.d.ts +24 -0
- package/dist/schemas/openapi.js +1038 -0
- package/dist/schemas/response-scalars.d.ts +10 -0
- package/dist/schemas/response-scalars.js +10 -0
- package/dist/schemas/responses.d.ts +536 -0
- package/dist/schemas/responses.js +350 -0
- package/dist/schemas/search-response-parts.d.ts +97 -0
- package/dist/schemas/search-response-parts.js +103 -0
- package/dist/schemas/storage-schemas.d.ts +175 -0
- package/dist/schemas/storage-schemas.js +277 -0
- package/dist/schemas/zod-setup.d.ts +15 -0
- package/dist/schemas/zod-setup.js +17 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.js +57 -0
- package/dist/services/abstract-query-policy.d.ts +13 -0
- package/dist/services/abstract-query-policy.js +50 -0
- package/dist/services/affinity-clustering.d.ts +66 -0
- package/dist/services/affinity-clustering.js +125 -0
- package/dist/services/agentic-retrieval.d.ts +38 -0
- package/dist/services/agentic-retrieval.js +126 -0
- package/dist/services/answer-format.d.ts +56 -0
- package/dist/services/answer-format.js +118 -0
- package/dist/services/answer-rescue.d.ts +72 -0
- package/dist/services/answer-rescue.js +177 -0
- package/dist/services/answer-verifier.d.ts +24 -0
- package/dist/services/answer-verifier.js +73 -0
- package/dist/services/api-retry.d.ts +6 -0
- package/dist/services/api-retry.js +41 -0
- package/dist/services/assistant-turn-filter.d.ts +20 -0
- package/dist/services/assistant-turn-filter.js +69 -0
- package/dist/services/atomicmem-uri.d.ts +33 -0
- package/dist/services/atomicmem-uri.js +86 -0
- package/dist/services/audit-events.d.ts +54 -0
- package/dist/services/audit-events.js +56 -0
- package/dist/services/chunked-extraction.d.ts +21 -0
- package/dist/services/chunked-extraction.js +108 -0
- package/dist/services/claim-slotting.d.ts +27 -0
- package/dist/services/claim-slotting.js +38 -0
- package/dist/services/claude-code-llm.d.ts +19 -0
- package/dist/services/claude-code-llm.js +96 -0
- package/dist/services/composite-dedup.d.ts +50 -0
- package/dist/services/composite-dedup.js +153 -0
- package/dist/services/composite-grouping.d.ts +41 -0
- package/dist/services/composite-grouping.js +111 -0
- package/dist/services/composite-staleness.d.ts +20 -0
- package/dist/services/composite-staleness.js +50 -0
- package/dist/services/conciseness-preference.d.ts +14 -0
- package/dist/services/conciseness-preference.js +42 -0
- package/dist/services/conflict-policy.d.ts +20 -0
- package/dist/services/conflict-policy.js +335 -0
- package/dist/services/consensus-extraction.d.ts +39 -0
- package/dist/services/consensus-extraction.js +147 -0
- package/dist/services/consensus-validation.d.ts +52 -0
- package/dist/services/consensus-validation.js +206 -0
- package/dist/services/consolidation-service.d.ts +60 -0
- package/dist/services/consolidation-service.js +171 -0
- package/dist/services/content-detection.d.ts +18 -0
- package/dist/services/content-detection.js +25 -0
- package/dist/services/contradiction-surfacing.d.ts +62 -0
- package/dist/services/contradiction-surfacing.js +111 -0
- package/dist/services/cost-telemetry.d.ts +39 -0
- package/dist/services/cost-telemetry.js +58 -0
- package/dist/services/counter-evidence.d.ts +34 -0
- package/dist/services/counter-evidence.js +92 -0
- package/dist/services/current-state-ranking.d.ts +21 -0
- package/dist/services/current-state-ranking.js +152 -0
- package/dist/services/deferred-audn.d.ts +47 -0
- package/dist/services/deferred-audn.js +162 -0
- package/dist/services/document-chunker.d.ts +50 -0
- package/dist/services/document-chunker.js +153 -0
- package/dist/services/document-failure-markers.d.ts +91 -0
- package/dist/services/document-failure-markers.js +305 -0
- package/dist/services/document-indexer.d.ts +122 -0
- package/dist/services/document-indexer.js +405 -0
- package/dist/services/document-service.d.ts +245 -0
- package/dist/services/document-service.js +325 -0
- package/dist/services/document-upload-artifact-sync.d.ts +80 -0
- package/dist/services/document-upload-artifact-sync.js +162 -0
- package/dist/services/document-upload-beta2-recovery.d.ts +72 -0
- package/dist/services/document-upload-beta2-recovery.js +94 -0
- package/dist/services/document-upload.d.ts +44 -0
- package/dist/services/document-upload.js +353 -0
- package/dist/services/embedding.d.ts +57 -0
- package/dist/services/embedding.js +416 -0
- package/dist/services/entity-attribute-extractor.d.ts +34 -0
- package/dist/services/entity-attribute-extractor.js +117 -0
- package/dist/services/entity-card-synthesis.d.ts +54 -0
- package/dist/services/entity-card-synthesis.js +92 -0
- package/dist/services/entity-dedup.d.ts +9 -0
- package/dist/services/entity-dedup.js +14 -0
- package/dist/services/entity-graph.d.ts +17 -0
- package/dist/services/entity-graph.js +135 -0
- package/dist/services/entropy-gate.d.ts +52 -0
- package/dist/services/entropy-gate.js +56 -0
- package/dist/services/episode-fetcher.d.ts +47 -0
- package/dist/services/episode-fetcher.js +128 -0
- package/dist/services/event-anchor-facts.d.ts +8 -0
- package/dist/services/event-anchor-facts.js +205 -0
- package/dist/services/event-chain-detector.d.ts +52 -0
- package/dist/services/event-chain-detector.js +83 -0
- package/dist/services/extraction-cache.d.ts +9 -0
- package/dist/services/extraction-cache.js +54 -0
- package/dist/services/extraction-enrichment.d.ts +9 -0
- package/dist/services/extraction-enrichment.js +223 -0
- package/dist/services/extraction.d.ts +69 -0
- package/dist/services/extraction.js +596 -0
- package/dist/services/fact-normalization.d.ts +12 -0
- package/dist/services/fact-normalization.js +248 -0
- package/dist/services/filecoin-observability.d.ts +127 -0
- package/dist/services/filecoin-observability.js +200 -0
- package/dist/services/first-mention-service.d.ts +76 -0
- package/dist/services/first-mention-service.js +186 -0
- package/dist/services/hierarchical-retrieval.d.ts +49 -0
- package/dist/services/hierarchical-retrieval.js +50 -0
- package/dist/services/ingest-fact-pipeline.d.ts +32 -0
- package/dist/services/ingest-fact-pipeline.js +212 -0
- package/dist/services/ingest-post-write.d.ts +50 -0
- package/dist/services/ingest-post-write.js +117 -0
- package/dist/services/ingest-trace.d.ts +32 -0
- package/dist/services/ingest-trace.js +60 -0
- package/dist/services/input-sanitizer.d.ts +41 -0
- package/dist/services/input-sanitizer.js +135 -0
- package/dist/services/iterative-retrieval.d.ts +26 -0
- package/dist/services/iterative-retrieval.js +139 -0
- package/dist/services/keyword-expansion.d.ts +10 -0
- package/dist/services/keyword-expansion.js +26 -0
- package/dist/services/lesson-service.d.ts +68 -0
- package/dist/services/lesson-service.js +178 -0
- package/dist/services/literal-extractor.d.ts +16 -0
- package/dist/services/literal-extractor.js +74 -0
- package/dist/services/literal-list-protection.d.ts +17 -0
- package/dist/services/literal-list-protection.js +134 -0
- package/dist/services/literal-query-expansion.d.ts +20 -0
- package/dist/services/literal-query-expansion.js +181 -0
- package/dist/services/llm.d.ts +61 -0
- package/dist/services/llm.js +265 -0
- package/dist/services/memcell-projection.d.ts +17 -0
- package/dist/services/memcell-projection.js +41 -0
- package/dist/services/memory-audn.d.ts +43 -0
- package/dist/services/memory-audn.js +419 -0
- package/dist/services/memory-crud.d.ts +93 -0
- package/dist/services/memory-crud.js +255 -0
- package/dist/services/memory-ingest.d.ts +21 -0
- package/dist/services/memory-ingest.js +249 -0
- package/dist/services/memory-lifecycle.d.ts +75 -0
- package/dist/services/memory-lifecycle.js +108 -0
- package/dist/services/memory-lineage.d.ts +181 -0
- package/dist/services/memory-lineage.js +232 -0
- package/dist/services/memory-network.d.ts +40 -0
- package/dist/services/memory-network.js +75 -0
- package/dist/services/memory-search-types.d.ts +25 -0
- package/dist/services/memory-search-types.js +10 -0
- package/dist/services/memory-search.d.ts +48 -0
- package/dist/services/memory-search.js +505 -0
- package/dist/services/memory-service-types.d.ts +371 -0
- package/dist/services/memory-service-types.js +8 -0
- package/dist/services/memory-service.d.ts +152 -0
- package/dist/services/memory-service.js +225 -0
- package/dist/services/memory-storage.d.ts +33 -0
- package/dist/services/memory-storage.js +328 -0
- package/dist/services/msr-aggregator.d.ts +38 -0
- package/dist/services/msr-aggregator.js +97 -0
- package/dist/services/msr-detector.d.ts +35 -0
- package/dist/services/msr-detector.js +65 -0
- package/dist/services/namespace-retrieval.d.ts +60 -0
- package/dist/services/namespace-retrieval.js +180 -0
- package/dist/services/observation-date-extraction.d.ts +12 -0
- package/dist/services/observation-date-extraction.js +50 -0
- package/dist/services/observation-service.d.ts +27 -0
- package/dist/services/observation-service.js +84 -0
- package/dist/services/packaging-observability.d.ts +29 -0
- package/dist/services/packaging-observability.js +146 -0
- package/dist/services/query-expansion.d.ts +83 -0
- package/dist/services/query-expansion.js +242 -0
- package/dist/services/query-keyword-matches.d.ts +6 -0
- package/dist/services/query-keyword-matches.js +56 -0
- package/dist/services/query-term-visibility.d.ts +28 -0
- package/dist/services/query-term-visibility.js +100 -0
- package/dist/services/quick-extraction.d.ts +25 -0
- package/dist/services/quick-extraction.js +431 -0
- package/dist/services/quoted-entity-extraction.d.ts +10 -0
- package/dist/services/quoted-entity-extraction.js +161 -0
- package/dist/services/raw-storage-reconciler-backoff.d.ts +8 -0
- package/dist/services/raw-storage-reconciler-backoff.js +14 -0
- package/dist/services/raw-storage-reconciler-scheduler.d.ts +29 -0
- package/dist/services/raw-storage-reconciler-scheduler.js +43 -0
- package/dist/services/raw-storage-reconciler.d.ts +71 -0
- package/dist/services/raw-storage-reconciler.js +278 -0
- package/dist/services/recap-builder.d.ts +49 -0
- package/dist/services/recap-builder.js +157 -0
- package/dist/services/reflect-jobs.d.ts +23 -0
- package/dist/services/reflect-jobs.js +36 -0
- package/dist/services/reflect-prompts.d.ts +71 -0
- package/dist/services/reflect-prompts.js +99 -0
- package/dist/services/reflect-retrieval.d.ts +33 -0
- package/dist/services/reflect-retrieval.js +30 -0
- package/dist/services/reflect.d.ts +49 -0
- package/dist/services/reflect.js +84 -0
- package/dist/services/relative-temporal.d.ts +14 -0
- package/dist/services/relative-temporal.js +163 -0
- package/dist/services/relevance-policy.d.ts +37 -0
- package/dist/services/relevance-policy.js +109 -0
- package/dist/services/rerank.d.ts +32 -0
- package/dist/services/rerank.js +118 -0
- package/dist/services/reranker.d.ts +20 -0
- package/dist/services/reranker.js +99 -0
- package/dist/services/retrieval-channel-rules.d.ts +34 -0
- package/dist/services/retrieval-channel-rules.js +41 -0
- package/dist/services/retrieval-config-overlay.d.ts +36 -0
- package/dist/services/retrieval-config-overlay.js +44 -0
- package/dist/services/retrieval-format.d.ts +119 -0
- package/dist/services/retrieval-format.js +559 -0
- package/dist/services/retrieval-policy.d.ts +69 -0
- package/dist/services/retrieval-policy.js +275 -0
- package/dist/services/retrieval-profiles.d.ts +37 -0
- package/dist/services/retrieval-profiles.js +90 -0
- package/dist/services/retrieval-side-effects.d.ts +14 -0
- package/dist/services/retrieval-side-effects.js +26 -0
- package/dist/services/retrieval-trace.d.ts +108 -0
- package/dist/services/retrieval-trace.js +147 -0
- package/dist/services/rrf-fusion.d.ts +18 -0
- package/dist/services/rrf-fusion.js +34 -0
- package/dist/services/search-pipeline.d.ts +71 -0
- package/dist/services/search-pipeline.js +788 -0
- package/dist/services/session-date.d.ts +20 -0
- package/dist/services/session-date.js +61 -0
- package/dist/services/session-packaging.d.ts +53 -0
- package/dist/services/session-packaging.js +182 -0
- package/dist/services/session-summary-generator.d.ts +53 -0
- package/dist/services/session-summary-generator.js +134 -0
- package/dist/services/specialists/cr-specialist.d.ts +52 -0
- package/dist/services/specialists/cr-specialist.js +121 -0
- package/dist/services/specialists/dispatch.d.ts +53 -0
- package/dist/services/specialists/dispatch.js +102 -0
- package/dist/services/specialists/ie-ku-specialist.d.ts +37 -0
- package/dist/services/specialists/ie-ku-specialist.js +63 -0
- package/dist/services/specialists/msr-specialist.d.ts +61 -0
- package/dist/services/specialists/msr-specialist.js +162 -0
- package/dist/services/specialists/tr-specialist.d.ts +37 -0
- package/dist/services/specialists/tr-specialist.js +146 -0
- package/dist/services/storage-key-prefix.d.ts +42 -0
- package/dist/services/storage-key-prefix.js +45 -0
- package/dist/services/storage-put-recovery.d.ts +71 -0
- package/dist/services/storage-put-recovery.js +269 -0
- package/dist/services/storage-service-errors.d.ts +124 -0
- package/dist/services/storage-service-errors.js +189 -0
- package/dist/services/storage-service.d.ts +176 -0
- package/dist/services/storage-service.js +423 -0
- package/dist/services/subject-aware-ranking.d.ts +19 -0
- package/dist/services/subject-aware-ranking.js +161 -0
- package/dist/services/supplemental-extraction.d.ts +7 -0
- package/dist/services/supplemental-extraction.js +116 -0
- package/dist/services/tbc-execution.d.ts +49 -0
- package/dist/services/tbc-execution.js +284 -0
- package/dist/services/temporal-classifier.d.ts +56 -0
- package/dist/services/temporal-classifier.js +94 -0
- package/dist/services/temporal-endpoint-evidence.d.ts +12 -0
- package/dist/services/temporal-endpoint-evidence.js +313 -0
- package/dist/services/temporal-fingerprint.d.ts +6 -0
- package/dist/services/temporal-fingerprint.js +12 -0
- package/dist/services/temporal-format.d.ts +9 -0
- package/dist/services/temporal-format.js +21 -0
- package/dist/services/temporal-intent.d.ts +39 -0
- package/dist/services/temporal-intent.js +78 -0
- package/dist/services/temporal-query-constraints.d.ts +16 -0
- package/dist/services/temporal-query-constraints.js +107 -0
- package/dist/services/temporal-query-expansion.d.ts +14 -0
- package/dist/services/temporal-query-expansion.js +131 -0
- package/dist/services/temporal-rerank.d.ts +22 -0
- package/dist/services/temporal-rerank.js +47 -0
- package/dist/services/temporal-result-protection.d.ts +7 -0
- package/dist/services/temporal-result-protection.js +60 -0
- package/dist/services/temporal-state-write.d.ts +57 -0
- package/dist/services/temporal-state-write.js +45 -0
- package/dist/services/tiered-context.d.ts +87 -0
- package/dist/services/tiered-context.js +214 -0
- package/dist/services/tiered-loading.d.ts +88 -0
- package/dist/services/tiered-loading.js +263 -0
- package/dist/services/timeline-pack.d.ts +36 -0
- package/dist/services/timeline-pack.js +50 -0
- package/dist/services/timing.d.ts +13 -0
- package/dist/services/timing.js +72 -0
- package/dist/services/tll-augmentation.d.ts +20 -0
- package/dist/services/tll-augmentation.js +125 -0
- package/dist/services/tll-retrieval.d.ts +55 -0
- package/dist/services/tll-retrieval.js +101 -0
- package/dist/services/topic-abstraction.d.ts +36 -0
- package/dist/services/topic-abstraction.js +105 -0
- package/dist/services/trust-scoring.d.ts +43 -0
- package/dist/services/trust-scoring.js +89 -0
- package/dist/services/typed-belief-calculus.d.ts +126 -0
- package/dist/services/typed-belief-calculus.js +204 -0
- package/dist/services/upload-config.d.ts +34 -0
- package/dist/services/upload-config.js +23 -0
- package/dist/services/upload-decision.d.ts +65 -0
- package/dist/services/upload-decision.js +98 -0
- package/dist/services/upload-helpers.d.ts +107 -0
- package/dist/services/upload-helpers.js +148 -0
- package/dist/services/user-profile-builder.d.ts +22 -0
- package/dist/services/user-profile-builder.js +109 -0
- package/dist/services/voyage-embedding.d.ts +22 -0
- package/dist/services/voyage-embedding.js +77 -0
- package/dist/services/write-security.d.ts +31 -0
- package/dist/services/write-security.js +64 -0
- package/dist/storage/artifact-public-redaction.d.ts +34 -0
- package/dist/storage/artifact-public-redaction.js +83 -0
- package/dist/storage/cleanup.d.ts +103 -0
- package/dist/storage/cleanup.js +138 -0
- package/dist/storage/codec-factory.d.ts +17 -0
- package/dist/storage/codec-factory.js +33 -0
- package/dist/storage/codecs/aes-gcm-codec.d.ts +44 -0
- package/dist/storage/codecs/aes-gcm-codec.js +108 -0
- package/dist/storage/codecs/noop-codec.d.ts +16 -0
- package/dist/storage/codecs/noop-codec.js +23 -0
- package/dist/storage/factory.d.ts +44 -0
- package/dist/storage/factory.js +99 -0
- package/dist/storage/filecoin-cid-validation.d.ts +82 -0
- package/dist/storage/filecoin-cid-validation.js +122 -0
- package/dist/storage/filecoin-public-metadata.d.ts +73 -0
- package/dist/storage/filecoin-public-metadata.js +110 -0
- package/dist/storage/local-fs-store.d.ts +39 -0
- package/dist/storage/local-fs-store.js +145 -0
- package/dist/storage/pointer-uri-allowlist.d.ts +38 -0
- package/dist/storage/pointer-uri-allowlist.js +70 -0
- package/dist/storage/provider-metadata-projection.d.ts +27 -0
- package/dist/storage/provider-metadata-projection.js +68 -0
- package/dist/storage/providers/filecoin/backend.d.ts +42 -0
- package/dist/storage/providers/filecoin/backend.js +250 -0
- package/dist/storage/providers/filecoin/config.d.ts +70 -0
- package/dist/storage/providers/filecoin/config.js +275 -0
- package/dist/storage/providers/filecoin/errors.d.ts +45 -0
- package/dist/storage/providers/filecoin/errors.js +56 -0
- package/dist/storage/providers/filecoin/filecoin-pin-car.d.ts +78 -0
- package/dist/storage/providers/filecoin/filecoin-pin-car.js +155 -0
- package/dist/storage/providers/filecoin/filecoin-pin-client.d.ts +92 -0
- package/dist/storage/providers/filecoin/filecoin-pin-client.js +199 -0
- package/dist/storage/providers/filecoin/filecoin-pin-mapping.d.ts +58 -0
- package/dist/storage/providers/filecoin/filecoin-pin-mapping.js +103 -0
- package/dist/storage/providers/filecoin/filecoin-pin-timeout.d.ts +30 -0
- package/dist/storage/providers/filecoin/filecoin-pin-timeout.js +53 -0
- package/dist/storage/providers/filecoin/filecoin-pin-vendor.d.ts +111 -0
- package/dist/storage/providers/filecoin/filecoin-pin-vendor.js +87 -0
- package/dist/storage/providers/filecoin/hints.d.ts +71 -0
- package/dist/storage/providers/filecoin/hints.js +123 -0
- package/dist/storage/providers/filecoin/index.d.ts +51 -0
- package/dist/storage/providers/filecoin/index.js +103 -0
- package/dist/storage/providers/filecoin/ipfs-cid.d.ts +50 -0
- package/dist/storage/providers/filecoin/ipfs-cid.js +64 -0
- package/dist/storage/providers/filecoin/metadata.d.ts +72 -0
- package/dist/storage/providers/filecoin/metadata.js +137 -0
- package/dist/storage/providers/filecoin/piece-cid.d.ts +48 -0
- package/dist/storage/providers/filecoin/piece-cid.js +57 -0
- package/dist/storage/providers/filecoin/provider-client.d.ts +234 -0
- package/dist/storage/providers/filecoin/provider-client.js +27 -0
- package/dist/storage/providers/filecoin/readiness.d.ts +62 -0
- package/dist/storage/providers/filecoin/readiness.js +85 -0
- package/dist/storage/providers/filecoin/retriever.d.ts +82 -0
- package/dist/storage/providers/filecoin/retriever.js +63 -0
- package/dist/storage/providers/filecoin/skeleton-client.d.ts +36 -0
- package/dist/storage/providers/filecoin/skeleton-client.js +55 -0
- package/dist/storage/providers/filecoin/synapse-client.d.ts +169 -0
- package/dist/storage/providers/filecoin/synapse-client.js +343 -0
- package/dist/storage/providers/filecoin/synapse-construction.d.ts +26 -0
- package/dist/storage/providers/filecoin/synapse-construction.js +47 -0
- package/dist/storage/providers/filecoin/synapse-error-mapping.d.ts +23 -0
- package/dist/storage/providers/filecoin/synapse-error-mapping.js +49 -0
- package/dist/storage/providers/filecoin/synapse-readiness.d.ts +37 -0
- package/dist/storage/providers/filecoin/synapse-readiness.js +231 -0
- package/dist/storage/providers/filecoin/uri.d.ts +49 -0
- package/dist/storage/providers/filecoin/uri.js +84 -0
- package/dist/storage/providers/filecoin/verified-fetch-lifecycle.d.ts +77 -0
- package/dist/storage/providers/filecoin/verified-fetch-lifecycle.js +196 -0
- package/dist/storage/providers/filecoin/verified-fetch-retriever.d.ts +54 -0
- package/dist/storage/providers/filecoin/verified-fetch-retriever.js +81 -0
- package/dist/storage/providers/filecoin/verified-fetch-vendor.d.ts +71 -0
- package/dist/storage/providers/filecoin/verified-fetch-vendor.js +94 -0
- package/dist/storage/raw-content-codec.d.ts +89 -0
- package/dist/storage/raw-content-codec.js +47 -0
- package/dist/storage/raw-content-store-backend-adapter.d.ts +28 -0
- package/dist/storage/raw-content-store-backend-adapter.js +67 -0
- package/dist/storage/raw-content-store.d.ts +228 -0
- package/dist/storage/raw-content-store.js +27 -0
- package/dist/storage/s3-store.d.ts +42 -0
- package/dist/storage/s3-store.js +181 -0
- package/dist/storage/storage-backend-registry.d.ts +58 -0
- package/dist/storage/storage-backend-registry.js +56 -0
- package/dist/storage/storage-backend.d.ts +82 -0
- package/dist/storage/storage-backend.js +14 -0
- package/dist/storage/storage-capabilities.d.ts +56 -0
- package/dist/storage/storage-capabilities.js +170 -0
- package/dist/storage/store-registry.d.ts +67 -0
- package/dist/storage/store-registry.js +77 -0
- package/dist/vector-math.d.ts +15 -0
- package/dist/vector-math.js +31 -0
- package/dist/xml-escape.d.ts +5 -0
- package/dist/xml-escape.js +7 -0
- package/openapi.json +15395 -0
- package/openapi.yaml +10794 -0
- package/package.json +119 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core runtime container — the explicit composition root for atomicmemory-core.
|
|
3
|
+
*
|
|
4
|
+
* Owns the construction of config, pool, repositories, and services so
|
|
5
|
+
* startup (`server.ts`), tests, and in-process research harnesses all boot
|
|
6
|
+
* through the same seam. Replaces the hidden singleton wiring that used to
|
|
7
|
+
* live inline in `server.ts`.
|
|
8
|
+
*
|
|
9
|
+
* Runtime-container wiring — the composition root that replaces
|
|
10
|
+
* per-startup hand-wiring of repos and services in `server.ts`.
|
|
11
|
+
*/
|
|
12
|
+
import { applyRuntimeConfigUpdates, config as defaultConfig, } from '../config.js';
|
|
13
|
+
import { AgentTrustRepository } from '../db/agent-trust-repository.js';
|
|
14
|
+
import { BeliefEdgesRepository } from '../db/belief-edges-repository.js';
|
|
15
|
+
import { ClaimRepository } from '../db/claim-repository.js';
|
|
16
|
+
import { LinkRepository } from '../db/link-repository.js';
|
|
17
|
+
import { MemoryRepository } from '../db/memory-repository.js';
|
|
18
|
+
import { EntityRepository } from '../db/repository-entities.js';
|
|
19
|
+
import { EntityAttributesRepository } from '../db/repository-entity-attributes.js';
|
|
20
|
+
import { LessonRepository } from '../db/repository-lessons.js';
|
|
21
|
+
import { SummariesRepository } from '../db/summaries-repository.js';
|
|
22
|
+
import { UserProfileRepository } from '../db/repository-user-profiles.js';
|
|
23
|
+
import { ReflectionsRepository } from '../db/reflections-repository.js';
|
|
24
|
+
import { ReflectionJobsRepository } from '../db/reflection-jobs-repository.js';
|
|
25
|
+
import { EntityCardsRepository } from '../db/entity-cards-repository.js';
|
|
26
|
+
import { ContradictionsRepository } from '../db/contradictions-repository.js';
|
|
27
|
+
import { EntityValuesRepository } from '../db/entity-values-repository.js';
|
|
28
|
+
import { TllRepository } from '../db/repository-tll.js';
|
|
29
|
+
import { FirstMentionRepository } from '../db/repository-first-mentions.js';
|
|
30
|
+
import { DocumentService } from '../services/document-service.js';
|
|
31
|
+
import { StorageService } from '../services/storage-service.js';
|
|
32
|
+
import { RawContentStoreBackendAdapter } from '../storage/raw-content-store-backend-adapter.js';
|
|
33
|
+
import { buildBackendRegistry } from '../storage/storage-backend-registry.js';
|
|
34
|
+
import { buildRawContentStore, buildLegacyStores } from '../storage/factory.js';
|
|
35
|
+
import { buildStoreRegistry } from '../storage/store-registry.js';
|
|
36
|
+
import { buildRawContentCodec } from '../storage/codec-factory.js';
|
|
37
|
+
import { FirstMentionService } from '../services/first-mention-service.js';
|
|
38
|
+
import { llm } from '../services/llm.js';
|
|
39
|
+
import { PgMemoryStore } from '../db/pg-memory-store.js';
|
|
40
|
+
import { PgEpisodeStore } from '../db/pg-episode-store.js';
|
|
41
|
+
import { PgRecapStore } from '../db/pg-recap-store.js';
|
|
42
|
+
import { PgSearchStore } from '../db/pg-search-store.js';
|
|
43
|
+
import { PgSemanticLinkStore } from '../db/pg-link-store.js';
|
|
44
|
+
import { PgRepresentationStore } from '../db/pg-representation-store.js';
|
|
45
|
+
import { MemoryService } from '../services/memory-service.js';
|
|
46
|
+
import { initEmbedding, embedText } from '../services/embedding.js';
|
|
47
|
+
import { initLlm, callAnthropicTool } from '../services/llm.js';
|
|
48
|
+
import { runReflectForConversation } from '../services/reflect.js';
|
|
49
|
+
import { startReflectWorker } from '../services/reflect-jobs.js';
|
|
50
|
+
import { setBeliefDualWriteHook } from '../services/tbc-execution.js';
|
|
51
|
+
import { readRuntimeConfigRouteSnapshot, } from './runtime-config-route-snapshot.js';
|
|
52
|
+
/**
|
|
53
|
+
* Compose the core runtime. Instantiates repositories and the memory
|
|
54
|
+
* service from an explicit pool. Uses either the module-level config singleton
|
|
55
|
+
* or an explicit composition-time config and passes that same object into leaf
|
|
56
|
+
* module initializers and MemoryService so the composition root owns the seam.
|
|
57
|
+
* No mutation.
|
|
58
|
+
*/
|
|
59
|
+
// fallow-ignore-next-line complexity
|
|
60
|
+
export async function createCoreRuntime(deps) {
|
|
61
|
+
const { pool } = deps;
|
|
62
|
+
const runtimeConfig = deps.config ?? defaultConfig;
|
|
63
|
+
// Leaf-module config init. Embedding and LLM modules
|
|
64
|
+
// hold module-local config bound here at composition-root time.
|
|
65
|
+
// Provider/model selection is startup-only, so rebinding
|
|
66
|
+
// only happens via explicit init call (e.g., from tests that swap
|
|
67
|
+
// providers).
|
|
68
|
+
initEmbedding(runtimeConfig);
|
|
69
|
+
initLlm(runtimeConfig);
|
|
70
|
+
// Raw-content adapter. Built up front so it can be threaded
|
|
71
|
+
// into both the memory store layer (deleteAll honors managed-blob
|
|
72
|
+
// cleanup) and the document service (upload + delete cascade). Null
|
|
73
|
+
// for `rawStorageMode='pointer_only'` deployments. Async because the
|
|
74
|
+
// Filecoin provider construction is async — the
|
|
75
|
+
// plan's fail-closed rule requires credentials to be resolved at
|
|
76
|
+
// composition time, not at first upload.
|
|
77
|
+
const rawContentStore = await buildRawContentStore(runtimeConfig);
|
|
78
|
+
// Per-row dispatch registry. Active store + any legacy
|
|
79
|
+
// read-only adapters configured via `RAW_STORAGE_LEGACY_PROVIDERS`,
|
|
80
|
+
// wrapped in one `RawContentStoreRegistry` that cleanup helpers
|
|
81
|
+
// dispatch through.
|
|
82
|
+
const legacyStores = buildLegacyStores(runtimeConfig);
|
|
83
|
+
const storeRegistry = buildStoreRegistry(rawContentStore, legacyStores);
|
|
84
|
+
// Content codec — wraps adapter `put()` so the bytes sent
|
|
85
|
+
// to the provider may differ from the plaintext bytes the upload
|
|
86
|
+
// service hashes. Plaintext content_hash/size_bytes stay the row's
|
|
87
|
+
// source of truth; codec sidecar lands under raw_storage_metadata.codec.
|
|
88
|
+
const rawContentCodec = buildRawContentCodec(runtimeConfig);
|
|
89
|
+
const reconcilerDeps = buildReconcilerDeps(pool, rawContentStore, rawContentCodec, runtimeConfig);
|
|
90
|
+
const memory = new MemoryRepository(pool, { rawContentStore, storeRegistry });
|
|
91
|
+
const claims = new ClaimRepository(pool);
|
|
92
|
+
const trust = new AgentTrustRepository(pool);
|
|
93
|
+
const links = new LinkRepository(pool);
|
|
94
|
+
const entities = runtimeConfig.entityGraphEnabled ? new EntityRepository(pool) : null;
|
|
95
|
+
const lessons = runtimeConfig.lessonsEnabled ? new LessonRepository(pool) : null;
|
|
96
|
+
const beliefEdges = runtimeConfig.tbcEnabled ? new BeliefEdgesRepository(pool) : null;
|
|
97
|
+
const summaries = runtimeConfig.hierarchicalRetrievalEnabled ? new SummariesRepository(pool) : null;
|
|
98
|
+
const userProfile = runtimeConfig.userProfileChannelEnabled ? new UserProfileRepository(pool) : null;
|
|
99
|
+
const entityAttributes = runtimeConfig.entityAttributesEnabled ? new EntityAttributesRepository(pool) : null;
|
|
100
|
+
const reflections = runtimeConfig.reflectEnabled ? new ReflectionsRepository(pool) : null;
|
|
101
|
+
const reflectionJobs = runtimeConfig.reflectEnabled ? new ReflectionJobsRepository(pool) : null;
|
|
102
|
+
const entityValues = runtimeConfig.phase2SpecialistsEnabled ? new EntityValuesRepository(pool) : null;
|
|
103
|
+
const entityCards = runtimeConfig.entityCardEnabled ? new EntityCardsRepository(pool) : null;
|
|
104
|
+
const contradictions = buildContradictionsRepo(runtimeConfig, pool);
|
|
105
|
+
// TBC dual-write hook: when TBC is enabled, route belief operations
|
|
106
|
+
// through BeliefEdgesRepository (typed edges) and a direct SQL update
|
|
107
|
+
// on memories typed columns (confidence/belief_tier/mutation_type).
|
|
108
|
+
// The hook is process-global (module-level singleton in tbc-execution).
|
|
109
|
+
if (beliefEdges) {
|
|
110
|
+
setBeliefDualWriteHook({
|
|
111
|
+
async appendEdge(input) {
|
|
112
|
+
await beliefEdges.appendEdge({
|
|
113
|
+
userId: input.userId,
|
|
114
|
+
sourceId: input.sourceId,
|
|
115
|
+
targetId: input.targetId,
|
|
116
|
+
edgeType: input.edgeType,
|
|
117
|
+
weight: input.weight,
|
|
118
|
+
rationale: input.rationale,
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
async updateColumns(input) {
|
|
122
|
+
const fields = [];
|
|
123
|
+
const values = [];
|
|
124
|
+
let i = 1;
|
|
125
|
+
if (input.confidence !== undefined) {
|
|
126
|
+
fields.push(`confidence = $${i++}`);
|
|
127
|
+
values.push(input.confidence);
|
|
128
|
+
}
|
|
129
|
+
if (input.beliefTier !== undefined) {
|
|
130
|
+
fields.push(`belief_tier = $${i++}`);
|
|
131
|
+
values.push(input.beliefTier);
|
|
132
|
+
}
|
|
133
|
+
if (input.mutationType !== undefined) {
|
|
134
|
+
fields.push(`mutation_type = $${i++}`);
|
|
135
|
+
values.push(input.mutationType);
|
|
136
|
+
}
|
|
137
|
+
if (fields.length === 0)
|
|
138
|
+
return;
|
|
139
|
+
values.push(input.memoryId, input.userId);
|
|
140
|
+
await pool.query(`UPDATE memories SET ${fields.join(', ')} WHERE id = $${i++} AND user_id = $${i}`, values);
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
setBeliefDualWriteHook(undefined);
|
|
146
|
+
}
|
|
147
|
+
const stores = {
|
|
148
|
+
memory: new PgMemoryStore(pool, { rawContentStore, storeRegistry }),
|
|
149
|
+
episode: new PgEpisodeStore(pool),
|
|
150
|
+
recap: new PgRecapStore(pool),
|
|
151
|
+
search: new PgSearchStore(pool),
|
|
152
|
+
link: new PgSemanticLinkStore(pool),
|
|
153
|
+
representation: new PgRepresentationStore(pool),
|
|
154
|
+
claim: claims,
|
|
155
|
+
entity: entities,
|
|
156
|
+
entityAttributes,
|
|
157
|
+
lesson: lessons,
|
|
158
|
+
summaries,
|
|
159
|
+
userProfile,
|
|
160
|
+
reflections,
|
|
161
|
+
reflectionJobs,
|
|
162
|
+
beliefEdges,
|
|
163
|
+
entityValues,
|
|
164
|
+
entityCards,
|
|
165
|
+
contradictions,
|
|
166
|
+
pool,
|
|
167
|
+
};
|
|
168
|
+
// TLL — per-entity event chain for EO/MSR/TR queries.
|
|
169
|
+
// Append on memory store, traverse on retrieval.
|
|
170
|
+
const tllRepository = entities ? new TllRepository(pool) : null;
|
|
171
|
+
// First-mention events — chronological topic-introduction list. Caller
|
|
172
|
+
// (e.g. an external harness) drives extraction explicitly via the
|
|
173
|
+
// POST /v1/memories/first-mentions/extract route, supplying its own
|
|
174
|
+
// turn-id-to-memory-id mapping (the ingest pipeline does not retain
|
|
175
|
+
// turn structure). The chatFn adapter wraps the configured LLM
|
|
176
|
+
// singleton; per-call cost is logged inside `llm.chat`.
|
|
177
|
+
const firstMentionRepository = new FirstMentionRepository(pool);
|
|
178
|
+
const firstMentionService = new FirstMentionService(firstMentionRepository, async (system, user, maxTokens) => {
|
|
179
|
+
const text = await llm.chat([
|
|
180
|
+
{ role: 'system', content: system },
|
|
181
|
+
{ role: 'user', content: user },
|
|
182
|
+
], { maxTokens });
|
|
183
|
+
// Token usage is intentionally NOT returned here: `LLMProvider.chat`
|
|
184
|
+
// emits per-call cost telemetry via `writeCostEvent` internally
|
|
185
|
+
// (see `src/services/llm.ts`). Surfacing zeros at this seam invited
|
|
186
|
+
// the bug the prior reviewer caught — readers would treat them as
|
|
187
|
+
// real counts. Drop the field instead until usage is plumbed.
|
|
188
|
+
return { text };
|
|
189
|
+
});
|
|
190
|
+
// Document registry. Raw-content wiring provides a managed-blob
|
|
191
|
+
// `RawContentStore` when `rawStorageMode='managed_blob'`; pointer-only
|
|
192
|
+
// deployments get `null` here and the upload route returns 503. The
|
|
193
|
+
// same store is threaded into MemoryService so reset-source can clean
|
|
194
|
+
// up managed-blob URIs after the DB cascade.
|
|
195
|
+
const service = new MemoryService(memory, claims, entities ?? undefined, lessons ?? undefined, undefined, runtimeConfig, stores, tllRepository ?? undefined, firstMentionService, rawContentStore, storeRegistry);
|
|
196
|
+
const documents = new DocumentService(pool, {
|
|
197
|
+
rawContentStore,
|
|
198
|
+
storeRegistry,
|
|
199
|
+
codec: rawContentCodec,
|
|
200
|
+
config: runtimeConfig,
|
|
201
|
+
});
|
|
202
|
+
// Direct storage API service. Each registered `RawContentStore`
|
|
203
|
+
// (active + legacy) is wrapped in a `RawContentStoreBackendAdapter`
|
|
204
|
+
// so the storage service can dispatch by `storage_artifacts.provider`
|
|
205
|
+
// for read/delete/verify of historical rows whose provider differs
|
|
206
|
+
// from the current active backend. Pointer artifacts short-circuit
|
|
207
|
+
// before backend lookup so pointer-only deployments still work.
|
|
208
|
+
const backendRegistry = buildBackendRegistry(rawContentStore === null ? null : new RawContentStoreBackendAdapter(rawContentStore), storeRegistry.entries
|
|
209
|
+
.filter(([provider]) => provider !== rawContentStore?.provider)
|
|
210
|
+
.map(([, store]) => new RawContentStoreBackendAdapter(store)));
|
|
211
|
+
const storage = new StorageService({
|
|
212
|
+
pool,
|
|
213
|
+
backendRegistry,
|
|
214
|
+
pointerSchemes: runtimeConfig.rawStoragePointerUriSchemes,
|
|
215
|
+
storageKeyHmacSecret: runtimeConfig.storageKeyHmacSecret,
|
|
216
|
+
});
|
|
217
|
+
// Start the reflect background worker when reflect is enabled.
|
|
218
|
+
// The worker pulls pending reflection_jobs, runs the orchestrator,
|
|
219
|
+
// and marks each job completed or failed. It is intentionally
|
|
220
|
+
// fire-and-forget — the returned handle is not used here because the
|
|
221
|
+
// process lifecycle owns shutdown (SIGTERM/SIGINT in server.ts).
|
|
222
|
+
if (runtimeConfig.reflectEnabled && reflections && reflectionJobs) {
|
|
223
|
+
const entityCardDeps = buildEntityCardDeps(runtimeConfig, entityCards);
|
|
224
|
+
startReflectWorker({
|
|
225
|
+
jobs: reflectionJobs,
|
|
226
|
+
runReflect: (userId, conversationId) => runReflectForConversation({
|
|
227
|
+
fetchMemories: (u, c) => memory.findByConversation(u, c),
|
|
228
|
+
llmCallTool: (system, user, schema) => callAnthropicTool(runtimeConfig.reflectModel, system, user, schema),
|
|
229
|
+
embed: (text) => embedText(text),
|
|
230
|
+
reflections,
|
|
231
|
+
maxObservations: runtimeConfig.reflectMaxObservations,
|
|
232
|
+
entityCards: entityCardDeps,
|
|
233
|
+
}, userId, conversationId),
|
|
234
|
+
}, runtimeConfig.reflectJobPollMs);
|
|
235
|
+
}
|
|
236
|
+
return {
|
|
237
|
+
config: runtimeConfig,
|
|
238
|
+
configRouteAdapter: {
|
|
239
|
+
base() {
|
|
240
|
+
return runtimeConfig;
|
|
241
|
+
},
|
|
242
|
+
current() {
|
|
243
|
+
return readRuntimeConfigRouteSnapshot(runtimeConfig);
|
|
244
|
+
},
|
|
245
|
+
update(updates) {
|
|
246
|
+
return applyRuntimeConfigUpdates(runtimeConfig, updates);
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
pool,
|
|
250
|
+
repos: { memory, claims, trust, links, entities, lessons, beliefEdges },
|
|
251
|
+
stores,
|
|
252
|
+
services: { memory: service, documents, storage },
|
|
253
|
+
rawContentStore,
|
|
254
|
+
storeRegistry,
|
|
255
|
+
reconcilerDeps,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Build the optional entity-card synthesis deps for the Reflect worker.
|
|
260
|
+
* Returns `undefined` when the channel is disabled or the repo is null
|
|
261
|
+
* — `runReflectForConversation` short-circuits on a missing/disabled bag.
|
|
262
|
+
*/
|
|
263
|
+
function buildEntityCardDeps(runtimeConfig, entityCards) {
|
|
264
|
+
if (!entityCards || !runtimeConfig.entityCardEnabled)
|
|
265
|
+
return undefined;
|
|
266
|
+
return {
|
|
267
|
+
enabled: true,
|
|
268
|
+
repo: entityCards,
|
|
269
|
+
synth: {
|
|
270
|
+
llmCallTool: (system, user, schema) => callAnthropicTool(runtimeConfig.reflectModel, system, user, schema),
|
|
271
|
+
minObservations: runtimeConfig.entityCardMinObservations,
|
|
272
|
+
maxEntities: runtimeConfig.entityCardMaxPerSession,
|
|
273
|
+
},
|
|
274
|
+
maxCardsPerSession: runtimeConfig.entityCardMaxPerSession,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* BEAM CR fix: bilateral preservation. The repo is instantiated when either
|
|
279
|
+
* the write-side preservation OR the read-side surfacing is enabled, since
|
|
280
|
+
* retrieval enrichment needs to read pre-existing contradictions even when
|
|
281
|
+
* the write-side flag has since been turned off. Extracted as a helper to
|
|
282
|
+
* keep `createCoreRuntime` below the cyclomatic-complexity baseline.
|
|
283
|
+
*/
|
|
284
|
+
function buildContradictionsRepo(runtimeConfig, pool) {
|
|
285
|
+
const needsRepo = runtimeConfig.contradictionPreservationEnabled ||
|
|
286
|
+
runtimeConfig.contradictionSurfacingEnabled;
|
|
287
|
+
return needsRepo ? new ContradictionsRepository(pool) : null;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Build the reconciler dependency bundle. Returns `null` until
|
|
291
|
+
* production reconciler scheduling is enabled for the active provider.
|
|
292
|
+
* The reconciler module remains in place so provider wiring can opt in
|
|
293
|
+
* without changing the route layer.
|
|
294
|
+
*/
|
|
295
|
+
function buildReconcilerDeps(_pool, _rawContentStore, _codec, _cfg) {
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Startup guard functions run before the HTTP server accepts traffic.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `server.ts` so tests can exercise individual checks and
|
|
5
|
+
* future startup guards can be added without growing the server bootstrap
|
|
6
|
+
* module. Phase 1A of the rearchitecture.
|
|
7
|
+
*/
|
|
8
|
+
import pg from 'pg';
|
|
9
|
+
import type { CoreRuntimeConfig } from './runtime-container.js';
|
|
10
|
+
/**
|
|
11
|
+
* Result of an embedding dimension check against the `memories.embedding`
|
|
12
|
+
* column. `ok=false` means the process should exit before serving traffic.
|
|
13
|
+
*/
|
|
14
|
+
export interface EmbeddingDimensionCheckResult {
|
|
15
|
+
ok: boolean;
|
|
16
|
+
dbDims: number | null;
|
|
17
|
+
configDims: number;
|
|
18
|
+
message: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Verify DB embedding column dimensions match the configured embedding size.
|
|
22
|
+
* Catches the "expected N dimensions, not M" class of errors at startup,
|
|
23
|
+
* which would otherwise surface as opaque insert failures during ingest.
|
|
24
|
+
*
|
|
25
|
+
* This function never throws or exits — it returns a structured result so
|
|
26
|
+
* the caller decides how to react (log + exit at boot, throw in tests).
|
|
27
|
+
*/
|
|
28
|
+
export declare function checkEmbeddingDimensions(pool: pg.Pool, config: CoreRuntimeConfig): Promise<EmbeddingDimensionCheckResult>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Startup guard functions run before the HTTP server accepts traffic.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `server.ts` so tests can exercise individual checks and
|
|
5
|
+
* future startup guards can be added without growing the server bootstrap
|
|
6
|
+
* module. Phase 1A of the rearchitecture.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Verify DB embedding column dimensions match the configured embedding size.
|
|
10
|
+
* Catches the "expected N dimensions, not M" class of errors at startup,
|
|
11
|
+
* which would otherwise surface as opaque insert failures during ingest.
|
|
12
|
+
*
|
|
13
|
+
* This function never throws or exits — it returns a structured result so
|
|
14
|
+
* the caller decides how to react (log + exit at boot, throw in tests).
|
|
15
|
+
*/
|
|
16
|
+
export async function checkEmbeddingDimensions(pool, config) {
|
|
17
|
+
const { rows } = await pool.query(`SELECT atttypmod AS typmod
|
|
18
|
+
FROM pg_attribute a
|
|
19
|
+
JOIN pg_class c ON a.attrelid = c.oid
|
|
20
|
+
WHERE c.relname = 'memories' AND a.attname = 'embedding'`);
|
|
21
|
+
if (rows.length === 0) {
|
|
22
|
+
return {
|
|
23
|
+
ok: false,
|
|
24
|
+
dbDims: null,
|
|
25
|
+
configDims: config.embeddingDimensions,
|
|
26
|
+
message: 'memories.embedding column not found — run npm run migrate first',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const dbDims = rows[0].typmod > 0 ? rows[0].typmod : null;
|
|
30
|
+
if (dbDims !== null && dbDims !== config.embeddingDimensions) {
|
|
31
|
+
return {
|
|
32
|
+
ok: false,
|
|
33
|
+
dbDims,
|
|
34
|
+
configDims: config.embeddingDimensions,
|
|
35
|
+
message: `DB vector column is ${dbDims} dimensions but EMBEDDING_DIMENSIONS=${config.embeddingDimensions}. ` +
|
|
36
|
+
`Fix: set EMBEDDING_DIMENSIONS=${dbDims} or run 'npm run migrate' to recreate the schema.`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
ok: true,
|
|
41
|
+
dbDims,
|
|
42
|
+
configDims: config.embeddingDimensions,
|
|
43
|
+
message: `Embedding dimensions OK: config=${config.embeddingDimensions}, DB=${dbDims ?? 'unset'}`,
|
|
44
|
+
};
|
|
45
|
+
}
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* AtomicMemory Core CLI entry point.
|
|
4
|
+
*
|
|
5
|
+
* Keeps npm execution intentionally thin: it applies an explicit local
|
|
6
|
+
* development profile when requested, then delegates to the same server and
|
|
7
|
+
* migration entry points used by source and Docker workflows.
|
|
8
|
+
*/
|
|
9
|
+
type CommandName = 'start' | 'migrate';
|
|
10
|
+
type ProfileName = 'local';
|
|
11
|
+
interface ParsedArgs {
|
|
12
|
+
command: CommandName | null;
|
|
13
|
+
help: boolean;
|
|
14
|
+
profile: ProfileName | null;
|
|
15
|
+
}
|
|
16
|
+
export declare function parseCliArgs(argv: string[]): ParsedArgs;
|
|
17
|
+
export {};
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* AtomicMemory Core CLI entry point.
|
|
4
|
+
*
|
|
5
|
+
* Keeps npm execution intentionally thin: it applies an explicit local
|
|
6
|
+
* development profile when requested, then delegates to the same server and
|
|
7
|
+
* migration entry points used by source and Docker workflows.
|
|
8
|
+
*/
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
const LOCAL_PROFILE_DEFAULTS = {
|
|
11
|
+
CORE_API_KEY: 'local-dev-key',
|
|
12
|
+
EMBEDDING_DIMENSIONS: '384',
|
|
13
|
+
EMBEDDING_MODEL: 'Xenova/all-MiniLM-L6-v2',
|
|
14
|
+
EMBEDDING_PROVIDER: 'transformers',
|
|
15
|
+
LLM_PROVIDER: 'claude-code',
|
|
16
|
+
PORT: '3050',
|
|
17
|
+
RAW_STORAGE_DEPLOYMENT_ENV: 'local',
|
|
18
|
+
RAW_STORAGE_MODE: 'pointer_only',
|
|
19
|
+
STORAGE_KEY_HMAC_SECRET: '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
|
|
20
|
+
};
|
|
21
|
+
function printHelp() {
|
|
22
|
+
console.log(`AtomicMemory Core
|
|
23
|
+
|
|
24
|
+
Usage:
|
|
25
|
+
atomicmemory-core start [--profile local]
|
|
26
|
+
atomicmemory-core migrate [--profile local]
|
|
27
|
+
|
|
28
|
+
Commands:
|
|
29
|
+
start Start the HTTP API server
|
|
30
|
+
migrate Apply the Postgres/pgvector schema
|
|
31
|
+
|
|
32
|
+
Profiles:
|
|
33
|
+
local Fill local-only defaults for port, auth, storage policy,
|
|
34
|
+
transformers embeddings, and Claude Code LLM.
|
|
35
|
+
|
|
36
|
+
Required:
|
|
37
|
+
DATABASE_URL must point at a reachable Postgres database with pgvector.
|
|
38
|
+
`);
|
|
39
|
+
}
|
|
40
|
+
export function parseCliArgs(argv) {
|
|
41
|
+
const [commandArg, ...rest] = argv;
|
|
42
|
+
return {
|
|
43
|
+
command: parseCommand(commandArg),
|
|
44
|
+
help: shouldShowHelp(argv, commandArg),
|
|
45
|
+
profile: parseProfile(rest),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function parseCommand(value) {
|
|
49
|
+
if (value === 'start' || value === 'migrate')
|
|
50
|
+
return value;
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function shouldShowHelp(argv, commandArg) {
|
|
54
|
+
return argv.includes('--help') || argv.includes('-h') || !commandArg;
|
|
55
|
+
}
|
|
56
|
+
function parseProfile(argv) {
|
|
57
|
+
const profileIndex = argv.indexOf('--profile');
|
|
58
|
+
if (profileIndex < 0) {
|
|
59
|
+
assertNoUnknownArgs(argv);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const value = argv[profileIndex + 1];
|
|
63
|
+
if (value !== 'local')
|
|
64
|
+
throw new Error(`Unsupported profile: ${value ?? '<missing>'}`);
|
|
65
|
+
assertNoUnknownArgs([
|
|
66
|
+
...argv.slice(0, profileIndex),
|
|
67
|
+
...argv.slice(profileIndex + 2),
|
|
68
|
+
]);
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
function assertNoUnknownArgs(argv) {
|
|
72
|
+
const unknown = argv.find((arg) => arg !== '--help' && arg !== '-h');
|
|
73
|
+
if (unknown)
|
|
74
|
+
throw new Error(`Unknown argument: ${unknown}`);
|
|
75
|
+
}
|
|
76
|
+
function applyLocalProfileDefaults() {
|
|
77
|
+
const applied = [];
|
|
78
|
+
for (const [key, value] of Object.entries(LOCAL_PROFILE_DEFAULTS)) {
|
|
79
|
+
if (process.env[key])
|
|
80
|
+
continue;
|
|
81
|
+
process.env[key] = value;
|
|
82
|
+
applied.push(key);
|
|
83
|
+
}
|
|
84
|
+
return applied;
|
|
85
|
+
}
|
|
86
|
+
function assertLocalProfileReady() {
|
|
87
|
+
if (process.env.DATABASE_URL)
|
|
88
|
+
return;
|
|
89
|
+
throw new Error("DATABASE_URL is required. For local testing, start Postgres/pgvector and set " +
|
|
90
|
+
"DATABASE_URL='postgresql://user:pass@host:5432/database'.");
|
|
91
|
+
}
|
|
92
|
+
async function runCommand(command) {
|
|
93
|
+
if (command === 'start') {
|
|
94
|
+
await import('./server.js');
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
await import('./db/migrate.js');
|
|
98
|
+
}
|
|
99
|
+
async function main(argv) {
|
|
100
|
+
const parsed = parseCliArgs(argv);
|
|
101
|
+
if (parsed.help) {
|
|
102
|
+
printHelp();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (!parsed.command)
|
|
106
|
+
throw new Error(`Unknown command: ${argv[0]}`);
|
|
107
|
+
applyProfile(parsed.profile);
|
|
108
|
+
await runCommand(parsed.command);
|
|
109
|
+
}
|
|
110
|
+
function applyProfile(profile) {
|
|
111
|
+
if (profile !== 'local')
|
|
112
|
+
return;
|
|
113
|
+
const applied = applyLocalProfileDefaults();
|
|
114
|
+
if (applied.length > 0) {
|
|
115
|
+
console.log(`[cli] Applied local profile defaults: ${applied.join(', ')}`);
|
|
116
|
+
}
|
|
117
|
+
assertLocalProfileReady();
|
|
118
|
+
}
|
|
119
|
+
function isEntrypoint() {
|
|
120
|
+
const invokedPath = process.argv[1] ?? '';
|
|
121
|
+
return invokedPath === fileURLToPath(import.meta.url) || invokedPath.endsWith('/atomicmemory-core');
|
|
122
|
+
}
|
|
123
|
+
if (isEntrypoint()) {
|
|
124
|
+
main(process.argv.slice(2)).catch((err) => {
|
|
125
|
+
console.error(err instanceof Error ? err.message : err);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
});
|
|
128
|
+
}
|