From 5fe2f8795e623be94b67e0ea1a302b04bc661a81 Mon Sep 17 00:00:00 2001 From: Harivansh Rathi Date: Sat, 3 Jan 2026 03:59:39 +0530 Subject: [PATCH] skill updates --- commands/simplify.md | 84 ++++++++++++++++++++++++++++++++++ install.sh | 62 +++++++++++++------------ skills/codebase-agent/SKILL.md | 36 +++++++++++++++ 3 files changed, 154 insertions(+), 28 deletions(-) create mode 100644 commands/simplify.md diff --git a/commands/simplify.md b/commands/simplify.md new file mode 100644 index 0000000..92425d8 --- /dev/null +++ b/commands/simplify.md @@ -0,0 +1,84 @@ +--- +description: Simplify overly complex code while preserving full functionality +allowed-tools: Read, Edit, Bash(git diff:*), Bash(git status:*), Grep, Glob +argument-hint: [staged|unstaged|both] +--- + +# Simplify Implementation + +You are reviewing code you just wrote to simplify it. Claude has a tendency to over-engineer. Your job is to ruthlessly simplify while preserving full functionality. + +## Context + +Current git status: !`git status --short` + +### Changes to Review + +Based on the argument provided ($ARGUMENTS), review the appropriate diff: + +- **staged** (or no argument): Review staged changes only +- **unstaged**: Review unstaged changes only +- **both**: Review all changes (staged and unstaged) + +Staged changes: !`git diff --cached` +Unstaged changes: !`git diff` + +## Simplification Principles + +### Remove Over-Engineering + +1. **Delete unnecessary abstractions**: If a function is called once, inline it +2. **Remove premature generalization**: Delete parameters, options, or config that aren't used +3. **Flatten unnecessary nesting**: Reduce indirection levels +4. **Kill dead code paths**: Remove conditionals that can't trigger +5. **Simplify error handling**: Don't catch errors you can't meaningfully handle +6. **Remove defensive coding against impossible states**: Trust internal code + +### Prefer Direct Solutions + +1. **Three lines > one abstraction**: Repeated simple code beats a premature helper +2. **Explicit > clever**: Readable beats compact +3. **Flat > nested**: Early returns, guard clauses +4. **Concrete > generic**: Solve the actual problem, not hypothetical ones +5. **Standard library > custom implementation**: Use built-ins when available + +### Preserve + +1. **All functionality**: The feature must work exactly as before +2. **Public interfaces**: Don't change signatures that external code depends on +3. **Test coverage**: Existing tests must still pass +4. **Actual error handling**: Keep meaningful error cases + +## Your Task + +1. **Analyze the diff**: Identify over-engineered patterns +2. **List simplifications**: For each issue, explain what's complex and how to simplify +3. **Apply changes**: Edit the files to simplify +4. **Verify**: Ensure functionality is preserved + +## Output Format + +For each simplification: +``` +FILE: path/to/file.ts + +ISSUE: [What's over-engineered] +BEFORE: [Brief description or code snippet] +AFTER: [Brief description or code snippet] +WHY: [Why this is simpler without losing functionality] +``` + +Then apply the edits. + +## Red Flags to Watch For + +- Functions with > 3 parameters (probably doing too much) +- Deeply nested callbacks or conditionals (flatten them) +- Abstract base classes with one implementation (delete the abstraction) +- Config objects for things that could be hardcoded +- Wrapper functions that just call another function +- Comments explaining what code does (code should be self-explanatory) +- Type definitions that duplicate structure (use inference) +- Utility functions used once (inline them) +- Try/catch that just re-throws or logs (let it bubble) +- Feature flags for features that are always on diff --git a/install.sh b/install.sh index 137e354..496d654 100755 --- a/install.sh +++ b/install.sh @@ -35,13 +35,7 @@ echo "" # Check if .claude directory exists if [ -d "$TARGET_DIR/.claude" ]; then - echo -e "${YELLOW}Warning: .claude directory already exists${NC}" - read -p "Continue and merge files? (y/n) " -n 1 -r - echo - if [[ ! $REPLY =~ ^[Yy]$ ]]; then - echo "Aborted." - exit 1 - fi + echo -e "${YELLOW}Note: .claude directory already exists - will add missing files only${NC}" fi # Create directory structure @@ -54,19 +48,28 @@ mkdir -p "$TARGET_DIR/.claude/hooks" echo "Copying files..." # Function to copy file from local or download from remote +# Only copies if destination doesn't exist (no overwrite) copy_file() { local src="$1" local dest="$2" + # Skip if destination already exists + if [ -f "$dest" ]; then + echo " Skipping $(basename "$dest") - already exists" + return 0 + fi + if [ -n "$SCRIPT_DIR" ] && [ -f "$SCRIPT_DIR/$src" ]; then # Local install cp "$SCRIPT_DIR/$src" "$dest" + echo " Added $(basename "$dest")" else # Remote install - download from GitHub if ! curl -fsSL "$REPO_RAW_URL/$src" -o "$dest"; then echo -e "${RED}Error: Failed to download $src${NC}" exit 1 fi + echo " Added $(basename "$dest")" fi } @@ -76,39 +79,42 @@ copy_file "commands/setup-agent.md" "$TARGET_DIR/.claude/commands/setup-agent.md copy_file "commands/retrospective.md" "$TARGET_DIR/.claude/commands/retrospective.md" copy_file "hooks/session-end.sh" "$TARGET_DIR/.claude/hooks/session-end.sh" -# Make hook executable -chmod +x "$TARGET_DIR/.claude/hooks/session-end.sh" +# Make hook executable (if it exists and was just copied) +if [ -f "$TARGET_DIR/.claude/hooks/session-end.sh" ]; then + chmod +x "$TARGET_DIR/.claude/hooks/session-end.sh" +fi -# Handle settings.json merge -echo "Configuring hooks..." +# Handle settings.json SETTINGS_FILE="$TARGET_DIR/.claude/settings.json" if [ -f "$SETTINGS_FILE" ]; then - # Merge with existing settings - echo -e "${YELLOW}Existing settings.json found. Please manually add the hook configuration:${NC}" - echo "" - cat << 'EOF' -Add to your .claude/settings.json: + # Check if SessionEnd hook is already configured + if grep -q "session-end.sh" "$SETTINGS_FILE" 2>/dev/null; then + echo " Skipping settings.json - SessionEnd hook already configured" + else + echo "" + echo -e "${YELLOW}Existing settings.json found. Please manually add the hook configuration:${NC}" + echo "" + cat << 'EOF' +Add to your .claude/settings.json hooks section: -{ - "hooks": { - "SessionEnd": [ +"SessionEnd": [ + { + "hooks": [ { - "hooks": [ - { - "type": "command", - "command": "\"$CLAUDE_PROJECT_DIR/.claude/hooks/session-end.sh\"", - "timeout": 60 - } - ] + "type": "command", + "command": "\"$CLAUDE_PROJECT_DIR/.claude/hooks/session-end.sh\"", + "timeout": 60 } ] } -} +] EOF - echo "" + echo "" + fi else # Create new settings.json + echo " Creating settings.json with SessionEnd hook" cat > "$SETTINGS_FILE" << 'EOF' { "hooks": { diff --git a/skills/codebase-agent/SKILL.md b/skills/codebase-agent/SKILL.md index f2f3994..e32f489 100644 --- a/skills/codebase-agent/SKILL.md +++ b/skills/codebase-agent/SKILL.md @@ -24,6 +24,42 @@ and leverage proven approaches. 3. **Follow conventions**: Adhere to project conventions discovered in learnings 4. **Note discoveries**: When you find something new (pattern, failure, edge case), mention it +## Code Simplicity + +**Default to the simplest solution that works.** Resist the urge to over-engineer. + +### Write Less Code + +- Solve the actual problem, not hypothetical future problems +- If a function is called once, consider inlining it +- Three similar lines are better than a premature abstraction +- Use standard library and built-ins before writing custom code +- Delete code paths that can't happen + +### Keep It Flat + +- Use early returns and guard clauses to reduce nesting +- Avoid callback pyramids - flatten with async/await or composition +- One level of abstraction per function + +### Avoid Premature Abstraction + +- Don't add parameters "in case we need them later" +- Don't create base classes until you have 2+ implementations +- Don't add config for things that could be hardcoded +- Don't create wrapper functions that just call another function + +### Trust Your Code + +- Don't defensively code against impossible internal states +- Don't catch errors you can't meaningfully handle +- Don't validate data that's already validated upstream +- Validate at system boundaries (user input, external APIs), trust internal code + +### When in Doubt + +Ask: "What's the least code that makes this work?" Write that first. Add complexity only when reality demands it. + ## Codebase Context