JavaScript Development
Modern JS; runtime-aware; semantics first; no cargo-cult sludge.
Activation Triggers
Use for .js, .mjs, .cjs; package.json when type, exports, imports, entrypoints, or ESM/CJS interop matter; jest.config.*, vitest.config.*, or Testing Library setup in JavaScript-first repos; import, export, require, type: module, exports, imports, or dynamic import(); Promises, async/await, task/microtask ordering, AbortController, fetch, streams, or workers; closures, this, coercion, prototypes, hoisting, TDZ, stale captures, or unexpected undefined; Node.js or browser behavior where JS semantics are central; JS-specific tests, mocking, fake timers, or async-test flakiness; legacy refactors where runtime behavior must remain unchanged.
Workflow
1. DETECT -> runtime, package manager, module mode, test runner, build tool
2. CLASSIFY -> semantics bug | async flow | module/interop | runtime API | tests | perf/refactor
3. MODEL -> data flow, mutation points, cancellation/error boundaries, public API
4. IMPLEMENT -> smallest safe change; prefer native APIs; keep module mode coherent
5. VALIDATE -> repo scripts first; then targeted tests/lint/build; no watch mode by default
6. HARDEN -> inspect leaks, circular deps, hot paths, retries/timeouts only where risk justifies
Core Rules
- Choose patterns from runtime + toolchain, not aesthetics.
- Inspect the nearest working implementation first; reuse an adequate helper, platform API, or installed dependency.
- Prefer const, local immutability, and pure transforms; mutate locally when simpler or measurably faster.
- Parse and normalize untrusted input at API, file, queue, CLI, or environment boundaries. Keep raw transport data, retries, logging, and process exits at I/O boundaries.
- Name distinct domain values clearly; represent meaningful outcomes explicitly. Do not hide state machines in truthy values or optional-field piles.
- Use
async/await for orchestration and Promise combinators for concurrency. Expose cancellation on long-lived or user-driven work.
- Before optimizing, check independent async loops for accidental serialization.
- Debug weird behavior from language semantics first: coercion, equality,
this, closures, prototype chain, task queues.
- Catch only to recover, translate, or add context; preserve original causes when wrapping; never silence failures.
- Keep one module story per package: module mode is a package-level contract before a file-level syntax choice.
- Prefer native platform features before dependencies.
- Add no dependency, abstraction, parser, normalization layer, or defensive branch without a concrete caller, boundary, or failure mode.
- Test at the right layer: pure transforms → unit; I/O boundaries → integration; UI behavior → Testing Library with user-observable queries.
- Mock external edges, not core logic. Prefer real values, in-memory fakes, or wire-level fakes when deterministic and isolated.
- Treat large files, parameter bundles, negative-name mazes, redundant post-action checks, and broad catches as review triggers, not automatic rewrites.
- Use
rg for repository discovery and ast-grep for structural search when cheaper.
- Use the existing repo runner. If none exists, choose the lowest-friction runner matching the toolchain; do not introduce a second stack.
- Do not cargo-cult coverage numbers; add tests where failure risk lives.
Expected Outputs
Match output to task size:
- small fix → root cause + minimal patch + targeted validation
- refactor → migration plan + coherent code changes + risk notes
- debugging → likely-cause ranking + repro/inspection steps + fix
- testing task → runner-aware tests with mocked external edges only
- module issue → explicit package/module decision and required file or
package.json changes
When to Use
- JS app, library, CLI, service, or automation
- async-flow design, cancellation, streams, or workers
- Node.js or browser APIs
- module,
package.json, or interop issues
- testing strategy or flaky JS tests
- performance debugging, legacy refactors, or weird runtime behavior
When Not to Use
.ts / .tsx type-system design central → also load typescript
- React / Next render or bundle work dominant → also load
react-best-practices
- Fresh external-library API docs more important than JS mechanics → load
research, then context7 or grep-app
Quick Start
- Detect runtime, package manager, module mode, runner, and build tool.
- Classify: semantics, async, modules/interop, runtime API, tests, or perf/refactor.
- Make the smallest coherent change for that runtime.
- Validate with repo scripts first; use targeted checks before broad suites.
- Read the smallest relevant file before improvising across module boundaries, async flow, or test architecture.
Defaults, validation order, and interop rules live in reference.md.
Required Follow-up Reads
| Need |
Read |
When |
Coercion, this, closures, prototypes |
cookbook/semantics.md |
Debugging language-semantics failures |
| Syntax, transforms, iterators, immutable updates |
cookbook/patterns.md |
Selecting implementation patterns |
| Promises, cancellation, queues, async iterators |
cookbook/async.md |
Designing or debugging async flow |
| ESM/CJS, exports, resolution, dynamic imports |
cookbook/modules.md |
Crossing module boundaries |
| Node.js APIs, streams, workers, processes |
cookbook/node.md |
Node runtime behavior matters |
| Browser APIs, workers, storage, observers |
cookbook/browser.md |
Browser runtime behavior matters |
| Tests, mocks, fixtures, timers, Testing Library |
cookbook/testing.md |
Testing behavior or flakiness |
| Routing, validation defaults, failure modes |
reference.md |
Before implementation when route is unclear |
Assets
assets/vitest.config.mjs - minimal starter Vitest config for JS repos
assets/jest.config.mjs - minimal starter Jest config for JS repos
Research Tools
gh search code '"type": "module"' --language=json
gh search code 'AbortController' --language=javascript
gh search code 'defineConfig({ test:' --language=javascript
gh search code 'createRequire(import.meta.url)' --language=javascript
1---2disable-model-invocation: true3name: javascript4description: "Use when JavaScript, Node.js, browser JS, modules, async behavior, APIs, tests, or performance are involved."5license: AGPL-3.0-or-later6metadata:7 author: anntnzrb89---1011# JavaScript Development1213Modern JS; runtime-aware; semantics first; no cargo-cult sludge.1415## Activation Triggers1617Use for `.js`, `.mjs`, `.cjs`; `package.json` when `type`, `exports`, `imports`, entrypoints, or ESM/CJS interop matter; `jest.config.*`, `vitest.config.*`, or Testing Library setup in JavaScript-first repos; `import`, `export`, `require`, `type: module`, `exports`, `imports`, or dynamic `import()`; Promises, `async`/`await`, task/microtask ordering, `AbortController`, `fetch`, streams, or workers; closures, `this`, coercion, prototypes, hoisting, TDZ, stale captures, or unexpected `undefined`; Node.js or browser behavior where JS semantics are central; JS-specific tests, mocking, fake timers, or async-test flakiness; legacy refactors where runtime behavior must remain unchanged.1819## Workflow2021```text221. DETECT -> runtime, package manager, module mode, test runner, build tool232. CLASSIFY -> semantics bug | async flow | module/interop | runtime API | tests | perf/refactor243. MODEL -> data flow, mutation points, cancellation/error boundaries, public API254. IMPLEMENT -> smallest safe change; prefer native APIs; keep module mode coherent265. VALIDATE -> repo scripts first; then targeted tests/lint/build; no watch mode by default276. HARDEN -> inspect leaks, circular deps, hot paths, retries/timeouts only where risk justifies28```2930## Core Rules3132- Choose patterns from **runtime + toolchain**, not aesthetics.33- Inspect the nearest working implementation first; reuse an adequate helper, platform API, or installed dependency.34- Prefer **const**, local immutability, and pure transforms; mutate locally when simpler or measurably faster.35- Parse and normalize untrusted input at API, file, queue, CLI, or environment boundaries. Keep raw transport data, retries, logging, and process exits at I/O boundaries.36- Name distinct domain values clearly; represent meaningful outcomes explicitly. Do not hide state machines in truthy values or optional-field piles.37- Use `async`/`await` for orchestration and Promise combinators for concurrency. Expose **cancellation** on long-lived or user-driven work.38- Before optimizing, check independent async loops for accidental serialization.39- Debug weird behavior from language semantics first: coercion, equality, `this`, closures, prototype chain, task queues.40- Catch only to recover, translate, or add context; preserve original causes when wrapping; never silence failures.41- Keep one **module story** per package: module mode is a package-level contract before a file-level syntax choice.42- Prefer **native platform features** before dependencies.43- Add no dependency, abstraction, parser, normalization layer, or defensive branch without a concrete caller, boundary, or failure mode.44- Test at the right layer: pure transforms → unit; I/O boundaries → integration; UI behavior → Testing Library with user-observable queries.45- Mock **external edges**, not core logic. Prefer real values, in-memory fakes, or wire-level fakes when deterministic and isolated.46- Treat large files, parameter bundles, negative-name mazes, redundant post-action checks, and broad catches as review triggers, not automatic rewrites.47- Use `rg` for repository discovery and `ast-grep` for structural search when cheaper.48- Use the existing repo runner. If none exists, choose the lowest-friction runner matching the toolchain; do not introduce a second stack.49- Do not cargo-cult coverage numbers; add tests where failure risk lives.5051## Expected Outputs5253Match output to task size:54- small fix → root cause + minimal patch + targeted validation55- refactor → migration plan + coherent code changes + risk notes56- debugging → likely-cause ranking + repro/inspection steps + fix57- testing task → runner-aware tests with mocked external edges only58- module issue → explicit package/module decision and required file or `package.json` changes5960## When to Use6162- JS app, library, CLI, service, or automation63- async-flow design, cancellation, streams, or workers64- Node.js or browser APIs65- module, `package.json`, or interop issues66- testing strategy or flaky JS tests67- performance debugging, legacy refactors, or weird runtime behavior6869## When Not to Use7071- `.ts` / `.tsx` type-system design central → also load `typescript`72- React / Next render or bundle work dominant → also load `react-best-practices`73- Fresh external-library API docs more important than JS mechanics → load `research`, then `context7` or `grep-app`7475## Quick Start76771. Detect runtime, package manager, module mode, runner, and build tool.782. Classify: semantics, async, modules/interop, runtime API, tests, or perf/refactor.793. Make the smallest coherent change for that runtime.804. Validate with repo scripts first; use targeted checks before broad suites.815. Read the smallest relevant file before improvising across module boundaries, async flow, or test architecture.8283Defaults, validation order, and interop rules live in `reference.md`.8485## Required Follow-up Reads8687|Need|Read|When|88|---|---|---|89|Coercion, `this`, closures, prototypes|`cookbook/semantics.md`|Debugging language-semantics failures|90|Syntax, transforms, iterators, immutable updates|`cookbook/patterns.md`|Selecting implementation patterns|91|Promises, cancellation, queues, async iterators|`cookbook/async.md`|Designing or debugging async flow|92|ESM/CJS, exports, resolution, dynamic imports|`cookbook/modules.md`|Crossing module boundaries|93|Node.js APIs, streams, workers, processes|`cookbook/node.md`|Node runtime behavior matters|94|Browser APIs, workers, storage, observers|`cookbook/browser.md`|Browser runtime behavior matters|95|Tests, mocks, fixtures, timers, Testing Library|`cookbook/testing.md`|Testing behavior or flakiness|96|Routing, validation defaults, failure modes|`reference.md`|Before implementation when route is unclear|9798## Assets99100- `assets/vitest.config.mjs` - minimal starter Vitest config for JS repos101- `assets/jest.config.mjs` - minimal starter Jest config for JS repos102103## Research Tools104105```bash106gh search code '"type": "module"' --language=json107gh search code 'AbortController' --language=javascript108gh search code 'defineConfig({ test:' --language=javascript109gh search code 'createRequire(import.meta.url)' --language=javascript110```