Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions ops/TriWeavon.Unitary.Profile.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

Set-StrictMode -Version Latest

$script:UnitaryVersion = '1.1.1-unitary'
$script:UnitaryVersion = '1.1.2-unitary'
$script:SensorCache = $null
$script:SensorCacheAt = [datetime]::MinValue
$script:SensorTtlSec = 6
Expand Down Expand Up @@ -147,6 +147,33 @@ function Get-ShadeBar {
return ('█' * $n) + ('░' * ($Width - $n))
}


function Test-NextActionRunnable {
<#
.SYNOPSIS
ATOM-CLAUDE-LABEL-TW-NEXTLINE-20260820
A next: line is paste-able iff it is a resolvable command or comment-prefixed.
Prose in a command slot must fail here, not reach the operator.
#>
[CmdletBinding()]
param([Parameter(Mandatory)][AllowEmptyString()][string]$Line)
$item = ($Line -replace '^\d+\.\s*', '').Trim()
if (-not $item) { return $true }
if ($item.StartsWith('#')) { return $true }
$payload = ($item -split '#', 2)[0].Trim()
return [bool]($payload -match '^(tw|logos-[a-z-]+|cargo|docker|python|pwsh|cd|git|npm|node)\b')
}

function Assert-NextActionsRunnable {
param([string[]]$Actions)
foreach ($a in @($Actions)) {
if ($null -eq $a -or "$a" -eq '') { continue }
if (-not (Test-NextActionRunnable -Line "$a")) {
throw "tw next: prose in a command slot: $a — emit a resolvable command or prefix with #"
}
}
}

# ─── Sensor board ────────────────────────────────────────────────────────────

function Get-TriWeavonSensors {
Expand All @@ -171,15 +198,15 @@ function Get-TriWeavonSensors {
$s.logos_root = [pscustomobject]@{
name = 'logos_root'; ok = [bool]$root; critical = $true
detail = if ($root) { $root } else { 'MISSING — set LOGOS_ROOT' }
fix = if (-not $root) { 'Set LOGOS_ROOT=%USERPROFILE%\LogOS (or your clone path)' } else { $null }
fix = if (-not $root) { '# Set LOGOS_ROOT=%USERPROFILE%\LogOS (or your clone path)' } else { $null }
shade = Get-ShadeBar $(if ($root) { 1 } else { 0 })
}

$wsl = Get-UnitaryWslDistro
$s.wsl = [pscustomobject]@{
name = 'wsl'; ok = [bool]$wsl; critical = $true
detail = if ($wsl) { $wsl } else { 'no distro' }
fix = if (-not $wsl) { 'Install/start WSL Kali (build substrate)' } else { $null }
fix = if (-not $wsl) { '# Install/start WSL Kali (build substrate)' } else { $null }
shade = Get-ShadeBar $(if ($wsl) { 1 } else { 0 })
}

Expand Down Expand Up @@ -219,7 +246,7 @@ function Get-TriWeavonSensors {
$s.bridge = [pscustomobject]@{
name = 'bridge'; ok = $br; critical = $false
detail = if ($br) { 'ws://127.0.0.1:8088' } else { 'down — optional SPHINX WS' }
fix = if (-not $br) { 'Optional: start reson8 styx WS bridge on :8088' } else { $null }
fix = if (-not $br) { 'logos-bridge' } else { $null }
shade = Get-ShadeBar $(if ($br) { 0.9 } else { 0.15 })
}

Expand All @@ -235,7 +262,7 @@ function Get-TriWeavonSensors {
$s.docker = [pscustomobject]@{
name = 'docker'; ok = ($dockerHost -or $dockerWsl); critical = $false
detail = if ($dockerHost) { 'host CLI' } elseif ($dockerWsl) { "WSL/$wsl" } else { 'absent' }
fix = if (-not ($dockerHost -or $dockerWsl)) { 'Start Docker Desktop or dockerd in WSL' } else { $null }
fix = if (-not ($dockerHost -or $dockerWsl)) { '# Start Docker Desktop or dockerd in WSL' } else { $null }
shade = Get-ShadeBar $(if ($dockerHost -or $dockerWsl) { 0.9 } else { 0.1 })
}

Expand All @@ -250,7 +277,7 @@ function Get-TriWeavonSensors {
$s.schemas = [pscustomobject]@{
name = 'schemas'; ok = $schemaOk; critical = $true
detail = if ($schemaOk) { 'v0.1 filed' } else { 'schemas missing' }
fix = if (-not $schemaOk) { 'Pull LogOS; ensure docs/schemas/v0.1 exists' } else { $null }
fix = if (-not $schemaOk) { '# Pull LogOS; ensure docs/schemas/v0.1 exists' } else { $null }
shade = Get-ShadeBar $(if ($schemaOk) { 1 } else { 0 })
}

Expand All @@ -269,6 +296,7 @@ function Get-TriWeavonSensors {

$down = @($s.Values | Where-Object { -not $_.ok })
$actions = @($down | Where-Object { $_.fix } | ForEach-Object { $_.fix } | Select-Object -First 5)
Assert-NextActionsRunnable $actions

$board = [pscustomobject]@{
timestamp = $now.ToString('o')
Expand Down Expand Up @@ -751,5 +779,7 @@ Export-ModuleMember -Function @(
'Invoke-TriWeavonTw',
'Start-TriWeavonUnitary',
'Get-ShadeBar',
'Test-TcpPortFast'
'Test-TcpPortFast',
'Test-NextActionRunnable',
'Assert-NextActionsRunnable'
) -Alias @('tw', 'tw-sensors', 'tw-health', 'tw-fix', 'tw-up', 'tw-verify', 'tw-help', 'tw-confidence')
40 changes: 40 additions & 0 deletions ops/tests/Test-TwNextActions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ATOM-CLAUDE-LABEL-TW-NEXTLINE-20260820
# Fail the build if tw next: would print prose in a command slot.
# Checked by claude/reason. Owner: grok/build.

$ErrorActionPreference = 'Stop'
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$mod = Join-Path (Split-Path -Parent $here) 'TriWeavon.Unitary.Profile.psm1'
if (-not (Test-Path -LiteralPath $mod)) {
$mod = Join-Path $PSScriptRoot '../TriWeavon.Unitary.Profile.psm1'
}
Import-Module $mod -Force

$pass = 0; $fail = 0
function Expect($line, $ok) {
$got = Test-NextActionRunnable -Line $line
if ($got -eq $ok) {
Write-Host " PASS ok=$ok $line" -ForegroundColor Green
$script:pass++
} else {
Write-Host " FAIL expected ok=$ok got=$got $line" -ForegroundColor Red
$script:fail++
}
}

Expect 'logos-bridge' $true
Expect 'tw up waist # or WSL: cd "$LOGOS_ROOT" && docker compose up -d' $true
Expect 'tw up bbbr # python hup/unikernel/bbbr-verifier/bbbr_unix.py (:8081)' $true
Expect 'tw up styx # cargo run -p styx-vfs-layer --bin styx-bookshelf' $true
Expect '# Set LOGOS_ROOT=%USERPROFILE%\LogOS (or your clone path)' $true
Expect '# Install/start WSL Kali (build substrate)' $true
Expect '# Start Docker Desktop or dockerd in WSL' $true
Expect '# Pull LogOS; ensure docs/schemas/v0.1 exists' $true
Expect 'Optional: start reson8 styx WS bridge on :8088' $false
Expect 'Set LOGOS_ROOT=%USERPROFILE%\LogOS (or your clone path)' $false
Expect '' $true
Expect '# comment only' $true

Write-Host (" result: {0} pass / {1} fail" -f $pass, $fail)
if ($fail -gt 0) { exit 1 }
exit 0
Loading