Skip to content

Self-improving AI Employees for everyone

fix: process cleanup, screenshot options, shell OS commands, LLM None args

trohitgd8a6e8bfce57
diff --git a/client/package.json b/client/package.json
index 6c6fd6b7..48af6622 100644
--- a/client/package.json
+++ b/client/package.json
@@ -1,7 +1,7 @@
{
"name": "react-flow-client",
"private": true,
- "version": "0.0.62",
+ "version": "0.0.63",
"type": "module",
"scripts": {
"start": "vite --host 0.0.0.0",
diff --git a/client/src/nodeDefinitions/browserNodes.ts b/client/src/nodeDefinitions/browserNodes.ts
index 2fa134a3..2bc5fdf1 100644
--- a/client/src/nodeDefinitions/browserNodes.ts
+++ b/client/src/nodeDefinitions/browserNodes.ts
@@ -131,6 +131,35 @@ export const browserNodes: Record<string, INodeTypeDescription> = {
description: 'Capture the full scrollable page',
displayOptions: { show: { operation: ['screenshot'] } },
},
+ {
+ displayName: 'Annotate',
+ name: 'annotate',
+ type: 'boolean',
+ default: false,
+ description: 'Add numbered labels to interactive elements (useful for AI vision models)',
+ displayOptions: { show: { operation: ['screenshot'] } },
+ },
+ {
+ displayName: 'Format',
+ name: 'screenshotFormat',
+ type: 'options',
+ default: 'png',
+ options: [
+ { name: 'PNG', value: 'png' },
+ { name: 'JPEG', value: 'jpeg' },
+ ],
+ description: 'Screenshot image format',
+ displayOptions: { show: { operation: ['screenshot'] } },
+ },
+ {
+ displayName: 'Quality',
+ name: 'screenshotQuality',
+ type: 'number',
+ default: 80,
+ typeOptions: { minValue: 1, maxValue: 100 },
+ description: 'JPEG quality (1-100, only used for JPEG format)',
+ displayOptions: { show: { operation: ['screenshot'], screenshotFormat: ['jpeg'] } },
+ },
{
displayName: 'JavaScript Expression',
name: 'expression',
diff --git a/package.json b/package.json
index 286dbdaa..5ddb29a9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "machinaos",
- "version": "0.0.62",
+ "version": "0.0.63",
"description": "Open source workflow automation platform with AI agents, React Flow, and n8n-inspired architecture",
"type": "module",
"keywords": [
diff --git a/server/services/agents/adapters.py b/server/services/agents/adapters.py
index 4635bcc5..957a557c 100644
--- a/server/services/agents/adapters.py
+++ b/server/services/agents/adapters.py
@@ -161,6 +161,13 @@ class ResponseExtractor:
if getattr(msg, "type", None) == "ai" and getattr(msg, "tool_calls", None):
iterations += 1
+ # Log all messages for debugging
+ for i, msg in enumerate(messages):
+ msg_type = getattr(msg, "type", "?")
+ has_tools = bool(getattr(msg, "tool_calls", None))
+ content_preview = str(getattr(msg, "content", ""))[:150]
+ logger.info("[DeepAgent] msg[%d] type=%s tool_calls=%s content=%s", i, msg_type, has_tools, content_preview)
+
# Extract final AI response
for msg in reversed(messages):
if getattr(msg, "type", None) == "ai" and hasattr(msg, "content"):
@@ -185,6 +192,11 @@ class ResponseExtractor:
_, thinking_content = extract_thinking_from_response(msg)
break
+ logger.info("[DeepAgent] Extracted: response_len=%d thinking=%s iterations=%d",
+ len(response_content), thinking_content is not None, max(iterations, 1))
+ if not response_content:
+ logger.warning("[DeepAgent] Empty response extracted from %d messages", len(messages))
+
return {
"response": response_content,
"thinking": thinking_content,
diff --git a/server/services/handlers/browser.py b/server/services/handlers/browser.py
index cd3aeb30..670fc24e 100644
--- a/server/services/handlers/browser.py
+++ b/server/services/handlers/browser.py
@@ -161,7 +161,18 @@ def _build_args(op: str, p: Dict[str, Any]) -> list:
case "fill":
return ["fill", _req_sel(s), p.get("value") or ""]
case "screenshot":
- return ["screenshot"] + (["--full"] if p.get("fullPage") else [])
+ args = ["screenshot"]
+ if p.get("fullPage"):
+ args.append("--full")
+ if p.get("annotate"):
+ args.append("--annotate")
+ fmt = p.get("screenshotFormat", "png")
+ if fmt and fmt != "png":
+ args.extend(["--screenshot-format", fmt])
+ quality = p.get("screenshotQuality")
+ if quality and fmt == "jpeg":
+ args.extend(["--screenshot-quality", str(quality)])
+ return args
case "snapshot":
return ["snapshot", "-i"]
case "get_text":
diff --git a/server/services/handlers/process.py b/server/services/handlers/process.py
index 7cd7400f..e918fbec 100644
--- a/server/services/handlers/process.py
+++ b/server/services/handlers/process.py
@@ -42,33 +42,41 @@ async def handle_process_manager(
return result
+def _clean_arg(val: str) -> str:
+ """LLMs sometimes pass literal 'None' string instead of omitting the field."""
+ if not val or val == "None":
+ return ""
+ return val
+
+
async def execute_process_manager(tool_args: Dict[str, Any], config: Dict[str, Any]) -> Dict[str, Any]:
"""AI tool entry point. Dispatches by operation."""
svc = get_process_service()
op = tool_args.get("operation", "list")
workflow_id = config.get("workflow_id", "default")
- name = tool_args.get("name", "")
+ name = _clean_arg(tool_args.get("name", ""))
+ workspace_dir = config.get("workspace_dir", "")
- logger.info("[ProcessManager] op=%s name=%s", op, name)
+ logger.info("[ProcessManager] op=%s name=%s workspace=%s", op, name, workspace_dir)
if op == "start":
return await svc.start(
name=name,
- command=tool_args.get("command", ""),
+ command=_clean_arg(tool_args.get("command", "")),
workflow_id=workflow_id,
- working_directory=tool_args.get("working_directory", config.get("workspace_dir", "")),
+ working_directory=_clean_arg(tool_args.get("working_directory", "")) or workspace_dir,
)
elif op == "stop":
return await svc.stop(name, workflow_id)
elif op == "restart":
return await svc.restart(name, workflow_id)
elif op == "send_input":
- return await svc.send_input(name, workflow_id, tool_args.get("text", ""))
+ return await svc.send_input(name, workflow_id, _clean_arg(tool_args.get("text", "")))
elif op == "list":
return {"success": True, "result": {"processes": svc.list_processes(workflow_id)}}
elif op == "get_output":
- stream = tool_args.get("stream", "stdout")
- tail = int(tool_args.get("tail", 50))
+ stream = _clean_arg(tool_args.get("stream", "")) or "stdout"
+ tail = int(tool_args.get("tail", 50) or 50)
offset = int(tool_args.get("offset", 0))
return {"success": True, "result": svc.get_output(name, workflow_id, stream, tail, offset)}
else:
diff --git a/server/services/process_service.py b/server/services/process_service.py
index bf929bf2..58f45c0c 100644
--- a/server/services/process_service.py
+++ b/server/services/process_service.py
@@ -192,7 +192,14 @@ class ProcessService:
managed.exit_code = -1
logger.info("[Process] Stopped: %s (exit=%s)", name, managed.exit_code)
- return {"success": True, "result": self._info(managed)}
+ result = self._info(managed)
+
+ # Schedule cleanup after 60s to allow output reading
+ asyncio.get_event_loop().call_later(
+ 60, lambda: self._cleanup_completed(workflow_id, name)
+ )
+
+ return {"success": True, "result": result}
async def restart(self, name: str, workflow_id: str = "default") -> Dict[str, Any]:
"""Restart a process with the same command."""
@@ -268,13 +275,54 @@ class ProcessService:
return {"lines": lines, "total": total, "file": str(log_file)}
- def cleanup_logs(self, name: str, workflow_id: str = "default") -> None:
- """Remove log files for a process."""
+ def _cleanup_completed(self, workflow_id: str, name: str) -> None:
+ """Remove log files and process entry for a completed process.
+
+ Called automatically 60s after process exits, giving time to read output.
+ Also cleans the parent .processes/ dir if empty.
+ """
key = self._key(workflow_id, name)
managed = self._processes.get(key)
- if managed and managed.log_dir.exists():
+ if not managed or managed.status == "running":
+ return
+
+ # Remove log directory
+ if managed.log_dir.exists():
shutil.rmtree(managed.log_dir, ignore_errors=True)
- logger.info("[Process] Cleaned logs: %s", managed.log_dir)
+
+ # Remove parent .processes/ if empty
+ parent = managed.log_dir.parent
+ if parent.exists() and parent.name == ".processes" and not any(parent.iterdir()):
+ parent.rmdir()
+
+ # Remove from tracking dict
+ self._processes.pop(key, None)
+ logger.info("[Process] Cleaned up: %s (workflow=%s)", name, workflow_id)
+
+ async def stop_workflow(self, workflow_id: str) -> int:
+ """Stop all processes for a workflow and clean up immediately."""
+ killed = 0
+ for key in list(self._processes.keys()):
+ wid, name = key
+ if wid != workflow_id:
+ continue
+ managed = self._processes[key]
+ if managed.status == "running":
+ _kill_process_tree(managed.pid)
+ for task in (managed.stdout_task, managed.stderr_task):
+ if task and not task.done():
+ task.cancel()
+ killed += 1
+ logger.info("[Process] Killed for workflow stop: %s (pid=%d)", name, managed.pid)
+ # Clean log files and remove entry
+ if managed.log_dir.exists():
+ shutil.rmtree(managed.log_dir, ignore_errors=True)
+ self._processes.pop(key, None)
+
+ # Clean parent .processes/ dirs if empty
+ if killed:
+ logger.info("[Process] Stopped %d process(es) for workflow %s", killed, workflow_id)
+ return killed
async def shutdown(self) -> None:
"""Kill all managed processes and clean up log files."""
@@ -340,6 +388,11 @@ class ProcessService:
managed.status = "stopped" if managed.exit_code == 0 else "error"
logger.info("[Process] Exited: %s (exit=%s)", managed.name, managed.exit_code)
+ # Schedule auto-cleanup of log files and process entry after delay
+ asyncio.get_event_loop().call_later(
+ 60, lambda: self._cleanup_completed(managed.workflow_id, managed.name)
+ )
+
@staticmethod
def _info(m: ManagedProcess) -> Dict[str, Any]:
return {
diff --git a/server/skills/terminal/shell-skill/SKILL.md b/server/skills/terminal/shell-skill/SKILL.md
index 124c8b49..92723fc2 100644
--- a/server/skills/terminal/shell-skill/SKILL.md
+++ b/server/skills/terminal/shell-skill/SKILL.md
@@ -4,7 +4,7 @@ description: Execute short-lived shell commands in a sandboxed environment. No P
allowed-tools: shell_execute
metadata:
author: machina
- version: "2.0"
+ version: "3.0"
category: execution
icon: "\U0001F4BB"
color: "#ff79c6"
@@ -23,15 +23,6 @@ Execute short-lived shell commands in a sandboxed workspace. The shell runs with
| command | string | Yes | Shell command to execute |
| timeout | int | No | Timeout in seconds (default: 30, max: 300) |
-### Examples
-
-```json
-{"command": "ls -la"}
-{"command": "cat README.md"}
-{"command": "echo hello > output.txt"}
-{"command": "find . -name '*.py' -type f"}
-```
-
### Response
```json
@@ -39,7 +30,7 @@ Execute short-lived shell commands in a sandboxed workspace. The shell runs with
"stdout": "command output",
"exit_code": 0,
"truncated": false,
- "command": "ls -la"
+ "command": "dir"
}
```
@@ -51,36 +42,69 @@ Execute short-lived shell commands in a sandboxed workspace. The shell runs with
| 124 | Timed out |
| non-zero | Failure |
+## OS-Specific Commands
+
+The shell uses the system's native shell (`cmd.exe` on Windows, `/bin/sh` on Linux/macOS). Use the correct commands for the platform.
+
+### Detect OS first
+
+```json
+{"command": "ver"}
+```
+If output contains `Windows`, use Windows commands. Otherwise use Unix commands.
+
+### Windows (cmd.exe)
+
+| Task | Command |
+|------|---------|
+| List files | `dir` |
+| List with details | `dir /a` |
+| Read file | `type README.md` |
+| Write to file | `echo hello > output.txt` |
+| Find files | `dir /s /b *.py` |
+| Search content | `findstr /s /i "pattern" *.py` |
+| Copy file | `copy src.txt dst.txt` |
+| Move file | `move src.txt dst.txt` |
+| Delete file | `del output.txt` |
+| Delete folder | `rmdir /s /q folder` |
+| Create folder | `mkdir newfolder` |
+| Show current dir | `cd` |
+
+### Linux / macOS (sh)
+
+| Task | Command |
+|------|---------|
+| List files | `ls -la` |
+| Read file | `cat README.md` |
+| Write to file | `echo hello > output.txt` |
+| Find files | `find . -name '*.py' -type f` |
+| Search content | `grep -r "pattern" --include='*.py' .` |
+| Copy file | `cp src.txt dst.txt` |
+| Move file | `mv src.txt dst.txt` |
+| Delete file | `rm output.txt` |
+| Delete folder | `rm -rf folder` |
+| Create folder | `mkdir -p newfolder` |
+| Show current dir | `pwd` |
+
## Shell vs Process Manager
| Need | Tool | Why |
|------|------|-----|
-| List files, read files, move/copy | **shell_execute** | Sandboxed, safe |
-| Delete files (`rm`, `del`) | **shell_execute** | Confined to workspace |
-| Search content (grep, find) | **shell_execute** | Fast, no PATH needed |
-| Echo, cat, simple file ops | **shell_execute** | Sandboxed |
+| List/read/copy/move files | **shell_execute** | Sandboxed, safe |
+| Delete files | **shell_execute** | Confined to workspace |
+| Search file content | **shell_execute** | Fast, no PATH needed |
| `npm install`, `pip install` | **process_manager** | Needs PATH |
| `python script.py`, `node app.js` | **process_manager** | Needs PATH |
-| Dev servers, watchers, build tools | **process_manager** | Long-running |
-
-The shell is the **only safe tool for file deletion**. It runs inside the agent's workspace with `virtual_mode=True` (path traversal blocked). The process_manager blocks destructive commands like `rm` since it has full PATH and could reach outside the workspace.
-
-## OS-Specific Commands
-
-For OS-specific syntax and tools, refer to:
-- **bash-skill** -- Linux/macOS commands (find, grep, apt, brew)
-- **powershell-skill** -- Windows commands (Get-ChildItem, Select-String)
-- **wsl-skill** -- Running Linux tools on Windows via WSL
+| Dev servers, watchers | **process_manager** | Long-running |
-These skills are in the `terminal` skill folder alongside this one.
+The shell is the **only safe tool for file deletion**. It runs inside the agent's workspace with `virtual_mode=True` (path traversal blocked). The process_manager blocks destructive commands since it has full PATH.
## Guidelines
-1. **Short-lived commands only** -- the shell waits for completion
-2. **No system PATH** -- `npm`, `python`, `node` will not be found. Use process_manager
-3. **No daemons/servers** -- commands that don't exit will hang until timeout
-4. Exit code 124 = timed out
-5. Check `truncated` flag for large output
-6. Use relative paths (workspace is the working directory)
-7. Chain with `&&` for sequential execution
-8. Avoid interactive commands requiring user input
+1. **Detect OS first** -- use `ver` to check Windows vs Unix, then use correct commands
+2. **Short-lived commands only** -- the shell waits for completion
+3. **No system PATH** -- `npm`, `python`, `node` will not be found. Use process_manager
+4. **No daemons/servers** -- commands that don't exit will hang until timeout
+5. Use relative paths (workspace is the working directory)
+6. Chain with `&&` for sequential execution
+7. Avoid interactive commands requiring user input
diff --git a/server/skills/web_agent/browser-skill/SKILL.md b/server/skills/web_agent/browser-skill/SKILL.md
index 89cd0982..0e6b9278 100644
--- a/server/skills/web_agent/browser-skill/SKILL.md
+++ b/server/skills/web_agent/browser-skill/SKILL.md
@@ -35,6 +35,9 @@ Use the **snapshot -> act -> snapshot** loop:
| direction | string | scroll | up, down, left, right (default: down) |
| amount | int | scroll | Pixels to scroll (default: 500) |
| fullPage | bool | screenshot | Capture full scrollable page (default: false) |
+| annotate | bool | screenshot | Add numbered labels to elements (default: false) |
+| screenshotFormat | string | screenshot | Image format: png (default) or jpeg |
+| screenshotQuality | int | screenshot | JPEG quality 1-100 (default: 80, only for jpeg) |
## Operations
@@ -80,6 +83,16 @@ Take a screenshot of the current page.
{"operation": "screenshot", "fullPage": true}
```
+**Annotated screenshot** (numbered labels on interactive elements -- best for AI vision):
+```json
+{"operation": "screenshot", "annotate": true}
+```
+
+**JPEG format** (smaller file size):
+```json
+{"operation": "screenshot", "screenshotFormat": "jpeg", "screenshotQuality": 80}
+```
+
### get_text
Extract text content from an element.
```json