pub struct Api { /* private fields */ }Expand description
Main API for RYO operations.
This is the primary entry point for external consumers (CLI, UI, Agent). All operations go through this facade.
Implementations§
Source§impl Api
impl Api
Sourcepub fn from_path(path: impl AsRef<Path>) -> ApiResult<Self>
pub fn from_path(path: impl AsRef<Path>) -> ApiResult<Self>
Create a new API from a project path.
This loads the project and builds the analysis context.
Uses from_workspace_root for full workspace analysis (not just entry points).
Sourcepub fn with_context(
context: AnalysisContext,
project: Project,
storage: Box<dyn Storage>,
) -> Self
pub fn with_context( context: AnalysisContext, project: Project, storage: Box<dyn Storage>, ) -> Self
Create a new API with a pre-built context.
This is useful for server mode where the context is already loaded. Loads suggest configuration from ryo.toml via the Project.
Sourcepub fn new(storage: Box<dyn Storage>) -> Self
pub fn new(storage: Box<dyn Storage>) -> Self
Create a new API with the given storage backend.
This is the legacy constructor for backward compatibility. Uses current directory to load project. Loads suggest configuration from ryo.toml.
§Panics
Panics if project cannot be loaded from current directory.
Consider using from_path() instead.
Sourcepub fn discover(
&mut self,
request: DiscoverRequest,
) -> ApiResult<DiscoverResponse>
pub fn discover( &mut self, request: DiscoverRequest, ) -> ApiResult<DiscoverResponse>
Sourcepub fn overview(&self, _request: OverviewRequest) -> ApiResult<OverviewResponse>
pub fn overview(&self, _request: OverviewRequest) -> ApiResult<OverviewResponse>
Get codebase overview (module tree, key types, statistics).
Sourcepub fn query_ryoql(&self, request: RyoqlRequest) -> ApiResult<QueryResponse>
pub fn query_ryoql(&self, request: RyoqlRequest) -> ApiResult<QueryResponse>
Execute a RyoQL query and return structured results.
Parses the query string (YAML/JSON), determines view mode, and executes against the analysis context.
Sourcepub fn search_literal(
&self,
_request: LiteralSearchRequest,
) -> ApiResult<LiteralSearchResponse>
pub fn search_literal( &self, _request: LiteralSearchRequest, ) -> ApiResult<LiteralSearchResponse>
Search literals - stub when feature is disabled.
Sourcepub fn suggest(&self, request: SuggestRequest) -> ApiResult<SuggestResponse>
pub fn suggest(&self, request: SuggestRequest) -> ApiResult<SuggestResponse>
Sourcepub fn suggest_scan(&self) -> usize
pub fn suggest_scan(&self) -> usize
Scan the codebase and detect new suggestions.
This runs all registered patterns against the current context and populates the suggestion cache.
Respects disabled_rules, enabled_rules, and severity_overrides from ryo.toml.
Sourcepub fn suggest_scan_with_scope(&self, scope_filter: &[SymbolScope]) -> usize
pub fn suggest_scan_with_scope(&self, scope_filter: &[SymbolScope]) -> usize
Scan with scope filtering.
If scope_filter is empty, all scopes are included.
Otherwise, only suggestions matching one of the specified scopes are stored.
Sourcepub fn suggest_scan_with_precheck(&self) -> DetectWithPrecheckResult
pub fn suggest_scan_with_precheck(&self) -> DetectWithPrecheckResult
Scan the codebase with pre-check verification.
This runs all registered patterns against the current context, verifies each suggestion speculatively, and only stores suggestions that pass the pre-check. This ensures that Apply will succeed.
§Example
let result = api.suggest_scan_with_precheck();
println!("Passed: {}, Failed: {}", result.passed, result.failed_precheck);Sourcepub fn suggest_service(&self) -> &SuggestService
pub fn suggest_service(&self) -> &SuggestService
Get the SuggestService for direct access.
Sourcepub fn suggest_config(&self) -> &SuggestConfig
pub fn suggest_config(&self) -> &SuggestConfig
Get the SuggestConfig.
Sourcepub fn take_suggest_store(&self) -> SuggestStore
pub fn take_suggest_store(&self) -> SuggestStore
Take the suggestion store contents for preservation across reload.
Returns the current store, leaving an empty store in place.
Sourcepub fn restore_suggest_store(&self, store: SuggestStore)
pub fn restore_suggest_store(&self, store: SuggestStore)
Restore suggestion store contents after reload.
Sourcepub fn suggest_apply(
&mut self,
request: SuggestApplyRequest,
) -> ApiResult<SuggestApplyResponse>
pub fn suggest_apply( &mut self, request: SuggestApplyRequest, ) -> ApiResult<SuggestApplyResponse>
Apply suggestions by ID.
Takes suggestion IDs, generates MutationSpecs, and executes them. Returns information about which suggestions were successfully applied.
§Example
let response = api.suggest_apply(SuggestApplyRequest {
ids: vec!["S001g0".to_string(), "S002g0".to_string()],
dry_run: false,
check_syntax: true,
})?;
if response.success {
println!("Applied {} suggestions", response.applied_ids.len());
}Sourcepub fn graph_summary(
&self,
request: GraphSummaryRequest,
) -> ApiResult<GraphSummaryResponse>
pub fn graph_summary( &self, request: GraphSummaryRequest, ) -> ApiResult<GraphSummaryResponse>
Sourcepub fn graph_cascade(
&self,
request: CascadeRequest,
) -> ApiResult<CascadeResponse>
pub fn graph_cascade( &self, request: CascadeRequest, ) -> ApiResult<CascadeResponse>
Sourcepub fn graph_type(
&self,
request: TypeAnalysisRequest,
) -> ApiResult<TypeAnalysisResponse>
pub fn graph_type( &self, request: TypeAnalysisRequest, ) -> ApiResult<TypeAnalysisResponse>
Type relationship analysis using TypeFlowGraph.
Analyzes type definitions → usage relationships with O(1) impact analysis via inverted index.
Sourcepub fn graph_flow(
&self,
request: FlowAnalysisRequest,
) -> ApiResult<FlowAnalysisResponse>
pub fn graph_flow( &self, request: FlowAnalysisRequest, ) -> ApiResult<FlowAnalysisResponse>
Data flow analysis (provenance and impact tracking).
Tracks data provenance (where values come from) and impact (where values flow to). Identifies sources and sinks.
Sourcepub fn graph_borrow(
&self,
request: BorrowAnalysisRequest,
) -> ApiResult<BorrowAnalysisResponse>
pub fn graph_borrow( &self, request: BorrowAnalysisRequest, ) -> ApiResult<BorrowAnalysisResponse>
Borrow analysis (conflict detection, use-after-move).
Tracks active borrows and detects potential conflicts or use-after-move errors.
Sourcepub fn graph_lock(
&self,
request: LockAnalysisRequest,
) -> ApiResult<LockAnalysisResponse>
pub fn graph_lock( &self, request: LockAnalysisRequest, ) -> ApiResult<LockAnalysisResponse>
Lock analysis (critical sections and optimization).
Analyzes lock usage patterns, critical section sizes, and provides optimization suggestions.
Sourcepub fn graph_chain(
&self,
request: ChainAnalysisRequest,
) -> ApiResult<ChainAnalysisResponse>
pub fn graph_chain( &self, request: ChainAnalysisRequest, ) -> ApiResult<ChainAnalysisResponse>
Transitive call chain traversal.
Analyzes the transitive closure of call/use relationships up to a specified depth. Uses BFS for level-order traversal with accurate depth tracking.
§Directions
- Callers: Who calls this function (transitively)?
- Callees: What does this function call (transitively)?
- Users: What types use this type (transitively)?
- Uses: What types does this type use (transitively)?
Sourcepub fn status(&self) -> StatusResponse
pub fn status(&self) -> StatusResponse
Get server/context status.
Sourcepub fn spec(&mut self, request: SpecRequest) -> ApiResult<SpecResponse>
pub fn spec(&mut self, request: SpecRequest) -> ApiResult<SpecResponse>
Sourcepub fn run(&mut self, request: RunRequest) -> ApiResult<RunResponse>
pub fn run(&mut self, request: RunRequest) -> ApiResult<RunResponse>
Sourcepub fn execute(&mut self, goal: Goal) -> ApiResult<ExecutionResult>
pub fn execute(&mut self, goal: Goal) -> ApiResult<ExecutionResult>
Execute a goal with default options.
This is a convenience wrapper around execute_with_options with default settings.
Sourcepub fn execute_with_options(
&mut self,
goal: Goal,
options: ExecuteOptions,
) -> ApiResult<ExecutionResult>
pub fn execute_with_options( &mut self, goal: Goal, options: ExecuteOptions, ) -> ApiResult<ExecutionResult>
Execute a goal on a project with custom options.
This is the main entry point for code transformations with full control.
§Flow
- Validate goal confidence
- Plan mutations from Intent using Planner
- Build ParallelBlueprint from MutationSpecs
- Handle conflicts according to ConflictStrategy
- Execute via BlueprintExecutor (unless dry_run)
- Verify syntax if check_syntax enabled
- Record mutations to TxLog
- Apply changes back to Project
§Conflict Handling
ConflictStrategy::Fail: Returns error if conflicts detectedConflictStrategy::IntentOrder: Clears conflicts, executes in intent orderConflictStrategy::ParallelOnly: Skips conflicting mutations
Sourcepub fn execute_and_save(&mut self, goal: Goal) -> ApiResult<ExecutionResult>
pub fn execute_and_save(&mut self, goal: Goal) -> ApiResult<ExecutionResult>
Execute a goal and save the session.
Sourcepub fn execute_and_save_with_options(
&mut self,
goal: Goal,
options: ExecuteOptions,
) -> ApiResult<ExecutionResult>
pub fn execute_and_save_with_options( &mut self, goal: Goal, options: ExecuteOptions, ) -> ApiResult<ExecutionResult>
Execute a goal with options and save the session.
Sourcepub fn list_sessions(&self) -> ApiResult<Vec<String>>
pub fn list_sessions(&self) -> ApiResult<Vec<String>>
List all sessions.
Sourcepub fn load_session(&self, session_id: &str) -> ApiResult<TxLog>
pub fn load_session(&self, session_id: &str) -> ApiResult<TxLog>
Load a session’s transaction log.
Sourcepub fn storage_mut(&mut self) -> &mut dyn Storage
pub fn storage_mut(&mut self) -> &mut dyn Storage
Get mutable access to storage (for initialization, etc.)
Sourcepub fn context(&self) -> &AnalysisContext
pub fn context(&self) -> &AnalysisContext
Get reference to the analysis context.
Sourcepub fn save_uuid_mappings(&self) -> ApiResult<()>
pub fn save_uuid_mappings(&self) -> ApiResult<()>
Save UUID mappings to disk for persistence across sessions.
Callers must explicitly call this method to persist UUID mappings. This is NOT called automatically on drop.
§When to Call
- Server mode: On shutdown RPC and idle timeout (see
RyoServer) - Standalone mode: At the end of commands that modify symbols
UUID mappings are saved to .ryo/uuid-mapping.json in the workspace root.
Sourcepub fn suggest_choices(
&self,
request: SuggestChoicesRequest,
) -> ApiResult<SuggestChoicesResponse>
pub fn suggest_choices( &self, request: SuggestChoicesRequest, ) -> ApiResult<SuggestChoicesResponse>
Get design choices for a suggestion.
Returns the available design choices for a suggestion that has multiple implementation approaches (e.g., different refactoring strategies).
§Example
let response = api.suggest_choices(SuggestChoicesRequest::new("S001g0"))?;
if response.has_choices {
for choice in &response.choices {
println!("{}: {} ({})", choice.label, choice.title, choice.description);
}
}Sourcepub fn suggest_verify(
&self,
request: SuggestVerifyRequest,
) -> ApiResult<SuggestVerifyResponse>
pub fn suggest_verify( &self, request: SuggestVerifyRequest, ) -> ApiResult<SuggestVerifyResponse>
Verify a suggestion before applying.
Runs verification checks on a suggestion to ensure it can be safely applied. Supports two verification levels:
- Light: Fast in-memory graph check
- Full: Cargo check in temporary workspace
§Example
let response = api.suggest_verify(SuggestVerifyRequest::new("S001g0").level(VerifyLevel::Full))?;
if response.passed {
println!("Verification passed in {}ms", response.duration_ms);
} else {
for diag in &response.diagnostics {
println!(" {}", diag);
}
}Sourcepub fn suggest_compare(
&self,
request: SuggestCompareRequest,
) -> ApiResult<SuggestCompareResponse>
pub fn suggest_compare( &self, request: SuggestCompareRequest, ) -> ApiResult<SuggestCompareResponse>
Compare design choices for a suggestion.
Generates a comparison table showing trade-offs between different implementation approaches for a suggestion.
§Example
let response = api.suggest_compare(SuggestCompareRequest::new("S001g0"))?;
println!("{}", response.comparison_table);
for choice in &response.ranked_choices {
println!("{}: {}", choice.label, choice.title);
}Sourcepub fn suggest_generate(
&self,
request: SuggestGenerateRequest,
) -> ApiResult<SuggestGenerateResponse>
pub fn suggest_generate( &self, request: SuggestGenerateRequest, ) -> ApiResult<SuggestGenerateResponse>
Generate code from parameterized patterns.
This method supports two modes:
- List mode (
list: true): Returns available parameterized patterns - Generate mode: Creates code from a pattern with parameters
§Example
// List available patterns
let list_req = SuggestGenerateRequest::list_patterns();
let patterns = api.suggest_generate(list_req)?;
// Generate OrderAPI
let gen_req = SuggestGenerateRequest::generate("api-pattern")
.with_param("name", "Order");
let result = api.suggest_generate(gen_req)?;Auto Trait Implementations§
impl !Freeze for Api
impl !RefUnwindSafe for Api
impl Send for Api
impl Sync for Api
impl Unpin for Api
impl UnsafeUnpin for Api
impl !UnwindSafe for Api
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more