feat: file/image upload + separated framework root (sessions/data/uploads)

- POST /api/uploads: base64 -> shared ~/.strata-ctl/uploads store (uuid+ext),
  content-sniffed kind (image/text/binary), text token-counted via the model
  tokenizer; metadata persisted in a new uploads table.
- Chat attachments routed by kind: images -> Vision bridge (multipart image_url),
  small text (<=2000 tokens) inlined, large text/binary -> path + shell_exec
  reminder; binaries never inlined. Attachment context persisted with the turn.
- GUI: attach button + file picker, removable chips, attachments sent with the
  turn and shown on the user bubble; cleared on session switch.
- Framework root ~/.strata-ctl separated by type: sessions/<name>/, data/ (SQLite,
  moved from ~/.config/strata-ctl), uploads/. Legacy DB copied once on first run.
- count_tokens seam on Formatter (real tokenizer override) + ChatService.
- i18n: upload errors + attachment markers (backend) and attach.* (GUI), it+en.
- 121 tests + 2 ignored; clippy/fmt clean; validated live (upload routing, real
  tokenizer count, image->Vision answered "Rosso", new layout).
This commit is contained in:
adm committed 2026-11-25 16:25:55 +01:00
1 parent 498e3dbc1b
commit 65f8111ba2
19 files changed
+672 -47

No files matched your search

+37 -10
View File
@@ -84,7 +84,9 @@ pub struct Config {
#[serde(default)]
pub system_prompt: Option<String>,
/// Parent of the per-session personal workspace folders (default `~/.strata-ctl`).
/// Framework root (default `~/.strata-ctl`, the Linux user's home). Content
/// is separated into subfolders by type: `sessions/` (agent workspace
/// folders), `data/` (SQLite), `uploads/` (uploaded files).
#[serde(default)]
pub workspace_root: Option<String>,
@@ -109,7 +111,7 @@ pub struct Config {
pub allowed_hosts: Option<Vec<String>>,
/// Path to the GUI session database (SQLite). Defaults to
/// `~/.config/strata-ctl/sessions.db`.
/// `<framework_root>/data/sessions.db`.
#[serde(default)]
pub db_path: Option<String>,
@@ -209,13 +211,12 @@ impl Config {
Duration::from_secs(self.silence_timeout_secs.unwrap_or(600))
}
/// Effective GUI database path: config > `~/.config/strata-ctl/sessions.db`.
/// Effective GUI database path: config > `<framework_root>/data/sessions.db`.
pub fn gui_db_path(&self) -> PathBuf {
if let Some(p) = &self.db_path {
return PathBuf::from(p);
}
let home = std::env::var("HOME").unwrap_or_default();
PathBuf::from(home).join(".config/strata-ctl/sessions.db")
self.data_dir().join("sessions.db")
}
/// The global default settings template for new GUI sessions, seeded from
@@ -232,8 +233,8 @@ impl Config {
}
}
/// Effective workspace root: config > `~/.strata-ctl`. Each session's
/// personal folder is created under this root at its first interaction.
/// Effective framework root: config > `~/.strata-ctl` (the Linux user's
/// home). Content is separated into subfolders by type.
pub fn workspace_root(&self) -> PathBuf {
if let Some(p) = &self.workspace_root {
return PathBuf::from(p);
@@ -242,6 +243,21 @@ impl Config {
PathBuf::from(home).join(".strata-ctl")
}
/// Per-session personal workspace folders: `<root>/sessions/<slug>`.
pub fn sessions_dir(&self) -> PathBuf {
self.workspace_root().join("sessions")
}
/// SQLite store directory: `<root>/data`.
pub fn data_dir(&self) -> PathBuf {
self.workspace_root().join("data")
}
/// Shared upload store: `<root>/uploads`.
pub fn upload_dir(&self) -> PathBuf {
self.workspace_root().join("uploads")
}
/// Effective language: config > `it`.
pub fn language(&self) -> String {
self.language.clone().unwrap_or_else(|| "it".to_string())
@@ -396,10 +412,21 @@ mod tests {
#[test]
fn gui_db_path_default_and_override() {
let cfg = Config::parse(REAL, "test").unwrap();
assert!(cfg
.gui_db_path()
.ends_with(".config/strata-ctl/sessions.db"));
assert!(cfg.gui_db_path().ends_with(".strata-ctl/data/sessions.db"));
let cfg2 = Config::parse(r#"{"exe":"/x/e","db_path":"/tmp/x.db"}"#, "test").unwrap();
assert_eq!(cfg2.gui_db_path(), PathBuf::from("/tmp/x.db"));
}
#[test]
fn framework_root_separates_content_types() {
let cfg = Config::parse(r#"{"exe":"/x/e","workspace_root":"/tmp/fwk"}"#, "test").unwrap();
assert_eq!(cfg.workspace_root(), PathBuf::from("/tmp/fwk"));
assert_eq!(cfg.sessions_dir(), PathBuf::from("/tmp/fwk/sessions"));
assert_eq!(cfg.data_dir(), PathBuf::from("/tmp/fwk/data"));
assert_eq!(cfg.upload_dir(), PathBuf::from("/tmp/fwk/uploads"));
assert_eq!(
cfg.gui_db_path(),
PathBuf::from("/tmp/fwk/data/sessions.db")
);
}
}