mcp-ssh-manager 3.8.7 → 4.0.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 (104) hide show
  1. package/.eslintignore +5 -0
  2. package/.gitattributes +5 -0
  3. package/CHANGELOG.md +371 -6
  4. package/CLAUDE.md +6 -0
  5. package/CODE_OF_CONDUCT.md +18 -0
  6. package/CONTRIBUTING.md +30 -0
  7. package/Formula/ssh-manager.rb +60 -0
  8. package/README.md +484 -964
  9. package/ROADMAP-V4.md +451 -0
  10. package/brand/README.md +43 -0
  11. package/brand/icon.svg +32 -0
  12. package/brand/mark.svg +18 -0
  13. package/brand/wordmark.svg +30 -0
  14. package/cli/app.js +230 -0
  15. package/cli/control.js +116 -0
  16. package/cli/lib/colors.sh +15 -0
  17. package/cli/lib/menu.sh +145 -96
  18. package/cli/portability.js +186 -0
  19. package/cli/ssh-manager +197 -91
  20. package/cli/ssh-manager.js +14 -0
  21. package/cli/style.js +17 -0
  22. package/cli/vault.js +411 -0
  23. package/desktop/ControlPlaneApp.swift +219 -0
  24. package/desktop/build.sh +58 -0
  25. package/desktop/electron/after-pack.cjs +39 -0
  26. package/desktop/electron/electron-builder.yml +148 -0
  27. package/desktop/electron/finalize-artifacts.mjs +83 -0
  28. package/desktop/electron/main.js +815 -0
  29. package/desktop/electron/package-lock.json +3656 -0
  30. package/desktop/electron/package.json +30 -0
  31. package/desktop/electron/prepare-engine.mjs +84 -0
  32. package/desktop/electron/resources/entitlements.mac.plist +22 -0
  33. package/desktop/electron/resources/icon.png +0 -0
  34. package/desktop/electron/resources/trayTemplate.png +0 -0
  35. package/desktop/electron/resources/trayTemplate@2x.png +0 -0
  36. package/desktop/electron/smoke-test.mjs +184 -0
  37. package/dist/ui/app.css +1 -0
  38. package/dist/ui/app.js +501 -0
  39. package/dist/ui/assets/Forum-Regular.woff2 +0 -0
  40. package/dist/ui/assets/JetBrainsMono-Bold.woff2 +0 -0
  41. package/dist/ui/assets/JetBrainsMono-Regular.woff2 +0 -0
  42. package/dist/ui/assets/Karla-Variable.woff2 +0 -0
  43. package/dist/ui/index.html +16 -0
  44. package/docs/DISTRIBUTION.md +136 -0
  45. package/docs/FINAL-TEST-V4.md +209 -0
  46. package/docs/MIGRATION.md +334 -0
  47. package/docs/TESTING-V4.md +119 -0
  48. package/docs/superpowers/specs/2026-10-08-desktop-from-npm-and-cli-design.md +187 -0
  49. package/docs/videos/control-plane.mp4 +0 -0
  50. package/package.json +61 -30
  51. package/scripts/build-interface.mjs +73 -0
  52. package/scripts/capture-screenshots.mjs +191 -0
  53. package/scripts/demo-env.mjs +461 -0
  54. package/scripts/frame-screenshots.py +176 -0
  55. package/scripts/macbook-mockup.py +296 -0
  56. package/scripts/make-tray-icon.py +61 -0
  57. package/scripts/preview-candidate.mjs +291 -0
  58. package/scripts/publish-desktop.mjs +46 -0
  59. package/scripts/record-demo.mjs +229 -0
  60. package/scripts/release-version.mjs +32 -0
  61. package/scripts/render-cli-menu.py +157 -0
  62. package/scripts/requirements-dev.in +12 -0
  63. package/scripts/requirements-dev.txt +424 -0
  64. package/scripts/run-ui-regression.mjs +48 -0
  65. package/scripts/setup-hooks.sh +7 -13
  66. package/scripts/smoke-desktop.mjs +80 -0
  67. package/scripts/test-drag-and-drop.mjs +114 -0
  68. package/scripts/test-first-run.mjs +5 -0
  69. package/scripts/test-import-ui.mjs +5 -0
  70. package/scripts/test-preferences-persist.mjs +5 -0
  71. package/scripts/test-upgrade-from-published.mjs +226 -0
  72. package/scripts/verify-mac-build.sh +153 -0
  73. package/scripts/verify-windows-build.ps1 +15 -0
  74. package/server.json +3 -3
  75. package/skills/README.md +42 -0
  76. package/skills/ssh-incident/SKILL.md +55 -0
  77. package/skills/ssh-operations/SKILL.md +62 -0
  78. package/skills/ssh-restricted/SKILL.md +57 -0
  79. package/src/agent-clients.js +482 -0
  80. package/src/approval.js +291 -0
  81. package/src/audit.js +11 -1
  82. package/src/command-log.js +162 -0
  83. package/src/config-loader.js +119 -4
  84. package/src/config-paths.js +101 -0
  85. package/src/control-plane.js +2730 -0
  86. package/src/desktop-install.js +747 -0
  87. package/src/index.js +179 -213
  88. package/src/live-stream.js +261 -0
  89. package/src/saved-commands.js +150 -0
  90. package/src/secret-store.js +573 -0
  91. package/src/server-aliases.js +8 -7
  92. package/src/server-config-manager.js +33 -7
  93. package/src/server-export.js +106 -0
  94. package/src/server-groups.js +82 -21
  95. package/src/server-import.js +477 -0
  96. package/src/shell-quote.js +9 -2
  97. package/src/ssh-connection.js +155 -0
  98. package/src/ssh-manager.js +186 -13
  99. package/src/tunnel-manager.js +79 -0
  100. package/src/vault-recovery.js +206 -0
  101. package/src/xlsx.js +322 -0
  102. package/docs/images/social-preview.png +0 -0
  103. package/docs/images/social-preview@2x.png +0 -0
  104. package/docs/images/ssh-manager-cli-menu.png +0 -0
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "mcp-ssh-manager",
3
- "version": "3.8.7",
3
+ "version": "4.0.1",
4
4
  "mcpName": "io.github.bvisible/mcp-ssh-manager",
5
- "description": "MCP SSH Manager: Model Context Protocol server for SSH remote server management. Control SSH connections from Claude Code and OpenAI Codex - execute commands, transfer files, database operations, backups, health monitoring, and DevOps automation. NEW: Tool activation system reduces context usage by 92%",
5
+ "description": "MCP server for SSH: let AI agents (Claude Code, Codex, any MCP client) run commands, transfer files and manage servers over SSH, with human approval, an encrypted vault and a live audit trail.",
6
6
  "main": "src/index.js",
7
7
  "bin": {
8
8
  "mcp-ssh-manager": "src/index.js",
@@ -14,14 +14,18 @@
14
14
  "setup": "npm install && pip install -r tools/requirements.txt",
15
15
  "configure": "python tools/server-manager.py",
16
16
  "test-connection": "python tools/test-connection.py",
17
- "test": "npm run test:lockfile && npm run test:sudostdin && npm run test:redaction && npm run test:profiles && npm run test:aliases && npm run test:hooks && npm run test:hostkeys && npm run test:tools && npm run test:policy && npm run test:policynames && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:groups && npm run test:agentforward && npm run test:certpath && npm run test:lifecycle && npm run test:tunnel && npm run test:sync && npm run test:sync-path && npm run test:dbquoting && npm run test:dbinjection && npm run test:backupinjection && npm run test:dbrowcount && npm run test:cli-edit",
17
+ "test": "npm run test:lockfile && npm run test:sudostdin && npm run test:vault && npm run test:recovery && npm run test:upgrade && npm run test:notify && npm run test:commands && npm run test:commandlog && npm run test:portability && npm run test:approval && npm run test:controlplane && npm run test:terminal && npm run test:files && npm run test:livestream && npm run test:skills && npm run test:redaction && npm run test:profiles && npm run test:aliases && npm run test:hooks && npm run test:tools && npm run test:policy && npm run test:policynames && npm run test:ping && npm run test:config && npm run test:fieldnames && npm run test:groups && npm run test:agentforward && npm run test:certpath && npm run test:agentannounce && npm run test:autherrors && npm run test:envchoice && npm run test:lifecycle && npm run test:tunnel && npm run test:sync && npm run test:sync-path && npm run test:dbquoting && npm run test:dbinjection && npm run test:quoteprops && npm run test:backupinjection && npm run test:dbrowcount && npm run test:migration && npm run test:security && npm run test:hostkeys && npm run test:proxy && npm run test:working-directory && npm run test:groups-persistence && npm run test:release && npm run test:cli-experience && npm run test:desktop-install && npm run test:agent-clients && npm run test:appupdate && npm run test:preview && npm run test:desktop-smoke && npm run test:cli-edit",
18
18
  "test:lockfile": "node tests/test-lockfile.js",
19
19
  "test:sudostdin": "node tests/test-sudo-stdin.js",
20
+ "test:vault": "node tests/test-secret-store.js",
21
+ "test:approval": "node tests/test-approval.js",
22
+ "test:controlplane": "node tests/test-control-plane.js",
23
+ "test:livestream": "node tests/test-live-stream.js",
24
+ "test:skills": "node tests/test-skills.js",
20
25
  "test:redaction": "node tests/test-logger-redaction.js",
21
26
  "test:profiles": "node tests/test-profiles.js",
22
27
  "test:aliases": "node tests/test-command-aliases.js",
23
28
  "test:hooks": "node tests/test-hooks.js",
24
- "test:hostkeys": "node tests/test-host-key-verification.js",
25
29
  "test:tools": "node tests/test-tool-registry.js",
26
30
  "test:policy": "node tests/test-policy.js",
27
31
  "test:ping": "node tests/test-ssh-ping.js",
@@ -30,12 +34,16 @@
30
34
  "test:groups": "node tests/test-server-groups.js",
31
35
  "test:agentforward": "node tests/test-agent-forward.js",
32
36
  "test:certpath": "node tests/test-cert-path.js",
37
+ "test:agentannounce": "node tests/test-agent-announce.js",
38
+ "test:autherrors": "node tests/test-auth-errors.js",
39
+ "test:envchoice": "node tests/test-env-file-choice.js",
33
40
  "test:lifecycle": "node tests/test-lifecycle.js",
34
41
  "test:tunnel": "node tests/test-tunnel-listen.js",
35
42
  "test:sync": "node tests/test-sync-stats.js",
36
43
  "test:sync-path": "node tests/test-rsync-path.js",
37
44
  "test:dbquoting": "node tests/test-database-query-quoting.js",
38
45
  "test:dbinjection": "node tests/test-database-injection.js",
46
+ "test:quoteprops": "node tests/test-shell-quote-properties.js",
39
47
  "test:backupinjection": "node tests/test-backup-monitor-injection.js",
40
48
  "test:dbrowcount": "node tests/test-database-row-count.js",
41
49
  "test:cli-edit": "node tests/test-cli-edit-server.js",
@@ -44,46 +52,67 @@
44
52
  "typecheck": "tsc -p tsconfig.json",
45
53
  "lint": "eslint src/*.js",
46
54
  "format": "prettier --write 'src/**/*.js' 'tests/**/*.js'",
55
+ "test:terminal": "node tests/test-terminal.js",
56
+ "test:files": "node tests/test-files.js",
57
+ "build:ui": "node scripts/build-interface.mjs",
58
+ "prepack": "node scripts/build-interface.mjs",
59
+ "test:recovery": "node tests/test-vault-recovery.js",
60
+ "test:upgrade": "node tests/test-upgrade.js",
61
+ "test:notify": "node tests/test-notify.js",
62
+ "test:commands": "node tests/test-saved-commands.js",
63
+ "test:commandlog": "node tests/test-command-log.js",
64
+ "test:portability": "node tests/test-portability.js",
65
+ "test:migration": "node tests/test-v4-migration.js",
66
+ "test:security": "node tests/test-security-boundary.js",
67
+ "test:hostkeys": "node tests/test-host-key-verification.js",
68
+ "test:proxy": "node tests/test-ssh-connection.js",
69
+ "test:working-directory": "node tests/test-working-directory.js",
70
+ "test:groups-persistence": "node tests/test-groups-persistence.js",
71
+ "test:release": "node tests/test-release.js",
72
+ "test:cli-experience": "node tests/test-cli-experience.js",
73
+ "test:agent-clients": "node tests/test-agent-clients.js",
74
+ "test:appupdate": "node tests/test-app-update.js",
75
+ "test:desktop-install": "node tests/test-desktop-install.js",
76
+ "test:published-upgrade": "node scripts/test-upgrade-from-published.mjs",
77
+ "test:ui": "npm --prefix ui run test:e2e",
78
+ "test:preview": "node tests/test-preview-candidate.js",
79
+ "test:desktop-smoke": "node tests/test-desktop-smoke.js",
47
80
  "test:policynames": "node tests/test-policy-name-resolution.js"
48
81
  },
49
82
  "keywords": [
50
83
  "mcp",
84
+ "mcp-server",
85
+ "model-context-protocol",
51
86
  "ssh",
52
- "mcp-ssh",
53
- "mcp ssh",
54
87
  "ssh-mcp",
55
- "ssh mcp",
56
- "model-context-protocol-ssh",
57
- "mcp-server",
58
- "mcp server ssh",
88
+ "mcp-ssh",
89
+ "sftp",
90
+ "ssh-client",
59
91
  "claude-code",
60
- "claude-ssh",
61
- "claude-code-ssh",
92
+ "claude-desktop",
62
93
  "openai-codex",
63
94
  "codex",
64
- "model-context-protocol",
95
+ "ai-agents",
96
+ "agentic-ai",
97
+ "llm-tools",
98
+ "ai-assistant",
99
+ "devops",
65
100
  "remote-server",
101
+ "server-management",
102
+ "remote-access",
103
+ "human-in-the-loop",
104
+ "approval",
105
+ "audit-log",
106
+ "security",
107
+ "backup",
108
+ "database",
109
+ "health-monitoring",
66
110
  "ssh-manager",
67
- "ssh manager mcp",
68
- "remote-ssh",
69
111
  "ssh-automation",
70
112
  "deployment",
71
- "devops",
72
- "automation",
73
- "backup",
74
- "restore",
75
- "health-monitoring",
76
- "database",
77
113
  "mysql",
78
114
  "postgresql",
79
- "mongodb",
80
- "profiles",
81
- "hooks",
82
- "aliases",
83
- "toml",
84
- "ai-assistant",
85
- "ai-tools",
86
- "llm-tools"
115
+ "mongodb"
87
116
  ],
88
117
  "author": "MCP SSH Manager Contributors",
89
118
  "license": "MIT",
@@ -103,8 +132,10 @@
103
132
  "zod": "^4.6.7"
104
133
  },
105
134
  "devDependencies": {
135
+ "@types/node": "^26.6.4",
106
136
  "eslint": "^8.56.0",
107
- "knip": "^5.0.0",
137
+ "fast-check": "^4.10.2",
138
+ "knip": "^6.40.0",
108
139
  "prettier": "^3.2.4",
109
140
  "typescript": "^6.0.3"
110
141
  },
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+ // Builds the control plane interface into dist/ui.
3
+ //
4
+ // dist/ui is generated, never committed: it is built when the npm package is
5
+ // made (`prepack`), when the desktop app is assembled (prepare-engine) and by
6
+ // hand with `npm run build:ui`. What a user installs is unchanged: the package
7
+ // and the app carry the built interface, so nothing compiles on their machine.
8
+ //
9
+ // The interface sources live in ui/ and are not part of the package, so a tree
10
+ // without ui/ (an unpacked tarball) keeps the dist/ui it already has.
11
+ import { execFileSync } from 'node:child_process';
12
+ import fs from 'node:fs';
13
+ import path from 'node:path';
14
+ import { fileURLToPath } from 'node:url';
15
+
16
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
17
+ const ui = path.join(root, 'ui');
18
+ const out = path.join(root, 'dist', 'ui');
19
+ const REQUIRED = ['index.html', 'app.js', 'app.css'];
20
+
21
+ /** What is missing from a build, empty when it is complete. */
22
+ function missingFrom(dir) {
23
+ return REQUIRED.filter(name => {
24
+ try { return fs.statSync(path.join(dir, name)).size === 0; } catch { return true; }
25
+ });
26
+ }
27
+
28
+ /**
29
+ * Run npm without a shell. `npm_execpath` is npm's own script when this file is
30
+ * started by `npm run`; Windows has no `npm` binary, only `npm.cmd`, which Node
31
+ * will not spawn without a shell.
32
+ * @param {string[]} args
33
+ */
34
+ function npm(args) {
35
+ const cli = process.env.npm_execpath;
36
+ // Everything is written to stderr: as `prepack` this runs inside `npm pack`,
37
+ // whose stdout may be machine-read (`npm pack --json`) and must stay clean.
38
+ const stdio = ['ignore', process.stderr.fd, process.stderr.fd];
39
+ if (cli && cli.endsWith('.js')) {
40
+ execFileSync(process.execPath, [cli, ...args], { cwd: root, stdio });
41
+ } else {
42
+ execFileSync(process.platform === 'win32' ? 'npm.cmd' : 'npm', args, { cwd: root, stdio, shell: process.platform === 'win32' });
43
+ }
44
+ }
45
+
46
+ if (!fs.existsSync(path.join(ui, 'package.json'))) {
47
+ const missing = missingFrom(out);
48
+ if (missing.length) {
49
+ console.error(`The interface sources (ui/) are not here and dist/ui is incomplete (missing: ${missing.join(', ')}).`);
50
+ process.exit(1);
51
+ }
52
+ console.error('No interface sources here; keeping the dist/ui that comes with this tree.');
53
+ process.exit(0);
54
+ }
55
+
56
+ // A pack from a fresh checkout has no ui/node_modules yet; the lockfile decides
57
+ // what gets installed, exactly as in CI.
58
+ if (!fs.existsSync(path.join(ui, 'node_modules'))) {
59
+ console.error('Installing the interface dependencies from ui/package-lock.json…');
60
+ npm(['ci', '--prefix', 'ui', '--no-audit', '--no-fund']);
61
+ }
62
+
63
+ // Never ship a stale or half-written build: start from nothing.
64
+ fs.rmSync(out, { recursive: true, force: true });
65
+ console.error('Building the interface into dist/ui…');
66
+ npm(['run', 'build', '--prefix', 'ui']);
67
+
68
+ const missing = missingFrom(out);
69
+ if (missing.length) {
70
+ console.error(`The interface build did not produce: ${missing.join(', ')}`);
71
+ process.exit(1);
72
+ }
73
+ console.error('dist/ui is ready.');
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Take the README screenshots, the same way every time.
4
+ *
5
+ * Screenshots rot: a rail gets an item, a colour changes, and the pictures
6
+ * quietly describe a version nobody is running. They also leak — an early set
7
+ * in this repo had to be thrown away because it showed the author's real home
8
+ * directory in the file browser. Both problems come from screenshots being
9
+ * taken by hand.
10
+ *
11
+ * So this drives a real Chrome over the DevTools protocol against
12
+ * scripts/demo-env.mjs, at a fixed viewport and deviceScaleFactor 2, and writes
13
+ * PNGs whose only inputs are the demo personas. Re-running it after a UI change
14
+ * regenerates the whole set.
15
+ *
16
+ * Two variants per view, because the product genuinely runs two ways:
17
+ *
18
+ * browser a tab on the local control plane
19
+ * app the packaged desktop build, which appends `?shell=macos`; the rail
20
+ * then leaves room at the top for the window buttons
21
+ *
22
+ * The window frames are drawn afterwards by scripts/frame-screenshots.py.
23
+ *
24
+ * Chrome's --headless does not return on macOS 27 / Chrome 152, so this uses a
25
+ * real window on a scratch profile instead. It steals focus for a few seconds.
26
+ *
27
+ * Usage:
28
+ * node scripts/demo-env.mjs --port 7315 & # in another shell
29
+ * node scripts/capture-screenshots.mjs <url-with-token>
30
+ */
31
+ import fs from 'fs';
32
+ import os from 'os';
33
+ import path from 'path';
34
+ import { spawn } from 'child_process';
35
+
36
+ // Node has had a global WebSocket since 22; the shared eslint env predates it.
37
+ /* global WebSocket */
38
+
39
+ const CHROME = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
40
+ const OUT = path.join(path.dirname(new URL(import.meta.url).pathname), '..', 'docs', 'images', '.raw');
41
+ const PORT = 9333;
42
+ const WIDTH = 1440;
43
+ const HEIGHT = 880;
44
+
45
+ /**
46
+ * The views worth showing, and how to reach each one.
47
+ *
48
+ * The interface keeps the current view in a store, not in the URL, so these
49
+ * click rather than navigate. Matching on the rail item's own text means a
50
+ * renamed view breaks the capture loudly instead of silently re-shooting the
51
+ * server list five times.
52
+ */
53
+ // The count badge is inside the button, so its textContent is 'Waiting1' the
54
+ // moment anything is pending — an exact match silently re-shot the server list.
55
+ // Matched on the accessible name, not the visible text: the rail is collapsed
56
+ // by default now, so its items show an icon and nothing else. The old text
57
+ // match found nothing and the capture died on the second view.
58
+ const rail = label =>
59
+ `(() => { const b = document.querySelector('button[aria-label=${JSON.stringify(label)}]');`
60
+ + ` if (!b) throw new Error('no rail item ' + ${JSON.stringify(label)}); b.click(); })()`;
61
+
62
+ const VIEWS = [
63
+ { name: 'v4-servers', reach: 'null', settle: 1200 },
64
+ { name: 'v4-terminal', reach: rail('Terminal'), settle: 1400 },
65
+ { name: 'v4-waiting', reach: rail('Waiting'), settle: 1200 },
66
+ // Health probes when asked, so the screenshot needs the button pressed as well
67
+ // as the view opened — otherwise it is a picture of 'Nothing probed yet'.
68
+ { name: 'v4-health',
69
+ reach: rail('Health') + '; await new Promise(r => setTimeout(r, 600));' +
70
+ '[...document.querySelectorAll(\'button\')].find(b => /Check every server/.test(b.textContent))?.click()',
71
+ settle: 8000, awaitPromise: true },
72
+ // The output lives behind a disclosure row; a collapsed Live view shows a
73
+ // command name and nothing of what makes the screen worth having.
74
+ { name: 'v4-live',
75
+ reach: rail('Live') + '; await new Promise(r => setTimeout(r, 800));' +
76
+ '[...document.querySelectorAll(\'button\')]' +
77
+ '.find(b => b.textContent.includes(\'tail -f\')).click()',
78
+ settle: 1800, awaitPromise: true },
79
+ // Not a rail item: the browser opens from a server card. The second one is
80
+ // `production`, which has the deepest tree in the demo.
81
+ { name: 'v4-files',
82
+ reach: 'document.querySelectorAll(\'[aria-label="Browse files"]\')[1]?.click() ?? null',
83
+ settle: 3500 },
84
+ ];
85
+
86
+ const sleep = ms => new Promise(r => setTimeout(r, ms));
87
+
88
+ /** A minimal CDP client: one socket, numbered commands, awaited replies. */
89
+ class Devtools {
90
+ constructor(ws) {
91
+ this.ws = ws;
92
+ this.next = 1;
93
+ this.pending = new Map();
94
+ ws.addEventListener('message', event => {
95
+ const message = JSON.parse(event.data);
96
+ const waiter = this.pending.get(message.id);
97
+ if (waiter) {
98
+ this.pending.delete(message.id);
99
+ message.error ? waiter.reject(new Error(message.error.message)) : waiter.resolve(message.result);
100
+ }
101
+ });
102
+ }
103
+
104
+ static async connect(target) {
105
+ const ws = new WebSocket(target);
106
+ await new Promise((resolve, reject) => {
107
+ ws.addEventListener('open', resolve, { once: true });
108
+ ws.addEventListener('error', () => reject(new Error('cannot reach Chrome')), { once: true });
109
+ });
110
+ return new Devtools(ws);
111
+ }
112
+
113
+ send(method, params = {}) {
114
+ const id = this.next++;
115
+ this.ws.send(JSON.stringify({ id, method, params }));
116
+ return new Promise((resolve, reject) => this.pending.set(id, { resolve, reject }));
117
+ }
118
+ }
119
+
120
+ async function targetUrl() {
121
+ // Chrome takes a moment to open the port after launch.
122
+ for (let attempt = 0; attempt < 60; attempt++) {
123
+ try {
124
+ const list = await fetch(`http://127.0.0.1:${PORT}/json/list`).then(r => r.json());
125
+ const page = list.find(t => t.type === 'page' && t.webSocketDebuggerUrl);
126
+ if (page) return page.webSocketDebuggerUrl;
127
+ } catch { /* not up yet */ }
128
+ await sleep(250);
129
+ }
130
+ throw new Error('Chrome never opened its debugging port');
131
+ }
132
+
133
+ async function main() {
134
+ const base = process.argv[2];
135
+ if (!base) {
136
+ console.error('usage: node scripts/capture-screenshots.mjs <control-plane-url-with-token>');
137
+ process.exit(1);
138
+ }
139
+
140
+ fs.mkdirSync(OUT, { recursive: true });
141
+ const profile = fs.mkdtempSync(path.join(os.tmpdir(), 'shots-profile-'));
142
+ const chrome = spawn(CHROME, [
143
+ `--remote-debugging-port=${PORT}`,
144
+ `--user-data-dir=${profile}`,
145
+ '--no-first-run', '--no-default-browser-check',
146
+ '--disable-background-networking', '--disable-features=Translate',
147
+ `--window-size=${WIDTH},${HEIGHT}`,
148
+ 'about:blank',
149
+ ], { stdio: 'ignore' });
150
+
151
+ const cdp = await Devtools.connect(await targetUrl());
152
+ await cdp.send('Page.enable');
153
+ await cdp.send('Runtime.enable');
154
+ // The viewport, not the window: no chrome, no scrollbar, and 2x so the PNG
155
+ // survives being shown at half size on a high-density display.
156
+ await cdp.send('Emulation.setDeviceMetricsOverride',
157
+ { width: WIDTH, height: HEIGHT, deviceScaleFactor: 2, mobile: false });
158
+
159
+ for (const variant of ['browser', 'app']) {
160
+ const url = variant === 'app'
161
+ ? base + (base.includes('?') ? '&' : '?') + 'shell=macos'
162
+ : base;
163
+ for (const view of VIEWS) {
164
+ // Reload for each view: clicking from a known starting point beats
165
+ // unwinding whatever the previous view left open.
166
+ await cdp.send('Page.navigate', { url });
167
+ await sleep(1500);
168
+ const { exceptionDetails } = await cdp.send('Runtime.evaluate', {
169
+ expression: view.awaitPromise ? `(async () => { ${view.reach} })()` : view.reach,
170
+ awaitPromise: Boolean(view.awaitPromise),
171
+ });
172
+ if (exceptionDetails) throw new Error(`${view.name}: ${exceptionDetails.text}`);
173
+ await sleep(view.settle);
174
+ const { data } = await cdp.send('Page.captureScreenshot', { format: 'png' });
175
+ const file = path.join(OUT, `${view.name}-${variant}.png`);
176
+ fs.writeFileSync(file, Buffer.from(data, 'base64'));
177
+ console.log(` ${path.basename(file).padEnd(30)} ${(fs.statSync(file).size / 1024).toFixed(0)} Ko`);
178
+ }
179
+ }
180
+
181
+ chrome.kill();
182
+ // Chrome keeps writing to its profile for a moment after the signal; removing
183
+ // it immediately races and throws ENOTEMPTY on a run that otherwise worked.
184
+ await sleep(1500);
185
+ try { fs.rmSync(profile, { recursive: true, force: true }); } catch { /* it is a temp dir */ }
186
+ }
187
+
188
+ main().catch(error => {
189
+ console.error(error.message);
190
+ process.exit(1);
191
+ });