Files
capri-core-rust/crates/capri/src/diagnostics.rs
T
nocodeandClaude Opus 5.5 49349d6ecd
CI / test (push) Has been cancelled
Linux port: first run, packaging, single instance, privacy and wiring
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>
2026-11-12 20:21:40 +01:00

89 lines
4.4 KiB
Rust

//! `capri diagnostics export`: a ZIP to attach to a bug report (spec 09 RT-34/38). It holds only
//! allow-listed facts — versions, desktop, hardware, the doctor checks and a settings summary —
//! never conversations, memory, personality, file paths of documents, keys or screenshots.
use std::io::Write;
use std::path::{Path, PathBuf};
use anyhow::{Context, Result};
use capri_core::{Paths, Settings};
use serde_json::{json, Value};
/// Settings that help debugging and say nothing about the owner.
fn settings_summary(settings: &Settings) -> Value {
let inference: capri_llm::sections::InferenceSection = settings.section();
let api: capri_llm::sections::ApiSection = settings.section();
let router: capri_llm::sections::RouterSection = settings.section();
json!({
"model": settings.model,
"upstreamModel": settings.upstream_model,
"contextTokens": settings.context_tokens,
"keepAlive": settings.keep_alive,
"acceleration": settings.acceleration,
"device": inference.device,
"externalOllama": settings.ollama_url.is_some(),
"apiMode": api.enabled,
"apiConnections": api.connections.len(),
"requestRouter": router.enabled,
"language": {"interface": settings.language.interface, "conversation": settings.language.conversation},
})
}
fn system() -> Value {
let read = |p: &str| std::fs::read_to_string(p).ok().map(|s| s.trim().to_string());
let os = read("/etc/os-release").and_then(|t| t.lines().find_map(|l| l.strip_prefix("PRETTY_NAME=").map(|v| v.trim_matches('"').to_string())));
let var = |k: &str| std::env::var(k).ok();
json!({
"capri": env!("CARGO_PKG_VERSION"),
"os": os,
"kernel": read("/proc/sys/kernel/osrelease"),
"sessionType": var("XDG_SESSION_TYPE"),
"desktop": var("XDG_CURRENT_DESKTOP"),
"wayland": var("WAYLAND_DISPLAY").is_some(),
"x11": var("DISPLAY").is_some(),
})
}
/// Default report location: `~/capri-diagnostics-<UTC time>.zip`.
pub fn default_output() -> PathBuf {
let name = format!("capri-diagnostics-{}.zip", chrono::Utc::now().format("%Y%m%d-%H%M%S"));
std::env::var_os("HOME").map_or_else(|| PathBuf::from(&name), |h| PathBuf::from(h).join(&name))
}
pub async fn export(paths: &Paths, settings: &Settings, output: &Path) -> Result<()> {
let checks = crate::doctor::checks(paths, settings).await;
let running = crate::instance::running(paths);
let status = if running { crate::instance::request(paths, "status").await.ok() } else { None };
// The running companion's status, reduced to non-private fields.
let companion = status.map(|s| json!({"core": s["core"], "busy": s["busy"], "backend": s["backend"].as_str().map(|b| b.split(" · ").next().unwrap_or_default().to_string()), "naturalVoice": s["naturalVoice"]}));
let files: [(&str, Value); 4] = [
("system.json", system()),
("doctor.json", crate::doctor::to_json(&checks)),
("settings-summary.json", settings_summary(settings)),
("session.json", json!({"desktop": if running { "running" } else { "stopped" }, "companion": companion})),
];
let file = std::fs::OpenOptions::new().write(true).create_new(true).open(output).with_context(|| format!("cannot create {}", output.display()))?;
let mut zip = zip::ZipWriter::new(file);
let options = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated).unix_permissions(0o600);
for (name, value) in files {
zip.start_file(name, options)?;
zip.write_all(serde_json::to_string_pretty(&value)?.as_bytes())?;
}
zip.start_file("README.txt", options)?;
zip.write_all(b"Capri diagnostics: versions, desktop, hardware, setup checks and a settings summary.\nNo conversations, memory, personality, keys, screenshots or logs are included.\n")?;
zip.finish()?;
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn summary_has_no_private_values() {
let mut settings = Settings::default();
settings.set_section(&capri_llm::sections::ApiSection { enabled: true, active: Some("c".into()), connections: vec![capri_llm::openai::ApiConnection { id: "c".into(), base_url: "https://secret.example/v1".into(), model: "m".into(), ..Default::default() }] });
let text = settings_summary(&settings).to_string();
assert!(!text.contains("secret.example") && text.contains("\"apiConnections\":1"));
}
}