feat(cli): Preserve CLI environment when adding processes, simplify edit flow, and refresh README docs

This commit is contained in:
2025-08-30 15:11:38 +00:00
parent 2b57251f47
commit 699d07ea36
5 changed files with 368 additions and 198 deletions

View File

@@ -69,6 +69,33 @@ export function registerAddCommand(smartcli: plugins.smartcli.Smartcli) {
if (watchPaths) console.log(` Watch paths: ${watchPaths.join(',')}`);
}
// Capture essential environment variables from the CLI environment
// so processes have access to the same environment they were added with
const essentialEnvVars: NodeJS.ProcessEnv = {
PATH: process.env.PATH || '',
HOME: process.env.HOME,
USER: process.env.USER,
SHELL: process.env.SHELL,
LANG: process.env.LANG,
LC_ALL: process.env.LC_ALL,
// Node.js specific
NODE_ENV: process.env.NODE_ENV,
NODE_PATH: process.env.NODE_PATH,
// npm/pnpm/yarn paths
npm_config_prefix: process.env.npm_config_prefix,
// Include any TSPM_ prefixed vars
...Object.fromEntries(
Object.entries(process.env).filter(([key]) => key.startsWith('TSPM_'))
),
};
// Remove undefined values
Object.keys(essentialEnvVars).forEach(key => {
if (essentialEnvVars[key] === undefined) {
delete essentialEnvVars[key];
}
});
const response = await tspmIpcClient.request('add', {
config: {
name,
@@ -76,9 +103,7 @@ export function registerAddCommand(smartcli: plugins.smartcli.Smartcli) {
args: cmdArgs,
projectDir,
memoryLimitBytes: memoryLimit,
// Persist the PATH from the current CLI environment so managed
// processes see the same PATH they had when added.
env: { PATH: process.env.PATH || '' },
env: essentialEnvVars,
autorestart,
watch,
watchPaths,