hostinger-api-mcp 4.15.2 → 4.17.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 (54) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +31 -6
  3. package/gemini-extension.json +1 -1
  4. package/package.json +1 -1
  5. package/server.json +2 -2
  6. package/skills/headless/SKILL.md +23 -0
  7. package/skills/headless/VERSION +2 -2
  8. package/skills/headless/local-server.mjs +64 -0
  9. package/skills/headless/processes.mjs +62 -0
  10. package/skills/headless/report.schema.json +16 -0
  11. package/skills/headless/run-log.mjs +27 -54
  12. package/skills/headless/servers.mjs +169 -0
  13. package/skills/headless/steps/06-frontend/SKILL.md +3 -1
  14. package/skills/headless/steps/06-frontend/bring-your-own-frontend.md +5 -0
  15. package/skills/headless/steps/07-validate/SKILL.md +5 -4
  16. package/skills/headless/steps/09-done/SKILL.md +3 -0
  17. package/skills/headless/workspace.mjs +28 -0
  18. package/src/core/runtime.js +1 -1
  19. package/src/core/runtime.ts +1 -1
  20. package/src/core/skills.js +49 -21
  21. package/src/core/skills.ts +49 -21
  22. package/src/core/tools/all.js +39 -4
  23. package/src/core/tools/all.ts +39 -4
  24. package/src/core/tools/horizons.js +39 -4
  25. package/src/core/tools/horizons.ts +39 -4
  26. package/src/servers/agency-hosting.js +1 -1
  27. package/src/servers/agency-hosting.ts +1 -1
  28. package/src/servers/agent-readiness.js +1 -1
  29. package/src/servers/agent-readiness.ts +1 -1
  30. package/src/servers/all.js +1 -1
  31. package/src/servers/all.ts +1 -1
  32. package/src/servers/billing.js +1 -1
  33. package/src/servers/billing.ts +1 -1
  34. package/src/servers/dns.js +1 -1
  35. package/src/servers/dns.ts +1 -1
  36. package/src/servers/domains.js +1 -1
  37. package/src/servers/domains.ts +1 -1
  38. package/src/servers/ecommerce.js +1 -1
  39. package/src/servers/ecommerce.ts +1 -1
  40. package/src/servers/gpu.js +1 -1
  41. package/src/servers/gpu.ts +1 -1
  42. package/src/servers/horizons.js +1 -1
  43. package/src/servers/horizons.ts +1 -1
  44. package/src/servers/hosting.js +1 -1
  45. package/src/servers/hosting.ts +1 -1
  46. package/src/servers/mail.js +1 -1
  47. package/src/servers/mail.ts +1 -1
  48. package/src/servers/reach.js +1 -1
  49. package/src/servers/reach.ts +1 -1
  50. package/src/servers/vps.js +1 -1
  51. package/src/servers/vps.ts +1 -1
  52. package/src/servers/wordpress.js +1 -1
  53. package/src/servers/wordpress.ts +1 -1
  54. package/types.d.ts +39 -4
package/CHANGELOG.md CHANGED
@@ -4,6 +4,30 @@ Generated at release time from the diff between the previous and current
4
4
  build. Tool changes are listed individually; everything else is summarised
5
5
  by area.
6
6
 
7
+ ## v4.17.0 — 2026-11-23
8
+
9
+ ### Operations
10
+
11
+ - Added `horizons_websites_build-task` — Get website build task
12
+ - Changed the description of `horizons_websites_create`
13
+ - Changed the description of `horizons_websites_edit`
14
+ - Changed the description of `horizons_websites_publish`
15
+ - Changed the description of `horizons_websites_get`
16
+
17
+ ### Also in this release
18
+
19
+ - Documentation: `README.md`
20
+ - Request handling and authentication: `src/core/runtime.js`, `src/core/runtime.ts`
21
+ - Build and packaging: `types.d.ts`
22
+
23
+ ## v4.16.0 — 2026-11-23
24
+
25
+ ### Also in this release
26
+
27
+ - Dependencies: `package-lock.json`
28
+ - Bundled agent skills: 12 files
29
+ - Other files: `src/core/skills.js`, `src/core/skills.ts`
30
+
7
31
  ## v4.15.2 — 2026-11-23
8
32
 
9
33
  ### Also in this release
package/README.md CHANGED
@@ -78,7 +78,7 @@ pnpm update -g @hostinger/mcp
78
78
 
79
79
  This package installs the following MCP server commands:
80
80
 
81
- - `hostinger-api-mcp` — unified server over every operation (426 total)
81
+ - `hostinger-api-mcp` — unified server over every operation (427 total)
82
82
  - `hostinger-agency-hosting-mcp` — 43 operations for agency-hosting
83
83
  - `hostinger-agent-readiness-mcp` — 4 operations for agent-readiness
84
84
  - `hostinger-billing-mcp` — 10 operations for billing
@@ -86,7 +86,7 @@ This package installs the following MCP server commands:
86
86
  - `hostinger-domains-mcp` — 43 operations for domains
87
87
  - `hostinger-ecommerce-mcp` — 33 operations for ecommerce
88
88
  - `hostinger-gpu-mcp` — 13 operations for gpu
89
- - `hostinger-horizons-mcp` — 7 operations for horizons
89
+ - `hostinger-horizons-mcp` — 8 operations for horizons
90
90
  - `hostinger-hosting-mcp` — 59 operations for hosting
91
91
  - `hostinger-mail-mcp` — 39 operations for mail
92
92
  - `hostinger-reach-mcp` — 73 operations for reach
@@ -2056,8 +2056,10 @@ The complete list of websites is returned in a single response - it is not pagin
2056
2056
  Create new Hostinger AI Builder website from the given message.\n
2057
2057
  Use this tool when user asks you to create a website, landing page, blog
2058
2058
  or any other type of application.\n
2059
- This tool initiates the website creation process and returns a website URL and ID.
2060
- The generation happens asynchronously.\n
2059
+ This tool initiates the website creation process and returns a website URL, ID and build `task`.
2060
+ The generation happens asynchronously. To learn whether it succeeded, poll the
2061
+ `Get website build task` tool with `task.id`; `is_generating` turning false on `Get website`
2062
+ happens whether the build completed or failed.\n
2061
2063
  After invoking this tool, your chat reply must be EXACTLY 1 sentence summarizing
2062
2064
  that Hostinger AI Builder is now creating their website and it will be ready in a few minutes
2063
2065
  and you should provide the website URL to the user immediately
@@ -2096,8 +2098,10 @@ MAPS:\n
2096
2098
 
2097
2099
  Edit an existing Hostinger AI Builder website with a follow-up message.\n
2098
2100
  Use this tool when the user wants to change, extend or fix a website that already exists.\n
2099
- This tool queues the requested changes and returns the website URL and ID.
2100
- The changes are applied asynchronously.\n
2101
+ This tool queues the requested changes and returns the website URL, ID and build `task`.
2102
+ The changes are applied asynchronously. To learn whether they were applied, poll the
2103
+ `Get website build task` tool with `task.id`; `is_generating` turning false on `Get website`
2104
+ happens whether the build completed or failed.\n
2101
2105
  After invoking this tool, your chat reply must be EXACTLY 1 sentence summarizing
2102
2106
  that Hostinger AI Builder is now applying the requested changes and they will be ready
2103
2107
  in a few minutes, and you should provide the website URL to the user immediately.
@@ -2112,6 +2116,9 @@ and do not generate code yourself in the chat.
2112
2116
 
2113
2117
  Publish a Hostinger AI Builder website so its latest changes go live.\n
2114
2118
  Use this tool when the user asks to publish, deploy or make their website live.\n
2119
+ If you created or edited the website in this conversation, first check its build with the
2120
+ `Get website build task` tool and publish only when its `state` is `TASK_STATE_COMPLETED`.
2121
+ After a failed build, tell the user instead of publishing.\n
2115
2122
  This tool starts the publish process and returns the URL the website will be live on.
2116
2123
  Publishing happens asynchronously and takes a few minutes.\n
2117
2124
  Set `is_template` only when the user explicitly asks to share the website as a template:
@@ -2131,6 +2138,8 @@ website URL before or after editing it.\n
2131
2138
  `is_in_progress` is true while changes are being generated or the website is being published;
2132
2139
  wait until it is false before publishing. `is_generating` is true while changes are being generated,
2133
2140
  and `actions_in_progress` has `website_publish` while the website is being published.
2141
+ `is_generating` turns false whether the build completed or failed: use the `Get website build task`
2142
+ tool to learn its outcome.
2134
2143
  `published_at` is when the website was last published,
2135
2144
  `is_template` is whether its published pages show the "Use template" banner, and
2136
2145
  `has_ecommerce_store` is whether it has an online store.\n
@@ -2140,6 +2149,22 @@ interface in the provided website URL.
2140
2149
  - **Method**: `GET`
2141
2150
  - **Path**: `/api/horizons/v1/websites/{websiteId}`
2142
2151
 
2152
+ #### horizons_websites_build-task
2153
+
2154
+ Get the state and outcome of a website build started by the `Create website` or `Edit website` tool.\n
2155
+ Use this tool with the `task.id` those tools return to find out whether the build completed or failed.
2156
+ Poll it every 30 seconds or so while `state` is `TASK_STATE_SUBMITTED` or `TASK_STATE_WORKING`.\n
2157
+ When `state` is `TASK_STATE_FAILED` or `TASK_STATE_REJECTED`, the website does not contain the requested
2158
+ changes: tell the user, using `message` and `reason_code`, and do not publish it.
2159
+ When `state` is `TASK_STATE_CANCELED`, the user stopped the build and changes made before that may be kept:
2160
+ publish only if the user asks to.
2161
+ `reason_code` `insufficient_credits` means the user must get more credits before building again.\n
2162
+ When `state` is `TASK_STATE_COMPLETED`, the website can be published. A `reason_code` of
2163
+ `iteration_limit` on a completed build means it stopped early and kept the work done so far.
2164
+
2165
+ - **Method**: `GET`
2166
+ - **Path**: `/api/horizons/v1/websites/{websiteId}/tasks/{taskId}`
2167
+
2143
2168
  ### `hostinger-hosting-mcp`
2144
2169
 
2145
2170
  #### changelog_list-entries
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hostinger-api-mcp",
3
- "version": "4.15.2",
3
+ "version": "4.17.0",
4
4
  "description": "Hostinger API — manage domains, DNS, hosting, VPS, billing and more from Gemini CLI.",
5
5
  "mcpServers": {
6
6
  "hostinger": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hostinger-api-mcp",
3
- "version": "4.15.2",
3
+ "version": "4.17.0",
4
4
  "mcpName": "io.github.hostinger/hostinger-api-mcp",
5
5
  "description": "MCP server for Hostinger API",
6
6
  "repository": {
package/server.json CHANGED
@@ -17,12 +17,12 @@
17
17
  "url": "https://github.com/hostinger/api-mcp-server",
18
18
  "source": "github"
19
19
  },
20
- "version": "4.15.2",
20
+ "version": "4.17.0",
21
21
  "packages": [
22
22
  {
23
23
  "registryType": "npm",
24
24
  "identifier": "@hostinger/mcp",
25
- "version": "4.15.2",
25
+ "version": "4.17.0",
26
26
  "transport": {
27
27
  "type": "stdio"
28
28
  },
@@ -256,6 +256,28 @@ exits 0 with `ok: true` and what it waited for; 1 with `ok: false` when the job
256
256
  the local Hostinger MCP, with `fallback` naming the connector operation to poll yourself, every ~15 s.
257
257
  Never write your own `sleep` loops.
258
258
 
259
+ ### Local servers: `local-server.mjs`
260
+
261
+ Start every local dev or preview server (frontend's visual check, validate's sign-off preview) through
262
+ `local-server.mjs` (next to this file), never with `&`, `nohup` or your tool's background mode. Run it
263
+ from the project folder; `{port}` in the command becomes the port it picked:
264
+
265
+ ```bash
266
+ cd ~/.hostinger/<domain>/src && node <skill>/local-server.mjs start <domain> -- npx next start -p {port} # Next.js, after npm run build
267
+ cd ~/.hostinger/<domain>/src && node <skill>/local-server.mjs start <domain> -- npx astro preview --port {port} --ignore-lock # Astro, after npm run build
268
+ cd ~/.hostinger/<domain>/src && node <skill>/local-server.mjs start <domain> -- npx next dev -p {port} # a dev server starts the same way
269
+ ```
270
+
271
+ `start` stops the server this domain already runs, so after a rebuild just run it again. It picks a
272
+ free port, so builds running side by side never collide, and waits until the port answers. It prints
273
+ one JSON line and exits 0 with `ok: true` and the `url` to open; 1 with `ok: false`, `error` and
274
+ `log_tail` when the server exited or didn't answer within `--timeout` (90s by default; keep it under
275
+ your tool's command limit); 2 when it couldn't run.
276
+
277
+ `run-log.mjs report` stops the run's servers when it ends, and `run-start` stops any that an earlier,
278
+ ended session left. Neither touches a server `local-server.mjs` didn't start, such as the user's own
279
+ `next dev`.
280
+
259
281
  ---
260
282
 
261
283
  ## State and artifacts
@@ -292,6 +314,7 @@ took from it.
292
314
  | `design.md` (+ `brand/` logo files) | design | chosen design direction: tokens, type, logo, components, per-page composition, accessibility |
293
315
  | `src/` | frontend | the website source implementing `design.md`; framework choice is recorded in `state.json → frontend` |
294
316
  | `deploy.json` | deploy | build id, deployed at, live URLs |
317
+ | `servers.json` (+ `servers/<port>.log`) | `local-server.mjs` only | each local dev or preview server a run started: pid, port, command, start time, and whether it was stopped |
295
318
  | `events.jsonl` | every stage, via `run-log.mjs` | append-only log of issues, user feedback, skill gaps and wins |
296
319
  | `reports/<run>.json` + `.html`, `report.html` | done (or any early stop), via `run-log.mjs` | the build report for each run; `report.html` is the latest |
297
320
 
@@ -1,3 +1,3 @@
1
- version=4.15.2
2
- commit=a77d23713202
1
+ version=4.17.0
2
+ commit=02f4944d7548
3
3
  built=2026-11-23
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ // Hostinger Headless local server: starts a build's local dev or preview server, and stops them, so a
3
+ // run never leaves one behind.
4
+ //
5
+ // cd <project> && node local-server.mjs start <domain> [--timeout 90s] -- <command…>
6
+ // node local-server.mjs stop <domain>
7
+ //
8
+ // start replaces the servers this domain already runs, picks a free port, runs the command from the
9
+ // current folder with PORT set and every {port} in its arguments replaced, waits until the port answers
10
+ // HTTP and records the server in ~/.hostinger/<domain>/servers.json. stop stops every server recorded
11
+ // there that may still be running. run-log.mjs stops them too, at run-start and report.
12
+ //
13
+ // stdout is one JSON line. Exit 0 when done; 1 when the server didn't come up (`error`, `log_tail`) or
14
+ // a server couldn't be confirmed stopped; 2 when it couldn't run (`error`).
15
+
16
+ import { isDown, startServer, stopServers } from './servers.mjs';
17
+ import { workspaceDir } from './workspace.mjs';
18
+
19
+ const finish = (code, result) => {
20
+ process.stdout.write(`${JSON.stringify(result)}\n`);
21
+ process.exit(code);
22
+ };
23
+ const fail = (message) => finish(2, { ok: false, error: message });
24
+ const DEFAULT_TIMEOUT = '90s';
25
+
26
+ function parseArgs(argv) {
27
+ const positional = [];
28
+ const flags = {};
29
+ for (let i = 0; i < argv.length; i += 1) {
30
+ if (argv[i].startsWith('--')) {
31
+ const key = argv[i].slice(2);
32
+ const value = argv[i + 1] && !argv[i + 1].startsWith('--') ? argv[(i += 1)] : true;
33
+ flags[key] = value;
34
+ } else positional.push(argv[i]);
35
+ }
36
+ return { positional, flags };
37
+ }
38
+
39
+ function duration(text) {
40
+ const m = typeof text === 'string' && text.match(/^(\d+(?:\.\d+)?)\s*([smh])$/);
41
+ if (!m) fail(`--timeout "${text}" should look like 90s, 10m or 1h`);
42
+ return Number(m[1]) * { s: 1e3, m: 6e4, h: 36e5 }[m[2]];
43
+ }
44
+
45
+ const argv = process.argv.slice(2);
46
+ const dash = argv.includes('--') ? argv.indexOf('--') : argv.length;
47
+ const { positional: [action, domain, ...extra], flags } = parseArgs(argv.slice(0, dash));
48
+ const command = argv.slice(dash + 1);
49
+ if (!['start', 'stop'].includes(action) || extra.length) fail(`usage: start <domain> [--timeout ${DEFAULT_TIMEOUT}] -- <command…> | stop <domain>`);
50
+ if (action === 'start' && !command.length) fail('give the server command after --, e.g. start <domain> -- npx next start -p {port}');
51
+ let dir;
52
+ try {
53
+ dir = workspaceDir(domain);
54
+ } catch (error) {
55
+ fail(error.message);
56
+ }
57
+
58
+ if (action === 'start') {
59
+ const result = await startServer(dir, command, { timeoutMs: duration(flags.timeout ?? DEFAULT_TIMEOUT) });
60
+ finish(result.ok ? 0 : 1, result);
61
+ }
62
+ const tried = await stopServers(dir);
63
+ const ok = tried.every(isDown);
64
+ finish(ok ? 0 : 1, { ok, stopped: tried.map(({ port, pid, command: cmd, status }) => ({ port, pid, command: cmd, status })) });
@@ -0,0 +1,62 @@
1
+ // The process list and process-tree signals, shared by run-log.mjs (the domain lock) and
2
+ // local-server.mjs (the servers a run starts). Both tell a live process from a reused PID by its
3
+ // start time.
4
+
5
+ import { spawnSync } from 'node:child_process';
6
+ import { homedir } from 'node:os';
7
+ import { basename, delimiter, isAbsolute, join } from 'node:path';
8
+
9
+ export const processName = (name) => basename(name.replace(/\\/g, '/')).replace(/^-/, '').replace(/\.exe$/i, '').toLowerCase();
10
+
11
+ // These scripts run in the user's project, maybe a cloned repository. Windows looks a bare program name
12
+ // up in the working directory before PATH, as does a relative PATH entry elsewhere, so system programs
13
+ // run from home with only absolute, non-node_modules PATH entries (as connect/launch.mjs runs npx),
14
+ // and Windows programs are named by their full path.
15
+ const helperEnv = { ...process.env, LC_ALL: 'C', TZ: 'UTC' };
16
+ for (const key of Object.keys(helperEnv).filter((k) => k.toUpperCase() === 'PATH')) {
17
+ helperEnv[key] = helperEnv[key].split(delimiter)
18
+ .filter((p) => isAbsolute(p) && !p.split(/[\\/]/).includes('node_modules'))
19
+ .join(delimiter);
20
+ }
21
+ const systemRoot = isAbsolute(process.env.SystemRoot ?? '') ? process.env.SystemRoot : 'C:\\Windows';
22
+ const POWERSHELL = join(systemRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
23
+ const TASKKILL = join(systemRoot, 'System32', 'taskkill.exe');
24
+
25
+ // pid -> { ppid, started, name }; null when the process list can't be read (a sandbox that blocks ps).
26
+ export function processTable() {
27
+ const windows = process.platform === 'win32';
28
+ const r = windows
29
+ ? spawnSync(POWERSHELL, ['-NoProfile', '-NonInteractive', '-Command',
30
+ 'Get-CimInstance Win32_Process | ForEach-Object { "$($_.ProcessId)`t$($_.ParentProcessId)`t$(if ($_.CreationDate) { $_.CreationDate.ToUniversalTime().ToString(\'o\') })`t$($_.Name)" }'], { encoding: 'utf8', cwd: homedir(), env: helperEnv })
31
+ : spawnSync('ps', ['-A', '-o', 'pid=,ppid=,lstart=,comm='], { encoding: 'utf8', cwd: homedir(), env: helperEnv });
32
+ if (r.status !== 0 || !r.stdout) return null;
33
+ const table = new Map();
34
+ for (const line of r.stdout.split(/\r?\n/)) {
35
+ const m = windows ? line.match(/^(\d+)\t(\d+)\t([^\t]*)\t(.*)$/) : line.trim().match(/^(\d+)\s+(\d+)\s+(\w+\s+\w+\s+\d+\s+[\d:]+\s+\d+)\s+(.*)$/);
36
+ if (m) table.set(Number(m[1]), { ppid: Number(m[2]), started: m[3].replace(/\s+/g, ' ') || null, name: m[4] });
37
+ }
38
+ return table.size ? table : null;
39
+ }
40
+
41
+ // Whether the process group led by pid (on Windows, the process itself) still has a member.
42
+ export function groupAlive(pid) {
43
+ if (process.platform === 'win32') return processTable()?.has(pid) ?? false;
44
+ try {
45
+ process.kill(-pid, 0);
46
+ return true;
47
+ } catch (error) {
48
+ return error.code === 'EPERM';
49
+ }
50
+ }
51
+
52
+ // Signals the process group led by pid: a server started detached leads its own group, so npx, the
53
+ // framework and its workers all get it. Windows has no groups: taskkill /T walks the tree instead.
54
+ export function signalGroup(pid, signal) {
55
+ if (process.platform === 'win32') {
56
+ spawnSync(TASKKILL, ['/PID', String(pid), '/T', ...(signal === 'SIGKILL' ? ['/F'] : [])], { cwd: homedir(), env: helperEnv, stdio: 'ignore' });
57
+ return;
58
+ }
59
+ try {
60
+ process.kill(-pid, signal);
61
+ } catch {}
62
+ }
@@ -138,6 +138,22 @@
138
138
  "properties": { "stage": { "type": "string" }, "phase": { "type": ["string", "null"] }, "problem": { "type": "string" } }
139
139
  }
140
140
  },
141
+ "servers": {
142
+ "description": "Local dev and preview servers this run started through local-server.mjs, and what stopping them at the end of the run found.",
143
+ "type": "array",
144
+ "items": {
145
+ "type": "object",
146
+ "required": ["port", "command", "status"],
147
+ "properties": {
148
+ "pid": { "type": "integer" },
149
+ "port": { "type": "integer" },
150
+ "command": { "type": "string" },
151
+ "started_at": { "type": "string" },
152
+ "stopped_at": { "type": ["string", "null"] },
153
+ "status": { "type": "string", "enum": ["stopped", "already_gone", "not_verified", "still_running"] }
154
+ }
155
+ }
156
+ },
141
157
  "previous_runs": {
142
158
  "type": "array",
143
159
  "items": {
@@ -15,18 +15,18 @@
15
15
  // node run-log.mjs <domain> report-sent [<run>]
16
16
  // node run-log.mjs <domain> report-rejected [<run>]
17
17
 
18
- import { spawnSync } from 'node:child_process';
19
- import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
20
- import { homedir, hostname } from 'node:os';
21
- import { basename, delimiter, dirname, isAbsolute, join } from 'node:path';
18
+ import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
19
+ import { hostname } from 'node:os';
20
+ import { dirname, join } from 'node:path';
22
21
  import { fileURLToPath } from 'node:url';
22
+ import { processName, processTable } from './processes.mjs';
23
+ import { describeServer, isDown, serversSince, stopServers } from './servers.mjs';
24
+ import { now, workspaceDir, writeJsonAtomic } from './workspace.mjs';
23
25
 
24
26
  const STAGES = ['refine', 'connect', 'check_state', 'provision', 'content_model', 'design', 'frontend', 'validate', 'deploy', 'done'];
25
27
  // Stages that stop for the user to restart their tool, so it loads a newly registered Hostinger MCP server.
26
28
  const RESTART_STAGES = ['connect', 'provision', 'content_model'];
27
29
  const PAUSE_NOTE = 'paused for a tool restart';
28
- // A domain names a folder under ~/.hostinger, so "../x" or "a/b" must never reach the file system.
29
- const HOSTNAME = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+$/i;
30
30
  const RESULTS = ['ok', 'ok_after_retries', 'ok_with_fixups', 'failed', 'skipped', 'stopped'];
31
31
  const OUTCOMES = ['live', 'stopped', 'failed', 'abandoned'];
32
32
  const EVENT_FIELDS = {
@@ -38,7 +38,6 @@ const EVENT_FIELDS = {
38
38
  const EVENT_LISTS = { issue: 'issues', feedback: 'user_feedback', skill_gap: 'skill_gaps', good: 'what_went_well' };
39
39
 
40
40
  const here = dirname(fileURLToPath(import.meta.url));
41
- const now = () => new Date().toISOString().replace(/\.\d{3}Z$/, 'Z');
42
41
  // A start logged late is kept but marked estimated, so the report can tell measured times from remembered ones.
43
42
  function lateStart(flags, run) {
44
43
  let at = null;
@@ -79,10 +78,12 @@ const writeJson = (file, value) => writeFileSync(file, `${JSON.stringify(value,
79
78
  // run-start is a run's first command, before anything else has written to the workspace.
80
79
  function workspace(domain, { create = false } = {}) {
81
80
  if (!domain || domain.startsWith('-')) fail('first argument must be the domain');
82
- if (!HOSTNAME.test(domain)) fail(`"${domain}" is not a domain (use its ASCII form, e.g. xn--caf-dma.com)`);
83
- const dir = join(homedir(), '.hostinger', domain);
84
- if (create) mkdirSync(dir, { recursive: true });
85
- else if (!existsSync(dir)) fail(`no workspace at ${dir}; run-start creates it`);
81
+ let dir;
82
+ try {
83
+ dir = workspaceDir(domain, { create });
84
+ } catch (error) {
85
+ fail(error.message);
86
+ }
86
87
  return {
87
88
  dir,
88
89
  domain,
@@ -104,38 +105,6 @@ const WRAPPERS = new Set(['sh', 'bash', 'zsh', 'dash', 'fish', 'pwsh', 'powershe
104
105
  // counts as live while it was refreshed this recently.
105
106
  const LOCK_FRESH_MS = 30 * 60 * 1000;
106
107
 
107
- const processName = (name) => basename(name.replace(/\\/g, '/')).replace(/^-/, '').replace(/\.exe$/i, '').toLowerCase();
108
-
109
- // This script runs in the user's project, maybe a cloned repository. Windows looks a bare program name
110
- // up in the working directory before PATH, as does a relative PATH entry elsewhere, so the process list
111
- // is read from home with only absolute, non-node_modules PATH entries (as connect/launch.mjs runs npx),
112
- // and Windows PowerShell is named by its full path.
113
- const helperEnv = { ...process.env, LC_ALL: 'C', TZ: 'UTC' };
114
- for (const key of Object.keys(helperEnv).filter((k) => k.toUpperCase() === 'PATH')) {
115
- helperEnv[key] = helperEnv[key].split(delimiter)
116
- .filter((p) => isAbsolute(p) && !p.split(/[\\/]/).includes('node_modules'))
117
- .join(delimiter);
118
- }
119
- const systemRoot = isAbsolute(process.env.SystemRoot ?? '') ? process.env.SystemRoot : 'C:\\Windows';
120
- const POWERSHELL = join(systemRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
121
-
122
- // pid -> { ppid, started, name }; null when the process list can't be read. The start time tells a
123
- // reused PID from the process that held the lock.
124
- function processTable() {
125
- const windows = process.platform === 'win32';
126
- const r = windows
127
- ? spawnSync(POWERSHELL, ['-NoProfile', '-NonInteractive', '-Command',
128
- 'Get-CimInstance Win32_Process | ForEach-Object { "$($_.ProcessId)`t$($_.ParentProcessId)`t$(if ($_.CreationDate) { $_.CreationDate.ToUniversalTime().ToString(\'o\') })`t$($_.Name)" }'], { encoding: 'utf8', cwd: homedir(), env: helperEnv })
129
- : spawnSync('ps', ['-A', '-o', 'pid=,ppid=,lstart=,comm='], { encoding: 'utf8', cwd: homedir(), env: helperEnv });
130
- if (r.status !== 0 || !r.stdout) return null;
131
- const table = new Map();
132
- for (const line of r.stdout.split(/\r?\n/)) {
133
- const m = windows ? line.match(/^(\d+)\t(\d+)\t([^\t]*)\t(.*)$/) : line.trim().match(/^(\d+)\s+(\d+)\s+(\w+\s+\w+\s+\d+\s+[\d:]+\s+\d+)\s+(.*)$/);
134
- if (m) table.set(Number(m[1]), { ppid: Number(m[2]), started: m[3].replace(/\s+/g, ' ') || null, name: m[4] });
135
- }
136
- return table.size ? table : null;
137
- }
138
-
139
108
  function currentHolder(table) {
140
109
  let pid = process.ppid;
141
110
  while (table?.has(pid) && WRAPPERS.has(processName(table.get(pid).name))) pid = table.get(pid).ppid;
@@ -174,12 +143,6 @@ function lockStatus(lock, me, table) {
174
143
  return byRecency(lock);
175
144
  }
176
145
 
177
- // Replacing the lock goes through a rename, so a reader never sees half of it.
178
- function writeLock(ws, lock) {
179
- const tmp = `${ws.lockPath}.${process.pid}.tmp`;
180
- writeJson(tmp, lock);
181
- renameSync(tmp, ws.lockPath);
182
- }
183
146
 
184
147
  // Of two sessions creating a missing lock at once, exactly one succeeds.
185
148
  function createLock(ws, lock) {
@@ -237,7 +200,7 @@ function claimLock(ws, { take = false, start = false, takeOver = false, tool = n
237
200
  const status = verdict === 'unverified' ? (start ? byRecency(lock) : 'own') : verdict;
238
201
  if (status === 'own') {
239
202
  const refreshed = { ...lock, tool: tool ?? lock.tool, refreshed_at: now() };
240
- writeLock(ws, refreshed);
203
+ writeJsonAtomic(ws.lockPath, refreshed);
241
204
  return { lock: refreshed, wasFree: false };
242
205
  }
243
206
  if (status === 'live' && !takeOver) refuse(ws, lock, { offerTakeOver: start });
@@ -245,7 +208,7 @@ function claimLock(ws, { take = false, start = false, takeOver = false, tool = n
245
208
  // Two sessions taking over the same dead lock at once both rename theirs in; the one that lost
246
209
  // is refused at its next command.
247
210
  const taken = record();
248
- writeLock(ws, taken);
211
+ writeJsonAtomic(ws.lockPath, taken);
249
212
  return { lock: taken, wasFree: false };
250
213
  }
251
214
  fail(`${ws.lockPath} keeps appearing and disappearing; another session is starting on ${ws.domain}. Stop and tell the user`);
@@ -309,7 +272,11 @@ function readConnect(ws) {
309
272
  return { tool: typeof connect.tool === 'string' ? connect.tool : null, mcp: version, skills: typeof connect.skills === 'string' ? connect.skills : null };
310
273
  }
311
274
 
312
- function runStart(ws, flags, lockWasFree) {
275
+ // This session holds the domain now, so a server still recorded in the workspace was left by a session
276
+ // that is gone; stopping it first also gets it into the report of the run that started it.
277
+ async function runStart(ws, flags, lockWasFree) {
278
+ const leftovers = await stopServers(ws.dir);
279
+ if (leftovers.length) console.log(`local servers left by an earlier session: ${leftovers.map(describeServer).join('; ')}`);
313
280
  const log = loadLog(ws);
314
281
  // A run left open in a restart stage goes on in the new session, at connect, instead of being
315
282
  // abandoned. The paused stage ends at its last logged activity, so the restart wait isn't counted.
@@ -542,6 +509,7 @@ function buildReport(ws, { outcome, tokens } = {}) {
542
509
  const gaps = [...loggingGaps(stages, run, resolvedOutcome), ...dropped];
543
510
  const strip = ({ ts, run: _run, type: _type, ...rest }) => ({ ...rest, logged_at: ts });
544
511
  const liveStage = stages.find((s) => s.stage === 'deploy' && s.result?.startsWith('ok'));
512
+ const servers = serversSince(ws.dir, run.started_at);
545
513
  if (!OUTCOMES.includes(resolvedOutcome)) fail(`unknown outcome "${resolvedOutcome}"; one of ${OUTCOMES.join(', ')}`);
546
514
 
547
515
  const previous = existsSync(ws.reportsDir)
@@ -588,6 +556,7 @@ function buildReport(ws, { outcome, tokens } = {}) {
588
556
  skill_gaps: events.filter((e) => e.type === 'skill_gap').map(strip),
589
557
  what_went_well: events.filter((e) => e.type === 'good').map(strip),
590
558
  logging_gaps: gaps,
559
+ servers,
591
560
  previous_runs: previous,
592
561
  };
593
562
 
@@ -601,6 +570,7 @@ function buildReport(ws, { outcome, tokens } = {}) {
601
570
  fresh.run.reported_at = now();
602
571
  saveLog(ws, fresh);
603
572
  for (const g of gaps) console.log(`warning: ${g.stage}${g.phase ? `/${g.phase}` : ''}: ${g.problem}`);
573
+ for (const s of servers.filter((s) => !isDown(s))) console.log(`server not stopped: ${describeServer(s)}`);
604
574
  return join(ws.dir, 'report.html');
605
575
  }
606
576
 
@@ -846,6 +816,7 @@ details summary { cursor:pointer; color:var(--text-secondary); margin-top:16px;
846
816
  <div class="legend"><span><span class="swatch sw-solid"></span>Finished</span><span><span class="swatch sw-hatch"></span>Failed, stopped or not finished</span><span><span class="swatch sw-est"></span>Start estimated</span><span>Stages can overlap: prep work runs while provisioning settles.</span></div>
847
817
  <details><summary>Show as table</summary><div class="table-wrap"><table><thead><tr><th>Stage</th><th>Start</th><th>End</th><th class="num">Minutes</th><th>Result</th><th>Note</th></tr></thead><tbody>${stageRows}</tbody></table></div></details></section>
848
818
  ${r.logging_gaps.length ? `<section><h2>Logging gaps (${r.logging_gaps.length})</h2><p class="muted">Where the run log is missing or unsure, so times here are less reliable.</p><ul>${r.logging_gaps.map((g) => `<li><strong>${esc(label(g.stage))}${g.phase ? ` · ${esc(g.phase)}` : ''}</strong> — ${esc(g.problem)}</li>`).join('')}</ul></section>` : ''}
819
+ ${r.servers.length ? `<section><h2>Local servers (${r.servers.length})</h2><p class="muted">Dev and preview servers this run started, and what stopping them when it ended found.</p><div class="table-wrap"><table><thead><tr><th class="num">Port</th><th class="num">PID</th><th>Command</th><th>Started</th><th>Stopped</th><th>Status</th></tr></thead><tbody>${r.servers.map((s) => `<tr><td class="num">${s.port}</td><td class="num">${s.pid}</td><td><code>${esc(s.command)}</code></td><td>${time(s.started_at)}</td><td>${time(s.stopped_at)}</td><td>${esc(label(s.status))}</td></tr>`).join('')}</tbody></table></div></section>` : ''}
849
820
  <section><h2>Issues (${r.issues.length})</h2>${r.issues.length ? `<div class="table-wrap"><table><thead><tr><th>Severity</th><th>Stage</th><th>Symptom</th><th>Cause</th><th>Workaround</th><th>Status</th></tr></thead><tbody>${issues}</tbody></table></div>` : '<p class="muted">No issues logged.</p>'}</section>
850
821
  <div class="cols"><section><h2>User feedback</h2>${list(r.user_feedback, (f) => `<li><span class="chip">${esc(label(f.category))}</span> <span class="muted">${esc(label(f.stage))}</span> — “${esc(f.paraphrase)}”</li>`, 'No feedback logged.')}</section>
851
822
  <section><h2>Skill gaps</h2>${list(r.skill_gaps, (g) => `<li><code>${esc(g.skill)}</code> — ${esc(g.gap)}</li>`, 'No skill gaps logged.')}</section></div>
@@ -866,7 +837,8 @@ document.querySelectorAll('.bar').forEach((el) => {
866
837
  `;
867
838
  }
868
839
 
869
- function report(ws, flags) {
840
+ // The run ends here, finished or stopped early, so its local servers stop before the report records them.
841
+ async function report(ws, flags) {
870
842
  let tokens;
871
843
  if (typeof flags.tokens === 'string') {
872
844
  try {
@@ -878,6 +850,7 @@ function report(ws, flags) {
878
850
  if (tokens === null || (typeof tokens === 'object' && !Array.isArray(tokens) && !Object.keys(tokens).length)) tokens = undefined;
879
851
  else validate(tokens, { ...reportSchema()?.properties?.tokens, type: 'object' }, '--tokens');
880
852
  }
853
+ await stopServers(ws.dir);
881
854
  console.log(`report written: ${buildReport(ws, { outcome: flags.outcome, tokens })}`);
882
855
  const { id, file } = reportFile(ws);
883
856
  console.log(`send it: pass ${file} unchanged to hosting_headless_submit-build-report, then run report-sent ${id} (or report-rejected ${id} on a 422)`);
@@ -915,6 +888,6 @@ const claim = spec.lock === 'none' ? null : claimLock(ws, {
915
888
  takeOver: start && flags['take-over'] === true,
916
889
  tool: start && typeof flags.tool === 'string' ? flags.tool : null,
917
890
  });
918
- spec.run(ws, rest, flags, claim);
891
+ await spec.run(ws, rest, flags, claim);
919
892
  // A command that fails exits before this, so a refused pause or report keeps the lock.
920
893
  if (spec.lock === 'release' && claim.lock) rmSync(ws.lockPath, { force: true });