rightkit_agent_tools/lib.rs
1//! rightkit-agent-tools: one typed tool interface for agents over the Right Suite.
2//!
3//! * [`Tool`] / [`ToolSpec`]: a name, a JSON schema and an effect class.
4//! * [`Toolbox`]: registry plus the one gate every call passes (hard exposure
5//! rules, per-caller allowlist, argument schema, the caller's admission hook,
6//! journal).
7//! * Backends: `<app>.*` over each app's in-app control service
8//! (`rightkit-qa-driver` on `rightkit-daemon`, including the app's own typed
9//! commands), `desktop.*` over `rightkit-automation`, `browser.*` over
10//! `rightkit-browser`, `speech.*` over the shared speech service
11//! (`rightkit-speech-client`, the first client).
12//! * `right-ctl <app> <command>`: the CLI over the same toolbox.
13//!
14//! HeardRight's rules are built in and not configurable: no dictation, text
15//! delivery, pasteboard or history tool can be registered or called ([`exposure`]).
16
17pub mod backends;
18pub mod exposure;
19mod journal;
20mod peer;
21mod spec;
22mod toolbox;
23
24pub use backends::control::{
25 control_tools, AppProfile, CommandPolicy, CLIENT_APP, CONTROL_METHODS,
26};
27pub use journal::JsonlJournal;
28pub use peer::CallContextExt;
29pub use spec::*;
30pub use toolbox::{
31 DeniedBy, Journal, MemoryJournal, Metrics, ToolAdmission, ToolEvent, ToolRequest, Toolbox,
32 Verdict,
33};
34
35use rightkit_daemon::Suite;
36use std::sync::Arc;
37
38/// The caller identity `right-ctl` uses (and the service-side allowlist key).
39pub const CTL_CALLER: &str = CLIENT_APP;
40
41/// A toolbox for the CLI caller: `<app>.*` tools for each named app (built-in
42/// [`AppProfile::for_app`] profile), `speech.*` when HeardRight is among them,
43/// and allowlist patterns granting `right-ctl` exactly what each profile allows.
44pub fn control_toolbox(suite: &Suite, apps: &[&str]) -> Result<Toolbox, ToolError> {
45 let mut tb = Toolbox::new();
46 for app in apps {
47 add_app(&mut tb, suite, AppProfile::for_app(app))?;
48 }
49 Ok(tb)
50}
51
52/// Register one app profile and grant [`CTL_CALLER`] its patterns.
53pub fn add_app(tb: &mut Toolbox, suite: &Suite, profile: AppProfile) -> Result<(), ToolError> {
54 tb.register_all(control_tools(suite, &profile))?;
55 tb.allow(CTL_CALLER, profile.allow_patterns());
56 #[cfg(feature = "speech")]
57 if profile.app == "heardright" {
58 tb.register_all(backends::speech::speech_tools(suite))?;
59 tb.allow(CTL_CALLER, ["speech.transcribe", "speech.capabilities"]);
60 }
61 Ok(())
62}
63
64/// Convenience: share a toolbox.
65pub fn shared(tb: Toolbox) -> Arc<Toolbox> {
66 Arc::new(tb)
67}