feat: TOML-Config und Datenordner anlegen

config.toml im App-Konfigurationsordner, Standard wird beim ersten Start
angelegt. Datenordner und Aufgabenordner werden aufgelöst und im Setup
angezeigt. Standard-Startseite ersetzt durch Pfad-Ansicht.
cargo test: 6 Tests grün. Klicktests start2app.1-.2 noch manuell offen.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-06 18:49:29 +01:00
parent 57fbc57a54
commit 3bd5197867
6 changed files with 233 additions and 143 deletions

View File

@ -18,7 +18,7 @@ Zeichen: ✓ fertig · ◐ teilweise · ✗ offen · ? nicht geprüft.
| ID | Anforderung | Quelle | Stand | Anmerkung | | ID | Anforderung | Quelle | Stand | Anmerkung |
| --- | --- | --- | --- | --- | | --- | --- | --- | --- | --- |
| #1001 | F-01 Tauri-Grundgerüst, Datenordner, Config | SPEC 12 | ◐ | Gerüst steht: `npm run build` und `cargo check` grün, App nicht gestartet. Datenordner und TOML-Config fehlen (→ #1018) | | #1001 | F-01 Tauri-Grundgerüst, Datenordner, Config | SPEC 12 | ◐ | Umgesetzt: Gerüst, TOML-Config mit Standardanlage, Datenordner, Setup zeigt Pfade. `cargo test` 6/6, `npm run build` grün. Klicktests `start2app.1–.2` manuell noch nicht ✓ (→ #1018) |
| #1002 | F-02 Aufgaben laden und validieren | SPEC 4, 12 | ✗ | noch nicht begonnen (→ #1019) | | #1002 | F-02 Aufgaben laden und validieren | SPEC 4, 12 | ✗ | noch nicht begonnen (→ #1019) |
| #1003 | F-03 Agent-Loop gegen Ollama mit Tools und Fehlerklassen | SPEC 5, 12 | ✗ | noch nicht begonnen (→ #1021) | | #1003 | F-03 Agent-Loop gegen Ollama mit Tools und Fehlerklassen | SPEC 5, 12 | ✗ | noch nicht begonnen (→ #1021) |
| #1004 | F-04 Docker-Sandbox pro Lauf | SPEC 6, 12 | ✗ | noch nicht begonnen (→ #1020) | | #1004 | F-04 Docker-Sandbox pro Lauf | SPEC 6, 12 | ✗ | noch nicht begonnen (→ #1020) |
@ -44,7 +44,7 @@ Zeichen: ✓ fertig · ◐ teilweise · ✗ offen · ? nicht geprüft.
## 4. Todo (nach Priorität, Stand 2026-11-06) ## 4. Todo (nach Priorität, Stand 2026-11-06)
**P1 – als Nächstes (Release 0.1.0, Phase 1 Kern)** **P1 – als Nächstes (Release 0.1.0, Phase 1 Kern)**
- [#1018] **Gerüst anlegen.** Tauri 2 mit Svelte und TypeScript, Rust-Backend, Datenordner, TOML-Config. Gerüst steht auf Branch `release/0.1.0` (`create-tauri-app`, svelte-ts). Offen: Datenordner und TOML-Config. Tests `start2app.1–.2`. → #1001 - [#1018] **Gerüst anlegen.** Tauri 2 mit Svelte und TypeScript, Rust-Backend, Datenordner, TOML-Config. Gerüst (`create-tauri-app`, svelte-ts) und Config-/Datenordner-Logik (`src-tauri/src/config.rs`) sind gebaut; `cargo test` 6/6 grün. Offen: die Klicktests `start2app.1–.2` vom Menschen manuell ausführen lassen. Erst dann gilt #1018 als fertig. Tests `start2app.1–.2`. → #1001
- [#1019] **Aufgaben laden und validieren.** Ordner `tasks/<gruppe>/<name>/`, Pflichtdateien, TOML, ausführbares `check.sh`, Fehler in der GUI. Tests `aufgabe2validierung.1–.2`. → #1002 - [#1019] **Aufgaben laden und validieren.** Ordner `tasks/<gruppe>/<name>/`, Pflichtdateien, TOML, ausführbares `check.sh`, Fehler in der GUI. Tests `aufgabe2validierung.1–.2`. → #1002
- [#1020] **Docker-Sandbox pro Lauf.** Frischer Container, `--network none`, Speicher-/CPU-Limit, `/work` als Artefakt, Container entfernen. Tests `lauf2sandbox.1–.2`. → #1004 - [#1020] **Docker-Sandbox pro Lauf.** Frischer Container, `--network none`, Speicher-/CPU-Limit, `/work` als Artefakt, Container entfernen. Tests `lauf2sandbox.1–.2`. → #1004
- [#1021] **Agent-Loop gegen Ollama.** Tools `read_file`, `write_file`, `list_dir`, `run_shell`, `done`; Pfade auf `/work`; Fehlerklassen und Metriken. Tests `lauf2ergebnis.1–.3`. → #1003 - [#1021] **Agent-Loop gegen Ollama.** Tools `read_file`, `write_file`, `list_dir`, `run_shell`, `done`; Pfade auf `/work`; Fehlerklassen und Metriken. Tests `lauf2ergebnis.1–.3`. → #1003

1
src-tauri/Cargo.lock generated
View File

@ -475,6 +475,7 @@ dependencies = [
"tauri", "tauri",
"tauri-build", "tauri-build",
"tauri-plugin-opener", "tauri-plugin-opener",
"toml 0.8.2",
] ]
[[package]] [[package]]

View File

@ -22,6 +22,7 @@ tauri = { version = "2", features = [] }
tauri-plugin-opener = "2" tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
toml = "0.8"
# Read the optimization guideline for more details: https://tauri.app/concept/size/#cargo-configuration # Read the optimization guideline for more details: https://tauri.app/concept/size/#cargo-configuration

138
src-tauri/src/config.rs Normal file
View File

@ -0,0 +1,138 @@
//! Konfiguration (TOML) und Datenordner (F-01).
//!
//! Die Datei `config.toml` liegt im App-Konfigurationsordner. Fehlt sie, wird sie
//! mit Standardwerten angelegt. Pfade in der Datei sind optional; ohne Angabe
//! gilt der Standardordner der App bzw. `<datenordner>/tasks`.
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::{Path, PathBuf};
pub const CONFIG_FILE_NAME: &str = "config.toml";
/// Rohe Konfiguration, so wie sie in der Datei steht.
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct Config {
/// Datenordner (Ergebnisse, Artefakte, Datenbank). Leer = Standard der App.
pub data_dir: Option<PathBuf>,
/// Aufgabenordner. Leer = `<datenordner>/tasks`.
pub tasks_dir: Option<PathBuf>,
}
/// Aufgelöste Pfade, die die App tatsächlich verwendet.
#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct Paths {
pub config_file: PathBuf,
pub data_dir: PathBuf,
pub tasks_dir: PathBuf,
}
impl Config {
/// Liest die Konfiguration aus einem TOML-Text.
pub fn parse(text: &str) -> Result<Config, String> {
toml::from_str(text).map_err(|e| format!("config.toml ist ungültig: {e}"))
}
/// Löst die Pfade auf. `default_data_dir` ist der Standardordner der App.
pub fn resolve(&self, config_file: &Path, default_data_dir: &Path) -> Paths {
let data_dir = self
.data_dir
.clone()
.unwrap_or_else(|| default_data_dir.to_path_buf());
let tasks_dir = self
.tasks_dir
.clone()
.unwrap_or_else(|| data_dir.join("tasks"));
Paths {
config_file: config_file.to_path_buf(),
data_dir,
tasks_dir,
}
}
}
/// Lädt die Konfiguration aus `config_dir/config.toml`, legt die Datei bei Bedarf
/// mit Standardwerten an und stellt sicher, dass der Datenordner existiert.
pub fn load_or_create(config_dir: &Path, default_data_dir: &Path) -> Result<Paths, String> {
fs::create_dir_all(config_dir)
.map_err(|e| format!("Konfigurationsordner {} nicht anlegbar: {e}", config_dir.display()))?;
let config_file = config_dir.join(CONFIG_FILE_NAME);
let config = if config_file.exists() {
let text = fs::read_to_string(&config_file)
.map_err(|e| format!("{} nicht lesbar: {e}", config_file.display()))?;
Config::parse(&text)?
} else {
let defaults = Config::default();
let text = toml::to_string_pretty(&defaults)
.map_err(|e| format!("Standard-Config nicht serialisierbar: {e}"))?;
fs::write(&config_file, format!("# coding-bench Konfiguration\n{text}"))
.map_err(|e| format!("{} nicht schreibbar: {e}", config_file.display()))?;
defaults
};
let paths = config.resolve(&config_file, default_data_dir);
fs::create_dir_all(&paths.data_dir)
.map_err(|e| format!("Datenordner {} nicht anlegbar: {e}", paths.data_dir.display()))?;
Ok(paths)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn leere_datei_ergibt_standardwerte() {
let c = Config::parse("").unwrap();
assert_eq!(c, Config::default());
}
#[test]
fn pfade_werden_gelesen() {
let c = Config::parse("data_dir = \"/x/daten\"\ntasks_dir = \"/x/aufgaben\"\n").unwrap();
assert_eq!(c.data_dir, Some(PathBuf::from("/x/daten")));
assert_eq!(c.tasks_dir, Some(PathBuf::from("/x/aufgaben")));
}
#[test]
fn unbekannter_schluessel_ist_fehler() {
assert!(Config::parse("unbekannt = 1\n").is_err());
}
#[test]
fn tasks_standard_liegt_im_datenordner() {
let p = Config::default().resolve(Path::new("/c/config.toml"), Path::new("/d"));
assert_eq!(p.data_dir, PathBuf::from("/d"));
assert_eq!(p.tasks_dir, PathBuf::from("/d/tasks"));
}
#[test]
fn angegebener_datenordner_gilt_auch_fuer_tasks() {
let c = Config::parse("data_dir = \"/x\"\n").unwrap();
let p = c.resolve(Path::new("/c/config.toml"), Path::new("/d"));
assert_eq!(p.data_dir, PathBuf::from("/x"));
assert_eq!(p.tasks_dir, PathBuf::from("/x/tasks"));
}
#[test]
fn load_or_create_legt_datei_und_ordner_an() {
let base = std::env::temp_dir().join(format!("cb-config-test-{}", std::process::id()));
let _ = fs::remove_dir_all(&base);
let cfg_dir = base.join("cfg");
let data_dir = base.join("data");
let paths = load_or_create(&cfg_dir, &data_dir).unwrap();
assert!(cfg_dir.join(CONFIG_FILE_NAME).exists());
assert!(data_dir.is_dir());
assert_eq!(paths.tasks_dir, data_dir.join("tasks"));
// Zweiter Aufruf liest die vorhandene Datei, ohne sie zu verändern.
let before = fs::read_to_string(cfg_dir.join(CONFIG_FILE_NAME)).unwrap();
load_or_create(&cfg_dir, &data_dir).unwrap();
let after = fs::read_to_string(cfg_dir.join(CONFIG_FILE_NAME)).unwrap();
assert_eq!(before, after);
let _ = fs::remove_dir_all(&base);
}
}

View File

@ -1,14 +1,34 @@
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ mod config;
use config::Paths;
use tauri::{Manager, State};
/// Aufgelöste Pfade, einmal beim Start ermittelt.
pub struct AppPaths(pub Paths);
#[tauri::command] #[tauri::command]
fn greet(name: &str) -> String { fn get_paths(paths: State<'_, AppPaths>) -> Paths {
format!("Hello, {}! You've been greeted from Rust!", name) paths.0.clone()
} }
#[cfg_attr(mobile, tauri::mobile_entry_point)] #[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() { pub fn run() {
tauri::Builder::default() tauri::Builder::default()
.plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![greet]) .setup(|app| {
let config_dir = app
.path()
.app_config_dir()
.map_err(|e| format!("Konfigurationsordner nicht ermittelbar: {e}"))?;
let default_data_dir = app
.path()
.app_data_dir()
.map_err(|e| format!("Datenordner nicht ermittelbar: {e}"))?;
let paths = config::load_or_create(&config_dir, &default_data_dir)?;
app.manage(AppPaths(paths));
Ok(())
})
.invoke_handler(tauri::generate_handler![get_paths])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
} }

View File

@ -1,156 +1,86 @@
<script lang="ts"> <script lang="ts">
import { onMount } from "svelte";
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
let name = $state(""); type Paths = {
let greetMsg = $state(""); config_file: string;
data_dir: string;
tasks_dir: string;
};
async function greet(event: Event) { let paths = $state<Paths | null>(null);
event.preventDefault(); let error = $state("");
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
greetMsg = await invoke("greet", { name }); onMount(async () => {
try {
paths = await invoke<Paths>("get_paths");
} catch (e) {
error = String(e);
} }
});
</script> </script>
<main class="container"> <main class="container">
<h1>Welcome to Tauri + Svelte</h1> <h1>coding-bench</h1>
<div class="row"> <section>
<a href="https://vite.dev" target="_blank"> <h2>Setup: Pfade</h2>
<img src="/vite.svg" class="logo vite" alt="Vite Logo" /> {#if error}
</a> <p class="fehler">Fehler: {error}</p>
<a href="https://tauri.app" target="_blank"> {:else if paths}
<img src="/tauri.svg" class="logo tauri" alt="Tauri Logo" /> <dl>
</a> <dt>Konfiguration</dt>
<a href="https://svelte.dev" target="_blank"> <dd><code>{paths.config_file}</code></dd>
<img src="/svelte.svg" class="logo svelte-kit" alt="SvelteKit Logo" /> <dt>Datenordner</dt>
</a> <dd><code>{paths.data_dir}</code></dd>
</div> <dt>Aufgabenordner</dt>
<p>Click on the Tauri, Vite, and SvelteKit logos to learn more.</p> <dd><code>{paths.tasks_dir}</code></dd>
</dl>
<form class="row" onsubmit={greet}> {:else}
<input id="greet-input" placeholder="Enter a name..." bind:value={name} /> <p>Lade Pfade …</p>
<button type="submit">Greet</button> {/if}
</form> </section>
<p>{greetMsg}</p>
</main> </main>
<style> <style>
.logo.vite:hover {
filter: drop-shadow(0 0 2em #747bff);
}
.logo.svelte-kit:hover {
filter: drop-shadow(0 0 2em #ff3e00);
}
:root { :root {
font-family: Inter, Avenir, Helvetica, Arial, sans-serif; font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
font-size: 16px; font-size: 16px;
line-height: 24px; line-height: 24px;
font-weight: 400;
color: #0f0f0f; color: #0f0f0f;
background-color: #f6f6f6; background-color: #f6f6f6;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;
} }
.container {
margin: 0;
padding-top: 10vh;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: 0.75s;
}
.logo.tauri:hover {
filter: drop-shadow(0 0 2em #24c8db);
}
.row {
display: flex;
justify-content: center;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
h1 {
text-align: center;
}
input,
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
color: #0f0f0f;
background-color: #ffffff;
transition: border-color 0.25s;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
}
button {
cursor: pointer;
}
button:hover {
border-color: #396cd8;
}
button:active {
border-color: #396cd8;
background-color: #e8e8e8;
}
input,
button {
outline: none;
}
#greet-input {
margin-right: 5px;
}
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
:root { :root {
color: #f6f6f6; color: #f6f6f6;
background-color: #2f2f2f; background-color: #2f2f2f;
} }
a:hover {
color: #24c8db;
} }
input, .container {
button { margin: 0 auto;
color: #ffffff; padding: 2rem 1rem;
background-color: #0f0f0f98; max-width: 48rem;
}
button:active {
background-color: #0f0f0f69;
}
} }
dl {
display: grid;
grid-template-columns: max-content 1fr;
gap: 0.4rem 1rem;
}
dt {
font-weight: 600;
}
dd {
margin: 0;
overflow-wrap: anywhere;
}
.fehler {
color: #c62828;
}
</style> </style>