Agent Native Hardening
Use this skill when the user asks to review and improve a codebase for agent-native maintainability, especially requests like:
- "score this repo"
- "make this codebase agent-friendly"
- "improve code quality / maintainability"
- "clean up the architecture"
- "refactor with swarm/worktrees"
- "improve quality loops and structure"
Must-Read References
Read these supporting files before applying the skill, not after improvising the workflow:
references/scoring-rubric.md before any scorecard, findings list, or severity ranking.
references/swarm-lanes.md before planning discovery lanes, implementation lanes, worktrees, or subagent splits.
If a reference file is missing or unreadable, say so and continue with the closest fallback, but do not silently skip it.
Core Principles
- Fail fast. Do not hide errors.
- Prefer in-code discoverability over markdown sprawl.
- Keep tests light and deterministic; avoid flaky integration tests unless requested.
- Use lanes to separate evidence gathering and implementation. A lane can be a read-only exploration task, a direct coding pass, a subagent task, or a worktree branch depending on scope and risk.
- Keep each lane focused, low-overlap, and easy to verify.
- Prefer feature folders over catch-all files; godfiles must be extracted into clear feature-owned modules.
- Push toward DRY and separation of concerns; remove copy-paste and mixed-responsibility modules without replacing them with new junk drawers.
Required Scorecard
Always score these categories from 0-10 and explain evidence with file references:
agent_native
fully_typed
traversable
test_coverage
feedback_loops
self_documenting
Use rubric: references/scoring-rubric.md. Read it fully before assigning scores.
Always call out godfiles, mixed-concern modules, duplication hotspots, and feature-boundary violations in the evidence.
Type Safety Policy
- Make impossible states unrepresentable: prefer discriminated unions over boolean flag bags and optional-field state objects.
- Use branded/domain types for validated primitives when values are easy to mix up, such as IDs, emails, paths, slugs, and external references.
- Validate at IO boundaries, then pass trusted domain types internally.
- Derive types from the source of truth instead of restating shapes by hand.
- Preserve types across DB, server, client, and event/queue boundaries when project tooling supports it.
- Prefer object parameters over positional arguments for functions with multiple ambiguous arguments.
- Penalize pervasive
any, unsafe casts, manually duplicated DTOs, and type drift between layers.
Godfile + Boundary Policy
- Treat a file or folder as a godfile hotspot when it acts as a catch-all for unrelated responsibilities, mixes layers, or keeps absorbing unrelated edits.
- Godfiles must be broken apart into feature folders with clear ownership and small entrypoints.
- Extract by feature first, then by concern inside the feature: keep orchestration, domain logic, IO, schemas/types, UI, and tests separated when the codebase shape allows it.
- Enforce DRY by pulling repeated logic into the nearest stable shared boundary with a clear owner.
- Do not "fix" duplication by creating a generic
utils or helpers dumping ground; shared code still needs an explicit domain or platform owner.
- Penalize codebases that retain godfiles, mixed-responsibility modules, or broad cross-feature coupling even if tests still pass.
Execution Workflow
- Baseline
- Confirm clean git state.
- Identify active check commands (
lint, typecheck, test, format:check).
- Evidence Sweep
- For non-trivial repos, use read-only discovery lanes first. These may be explore-style subagents or your own direct inspection.
- Discovery lanes return evidence only: files, commands, risks, ownership boundaries, and proposed next lanes.
- Verify discovery findings yourself before edits.
- Identify hotspots: oversized files, godfiles, missing feature boundaries, duplication, weak tests, stale docs.
- Plan Lanes
- Split work into 3-6 lanes with minimal overlap.
- Read
references/swarm-lanes.md before finalizing lanes.
- Choose the lightest lane mechanism that fits: direct edit, explore subagent, coding subagent, worktree, or integration branch.
- Worktrees and commits are recommended for parallel/high-risk implementation, not mandatory for every lane.
- Each implementation lane has one atomic objective and a clear validation command.
- Implement or Coordinate
- Use subagents when they reduce context load or parallelize cleanly; otherwise implement directly.
- Require each implementation lane to run only relevant checks.
- Track exact changed files. If using worker agents or worktrees, require a commit message or merge summary.
- Merge + Stabilize
- If worktrees/branches were used, merge lane branches into an integration branch.
- Resolve conflicts centrally.
- Run full repo checks.
- Fix only real breakages introduced by the hardening pass or lane merges.
- Final Report
- Report findings first (by severity).
- Provide updated scorecard.
- Provide concise change log and remaining risks.
Strategic Comment Policy
Add comments only where they reduce agent/human reread cost:
- Invariants and assumptions.
- Non-obvious control flow.
- Side effects, ordering constraints, idempotency behavior.
- Boundary ownership for modular lanes.
Avoid comments that restate obvious code.
Structural Refactor Policy
- Default repo shape should favor feature folders over layerless file piles.
- When a file mixes multiple concerns, split it before adding more behavior.
- When duplication appears across features, first check whether the behavior is truly shared and stable; if yes, extract it into an owned shared module, otherwise keep it feature-local.
- Prefer small, composable modules with obvious ownership over giant "central" files.
- In findings and final scoring, explicitly say whether the repo is moving toward or away from DRY and separation of concerns.
Minimal Documentation Policy
- Prefer one lane map doc over many docs.
- Keep architecture docs short and file-reference-heavy.
- If
README is stale/template text, replace with project-specific quick map.
- Do not create broad prose docs when comments + one map are sufficient.
Test Policy
- Add tests only for deterministic units:
- pure transforms
- reducers/state machines
- schema validation
- handler guards
- Skip flaky E2E unless explicitly requested.
- Wire tests into existing check pipeline.
Deliverable Format
- Findings (severity ordered)
- Scorecard (before/after)
- Refactor/implementation summary
- Remaining risks and next step options
1---2name: agent-native-hardening3description: TypeScript/JavaScript codebase hardening: maintainability, code quality, architecture cleanup, repo scoring, agent-friendly structure, godfiles, feature folders, DRY, type safety, traversability, feedback loops, worktrees, subagents, swarm refactors.4---56# Agent Native Hardening78Use this skill when the user asks to review and improve a codebase for agent-native maintainability, especially requests like:9- "score this repo"10- "make this codebase agent-friendly"11- "improve code quality / maintainability"12- "clean up the architecture"13- "refactor with swarm/worktrees"14- "improve quality loops and structure"1516## Must-Read References1718Read these supporting files before applying the skill, not after improvising the workflow:19- `references/scoring-rubric.md` before any scorecard, findings list, or severity ranking.20- `references/swarm-lanes.md` before planning discovery lanes, implementation lanes, worktrees, or subagent splits.2122If a reference file is missing or unreadable, say so and continue with the closest fallback, but do not silently skip it.2324## Core Principles25261. Fail fast. Do not hide errors.272. Prefer in-code discoverability over markdown sprawl.283. Keep tests light and deterministic; avoid flaky integration tests unless requested.294. Use lanes to separate evidence gathering and implementation. A lane can be a read-only exploration task, a direct coding pass, a subagent task, or a worktree branch depending on scope and risk.305. Keep each lane focused, low-overlap, and easy to verify.316. Prefer feature folders over catch-all files; godfiles must be extracted into clear feature-owned modules.327. Push toward DRY and separation of concerns; remove copy-paste and mixed-responsibility modules without replacing them with new junk drawers.3334## Required Scorecard3536Always score these categories from 0-10 and explain evidence with file references:371. `agent_native`382. `fully_typed`393. `traversable`404. `test_coverage`415. `feedback_loops`426. `self_documenting`4344Use rubric: `references/scoring-rubric.md`. Read it fully before assigning scores.45Always call out godfiles, mixed-concern modules, duplication hotspots, and feature-boundary violations in the evidence.4647## Type Safety Policy48491. Make impossible states unrepresentable: prefer discriminated unions over boolean flag bags and optional-field state objects.502. Use branded/domain types for validated primitives when values are easy to mix up, such as IDs, emails, paths, slugs, and external references.513. Validate at IO boundaries, then pass trusted domain types internally.524. Derive types from the source of truth instead of restating shapes by hand.535. Preserve types across DB, server, client, and event/queue boundaries when project tooling supports it.546. Prefer object parameters over positional arguments for functions with multiple ambiguous arguments.557. Penalize pervasive `any`, unsafe casts, manually duplicated DTOs, and type drift between layers.5657## Godfile + Boundary Policy58591. Treat a file or folder as a godfile hotspot when it acts as a catch-all for unrelated responsibilities, mixes layers, or keeps absorbing unrelated edits.602. Godfiles must be broken apart into feature folders with clear ownership and small entrypoints.613. Extract by feature first, then by concern inside the feature: keep orchestration, domain logic, IO, schemas/types, UI, and tests separated when the codebase shape allows it.624. Enforce DRY by pulling repeated logic into the nearest stable shared boundary with a clear owner.635. Do not "fix" duplication by creating a generic `utils` or `helpers` dumping ground; shared code still needs an explicit domain or platform owner.646. Penalize codebases that retain godfiles, mixed-responsibility modules, or broad cross-feature coupling even if tests still pass.6566## Execution Workflow67681. Baseline69- Confirm clean git state.70- Identify active check commands (`lint`, `typecheck`, `test`, `format:check`).71722. Evidence Sweep73- For non-trivial repos, use read-only discovery lanes first. These may be explore-style subagents or your own direct inspection.74- Discovery lanes return evidence only: files, commands, risks, ownership boundaries, and proposed next lanes.75- Verify discovery findings yourself before edits.76- Identify hotspots: oversized files, godfiles, missing feature boundaries, duplication, weak tests, stale docs.77783. Plan Lanes79- Split work into 3-6 lanes with minimal overlap.80- Read `references/swarm-lanes.md` before finalizing lanes.81- Choose the lightest lane mechanism that fits: direct edit, explore subagent, coding subagent, worktree, or integration branch.82- Worktrees and commits are recommended for parallel/high-risk implementation, not mandatory for every lane.83- Each implementation lane has one atomic objective and a clear validation command.84854. Implement or Coordinate86- Use subagents when they reduce context load or parallelize cleanly; otherwise implement directly.87- Require each implementation lane to run only relevant checks.88- Track exact changed files. If using worker agents or worktrees, require a commit message or merge summary.89905. Merge + Stabilize91- If worktrees/branches were used, merge lane branches into an integration branch.92- Resolve conflicts centrally.93- Run full repo checks.94- Fix only real breakages introduced by the hardening pass or lane merges.95966. Final Report97- Report findings first (by severity).98- Provide updated scorecard.99- Provide concise change log and remaining risks.100101## Strategic Comment Policy102103Add comments only where they reduce agent/human reread cost:1041. Invariants and assumptions.1052. Non-obvious control flow.1063. Side effects, ordering constraints, idempotency behavior.1074. Boundary ownership for modular lanes.108109Avoid comments that restate obvious code.110111## Structural Refactor Policy1121131. Default repo shape should favor feature folders over layerless file piles.1142. When a file mixes multiple concerns, split it before adding more behavior.1153. When duplication appears across features, first check whether the behavior is truly shared and stable; if yes, extract it into an owned shared module, otherwise keep it feature-local.1164. Prefer small, composable modules with obvious ownership over giant "central" files.1175. In findings and final scoring, explicitly say whether the repo is moving toward or away from DRY and separation of concerns.118119## Minimal Documentation Policy1201211. Prefer one lane map doc over many docs.1222. Keep architecture docs short and file-reference-heavy.1233. If `README` is stale/template text, replace with project-specific quick map.1244. Do not create broad prose docs when comments + one map are sufficient.125126## Test Policy1271281. Add tests only for deterministic units:129- pure transforms130- reducers/state machines131- schema validation132- handler guards1332. Skip flaky E2E unless explicitly requested.1343. Wire tests into existing check pipeline.135136## Deliverable Format1371381. Findings (severity ordered)1392. Scorecard (before/after)1403. Refactor/implementation summary1414. Remaining risks and next step options