prvng_core/nulib/lib_provisioning/plugins_defs.nu
Jesús Pérez 894046ef5a
feat(core): three-layer DAG, unified component arch, commands-registry cache, Nushell 0.112.2 migration
- DAG architecture: `dag show/validate/export` (nulib/main_provisioning/dag.nu),
    config loader (lib_provisioning/config/loader/dag.nu), taskserv dag-executor.
    Backed by schemas/lib/dag/*.ncl; orchestrator emits NATS events via
    WorkspaceComposition::into_workflow. See ADR-020, ADR-021.
  - Unified Component Architecture: components/mod.nu, main_provisioning/
    {components,workflow,extensions,ontoref-queries}.nu. Full workflow engine with
    topological sort and NATS subject emission. Blocks A-H complete (libre-daoshi).
  - Commands-registry: nulib/commands-registry.ncl (Nickel source, 314 lines) +
    JSON cache at ~/.cache/provisioning/commands-registry.json rebuilt on source
    change. cli/provisioning fast-path alias expansion avoids cold Nu startup.
    ADDING_COMMANDS.md documents new-command workflow.
  - Platform service manager: service-manager.nu (+573), startup.nu (+611),
    service-check.nu (+255); autostart/bootstrap/health/target refactored.
  - Nushell 0.112.2 migration: removed all try/catch and bash redirections;
    external commands prefixed with ^; type signatures enforced. Driven by
    scripts/refactor-try-catch{,-simplified}.nu.
  - TTY stack: removed shlib/*-tty.sh; replaced by cli/tty-dispatch.sh,
    tty-filter.sh, tty-commands.conf.
  - New domain modules: images/ (golden image lifecycle), workspace/{state,sync}.nu,
    main_provisioning/{bootstrap,cluster-deploy,fip,state}.nu, commands/{state,
    build,integrations/auth,utilities/alias}.nu, platform.nu expanded (+874).
  - Config loader overhaul: loader/core.nu slimmed (-759), cache/core.nu
    refactored (-454), removed legacy loaders/file_loader.nu (-330).
  - Thirteen new provisioning-<domain>.nu top-level modules for bash dispatcher.
  - Tests: test_workspace_state.nu (+351); updates to test_oci_registry,
    test_services.
  - README + CHANGELOG updated.
2026-04-17 04:27:33 +01:00

124 lines
3.2 KiB
Text

use utils *
use config/accessor.nu *
use ./utils/nickel_processor.nu [ncl-eval]
export def clip_copy [
msg: string
show: bool
] {
if ( (version).installed_plugins | str contains "clipboard" ) {
$msg | clipboard copy
print $"(_ansi default_dimmed)copied into clipboard now (_ansi reset)"
} else {
if (not $show) { _print $msg }
}
}
export def notify_msg [
title: string
body: string
icon: string
time_body: string
timeout: duration
task?: closure
] {
if ( (version).installed_plugins | str contains "desktop_notifications" ) {
if $task != null {
( notify -s $title -t $time_body --timeout $timeout -i $icon)
} else {
( notify -s $title -t $body --timeout $timeout -i $icon)
}
} else {
if $task != null {
_print (
$"(_ansi blue)($title)(_ansi reset)\n(_ansi blue_bold)($time_body)(_ansi reset)"
)
} else {
_print (
$"(_ansi blue)($title)(_ansi reset)\n(_ansi blue_bold)($body)(_ansi reset)"
)
}
}
}
export def show_qr [
url: string
] {
# Try to use pre-generated QR code files
let qr_path = ((get-provisioning-resources) | path join "qrs" | path join ($url | path basename))
if ($qr_path | path exists) {
_print (open -r $qr_path)
} else {
# Fallback: display URL in reverse video format
_print $"(_ansi blue_reverse)($url)(_ansi reset)"
_print $"(_ansi purple)($url)(_ansi reset)"
}
}
export def port_scan [
ip: string
port: int
sec_timeout: int
] {
# Use netcat for port scanning - reliable and portable
(^nc -zv -w $sec_timeout ($ip | str trim) $port err> (if $nu.os-info.name == "windows" { "NUL" } else { "/dev/null" }) | complete).exit_code == 0
}
export def render_template [
template_path: string
vars: record
--ai_prompt: string
] {
# Regular template rendering
if ( (version).installed_plugins | str contains "tera" ) {
$vars | tera-render $template_path
} else {
error make { msg: "nu_plugin_tera not available - template rendering not supported" }
}
}
export def render_template_ai [
ai_prompt: string
template_type: string = "template"
] {
use ai/lib.nu *
ai_generate_template $ai_prompt $template_type
}
export def process_decl_file [
decl_file: string
format: string
] {
# Use external Nickel CLI (nickel export)
if (get-use-nickel) {
# Note: format parameter is only used if it's "json"; otherwise raw nickel export is needed
if $format == "json" {
let result = (ncl-eval $decl_file [])
$result | to json
} else {
# For non-JSON formats, use raw nickel command
let result = (do { ^nickel export $decl_file --format $format } | complete)
if $result.exit_code == 0 {
$result.stdout
} else {
error make { msg: $result.stderr }
}
}
} else {
error make { msg: "Nickel CLI not available" }
}
}
export def validate_decl_schema [
decl_file: string
data: record
] {
# Validate using external Nickel CLI
if (get-use-nickel) {
let data_json = ($data | to json)
let result = (^nickel validate $decl_file --data $data_json | complete)
$result.exit_code == 0
} else {
false
}
}