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
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Getting servers back out, and handing someone a form to fill in.
3
+ *
4
+ * Export exists for the obvious reason — your list should not be trapped in this
5
+ * tool — and for a less obvious one: it is how the import format documents
6
+ * itself. Export your servers, look at the columns, and you know exactly what a
7
+ * spreadsheet has to contain.
8
+ *
9
+ * **No secrets leave this way.** A password or a passphrase in the vault stays
10
+ * in the vault; the export carries hosts, users, ports and key *paths*. An
11
+ * export is a file people mail to each other and commit by accident, and a
12
+ * format that sometimes contains a production password is a format nobody can
13
+ * use safely. Where a secret exists, the export says so in a column rather than
14
+ * printing it.
15
+ */
16
+ import { writeSheet } from './xlsx.js';
17
+
18
+ /**
19
+ * The columns, in the order a person reads them.
20
+ *
21
+ * Typed as tuples, or every `.map` off this array widens to `(string|number)[]`
22
+ * and the sheet writer stops accepting it.
23
+ *
24
+ * @type {[string, string, number][]}
25
+ */
26
+ const FIELDS = [
27
+ ['name', 'name', 18],
28
+ ['host', 'host', 30],
29
+ ['user', 'user', 16],
30
+ ['port', 'port', 7],
31
+ ['keyPath', 'key path', 34],
32
+ ['defaultDir', 'default directory', 24],
33
+ ['group', 'group', 16],
34
+ ['platform', 'platform', 11],
35
+ ['proxyJump', 'proxy jump', 16],
36
+ ['description', 'description', 30],
37
+ ];
38
+
39
+ /** @param {any} server @returns {string[]} One row, in FIELDS order */
40
+ function row(server) {
41
+ return FIELDS.map(([field]) => {
42
+ const value = server[field];
43
+ if (value === undefined || value === null) return '';
44
+ if (field === 'port' && Number(value) === 22) return '';
45
+ return String(value);
46
+ });
47
+ }
48
+
49
+ /** @param {any[]} servers @returns {string[][]} Header plus one row each */
50
+ function table(servers) {
51
+ return [FIELDS.map(([, header]) => header), ...servers.map(row)];
52
+ }
53
+
54
+ /**
55
+ * @param {any[]} servers
56
+ * @returns {string} RFC 4180 CSV, comma-separated, with a UTF-8 BOM
57
+ */
58
+ export function toCsv(servers) {
59
+ const quote = cell => /[",\n]/.test(cell) ? `"${cell.replace(/"/g, '""')}"` : cell;
60
+ const body = table(servers).map(cells => cells.map(quote).join(',')).join('\n');
61
+ // The BOM is what makes Excel on Windows read this as UTF-8 rather than
62
+ // Latin-1, which is the difference between "café" and "café" in a hostname
63
+ // comment. Every other reader ignores it.
64
+ return `\ufeff${body}\n`;
65
+ }
66
+
67
+ /** @param {any[]} servers @returns {Buffer} */
68
+ export function toXlsx(servers) {
69
+ return writeSheet(table(servers), {
70
+ sheetName: 'Servers',
71
+ widths: FIELDS.map(([, , width]) => width),
72
+ });
73
+ }
74
+
75
+ /**
76
+ * A blank form, with examples.
77
+ *
78
+ * The examples are deliberately obvious fiction — `example.com`, `10.0.0.5` —
79
+ * so nobody imports them by accident and everybody can see what each column
80
+ * wants. They are meant to be typed over.
81
+ *
82
+ * @returns {Buffer}
83
+ */
84
+ export function template() {
85
+ const examples = [
86
+ { name: 'production', host: 'prod.example.com', user: 'deploy', port: 22,
87
+ keyPath: '~/.ssh/id_ed25519', defaultDir: '/var/www', group: 'production',
88
+ description: 'Delete this row and the two below, then add your own' },
89
+ { name: 'staging', host: 'staging.example.com', user: 'deploy',
90
+ keyPath: '~/.ssh/id_ed25519', group: 'staging' },
91
+ { name: 'internal', host: '10.0.0.5', user: 'admin', port: 2222,
92
+ group: 'infra', proxyJump: 'production',
93
+ description: 'Reached through the production host' },
94
+ ];
95
+ return writeSheet([
96
+ FIELDS.map(([, header]) => header),
97
+ ...examples.map(row),
98
+ [],
99
+ ['# Only "host" is required.', '', '', '', '', '', '', '', '', ''],
100
+ ['# Leave port empty for 22.', '', '', '', '', '', '', '', '', ''],
101
+ ['# "group" is any label you like — it is what you run commands across.', '', '', '', '', '', '', '', '', ''],
102
+ ['# "platform" is only for Windows hosts. Leave it empty otherwise.', '', '', '', '', '', '', '', '', ''],
103
+ ['# "proxy jump" is the name of another row, used as a bastion.', '', '', '', '', '', '', '', '', ''],
104
+ ['# Passwords are never read from this file. You are asked once, on first connection.', '', '', '', '', '', '', '', '', ''],
105
+ ], { sheetName: 'Servers', widths: FIELDS.map(([, , width]) => width) });
106
+ }
@@ -5,14 +5,22 @@
5
5
 
6
6
  import fs from 'fs';
7
7
  import path from 'path';
8
+ import os from 'os';
9
+ import { randomUUID } from 'crypto';
8
10
  import { fileURLToPath } from 'url';
9
11
  import { logger } from './logger.js';
10
12
 
11
13
  const __filename = fileURLToPath(import.meta.url);
12
14
  const __dirname = path.dirname(__filename);
13
15
 
14
- // Default groups file location
15
- const GROUPS_FILE = path.join(__dirname, '..', '.server-groups.json');
16
+ const LEGACY_GROUPS_FILE = path.join(__dirname, '..', '.server-groups.json');
17
+
18
+ // Shared by npm, the CLI and the desktop app. Never write inside an installed
19
+ // package: updates replace it, and writing in a macOS bundle invalidates its seal.
20
+ export function defaultGroupsPath() {
21
+ return process.env.SSH_GROUPS_FILE
22
+ || path.join(process.env.SSH_MANAGER_HOME || path.join(os.homedir(), '.ssh-manager'), 'groups.json');
23
+ }
16
24
 
17
25
  // Group execution strategies
18
26
  const EXECUTION_STRATEGIES = {
@@ -23,9 +31,13 @@ const EXECUTION_STRATEGIES = {
23
31
 
24
32
  export class ServerGroups {
25
33
  constructor(options = {}) {
26
- // Both options exist so this class can be instantiated in isolation (tests,
27
- // embedding). The exported singleton below keeps the historical defaults.
28
- this.groupsFile = options.groupsFile || GROUPS_FILE;
34
+ this.groupsFile = options.groupsFile || defaultGroupsPath();
35
+ // Explicit paths are isolated unless their caller explicitly opts into a
36
+ // legacy file. Migration is a read fallback until the first successful edit;
37
+ // simply upgrading or listing groups creates no files and retains rollback.
38
+ this.legacyGroupsFile = options.legacyGroupsFile
39
+ ?? (options.groupsFile || process.env.SSH_GROUPS_FILE ? null : LEGACY_GROUPS_FILE);
40
+ this.loadError = null;
29
41
  this.serverConfigProvider = typeof options.serverConfigProvider === 'function'
30
42
  ? options.serverConfigProvider
31
43
  : null;
@@ -73,10 +85,35 @@ export class ServerGroups {
73
85
  * Load groups from file
74
86
  */
75
87
  loadGroups() {
88
+ return this.#withoutPrototype(this.#readGroups());
89
+ }
90
+
91
+ /**
92
+ * Group names are user and agent input — `ssh_group_manage` takes them from
93
+ * a model, and a model reads whatever a server prints. Held in an ordinary
94
+ * object, `this.groups['__proto__']`, `['constructor']` or `['toString']`
95
+ * resolve to Object.prototype and its members: those names were reported as
96
+ * already existing, `constructor` "resolved" to a function, and an overwrite
97
+ * of `__proto__` would have replaced the map's prototype. With no prototype
98
+ * they are plain keys like any other. Names stay free-form, as 3.x allowed.
99
+ *
100
+ * @param {Record<string, any>} groups - Loaded or default groups
101
+ * @returns {Record<string, any>}
102
+ */
103
+ #withoutPrototype(groups) {
104
+ return Object.assign(Object.create(null), groups);
105
+ }
106
+
107
+ #readGroups() {
108
+ this.loadError = null;
76
109
  try {
77
- if (fs.existsSync(this.groupsFile)) {
78
- const data = fs.readFileSync(this.groupsFile, 'utf8');
110
+ const source = fs.existsSync(this.groupsFile) ? this.groupsFile : this.legacyGroupsFile;
111
+ if (source && fs.existsSync(source)) {
112
+ const data = fs.readFileSync(source, 'utf8');
79
113
  const stored = JSON.parse(data);
114
+ if (!stored || typeof stored !== 'object' || Array.isArray(stored)) {
115
+ throw new Error(`Invalid server groups file: ${source}`);
116
+ }
80
117
 
81
118
  // Dynamic groups are deliberately never persisted (see saveGroups), so
82
119
  // they are missing from every file written after the first group edit.
@@ -86,6 +123,7 @@ export class ServerGroups {
86
123
  return { ...this.getDynamicGroups(), ...stored };
87
124
  }
88
125
  } catch (error) {
126
+ this.loadError = error;
89
127
  logger.warn('Failed to load server groups', { error: error.message });
90
128
  }
91
129
 
@@ -115,21 +153,31 @@ export class ServerGroups {
115
153
  * Save groups to file
116
154
  */
117
155
  saveGroups() {
156
+ const temporary = `${this.groupsFile}.${randomUUID()}.tmp`;
118
157
  try {
158
+ if (this.loadError) throw this.loadError;
119
159
  // Don't save dynamic groups
120
- const groupsToSave = {};
160
+ // No prototype here either: `groupsToSave['__proto__'] = group` on an
161
+ // ordinary object sets its prototype, and the group vanishes from the file.
162
+ const groupsToSave = Object.create(null);
121
163
  for (const [name, group] of Object.entries(this.groups)) {
122
164
  if (!group.dynamic) {
123
165
  groupsToSave[name] = group;
124
166
  }
125
167
  }
126
168
 
127
- fs.writeFileSync(this.groupsFile, JSON.stringify(groupsToSave, null, 2));
169
+ fs.mkdirSync(path.dirname(this.groupsFile), { recursive: true, mode: 0o700 });
170
+ fs.writeFileSync(temporary, `${JSON.stringify(groupsToSave, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
171
+ fs.renameSync(temporary, this.groupsFile);
128
172
  logger.info('Server groups saved', { count: Object.keys(groupsToSave).length });
129
173
  return true;
130
174
  } catch (error) {
175
+ try { fs.rmSync(temporary, { force: true }); } catch { /* keep the original write error */ }
176
+ // A failed write is not a successful in-memory edit. Keep the UI and MCP
177
+ // responses consistent with what a restart will actually read.
178
+ this.groups = this.loadGroups();
131
179
  logger.error('Failed to save server groups', { error: error.message });
132
- return false;
180
+ throw new Error(`Could not save server groups to ${this.groupsFile}: ${error.message}`);
133
181
  }
134
182
  }
135
183
 
@@ -519,16 +567,29 @@ export class ServerGroups {
519
567
  }
520
568
  }
521
569
 
522
- // Export singleton instance
523
- const serverGroups = new ServerGroups();
570
+ // Resolve lazily, after CLI/environment setup, and refresh before each public
571
+ // operation so an already-running MCP server sees edits from the desktop app.
572
+ let serverGroups = null;
573
+ let configProvider = null;
574
+ function currentGroups() {
575
+ if (!serverGroups || serverGroups.groupsFile !== defaultGroupsPath()) {
576
+ serverGroups = new ServerGroups({ serverConfigProvider: configProvider });
577
+ } else {
578
+ serverGroups.groups = serverGroups.loadGroups();
579
+ }
580
+ return serverGroups;
581
+ }
524
582
 
525
583
  // Export convenience functions
526
- export const setServerConfigProvider = (provider) => serverGroups.setServerConfigProvider(provider);
527
- export const getGroup = (name) => serverGroups.getGroup(name);
528
- export const createGroup = (name, servers, options) => serverGroups.createGroup(name, servers, options);
529
- export const updateGroup = (name, updates) => serverGroups.updateGroup(name, updates);
530
- export const deleteGroup = (name) => serverGroups.deleteGroup(name);
531
- export const addServersToGroup = (name, servers) => serverGroups.addServers(name, servers);
532
- export const removeServersFromGroup = (name, servers) => serverGroups.removeServers(name, servers);
533
- export const listGroups = () => serverGroups.listGroups();
534
- export const executeOnGroup = (name, executor, options) => serverGroups.executeOnGroup(name, executor, options);
584
+ export const setServerConfigProvider = (provider) => {
585
+ configProvider = provider;
586
+ currentGroups().setServerConfigProvider(provider);
587
+ };
588
+ export const getGroup = (name) => currentGroups().getGroup(name);
589
+ export const createGroup = (name, servers, options) => currentGroups().createGroup(name, servers, options);
590
+ export const updateGroup = (name, updates) => currentGroups().updateGroup(name, updates);
591
+ export const deleteGroup = (name) => currentGroups().deleteGroup(name);
592
+ export const addServersToGroup = (name, servers) => currentGroups().addServers(name, servers);
593
+ export const removeServersFromGroup = (name, servers) => currentGroups().removeServers(name, servers);
594
+ export const listGroups = () => currentGroups().listGroups();
595
+ export const executeOnGroup = (name, executor, options) => currentGroups().executeOnGroup(name, executor, options);