Agent skill
single-file-topdown-ordering
Use when a single file is difficult to understand top-down because the public surface is buried or definitions appear before the behavior they support. Goal: restore a clear reading flow without changing semantics.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/single-file-topdown-ordering
Metadata
Additional technical details for this skill
- short description
- Read top-down
SKILL.md
Code Ordering
Restore a top-down narrative inside a single file: start from the public surface, then unfold supporting details.
Core Rule
Blocks that depend on other blocks appear earlier. Their dependencies appear later.
Only reorder when language semantics remain correct.
Block Scope
Blocks are structural units such as exported/public declarations, classes, functions/methods, and relevant type definitions. Imports and module-level conventions stay untouched.
Dependency Detection
For a block, collect dependencies in this order:
- Signature dependencies: types and interfaces referenced by the declaration.
- Body dependencies: symbols required by the implementation, ordered by semantic execution and control flow.
Ordering Process
Treat the file as breadth-first expansion from public entry blocks.
-
Collect exported/public entry blocks.
-
Sort entry blocks by dependency-after: if an entry block depends on another entry block, place the dependent first. If no ordering is implied, keep original order.
-
Repeat the following layer step until no new blocks are discovered:
- Scan every block in the current layer and collect dependencies using Dependency Detection.
- Remove blocks already placed and anything out of scope.
- The remaining blocks become the next layer, preserving first-encounter order across the scan.
- Append the next layer after the current layer.
Cycles
Cycles are common. Keep best-effort ordering and treat a cycle as a single group during layering.
Warn only when the cycle prevents a stable, semantics-preserving top-down order. Otherwise, do not warn.
Review Checklist
- Public surface appears before supporting details.
- A block appears before the blocks it depends on whenever a valid order exists.
- Signature dependencies are introduced before body dependencies for the same dependent.
- The result reads top-down without changing behavior.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?