Linux port: first run, packaging, single instance, privacy and wiring
CI / test (push) Has been cancelled
CI / test (push) Has been cancelled
First run and backend - The companion opens without Ollama or a model (OFFLINE / SETUP REQUIRED), opens Settings > Language model and picks the model up once downloaded. - Model, provider and GPU changes apply without restarting (Ollama is restarted when launch settings change); no silent fallback from API mode. - Fatal startup errors are shown in a window; the fallback avatar loads again; the shipped Capri artwork is used when nothing was imported. Packaging and tooling - packaging/arch/PKGBUILD, capri.desktop (KWin ScreenShot2 key), icons, artwork under /usr/share/capri/assets, Gitea Actions CI. - xtask: `icons` and `release-check` (no private data or credentials). Runtime - One instance per data folder (flock + control socket): second launch shows the window; capri stop / restart / toggle / status (JSON, starts nothing) / doctor / setup / diagnostics export / purge. - A foreign program on the Ollama port is refused; an Ollama left behind by Capri is replaced. Privacy and security - No raw Ollama log on disk; API keys are never saved in plaintext (old ones move to the keyring); refused credential notes are stored as [Credentials omitted]; launched apps get an allow-listed environment. Fixes - Stop/Escape silence the voice; saved voice effects apply to replies; settings_control glitch settings apply; distinct KWin cursor scripts; KDE window capture authorized for source builds; Linux wording. - Voice pack references zipped with Windows separators are found. Wired features - Initiatives, request router, resource monitor, "clip that", questions about a snapshot, sleep mode, tap reactions, stopwatch, attachments, Internet mode button, voice-synced subtitles, wake visuals, dictation draft, tray switches, Spotify seek/shuffle/repeat; computer-control planner and classifier follow model switches and API mode. - Approval cards: one shown, 8 queued, deduplicated, cancelled on stop, failure, lock or pause; one Application access switch. Desktop - Compositor detection (no black overlay on i3 without picom), i3lock detection, unsupported desktops reported at startup, screenshot-only control without AT-SPI, fontconfig fallbacks, translatable feature pages with French translations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
73 files changed
+4834
-517
No files matched your search
+279
-18
@@ -14,6 +14,18 @@ use tokio::sync::oneshot;
|
||||
|
||||
pub use crate::dock::AvatarCommand;
|
||||
|
||||
/// What the presence indicator reports about the model backend.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum Backend {
|
||||
/// The model answers.
|
||||
#[default]
|
||||
Ready,
|
||||
/// The local model server does not answer (Ollama missing or stopped).
|
||||
Offline,
|
||||
/// The server answers but no language model is installed (first run).
|
||||
Setup,
|
||||
}
|
||||
|
||||
/// Wake-word feedback.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum Wake {
|
||||
@@ -46,10 +58,47 @@ pub trait Attachments: Send + Sync {
|
||||
/// the model reaction at count 10 belong to the voice/engine side.
|
||||
pub type TapHook = Arc<dyn Fn(&str, &str, u32) + Send + Sync>;
|
||||
|
||||
/// Sleep (`true`) or wake (`false`): the app unloads or reloads the models (spec 10 ORC-06).
|
||||
pub type PowerHook = Arc<dyn Fn(bool) + Send + Sync>;
|
||||
|
||||
/// `isSleepCommand` (spec 10 ORC-06): the whole message asks Capri to go to sleep.
|
||||
pub fn is_sleep_command(text: &str) -> bool {
|
||||
let mut t = text.trim().to_lowercase().replace(['’', '‘'], "'");
|
||||
t = t.trim_end_matches(['.', '!', '?', '…', ' ']).to_string();
|
||||
for prefix in ["hey ", "эй "] {
|
||||
if let Some(rest) = t.strip_prefix(prefix) {
|
||||
t = rest.trim_start().to_string();
|
||||
}
|
||||
}
|
||||
for name in ["capri", "капри"] {
|
||||
if let Some(rest) = t.strip_prefix(name) {
|
||||
t = rest.trim_start_matches([',', ':', '!', ' ']).to_string();
|
||||
}
|
||||
}
|
||||
for polite in ["please ", "пожалуйста, ", "пожалуйста "] {
|
||||
if let Some(rest) = t.strip_prefix(polite) {
|
||||
t = rest.to_string();
|
||||
}
|
||||
}
|
||||
for polite in [", please", " please", ", пожалуйста", " пожалуйста"] {
|
||||
if let Some(rest) = t.strip_suffix(polite) {
|
||||
t = rest.to_string();
|
||||
}
|
||||
}
|
||||
let t = t.trim();
|
||||
const PHRASES: [&str; 18] = [
|
||||
"sleep", "go to sleep", "you can sleep", "you can go to sleep", "time to sleep", "time to go to sleep", "it's time to sleep", "it's time to go to sleep",
|
||||
"it is time to sleep", "it is time to go to sleep", "take a nap", "get some rest", "иди спать", "иди поспи", "ложись спать", "пора спать", "тебе пора спать", "отдыхай",
|
||||
];
|
||||
PHRASES.contains(&t) || ["можешь идти спать", "можешь поспать", "можешь отдохнуть"].contains(&t)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Command {
|
||||
Show,
|
||||
Hide,
|
||||
/// Show when hidden, hide when shown (`capri toggle`, bound to a key by the owner).
|
||||
Toggle,
|
||||
ToggleFocus,
|
||||
Settings(Option<String>),
|
||||
Teleport,
|
||||
@@ -60,17 +109,38 @@ pub enum Command {
|
||||
Notice(String),
|
||||
/// Send this text as an owner message, exactly like the composer (spoken input).
|
||||
Submit(String),
|
||||
/// Recognized speech to review before sending (automatic sending off): fills the composer.
|
||||
Draft(String),
|
||||
/// Sleep (`true`, unload the models) or wake up (`false`).
|
||||
Sleep(bool),
|
||||
/// Tray switches: microphone, spoken replies, internet mode.
|
||||
ToggleMicrophone,
|
||||
ToggleVoice,
|
||||
ToggleInternet,
|
||||
/// Plays a cue preset (`spark`, `pulse`…) or a sound file (`file:<path>`).
|
||||
Sound(String),
|
||||
/// A line Capri says on her own (initiative): shown like a reply, with its expression.
|
||||
Line { text: String, avatar: Option<String> },
|
||||
/// The sentence Capri starts speaking: the reply page follows the voice.
|
||||
Subtitle(String),
|
||||
Quit,
|
||||
}
|
||||
|
||||
/// One approval card. Only the first card of `State::cards` is shown and can be answered;
|
||||
/// the others wait their turn (`MAX_QUEUED`), each with a fresh lifetime when shown.
|
||||
pub(crate) struct Card {
|
||||
pub id: u64,
|
||||
pub request: Approval,
|
||||
/// When the card became the shown one (the danger delay counts from here).
|
||||
pub created: Instant,
|
||||
pub expires: Instant,
|
||||
pub reply: Option<oneshot::Sender<bool>>,
|
||||
/// Every waiting caller: an identical request joins the existing card.
|
||||
pub replies: Vec<oneshot::Sender<bool>>,
|
||||
}
|
||||
|
||||
/// Cards waiting behind the shown one (spec 08 TL-05: one pending + 8 queued).
|
||||
pub const MAX_QUEUED: usize = 8;
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct State {
|
||||
pub mouth: u8,
|
||||
@@ -79,6 +149,7 @@ pub(crate) struct State {
|
||||
pub sleeping: bool,
|
||||
pub wake: Wake,
|
||||
pub wake_at: Option<Instant>,
|
||||
pub backend: Backend,
|
||||
pub stopwatch: Option<(Stopwatch, Instant)>,
|
||||
pub commands: VecDeque<Command>,
|
||||
pub cards: Vec<Card>,
|
||||
@@ -87,11 +158,18 @@ pub(crate) struct State {
|
||||
pub tap_hook: Option<TapHook>,
|
||||
/// Tray checkboxes: (detached, focus mode, always on top).
|
||||
pub tray: (bool, bool, bool),
|
||||
/// Tray switches: (microphone, spoken replies, internet mode); `None` = no voice controls.
|
||||
pub tray_switches: (Option<(bool, bool)>, bool),
|
||||
/// Computer-control indicator: one click-through overlay per monitor while `Some`.
|
||||
pub overlay: Option<ControlOverlay>,
|
||||
/// Set by the shell once every overlay window was drawn.
|
||||
pub overlay_drawn: bool,
|
||||
pub stop_hook: Option<Arc<dyn Fn() + Send + Sync>>,
|
||||
pub power: Option<PowerHook>,
|
||||
/// Compact resource line under the header (`RAM 42% · CPU 12% · GPU 3.1/8 GB`).
|
||||
pub resources: Option<String>,
|
||||
/// Silences Capri's voice (Stop button, Escape).
|
||||
pub stop_speech: Option<Arc<dyn Fn() + Send + Sync>>,
|
||||
/// Microphone and spoken-reply switches (header buttons).
|
||||
pub audio: Option<AudioControls>,
|
||||
/// Real pointer (desktop pixels) and its recent positions for the overlay reticle.
|
||||
@@ -199,10 +277,50 @@ impl UiHandle {
|
||||
}
|
||||
|
||||
/// Sleep visuals: closed eyes, `Zzz` caption, silent taps.
|
||||
pub fn set_resource_line(&self, line: Option<String>) {
|
||||
if self.0.state.lock().resources != line {
|
||||
self.with(|s| s.resources = line);
|
||||
}
|
||||
}
|
||||
|
||||
/// Capri's voice is playing (read by the initiative gates).
|
||||
pub fn speaking(&self) -> bool {
|
||||
self.0.state.lock().speaking
|
||||
}
|
||||
|
||||
pub fn sleeping(&self) -> bool {
|
||||
self.0.state.lock().sleeping
|
||||
}
|
||||
|
||||
pub fn set_sleeping(&self, sleeping: bool) {
|
||||
self.with(|s| s.sleeping = sleeping);
|
||||
}
|
||||
|
||||
pub fn on_power(&self, hook: PowerHook) {
|
||||
self.with(|s| s.power = Some(hook));
|
||||
}
|
||||
|
||||
/// Puts Capri to sleep or wakes her: shown at once, models unloaded/reloaded by the app.
|
||||
pub fn request_sleep(&self, sleep: bool) {
|
||||
let hook = {
|
||||
let mut s = self.0.state.lock();
|
||||
if s.sleeping == sleep {
|
||||
return;
|
||||
}
|
||||
s.sleeping = sleep;
|
||||
s.power.clone()
|
||||
};
|
||||
if sleep {
|
||||
self.cancel_approvals();
|
||||
}
|
||||
if let Some(hook) = hook {
|
||||
hook(sleep);
|
||||
}
|
||||
if let Some(ctx) = self.0.ctx.get() {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_wake(&self, wake: Wake) {
|
||||
self.with(|s| {
|
||||
s.wake = wake;
|
||||
@@ -222,6 +340,11 @@ impl UiHandle {
|
||||
self.with(|s| s.tap_hook = Some(hook));
|
||||
}
|
||||
|
||||
/// Backend state shown by the presence indicator (`OFFLINE`, `SETUP REQUIRED`).
|
||||
pub fn set_backend(&self, backend: Backend) {
|
||||
self.with(|s| s.backend = backend);
|
||||
}
|
||||
|
||||
/// Error notice in the companion.
|
||||
pub fn notice(&self, text: impl Into<String>) {
|
||||
self.command(Command::Notice(text.into()));
|
||||
@@ -275,6 +398,18 @@ impl UiHandle {
|
||||
}
|
||||
|
||||
/// Called by the "Stop computer control" button.
|
||||
pub fn on_stop_speech(&self, hook: Arc<dyn Fn() + Send + Sync>) {
|
||||
self.with(|s| s.stop_speech = Some(hook));
|
||||
}
|
||||
|
||||
/// Silences the voice now (no effect when nothing is spoken).
|
||||
pub(crate) fn stop_speech(&self) {
|
||||
let hook = self.0.state.lock().stop_speech.clone();
|
||||
if let Some(stop) = hook {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_stop_control(&self, hook: Arc<dyn Fn() + Send + Sync>) {
|
||||
self.with(|s| s.stop_hook = Some(hook));
|
||||
}
|
||||
@@ -287,38 +422,115 @@ impl UiHandle {
|
||||
self.0.state.lock().commands.drain(..).collect()
|
||||
}
|
||||
|
||||
/// Answers a card from the UI.
|
||||
/// Answers the shown card from the UI.
|
||||
pub(crate) fn answer(&self, id: u64, accepted: bool) {
|
||||
self.with(|s| {
|
||||
if let Some(i) = s.cards.iter().position(|c| c.id == id) {
|
||||
// The danger delay is enforced here, not only by a disabled button.
|
||||
if accepted && s.cards[i].request.kind == DANGER_KIND && s.cards[i].created.elapsed() < DANGER_DELAY {
|
||||
return;
|
||||
}
|
||||
let mut card = s.cards.remove(i);
|
||||
if let Some(reply) = card.reply.take() {
|
||||
let _ = reply.send(accepted && Instant::now() < card.expires);
|
||||
let Some(card) = s.cards.first() else { return };
|
||||
if card.id != id {
|
||||
return;
|
||||
}
|
||||
// The danger delay is enforced here, not only by a disabled button.
|
||||
if accepted && card.request.kind == DANGER_KIND && card.created.elapsed() < DANGER_DELAY {
|
||||
return;
|
||||
}
|
||||
let card = s.cards.remove(0);
|
||||
let accepted = accepted && Instant::now() < card.expires;
|
||||
for reply in card.replies {
|
||||
let _ = reply.send(accepted);
|
||||
}
|
||||
Self::promote(s);
|
||||
});
|
||||
}
|
||||
|
||||
/// Refuses every shown and queued card: Stop, Escape, a cancelled or failed turn, screen
|
||||
/// lock, Application access paused, quit (spec 08 TL-05 `cancel()` triggers).
|
||||
pub fn cancel_approvals(&self) {
|
||||
self.with(|s| {
|
||||
for card in s.cards.drain(..) {
|
||||
for reply in card.replies {
|
||||
let _ = reply.send(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// The next queued card becomes the shown one with its own full lifetime.
|
||||
fn promote(s: &mut State) {
|
||||
if let Some(next) = s.cards.first_mut() {
|
||||
next.created = Instant::now();
|
||||
next.expires = next.created + next.request.timeout;
|
||||
}
|
||||
}
|
||||
|
||||
/// Refuses the shown card once its time is over.
|
||||
fn expire(&self) {
|
||||
self.with(|s| {
|
||||
if s.cards.first().is_some_and(|c| Instant::now() >= c.expires) {
|
||||
for reply in s.cards.remove(0).replies {
|
||||
let _ = reply.send(false);
|
||||
}
|
||||
Self::promote(s);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Drops cards whose callers all went away (their turn was cancelled).
|
||||
fn forget_abandoned(&self) {
|
||||
self.with(|s| {
|
||||
let first = s.cards.first().map(|c| c.id);
|
||||
for card in &mut s.cards {
|
||||
card.replies.retain(|r| !r.is_closed());
|
||||
}
|
||||
s.cards.retain(|c| !c.replies.is_empty());
|
||||
if s.cards.first().map(|c| c.id) != first {
|
||||
Self::promote(s);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes the caller's card when `confirm` is dropped before an answer (cancelled turn).
|
||||
struct Abandon(UiHandle);
|
||||
|
||||
impl Drop for Abandon {
|
||||
fn drop(&mut self) {
|
||||
self.0.forget_abandoned();
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Approvals for UiHandle {
|
||||
/// Shows an exact, temporary card; anything but an explicit accept before expiry is a refusal.
|
||||
async fn confirm(&self, request: Approval) -> bool {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let timeout = request.timeout;
|
||||
let mut id = 0;
|
||||
// Declared first so it drops last, after the receiver: the sender then reads as closed.
|
||||
let _abandon = Abandon(self.clone());
|
||||
let (tx, mut rx) = oneshot::channel();
|
||||
let mut queued = true;
|
||||
self.with(|s| {
|
||||
let same = |c: &Card| c.request.kind == request.kind && c.request.title == request.title && c.request.detail == request.detail;
|
||||
if let Some(card) = s.cards.iter_mut().find(|c| same(c)) {
|
||||
card.replies.push(tx);
|
||||
return;
|
||||
}
|
||||
if s.cards.len() > MAX_QUEUED {
|
||||
queued = false; // "Too many pending permission requests."
|
||||
return;
|
||||
}
|
||||
s.next_id += 1;
|
||||
id = s.next_id;
|
||||
s.cards.push(Card { id, request, created: Instant::now(), expires: Instant::now() + timeout, reply: Some(tx) });
|
||||
let now = Instant::now();
|
||||
// A queued card gets its lifetime when it is shown (see `promote`).
|
||||
let expires = if s.cards.is_empty() { now + request.timeout } else { now + Duration::from_secs(86_400) };
|
||||
s.cards.push(Card { id: s.next_id, request, created: now, expires, replies: vec![tx] });
|
||||
});
|
||||
let accepted = matches!(tokio::time::timeout(timeout, rx).await, Ok(Ok(true)));
|
||||
self.with(|s| s.cards.retain(|c| c.id != id));
|
||||
accepted
|
||||
if !queued {
|
||||
return false;
|
||||
}
|
||||
loop {
|
||||
match tokio::time::timeout(Duration::from_millis(200), &mut rx).await {
|
||||
Ok(answer) => return answer.unwrap_or(false),
|
||||
Err(_) => self.expire(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,4 +569,53 @@ mod tests {
|
||||
ui.set_mouth_level(9);
|
||||
assert_eq!(ui.0.state.lock().mouth, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sleep_commands() {
|
||||
for yes in ["sleep", "Go to sleep.", "Hey Capri, take a nap please", "capri: you can go to sleep!", "It’s time to sleep", "Капри, иди спать", "пожалуйста, отдыхай"] {
|
||||
assert!(is_sleep_command(yes), "{yes}");
|
||||
}
|
||||
for no in ["sleep well tonight", "I want to sleep", "how do I sleep better?", "remind me to sleep at 11"] {
|
||||
assert!(!is_sleep_command(no), "{no}");
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn approval_queue_dedupe_cap_and_cancel() {
|
||||
let ui = UiHandle::new();
|
||||
let ask = |a: Approval| { let ui = ui.clone(); tokio::spawn(async move { ui.confirm(a).await }) };
|
||||
let count = |ui: &UiHandle| ui.0.state.lock().cards.len();
|
||||
let first = ask(approval(5000));
|
||||
let same = ask(approval(5000));
|
||||
while count(&ui) == 0 || ui.0.state.lock().cards[0].replies.len() < 2 {
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
assert_eq!(count(&ui), 1, "an identical request joins the shown card");
|
||||
let queued: Vec<_> = (0..MAX_QUEUED).map(|i| ask(Approval { detail: format!("/tmp/{i}"), ..approval(5000) })).collect();
|
||||
while count(&ui) < 1 + MAX_QUEUED {
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
assert!(!ui.confirm(Approval { detail: "/tmp/one-too-many".into(), ..approval(5000) }).await, "the queue is full");
|
||||
// Only the shown card can be answered; both callers get the answer.
|
||||
let second = ui.0.state.lock().cards[1].id;
|
||||
ui.answer(second, true);
|
||||
assert_eq!(count(&ui), 1 + MAX_QUEUED);
|
||||
let shown = ui.0.state.lock().cards[0].id;
|
||||
ui.answer(shown, true);
|
||||
assert!(first.await.unwrap() && same.await.unwrap());
|
||||
// Stop refuses everything left.
|
||||
ui.cancel_approvals();
|
||||
for waiter in queued {
|
||||
assert!(!waiter.await.unwrap());
|
||||
}
|
||||
assert_eq!(count(&ui), 0);
|
||||
// A caller that goes away (cancelled turn) leaves no card behind.
|
||||
let gone = ask(approval(5000));
|
||||
while count(&ui) == 0 {
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
gone.abort();
|
||||
let _ = gone.await;
|
||||
assert_eq!(count(&ui), 0);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user