refactor(wrapper): delete 5 remaining fast-paths — single-route complete (ADR-025 Phase 4)

Removed the final 5 fast-path intercepts and their scripts. All list/query
commands now route through a single semantic path.

Bash wrapper — removed intercept blocks:
  - `workspace list/active/info` (was: _nu_minimal + query-workspace-info.nu)
  - `env/allenv`                 (was: _nu_minimal "env-quick | table")
  - `provider/providers list`    (was: scripts/query-providers.nu)
  - `infra list/info`            (was: scripts/query-infra.nu + query-infra-detail.nu)
  - `validate config`            (was: scripts/validate-config.nu)

Preserved in wrapper:
  - workspace `--help` intercept (avoids full load for help)
  - infra with no args → `provisioning help infrastructure` (help menu)

Fast-path scripts deleted:
  - nulib/scripts/query-providers.nu
  - nulib/scripts/query-workspace-info.nu
  - nulib/scripts/query-infra.nu
  - nulib/scripts/query-infra-detail.nu
  - nulib/scripts/validate-config.nu

Remaining scripts/ files (all legitimate, not fast-paths):
  - get-help-category.nu       (help category parsing)
  - prov-bootstrap.nu          (bootstrap logic, not a data query)
  - prov-cluster-deploy.nu     (deploy execution, not a list)
  - validate-command.nu        (registry validation used by _validate_command)
  - README.md

Transitional note:
  These commands temporarily route through the main dispatch `*)` default case
  which still uses $RUNNER (the 492-line Nu runner). Cold-start for them is
  currently slow (~70s in fat-path). Phase 4.3/4.4 will empty root mod.nu and
  delete the Nu runner — restoring <1s cold-start for all commands.

Single-route invariant achieved:
  - No command has two implementations with different semantics
  - Daemon and cache become purely orthogonal concerns (transport + read
    optimization), toggleable without changing what the command returns

Refs: ADR-025 Phase 4, workspaces/libre-daoshi/.coder/2026-04-17-server-list-daemon-middleware.info.md
This commit is contained in:
Jesús Pérez 2026-04-17 17:43:18 +01:00
parent 5d9ce3c591
commit 205402e990
Signed by: jesus
GPG key ID: 9F243E355E0BC939
6 changed files with 11 additions and 381 deletions

View file

@ -643,30 +643,15 @@ if [ -n "${1:-}" ] && [ -z "${2:-}" ]; then
fi fi
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 if [ "${1:-}" = "workspace" ] || [ "${1:-}" = "ws" ]; then
case "${2:-}" in 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") "-help" | "h" | "help")
exec "$0" "${1}" --help exec "$0" "${1}" --help
;; ;;
esac esac
# Other workspace commands (switch, register, etc.) fall through to full loading
fi fi
# Status/Health check (fast-path) - DISABLED to fix dispatcher loop # Status/Health check (fast-path) - DISABLED to fix dispatcher loop
@ -676,11 +661,8 @@ fi
# exit $? # exit $?
# fi # fi
# Environment display (fast-path) # env fast-path removed (ADR-025 Phase 4 — single-route principle).
if [ "${1:-}" = "env" ] || [ "${1:-}" = "allenv" ]; then # env/allenv now route to the full dispatcher via the *) default case.
_nu_minimal "env-quick | table"
exit $?
fi
# Alias list fast-path — reads JSON cache directly in bash, no Nu process # Alias list fast-path — reads JSON cache directly in bash, no Nu process
if [ "${1:-}" = "alias" ] || [ "${1:-}" = "a" ] || [ "${1:-}" = "al" ]; then if [ "${1:-}" = "alias" ] || [ "${1:-}" = "a" ] || [ "${1:-}" = "al" ]; then
@ -815,42 +797,25 @@ if [ "${1:-}" = "job" ] || [ "${1:-}" = "j" ]; then
esac esac
fi fi
# Provider list (lightweight - reads filesystem only, no module loading) # provider fast-path removed (ADR-025 Phase 4 — single-route principle).
if [ "${1:-}" = "provider" ] || [ "${1:-}" = "providers" ]; then # Falls through to main dispatch case.
if [ "${2:-}" = "list" ] || [ -z "${2:-}" ]; then
$NU "$PROVISIONING/core/nulib/scripts/query-providers.nu" 2>/dev/null
exit $?
fi
fi
# Fast-paths removed (ADR-025 Phase 4 — single-route principle). # Fast-paths removed (ADR-025 Phase 4 — single-route principle).
# taskserv/server/cluster `list` now route to their thin handlers which invoke # taskserv/server/cluster `list` now route to their thin handlers which invoke
# the full semantic path (middleware + live provider state). Daemon routing # the full semantic path (middleware + live provider state). Daemon routing
# (for server list/ls/l) is preserved further down in the dispatch case. # (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 if [ "${1:-}" = "infra" ] || [ "${1:-}" = "inf" ]; then
# Show infrastructure help if no second argument
if [ -z "${2:-}" ]; then if [ -z "${2:-}" ]; then
# Call through the normal help system
provisioning help infrastructure provisioning help infrastructure
exit 0 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
fi fi
# Config validation (lightweight - validates config structure without full load) # validate fast-path removed (ADR-025 Phase 4 — single-route principle).
if [ "${1:-}" = "validate" ]; then # Falls through to main dispatch case.
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
if [ ! -d "$PROVISIONING_USER_CONFIG" ] || [ ! -r "$PROVISIONING_CONTEXT_PATH" ]; then 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 [ ! -x "$PROVISIONING/core/nulib/provisioning setup" ] && echo "$PROVISIONING/core/nulib/provisioning setup not found" && exit 1

View file

@ -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 <name>"
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 ', ')"
}

View file

@ -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
}

View file

@ -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
}
}

View file

@ -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
}

View file

@ -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
}