The #195 opt-out lives in scripts/inject-plan.sh, and the Cursor hooks read task_plan.md directly instead of dispatching to it, so PLANNING_DISABLED=1 never reached any of the eight. Each guard reproduces its own hook's no-plan-file output, so the Cursor protocol shape is unchanged: PreToolUse still answers {"decision": "allow"} because that is what it emits unconditionally today, and the other three stay silent. Three defects found while auditing #222, #223 and #224: - The Copilot PreToolUse guard answered permissionDecision "allow" on the disabled path, so setting the variable to make planning inert also handed every tool call a blanket approval. Both copies now emit {}, matching their own no-plan-file path, which returns the decision to Copilot. - .cursor/hooks/stop.ps1 was the last copy the #191 zero-phase guard never reached. It answered "0/0 phases done" and auto-continued on a plan that was never phase-structured. - .github/hooks/scripts/error-occurred.ps1 read stdin into $input, which is PowerShell's automatic pipeline variable. Under -File the assignment does not stick, so the JSON parse always saw an empty string and the hook has never logged an error on Windows. Reproduced under pwsh 7 and Windows PowerShell 5.1 before the rename. The opt-out tests now run every hook twice, unset and set, and fail if the unset run is already inert. The merged versions asserted only the disabled run, which a fleet gutted to unconditional {} also passed. That baseline is what caught the $input bug.
43 lines
1.3 KiB
PowerShell
43 lines
1.3 KiB
PowerShell
# planning-with-files: Error hook for GitHub Copilot (Windows PowerShell)
|
|
# Logs errors to task_plan.md when the agent encounters an error.
|
|
|
|
if ($env:PLANNING_DISABLED -eq '1') {
|
|
Write-Output '{}'
|
|
exit 0
|
|
}
|
|
|
|
$planFile = "task_plan.md"
|
|
|
|
if (-not (Test-Path $planFile)) {
|
|
Write-Output '{}'
|
|
exit 0
|
|
}
|
|
|
|
# Read stdin. Do not name this $input: that is PowerShell's automatic pipeline
|
|
# variable, and under `-File` the assignment does not stick, so the hook read an
|
|
# empty string and never logged an error on Windows.
|
|
$InputData = [Console]::In.ReadToEnd()
|
|
|
|
try {
|
|
$data = $InputData | ConvertFrom-Json
|
|
$errorMsg = ""
|
|
if ($data.error -is [PSCustomObject]) {
|
|
$errorMsg = $data.error.message
|
|
} elseif ($data.error) {
|
|
$errorMsg = [string]$data.error
|
|
}
|
|
|
|
if ($errorMsg) {
|
|
$truncated = $errorMsg.Substring(0, [Math]::Min(200, $errorMsg.Length))
|
|
$context = "[planning-with-files] Error detected: $truncated. Log this error in task_plan.md under Errors Encountered with the attempt number and resolution."
|
|
$escaped = $context | ConvertTo-Json
|
|
Write-Output "{`"hookSpecificOutput`":{`"hookEventName`":`"ErrorOccurred`",`"additionalContext`":$escaped}}"
|
|
} else {
|
|
Write-Output '{}'
|
|
}
|
|
} catch {
|
|
Write-Output '{}'
|
|
}
|
|
|
|
exit 0
|