1#![allow(dead_code)]
2#![allow(unused)]
3#![allow(unused_mut)]
4#![allow(unused_variables)]
5#![allow(unexpected_cfgs)]
6#![allow(unreachable_patterns)]
7#![allow(irrefutable_let_patterns)]
8#![allow(non_camel_case_types)]
9#![allow(non_snake_case)]
10#![allow(async_fn_in_trait)]
11
12pub mod cli_ndjson_safe_stringify;
13pub mod agent;
14pub mod error;
15pub mod hooks;
16pub mod http_client;
17pub mod interact;
18pub mod mcp;
19pub mod message_queue_types;
20pub(crate) mod query_engine;
21pub mod session;
22pub mod session_restore;
23pub mod session_state;
24pub mod state;
25pub mod stream;
26pub mod streaming_tool_executor;
27pub mod task;
28pub mod tasks;
29#[cfg(test)]
30mod tests;
31
32#[doc(hidden)]
35pub mod test_utils;
36pub mod tool;
37pub mod tool_errors;
38pub mod tool_helper;
39pub mod tool_result_storage;
40pub mod tool_validation;
41pub mod tools;
42pub mod types;
43pub mod utils;
44
45pub mod env;
46pub mod extract_memories;
47pub mod memdir;
48pub mod permission;
49pub mod plugin;
50
51pub use types::ids::AgentId;
52pub use utils::{
53 AbortController, AbortSignal, create_abort_controller, create_abort_controller_default,
54 create_agent_id, create_child_abort_controller, get_aws_region, get_claude_config_home_dir,
55 get_cwd, get_default_vertex_region, get_original_cwd, get_teams_dir,
56 get_vertex_region_for_model, has_node_option, is_bare_mode, is_env_defined_falsy,
57 is_env_truthy, is_in_protected_namespace, is_running_on_homespace, parse_env_vars, pwd,
58 run_with_cwd_override, set_cwd, should_maintain_project_working_dir, validate_uuid,
59};
60pub mod ai_md;
61pub mod analytics;
62pub mod bootstrap;
63pub mod bridge;
64pub mod bridge_enabled;
65pub mod commands;
66pub mod compact;
67pub mod constants;
68pub mod coordinator;
69pub mod cost;
70pub mod memory_types;
71pub mod prompts;
72pub mod review;
73pub mod services;
74pub mod session_discovery;
75pub mod session_history;
76pub mod session_memory;
77pub mod skills;
78pub mod team_memory;
79pub mod token_budget;
80pub mod user_agent;
81
82pub use agent::Agent;
83pub use ai_md::{
84 AI_MD_INSTRUCTION_PROMPT, AiMdContent, AiMdFile, AiMdType, MAX_AI_MD_CHARACTER_COUNT,
85 get_ai_md_files, load_ai_md, process_ai_md_file,
86};
87pub use bridge_enabled::{
88 OauthAccountInfo, check_bridge_min_version, get_bridge_disabled_reason,
89 get_ccr_auto_connect_default, is_bridge_enabled, is_bridge_enabled_blocking,
90 is_ccr_mirror_enabled, is_cse_shim_enabled, is_env_less_bridge_enabled,
91};
92pub use compact::{
93 AUTOCOMPACT_BUFFER_TOKENS, CompactCommand, ERROR_THRESHOLD_BUFFER_TOKENS,
94 MANUAL_COMPACT_BUFFER_TOKENS, MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES, TokenWarningState,
95 WARNING_THRESHOLD_BUFFER_TOKENS, calculate_token_warning_state, compact_errors,
96 estimate_token_count, get_auto_compact_threshold, get_compact_command,
97 get_effective_context_window_size, should_compact,
98};
99pub use env::{EnvConfig, is_assistant_mode, is_assistant_mode_enabled};
100pub use error::AgentError;
101pub use extract_memories::{
102 ExtractMemoriesConfig, ExtractMemoriesResult, ExtractMemoriesState, MemoryEntry,
103 MemoryEntryType, PendingExtraction, build_extract_auto_only_prompt,
104 build_extract_combined_prompt, count_model_visible_messages_since, count_tool_calls,
105 create_auto_mem_can_use_tool, drain_pending_extractions, execute_extract_memories,
106 parse_extracted_content, should_extract_memories,
107};
108pub use hooks::{
109 CONFIG_CHANGE_SOURCES, EXIT_REASONS, HOOK_EVENTS, HookConfig, HookDefinition, HookInput,
110 HookOutput, HookRegistry, INSTRUCTIONS_LOAD_REASONS, INSTRUCTIONS_MEMORY_TYPES,
111 create_hook_registry,
112};
113pub use memdir::{
114 EntrypointTruncation, MAX_ENTRYPOINT_LINES, MemoryFrontmatter, MemoryType,
115 ensure_memory_dir_exists, get_auto_mem_path, get_memory_base_dir, get_memory_entrypoint,
116 is_auto_mem_path, is_auto_memory_enabled, load_memory_prompt_sync,
117};
118pub use message_queue_types::MessageQueueEntry;
119pub use permission::{
120 PermissionAllowDecision, PermissionAskDecision, PermissionBehavior, PermissionContext,
121 PermissionDecision, PermissionDecisionReason, PermissionDenyDecision, PermissionHandler,
122 PermissionMetadata, PermissionMode, PermissionResult, PermissionRule, PermissionRuleSource,
123};
124pub use plugin::{
125 BUILTIN_MARKETPLACE_NAME_CONST, clear_builtin_plugins, get_builtin_plugin_definition,
126 get_builtin_plugin_skill_definitions, get_builtin_plugins, is_builtin_plugin_id,
127 register_builtin_plugin, BuiltinPluginResult, CommandAvailability, CommandMetadata,
128 CommandRegistry, CommandResult, CommandResultDisplay, CommandSource, LoadedPlugin,
129 PluginAuthor, PluginCommand, PluginComponent, PluginConfig, PluginError, PluginLoadResult,
130 PluginManifest, PluginMcpServer, PluginMcpServerManager, PluginRepository, PluginSkill,
131 get_plugin_error_message, load_plugin, load_plugin_skills, load_plugins_from_dir,
132 load_plugins_from_sources, register_plugin_skills,
133};
134pub use services::compact::auto_compact::{
135 AutoCompactResult, AutoCompactTrackingState, RecompactionInfo, is_auto_compact_enabled,
136 should_auto_compact,
137};
138pub use services::{
139 api::retry_helpers::{
140 is_connection_error, is_max_tokens_overflow as is_max_tokens_overflow_error,
141 is_server_error,
142 },
143 api::with_retry::{
145 DEFAULT_MAX_RETRIES as API_DEFAULT_MAX_RETRIES, FLOOR_OUTPUT_TOKENS, MAX_529_RETRIES,
146 RetryConfig as ApiRetryConfig, extract_retry_after_ms, get_retry_delay, is_529_error,
147 parse_max_tokens_overflow, retry_post, should_retry, with_retry,
148 },
149 api::{
150 API_ERROR_MESSAGE_PREFIX, API_TIMEOUT_ERROR_MESSAGE, ApiErrorMessage, ApiErrorType,
151 CCR_AUTH_ERROR_MESSAGE, CREDIT_BALANCE_TOO_LOW_ERROR_MESSAGE, CUSTOM_OFF_SWITCH_MESSAGE,
152 INVALID_API_KEY_ERROR_MESSAGE, INVALID_API_KEY_ERROR_MESSAGE_EXTERNAL,
153 NO_RESPONSE_REQUESTED, OAUTH_ORG_NOT_ALLOWED_ERROR_MESSAGE,
154 ORG_DISABLED_ERROR_MESSAGE_ENV_KEY, ORG_DISABLED_ERROR_MESSAGE_ENV_KEY_WITH_OAUTH,
155 PROMPT_TOO_LONG_ERROR_MESSAGE, REPEATED_529_ERROR_MESSAGE, SDKAssistantMessageError,
156 TOKEN_REVOKED_ERROR_MESSAGE, categorize_retryable_api_error, classify_api_error,
157 create_assistant_api_error_message, create_assistant_api_error_message_with_options,
158 extract_unknown_error_format, get_error_message_if_refusal,
159 get_image_too_large_error_message, get_oauth_org_not_allowed_error_message,
160 get_pdf_invalid_error_message, get_pdf_password_protected_error_message,
161 get_pdf_too_large_error_message, get_prompt_too_long_token_gap,
162 get_request_too_large_error_message, get_token_revoked_error_message, is_ccr_mode,
163 is_media_size_error, is_media_size_error_message, is_prompt_too_long_message,
164 is_valid_api_message, parse_prompt_too_long_token_counts, starts_with_api_error_prefix,
165 },
166 model_cost::{
167 COST_HAIKU_35, COST_HAIKU_45, COST_TIER_3_15, COST_TIER_5_25, COST_TIER_15_75, CostSummary,
168 ModelCostRegistry, ModelCosts, ModelInfo, TokenUsage, calculate_cost, format_cost,
169 get_available_models,
170 },
171 rate_limit::{
172 RateLimit as RateLimitInfo, RateLimitConfig, RateLimitStatus, RateLimiter,
173 RateLimiterBuilder,
174 },
175 retry::{
176 DEFAULT_MAX_RETRIES, RetryConfig, RetryError, is_rate_limit_error, is_retryable_error,
177 is_service_unavailable_error, retry_async, retry_with_retry_after,
178 },
179 token_estimation::{
180 EstimationMethod, TokenEstimate, calculate_padding, estimate_conversation, estimate_tokens,
181 estimate_tokens_characters, estimate_tokens_words, estimate_tool_definitions,
182 fits_in_context,
183 },
184};
185pub use session::{
186 SessionData, SessionMetadata, append_to_session, delete_session, fork_session,
187 get_session_info, get_session_messages, list_sessions, load_session, rename_session,
188 save_session, tag_session,
189};
190pub use session_discovery::discover_assistant_sessions;
191pub use session_history::{
192 HISTORY_PAGE_SIZE, HistoryAuthCtx, HistoryPage, OAuthTokens, OauthConfig, SDKMessage,
193 create_history_auth_ctx, fetch_latest_events, fetch_older_events, get_bridge_access_token,
194 get_bridge_base_url, get_bridge_base_url_override, get_bridge_headers,
195 get_bridge_token_override, get_oauth_headers, prepare_api_request,
196};
197pub use session_memory::{
198 DEFAULT_SESSION_MEMORY_CONFIG, ManualExtractionResult, SessionMemoryConfig,
199 get_last_summarized_message_id, get_session_memory_config, get_session_memory_content,
200 get_session_memory_dir, get_session_memory_path,
201 get_tool_calls_between_updates, has_met_initialization_threshold, has_met_update_threshold,
202 init_session_memory_file, is_session_memory_initialized, mark_session_memory_initialized,
203 record_extraction_token_count, reset_session_memory_state, set_last_summarized_message_id,
204 set_session_memory_config, should_extract_memory, wait_for_session_memory_extraction,
205};
206pub use skills::{
207 BundledSkill, LoadedSkill, SkillMetadata, get_bundled_skills, init_bundled_skills,
208 load_skill_from_dir, load_skills_from_dir,
209};
210pub use state::Store;
211pub use stream::{CancelGuard, EventSubscriber};
212pub use task::{
213 LocalShellSpawnInput, ShellKind, TASK_ID_ALPHABET, TASK_ID_PREFIXES, TaskHandle, TaskStateBase,
214 TaskStatus, TaskType, create_task_state_base, generate_task_id, get_task_id_prefix,
215 get_task_output_path, is_terminal_task_status,
216};
217pub use team_memory::{
218 MAX_CONFLICT_RETRIES, MAX_FILE_SIZE_BYTES, MAX_PUT_BODY_BYTES, MAX_RETRIES, SkippedSecretFile,
219 SyncState, TEAM_MEMORY_SYNC_TIMEOUT_MS, TeamMemoryContent, TeamMemoryData,
220 TeamMemoryHashesResult, TeamMemorySyncFetchResult, TeamMemorySyncPushResult,
221 TeamMemorySyncUploadResult, TeamMemoryTooManyEntries, batch_delta_by_bytes, compute_delta,
222 create_sync_state, delete_local_team_memory_entry, disable_team_memory, enable_team_memory,
223 get_last_sync_error, get_team_memory_dir, get_team_memory_path, hash_content,
224 is_team_memory_enabled, is_team_memory_sync_available, pull_team_memory, push_team_memory,
225 read_local_team_memory, scan_entries_for_secrets, scan_for_secrets, set_last_sync_error,
226 sync_team_memory, validate_team_memory_key, write_local_team_memory,
227};
228pub use tool_helper::{
229 SdkToolDefinition, ToolAnnotations, create_tool, create_tool_with_annotations,
230 sdk_tool_to_tool_definition,
231};
232pub use tools::{
233 Tool, ToolDefinition, ToolFuture, ToolInputSchema, filter_tools, get_all_base_tools,
234};
235pub use types::*;
236
237pub fn get_all_tools() -> Vec<ToolDefinition> {
239 get_all_base_tools()
240}
241
242pub const MACRO_VERSION: &str = env!("CARGO_PKG_VERSION");
244
245pub use user_agent::get_claude_code_user_agent;
246
247pub use coordinator::{
249 WORKER_AGENT, apply_coordinator_tool_filter, get_coordinator_system_prompt,
250 get_coordinator_user_context, is_coordinator_mode, is_pr_activity_subscription_tool,
251 match_session_mode,
252};