Skip to content

Agent Zero AI framework

Add Goal mode shortcut to chat composer

Alessandrocf1bec3ed912
diff --git a/plugins/_goal/AGENTS.md b/plugins/_goal/AGENTS.md
index 36df52b22..1cbba4020 100644
--- a/plugins/_goal/AGENTS.md
+++ b/plugins/_goal/AGENTS.md
@@ -11,7 +11,7 @@
- `tools/goal.py` owns the single agent-facing goal tool, file-backed state under `usr/plugins/_goal/goals/`, and goal status normalization.
- `api/goal.py` owns the WebUI JSON API for reading, editing, pausing, resuming, and deleting goals.
- `commands/` owns the `/goal` slash command contributed to `_commands`.
-- `webui/` and `extensions/webui/` own the composer goal strip and inline controls.
+- `webui/` and `extensions/webui/` own the composer goal strip, Goal mode shortcut, and inline controls.
- `tools/goal.py` and `prompts/agent.system.tool.goal.md` own agent-facing goal inspection, creation, and status updates.
- `tools/response.py` overrides the core response tool so an active goal continues the current monologue.
- `extensions/python/message_loop_prompts_after/` owns injecting the active goal into agent context.
@@ -24,6 +24,7 @@
- User controls may pause, resume, edit, or delete a goal; destructive delete uses inline confirmation. Model tools may create goals and mark them complete or blocked.
- Saving an edit that reactivates a complete or blocked goal resends the edited objective so agent processing resumes.
- `/goal <objective>` creates the goal and sends the objective as the user message so the agent starts working immediately.
+- The composer Goal mode shortcut only prefills `/goal ` and focuses the input; it never sends the command.
- `/goal auto` fills the composer with a prompt asking the agent to create and manage its own goal instead of silently sending a message.
- While a goal is active, response-tool calls are intermediate updates; only completing or blocking the goal restores normal loop termination.
- Goal UI feedback uses toast notifications and inline controls, not modal dialogs.
diff --git a/plugins/_goal/extensions/webui/initFw_end/goal-menu-injector.js b/plugins/_goal/extensions/webui/initFw_end/goal-menu-injector.js
new file mode 100644
index 000000000..c2cb9ccad
--- /dev/null
+++ b/plugins/_goal/extensions/webui/initFw_end/goal-menu-injector.js
@@ -0,0 +1,61 @@
+import { store as chatInputStore } from "/components/chat/input/input-store.js";
+
+const MENU_SELECTOR = ".chat-bottom-actions-menu";
+const BUTTON_ID = "goal-chat-more-item";
+
+function buildButton() {
+ const button = document.createElement("button");
+ button.type = "button";
+ button.className = "chat-bottom-menu-item";
+ button.id = BUTTON_ID;
+ button.innerHTML = `
+ <x-icon aria-hidden="true" name="track_changes"></x-icon>
+ <span>Goal mode</span>
+ `;
+
+ button.addEventListener("click", () => {
+ chatInputStore.closeChatMoreMenu();
+ chatInputStore.message = "/goal ";
+ chatInputStore.adjustTextareaHeight();
+ chatInputStore.focus();
+ chatInputStore._setEditorCaret?.(chatInputStore.message.length);
+ });
+
+ return button;
+}
+
+function injectButton(menu) {
+ if (!(menu instanceof HTMLElement)) return;
+ if (menu.querySelector(`#${BUTTON_ID}`)) return;
+ menu.appendChild(buildButton());
+}
+
+function scan(root = document) {
+ for (const menu of root.querySelectorAll(MENU_SELECTOR)) {
+ injectButton(menu);
+ }
+}
+
+export default async function initGoalMenuInjector() {
+ scan();
+
+ const observer = new MutationObserver((mutations) => {
+ for (const mutation of mutations) {
+ for (const node of mutation.addedNodes) {
+ if (!(node instanceof Element)) continue;
+
+ if (node.matches?.(MENU_SELECTOR)) {
+ injectButton(node);
+ continue;
+ }
+
+ if (node.querySelectorAll) scan(node);
+ }
+ }
+ });
+
+ observer.observe(document.body, {
+ childList: true,
+ subtree: true,
+ });
+}
diff --git a/plugins/_goal/tests/test_goal_plugin.py b/plugins/_goal/tests/test_goal_plugin.py
index 9214e3d96..564bf3e6c 100644
--- a/plugins/_goal/tests/test_goal_plugin.py
+++ b/plugins/_goal/tests/test_goal_plugin.py
@@ -111,6 +111,21 @@ def test_goal_webui_uses_state_revisions_instead_of_polling():
assert "goalStore.refresh(true)" in refresh
+def test_goal_composer_menu_prefills_without_sending():
+ plugin_root = Path(__file__).resolve().parents[1]
+ injector = (
+ plugin_root
+ / "extensions"
+ / "webui"
+ / "initFw_end"
+ / "goal-menu-injector.js"
+ ).read_text()
+
+ assert 'chatInputStore.message = "/goal ";' in injector
+ assert "chatInputStore.focus();" in injector
+ assert "sendMessage" not in injector
+
+
@pytest.mark.skipif(not shutil.which("node"), reason="node is required")
def test_goal_webui_uses_shared_hour_aware_duration_formatter():
project_root = Path(__file__).resolve().parents[3]