Reduce WhatsApp ops tool friction with looser xlsx/file schemas and short-intent playbooks.

Production usage showed schema mismatches and multi-tool loops; accept common arg aliases and route agents to <=3-call alarm recipes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-08-10 22:32:44 +08:00
parent 685e3ffa8d
commit aff11c1eae
11 changed files with 276 additions and 24 deletions

View file

@ -6,12 +6,30 @@ from runtime.tools.base import ToolSpec
from runtime.tools.path_guard import resolve_workspace_path
def _resolve_write_path(args: dict[str, Any]) -> str:
for key in ("path", "file", "filename", "file_path", "filepath", "name"):
raw = str(args.get(key) or "").strip().strip('"').strip("'")
if raw:
return raw
return ""
def write_file_tool() -> ToolSpec:
def _handler(args: dict[str, Any]) -> dict[str, Any]:
raw = str(args.get("path") or "").strip().strip('"').strip("'")
raw = _resolve_write_path(args)
if not raw:
return {"ok": False, "error": "path_required"}
content = str(args.get("content") or "")
return {
"ok": False,
"error": "path_required",
"hint": "Pass path (or file/filename) relative to workspace root.",
"example": {"path": "tmp/notes.txt", "content": "hello", "mode": "overwrite"},
}
content = args.get("content")
if content is None:
content = args.get("text")
if content is None:
content = args.get("body")
content_s = "" if content is None else str(content)
mode = str(args.get("mode") or "overwrite").strip().lower()
try:
p = resolve_workspace_path(raw)
@ -21,22 +39,32 @@ def write_file_tool() -> ToolSpec:
if mode not in ("overwrite", "append"):
return {"ok": False, "error": "invalid_mode", "allowed": ["overwrite", "append"]}
if mode == "append":
p.write_text(p.read_text(encoding="utf-8", errors="replace") + content, encoding="utf-8")
p.write_text(p.read_text(encoding="utf-8", errors="replace") + content_s, encoding="utf-8")
else:
p.write_text(content, encoding="utf-8")
p.write_text(content_s, encoding="utf-8")
return {"ok": True, "path": str(p), "bytes": p.stat().st_size}
return ToolSpec(
name="write_file",
description="Write text content to a workspace file (overwrite or append).",
description=(
"Write text content to a workspace file (overwrite or append). "
"Path aliases: file, filename, file_path."
),
parameters={
"type": "object",
"properties": {
"path": {"type": "string", "description": "File path, relative to workspace root."},
"file": {"type": "string", "description": "Alias for path."},
"filename": {"type": "string", "description": "Alias for path."},
"file_path": {"type": "string", "description": "Alias for path."},
"filepath": {"type": "string", "description": "Alias for path."},
"name": {"type": "string", "description": "Alias for path (when it looks like a relative file path)."},
"content": {"type": "string", "description": "Full text content to write."},
"text": {"type": "string", "description": "Alias for content."},
"body": {"type": "string", "description": "Alias for content."},
"mode": {"type": "string", "enum": ["overwrite", "append"], "default": "overwrite"},
},
"required": ["path", "content"],
"required": [],
"additionalProperties": False,
},
handler=_handler,