mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 04:40:45 +08:00
Stop shell Excel builds, default write_file paths, and cap short-intent tool rounds.
Refuse openpyxl/pandas-to_excel via run_command, auto-write content-only files under tmp/, and limit WhatsApp ops short intents to 8 tool rounds by default. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
a5ebabbaae
commit
d8bc08ee0d
6 changed files with 162 additions and 13 deletions
|
|
@ -5,6 +5,26 @@ from typing import Any
|
|||
from runtime.tools.base import ToolSpec
|
||||
from runtime.tools.public.local_sdk import get_local_adapter
|
||||
|
||||
_XLSX_SHELL_MARKERS = (
|
||||
"openpyxl",
|
||||
"xlsxwriter",
|
||||
"to_excel(",
|
||||
"workbook(",
|
||||
"load_workbook(",
|
||||
)
|
||||
|
||||
|
||||
def _looks_like_xlsx_via_shell(command: str) -> bool:
|
||||
"""Detect agents trying to build Excel via shell/python instead of write_xlsx."""
|
||||
low = str(command or "").lower()
|
||||
if not low:
|
||||
return False
|
||||
if any(m in low for m in _XLSX_SHELL_MARKERS):
|
||||
return True
|
||||
if ".xlsx" in low and any(tok in low for tok in ("python", "pip", "pandas", "-c ", "import ")):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def run_command_tool() -> ToolSpec:
|
||||
def _handler(args: dict[str, Any]) -> dict[str, Any]:
|
||||
|
|
@ -19,13 +39,29 @@ def run_command_tool() -> ToolSpec:
|
|||
"hint": "Pass command (aliases: cmd, shell).",
|
||||
"example": {"command": "echo hello", "timeout": 60},
|
||||
}
|
||||
if _looks_like_xlsx_via_shell(command):
|
||||
return {
|
||||
"ok": False,
|
||||
"error_code": "xlsx_via_shell_forbidden",
|
||||
"error": "xlsx_via_shell_forbidden",
|
||||
"failure_class": "schema_validation",
|
||||
"retry_forbidden": True,
|
||||
"hint": (
|
||||
"Do not build Excel via run_command/openpyxl/pandas. "
|
||||
"Use ume_alarm_xlsx_report or write_xlsx(deliverable=true) instead."
|
||||
),
|
||||
"fallback_tools": ["ume_alarm_xlsx_report", "write_xlsx"],
|
||||
}
|
||||
cwd = str(args.get("cwd") or args.get("workdir") or "").strip() or None
|
||||
timeout = int(args.get("timeout") or 300)
|
||||
return get_local_adapter().run_command(command=command, cwd=cwd, timeout=timeout)
|
||||
|
||||
return ToolSpec(
|
||||
name="run_command",
|
||||
description="Run a shell command via local backend. Prefer cmd aliases: command/cmd/shell.",
|
||||
description=(
|
||||
"Run a shell command via local backend. Prefer cmd aliases: command/cmd/shell. "
|
||||
"Do not use this to build .xlsx (use write_xlsx / ume_alarm_xlsx_report)."
|
||||
),
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
@ -48,4 +84,4 @@ def run_command_tool() -> ToolSpec:
|
|||
)
|
||||
|
||||
|
||||
__all__ = ["run_command_tool"]
|
||||
__all__ = ["run_command_tool", "_looks_like_xlsx_via_shell"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue