.agents/skills/lib-replacement/SKILL.md
Use when auditing codebase for custom implementations that can be replaced with well-known libraries. Provides replacement patterns, audit checklist, and migration strategies.
npx skillsauth add tacogips/codex-agent lib-replacementInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill provides guidelines for finding redundant custom implementations and replacing them with well-known libraries.
Identify custom implementations that:
Apply this skill when:
| Category | Custom Implementation Signs | Recommended Libraries |
|----------|----------------------------|----------------------|
| Result/Error Handling | Custom Result type, ok/err pattern | neverthrow, ts-results, effect |
| Validation | Custom validate functions, manual checks | zod, valibot, arktype |
| Date/Time | Custom date parsing/formatting | date-fns, dayjs, luxon |
| Path Operations | Custom path manipulation | pathe, upath (cross-platform) |
| CLI Parsing | Custom argument parsing | commander, yargs, citty |
| Configuration | Custom config loading | c12, cosmiconfig, rc9 |
| Logging | Custom logger implementations | pino, consola, winston |
| HTTP Client | Custom fetch wrappers | ofetch, ky, got |
| Retry Logic | Custom retry loops | p-retry, async-retry |
| Debounce/Throttle | Custom implementations | lodash-es (specific imports), perfect-debounce |
| Deep Clone/Merge | Custom recursive functions | klona, defu, deepmerge-ts |
| Type Guards | Repetitive type checks | typeguard, ts-is |
| UUID/ID Generation | Custom ID generators | nanoid, ulid, uuid |
| Hashing | Custom hash implementations | ohash, hash-sum |
| File Watching | Custom fs.watch wrappers | chokidar, watchlist |
| Glob Patterns | Custom glob matching | tinyglobby, fast-glob, picomatch |
| JSON Parsing | Custom streaming JSON | @streamparser/json, stream-json |
| JSONL/NDJSON | Custom line-by-line parsing | ndjson, jsonlines |
| String Utils | Custom case conversion, trim | scule, change-case |
| Async Utilities | Custom promise helpers | p-* packages (p-limit, p-map, p-queue) |
| Schema Generation | Custom type-to-schema | typebox, zod-to-json-schema |
| Diff/Patch | Custom diff algorithms | diff, fast-diff, json-diff |
| Template Strings | Custom template parsing | handlebars, mustache, eta |
| Caching | Custom cache implementations | lru-cache, quick-lru, keyv |
| Rate Limiting | Custom rate limiters | p-throttle, limiter, bottleneck |
Bun provides built-in alternatives for some patterns:
| Pattern | Bun Built-in | External Library |
|---------|--------------|------------------|
| Glob | Bun.glob() | Not needed |
| File I/O | Bun.file(), Bun.write() | Not needed |
| Hashing | Bun.hash(), Bun.CryptoHasher | Not needed |
| SQLite | bun:sqlite | Not needed |
| Test Runner | bun:test | Not needed |
| Shell Commands | Bun.spawn(), Bun.$ | Not needed |
When auditing code, look for:
// RED FLAG: Custom implementations of common utilities
function deepClone(obj) { ... }
function debounce(fn, delay) { ... }
function retry(fn, maxAttempts) { ... }
function generateId() { return Math.random()... }
// RED FLAG: Custom Result type
type Result<T, E> = { ok: true; value: T } | { ok: false; error: E };
// BETTER: Use neverthrow
import { Result, ok, err } from 'neverthrow';
// RED FLAG: Manual validation
function validateEmail(email: string): boolean {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}
// BETTER: Use zod
const emailSchema = z.string().email();
// RED FLAG: Custom date formatting
function formatDate(date: Date): string {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
...
}
// BETTER: Use date-fns
import { format } from 'date-fns';
format(date, 'yyyy-MM-dd');
// RED FLAG: Custom promise utilities
async function promisePool(tasks, concurrency) { ... }
async function withTimeout(promise, ms) { ... }
// BETTER: Use p-* packages
import pLimit from 'p-limit';
import pTimeout from 'p-timeout';
For each replacement:
Parallelizable replacements (no shared dependencies):
Sequential replacements (shared dependencies):
generateId() -> nanoid()development
Use when writing, reviewing, or refactoring TypeScript code. Provides type safety patterns, error handling, project layout, and async programming guidelines.
development
Use when refactoring tests for better maintainability. Provides guidelines for removing duplicates, DRYing fixtures/assertions, restructuring test organization, renaming, and splitting oversized files.
testing
Use when creating test plans from implementation and design documents. Provides test plan structure, test case tracking, and coverage guidelines.
development
Use when creating, publishing, or maintaining npm packages with Bun. Provides Shai-Hulud supply chain attack countermeasures including npm token management, 2FA enforcement, provenance signing, trusted publishing via GitHub Actions, and pre-publish security checklists.