agentleFS
PatriotAgenticLLCPatriotAgenticLLC/better_claude_skillz/skills/extract-shared/SKILL.md

extract-shared

Skill3 starsChanged 5 months agoMITView on GitHub

Identify cross-project code duplication and generate candidates for a shared utility package.

  • Reads credentials

The file

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 9 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    No arguments or --scan: Run full scan and report (default)

    line 23
  2. Very specific:

    --python: Only scan Python projects

    line 25
  3. Very specific:

    --node: Only scan Node.js projects

    line 26
  4. Distinctive:

    Search for health endpoint implementations:

    line 35
  5. Distinctive:

    Search for custom exception classes and error response patterns:

    line 47
  6. Distinctive:

    Search for config loading patterns:

    line 58
  7. Distinctive:

    Read the relevant function/class from each project

    line 118
  8. Distinctive:

    If a project path doesn't exist, skip it

    line 210
  9. Distinctive:

    If grep finds no matches in a category, report "No instances found"

    line 211
  10. Distinctive:

    Never modify any project files — this is analysis only

    line 213
  11. Distinctive:

    Use the report to plan extraction work in a follow-up session

    line 218
  12. Distinctive:

    Run this quarterly or before starting a new project

    line 222

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Shared Utilities Extractor

Scan your projects for duplicated patterns and identify candidates for extraction into a shared utility package.

Selecting Projects to Scan

Decide what to scan, in this order:

  1. Paths passed as arguments — scan exactly those project directories.
  2. A workspace root — if you keep several projects under one directory (e.g. ~/projects), scan each immediate subdirectory.
  3. The current directory — if neither applies, this skill needs at least two projects to compare; ask the user to point it at a workspace root or a set of paths.

Arguments

Parse $ARGUMENTS:

  • No arguments or --scan: Run full scan and report (default)
  • --report: Show results from last scan without re-scanning
  • --python: Only scan Python projects
  • --node: Only scan Node.js projects

Process

Step 1: Define Search Patterns

Scan for these known duplication categories across the selected projects:

Category 1: Health Check Endpoints

Search for health endpoint implementations:

# Python
grep -rn "def health" --include="*.py" <path>
grep -rn "/health" --include="*.py" <path>

# Node/TypeScript
grep -rn "'/health'" --include="*.ts" --include="*.js" <path>
grep -rn "\"/health\"" --include="*.ts" --include="*.js" <path>

Category 2: Error Response Formats

Search for custom exception classes and error response patterns:

# Python
grep -rn "class.*Error.*Exception" --include="*.py" <path>
grep -rn "class.*APIError\|class.*AppError\|class.*ServiceError" --include="*.py" <path>

# Node/TypeScript
grep -rn "class.*Error extends" --include="*.ts" --include="*.js" <path>

Category 3: Configuration / Settings Patterns

Search for config loading patterns:

# Python
grep -rn "os.environ\|os.getenv\|environ.get" --include="*.py" <path> | head -10
grep -rn "class.*Config\|class.*Settings" --include="*.py" <path>

# Node/TypeScript
grep -rn "process.env" --include="*.ts" --include="*.js" <path> | head -10

Category 4: Authentication / Rate Limiting

# Python
grep -rn "rate.limit\|RateLimiter\|throttle" --include="*.py" <path>
grep -rn "auth.*decorator\|login_required\|verify_token" --include="*.py" <path>

# Node/TypeScript
grep -rn "rateLimit\|rate-limit" --include="*.ts" --include="*.js" <path>
grep -rn "authenticate\|verifyToken\|authMiddleware" --include="*.ts" --include="*.js" <path>

Category 5: Database Utilities

# Python
grep -rn "def get_db\|def create_tables\|def run_migration" --include="*.py" <path>
grep -rn "session.execute\|session.commit" --include="*.py" <path> | head -5

# Node/TypeScript
grep -rn "getConnection\|createPool\|query(" --include="*.ts" --include="*.js" <path>

Category 6: Encryption / Secrets Helpers

grep -rn "Fernet\|encrypt\|decrypt\|hashlib\|bcrypt" --include="*.py" <path>
grep -rn "crypto\|encrypt\|decrypt\|hash" --include="*.ts" --include="*.js" <path>

Category 7: Audit Logging

grep -rn "record_audit\|audit_log\|log_action\|telemetry" --include="*.py" <path>

Category 8: Docker Health Checks

grep -rn "healthcheck\|HEALTHCHECK" <path>/docker-compose*.yml <path>/Dockerfile 2>/dev/null

Step 2: Collect and Compare

For each category, collect the implementations found across projects. Use the Grep tool for each pattern across each project directory.

Group results by category and compare:

  • How many projects implement this pattern?
  • Are the implementations similar enough to share?
  • What's the effort to extract vs. keep separate?

Step 3: Analyze Similarity

For patterns found in 2+ projects, read the actual implementation files and compare:

  1. Read the relevant function/class from each project
  2. Assess similarity (identical, similar with minor differences, fundamentally different)
  3. Rate extraction feasibility: Easy (copy-paste), Medium (needs abstraction), Hard (too different)

Step 4: Report

## Cross-Project Duplication Report

### High-Value Extraction Candidates (found in 3+ projects)

#### 1. Health Check Endpoints
- **Projects:** api-service, web-app, dashboard, platform
- **Pattern:** GET /health returning {status: "healthy", service: "<name>"}
- **Similarity:** High — nearly identical implementations
- **Extraction effort:** Easy
- **Recommendation:** Create shared `health_check()` factory function

#### 2. Error Response Formats
- **Projects:** api-service, web-app
- **Pattern:** Custom exception classes with JSON error responses
- **Similarity:** Medium — same structure, different exception types
- **Extraction effort:** Medium
- **Recommendation:** Create shared base error classes with JSON serialization

### Medium-Value Candidates (found in 2 projects)

#### 3. Encryption Utilities
- **Projects:** api-service (Fernet), web-app (potential)
- **Similarity:** Low — only one project has it currently
- **Extraction effort:** Easy
- **Recommendation:** Extract if second project needs it

...

### Not Worth Extracting (domain-specific)

- Business-logic parsers unique to a single project
- Third-party integration sync code used by only one project
- Bespoke handlers unique to one product

### Proposed Shared Package Structure

If extracting a Python shared package (`shared-common`):

shared-common/ ├── pyproject.toml ├── shared_common/ │ ├── init.py │ ├── health.py # Health check endpoint factory │ ├── errors.py # Base error classes │ ├── config.py # Configuration loader │ ├── auth.py # Auth decorators │ ├── audit.py # Audit logging │ └── encryption.py # Encryption helpers └── tests/ └── ...


If extracting a Node shared package (`@yourorg/common`):

shared-common-node/ ├── package.json ├── src/ │ ├── health.ts │ ├── errors.ts │ ├── config.ts │ └── auth.ts └── tests/ └── ...


### Summary

| Category | Projects | Similarity | Effort | Priority |
|----------|----------|-----------|--------|----------|
| Health checks | 4 | High | Easy | HIGH |
| Error formats | 2 | Medium | Medium | MEDIUM |
| Config loading | 4 | Medium | Medium | MEDIUM |
| Rate limiting | 2 | Low | Medium | LOW |
| Encryption | 1+ | N/A | Easy | LOW |
| Audit logging | 2 | Medium | Medium | MEDIUM |
| Docker health | 3 | High | Easy | HIGH |

Total duplication categories: X
Worth extracting now: Y
Worth extracting later: Z
Domain-specific (keep separate): W

Error Handling

  • If a project path doesn't exist, skip it
  • If grep finds no matches in a category, report "No instances found"
  • Large result sets: limit to first 10 matches per project per category
  • Never modify any project files — this is analysis only

Notes

  • This skill is read-only — it identifies duplication but does not extract or create packages
  • Use the report to plan extraction work in a follow-up session
  • Focus on patterns that appear in 3+ projects for highest ROI
  • Domain-specific code (single-project business logic, one-off integrations) should stay in its project
  • The proposed package structure is a recommendation — adjust based on actual findings
  • Run this quarterly or before starting a new project

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.