Skip to main content

exo_dag_db_postgres/
lib.rs

1//! PostgreSQL persistence adapters for DAG DB.
2//!
3//! Facade removal is complete; this crate owns SQLx-backed migrations, import,
4//! export, writeback, context selection, idempotency, outbox, and persistence
5//! adapters. Downstream compatibility uses explicit bridges such as
6//! `exo_api::dagdb`.
7
8#![cfg_attr(test, allow(clippy::expect_used, clippy::unwrap_used))]
9
10#[cfg(feature = "postgres")]
11pub use exo_dag_db_core::hash::{
12    AgentMemorySafetyScoreIdMaterial, CatalogEntryIdMaterial, ContextPacketIdMaterial,
13    CouncilDecisionIdMaterial, InboundAgentCredentialIdMaterial, ParentLink, ReceiptHashMaterial,
14    ReceiptMemoryObjectIdMaterial, RequestHashMaterial, RouteIdMaterial,
15    ValidationReportIdMaterial,
16};
17#[cfg(feature = "postgres")]
18pub use exo_dag_db_core::{error, hash, metadata, similarity, tenant};
19#[cfg(feature = "postgres")]
20pub use exo_dag_db_domain::{
21    context, context_packet_persistence, continuation_packet, continuation_persistence,
22    default_route, export_finality, graph, lifecycle_action, model, placement, route_invalidation,
23    scoring, state,
24};
25#[cfg(feature = "postgres")]
26pub use exo_dag_db_domain::{
27    context::{ContextPacketDomainInput, build_context_packet},
28    context_packet_persistence::{
29        CONTEXT_PACKET_RECORD_SCHEMA_VERSION, ContextPacketRecord, DefaultContextQuality,
30        PacketFreshnessStatus, PacketPersistenceStatus, PacketValidationStatus,
31        canonical_idempotency_key,
32    },
33    export_finality::ExportFinalityError,
34    graph::{MemoryGraphEdge, MemoryGraphNode, PlacementTraceStep, required_placement_steps},
35    lifecycle_action::{
36        LifecycleAction, LifecycleActionError, LifecycleActionLedger, LifecycleActionType,
37        LifecycleApplyResult, LifecycleEvidenceRef, LifecycleMemoryRef, LifecycleRollbackRef,
38        LifecycleTerminalState, PRD17_LIFECYCLE_ACTION_SCHEMA,
39        PRD17_LIFECYCLE_MUTATION_REPORT_SCHEMA, ProductionLifecycleApproval,
40    },
41    model::{
42        AgentMemorySafetyScore, CatalogEntry, ContextPacket, CouncilDecision, DagDbAuthorizedScope,
43        InboundAgentCredential, MemoryCandidateEmitter, MemoryCandidateValidationError,
44        OutputObserver, ReceiptMemoryObject, RouteMemoryReceipt, TaskAgentWritebackHint,
45        ValidationReport,
46    },
47    placement::{
48        GraphOrganizer, MemoryPlacementController, MemoryPlacementInput, PlacementExistingMemory,
49    },
50    scoring::{DomainError, DomainResult},
51};
52#[cfg(feature = "postgres")]
53pub use exo_dag_db_exchange::{kg_export, kg_import, kg_writeback, kg_writeback_hygiene};
54#[cfg(feature = "postgres")]
55pub use exo_dag_db_exchange::{
56    kg_export::{
57        KG_EXPORT_DATABASE_URL_ENV, KG_EXPORT_FINALITY_OUTBOX_ROUTE_NAME,
58        KG_EXPORT_FINALITY_OUTBOX_SUMMARY_SCHEMA, KG_EXPORT_JSON_PATH, KG_EXPORT_MD_PATH,
59        KG_EXPORT_PERSISTED_ROUTE_NAME, KG_EXPORT_PERSISTED_SUMMARY_SCHEMA,
60        KG_EXPORT_PERSISTENCE_VERIFICATION_SCHEMA, KG_EXPORT_REPORT_ROUTE_NAME,
61        KG_EXPORT_TARGET_DIR, KG_PORTABLE_EXPORT_SCHEMA, KG_PORTABLE_EXPORT_SUMMARY_SCHEMA,
62        KgExportAcceptance, KgExportArtifactSet, KgExportBuildInput, KgExportError,
63        KgExportFinalityOutboxAdvisoryDiagnostics, KgExportFinalityOutboxChallengeDiagnostics,
64        KgExportFinalityOutboxDiagnostics, KgExportFinalityOutboxEvidenceDiagnostics,
65        KgExportFinalityOutboxReceiptDiagnostics, KgExportFinalityOutboxRequest,
66        KgExportFinalityOutboxRowDiagnostics, KgExportFinalityOutboxSummary, KgExportHashes,
67        KgExportHlc, KgExportPersistedAdvisoryDiagnostics, KgExportPersistedChallengeDiagnostics,
68        KgExportPersistedDiagnostics, KgExportPersistedEvidenceDiagnostics,
69        KgExportPersistedIdempotencyDiagnostics, KgExportPersistedReceiptDiagnostics,
70        KgExportPersistedRowCounts, KgExportPersistedSectionDiagnostics, KgExportPersistedSummary,
71        KgExportPersistenceVerificationSummary, KgExportRecord, KgExportScope,
72        KgExportVerification, KgPortableExport, build_portable_export, kg_export_markdown_summary,
73        parse_portable_export_json, reject_forbidden_export_json, reject_forbidden_string,
74        validate_portable_export_for_persistence, write_default_kg_export_artifacts,
75        write_kg_export_artifacts,
76    },
77    kg_import::{
78        KG_IMPORT_CANDIDATES_SCHEMA, KG_IMPORT_DATABASE_URL_ENV, KG_IMPORT_DRY_RUN_REPORT_SCHEMA,
79        KG_IMPORT_PERSISTED_ROUTE_NAME, KG_IMPORT_PERSISTED_SUMMARY_SCHEMA, KgImportDryRunReport,
80        KgImportError, KgImportPersistedSummary, hash_from_hex, required_trace, stable_hash,
81    },
82    kg_writeback::{
83        KG_WRITEBACK_DATABASE_URL_ENV, KG_WRITEBACK_DRY_RUN_JSON_PATH,
84        KG_WRITEBACK_DRY_RUN_MD_PATH, KG_WRITEBACK_DRY_RUN_REPORT_SCHEMA,
85        KG_WRITEBACK_DRY_RUN_ROUTE_NAME, KG_WRITEBACK_DRY_RUN_SUMMARY_SCHEMA,
86        KG_WRITEBACK_DRY_RUN_TARGET_DIR, KG_WRITEBACK_PERSISTED_ROUTE_NAME,
87        KG_WRITEBACK_PERSISTED_SUMMARY_SCHEMA, KgAgentWritebackHint, KgWritebackArtifactSet,
88        KgWritebackDryRunReport, KgWritebackError, KgWritebackEvidenceBinding,
89        KgWritebackExistingMemory, KgWritebackLayeredWriteback,
90        KgWritebackPersistedLayerDiagnostics, KgWritebackPersistedSummary,
91        KgWritebackProposalRequest, build_writeback_dry_run_report,
92        parse_agent_writeback_hint_json, write_default_writeback_dry_run_artifacts,
93        write_writeback_dry_run_artifacts, writeback_markdown_summary,
94    },
95};
96#[cfg(feature = "postgres")]
97pub use exo_dag_db_graph::{
98    layer_creation_policy, layered_graph, layered_hygiene, layered_placement,
99};
100#[cfg(feature = "postgres")]
101pub use exo_dag_db_graph::{
102    layer_creation_policy::{
103        LAYER_CREATION_MAX_DEPTH, LAYER_CREATION_POLICY_SCHEMA_VERSION,
104        LAYER_CREATION_POLICY_VERSION,
105    },
106    layered_graph::{
107        LAYERED_GRAPH_INVARIANT_REPORT_SCHEMA_VERSION, LayeredGraphInvariantError,
108        LayeredGraphInvariantFailure, LayeredGraphInvariantReport, LayeredGraphLayer,
109        LayeredGraphLayerEdge, LayeredGraphLayerEdgeKind, LayeredGraphLayerKind,
110        LayeredGraphMembership, LayeredGraphMembershipRole, LayeredGraphNodeRef,
111        LayeredGraphValidationStatus, build_layered_graph_invariant_report,
112        validate_layered_graph_invariants,
113    },
114    layered_hygiene::{
115        LayerHygieneEdgeState, LayerHygienePlan, LayerHygienePolicy,
116        build_layered_retrieval_hygiene_report,
117    },
118    layered_placement::{
119        LAYER_PLACEMENT_KNOWLEDGE_GRAPH_PATH, LAYER_PLACEMENT_MAX_DEPTH,
120        LAYER_PLACEMENT_REPOSITORY_PATH, LAYER_PLACEMENT_ROOT_PATH, LayerPlacementError,
121        LayerPlacementRequest, LayerPlacementSelection, LayerPlacementSourceKind,
122        deterministic_layer_edge_id, deterministic_layer_id, deterministic_layer_membership_id,
123        select_target_layer,
124    },
125};
126#[cfg(feature = "postgres")]
127pub use exo_dag_db_retrieval::context_packet_output::build_graph_context_packet;
128#[cfg(feature = "postgres")]
129pub use exo_dag_db_retrieval::{
130    context_packet_output::{
131        GRAPH_CONTEXT_PACKET_SCHEMA_VERSION, LAYERED_CONTEXT_PACKET_OUTPUT_SCHEMA_VERSION,
132        LayeredContextPacketAdditions, LayeredContextPacketBudgetReport,
133        LayeredContextPacketHygieneReport, LayeredContextPacketOutput,
134        LayeredContextPacketRollupSummary, LayeredContextPacketSelectedLayer,
135        LayeredContextPacketSelectedLayerEdge, build_layered_context_packet_output,
136    },
137    graph_context_selection::{
138        GraphContextMemoryCandidate, GraphContextSelectionState, MAX_FAMILY_REF_SHARE,
139        MAX_ROLLUP_SCORE_BP, MAX_SELECTED_GRAPH_EDGES_PER_PACKET, ROLLUP_SCORING_SHARE_BP,
140        TASK_BUDGET_CAP_TOKENS, TASK_BUDGET_FLOOR_TOKENS, TaskBudgetClass,
141        classify_task_budget_class, rollup_score_for_root, task_budget_tokens,
142    },
143    kg_catalog_router::{
144        KG_CATALOG_ROUTER_PREVIEW_SCHEMA, KgCatalogPathCandidate, KgCatalogRouterBoundaries,
145        KgCatalogRouterBoundaryStatus, KgCatalogRouterEdgeActionClassification,
146        KgCatalogRouterError, KgCatalogRouterGraphEdgeRef, KgCatalogRouterMemoryRef,
147        KgCatalogRouterOmittedRef, KgCatalogRouterPacketMetrics, KgCatalogRouterPreview,
148        KgCatalogRouterScoreComponent, KgCatalogRouterSubgraphRecommendationKind,
149        KgCatalogRouterTaskInput, KgSelectedCatalogRoute, KgSubgraphDelegationRecommendation,
150    },
151    kg_retrieval::{
152        KG_CONTEXT_PACKET_PREVIEW_SCHEMA, KG_RETRIEVAL_DATABASE_URL_ENV,
153        KG_RETRIEVAL_DEFAULT_MAX_LAYER_DEPTH, KG_RETRIEVAL_DEFAULT_MAX_LAYER_EDGES,
154        KG_RETRIEVAL_DEFAULT_MAX_LAYERS_SELECTED, KG_RETRIEVAL_DEFAULT_MAX_MEMORY_REFS,
155        KG_RETRIEVAL_DEFAULT_MAX_NODES_PER_LAYER, KG_RETRIEVAL_PREVIEW_ROUTE_NAME,
156        KgCitationHandle, KgContextPacketPreview, KgGraphEdgeRef, KgLayerBudgetReport,
157        KgLayerCandidate, KgLayerEdgeCandidate, KgLayerEdgeRef, KgLayeredRetrievalBudgetReport,
158        KgLayeredRetrievalBudgets, KgLayeredRetrievalRequest, KgLayeredRetrievalSelection,
159        KgMemoryRef, KgRetrievalDiagnostics, KgRetrievalError, KgRetrievalRequest,
160        KgRollupSummaryRef, KgSelectedLayer, KgSelectedLayerEdge, KgSelectedLayerRef,
161        KgValidationSummary, select_layered_retrieval_candidates,
162    },
163    layered_drilldown::{
164        LAYERED_DRILLDOWN_MAX_CHILD_REFS_PER_ROOT, LAYERED_DRILLDOWN_MAX_RESERVE_BP,
165        LAYERED_DRILLDOWN_ROOT_FLAG_PREFIX, LAYERED_DRILLDOWN_SELECTION_REASON,
166        drilldown_effective_max_depth, drilldown_reserved_breadth_budget, drilldown_root_flag,
167        layered_drilldown_active,
168    },
169    query::{
170        GraphQueryService, GraphQueryState, build_context_packet_graph,
171        emit_route_invalidation_receipt, graph_route_planner_order,
172    },
173    views::{
174        GraphViewError, GraphViewSource, build_graph_view, regenerate_graph_view_if_stale,
175        topological_order, transitive_reduction,
176    },
177};
178#[cfg(feature = "postgres")]
179pub use exo_dag_db_retrieval::{
180    graph_context_selection, kg_catalog_router, kg_retrieval, layered_drilldown,
181};
182#[cfg(feature = "postgres")]
183pub use graph_context_selection::select_graph_context;
184#[cfg(feature = "postgres")]
185pub use persistent_context::{
186    PersistentGraphContextPacket, PersistentGraphContextSelection,
187    build_persistent_graph_context_packet,
188    build_persistent_graph_context_packet_with_layered_drilldown,
189    build_persistent_graph_context_selection,
190    build_persistent_graph_context_selection_with_layered_drilldown,
191};
192#[cfg(feature = "postgres")]
193pub use postgres::kg_catalog_router::{
194    KgCatalogRouterPostgresError, build_kg_catalog_router_preview,
195    build_kg_catalog_router_preview_from_database_url, build_kg_catalog_router_preview_from_env,
196};
197#[cfg(feature = "postgres")]
198pub use postgres::kg_context_selection_write::{
199    CONTEXT_SELECTION_PACKET_RECEIPT_ROUTE_NAME, CONTEXT_SELECTION_USAGE_EVENT_ROUTE_NAME,
200    DbWriteSummary, persist_context_packet_receipt_to_db, persist_usage_event_to_db,
201};
202
203#[cfg(feature = "postgres")]
204pub mod idempotency;
205#[cfg(feature = "postgres")]
206pub mod outbox;
207#[cfg(feature = "postgres")]
208pub mod persistent_context;
209#[cfg(feature = "postgres")]
210pub mod postgres;
211#[cfg(feature = "postgres")]
212pub mod receipt;