CLI command design

clean

Normalizes Altium schematic, schematic-library, and PCB-library style details with JSON/JSONC-configured rules.

Usage

altium-cruncher clean input.SchDoc --init-config
altium-cruncher clean --init-config --config-type pcblib --config altium-pcblib-clean.json
altium-cruncher clean input.SchDoc --config altium-clean.json -o output
altium-cruncher clean project.PrjPcb --backup
altium-cruncher clean footprint.PcbLib --config pcblib-clean.json

Arguments

file accepts .PrjPcb, .SchDoc, .SchLib, or .PcbLib. With no file, the command auto-detects one project or one supported document in the current directory unless --init-config --config-type is used. --config selects rule JSON/JSONC. When omitted, schematic inputs use altium-clean.json next to the input and PcbLib inputs use workspace altium-pcblib-clean.json when available, falling back to the input folder. --init-config writes the selected commented JSONC template and exits without loading or cleaning the input. With a file, template type is inferred from the suffix; without a file, --config-type schematic or --config-type pcblib is required. --force-config permits intentional overwrite during --init-config. If the resolved config is missing during a normal clean run, the command writes a commented template and exits without modifying the design. --backup and --backup-path control source preservation. -o selects a single output file for document/library input and an output directory for .PrjPcb fanout.

Config Lifecycle

Generated configs are JSONC: comments and trailing commas are accepted by the loader. The machine-readable contract is docs/contracts/clean_config.a0.schema.json. Templates deliberately include comments for every option because clean rules are usually tuned by hand. Generated config comments are part of the public editing surface and follow ADR-0007: string/enum fields list accepted options in the field comment. Explicit --init-config is the preferred non-mutating way to create or inspect defaults. The first normal run is also non-mutating when a config does not exist. A second run applies the edited config. For experiments, users should prefer --output or --backup until rule effects are reviewed.

Schematic Rules

altium-clean.json uses schema altium_cruncher.clean.config.a0 and applies to .SchDoc, .SchLib, and project-driven .PrjPcb cleaning. Supported sections are normalize_pin_fonts, normalize_symbol_body_rectangles, normalize_power_symbols, normalize_net_labels, normalize_component_designators, normalize_component_parameters, normalize_component_free_text, normalize_wires, normalize_no_erc, normalize_sheet_style, and normalize_symbol_internal_graphics_monochrome. Font specs use font_name, size_pt, bold, italic, and optional color. Colors may be Win32/BGR integers, integer strings such as 0x000000, or #RRGGBB. Line widths accept names such as smallest, small, medium, and large. No-ERC symbols accept names such as cross, thin cross, small cross, checkbox, and triangle.

PcbLib Rules

altium-pcblib-clean.json uses schema altium_cruncher.pcblib.clean.config.a0. PcbLib cleaning targets vendor footprint drafting noise while preserving manufacturable footprint data. Supported sections are remove_mechanical_primitives, remove_text_strings, and remove_regions. The preservation flags are important: component bodies, embedded 3D models, board cutouts, keepouts, and custom-pad regions should not be removed by broad cleanup rules.

Output

For .SchDoc, .SchLib, and .PcbLib, omitted -o means in-place overwrite after config exists. For .PrjPcb, omitted -o writes each listed schematic in place; an output directory mirrors project-relative schematic paths. Backup paths follow the same shape: one backup file for single-file input, or a backup directory for project fanout. Command logs include changed-object counts for each rule family so rule changes can be reviewed after a run.

Tests

L3 verifies first-run and explicit --init-config template creation without mutating committed Hydroscope assets. Unit tests verify JSONC template parsing, per-option template comments, PcbLib config discovery, schematic clean helper behavior, PcbLib config loading, and selected helper behavior. Release signoff should add more fixture-backed apply tests for project fanout, backup/output behavior, and PcbLib primitive removal.