prvng_core/nulib/lib_provisioning/project/detect.nu
Jesús Pérez e5ffc55104
refactor(23 files): selective imports + dangling/broken cleanup (ADR-025 L2/L3)
Large combined batch of 23 files refactored from star-imports to selective.
Grouped because two sub-batches accumulated in staging without intermediate
commit.

=== Orchestrator facades (Layer 3) ===
  ai/mod.nu              [12 symbols from ai/lib.nu]
  config/loader.nu       [14 symbols from loader/mod.nu]
  config/accessor/mod.nu [15 symbols from accessor/functions.nu]
  sops/mod.nu            [11 symbols from sops/lib.nu]
  user/mod.nu            [16 symbols from user/config.nu]

=== Selective imports ===
  defs/lists.nu                      utils/on_select (kept, selective)
  services/manager.nu                (all dead dropped)
  webhook/ai_webhook.nu              ai/lib [4] + settings/lib
  kms/lib.nu                         utils/error + utils/interface + plugins/kms
  gitea/locking.nu                   api_client [8]
  gitea/workspace_git.nu             api_client [3]
  gitea/extension_publish.nu         api_client [8] + config/loader
  infra_validator/rules_engine.nu    config_loader [3]
  plugins/kms.nu                     config/accessor/core [config-get]
  coredns/api_client.nu              config/loader [get-config]

=== Dangling imports removed (target file does not exist) ===
  coredns/docker.nu                  ../utils/log.nu → deleted (uses corefile.nu [2])
  coredns/zones.nu                   ../utils/log.nu → deleted (uses corefile.nu [1])
  coredns/service.nu                 ../utils/log.nu → deleted (uses corefile.nu [2])
  coredns/corefile.nu                ../utils/log.nu → deleted

=== Broken paths cleaned up ===
  project/detect.nu   Former `use ../../../lib_provisioning *` resolved to
    non-existent path (core/lib_provisioning). Silent no-op at runtime.
    Removed. Error count went 19 -> 17.

=== Dead imports dropped ===
  utils/ssh.nu           config/accessor DROPPED (dead)
  utils/init.nu          config/accessor DROPPED (dead)
  infra_validator/agent_interface.nu   report_generator DROPPED (dead)

=== Dynamic imports preserved ===
  providers/loader.nu   line 179 `use ($provider_entry.entry_point) *` is
    intentional runtime dispatch — not convertible to selective.

Validation: all files match pre-existing baseline. Gitea subsystem has
known pre-existing 50-error noise (transitive); independent of this work.

Refs: ADR-025
2026-04-17 12:13:13 +01:00

191 lines
4.7 KiB
Text

# Provisioning Project Detection Module
# Provides functions for technology detection and requirement inference
# Former `use ../../../lib_provisioning *` was a broken path (resolves to
# non-existent core/lib_provisioning) — it was a silent no-op at runtime.
# Removed per ADR-025 Phase 3 Layer 2.
# 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 }
}