一键导入
extract-shared
Identify cross-project code duplication and generate candidates for a shared utility package.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Identify cross-project code duplication and generate candidates for a shared utility package.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Scan project, then generate or reconcile .primeignore patterns for smarter /prime loading
Run WCAG accessibility audits on frontend projects. Checks HTML semantics, ARIA usage, color contrast, and keyboard navigation patterns.
Generate OpenAPI specs from code, validate API contracts, and check for breaking changes between versions.
Backend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes.
Incrementally fix TypeScript and build errors one at a time with verification. Invokes the build-error-resolver agent.
Create or verify a checkpoint in your workflow
| name | extract-shared |
| description | Identify cross-project code duplication and generate candidates for a shared utility package. |
| argument-hint | [--scan|--report|--python|--node] |
Scan your projects for duplicated patterns and identify candidates for extraction into a shared utility package.
Decide what to scan, in this order:
~/projects), scan each immediate subdirectory.Parse $ARGUMENTS:
--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 projectsScan for these known duplication categories across the selected projects:
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>
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>
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
# 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>
# 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>
grep -rn "Fernet\|encrypt\|decrypt\|hashlib\|bcrypt" --include="*.py" <path>
grep -rn "crypto\|encrypt\|decrypt\|hash" --include="*.ts" --include="*.js" <path>
grep -rn "record_audit\|audit_log\|log_action\|telemetry" --include="*.py" <path>
grep -rn "healthcheck\|HEALTHCHECK" <path>/docker-compose*.yml <path>/Dockerfile 2>/dev/null
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:
For patterns found in 2+ projects, read the actual implementation files and compare:
## 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