clarify

Ask the user a question when you need clarification, feedback, or a decision before proceeding. Supports two modes:

1. **Multiple choice** — provide up to 4 choices. The user picks one or types their own answer via a 5th 'Other' option.
2. **Open-ended** — omit choices entirely. The user types a free-form response.

Use this tool when:
- The task is ambiguous and you need the user to choose an approach
- You want post-task feedback ('How did that work out?')
- You want to offer to save a skill or update memory
- A decision has meaningful trade-offs the user should weigh in on

Do NOT use this tool for simple yes/no confirmation of dangerous commands (the terminal tool handles that). Prefer making a reasonable default choice yourself when the decision is low-stakes.

The question to present to the user.

Choices:
Up to 4 answer choices. Omit this parameter entirely to ask an open-ended question. When provided, the UI automatically appends an 'Other (type your answer)' option.

cronjob

Manage scheduled cron jobs with a single compressed tool.

Use action='create' to schedule a new job from a prompt or one or more skills.
Use action='list' to inspect jobs.
Use action='update', 'pause', 'resume', 'remove', or 'run' to manage an existing job.

To stop a job the user no longer wants: first action='list' to find the job_id, then action='remove' with that job_id. Never guess job IDs — always list first.

Jobs run in a fresh session with no current-chat context, so prompts must be self-contained.
If skills are provided on create, the future cron run loads those skills in order, then follows the prompt as the task instruction.
On update, passing skills=[] clears attached skills.

NOTE: The agent's final response is auto-delivered to the target. Put the primary
user-facing content in the final response. Cron jobs run autonomously with no user
present — they cannot ask questions or request clarification.

Important safety rule: cron-run sessions should not recursively schedule more cron jobs.

One of: create, list, update, pause, resume, remove, run

Required for update/pause/resume/remove/run

For create: the full self-contained prompt. If skills are also provided, this becomes the task instruction paired with those skills.

For create/update: '30m', 'every 2h', '0 9 * * *', or ISO timestamp

Optional human-friendly name

Optional repeat count. Omit for defaults (once for one-shot, forever for recurring).

Omit this parameter to auto-deliver back to the current chat and topic (recommended). Auto-detection preserves thread/topic context. Only set explicitly when the user asks to deliver somewhere OTHER than the current conversation. Values: 'origin' (same as omitting), 'local' (no delivery, save only), or platform:chat_id:thread_id for a specific destination. Examples: 'telegram:-1001234567890:17585', 'discord:#engineering', 'sms:+15551234567'. WARNING: 'platform:chat_id' without :thread_id loses topic targeting.

Optional ordered list of skill names to load before executing the cron prompt. On update, pass an empty array to clear attached skills.

Optional per-job model override. If provider is omitted, the current main provider is pinned at creation time so the job stays stable.

Provider name (e.g. 'openrouter', 'anthropic', or 'custom:<name>' for a provider defined in custom_providers config — always include the ':<name>' suffix, never pass the bare 'custom'). Omit to use and pin the current provider.

Model name (e.g. 'anthropic/claude-sonnet-4', 'claude-sonnet-4')

Optional path to a script that runs each tick. In the default mode its stdout is injected into the agent's prompt as context (data-collection / change-detection pattern). With no_agent=True, the script IS the job and its stdout is delivered verbatim (classic watchdog pattern). Relative paths resolve under ~/hermes/scripts/. ``.sh``/``.bash`` extensions run via bash, everything else via Python. On update, pass empty string to clear.

Default: False (LLM-driven job — the agent runs the prompt each tick). Set True to skip the LLM entirely: the scheduler just runs ``script`` on schedule and delivers its stdout verbatim. No tokens, no agent loop, no model override honoured.

REQUIREMENTS when True: ``script`` MUST be set (``prompt`` and ``skills`` are ignored).

DELIVERY SEMANTICS when True: (a) non-empty stdout is sent verbatim as the message; (b) EMPTY stdout means SILENT — nothing is sent to the user and they won't see anything happened, so design your script to stay quiet when there's nothing to report (the watchdog pattern); (c) non-zero exit / timeout sends an error alert so a broken watchdog can't fail silently.

WHEN TO USE True: recurring script-only pings where the script itself produces the exact message text (memory/disk/GPU watchdogs, threshold alerts, heartbeats, CI notifications, API pollers with a fixed output shape). WHEN TO USE False (default): anything that needs reasoning — summarize a feed, draft a daily briefing, pick interesting items, rephrase data for a human, follow conditional logic based on content.

Optional job ID or list of job IDs whose most recent completed output is injected into the prompt as context before each run. Use this to chain cron jobs: job A collects data, job B processes it. Each entry must be a valid job ID (from cronjob action='list'). Note: injects the most recent completed output — does not wait for upstream jobs running in the same tick. On update, pass an empty array to clear.

Optional list of toolset names to restrict the job's agent to (e.g. ["web", "terminal", "file", "delegation"]). When set, only tools from these toolsets are loaded, significantly reducing input token overhead. When omitted, all default tools are loaded. Infer from the job's prompt — e.g. use "web" if it calls web_search, "terminal" if it runs scripts, "file" if it reads files, "delegation" if it calls delegate_task. On update, pass an empty array to clear.

Optional absolute path to run the job from. When set, AGENTS.md / CLAUDE.md / .cursorrules from that directory are injected into the system prompt, and the terminal/file/code_exec tools use it as their working directory — useful for running a job inside a specific project repo. Must be an absolute path that exists. When unset (default), preserves the original behaviour: no project context files, tools use the scheduler's cwd. On update, pass an empty string to clear. Jobs with workdir run sequentially (not parallel) to keep per-job directories isolated.

Spawn one or more subagents to work on tasks in isolated contexts. Each subagent gets its own conversation, terminal session, and toolset. Only the final summary is returned -- intermediate tool results never enter your context window.

TWO MODES (one of 'goal' or 'tasks' is required):
1. Single task: provide 'goal' (+ optional context, toolsets)
2. Batch (parallel): provide 'tasks' array with up to delegation.max_concurrent_children items (default 3, configurable via config.yaml, no hard ceiling). All run concurrently and results are returned together. Nested delegation requires role='orchestrator' and delegation.max_spawn_depth >= 2.

WHEN TO USE delegate_task:
- Reasoning-heavy subtasks (debugging, code review, research synthesis)
- Tasks that would flood your context with intermediate data
- Parallel independent workstreams (research A and B simultaneously)

WHEN NOT TO USE (use these instead):
- Mechanical multi-step work with no reasoning needed -> use execute_code
- Single tool call -> just call the tool directly
- Tasks needing user interaction -> subagents cannot use clarify
- Durable long-running work that must outlive the current turn -> use cronjob (action='create') or terminal(background=True, notify_on_complete=True) instead. delegate_task runs SYNCHRONOUSLY inside the parent turn: if the parent is interrupted (user sends a new message, /stop, /new) the child is cancelled with status='interrupted' and its work is discarded. Children cannot continue in the background.

IMPORTANT:
- Subagents have NO memory of your conversation. Pass all relevant info (file paths, error messages, constraints) via the 'context' field.
- If the user is writing in a non-English language, or asked for output in a specific language / tone / style, say so in 'context' (e.g. "respond in Chinese", "return output in Japanese"). Otherwise subagents default to English and their summaries will contaminate your final reply with the wrong language.
- Subagent summaries are SELF-REPORTS, not verified facts. A subagent that claims "uploaded successfully" or "file written" may be wrong. For operations with external side-effects (HTTP POST/PUT, remote writes, file creation at shared paths, publishing), require the subagent to return a verifiable handle (URL, ID, absolute path, HTTP status) and verify it yourself — fetch the URL, stat the file, read back the content — before telling the user the operation succeeded.
- Leaf subagents (role='leaf', the default) CANNOT call: delegate_task, clarify, memory, send_message, execute_code.
- Orchestrator subagents (role='orchestrator') retain delegate_task so they can spawn their own workers, but still cannot use clarify, memory, send_message, or execute_code. Orchestrators are bounded by delegation.max_spawn_depth (default 2) and can be disabled globally via delegation.orchestrator_enabled=false.
- Each subagent gets its own terminal session (separate working directory and state).
- Results are always returned as an array, one entry per task.

What the subagent should accomplish. Be specific and self-contained -- the subagent knows nothing about your conversation history.

Background information the subagent needs: file paths, error messages, project structure, constraints. The more specific you are, the better the subagent performs.

Toolsets to enable for this subagent. Default: inherits your enabled toolsets. Available toolsets: 'browser', 'cronjob', 'discord', 'discord_admin', 'feishu_doc', 'feishu_drive', 'file', 'homeassistant', 'image_gen', 'kanban', 'search', 'session_search', 'skills', 'spotify', 'terminal', 'todo', 'tts', 'video', 'vision', 'web', 'yuanbao'. Common patterns: ['terminal', 'file'] for code work, ['web'] for research, ['browser'] for web interaction, ['terminal', 'file', 'web'] for full-stack tasks.

Task goal

Task-specific context

Toolsets for this specific task. Available: 'browser', 'cronjob', 'discord', 'discord_admin', 'feishu_doc', 'feishu_drive', 'file', 'homeassistant', 'image_gen', 'kanban', 'search', 'session_search', 'skills', 'spotify', 'terminal', 'todo', 'tts', 'video', 'vision', 'web', 'yuanbao'. Use 'web' for network access, 'terminal' for shell, 'browser' for web interaction.

Per-task ACP command override (e.g. 'claude'). Overrides the top-level acp_command for this task only.

Per-task ACP args override.

Per-task role override. See top-level 'role' for semantics.

Batch mode: tasks to run in parallel (limit configurable via delegation.max_concurrent_children, default 3). Each gets its own subagent with isolated context and terminal session. When provided, top-level goal/context/toolsets are ignored.

Role of the child agent. 'leaf' (default) = focused worker, cannot delegate further. 'orchestrator' = can use delegate_task to spawn its own workers. Requires delegation.max_spawn_depth >= 2 in config; ignored (treated as 'leaf') when the child would exceed max_spawn_depth or when delegation.orchestrator_enabled=false.

Override ACP command for child agents (e.g. 'claude', 'copilot'). When set, children use ACP subprocess transport instead of inheriting the parent's transport. Enables spawning Claude Code (claude --acp --stdio) or other ACP-capable agents from any parent, including Discord/Telegram/CLI.

Arguments for the ACP command (default: ['--acp', '--stdio']). Only used when acp_command is set. Example: ['--acp', '--stdio', '--model', 'claude-opus-4-6']

Run a Python script that can call Hermes tools programmatically. Use this when you need 3+ tool calls with processing logic between them, need to filter/reduce large tool outputs before they enter your context, need conditional branching (if X then Y else Z), or need to loop (fetch N pages, process N files, retry on failure).

Use normal tool calls instead when: single tool call with no processing, you need to see the full result and apply complex reasoning, or the task requires interactive user input.

Available via `from hermes_tools import ...`:

  read_file(path: str, offset: int = 1, limit: int = 500) -> dict
    Lines are 1-indexed. Returns {"content": "...", "total_lines": N}
  write_file(path: str, content: str) -> dict
    Always overwrites the entire file.
  search_files(pattern: str, target="content", path=".", file_glob=None, limit=50) -> dict
    target: "content" (search inside files) or "files" (find files by name). Returns {"matches": [...]}
  patch(path: str, old_string: str, new_string: str, replace_all: bool = False) -> dict
    Replaces old_string with new_string in the file.
  terminal(command: str, timeout=None, workdir=None) -> dict
    Foreground only (no background/pty). Returns {"output": "...", "exit_code": N}

Limits: 5-minute timeout, 50KB stdout cap, max 50 tool calls per script. terminal() is foreground-only (no background or pty).

Scripts run in the session's working directory with the active venv's python, so project deps (pandas, etc.) and relative paths work like in terminal().

Print your final result to stdout. Use Python stdlib (json, re, math, csv, datetime, collections, etc.) for processing between tool calls.

Also available (no import needed — built into hermes_tools):
  json_parse(text: str) — json.loads with strict=False; use for terminal() output with control chars
  shell_quote(s: str) — shlex.quote(); use when interpolating dynamic strings into shell commands
  retry(fn, max_attempts=3, delay=2) — retry with exponential backoff for transient failures

Python code to execute. Import tools with `from hermes_tools import terminal, ...` and print your final result to stdout.

memory

Save durable information to persistent memory that survives across sessions. Memory is injected into future turns, so keep it compact and focused on facts that will still matter later.

WHEN TO SAVE (do this proactively, don't wait to be asked):
- User corrects you or says 'remember this' / 'don't do that again'
- User shares a preference, habit, or personal detail (name, role, timezone, coding style)
- You discover something about the environment (OS, installed tools, project structure)
- You learn a convention, API quirk, or workflow specific to this user's setup
- You identify a stable fact that will be useful again in future sessions

PRIORITY: User preferences and corrections > environment facts > procedural knowledge. The most valuable memory prevents the user from having to repeat themselves.

Do NOT save task progress, session outcomes, completed-work logs, or temporary TODO state to memory; use session_search to recall those from past transcripts.
If you've discovered a new way to do something, solved a problem that could be necessary later, save it as a skill with the skill tool.

TWO TARGETS:
- 'user': who the user is -- name, role, preferences, communication style, pet peeves
- 'memory': your notes -- environment facts, project conventions, tool quirks, lessons learned

ACTIONS: add (new entry), replace (update existing -- old_text identifies it), remove (delete -- old_text identifies it).

SKIP: trivial/obvious info, things easily re-discovered, raw data dumps, and temporary task state.

The action to perform.

Which memory store: 'memory' for personal notes, 'user' for user profile.

The entry content. Required for 'add' and 'replace'.

Short unique substring identifying the entry to replace or remove.

patch

Targeted find-and-replace edits in files. Use this instead of sed/awk in terminal. Uses fuzzy matching (9 strategies) so minor whitespace/indentation differences won't break it. Returns a unified diff. Auto-runs syntax checks after editing.

Replace mode (default): find a unique string and replace it.
Patch mode: apply V4A multi-file patches for bulk changes.

Edit mode: 'replace' for targeted find-and-replace, 'patch' for V4A multi-file patches

File path to edit (required for 'replace' mode)

Text to find in the file (required for 'replace' mode). Must be unique in the file unless replace_all=true. Include enough surrounding context to ensure uniqueness.

Replacement text (required for 'replace' mode). Can be empty string to delete the matched text.

Replace all occurrences instead of requiring a unique match (default: false)

V4A format patch content (required for 'patch' mode). Format:
*** Begin Patch
*** Update File: path/to/file
@@ context hint @@
 context line
-removed line
+added line
*** End Patch

process

Manage background processes started with terminal(background=true). Actions: 'list' (show all), 'poll' (check status + new output), 'log' (full output with pagination), 'wait' (block until done or timeout), 'kill' (terminate), 'write' (send raw stdin data without newline), 'submit' (send data + Enter, for answering prompts), 'close' (close stdin/send EOF).

list poll log wait kill write submit close

Action to perform on background processes

Process session ID (from terminal background output). Required for all actions except 'list'.

Text to send to process stdin (for 'write' and 'submit' actions)

Max seconds to block for 'wait' action. Returns partial output on timeout.

Line offset for 'log' action (default: last 200 lines)

Max lines to return for 'log' action

Read a text file with line numbers and pagination. Use this instead of cat/head/tail in terminal. Output format: 'LINE_NUM|CONTENT'. Suggests similar filenames if not found. Use offset and limit for large files. Reads exceeding ~100K characters are rejected; use offset and limit to read specific sections of large files. NOTE: Cannot read images or binary files — use vision_analyze for images.

Path to the file to read (absolute, relative, or ~/path)

Line number to start reading from (1-indexed, default: 1)

Maximum number of lines to read (default: 500, max: 2000)

Search file contents or find files by name. Use this instead of grep/rg/find/ls in terminal. Ripgrep-backed, faster than shell equivalents.

Content search (target='content'): Regex search inside files. Output modes: full matches with line numbers, file paths only, or match counts.

File search (target='files'): Find files by glob pattern (e.g., '*.py', '*config*'). Also use this instead of ls — results sorted by modification time.

Regex pattern for content search, or glob pattern (e.g., '*.py') for file search

'content' searches inside file contents, 'files' searches for files by name

Directory or file to search in (default: current working directory)

Filter files by pattern in grep mode (e.g., '*.py' to only search Python files)

Maximum number of results to return (default: 50)

Skip first N results for pagination (default: 0)

Output format for grep mode: 'content' shows matching lines with line numbers, 'files_only' lists file paths, 'count' shows match counts per file

Number of context lines before and after each match (grep mode only)

Send a message to a connected messaging platform, or list available targets.

IMPORTANT: When the user asks to send to a specific channel or person (not just a bare platform name), call send_message(action='list') FIRST to see available targets, then send to the correct one.
If the user just says a platform name like 'send to telegram', send directly to the home channel without listing first.

Action to perform. 'send' (default) sends a message. 'list' returns all available channels/contacts across connected platforms.

Delivery target. Format: 'platform' (uses home channel), 'platform:#channel-name', 'platform:chat_id', or 'platform:chat_id:thread_id' for Telegram topics and Discord threads. Examples: 'telegram', 'telegram:-1001234567890:17585', 'discord:999888777:555444333', 'discord:#bot-home', 'slack:#engineering', 'signal:+155****4567', 'matrix:!roomid:server.org', 'matrix:@user:server.org', 'yuanbao:direct:<account_id>' (DM), 'yuanbao:group:<group_code>' (group chat)

The message text to send. To send an image or file, include MEDIA:<local_path> (e.g. 'MEDIA:/tmp/hermes/cache/img_xxx.jpg') in the message — the platform will deliver it as a native media attachment.

Search your long-term memory of past conversations, or browse recent sessions. This is your recall -- every past session is searchable, and this tool summarizes what happened.

TWO MODES:
1. Recent sessions (no query): Call with no arguments to see what was worked on recently. Returns titles, previews, and timestamps. Zero LLM cost, instant. Start here when the user asks what were we working on or what did we do recently.
2. Keyword search (with query): Search for specific topics across all past sessions. Returns LLM-generated summaries of matching sessions.

USE THIS PROACTIVELY when:
- The user says 'we did this before', 'remember when', 'last time', 'as I mentioned'
- The user asks about a topic you worked on before but don't have in current context
- The user references a project, person, or concept that seems familiar but isn't in memory
- You want to check if you've solved a similar problem before
- The user asks 'what did we do about X?' or 'how did we fix Y?'

Don't hesitate to search when it is actually cross-session -- it's fast and cheap. Better to search and confirm than to guess or ask the user to repeat themselves.

Search syntax: keywords joined with OR for broad recall (elevenlabs OR baseten OR funding), phrases for exact match ("docker networking"), boolean (python NOT java), prefix (deploy*). IMPORTANT: Use OR between keywords for best results — FTS5 defaults to AND which misses sessions that only mention some terms. If a broad OR query returns nothing, try individual keyword searches in parallel. Returns summaries of the top matching sessions.

Search query — keywords, phrases, or boolean expressions to find in past sessions. Omit this parameter entirely to browse recent sessions instead (returns titles, previews, timestamps with no LLM cost).

Optional: only search messages from specific roles (comma-separated). E.g. 'user,assistant' to skip tool outputs.

Max sessions to summarize (default: 3, max: 5).

Manage skills (create, update, delete). Skills are your procedural memory — reusable approaches for recurring task types. New skills go to ~/hermes/skills/; existing skills can be modified wherever they live.

Actions: create (full SKILL.md + optional category), patch (old_string/new_string — preferred for fixes), edit (full SKILL.md rewrite — major overhauls only), delete, write_file, remove_file.

On delete, pass `absorbed_into=<umbrella>` when you're merging this skill's content into another one, or `absorbed_into=""` when you're pruning it with no forwarding target. This lets the curator tell consolidation from pruning without guessing, so downstream consumers (cron jobs that reference the old skill name, etc.) get updated correctly. The target you name in `absorbed_into` must already exist — create/patch the umbrella first, then delete.

Create when: complex task succeeded (5+ calls), errors overcome, user-corrected approach worked, non-trivial workflow discovered, or user asks you to remember a procedure.
Update when: instructions stale/wrong, OS-specific failures, missing steps or pitfalls found during use. If you used a skill and hit issues not covered by it, patch it immediately.

After difficult/iterative tasks, offer to save as a skill. Skip for simple one-offs. Confirm with user before creating/deleting.

Good skills: trigger conditions, numbered steps with exact commands, pitfalls section, verification steps. Use skill_view() to see format examples.

Pinned skills are protected from deletion only — skill_manage(action='delete') will refuse with a message pointing the user to `hermes curator unpin <name>`. Patches and edits go through on pinned skills so you can still improve them as pitfalls come up; pin only guards against irrecoverable loss.

create patch edit delete write_file remove_file

The action to perform.

Skill name (lowercase, hyphens/underscores, max 64 chars). Must match an existing skill for patch/edit/delete/write_file/remove_file.

Full SKILL.md content (YAML frontmatter + markdown body). Required for 'create' and 'edit'. For 'edit', read the skill first with skill_view() and provide the complete updated text.

Text to find in the file (required for 'patch'). Must be unique unless replace_all=true. Include enough surrounding context to ensure uniqueness.

Replacement text (required for 'patch'). Can be empty string to delete the matched text.

For 'patch': replace all occurrences instead of requiring a unique match (default: false).

Optional category/domain for organizing the skill (e.g., 'devops', 'data-science', 'mlops'). Creates a subdirectory grouping. Only used with 'create'.

Path to a supporting file within the skill directory. For 'write_file'/'remove_file': required, must be under references/, templates/, scripts/, or assets/. For 'patch': optional, defaults to SKILL.md if omitted.

Content for the file. Required for 'write_file'.

For 'delete' only — declares intent so the curator can tell consolidation from pruning without guessing. Pass the umbrella skill name when this skill's content was merged into another (the target must already exist). Pass an empty string when the skill is truly stale and being pruned with no forwarding target. Omitting the arg on delete is supported for backward compatibility but downstream tooling (e.g. cron-job skill reference rewriting) will have to guess at intent.

Skills allow for loading information about specific tasks and workflows, as well as scripts and templates. Load a skill's full content or access its linked files (references, templates, scripts). First call returns SKILL.md content plus a 'linked_files' dict showing available references/templates/scripts. To access those, call again with file_path parameter.

The skill name (use skills_list to see available skills). For plugin-provided skills, use the qualified form 'plugin:skill' (e.g. 'superpowers:writing-plans').

OPTIONAL: Path to a linked file within the skill (e.g., 'references/api.md', 'templates/config.yaml', 'scripts/validate.py'). Omit to get the main SKILL.md content.

List available skills (name + description). Use skill_view(name) to load full content.

Optional category filter to narrow results

terminal

Execute shell commands on a Linux environment. Filesystem usually persists between calls.

Do NOT use cat/head/tail to read files — use read_file instead.
Do NOT use grep/rg/find to search — use search_files instead.
Do NOT use ls to list directories — use search_files(target='files') instead.
Do NOT use sed/awk to edit files — use patch instead.
Do NOT use echo/cat heredoc to create files — use write_file instead.
Reserve terminal for: builds, installs, git, processes, scripts, network, package managers, and anything that needs a shell.

Foreground (default): Commands return INSTANTLY when done, even if the timeout is high. Set timeout=300 for long builds/scripts — you'll still get the result in seconds if it's fast. Prefer foreground for short commands.
Background: Set background=true to get a session_id. Two patterns:
  (1) Long-lived processes that never exit (servers, watchers).
  (2) Long-running tasks with notify_on_complete=true — you can keep working on other things and the system auto-notifies you when the task finishes. Great for test suites, builds, deployments, or anything that takes more than a minute.
For servers/watchers, do NOT use shell-level background wrappers (nohup/disown/setsid/trailing '&') in foreground mode. Use background=true so Hermes can track lifecycle and output.
After starting a server, verify readiness with a health check or log signal, then run tests in a separate terminal() call. Avoid blind sleep loops.
Use process(action="poll") for progress checks, process(action="wait") to block until done.
Working directory: Use 'workdir' for per-command cwd.
PTY mode: Set pty=true for interactive CLI tools (Codex, Claude Code, Python REPL).

Do NOT use vim/nano/interactive tools without pty=true — they hang without a pseudo-terminal. Pipe git output to cat if it might page.

The command to execute on the VM

Run the command in the background. Two patterns: (1) Long-lived processes that never exit (servers, watchers). (2) Long-running tasks paired with notify_on_complete=true — you can keep working and get notified when the task finishes. For short commands, prefer foreground with a generous timeout instead.

Max seconds to wait (default: 180, foreground max: 600). Returns INSTANTLY when command finishes — set high for long tasks, you won't wait unnecessarily. Foreground timeout above 600s is rejected; use background=true for longer commands.

Working directory for this command (absolute path). Defaults to the session working directory.

Run in pseudo-terminal (PTY) mode for interactive CLI tools like Codex, Claude Code, or Python REPL. Only works with local and SSH backends. Default: false.

When true (and background=true), you'll be automatically notified exactly once when the process finishes. **This is the right choice for almost every long-running task** — tests, builds, deployments, multi-item batch jobs, anything that takes over a minute and has a defined end. Use this and keep working on other things; the system notifies you on exit. MUTUALLY EXCLUSIVE with watch_patterns — when both are set, watch_patterns is dropped.

Strings to watch for in background process output. HARD RATE LIMIT: at most 1 notification per 15 seconds per process — matches arriving inside the cooldown are dropped. After 3 consecutive 15-second windows with dropped matches, watch_patterns is automatically disabled for that process and promoted to notify_on_complete behavior (one notification on exit, no more mid-process spam). USE ONLY for truly rare, one-shot mid-process signals on LONG-LIVED processes that will never exit on their own — e.g. ['Application startup complete'] on a server so you know when to hit its endpoint, or ['migration done'] on a daemon. DO NOT use for: (1) end-of-run markers like 'DONE'/'PASS' — use notify_on_complete instead; (2) error patterns like 'ERROR'/'Traceback' in loops or multi-item batch jobs — they fire on every iteration and you'll hit the strike limit fast; (3) anything you'd ever combine with notify_on_complete. When in doubt, choose notify_on_complete. MUTUALLY EXCLUSIVE with notify_on_complete — set one, not both.

Convert text to speech audio. Returns a MEDIA: path that the platform delivers as native audio. Compatible providers render as a voice bubble on Telegram; otherwise audio is sent as a regular attachment. In CLI mode, saves to ~/voice-memos/. Voice and provider are user-configured (built-in providers like edge/openai or custom command providers under tts.providers.<name>), not model-selected.

The text to convert to speech. Provider-specific character caps apply and are enforced automatically (OpenAI 4096, xAI 15000, MiniMax 10000, ElevenLabs 5k-40k depending on model); over-long input is truncated.

Optional custom file path to save the audio. Defaults to ~/hermes/audio_cache/<timestamp>.mp3

todo

Manage your task list for the current session. Use for complex tasks with 3+ steps or when the user provides multiple tasks. Call with no parameters to read the current list.

Writing:
- Provide 'todos' array to create/update items
- merge=false (default): replace the entire list with a fresh plan
- merge=true: update existing items by id, add any new ones

Each item: {id: string, content: string, status: pending|in_progress|completed|cancelled}
List order is priority. Only ONE item in_progress at a time.
Mark items completed immediately when done. If something fails, cancel it and add a revised item.

Always returns the full current list.

Task items to write. Omit to read current list.

Unique item identifier

Task description

Current status

true: update existing items by id, add new ones. false (default): replace the entire list.

Inspect an image from a URL, file path, or tool output when you need closer detail than what's visible in the conversation. If the user's image is already attached to the conversation and you can see it, just answer directly — only call this tool for images referenced by URL/path, images returned inside other tool results (browser screenshots, search thumbnails), or when you need a deeper look at a specific region the main model's vision may have missed.

Image URL (http/https) or local file path to analyze.

Your specific question or request about the image to resolve. The AI will automatically provide a complete image description AND answer your specific question.

Write content to a file, completely replacing existing content. Use this instead of echo/cat heredoc in terminal. Creates parent directories automatically. OVERWRITES the entire file — use 'patch' for targeted edits. Auto-runs syntax checks on .py/.json/.yaml/.toml and other linted languages; only NEW errors introduced by this write are surfaced (pre-existing errors are filtered out).

Path to the file to write (will be created if it doesn't exist, overwritten if it does)

Complete content to write to the file


Gib mir alles zu Browser was du so gespeichert hast. Wie können wir den nutzen etc.


Explanation: Der Benutzer fragt nach allem, was ich über Browser gespeichert habe, und wie wir sie nutzen können. Ich sollte zuerst nach relevanten Skills suchen, dann meine Memory durchsuchen, und schließlich die Session-Search nutzen, um vergangene Konversationen zu finden.

Question: browser OR chromium OR playwright OR selenium OR headless


headless-browser-automation

Running real browser automation (Playwright, Selenium) on headless Linux systems that lack desktop libraries, package managers, or writable system paths — common on ZimaOS, CasaOS, NAS appliances, and restricted containers. Covers Docker-based Chromium, system-library fallbacks, and anti-detection setup.

kanban-orchestrator

Decomposition playbook + specialist-roster conventions + anti-temptation rules for an orchestrator profile routing work through Kanban. The "don't do the work yourself" rule and the basic lifecycle are auto-injected into every kanban worker's system prompt; this skill is the deeper playbook when you're specifically playing the orchestrator role.

kanban-worker

Pitfalls, examples, and edge cases for Hermes Kanban workers. The lifecycle itself is auto-injected into every worker's system prompt as KANBAN_GUIDANCE (from agent/prompt_builder.py); this skill is what you load when you want deeper detail on specific scenarios.

kiwi-browser-setup

Aufsetzen eines headless Chromium Browsers in einem Docker-Container auf ZimaOS für Web-Scraping und Automatisierung

server-environment-setup

Installing and configuring CLI tools, Python packages, and browsers on headless Linux servers with limited privileges (e.g., ZimaOS, CasaOS, NAS environments).

webhook-subscriptions

Webhook subscriptions: event-driven agent runs.

Use skill_view(name) to see full content, tags, and linked files


Question: browser OR chromium OR playwright OR selenium OR headless

Summary:
**Summary: Browser / Headless Chromium Topic**

**1. User's Intent**
The user (Ahmed Zeyd) was onboarding the Hermes Agent ("Kiwi") via Telegram and importing configuration details from his prior OpenClaw bot ("Monti"). As part of this data hand-off, he pasted a headless Chromium launch command that Monti had been using.

**2. Actions & Outcomes**
- **Hermes browser capabilities identified:** The loaded Hermes Agent documentation showed that Hermes supports a dedicated `browser` toolset for browser automation (backends: Browserbase, Camofox, or local Chromium) and an in-session slash command `/browser` to open a CDP (Chrome DevTools Protocol) browser connection.
- **Chromium command received:** The user provided Monti's headless Chromium startup command. The assistant attempted to check whether this process was still alive on the system by calling `execute_code`.
- **Check interrupted:** The `execute_code` call returned `status: "interrupted"` before producing results, because the user sent additional follow-up messages (media paths, container apps, secrets) that preempted the tool response.

**3. Key Technical Details**
- **Monti's headless Chromium command:**
  ```bash
  nohup chromium --headless --disable-gpu --no-sandbox --disable-dev-shm-usage \
    --remote-debugging-port=18800 --user-data-dir=/tmp/chromium-data \
    --disable-background-timer-throttling \
    --disable-backgrounding-occluded-windows \
    --disable-renderer-backgrounding > /tmp/chromium.log 2>&1 &
  ```
  This launched a headless Chromium instance with remote debugging exposed on port `18800`, logging to `/tmp/chromium.log`.
- **Hermes references:**
  - Toolset: `browser` — "Browser automation (Browserbase, Camofox, or local Chromium)"
  - Slash command: `/browser` — "Open CDP browser connection"
- **System context:** The host is ZimaOS Linux (`/DATA/AppData/hermes`). The assistant suspected the Chromium process might still be running and noted the media paths and logging location as useful for the user's YouTube workflow.

**4. Unresolved / Notable**
- It was **not confirmed** whether the headless Chromium process is actually still running; the verification was cut short by the interruption.
- The user did not ask to start, stop, or migrate the Chromium instance to Hermes; he only shared the command as part of Monti's config dump.
- No mention of **Playwright** or **Selenium** appeared in the transcript; Hermes' browser toolset appears to use CDP/local Chromium directly rather than via those frameworks.

Summary:
**Summary: Browser/Headless Chromium Skills Discussion**

**1. User’s Question**
After reviewing the list of 89 active skills, the user noticed two browser-related entries—`headless-browser-automation` and `kiwi-browser-setup`—and asked whether a browser capability had already existed before they “made one” during onboarding.

**2. Actions Taken & Explanation Given**
The assistant clarified the distinction between the two skills:

- **`headless-browser-automation`** (pre-existing) — A generic skill covering Playwright/Selenium automation on headless Linux systems (ZimaOS, CasaOS, NAS appliances, restricted containers). It described Docker-based Chromium, system-library fallbacks, and anti-detection setup in theoretical terms (e.g., suggesting `--no-sandbox` and generic paths like `/usr/bin/chromium`).
- **`kiwi-browser-setup`** (created during onboarding) — A ZimaOS-specific skill containing the exact, validated configuration for the user’s concrete environment. It included the real Docker run commands with precise volume/port mappings, the actual host path `/DATA/AppData/hermes/browser/`, and a specifically configured Stealth-Plugin for anti-detection.

**3. Key Conclusion**
The assistant established that the user did not invent a browser from scratch; rather, they tested and validated the generic `headless-browser-automation` approach against their actual system and saved the working result as a reusable, environment-specific skill (`kiwi-browser-setup`). The assistant recommended keeping both: the generic one as broad reference material and the Kiwi one as the guaranteed-working recipe for that exact ZimaOS box.

**4. Important Technical Details**
- **Generic path referenced in old skill:** `/usr/bin/chromium`
- **Actual validated path in new skill:** `/DATA/AppData/hermes/browser/`
- **Anti-detection:** The `kiwi-browser-setup` skill explicitly included the Stealth-Plugin configuration, whereas the generic skill only mentioned anti-detection setup abstractly.
- **Engine context:** The Hermes `config.yaml` showed the `browser` engine set to `auto` with `cdp_url: ''` and `camofox.managed_persistence: false`, and the `browser` toolset was enabled under `platform_toolsets` for CLI.

**5. Unresolved / Notable**
Nothing was left unresolved on this specific topic. The assistant offered to remove `kiwi-browser-setup` if the user preferred, but the user did not request deletion. No browser automation tasks were actually executed during this session; the discussion remained a conceptual clarification about the skill inventory.


Explanation: Der Benutzer möchte wissen, was ich zum Thema Browser gespeichert habe und wie er den nutzen kann. Ich habe 2 relevante Skills gefunden und 2 Session-Suchergebnisse. Ich sollte die Skills laden, um den aktuellen Stand zu zeigen.


kiwi-browser-setup

---
name: kiwi-browser-setup
description: Aufsetzen eines headless Chromium Browsers in einem Docker-Container auf ZimaOS für Web-Scraping und Automatisierung
trigger:
  - "browser"
  - "chromium"
  - "chrome"
  - "web scraping"
  - "headless browser"
  - "docker browser"
priority: high
---

# Kiwi Browser Setup

Auf ZimaOS (IceWhale) gibt es keinen Paketmanager und kein Desktop-Environment. Chromium/Chrome kann nicht nativ installiert werden. Die Lösung ist ein Debian-Docker-Container mit Chromium.

## Architektur

- **Host**: ZimaOS (ZimaCube) mit Docker
- **Container**: `kiwi-browser` (Debian Bookworm Slim)
- **Chromium**: Headless, `--no-sandbox`, `--disable-gpu`
- **API**: Flask HTTP-Server auf Port 3000 (extern 30000)
- **Protokoll**: JSON über HTTP POST

## Voraussetzungen

- Docker läuft auf ZimaOS
- User `az-a` hat sudo-Rechte für docker
- Port 30000 frei

## Setup-Schritte (automatisiert)

### 1. Debian-Container starten

```bash
sudo docker run -d --name kiwi-browser-setup debian:bookworm-slim sleep 3600
```

### 2. Chromium + Python installieren

```bash
sudo docker exec kiwi-browser-setup apt-get update -qq
sudo docker exec kiwi-browser-setup sh -c 'DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends chromium python3 python3-pip curl ca-certificates fonts-liberation && rm -rf /var/lib/apt/lists/*'
```

### 3. API-Server installieren

Kopiere das fertige Server-Script in den Container:

```bash
sudo docker cp ${HERMES_HOME:-/DATA/AppData/hermes}/skills/devops/kiwi-browser-setup/scripts/kiwi-browser-server.py kiwi-browser-setup:/app/server.py
```

oder manuell ein Python-Flask-Server mit Endpunkten:
- `GET /health` — Status
- `POST /visit` — Seite besuchen (JSON: `url`, `selector`)
- `POST /screenshot` — Screenshot (JSON: `url`)

### 4. Container committen & mit Port-Map starten

```bash
sudo docker stop kiwi-browser-setup
sudo docker commit kiwi-browser-setup kiwi-browser:v1
sudo docker rm kiwi-browser-setup
sudo docker run -d \
  --name kiwi-browser \
  --restart unless-stopped \
  -p 0.0.0.0:30000:3000 \
  kiwi-browser:v1 \
  bash -c 'cd /app && python3 server.py > /app/server.log 2>&1'
```

## Verwendung

### Health Check
```bash
curl -s http://127.0.0.1:30000/health
```

### Webseite besuchen
```bash
curl -s -X POST http://127.0.0.1:30000/visit \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com","selector":"price"}'
```

### Screenshot
```bash
curl -s -X POST http://127.0.0.1:30000/screenshot \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com"}' \
  | jq -r '.result.screenshot_base64' | base64 -d > screenshot.png
```

## Bekannte Limitierungen

| Limitierung | Ursache | Workaround |
|-------------|---------|------------|
| Amazon blockt | Harter Bot-Schutz (TLS-Fingerprint, Canvas-Fingerprint, IP-Rate-Limit, bot detection) | Nitter/Keepa/DuckDuckGo für Daten; Proxy mit `--proxy-server` in Chrome-Args |
| Kein echter Maus-Klick | Headless-Mode | JavaScript-Events simulieren |
| Kein Cookie-Persistenz | Container ist stateless | Docker-Volume mounten |
| Kein Proxy | Noch nicht konfiguriert | `--proxy-server` in Chrome-Args |

### ZimaOS-spezifische Probleme

| Problem | Warum | Lösung |
|---------|-------|--------|
| **ZimaOS hat keinen Paketmanager** | `apt`, `pacman`, `apk` fehlen | Docker-Container nutzen (Debian/Alpine) |
| **Docker Build funktioniert nicht** | Rootfs ist read-only, `/root/.docker` nicht beschreibbar | Fertiges Debian-Image pullen (nicht selbst bauen) |
| **GLIBC-Inkompatible bei Lib-Extraktion** | System-Libs neuer als Host | Container komplett isoliert sein lassen |
| **Chrom(e/ium) läuft nicht nativ** | `libatk`, `libgtk`, `X11` fehlen | Headless-Chromium im Container mit `--no-sandbox` |

## Fehlerbehebung

### Container läuft nicht
```bash
sudo docker logs kiwi-browser --tail 20
```

### Chromium crasht
```bash
sudo docker exec kiwi-browser chromium --version
```
Wenn `GLIBC` Fehler → Image neu bauen (neueres Debian).

### Port nicht erreichbar
```bash
sudo docker ps | grep kiwi-browser
ss -tlnp | grep 30000
```

## Wichtige Dateien

| Datei | Pfad |
|-------|------|
| Container-Image | `kiwi-browser:v1` |
| API-Server | `/app/server.py` im Container |
| Logs | `/app/server.log` im Container |
| Cache | `/DATA/AppData/hermes/browser/` (Host) |

## Erweiterungen (geplant)

- Proxy-Unterstützung für IP-Rotation
- Cookie-Persistenz über Docker-Volume
- Playwright statt Flask für komplexere Aktionen
- Mehrere Browser-Instanzen für Parallelität

To view linked files, call skill_view(name, file_path) where file_path is e.g. 'references/api.md' or 'assets/config.yaml'


headless-browser-automation

---
name: headless-browser-automation
title: Browser Automation on Headless Servers
category: devops
description: Running real browser automation (Playwright, Selenium) on headless Linux systems that lack desktop libraries, package managers, or writable system paths — common on ZimaOS, CasaOS, NAS appliances, and restricted containers. Covers Docker-based Chromium, system-library fallbacks, and anti-detection setup.
tags: [browser, automation, playwright, docker, headless, zimaos, casaos]
---

# Browser Automation on Headless Servers

## When to use
The system has no `apt`, `pacman`, or `apk`, and Playwright's bundled Chromium fails with `libatk-1.0.so.0: cannot open shared object file` or similar. Or `docker` is available but the user is not in the `docker` group.

## 1. Check system reality first
```bash
# Which package manager exists?
which apt-get || which pacman || which apk || which dnf || echo 'NONE'

# Are desktop libs present?
ldconfig -p | grep libatk
ldconfig -p | grep libgtk

# Docker access?
docker ps 2>&1 | head -1
```

**If a package manager exists:** Install missing libs with it and use Playwright normally.

**If no package manager exists:** Go to Docker approach (section 2).

## 2. Dockerized Chromium for ZimaOS/CasaOS (recommended)

When the host OS has **no package manager** (no apt/pacman/apk) and a **read-only root filesystem** (docker build fails), the robust approach is to start a minimal Debian container, install Chromium inside it, and expose the browser as an HTTP API.

### The "Debian Container Build-Up" method (works when upstream images fail)
```bash
# 1. Start a Debian container that stays alive
sudo docker run -d --name browser-build debian:bookworm-slim sleep 3600

# 2. Update and install Chromium + Python inside the container
sudo docker exec browser-build apt-get update -qq
sudo docker exec browser-build apt-get install -y -qq --no-install-recommends chromium python3 curl

# 3. Verify Chromium works inside the container
sudo docker exec browser-build chromium --version

# 4. Commit the container to a local image
sudo docker stop browser-build
sudo docker commit browser-build kiwi-browser:v1
sudo docker rm browser-build

# 5. Start the committed image with port mapping + auto-restart
sudo docker run -d \
  --name kiwi-browser \
  --restart unless-stopped \
  -p 0.0.0.0:30000:3000 \
  kiwi-browser:v1 \
  bash -c 'cd /app && python3 server.py'
```

**Why this works on ZimaOS:** It avoids `docker build` (needs writable `/root/.docker`) and avoids pulling large upstream images that may timeout or have unavailable tags. Debian slim is ~30MB and pulls reliably. Everything happens inside the container.

### Quick alternative: Pull upstream image (if network is fast)
```bash
# Use the official Playwright image
docker run -d \
  --name playwright-browser \
  --network host \
  -p 9222:9222 \
  -e DISPLAY=:99 \
  mcr.microsoft.com/playwright:v1.59.0-jammy \
  bash -c "cd /ms-playwright && npx playwright-core launch-server chromium --port=9222 --ws-path=/"
```

### Connect from Python / Agent
```python
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    # Connect to remote browser in Docker
    browser = p.chromium.connect_over_cdp("http://localhost:9222")
    page = browser.new_page()
    page.goto("https://example.com")
    page.screenshot(path="screenshot.png")
    browser.close()
```

### Alternative: CDP connection (raw)
```python
import requests

# Start Chrome/CDP in container with --remote-debugging-port=9222
# Then connect via websocket or HTTP:
r = requests.get("http://localhost:9222/json/version")
print(r.json())
```

## 3. Anti-detection setup
Regardless of where Chromium runs, mask automation flags:

```python
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(
        headless=True,
        args=[
            '--no-sandbox',
            '--disable-gpu',
            '--disable-dev-shm-usage',
            '--disable-blink-features=AutomationControlled',
            '--disable-web-security',
            '--window-size=1920,1080',
        ]
    )
    context = browser.new_context(
        viewport={'width': 1920, 'height': 1080},
        user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0 Safari/537.36',
        locale='de-DE',
    )
    page = context.new_page()
    page.add_init_script('''
        Object.defineProperty(navigator, 'webdriver', {get: () => undefined});
        Object.defineProperty(navigator, 'plugins', {get: () => [1,2,3,4,5]});
        window.chrome = { runtime: {} };
    ''')
```

## 4. User-permission prerequisites
The agent user must either:
- Be in the `docker` group: `sudo usermod -aG docker az-a` (then re-login)
- Or have explicit `NOPASSWD` sudo for `docker`: add `/usr/bin/docker` to sudoers

## Pitfalls
- **ZimaOS has no package manager.** `apt-get`, `pacman`, `apk` are all absent. Do not waste time trying to install system libraries on the host.
- **ZimaOS rootfs is read-only.** `docker build` fails because `/root/.docker` cannot be written. Work around this by running a Debian container, installing packages inside it, and committing it: `docker run -d debian:bookworm-slim sleep 3600`, then `docker exec <id> apt-get install chromium`, then `docker commit`.
- **Playwright's bundled Chromium expects Ubuntu-like libs.** On stripped-down NAS OS, it will always fail with missing `.so` files.
- **Docker group membership requires re-login.** After `usermod -aG docker`, the user must open a new shell session.
- **Browserless services may need memory limits.** Chromium in Docker uses 200-400 MB baseline; restrict with `--memory=512m` if the NAS is tight.
- **Screenshots accumulate fast.** Always write to `/DATA/AppData/hermes/cache/` or similar, and clean up periodically.
- **Amazon DE aggressively blocks headless Chromium** even inside a container. Expect "Page Not Found" on product pages. Use the API for sites with lighter bot detection, or add proxy rotation (not covered here).

## Verification checklist
- [ ] Docker accessible (`docker ps` works)
- [ ] Container starts without port conflict
- [ ] `curl http://localhost:30000/health` returns `{"status": "ok"}` (or equivalent for your chosen port)
- [ ] Screenshot or scrape from target site succeeds
- [ ] Anti-detection script injected (`navigator.webdriver` is undefined)

## Session-specific reference
- `references/kiwi-browser-api-recipe.md` — exact reproduction recipe for the Docker-based Chromium HTTP API built on ZimaOS during session 2026-05-07.
- `templates/kiwi-browser-server.py` — the Flask-style HTTP server that runs inside the container to expose Chromium as `POST /visit` and `POST /screenshot`.


Explanation: Zeyd fragt nach allem, was ich zum Browser gespeichert habe, und wie wir den nutzen können. Ich habe jetzt beide Skills geladen und die Session-Suchergebnisse. Lass mich die Server-Script-Datei auch noch anschauen, da die Skills darauf verweisen.


kiwi-browser-setup

#!/usr/bin/env python3
"""
Kiwi Browser API Server — läuft im Debian-Docker-Container.
Headless Chromium wrapper mit HTTP-Endpunkten für Web-Scraping.

Start im Container:
    cd /app && python3 kiwi-browser-server.py

API:
    GET  /health              → Status
    POST /visit               → Seite besuchen + Text extrahieren
    POST /screenshot          → Screenshot als Base64
"""

import subprocess, json, base64, os, tempfile, re
from http.server import HTTPServer, BaseHTTPRequestHandler

BROWSER = os.environ.get("CHROME_BIN", "/usr/bin/chromium")

def safe_json_response(data):
    return json.dumps(data, ensure_ascii=False).encode()

class Handler(BaseHTTPRequestHandler):
    def log_message(self, format, *args):
        pass

    def do_GET(self):
        if self.path == '/health':
            self.send_response(200)
            self.send_header('Content-type', 'application/json')
            self.end_headers()
            self.wfile.write(safe_json_response({
                "status": "ok",
                "browser": BROWSER,
                "version": self._chrome_version()
            }))
        else:
            self.send_response(404)
            self.end_headers()

    def do_POST(self):
        content_length = int(self.headers.get('Content-Length', 0))
        body = self.rfile.read(content_length) if content_length else b'{}'
        try:
            data = json.loads(body.decode())
        except:
            data = {}

        if self.path == '/visit':
            self.handle_visit(data)
        elif self.path == '/screenshot':
            self.handle_screenshot(data)
        else:
            self.send_response(404)
            self.end_headers()

    def _chrome_version(self):
        try:
            r = subprocess.run([BROWSER, "--version"], capture_output=True, text=True, timeout=5)
            return r.stdout.strip()
        except:
            return "unknown"

    def handle_visit(self, data):
        url = data.get('url', 'https://example.com')
        selector = data.get('selector', None)
        wait = data.get('wait', 'networkidle')

        cmd = [
            BROWSER, '--headless', '--no-sandbox', '--disable-gpu',
            '--disable-dev-shm-usage', '--disable-background-networking',
            '--window-size=1920,1080', '--timeout=20000',
            '--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
            '--dump-dom', url
        ]

        try:
            result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
            html = result.stdout[:15000]

            extracted = None
            if selector:
                patterns = [
                    rf'class="[^"]*{re.escape(selector)}[^"]*"[^>]*>([^<]+)',
                    rf'id="{re.escape(selector)}"[^>]*>([^<]+)',
                    rf'<[^>]*class="[^"]*price[^"]*"[^>]*>([^<]+)',
                ]
                for pat in patterns:
                    m = re.search(pat, html, re.I | re.DOTALL)
                    if m:
                        extracted = re.sub(r'<[^>]+>', '', m.group(1)).strip()
                        break

            self.json_response({
                "success": result.returncode == 0,
                "url": url,
                "title": self._extract_title(html),
                "html_preview": html[:3000],
                "extracted": extracted,
                "error": result.stderr[:500] if result.returncode != 0 else None
            })
        except Exception as e:
            self.json_response({"success": False, "error": str(e)}, 500)

    def _extract_title(self, html):
        m = re.search(r'<title>(.*?)</title>', html, re.I | re.DOTALL)
        return re.sub(r'\s+', ' ', m.group(1)).strip() if m else None

    def handle_screenshot(self, data):
        url = data.get('url', 'https://example.com')
        full_page = data.get('full_page', False)

        with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as f:
            out_path = f.name

        cmd = [
            BROWSER, '--headless', '--no-sandbox', '--disable-gpu',
            '--disable-dev-shm-usage', '--window-size=1920,1080',
            f'--screenshot={out_path}', url
        ]
        if full_page:
            cmd.append('--hide-scrollbars')

        try:
            result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)

            if os.path.exists(out_path) and os.path.getsize(out_path) > 0:
                with open(out_path, 'rb') as f:
                    img = base64.b64encode(f.read()).decode()
                os.unlink(out_path)
                self.json_response({"success": True, "screenshot_base64": img, "url": url})
            else:
                self.json_response({"success": False, "error": "no screenshot", "stderr": result.stderr[:200]}, 500)
        except Exception as e:
            self.json_response({"success": False, "error": str(e)}, 500)

    def json_response(self, data, status=200):
        self.send_response(status)
        self.send_header('Content-type', 'application/json')
        self.send_header('Access-Control-Allow-Origin', '*')
        self.end_headers()
        self.wfile.write(safe_json_response(data))

if __name__ == '__main__':
    import sys
    host = os.environ.get('HOST', '0.0.0.0')
    port = int(os.environ.get('PORT', 3000))
    server = HTTPServer((host, port), Handler)
    print(f"Kiwi Browser API running on http://{host}:{port}", flush=True)
    server.serve_forever()


Hier ist alles komprimiert:

## Was gespeichert ist

**1. `kiwi-browser-setup`** — Dein ZimaOS-spezifischer Browser im Docker-Container.
**2. `headless-browser-automation`** — Generischer Fallback-Skill (Playwright etc.).

## Architektur

Auf ZimaOS gibt es keinen Paketmanager. Chromium läuft daher in einem Debian-Docker-Container mit einem Flask-API-Server.

| Komponente | Was |
|---|---|
| Container | `kiwi-browser` (Debian Bookworm Slim) |
| Browser | Headless Chromium `--no-sandbox` |
| API | HTTP auf Port `30000` (intern `3000`) |
| Endpunkte | `GET /health`, `POST /visit`, `POST /screenshot` |

## Aktueller Status — prüfen wir jetzt

Lass mich schauen, ob der Container momentan läuft:

Explanation:
So der User fragt auf Deutsch nach allem, was ich zu Browsern gespeichert habe, und wie wir ihn nutzen können.

Ich habe jetzt alle relevanten Infos geladen:
1. `kiwi-browser-setup` - Der spezifische ZimaOS-Browser-Skill, den wir während des Onboardings erstellt haben
2. `headless-browser-automation` - Der generische Skill für headless Browser
3. `scripts/kiwi-browser-server.py` - Der Server-Script, der im Container läuft
4. Session-Suchergebnisse mit Kontext über Monti's alten Chromium-Befehl

Ich sollte alles kompakt zusammenfassen, auf Deutsch, kurz und effizient (User mag keine langen Texte).

terminal

sudo docker ps | grep -E 'kiwi-browser|browser' || echo 'Kein Browser-Container aktiv'


Output: 2796c75be669   kiwi-browser:v1                                                  "bash -c 'cd /app &&…"   36 hours ago   Up 36 hours             0.0.0.0:30000->3000/tcp                                                                          kiwi-browser


Läuft. Health-Check:

Explanation: Der Container läuft seit 36 Stunden. Jetzt prüfe ich, ob die API erreichbar ist.


Output:
{
  "status": "ok",
  "browser": "/usr/bin/chromium"
}


**Läuft seit 36h, alles gesund.**

## Was du damit machen kannst

**1. Screenshots für Thumbnails/Videos**
```bash
curl -s -X POST http://127.0.0.1:30000/screenshot \
  -H "Content-Type: application/json" \
  -d '{"url":"https://deine-webseite.com"}' \
  | jq -r '.screenshot_base64' | base64 -d > thumbnail.png
```

**2. Webseite besuchen + Text/Preise extrahieren**
```bash
curl -s -X POST http://127.0.0.1:30000/visit \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com","selector":"price"}'
```

**3. Direkt über Kiwi (mich)** — Ich kann das selbst aufrufen, z.B.:
- "Mach einen Screenshot von youtube.com"
- "Lies mir den Text von dieser Webseite"

## Für deine YouTube-Pläne konkret

| Anwendung | Wie |
|---|---|
| Thumbnail-Vorlagen | Screenshots von Design-Tools |
| Webseiten-Content scrapen | Für Recherche/Script-Basis |
| Automatisiert hochladen | YouTube Studio im Browser steuern (experimentell) |

## Bekannte Limits

- **Amazon blockt hart** — Bot-Schutz
- **Keine echten Maus-Klicks** — nur JavaScript-Events
- **Container ist stateless** — Cookies verschwinden beim Neustart

Soll ich was konkretes testen? Screenshot von einer Seite, oder ein Script für YouTube-Automatisierung bauen?

Explanation:
Der Browser läuft und ist gesund. Jetzt kann ich dem User erklären, was er damit machen kann.

Die wichtigsten Nutzungsmöglichkeiten:
1. Website besuchen + Inhalt extrahieren (Text, Preise, etc.)
2. Screenshots machen
3. Für YouTube/Thumbnails: Visuals generieren (indirekt)
4. Web-Scraping allgemein

Ich sollte kurz und prägnant bleiben - der User mag keine langen Texte.


Wie schaffen wir es, dass du echte Mais Klicks machen kannst


Explanation:
Der User fragt auf Deutsch: "Wie schaffen wir es, dass du echte Maus Klicks machen kannst" - er meint "echte Maus-Klicks" (er hat "Mais" statt "Maus" geschrieben, aber Kontext ist klar).

Das ist eine technische Frage über Browser-Automatisierung. Ich soll die relevanten Skills laden, insbesondere die Browser-Skills, um eine fundierte Antwort zu geben.

Ich habe bereits die Skills `kiwi-browser-setup` und `headless-browser-automation` geladen. Lass mich nochmal prüfen, ob es weitere relevante Skills gibt, z.B. `playwright`, `selenium`, etc.

Aber eigentlich ist die Antwort relativ straightforward: Um echte Maus-Klicks zu machen, brauchen wir entweder:
1. Einen Browser mit echtem Display (nicht headless) + X11/Virtual Display + Maus-Klick-Simulation
2. Playwright/Selenium statt dem aktuellen Chromium-CLI-Ansatz
3. Evtl. ein Docker-Image mit Playwright oder Selenium + VNC

Der aktuelle `kiwi-browser` nutzt Chromium headless mit `--dump-dom` und `--screenshot` über die Kommandozeile. Das ist kein echter Browser-Prozess mit einer Seite, die interaktiv bedient wird - es ist ein one-shot Aufruf.

Um echte Maus-Klicks zu machen, brauchen wir:
- Einen laufenden Chromium-Prozess mit remote debugging (CDP)
- Playwright, das sich via CDP oder WebSocket verbindet
- Oder Selenium WebDriver
- Und dann `page.click()` oder `page.mouse.click()`

Auf ZimaOS (headless, kein X11) brauchen wir zusätzlich:
- Einen virtuellen Display (Xvfb)
- Oder Chrome in headless mode mit Playwright (Playwright kann auch headless, aber die Klicks sind dann "echt" im Sinne von DOM-Events, nicht unbedingt Maus-Cursor-Bewegungen)

Warte, der User fragt nach "echte Maus Klicks". Das ist ein bisschen mehrdeutig:
1. "Echte" DOM-Events (nicht nur JavaScript `element.click()`)
2. Oder tatsächliche Maus-Cursor-Bewegung und Klick wie ein Mensch

Für YouTube-Upload etc. brauchen wir wahrscheinlich beides.

Lass mich die Skills nochmal anschauen und vielleicht die referenzierten Dateien laden. Ich habe schon `kiwi-browser-setup` und `headless-browser-automation` geladen. Lass mich die `references/kiwi-browser-api-recipe.md` und `scripts/kiwi-browser-server.py` von `headless-browser-automation` auch laden, um zu sehen, ob es Playwright-Varianten gibt.

Aber warte - ich sollte zuerst die Skills prüfen, die noch nicht geladen sind. Gibt es `playwright` oder `selenium` als Skills? Ich habe `headless-browser-automation` gesehen, der erwähnt Playwright.

Lass mich auch die `headless-browser-automation` referenzierte Dateien laden.

Aber bevor ich das tue: Der User will eine konkrete Lösung. Ich sollte nicht zu lange recherchieren, sondern eine direkte Antwort geben.

Zusammenfassung der Optionen für ZimaOS:

**Option A: Playwright im Docker-Container (empfohlen)**
- Playwright hat eingebautes Chromium mit allen Libs
- Headless funktioniert, Klicks sind DOM-echt
- Für "visuelle" Klicks braucht man Xvfb + VNC oder Video-Aufnahme
- Playwright simuliert Klicks auf Koordinaten mit Easing/Pause wie Mensch

**Option B: Selenium + WebDriver**
- Ähnlich, aber schwerfälliger

**Option C: Erweiterung des aktuellen kiwi-browser-server.py**
- Statt `subprocess.run(chromium --dump-dom)` einen persistenten Chromium-Prozess starten
- CDP (Chrome DevTools Protocol) verwenden
- Via CDP Maus-Klicks senden

**Option D: Puppeteer/Playwright direkt im Container**
- Beste Lösung für YouTube-Upload etc.

Der aktuelle Container läuft bereits seit 36h. Ich sollte vorschlagen, ein neues Image zu bauen oder den bestehenden zu erweitern.

Warte, ich habe den `kiwi-browser-server.py` schon gelesen. Der startet Chromium als one-shot Prozess. Um echte Interaktion zu haben, müssen wir auf Playwright oder Puppeteer umsteigen.

Lass mich die `headless-browser-automation` Referenzen laden.


headless-browser-automation

# Kiwi Browser API — Session Recipe (May 7, 2026)

This is the exact working setup built during the session. It runs Chromium inside a Debian Docker container on ZimaOS (which has no package manager and a read-only rootfs).

## One-liner setup

```bash
# Run this from the server shell (or via Hermes terminal)
sudo docker run -d --name kiwi-browser --restart unless-stopped \
  -p 0.0.0.0:30000:3000 \
  kiwi-browser:v1 \
  bash -c 'cd /app && python3 server.py > /app/server.log 2>&1'
```

## What the setup gives you

- Chromium 148+ running inside Debian Bookworm container
- HTTP API on `http://127.0.0.1:30000`
- Health endpoint, page visit, screenshot capture

## API endpoints

### GET /health
```bash
curl http://localhost:30000/health
# → {"status": "ok", "browser": "/usr/bin/chromium"}
```

### POST /visit
```bash
# Visit a page
DATA=$(printf '%s' '{"url": "https://www.amazon.de/dp/B0CRLJ9V5L", "selector": "a-offscreen"}')
curl -X POST http://localhost:30000/visit \
  -H "Content-Type: application/json" \
  -d "$DATA"
```

**Response fields:**
- `success` — boolean, true if page loaded
- `title` — page title
- `html_preview` — first 2000 chars of HTML
- `extracted` — text matching the optional selector
- `error` — stderr if Chromium failed

### POST /screenshot
```bash
# Screenshot a page
DATA=$(printf '%s' '{"url": "https://www.amazon.de/dp/B0CRLJ9V5L"}')
RESULT=$(curl -s -X POST http://localhost:30000/screenshot \
  -H "Content-Type: application/json" \
  -d "$DATA")

# Extract and save base64 image
echo "$RESULT" | python3 -c 'import json, sys, base64; d=json.load(sys.stdin); open("/tmp/screenshot.png","wb").write(base64.b64decode(d["screenshot_base64"]))'
```

## How to build the Kiwi-Browser image from scratch

```bash
# Step 1: Pull Debian slim (reliable, ~30MB)
sudo docker run -d --name browser-build debian:bookworm-slim sleep 3600

# Step 2: Install Chromium + Python
sudo docker exec browser-build apt-get update -qq
sudo docker exec browser-build apt-get install -y -qq --no-install-recommends chromium python3

# Step 3: Verify
sudo docker exec browser-build chromium --version

# Step 4: Add the Python API server (server.py must be built first)
# See templates/kiwi-browser-server.py
sudo docker cp kiwi-browser-server.py browser-build:/app/server.py

# Step 5: Commit to local image
sudo docker stop browser-build
sudo docker commit browser-build kiwi-browser:v1
sudo docker rm browser-build
```

## Known limits

- Amazon DE blocks headless Chromium aggressively (returns "Page Not Found" or captcha).
- YouTube works for basic page loads but heavy JS may need longer timeouts.
- The container needs `--restart unless-stopped` or a systemd/Cron restart rule.

## ZimaOS prerequisites

- User `az-a` must have `sudo` privileges for `docker` commands.
- The `docker` binary must be usable: `sudo usermod -aG docker az-a` (then re-login).


#!/usr/bin/env python3
"""
Kiwi Browser API server — runs inside a Docker container with Chromium.
Provides /health, /visit, and /screenshot endpoints over HTTP.

Place this at /app/server.py inside a Debian container that has chromium
and python3 installed. Then start with:
    python3 /app/server.py

The container must expose port 3000.
"""

import subprocess, json, base64, os, tempfile, re
from http.server import HTTPServer, BaseHTTPRequestHandler

BROWSER = "/usr/bin/chromium"

def clean_json(data):
    return json.dumps(data).encode()

class Handler(BaseHTTPRequestHandler):
    def log_message(self, fmt, *args):
        # Suppress stdout noise
        pass

    def _send_json(self, data, status=200):
        self.send_response(status)
        self.send_header("Content-Type", "application/json")
        self.end_headers()
        self.wfile.write(clean_json(data))

    def do_GET(self):
        if self.path == "/health":
            self._send_json({"status": "ok", "browser": BROWSER})
        else:
            self.send_response(404)
            self.end_headers()

    def do_POST(self):
        length = int(self.headers.get("Content-Length", 0))
        body = self.rfile.read(length) if length else b"{}"
        try:
            data = json.loads(body.decode())
        except Exception:
            data = {}

        if self.path == "/visit":
            self._visit(data)
        elif self.path == "/screenshot":
            self._screenshot(data)
        else:
            self.send_response(404)
            self.end_headers()

    def _extract_title(self, html: str) -> str | None:
        m = re.search(r'<title>(.*?)</title>', html, re.IGNORECASE | re.DOTALL)
        return re.sub(r'\s+', ' ', m.group(1)).strip() if m else None

    def _visit(self, data):
        url = data.get("url", "https://example.com")
        selector = data.get("selector", None)

        cmd = [
            BROWSER,
            "--headless",
            "--no-sandbox",
            "--disable-gpu",
            "--disable-dev-shm-usage",
            "--window-size=1920,1080",
            "--timeout=20000",
            "--dump-dom",
            url,
        ]

        try:
            result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
            html = result.stdout[:10000]

            extracted = None
            if selector:
                patterns = [
                    rf'class="[^"]*{re.escape(selector)}[^"]*"[^>]*>([^<]+)',
                    rf'id="{re.escape(selector)}"[^>]*>([^<]+)',
                    rf'<[^>]*class="[^"]*price[^"]*"[^>]*>([^<]+)',
                ]
                for pat in patterns:
                    m = re.search(pat, html, re.IGNORECASE | re.DOTALL)
                    if m:
                        extracted = re.sub(r'<[^>]+>', '', m.group(1)).strip()
                        break

            self._send_json({
                "success": result.returncode == 0,
                "url": url,
                "title": self._extract_title(html),
                "html_preview": html[:2000],
                "extracted": extracted,
                "error": result.stderr[:500] if result.returncode != 0 else None,
            })
        except Exception as exc:
            self._send_json({"success": False, "error": str(exc)}, 500)

    def _screenshot(self, data):
        url = data.get("url", "https://example.com")

        with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
            out_path = tmp.name

        cmd = [
            BROWSER,
            "--headless",
            "--no-sandbox",
            "--disable-gpu",
            "--disable-dev-shm-usage",
            "--window-size=1920,1080",
            f"--screenshot={out_path}",
            url,
        ]

        try:
            result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
            if os.path.exists(out_path):
                with open(out_path, "rb") as img:
                    b64 = base64.b64encode(img.read()).decode()
                os.unlink(out_path)
                self._send_json({"success": True, "screenshot_base64": b64, "url": url})
            else:
                self._send_json(
                    {"success": False, "error": "no screenshot", "stderr": result.stderr[:200]},
                    500,
                )
        except Exception as exc:
            self._send_json({"success": False, "error": str(exc)}, 500)

if __name__ == "__main__":
    server = HTTPServer(("0.0.0.0", 3000), Handler)
    server.serve_forever()


Der aktuelle Server kann nur Seiten laden (`--dump-dom`) und Screenshots machen — **keine Interaktion**. Für echte Maus-Klicks brauchen wir eine richtige Browser-Steuerung, nicht nur Chromium als Kommandozeilen-Tool.

Beste Lösung für ZimaOS: **Playwright** im laufenden Container. Playwright erzeugt echte native Input-Events (Maus, Tastatur, Scroll) und maskiert Automation-Detection.

Ich baue das jetzt. Zuerst teste ich, ob Playwright im Container installierbar ist:

Explanation:
Der Benutzer fragt, wie wir echte Mausklicks simulieren können ("Mais Klicks" ist wahrscheinlich "Maus Klicks" mit Autokorrektur/Speech-to-Text). Der aktuelle Browser-Server macht nur `chromium --dump-dom` und `--screenshot` - das ist sehr basic und kann keine echte Interaktion.

Um echte Mausklicks zu machen, brauchen wir:
1. Einen Browser mit einer richtigen Automatisierungs-Engine (Playwright, Selenium, oder CDP/Chrome DevTools Protocol)
2. Nicht nur `--dump-dom`, sondern eine laufende Browser-Instanz die wir fernsteuern können
3. Anti-Detection (Stealth-Plugin, headless-mode maskieren)

Die Optionen sind:

**Option A: Playwright im Container**
- Playwright hat `page.click()`, `page.fill()`, etc.
- Aber es braucht Node.js oder Python mit Playwright installiert
- Auf ZimaOS im Docker-Container umsetzbar

**Option B: CDP (Chrome DevTools Protocol)**
- Chromium mit `--remote-debugging-port=9222` starten
- Dann über HTTP/WebSocket Befehle schicken
- Direkt im Browser ausführen: `Runtime.evaluate` für JavaScript, `Input.dispatchMouseEvent` für Klicks
- Das ist elegant, weil es mit dem vorhandenen Chromium funktioniert

**Option C: Selenium**
- Ähnlich wie Playwright aber schwerer

**Empfehlung: CDP (Chrome DevTools Protocol)**
- Wir haben schon Chromium im Container
- Wir müssen nur den Start-Command ändern: `--remote-debugging-port=9222` hinzufügen
- Dann einen kleinen Python-Client schreiben, der CDP-Befehle schickt
- Das ist leichtgewichtig und braucht keine extra Dependencies außer `requests` und `websocket-client`

Aber wait - der aktuelle Container läuft mit `bash -c 'cd /app && python3 server.py'` und der Server startet Chromium per `subprocess.run()` mit `--dump-dom`. Das startet Chromium neu für jeden Request und beendet es danach. Für CDP brauchen wir einen dauerhaft laufenden Chromium-Prozess mit `--remote-debugging-port`.

Also brauchen wir:
1. Den Container so umbauen, dass Chromium als Service läuft (nicht nur per Request)
2. Einen neuen API-Server, der über CDP mit dem laufenden Chromium spricht
3. Endpunkte für: `click`, `type`, `scroll`, `screenshot`, `goto`

Oder wir bauen einen komplett neuen Server, der Playwright nutzt. Aber Playwright braucht viel mehr Speicher und Dependencies.

CDP-Approach ist besser für ZimaOS:
- Reuse bestehendes Chromium
- Wenig Overhead
- Echte Maus-Events über `Input.dispatchMouseEvent`

Lass mich dem Benutzer die Optionen erklären und dann den besseren Server bauen. Der Benutzer will kurze Antworten - also direkt zum Punkt.

Der Plan:
1. Aktuellen Container stoppen
2. Neuen Container bauen mit dauerhaft laufendem Chromium + CDP
3. Neuen Python-Server mit CDP-Client
4. Endpunkte: `/goto`, `/click`, `/type`, `/screenshot`, `/scroll`

Aber der Benutzer fragt "wie schaffen wir es" - ich sollte erstmal die Strategie erklären (kurz) und dann fragen ob er will dass ich es baue, oder direkt bauen. Er sagte "figure-it-out philosophy - test 3+ approaches before asking". Also sollte ich es direkt bauen.

Aber der aktuelle Container läuft. Ich sollte vorsichtig sein. Lass mich einen Plan machen und ausführen.

Aktueller Container: `kiwi-browser:v1` läuft, basiert auf Debian mit Chromium + Python.

Strategie:
- Neuen Container-Image bauen: `kiwi-browser-v2`
- Darin: Chromium läuft als Hintergrundprozess mit `--remote-debugging-port=9222`
- Flask/FastAPI-Server (oder einfacher HTTP-Server) der CDP-Befehle schickt
- Endpunkte für echte Interaktion

Warte, Python hat kein `websocket` standardmäßig. Wir brauchen `python3-websockets` oder `websocket-client`. Oder wir nutzen `requests` für HTTP-CDP (es gibt auch HTTP-Endpoints bei CDP).

CDP über HTTP:
- `http://localhost:9222/json` - Liste der Tabs
- `http://localhost:9222/json/new?https://...` - Neue Tab öffnen
- `ws://localhost:9222/devtools/page/<id>` - WebSocket für Befehle
- Wir können auch JavaScript über die HTTP-API ausführen: nicht direkt, aber über WS.

Alternative: Puppeteer/Playwright im Container. Aber das braucht Node.js/npm.

Besser: `selenium` oder `playwright` Python packages installieren im Container. Aber das ist schwerer.

Noch besser: Ein kleiner CDP-Wrapper in Python. Ich kann `websocket-client` via pip installieren oder Debian-Paket `python3-websockets`.

Schauen wir was im Container verfügbar ist: Debian Bookworm. `python3-websockets` ist als Paket verfügbar (`apt-get install python3-websockets`). Oder `pip install websocket-client --break-system-packages` (nicht empfohlen aber in Container ok).

Oder noch einfacher: Wir nutzen `curl` + Chrome's Debug Protocol über HTTP wo möglich, und für Klicks nutzen wir JavaScript-Injection (was fast gleichwertig ist zu echten CDP-Maus-Events).

Warte, der Benutzer fragt nach "echten Maus-Klicks". CDP `Input.dispatchMouseEvent` ist echt aus Browser-Sicht (es geht durch den Input-Stack des Renderers). JavaScript `element.click()` ist ebenfalls echt für die Webseite, aber manche Seiten erkennen den Unterschied (z.B. weil kein `isTrusted` Event).

CDP `Input.dispatchMouseEvent` erzeugt ein `isTrusted=true` Event! Das ist der Goldstandard.

Also brauchen wir definitiv CDP mit WebSocket.

Plan:
1. Prüfen ob `python3-websockets` im Container verfügbar ist
2. Neuen Server schreiben der:
   - Chromium als Child-Prozess startet mit `--remote-debugging-port=9222`
   - CDP-WebSocket-Verbindung hält
   - HTTP-Endpunkte für Actions bereitstellt

Aber warten - der aktuelle Server ist ein simpler HTTP-Server. Der startet Chromium pro Request. Wenn wir CDP machen wollen, sollten wir Chromium dauerhaft laufen lassen. Das bedeutet entweder:
a) Der Python-Server startet Chromium beim Start und hält ihn am Leben
b) Chromium läuft als separater Prozess im Container, der Server connectet zu ihm

Option (a) ist besser weil alles in einem Prozess ist.

CDP Python-Client selbst bauen:
```python
import asyncio, websockets, json, requests

async def cdp_click(ws_url, x, y):
    async with websockets.connect(ws_url) as ws:
        # enable input
        await ws.send(json.dumps({"id": 1, "method": "Input.enable"}))
        # dispatch mouse event
        await ws.send(json.dumps({
            "id": 2,
            "method": "Input.dispatchMouseEvent",
            "params": {
                "type": "mousePressed",
                "x": x, "y": y,
                "button": "left",
                "clickCount": 1
            }
        }))
        await ws.send(json.dumps({
            "id": 3,
            "method": "Input.dispatchMouseEvent",
            "params": {
                "type": "mouseReleased",
                "x": x, "y": y,
                "button": "left",
                "clickCount": 1
            }
        }))
```

Das ist machbar.

Aber noch einfacher: Es gibt ein kleines Python-Modul `chromedp` oder `pycdp`? Oder `PyChromeDevToolsProtocol`. Aber die sind nicht standardmäßig installiert. Wir können sie aber via pip installieren.

Im Container: `pip install PyChromeDevToolsProtocol` oder `pip install chromote`?

Lass mich prüfen was im aktuellen Container schon da ist und was geht.

Aber vielleicht ist es noch einfacher: **Playwright** ist die modernste Lösung und "Just Works". Der Nachteil: Es braucht `playwright install chromium` was viel Speicher braucht. Aber wir haben bereits Chromium installiert! Wir können Playwright mit `executable_path` auf `/usr/bin/chromium` zeigen.

Playwright Python im Container:
```bash
pip install playwright
# playwright install chromium  -- NICHT nötig wenn wir executable_path setzen
```

Dann im Code:
```python
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(
        executable_path="/usr/bin/chromium",
        headless=True,
        args=['--no-sandbox', '--disable-gpu']
    )
    page = browser.new_page()
    page.goto("https://...")
    page.click("#button")
    page.screenshot(path="...")
```

Das ist extrem einfach und Playwright erzeugt echte, native Input-Events (Maus, Tastatur). Es ist quasi der Industriestandard.

Aber: Der aktuelle Server startet pro Request einen neuen Browser. Das ist ineffizient. Besser: Browser-Pool oder Browser pro Session.

Also der richtige Weg:
1. **Neuen API-Server bauen** mit Playwright im Container
2. **Browser-Instanz wiederverwenden** (persistent über mehrere Requests)
3. **Endpunkte**: `/start_session`, `/goto`, `/click`, `/type`, `/screenshot`, `/close_session`

Oder noch einfacher: Ein einzelner dauerhafter Browser, der für alle Requests genutzt wird (aber mit neuen Contexten/Seiten für Isolation).

ZimaOS-Server hat begrenzten RAM. Ein Chromium-Prozess braucht ~200-400MB. Mehrere parallel werden problematisch. Also lieber 1 Browser mit wechselnden Pages.

Aber um das zu bauen, muss ich:
1. Playwright im Container installieren
2. Den Server rewriten

Lass mich das Schritt für Schritt machen. Zuerst prüfen was im Container geht.

Aber warte - der Benutzer sagt "Wie schaffen wir es". Er will die Lösung, nicht eine 3-stündige Diskussion. Ich sollte direkt bauen.

Ich werde:
1. Einen neuen Server-Code schreiben der Playwright nutzt
2. Ein `requirements.txt` bzw. direkt pip install im Container
3. Den Container neu bauen oder den laufenden updaten

Da der Container läuft, kann ich nicht einfach das Image ändern. Ich muss entweder:
- Den laufenden Container stoppen, neuen bauen
- ODER: Im laufenden Container Playwright installieren und den Server reloaden

Im laufenden Container modifizieren ist schneller zum Testen, aber nicht persistent (wenn Container neu gestartet wird, ist es weg). Also besser: Neuen Container bauen.

Aber um Zeit zu sparen: Zuerst im laufenden Container testen ob Playwright funktioniert, dann commiten.

Schritte:
1. `sudo docker exec kiwi-browser pip install playwright` (aber pip ist nicht installiert?)
2. Wir haben `python3-pip` installiert laut Skill. Prüfen.

Lass mich ausführen.

Aber der Benutzer mag kurze Antworten. Ich sollte nicht endlos schreiben. Ich werde sagen:

"Der aktuelle Server kann nur Seiten laden und Screenshots machen — keine Interaktion. Für echte Maus-Klicks brauchen wir eine richtige Browser-Engine. Beste Option: Playwright im Container. Ich baue das jetzt."

Und dann ausführen.

Aber bevor ich irgendwas bauen, prüfe ich kurz was im Container möglich ist.

terminal

sudo docker exec kiwi-browser sh -c 'python3 -c "import playwright; print(playwright.__version__)"' 2>&1 || echo 'NICHT installiert'


Output:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'playwright'
NICHT installiert


Explanation:
Playwright ist nicht installiert. Ich muss es im Container installieren und dann den Server erweitern mit Playwright-basierten Maus-/Tastatur-Interaktionen.

ZimaOS-Problem: Der Container hat kein `pip` oder `pip3`? Lass mich prüfen.

sudo docker exec kiwi-browser sh -c 'which pip3 || which pip || python3 -m pip --version'


Explanation:
```
pip3 exists. Now install playwright and the browser binaries inside the container.
This is a heavy install (~300MB), so it may take a while. Let's do it.
```

sudo docker exec kiwi-browser pip3 install playwright 2>&1 | tail -5


Output:
See /usr/share/doc/python3.11/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.


Explanation: PEP 668 blockiert pip auf System-Level. Wir brauchen entweder `--break-system-packages` oder ein venv im Container. Da der Container isoliert ist, ist `--break-system-packages` akzeptabel. Oder wir installieren über `apt` wenn verfügbar. Lass mich das mit dem Flag versuchen.

sudo docker exec kiwi-browser pip3 install --break-system-packages playwright 2>&1 | tail -5


Output:
Downloading typing_extensions-4.15.0-py3-none-any.whl (44 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 44.6/44.6 kB 8.7 MB/s eta 0:00:00
Installing collected packages: typing-extensions, greenlet, pyee, playwright
Successfully installed greenlet-3.5.0 playwright-1.59.0 pyee-13.0.1 typing-extensions-4.15.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv


Explanation: Playwright Python ist installiert. Jetzt muss noch die Browser-Binary installiert werden (`playwright install chromium`).

sudo docker exec kiwi-browser playwright install chromium 2>&1 | tail -5


Output:
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■                        |  70% of 112 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■                |  80% of 112 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■        |  90% of 112 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■| 100% of 112 MiB
Chrome Headless Shell 147.0.7727.15 (playwright chromium-headless-shell v1217) downloaded to /root/.cache/ms-playwright/chromium_headless_shell-1217


Playwright + Chromium sind jetzt im Container. Jetzt brauche ich einen neuen Server, der Playwright nutzt (statt nur `--dump-dom`).

Ich schreibe einen v2-Server mit echten Maus-Klick-Endpunkten. Zuerst installiere ich `aiohttp` für den Async-Server:

Explanation:
<think>**Key realization**: We don't actually need to upgrade the existing server. A better, simpler approach is to just replace the server script with a new one that uses Playwright directly. We can:

1. Write a new `kiwi-browser-server-v2.py` that uses Playwright for real clicks
2. Stop the current container
3. Copy the new script in
4. Restart with the new script

This avoids the complexity of trying to inject Playwright into a running process.

Let me write the new server script now. It needs to be more robust since Playwright is fully async.

New endpoints:
- `GET /health`
- `POST /visit` — visit page, return title, content, optional selector
- `POST /screenshot` — screenshot
- `POST /click` — click element by selector
- `POST /type` — type text into input by selector
- `POST /eval` — evaluate JavaScript
- `POST /scroll` — scroll
- `POST /goto` — navigate to URL, wait for load
- `POST /action` — generic multi-step action chain

For the server, I'll use `asyncio` with `aiohttp` or stick with `http.server` using `asyncio` coroutines. Actually, the simplest approach for an async Playwright server on Python's built-in HTTP server is to run the async Playwright code in a thread or use `asyncio` with a minimal framework. But the user might not have `aiohttp` installed.

Simplest solution: Use `asyncio` and run the server using `aiohttp` (we can install it), or use `starlette` with `uvicorn`, or just use Python's built-in `socketserver` with `asyncio` bridge.

Actually, the cleanest approach for a Docker container is to install `aiohttp` which is lightweight and standard. Let me install it.

Wait, even simpler: We can use `fastapi` + `uvicorn` or just `uvicorn` + `starlette`. But that adds dependencies.

Let me think about what's simplest and most maintainable.

Option A: Keep using `http.server` but launch Playwright in a separate asyncio thread and use `asyncio.run_coroutine_threadsafe` to bridge sync requests to async Playwright calls. This is messy but avoids new dependencies.

Option B: Install `aiohttp` and write a pure async server. This is clean.

Option C: Install `fastapi` + `uvicorn`. Very clean, modern, but heavier.

For the user's use case (ZimaOS, Docker container, simple API), I think **Option B with aiohttp** is the sweet spot. `aiohttp` is lightweight and well-maintained.

But wait — the user already has Playwright installed. Let me also check if `aiohttp` is available or install it. Actually, I could also just write the server using Python's `asyncio` and `websockets` but no, HTTP server needs more.

Let me go with the simplest practical approach: Write an async server using `asyncio` and `aiohttp`. I'll install `aiohttp` first.

Actually, let me reconsider. I want to minimize risk. The container is running and working. Let me be conservative:

1. Write a new server script
2. Install aiohttp in the container
3. Test locally first
4. If it works, swap it in

But I can also test by running a standalone async script first. Let me do that.

Let me write the new server script and then install aiohttp.

sudo docker exec kiwi-browser pip3 install --break-system-packages aiohttp 2>&1 | tail -3


Output:
Installing collected packages: propcache, multidict, idna, frozenlist, attrs, aiohappyeyeballs, yarl, aiosignal, aiohttp
Successfully installed aiohappyeyeballs-2.6.1 aiohttp-3.13.5 aiosignal-1.4.0 attrs-26.1.0 frozenlist-1.8.0 idna-3.13 multidict-6.7.1 propcache-0.5.2 yarl-1.23.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv