@mainwp/control 1.1.0-beta.1 → 1.1.1

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 (168) hide show
  1. package/CHANGELOG.md +156 -0
  2. package/README.md +135 -505
  3. package/dist/chat/chat-engine.d.ts +24 -54
  4. package/dist/chat/chat-engine.d.ts.map +1 -1
  5. package/dist/chat/chat-engine.js +345 -166
  6. package/dist/chat/chat-engine.js.map +1 -1
  7. package/dist/chat/context-window.d.ts +57 -0
  8. package/dist/chat/context-window.d.ts.map +1 -0
  9. package/dist/chat/context-window.js +94 -0
  10. package/dist/chat/context-window.js.map +1 -0
  11. package/dist/chat/providers/anthropic.d.ts +0 -4
  12. package/dist/chat/providers/anthropic.d.ts.map +1 -1
  13. package/dist/chat/providers/anthropic.js +67 -45
  14. package/dist/chat/providers/anthropic.js.map +1 -1
  15. package/dist/chat/providers/gemini.d.ts +2 -2
  16. package/dist/chat/providers/gemini.d.ts.map +1 -1
  17. package/dist/chat/providers/gemini.js +67 -43
  18. package/dist/chat/providers/gemini.js.map +1 -1
  19. package/dist/chat/providers/openai-compatible.d.ts +1 -1
  20. package/dist/chat/providers/openai-compatible.d.ts.map +1 -1
  21. package/dist/chat/providers/openai-compatible.js +91 -29
  22. package/dist/chat/providers/openai-compatible.js.map +1 -1
  23. package/dist/chat/providers/provider-fetch.d.ts +11 -0
  24. package/dist/chat/providers/provider-fetch.d.ts.map +1 -1
  25. package/dist/chat/providers/provider-fetch.js +86 -4
  26. package/dist/chat/providers/provider-fetch.js.map +1 -1
  27. package/dist/chat/providers/provider.d.ts +74 -1
  28. package/dist/chat/providers/provider.d.ts.map +1 -1
  29. package/dist/chat/providers/provider.js +112 -2
  30. package/dist/chat/providers/provider.js.map +1 -1
  31. package/dist/chat/providers/sse-reader.d.ts +3 -0
  32. package/dist/chat/providers/sse-reader.d.ts.map +1 -1
  33. package/dist/chat/providers/sse-reader.js +75 -15
  34. package/dist/chat/providers/sse-reader.js.map +1 -1
  35. package/dist/chat/system-prompt.d.ts +0 -2
  36. package/dist/chat/system-prompt.d.ts.map +1 -1
  37. package/dist/chat/system-prompt.js +10 -6
  38. package/dist/chat/system-prompt.js.map +1 -1
  39. package/dist/chat/tool-envelope.d.ts +3 -0
  40. package/dist/chat/tool-envelope.d.ts.map +1 -1
  41. package/dist/chat/tool-envelope.js +156 -10
  42. package/dist/chat/tool-envelope.js.map +1 -1
  43. package/dist/commands/abilities/info.d.ts.map +1 -1
  44. package/dist/commands/abilities/info.js +6 -3
  45. package/dist/commands/abilities/info.js.map +1 -1
  46. package/dist/commands/abilities/list.js +2 -2
  47. package/dist/commands/abilities/list.js.map +1 -1
  48. package/dist/commands/abilities/run.d.ts.map +1 -1
  49. package/dist/commands/abilities/run.js +126 -41
  50. package/dist/commands/abilities/run.js.map +1 -1
  51. package/dist/commands/chat.d.ts +12 -0
  52. package/dist/commands/chat.d.ts.map +1 -1
  53. package/dist/commands/chat.js +61 -27
  54. package/dist/commands/chat.js.map +1 -1
  55. package/dist/commands/config/show.d.ts.map +1 -1
  56. package/dist/commands/config/show.js +59 -47
  57. package/dist/commands/config/show.js.map +1 -1
  58. package/dist/commands/doctor.d.ts +0 -8
  59. package/dist/commands/doctor.d.ts.map +1 -1
  60. package/dist/commands/doctor.js +22 -36
  61. package/dist/commands/doctor.js.map +1 -1
  62. package/dist/commands/jobs/watch.d.ts +4 -0
  63. package/dist/commands/jobs/watch.d.ts.map +1 -1
  64. package/dist/commands/jobs/watch.js +66 -27
  65. package/dist/commands/jobs/watch.js.map +1 -1
  66. package/dist/commands/login.d.ts.map +1 -1
  67. package/dist/commands/login.js +59 -10
  68. package/dist/commands/login.js.map +1 -1
  69. package/dist/commands/profile/delete.d.ts.map +1 -1
  70. package/dist/commands/profile/delete.js +19 -3
  71. package/dist/commands/profile/delete.js.map +1 -1
  72. package/dist/commands/profile/list.d.ts.map +1 -1
  73. package/dist/commands/profile/list.js +6 -2
  74. package/dist/commands/profile/list.js.map +1 -1
  75. package/dist/commands/profile/use.d.ts.map +1 -1
  76. package/dist/commands/profile/use.js +4 -1
  77. package/dist/commands/profile/use.js.map +1 -1
  78. package/dist/config/fs-utils.d.ts.map +1 -1
  79. package/dist/config/fs-utils.js +19 -6
  80. package/dist/config/fs-utils.js.map +1 -1
  81. package/dist/config/keychain.d.ts +78 -6
  82. package/dist/config/keychain.d.ts.map +1 -1
  83. package/dist/config/keychain.js +194 -27
  84. package/dist/config/keychain.js.map +1 -1
  85. package/dist/config/profile-store.d.ts +11 -3
  86. package/dist/config/profile-store.d.ts.map +1 -1
  87. package/dist/config/profile-store.js +53 -19
  88. package/dist/config/profile-store.js.map +1 -1
  89. package/dist/core/abilities-executor.d.ts +23 -5
  90. package/dist/core/abilities-executor.d.ts.map +1 -1
  91. package/dist/core/abilities-executor.js +137 -42
  92. package/dist/core/abilities-executor.js.map +1 -1
  93. package/dist/core/batch-manager.d.ts +10 -5
  94. package/dist/core/batch-manager.d.ts.map +1 -1
  95. package/dist/core/batch-manager.js +78 -22
  96. package/dist/core/batch-manager.js.map +1 -1
  97. package/dist/core/execute-ability-with-policy.d.ts +8 -0
  98. package/dist/core/execute-ability-with-policy.d.ts.map +1 -0
  99. package/dist/core/execute-ability-with-policy.js +19 -0
  100. package/dist/core/execute-ability-with-policy.js.map +1 -0
  101. package/dist/core/http-client.d.ts +4 -0
  102. package/dist/core/http-client.d.ts.map +1 -1
  103. package/dist/core/http-client.js +116 -44
  104. package/dist/core/http-client.js.map +1 -1
  105. package/dist/core/job-id.d.ts +2 -0
  106. package/dist/core/job-id.d.ts.map +1 -0
  107. package/dist/core/job-id.js +22 -0
  108. package/dist/core/job-id.js.map +1 -0
  109. package/dist/core/safety-controller.d.ts +20 -10
  110. package/dist/core/safety-controller.d.ts.map +1 -1
  111. package/dist/core/safety-controller.js +87 -35
  112. package/dist/core/safety-controller.js.map +1 -1
  113. package/dist/lib/base-command.d.ts +20 -0
  114. package/dist/lib/base-command.d.ts.map +1 -1
  115. package/dist/lib/base-command.js +92 -35
  116. package/dist/lib/base-command.js.map +1 -1
  117. package/dist/output/formatter.d.ts +36 -0
  118. package/dist/output/formatter.d.ts.map +1 -1
  119. package/dist/output/formatter.js +105 -15
  120. package/dist/output/formatter.js.map +1 -1
  121. package/dist/output/json-envelope.d.ts.map +1 -1
  122. package/dist/output/json-envelope.js +8 -5
  123. package/dist/output/json-envelope.js.map +1 -1
  124. package/dist/utils/audit-logger.d.ts +26 -8
  125. package/dist/utils/audit-logger.d.ts.map +1 -1
  126. package/dist/utils/audit-logger.js +93 -20
  127. package/dist/utils/audit-logger.js.map +1 -1
  128. package/dist/utils/error-sanitizer.d.ts +6 -0
  129. package/dist/utils/error-sanitizer.d.ts.map +1 -0
  130. package/dist/utils/error-sanitizer.js +120 -0
  131. package/dist/utils/error-sanitizer.js.map +1 -0
  132. package/dist/utils/errors.d.ts +12 -0
  133. package/dist/utils/errors.d.ts.map +1 -1
  134. package/dist/utils/errors.js +14 -0
  135. package/dist/utils/errors.js.map +1 -1
  136. package/dist/utils/format.d.ts +68 -0
  137. package/dist/utils/format.d.ts.map +1 -1
  138. package/dist/utils/format.js +668 -0
  139. package/dist/utils/format.js.map +1 -1
  140. package/dist/utils/prompt.d.ts.map +1 -1
  141. package/dist/utils/prompt.js +24 -23
  142. package/dist/utils/prompt.js.map +1 -1
  143. package/dist/utils/redaction.d.ts +21 -0
  144. package/dist/utils/redaction.d.ts.map +1 -0
  145. package/dist/utils/redaction.js +85 -0
  146. package/dist/utils/redaction.js.map +1 -0
  147. package/dist/utils/retry.d.ts +0 -4
  148. package/dist/utils/retry.d.ts.map +1 -1
  149. package/dist/utils/retry.js +0 -9
  150. package/dist/utils/retry.js.map +1 -1
  151. package/dist/utils/terminal-sanitizer.d.ts +21 -0
  152. package/dist/utils/terminal-sanitizer.d.ts.map +1 -1
  153. package/dist/utils/terminal-sanitizer.js +80 -14
  154. package/dist/utils/terminal-sanitizer.js.map +1 -1
  155. package/dist/validation/input-sanitizer.d.ts +0 -4
  156. package/dist/validation/input-sanitizer.d.ts.map +1 -1
  157. package/dist/validation/input-sanitizer.js +15 -64
  158. package/dist/validation/input-sanitizer.js.map +1 -1
  159. package/dist/validation/sanitize-schema.d.ts +31 -0
  160. package/dist/validation/sanitize-schema.d.ts.map +1 -0
  161. package/dist/validation/sanitize-schema.js +158 -0
  162. package/dist/validation/sanitize-schema.js.map +1 -0
  163. package/dist/validation/schema-validator.d.ts +10 -0
  164. package/dist/validation/schema-validator.d.ts.map +1 -1
  165. package/dist/validation/schema-validator.js +50 -5
  166. package/dist/validation/schema-validator.js.map +1 -1
  167. package/oclif.manifest.json +23 -1
  168. package/package.json +21 -7
package/README.md CHANGED
@@ -1,457 +1,156 @@
1
- # MainWP Control
2
-
3
- A CLI for managing your MainWP Dashboard from the terminal. List sites, push updates, sync data, run batch operations across dozens of sites. The command is `mainwpcontrol`.
1
+ <p align="center">
2
+ <img src="docs/images/mainwp-control-logo-2026.png" alt="MainWP Control" width="400">
3
+ </p>
4
4
 
5
- **Looking for the MCP Server instead?** [MainWP MCP Server](https://github.com/mainwp/mainwp-mcp) is for conversational AI management inside Claude, Cursor, or any MCP-compatible client. MainWP Control is for automation: cron jobs, CI/CD pipelines, monitoring scripts, and batch operations. Both talk to the same Abilities API with the same safety model.
6
-
7
- ---
5
+ <p align="center">
6
+ <img src="https://img.shields.io/badge/status-stable-green" alt="Stable">
7
+ <a href="https://www.npmjs.com/package/@mainwp/control"><img src="https://img.shields.io/npm/v/@mainwp/control" alt="npm version"></a>
8
+ <a href="https://github.com/mainwp/mainwp-control/actions/workflows/ci.yml"><img src="https://github.com/mainwp/mainwp-control/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
9
+ </p>
8
10
 
9
- ## Quick Start
11
+ # MainWP Control
10
12
 
11
- > **On Windows?** Use [Git Bash](https://gitforwindows.org/) and every example below works without changes. For scheduled workflows (cron), see [WSL](https://learn.microsoft.com/en-us/windows/wsl/install).
13
+ _A [MainWP Labs](https://mainwp.com/mainwp-labs/) project, powered by MainWP_
12
14
 
13
- You need Node.js 20+ and a MainWP Dashboard (v6+) with an [Application Password](https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/).
15
+ Manage your whole WordPress network from the terminal. [MainWP Control](https://github.com/mainwp/mainwp-control) is a command-line interface for your MainWP Dashboard, built for the work you do on a schedule rather than in a browser tab:
14
16
 
15
17
  ```bash
16
- npm install -g @mainwp/control
17
-
18
- mainwpcontrol login
19
-
20
- mainwpcontrol abilities list
21
- ```
22
-
23
- You should see something like this:
18
+ # Which sites have pending updates?
19
+ mainwpcontrol abilities run list-updates-v1 --json
24
20
 
25
- ```text
26
- Abilities (87 total)
21
+ # Sync every site and wait for the result
22
+ mainwpcontrol abilities run sync-sites-v1 --wait --json
27
23
 
28
- Sites
29
- Name Description Type
30
- ---------------- -------------------- --------------
31
- list-sites-v1 List MainWP sites 📖 read
32
- mainwpcontrol abilities run list-sites-v1
33
- get-site-v1 Get site details 📖 read
34
- mainwpcontrol abilities run get-site-v1
35
- sync-sites-v1 Sync all sites ✏️ write
36
- mainwpcontrol abilities run sync-sites-v1
24
+ # Nightly health check from cron, alert on failure
25
+ mainwpcontrol abilities run check-sites-v1 --quiet \
26
+ || curl -fsS "$SLACK_WEBHOOK" -d '{"text":"Sites down"}'
37
27
  ```
38
28
 
39
- That's it. You're connected and you can see every operation your Dashboard supports.
40
-
41
- ---
42
-
43
- ## What Just Happened
44
-
45
- `abilities list` shows every operation available on your Dashboard. These are called "abilities" and they cover sites, plugins, themes, updates, clients, tags, and more.
29
+ The CLI is a small program that runs on your own computer or server. Nothing new is installed on your Dashboard or your child sites; it talks to the same Abilities API your Dashboard already exposes. Anything classified as destructive stops for a preview and your explicit confirmation before it runs.
46
30
 
47
- Each ability has a name (like `list-sites-v1`) that you pass to `abilities run` to execute it. The list tells you whether each one is read-only, a write operation, or destructive.
31
+ <p align="center">
32
+ <img src="docs/images/mainwp-control-fleet-from-the-terminal.png" alt="Dark MainWP branded card with the headline &quot;Your WordPress fleet from the terminal&quot; and a terminal listing 87 Dashboard abilities, running sync-sites-v1 with the wait and json flags to a success envelope, then checking exit code 0" width="800">
33
+ </p>
48
34
 
49
- ---
50
-
51
- ## Common Use Cases
52
-
53
- **List all your sites:**
54
-
55
- ```bash
56
- mainwpcontrol abilities run list-sites-v1 --json
57
- ```
35
+ **Looking for the MCP Server instead?** [MainWP MCP Server](https://github.com/mainwp/mainwp-mcp) connects Claude, Cursor, and other AI tools to your Dashboard for conversational management. MainWP Control is for automation: cron jobs, CI/CD pipelines, monitoring scripts, and batch operations. Both talk to the same Abilities API with the same safety model.
58
36
 
59
- **Check for pending updates across sites:**
37
+ ## Why a CLI?
60
38
 
61
- ```bash
62
- mainwpcontrol abilities run list-updates-v1 --json
63
- ```
64
-
65
- **Get details for a specific site:**
66
-
67
- ```bash
68
- mainwpcontrol abilities run get-site-v1 --input '{"site_id_or_domain": 1}' --json
69
- ```
39
+ The Dashboard UI is built for a person clicking through sites. A CLI is built for everything that should happen without you watching:
70
40
 
71
- > **Windows?** This works as-is in [Git Bash](https://gitforwindows.org/). In PowerShell, escape the inner quotes: `'{\"site_id_or_domain\": 1}'`. Or skip quoting entirely with `--input-file` ([details](docs/workflows/input-from-file.md)).
41
+ - **Scriptable output.** `--json` prints exactly one machine-readable envelope on stdout. Warnings and progress never contaminate it, so you can pipe results straight into `jq`, a spreadsheet, or a monitoring agent.
42
+ - **Honest exit codes.** Classified outcomes exit 0-5 by error class (input, auth, network, API, internal); interruptions use the standard signal exits (130/143). Your pipeline branches on the code instead of parsing error text.
43
+ - **Batch operations that survive.** Large operations queue as batch jobs with a `job_id` you can watch, wait on, or come back to. A timeout or Ctrl-C leaves you with a resumable job, not a mystery.
44
+ - **Credentials that stay put.** Passwords live in your OS keychain, or in an environment variable for CI. The profile file on disk never contains them.
45
+ - **Guard rails you can't script around by accident.** Destructive abilities require a successful `--dry-run` preview and an explicit `--confirm`, and each confirmed run is written to a local audit log.
72
46
 
73
- **Preview a destructive action before running it:**
47
+ ## What You Can Do
74
48
 
75
- ```bash
76
- mainwpcontrol abilities run delete-site-v1 \
77
- --input '{"site_id_or_domain": "mysite.com"}' \
78
- --dry-run --json
79
- ```
49
+ - **Site Management**: List sites, check connection status, sync data, add or remove child sites
50
+ - **Update Management**: See pending updates across all sites, apply core/plugin/theme updates
51
+ - **Plugin and Theme Control**: View installed plugins and themes, activate or deactivate them
52
+ - **Client Organization**: Manage client records, assign sites to clients, track costs
53
+ - **Bulk Operations**: Sync, reconnect, or check connectivity across dozens of sites at once
54
+ - **Chat Mode**: Optionally talk to your Dashboard in plain English, with the same safety gates
80
55
 
81
- Nothing changes until you explicitly pass `--confirm`.
56
+ Built for WordPress agencies and site managers who want their MainWP routine in scripts, schedulers, and pipelines.
82
57
 
83
- **Update plugins and wait for completion:**
58
+ ## Quick Start
84
59
 
85
- ```bash
86
- mainwpcontrol abilities run update-site-plugins-v1 \
87
- --input '{"site_id": 1}' \
88
- --wait --json
89
- ```
60
+ **Requirements:** Node.js >=20.18.1 and MainWP Dashboard 6.0+
90
61
 
91
- `--wait` blocks until the operation finishes. Useful in CI pipelines.
62
+ > **On Windows?** Use [Git Bash](https://gitforwindows.org/) and every example below works without changes. For scheduled workflows (cron), see [WSL](https://learn.microsoft.com/en-us/windows/wsl/install).
92
63
 
93
- ---
64
+ **1. Create an Application Password.** This is a separate password WordPress issues for tools like this one; it never changes your login and you can revoke it at any time.
94
65
 
95
- ## Installation
66
+ 1. Log into your MainWP Dashboard as an administrator
67
+ 2. Go to **Users > Profile** (click your username in the top right)
68
+ 3. Scroll to the **Application Passwords** section
69
+ 4. Enter a name like "MainWP Control" and click **Add New Application Password**
70
+ 5. Copy the generated password immediately (it is only shown once; spaces are fine either way)
96
71
 
97
- ### Standard install (recommended)
72
+ > **Tip:** Create a dedicated WordPress user for API access rather than using your main admin account. It keeps the audit trail clean and is easy to revoke later.
98
73
 
99
- Pre-built keychain binaries are included for macOS, Windows, and Linux (x64 and arm64). On other platforms you may need C++ build tools during installation.
74
+ **2. Install and log in.**
100
75
 
101
76
  ```bash
102
77
  npm install -g @mainwp/control
103
78
 
104
- # Interactive login (stores credentials in your OS keychain)
105
79
  mainwpcontrol login
106
80
  ```
107
81
 
108
- ### Environment variable auth (CI, Docker, headless)
109
-
110
- Use this when no OS keychain is available, or if keytar fails to build.
111
-
112
- ```bash
113
- npm install -g @mainwp/control
114
-
115
- export MAINWP_APP_PASSWORD='xxxx xxxx xxxx xxxx xxxx xxxx'
116
-
117
- mainwpcontrol login --url https://dashboard.example.com --username admin
118
- ```
119
-
120
- When the OS keychain is unavailable, credentials are not stored on disk. Keep `MAINWP_APP_PASSWORD` set for each run.
121
-
122
- If keytar is installed but broken, set `MAINWPCONTROL_NO_KEYTAR=1` to skip loading it.
123
-
124
- ---
125
-
126
- <details>
127
- <summary><strong>New to the Command Line?</strong></summary>
128
-
129
- If you haven't used a terminal before, here's what you need to know.
130
-
131
- ### What is a terminal?
132
-
133
- A terminal is where you type commands instead of clicking buttons. You'll see it called "command line" or "shell" in different places.
134
-
135
- **How to open it:**
136
- - **macOS**: Open **Terminal** (search in Spotlight, or look in Applications > Utilities)
137
- - **Windows**: Open **Git Bash** (installed with [Git for Windows](https://gitforwindows.org/)). If you don't have it, PowerShell works too — see the [quoting notes](#json-quoting-on-the-command-line) below.
138
- - **Linux**: Open your distribution's **Terminal** app (usually in the applications menu)
139
-
140
- ### What does `npm install -g` do?
141
-
142
- `npm` is the Node.js package manager. It downloads and installs JavaScript packages. The `-g` flag installs globally, which makes `mainwpcontrol` available as a command anywhere on your system, not only in one project folder.
143
-
144
- ### What is an environment variable?
145
-
146
- An environment variable is a named value that programs can read. They're commonly used for passwords and API keys.
147
-
148
- **Setting one:**
149
- ```bash
150
- # macOS / Linux (lasts until you close the terminal)
151
- export MAINWP_APP_PASSWORD='xxxx xxxx xxxx xxxx xxxx xxxx'
152
-
153
- # Windows PowerShell (lasts until you close the window)
154
- $env:MAINWP_APP_PASSWORD = 'xxxx xxxx xxxx xxxx xxxx xxxx'
155
- ```
156
-
157
- For long-term storage, use the OS keychain (the default when you run `mainwpcontrol login`) or a restricted-permission `.env` file rather than pasting credentials into shell profile files.
158
-
159
- ### What is an Application Password?
160
-
161
- WordPress Application Passwords let external tools like `mainwpcontrol` access your site without using your main login password. They look like groups of four characters separated by spaces (e.g., `abcd efgh ijkl mnop qrst uvwx`).
162
-
163
- **To create one:** Log into WordPress admin > Users > Your Profile > scroll to **Application Passwords** > enter a name like "mainwpcontrol" > click **Add New Application Password** > copy the generated password.
164
-
165
- ### Reading command output
166
-
167
- When you run a command, the output appears in your terminal. A few things to know:
168
-
169
- - **`--json`** tells `mainwpcontrol` to output structured JSON (useful for scripting and piping to other tools)
170
- - **Exit codes** indicate success (`0`) or failure (`1` through `5`). You won't see them directly, but scripts and CI use them to decide what happens next. Run `echo $?` (macOS/Linux) or `echo $LASTEXITCODE` (PowerShell) after a command to check.
171
-
172
- ### JSON quoting on the command line
173
-
174
- When you pass JSON with `--input`, quoting depends on your shell:
175
-
176
- ```bash
177
- # macOS / Linux / Git Bash on Windows
178
- mainwpcontrol abilities run get-site-v1 --input '{"site_id_or_domain": 1}' --json
179
-
180
- # Windows PowerShell
181
- mainwpcontrol abilities run get-site-v1 --input '{\"site_id_or_domain\": 1}' --json
182
- ```
183
-
184
- **Git Bash on Windows** (comes with [Git for Windows](https://gitforwindows.org/)) handles quoting the same way macOS and Linux do. If you use Git Bash, all the examples in this documentation work without changes.
185
-
186
- PowerShell strips the inner double quotes unless you escape them with backslashes. If this gets annoying, put your parameters in a file and use `--input-file`:
187
-
188
- ```bash
189
- mainwpcontrol abilities run get-site-v1 --input-file params.json --json
190
- ```
191
-
192
- This works the same on every platform. See [Input from File](docs/workflows/input-from-file.md) for details.
193
-
194
- </details>
195
-
196
- ---
197
-
198
- ## Basic Usage
82
+ `login` prompts for your Dashboard URL, username, and the Application Password, then stores the credentials in your OS keychain. For CI and headless machines, use [environment variable auth](docs/configuration.md#environment-variable-auth) instead.
199
83
 
200
- ### Abilities
201
-
202
- Your Dashboard exposes its operations as "abilities." You browse them, pick one, and run it. Every ability has a versioned name like `list-sites-v1` that you pass to `abilities run`.
84
+ **3. See what your Dashboard can do.**
203
85
 
204
86
  ```bash
205
- # List all abilities
206
87
  mainwpcontrol abilities list
207
-
208
- # Filter by category
209
- mainwpcontrol abilities list --category sites
210
-
211
- # Get full details and input schema for an ability
212
- mainwpcontrol abilities info list-sites-v1
213
-
214
- # Run an ability
215
- mainwpcontrol abilities run list-sites-v1 --json
216
-
217
- # Run with input parameters
218
- mainwpcontrol abilities run get-site-v1 --input '{"site_id_or_domain": 1}' --json
219
-
220
- # Windows PowerShell: escape inner quotes (Git Bash doesn't need this)
221
- mainwpcontrol abilities run get-site-v1 --input '{\"site_id_or_domain\": 1}' --json
222
-
223
- # Or use a file (works everywhere)
224
- mainwpcontrol abilities run get-site-v1 --input-file params.json --json
225
- ```
226
-
227
- ### Profiles
228
-
229
- Each `mainwpcontrol login` creates a profile, a named connection to a Dashboard, identified by hostname. If you manage multiple Dashboards, run `login` once per Dashboard to create a profile for each.
230
-
231
- ```bash
232
- # List all profiles
233
- mainwpcontrol profile list
234
-
235
- # Switch active profile
236
- mainwpcontrol profile use production.example.com
237
-
238
- # Use a profile for one command without switching
239
- mainwpcontrol abilities list --profile staging.example.com
240
-
241
- # Delete a profile and its keychain credentials
242
- mainwpcontrol profile delete staging.example.com
243
88
  ```
244
89
 
245
- ### Diagnostics
246
-
247
- `doctor` checks your configuration, credentials, and Dashboard connectivity. Run it first if something isn't working.
248
-
249
- ```bash
250
- # Check configuration and connectivity
251
- mainwpcontrol doctor
252
-
253
- # Verbose output
254
- mainwpcontrol doctor -v
90
+ ```text
91
+ Abilities (87 total)
255
92
 
256
- # JSON output
257
- mainwpcontrol doctor --json
93
+ Sites
94
+ Name Description Type
95
+ ---------------- -------------------- --------------
96
+ list-sites-v1 List MainWP sites 📖 read
97
+ mainwpcontrol abilities run list-sites-v1
98
+ get-site-v1 Get site details 📖 read
99
+ mainwpcontrol abilities run get-site-v1
100
+ sync-sites-v1 Sync all sites ✏️ write
101
+ mainwpcontrol abilities run sync-sites-v1
258
102
  ```
259
103
 
260
- ### Chat Mode
261
-
262
- If you have an LLM API key, you can talk to your Dashboard in plain English instead of constructing commands. Good for exploration, not required for anything.
263
-
264
- Set one of these environment variables to enable it:
104
+ Every operation your Dashboard supports, with the exact command to run it and whether it reads, writes, or destroys. Pick one and run it:
265
105
 
266
106
  ```bash
267
- # Pick one (Anthropic, OpenAI, Google, or OpenRouter)
268
- export ANTHROPIC_API_KEY='sk-ant-...'
269
-
270
- mainwpcontrol chat
271
- mainwpcontrol chat "list all sites with pending updates"
107
+ mainwpcontrol abilities run list-sites-v1 --json
272
108
  ```
273
109
 
274
- See [Chat Mode Configuration](#chat-mode-configuration) for all supported providers and flags.
275
-
276
- ### Global Flags
277
-
278
- These flags work on every command.
279
-
280
- | Flag | Description |
281
- |------|-------------|
282
- | `--json` | Structured JSON output |
283
- | `--quiet` / `-q` | Suppress output (exit code only) |
284
- | `--profile <name>` | Use a specific profile |
285
- | `--debug` | Show redacted debug diagnostics on stderr |
286
- | `--help` | Show help |
287
-
288
- ### Abilities Run Flags
289
-
290
- Extra flags for `abilities run`. These control input, safety checks, and batch job behavior.
291
-
292
- | Flag | Description |
293
- |------|-------------|
294
- | `--input` / `-i` | Input parameters as JSON (use `-` for stdin) |
295
- | `--input-file` | Read input from a JSON file |
296
- | `--dry-run` | Preview changes without executing |
297
- | `--confirm` | Execute a destructive ability |
298
- | `--force` | Skip interactive confirmation (CI mode) |
299
- | `--wait` | Block until batch job completes |
300
- | `--wait-timeout` | Max seconds to wait (default: 300) |
110
+ > **New to the command line?** [Getting Started](docs/getting-started.md) covers terminals, environment variables, JSON quoting, and everything else the other guides assume.
301
111
 
302
- ---
303
-
304
- ## Concepts
305
-
306
- ### Abilities
307
-
308
- Abilities are the operations your MainWP Dashboard exposes through its REST API. Each one has:
309
-
310
- - A versioned name (e.g., `list-sites-v1`, `delete-site-v1`)
311
- - An input schema (what parameters it accepts)
312
- - Annotations that tell you what kind of operation it is
313
-
314
- The annotations matter:
315
- - **Readonly**: Safe to run anytime. Cannot modify data.
316
- - **Destructive**: Permanently changes or deletes data. Requires `--dry-run` preview, then `--confirm` to execute.
317
- - **Idempotent**: Safe to re-run. Same result on repeated calls.
318
-
319
- Run `mainwpcontrol abilities info <name>` to see the full schema and annotations for any ability.
320
-
321
- ### Profiles
322
-
323
- A profile is a named connection to a MainWP Dashboard. It stores the Dashboard URL and username. Your password stays in the OS keychain (or in the `MAINWP_APP_PASSWORD` environment variable when no keychain is available).
324
-
325
- Running `mainwpcontrol login` creates a profile automatically, named after the Dashboard hostname:
112
+ ## Everyday Commands
326
113
 
327
114
  ```bash
328
- # Creates profile "staging.example.com"
329
- mainwpcontrol login --url https://staging.example.com --username admin
330
-
331
- # Creates profile "production.example.com"
332
- mainwpcontrol login --url https://production.example.com --username admin
333
- ```
334
-
335
- The profile file at `~/.config/mainwpcontrol/profiles.json` never contains passwords.
336
-
337
- ### Safety Model
115
+ # Check for pending updates across all sites
116
+ mainwpcontrol abilities run list-updates-v1 --json
338
117
 
339
- Destructive operations follow a two-step pattern: preview first, then execute.
118
+ # Get details for one site
119
+ mainwpcontrol abilities run get-site-v1 --input '{"site_id_or_domain": 1}' --json
340
120
 
341
- ```bash
342
- # Step 1: Preview (nothing changes)
121
+ # Preview a destructive action; nothing changes without --confirm
343
122
  mainwpcontrol abilities run delete-site-v1 \
344
123
  --input '{"site_id_or_domain": "mysite.com"}' \
345
124
  --dry-run --json
346
125
 
347
- # Step 2: Execute after reviewing the preview
348
- mainwpcontrol abilities run delete-site-v1 \
349
- --input '{"site_id_or_domain": "mysite.com"}' \
350
- --confirm --force --json
351
- ```
352
-
353
- `--dry-run` and `--confirm` are mutually exclusive. You cannot pass both.
354
-
355
- In CI/scripted workflows where you've already validated the operation, pass `--confirm --force` directly to skip the interactive prompt.
356
-
357
- ### Batch Jobs
358
-
359
- Operations that affect many items (200+) are automatically queued as batch jobs. The command returns a `job_id` immediately, and you can watch progress:
360
-
361
- ```bash
362
- mainwpcontrol jobs watch <job-id>
363
-
364
- # With a timeout
365
- mainwpcontrol jobs watch <job-id> --timeout 120
366
- ```
367
-
368
- Or use `--wait` on the original command to block until completion:
369
-
370
- ```bash
371
- mainwpcontrol abilities run sync-sites-v1 --wait --wait-timeout 300 --json
372
- ```
373
-
374
- ---
375
-
376
- ## Advanced Usage
377
-
378
- ### CI/CD Patterns
379
-
380
- ```bash
381
- # Non-interactive login
382
- export MAINWP_APP_PASSWORD='xxxx xxxx xxxx xxxx xxxx xxxx'
383
- mainwpcontrol login --url https://dashboard.example.com --username admin
384
-
385
- # Silent execution with exit codes
386
- mainwpcontrol abilities run list-sites-v1 --json --quiet
387
- echo "Exit code: $?"
388
-
389
- # Pipeline branching on exit codes
390
- if mainwpcontrol abilities run check-sites-v1 --json --quiet; then
391
- echo "All sites healthy"
392
- else
393
- echo "Issues detected"
394
- fi
395
- ```
396
-
397
- ### Input from Files and Stdin
398
-
399
- ```bash
400
- # From a JSON file
401
- mainwpcontrol abilities run update-site-plugins-v1 --input-file params.json --json
402
-
403
- # From stdin
404
- echo '{"site_id_or_domain": 1}' | mainwpcontrol abilities run get-site-v1 --input - --json
405
-
406
- # Heredoc
407
- mainwpcontrol abilities run get-site-v1 --input - --json <<EOF
408
- {"site_id_or_domain": 1}
409
- EOF
410
- ```
411
-
412
- ### Chat Mode Configuration
413
-
414
- Chat requires one of these environment variables:
415
-
416
- | Variable | Provider |
417
- |----------|----------|
418
- | `ANTHROPIC_API_KEY` | Anthropic Claude |
419
- | `OPENAI_API_KEY` | OpenAI GPT |
420
- | `GOOGLE_API_KEY` | Google Gemini |
421
- | `OPENROUTER_API_KEY` | OpenRouter |
422
- | `LOCAL_LLM_API_KEY` | Local LLM (with optional `LOCAL_LLM_URL`) |
423
-
424
- Additional chat flags: `--provider`, `--model`, `--max-turns`, `--max-context-messages`, `--no-stream`.
425
-
426
- In non-TTY environments (pipes, CI), `mainwpcontrol chat` without a message argument exits with guidance instead of hanging.
126
+ # Updates are classified destructive too: preview, then confirm
127
+ # (--force skips the interactive prompt for CI; --wait blocks until done)
128
+ mainwpcontrol abilities run update-site-plugins-v1 \
129
+ --input '{"site_id_or_domain": 1}' --dry-run --json
130
+ mainwpcontrol abilities run update-site-plugins-v1 \
131
+ --input '{"site_id_or_domain": 1}' --confirm --force --wait --json
427
132
 
428
- ### Shell Completion
133
+ # See the input schema for any ability
134
+ mainwpcontrol abilities info update-site-plugins-v1
429
135
 
430
- ```bash
431
- # Bash
432
- source /path/to/mainwp-control/scripts/completions/mainwpcontrol.bash
433
-
434
- # Zsh
435
- source /path/to/mainwp-control/scripts/completions/mainwpcontrol.zsh
136
+ # Something wrong? Diagnose configuration and connectivity
137
+ mainwpcontrol doctor
436
138
  ```
437
139
 
438
- ### Configuration File
140
+ Managing more than one Dashboard? Each `login` creates a profile named after the hostname; switch with `mainwpcontrol profile use <name>` or per-command with `--profile <name>`. See the [CLI Reference](docs/cli-reference.md#profile) for details.
439
141
 
440
- Settings live at `~/.config/mainwpcontrol/settings.json`:
142
+ > **Windows PowerShell** quoting of inline JSON is unreliable; put parameters in a file and use `--input-file` instead. Git Bash handles the examples as written. Details in [Input from File](docs/workflows/input-from-file.md).
441
143
 
442
- ```json
443
- {
444
- "defaultJsonOutput": true,
445
- "timeout": 30000,
446
- "debug": false,
447
- "llmProvider": "openai",
448
- "chatContextMessages": 20
449
- }
450
- ```
144
+ ## Documentation
451
145
 
452
- ### Workflow Guides
146
+ - [Getting Started](docs/getting-started.md): terminals, npm, Application Passwords, and JSON quoting, if the command line is new territory
147
+ - [CLI Reference](docs/cli-reference.md): every command, flag, and exit code
148
+ - [Configuration](docs/configuration.md): profiles, settings.json, environment variables, and credential storage
149
+ - [Safety & Destructive Operations](docs/safety.md): the preview-and-confirm flow, ability annotations, batch jobs, and what the guard rails do and don't cover
150
+ - [Chat Mode](docs/chat.md): plain-English management with your own LLM API key
151
+ - [Troubleshooting](docs/troubleshooting.md): install failures, connection errors, and authentication issues
453
152
 
454
- Step-by-step guides for common automation patterns:
153
+ Step-by-step automation guides live in [docs/workflows](docs/workflows):
455
154
 
456
155
  | Workflow | Description |
457
156
  |----------|-------------|
@@ -461,152 +160,83 @@ Step-by-step guides for common automation patterns:
461
160
  | [Input from File](docs/workflows/input-from-file.md) | Pass complex parameters via JSON files, stdin pipes, or heredocs |
462
161
  | [Monitoring Integration](docs/workflows/monitoring-integration.md) | Send site metrics to Datadog, StatsD, or other monitoring tools |
463
162
 
464
- ---
465
-
466
- ## Reference
467
-
468
- ### Exit Codes
469
-
470
- | Code | Meaning | CI Usage |
471
- |------|---------|----------|
472
- | 0 | Success | Continue pipeline |
473
- | 1 | User/input error | Fix command syntax |
474
- | 2 | Auth/config error | Check credentials |
475
- | 3 | Network error | Retry or check connectivity |
476
- | 4 | API error | Check ability parameters |
477
- | 5 | Internal error | Report bug |
163
+ ## Configuration
478
164
 
479
- ### Environment Variables
480
-
481
- #### MainWP Configuration
165
+ Interactive use needs no configuration beyond `mainwpcontrol login`. For CI, Docker, and headless machines:
482
166
 
483
167
  | Variable | Description |
484
168
  |----------|-------------|
485
- | `MAINWP_APP_PASSWORD` | Application password for non-interactive login and commands when keychain is unavailable |
486
- | `MAINWPCONTROL_NO_KEYTAR` | Set to `1` to skip keytar (keychain) loading entirely |
487
- | `MAINWP_ALLOW_HTTP` | Set to `1` to allow insecure HTTP Dashboard URLs |
488
-
489
- #### Chat/LLM Configuration
490
-
491
- | Variable | Description |
492
- |----------|-------------|
493
- | `ANTHROPIC_API_KEY` | Anthropic Claude |
494
- | `OPENAI_API_KEY` | OpenAI GPT |
495
- | `GOOGLE_API_KEY` | Google Gemini |
496
- | `OPENROUTER_API_KEY` | OpenRouter |
497
- | `LOCAL_LLM_API_KEY` | Local LLM provider (required to enable local provider) |
498
- | `LOCAL_LLM_URL` | Local endpoint URL (optional, defaults to localhost) |
499
- | `MAINWP_LLM_PROVIDER` | Override auto-detected provider |
500
- | `MAINWP_LLM_MODEL` | Specify model to use |
501
-
502
- ### Configuration Settings
503
-
504
- All settings in `~/.config/mainwpcontrol/settings.json`:
505
-
506
- | Setting | Type | Description |
507
- |---------|------|-------------|
508
- | `defaultJsonOutput` | boolean | Default to JSON output |
509
- | `timeout` | number | HTTP request timeout in milliseconds |
510
- | `debug` | boolean | Enable debug output |
511
- | `llmProvider` | string | Default LLM provider for chat |
512
- | `chatContextMessages` | number | Max messages in chat context |
513
- | `skipSSLVerification` | boolean | Disable TLS verification (insecure, prefer per-profile setting via `login --skip-ssl-verify`) |
514
- | `allowInsecureHttp` | boolean | Allow `http://` Dashboard URLs without `MAINWP_ALLOW_HTTP=1` |
515
-
516
- ---
517
-
518
- ## Troubleshooting
519
-
520
- <details>
521
- <summary><strong>"keytar failed to build" or native module errors during install</strong></summary>
522
-
523
- Keytar requires native C++ compilation on some platforms. If it fails:
524
-
525
- 1. **Use environment variable auth instead** (bypasses keytar entirely):
526
- ```bash
527
- export MAINWP_APP_PASSWORD='your-application-password'
528
- mainwpcontrol login --url https://dashboard.example.com --username admin
529
- ```
530
- 2. **Or skip keytar explicitly** by setting `MAINWPCONTROL_NO_KEYTAR=1` before running commands.
169
+ | `MAINWP_APP_PASSWORD` | Application Password for non-interactive login, and for commands when no OS keychain is available |
170
+ | `MAINWP_DASHBOARD_URL` | The Dashboard `MAINWP_APP_PASSWORD` belongs to. Required whenever a command authenticates using that fallback |
171
+ | `MAINWPCONTROL_NO_KEYTAR` | Set to `1` to skip keychain loading entirely |
172
+ | `MAINWP_ALLOW_HTTP` | Set to `1` to allow insecure `http://` Dashboard URLs |
531
173
 
532
- The pre-built binaries cover macOS, Windows, and Linux (x64/arm64). If you're on a different platform or architecture, you'll need C++ build tools (`gcc`, `g++`, `make`) or the env var approach.
533
-
534
- </details>
535
-
536
- <details>
537
- <summary><strong>"command not found" after install</strong></summary>
174
+ ```bash
175
+ export MAINWP_APP_PASSWORD='xxxx xxxx xxxx xxxx xxxx xxxx'
176
+ export MAINWP_DASHBOARD_URL='https://dashboard.example.com'
177
+ mainwpcontrol login --url https://dashboard.example.com --username admin
178
+ mainwpcontrol abilities list
179
+ ```
538
180
 
539
- This usually means your npm global bin directory isn't in your system PATH.
181
+ Whenever the password comes from `MAINWP_APP_PASSWORD`, the CLI sends it only to the
182
+ Dashboard named in `MAINWP_DASHBOARD_URL`, and fails instead of sending it anywhere
183
+ else. That covers `login` as well as later commands: in CI the password usually lives
184
+ in a protected secret store while command arguments do not, so pinning the destination
185
+ next to the secret is what stops an edited pipeline from redirecting it. It also means
186
+ a `profiles.json` someone else can write cannot point your credential at their server.
540
187
 
541
- 1. **Find where npm installs global packages:**
542
- ```bash
543
- npm config get prefix
544
- ```
545
- 2. **Add the `bin` subdirectory to your PATH.** For example, if the prefix is `/usr/local`:
546
- ```bash
547
- # Add to ~/.bashrc, ~/.zshrc, or your shell profile:
548
- export PATH="/usr/local/bin:$PATH"
549
- ```
550
- 3. **Restart your terminal** (or run `source ~/.zshrc` / `source ~/.bashrc`) and try again.
188
+ Credentials in the OS keychain are bound to their Dashboard the same way and need no
189
+ extra variable. `login` only prompts for the password when `MAINWP_APP_PASSWORD` is
190
+ unset; when it is set, the same binding applies. Commands that only display
191
+ configuration, such as `doctor` and `config show`, are unaffected.
551
192
 
552
- On Windows, the npm global directory is usually already in PATH after installing Node.js.
193
+ Optional defaults (JSON output, timeouts, chat provider) live in `~/.config/mainwpcontrol/settings.json`. The full list of settings, chat provider keys, and the credential storage model are in the [Configuration guide](docs/configuration.md).
553
194
 
554
- </details>
195
+ ## Abilities
555
196
 
556
- <details>
557
- <summary><strong>"connection refused" or network errors</strong></summary>
197
+ Your Dashboard exposes its operations as versioned, self-describing "abilities" (the exact set varies by Dashboard version):
558
198
 
559
- If `mainwpcontrol login` or commands fail with connection errors:
199
+ | Category | Abilities | Reference |
200
+ | ---------------- | --------- | ----------------------------------------------------------------------------------------- |
201
+ | Sites | 30 | [Sites Abilities](https://docs.mainwp.com/api-reference/abilities-api/sites) |
202
+ | Updates | 13 | [Updates Abilities](https://docs.mainwp.com/api-reference/abilities-api/updates) |
203
+ | Clients | 11 | [Clients Abilities](https://docs.mainwp.com/api-reference/abilities-api/clients) |
204
+ | Tags | 7 | [Tags Abilities](https://docs.mainwp.com/api-reference/abilities-api/tags) |
205
+ | Batch Operations | 1 | [Batch Operations](https://docs.mainwp.com/api-reference/abilities-api/batch-operations) |
560
206
 
561
- 1. **Check the Dashboard URL.** Make sure it's the full URL with `https://` (e.g., `https://dashboard.example.com`). Don't include a trailing slash.
562
- 2. **Verify HTTPS.** `mainwpcontrol` requires HTTPS by default. If your Dashboard uses HTTP (not recommended), set `MAINWP_ALLOW_HTTP=1`.
563
- 3. **Check firewall/network.** Make sure your machine can reach the Dashboard:
564
- ```bash
565
- curl -I https://dashboard.example.com
566
- ```
567
- 4. **SSL certificate issues.** If using a self-signed certificate, you can use `mainwpcontrol login --skip-ssl-verify` (not recommended for production).
207
+ The table counts the Dashboard's built-in `mainwp/*` abilities. Extensions and other plugins can register their own, so your total may be higher (the 87 in the Quick Start sample comes from a Dashboard with extensions installed). `abilities list` shows what your Dashboard actually offers, `abilities info <name>` shows an ability's input schema and annotations, and `abilities run <name>` executes it. Because the CLI discovers abilities at runtime, new Dashboard capabilities appear without a CLI update.
568
208
 
569
- </details>
209
+ ## Safety
570
210
 
571
- ---
211
+ Every ability carries annotations that classify it as read-only, a write, or destructive, and the CLI enforces them. Destructive operations follow a two-step flow: a `--dry-run` preview shows what the Dashboard reports would be affected, and only an explicit `--confirm` executes it. The destructive class is deliberately wide: deletions, updates (`update-site-*`, `run-updates-*`, `update-all-*`), any ability that does not declare itself non-destructive, and a conservative name-based override that a mislabeling Dashboard cannot downgrade. The two flags are mutually exclusive, previews that fail block execution, and each confirmed run is written to a local audit log. Scripted pipelines that have already validated an operation can pass `--confirm --force` to skip the interactive prompt; that is a deliberate, per-command decision, never a default. Chat mode goes through the identical execution path, so an LLM can propose a destructive action but cannot confirm it. The full model is in [Safety & Destructive Operations](docs/safety.md).
572
212
 
573
213
  ## Contributing
574
214
 
575
215
  ```bash
576
- npm run build # Build the project
577
- npm test # Run tests (unit + e2e, no network needed)
578
- npm run lint # Check code style
216
+ npm ci # install dependencies
217
+ npm run build # build
218
+ npm test # run tests (unit + e2e, no network needed)
219
+ npm run lint # check code style
579
220
  ```
580
221
 
581
- ### Live Integration Tests
222
+ CI runs lint, type check, tests, and build on every pull request.
582
223
 
583
- `npm run test:live` runs tests against a real MainWP Dashboard, including workflow documentation validation. These require a running Dashboard and credentials:
224
+ `npm run test:live` exercises a real Dashboard: API tests (login, discovery, read-only execution, safety model, exit codes) plus validation that every jq expression and field name in `docs/workflows/` works against the real API. It runs read-only operations and `--dry-run` previews only, never mutations, and needs credentials:
584
225
 
585
226
  ```bash
586
227
  export MAINWP_API_URL=https://your-dashboard.example.com
587
228
  export MAINWP_USER=your-admin-username
588
229
  export MAINWP_APP_PASSWORD='your-application-password'
230
+ export MAINWP_DASHBOARD_URL="$MAINWP_API_URL"
589
231
 
590
232
  npm run test:live
591
233
  ```
592
234
 
593
- The live suite includes API tests (login, abilities discovery, read-only execution, safety model, exit codes) and workflow doc tests (validates that every jq expression, field name, and data pipeline documented in `docs/workflows/` works against the real API).
594
-
595
- Live tests are safe: they only run read-only operations and `--dry-run` previews, never mutations.
596
-
597
- ---
235
+ The full acceptance harness, which packs and installs the CLI as a consumer would, is described in [Acceptance Testing](docs/acceptance-testing.md).
598
236
 
599
237
  ## License
600
238
 
601
- GPL-3.0-or-later
602
-
603
- ---
604
-
605
- ## Requirements
606
-
607
- - Node.js 20 LTS or later
608
- - MainWP Dashboard 6+ with Abilities API
609
- - WordPress Application Password
239
+ GPL-3.0-or-later. See [LICENSE](LICENSE).
610
240
 
611
241
  ---
612
242