1pub mod governance;
2pub mod harness;
3pub mod harness_loop;
4pub mod knowledge;
5pub mod memory;
6pub mod providers;
7pub mod run_event;
8pub mod runtime;
9pub mod safety;
10pub mod signals;
11pub mod tools;
12
13#[cfg(test)]
14mod tests;
15
16pub use deepstrike_core::context::measurement::{MeasurementConfidence, MeasurementSource};
17pub use deepstrike_core::context::renderer::InternalRenderedContext as RenderedContext;
20pub use deepstrike_core::governance::permission::PermissionAction;
21pub use deepstrike_core::governance::quota::ResourceQuota;
22pub use deepstrike_core::mm::memory::{
27 MemoryAuthor, MemoryKind, MemoryProvenance, MemoryQuery, MemoryRecall, MemoryRecord,
28 MemoryScope, MemoryTrustLevel,
29};
30pub use deepstrike_core::runtime::kernel::wire::MemoryPolicy;
31pub use deepstrike_core::{EntropySample, EntropyTracker, EntropyWatchConfig};
32pub use deepstrike_core::orchestration::workflow::{JudgeMatch, WorkflowRun, WorkflowSpawnInfo};
38pub use deepstrike_core::orchestration::workflow::{
39 WorkflowNode, WorkflowSpec, fanout_synthesize, gen_eval, generate_and_filter, verify_rules,
40};
41pub use governance::{Governance, GovernanceVerdict};
42pub use harness::{Criterion, CriterionResult, Verdict};
43pub use harness_loop::{
44 AttemptBody, AttemptBodyContext, AttemptBodyEvent, AttemptBodyStream, AttemptJudge,
45 AttemptLoop, AttemptLoopEvent, AttemptLoopStream, AttemptOutcome, AttemptOutcomeKind,
46 AttemptRequest, CarryContext, CarryPolicy, ContinueSession, DigestFn, DigestFuture,
47 FreshWithDigest, FreshWithFeedback, HybridJudge, JudgeContext, JudgeResult, LlmEvalJudge,
48 PassHook, PassHookFuture, PreparedAttempt, RuntimeAttemptBody, StopPolicy, VerdictFn,
49 VerdictFnJudge,
50};
51pub use knowledge::KnowledgeSource;
52pub use memory::{
53 DurableMemory, InMemoryMemoryStore, MemorySearchOptions, MemoryStore, WorkingMemory,
54};
55pub use providers::RuntimePolicy;
56pub use providers::anthropic::AnthropicProvider;
57pub use providers::openai::{OpenAIProvider, deepseek, kimi, minimax, ollama, qwen};
58pub use providers::request_plan::{
59 CostObservation, NormalizedProviderUsage, PricingRates, PricingSnapshot,
60 ProviderRequestEndpoint, ProviderRequestPlan, ProviderUsage, RecordedPromptMeasurement,
61 RequestPlanError, UnpricedReason, measurement_for_plan, normalize_provider_usage,
62 price_provider_usage, record_prompt_measurement,
63};
64pub use providers::{
65 LLMProvider, ProviderError, ProviderErrorKind, ProviderRunState, ProviderToolSpec, StreamEvent,
66 TokenUsage,
67};
68pub use run_event::RunEvent;
69pub use runtime::eval::{Criterion as EvalCriterion, Verdict as EvalVerdict};
70pub use runtime::eval::{build_eval_messages, judge, parse_verdict, verdict_output_schema};
71pub use runtime::replay_fixture::{
72 extract_recorded_messages, extract_recorded_messages_from_entries,
73};
74pub use runtime::replay_provider::{ReplayProvider, ReplayProviderOpts};
75pub use runtime::{
76 CanonicalCheckpoint, CanonicalCheckpointCandidate, CanonicalCommit, CanonicalKernel,
77 CanonicalPreparation,
78};
79pub use runtime::{
80 ChainedCredentialVault, CredentialVault, EnvCredentialVault, InMemoryCredentialVault,
81};
82pub use runtime::{
83 DEFAULT_NATIVE_SIGNAL_POLICY, GovernancePolicy, MemoryWriteRateLimit, NativeOsProfile,
84 OsProfile, SchedulerPolicyConfig, SignalPolicy, assert_native_profile,
85 default_native_governance_policy, os_profile,
86};
87pub use runtime::{ExecutionPlane, LocalExecutionPlane};
88pub use runtime::{FilePayloadStore, PayloadStore};
89pub use runtime::{FileSessionLog, InMemorySessionLog, SessionEntry, SessionLog};
90pub use runtime::{
91 KernelReliability, MilestoneEvaluationContext, MilestoneEvaluationHandler, MilestonePolicy,
92 RuntimeOptions, RuntimeRunner, collect_text,
93};
94pub use runtime::{
97 CheckpointCandidate, FileKernelJournal, InMemoryKernelJournal, InstalledCheckpoint,
98 JournalAppendReceipt, JournalEntry, JournalError, JournalHead, JournalPruneReceipt,
99 JournalRecordInput, JournalResult, KernelJournal,
100};
101pub use runtime::{McpProxyPlane, McpServerConfig};
102pub use runtime::{
103 PermissionRequest, PermissionRequestHandler, PermissionResponse, RunContext,
104 ToolSuspendHandler, ToolSuspendRequest,
105};
106pub use runtime::{ProcessSandboxPlane, SandboxOptions};
107pub use runtime::{RemoteVpcOptions, RemoteVpcPlane};
108pub use safety::{Permission, PermissionDecision, PermissionManager, PermissionMode};
109pub use signals::{
110 GatewayReceiver, RuntimeSignal, ScheduledPrompt, SignalClaim, SignalDeliveryReceipt,
111 SignalGateway, SignalSource,
112};
113pub use tools::{
114 RegisteredTool, SafeToolResult, TextToolSession, ToolChunk, ToolEnvelope, ToolEnvelopeFail,
115 ToolEnvelopeOk, ToolSession, ToolStep, execute_tools, fail, ok, read_file_tool, safe_tool,
116 tool_fail, validate_tool_arguments,
117};
118
119#[derive(Debug, thiserror::Error)]
120pub enum Error {
121 #[error("provider error: {0}")]
122 Provider(String),
123 #[error(transparent)]
124 ProviderFailure(#[from] providers::ProviderError),
125 #[error("tool error: {0}")]
126 Tool(String),
127 #[error("io error: {0}")]
128 Io(#[from] std::io::Error),
129 #[error("tool execution failed: {output}")]
130 ToolExecutionFailed {
131 output: String,
132 is_fatal: bool,
133 error_kind: Option<deepstrike_core::types::message::ToolErrorKind>,
134 },
135 #[error("{output}")]
140 ToolFail {
141 output: String,
142 code: Option<String>,
143 hint: Option<String>,
144 is_fatal: bool,
145 error_kind: Option<deepstrike_core::types::message::ToolErrorKind>,
146 },
147 #[error("{0}")]
148 Other(String),
149}
150
151pub fn format_tool_error(e: &Error) -> String {
160 match e {
161 Error::Tool(s) => s.clone(),
162 Error::ToolExecutionFailed { output, .. } => output.clone(),
163 Error::ToolFail {
164 output, code, hint, ..
165 } => {
166 if code.is_none() && hint.is_none() {
167 return output.clone();
168 }
169 let mut obj = serde_json::Map::with_capacity(3);
170 obj.insert(
171 "message".to_string(),
172 serde_json::Value::String(output.clone()),
173 );
174 if let Some(c) = code {
175 obj.insert("code".to_string(), serde_json::Value::String(c.clone()));
176 }
177 if let Some(h) = hint {
178 obj.insert("hint".to_string(), serde_json::Value::String(h.clone()));
179 }
180 serde_json::to_string(&serde_json::Value::Object(obj))
181 .unwrap_or_else(|_| output.clone())
182 }
183 _ => e.to_string(),
184 }
185}
186
187pub type Result<T> = std::result::Result<T, Error>;