diff --git a/src/hooks/non-interactive-env/constants.ts b/src/hooks/non-interactive-env/constants.ts index d9a5937..2636802 100644 --- a/src/hooks/non-interactive-env/constants.ts +++ b/src/hooks/non-interactive-env/constants.ts @@ -14,4 +14,56 @@ export const NON_INTERACTIVE_ENV: Record = { // Block pagers GIT_PAGER: "cat", PAGER: "cat", + // NPM non-interactive + npm_config_yes: "true", + // Pip non-interactive + PIP_NO_INPUT: "1", + // Yarn non-interactive + YARN_ENABLE_IMMUTABLE_INSTALLS: "false", } + +/** + * Shell command guidance for non-interactive environments. + * These patterns should be followed to avoid hanging on user input. + */ +export const SHELL_COMMAND_PATTERNS = { + // Package managers - always use non-interactive flags + npm: { + bad: ["npm init", "npm install (prompts)"], + good: ["npm init -y", "npm install --yes"], + }, + apt: { + bad: ["apt-get install pkg"], + good: ["apt-get install -y pkg", "DEBIAN_FRONTEND=noninteractive apt-get install pkg"], + }, + pip: { + bad: ["pip install pkg (with prompts)"], + good: ["pip install --no-input pkg", "PIP_NO_INPUT=1 pip install pkg"], + }, + // Git operations - always provide messages/flags + git: { + bad: ["git commit", "git merge branch", "git add -p", "git rebase -i"], + good: ["git commit -m 'msg'", "git merge --no-edit branch", "git add .", "git rebase --no-edit"], + }, + // System commands - force flags + system: { + bad: ["rm file (prompts)", "cp a b (prompts)", "ssh host"], + good: ["rm -f file", "cp -f a b", "ssh -o BatchMode=yes host", "unzip -o file.zip"], + }, + // Banned commands - will always hang + banned: [ + "vim", "nano", "vi", "emacs", // Editors + "less", "more", "man", // Pagers + "python (REPL)", "node (REPL)", // REPLs without -c/-e + "git add -p", "git rebase -i", // Interactive git modes + ], + // Workarounds for scripts that require input + workarounds: { + yesPipe: "yes | ./script.sh", + heredoc: `./script.sh <