57 lines
1.9 KiB
Text
57 lines
1.9 KiB
Text
|
|
#!/usr/bin/env nu
|
||
|
|
# scripts/check-gate.nu
|
||
|
|
# Query the vapora gate ontology for a given signal.
|
||
|
|
# Exits 0 if at least one active membrana accepts the signal, 1 otherwise.
|
||
|
|
#
|
||
|
|
# Usage:
|
||
|
|
# nu scripts/check-gate.nu --ontology .ontology --signal DepthDemonstrated
|
||
|
|
# nu scripts/check-gate.nu --ontology .ontology --signal PreguntaQueRompeElMarco --verbose
|
||
|
|
|
||
|
|
def main [
|
||
|
|
--ontology: path = ".ontology", # Path to the project .ontology directory
|
||
|
|
--signal: string = "", # Signal to check (TipoSenal variant name)
|
||
|
|
--verbose, # Print full membrana details
|
||
|
|
] {
|
||
|
|
if ($signal | is-empty) {
|
||
|
|
error make { msg: "required flag --signal is missing" }
|
||
|
|
}
|
||
|
|
|
||
|
|
let gate_file = $ontology | path join "gate.ncl"
|
||
|
|
|
||
|
|
if not ($gate_file | path exists) {
|
||
|
|
error make { msg: $"gate.ncl not found at '($gate_file)'" }
|
||
|
|
}
|
||
|
|
|
||
|
|
let result = do { ^nickel export --format json $gate_file } | complete
|
||
|
|
if $result.exit_code != 0 {
|
||
|
|
error make { msg: $"nickel export failed: ($result.stderr | str trim)" }
|
||
|
|
}
|
||
|
|
|
||
|
|
let config = $result.stdout | from json
|
||
|
|
let membranas = $config.membranas
|
||
|
|
|
||
|
|
let accepting = $membranas | where { |m|
|
||
|
|
$m.activa and ($m.acepta | any { |s| $s == $signal })
|
||
|
|
}
|
||
|
|
|
||
|
|
if $verbose {
|
||
|
|
print $"Signal: ($signal)"
|
||
|
|
print $"Active membranas checked: ($membranas | where activa | length)"
|
||
|
|
if not ($accepting | is-empty) {
|
||
|
|
print "Accepting membranas:"
|
||
|
|
$accepting | each { |m|
|
||
|
|
print $" ✓ ($m.id) [permeabilidad=($m.permeabilidad)] — ($m.descripcion)"
|
||
|
|
} | ignore
|
||
|
|
} else {
|
||
|
|
print "No active membrana accepts this signal."
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($accepting | is-empty) {
|
||
|
|
print $"gate: BLOCKED — no active membrana accepts signal '($signal)'"
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
|
||
|
|
print $"gate: PASS — ($accepting | length) membrana(s) accept signal '($signal)'"
|
||
|
|
}
|