prvng_core/nulib/lib_provisioning/project/detect.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

189 lines
4.6 KiB
Text

# Provisioning Project Detection Module
# Provides functions for technology detection and requirement inference
use ../../../lib_provisioning *
# Detect technologies in a project
export def detect-project [
project_path: string
--format: string = "text"
--high-confidence-only: bool = false
--pretty: bool = false
--debug: bool = false
] {
let detector_bin = (find-detector-binary)
if ($detector_bin | is-empty) or not ($detector_bin | path exists) {
return {
error: "Detector binary not found"
message: "Install: cargo build --release --bin provisioning-detector"
}
}
mut args = [
"detect"
$project_path
"--format" $format
]
if $high_confidence_only {
$args = ($args | append "--high-confidence-only")
}
if $pretty {
$args = ($args | append "--pretty")
}
# Execute detector binary (no try-catch)
let exec_result = (do { ^$detector_bin ...$args 2>&1 } | complete)
if $exec_result.exit_code != 0 {
return {
error: "Detection failed"
message: $exec_result.stderr
}
}
let output = $exec_result.stdout
if $format == "json" {
$output | from json
} else {
{ output: $output }
}
}
# Analyze gaps in infrastructure declaration
export def complete-project [
project_path: string
--format: string = "text"
--check: bool = false
--pretty: bool = false
--debug: bool = false
] {
let detector_bin = (find-detector-binary)
if ($detector_bin | is-empty) or not ($detector_bin | path exists) {
return {
error: "Detector binary not found"
message: "Install: cargo build --release --bin provisioning-detector"
}
}
mut args = [
"complete"
$project_path
"--format" $format
]
if $check {
$args = ($args | append "--check")
}
if $pretty {
$args = ($args | append "--pretty")
}
# Execute detector binary (no try-catch)
let exec_result = (do { ^$detector_bin ...$args 2>&1 } | complete)
if $exec_result.exit_code != 0 {
return {
error: "Completion failed"
message: $exec_result.stderr
}
}
let output = $exec_result.stdout
if $format == "json" {
$output | from json
} else {
{ output: $output }
}
}
# Find provisioning-detector binary in standard locations
def find-detector-binary [] {
let possible_paths = [
($env.PROVISIONING? | default "" | path join "platform" "detector" "target" "release" "provisioning-detector")
($env.PROVISIONING? | default "" | path join "platform" "detector" "target" "debug" "provisioning-detector")
"/usr/local/bin/provisioning-detector"
"/usr/bin/provisioning-detector"
]
let existing = ($possible_paths
| where {|p| ($p | is-not-empty) and ($p | path exists) }
)
if ($existing | length) > 0 {
$existing | first
} else {
""
}
}
# Format detection results for display
export def format-detection [
detection: record
--format: string = "text"
] {
if $format == "json" {
$detection | to json
} else {
# Text formatting
let output = @"
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Project Technology Detection Results
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Overall Confidence: ($detection.overall_confidence | into float | math round -p 1 | into string)%
Detected Technologies:
"@
let detections = if ($detection.detections | type) == "list" {
$detection.detections
} else {
[]
}
let result = if ($detections | length) > 0 {
($output + "\n" + ($detections | each {|d|
$" • ($d.technology) - ($d.confidence | into float | math round -p 1)%\n"
} | str join ""))
} else {
$output + "\n (No technologies detected)\n"
}
$result
}
}
# Check if project has specific technology
export def has-technology [
detection: record
technology: string
] {
$detection.detections
| any {|d| ($d.technology | str downcase) == ($technology | str downcase) }
}
# Get all detected technologies
export def get-technologies [
detection: record
] {
$detection.detections | each {|d| $d.technology }
}
# Get all inferred requirements
export def get-requirements [
detection: record
] {
$detection.requirements | default []
}
# Get required taskservs only
export def get-required-taskservs [
detection: record
] {
($detection.requirements | default [])
| where {|r| $r.required == true }
| each {|r| $r.taskserv }
}