1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
// Copyright 2024-2026 Reflective Labs
// SPDX-License-Identifier: MIT
//! # Converge Core
//!
//! A correctness-first, context-driven multi-suggestor runtime.
//!
//! Converge is a Suggestor OS where:
//! - Context is the API
//! - Suggestors collaborate through data, not calls
//! - Execution proceeds until a fixed point
//! - Convergence is explicit and observable
//!
//! ## Quick Start
//!
//! ```ignore
//! use converge_core::{Context, ContextKey, Engine};
//! use converge_core::suggestors::{ReactOnceSuggestor, SeedSuggestor};
//!
//! // Create engine and register suggestors
//! let mut engine = Engine::new();
//! engine.register_suggestor(SeedSuggestor::new("seed-1", "initial data"));
//! engine.register_suggestor(ReactOnceSuggestor::new("hyp-1", "derived insight"));
//!
//! // Run until convergence (async)
//! let result = engine.run(Context::new()).await.expect("should converge");
//!
//! // Inspect results
//! assert!(result.converged);
//! assert!(result.context.has(ContextKey::Seeds));
//! assert!(result.context.has(ContextKey::Hypotheses));
//! println!("Converged in {} cycles", result.cycles);
//! ```
//!
//! ## Core Concepts
//!
//! - [`Context`]: The shared, typed, evolving state of a job
//! - [`Suggestor`]: A capability that reads context and emits effects
//! - [`AgentEffect`]: Buffered proposal output from a suggestor
//! - [`Engine`]: The convergence loop that coordinates suggestors
//!
//! ## Guarantees
//!
//! - **Determinism**: Same input → same output
//! - **Termination**: Budgets prevent infinite loops
//! - **Isolation**: Suggestors never call each other
//! - **Auditability**: All changes are traceable
//!
//! # Design Tenets
//!
//! These are the nine non-negotiable axioms that `converge-core` exists to encode,
//! enforce, and protect. Every type, trait, and pattern in this crate serves one
//! or more of these tenets.
//!
//! ## 1. Explicit Authority
//!
//! **Axiom**: No defaults that grant authority. Authority is always explicit, typed, and traceable.
//!
//! **Why**: Implicit permissions lead to security drift and unauditable systems.
//!
//! **In code**: [`AuthorityGrant`] and [`AuthorityScope`] require explicit construction.
//! The `pub(crate)` constructors on `AuthorityGrant` prevent external code from forging
//! authority. See also [`PromotionRecord`] which traces approvers.
//!
//! ## 2. Convergence Over Control Flow
//!
//! **Axiom**: We converge on outcomes via governed proposals, not ad-hoc loops or hidden heuristics.
//!
//! **Why**: Control flow hides decisions; convergence makes them observable.
//!
//! **In code**: The [`Engine`] runs suggestors repeatedly until a fixed point is reached.
//! [`StopReason`] exhaustively enumerates why execution halted. No hidden loops.
//!
//! ## 3. Append-Only Truth
//!
//! **Axiom**: Facts are never mutated. Corrections are new facts.
//!
//! **Why**: Mutable state hides history and prevents audit replay.
//!
//! **In code**: [`TypesFact`] has private fields with no `&mut` methods.
//! [`CorrectionEvent`] creates new correction facts rather than
//! mutating existing ones. The [`Context`] accumulates facts without overwriting.
//!
//! ## 4. Suggestors Suggest, Engine Decides
//!
//! **Axiom**: Suggestors emit proposals; promotion requires validation gates (and sometimes humans).
//!
//! **Why**: Separates suggestion from decision, enabling governance and audit.
//!
//! **In code**: [`PromotionGate`] is the ONLY path to create Facts. Suggestors produce
//! [`Proposal`] in the `Draft` state which must go through [`ValidationReport`]
//! before becoming `Validated` and finally [`TypesFact`].
//!
//! ## 5. Safety by Construction
//!
//! **Axiom**: Make invalid states unrepresentable. Prefer types over conventions.
//!
//! **Why**: Runtime checks can be bypassed; type-level guarantees cannot.
//!
//! **In code**: The type-state pattern on [`Proposal`] (`Draft` vs `Validated`)
//! makes it impossible to promote an unvalidated proposal. Newtype IDs like [`FactId`],
//! [`ProposalId`], and [`ObservationId`] prevent mixing.
//!
//! ## 6. Transparent Determinism
//!
//! **Axiom**: The system tells the truth about replayability and determinism.
//!
//! **Why**: Hidden non-determinism corrupts audit trails and reproducibility.
//!
//! **In code**: [`TypesTraceLink`] distinguishes [`LocalTrace`]
//! (replay-eligible) from [`RemoteRef`] (audit-only). [`Replayability`]
//! explicitly marks whether operations can be replayed deterministically.
//!
//! ## 7. Human Authority First-Class
//!
//! **Axiom**: Explicit pause/approve gates for consequential actions.
//!
//! **Why**: AI systems must preserve human oversight for high-stakes decisions.
//!
//! **In code**: [`Actor`] and [`ActorKind`] distinguish
//! human from automated approvers. [`PromotionRecord`] records
//! who approved each fact. The [`ValidationPolicy`] can require human approval.
//!
//! ## 8. No Hidden Work
//!
//! **Axiom**: No silent background effects, retries, implicit state changes, or shadow decisioning.
//!
//! **Why**: Hidden work makes systems unpredictable and unauditable.
//!
//! **In code**: [`AgentEffect`] explicitly captures all suggestor output. The [`Engine`]
//! budget system ([`CycleBudget`], [`FactBudget`], [`TokenBudget`]) makes resource
//! consumption visible. [`StopReason`] explains exactly why execution ended.
//!
//! ## 9. Scale by Intent Replication
//!
//! **Axiom**: Scale by replicating intent and invariants across domains.
//!
//! **Why**: Scaling should preserve governance, not bypass it.
//!
//! **In code**: [`RootIntent`] and [`Frame`] capture intent as data.
//! [`Invariant`] enforces governance rules. These types can be serialized and
//! replicated across distributed systems while preserving their constraints.
//!
//! # Purity Declaration
//!
//! `converge-core` is the constitutional foundation for Converge. It must remain
//! **pure** in the architectural sense: no I/O, no persistence, no hidden
//! background work, and no runtime ownership. Core coordination logic such as
//! the engine and promotion gates belongs here; adapters and transport/runtime
//! wiring do not.
//!
//! ## Allowed Dependencies
//!
//! | Crate | Purpose | Rationale |
//! |-------|---------|-----------|
//! | `thiserror` | Error derives | Pure derives, no runtime |
//! | `tracing` | Log macros | Compile-time only when used |
//! | `serde` | Serialization derives | Pure derives, no I/O |
//! | `serde_json` | JSON encoding | Value-only, no I/O |
//! | `typed-builder` | Builder derives | Pure derives |
//! | `hex` | Hex encoding | Pure transforms |
//! | Small pure libs | Hashing, encoding | No I/O, no runtime ownership |
//!
//! ## Forbidden Dependencies
//!
//! | Crate | Category | Why Forbidden |
//! |-------|----------|---------------|
//! | `tokio` | Async runtime | Implies execution |
//! | `reqwest` | HTTP client | Network I/O |
//! | `axum` | HTTP server | Network I/O |
//! | `tonic` | gRPC | Network I/O |
//! | `prost` | Protobuf | gRPC dependency |
//! | `burn` | ML runtime | Heavy computation |
//! | `llama-burn` | LLM inference | Model execution |
//! | `fastembed` | Embeddings | Model execution |
//! | `polars` | DataFrames | Heavy computation |
//! | `arrow` | Columnar data | Analytics dependency |
//! | `lancedb` | Vector DB | Persistence |
//! | `surrealdb` | Database | Persistence |
//! | `postgres` | Database | Persistence |
//! | `rand` | Randomness | Non-determinism |
//! | `rayon` | Parallelism | Execution strategy |
//!
//! ## The Purity Rule
//!
//! > If a module implies executor ownership, I/O, network, model inference, or
//! > persistence, it does not belong in `converge-core`.
//!
//! Capability crates (e.g., `converge-runtime`, `converge-llm`, `converge-provider`)
//! implement the traits defined here using the forbidden dependencies.
//!
//! See `deny.toml` at the crate root for CI enforcement of these rules.
pub use ;
pub use ;
pub use AgentEffect;
/// Re-export the Context trait from converge-pack.
/// Suggestor and Invariant implementations use `&dyn ContextView` in their signatures.
pub use Context as ContextView;
pub use ;
pub use ConvergeError;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
// IntentId canonical definition is in types::frame, re-exported here
pub use ;
pub use IntentId;
// Re-export core capability types for convenience
pub use ;
// Re-export capability boundary traits (interfaces for external implementations)
pub use ;
// Re-export kernel boundary types (constitutional types for all kernels)
pub use ;
// Re-export governed artifact types (lifecycle governance for any artifact that changes outcomes)
pub use ;
// Re-export backend types (unified LLM interface for local and remote)
pub use ;
// Re-export new types module (3-tier hierarchy: Observation -> Proposal -> Fact)
// Note: types::Fact is the governed semantic fact with PromotionRecord.
// context::Fact is the stable read-only runtime/context surface.
pub use ;
// Gate Pattern (suggestors suggest, engine decides)
pub use ;