Skip to main content

AppContext

Struct AppContext 

Source
pub struct AppContext {
    pub harness: RefCell<Option<Harness>>,
    /* private fields */
}
Expand description

Shared application context threaded through all command handlers.

Holds the language provider, backup/checkpoint stores, configuration, and call graph engine. Constructed once at startup and passed by reference to dispatch.

Stores use RefCell for interior mutability — the binary is single-threaded (one request at a time on the stdin read loop) so runtime borrow checking is safe and never contended.

Fields§

§harness: RefCell<Option<Harness>>

Implementations§

Source§

impl AppContext

Source§

impl AppContext

Source

pub fn new(provider: Box<dyn LanguageProvider>, config: Config) -> Self

Source

pub fn status_bar_counts(&self) -> Option<StatusBarCounts>

Current agent status-bar counts. errors/warnings are read LIVE from the LSP diagnostics store (continuously drained, no round-trip); the Tier-2 + todos counts are the last-known cached values. Returns None until the Tier-2 cache has been populated at least once, so we never surface a bar that misleadingly claims “0 dead code” before any scan.

Source

pub fn clear_tsconfig_membership_cache(&self)

Invalidate the status-bar tsconfig-membership cache. Called from the watcher seam when a tsconfig-like file changes and from configure when the project root changes, so the next bar count re-reads from disk.

Source

pub fn mark_status_bar_tier2_stale(&self) -> bool

Mark the status-bar Tier-2 counts stale (rendered with ~) without changing the numbers — called when the watcher sees a source-file change, so the bar honestly signals the counts predate the latest edit until the next background scan completes. Returns true only when the visible stale bit flips. No-op before the first populate.

Source

pub fn update_status_bar_tier2( &self, dead_code: Option<usize>, unused_exports: Option<usize>, duplicates: Option<usize>, todos: Option<usize>, stale: bool, )

Refresh the cached Tier-2 + todos counts for the status bar. Each count is Option: None preserves the last-known value (the category wasn’t recomputed or has no real aggregate yet) so we never overwrite a real count with a fabricated 0. stale marks the Tier-2 numbers as not-yet-reconciled with the latest edits.

Source

pub fn gitignore(&self) -> Option<Arc<Gitignore>>

Borrow the cached project gitignore matcher. Returns None when no project_root is configured or when the project has no gitignore files.

Source

pub fn clear_gitignore(&self)

Rebuild the gitignore matcher from the current project_root and cache it. Called by the configure handler whenever the project root changes, and by the watcher event drain when a .gitignore file itself is modified.

The builder honors:

  • <project_root>/.gitignore
  • Git’s global excludes file (the same source used by ignore::WalkBuilder)
  • the repository’s real info/exclude file, resolved through Git’s common dir for linked worktrees
  • nested .gitignore files (each .gitignore discovered during the recursive walk)

Stores None if there’s no project_root or no matchable gitignore files. Logs build errors but never fails configure. Clear any cached gitignore matcher without rebuilding.

Used by handle_configure in degraded mode (e.g. project_root == $HOME) where running the gitignore-discovery walk would exceed the configure budget. The watcher event filter falls back to the hardcoded infra-dir skip list when no matcher is present.

Source

pub fn rebuild_gitignore(&self)

Source

pub fn bash_compress_flag(&self) -> Arc<AtomicBool>

Shared atomic mirror of experimental.bash.compress. Updated by the configure handler. Read by the BgTaskRegistry compressor closure.

Source

pub fn sync_bash_compress_flag(&self)

Update the shared bash_compress_flag mirror. Call this from the configure handler whenever experimental.bash.compress changes so the BgTaskRegistry watchdog sees the new value on the next completion.

Source

pub fn set_bash_compress_enabled(&self, enabled: bool)

Source

pub fn filter_registry(&self) -> RwLockReadGuard<'_, FilterRegistry>

Read-only access to the TOML filter registry, building it lazily on first use. Returns an RwLockReadGuard that callers can lookup against directly.

Source

pub fn shared_filter_registry(&self) -> SharedFilterRegistry

Returns the shared Arc<RwLock<FilterRegistry>> handle so threads outside AppContext (notably the bash watchdog) can read it without touching the rest of the context.

Source

pub fn reset_filter_registry(&self)

Force a fresh load of the TOML filter registry. Called when configure changes the project root, storage_dir, or trust state so subsequent compress::compress calls pick up new filters.

Source

pub fn lsp_child_registry(&self) -> LspChildRegistry

Clone the LSP child registry handle. Used by main.rs to give the signal handler thread a way to SIGKILL LSP children on shutdown.

Source

pub fn stdout_writer(&self) -> SharedStdoutWriter

Source

pub fn set_progress_sender(&self, sender: Option<ProgressSender>)

Source

pub fn emit_progress(&self, frame: ProgressFrame)

Source

pub fn status_emitter(&self) -> &StatusEmitter

Source

pub fn progress_sender_handle(&self) -> Option<ProgressSender>

Get a clone of the current progress sender for use from background threads. Returns None when the main loop hasn’t installed one (tests, CLI without push frames).

Used by configure’s deferred file-walk thread to push warnings after configure has already returned, so configure latency stays sub-100 ms even on huge directories.

Source

pub fn advance_configure_generation(&self) -> u64

Source

pub fn configure_generation(&self) -> u64

Source

pub fn configure_warnings_sender(&self) -> Sender<(u64, ConfigureWarningsFrame)>

Source

pub fn drain_configure_warnings(&self) -> Vec<(u64, ConfigureWarningsFrame)>

Source

pub fn bash_background(&self) -> &BgTaskRegistry

Source

pub fn drain_bg_completions(&self) -> Vec<BgCompletion>

Source

pub fn provider(&self) -> &dyn LanguageProvider

Access the language provider.

Source

pub fn backup(&self) -> &RefCell<BackupStore>

Access the backup store.

Source

pub fn checkpoint(&self) -> &RefCell<CheckpointStore>

Access the checkpoint store.

Source

pub fn set_db(&self, conn: Arc<Mutex<Connection>>)

Source

pub fn clear_db(&self)

Source

pub fn db(&self) -> Option<Arc<Mutex<Connection>>>

Source

pub fn config(&self) -> Ref<'_, Config>

Access the configuration (shared borrow).

Source

pub fn config_mut(&self) -> RefMut<'_, Config>

Access the configuration (mutable borrow).

Source

pub fn set_harness(&self, harness: Harness)

Source

pub fn harness_opt(&self) -> Option<Harness>

Source

pub fn harness(&self) -> Harness

Source

pub fn storage_dir(&self) -> PathBuf

Source

pub fn harness_dir(&self) -> PathBuf

Source

pub fn inspect_dir(&self) -> PathBuf

Source

pub fn bash_tasks_dir(&self, session_id: &str) -> PathBuf

Source

pub fn backups_dir(&self, session_id: &str, path_hash: &str) -> PathBuf

Source

pub fn filters_dir(&self) -> PathBuf

Source

pub fn trust_file(&self) -> PathBuf

HOST-GLOBAL — NOT under harness_dir. Read by trust.rs across both harnesses.

Source

pub fn set_canonical_cache_root(&self, root: PathBuf)

Source

pub fn canonical_cache_root(&self) -> PathBuf

Source

pub fn canonical_cache_root_opt(&self) -> Option<PathBuf>

Source

pub fn set_cache_role( &self, is_worktree_bridge: bool, git_common_dir: Option<PathBuf>, )

Source

pub fn is_worktree_bridge(&self) -> bool

Source

pub fn git_common_dir(&self) -> Option<PathBuf>

Source

pub fn set_degraded_reasons(&self, reasons: Vec<String>)

Replace the current degraded-mode reasons. Empty vec = full-featured mode (no degradation). Called by handle_configure after deciding which subsystems to disable for this project root.

Source

pub fn add_degraded_reason(&self, reason: impl Into<String>) -> bool

Source

pub fn degraded_reasons(&self) -> Vec<String>

Snapshot of current degraded-mode reasons. Order is stable (insertion order from set_degraded_reasons) so UI rendering and snapshot diffs are deterministic.

Source

pub fn is_degraded(&self) -> bool

True iff at least one degraded reason is recorded.

Source

pub fn cache_role(&self) -> &'static str

Source

pub fn callgraph(&self) -> &RefCell<Option<CallGraph>>

Access the call graph engine.

Source

pub fn callgraph_store(&self) -> &RefCell<Option<CallGraphStore>>

Access the persisted call graph store.

Source

pub fn mark_callgraph_store_force_rebuild(&self)

Source

pub fn callgraph_store_dir(&self) -> PathBuf

Source

pub fn ensure_callgraph_store( &self, ) -> Result<Option<RefMut<'_, CallGraphStore>>, CallGraphStoreError>

Source

pub fn revalidate_callgraph_store_generation(&self)

Access the persisted callgraph store for the five store-backed edge-query ops without ever blocking the request thread on a cold build.

  • Store resident -> Ready.
  • Warm on-disk DB present -> opened synchronously (cheap) -> Ready.
  • Genuine cold build needed -> kicked off in the background, returns Building; the watcher keeps the store fresh once it lands.
  • Worktree without a built store, or not configured -> Unavailable.

A build already in flight (callgraph_store_rx set) also returns Building without starting a second build. Drop the resident callgraph store when another process (or a local cold rebuild) has published a newer generation, so the next access reopens via the pointer. No-op when no store is resident, a build is in flight, or the store is still current. Must run before serving ops AND before any incremental write, so every process converges on the current generation rather than writing to a stale one.

Source

pub fn callgraph_store_for_ops(&self) -> CallgraphStoreAccess<'_>

Source

pub fn callgraph_store_rx(&self) -> &RefCell<Option<Receiver<CallGraphStore>>>

Access the callgraph-store background-build receiver (drained by the main loop once the cold build completes).

Source

pub fn add_pending_callgraph_store_paths<I>(&self, paths: I)
where I: IntoIterator<Item = PathBuf>,

Record source-file paths that changed while a cold build was in flight, so they can be refreshed once the freshly-built store is installed.

Source

pub fn take_pending_callgraph_store_paths(&self) -> Vec<PathBuf>

Take and clear the paths that changed during a background cold build.

Source

pub fn search_index(&self) -> &RefCell<Option<SearchIndex>>

Access the search index.

Source

pub fn search_index_rx(&self) -> &RefCell<Option<Receiver<SearchIndex>>>

Access the search-index build receiver.

Source

pub fn add_pending_search_index_paths<I>(&self, paths: I)
where I: IntoIterator<Item = PathBuf>,

Source

pub fn take_pending_search_index_paths(&self) -> Vec<PathBuf>

Source

pub fn add_pending_semantic_index_paths<I>(&self, paths: I)
where I: IntoIterator<Item = PathBuf>,

Source

pub fn take_pending_semantic_index_paths(&self) -> Vec<PathBuf>

Source

pub fn mark_pending_semantic_corpus_refresh(&self)

Source

pub fn take_pending_semantic_corpus_refresh(&self) -> bool

Source

pub fn clear_pending_index_updates(&self)

Source

pub fn inspect_manager(&self) -> Arc<InspectManager>

Source

pub fn take_new_reuse_completions(&self) -> bool

Returns true when one or more watcher-driven (reuse-path) Tier-2 scans have completed since the last call, advancing the last-seen marker. The per-request inspect drain uses this to refresh the status bar after a background scan — those completions bypass drain_completions.

Source

pub fn reset_tier2_refresh_scheduler(&self)

Source

pub fn request_tier2_refresh_pull(&self) -> bool

Source

pub fn tick_tier2_refresh_scheduler( &self, changed_path_count: usize, ) -> Option<Tier2TriggerReason>

Source

pub fn note_tier2_refresh_started(&self)

Source

pub fn tier2_trigger_reason(&self) -> Option<&'static str>

Source

pub fn symbol_cache(&self) -> SharedSymbolCache

Access the shared symbol cache.

Source

pub fn reset_symbol_cache(&self) -> u64

Clear the shared symbol cache and return the new active generation.

Source

pub fn semantic_index(&self) -> &RefCell<Option<SemanticIndex>>

Access the semantic search index.

Source

pub fn semantic_index_rx( &self, ) -> &RefCell<Option<Receiver<SemanticIndexEvent>>>

Access the semantic-index build receiver.

Source

pub fn semantic_index_status(&self) -> &RefCell<SemanticIndexStatus>

Source

pub fn install_semantic_refresh_worker( &self, sender: Sender<SemanticRefreshRequest>, event_rx: Receiver<SemanticRefreshEvent>, worker_slot: SemanticRefreshWorkerSlot, )

Source

pub fn clear_semantic_refresh_worker(&self)

Source

pub fn semantic_refresh_sender(&self) -> Option<Sender<SemanticRefreshRequest>>

Source

pub fn semantic_refresh_event_rx( &self, ) -> &RefCell<Option<Receiver<SemanticRefreshEvent>>>

Source

pub fn semantic_embedding_model(&self) -> &RefCell<Option<EmbeddingModel>>

Access the cached semantic embedding model.

Source

pub fn watcher(&self) -> &RefCell<Option<RecommendedWatcher>>

Access the file watcher handle (kept alive to continue watching).

Source

pub fn watcher_rx(&self) -> &RefCell<Option<Receiver<Result<Event>>>>

Access the watcher event receiver.

Source

pub fn lsp(&self) -> RefMut<'_, LspManager>

Access the LSP manager.

Source

pub fn lsp_notify_file_changed(&self, file_path: &Path, content: &str)

Notify LSP servers that a file was written. Call this after write_format_validate in command handlers.

Source

pub fn lsp_clear_diagnostics_for_file(&self, file_path: &Path) -> bool

Drop cached LSP diagnostics for a deleted/renamed-away file so its errors/warnings don’t linger in the warm set (no server republishes for a vanished path), keeping the status bar and aft_inspect honest. Returns true if any entry was removed. Best-effort: a contended borrow is skipped silently (the watcher drain retries on subsequent events).

Source

pub fn lsp_notify_and_collect_diagnostics( &self, file_path: &Path, content: &str, timeout: Duration, ) -> PostEditWaitOutcome

Notify LSP and optionally wait for diagnostics.

Call this after write_format_validate when the request has "diagnostics": true. Sends didChange to the server, waits briefly for publishDiagnostics, and returns any diagnostics for the file. If no server is running, returns empty immediately.

v0.17.3: this is the version-aware path. Pre-edit cached diagnostics are NEVER returned — only entries whose version matches the post-edit document version (or, for unversioned servers, whose epoch advanced past the pre-edit snapshot).

Source

pub fn lsp_notify_watched_config_file( &self, file_path: &Path, change_type: FileChangeType, )

Source

pub fn lsp_post_multi_file_write( &self, file_path: &Path, content: &str, file_paths: &[PathBuf], params: &Value, ) -> Option<PostEditWaitOutcome>

Post-write LSP hook for multi-file edits. When the patch includes config-file edits, notify active workspace servers via workspace/didChangeWatchedFiles before sending the per-document didOpen/didChange for the current file.

Source

pub fn lsp_post_write( &self, file_path: &Path, content: &str, params: &Value, ) -> Option<PostEditWaitOutcome>

Post-write LSP hook: notify server and optionally collect diagnostics.

This is the single call site for all command handlers after write_format_validate. Behavior:

  • When diagnostics: true is in params, notifies the server, waits until matching diagnostics arrive or the timeout expires, and returns Some(outcome) with the verified-fresh diagnostics + per-server status.
  • When diagnostics: false (or absent), just notifies (fire-and-forget) and returns None. Callers must NOT wrap this in Some(...); the None is what tells the response builder to omit the LSP fields entirely (preserves the no-diagnostics-requested response shape).

v0.17.3: default wait_ms raised from 1500 to 3000 because real-world tsserver re-analysis on monorepo files routinely takes 2-5s. Still capped at 10000ms.

Source

pub fn validate_path( &self, req_id: &str, path: &Path, ) -> Result<PathBuf, Response>

Validate that a file path falls within the configured project root.

When project_root is configured (normal plugin usage), this resolves the path and checks it starts with the root. Returns the canonicalized path on success, or an error response on violation.

When no project_root is configured (direct CLI usage), all paths pass through unrestricted for backward compatibility.

Source

pub fn lsp_server_count(&self) -> usize

Count active LSP server instances.

Source

pub fn symbol_cache_stats(&self) -> Value

Symbol cache statistics from the language provider.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more