Skip to main content

Crate ryu_predict

Crate ryu_predict 

Source
Expand description

Predictive typing — the “brain” behind system-wide inline autocomplete.

This crate owns the completion engine: the config (model / per-app allowlist / debounce), the privacy denylist for password & secure controls, the prompt assembly, the cleanup of the raw model reply, and the /api/predict/* HTTP surface (api). The native overlay (apps-store/predict) stays deliberately dumb — it reads the caret context, POSTs it here, and renders whatever string comes back. No Gateway URL, key, or model id ever lives in the overlay process.

Placement (CLAUDE.md §1, Core vs Gateway): deciding what runs (assemble the prompt, enforce the app allowlist, refuse secure fields) is Core. The actual model call is handed to the Gateway via the host’s PredictHost::call_side_model (the same path /btw, goal, and double-check use), so model routing / firewall / budgets / audit all apply — nothing hardcoded.

§What stayed in the kernel

The process-global “predictive typing is on” flag — predict::set_enabled / predict::is_enabled, seeded at boot from the built-in Predict plugin’s persisted state and flipped live from the plugin enable/disable path (apply_policy) — stays in apps/core: it is the plugin’s on/off switch, part of the AppGate/plugin wiring, not the completion engine. This crate reads it through PredictHost::is_enabled. The plugin id const + the predict.plugin.json fixture likewise stay in Core.

The shared in-editor copilot (PlateJS ghost text) routes through the Gateway directly from the desktop webview; this endpoint is the system-wide sibling for arbitrary native apps, but both speak the same predictive contract.

Re-exports§

pub use api::routes;
pub use api::PredictCtx;

Modules§

api
HTTP API for predictive typing (/api/predict/*): the system-wide inline autocomplete brain.

Structs§

PredictConfig
Persisted predictive-typing configuration. camelCase so the desktop settings tab and the overlay can read/write the same JSON shape.

Constants§

DEFAULT_DEBOUNCE_MS
Default debounce between caret changes and a prediction request (ms).
DEFAULT_MAX_CHARS
Default cap on a suggestion’s length (characters). Keeps inline ghost text to a sentence-ish continuation rather than a runaway paragraph.
PREDICT_CONFIG_PREF
Preference key holding the predictive-typing config blob (one JSON object, mirroring how editor-ai is stored). The desktop settings tab and the apps-store/predict overlay both read/write this single key.

Traits§

PredictHost
The kernel couplings the moved predict engine needs, inverted so this crate stays free of any apps/core dependency. Core implements it (predict_host.rs) over the ServerState and installs it into the PredictCtx.

Functions§

app_allowed
True when app is permitted by allowlist. An empty allowlist permits every app; otherwise the process name must match an entry (case-insensitive, trimmed). app may be a full path or a bare exe name — we compare on the file name component so C:\\…\\chrome.exe matches chrome.exe.
build_messages
The predictive system prompt + user message for a given caret context. Pure so the exact wording is testable and lives in one place.
clean_suggestion
Clean a raw model reply into an inline suggestion. Strips wrapping quotes / code fences, collapses to a single line, trims, enforces max_chars, and maps the 0 sentinel (and empties) to an empty string = “no suggestion”.
is_secure_control
True when a control type / field descriptor names a password or secure input. Pure + case-insensitive so it is unit-testable without UIA.