Agent Zero AI framework
Add text_editor custom message handler and CSS
linklitid1907bcd41a1
diff --git a/plugins/_a0_connector/AGENTS.md b/plugins/_a0_connector/AGENTS.mdindex a2d4cca8a..d7a42fa73 100644--- a/plugins/_a0_connector/AGENTS.md+++ b/plugins/_a0_connector/AGENTS.md@@ -14,6 +14,8 @@## Local Contracts+- `tools/text_editor_remote.py` overrides `get_log_object()` to log `type="text_editor"` so the WebUI routes its messages through the `_text_editor` plugin's `get_message_handler` JS extension, keeping remote edits visually consistent with local edits.+- Preserve session-auth and `auth.handlers` activation assumptions.- Keep remote tool prompts synchronized with remote tool behavior and disclosethem only from connected CLI metadata: no connected CLI hides all remote tooldiff --git a/plugins/_a0_connector/tools/text_editor_remote.py b/plugins/_a0_connector/tools/text_editor_remote.pyindex 1db409c66..d764f491d 100644--- a/plugins/_a0_connector/tools/text_editor_remote.py+++ b/plugins/_a0_connector/tools/text_editor_remote.py@@ -40,6 +40,24 @@ UNSUPPORTED_FRESHNESS_ERROR = (class TextEditorRemote(Tool):"""Send file-editing operations to the connected CLI machine."""+ def get_log_object(self):+ action = str(self.args.get("action") or "")+ path = str(self.args.get("path") or "")+ verb = {"read": "Reading", "write": "Writing", "patch": "Patching"}.get(action)+ heading = (+ f"icon://construction {verb} {path} (remote)".strip()+ if verb and path+ else f"icon://construction {self.agent.agent_name}: Using tool '{self.name}' (remote)"+ )+ return self.agent.context.log.log(+ type="text_editor",+ heading=heading,+ content="",+ kvps=self.args,+ _tool_name=self.name,+ id=str(uuid.uuid4()),+ )+async def execute(self, **kwargs: Any) -> Response:op = (str(diff --git a/plugins/_code_execution/extensions/webui/chat-top-start/_10_styles.html b/plugins/_code_execution/extensions/webui/chat-top-start/_10_styles.htmlnew file mode 100644index 000000000..977211411--- /dev/null+++ b/plugins/_code_execution/extensions/webui/chat-top-start/_10_styles.html@@ -0,0 +1,9 @@+<style>+/* EXE - code_exe type (magenta/purple) */+.process-group .EXE {+ --step-accent: #ba68c8;+}+.light-mode .process-group .EXE {+ --step-accent: #7c3aed;+}+</style>diff --git a/plugins/_text_editor/AGENTS.md b/plugins/_text_editor/AGENTS.mdindex 14f38fb38..912a53c3c 100644--- a/plugins/_text_editor/AGENTS.md+++ b/plugins/_text_editor/AGENTS.md@@ -13,6 +13,8 @@## Local Contracts+- `tools/text_editor.py` overrides `get_log_object()` to log `type="text_editor"` so the WebUI `get_message_handler` extension hook can route messages to `_text_editor/extensions/webui/get_message_handler/_10_text_editor_handler.js` instead of the default `drawMessageTool` handler.+- Preserve stale-read protection before patch operations.- Validate patch structures before applying edits.- Read back changed regions after writes or patches where the tool contract requires confirmation.diff --git a/plugins/_text_editor/extensions/webui/chat-top-start/_10_styles.html b/plugins/_text_editor/extensions/webui/chat-top-start/_10_styles.htmlnew file mode 100644index 000000000..80c221d57--- /dev/null+++ b/plugins/_text_editor/extensions/webui/chat-top-start/_10_styles.html@@ -0,0 +1,9 @@+<style>+/* TXT - text_editor tool (cyan) */+.process-group .TXT {+ --step-accent: #22d3ee;+}+.light-mode .process-group .TXT {+ --step-accent: #0891b2;+}+</style>diff --git a/plugins/_text_editor/extensions/webui/get_message_handler/_10_text_editor_handler.js b/plugins/_text_editor/extensions/webui/get_message_handler/_10_text_editor_handler.jsnew file mode 100644index 000000000..0c98bbc36--- /dev/null+++ b/plugins/_text_editor/extensions/webui/get_message_handler/_10_text_editor_handler.js@@ -0,0 +1,57 @@+/**+ * Custom handler for text_editor tool messages+ * Uses drawProcessStep with code='TXT' (cyan)+ * Hides _tool_name from display to keep the step clean.+ */+import {+ buildDetailPayload,+ cleanStepTitle,+ drawProcessStep,+} from "/js/messages.js";+import { store as stepDetailStore } from "/components/modals/process-step-detail/step-detail-store.js";+import { ttsService } from "/js/tts-service.js";+import {+ copyToClipboard,+ createActionButton,+} from "/components/messages/action-buttons/simple-action-buttons.js";++export default function (extData) {+ if (extData.type !== "text_editor") return;++ extData.handler = function ({ id, content, kvps, heading, timestamp, agentno = 0, ...rest }) {+ const title = cleanStepTitle(heading);+ const displayKvps = { ...kvps };+ // Hide internal tool name from display+ delete displayKvps._tool_name;++ const contentText = String(content ?? "");+ const actionButtons = contentText.trim()+ ? [+ createActionButton("detail", "", () =>+ stepDetailStore.showStepDetail(+ buildDetailPayload(arguments[0], { headerLabels: [] })+ )+ ),+ createActionButton("copy", "", () => copyToClipboard(contentText)),+ createActionButton("speak", "", () => ttsService.speak(contentText)),+ ]+ : [+ createActionButton("detail", "", () =>+ stepDetailStore.showStepDetail(+ buildDetailPayload(arguments[0], { headerLabels: [] })+ )+ ),+ ];++ return drawProcessStep({+ id,+ title,+ code: "TXT",+ classes: ["TXT"],+ kvps: displayKvps,+ content,+ actionButtons,+ log: arguments[0],+ });+ };+}diff --git a/plugins/_text_editor/tools/text_editor.py b/plugins/_text_editor/tools/text_editor.pyindex f804e6507..56ac05e3a 100644--- a/plugins/_text_editor/tools/text_editor.py+++ b/plugins/_text_editor/tools/text_editor.py@@ -1,3 +1,4 @@+import uuidfrom pathlib import Pathfrom helpers.tool import Tool, Response@@ -30,6 +31,24 @@ _MTIME_KEY = LOCAL_FRESHNESS_KEYclass TextEditor(Tool):+ def get_log_object(self):+ action = str(self.args.get("action") or "")+ path = str(self.args.get("path") or "")+ verb = {"read": "Reading", "write": "Writing", "patch": "Patching"}.get(action)+ heading = (+ f"icon://construction {verb} {path}".strip()+ if verb and path+ else f"icon://construction {self.agent.agent_name}: Using tool '{self.name}'"+ )+ return self.agent.context.log.log(+ type="text_editor",+ heading=heading,+ content="",+ kvps=self.args,+ _tool_name=self.name,+ id=str(uuid.uuid4()),+ )+async def execute(self, **kwargs):action = _current_action(self, kwargs)if action == "read":diff --git a/tests/test_text_editor_message_handler.py b/tests/test_text_editor_message_handler.pynew file mode 100644index 000000000..43c3b5871--- /dev/null+++ b/tests/test_text_editor_message_handler.py@@ -0,0 +1,112 @@+from __future__ import annotations++import sys+import uuid+from pathlib import Path+from types import SimpleNamespace++import pytest++PROJECT_ROOT = Path(__file__).resolve().parents[1]+if str(PROJECT_ROOT) not in sys.path:+ sys.path.insert(0, str(PROJECT_ROOT))+++class _FakeLogItem:+ def __init__(self, type_, heading="", content="", kvps=None, id=None, **kwargs):+ self.type = type_+ self.heading = heading+ self.content = content+ self.kvps = dict(kvps or {})+ self.kvps.update(kwargs)+ self.id = id+++class _FakeLog:+ def __init__(self):+ self.items = []++ def log(self, type, heading="", content="", kvps=None, id=None, **kwargs):+ item = _FakeLogItem(type, heading, content, kvps, id, **kwargs)+ self.items.append(item)+ return item+++class _FakeContext:+ def __init__(self):+ self.id = "ctx"+ self.log = _FakeLog()+++class _FakeAgent:+ def __init__(self):+ self.context = _FakeContext()+ self.agent_name = "A0"+++def _make_tool(cls, **args):+ return cls(_FakeAgent(), "text_editor", None, args, "", None)++[email protected](scope="module")+def text_editor_cls():+ from plugins._text_editor.tools.text_editor import TextEditor+ return TextEditor++[email protected](scope="module")+def text_editor_remote_cls():+ from plugins._a0_connector.tools.text_editor_remote import TextEditorRemote+ return TextEditorRemote+++def test_text_editor_log_object_uses_custom_type(text_editor_cls):+ tool = _make_tool(text_editor_cls, action="read", path="/a0/file.txt")+ item = tool.get_log_object()+ assert item.type == "text_editor"+ assert item.kvps["_tool_name"] == "text_editor"+ assert item.kvps["action"] == "read"+ assert item.kvps["path"] == "/a0/file.txt"+++def test_text_editor_log_object_heading_uses_action_and_path(text_editor_cls):+ cases = [+ ("read", "/a0/a.txt", "Reading /a0/a.txt"),+ ("write", "/a0/b.txt", "Writing /a0/b.txt"),+ ("patch", "/a0/c.txt", "Patching /a0/c.txt"),+ ]+ for action, path, expected in cases:+ tool = _make_tool(text_editor_cls, action=action, path=path)+ item = tool.get_log_object()+ assert item.heading == f"icon://construction {expected}", item.heading+++def test_text_editor_log_object_falls_back_when_args_missing(text_editor_cls):+ tool = _make_tool(text_editor_cls)+ item = tool.get_log_object()+ assert item.type == "text_editor"+ assert "A0" in item.heading+ assert "text_editor" in item.heading+++def test_text_editor_log_object_id_is_uuid(text_editor_cls):+ tool = _make_tool(text_editor_cls, action="read", path="/x")+ item = tool.get_log_object()+ parsed = uuid.UUID(str(item.id))+ assert str(parsed) == str(item.id)+++def test_text_editor_remote_log_object_has_remote_suffix(text_editor_remote_cls):+ tool = _make_tool(text_editor_remote_cls, action="read", path="/remote/file.txt")+ item = tool.get_log_object()+ assert item.type == "text_editor"+ assert item.heading == "icon://construction Reading /remote/file.txt (remote)"+ assert item.kvps["_tool_name"] == "text_editor"+++def test_text_editor_remote_falls_back_with_remote_suffix(text_editor_remote_cls):+ tool = _make_tool(text_editor_remote_cls)+ item = tool.get_log_object()+ assert item.type == "text_editor"+ assert "(remote)" in item.heading+diff --git a/webui/components/messages/process-group/process-group.css b/webui/components/messages/process-group/process-group.cssindex 662863d62..c64814a05 100644--- a/webui/components/messages/process-group/process-group.css+++ b/webui/components/messages/process-group/process-group.css@@ -196,14 +196,6 @@--step-accent: #0f766e;}-/* EXE - code_exe type (magenta/purple) */-.process-group .EXE {- --step-accent: #ba68c8;-}-.light-mode .process-group .EXE {- --step-accent: #7c3aed;-}-/* WWW - browser type (indigo) */.process-group .WWW {--step-accent: #818cf8;diff --git a/webui/js/messages.js b/webui/js/messages.jsindex e22c8f67a..07b8ea80b 100644--- a/webui/js/messages.js+++ b/webui/js/messages.js@@ -183,7 +183,7 @@ export async function getMessageHandler(type) {// return handler from extensionsif(typeof extData.handler == "function") return extData.handler;//not set by extensions, return default- return drawMessageDefault;+ return drawMessageTool;}}