Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
[{"skill":"refactoring-surgeon","reason":"General refactoring principles applied to scripts"},{"skill":"error-handling-patterns","reason":"Robust error handling is the primary script improvement"},{"skill":"beautiful-cli-design","reason":"Good CLI ergonomics for script interfaces"},{"skill":"devops-automator","reason":"Scripts often live inside CI/CD pipelines"}]
Script Refactorer
Modernizes legacy scripts into reliable, maintainable tools. Replaces deprecated patterns,
adds error handling and input validation, converts callback spaghetti to async/await,
and turns undocumented one-off hacks into proper CLI tools.
Activation Triggers
Use this skill when:
A bash/Node/Python script works but is fragile, undocumented, or hard to modify
Scripts use deprecated Node.js APIs (e.g., new Buffer(), url.parse(), fs.exists())
EOF
Usage: $(basename "$0") [OPTIONS]
Deploy the application from git with rollback safety.
Options:
--branch <branch> Branch to deploy (default: main)
--skip-build Skip npm install and build steps
--dry-run Show what would happen without doing it
-h, --help Show this help message
Environment:
APP_DIR Application directory (default: /opt/app)
PM2_APP_NAME PM2 process name (default: app)
EOF
exit
log
echo
"[$(date '+%H:%M:%S')] $*"
tee
"$LOG_FILE"
die
log
"FATAL: $*"
exit
parse_args
while
$#
do
case
"$1"
in
"${2:?--branch requires a value}"
shift
true
shift
true
shift
help
"Unknown option: $1"
esac
done
preflight_checks
command
"git is not installed"
command
"npm is not installed"
command
"pm2 is not installed"
"$APP_DIR/.git"
"$APP_DIR is not a git repository"
main
"$@"
local
"$APP_DIR"
log
"Current commit: ${prev_commit:0:8}"
log
"Deploying branch: $BRANCH"
if
$DRY_RUN
then
log
"DRY RUN — would deploy $BRANCH to $APP_DIR"
exit
fi
# Capture state for rollback
trap
'log "Deploy failed. Rolling back to ${prev_commit:0:8}"; git -C "$APP_DIR" checkout "$prev_commit" 2>/dev/null'
Convert: New Node.js projects, anything using type: "module" in package.json, libraries targeting modern consumers
Keep CJS: Scripts embedded in legacy build systems, anything that must require() conditionally, tools with no plans to publish as packages
Language-specific argument parsers
Language
Recommended
Why
Bash
Manual case loop or getopts
No dependencies, portable
Node.js
parseArgs (built-in since Node 18.3)
Zero dependencies
Python
argparse (stdlib)
Battle-tested, auto-generates help
Go
flag (stdlib) or cobra
Standard practice
Anti-Patterns
1. Gold-plating a throwaway script
Symptom: Adding full argument parsing, logging, and tests to a one-time data migration script
Fix: If the script runs once and is deleted, minimal error handling is enough. Save the polish for scripts that live in the repo.
2. Replacing bash with Node.js for file operations
Symptom: Rewriting cp, mv, find, grep in JavaScript
Fix: Shell is the right tool for file manipulation. Only move to Node.js when the logic (not the I/O) is complex.
3. Adding types without adding tests
Symptom: Converting a .js script to .ts and calling it "modernized"
Fix: Types catch shape errors. Tests catch logic errors. You need both.
4. Breaking the interface
Symptom: Renaming flags, changing exit codes, or altering output format during a refactor
Fix: Refactoring means behavior-preserving changes. If callers depend on the interface, maintain backward compatibility or coordinate the migration.
5. Ignoring the shebang
Symptom: #!/bin/bash on a script that uses bash 4+ features, deployed to macOS (bash 3.2)
Fix: Use #!/usr/bin/env bash and test on all target platforms. If you need bash 4+, document it.
6. Silent failures in pipelines
Symptom: cat file.txt | grep pattern | wc -l where file.txt doesn't exist and the script continues
Fix: set -o pipefail in bash. In Node.js, check process.exitCode after spawning child processes.
7. Mixing refactoring with feature additions
Symptom: "While I'm in here, let me also add support for..."
Fix: One commit for the refactor (behavior-preserving). A separate commit for new features. This keeps the refactor reviewable and revertable.
Quality Checklist
Script has a clear, documented purpose (comment header or --help)
All arguments are validated with usage errors on bad input