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.
- package/.eslintignore +5 -0
- package/.gitattributes +5 -0
- package/CHANGELOG.md +371 -6
- package/CLAUDE.md +6 -0
- package/CODE_OF_CONDUCT.md +18 -0
- package/CONTRIBUTING.md +30 -0
- package/Formula/ssh-manager.rb +60 -0
- package/README.md +484 -964
- package/ROADMAP-V4.md +451 -0
- package/brand/README.md +43 -0
- package/brand/icon.svg +32 -0
- package/brand/mark.svg +18 -0
- package/brand/wordmark.svg +30 -0
- package/cli/app.js +230 -0
- package/cli/control.js +116 -0
- package/cli/lib/colors.sh +15 -0
- package/cli/lib/menu.sh +145 -96
- package/cli/portability.js +186 -0
- package/cli/ssh-manager +197 -91
- package/cli/ssh-manager.js +14 -0
- package/cli/style.js +17 -0
- package/cli/vault.js +411 -0
- package/desktop/ControlPlaneApp.swift +219 -0
- package/desktop/build.sh +58 -0
- package/desktop/electron/after-pack.cjs +39 -0
- package/desktop/electron/electron-builder.yml +148 -0
- package/desktop/electron/finalize-artifacts.mjs +83 -0
- package/desktop/electron/main.js +815 -0
- package/desktop/electron/package-lock.json +3656 -0
- package/desktop/electron/package.json +30 -0
- package/desktop/electron/prepare-engine.mjs +84 -0
- package/desktop/electron/resources/entitlements.mac.plist +22 -0
- package/desktop/electron/resources/icon.png +0 -0
- package/desktop/electron/resources/trayTemplate.png +0 -0
- package/desktop/electron/resources/trayTemplate@2x.png +0 -0
- package/desktop/electron/smoke-test.mjs +184 -0
- package/dist/ui/app.css +1 -0
- package/dist/ui/app.js +501 -0
- package/dist/ui/assets/Forum-Regular.woff2 +0 -0
- package/dist/ui/assets/JetBrainsMono-Bold.woff2 +0 -0
- package/dist/ui/assets/JetBrainsMono-Regular.woff2 +0 -0
- package/dist/ui/assets/Karla-Variable.woff2 +0 -0
- package/dist/ui/index.html +16 -0
- package/docs/DISTRIBUTION.md +136 -0
- package/docs/FINAL-TEST-V4.md +209 -0
- package/docs/MIGRATION.md +334 -0
- package/docs/TESTING-V4.md +119 -0
- package/docs/superpowers/specs/2026-10-08-desktop-from-npm-and-cli-design.md +187 -0
- package/docs/videos/control-plane.mp4 +0 -0
- package/package.json +61 -30
- package/scripts/build-interface.mjs +73 -0
- package/scripts/capture-screenshots.mjs +191 -0
- package/scripts/demo-env.mjs +461 -0
- package/scripts/frame-screenshots.py +176 -0
- package/scripts/macbook-mockup.py +296 -0
- package/scripts/make-tray-icon.py +61 -0
- package/scripts/preview-candidate.mjs +291 -0
- package/scripts/publish-desktop.mjs +46 -0
- package/scripts/record-demo.mjs +229 -0
- package/scripts/release-version.mjs +32 -0
- package/scripts/render-cli-menu.py +157 -0
- package/scripts/requirements-dev.in +12 -0
- package/scripts/requirements-dev.txt +424 -0
- package/scripts/run-ui-regression.mjs +48 -0
- package/scripts/setup-hooks.sh +7 -13
- package/scripts/smoke-desktop.mjs +80 -0
- package/scripts/test-drag-and-drop.mjs +114 -0
- package/scripts/test-first-run.mjs +5 -0
- package/scripts/test-import-ui.mjs +5 -0
- package/scripts/test-preferences-persist.mjs +5 -0
- package/scripts/test-upgrade-from-published.mjs +226 -0
- package/scripts/verify-mac-build.sh +153 -0
- package/scripts/verify-windows-build.ps1 +15 -0
- package/server.json +3 -3
- package/skills/README.md +42 -0
- package/skills/ssh-incident/SKILL.md +55 -0
- package/skills/ssh-operations/SKILL.md +62 -0
- package/skills/ssh-restricted/SKILL.md +57 -0
- package/src/agent-clients.js +482 -0
- package/src/approval.js +291 -0
- package/src/audit.js +11 -1
- package/src/command-log.js +162 -0
- package/src/config-loader.js +119 -4
- package/src/config-paths.js +101 -0
- package/src/control-plane.js +2730 -0
- package/src/desktop-install.js +747 -0
- package/src/index.js +179 -213
- package/src/live-stream.js +261 -0
- package/src/saved-commands.js +150 -0
- package/src/secret-store.js +573 -0
- package/src/server-aliases.js +8 -7
- package/src/server-config-manager.js +33 -7
- package/src/server-export.js +106 -0
- package/src/server-groups.js +82 -21
- package/src/server-import.js +477 -0
- package/src/shell-quote.js +9 -2
- package/src/ssh-connection.js +155 -0
- package/src/ssh-manager.js +186 -13
- package/src/tunnel-manager.js +79 -0
- package/src/vault-recovery.js +206 -0
- package/src/xlsx.js +322 -0
- package/docs/images/social-preview.png +0 -0
- package/docs/images/social-preview@2x.png +0 -0
- package/docs/images/ssh-manager-cli-menu.png +0 -0
package/src/config-loader.js
CHANGED
|
@@ -5,6 +5,8 @@ import path from 'path';
|
|
|
5
5
|
import os from 'os';
|
|
6
6
|
import { logger } from './logger.js';
|
|
7
7
|
import { VALID_MODES } from './policy.js';
|
|
8
|
+
import { SecretStore, defaultVaultPath } from './secret-store.js';
|
|
9
|
+
import { resolveConfigOptions } from './config-paths.js';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* A resolved SSH server configuration, as produced by this loader and consumed
|
|
@@ -34,7 +36,9 @@ import { VALID_MODES } from './policy.js';
|
|
|
34
36
|
* @property {string} [proxyJump] Name of another configured server to jump through.
|
|
35
37
|
* @property {string} [proxyCommand] Custom proxy command (`%h` / `%p` placeholders).
|
|
36
38
|
* @property {boolean} [forwardAgent] Forward the local ssh-agent to this server.
|
|
39
|
+
* @property {boolean} [announceAgent] Send AI_AGENT=mcp-ssh-manager on each command channel. Unset defers to SSH_MANAGER_ANNOUNCE_AGENT (off by default); false keeps a host silent even when that is on.
|
|
37
40
|
* @property {string} [mode] Security mode: `unrestricted`, `readonly` or `restricted`.
|
|
41
|
+
* @property {string} [approval] Human approval mode: `never`, `destructive` or `always`.
|
|
38
42
|
* @property {string[]} [allowPatterns] Regex sources allowed in `restricted` mode.
|
|
39
43
|
* @property {string[]} [denyPatterns] Regex sources always refused.
|
|
40
44
|
* @property {string} [auditLog] Path to a per-server audit log.
|
|
@@ -77,12 +81,26 @@ function parseBool(raw) {
|
|
|
77
81
|
return ['true', '1', 'yes', 'on'].includes(raw.trim().toLowerCase());
|
|
78
82
|
}
|
|
79
83
|
|
|
84
|
+
// Three states rather than two. An unset value has to stay unset, so that a
|
|
85
|
+
// global switch can still decide; only an explicit value is a per-server
|
|
86
|
+
// decision. A malformed value is treated as unset, never as a choice.
|
|
87
|
+
function parseOptionalBool(raw) {
|
|
88
|
+
if (typeof raw === 'boolean') return raw;
|
|
89
|
+
if (typeof raw !== 'string' || raw.trim() === '') return undefined;
|
|
90
|
+
const value = raw.trim().toLowerCase();
|
|
91
|
+
if (['true', '1', 'yes', 'on'].includes(value)) return true;
|
|
92
|
+
if (['false', '0', 'no', 'off'].includes(value)) return false;
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
80
96
|
export class ConfigLoader {
|
|
81
97
|
constructor() {
|
|
82
98
|
/** @type {Map<string, ServerConfig>} */
|
|
83
99
|
this.servers = new Map();
|
|
84
100
|
/** @type {string|null} */
|
|
85
101
|
this.configSource = null;
|
|
102
|
+
/** @type {string|null} The .env actually read, once one has been. */
|
|
103
|
+
this.envPath = null;
|
|
86
104
|
}
|
|
87
105
|
|
|
88
106
|
/**
|
|
@@ -94,14 +112,17 @@ export class ConfigLoader {
|
|
|
94
112
|
* @returns {Promise<Map<string, ServerConfig>>}
|
|
95
113
|
*/
|
|
96
114
|
async load(options = {}) {
|
|
115
|
+
const defaults = resolveConfigOptions(options.envPath);
|
|
97
116
|
const {
|
|
98
|
-
envPath =
|
|
99
|
-
tomlPath =
|
|
100
|
-
preferToml =
|
|
117
|
+
envPath = defaults.envPath,
|
|
118
|
+
tomlPath = defaults.tomlPath,
|
|
119
|
+
preferToml = defaults.preferToml
|
|
101
120
|
} = options;
|
|
102
121
|
|
|
103
122
|
// Clear existing servers
|
|
104
123
|
this.servers.clear();
|
|
124
|
+
this.envPath = null;
|
|
125
|
+
this.configSource = null;
|
|
105
126
|
|
|
106
127
|
// Load in reverse priority order (lowest to highest)
|
|
107
128
|
let loadedFromToml = false;
|
|
@@ -122,6 +143,9 @@ export class ConfigLoader {
|
|
|
122
143
|
if (!preferToml && fs.existsSync(envPath)) {
|
|
123
144
|
try {
|
|
124
145
|
this.loadEnvConfig(envPath);
|
|
146
|
+
// Kept so callers can name the file they are talking about — the
|
|
147
|
+
// control plane tells the operator which .env it found.
|
|
148
|
+
this.envPath = envPath;
|
|
125
149
|
loadedFromEnv = true;
|
|
126
150
|
logger.info(`Loaded SSH configuration from .env: ${envPath}`);
|
|
127
151
|
} catch (error) {
|
|
@@ -129,11 +153,49 @@ export class ConfigLoader {
|
|
|
129
153
|
}
|
|
130
154
|
}
|
|
131
155
|
|
|
156
|
+
// Load the encrypted vault (v4). It sits above the files and below the
|
|
157
|
+
// process environment: a credential the user deliberately stored in the
|
|
158
|
+
// vault should win over one left in a .env, but an operator overriding
|
|
159
|
+
// things from the environment for one run must still win over both.
|
|
160
|
+
// Absent vault → this is a no-op, and behaviour is exactly as before.
|
|
161
|
+
let loadedFromVault = false;
|
|
162
|
+
const vaultPath = options.vaultPath === null ? null : options.vaultPath || defaultVaultPath();
|
|
163
|
+
const store = new SecretStore(vaultPath || defaultVaultPath());
|
|
164
|
+
if (vaultPath && store.exists()) {
|
|
165
|
+
try {
|
|
166
|
+
const vaultServers = store.getAllDecrypted();
|
|
167
|
+
for (const [name, config] of Object.entries(vaultServers)) {
|
|
168
|
+
const existing = this.servers.get(name);
|
|
169
|
+
this.servers.set(name, { ...(existing || {}), ...config, name });
|
|
170
|
+
}
|
|
171
|
+
loadedFromVault = Object.keys(vaultServers).length > 0;
|
|
172
|
+
if (loadedFromVault) {
|
|
173
|
+
logger.info(`Loaded ${Object.keys(vaultServers).length} server(s) from the encrypted vault`);
|
|
174
|
+
}
|
|
175
|
+
} catch (error) {
|
|
176
|
+
// Once adopted, the vault owns security settings as well as secrets.
|
|
177
|
+
// Falling back to files could silently remove approval or policy rules.
|
|
178
|
+
// The control plane can still start independently to restore the vault.
|
|
179
|
+
logger.error(`Failed to read the vault at ${vaultPath}`, { error: error.message });
|
|
180
|
+
this.servers.clear();
|
|
181
|
+
throw Object.assign(new Error(
|
|
182
|
+
`The encrypted vault at ${vaultPath} cannot be read. SSH operations are blocked to preserve its security settings. `
|
|
183
|
+
+ 'Run ssh-manager control and restore a recovery file in Options > Vault, '
|
|
184
|
+
+ 'or run ssh-manager vault restore <file>. '
|
|
185
|
+
+ `Cause: ${error.message}`
|
|
186
|
+
), { code: 'VAULT_UNREADABLE' });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
132
190
|
// Load from environment variables (highest priority, overwrites everything)
|
|
133
191
|
this.loadEnvironmentVariables();
|
|
134
192
|
|
|
193
|
+
this.#rejectFileApproval();
|
|
194
|
+
|
|
135
195
|
// Determine primary config source
|
|
136
|
-
if (
|
|
196
|
+
if (loadedFromVault) {
|
|
197
|
+
this.configSource = 'vault';
|
|
198
|
+
} else if (loadedFromEnv) {
|
|
137
199
|
this.configSource = 'env';
|
|
138
200
|
} else if (loadedFromToml) {
|
|
139
201
|
this.configSource = 'toml';
|
|
@@ -147,6 +209,30 @@ export class ConfigLoader {
|
|
|
147
209
|
return this.servers;
|
|
148
210
|
}
|
|
149
211
|
|
|
212
|
+
/**
|
|
213
|
+
* Tell anyone who set approval in a file that it no longer does anything.
|
|
214
|
+
*
|
|
215
|
+
* Silently ignoring it would be the worst outcome available: they would
|
|
216
|
+
* believe an agent stops and waits for them on that server, and it would not.
|
|
217
|
+
* Better to say so on every start until they move it.
|
|
218
|
+
*/
|
|
219
|
+
#rejectFileApproval() {
|
|
220
|
+
const named = new Set();
|
|
221
|
+
for (const key of Object.keys(process.env)) {
|
|
222
|
+
const match = key.match(/^SSH_SERVER_(.+)_APPROVAL$/);
|
|
223
|
+
if (match) named.add(match[1].toLowerCase());
|
|
224
|
+
}
|
|
225
|
+
if (process.env.SSH_MANAGER_APPROVAL) named.add('(all servers)');
|
|
226
|
+
if (named.size === 0) return;
|
|
227
|
+
logger.warn(
|
|
228
|
+
'Approval can no longer be set from a file or the environment, and these '
|
|
229
|
+
+ 'settings are being ignored. Set it in the control plane instead: '
|
|
230
|
+
+ '`ssh-manager control`, then the server\'s Approval field. It moved so '
|
|
231
|
+
+ 'that a shell on one of your machines cannot turn off the gate that '
|
|
232
|
+
+ 'exists to stop it.',
|
|
233
|
+
{ ignored: [...named] });
|
|
234
|
+
}
|
|
235
|
+
|
|
150
236
|
/**
|
|
151
237
|
* Load configuration from TOML file
|
|
152
238
|
*/
|
|
@@ -190,7 +276,10 @@ export class ConfigLoader {
|
|
|
190
276
|
proxyJump: serverConfig.proxy_jump,
|
|
191
277
|
proxyCommand: serverConfig.proxy_command || serverConfig.proxycommand,
|
|
192
278
|
forwardAgent: parseBool(serverConfig.forward_agent),
|
|
279
|
+
announceAgent: parseOptionalBool(serverConfig.announce_agent),
|
|
193
280
|
mode,
|
|
281
|
+
// approval is deliberately NOT read here — see loadEnvConfig below.
|
|
282
|
+
|
|
194
283
|
allowPatterns: tomlAllow,
|
|
195
284
|
denyPatterns: tomlDeny,
|
|
196
285
|
auditLog: serverConfig.audit_log,
|
|
@@ -264,13 +353,31 @@ export class ConfigLoader {
|
|
|
264
353
|
proxyJump: env[`SSH_SERVER_${match[1]}_PROXYJUMP`],
|
|
265
354
|
proxyCommand: env[`SSH_SERVER_${match[1]}_PROXYCOMMAND`],
|
|
266
355
|
forwardAgent: parseBool(env[`SSH_SERVER_${match[1]}_FORWARD_AGENT`]),
|
|
356
|
+
announceAgent: parseOptionalBool(env[`SSH_SERVER_${match[1]}_ANNOUNCE_AGENT`]),
|
|
267
357
|
mode,
|
|
358
|
+
// approval is deliberately NOT read from files. It is the switch
|
|
359
|
+
// that makes an agent stop and wait for a human, and a switch that
|
|
360
|
+
// lives in a plain-text file next to the code is a switch the agent
|
|
361
|
+
// can flip on its own: one `sed -i` in .env and the gate it was meant
|
|
362
|
+
// to pass is gone. It lives in the vault instead, and the control
|
|
363
|
+
// plane is the only thing that writes it — a deliberate act by the
|
|
364
|
+
// person the gate exists to protect.
|
|
365
|
+
//
|
|
366
|
+
// This is defence in depth, not a wall: the vault key sits in the
|
|
367
|
+
// same user's keychain, so the same shell can in principle reach it.
|
|
368
|
+
// What it removes is the trivial path, which is the one that gets
|
|
369
|
+
// taken. See rejectFileApproval() for what happens to an old setting.
|
|
268
370
|
allowPatterns: envAllow,
|
|
269
371
|
denyPatterns: envDeny,
|
|
270
372
|
auditLog: env[`SSH_SERVER_${match[1]}_AUDIT_LOG`],
|
|
271
373
|
source: 'env'
|
|
272
374
|
};
|
|
273
375
|
|
|
376
|
+
// The environment keeps its published precedence for connection fields,
|
|
377
|
+
// but it cannot switch off a gate that is controlled only by the vault.
|
|
378
|
+
const approval = this.servers.get(serverName)?.approval;
|
|
379
|
+
if (approval !== undefined) server.approval = approval;
|
|
380
|
+
|
|
274
381
|
this.servers.set(serverName, server);
|
|
275
382
|
processedServers.add(serverName);
|
|
276
383
|
}
|
|
@@ -331,6 +438,9 @@ export class ConfigLoader {
|
|
|
331
438
|
if (server.proxyCommand) serverConfig.proxy_command = server.proxyCommand;
|
|
332
439
|
// Only emit when opted in, so generated TOML stays clean by default.
|
|
333
440
|
if (server.forwardAgent) serverConfig.forward_agent = true;
|
|
441
|
+
// Either explicit value is a decision worth keeping; unset is not written,
|
|
442
|
+
// so the global switch still applies after a round trip.
|
|
443
|
+
if (typeof server.announceAgent === 'boolean') serverConfig.announce_agent = server.announceAgent;
|
|
334
444
|
// Only emit security fields if they diverge from defaults — keeps generated
|
|
335
445
|
// TOML files clean for users who never opted in.
|
|
336
446
|
if (server.mode && server.mode !== 'unrestricted') serverConfig.mode = server.mode;
|
|
@@ -373,6 +483,9 @@ export class ConfigLoader {
|
|
|
373
483
|
// truncated at the first ` #` when the generated file is read back.
|
|
374
484
|
if (server.group) lines.push(`SSH_SERVER_${upperName}_GROUP="${server.group}"`);
|
|
375
485
|
if (server.platform) lines.push(`SSH_SERVER_${upperName}_PLATFORM=${server.platform}`);
|
|
486
|
+
// Written whenever it was set, true or false: an explicit false has to
|
|
487
|
+
// survive a round trip, or a global switch would re-enable that host.
|
|
488
|
+
if (typeof server.announceAgent === 'boolean') lines.push(`SSH_SERVER_${upperName}_ANNOUNCE_AGENT=${server.announceAgent}`);
|
|
376
489
|
if (server.proxyJump) lines.push(`SSH_SERVER_${upperName}_PROXYJUMP=${server.proxyJump}`);
|
|
377
490
|
if (server.proxyCommand) lines.push(`SSH_SERVER_${upperName}_PROXYCOMMAND=${server.proxyCommand}`);
|
|
378
491
|
// Security fields — only emit when non-default to avoid clutter in
|
|
@@ -386,6 +499,8 @@ export class ConfigLoader {
|
|
|
386
499
|
if (server.denyPatterns && server.denyPatterns.length > 0) {
|
|
387
500
|
lines.push(`SSH_SERVER_${upperName}_DENY_PATTERNS="${server.denyPatterns.join(';')}"`);
|
|
388
501
|
}
|
|
502
|
+
// Not exported: writing APPROVAL into a .env would produce a file that
|
|
503
|
+
// looks like it configures approval and silently does not.
|
|
389
504
|
if (server.auditLog) lines.push(`SSH_SERVER_${upperName}_AUDIT_LOG=${server.auditLog}`);
|
|
390
505
|
lines.push('');
|
|
391
506
|
}
|
package/src/config-paths.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
1
2
|
import os from 'os';
|
|
2
3
|
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import dotenv from 'dotenv';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* The directory that holds this user's settings and state: SSH_MANAGER_HOME,
|
|
@@ -10,3 +13,101 @@ import path from 'path';
|
|
|
10
13
|
export function managerHome() {
|
|
11
14
|
return process.env.SSH_MANAGER_HOME || path.join(os.homedir(), '.ssh-manager');
|
|
12
15
|
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Expand a leading `~` (alone or followed by a separator) to the home
|
|
19
|
+
* directory, as a shell would. `keyPath.replace('~', home)` replaced the first
|
|
20
|
+
* tilde anywhere, so `/srv/keys/~old/id` and `~user/id` came out wrong
|
|
21
|
+
* (issue #89). Any other path is returned as written.
|
|
22
|
+
* @param {string} value
|
|
23
|
+
* @returns {string}
|
|
24
|
+
*/
|
|
25
|
+
export function expandHomePath(value) {
|
|
26
|
+
const text = String(value);
|
|
27
|
+
if (text === '~') return os.homedir();
|
|
28
|
+
if (text.startsWith('~/') || (path.sep === '\\' && text.startsWith('~\\'))) {
|
|
29
|
+
return path.join(os.homedir(), text.slice(2));
|
|
30
|
+
}
|
|
31
|
+
return text;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Which .env the engine reads, and why.
|
|
36
|
+
*
|
|
37
|
+
* The same .env must be used by the MCP engine, CLI and optional control plane.
|
|
38
|
+
* Keep the published engine's discovery order; SSH_MANAGER_ENV is the CLI's
|
|
39
|
+
* existing explicit override and is accepted when SSH_ENV_PATH is absent.
|
|
40
|
+
*
|
|
41
|
+
* 3.8.5's engine never read SSH_MANAGER_ENV (only the CLI did), so a profile
|
|
42
|
+
* that still exported it towards a file since deleted cost nothing until 4.0
|
|
43
|
+
* honoured it, and then loaded zero servers without a word (issue #90). A
|
|
44
|
+
* missing file named by SSH_MANAGER_ENV is therefore skipped, as 3.8.5 skipped
|
|
45
|
+
* the variable, and reported in `ignored`. SSH_ENV_PATH was always the
|
|
46
|
+
* engine's own override: a missing file there stays the choice, reported as
|
|
47
|
+
* `missing`, so nothing is silently read in place of what was asked for.
|
|
48
|
+
* @param {{ projectRoot?: string }} [options]
|
|
49
|
+
* @returns {{path: string, variable: string|null, missing: boolean,
|
|
50
|
+
* ignored: {variable: string, path: string}|null}}
|
|
51
|
+
*/
|
|
52
|
+
export function envFileChoice({
|
|
53
|
+
projectRoot = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
|
|
54
|
+
} = {}) {
|
|
55
|
+
if (process.env.SSH_ENV_PATH) {
|
|
56
|
+
const file = process.env.SSH_ENV_PATH;
|
|
57
|
+
return { path: file, variable: 'SSH_ENV_PATH', missing: !fs.existsSync(file), ignored: null };
|
|
58
|
+
}
|
|
59
|
+
let ignored = null;
|
|
60
|
+
if (process.env.SSH_MANAGER_ENV) {
|
|
61
|
+
const file = process.env.SSH_MANAGER_ENV;
|
|
62
|
+
if (fs.existsSync(file)) return { path: file, variable: 'SSH_MANAGER_ENV', missing: false, ignored: null };
|
|
63
|
+
ignored = { variable: 'SSH_MANAGER_ENV', path: file };
|
|
64
|
+
}
|
|
65
|
+
const candidates = [
|
|
66
|
+
path.join(managerHome(), '.env'),
|
|
67
|
+
path.join(process.cwd(), '.env'),
|
|
68
|
+
path.join(os.homedir(), '.env'),
|
|
69
|
+
path.join(projectRoot, '.env'),
|
|
70
|
+
];
|
|
71
|
+
const found = candidates.find(candidate => fs.existsSync(candidate));
|
|
72
|
+
// No file at all is a valid setup (servers from the environment or TOML).
|
|
73
|
+
return { path: found || path.join(process.cwd(), '.env'), variable: null, missing: false, ignored };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The .env path alone; see envFileChoice for the rules.
|
|
78
|
+
* @param {{ projectRoot?: string }} [options]
|
|
79
|
+
* @returns {string}
|
|
80
|
+
*/
|
|
81
|
+
export function resolveEnvFilePath(options) {
|
|
82
|
+
return envFileChoice(options).path;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A sentence for the operator when the configuration file was not what the
|
|
87
|
+
* environment asked for, or null when it was.
|
|
88
|
+
* @param {ReturnType<typeof envFileChoice>} choice
|
|
89
|
+
* @returns {string|null}
|
|
90
|
+
*/
|
|
91
|
+
export function envFileProblem(choice) {
|
|
92
|
+
if (choice.missing) {
|
|
93
|
+
return `${choice.variable} names ${choice.path}, which does not exist: no server is loaded from a .env file`;
|
|
94
|
+
}
|
|
95
|
+
if (choice.ignored) {
|
|
96
|
+
return `${choice.ignored.variable} names ${choice.ignored.path}, which does not exist; using ${choice.path} instead`;
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Read file-selected TOML settings just as the MCP entry point does.
|
|
102
|
+
* @param {string} [envPath]
|
|
103
|
+
*/
|
|
104
|
+
export function resolveConfigOptions(envPath = resolveEnvFilePath()) {
|
|
105
|
+
let values = {};
|
|
106
|
+
try { values = dotenv.parse(fs.readFileSync(envPath)); } catch { /* The loader reports unreadable files. */ }
|
|
107
|
+
return {
|
|
108
|
+
envPath,
|
|
109
|
+
tomlPath: process.env.SSH_CONFIG_PATH ?? values.SSH_CONFIG_PATH
|
|
110
|
+
?? path.join(os.homedir(), '.codex', 'ssh-config.toml'),
|
|
111
|
+
preferToml: (process.env.PREFER_TOML_CONFIG ?? values.PREFER_TOML_CONFIG) === 'true',
|
|
112
|
+
};
|
|
113
|
+
}
|