main
md 148 lines 4.48 KB
Rendered Raw
1 # Commands
2
3 YAML-configured slash commands for Agent Zero.
4
5 This plugin lets you define reusable `/commands` as `.command.yaml` files with either:
6
7 - a `.txt` template body
8 - a `.py` script hook
9
10 Commands are managed from the plugin modal and can be inserted directly from the chat composer with prefix syntax (`/goal objective`) or an exact trailing command (`objective /goal`). The picker opens only for prefix syntax; trailing commands resolve when sent.
11
12 ## Features
13
14 - `.command.yaml` config files with command metadata
15 - Text template commands with `{}` placeholders and parsed args
16 - Python hook commands with parsed args and optional chat history payload
17 - Unified parser for positional args, free-form tail, and flags
18 - Prefix and postfix command resolution for WebUI and remote/AI-sent messages
19 - Scope-aware command resolution across project and global scopes
20 - Built-in A0 CLI connector command pack for common session, queue, model, project, browser, and connector status commands
21 - `/stop` control that uses the same hard-stop operation as the WebUI composer button
22 - Slash picker in the chat composer with keyboard navigation and create-on-empty flow
23
24 ## Command File Model
25
26 Each command is defined by one config file plus one content file in the same scope directory.
27 Set `webui_hidden: true` to keep a command resolvable while omitting it from the chat composer picker.
28
29 Example text command:
30
31 `scan.command.yaml`
32
33 ```yaml
34 name: scan
35 description: Scan a Git repository.
36 argument_hint: /scan --git-url https://github.com/org/repo
37 type: text
38 template_path: scan.txt
39 ```
40
41 `scan.txt`
42
43 ```txt
44 Please scan repository: {args.flags.git_url}
45
46 Raw input:
47 {raw}
48 ```
49
50 Example python hook command:
51
52 `optimize.command.yaml`
53
54 ```yaml
55 name: optimize
56 description: Optimize the current request.
57 argument_hint: /optimize 30%
58 type: script
59 script_path: optimize.py
60 include_history: true
61 ```
62
63 `optimize.py`
64
65 ```python
66 def run(payload):
67 args = payload["arguments"]
68 pct = args["positional"][0] if args["positional"] else "10%"
69 return {
70 "text": f"Optimize this response by {pct}.",
71 "effects": [],
72 }
73 ```
74
75 ## Argument Parsing
76
77 The parser supports:
78
79 - Positional input: `/scan https://github.com/org/repo`
80 - Postfix input: `https://github.com/org/repo /scan`
81 - Long flags: `/scan --git-url https://github.com/org/repo`
82 - Long flags with equals: `/scan --git-url=https://github.com/org/repo`
83 - Short flags and bundles: `/scan -v -q` or `/scan -vq`
84
85 Parsed data is available to:
86
87 - Text templates via `{}` placeholders:
88 - `{raw}`
89 - `{args.positional.0}`
90 - `{args.flags.git_url}`
91 - Python scripts via `payload["arguments"]`
92
93 ## Script Hook Contract
94
95 Python hook file must expose:
96
97 ```python
98 def run(payload): ...
99 ```
100
101 It can return:
102
103 - `str` (used as replacement text)
104 - `dict` with:
105 - `text: str` (replacement text)
106 - `effects: list[dict]`
107
108 Supported frontend effects:
109
110 - `{"type": "replace_input", "text": "..."}`
111 - `{"type": "append_input", "text": "..."}`
112 - `{"type": "toast", "level": "info|error|success", "message": "..."}`
113 - Built-in UI effects for existing WebUI actions such as chat switching, modals, attachments, compaction, queue actions, transcript copy, and toast output
114
115 ## Scope Resolution
116
117 Commands are discovered from these scope folders:
118
119 - Project: `usr/projects/<project>/.a0proj/plugins/_commands/commands/`
120 - Global fallback: `usr/plugins/_commands/commands/`
121 - Built-in defaults: `plugins/_commands/commands/`
122 - Other enabled plugins: `plugins/<plugin>/commands/` or `usr/plugins/<plugin>/commands/`
123
124 Precedence in the chat picker:
125
126 1. Project
127 2. Global
128 3. Built-in `_commands`
129 4. Other plugin-distributed commands
130
131 ## Legacy Community Plugin Migration
132
133 When the built-in `_commands` plugin starts, it migrates files from the older community `commands` plugin namespace:
134
135 - Copies `usr/plugins/commands/commands/` into `usr/plugins/_commands/commands/`
136 - Copies `usr/plugins/commands/skills/` into `usr/plugins/_commands/skills/`
137 - Copies project and agent scoped `plugins/commands/commands/` folders to matching `plugins/_commands/commands/` folders
138 - Skips existing destination files
139 - Disables the legacy `commands` plugin roots so the WebUI does not load two slash-command popovers
140
141 ## UI Surfaces
142
143 - Plugin modal: manage project/global commands and create editable same-name overrides of bundled commands
144 - Chat composer: type `/` at the start or as the final token to browse commands
145
146 ## Agent Skill
147
148 The plugin ships with `commands-create-slash-command`, a plugin-scoped skill that helps Agent Zero create or update command files.