devops-whc 1.0.2 → 1.0.3

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.
package/README.md CHANGED
@@ -1,377 +1,134 @@
1
- # devops-whc
2
-
3
- WHC cPanel automation CLI for deploy, verify, rollback, logs, backup, and health flows.
4
-
5
- Current workspace version: 1.0.2
6
-
7
- ## Publish Package Layout
8
-
9
- Npm release artifacts are now isolated in a dedicated package folder:
10
-
11
- - `packages/devops-whc`
12
-
13
- The repository root is the development workspace. The publish package is prepared by syncing built/runtime files into `packages/devops-whc` before packing or publishing.
14
-
15
- ## What this is
16
-
17
- This package exposes a stdio tool server and CLI that VS Code Copilot or other clients can launch. It is designed for WHC cPanel projects and keeps the local workflow, target environment, and safety rules explicit.
18
-
19
- The server supports both usage patterns:
20
-
21
- 1. Run from a local clone while developing.
22
- 2. Install from npm and launch with `npx` or a global install.
23
-
24
- ## Install
25
-
26
- ### From a clone
27
-
28
- ```powershell
29
- npm install
30
- npm run build
31
- ```
32
-
33
- ### From npm
34
-
35
- ```powershell
36
- npx -y devops-whc --help
37
- ```
38
-
39
- Or install globally:
40
-
41
- ```powershell
42
- npm install -g devops-whc
43
- whc --help
44
- ```
45
-
46
- ## Quick Start
47
-
48
- 1. Copy `.env.example` to `.env`.
49
- 2. Fill in the required WHC credentials and target paths.
50
- 3. Run `npm run prepare` once per workspace.
51
- 4. Start the server with `npm run serve` for local development, or `npx -y devops-whc --serve` after npm install.
52
-
53
- If you are using VS Code Copilot, point the server command to the published package or to the local `start-whc.cjs` helper.
54
-
55
- ## NPM Scripts (Workspace Root)
56
-
57
- Run these from repository root (`devops-whc`):
58
-
59
- ```powershell
60
- npm run help
61
- npm run serve
62
- npm run start
63
- npm run probe
64
- npm run check:generic
65
- npm run check:health
66
- ```
67
-
68
- Quality and release scripts:
69
-
70
- ```powershell
71
- npm run lint
72
- npm run typecheck
73
- npm test
74
- npm run build
75
- npm run pack:check
76
- npm run publish:prepare
77
- ```
78
-
79
- When to use each:
80
-
81
- 1. `npm run serve`: run directly from TypeScript source (best for local development).
82
- 2. `npm run start`: run built output through `scripts/start-whc.cjs` (best for local runtime behavior similar to published package).
83
- 3. `npm run prepare`: initialize local `.whc` state once.
84
- 4. `npm run pack:check` / `npm run publish:npm`: publish pipeline scripts.
85
-
86
- ## NPM Scripts (Publish Subpackage)
87
-
88
- If you work inside `packages/devops-whc`, available scripts are:
89
-
90
- ```powershell
91
- npm --prefix packages/devops-whc run help
92
- npm --prefix packages/devops-whc run start
93
- npm --prefix packages/devops-whc run serve
94
- npm --prefix packages/devops-whc run probe
95
- npm --prefix packages/devops-whc run check:generic
96
- npm --prefix packages/devops-whc run check:health
97
- ```
98
-
99
- These scripts automatically sync fresh artifacts from root via pre-hooks before execution.
100
-
101
- ## VS Code Tool Server Config
102
-
103
- Published-package example:
104
-
105
- ```jsonc
106
- {
107
- "servers": {
108
- "whc": {
109
- "type": "stdio",
110
- "command": "npx",
111
- "args": ["-y", "devops-whc", "--serve"],
112
- "env": {
113
- "WHC_ENV_FILE": "${workspaceFolder}/.env",
114
- "WHC_LOCAL_PROJECT_ROOT": "${workspaceFolder}",
115
- "WHC_STATE_ROOT": ".whc",
116
- "WHC_INSTANCE_NAME": "whc"
117
- }
118
- }
119
- }
120
- }
121
- ```
122
-
123
- Local-source example:
124
-
125
- ```jsonc
126
- {
127
- "servers": {
128
- "whc": {
129
- "type": "stdio",
130
- "command": "node",
131
- "args": ["./scripts/start-whc.cjs"],
132
- "cwd": "${workspaceFolder}",
133
- "env": {
134
- "WHC_ENV_FILE": "${workspaceFolder}/.env",
135
- "WHC_LOCAL_PROJECT_ROOT": "${workspaceFolder}",
136
- "WHC_STATE_ROOT": ".whc",
137
- "WHC_INSTANCE_NAME": "whc"
138
- }
139
- }
140
- }
141
- }
142
- ```
143
-
144
- ## CLI Commands
145
-
146
- ```powershell
147
- whc --serve
148
- whc --probe
149
- whc --check-generic --project-root D:/Source/mytho/source/wordpress --workflow-mode ssh_scp_wpcli
150
- whc --check-health
151
- whc --help
152
- whc --version
153
- ```
154
-
155
- If you are using the npm package directly, the same commands work through `npx`:
156
-
157
- ```powershell
158
- npx -y devops-whc --serve
159
- npx -y devops-whc --probe
160
- npx -y devops-whc --check-generic --project-root D:/Source/mytho/source/wordpress --workflow-mode ssh_scp_wpcli
161
- npx -y devops-whc --check-health
162
- npx -y devops-whc --help
163
- npx -y devops-whc --version
164
- ```
165
-
166
- ## Local Run vs Script Run
167
-
168
- You can run the tool in both ways:
169
-
170
- 1. Local development from this repo:
171
- - Use npm scripts (`npm run serve`, `npm run probe`, `npm run check:generic`, ...).
172
- 2. Installed package usage:
173
- - Use `npx -y devops-whc ...` or global `whc ...`.
174
-
175
- You do not have to call custom script files manually in normal usage. The wrapper script (`start-whc.cjs`) is already wired behind `npm run start` and package start flow.
176
-
177
- ## Required Environment Variables
178
-
179
- Base config:
180
-
181
- - `WHC_WORKFLOW_MODE`
182
- - `WHC_LOCAL_PROJECT_ROOT`
183
-
184
- For `git_deploy`:
185
-
186
- - `WHC_API_TOKEN`
187
- - `WHC_USER`
188
- - `WHC_HOST`
189
- - `WHC_PROD_PATH`
190
-
191
- For `ssh_scp_wpcli`:
192
-
193
- - `WHC_STAGING_SSH_HOST`
194
- - `WHC_STAGING_SSH_USERNAME`
195
- - one of:
196
- - `WHC_STAGING_SSH_PRIVATE_KEY_PATH`
197
- - `WHC_STAGING_SSH_PASSWORD`
198
-
199
- ## Optional Environment Variables
200
-
201
- - `WHC_WORKFLOW_MODE`
202
- - `git_deploy`: local source -> cPanel-managed Git repo -> deployment task
203
- - `ssh_scp_wpcli`: source-driven workflow like `mytho/source` (doctor + SCP + WP-CLI + smoke)
204
- - default if omitted: `ssh_scp_wpcli`
205
- - `WHC_PRIMARY_DOMAIN`
206
- - `WHC_TESTING_DOMAIN`
207
- - `WHC_STAGING_DOMAIN`
208
- - `WHC_PROD_PATH`
209
- - `WHC_STAGING_PATH`
210
- - `WHC_REQUIRE_STAGING_CONFIRM`
211
- - `WHC_WARN_DYNAMIC_DATA_SYNC`
212
- - `WHC_ENFORCE_STAGING_FIRST`
213
-
214
- - `WHC_STAGING_SSH_HOST`
215
- - `WHC_STAGING_SSH_PORT`
216
- - `WHC_STAGING_SSH_USERNAME`
217
- - `WHC_STAGING_SSH_PRIVATE_KEY_PATH`
218
- - `WHC_STAGING_SSH_PASSWORD`
219
- - `WHC_STAGING_SSH_HOSTKEY`
220
- - `WHC_LOCAL_PROJECT_ROOT`
221
- - `WHC_LOCAL_APP_PATH`
222
- - `WHC_SOURCE_KIND`
223
- - `WHC_DEPLOY_UNIT`
224
- - `WHC_BUILD_COMMAND`
225
- - `WHC_BUILD_ARTIFACT_PATH`
226
- - `WHC_DEFAULT_RELEASE_INTENT`
227
- - `WHC_API_TIMEOUT_MS`
228
- - `WHC_SSH_TIMEOUT_MS`
229
- - `WHC_FLOW_LOG_PATH`
230
- - `WHC_STATE_ROOT`
231
-
232
- ## Practical Examples
233
-
234
- ### 1) Check connectivity before deploy
235
-
236
- ```powershell
237
- npx -y devops-whc --probe
238
- ```
239
-
240
- This checks the UAPI, SSH, and WP-CLI connectivity signals before a deploy run.
241
-
242
- ### 2) Run a health check
243
-
244
- ```powershell
245
- npx -y devops-whc --check-health
246
- ```
247
-
248
- Use this to inspect disk, SSL, load, and capability state.
249
-
250
- ### 3) Run deploy readiness check (single command)
251
-
252
- ```powershell
253
- npx -y devops-whc --check-generic --project-root D:/Source/mytho/source/wordpress --workflow-mode ssh_scp_wpcli
254
- ```
255
-
256
- Or from local clone:
257
-
258
- ```powershell
259
- npm run check:generic -- D:/Source/mytho/source/wordpress
260
- ```
261
-
262
- This command validates whether your local WordPress source shape is compatible with the WHC generic pipeline supported by this tool.
263
-
264
- `--project-root` is required. `--app-path` is optional.
265
-
266
- If `--app-path` is omitted, WHC treats `project-root` itself as the app root.
267
- If `--app-path` is provided but wrong, the command fails and does not initialize hidden files.
268
-
269
- Once the effective app root is valid, the command bootstraps hidden WHC state inside that app directory:
270
-
271
- 1. `<app-path>/.whc/state/...`
272
- 2. `<app-path>/.whc/logs/...`
273
- 3. `<app-path>/.whc/env/whc.env`
274
- 4. `<app-path>/.whc/env/whc.env.example`
275
-
276
- If credentials or SSH keys are still missing for that specific project, the check returns `status=blocked` with exact env keys to fill in the bootstrapped hidden env file.
277
-
278
- Current behavior by workflow mode:
279
-
280
- 1. `git_deploy`: validates local source/layout compatibility for repository-driven cPanel deploy flows, including `.cpanel.yml` at repository root.
281
- 2. `ssh_scp_wpcli`: validates the `mytho/source` style contract more directly:
282
- - deployable plugin/theme entrypoints
283
- - idempotent seed script
284
- - local `ssh`/`scp`
285
- - staging SSH/WP-CLI/path/domain probes
286
- - `/wp-json/` HTTP readiness
287
-
288
- Important current boundary:
289
-
290
- 1. `check:generic` is the main trustworthy gate for source compatibility and hidden-state bootstrap.
291
- 2. `whc_setup_remote` is for wiring remote Git repository metadata on cPanel.
292
- 3. `ssh_scp_wpcli` is the default workflow mode for `mytho/source`.
293
- 4. `git_deploy` now triggers the cPanel deployment task for the requested `repository_root` and optional `branch`.
294
- 5. `whc_deploy` is still not the end-to-end executor for the `mytho/source` SCP/WP-CLI pipeline.
295
-
296
- What you need from the result:
297
-
298
- 1. `ready_for_deploy=true` and `status=ready`: ready to run deploy pipeline.
299
- 2. `ready_for_deploy=false` and `status=blocked`: not ready yet.
300
- 3. `next_actions`: exact steps to fix before rerun.
301
-
302
- You do not need to choose or manage internal source categories. The command applies internal checks and returns one deploy readiness decision plus actionable next steps.
303
-
304
- ### 4) Start the tool server in VS Code
305
-
306
- Once the config is in place, Copilot can launch the server and call tools such as `whc_prepare`, `whc_deploy`, `whc_verify`, and `whc_rollback`.
307
-
308
- ### 5) Prepare workspace state once
309
-
310
- ```powershell
311
- npm run prepare
312
- ```
313
-
314
- This initializes the hidden project state under `.whc` and ensures the workspace ignores local management files.
315
-
316
- ## Safety Notes
317
-
318
- 1. Never commit `.env` or `.vscode/whc.env`.
319
- 2. Keep secrets in your local workspace only.
320
- 3. The npm tarball is limited to the published files list and does not include local env files.
321
- 4. For staging-to-live or database-changing operations, follow the tool safety prompts and confirm the release intent.
322
-
323
- ## Release Prep
324
-
325
- Run these from repository root before publishing:
1
+ # devops-whc
326
2
 
327
- ```powershell
328
- npm run typecheck
329
- npm test
330
- npm run publish:prepare
331
- npm run pack:check
332
- ```
3
+ WHC cPanel automation CLI for deploy, verify, rollback, logs, backup, and health flows.
333
4
 
334
- What each step does:
5
+ ## Getting Started
335
6
 
336
- 1. `npm run typecheck`: validates TypeScript before release.
337
- 2. `npm test`: runs the test suite.
338
- 3. `npm run publish:prepare`: syncs root docs/scripts/build output into `packages/devops-whc`.
339
- 4. `npm run pack:check`: dry-runs the actual npm package from `packages/devops-whc`.
7
+ Install globally:
8
+
9
+ ```powershell
10
+ npm install -g devops-whc
11
+ whc --help
12
+ ```
340
13
 
341
- Publish only after the dry-run looks correct:
14
+ Or run directly with `npx`:
342
15
 
343
16
  ```powershell
344
- npm run publish:npm
17
+ npx -y devops-whc --help
345
18
  ```
346
19
 
347
- ## NPM Auth
20
+ ## What This Package Is For
21
+
22
+ Use `devops-whc` when you need a local CLI / stdio server for WHC cPanel workflows such as:
23
+
24
+ 1. deploy readiness checks
25
+ 2. health and connectivity checks
26
+ 3. repository-driven cPanel Git deployment
27
+ 4. source-driven WordPress delivery with SSH/SCP/WP-CLI
28
+
29
+ ## Two Workflow Modes
30
+
31
+ ### `ssh_scp_wpcli`
32
+
33
+ Default mode. Use this for `mytho/source` style delivery:
34
+
35
+ 1. doctor
36
+ 2. backup
37
+ 3. SCP code sync
38
+ 4. WP-CLI bootstrap
39
+ 5. seed/bootstrap
40
+ 6. smoke gate
41
+
42
+ ### `git_deploy`
43
+
44
+ Use this when your real deployment path is:
45
+
46
+ 1. local Git repository
47
+ 2. push to cPanel-managed repository
48
+ 3. trigger cPanel deployment task
49
+
50
+ For this mode, `whc_deploy` uses:
348
51
 
349
- Authenticate npm on this machine before the real publish:
52
+ 1. `repository_root` as the remote cPanel-managed repository path
53
+ 2. optional `branch` if you want to deploy a specific branch
54
+
55
+ ## First Practical Step
56
+
57
+ Run a readiness check against the actual project folder you want to manage:
350
58
 
351
59
  ```powershell
352
- npm whoami
353
- npm login
354
- npm whoami
60
+ npx -y devops-whc --check-generic --project-root D:/Source/mytho/source/wordpress
355
61
  ```
356
62
 
357
- If your org uses browser-based auth, npm may open a web flow after `npm login`.
63
+ What this does:
64
+
65
+ 1. validates the target project layout
66
+ 2. bootstraps hidden WHC state under that project
67
+ 3. tells you exactly which env values are still missing
68
+
69
+ `--project-root` is required.
358
70
 
359
- Useful checks:
71
+ `--app-path` is optional.
72
+ If omitted, WHC treats `project-root` itself as the app root.
73
+
74
+ ## Commands You Will Actually Use
360
75
 
361
76
  ```powershell
362
- npm config get registry
363
- npm access ls-packages
77
+ whc --help
78
+ whc --probe
79
+ whc --check-health
80
+ whc --check-generic --project-root D:/Source/mytho/source/wordpress
81
+ whc --serve
82
+ ```
83
+
84
+ The same commands also work with `npx -y devops-whc ...`.
85
+
86
+ ## VS Code / Copilot Example
87
+
88
+ ```jsonc
89
+ {
90
+ "servers": {
91
+ "whc": {
92
+ "type": "stdio",
93
+ "command": "npx",
94
+ "args": ["-y", "devops-whc", "--serve"],
95
+ "env": {
96
+ "WHC_ENV_FILE": "${workspaceFolder}/.env",
97
+ "WHC_LOCAL_PROJECT_ROOT": "${workspaceFolder}",
98
+ "WHC_STATE_ROOT": ".whc",
99
+ "WHC_INSTANCE_NAME": "whc"
100
+ }
101
+ }
102
+ }
103
+ }
364
104
  ```
365
105
 
366
- Release notes:
367
-
368
- 1. `npm run publish:npm` publishes from `packages/devops-whc`, not from repository root.
369
- 2. For prerelease versions like `1.0.2-next`, the publish script automatically uses dist-tag `next`.
370
- 3. Do not run `npm publish` directly from the repository root package.
371
- 4. Be explicit in release notes that `ssh_scp_wpcli` is the default mode for `mytho/source`, while `git_deploy` is the repository-driven cPanel deployment path.
372
-
373
- ## License
374
-
375
- ISC
376
-
377
-
106
+ ## Minimum Config Mindset
107
+
108
+ For `git_deploy`, think:
109
+
110
+ 1. `WHC_API_TOKEN`
111
+ 2. `WHC_USER`
112
+ 3. `WHC_HOST`
113
+ 4. `WHC_PROD_PATH`
114
+ 5. `repository_root`
115
+
116
+ For `ssh_scp_wpcli`, think:
117
+
118
+ 1. local WordPress app root
119
+ 2. staging SSH host/user
120
+ 3. SSH key or password
121
+ 4. remote staging path
122
+ 5. smoke-ready WordPress runtime
123
+
124
+ ## Current Boundary
125
+
126
+ 1. `check:generic` is the main trustworthy readiness/bootstrap gate.
127
+ 2. `whc_setup_remote` prepares remote Git repository wiring on cPanel.
128
+ 3. `git_deploy` triggers the cPanel deployment task for the requested `repository_root` and optional `branch`.
129
+ 4. `ssh_scp_wpcli` is still the correct default mindset for `mytho/source`.
130
+ 5. `whc_deploy` does not yet execute the full `ssh_scp_wpcli` runtime pipeline end to end; keep that in project-local scripts.
131
+
132
+ ## License
133
+
134
+ ISC
@@ -7,10 +7,10 @@ exports.loadConfig = loadConfig;
7
7
  const dotenv_1 = __importDefault(require("dotenv"));
8
8
  const zod_1 = require("zod");
9
9
  if (process.env.WHC_ENV_FILE && process.env.WHC_ENV_FILE.trim().length > 0) {
10
- dotenv_1.default.config({ path: process.env.WHC_ENV_FILE });
10
+ dotenv_1.default.config({ path: process.env.WHC_ENV_FILE, quiet: true });
11
11
  }
12
12
  else {
13
- dotenv_1.default.config();
13
+ dotenv_1.default.config({ quiet: true });
14
14
  }
15
15
  const envSchema = zod_1.z.object({
16
16
  WHC_API_TOKEN: zod_1.z.string().min(1).optional(),
package/dist/index.js CHANGED
@@ -23,34 +23,34 @@ const APP_VERSION = process.env.npm_package_version ?? "0.0.0";
23
23
  const HELP_TEXT = [
24
24
  `WHC CLI Help v${APP_VERSION}`,
25
25
  "",
26
+ "Getting started:",
27
+ " 1) Create a project-local .env with your WHC values",
28
+ " 2) Run check-generic against the real project folder you want to manage",
29
+ " 3) Fix any blocked env/path issues reported by the check",
30
+ " 4) Run serve when you want Copilot/clients to call the tool server",
31
+ "",
32
+ "Most-used commands:",
33
+ " whc --help",
34
+ " whc --probe",
35
+ " whc --check-health",
36
+ " whc --check-generic --project-root D:/Source/mytho/source/wordpress",
37
+ " whc --serve",
38
+ "",
39
+ "npx equivalents:",
40
+ " npx -y devops-whc --help",
41
+ " npx -y devops-whc --probe",
42
+ " npx -y devops-whc --check-health",
43
+ " npx -y devops-whc --check-generic --project-root D:/Source/mytho/source/wordpress",
44
+ " npx -y devops-whc --serve",
45
+ "",
26
46
  "Modes:",
27
- " --serve Start stdio tool server (registers all tools)",
47
+ " --serve Start stdio tool server",
28
48
  " --probe Run connectivity probe (UAPI, SSH, WP-CLI)",
29
49
  " --check-generic Run one-shot deploy readiness check for a specific project folder",
30
50
  " --check-health Execute whc_check_health once and print JSON",
31
51
  " --version Print CLI version",
32
52
  " --help Show this help",
33
53
  "",
34
- "Quick start:",
35
- " 1) npm install",
36
- " 2) copy .env.example to .env and fill secrets",
37
- " 3) npm run prepare",
38
- " 4) npm run serve",
39
- "",
40
- "Published package use:",
41
- " npx -y devops-whc --serve",
42
- " npx -y devops-whc --probe",
43
- " npx -y devops-whc --check-generic --project-root D:/Source/mytho/source/wordpress --workflow-mode ssh_scp_wpcli",
44
- " npx -y devops-whc --check-health",
45
- "",
46
- "Safe release flow:",
47
- " 1) check-health",
48
- " 2) pre-deploy logs",
49
- " 3) staging deploy dry-run (confirmed=true if policy requires)",
50
- " 4) staging deploy real",
51
- " 5) smoke gate",
52
- " 6) promote live only when smoke is green",
53
- "",
54
54
  "Git deploy payload reminders:",
55
55
  " - repository_root is required",
56
56
  " - branch is optional; omitted means deploy current configured HEAD",
@@ -68,8 +68,8 @@ const HELP_TEXT = [
68
68
  " - do not commit .env or .vscode/whc.env",
69
69
  " - npm tarball excludes local env files by design",
70
70
  "",
71
- "Reference:",
72
- " - AGENT_USAGE.md",
71
+ "Contributor note:",
72
+ " - if you are developing from the git repo, use README.md in the repository root",
73
73
  ].join("\n");
74
74
  async function main() {
75
75
  if (process.argv.includes("--help")) {
package/dist/server.js CHANGED
@@ -50,7 +50,7 @@ async function createWhcToolServer() {
50
50
  const ToolServerClass = sdkModule["M" + "cpServer"];
51
51
  const server = new ToolServerClass({
52
52
  name: instanceName,
53
- version: "1.0.2",
53
+ version: "1.0.3",
54
54
  });
55
55
  // ── whc_prepare ───────────────────────────────────────────────────────────
56
56
  server.registerTool("whc_prepare", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devops-whc",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "WHC cPanel automation CLI for deploy, verify, and rollback flows",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -12,27 +12,15 @@
12
12
  "files": [
13
13
  "dist",
14
14
  "scripts/start-whc.cjs",
15
- "scripts/prepare-first-time.cjs",
16
15
  "README.md",
17
- "AGENT_USAGE.md",
18
- "WHC_REQUIREMENTS.md",
19
16
  "LICENSE"
20
17
  ],
21
18
  "scripts": {
22
- "prepack": "node ../../scripts/prepare-publish-package.cjs",
23
- "publish:release": "npm publish",
24
- "pack:check": "npm pack --dry-run",
25
- "prehelp": "node ../../scripts/prepare-publish-package.cjs",
26
19
  "help": "node dist/index.js --help",
27
- "prestart": "node ../../scripts/prepare-publish-package.cjs",
28
20
  "start": "node scripts/start-whc.cjs",
29
- "preserve": "node ../../scripts/prepare-publish-package.cjs",
30
21
  "serve": "node dist/index.js --serve",
31
- "preprobe": "node ../../scripts/prepare-publish-package.cjs",
32
22
  "probe": "node dist/index.js --probe",
33
- "precheck:generic": "node ../../scripts/prepare-publish-package.cjs",
34
23
  "check:generic": "node dist/index.js --check-generic",
35
- "precheck:health": "node ../../scripts/prepare-publish-package.cjs",
36
24
  "check:health": "node dist/index.js --check-health"
37
25
  },
38
26
  "keywords": [
package/AGENT_USAGE.md DELETED
@@ -1,375 +0,0 @@
1
- # WHC CLI Agent Usage Guide
2
-
3
- This guide is for AI agents and operators who need predictable, safe usage of the WHC tool server.
4
-
5
- ## 1. Goal
6
-
7
- Use WHC CLI to run a safe release flow:
8
-
9
- 1. Initialize workspace state (`whc_prepare`).
10
- 2. Validate connectivity and environment.
11
- 3. Deploy to staging first.
12
- 4. Run technical verify (`whc_verify`) and smoke gate.
13
- 5. Promote to live only if staging passes.
14
-
15
- ## 2. Runtime Model
16
-
17
- The server supports two workflow modes:
18
-
19
- 1. `git_deploy`
20
- 2. `ssh_scp_wpcli`
21
-
22
- `git_deploy` means local source is pushed to a cPanel-managed Git repository and deployment is triggered from that repository.
23
- `ssh_scp_wpcli` means source-first delivery over SSH/SCP with runtime bootstrap via WP-CLI and smoke gating.
24
- If `WHC_WORKFLOW_MODE` is omitted, default to `ssh_scp_wpcli`.
25
-
26
- ## 2.2 Tool Server Registration Standard
27
-
28
- Use one of these two registration patterns and keep them consistent with README.
29
-
30
- Published package (`npx`) recommended for most users:
31
-
32
- ```jsonc
33
- {
34
- "servers": {
35
- "whc": {
36
- "type": "stdio",
37
- "command": "npx",
38
- "args": ["-y", "devops-whc", "--serve"],
39
- "env": {
40
- "WHC_ENV_FILE": "${workspaceFolder}/.env",
41
- "WHC_LOCAL_PROJECT_ROOT": "${workspaceFolder}",
42
- "WHC_STATE_ROOT": ".whc",
43
- "WHC_INSTANCE_NAME": "whc"
44
- }
45
- }
46
- }
47
- }
48
- ```
49
-
50
- Local clone (`start-whc.cjs`) for contributors:
51
-
52
- ```jsonc
53
- {
54
- "servers": {
55
- "whc": {
56
- "type": "stdio",
57
- "command": "node",
58
- "args": ["./scripts/start-whc.cjs"],
59
- "cwd": "${workspaceFolder}",
60
- "env": {
61
- "WHC_ENV_FILE": "${workspaceFolder}/.env",
62
- "WHC_LOCAL_PROJECT_ROOT": "${workspaceFolder}",
63
- "WHC_STATE_ROOT": ".whc",
64
- "WHC_INSTANCE_NAME": "whc"
65
- }
66
- }
67
- }
68
- }
69
- ```
70
-
71
- Quick CLI checks:
72
-
73
- ```powershell
74
- npx -y devops-whc --help
75
- npx -y devops-whc --version
76
- npx -y devops-whc --probe
77
- ```
78
-
79
- ## 2.3 Publish Package Boundary
80
-
81
- Release artifacts are published from `packages/devops-whc`, not from repository root.
82
-
83
- Release commands:
84
-
85
- ```powershell
86
- npm run pack:check
87
- npm run publish:npm
88
- ```
89
-
90
- `npm run pack:check` will run publish preparation and package dry-run against the subpackage.
91
- `npm run publish:npm` runs `npm publish` from the publish subpackage.
92
- For prerelease versions, `npm run publish:npm` automatically adds `--tag next` unless an explicit tag is provided.
93
-
94
- ## 2.1 Why `whc_setup_remote` Exists
95
-
96
- `whc_setup_remote` does not deploy application code.
97
-
98
- It only prepares the remote Git endpoint on cPanel (repository root + SSH hint) so local source can be pushed.
99
-
100
- Think of it as wiring transport, not shipping release.
101
-
102
- After `whc_setup_remote`, a manual or automated `git push` from local source is still required.
103
-
104
- Current boundary:
105
-
106
- 1. `whc_setup_remote` is ready for remote Git repository setup.
107
- 2. `check:generic` is the main trustworthy readiness gate for both workflow modes.
108
- 3. `whc_deploy` for `git_deploy` triggers the real cPanel deployment task for a given `repository_root` and optional `branch`.
109
- 4. `whc_deploy` does not yet execute the full `ssh_scp_wpcli` runtime pipeline; keep that in project-local scripts for now.
110
-
111
- ## 3. Required Context Before Any Write
112
-
113
- Always collect these first:
114
-
115
- 1. Active workflow mode.
116
- 2. Target environment (`staging` or `live`).
117
- 3. For `git_deploy`, identify the remote repository root and branch that should be deployed.
118
- 4. For `ssh_scp_wpcli`, identify the local app root, staging SSH target, and runtime bootstrap path.
119
- 5. Whether `dry_run` and `confirmed` are required by policy.
120
-
121
- ## 3.1 Manual vs Agent Responsibilities
122
-
123
- User/operator must do manually (once per environment):
124
- 1. Create/rotate WHC API token and place in env (`WHC_API_TOKEN`).
125
- 2. Add SSH public key to correct cPanel account.
126
- 3. Confirm host/path ownership and account scope.
127
-
128
- Agent can automate repeatedly:
129
- 1. Validate context and run dry-run checks.
130
- 2. Create/list repository via `whc_setup_remote`.
131
- 3. Push local source to the cPanel-managed Git repository when credentials are available.
132
- 4. Trigger deployment via `whc_deploy` for the intended `repository_root` and optional `branch`.
133
- 5. Execute safe runtime probes and logs/health collection.
134
- 6. Run source-compatibility checks and hidden-state bootstrap for a specific project root.
135
-
136
- Hybrid step:
137
- 1. `git push` may be run by agent from local terminal when keys/permissions are ready; otherwise operator performs push manually.
138
-
139
- ## 4. Safety Rules
140
-
141
- 1. Never claim a deploy was executed unless the handler actually changed remote state.
142
- 2. Never promote live directly without staging verification.
143
- 3. Prefer `dry_run=true` before state-changing requests.
144
- 4. Always set `confirmed=true` when the policy requires explicit confirmation.
145
-
146
- ## 5. Tool Order (Recommended)
147
-
148
- 1. `whc_prepare` to initialize hidden state and readiness checks.
149
- 2. `whc_check_health` for target status and capability baseline.
150
- 3. `whc_get_logs` for pre-deploy signal.
151
- 4. For `git_deploy`, run remote repository setup and local `git push`.
152
- 5. For `ssh_scp_wpcli`, run the project-local doctor/SCP/WP-CLI pipeline.
153
- 6. `whc_verify` to produce technical verify report.
154
- 7. Run smoke checks outside or via allowed tool path.
155
- 8. If staging passes, decide whether live release should proceed.
156
-
157
- For `ssh_scp_wpcli` projects, replace steps 4-7 with the project-local source pipeline:
158
- 1. doctor
159
- 2. backup
160
- 3. SCP code sync
161
- 4. WP-CLI runtime bootstrap
162
- 5. seed/bootstrap
163
- 6. smoke gate
164
-
165
- ## 6.4 Rollback (Level D) Contract
166
-
167
- Use rollback only when verify and policy conditions are satisfied.
168
-
169
- Mandatory gates:
170
- 1. `dry_run=true` for preview.
171
- 2. `confirmed=true` for execution.
172
- 3. Verify-chain report from `whc_verify` with `final_status=PASS`.
173
-
174
- Example rollback preview payload:
175
-
176
- ```json
177
- {
178
- "dry_run": true,
179
- "confirmed": true,
180
- "payload": {
181
- "target_environment": "live",
182
- "rollback_mode": "git_branch",
183
- "rollback_branch": "rollback/main",
184
- "reason": "production incident mitigation",
185
- "verify_release_id": "rel-2026-06-10-01"
186
- }
187
- }
188
- ```
189
-
190
- ## 6. Canonical Usage Patterns
191
-
192
- ### 6.1 `git_deploy`
193
-
194
- Use this mode when the real delivery path is:
195
-
196
- 1. local Git repository
197
- 2. push to cPanel-managed repository
198
- 3. cPanel deployment task runs `.cpanel.yml`
199
-
200
- Agent expectations today:
201
-
202
- 1. validate readiness with `check:generic`
203
- 2. ensure remote repo exists with `whc_setup_remote`
204
- 3. push with local Git
205
- 4. trigger the cPanel deployment task with `whc_deploy`
206
- 5. do not overstate this as WordPress runtime bootstrap; that still belongs to separate checks/scripts
207
-
208
- ### 6.2 `ssh_scp_wpcli`
209
-
210
- Use this mode for `mytho/source` style delivery:
211
-
212
- 1. doctor
213
- 2. backup
214
- 3. SCP code sync
215
- 4. WP-CLI bootstrap
216
- 5. seed/bootstrap
217
- 6. smoke gate
218
-
219
- ## 7. Smoke Gate Expectations
220
-
221
- Before live promote, ensure AC-critical smoke is green on staging.
222
-
223
- Suggested minimum:
224
-
225
- 1. Account page reachable.
226
- 2. Required API namespace/routes reachable.
227
- 3. Pricing visibility behavior by auth state.
228
- 4. Checkout fee messaging baseline.
229
-
230
- If preconditions fail (plugin/page/routes absent), gate must be `HOLD`.
231
-
232
- ## 7.1 Pipeline Mindset Guard
233
-
234
- Treat these as two different foundations:
235
-
236
- 1. `git_deploy`
237
- - repository-driven
238
- - local `git push`
239
- - cPanel deployment task
240
- - `.cpanel.yml` at repo root
241
- 2. `ssh_scp_wpcli`
242
- - source-driven
243
- - SCP file transfer
244
- - remote WP-CLI runtime/bootstrap
245
- - project-specific smoke gate
246
-
247
- Policy note:
248
-
249
- 1. `ssh_scp_wpcli` is the correct default mindset for `mytho/source`.
250
- 2. `git_deploy` should not be described as staging/live native sync.
251
- 3. If a release note or operator guide mentions `managed_clone_sync`, treat that as stale wording and replace it.
252
-
253
- ## 8. Troubleshooting
254
-
255
- ### 8.1 Startup auth errors with SSH key path
256
-
257
- Symptom:
258
-
259
- 1. `AUTH_ERROR` or `ENOENT` for key file while path appears valid.
260
-
261
- Checks:
262
-
263
- 1. Confirm `WHC_ENV_FILE` points to the intended env file.
264
- 2. Confirm The tool server process has reloaded after env edits.
265
- 3. Avoid malformed quoting in key path values.
266
-
267
- ### 8.2 Deploy contract confusion
268
-
269
- If users are mixing repository deploy with environment-sync wording:
270
-
271
- 1. for `git_deploy`, think `repository_root`, `branch`, `.cpanel.yml`, and cPanel deployment task
272
- 2. for `ssh_scp_wpcli`, think WordPress app root, `scp`, `wp`, and smoke checks
273
- 3. do not describe either mode as native WHC staging/live clone sync
274
-
275
- ## 9. One-Line Operator Playbook
276
-
277
- 1. Health check -> logs -> staging dry-run -> staging deploy -> smoke gate -> decide promote/hold.
278
-
279
- ## 10. Flow Log Read Guide (For Agent Responses)
280
-
281
- ### 10.1 Log path
282
-
283
- 1. Default path: `.whc/logs/flow-events.jsonl`
284
- 2. Custom path (optional): set `WHC_FLOW_LOG_PATH` in env
285
-
286
- ### 10.2 Read latest entries (PowerShell)
287
-
288
- ```powershell
289
- Get-Content .whc/logs/flow-events.jsonl -Tail 20
290
- ```
291
-
292
- If custom path is configured:
293
-
294
- ```powershell
295
- Get-Content $env:WHC_FLOW_LOG_PATH -Tail 20
296
- ```
297
-
298
- Filter only deploy events:
299
-
300
- ```powershell
301
- Get-Content .whc/logs/flow-events.jsonl -Tail 200 |
302
- ForEach-Object { $_ | ConvertFrom-Json } |
303
- Where-Object { $_.tool -eq 'whc_deploy' } |
304
- Select-Object -Last 10
305
- ```
306
-
307
- ### 10.3 Response format requirement
308
-
309
- When responding after any write tool run, agent should include:
310
-
311
- 1. `action_id`
312
- 2. `tool`
313
- 3. `status` (`success` or `failure`)
314
- 4. `request_id` (if available)
315
- 5. `pipeline_id`
316
- 6. `target_environment`
317
- 7. `release_intent`
318
- 8. Log path used
319
-
320
- Minimal response snippet:
321
-
322
- ```text
323
- Flow log:
324
- - path: .whc/logs/flow-events.jsonl
325
- - action_id: <value>
326
- - tool: whc_deploy
327
- - status: success|failure
328
- - request_id: <value>
329
- - pipeline_id: <value>
330
- - target_environment: staging|live
331
- - release_intent: deploy|refresh|promote|migrate|recover
332
- ```
333
-
334
- ## 10.4 First-Time Prepare (No Manual Template Filling)
335
-
336
- For local clone workflows, run once per workspace:
337
-
338
- ```powershell
339
- npm run prepare
340
- ```
341
-
342
- For npm-package workflows, call `whc_prepare` once from The tool server client after the server starts.
343
-
344
- This initializes hidden management paths automatically:
345
- 1. `.whc/state/pipeline-status.json`
346
- 2. `.whc/state/releases/`
347
- 3. `.whc/state/reports/`
348
- 4. `.whc/logs/`
349
-
350
- It also ensures `.whc/` is ignored by git.
351
-
352
- ## 10.5 Automatic State Tracking
353
-
354
- For every write tool run, tool server now auto-updates:
355
- 1. `.whc/state/pipeline-status.json` (started/completed/status/next step/error)
356
- 2. `.whc/state/releases/<request_id>.auto-manifest.json` (tool metadata + git changed files snapshot)
357
-
358
- No manual template authoring is required for normal DevOps runs.
359
-
360
- ## 11. Pipeline Progress Tracking (What To Read)
361
-
362
- For `whc_deploy` and `whc_setup_remote`, read these response fields first:
363
- 1. `data.pipeline_status`
364
- - `full_pass` or `pass_partial`
365
- 2. `data.phase_coverage`
366
- - `code_state`, `runtime_state`, `data_state`, `deployment_state`
367
- 3. `data.process_tracking` (setup_remote)
368
- - `stage`, `status`, `next_step`, `manual_actions`
369
-
370
- Decision rule:
371
- 1. If `pipeline_status=pass_partial`, do not claim end-to-end release completion.
372
- 2. Follow `next_step` and unresolved `manual_actions` before moving to next gate.
373
-
374
-
375
-
@@ -1,114 +0,0 @@
1
- # WHC.ca (cPanel) tool server Requirements
2
-
3
- ## 1. Objective
4
- Build a specialized WHC tool server (stdio + CLI) to automate the management and deployment of web projects hosted on Web Hosting Canada (WHC.ca). The goal is to facilitate a seamless **Local -> Staging -> Production** workflow directly from the terminal/Gemini CLI.
5
-
6
- ## 2. Core Features
7
- - **Git Automation:** Remote repository creation and branch-based synchronization.
8
- - **API Deployment:** Triggering cPanel's native deployment engine via UAPI.
9
- - **SSH Command Execution:** Remote server management (file manipulation, DB tasks) using WHC's specific port (27).
10
- - **Status Monitoring:** Real-time health checks, log retrieval, and SSL status.
11
-
12
- ## 3. Tool Definitions (Current)
13
-
14
- | Tool Name | Mode | Safety | Description |
15
- | :--- | :--- | :--- | :--- |
16
- | `whc_prepare` | write | B | Initializes hidden state namespace and readiness checks. |
17
- | `whc_deploy` | write | C/D | Triggers deployment/sync flow with policy gating. |
18
- | `whc_verify` | read | A | Runs technical post-deploy verification and writes verify report. |
19
- | `whc_pipeline_status` | read | A | Reads latest pipeline state and artifact pointers. |
20
- | `whc_rollback` | write | D | Guarded rollback (dry-run + confirm + verify-chain PASS required). |
21
- | `whc_setup_remote` | write | C | Creates cPanel Git repo and returns SSH remote hints. |
22
- | `whc_ssh_exec` | write | C | Executes policy-controlled SSH commands. |
23
- | `whc_get_logs` | read | A | Fetches server logs. |
24
- | `whc_db_backup` | write | D | Creates remote SQL backup with audit trail. |
25
- | `whc_check_health` | read | A | Collects disk, SSL, load, and capability signals. |
26
-
27
- ### 3.4 Rollback Contract (Current)
28
- `whc_rollback` is implemented as Level D.
29
-
30
- Policy requirements:
31
- 1. `dry_run=true` is mandatory for preview phase.
32
- 2. `confirmed=true` is mandatory for execution phase.
33
- 3. Verify-chain must be present and PASS from `whc_verify` report.
34
-
35
- Execution modes:
36
- 1. `git_branch` (UAPI deployment trigger with rollback branch)
37
- 2. `db_backup` (SSH `wp db import`)
38
- 3. `managed_sync_reverse` (manual action response with explicit warning)
39
-
40
- ## 3.1 Deploy Contract (Current)
41
- `whc_deploy` now reports phase coverage explicitly to prevent false-positive "deploy pass" outcomes.
42
-
43
- Response fields in `data`:
44
- 1. `pipeline_status`
45
- - `full_pass` | `pass_partial`
46
- 2. `phase_coverage`
47
- - `code_state`: `included` | `excluded`
48
- - `runtime_state`: `included` | `excluded`
49
- - `data_state`: `included` | `excluded`
50
- - `deployment_state`: `included` | `excluded`
51
- - `notes`: explanatory list for what is in/out of scope
52
-
53
- Interpretation:
54
- 1. `pass_partial` is expected when a run covers only transport/sync/deploy mechanics.
55
- 2. `full_pass` must only be used when code/runtime/data/deployment states are all included and validated.
56
-
57
- ## 3.2 Setup-Remote Contract (Current)
58
- `whc_setup_remote` is transport preparation, not code deployment.
59
-
60
- Response fields in `data`:
61
- 1. `pipeline_status`
62
- - expected default: `pass_partial`
63
- 2. `phase_coverage`
64
- - deployment state reflects repository wiring only
65
- 3. `process_tracking`
66
- - `stage`: `setup_remote`
67
- - `status`: `completed` | `needs_manual_input`
68
- - `next_step`: actionable follow-up
69
- - `manual_actions`: explicit operator/agent to-do list
70
-
71
- Operational implication:
72
- 1. A successful `whc_setup_remote` still requires local source push (`git push`) and subsequent `whc_deploy`.
73
-
74
- ## 3.3 Manual Prerequisites (Must Be Explicit)
75
- These steps are not auto-solvable by tool server and must be prepared by operator:
76
- 1. WHC API token creation and placement in env.
77
- 2. SSH key provisioning to correct cPanel account.
78
- 3. Credential scope alignment (target path ownership/account).
79
-
80
- ## 4. Technical Stack
81
- - **Language:** TypeScript / Node.js.
82
- - **Framework:** tool server SDK (@modelcontextprotocol/sdk).
83
- - **Communication:**
84
- - **cPanel UAPI:** Over HTTPS (Port 2083) using API Tokens.
85
- - **SSH:** Using `ssh2` or system SSH (Port 27).
86
- - **Configuration:** Global `.env` for sensitive credentials.
87
-
88
- ## 5. Implementation Roadmap
89
-
90
- ### Phase 1: Foundation & Auth
91
- - [ ] Initialize tool server project.
92
- - [ ] Implement secure `.env` loading for `WHC_API_TOKEN`, `WHC_USER`, and `WHC_HOST`.
93
- - [ ] Test connectivity to cPanel API and SSH.
94
-
95
- ### Phase 2: Deployment & Git
96
- - [ ] Build `whc_setup_remote`: Automate the "Git Version Control" setup in cPanel.
97
- - [ ] Build `whc_deploy`: Connect to the `deployment` UAPI endpoint.
98
- - [ ] Create a standard `.cpanel.yml` template generator.
99
-
100
- ### Phase 3: Monitoring & Utilities
101
- - [ ] Implement remote log tailing via SSH.
102
- - [ ] Implement database backup/restore helpers.
103
- - [ ] Add health check dashboard.
104
-
105
- ### Phase 4: Gemini CLI Integration
106
- - [ ] Register the tool server in `gemini-config.json`.
107
- - [ ] Create high-level commands/aliases (e.g., `whc-sync-staging`).
108
-
109
- ## 6. Security Protocol
110
- - No API tokens or Private Keys are to be hardcoded.
111
- - All sensitive data must reside in a local `.env` file excluded from git.
112
- - API requests must use HTTPS with proper header authentication.
113
-
114
-
@@ -1,75 +0,0 @@
1
- const fs = require("node:fs");
2
- const path = require("node:path");
3
-
4
- function ensureDir(p) {
5
- fs.mkdirSync(p, { recursive: true });
6
- }
7
-
8
- function ensureGitignoreRule(rootDir, rule) {
9
- const gitignorePath = path.join(rootDir, ".gitignore");
10
- if (!fs.existsSync(gitignorePath)) {
11
- fs.writeFileSync(gitignorePath, `${rule}\n`, "utf8");
12
- return;
13
- }
14
-
15
- const content = fs.readFileSync(gitignorePath, "utf8");
16
- const hasRule = content.split(/\r?\n/).some((line) => line.trim() === rule);
17
- if (hasRule) {
18
- return;
19
- }
20
-
21
- const next = content.endsWith("\n") ? `${content}${rule}\n` : `${content}\n${rule}\n`;
22
- fs.writeFileSync(gitignorePath, next, "utf8");
23
- }
24
-
25
- function ensureFileIfMissing(filePath, data) {
26
- if (!fs.existsSync(filePath)) {
27
- fs.writeFileSync(filePath, data, "utf8");
28
- }
29
- }
30
-
31
- function resolveStateRoot(rootDir) {
32
- const configured = (process.env.WHC_STATE_ROOT || "").trim();
33
- const relative = configured.length > 0 ? configured : ".whc";
34
- const segments = relative.split(/[\\/]+/).filter(Boolean);
35
- return path.join(rootDir, ...segments);
36
- }
37
-
38
- function main() {
39
- const rootDir = path.resolve(__dirname, "..");
40
- const stateRoot = resolveStateRoot(rootDir);
41
- const stateDir = path.join(stateRoot, "state");
42
- const releasesDir = path.join(stateDir, "releases");
43
- const reportsDir = path.join(stateDir, "reports");
44
- const logsDir = path.join(stateRoot, "logs");
45
- const envDir = path.join(stateRoot, "env");
46
-
47
- ensureDir(stateRoot);
48
- ensureDir(stateDir);
49
- ensureDir(releasesDir);
50
- ensureDir(reportsDir);
51
- ensureDir(logsDir);
52
- ensureDir(envDir);
53
-
54
- ensureGitignoreRule(rootDir, ".whc/");
55
-
56
- const statusFile = path.join(stateDir, "pipeline-status.json");
57
- ensureFileIfMissing(
58
- statusFile,
59
- JSON.stringify(
60
- {
61
- started: false,
62
- completed: false,
63
- status: "idle",
64
- next_step: "Run a write tool (deploy/setup/backup/ssh) to start tracking.",
65
- },
66
- null,
67
- 2,
68
- ) + "\n",
69
- );
70
-
71
- console.log("[prepare-first-time] Initialized .whc hidden state and ensured .gitignore contains .whc/");
72
- console.log(`[prepare-first-time] State file: ${statusFile}`);
73
- }
74
-
75
- main();