DOCUMENTATION

Documentation

CLI reference, TypeScript API, type definitions, constraint system, and copy-paste prompts.

QUICK START

Up and running in 60 seconds.

terminal
npm install prune-systems
analyze.ts
import { analyzeSystem, classifyComponents, runPrune } from 'prune-systems';

// Full automated run
const result = runPrune('./src');
console.log(result.verdict);    // → SUCCESS
console.log(result.reductions); // → [{ type: 'remove', targets: [...] }, ...]
console.log(result.before);     // → { files: 42, totalLoc: 11400, ... }
console.log(result.after);      // → { files: 19, totalLoc: 5200, ... }

// Or step by step
const analysis = analyzeSystem('./src');
const classified = classifyComponents(analysis);
classified.forEach(c => {
  console.log(`${c.file}: ${c.classification} — ${c.reason}`);
});

CLI

Command line interface.

terminal
# Analyze system structure
$ prune analyze ./src

# Propose reductions with classifications
$ prune reduce ./src

# Full benchmark with before/after delta
$ prune benchmark ./src
prune analyze <path>Scan files, build dependency graph, report metrics and smells.
prune reduce <path>Classify components, propose ranked reductions.
prune benchmark <path>Full PRUNE loop: before/after metrics, constraint validation, verdict.

API REFERENCE

Core functions.

analyzeSystem(rootPath: string): SystemAnalysis

Scans a directory recursively. Extracts imports and exports from every source file (.ts, .tsx, .js, .jsx). Builds a directed dependency graph. Computes metrics (files, LOC, dependencies). Detects smells (circular deps, dead files, large files, duplicate exports).

classifyComponents(analysis: SystemAnalysis): ClassifiedNode[]

Classifies every node in the dependency graph as living, dead, duplicated, decorative, or parasitic. Uses graph topology: dependents count, fan-in/fan-out ratio, LOC, export overlap.

proposeReductions(analysis: SystemAnalysis, classified: ClassifiedNode[]): Reduction[]

Generates ranked reduction proposals. Dead modules → remove. Duplicated modules → merge (keep the one with more dependents). Decorative modules → inline into consumer. Parasitic → remove if orphaned.

evaluateConstraints(analysis: SystemAnalysis, removed: Set<string>): ConstraintResult

Validates a proposed removal set against 5 structural constraints: function preservation, irreducibility, no duplication, local reasoning (coupling score), traceability (path clarity).

runPrune(rootPath: string): PruneResult

The full PRUNE loop. Analyze → classify → propose → validate each proposal against constraints → accept or reject → return before/after metrics, accepted reductions, constraint results, and verdict.

TYPES

Type definitions.

SystemAnalysisComplete analysis: root path, dependency graph, aggregate metrics, detected smells.
DependencyGraphDirected graph with nodes (Map<string, FileNode>), forward edges (file → imports), and reverse edges (file → dependents).
FileNodeParsed source file: path, relativePath, imports (ImportRef[]), exports (string[]), loc.
ClassifiedNodeClassification result: file path, classification (living/dead/duplicated/decorative/parasitic), reason string.
ReductionProposed change: type (remove/merge/inline), targets (file paths), optional into (merge target), reason, impact score (0-1).
ConstraintResultFive constraint checks: functionPreserved (bool), irreducible (bool), noDuplication (bool), localReasoning (0-1), traceability (0-1), valid (composite).
PruneResultFull result: before/after Metrics, accepted reductions, constraint results, verdict (SUCCESS/PARTIAL/FAILURE).
MetricsAggregate numbers: files, totalLoc, dependencies, avgDepsPerFile, maxDepsPerFile.
SmellDetected issue: type (circular-dep/dead-file/large-file/duplicate-export), target files, message.

CLASSIFICATIONS

Five classifications.

Living

Actively used and connected. Has dependents and is imported by other modules. Earns its place in the system.

Dead

Zero dependents and not an entry point. No other module imports it. Safe to remove immediately.

Duplicated

Exports the same symbol names as another module. One should be removed or merged into the other.

Decorative

Thin wrapper under 15 lines with 1 or fewer dependents. Should be inlined into its consumer.

Parasitic

High fan-out (imports many modules) but few or zero dependents. Consumes without contributing.

CONSTRAINT SYSTEM

Five structural constraints.

Every proposed reduction must pass all five constraints. If any fails, the reduction is rejected. This prevents over-pruning, broken imports, and false simplification.

Function Preserved

Every remaining module's imports still resolve. No broken dependency chains after removal.

Irreducible

Every remaining non-entry module is depended upon by at least one other remaining module.

No Duplication

No two remaining modules export the same symbol name (excluding default exports).

Local Reasoning

Low coupling score. Computed as 1 - (avg fan-in × fan-out) / n². Must exceed 0.3.

Traceability

Short dependency chains. Computed via BFS average shortest path. Must exceed 0.3.

PROMPT LIBRARY

Copy-paste prompts.

Use these with any AI assistant to apply the PRUNE discipline without installing anything.

System AuditFull analysis with classifications, reductions, and constraint validation.
You are PRUNE, a constraint-based system analyzer.

Audit the system I describe:

1. Scan every module, file, component, and dependency
2. Build the dependency graph
3. Classify each element:
   - living (actively used, connected)
   - dead (no imports, no dependents)
   - duplicated (same exports as another module)
   - decorative (thin wrapper, <15 lines)
   - parasitic (high deps, low value)
4. Propose reductions:
   - remove dead modules
   - merge duplicates (keep the one with more dependents)
   - inline decorative wrappers
5. Validate against constraints:
   - Function preserved (no broken imports)
   - Irreducible (nothing else can be removed)
   - No duplication (no shared exports remain)
   - Local reasoning (low coupling score)
   - Traceability (short dependency chains)
6. Output:
   - Before/after metrics (files, lines, deps)
   - Delta percentages
   - Constraint results (✓/✗)
   - Verdict: SUCCESS / PARTIAL / FAILURE

Be precise. Be severe. Default to removal.
SimplifyReduce complexity by questioning every abstraction.
You are PRUNE in simplification mode.

Analyze this system and:
1. Identify every abstraction layer
2. Question each: does it earn its complexity?
3. Find merge opportunities (similar modules, redundant wrappers)
4. Propose the minimum viable architecture
5. Validate every proposal against the 5 constraints

Rules:
- Prefer deletion over refactoring
- Prefer merging over separating
- Prefer inlining over abstracting
- Every remaining element must justify its existence
BuildConstruct only from what survives reduction.
You are PRUNE in build mode. You only construct from what survives reduction.

Given this system diagnosis:
1. Build only from essential elements
2. Compose from existing primitives
3. Refuse any abstraction that doesn't pass all constraints
4. Keep the implementation traceable and removable
5. Output clean, minimal code

Rules:
- No premature abstraction
- No speculative architecture
- No wrapper functions that add no value
- Every line must earn its place
Full WorkflowComplete PRUNE discipline: audit → reduce → validate → build.
You are operating under the PRUNE discipline.

Before writing any code:
1. Audit: Scan the system. Classify all elements.
2. Reduce: Remove everything dead, duplicated, or decorative.
3. Validate: Check constraints — function preserved, irreducible, no duplication.
4. Build: Only after steps 1-3, implement the requested change.

Every addition must pass:
- Is this necessary or can the goal be achieved by removal?
- Does this break any existing dependency?
- Does this introduce duplication?
- Can this be removed later without cascading damage?

If any check fails, find a simpler path.