Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b4f95f1
account-availability -Mark writes and parses timestamps in the invari…
wshallwshall Nov 24, 2026
07d4759
account-availability -Clear and -Status refuse a missing root; a dire…
wshallwshall Nov 24, 2026
5399ad3
account-availability: ISO-only -EffectiveFrom, and the reader formats…
wshallwshall Nov 24, 2026
9e9ec1c
install-gate refuses to overwrite a gate that does not match its receipt
wshallwshall Nov 24, 2026
c63f1a7
install-gate receipt guard: review repairs
wshallwshall Nov 24, 2026
5002ebf
Scope the install-gate "changes nothing" claim, print (no receipt), f…
wshallwshall Nov 24, 2026
53d1e35
mail.ps1 keys every addressed path on its enclosing worktree root
wshallwshall Nov 24, 2026
fb6df84
Stop-hook notice shim emits a systemMessage so the missing-script not…
wshallwshall Nov 24, 2026
c54cfbc
mail.ps1 refuses a -To path below a worktree root instead of raising it
wshallwshall Nov 24, 2026
dcc787d
Notice-shim tests derive their rows from the installer and pin them t…
wshallwshall Nov 24, 2026
c6920f7
Withdraw the mail.ps1 addressing change; keep the spelling pins
wshallwshall Nov 24, 2026
2296372
Classify tests/test_session_mail_toplevel.py in the tooling manifest
wshallwshall Nov 24, 2026
6a3705f
Merge b681/account-availability (batch 681)
wshallwshall Nov 24, 2026
58f95f3
Merge b681/1247-fix (batch 681)
wshallwshall Nov 24, 2026
be1c48b
Merge b681/7575-notice-shim (batch 681)
wshallwshall Nov 24, 2026
65ddef2
Merge b681/7581-fix (batch 681)
wshallwshall Nov 24, 2026
41ca1f2
install-gate: the receipt guard judges the one read it re-checks; two…
wshallwshall Nov 24, 2026
2a6235c
install-gate tests: name what the one-read test covers, pin the refus…
wshallwshall Nov 24, 2026
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
14 changes: 14 additions & 0 deletions docs/WORKTREE-GATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ position, so a checkout many commits behind with an unchanged gate still passes.

`-UpstreamRef` names a different yardstick.

Every install leaves `worktree_gate.ps1.receipt.json` beside the installed gate, with the hash it wrote,
and keeps the replaced gate as `worktree_gate.ps1.bak`. The installer **refuses to overwrite an
installed gate that does not match its own receipt** (BACKLOG #1247): one whose content hash differs
from the receipt's, one whose receipt cannot be read or records no hash, and one with no receipt at all.
Each means something other than the installer may have written it. The refusal names the file and both
hashes, and runs before any write, so it changes nothing. (The separate refusal for a gate that
changed between that check and the copy throws later, after the allowlist write: the allowlist and its
`.bak` are already written, the gate is not.) A missing receipt refuses too, because the receipt is not protected by
the gate and deleting it must not silence the check; a box with no installed gate installs as before.
Find out who wrote the gate, then pass `-OverwriteUnexplained`; the new receipt records the
overwritten hash under `overwroteUnexplained`, and its bytes are kept as
`worktree_gate.ps1.unexplained-<sha12>`. `-Status` reports the same check. The receipt is a
convenience record, never attestation, and the gate does not protect it from an edit.

Two structural choices worth understanding:

- **Every config dir, not just `~/.claude`.** The hook is registered into `~/.claude/settings.json` **and**
Expand Down
75 changes: 62 additions & 13 deletions scripts/coord/account-availability.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ function Show-One([string]$Root) {
}
}

function Assert-ConfigRoot([string]$Root) {
if (-not (Test-Path -LiteralPath $Root -PathType Container)) {
Write-Host "REFUSED -- no such config root: $Root" -ForegroundColor Red
Write-Host " This script will not create one, and reads nothing from one. Check the path." -ForegroundColor DarkGray
exit 1
}
}

function Assert-MarkerNotDirectory([string]$MarkerPath) {
if (Test-Path -LiteralPath $MarkerPath -PathType Container) {
Write-Host "REFUSED -- the availability marker path is a directory: $MarkerPath" -ForegroundColor Red
Write-Host " The reader treats this account as UNAVAILABLE (MALFORMED). Remove the directory by hand." -ForegroundColor DarkGray
exit 1
}
}

switch ($PSCmdlet.ParameterSetName) {

'Mark' {
Expand All @@ -121,15 +137,34 @@ switch ($PSCmdlet.ParameterSetName) {
# -Force builds every missing ancestor, so a typo'd -ConfigDir would have this command
# MANUFACTURE a config root nothing can launch from and then declare it cancelled -- a wholly
# fictional account, recorded as fact, with nothing anywhere reporting a problem.
if (-not (Test-Path -LiteralPath $ConfigDir -PathType Container)) {
Write-Host "REFUSED -- no such config root: $ConfigDir" -ForegroundColor Red
Write-Host " This script will not create one. Check the path." -ForegroundColor DarkGray
exit 1
}
Assert-ConfigRoot $ConfigDir
$sd = Get-UsageStateDir $ConfigDir
$path = Join-Path $sd $script:UsageUnavailableMarker
Assert-MarkerNotDirectory $path

# THE INVARIANT CULTURE, BOTH WAYS, OR THE MARKER IS NOT THE ISO TEXT ITS READERS PARSE. Under
# th-TH the current culture's Thai Buddhist calendar wrote marked_at in year 2569, so an account
# marked dead NOW read PENDING for 543 years; under fi-FI the time separator became '.'; under
# ar-SA the Um Al Qura calendar refused '2026-10-01' outright. ConvertTo-UtcDateTime parses with
# the current culture, so -EffectiveFrom is parsed here instead, and ONLY as ISO-8601: a lenient
# parse took 'Jan 5' as a date already past and an en-GB '01/10/2026' as 10 January, marking a
# live account dead now. A form with no offset keeps its old meaning, the operator's LOCAL time.
$inv = [cultureinfo]::InvariantCulture
$iso = "yyyy-MM-dd'T'HH:mm:ss'Z'"
$eff = $null
if ($EffectiveFrom) {
$eff = ConvertTo-UtcDateTime $EffectiveFrom
# BOUND, NOT TRUTHY: an explicit -EffectiveFrom '' (a wrapper passing an unset variable) must be
# refused, not read as omitted and so as "now".
if ($PSBoundParameters.ContainsKey('EffectiveFrom')) {
$parsed = [System.DateTimeOffset]::MinValue
$forms = [string[]]@(
'yyyy-MM-dd',
"yyyy-MM-dd'T'HH:mm", "yyyy-MM-dd'T'HH:mmK",
"yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm:ssK",
"yyyy-MM-dd'T'HH:mm:ss.FFFFFFF", "yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK"
)
if ([System.DateTimeOffset]::TryParseExact([string]$EffectiveFrom, $forms, $inv, [System.Globalization.DateTimeStyles]::AssumeLocal, [ref]$parsed)) {
$eff = $parsed.UtcDateTime
}
if ($null -eq $eff) {
Write-Host "REFUSED -- -EffectiveFrom is not a date I can read: $EffectiveFrom" -ForegroundColor Red
Write-Host " Use an ISO-8601 date, for example 2026-10-01 or 2026-10-01T00:00:00Z." -ForegroundColor DarkGray
Expand All @@ -143,20 +178,25 @@ switch ($PSCmdlet.ParameterSetName) {
$doc = [ordered]@{
unavailable = $true
reason = $Reason
marked_at = $now.ToString('yyyy-MM-ddTHH:mm:ssZ')
marked_at = $now.ToString($iso, $inv)
marked_by = $By
effective_from = $(if ($eff) { $eff.ToString('yyyy-MM-ddTHH:mm:ssZ') } else { $now.ToString('yyyy-MM-ddTHH:mm:ssZ') })
effective_from = $(if ($eff) { $eff } else { $now }).ToString($iso, $inv)
}

$sd = Get-UsageStateDir $ConfigDir
New-Item -ItemType Directory -Force -Path $sd | Out-Null
$path = Join-Path $sd $script:UsageUnavailableMarker
# Temp-then-rename, the same discipline the collector uses: a reader must never observe a
# half-written marker, and a half-written marker reads as MALFORMED, which fails closed on a
# live account.
# The finally removes the temp file a failed write or rename would otherwise leave beside the
# marker; after a successful rename it no longer exists, so it removes nothing.
$tmp = "$path.$PID.tmp"
[System.IO.File]::WriteAllText($tmp, ($doc | ConvertTo-Json -Depth 4), [System.Text.Encoding]::UTF8)
[System.IO.File]::Move($tmp, $path, $true)
try {
[System.IO.File]::WriteAllText($tmp, ($doc | ConvertTo-Json -Depth 4), [System.Text.Encoding]::UTF8)
[System.IO.File]::Move($tmp, $path, $true)
}
finally {
if (Test-Path -LiteralPath $tmp) { Remove-Item -LiteralPath $tmp -Force -ErrorAction SilentlyContinue }
}

$pending = $eff -and $eff -gt $now
Write-Host ""
Expand All @@ -180,8 +220,14 @@ switch ($PSCmdlet.ParameterSetName) {
}

'Clear' {
# A typo'd root carries no marker, so without this a clear of a fictional account reported
# NOTHING TO CLEAR and exit 0, and the real marker stayed in force. BACKLOG #7558.
Assert-ConfigRoot $ConfigDir
$sd = Get-UsageStateDir $ConfigDir
$path = Join-Path $sd $script:UsageUnavailableMarker
# A directory at the marker path is not "no marker": the reader takes it as MALFORMED and the
# account as UNAVAILABLE, so NOTHING TO CLEAR there was false.
Assert-MarkerNotDirectory $path
Write-Host ""
if (Test-Path -LiteralPath $path -PathType Leaf) {
Remove-Item -LiteralPath $path -Force
Expand Down Expand Up @@ -220,6 +266,9 @@ switch ($PSCmdlet.ParameterSetName) {
}
}
else {
# A typo'd root has no marker and so read AVAILABLE, an all-clear for an account that
# does not exist. BACKLOG #7558.
Assert-ConfigRoot $ConfigDir
Show-One $ConfigDir
}
Write-Host ""
Expand Down
4 changes: 2 additions & 2 deletions scripts/coord/config-roots.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,11 @@ function Get-RootUnavailability {
# written rather than blanked, because a hand-edited marker saying "last Tuesday" should show what
# it says instead of vanishing.
$mk = ConvertTo-UtcDateTime $doc.marked_at
$o.marked_at = if ($mk) { $mk.ToString('yyyy-MM-ddTHH:mm:ssZ') } else { [string]$doc.marked_at }
$o.marked_at = if ($mk) { $mk.ToString('yyyy-MM-ddTHH:mm:ssZ', [cultureinfo]::InvariantCulture) } else { [string]$doc.marked_at }
$o.marked_by = [string]$doc.marked_by
$eff = ConvertTo-UtcDateTime $doc.effective_from
if ($eff) {
$o.effective_from = $eff.ToString('yyyy-MM-ddTHH:mm:ssZ')
$o.effective_from = $eff.ToString('yyyy-MM-ddTHH:mm:ssZ', [cultureinfo]::InvariantCulture)
if ($eff -gt (Get-Date).ToUniversalTime()) {
$o.state = 'PENDING'
return $o
Expand Down
13 changes: 10 additions & 3 deletions scripts/coord/install-coordination.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,16 @@ function New-AnnounceShimCommand {
#
# The wiki write prompt needs the same shape for the same reason, so one builder serves any row that
# sets Shim = "notice" and carries its own Notice text.
#
# WHY THE NOTICE IS {"systemMessage": ...} JSON AND NOT PLAIN TEXT (BACKLOG #7575). Every row that uses
# this shim is a Stop hook (tests/test_announce_wiring.py pins that). Plain exit-0 stdout reaches context only on SessionStart, UserPromptSubmit
# and a few other events (scripts/hooks/precompact-reprime.ps1 records the list); on Stop it goes to
# the debug log and nobody sees it, so a plain-text notice was as silent as the std shim it replaced.
# systemMessage is a field every hook event accepts and the user is shown; it neither blocks the Stop
# nor adds to context -- the same form install-gate.ps1's fail-open notice uses.
function New-NoticeShimCommand([string]$RelativeScript, [string]$Marker, [string]$Notice) {
# The notice sits inside a single-quoted literal, so double any single quote it carries.
$Notice = $Notice.Replace("'", "''")
# The JSON sits inside a single-quoted literal, so double any single quote it carries.
$json = ([ordered]@{ systemMessage = $Notice } | ConvertTo-Json -Compress).Replace("'", "''")
return (
"# $Marker`n" +
'$c = (& git rev-parse --path-format=absolute --git-common-dir 2>$null); ' +
Expand All @@ -274,7 +281,7 @@ function New-NoticeShimCommand([string]$RelativeScript, [string]$Marker, [string
'if (Test-Path -LiteralPath (Join-Path $b ''scripts/coord/presence.ps1'')) { $mf = $true } ' +
"`$s = Join-Path `$b '$RelativeScript'; " +
'if (Test-Path -LiteralPath $s) { & $s; $hit = $true; break } } ' +
'if (-not $hit -and $mf) { Write-Output ' + "'$Notice'" + ' } }'
'if (-not $hit -and $mf) { Write-Output ' + "'$json'" + ' } }'
)
}

Expand Down
Loading
Loading