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

+34
View File
@@ -180,6 +180,7 @@ async fn serve(cfg: &Config, cli_host: Option<&str>, cli_port: Option<u16>) -> E
// Open the GUI session store (SQLite). The web GUI + session API are mounted
// only when this succeeds; the standard /v1 API is unaffected either way.
let db_path = cfg.gui_db_path();
migrate_legacy_db(&db_path);
let store: Arc<dyn Store> = match SqliteStore::open(&db_path) {
Ok(s) => Arc::new(s),
Err(e) => {
@@ -266,6 +267,39 @@ fn print_plan(cfg: &Config, path: &std::path::Path, cli_host: Option<&str>, cli_
}
}
/// One-time relocation of the session DB from the old default
/// (`~/.config/strata-ctl/sessions.db`) into the framework `data/` dir. Copies
/// (never deletes) the legacy file plus any WAL/SHM siblings, so existing
/// history is preserved. A no-op once the new path exists or no legacy DB is
/// present.
fn migrate_legacy_db(db_path: &Path) {
if db_path.exists() {
return;
}
let home = std::env::var("HOME").unwrap_or_default();
let legacy = Path::new(&home).join(".config/strata-ctl/sessions.db");
if !legacy.exists() || legacy == db_path {
return;
}
if let Some(parent) = db_path.parent() {
let _ = std::fs::create_dir_all(parent);
}
for suffix in ["", "-wal", "-shm"] {
let mut from = legacy.as_os_str().to_os_string();
from.push(suffix);
let mut to = db_path.as_os_str().to_os_string();
to.push(suffix);
if Path::new(&from).exists() {
let _ = std::fs::copy(&from, &to);
}
}
tracing::info!(
from = %legacy.display(),
to = %db_path.display(),
"relocated legacy session database into the framework data dir"
);
}
fn report_config_error(path: &std::path::Path, err: ConfigError) -> ExitCode {
eprintln!("error: {err}");
if let ConfigError::MissingExe = err {