NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
synthesis.h
Go to the documentation of this file.
1
2#pragma once
3
9
10#include <cstddef>
11#include <cstdint>
12#include <functional>
13#include <memory>
14#include <optional>
15#include <stdexcept>
16#include <string>
17#include <string_view>
18#include <vector>
19
20namespace neograph::program {
21
22struct ProgramSynthesisProposalData {
23 std::string owner_scope;
24 std::string lineage_id;
25 std::string parent_run_id;
26 std::optional<std::string> instruction_id;
27 std::optional<ProgramSource> source;
28 std::vector<std::string> requested_capabilities;
29 std::vector<std::string> requested_effects;
30 RunBudget requested_budget;
31 std::int64_t created_at_ms = 0;
32};
33
35class NEOGRAPH_PROGRAM_API ProgramSynthesisProposal final {
36public:
37 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
38 static ProgramSynthesisProposal create(ProgramSynthesisProposalData data);
39 static ProgramSynthesisProposal parse(std::string_view stored_bytes);
40
41 const ProgramSynthesisProposalData& data() const noexcept;
42 const ProgramSource& source() const noexcept;
43 const std::string& id() const noexcept;
44 std::string serialize_canonical() const;
45
46private:
47 struct Impl;
48 explicit ProgramSynthesisProposal(std::shared_ptr<const Impl> impl);
49 std::shared_ptr<const Impl> impl_;
50};
51
52struct ProgramSynthesisReservationData {
53 std::string proposal_id;
54 std::string lineage_id;
55 std::string source_lineage_head_id;
56 std::string reserved_lineage_head_id;
57 RunBudget source_remaining;
58 RunBudget remaining_after_reservation;
59};
60
62class NEOGRAPH_PROGRAM_API ProgramSynthesisReservation final {
63public:
64 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
65 static ProgramSynthesisReservation create(ProgramSynthesisReservationData data);
66 static ProgramSynthesisReservation parse(std::string_view stored_bytes);
67
68 const ProgramSynthesisReservationData& data() const noexcept;
69 const std::string& id() const noexcept;
70 std::string serialize_canonical() const;
71
72private:
73 struct Impl;
74 explicit ProgramSynthesisReservation(std::shared_ptr<const Impl> impl);
75 std::shared_ptr<const Impl> impl_;
76};
77
78struct ProgramSynthesisReceiptData {
79 std::string proposal_id;
80 std::string reservation_id;
81 std::string bundle_id;
82 std::string program_version_id;
83 std::string policy_snapshot_fingerprint;
84};
85
86struct ProgramSynthesisSemanticDecision {
87 std::string validator_identity;
88 std::string contract_identity;
89 bool accepted = false;
90 json evidence = json::object();
91};
92
93struct ProgramSynthesisValidationReceiptData {
94 std::string proposal_id;
95 std::string reservation_id;
96 std::string bundle_id;
97 std::string validator_identity;
98 std::string contract_identity;
99 bool accepted = false;
100 std::string evidence_digest;
101};
102
104class NEOGRAPH_PROGRAM_API ProgramSynthesisValidationReceipt final {
105public:
106 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
107 static ProgramSynthesisValidationReceipt create(ProgramSynthesisValidationReceiptData data);
108 static ProgramSynthesisValidationReceipt parse(std::string_view stored_bytes);
109
110 const ProgramSynthesisValidationReceiptData& data() const noexcept;
111 const std::string& id() const noexcept;
112 std::string serialize_canonical() const;
113
114private:
115 struct Impl;
116 explicit ProgramSynthesisValidationReceipt(std::shared_ptr<const Impl> impl);
117 std::shared_ptr<const Impl> impl_;
118};
119
120NEOGRAPH_PROGRAM_API void validate_program_synthesis_validation_evidence(
122 const json& evidence);
123
125class NEOGRAPH_PROGRAM_API ProgramSynthesisValidationError final
126 : public std::runtime_error {
127public:
129
130 const ProgramSynthesisValidationReceipt& receipt() const noexcept;
131 const json& evidence() const noexcept;
132
133private:
135 json evidence_;
136};
137
138class NEOGRAPH_PROGRAM_API ProgramSynthesisReceipt final {
139public:
140 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
141 static ProgramSynthesisReceipt create(ProgramSynthesisReceiptData data);
142 static ProgramSynthesisReceipt parse(std::string_view stored_bytes);
143
144 const ProgramSynthesisReceiptData& data() const noexcept;
145 const std::string& id() const noexcept;
146 std::string serialize_canonical() const;
147
148private:
149 struct Impl;
150 explicit ProgramSynthesisReceipt(std::shared_ptr<const Impl> impl);
151 std::shared_ptr<const Impl> impl_;
152};
153
154using ProgramSynthesisReservationResolver =
156using ProgramSynthesisAdmissionResolver =
157 std::function<ProgramAdmission(const ProgramSynthesisProposal&,
158 const ProgramBundle&,
160using ProgramSynthesisSemanticValidator =
161 std::function<ProgramSynthesisSemanticDecision(const ProgramSynthesisProposal&,
162 const ProgramBundle&,
164
169
170struct ProgramSynthesisGatewayConfig {
171 std::shared_ptr<ProgramCompiler> compiler;
172 std::shared_ptr<ProgramCatalog> catalog;
173 ProgramSynthesisReservationResolver reserve;
174 ProgramSynthesisAdmissionResolver admission;
175 std::size_t max_source_bytes = 1024 * 1024;
177 ProgramSynthesisSemanticValidator validate_semantics;
178 std::size_t max_semantic_evidence_bytes = 1024 * 1024;
181};
182
183struct ProgramSynthesisResult {
184 ProgramSynthesisReservation reservation;
185 ProgramBundle bundle;
186 ProgramSynthesisValidationReceipt validation;
187 json validation_evidence;
188 ProgramVersion version;
189 ProgramSynthesisReceipt receipt;
190};
191
193NEOGRAPH_PROGRAM_API std::string program_synthesis_source_identity(const ProgramSource& source);
194
197 std::string owner_scope;
198 std::string parent_run_id;
199 std::string parent_program_version_id;
200 std::string parent_policy_fingerprint;
201 std::string lineage_id;
202 std::string expected_lineage_head_id;
203 std::string template_identity;
204 std::string reviewed_source_identity;
205 std::string semantic_validator_identity;
206 std::string semantic_contract_identity;
207 std::vector<std::string> allowed_capabilities;
208 std::vector<std::string> allowed_effects;
209 RunBudget child_budget_ceiling;
210 ExecutionGuarantee minimum_execution_guarantee = ExecutionGuarantee::Strict;
212 std::size_t max_source_bytes = 1024 * 1024;
213 std::size_t max_sealed_modules = 16;
214};
215
221class NEOGRAPH_PROGRAM_API ProgramChildSynthesisGrant final {
222public:
223 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
225 static ProgramChildSynthesisGrant parse(std::string_view stored_bytes);
226 const ProgramChildSynthesisGrantData& data() const noexcept;
227 const std::string& id() const noexcept;
228 std::string serialize_canonical() const;
229
230private:
231 struct Impl;
232 explicit ProgramChildSynthesisGrant(std::shared_ptr<const Impl> impl);
233 std::shared_ptr<const Impl> impl_;
234};
235
238 ProgramVersion version;
240 ProgramRunLineage lineage;
241 ProgramRunGeneration generation;
242};
243
244struct ProgramChildSynthesisAuthorizationData {
245 std::string proposal_id;
246 std::string grant_id;
247 std::string parent_run_record_id;
248 std::string parent_generation_id;
249 std::string registry_fingerprint;
250 std::string semantic_validator_identity;
251 std::string semantic_contract_identity;
252 std::string lineage_id;
253 std::string source_lineage_head_id;
254 RunBudget parent_remaining;
255 RunBudget child_budget;
256 ExecutionGuarantee minimum_execution_guarantee = ExecutionGuarantee::Strict;
257};
258
259class NEOGRAPH_PROGRAM_API ProgramChildSynthesisAuthorization;
260
262NEOGRAPH_PROGRAM_API ProgramChildSynthesisAuthorization
264 const ProgramChildSynthesisGrant& grant,
265 const ProgramChildSynthesisParent& parent);
266
272class NEOGRAPH_PROGRAM_API ProgramChildSynthesisAuthorization final {
273public:
274 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
275 const ProgramChildSynthesisAuthorizationData& data() const noexcept;
276 const std::string& id() const noexcept;
277 std::string serialize_canonical() const;
278
279private:
280 struct Impl;
281 explicit ProgramChildSynthesisAuthorization(std::shared_ptr<const Impl> impl);
282 std::shared_ptr<const Impl> impl_;
287};
288
289NEOGRAPH_PROGRAM_API void validate_program_child_synthesis_reservation(
290 const ProgramChildSynthesisAuthorization& authorization,
291 const ProgramSynthesisReservation& reservation);
292
293struct ProgramChildSynthesisResult {
295 ProgramSynthesisResult synthesis;
296};
297
298class NEOGRAPH_PROGRAM_API ProgramChildSynthesisError final : public std::runtime_error {
299public:
300 ProgramChildSynthesisError(std::string code, std::string message);
301 const std::string& code() const noexcept;
302
303private:
304 std::string code_;
305};
306
307class ProgramChildSynthesisRecord;
308
310class NEOGRAPH_PROGRAM_API ProgramSynthesisGateway final {
311public:
312 explicit ProgramSynthesisGateway(ProgramSynthesisGatewayConfig config);
316 const std::function<void(const ProgramChildSynthesisRecord&)>& publish) const;
321 asio::awaitable<ProgramChildSynthesisRecord> continue_child_async(
323 std::function<asio::awaitable<void>(const ProgramChildSynthesisRecord&)> publish) const;
324 ProgramSynthesisResult synthesize(const ProgramSynthesisProposal& proposal) const;
326 ProgramChildSynthesisResult synthesize_child(const ProgramSynthesisProposal& proposal,
327 const ProgramChildSynthesisGrant& grant,
328 const ProgramChildSynthesisParent& parent) const;
329
330private:
331 ProgramSynthesisResult synthesize_impl(
332 const ProgramSynthesisProposal& proposal,
333 const ProgramChildSynthesisAuthorization* child_authorization) const;
334 ProgramSynthesisGatewayConfig config_;
335};
336
337} // namespace neograph::program
ExecutionGuarantee
The lowest recoverability/integrity class reachable through an executable closure.
Definition bundle.h:29
Admission and process-local materialization of immutable Programs.
Read-only preflight evidence, not a compile debit, child binding, or spawn permission.
Definition synthesis.h:272
friend NEOGRAPH_PROGRAM_API ProgramChildSynthesisAuthorization authorize_program_child_synthesis(const ProgramSynthesisProposal &, const ProgramChildSynthesisGrant &, const ProgramChildSynthesisParent &)
Pure, fail-closed validation before reservation, compilation, or admission.
Stored grants are evidence only; recovery must reselect them through host policy.
Immutable identity of one admitted topology generation in a run lineage.
Definition lineage.h:102
Immutable content-addressed head of one stable run lineage.
Definition lineage.h:150
Deep-owned, content-addressed run snapshot used for reconnect and CAS publication.
Definition run_record.h:119
Enforces reserve -> compile -> semantic validate -> admit.
Definition synthesis.h:310
asio::awaitable< ProgramChildSynthesisRecord > continue_child_async(ProgramChildSynthesisRecord record, std::function< asio::awaitable< void >(const ProgramChildSynthesisRecord &)> publish) const
The same stages for a caller that cannot block (#557): publish is awaited, and so is the catalog's ad...
ProgramChildSynthesisRecord continue_child(ProgramChildSynthesisRecord record, const std::function< void(const ProgramChildSynthesisRecord &)> &publish) const
Continue a durably reserved request; publish must CAS each stage before returning.
ProgramChildSynthesisResult synthesize_child(const ProgramSynthesisProposal &proposal, const ProgramChildSynthesisGrant &grant, const ProgramChildSynthesisParent &parent) const
Checked child path; never treats a proposal or returned receipt as authority.
Immutable non-executable request to compile one sealed JavaScript successor.
Definition synthesis.h:35
Host evidence that one nonrenewable dynamic-compile unit was debited.
Definition synthesis.h:62
Typed fail-closed result of a completed semantic validation.
Definition synthesis.h:126
Immutable evidence that host-owned semantic validation ran before admission.
Definition synthesis.h:104
Immutable run-generation identity and lineage budget heads.
Pure versioned Program source compiler.
Immutable outcome of one Program run attempt.
Canonical immutable snapshot of one owner-scoped Program run.
Host-authored grant for one reviewed template instantiation and parent head.
Definition synthesis.h:196
Host-loaded snapshots; no identity or budget is taken from Program input.
Definition synthesis.h:237
NEOGRAPH_PROGRAM_API ProgramChildSynthesisAuthorization authorize_program_child_synthesis(const ProgramSynthesisProposal &proposal, const ProgramChildSynthesisGrant &grant, const ProgramChildSynthesisParent &parent)
Pure, fail-closed validation before reservation, compilation, or admission.
std::function< ProgramSynthesisReservation(const ProgramSynthesisProposal &, const ProgramChildSynthesisAuthorization &)> ProgramChildSynthesisReservationResolver
Atomically debit against authorization.data().source_lineage_head_id, or fail.
Definition synthesis.h:168
NEOGRAPH_PROGRAM_API std::string program_synthesis_source_identity(const ProgramSource &source)
Identity of the complete sealed source, including imports and module bytes.