gestura_core/
lib.rs

1//! Gestura's public core facade.
2//!
3//! `gestura-core` is the stable Rust API surface for Gestura.app. It owns the
4//! cross-domain orchestration that ties the workspace together and re-exports
5//! focused `gestura-core-*` domain crates so downstream code can import through
6//! a single, consistent path.
7//!
8//! ## Generated docs quick start
9//!
10//! If you are exploring the generated docs, start with these high-signal module
11//! entry points:
12//!
13//! - [`pipeline`]: main agent execution flow and request/response model
14//! - [`tools`]: built-in tools, permissions, schemas, and confirmation helpers
15//! - [`config`]: application configuration plus secret-hydration/runtime bridges
16//! - [`llm_provider`]: provider selection and LLM facade access
17//! - [`mcp`] and [`a2a`]: protocol surfaces for MCP and agent-to-agent flows
18//! - [`agent_sessions`], [`session_manager`], and [`tasks`]: session and task state
19//! - [`knowledge`], [`memory_bank`], and [`memory_console`]: expert knowledge and memory
20//! - [`security`] and [`streaming`]: security/runtime streaming boundaries
21//!
22//! A good reading path is:
23//!
24//! 1. start here in `gestura-core`
25//! 2. jump into one of the facade modules above
26//! 3. follow the re-export or module docs into the owning `gestura-core-*` crate
27//!    when you need domain-level detail
28//!
29//! ## Core-first architecture
30//!
31//! The workspace follows a core-first layout:
32//!
33//! - domain logic lives in dedicated crates such as `gestura-core-tools`,
34//!   `gestura-core-mcp`, `gestura-core-config`, and `gestura-core-context`
35//! - `gestura-core` re-exports those crates under stable public module names
36//! - presentation layers (`gestura-cli`, `gestura-gui`) stay thin and delegate
37//!   to this facade instead of owning business logic
38//!
39//! In practice, this means new work usually follows this path:
40//!
41//! 1. add or update behavior in the relevant domain crate
42//! 2. expose the stable public entry point from `gestura-core`
43//! 3. consume the stable API from CLI and GUI code
44//!
45//! ## What this crate owns directly
46//!
47//! This facade is intentionally more than a re-export crate. It also owns the
48//! integration points that combine multiple domains, including:
49//!
50//! - the agent pipeline and tool execution loop
51//! - provider selection from application configuration
52//! - guardrails, checkpoints, compaction, and orchestration helpers
53//! - configuration bridges that depend on security or runtime integration
54//! - shared surfaces consumed by both CLI and GUI entry points
55//!
56//! ## High-signal module groups
57//!
58//! - `pipeline`: agent request execution, tool routing, reflection, and
59//!   streaming integration
60//! - `tools`: stable access to built-in tools, schemas, permissions, and
61//!   streaming shell helpers
62//! - `config`: application configuration plus core-owned security bridges
63//! - `llm_provider`: provider selection and facade access to LLM types
64//! - `mcp`, `a2a`, `knowledge`, `memory_bank`: protocol and knowledge surfaces
65//! - `session_manager`, `session_workspace`, `agent_sessions`: session state and
66//!   workspace lifecycle
67//!
68//! ## Cargo features
69//!
70//! The facade exposes optional capabilities through Cargo features:
71//!
72//! - `voice-local`: local Whisper speech-to-text support
73//! - `nats`: NATS messaging integration
74//! - `json-ld`: JSON-LD processing for MDH workflows
75//! - `security`: encryption, keychain, and secure-storage integrations
76//! - `macos-permissions`, `linux-permissions`, `windows-permissions`:
77//!   platform-specific permission helpers
78//!
79//! ## Documentation strategy
80//!
81//! The long-term goal is for crate-level and module-level Rustdoc to become the
82//! canonical architecture and API reference surfaced by `cargo doc`. External
83//! documents should increasingly focus on operational workflows such as install,
84//! packaging, release, and troubleshooting.
85
86/// Crate version from Cargo.toml
87pub const VERSION: &str = env!("CARGO_PKG_VERSION");
88
89/// Crate name
90pub const NAME: &str = env!("CARGO_PKG_NAME");
91
92// ============================================================================
93// Core Modules (file-backed — business logic + domain-crate integration)
94// ============================================================================
95
96pub mod agent_sessions;
97/// Agent lifecycle management and orchestration primitives re-exported from
98/// `gestura-core-agents`.
99pub mod agents {
100    pub use gestura_core_agents::*;
101}
102pub mod checkpoints;
103pub mod compaction;
104pub mod config;
105/// Smart request analysis, entity extraction, and context resolution re-exported
106/// from `gestura-core-context`.
107pub mod context {
108    pub use gestura_core_context::*;
109}
110pub(crate) mod guardrails;
111pub mod llm_overrides;
112pub mod llm_provider;
113pub mod llm_validation;
114pub mod memory_console;
115/// OpenAI(-compatible) API compatibility helpers (e.g., parameter support quirks).
116pub mod openai_compat;
117pub mod orchestrator;
118pub mod pipeline;
119pub mod prompt_enhancement;
120pub mod speech;
121pub mod streaming;
122/// Token accounting helpers re-exported from `gestura-core-llm`.
123pub mod token_tracker {
124    pub use gestura_core_llm::token_tracker::*;
125}
126pub mod tools;
127
128// ============================================================================
129// Inline Modules (domain-crate types surfaced through gestura-core)
130// ============================================================================
131
132// -- gestura-core-foundation --
133/// Shared application errors and result aliases re-exported from
134/// `gestura-core-foundation`.
135pub mod error {
136    pub use gestura_core_foundation::error::*;
137}
138/// Outcome-linked learning signals re-exported from `gestura-core-foundation`.
139pub mod outcomes {
140    pub use gestura_core_foundation::outcomes::*;
141}
142/// Cross-cutting event types re-exported from `gestura-core-foundation`.
143pub mod events {
144    pub use gestura_core_foundation::events::*;
145}
146/// Execution-mode policy primitives re-exported from
147/// `gestura-core-foundation`.
148pub mod execution_mode {
149    pub use gestura_core_foundation::execution_mode::*;
150}
151/// Shared interaction model types re-exported from `gestura-core-foundation`.
152pub mod interaction {
153    pub use gestura_core_foundation::interaction::*;
154}
155/// Human-friendly model display helpers re-exported from
156/// `gestura-core-foundation`.
157pub mod model_display {
158    pub use gestura_core_foundation::model_display::*;
159}
160/// Platform-detection helpers re-exported from `gestura-core-foundation`.
161pub mod platform {
162    pub use gestura_core_foundation::platform::*;
163}
164/// Streaming error types re-exported from `gestura-core-foundation`.
165pub mod stream_error {
166    pub use gestura_core_foundation::stream_error::*;
167}
168/// Streaming health state types re-exported from `gestura-core-foundation`.
169pub mod stream_health {
170    pub use gestura_core_foundation::stream_health::*;
171}
172/// Streaming reconnection helpers re-exported from `gestura-core-foundation`.
173pub mod stream_reconnect {
174    pub use gestura_core_foundation::stream_reconnect::*;
175}
176/// Telemetry and instrumentation types re-exported from
177/// `gestura-core-foundation`.
178pub mod telemetry {
179    pub use gestura_core_foundation::telemetry::*;
180}
181
182// -- gestura-core-llm --
183/// Built-in provider model defaults re-exported from `gestura-core-llm`.
184pub mod default_models {
185    pub use gestura_core_llm::default_models::*;
186}
187/// Model discovery and listing helpers re-exported from `gestura-core-llm`.
188pub mod model_listing {
189    pub use gestura_core_llm::model_listing::*;
190}
191
192// -- gestura-core-mcp --
193/// Model Context Protocol types and services re-exported from
194/// `gestura-core-mcp`.
195pub mod mcp {
196    pub use gestura_core_mcp::*;
197}
198
199// -- gestura-core-sessions --
200/// Authentication and session-management services re-exported from
201/// `gestura-core-sessions`.
202pub mod session_manager {
203    pub use gestura_core_sessions::session_manager::*;
204}
205/// Session-scoped workspace management re-exported from
206/// `gestura-core-sessions`.
207pub mod session_workspace {
208    pub use gestura_core_sessions::session_workspace::*;
209}
210
211// -- gestura-core-streaming --
212/// Streaming cancellation primitives re-exported from
213/// `gestura-core-streaming`.
214pub mod stream_cancellation {
215    pub use gestura_core_streaming::cancellation::*;
216}
217
218// -- gestura-core-tasks --
219/// Task-management primitives re-exported from `gestura-core-tasks`.
220pub mod tasks {
221    pub use gestura_core_tasks::tasks::*;
222}
223/// Workflow helpers re-exported from `gestura-core-tasks`.
224pub mod workflows {
225    pub use gestura_core_tasks::workflows::*;
226}
227
228// -- gestura-core-security --
229/// Security domain types and services re-exported from `gestura-core-security`.
230pub mod security {
231    pub use gestura_core_security::*;
232}
233/// GDPR-specific helpers re-exported from `gestura-core-security`.
234pub mod gdpr {
235    pub use gestura_core_security::gdpr::*;
236}
237/// Sandbox primitives re-exported from `gestura-core-security`.
238pub mod sandbox {
239    pub use gestura_core_security::sandbox::*;
240}
241
242// -- gestura-core-audio --
243/// Audio noise-cancellation utilities re-exported from `gestura-core-audio`.
244pub mod audio {
245    pub use gestura_core_audio::noise_cancellation::*;
246}
247/// Audio capture helpers re-exported from `gestura-core-audio`.
248pub mod audio_capture {
249    pub use gestura_core_audio::audio_capture::*;
250}
251/// Speech-to-text provider interfaces re-exported from `gestura-core-audio`.
252pub mod stt_provider {
253    pub use gestura_core_audio::stt_provider::*;
254}
255
256// -- gestura-core-tools --
257/// Tool inspection and review helpers re-exported from `gestura-core-tools`.
258pub mod tool_inspection {
259    pub use gestura_core_tools::tool_inspection::*;
260}
261
262// -- gestura-core-config --
263/// Environment-based configuration loading re-exported from
264/// `gestura-core-config`.
265pub mod config_env {
266    pub use gestura_core_config::config_env::*;
267}
268
269// -- gestura-core-foundation + gestura-core-security --
270/// Secret-provider abstractions surfaced from foundation and security crates.
271pub mod secrets {
272    pub use gestura_core_foundation::secrets::*;
273    pub use gestura_core_security::secrets::SecureStorageSecretProvider;
274}
275
276// -- gestura-core-memory-bank --
277/// Persistent memory-bank types and services re-exported from
278/// `gestura-core-memory-bank`.
279pub mod memory_bank {
280    pub use gestura_core_memory_bank::*;
281}
282
283// -- gestura-core-a2a --
284/// Agent-to-Agent protocol types and helpers re-exported from
285/// `gestura-core-a2a`.
286pub mod a2a {
287    pub use gestura_core_a2a::*;
288}
289
290// -- gestura-core-explorer --
291/// File-system exploration helpers re-exported from `gestura-core-explorer`.
292pub mod explorer {
293    pub use gestura_core_explorer::*;
294}
295
296// -- gestura-core-knowledge --
297/// Built-in knowledge and expertise surfaces re-exported from
298/// `gestura-core-knowledge`.
299pub mod knowledge {
300    pub use gestura_core_knowledge::*;
301}
302
303// -- gestura-core-nats --
304/// NATS messaging primitives re-exported from `gestura-core-nats`.
305pub mod nats_mq {
306    pub use gestura_core_nats::*;
307}
308
309// -- gestura-core-ipc --
310/// Hotkey inter-process communication types re-exported from `gestura-core-ipc`.
311pub mod hotkey_ipc {
312    pub use gestura_core_ipc::*;
313}
314
315// -- gestura-core-analytics --
316/// Usage analytics types re-exported from `gestura-core-analytics`.
317pub mod analytics {
318    pub use gestura_core_analytics::analytics::*;
319}
320/// Recommendation types re-exported from `gestura-core-analytics`.
321pub mod recommendations {
322    pub use gestura_core_analytics::recommendations::*;
323}
324
325// -- gestura-core-hooks --
326/// Hook engine types re-exported from `gestura-core-hooks`.
327pub mod hooks {
328    pub use gestura_core_hooks::*;
329}
330
331// -- gestura-core-scripting --
332/// Scripting-engine types re-exported from `gestura-core-scripting`.
333pub mod scripting {
334    pub use gestura_core_scripting::*;
335}
336
337// -- gestura-core-plugins --
338/// Plugin-system types re-exported from `gestura-core-plugins`.
339pub mod plugin_system {
340    pub use gestura_core_plugins::*;
341}
342
343// -- gestura-core-retry --
344/// Retry strategy helpers re-exported from `gestura-core-retry`.
345pub mod retry {
346    pub use gestura_core_retry::*;
347}
348
349// -- gestura-core-intent --
350/// Unified intent normalization layer re-exported from `gestura-core-intent`.
351pub mod intent {
352    pub use gestura_core_intent::*;
353}
354
355// -- tool_confirmation (merged into gestura-core-tools) --
356/// Tool-confirmation flows re-exported from `gestura-core-tools`.
357pub mod tool_confirmation {
358    pub use gestura_core_tools::tool_confirmation::*;
359}
360
361// Re-export common types for convenience
362pub use a2a::{
363    A2AClient, A2AError, A2AMessage, A2ARequest, A2AResponse, A2AServer, A2ATask, AgentCard,
364    AgentCardRegistry, AgentProfile, Artifact, AuthenticationInfo, MessagePart, OAuth2Config,
365    ProfileStore, Skill, create_gestura_agent_card, is_token_well_formed,
366};
367pub use agent_sessions::{
368    AgentSession, AgentSessionResult, AgentSessionStore, ConversationMessage,
369    FileAgentSessionStore, MessageSource, SessionFilter, SessionInfo, SessionLlmConfig,
370    SessionPermissionLevel, SessionReflectionSettings, SessionState, SessionToolCall,
371    SessionToolSettings, SessionVoiceConfig, default_agent_sessions_dir,
372};
373pub use analytics::{
374    AnalyticsConfig, AnalyticsInsights, ErrorAnalysis, EventType, PerformanceMetrics, PrivacyMode,
375    TimePeriod, UsageAnalytics, UsageEvent, UsagePatterns,
376};
377pub use audio::{
378    NoiseCancellationConfig, NoiseCancellationProcessor, NoiseReductionStats,
379    create_music_noise_canceller, create_speech_noise_canceller,
380};
381pub use audio_capture::{
382    AudioCaptureConfig, AudioDeviceInfo, is_microphone_available, list_audio_input_devices,
383    record_audio, request_stop_recording, reset_stop_flag,
384};
385pub use checkpoints::{
386    Checkpoint, CheckpointError, CheckpointId, CheckpointManager, CheckpointMetadata,
387    CheckpointRetentionPolicy, CheckpointSnapshot, FileCheckpointStore, default_checkpoints_dir,
388};
389pub use compaction::{
390    CompactionConfig, CompactionEvent, CompactionEventType, CompactionResult, CompactionStrategy,
391    ContextCompactor,
392};
393pub use config::{
394    AppConfig, AppConfigSecurityExt, McpJsonFile, McpScope, McpServerEntry, McpTransportType,
395    import_claude_desktop_servers,
396};
397pub use context::{
398    CacheStats, ContextCache, ContextCategory, ContextManager, ContextManagerStats, EntityType,
399    ExtractedEntity, FileContext, RequestAnalysis, RequestAnalyzer, ResolvedContext, ToolContext,
400};
401pub use default_models::{
402    DEFAULT_ANTHROPIC_MODEL, DEFAULT_GEMINI_BASE_URL, DEFAULT_GEMINI_MODEL, DEFAULT_GROK_MODEL,
403    DEFAULT_OLLAMA_BASE_URL, DEFAULT_OLLAMA_MODEL, DEFAULT_OPENAI_MODEL, DEFAULT_OPENAI_STT_MODEL,
404};
405pub use error::{AppError, Result};
406pub use events::{
407    AgentEvent, EventBufferConfig, EventEmitter, EventReceiver, EventSender, ProgressStage,
408    ProgressTracker, create_event_channel,
409};
410pub use execution_mode::{
411    ExecutionMode, ModeConfig, ModeManager, ToolCategory, ToolExecutionCheck, ToolPermission,
412};
413pub use explorer::{
414    ExplorerEntry, ExplorerEntryKind, ExplorerError, ExplorerGitChangeKind, ExplorerGitPathStatus,
415    ExplorerGitStatusResponse, ExplorerListDirResponse, ExplorerRootResponse, canonical_root,
416    ensure_safe_rel_path, list_dir, normalize_git_change_path, resolve_under_root,
417};
418pub use gdpr::{
419    ConsentRecord, ConsentStatus, DataAuditEntry, DataCategory, DataOperation, GdprManager,
420    get_gdpr_manager,
421};
422pub use hooks::{HookContext, HookEngine, HookEvent, HookExecutionRecord, HooksSettings};
423pub use interaction::{
424    ButtonPressType, GestureType, HapticFeedback, HapticPattern, InteractionContext,
425    InteractionEvent, InteractionType, SlideDirection, ToolHint,
426};
427pub use knowledge::{
428    KnowledgeError, KnowledgeItem, KnowledgeMatch, KnowledgeQuery, KnowledgeReference,
429    KnowledgeSettingsManager, KnowledgeStore, LoadCondition, SessionKnowledgeSettings,
430    register_builtin_knowledge,
431};
432pub use llm_provider::{
433    AgentContext, LlmCallResponse, LlmProvider, TokenUsage, UnconfiguredProvider, select_provider,
434};
435pub use mcp::{
436    CachedTool, JsonRpcError, JsonRpcRequest, JsonRpcResponse, LocalMcp, McpCacheStats, McpClient,
437    McpClientRegistry, McpDiscoveryManager, McpIntegrator, McpRequestContext, McpResourceHandler,
438    McpServer, McpServerConfig, McpServerInfo, McpToolHandler, MdhResource, PopularMcpServer,
439    RegistryBrowseEntry, RegistryBrowsePage, ServerState, TokenInfo, browse_mcp_registry, get_mcp,
440    get_mcp_client_registry, list_popular_mcp_servers, mdh_translate, normalize_mcp_server_name,
441};
442pub use memory_bank::{
443    MemoryBankEntry, MemoryBankError, MemoryBankQuery, MemoryGovernanceRefreshReport,
444    MemoryGovernanceRelationship, MemoryGovernanceState, MemoryGovernanceSuggestion, MemoryKind,
445    MemoryScope, MemorySearchResult, MemoryType, ReflectionMemoryState, clear_memory_bank,
446    ensure_memory_bank_dir, get_memory_bank_dir, list_memory_bank, load_from_memory_bank,
447    refresh_memory_bank_governance, save_to_memory_bank, search_memory_bank,
448    search_memory_bank_with_query,
449};
450pub use model_display::{
451    format_anthropic_model_name, format_gemini_model_name, format_grok_model_name,
452    format_model_name, format_openai_model_name, is_local_provider,
453};
454pub use model_listing::{ModelInfo, check_ollama_connectivity, list_models_for_provider};
455pub use pipeline::{
456    AgentPipeline, AgentRequest, AgentResponse, Message, PausedExecutionState, PermissionLevel,
457    PipelineConfig, PipelineConfigExt, RequestMetadata, RequestSource, ToolCallRecord, ToolResult,
458};
459pub use platform::detect_system_dark_mode;
460pub use recommendations::{
461    PersonalizedRecommendationEngine, Recommendation, RecommendationConfig, RecommendationFeedback,
462    RecommendationType, SessionPatterns, UserBehaviorPattern,
463};
464pub use retry::{ErrorClass, RetryCallback, RetryEvent, RetryManager, RetryPolicy};
465pub use session_manager::{AuthToken, SessionManager, TokenType, UserSession, get_session_manager};
466pub use session_workspace::{
467    SessionWorkspace, WorkspaceError, WorkspaceResult, cleanup_old_sessions, get_sessions_base_dir,
468};
469pub use speech::{
470    LlmResponse, SpeechConfig, SpeechProcessor, SpeechProcessorCoreExt, TranscriptionResult,
471    get_speech_processor, is_speech_recording, update_speech_config,
472};
473pub use stream_error::{StreamError, StreamErrorCategory, StreamResult};
474pub use stream_health::{
475    StreamHealthConfig, StreamHealthEvent, StreamHealthHandle, StreamHealthMonitor,
476    StreamHealthStatus,
477};
478pub use stream_reconnect::{
479    ReconnectConfig, ReconnectEvent, ReconnectManager, ReconnectState, StreamState,
480};
481pub use streaming::{
482    CancellationToken, ShellOutputStream, ShellProcessState, StreamChunk, start_streaming,
483};
484pub use tasks::{
485    Task, TaskError, TaskList, TaskManager, TaskMemoryEvent, TaskMemoryLifecycle, TaskMemoryPhase,
486    TaskSource, TaskStatus, get_global_task_manager,
487};
488pub use telemetry::{
489    Metric, MetricType, SystemHealth, TelemetryManager, Timer, get_telemetry_manager,
490};
491pub use token_tracker::{
492    BudgetStatus, TokenTracker, UsageRecord, UsageStats, format_token_count, get_token_tracker,
493};
494pub use tool_inspection::{
495    ConfirmationRequest, ConfirmationResponse, InspectionResult, ToolInspectionManager,
496    ToolMetadata,
497};
498pub use tools::{
499    ToolDefinition, all_tools, find_tool, looks_like_capabilities_question,
500    looks_like_tools_question, render_capabilities, render_tool_detail, render_tools_overview,
501};
502pub use workflows::{Workflow, WorkflowError, WorkflowInfo, WorkflowManager};
503
504// NATS MQ module exports (messaging/JetStream)
505#[cfg(feature = "nats")]
506pub use nats_mq::NatsHealthMonitor;
507pub use nats_mq::{
508    Connection as NatsConnection, DispatchEvent, connect_nats, connect_with_retry, init_jetstream,
509    publish_json, spawn_nats_server, subjects, subscribe, subscribe_wildcard,
510};
511
512// Sandbox module exports (agent process isolation)
513pub use sandbox::{SandboxConfig, SandboxManager, create_default_sandbox};
514
515// Scripting module exports (Lua/Python/JS automation)
516pub use scripting::{
517    Script, ScriptContext, ScriptExecutionResult, ScriptLanguage, ScriptPermission, ScriptTrigger,
518    ScriptingEngine, get_scripting_engine,
519};
520
521// Security module exports (SecureStorage, encryption, etc.)
522#[cfg(feature = "security")]
523pub use security::{Encryptor, KeychainStorage, SecureConfigManager};
524pub use security::{
525    McpToken, MockSecureStorage, SecureStorage, SecureStorageError, create_secure_storage,
526};
527
528// Security/policy helpers and permission primitives.
529pub use tools::PermissionManager;
530pub use tools::permissions::{Permission, PermissionAuditEntry, PermissionCheck, PermissionScope};
531pub use tools::policy::{
532    ToolCallDecision, ToolConfirmationInfo, ToolPolicyEvaluation, evaluate_tool_call,
533    is_action_allowed, is_shell_command_write_operation, is_write_operation, requires_confirmation,
534};
535
536// Agents module exports (agent lifecycle, task delegation)
537pub use agents::{
538    AgentCommand, AgentEnvelope, AgentInfo, AgentManager, AgentSpawner, AgentStatus, DelegatedTask,
539    OrchestratorToolCall, TaskResult,
540};
541
542// Orchestrator exports (core-owned orchestration implementation)
543pub use orchestrator::{AgentOrchestrator, OrchestratorAgentManager, OrchestratorObserver};
544
545#[cfg(test)]
546mod tests {
547    use super::*;
548
549    #[test]
550    #[allow(clippy::const_is_empty)]
551    fn test_version() {
552        // VERSION comes from CARGO_PKG_VERSION which is always non-empty for valid packages
553        assert!(!VERSION.is_empty());
554    }
555
556    #[test]
557    fn test_name() {
558        assert_eq!(NAME, "gestura-core");
559    }
560}