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
97 changes: 95 additions & 2 deletions scripts/main/Start-ClaudeOS.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,25 @@ function Invoke-StepAgentInit {
}
}

function Get-StateJsonDashboard {
param([string]$Root)
$statePath = Join-Path $Root 'state.json'
if (-not (Test-Path $statePath)) {
return $null
}
try {
return Get-Content $statePath -Raw -Encoding UTF8 | ConvertFrom-Json
}
catch {
return $null
}
Comment on lines +224 to +235
}

function Write-BootDashboard {
param([array]$Results)
param(
[array]$Results,
[string]$Root
)
Write-BootStep 9 'Dashboard'
$ok = @($Results | Where-Object { $_.Status -eq 'OK' }).Count
$skip = @($Results | Where-Object { $_.Status -eq 'SKIP' }).Count
Expand All @@ -233,6 +250,82 @@ function Write-BootDashboard {
Write-Host (' SKIP : {0}' -f $skip) -ForegroundColor Yellow
Write-Host (' FAIL : {0}' -f $fail) -ForegroundColor Red
Write-Host ''

# state.json integration (Issue #71)
$state = if ($Root) { Get-StateJsonDashboard -Root $Root } else { $null }
if ($state) {
try {
$stateProps = $state.PSObject.Properties.Name

Write-Host ' ── Goal & KPI ──────────────────────────────' -ForegroundColor Magenta
if (($stateProps -contains 'goal') -and $state.goal -and $state.goal.title) {
Write-Host (' Goal : {0}' -f $state.goal.title) -ForegroundColor White
}
if (($stateProps -contains 'kpi') -and $state.kpi) {
$kpi = $state.kpi
$kpiProps = $kpi.PSObject.Properties.Name
$successTarget = if ($kpiProps -contains 'success_rate_target') { '{0:P0}' -f $kpi.success_rate_target } else { 'n/a' }
$ciTarget = if ($kpiProps -contains 'ci_pass_rate') { '{0:P0}' -f $kpi.ci_pass_rate } else { 'n/a' }
$openP1 = if ($kpiProps -contains 'open_p1_issues') { $kpi.open_p1_issues } else { 'n/a' }
Write-Host (" KPI : success>={0} CI>={1} P1-issues={2}" -f $successTarget, $ciTarget, $openP1) -ForegroundColor Cyan
}

if (($stateProps -contains 'execution') -and $state.execution) {
$exec = $state.execution
$execProps = $exec.PSObject.Properties.Name
$phase = if ($execProps -contains 'phase') { $exec.phase } else { 'unknown' }
$remaining = if ($execProps -contains 'remaining_minutes') { "$($exec.remaining_minutes)min" } else { 'n/a' }
$elapsed = if ($execProps -contains 'elapsed_minutes') { "$($exec.elapsed_minutes)min" } else { 'n/a' }
Write-Host ''
Write-Host ' ── Execution Status ────────────────────────' -ForegroundColor Magenta
Write-Host (" Phase : {0}" -f $phase) -ForegroundColor White
Write-Host (" Elapsed : {0} / Remaining: {1}" -f $elapsed, $remaining) -ForegroundColor White
}

if (($stateProps -contains 'token') -and $state.token) {
$tok = $state.token
$tokProps = $tok.PSObject.Properties.Name
$used = if ($tokProps -contains 'used') { $tok.used } else { '?' }
$remaining = if ($tokProps -contains 'remaining') { $tok.remaining } else { '?' }
$total = if ($tokProps -contains 'total_budget') { $tok.total_budget } else { '?' }
Write-Host ''
Write-Host ' ── Token Budget ────────────────────────────' -ForegroundColor Magenta
Write-Host (" Used/Total: {0}/{1} Remaining: {2}%" -f $used, $total, $remaining) -ForegroundColor White
}

if (($stateProps -contains 'current_work') -and $state.current_work) {
$work = $state.current_work
$workProps = $work.PSObject.Properties.Name
Write-Host ''
Write-Host ' ── Current Work ────────────────────────────' -ForegroundColor Magenta
if ($workProps -contains 'issue') {
$issueTitle = if ($workProps -contains 'title') { $work.title } else { '' }
Write-Host (" Issue #{0}: {1}" -f $work.issue, $issueTitle) -ForegroundColor White
}
if ($workProps -contains 'pr') {
$branch = if ($workProps -contains 'branch') { $work.branch } else { '' }
Write-Host (" PR #{0} [{1}]" -f $work.pr, $branch) -ForegroundColor Cyan
}
}

if (($stateProps -contains 'loop_history') -and $state.loop_history -and @($state.loop_history).Count -gt 0) {
$lastLoop = @($state.loop_history)[-1]
$loopProps = $lastLoop.PSObject.Properties.Name
$loopNum = if ($loopProps -contains 'loop') { $lastLoop.loop } else { '?' }
$loopPhase = if ($loopProps -contains 'phase') { $lastLoop.phase } else { '?' }
$loopOutcome = if ($loopProps -contains 'outcome') { $lastLoop.outcome } else { '' }
Write-Host ''
Write-Host ' ── Last Loop ───────────────────────────────' -ForegroundColor Magenta
Write-Host (" Loop {0} [{1}]: {2}" -f $loopNum, $loopPhase, $loopOutcome) -ForegroundColor DarkGray
}
Write-Host ''
}
catch {
Write-Host (' [WARN] Dashboard state.json read error: {0}' -f $_.Exception.Message) -ForegroundColor Yellow
Write-Host ''
}
}

return @{ OK = $ok; SKIP = $skip; FAIL = $fail }
}

Expand All @@ -255,7 +348,7 @@ $results += Invoke-StepAgentInit -Root $ScriptRoot
$results += Invoke-StepPlaceholder -Number 8 -Name 'Loop Engine Start' `
-Reason 'Loop orchestration handled by Claude Code /loop harness'

$summary = Write-BootDashboard -Results $results
$summary = Write-BootDashboard -Results $results -Root $ScriptRoot

if ($summary.FAIL -gt 0) {
Write-Host 'Boot sequence completed with errors.' -ForegroundColor Red
Expand Down
34 changes: 34 additions & 0 deletions tests/StartScripts.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,40 @@ Describe 'Start-*.ps1 dry-run flows' {
$output | Should -Match '\[Step 7\].*Agent Init'
$output | Should -Not -Match '\[Step 7\].*Agent Init.*SKIP'
}

It 'Start-ClaudeOS.ps1 の Step 9 Dashboard が state.json なしでも正常終了すること (Issue #71)' {
$scriptPath = Join-Path $script:RepoRoot 'scripts\main\Start-ClaudeOS.ps1'
$output = & $script:PowerShellExe -NoProfile -File $scriptPath -NonInteractive 2>&1 | Out-String
$LASTEXITCODE | Should -Be 0
$output | Should -Match '\[Step 9\].*Dashboard'
$output | Should -Match 'Boot Summary'
}
Comment on lines +219 to +225
Comment on lines +219 to +225

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

state.json 不在テストが不在条件を保証できていません

Line 219-225 は state.json を明示的に退避/削除していないため、既存ファイルがある環境ではフォールバック経路を検証できません。テスト名と実検証内容がズレます。

💡 修正案
     It 'Start-ClaudeOS.ps1 の Step 9 Dashboard が state.json なしでも正常終了すること (Issue `#71`)' {
         $scriptPath = Join-Path $script:RepoRoot 'scripts\main\Start-ClaudeOS.ps1'
-        $output = & $script:PowerShellExe -NoProfile -File $scriptPath -NonInteractive 2>&1 | Out-String
-        $LASTEXITCODE | Should -Be 0
-        $output | Should -Match '\[Step 9\].*Dashboard'
-        $output | Should -Match 'Boot Summary'
+        $statePath = Join-Path $script:RepoRoot 'state.json'
+        $stateBackup = if (Test-Path $statePath) { Get-Content $statePath -Raw -Encoding UTF8 } else { $null }
+        try {
+            Remove-Item $statePath -Force -ErrorAction SilentlyContinue
+            $output = & $script:PowerShellExe -NoProfile -File $scriptPath -NonInteractive 2>&1 | Out-String
+            $LASTEXITCODE | Should -Be 0
+            $output | Should -Match '\[Step 9\].*Dashboard'
+            $output | Should -Match 'Boot Summary'
+            $output | Should -Not -Match 'Goal & KPI'
+        }
+        finally {
+            if ($null -ne $stateBackup) {
+                Set-Content -Path $statePath -Value $stateBackup -Encoding UTF8
+            }
+        }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
It 'Start-ClaudeOS.ps1 の Step 9 Dashboard が state.json なしでも正常終了すること (Issue #71)' {
$scriptPath = Join-Path $script:RepoRoot 'scripts\main\Start-ClaudeOS.ps1'
$output = & $script:PowerShellExe -NoProfile -File $scriptPath -NonInteractive 2>&1 | Out-String
$LASTEXITCODE | Should -Be 0
$output | Should -Match '\[Step 9\].*Dashboard'
$output | Should -Match 'Boot Summary'
}
It 'Start-ClaudeOS.ps1 の Step 9 Dashboard が state.json なしでも正常終了すること (Issue `#71`)' {
$scriptPath = Join-Path $script:RepoRoot 'scripts\main\Start-ClaudeOS.ps1'
$statePath = Join-Path $script:RepoRoot 'state.json'
$stateBackup = if (Test-Path $statePath) { Get-Content $statePath -Raw -Encoding UTF8 } else { $null }
try {
Remove-Item $statePath -Force -ErrorAction SilentlyContinue
$output = & $script:PowerShellExe -NoProfile -File $scriptPath -NonInteractive 2>&1 | Out-String
$LASTEXITCODE | Should -Be 0
$output | Should -Match '\[Step 9\].*Dashboard'
$output | Should -Match 'Boot Summary'
$output | Should -Not -Match 'Goal & KPI'
}
finally {
if ($null -ne $stateBackup) {
Set-Content -Path $statePath -Value $stateBackup -Encoding UTF8
}
}
}
🧰 Tools
🪛 PSScriptAnalyzer (1.25.0)

[warning] Missing BOM encoding for non-ASCII encoded file 'StartScripts.Tests.ps1'

(PSUseBOMForUnicodeEncodedFile)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/StartScripts.Tests.ps1` around lines 219 - 225, The test block
"Start-ClaudeOS.ps1 の Step 9 Dashboard が state.json なしでも正常終了すること (Issue `#71`)"
does not ensure state.json is absent; update this It test to explicitly back up
and remove any existing state.json before invoking Start-ClaudeOS.ps1 and
restore the original file after the test (use a temp backup filename), so the
fallback path is exercised; reference the test's local variables ($scriptPath,
$output) and ensure cleanup runs even on failure (use Finally/try/finally
pattern or AfterEach-equivalent) to guarantee restoration.


It 'Start-ClaudeOS.ps1 の Step 9 Dashboard が state.json の Goal を表示すること (Issue #71)' {
$scriptPath = Join-Path $script:RepoRoot 'scripts\main\Start-ClaudeOS.ps1'
$statePath = Join-Path $script:RepoRoot 'state.json'
$stateBackup = if (Test-Path $statePath) { Get-Content $statePath -Raw -Encoding UTF8 } else { $null }
try {
@{
goal = @{ title = 'Dashboard UI Test Goal' }
kpi = @{ success_rate_target = 0.9; ci_pass_rate = 1.0; open_p1_issues = 0 }
execution = @{ phase = 'Verify'; elapsed_minutes = 10; remaining_minutes = 290 }
token = @{ used = 5; total_budget = 100; remaining = 95 }
} | ConvertTo-Json -Depth 5 | Set-Content -Path $statePath -Encoding UTF8
$output = & $script:PowerShellExe -NoProfile -File $scriptPath -NonInteractive 2>&1 | Out-String
$LASTEXITCODE | Should -Be 0
$output | Should -Match 'Dashboard UI Test Goal'
$output | Should -Match 'Goal'
}
finally {
if ($null -ne $stateBackup) {
Set-Content -Path $statePath -Value $stateBackup -Encoding UTF8
}
Comment on lines +229 to +246
else {
Remove-Item $statePath -Force -ErrorAction SilentlyContinue
}
}
}
}

Describe 'Start-Menu helper flows' {
Expand Down
Loading