diff --git a/cli/provisioning b/cli/provisioning index ddfab14..c3fb78a 100755 --- a/cli/provisioning +++ b/cli/provisioning @@ -643,30 +643,15 @@ if [ -n "${1:-}" ] && [ -z "${2:-}" ]; then fi fi -# Workspace operations (fast-path) +# workspace fast-path removed (ADR-025 Phase 4 — single-route principle). +# All workspace subcommands now route to main_provisioning/workspace.nu via +# the main dispatch case. --help still intercepts before full load. if [ "${1:-}" = "workspace" ] || [ "${1:-}" = "ws" ]; then case "${2:-}" in - "list" | "") - _nu_minimal "workspace-list | get ok | table" - exit $? - ;; - "active") - _nu_minimal "workspace-active" - exit $? - ;; - "info") - if [ -n "${3:-}" ]; then - $NU -n -c "source '$PROVISIONING/core/nulib/lib_minimal.nu'; source '$PROVISIONING/core/nulib/scripts/query-workspace-info.nu'" 2>/dev/null - else - $NU -n -c "source '$PROVISIONING/core/nulib/lib_minimal.nu'; source '$PROVISIONING/core/nulib/scripts/query-workspace-info.nu'" 2>/dev/null - fi - exit $? - ;; "-help" | "h" | "help") exec "$0" "${1}" --help ;; esac - # Other workspace commands (switch, register, etc.) fall through to full loading fi # Status/Health check (fast-path) - DISABLED to fix dispatcher loop @@ -676,11 +661,8 @@ fi # exit $? # fi -# Environment display (fast-path) -if [ "${1:-}" = "env" ] || [ "${1:-}" = "allenv" ]; then - _nu_minimal "env-quick | table" - exit $? -fi +# env fast-path removed (ADR-025 Phase 4 — single-route principle). +# env/allenv now route to the full dispatcher via the *) default case. # Alias list fast-path — reads JSON cache directly in bash, no Nu process if [ "${1:-}" = "alias" ] || [ "${1:-}" = "a" ] || [ "${1:-}" = "al" ]; then @@ -815,42 +797,25 @@ if [ "${1:-}" = "job" ] || [ "${1:-}" = "j" ]; then esac fi -# Provider list (lightweight - reads filesystem only, no module loading) -if [ "${1:-}" = "provider" ] || [ "${1:-}" = "providers" ]; then - if [ "${2:-}" = "list" ] || [ -z "${2:-}" ]; then - $NU "$PROVISIONING/core/nulib/scripts/query-providers.nu" 2>/dev/null - exit $? - fi -fi +# provider fast-path removed (ADR-025 Phase 4 — single-route principle). +# Falls through to main dispatch case. # Fast-paths removed (ADR-025 Phase 4 — single-route principle). # taskserv/server/cluster `list` now route to their thin handlers which invoke # the full semantic path (middleware + live provider state). Daemon routing # (for server list/ls/l) is preserved further down in the dispatch case. -# Infra list (lightweight - reads filesystem only) +# infra fast-path removed (ADR-025 Phase 4 — single-route principle). +# Falls through to main dispatch case. Help with no args still shows help menu. if [ "${1:-}" = "infra" ] || [ "${1:-}" = "inf" ]; then - # Show infrastructure help if no second argument if [ -z "${2:-}" ]; then - # Call through the normal help system provisioning help infrastructure exit 0 - elif [ "${2:-}" = "list" ]; then - $NU -n -c "source '$PROVISIONING/core/nulib/lib_minimal.nu'; source '$PROVISIONING/core/nulib/scripts/query-infra.nu'" 2>/dev/null - exit $? - elif [ "${2:-}" = "info" ]; then - INFRA_NAME="${3:-}" $NU -n -c "source '$PROVISIONING/core/nulib/lib_minimal.nu'; source '$PROVISIONING/core/nulib/scripts/query-infra-detail.nu'" 2>/dev/null - exit $? fi fi -# Config validation (lightweight - validates config structure without full load) -if [ "${1:-}" = "validate" ]; then - if [ "${2:-}" = "config" ] || [ -z "${2:-}" ]; then - $NU -n -c "source '$PROVISIONING/core/nulib/lib_minimal.nu'; source '$PROVISIONING/core/nulib/scripts/validate-config.nu'" 2>/dev/null - exit $? - fi -fi +# validate fast-path removed (ADR-025 Phase 4 — single-route principle). +# Falls through to main dispatch case. if [ ! -d "$PROVISIONING_USER_CONFIG" ] || [ ! -r "$PROVISIONING_CONTEXT_PATH" ]; then [ ! -x "$PROVISIONING/core/nulib/provisioning setup" ] && echo "$PROVISIONING/core/nulib/provisioning setup not found" && exit 1 diff --git a/nulib/scripts/query-infra-detail.nu b/nulib/scripts/query-infra-detail.nu deleted file mode 100644 index 66f9d01..0000000 --- a/nulib/scripts/query-infra-detail.nu +++ /dev/null @@ -1,84 +0,0 @@ -# Show details for a specific infrastructure -# INFRA_NAME env var must be set by caller -# Sourced by bash after lib_minimal.nu is loaded — not meant to be run standalone - -let infra_name = ($env.INFRA_NAME? | default "") -if ($infra_name | is-empty) { - print "No infrastructure specified. Use: prvng infra info " - exit 1 -} - -let ws_result = (workspace-active) -let ws_name = if (is-ok $ws_result) { $ws_result.ok } else { "" } -if ($ws_name | is-empty) { - print 'No active workspace' - exit 1 -} - -let user_config = (get-user-config-path) -if not ($user_config | path exists) { - print 'Config not found' - exit 1 -} - -let config = (open $user_config) -let ws = ($config | get --optional workspaces | default [] | where { $in.name == $ws_name } | first) -if ($ws | is-empty) { - print 'Workspace not found' - exit 1 -} - -let infra_path = ($ws.path | path join 'infra' | path join $infra_name) -if not ($infra_path | path exists) { - print $"Infrastructure '($infra_name)' not found in workspace '($ws_name)'" - exit 1 -} - -# Servers -let sf_direct = ($infra_path | path join 'servers.ncl') -let sf_defs = ($infra_path | path join 'defs' | path join 'servers.ncl') -let sf = if ($sf_direct | path exists) { $sf_direct } else { $sf_defs } -let servers = if ($sf | path exists) { - open $sf --raw - | split row "\n" - | where {|l| $l =~ 'hostname\s*=\s*"' } - | each {|l| - let parts = ($l | split row '"') - if ($parts | length) >= 2 { $parts | get 1 } else { "" } - } - | where {|h| $h | is-not-empty } -} else { [] } - -# Known config files -let config_files = ['servers.ncl' 'firewalls.ncl' 'settings.ncl' 'main.ncl'] - | where {|f| ($infra_path | path join $f) | path exists } - -# Taskservs dirs -let taskservs_path = ($infra_path | path join 'taskservs') -let taskservs = if ($taskservs_path | path exists) { - ls $taskservs_path | where type == 'dir' | each {|d| $d.name | path basename } -} else { [] } - -let default_infra = ($ws | get --optional default_infra | default "") -let is_default = $infra_name == $default_infra - -print $"🏗️ Infrastructure: ($infra_name)(if $is_default { ' ★ (default)' } else { '' })" -print $" Workspace: ($ws_name)" -print "" - -if ($servers | is-empty) { - print "🖥️ Servers: (none defined)" -} else { - print $"🖥️ Servers (($servers | length)):" - $servers | each {|s| print $" • ($s)" } | ignore -} - -print "" - -if ($config_files | is-not-empty) { - print $"📄 Config: ($config_files | str join ', ')" -} - -if ($taskservs | is-not-empty) { - print $"⚙️ Taskservs: ($taskservs | str join ', ')" -} diff --git a/nulib/scripts/query-infra.nu b/nulib/scripts/query-infra.nu deleted file mode 100755 index 07f012c..0000000 --- a/nulib/scripts/query-infra.nu +++ /dev/null @@ -1,71 +0,0 @@ -# List all infrastructures in active workspace -# This file is sourced by bash after lib_minimal.nu is loaded -# Not meant to be run standalone - -# Get active workspace -let ws_result = (workspace-active) -let active_ws = if (is-ok $ws_result) { $ws_result.ok } else { "" } -if ($active_ws | is-empty) { - print 'No active workspace' - exit 1 -} - -# Get workspace path from config -let user_config_path = ( - $env.HOME - | path join 'Library' - | path join 'Application Support' - | path join 'provisioning' - | path join 'user_config.yaml' -) - -if not ($user_config_path | path exists) { - print 'Config not found' - exit 1 -} - -let config = (open $user_config_path) -let workspaces = ($config | get --optional workspaces | default []) -let ws = ($workspaces | where { $in.name == $active_ws } | first) - -if ($ws | is-empty) { - print 'Workspace not found' - exit 1 -} - -let ws_path = $ws.path -let infra_path = ($ws_path | path join 'infra') - -if not ($infra_path | path exists) { - print '📁 Available Infrastructures: (none configured)' - exit 0 -} - -# List all infrastructures -let infras = ( - ls $infra_path - | where type == 'dir' - | each {|inf| - let inf_name = ($inf.name | path basename) - let inf_full_path = ($infra_path | path join $inf_name) - let has_config = (($inf_full_path | path join 'settings.ncl') | path exists) - - { - name: $inf_name - configured: $has_config - modified: $inf.modified - } - } -) - -if ($infras | length) == 0 { - print '📁 Available Infrastructures: (none found)' -} else { - print '📁 Available Infrastructures:' - print '' - $infras | each {|inf| - let status = if $inf.configured { '✓' } else { '○' } - let output = " [" + $status + "] " + $inf.name - print $output - } | ignore -} diff --git a/nulib/scripts/query-providers.nu b/nulib/scripts/query-providers.nu deleted file mode 100755 index 26e90c6..0000000 --- a/nulib/scripts/query-providers.nu +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env nu -# List all available providers - -def main [] { - let provisioning = ($env.PROVISIONING | default '/usr/local/provisioning') - let providers_base = ($provisioning | path join 'extensions' | path join 'providers') - - if not ($providers_base | path exists) { - print 'PROVIDERS list: (none found)' - return - } - - # Discover all providers from directories - let all_providers = ( - ls $providers_base - | where type == 'dir' - | each {|prov_dir| - let prov_name = ($prov_dir.name | path basename) - if $prov_name != 'prov_lib' { - {name: $prov_name, type: 'providers', version: '0.0.1'} - } else { - null - } - } - | compact - ) - - if ($all_providers | length) == 0 { - print 'PROVIDERS list: (none found)' - } else { - print 'PROVIDERS list: ' - print '' - $all_providers | table - } -} diff --git a/nulib/scripts/query-workspace-info.nu b/nulib/scripts/query-workspace-info.nu deleted file mode 100644 index 8c0b54b..0000000 --- a/nulib/scripts/query-workspace-info.nu +++ /dev/null @@ -1,44 +0,0 @@ -# Show active workspace info including infrastructure list -# Sourced by bash after lib_minimal.nu is loaded — not meant to be run standalone - -let ws_result = (workspace-active) -let ws_name = if (is-ok $ws_result) { $ws_result.ok } else { "" } - -if ($ws_name | is-empty) { - print 'No active workspace' - exit 1 -} - -let info_result = (workspace-info $ws_name) -if not (is-ok $info_result) { - print $"Error: ($info_result.err)" - exit 1 -} - -let info = $info_result.ok - -if not $info.exists { - print $"Workspace '($ws_name)' not found in config" - exit 1 -} - -print $"📊 Workspace: ($info.name)" -print $" Path: ($info.path)" -print $" Last used: ($info.last_used)" - -if ($info.default_infra | is-not-empty) { - print $" Default: ($info.default_infra)" -} - -print "" - -if ($info.infrastructures | is-empty) { - print "📁 Infrastructures: (none configured)" -} else { - print "📁 Infrastructures:" - $info.infrastructures | each {|inf| - let srv_label = if $inf.servers == 1 { "1 server" } else { $"($inf.servers) servers" } - let marker = if $inf.name == $info.default_infra { " ★" } else { "" } - print $" • ($inf.name) [($srv_label)]($marker)" - } | ignore -} diff --git a/nulib/scripts/validate-config.nu b/nulib/scripts/validate-config.nu deleted file mode 100755 index ba5c916..0000000 --- a/nulib/scripts/validate-config.nu +++ /dev/null @@ -1,101 +0,0 @@ -# Validate configuration structure without full load -# This file is sourced by bash after lib_minimal.nu is loaded -# Not meant to be run standalone - -# Use do/complete instead of try-catch for error handling -let result = (do { - # Get active workspace - let active_ws = (workspace-active) - if ($active_ws | is-empty) { - print '❌ Error: No active workspace' - exit 1 - } - - # Get workspace path from config - let user_config_path = ( - $env.HOME - | path join 'Library' - | path join 'Application Support' - | path join 'provisioning' - | path join 'user_config.yaml' - ) - - if not ($user_config_path | path exists) { - print $'❌ Error: User config not found at ($user_config_path)' - exit 1 - } - - let config = (open $user_config_path) - let workspaces = ($config | get --optional workspaces | default []) - let ws = ($workspaces | where { $in.name == $active_ws } | first) - - if ($ws | is-empty) { - print $'❌ Error: Workspace ($active_ws) not found in config' - exit 1 - } - - let ws_path = $ws.path - - # Validate workspace structure - let required_dirs = ['infra', 'config', '.clusters'] - let infra_path = ($ws_path | path join 'infra') - let config_path = ($ws_path | path join 'config') - - let missing_dirs = $required_dirs | where { not (($ws_path | path join $in) | path exists) } - - if ($missing_dirs | length) > 0 { - print $'⚠️ Warning: Missing directories: ($missing_dirs | str join ", ")' - } - - # Validate infrastructures have required files - if ($infra_path | path exists) { - let infras = (ls $infra_path | where type == 'dir') - let invalid_infras = ( - $infras - | each {|inf| - let inf_name = ($inf.name | path basename) - let inf_full_path = ($infra_path | path join $inf_name) - if not (($inf_full_path | path join 'settings.k') | path exists) { - $inf_name - } else { - null - } - } - | compact - ) - - if ($invalid_infras | length) > 0 { - print $'⚠️ Warning: Infrastructures missing settings.k: ($invalid_infras | str join ", ")' - } - } - - # Validate user config structure - let has_active = (($config | get --optional active_workspace) != null) - let has_workspaces = (($config | get --optional workspaces) != null) - let has_preferences = (($config | get --optional preferences) != null) - - if not $has_active { - print '⚠️ Warning: Missing active_workspace in user config' - } - - if not $has_workspaces { - print '⚠️ Warning: Missing workspaces list in user config' - } - - if not $has_preferences { - print '⚠️ Warning: Missing preferences in user config' - } - - # Summary - print '' - print $'✓ Configuration validation complete for workspace: ($active_ws)' - print $' Path: ($ws_path)' - print ' Status: Valid (with warnings, if any listed above)' - - {success: true} -} | complete) - -if ($result.exit_code != 0) { - print $'❌ Validation error: ($result.stderr)' - exit 1 -}