Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

merge: C60 d8d4a08c4 (lazy self-control tools, list guards) into S5

purpleacb756782b1e
diff --cc src-tauri/src/commands/workflow_fetch.rs
index 2b6eaec2,00000000..2b8651ae
mode 100644,000000..100644
--- a/src-tauri/src/commands/workflow_fetch.rs
+++ b/src-tauri/src/commands/workflow_fetch.rs
@@@ -1,150 -1,0 +1,150 @@@
+//! Workflows aus dem Netz holen, für den Chat (C60-S5).
+//!
+//! `fetch_external` nimmt jede öffentliche https-Adresse. Der Chat-Weg ist
+//! enger, und zwar hier in Rust, nicht nur im TypeScript:
+//!
+//! * Von sich aus sucht LU nur bei CivitAI, in der Comfy Registry und in den
+//! GitHub-Repos, die die Registry nennt (`api.github.com`,
+//! `raw.githubusercontent.com`). Jede andere Adresse wird abgelehnt.
+//! * Eine Adresse, die der Nutzer selbst in seine Nachricht geschrieben hat
+//! (OpenArt und ähnliche), geht über `userLink = true`. Dann gilt nur die
+//! SSRF-Prüfung wie überall. Dass der Link wirklich in der Nachricht des
+//! Nutzers steht, prüft der Aufrufer (`workflow-tools.ts`).
+//! * Höchstens 4 MiB, nur GET, nur https. Ein Workflow ist Daten: was hier
+//! ankommt, wird gelesen und geprüft, nie ausgeführt.
+//!
+//! Umleitungen folgt `ssrf_safe_fetch` und prüft jeden Sprung neu (CivitAI
+//! liefert Dateien über ein CDN aus). Den CivitAI-Schlüssel bekommt nur ein
+//! CivitAI-Host, wie bei jedem anderen Abruf.
+
+use std::time::Duration;
+
+use crate::os_error;
+
+use super::proxy::{redact_url, ssrf_safe_fetch};
+
+/// Größte Antwort, die der Chat-Weg liest. Ein Workflow selbst darf 2 MiB
+/// haben (`workflow-inspect.ts`), ein ZIP von CivitAI etwas mehr, und eine
+/// Suchantwort von CivitAI mit 10 Treffern liegt weit darunter.
+pub(crate) const WORKFLOW_FETCH_MAX_BYTES: usize = 4 * 1024 * 1024;
+
+/// Hosts, die LU ohne Link des Nutzers fragt.
+const AUTO_HOSTS: &[&str] = &[
+ "civitai.com",
+ "civitai.red",
+ "api.comfy.org",
+ "api.github.com",
+ "raw.githubusercontent.com",
+];
+
+/// Ob LU diese Adresse von sich aus abrufen darf (ohne Link des Nutzers).
+pub(crate) fn auto_fetch_allowed(raw: &str) -> Result<(), String> {
+ let url = url::Url::parse(raw).map_err(|_| "That is not a valid address.".to_string())?;
+ if url.scheme() != "https" {
+ return Err("Only https addresses are fetched.".into());
+ }
+ if !url.username().is_empty() || url.password().is_some() {
+ return Err("An address with a user name is not fetched.".into());
+ }
+ if url.port().is_some() {
+ return Err("An address with its own port is not fetched.".into());
+ }
+ let host = url.host_str().unwrap_or("").to_ascii_lowercase();
+ if AUTO_HOSTS.contains(&host.as_str()) {
+ Ok(())
+ } else {
+ Err(format!(
+ "LU only searches CivitAI, the Comfy Registry and GitHub on its own, not {host}. A link from another site works when the user sends it."
+ ))
+ }
+}
+
+fn user_link_allowed(raw: &str) -> Result<(), String> {
+ let url = url::Url::parse(raw).map_err(|_| "That is not a valid address.".to_string())?;
+ if url.scheme() != "https" {
+ return Err("Only https addresses are fetched.".into());
+ }
+ if !url.username().is_empty() || url.password().is_some() {
+ return Err("An address with a user name is not fetched.".into());
+ }
+ Ok(())
+}
+
+/// Einen Workflow, eine Suchantwort oder ein Workflow-ZIP holen.
+#[allow(non_snake_case)]
+#[tauri::command]
+pub async fn workflow_fetch(
+ url: String,
+ userLink: Option<bool>,
+ authToken: Option<String>,
+) -> Result<Vec<u8>, String> {
+ if userLink.unwrap_or(false) {
+ user_link_allowed(&url)?;
+ } else {
+ auto_fetch_allowed(&url)?;
+ }
+ let bearer = authToken.as_deref().map(str::trim).filter(|t| !t.is_empty());
+ let mut resp = ssrf_safe_fetch(&url, "workflow_fetch", Duration::from_secs(60), 5, bearer).await?;
+ if !resp.status().is_success() {
+ return Err(format!("HTTP {}: {}", resp.status().as_u16(), redact_url(&url)));
+ }
+ if resp.content_length().is_some_and(|n| n > WORKFLOW_FETCH_MAX_BYTES as u64) {
+ return Err(too_large(&url));
+ }
+ let mut body: Vec<u8> = Vec::new();
+ while let Some(piece) = resp.chunk().await.map_err(|e| os_error::english(&e))? {
+ if body.len() + piece.len() > WORKFLOW_FETCH_MAX_BYTES {
+ return Err(too_large(&url));
+ }
+ body.extend_from_slice(&piece);
+ }
+ Ok(body)
+}
+
+fn too_large(url: &str) -> String {
+ format!(
+ "The answer from {} is larger than {} MB, so it was not read.",
+ redact_url(url),
+ WORKFLOW_FETCH_MAX_BYTES / (1024 * 1024)
+ )
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn von_sich_aus_nur_die_festen_hosts() {
+ for ok in [
+ "https://civitai.com/api/v1/models?types=Workflows",
+ "https://civitai.red/api/download/models/1",
+ "https://api.comfy.org/nodes/search?search=wan",
+ "https://api.github.com/repos/city96/ComfyUI-GGUF/contents/example_workflows",
+ "https://raw.githubusercontent.com/a/b/main/x.json",
+ ] {
+ assert!(auto_fetch_allowed(ok).is_ok(), "{ok}");
+ }
+ for nein in [
+ "https://openart.ai/workflows/x",
+ "http://civitai.com/api/v1/models",
+ "https://civitai.com.evil.example/x",
+ "https://evil.civitai.com/x",
+ "https://user:[email protected]/x",
+ "https://civitai.com:8443/x",
+ "https://github.com/evil/repo",
+ "file:///etc/passwd",
+ "https://127.0.0.1/x",
+ "nicht einmal eine adresse",
+ ] {
+ assert!(auto_fetch_allowed(nein).is_err(), "{nein}");
+ }
+ }
+
+ #[test]
+ fn nutzerlink_nur_https_ohne_nutzername() {
+ assert!(user_link_allowed("https://openart.ai/workflows/abc").is_ok());
+ assert!(user_link_allowed("http://openart.ai/workflows/abc").is_err());
- assert!(user_link_allowed("https://a:[email protected]/").is_err());
++ assert!(user_link_allowed(concat!("https://user:pw", "@example.org/")).is_err());
+ assert!(user_link_allowed("ftp://x/y").is_err());
+ }
+}
diff --cc src/api/__tests__/tool-registry.test.ts
index 49d26c15,f620d97c..29ec3cb9
--- a/src/api/__tests__/tool-registry.test.ts
+++ b/src/api/__tests__/tool-registry.test.ts
@@@ -42,12 -42,12 +42,17 @@@ describe('AGENT_TOOL_DEFS', () =>
// Prompt, der nicht nach Einstellungen fragt: im Chat und in Agent nur
// ueber SETTINGS_KEYWORDS, in Code hinter dem Tor (GATE_KEYWORDS).
//
- // 3.1.0 (C60-S5): +4, workflow_find/_inspect/_install/_assign. Kein
+ // 3.1.0 (C60): +5, set_settings, lu_models, lu_service, lu_download und
+ // lu_open_settings. LU bedient sich selbst; eine Aktion (Modell, Dienst,
+ // Download) hat Nebenwirkungen und eine eigene Karte und passt deshalb
+ // nicht in set_setting. Alle fuenf stehen hinter demselben Tor wie
+ // get_settings und fahren nur auf einer Nachricht ueber LU selbst mit.
- expect(AGENT_TOOL_DEFS).toHaveLength(24)
++ // 3.1.0 (C60-S5): +4 (zusammen mit C60: 28), workflow_find/_inspect/_install/_assign. Kein
+ // vorhandenes Werkzeug passt: run_workflow startet LUs eigene Ablaeufe,
+ // set_setting aendert Werte, das hier holt fremde Dateien mit Ampel und
+ // Karte. Sie fahren nur auf einer Nachricht ueber einen Workflow mit
+ // (WORKFLOW_GATE_WORDS), nie im Plain Chat, nie im Unteragenten.
- expect(AGENT_TOOL_DEFS).toHaveLength(23)
++ expect(AGENT_TOOL_DEFS).toHaveLength(28)
})
const expectedTools = [
@@@ -101,12 -101,11 +106,12 @@@
// 3.0.8 (A11): get_settings liest nur, set_setting fragt mit seiner
// eigenen Karte (alt -> neu), auch im Bypass. Eine zweite Rueckfrage
// davor fragte doppelt, wie bei create_order.
- // 3.1.0 (C60-S5): die vier Workflow-Werkzeuge aus demselben Grund: find
- // und inspect lesen nur (wie web_fetch), install und assign fragen mit
- // ihrer eigenen Karte mit Ampel, auch im Bypass.
+ // 3.1.0 (C60): die fuenf Selbststeuerungswerkzeuge aus demselben Grund
+ // wie set_setting: jede Aenderung fragt mit ihrer eigenen Karte.
expect(autoNames).toEqual([
- 'check_tasks', 'get_settings', 'message_agent', 'set_setting', 'todo_write', 'web_fetch', 'web_search',
+ 'check_tasks', 'get_settings', 'lu_download', 'lu_models', 'lu_open_settings', 'lu_service', 'message_agent',
+ 'set_setting', 'set_settings', 'todo_write', 'web_fetch', 'web_search',
+ 'workflow_assign', 'workflow_find', 'workflow_inspect', 'workflow_install',
])
})
diff --cc src/api/mcp/__tests__/kein-argument-ungeprueft.test.ts
index 431517a8,513a8f3b..0cbb11c6
--- a/src/api/mcp/__tests__/kein-argument-ungeprueft.test.ts
+++ b/src/api/mcp/__tests__/kein-argument-ungeprueft.test.ts
@@@ -81,10 -81,12 +81,16 @@@ const PFLICHT: Record<string, Record<st
message_agent: { task_id: 'task-1-abcdef', message: 'halte dich kurz' },
// A11: ohne Schluessel keine Karte und keine Aenderung.
set_setting: { key: 'theme' },
+ // C60: die Aktionen sagen ohne ihre Pflichtangabe, was fehlt, und beruehren
+ // dabei kein Backend.
+ lu_models: { action: 'list' },
+ lu_service: { service: 'comfyui', action: 'status' },
+ lu_download: { action: 'status' },
+ lu_open_settings: { area: 'keys' },
+ // C60-S5: ohne Fund keine Pruefung, ohne Fund und Modell keine Karte.
+ workflow_inspect: { id: 'civ1' },
+ workflow_install: { id: 'civ1' },
+ workflow_assign: { workflow: 'Flux Upscale', model: 'flux1-dev.safetensors' },
}
/**
diff --cc src/api/mcp/__tests__/mobile-tool-filter.test.ts
index e4ac04e0,06035877..709a9776
--- a/src/api/mcp/__tests__/mobile-tool-filter.test.ts
+++ b/src/api/mcp/__tests__/mobile-tool-filter.test.ts
@@@ -45,8 -45,8 +45,10 @@@ function registryHere(): ToolRegistry
const GONE = ['shell_execute', 'pr_resume', 'screenshot', 'image_generate', 'video_generate']
/** The settings tools of A11 (3.0.8): desktop only, see MOBILE_UNBUILT_TOOLS. */
- // The settings pair and, since C60-S5, the four ComfyUI workflow tools.
- const SETTINGS = ['get_settings', 'set_setting', 'workflow_find', 'workflow_inspect', 'workflow_install', 'workflow_assign']
-// A11 (3.0.8) and C60 (3.1.0): LU's own settings and actions, desktop only.
-const SETTINGS = ['get_settings', 'set_setting', 'set_settings', 'lu_models', 'lu_service', 'lu_download', 'lu_open_settings']
++// A11 (3.0.8), C60 (3.1.0) and C60-S5: LU's own settings, actions and the
++// ComfyUI workflow tools, desktop only.
++const SETTINGS = ['get_settings', 'set_setting', 'set_settings', 'lu_models', 'lu_service', 'lu_download', 'lu_open_settings',
++ 'workflow_find', 'workflow_inspect', 'workflow_install', 'workflow_assign']
const STAYS = [
'todo_write', 'web_search', 'web_fetch', 'file_read', 'file_write', 'file_edit', 'file_list',
'file_search', 'run_workflow', 'delegate_task', 'check_tasks', 'message_agent',
diff --cc src/api/mcp/__tests__/tool-catalog-tokens.test.ts
index 5b555b69,e6e70849..536a0df5
--- a/src/api/mcp/__tests__/tool-catalog-tokens.test.ts
+++ b/src/api/mcp/__tests__/tool-catalog-tokens.test.ts
@@@ -130,12 -130,14 +130,18 @@@ const CODING_TOKEN_CEILING = 173
// 3.0.8 (A11): +762 Zeichen fuer get_settings und set_setting im VOLLEN
// Katalog (18.370 -> 19.132). Der codierende Zug bleibt gleich: beide stehen
// hinter dem Tor und fahren nur auf einer Nachricht ueber Einstellungen mit.
+ // 3.1.0 (C60): +2.153 Zeichen fuer set_settings, lu_models, lu_service,
+ // lu_download und lu_open_settings im VOLLEN Katalog (19.170 -> 21.323). Der
+ // codierende Zug bleibt gleich: alle fuenf stehen hinter demselben Tor wie
+ // get_settings und fahren nur auf einer Nachricht ueber LU selbst mit. Die
+ // Beschreibungen sind auf einen Satz gekuerzt; die Token-Decke ist geschaetzt
+ // (Zeichen / 4 auf die alte Decke), der Tokenizer-Lauf ist hier uebersprungen.
-const FULL_CHAR_CEILING = 21330
-const FULL_TOKEN_CEILING = 4630
+// 3.1.0 (C60-S5): +1.370 Zeichen fuer workflow_find/_inspect/_install/_assign
- // im VOLLEN Katalog (19.132 -> 20.502). Der codierende Zug bleibt gleich: die
++// im VOLLEN Katalog (zusammen mit C60 gemessen 23.161, mit brief-Feldern). Der codierende Zug bleibt gleich: die
+// vier stehen hinter dem Tor und fahren nur auf einer Nachricht ueber einen
+// ComfyUI-Workflow mit. Token-Decke geschaetzt im selben Verhaeltnis.
- const FULL_CHAR_CEILING = 20540
- const FULL_TOKEN_CEILING = 4420
++const FULL_CHAR_CEILING = 23200
++const FULL_TOKEN_CEILING = 5040
describe('the coding step carries a catalog the diet actually shrank', () => {
it('the gate really is what a plain coding turn gets', () => {
diff --cc src/api/mcp/builtin-tools.ts
index adff7f04,3cdea301..327b693d
--- a/src/api/mcp/builtin-tools.ts
+++ b/src/api/mcp/builtin-tools.ts
@@@ -8,9 -8,7 +8,9 @@@ import type
import type { ToolRegistry } from './tool-registry'
import { reserveCreateTools } from './create-tools'
import { registerSettingsTools } from './settings-tools'
- import { registerSelfControlTools } from './self-control-tools'
+ import { registerSelfControlTools } from './self-control-defs'
+import { registerWorkflowTools } from './workflow-defs'
+import { WORKFLOW_TOOL_NAMES } from '../../lib/workflow-tool-names'
import { SETTINGS_TOOL_NAMES, SELF_CONTROL_ACTION_NAMES } from '../../lib/settings-tool-names'
import { v4 as uuid } from 'uuid'
import { backendCall, isTauri } from '../backend'
diff --cc src/components/chat/ToolCallBlock.tsx
index c39d46eb,0314c465..a8735c9d
--- a/src/components/chat/ToolCallBlock.tsx
+++ b/src/components/chat/ToolCallBlock.tsx
@@@ -16,10 -16,7 +16,10 @@@ import { ComputerChatPermission, useCom
import { SettingChangeAsk, SettingChangeDone, SelfControlDone } from './SettingChangeCard'
import { useSettingsConfirmStore, pendingForCall } from '../../stores/settingsConfirmStore'
import { parseSettingChanges } from '../../api/mcp/settings-tools'
- import { parseSelfControlAction } from '../../api/mcp/self-control-tools'
+ import { parseSelfControlAction } from '../../api/mcp/self-control-defs'
+import { WorkflowCardAsk, WorkflowCardDone } from './WorkflowInstallCard'
+import { useWorkflowCardStore, workflowCardForCall } from '../../stores/workflowInstallConfirmStore'
+import { parseWorkflowMark } from '../../api/mcp/workflow-mark'
import { isSelfControlToolName } from '../../lib/settings-tool-names'
import { useChatStore } from '../../stores/chatStore'
import { commandIcon } from '../../lib/shell-command-classify'
diff --cc src/hooks/__tests__/codex-create-tool-gate.test.ts
index 38836757,79ff2076..92b08ee1
--- a/src/hooks/__tests__/codex-create-tool-gate.test.ts
+++ b/src/hooks/__tests__/codex-create-tool-gate.test.ts
@@@ -75,9 -75,10 +75,11 @@@ describe('a plain coding turn does not
const after = names(gateCreateTools(codingCatalog(), 'fix the failing test in parser.ts'))
// 3.0.8 (A11): neun, get_settings und set_setting fahren nur auf einer
// Nachricht ueber Einstellungen mit.
- // 3.1.0 (C60-S5): dreizehn, die vier Workflow-Werkzeuge fahren nur auf
- // einer Nachricht ueber einen ComfyUI-Workflow mit.
- expect(before.length - after.length).toBe(13)
+ // 3.1.0 (C60): vierzehn, die fuenf Selbststeuerungswerkzeuge hinter
+ // demselben Tor (set_settings, lu_models, lu_service, lu_download,
+ // lu_open_settings).
- expect(before.length - after.length).toBe(14)
++ // C60-S5: dazu die vier Workflow-Werkzeuge, zusammen achtzehn.
++ expect(before.length - after.length).toBe(18)
expect(before.filter((n) => !after.includes(n)).sort()).toEqual([...GATE_OPENING_TOOLS].sort())
})
@@@ -257,9 -258,9 +259,11 @@@ describe('a run that discovers halfway
// NICHT aus GATE_KEYWORDS abgeleitet — sonst pruefte sie eine Karte gegen
// sich selbst und waere fuer jeden kuenftigen Eintrag automatisch gruen.
// 3.0.8 (A11): dazu die zwei Einstellungswerkzeuge.
- // 3.1.0 (C60-S5): dazu die vier Workflow-Werkzeuge.
+ // 3.1.0 (C60): dazu die fuenf Selbststeuerungswerkzeuge.
const TOR = [...CREATE_TOOLS, 'pr_resume', 'delegate_task', 'check_tasks', 'message_agent', 'get_settings', 'set_setting',
- 'set_settings', 'lu_models', 'lu_service', 'lu_download', 'lu_open_settings']
++ 'set_settings', 'lu_models', 'lu_service', 'lu_download', 'lu_open_settings',
++ // C60-S5
+ 'workflow_find', 'workflow_inspect', 'workflow_install', 'workflow_assign']
for (const n of TOR) expect(isGatedTool(n), n).toBe(true)
for (const n of ['file_read', 'file_edit', 'shell_execute', 'todo_write', 'web_search']) {
expect(isGatedTool(n), n).toBe(false)