@mainwp/control 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +583 -0
  3. package/bin/_exit.js +12 -0
  4. package/bin/dev.js +7 -0
  5. package/bin/run.js +7 -0
  6. package/dist/chat/chat-engine.d.ts +213 -0
  7. package/dist/chat/chat-engine.d.ts.map +1 -0
  8. package/dist/chat/chat-engine.js +636 -0
  9. package/dist/chat/chat-engine.js.map +1 -0
  10. package/dist/chat/index.d.ts +10 -0
  11. package/dist/chat/index.d.ts.map +1 -0
  12. package/dist/chat/index.js +14 -0
  13. package/dist/chat/index.js.map +1 -0
  14. package/dist/chat/providers/anthropic.d.ts +52 -0
  15. package/dist/chat/providers/anthropic.d.ts.map +1 -0
  16. package/dist/chat/providers/anthropic.js +292 -0
  17. package/dist/chat/providers/anthropic.js.map +1 -0
  18. package/dist/chat/providers/gemini.d.ts +52 -0
  19. package/dist/chat/providers/gemini.d.ts.map +1 -0
  20. package/dist/chat/providers/gemini.js +284 -0
  21. package/dist/chat/providers/gemini.js.map +1 -0
  22. package/dist/chat/providers/index.d.ts +19 -0
  23. package/dist/chat/providers/index.d.ts.map +1 -0
  24. package/dist/chat/providers/index.js +23 -0
  25. package/dist/chat/providers/index.js.map +1 -0
  26. package/dist/chat/providers/local.d.ts +37 -0
  27. package/dist/chat/providers/local.d.ts.map +1 -0
  28. package/dist/chat/providers/local.js +130 -0
  29. package/dist/chat/providers/local.js.map +1 -0
  30. package/dist/chat/providers/openai-compatible.d.ts +155 -0
  31. package/dist/chat/providers/openai-compatible.d.ts.map +1 -0
  32. package/dist/chat/providers/openai-compatible.js +264 -0
  33. package/dist/chat/providers/openai-compatible.js.map +1 -0
  34. package/dist/chat/providers/openai.d.ts +24 -0
  35. package/dist/chat/providers/openai.d.ts.map +1 -0
  36. package/dist/chat/providers/openai.js +62 -0
  37. package/dist/chat/providers/openai.js.map +1 -0
  38. package/dist/chat/providers/openrouter.d.ts +26 -0
  39. package/dist/chat/providers/openrouter.d.ts.map +1 -0
  40. package/dist/chat/providers/openrouter.js +65 -0
  41. package/dist/chat/providers/openrouter.js.map +1 -0
  42. package/dist/chat/providers/provider-fetch.d.ts +15 -0
  43. package/dist/chat/providers/provider-fetch.d.ts.map +1 -0
  44. package/dist/chat/providers/provider-fetch.js +35 -0
  45. package/dist/chat/providers/provider-fetch.js.map +1 -0
  46. package/dist/chat/providers/provider.d.ts +214 -0
  47. package/dist/chat/providers/provider.d.ts.map +1 -0
  48. package/dist/chat/providers/provider.js +166 -0
  49. package/dist/chat/providers/provider.js.map +1 -0
  50. package/dist/chat/providers/sse-reader.d.ts +21 -0
  51. package/dist/chat/providers/sse-reader.d.ts.map +1 -0
  52. package/dist/chat/providers/sse-reader.js +48 -0
  53. package/dist/chat/providers/sse-reader.js.map +1 -0
  54. package/dist/chat/system-prompt.d.ts +33 -0
  55. package/dist/chat/system-prompt.d.ts.map +1 -0
  56. package/dist/chat/system-prompt.js +166 -0
  57. package/dist/chat/system-prompt.js.map +1 -0
  58. package/dist/chat/tool-envelope.d.ts +72 -0
  59. package/dist/chat/tool-envelope.d.ts.map +1 -0
  60. package/dist/chat/tool-envelope.js +263 -0
  61. package/dist/chat/tool-envelope.js.map +1 -0
  62. package/dist/commands/abilities/info.d.ts +21 -0
  63. package/dist/commands/abilities/info.d.ts.map +1 -0
  64. package/dist/commands/abilities/info.js +80 -0
  65. package/dist/commands/abilities/info.js.map +1 -0
  66. package/dist/commands/abilities/list.d.ts +19 -0
  67. package/dist/commands/abilities/list.d.ts.map +1 -0
  68. package/dist/commands/abilities/list.js +98 -0
  69. package/dist/commands/abilities/list.js.map +1 -0
  70. package/dist/commands/abilities/run.d.ts +75 -0
  71. package/dist/commands/abilities/run.d.ts.map +1 -0
  72. package/dist/commands/abilities/run.js +468 -0
  73. package/dist/commands/abilities/run.js.map +1 -0
  74. package/dist/commands/chat.d.ts +54 -0
  75. package/dist/commands/chat.d.ts.map +1 -0
  76. package/dist/commands/chat.js +384 -0
  77. package/dist/commands/chat.js.map +1 -0
  78. package/dist/commands/config/show.d.ts +54 -0
  79. package/dist/commands/config/show.d.ts.map +1 -0
  80. package/dist/commands/config/show.js +324 -0
  81. package/dist/commands/config/show.js.map +1 -0
  82. package/dist/commands/doctor.d.ts +77 -0
  83. package/dist/commands/doctor.d.ts.map +1 -0
  84. package/dist/commands/doctor.js +412 -0
  85. package/dist/commands/doctor.js.map +1 -0
  86. package/dist/commands/jobs/watch.d.ts +50 -0
  87. package/dist/commands/jobs/watch.d.ts.map +1 -0
  88. package/dist/commands/jobs/watch.js +269 -0
  89. package/dist/commands/jobs/watch.js.map +1 -0
  90. package/dist/commands/login.d.ts +25 -0
  91. package/dist/commands/login.d.ts.map +1 -0
  92. package/dist/commands/login.js +165 -0
  93. package/dist/commands/login.js.map +1 -0
  94. package/dist/commands/profile/delete.d.ts +22 -0
  95. package/dist/commands/profile/delete.d.ts.map +1 -0
  96. package/dist/commands/profile/delete.js +57 -0
  97. package/dist/commands/profile/delete.js.map +1 -0
  98. package/dist/commands/profile/list.d.ts +19 -0
  99. package/dist/commands/profile/list.d.ts.map +1 -0
  100. package/dist/commands/profile/list.js +53 -0
  101. package/dist/commands/profile/list.js.map +1 -0
  102. package/dist/commands/profile/use.d.ts +22 -0
  103. package/dist/commands/profile/use.d.ts.map +1 -0
  104. package/dist/commands/profile/use.js +46 -0
  105. package/dist/commands/profile/use.js.map +1 -0
  106. package/dist/config/fs-utils.d.ts +14 -0
  107. package/dist/config/fs-utils.d.ts.map +1 -0
  108. package/dist/config/fs-utils.js +31 -0
  109. package/dist/config/fs-utils.js.map +1 -0
  110. package/dist/config/keychain.d.ts +53 -0
  111. package/dist/config/keychain.d.ts.map +1 -0
  112. package/dist/config/keychain.js +175 -0
  113. package/dist/config/keychain.js.map +1 -0
  114. package/dist/config/profile-store.d.ts +85 -0
  115. package/dist/config/profile-store.d.ts.map +1 -0
  116. package/dist/config/profile-store.js +228 -0
  117. package/dist/config/profile-store.js.map +1 -0
  118. package/dist/config/settings.d.ts +71 -0
  119. package/dist/config/settings.d.ts.map +1 -0
  120. package/dist/config/settings.js +151 -0
  121. package/dist/config/settings.js.map +1 -0
  122. package/dist/core/abilities-executor.d.ts +126 -0
  123. package/dist/core/abilities-executor.d.ts.map +1 -0
  124. package/dist/core/abilities-executor.js +264 -0
  125. package/dist/core/abilities-executor.js.map +1 -0
  126. package/dist/core/batch-manager.d.ts +113 -0
  127. package/dist/core/batch-manager.d.ts.map +1 -0
  128. package/dist/core/batch-manager.js +244 -0
  129. package/dist/core/batch-manager.js.map +1 -0
  130. package/dist/core/http-client.d.ts +111 -0
  131. package/dist/core/http-client.d.ts.map +1 -0
  132. package/dist/core/http-client.js +329 -0
  133. package/dist/core/http-client.js.map +1 -0
  134. package/dist/core/safety-controller.d.ts +114 -0
  135. package/dist/core/safety-controller.d.ts.map +1 -0
  136. package/dist/core/safety-controller.js +229 -0
  137. package/dist/core/safety-controller.js.map +1 -0
  138. package/dist/hooks/command-not-found.d.ts +12 -0
  139. package/dist/hooks/command-not-found.d.ts.map +1 -0
  140. package/dist/hooks/command-not-found.js +58 -0
  141. package/dist/hooks/command-not-found.js.map +1 -0
  142. package/dist/index.d.ts +7 -0
  143. package/dist/index.d.ts.map +1 -0
  144. package/dist/index.js +7 -0
  145. package/dist/index.js.map +1 -0
  146. package/dist/lib/base-command.d.ts +123 -0
  147. package/dist/lib/base-command.d.ts.map +1 -0
  148. package/dist/lib/base-command.js +285 -0
  149. package/dist/lib/base-command.js.map +1 -0
  150. package/dist/output/formatter.d.ts +48 -0
  151. package/dist/output/formatter.d.ts.map +1 -0
  152. package/dist/output/formatter.js +138 -0
  153. package/dist/output/formatter.js.map +1 -0
  154. package/dist/output/json-envelope.d.ts +43 -0
  155. package/dist/output/json-envelope.d.ts.map +1 -0
  156. package/dist/output/json-envelope.js +73 -0
  157. package/dist/output/json-envelope.js.map +1 -0
  158. package/dist/utils/audit-logger.d.ts +97 -0
  159. package/dist/utils/audit-logger.d.ts.map +1 -0
  160. package/dist/utils/audit-logger.js +169 -0
  161. package/dist/utils/audit-logger.js.map +1 -0
  162. package/dist/utils/colors.d.ts +29 -0
  163. package/dist/utils/colors.d.ts.map +1 -0
  164. package/dist/utils/colors.js +36 -0
  165. package/dist/utils/colors.js.map +1 -0
  166. package/dist/utils/errors.d.ts +107 -0
  167. package/dist/utils/errors.d.ts.map +1 -0
  168. package/dist/utils/errors.js +149 -0
  169. package/dist/utils/errors.js.map +1 -0
  170. package/dist/utils/exit-codes.d.ts +21 -0
  171. package/dist/utils/exit-codes.d.ts.map +1 -0
  172. package/dist/utils/exit-codes.js +20 -0
  173. package/dist/utils/exit-codes.js.map +1 -0
  174. package/dist/utils/format.d.ts +64 -0
  175. package/dist/utils/format.d.ts.map +1 -0
  176. package/dist/utils/format.js +69 -0
  177. package/dist/utils/format.js.map +1 -0
  178. package/dist/utils/prompt.d.ts +34 -0
  179. package/dist/utils/prompt.d.ts.map +1 -0
  180. package/dist/utils/prompt.js +132 -0
  181. package/dist/utils/prompt.js.map +1 -0
  182. package/dist/utils/retry.d.ts +59 -0
  183. package/dist/utils/retry.d.ts.map +1 -0
  184. package/dist/utils/retry.js +96 -0
  185. package/dist/utils/retry.js.map +1 -0
  186. package/dist/utils/terminal-sanitizer.d.ts +60 -0
  187. package/dist/utils/terminal-sanitizer.d.ts.map +1 -0
  188. package/dist/utils/terminal-sanitizer.js +166 -0
  189. package/dist/utils/terminal-sanitizer.js.map +1 -0
  190. package/dist/validation/input-sanitizer.d.ts +76 -0
  191. package/dist/validation/input-sanitizer.d.ts.map +1 -0
  192. package/dist/validation/input-sanitizer.js +199 -0
  193. package/dist/validation/input-sanitizer.js.map +1 -0
  194. package/dist/validation/schema-validator.d.ts +75 -0
  195. package/dist/validation/schema-validator.d.ts.map +1 -0
  196. package/dist/validation/schema-validator.js +147 -0
  197. package/dist/validation/schema-validator.js.map +1 -0
  198. package/oclif.manifest.json +857 -0
  199. package/package.json +101 -0
  200. package/scripts/completions/README.md +221 -0
  201. package/scripts/completions/mainwpcontrol.bash +193 -0
  202. package/scripts/completions/mainwpcontrol.zsh +267 -0
  203. package/scripts/completions/profile-completer.sh +35 -0
  204. package/scripts/completions/regenerate.sh +78 -0
package/package.json ADDED
@@ -0,0 +1,101 @@
1
+ {
2
+ "name": "@mainwp/control",
3
+ "version": "1.0.0",
4
+ "description": "Command-line interface for scripting and automating MainWP Dashboard operations",
5
+ "type": "module",
6
+ "exports": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "mainwpcontrol": "./bin/run.js"
10
+ },
11
+ "files": [
12
+ "bin",
13
+ "dist",
14
+ "scripts/completions",
15
+ "oclif.manifest.json"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "clean": "rm -rf dist",
20
+ "lint": "eslint src --ext .ts",
21
+ "postpack": "rm -f oclif.manifest.json",
22
+ "prepack": "npm run clean && npm run build && oclif manifest",
23
+ "test": "vitest run",
24
+ "test:process": "npm run build && vitest run --config vitest.process.config.ts",
25
+ "test:live": "npm run build && MAINWP_LIVE_TEST=1 vitest run --config vitest.live.config.ts",
26
+ "test:all": "npm run test && npm run test:process",
27
+ "test:watch": "vitest",
28
+ "typecheck": "tsc --noEmit",
29
+ "pack": "oclif pack tarballs",
30
+ "pack:macos": "oclif pack macos",
31
+ "pack:win": "oclif pack win",
32
+ "pack:deb": "oclif pack deb"
33
+ },
34
+ "oclif": {
35
+ "bin": "mainwpcontrol",
36
+ "dirname": "mainwpcontrol",
37
+ "commands": "./dist/commands",
38
+ "default": "chat",
39
+ "plugins": [
40
+ "@oclif/plugin-help",
41
+ "@oclif/plugin-autocomplete"
42
+ ],
43
+ "hooks": {
44
+ "command_not_found": "./dist/hooks/command-not-found.js"
45
+ },
46
+ "topicSeparator": " ",
47
+ "macos": {
48
+ "identifier": "com.mainwp.mainwpcontrol"
49
+ },
50
+ "update": {
51
+ "s3": {
52
+ "bucket": "mainwpcontrol-releases"
53
+ }
54
+ }
55
+ },
56
+ "engines": {
57
+ "node": ">=20.0.0"
58
+ },
59
+ "keywords": [
60
+ "mainwp",
61
+ "wordpress",
62
+ "cli",
63
+ "automation",
64
+ "ci-cd",
65
+ "devops",
66
+ "scripting",
67
+ "mainwp-control"
68
+ ],
69
+ "publishConfig": {
70
+ "access": "public"
71
+ },
72
+ "license": "GPL-3.0-or-later",
73
+ "homepage": "https://github.com/mainwp/mainwp-control",
74
+ "repository": {
75
+ "type": "git",
76
+ "url": "https://github.com/mainwp/mainwp-control.git"
77
+ },
78
+ "bugs": {
79
+ "url": "https://github.com/mainwp/mainwp-control/issues"
80
+ },
81
+ "dependencies": {
82
+ "@oclif/core": "~4.0.0",
83
+ "@oclif/plugin-autocomplete": "~3.2.39",
84
+ "@oclif/plugin-help": "~6.0.0",
85
+ "ajv": "^8.18.0",
86
+ "undici": "^7.24.0"
87
+ },
88
+ "optionalDependencies": {
89
+ "keytar": "~7.9.0"
90
+ },
91
+ "devDependencies": {
92
+ "@oclif/test": "^4.0.0",
93
+ "@types/node": "^20.0.0",
94
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
95
+ "@typescript-eslint/parser": "^7.0.0",
96
+ "eslint": "^8.57.0",
97
+ "oclif": "^4.0.0",
98
+ "typescript": "^5.4.0",
99
+ "vitest": "^1.6.0"
100
+ }
101
+ }
@@ -0,0 +1,221 @@
1
+ # Shell Completion for MainWP Control
2
+
3
+ This directory contains shell completion scripts for `mainwpcontrol`, providing tab completion for commands, flags, and dynamic data like profile names.
4
+
5
+ ## Quick Start
6
+
7
+ ### Bash
8
+
9
+ Add to your `~/.bashrc`:
10
+
11
+ ```bash
12
+ source /path/to/mainwp-control/scripts/completions/mainwpcontrol.bash
13
+ ```
14
+
15
+ Then reload your shell:
16
+
17
+ ```bash
18
+ source ~/.bashrc
19
+ ```
20
+
21
+ ### Zsh
22
+
23
+ Add to your `~/.zshrc`:
24
+
25
+ ```bash
26
+ source /path/to/mainwp-control/scripts/completions/mainwpcontrol.zsh
27
+ ```
28
+
29
+ Then reload your shell:
30
+
31
+ ```bash
32
+ source ~/.zshrc
33
+ ```
34
+
35
+ ## For npm-installed CLI
36
+
37
+ If you installed `mainwpcontrol` globally via npm:
38
+
39
+ ```bash
40
+ # Find the installation path
41
+ npm root -g
42
+
43
+ # Source from node_modules (bash example)
44
+ source $(npm root -g)/@mainwp/control/scripts/completions/mainwpcontrol.bash
45
+
46
+ # Or for zsh
47
+ source $(npm root -g)/@mainwp/control/scripts/completions/mainwpcontrol.zsh
48
+ ```
49
+
50
+ ## For Local Development
51
+
52
+ If you're developing from the cloned repository:
53
+
54
+ ```bash
55
+ # Bash
56
+ source ./scripts/completions/mainwpcontrol.bash
57
+
58
+ # Zsh
59
+ source ./scripts/completions/mainwpcontrol.zsh
60
+ ```
61
+
62
+ ## What's Completed
63
+
64
+ ### Commands
65
+
66
+ All top-level and subcommands are completed:
67
+
68
+ - `chat` - Interactive chat mode
69
+ - `login` - Authenticate with a Dashboard
70
+ - `doctor` - Check configuration and connectivity
71
+ - `abilities list` - List available abilities
72
+ - `abilities info` - Get ability details
73
+ - `abilities run` - Execute an ability
74
+ - `profile list` - List all profiles
75
+ - `profile use` - Switch active profile
76
+ - `profile delete` - Delete a profile
77
+ - `jobs watch` - Monitor a batch job
78
+ - `autocomplete` - Display autocomplete setup instructions
79
+
80
+ ### Flags
81
+
82
+ All command flags are completed:
83
+
84
+ **Common flags (all commands):**
85
+ - `--json` - Output JSON
86
+ - `--profile`, `-p` - Use specific profile
87
+ - `--debug` - Show debug output
88
+ - `--help` - Show help
89
+
90
+ **abilities run:**
91
+ - `--input`, `-i` - Input parameters as JSON
92
+ - `--dry-run` - Preview changes
93
+ - `--confirm` - Execute after preview
94
+ - `--force` - Skip confirmation prompt
95
+
96
+ **abilities list:**
97
+ - `--category` - Filter by category (sites, clients, updates, plugins, themes, core, tags, batch)
98
+
99
+ **chat:**
100
+ - `--provider` - LLM provider (anthropic, gemini, local, openai, openrouter)
101
+ - `--model`, `-m` - Model to use
102
+ - `--api-key` - LLM API key
103
+ - `--base-url` - Custom API base URL
104
+ - `--max-turns` - Maximum tool calls per turn
105
+ - `--max-context-messages` - Maximum messages in context
106
+ - `--stream` / `--no-stream` - Enable/disable streaming
107
+
108
+ **doctor:**
109
+ - `--verbose`, `-v` - Verbose output
110
+
111
+ **jobs watch:**
112
+ - `--timeout` - Maximum wait time
113
+ - `--initial-delay` - Initial polling delay
114
+ - `--max-delay` - Maximum polling delay
115
+ - `--no-progress` - Disable progress output
116
+
117
+ **login:**
118
+ - `--url`, `-u` - Dashboard URL
119
+ - `--username` - WordPress username
120
+ - `--password` - Application password
121
+ - `--name`, `-n` - Profile name
122
+ - `--skip-ssl-verify` - Skip SSL verification
123
+
124
+ ### Dynamic Data
125
+
126
+ Profile names are completed dynamically for:
127
+
128
+ - `--profile` flag on all commands
129
+ - `profile use <name>` argument
130
+ - `profile delete <name>` argument
131
+
132
+ Profile names are read from `~/.config/mainwpcontrol/profiles.json`.
133
+
134
+ ## Updating Completions
135
+
136
+ After adding, removing, or modifying commands/flags in the CLI, run:
137
+
138
+ ```bash
139
+ ./scripts/completions/regenerate.sh
140
+ ```
141
+
142
+ This provides guidance on which files to update.
143
+
144
+ ## File Structure
145
+
146
+ | File | Purpose |
147
+ |------|---------|
148
+ | `mainwpcontrol.bash` | Bash completion script |
149
+ | `mainwpcontrol.zsh` | Zsh completion script |
150
+ | `profile-completer.sh` | Helper to read profile names from config |
151
+ | `regenerate.sh` | Helper script for updating completions |
152
+ | `README.md` | This documentation |
153
+
154
+ ## Troubleshooting
155
+
156
+ ### Completions not working
157
+
158
+ 1. **Check if sourced correctly:**
159
+ ```bash
160
+ # Bash
161
+ complete -p mainwpcontrol
162
+
163
+ # Zsh
164
+ whence -f _mainwpcontrol
165
+ ```
166
+
167
+ 2. **Reload shell configuration:**
168
+ ```bash
169
+ # Bash
170
+ source ~/.bashrc
171
+
172
+ # Zsh
173
+ source ~/.zshrc
174
+ ```
175
+
176
+ 3. **Check file paths:**
177
+ Ensure the sourced path in your shell config points to the correct location.
178
+
179
+ ### Profile names not completing
180
+
181
+ 1. **Check if profiles.json exists:**
182
+ ```bash
183
+ cat ~/.config/mainwpcontrol/profiles.json
184
+ ```
185
+
186
+ 2. **Check if jq is installed (optional but recommended):**
187
+ ```bash
188
+ which jq
189
+ ```
190
+ If not installed, the fallback grep/sed parser is used.
191
+
192
+ ### Bash completion not found
193
+
194
+ Ensure `bash-completion` is installed:
195
+
196
+ ```bash
197
+ # macOS
198
+ brew install bash-completion@2
199
+
200
+ # Ubuntu/Debian
201
+ apt install bash-completion
202
+
203
+ # Fedora/RHEL
204
+ dnf install bash-completion
205
+ ```
206
+
207
+ ### Permission errors
208
+
209
+ Make sure completion scripts are executable:
210
+
211
+ ```bash
212
+ chmod +x scripts/completions/*.sh
213
+ chmod +x scripts/completions/mainwpcontrol.bash
214
+ chmod +x scripts/completions/mainwpcontrol.zsh
215
+ ```
216
+
217
+ ## Requirements
218
+
219
+ - **Bash:** Version 4.0+ with bash-completion v2.0+
220
+ - **Zsh:** Any modern version (built-in completion support)
221
+ - **Optional:** `jq` for reliable JSON parsing of profile names
@@ -0,0 +1,193 @@
1
+ #!/bin/bash
2
+ # mainwpcontrol bash completion script
3
+ #
4
+ # Installation:
5
+ # source /path/to/mainwpcontrol/scripts/completions/mainwpcontrol.bash
6
+ #
7
+ # Or add to ~/.bashrc:
8
+ # source /path/to/mainwpcontrol/scripts/completions/mainwpcontrol.bash
9
+
10
+ # Determine the directory where this script is located
11
+ _MAINWPCTL_COMPLETION_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
+
13
+ # Source the profile completer helper
14
+ if [[ -f "${_MAINWPCTL_COMPLETION_DIR}/profile-completer.sh" ]]; then
15
+ source "${_MAINWPCTL_COMPLETION_DIR}/profile-completer.sh"
16
+ fi
17
+
18
+ _mainwpcontrol_completions() {
19
+ local cur prev words cword
20
+ _init_completion -n : || return
21
+
22
+ # All top-level commands
23
+ local commands="abilities autocomplete chat doctor help jobs login profile"
24
+
25
+ # Subcommands by topic
26
+ local abilities_commands="info list run"
27
+ local jobs_commands="watch"
28
+ local profile_commands="delete list use"
29
+
30
+ # Common flags (available on all commands)
31
+ local common_flags="--debug --help --json --profile -p"
32
+
33
+ # Command-specific flags
34
+ local abilities_run_flags="--confirm --dry-run --force --input -i"
35
+ local abilities_list_flags="--category"
36
+ local chat_flags="--api-key --base-url --max-context-messages --max-turns --model --no-stream --provider --stream -m"
37
+ local doctor_flags="--verbose -v"
38
+ local jobs_watch_flags="--initial-delay --max-delay --no-progress --timeout"
39
+ local login_flags="--name --password --skip-ssl-verify --url --username -n -u"
40
+
41
+ # Get the position in the command structure
42
+ local cmd_depth=0
43
+ local main_cmd=""
44
+ local sub_cmd=""
45
+
46
+ for ((i=1; i < cword; i++)); do
47
+ case "${words[i]}" in
48
+ -*)
49
+ # Skip flags and their values
50
+ if [[ "${words[i]}" =~ ^--(profile|input|model|provider|api-key|base-url|max-turns|max-context-messages|category|timeout|initial-delay|max-delay|url|username|password|name)$ ]]; then
51
+ ((i++)) # Skip the value too
52
+ fi
53
+ ;;
54
+ abilities|chat|doctor|help|jobs|login|profile|autocomplete)
55
+ if [[ -z "$main_cmd" ]]; then
56
+ main_cmd="${words[i]}"
57
+ cmd_depth=1
58
+ fi
59
+ ;;
60
+ info|list|run|watch|use|delete)
61
+ if [[ -n "$main_cmd" && -z "$sub_cmd" ]]; then
62
+ sub_cmd="${words[i]}"
63
+ cmd_depth=2
64
+ fi
65
+ ;;
66
+ esac
67
+ done
68
+
69
+ # Handle flag value completions
70
+ case "$prev" in
71
+ --profile|-p)
72
+ # Complete with profile names
73
+ local profiles
74
+ if type _mainwpcontrol_get_profiles &>/dev/null; then
75
+ profiles=$(_mainwpcontrol_get_profiles)
76
+ COMPREPLY=($(compgen -W "$profiles" -- "$cur"))
77
+ fi
78
+ return 0
79
+ ;;
80
+ --provider)
81
+ COMPREPLY=($(compgen -W "anthropic gemini local openai openrouter" -- "$cur"))
82
+ return 0
83
+ ;;
84
+ --category)
85
+ COMPREPLY=($(compgen -W "sites clients updates plugins themes core tags batch" -- "$cur"))
86
+ return 0
87
+ ;;
88
+ --input|-i|--model|-m|--api-key|--base-url|--max-turns|--max-context-messages|--timeout|--initial-delay|--max-delay|--url|-u|--username|--password|--name|-n)
89
+ # These flags require user input, no completion
90
+ return 0
91
+ ;;
92
+ esac
93
+
94
+ # Top-level command completion
95
+ if [[ $cword -eq 1 ]]; then
96
+ COMPREPLY=($(compgen -W "$commands" -- "$cur"))
97
+ return 0
98
+ fi
99
+
100
+ # Subcommand and flag completion based on context
101
+ case "$main_cmd" in
102
+ abilities)
103
+ if [[ -z "$sub_cmd" ]]; then
104
+ # Complete subcommands or flags
105
+ if [[ "$cur" == -* ]]; then
106
+ COMPREPLY=($(compgen -W "$common_flags" -- "$cur"))
107
+ else
108
+ COMPREPLY=($(compgen -W "$abilities_commands" -- "$cur"))
109
+ fi
110
+ else
111
+ # Complete flags for abilities subcommands
112
+ case "$sub_cmd" in
113
+ run)
114
+ COMPREPLY=($(compgen -W "$common_flags $abilities_run_flags" -- "$cur"))
115
+ ;;
116
+ list)
117
+ COMPREPLY=($(compgen -W "$common_flags $abilities_list_flags" -- "$cur"))
118
+ ;;
119
+ info)
120
+ COMPREPLY=($(compgen -W "$common_flags" -- "$cur"))
121
+ ;;
122
+ esac
123
+ fi
124
+ ;;
125
+ chat)
126
+ COMPREPLY=($(compgen -W "$common_flags $chat_flags" -- "$cur"))
127
+ ;;
128
+ doctor)
129
+ COMPREPLY=($(compgen -W "$common_flags $doctor_flags" -- "$cur"))
130
+ ;;
131
+ help)
132
+ # Complete with command names for help
133
+ COMPREPLY=($(compgen -W "$commands" -- "$cur"))
134
+ ;;
135
+ jobs)
136
+ if [[ -z "$sub_cmd" ]]; then
137
+ if [[ "$cur" == -* ]]; then
138
+ COMPREPLY=($(compgen -W "$common_flags" -- "$cur"))
139
+ else
140
+ COMPREPLY=($(compgen -W "$jobs_commands" -- "$cur"))
141
+ fi
142
+ else
143
+ case "$sub_cmd" in
144
+ watch)
145
+ COMPREPLY=($(compgen -W "$common_flags $jobs_watch_flags" -- "$cur"))
146
+ ;;
147
+ esac
148
+ fi
149
+ ;;
150
+ login)
151
+ COMPREPLY=($(compgen -W "$common_flags $login_flags" -- "$cur"))
152
+ ;;
153
+ profile)
154
+ if [[ -z "$sub_cmd" ]]; then
155
+ if [[ "$cur" == -* ]]; then
156
+ COMPREPLY=($(compgen -W "$common_flags" -- "$cur"))
157
+ else
158
+ COMPREPLY=($(compgen -W "$profile_commands" -- "$cur"))
159
+ fi
160
+ else
161
+ case "$sub_cmd" in
162
+ use|delete)
163
+ # Complete with profile names for these subcommands
164
+ if [[ "$cur" != -* ]]; then
165
+ local profiles
166
+ if type _mainwpcontrol_get_profiles &>/dev/null; then
167
+ profiles=$(_mainwpcontrol_get_profiles)
168
+ COMPREPLY=($(compgen -W "$profiles" -- "$cur"))
169
+ fi
170
+ else
171
+ COMPREPLY=($(compgen -W "$common_flags" -- "$cur"))
172
+ fi
173
+ ;;
174
+ list)
175
+ COMPREPLY=($(compgen -W "$common_flags" -- "$cur"))
176
+ ;;
177
+ esac
178
+ fi
179
+ ;;
180
+ autocomplete)
181
+ COMPREPLY=($(compgen -W "bash zsh" -- "$cur"))
182
+ ;;
183
+ *)
184
+ # Default: complete commands
185
+ COMPREPLY=($(compgen -W "$commands" -- "$cur"))
186
+ ;;
187
+ esac
188
+
189
+ return 0
190
+ }
191
+
192
+ # Register the completion function
193
+ complete -F _mainwpcontrol_completions mainwpcontrol