fix(kon): harden core crate — shared System instance, accurate CPU field, serialisable errors

- Share single System::new_all() in probe_system() instead of calling it twice
- Rename CpuInfo::core_count to logical_processors (sys.cpus().len() returns logical, not physical)
- Add fallback arm to probe_os() for unsupported cfg targets
- Add serde::Serialize to KonError for structured frontend error reporting
- Annotate dead code (ProviderRegistry, TranscriptMetadata) with #[allow(dead_code)] + TODO comments
- Update downstream references in recommendation tests and tauri hardware command

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
jake
2026-03-17 00:19:04 +00:00
parent 4fa20255ae
commit 95c8d490c3
6 changed files with 60 additions and 49 deletions

View File

@@ -1,8 +1,14 @@
use std::path::PathBuf;
use serde::Serialize;
use crate::types::ModelId;
#[derive(Debug, thiserror::Error)]
/// Structured error type for Kon.
///
/// Implements `Serialize` so errors can be sent to the frontend as
/// structured JSON rather than opaque strings.
#[derive(Debug, thiserror::Error, Serialize)]
pub enum KonError {
#[error("model not found: {0}")]
ModelNotFound(ModelId),
@@ -32,10 +38,23 @@ pub enum KonError {
StorageError(String),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
Io(
#[from]
#[serde(serialize_with = "serialize_io_error")]
std::io::Error,
),
#[error("{0}")]
Other(String),
}
/// Serialises `std::io::Error` as its display string, since it does
/// not implement `Serialize` natively.
fn serialize_io_error<S: serde::Serializer>(
err: &std::io::Error,
s: S,
) -> std::result::Result<S::Ok, S::Error> {
s.serialize_str(&err.to_string())
}
pub type Result<T> = std::result::Result<T, KonError>;