AI media harness for planning, generating, and editing locally
TypeScript
Rotate startup logs and update generator icons
Bitti6b6cc9fb603b
diff --git a/src-tauri/src/diagnostics.rs b/src-tauri/src/diagnostics.rsindex 380d51a..98ecfb6 100644--- a/src-tauri/src/diagnostics.rs+++ b/src-tauri/src/diagnostics.rs@@ -1,8 +1,8 @@//! Persistent diagnostics shared by the native runtime and the webview.//!//! One human-readable record is written per line so a damaged final write-//! never makes earlier records unreadable. The active file rotates at 5 MiB-//! and only one previous file is retained. Prompt bodies and credentials are+//! never makes earlier records unreadable. The active file rotates at startup+//! and at 5 MiB, and only one previous file is retained. Prompt bodies and credentials are//! deliberately excluded by callers and redacted again here at the final//! write boundary.@@ -19,7 +19,7 @@ use std::{use tauri::{AppHandle, Manager};const ACTIVE_FILE: &str = "slopus.log";-const PREVIOUS_FILE: &str = "slopus.previous.log";+const PREVIOUS_FILE: &str = "slopus-prev.log";const MAX_BYTES: u64 = 5 * 1024 * 1024;const MAX_TEXT_CHARS: usize = 8 * 1024;@@ -65,18 +65,16 @@ impl LogWriter {})?;let active_path = directory.join(ACTIVE_FILE);let previous_path = directory.join(PREVIOUS_FILE);- let bytes = fs::metadata(&active_path)- .map(|value| value.len())- .unwrap_or(0);- let file = open_append(&active_path)?;- Ok(Self {+ let mut writer = Self {active_path,previous_path,session_id: format!("{}-{}", std::process::id(), timestamp_ms()),max_bytes,- bytes,- file: Some(file),- })+ bytes: 0,+ file: None,+ };+ writer.rotate()?;+ Ok(writer)}fn write(@@ -125,11 +123,12 @@ impl LogWriter {if let Some(mut file) = self.file.take() {let _ = file.flush();}- if self.previous_path.exists() {- fs::remove_file(&self.previous_path)- .map_err(|error| format!("Could not replace previous diagnostic log: {error}"))?;- }if self.active_path.exists() {+ if self.previous_path.exists() {+ fs::remove_file(&self.previous_path).map_err(|error| {+ format!("Could not replace previous diagnostic log: {error}")+ })?;+ }fs::rename(&self.active_path, &self.previous_path).map_err(|error| format!("Could not rotate diagnostic log: {error}"))?;}@@ -436,6 +435,36 @@ mod tests {);}+ #[test]+ fn startup_rotates_the_old_log_and_replaces_the_previous_session() {+ let folder = tempfile::tempdir().unwrap();+ let active = folder.path().join(ACTIVE_FILE);+ let previous = folder.path().join("slopus-prev.log");+ fs::write(&active, "last session").unwrap();+ fs::write(&previous, "older session").unwrap();++ let mut writer = LogWriter::new(folder.path(), MAX_BYTES).unwrap();+ assert_eq!(fs::read_to_string(&previous).unwrap(), "last session");+ assert_eq!(fs::read_to_string(&active).unwrap(), "");+ assert_eq!(writer.bytes, 0);+ assert_eq!(+ writer.info().previous_path,+ Some(previous.to_string_lossy().into_owned())+ );+ writer+ .write("info", "test", "startup", "new session", Value::Null)+ .unwrap();+ drop(writer);++ let current = fs::read_to_string(&active).unwrap();+ assert!(current.contains("new session"));+ assert!(!current.contains("last session"));+ let writer = LogWriter::new(folder.path(), MAX_BYTES).unwrap();+ assert_eq!(fs::read_to_string(&previous).unwrap(), current);+ assert_eq!(fs::read_to_string(&active).unwrap(), "");+ drop(writer);+ }+#[test]fn rotation_keeps_one_previous_file() {let folder = tempfile::tempdir().unwrap();@@ -454,6 +483,6 @@ mod tests {drop(writer);assert!(folder.path().join(ACTIVE_FILE).is_file());assert!(folder.path().join(PREVIOUS_FILE).is_file());- assert!(!folder.path().join("slopus.previous.previous.log").exists());+ assert_eq!(fs::read_dir(folder.path()).unwrap().count(), 2);}}diff --git a/src/components/SettingsView.downloads.test.tsx b/src/components/SettingsView.downloads.test.tsxindex a9ca201..e24100e 100644--- a/src/components/SettingsView.downloads.test.tsx+++ b/src/components/SettingsView.downloads.test.tsx@@ -81,7 +81,7 @@ it("downloads the sample, enables its default choice, and removes only weights tconst radio = () => screen.getByRole("radio", { name: "Use First/Last Frame as the default generator" });expect(within(screen.getByRole("list", { name: "Generators" })).getByText("Default")).toBeInTheDocument();expect(within(screen.getByRole("list", { name: "Download" })).getByText("First/Last Frame")).toBeInTheDocument();- expect(radio()).toBeDisabled();+ expect(within(screen.getByRole("list", { name: "Download" })).queryByRole("radio")).toBeNull();expect(screen.queryByRole("button", { name: "Remove generator First/Last Frame" })).toBeNull();fireEvent.click(screen.getByRole("button", { name: "Download generator First/Last Frame" }));const remove = await screen.findByRole("button", { name: "Remove downloaded weights for First/Last Frame" });@@ -95,7 +95,7 @@ it("downloads the sample, enables its default choice, and removes only weights texpect(await screen.findByRole("button", { name: "Download generator First/Last Frame" })).toBeEnabled();expect(within(screen.getByRole("list", { name: "Download" })).getByText("First/Last Frame")).toBeInTheDocument();expect(within(screen.getByRole("list", { name: "Generators" })).queryByText("First/Last Frame")).toBeNull();- expect(radio()).toBeDisabled();+ expect(within(screen.getByRole("list", { name: "Download" })).queryByRole("radio")).toBeNull();expect(files.size).toBe(0);expect(loadGeneratorTemplateSettings().templates.find((template) => template.id === "minimax-h3-original")?.paths.transformer).toMatch(/^https:/);});diff --git a/src/components/SettingsView.test.tsx b/src/components/SettingsView.test.tsxindex ea2f6f7..830013e 100644--- a/src/components/SettingsView.test.tsx+++ b/src/components/SettingsView.test.tsx@@ -225,8 +225,9 @@ describe("the settings screen", () => {it("creates a generator with 20 steps, edits it on its own page, and can make it the default", () => {open();expect(screen.queryByLabelText(/Transformer weights/)).toBeNull();+ const nextGeneratorName = `Generator ${screen.getAllByRole("listitem").length + 1}`;fireEvent.click(screen.getByRole("button", { name: "New generator" }));- expect((screen.getByLabelText("Generator name") as HTMLInputElement).value).toBe("Generator 3");+ expect((screen.getByLabelText("Generator name") as HTMLInputElement).value).toBe(nextGeneratorName);expect((screen.getByLabelText("Generator default steps") as HTMLInputElement).value).toBe("20");fireEvent.change(screen.getByLabelText("Generator name"), { target: { value: "Fast draft" } });diff --git a/src/components/SettingsView.tsx b/src/components/SettingsView.tsxindex 27c111a..8e77159 100644--- a/src/components/SettingsView.tsx+++ b/src/components/SettingsView.tsx@@ -1,4 +1,4 @@-import { AlertCircle, Check, ChevronLeft, Download, FolderOpen, FolderSearch, LoaderCircle, Monitor, Moon, Plus, RefreshCw, RotateCcw, Sun, Trash2, X } from "lucide-react";+import { AlertCircle, Check, ChevronLeft, Download, FolderOpen, FolderSearch, LoaderCircle, Monitor, Moon, Plus, RefreshCw, RotateCcw, Sun, Trash2, Video, X } from "lucide-react";import { useCallback, useEffect, useRef, useState, useSyncExternalStore, type ReactNode } from "react";import { revealDiagnosticLog } from "../lib/diagnostics";import { isTauri } from "../lib/persistence";@@ -497,7 +497,7 @@ export function SettingsView({ onClose, updates, initialTab = "engine" }: { onCl</header><div className="generator-template-list" role="list" aria-label={section.title}>{section.templates.map((template) => (- <div className={`generator-template-item${template.id === templateSettings.defaultTemplateId ? " generator-template-item--selected" : ""}`} role="listitem" key={template.id}>+ <div className={`generator-template-item${templateNeedsDownload(template) ? " generator-template-item--download" : template.id === templateSettings.defaultTemplateId ? " generator-template-item--selected" : ""}`} role="listitem" key={template.id}>{downloadState?.active && downloadState.templateId === template.id && <spanclassName="generator-template-item__progress"role="progressbar"@@ -508,10 +508,11 @@ export function SettingsView({ onClose, updates, initialTab = "engine" }: { onClaria-valuetext={`${downloadState.completed} of ${downloadState.files} files complete${downloadState.total ? `; current file ${Math.floor(100 * downloadState.downloaded / downloadState.total)}%` : "; downloading"}`}style={{ width: `${downloadPercent}%` }}/>}- <label className="generator-template-item__default" title="Use this generator for generation by default">- <input type="radio" name="default-generator-template" checked={template.id === templateSettings.defaultTemplateId && !templateNeedsDownload(template)} disabled={templateNeedsDownload(template)} onChange={() => makeDefault(template.id)} aria-label={`Use ${template.name} as the default generator`} />- </label>+ {!templateNeedsDownload(template) && <label className="generator-template-item__default" title="Use this generator for generation by default">+ <input type="radio" name="default-generator-template" checked={template.id === templateSettings.defaultTemplateId} onChange={() => makeDefault(template.id)} aria-label={`Use ${template.name} as the default generator`} />+ </label>}<button type="button" className="generator-template-item__open" onClick={() => setEditingTemplateId(template.id)} aria-label={`Edit ${template.name} generator`}>+ <Video size={16} aria-hidden="true" /><b>{template.name}</b><small>{downloadState?.active && downloadState.templateId === template.id ? `Downloading · ${Math.floor(downloadPercent)}%` : `${template.defaultSteps} steps`}</small></button>{templateNeedsDownload(template)diff --git a/src/styles/shell.css b/src/styles/shell.cssindex 21f2ab0..f8aa38e 100644--- a/src/styles/shell.css+++ b/src/styles/shell.css@@ -269,6 +269,10 @@background: var(--field-bg);}+.generator-template-item--download {+ grid-template-columns: minmax(0, 1fr) var(--control-sm);+}+.generator-template-item__progress {position: absolute;inset: 0 auto 0 0;@@ -307,6 +311,12 @@white-space: nowrap;}+.generator-template-item__open > svg {+ flex-shrink: 0;+ align-self: center;+ color: var(--text-muted);+}+.generator-template-item__open small,.generator-template-item > label {color: var(--text-muted);