diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 6ec1ecb..b5a200e 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -3,3 +3,35 @@ use toolkit.nu fmt fmt # --check --verbose + +# ADR-025: Block root star-imports of lib_provisioning / main_provisioning. +# A line matching `use lib_provisioning *` or `use main_provisioning *` at the +# start of a file (top-level) reintroduces the transitive parse cost this +# refactor was designed to eliminate. All imports must be selective. +let staged = (git diff --cached --name-only | lines | where { str ends-with ".nu" }) + +if ($staged | length) > 0 { + let violations = ( + $staged + | each {|f| + let hits = ( + do { git show $":($f)" } | complete + | if $in.exit_code == 0 { $in.stdout } else { "" } + | lines + | enumerate + | where { $it.item | str starts-with "use lib_provisioning *" or $it.item | str starts-with "use main_provisioning *" } + | each {|row| $" ($f):($row.index + 1): ($row.item | str trim)"} + ) + $hits + } + | flatten + ) + + if ($violations | length) > 0 { + print "❌ ADR-025 star-import violation — selective imports required:" + for v in $violations { print $v } + print "" + print "Replace `use lib_provisioning *` with explicit `use lib_provisioning/path/to/module.nu [sym1 sym2]`" + exit 1 + } +} diff --git a/cli/provisioning b/cli/provisioning index f0f7d32..5f260f9 100755 --- a/cli/provisioning +++ b/cli/provisioning @@ -1115,8 +1115,15 @@ else esac ;; server | s) - # Intercept subcommand --help before Nu absorbs it at the top-level main + # Route list/sync to the lightweight handler (loads only list.nu, ~255ms). + # All other subcommands go to the full handler (~1.15s). _srv_sub="${2:-}" + case "$_srv_sub" in + list|ls|l|sync) + $NU "${NU_ARGS[@]}" "$PROVISIONING/core/nulib/provisioning-server-list.nu" $CMD_ARGS nothing { + if $debug { $env.PROVISIONING_DEBUG = true } + + let first = ($args | get 0? | default "") + let rest = if $first in ["server" "s"] { $args | skip 1 } else { $args } + let subcmd = ($rest | get 0? | default "list") + + match $subcmd { + "list" | "ls" | "lis" | "l" | "" => { + if ($infra | is-not-empty) { + main list --infra $infra --debug=$debug --out=$out + } else { + main list --debug=$debug --out=$out + } + } + "sync" => { + if ($infra | is-not-empty) { + main sync --infra $infra + } else { + main sync + } + } + _ => { + error make { msg: $"server-list handler received unexpected subcommand '($subcmd)'" } + } + } +}